Add configuration options for F-Ticks logging.
[libradsec.git] / radsecproxy.h
1 /*
2  * Copyright (C) 2006-2009 Stig Venaas <venaas@uninett.no>
3  * Copyright (C) 2010 NORDUnet A/S
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  */
9
10 #include "tlv11.h"
11 #include "radmsg.h"
12 #include "gconfig.h"
13
14 #define DEBUG_LEVEL 2
15
16 #define CONFIG_MAIN "/etc/radsecproxy.conf"
17
18 /* MAX_REQUESTS must be 256 due to Radius' 8 bit ID field */
19 #define MAX_REQUESTS 256
20 #define REQUEST_RETRY_INTERVAL 5
21 #define REQUEST_RETRY_COUNT 2
22 #define DUPLICATE_INTERVAL REQUEST_RETRY_INTERVAL * REQUEST_RETRY_COUNT
23 #define MAX_CERT_DEPTH 5
24 #define STATUS_SERVER_PERIOD 25
25 #define IDLE_TIMEOUT 300
26
27 /* 27262 is vendor DANTE Ltd. */
28 #define DEFAULT_TTL_ATTR "27262:1"
29
30 #define RAD_UDP 0
31 #define RAD_TLS 1
32 #define RAD_TCP 2
33 #define RAD_DTLS 3
34 #define RAD_PROTOCOUNT 4
35
36 enum rsp_fticks_reporting_type {
37     RSP_FTICKS_REPORTING_NONE = 0, /* Default.  */
38     RSP_FTICKS_REPORTING_BASIC,
39     RSP_FTICKS_REPORTING_FULL
40 };
41
42 enum rsp_fticks_mac_type {
43     RSP_FTICKS_MAC_STATIC = 0,  /* Default.  */
44     RSP_FTICKS_MAC_ORIGINAL,
45     RSP_FTICKS_MAC_VENDOR_HASHED,
46     RSP_FTICKS_MAC_VENDOR_KEY_HASHED,
47     RSP_FTICKS_MAC_FULLY_HASHED,
48     RSP_FTICKS_MAC_FULLY_KEY_HASHED
49 };
50
51 struct options {
52     char *logdestination;
53     char *ttlattr;
54     uint32_t ttlattrtype[2];
55     uint8_t addttl;
56     uint8_t loglevel;
57     uint8_t loopprevention;
58     enum rsp_fticks_reporting_type fticks_reporting;
59     enum rsp_fticks_mac_type fticks_mac;
60     char *fticks_key;
61 };
62
63 struct commonprotoopts {
64     char **listenargs;
65     char *sourcearg;
66 };
67
68 struct request {
69     struct timeval created;
70     uint32_t refcount;
71     uint8_t *buf, *replybuf;
72     struct radmsg *msg;
73     struct client *from;
74     struct server *to;
75     char *origusername;
76     uint8_t rqid;
77     uint8_t rqauth[16];
78     uint8_t newid;
79     int udpsock; /* only for UDP */
80     uint16_t udpport; /* only for UDP */
81 };
82
83 /* requests that our client will send */
84 struct rqout {
85     pthread_mutex_t *lock;
86     struct request *rq;
87     uint8_t tries;
88     struct timeval expiry;
89 };
90
91 struct gqueue {
92     struct list *entries;
93     pthread_mutex_t mutex;
94     pthread_cond_t cond;
95 };
96
97 struct clsrvconf {
98     char *name;
99     uint8_t type; /* RAD_UDP/RAD_TLS/RAD_TCP */
100     const struct protodefs *pdef;
101     char **hostsrc;
102     char *portsrc;
103     struct list *hostports;
104     char *secret;
105     char *tls;
106     char *matchcertattr;
107     regex_t *certcnregex;
108     regex_t *certuriregex;
109     char *confrewritein;
110     char *confrewriteout;
111     char *confrewriteusername;
112     struct modattr *rewriteusername;
113     char *dynamiclookupcommand;
114     uint8_t statusserver;
115     uint8_t retryinterval;
116     uint8_t retrycount;
117     uint8_t dupinterval;
118     uint8_t certnamecheck;
119     uint8_t addttl;
120     uint8_t loopprevention;
121     struct rewrite *rewritein;
122     struct rewrite *rewriteout;
123     pthread_mutex_t *lock; /* only used for updating clients so far */
124     struct tls *tlsconf;
125     struct list *clients;
126     struct server *servers;
127 };
128
129 #include "tlscommon.h"
130
131 struct client {
132     struct clsrvconf *conf;
133     int sock;
134     SSL *ssl;
135     struct request *rqs[MAX_REQUESTS];
136     struct gqueue *replyq;
137     struct gqueue *rbios; /* for dtls */
138     struct sockaddr *addr;
139     time_t expiry; /* for udp */
140 };
141
142 struct server {
143     struct clsrvconf *conf;
144     int sock;
145     SSL *ssl;
146     pthread_mutex_t lock;
147     pthread_t clientth;
148     uint8_t clientrdgone;
149     struct timeval lastconnecttry;
150     struct timeval lastreply;
151     uint8_t connectionok;
152     uint8_t lostrqs;
153     uint8_t dynstartup;
154     char *dynamiclookuparg;
155     int nextid;
156     struct timeval lastrcv;
157     struct rqout *requests;
158     uint8_t newrq;
159     pthread_mutex_t newrq_mutex;
160     pthread_cond_t newrq_cond;
161     struct gqueue *rbios; /* for dtls */
162 };
163
164 struct realm {
165     char *name;
166     char *message;
167     uint8_t accresp;
168     regex_t regex;
169     uint32_t refcount;
170     pthread_mutex_t mutex;
171     struct realm *parent;
172     struct list *subrealms;
173     struct list *srvconfs;
174     struct list *accsrvconfs;
175 };
176
177 struct modattr {
178     uint8_t t;
179     char *replacement;
180     regex_t *regex;
181 };
182
183 struct rewrite {
184     uint8_t *removeattrs;
185     uint32_t *removevendorattrs;
186     struct list *addattrs;
187     struct list *modattrs;
188 };
189
190 struct protodefs {
191     char *name;
192     char *secretdefault;
193     int socktype;
194     char *portdefault;
195     uint8_t retrycountdefault;
196     uint8_t retrycountmax;
197     uint8_t retryintervaldefault;
198     uint8_t retryintervalmax;
199     uint8_t duplicateintervaldefault;
200     void (*setprotoopts)(struct commonprotoopts *);
201     char **(*getlistenerargs)();
202     void *(*listener)(void*);
203     int (*connecter)(struct server *, struct timeval *, int, char *);
204     void *(*clientconnreader)(void*);
205     int (*clientradput)(struct server *, unsigned char *);
206     void (*addclient)(struct client *);
207     void (*addserverextra)(struct clsrvconf *);
208     void (*setsrcres)();
209     void (*initextra)();
210 };
211
212 #define RADLEN(x) ntohs(((uint16_t *)(x))[1])
213
214 #define ATTRTYPE(x) ((x)[0])
215 #define ATTRLEN(x) ((x)[1])
216 #define ATTRVAL(x) ((x) + 2)
217 #define ATTRVALLEN(x) ((x)[1] - 2)
218
219 struct clsrvconf *find_clconf(uint8_t type, struct sockaddr *addr, struct list_node **cur);
220 struct clsrvconf *find_srvconf(uint8_t type, struct sockaddr *addr, struct list_node **cur);
221 struct clsrvconf *find_clconf_type(uint8_t type, struct list_node **cur);
222 struct client *addclient(struct clsrvconf *conf, uint8_t lock);
223 void removelockedclient(struct client *client);
224 void removeclient(struct client *client);
225 struct gqueue *newqueue();
226 void freebios(struct gqueue *q);
227 struct request *newrequest();
228 void freerq(struct request *rq);
229 int radsrv(struct request *rq);
230 void replyh(struct server *server, unsigned char *buf);
231 struct addrinfo *resolve_hostport_addrinfo(uint8_t type, char *hostport);
232
233 /* Local Variables: */
234 /* c-file-style: "stroustrup" */
235 /* End: */