implemented retries
[libradsec.git] / radsecproxy.h
1 /*
2  * Copyright (C) 2006 Stig Venaas <venaas@uninett.no>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  */
8
9 #define RADLEN(x) ntohs(((uint16_t *)(x))[1])
10
11 #define SOCKADDR_SIZE(addr) ((addr).ss_family == AF_INET ? \
12                             sizeof(struct sockaddr_in) : \
13                             sizeof(struct sockaddr_in6))
14
15 #define MAX_PEERS 256
16 /* MAX_REQUESTS must be 256 due to Radius' 8 bit ID field */
17 #define MAX_REQUESTS 256
18 #define DEFAULT_TLS_SECRET "mysecret"
19 #define DEFAULT_UDP_PORT "1812"
20 #define DEFAULT_TLS_PORT "2083"
21 #define REQUEST_EXPIRY 20
22 #define REQUEST_RETRIES 3
23 #define MAX_CERT_DEPTH 5
24
25 #define RAD_Access_Request 1
26 #define RAD_Access_Accept 2
27 #define RAD_Access_Reject 3
28 #define RAD_Accounting_Request 4
29 #define RAD_Accounting_Response 5
30 #define RAD_Access_Challenge 11
31 #define RAD_Status_Server 12
32 #define RAD_Status_Client 13
33
34 #define RAD_Attr_User_Name 1
35 #define RAD_Attr_User_Password 2
36 #define RAD_Attr_Vendor_Specific 26
37 #define RAD_Attr_Tunnel_Password 69
38 #define RAD_Attr_Message_Authenticator 80
39
40 #define RAD_VS_ATTR_MS_MPPE_Send_Key 16
41 #define RAD_VS_ATTR_MS_MPPE_Recv_Key 17
42
43 #define RAD_Attr_Type 0
44 #define RAD_Attr_Length 1
45 #define RAD_Attr_Value 2
46
47 struct options {
48     char *tlscacertificatefile;
49     char *tlscacertificatepath;
50     char *tlscertificatefile;
51     char *tlscertificatekeyfile;
52     char *udpserverport;
53 };
54     
55 /* requests that our client will send */
56 struct request {
57     unsigned char *buf;
58     uint8_t tries;
59     uint8_t received;
60     struct timeval expiry;
61     struct client *from;
62     char *messageauthattrval;
63     uint8_t origid; /* used by servwr */
64     char origauth[16]; /* used by servwr */
65     struct sockaddr_storage fromsa; /* used by udpservwr */
66 };
67
68 /* replies that a server will send */
69 struct reply {
70     unsigned char *buf;
71     struct sockaddr_storage tosa; /* used by udpservwr */
72 };
73
74 struct replyq {
75     struct reply *replies;
76     int count;
77     int size;
78     pthread_mutex_t count_mutex;
79     pthread_cond_t count_cond;
80 };
81
82 struct peer {
83     char type; /* U for UDP, T for TLS */
84     char *host;
85     char *port;
86     char *secret;
87     SSL *ssl;
88     struct addrinfo *addrinfo;
89 };
90
91 struct client {
92     struct peer peer;
93     struct replyq *replyq;
94 };
95
96 struct server {
97     struct peer peer;
98     char *realmdata;
99     char **realms;
100     int sock;
101     pthread_mutex_t lock;
102     pthread_t clientth;
103     struct timeval lastconnecttry;
104     uint8_t connectionok;
105     int nextid;
106     struct request *requests;
107     uint8_t newrq;
108     pthread_mutex_t newrq_mutex;
109     pthread_cond_t newrq_cond;
110 };
111
112 void errx(char *format, ...);
113 void err(char *format, ...);
114 char *stringcopy(char *s, int len);
115 char *addr2string(struct sockaddr *addr, socklen_t len);
116 int bindport(int type, char *port);
117 int connectport(int type, char *host, char *port);