From: bodea Date: Thu, 16 Dec 2004 08:49:52 +0000 (+0000) Subject: use standard uintN_t types for portability X-Git-Tag: release_2_0_13~3 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/6b1075b65c4239e97629f3a891f49f5ae9ef3d4b?ds=sidebyside use standard uintN_t types for portability --- diff --git a/Changes b/Changes index f0cc0b9..0853325 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,4 @@ -* Mon Dec 13 2004 Brendan O'Dea 2.0.13 +* Thu Dec 16 2004 Brendan O'Dea 2.0.13 - Better cluster master collision resolution: keep a counter of state changes, propagated in the heartbeats; the master with the highest # of changes (that has kept in contact with the LAC through the @@ -12,6 +12,7 @@ attempt to avoid losing the cluster in high load (DoS) conditions. - Compress logs. - Retain counters of shutdown sessions to dump once per minute. +- Use standard uintN_t types for portability. * Wed Dec 1 2004 Brendan O'Dea 2.0.12 - The "This time, for sure!" release. diff --git a/Makefile b/Makefile index 8bbbc42..0bff86f 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,6 @@ install: all ## Dependencies: (autogenerated) ## arp.o: arp.c l2tpns.h -bgp.o: bgp.c l2tpns.h bgp.h util.h cli.o: cli.c l2tpns.h util.h cluster.h tbf.h ll.h bgp.h cluster.o: cluster.c l2tpns.h cluster.h util.h tbf.h bgp.h constants.o: constants.c constants.h @@ -132,6 +131,7 @@ ppp.o: ppp.c l2tpns.h constants.h plugin.h util.h tbf.h cluster.h radius.o: radius.c md5.h constants.h l2tpns.h plugin.h util.h tbf.o: tbf.c l2tpns.h util.h tbf.h util.o: util.c l2tpns.h bgp.h +bgp.o: bgp.c l2tpns.h bgp.h util.h garden.so: garden.c l2tpns.h plugin.h control.h throttlectl.so: throttlectl.c l2tpns.h plugin.h control.h autothrottle.so: autothrottle.c l2tpns.h plugin.h diff --git a/arp.c b/arp.c index 4434364..3dd6e96 100644 --- a/arp.c +++ b/arp.c @@ -1,6 +1,6 @@ // L2TPNS: arp -char const *cvs_id_arp = "$Id: arp.c,v 1.4 2004/07/08 16:19:09 bodea Exp $"; +char const *cvs_id_arp = "$Id: arp.c,v 1.5 2004/12/16 08:49:52 bodea Exp $"; #include #include @@ -18,12 +18,12 @@ struct arp_buf { /* Data bit - variably sized, so not present in |struct arphdr| */ unsigned char ar_sha[ETH_ALEN]; /* Sender hardware address */ - ipt ar_sip; /* Sender IP address. */ + in_addr_t ar_sip; /* Sender IP address. */ unsigned char ar_tha[ETH_ALEN]; /* Target hardware address */ - ipt ar_tip; /* Target ip */ + in_addr_t ar_tip; /* Target ip */ } __attribute__((packed)); -void sendarp(int ifr_idx, const unsigned char* mac, ipt ip) +void sendarp(int ifr_idx, const unsigned char* mac, in_addr_t ip) { int fd; struct sockaddr_ll sll; diff --git a/bgp.c b/bgp.c index cf8ab7e..9f64d39 100644 --- a/bgp.c +++ b/bgp.c @@ -10,7 +10,7 @@ * nor RFC2385 (which requires a kernel patch on 2.4 kernels). */ -char const *cvs_id_bgp = "$Id: bgp.c,v 1.8 2004/11/29 02:17:17 bodea Exp $"; +char const *cvs_id_bgp = "$Id: bgp.c,v 1.9 2004/12/16 08:49:52 bodea Exp $"; #include #include @@ -34,7 +34,7 @@ static struct bgp_route_list *bgp_insert_route(struct bgp_route_list *head, struct bgp_route_list *new); static void bgp_free_routes(struct bgp_route_list *routes); -static char const *bgp_msg_type_str(u8 type); +static char const *bgp_msg_type_str(uint8_t type); static int bgp_connect(struct bgp_peer *peer); static int bgp_handle_connect(struct bgp_peer *peer); static int bgp_write(struct bgp_peer *peer); @@ -43,9 +43,10 @@ static int bgp_handle_input(struct bgp_peer *peer); static int bgp_send_open(struct bgp_peer *peer); static int bgp_send_keepalive(struct bgp_peer *peer); static int bgp_send_update(struct bgp_peer *peer); -static int bgp_send_notification(struct bgp_peer *peer, u8 code, u8 subcode); +static int bgp_send_notification(struct bgp_peer *peer, uint8_t code, + uint8_t subcode); -static u16 our_as; +static uint16_t our_as; static struct bgp_route_list *bgp_routes = 0; int bgp_configured = 0; @@ -89,7 +90,8 @@ int bgp_setup(int as) } /* start connection with a peer */ -int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold, int enable) +int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, + int hold, int enable) { struct hostent *h; int ibgp; @@ -98,8 +100,8 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold char path_attrs[64]; char *p = path_attrs; in_addr_t ip; - u32 metric = htonl(BGP_METRIC); - u32 no_export = htonl(BGP_COMMUNITY_NO_EXPORT); + uint32_t metric = htonl(BGP_METRIC); + uint32_t no_export = htonl(BGP_COMMUNITY_NO_EXPORT); if (!our_as) return 0; @@ -170,9 +172,9 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold { /* just our AS */ struct { - u8 type; - u8 len; - u16 value; + uint8_t type; + uint8_t len; + uint16_t value; } as_path = { BGP_PATH_ATTR_CODE_AS_PATH_AS_SEQUENCE, 1, @@ -204,7 +206,7 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold if (ibgp) { - u32 local_pref = htonl(BGP_LOCAL_PREF); + uint32_t local_pref = htonl(BGP_LOCAL_PREF); /* LOCAL_PREF */ a.flags = BGP_PATH_ATTR_FLAG_TRANS; @@ -324,7 +326,7 @@ static void bgp_set_retry(struct bgp_peer *peer) static void bgp_cidr(in_addr_t ip, in_addr_t mask, struct bgp_ip_prefix *pfx) { int i; - u32 b; + uint32_t b; /* convert to prefix notation */ pfx->len = 32; @@ -641,7 +643,7 @@ char const *bgp_state_str(enum bgp_state state) return "?"; } -static char const *bgp_msg_type_str(u8 type) +static char const *bgp_msg_type_str(uint8_t type) { switch (type) { @@ -987,7 +989,7 @@ static int bgp_handle_input(struct bgp_peer *peer) static int bgp_send_open(struct bgp_peer *peer) { struct bgp_data_open data; - u16 len = sizeof(peer->outbuf->packet.header); + uint16_t len = sizeof(peer->outbuf->packet.header); memset(peer->outbuf->packet.header.marker, 0xff, sizeof(peer->outbuf->packet.header.marker)); @@ -1029,9 +1031,9 @@ static int bgp_send_keepalive(struct bgp_peer *peer) /* send/buffer UPDATE message */ static int bgp_send_update(struct bgp_peer *peer) { - u16 unf_len = 0; - u16 attr_len; - u16 len = sizeof(peer->outbuf->packet.header); + uint16_t unf_len = 0; + uint16_t attr_len; + uint16_t len = sizeof(peer->outbuf->packet.header); struct bgp_route_list *have = peer->routes; struct bgp_route_list *want = peer->routing ? bgp_routes : 0; struct bgp_route_list *e = 0; @@ -1169,10 +1171,11 @@ static int bgp_send_update(struct bgp_peer *peer) } /* send/buffer NOTIFICATION message */ -static int bgp_send_notification(struct bgp_peer *peer, u8 code, u8 subcode) +static int bgp_send_notification(struct bgp_peer *peer, uint8_t code, + uint8_t subcode) { struct bgp_data_notification data; - u16 len = 0; + uint16_t len = 0; data.error_code = code; len += sizeof(data.error_code); diff --git a/bgp.h b/bgp.h index ae89b47..6559566 100644 --- a/bgp.h +++ b/bgp.h @@ -1,5 +1,5 @@ /* BGPv4 (RFC1771) */ -/* $Id: bgp.h,v 1.3 2004/11/11 03:07:42 bodea Exp $ */ +/* $Id: bgp.h,v 1.4 2004/12/16 08:49:52 bodea Exp $ */ #ifndef __BGP_H__ #define __BGP_H__ @@ -17,8 +17,8 @@ struct bgp_header { char marker[16]; - u16 len; - u8 type; + uint16_t len; + uint8_t type; } __attribute__ ((packed)); /* bgp_header.type */ @@ -33,33 +33,33 @@ struct bgp_packet { } __attribute__ ((packed)); struct bgp_data_open { - u8 version; + uint8_t version; #define BGP_VERSION 4 - u16 as; - u16 hold_time; - u32 identifier; - u8 opt_len; + uint16_t as; + uint16_t hold_time; + uint32_t identifier; + uint8_t opt_len; #define BGP_DATA_OPEN_SIZE 10 /* size of struct excluding opt_params */ char opt_params[sizeof(((struct bgp_packet *)0)->data) - BGP_DATA_OPEN_SIZE]; /* variable */ } __attribute__ ((packed)); struct bgp_ip_prefix { - u8 len; - u32 prefix; /* variable */ + uint8_t len; + uint32_t prefix; /* variable */ } __attribute__ ((packed)); #define BGP_IP_PREFIX_SIZE(p) (1 + ((p).len / 8) + ((p).len % 8 != 0)) struct bgp_path_attr { - u8 flags; - u8 code; + uint8_t flags; + uint8_t code; union { struct { - u8 len; + uint8_t len; char value[29]; /* semi-random size, adequate for l2tpns */ } __attribute__ ((packed)) s; /* short */ struct { - u16 len; + uint16_t len; char value[28]; } __attribute__ ((packed)) e; /* extended */ } data; /* variable */ @@ -95,8 +95,8 @@ struct bgp_path_attr { #define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 /* don't advertise to any other AS */ struct bgp_data_notification { - u8 error_code; - u8 error_subcode; + uint8_t error_code; + uint8_t error_subcode; char data[sizeof(((struct bgp_packet *)0)->data) - 2]; /* variable */ } __attribute__ ((packed)); @@ -185,7 +185,9 @@ extern int bgp_configured; /* actions */ int bgp_setup(int as); -int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold, int enable); +int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, + int hold, int enable); + void bgp_stop(struct bgp_peer *peer); void bgp_halt(struct bgp_peer *peer); int bgp_restart(struct bgp_peer *peer); diff --git a/cli.c b/cli.c index 857f8b2..a02f645 100644 --- a/cli.c +++ b/cli.c @@ -2,7 +2,7 @@ // vim: sw=8 ts=8 char const *cvs_name = "$Name: $"; -char const *cvs_id_cli = "$Id: cli.c,v 1.40 2004/12/15 03:09:56 bodea Exp $"; +char const *cvs_id_cli = "$Id: cli.c,v 1.41 2004/12/16 08:49:52 bodea Exp $"; #include #include @@ -1252,8 +1252,8 @@ static int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc) { - ipt ip; - u16 port; + in_addr_t ip; + uint16_t port; sessionidt s; if (CLI_HELP_REQUESTED) @@ -2393,7 +2393,7 @@ static int cmd_no_ip_access_list(struct cli_def *cli, char *command, char **argv return access_list(cli, argv, argc, 0); } -static int show_ip_wild(char *buf, ipt ip, ipt wild) +static int show_ip_wild(char *buf, in_addr_t ip, in_addr_t wild) { if (ip == INADDR_ANY && wild == INADDR_BROADCAST) return sprintf(buf, " any"); @@ -2524,8 +2524,8 @@ ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char * for (a = 1, i = 0; i < 2; i++) { - ipt *ip; - ipt *wild; + in_addr_t *ip; + in_addr_t *wild; ip_filter_portt *port; if (i == 0) @@ -2667,7 +2667,7 @@ ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char * while (a < argc && (argv[a][0] == '+' || argv[a][0] == '-')) { - u8 *f; + uint8_t *f; f = (argv[a][0] == '+') ? &rule.tcp_sflags : &rule.tcp_cflags; diff --git a/cluster.c b/cluster.c index 4497f69..6ef6f83 100644 --- a/cluster.c +++ b/cluster.c @@ -1,6 +1,6 @@ // L2TPNS Clustering Stuff -char const *cvs_id_cluster = "$Id: cluster.c,v 1.24 2004/12/15 02:56:38 bodea Exp $"; +char const *cvs_id_cluster = "$Id: cluster.c,v 1.25 2004/12/16 08:49:53 bodea Exp $"; #include #include @@ -18,6 +18,7 @@ char const *cvs_id_cluster = "$Id: cluster.c,v 1.24 2004/12/15 02:56:38 bodea Ex #include #include #include +#include #include "l2tpns.h" #include "cluster.h" @@ -40,7 +41,7 @@ char const *cvs_id_cluster = "$Id: cluster.c,v 1.24 2004/12/15 02:56:38 bodea Ex // Module variables. int cluster_sockfd = 0; // The filedescriptor for the cluster communications port. -ipt my_address = 0; // The network address of my ethernet port. +in_addr_t my_address = 0; // The network address of my ethernet port. static int walk_session_number = 0; // The next session to send when doing the slow table walk. static int walk_tunnel_number = 0; // The next tunnel to send when doing the slow table walk. @@ -60,15 +61,15 @@ static struct { // we can re-transmit if needed. static struct { - u32 peer; - time_t basetime; - clockt timestamp; - int uptodate; + in_addr_t peer; + time_t basetime; + clockt timestamp; + int uptodate; } peers[CLUSTER_MAX_SIZE]; // List of all the peers we've heard from. static int num_peers; // Number of peers in list. -static int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize); -static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize); +static int rle_decompress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize); +static int rle_compress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize); // // Create a listening socket @@ -177,17 +178,17 @@ static int cluster_send_data(void *data, int datalen) // Maintains the format. Assumes that the caller // has passed in a big enough buffer! // -static void add_type(char ** p, int type, int more, char * data, int size) +static void add_type(char **p, int type, int more, char *data, int size) { - * ( (u32*)(*p) ) = type; - *p += sizeof(u32); + *((uint32_t *) (*p)) = type; + *p += sizeof(uint32_t); - * ( (u32*)(*p) ) = more; - *p += sizeof(u32); + *((uint32_t *)(*p)) = more; + *p += sizeof(uint32_t); if (data && size > 0) { memcpy(*p, data, size); - (*p) += size; + *p += size; } } @@ -221,7 +222,7 @@ static void cluster_uptodate(void) // Send a unicast UDP packet to a peer with 'data' as the // contents. // -static int peer_send_data(u32 peer, char * data, int size) +static int peer_send_data(in_addr_t peer, char *data, int size) { struct sockaddr_in addr = {0}; @@ -249,10 +250,10 @@ static int peer_send_data(u32 peer, char * data, int size) // // Send a structured message to a peer with a single element of type 'type'. // -static int peer_send_message(u32 peer, int type, int more, char * data, int size) +static int peer_send_message(in_addr_t peer, int type, int more, char *data, int size) { char buf[65536]; // Vast overkill. - char * p = buf; + char *p = buf; LOG(4, 0, 0, "Sending message to peer (type %d, more %d, size %d)\n", type, more, size); add_type(&p, type, more, data, size); @@ -266,7 +267,7 @@ static int peer_send_message(u32 peer, int type, int more, char * data, int size // The master just processes the payload as if it had // received it off the tun device. // -int master_forward_packet(char *data, int size, u32 addr, int port) +int master_forward_packet(char *data, int size, in_addr_t addr, int port) { char buf[65536]; // Vast overkill. char *p = buf; @@ -277,12 +278,11 @@ int master_forward_packet(char *data, int size, u32 addr, int port) LOG(4, 0, 0, "Forwarding packet from %s to master (size %d)\n", fmtaddr(addr, 0), size); STAT(c_forwarded); - add_type(&p, C_FORWARD, addr, (char*) &port, sizeof(port) ); + add_type(&p, C_FORWARD, addr, (char *) &port, sizeof(port)); memcpy(p, data, size); p += size; - return peer_send_data(config->cluster_master_address, buf, (p-buf) ); - + return peer_send_data(config->cluster_master_address, buf, (p - buf)); } // @@ -337,7 +337,7 @@ int master_garden_packet(sessionidt s, char *data, int size) // Send a chunk of data as a heartbeat.. // We save it in the history buffer as we do so. // -static void send_heartbeat(int seq, char * data, int size) +static void send_heartbeat(int seq, char *data, int size) { int i; @@ -426,7 +426,7 @@ void master_update_counts(void) // Forward the data to the master. LOG(4, 0, 0, "Sending byte counters to master (%d elements)\n", c); - peer_send_message(config->cluster_master_address, C_BYTES, c, (char*) &b, sizeof(b[0]) * c); + peer_send_message(config->cluster_master_address, C_BYTES, c, (char *) &b, sizeof(b[0]) * c); return; } @@ -688,9 +688,9 @@ static int hb_add_type(char **p, int type, int id) { switch (type) { case C_CSESSION: { // Compressed C_SESSION. - u8 c[sizeof(sessiont) * 2]; // Bigger than worst case. - u8 *d = (u8 *) &session[id]; - u8 *orig = d; + uint8_t c[sizeof(sessiont) * 2]; // Bigger than worst case. + uint8_t *d = (uint8_t *) &session[id]; + uint8_t *orig = d; int size; size = rle_compress( &d, sizeof(sessiont), c, sizeof(c) ); @@ -698,19 +698,19 @@ static int hb_add_type(char **p, int type, int id) // Did we compress the full structure, and is the size actually // reduced?? if ( (d - orig) == sizeof(sessiont) && size < sizeof(sessiont) ) { - add_type(p, C_CSESSION, id, (char*) c, size); + add_type(p, C_CSESSION, id, (char *) c, size); break; } // Failed to compress : Fall through. } case C_SESSION: add_type(p, C_SESSION, id, - (char*) &session[id], sizeof(sessiont)); + (char *) &session[id], sizeof(sessiont)); break; case C_CTUNNEL: { // Compressed C_TUNNEL - u8 c[sizeof(tunnelt) * 2]; // Bigger than worst case. - u8 *d = (u8 *) &tunnel[id]; - u8 *orig = d; + uint8_t c[sizeof(tunnelt) * 2]; // Bigger than worst case. + uint8_t *d = (uint8_t *) &tunnel[id]; + uint8_t *orig = d; int size; size = rle_compress( &d, sizeof(tunnelt), c, sizeof(c) ); @@ -724,7 +724,7 @@ static int hb_add_type(char **p, int type, int id) // Failed to compress : Fall through. } case C_TUNNEL: add_type(p, C_TUNNEL, id, - (char*) &tunnel[id], sizeof(tunnelt)); + (char *) &tunnel[id], sizeof(tunnelt)); break; default: LOG(0, 0, 0, "Found an invalid type in heart queue! (%d)\n", type); @@ -766,14 +766,14 @@ void cluster_heartbeat() h.timeout = config->cluster_hb_timeout; h.table_version = config->cluster_table_version; - add_type(&p, C_HEARTBEAT, HB_VERSION, (char*) &h, sizeof(h)); + add_type(&p, C_HEARTBEAT, HB_VERSION, (char *) &h, sizeof(h)); for (i = 0; i < config->cluster_num_changes; ++i) { hb_add_type(&p, cluster_changes[i].type, cluster_changes[i].id); } if (p > (buff + sizeof(buff))) { // Did we somehow manage to overun the buffer? - LOG(0, 0, 0, "FATAL: Overran the heartbeat buffer! This is fatal. Exiting. (size %d)\n", p - buff); + LOG(0, 0, 0, "FATAL: Overran the heartbeat buffer! This is fatal. Exiting. (size %d)\n", (int) (p - buff)); kill(0, SIGTERM); exit(1); } @@ -781,7 +781,7 @@ void cluster_heartbeat() // // Fill out the packet with sessions from the session table... // (not forgetting to leave space so we can get some tunnels in too ) - while ( (p + sizeof(u32) * 2 + sizeof(sessiont) * 2 ) < (buff + MAX_HEART_SIZE) ) { + while ( (p + sizeof(uint32_t) * 2 + sizeof(sessiont) * 2 ) < (buff + MAX_HEART_SIZE) ) { if (!walk_session_number) // session #0 isn't valid. ++walk_session_number; @@ -801,7 +801,7 @@ void cluster_heartbeat() // than the session table. This is good because stuffing up a // tunnel is a much bigger deal than stuffing up a session. // - while ( (p + sizeof(u32) * 2 + sizeof(tunnelt) ) < (buff + MAX_HEART_SIZE) ) { + while ( (p + sizeof(uint32_t) * 2 + sizeof(tunnelt) ) < (buff + MAX_HEART_SIZE) ) { if (!walk_tunnel_number) // tunnel #0 isn't valid. ++walk_tunnel_number; @@ -818,16 +818,16 @@ void cluster_heartbeat() // // Did we do something wrong? if (p > (buff + sizeof(buff))) { // Did we somehow manage to overun the buffer? - LOG(0, 0, 0, "Overran the heartbeat buffer now! This is fatal. Exiting. (size %d)\n", p - buff); + LOG(0, 0, 0, "Overran the heartbeat buffer now! This is fatal. Exiting. (size %d)\n", (int) (p - buff)); kill(0, SIGTERM); exit(1); } - LOG(3, 0, 0, "Sending v%d heartbeat #%d, change #%llu with %d changes " + LOG(3, 0, 0, "Sending v%d heartbeat #%d, change #%" PRIu64 " with %d changes " "(%d x-sess, %d x-tunnels, %d highsess, %d hightun, size %d)\n", HB_VERSION, h.seq, h.table_version, config->cluster_num_changes, count, tcount, config->cluster_highest_sessionid, - config->cluster_highest_tunnelid, (p-buff)); + config->cluster_highest_tunnelid, (int) (p - buff)); config->cluster_num_changes = 0; @@ -887,7 +887,7 @@ int cluster_send_tunnel(int tid) // missed a packet. We'll resend it every packet since // the last one it's seen. // -static int cluster_catchup_slave(int seq, u32 slave) +static int cluster_catchup_slave(int seq, in_addr_t slave) { int s; int diff; @@ -922,10 +922,10 @@ static int cluster_catchup_slave(int seq, u32 slave) // We've heard from another peer! Add it to the list // that we select from at election time. // -static int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size) +static int cluster_add_peer(in_addr_t peer, time_t basetime, pingt *pp, int size) { int i; - u32 clusterid; + in_addr_t clusterid; pingt p; // Allow for backward compatability. @@ -935,8 +935,8 @@ static int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size) if (size > sizeof(p)) size = sizeof(p); - memset( (void*) &p, 0, sizeof(p) ); - memcpy( (void*) &p, (void*) pp, size); + memset( (void *) &p, 0, sizeof(p) ); + memcpy( (void *) &p, (void *) pp, size); clusterid = p.addr; if (clusterid != config->bind_address) @@ -1006,11 +1006,11 @@ static int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size) // Note that we don't mark the session as dirty; We rely on // the slow table walk to propogate this back out to the slaves. // -static int cluster_handle_bytes(char * data, int size) +static int cluster_handle_bytes(char *data, int size) { - bytest * b; + bytest *b; - b = (bytest*) data; + b = (bytest *) data; LOG(3, 0, 0, "Got byte counter update (size %d)\n", size); @@ -1043,7 +1043,7 @@ static int cluster_handle_bytes(char * data, int size) // // Handle receiving a session structure in a heartbeat packet. // -static int cluster_recv_session(int more , u8 * p) +static int cluster_recv_session(int more, uint8_t *p) { if (more >= MAXSESSION) { LOG(0, 0, 0, "DANGER: Received a heartbeat session id > MAXSESSION!\n"); @@ -1058,7 +1058,7 @@ static int cluster_recv_session(int more , u8 * p) } } - load_session(more, (sessiont*) p); // Copy session into session table.. + load_session(more, (sessiont *) p); // Copy session into session table.. LOG(5, more, 0, "Received session update (%d undef)\n", config->cluster_undefined_sessions); @@ -1068,7 +1068,7 @@ static int cluster_recv_session(int more , u8 * p) return 0; } -static int cluster_recv_tunnel(int more, u8 *p) +static int cluster_recv_tunnel(int more, uint8_t *p) { if (more >= MAXTUNNEL) { LOG(0, 0, 0, "DANGER: Received a tunnel session id > MAXTUNNEL!\n"); @@ -1106,9 +1106,9 @@ static int cluster_recv_tunnel(int more, u8 *p) // // v3: added interval, timeout // v4: added table_version -static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32 addr) +static int cluster_process_heartbeat(uint8_t *data, int size, int more, uint8_t *p, in_addr_t addr) { - heartt * h; + heartt *h; int s = size - (p-data); int i, type; @@ -1126,7 +1126,7 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32 if (s < sizeof(*h)) goto shortpacket; - h = (heartt*) p; + h = (heartt *) p; p += sizeof(*h); s -= sizeof(*h); @@ -1144,7 +1144,7 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32 if (more >= 4) { if (h->table_version > config->cluster_table_version) { - LOG(0, 0, 0, "They've seen more state changes (%llu vs my %llu) so I'm gone!\n", + LOG(0, 0, 0, "They've seen more state changes (%" PRIu64 " vs my %" PRIu64 ") so I'm gone!\n", h->table_version, config->cluster_table_version); kill(0, SIGTERM); @@ -1220,21 +1220,21 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32 // Ok. process the packet... while ( s > 0) { - type = * ((u32*) p); - p += sizeof(u32); - s -= sizeof(u32); + type = *((uint32_t *) p); + p += sizeof(uint32_t); + s -= sizeof(uint32_t); - more = * ((u32*) p); - p += sizeof(u32); - s -= sizeof(u32); + more = *((uint32_t *) p); + p += sizeof(uint32_t); + s -= sizeof(uint32_t); switch (type) { case C_CSESSION: { // Compressed session structure. - u8 c [ sizeof(sessiont) + 2]; + uint8_t c[ sizeof(sessiont) + 2]; int size; - u8 * orig_p = p; + uint8_t *orig_p = p; - size = rle_decompress((u8 **) &p, s, c, sizeof(c) ); + size = rle_decompress((uint8_t **) &p, s, c, sizeof(c) ); s -= (p - orig_p); if (size != sizeof(sessiont) ) { // Ouch! Very very bad! @@ -1257,11 +1257,11 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32 break; case C_CTUNNEL: { // Compressed tunnel structure. - u8 c [ sizeof(tunnelt) + 2]; + uint8_t c[ sizeof(tunnelt) + 2]; int size; - u8 * orig_p = p; + uint8_t *orig_p = p; - size = rle_decompress( (u8 **) &p, s, c, sizeof(c) ); + size = rle_decompress((uint8_t **) &p, s, c, sizeof(c)); s -= (p - orig_p); if (size != sizeof(tunnelt) ) { // Ouch! Very very bad! @@ -1310,10 +1310,10 @@ shortpacket: // We got a packet on the cluster port! // Handle pings, lastseens, and heartbeats! // -int processcluster(char * data, int size, u32 addr) +int processcluster(char *data, int size, in_addr_t addr) { int type, more; - char * p = data; + char *p = data; int s = size; if (addr == my_address) @@ -1327,17 +1327,17 @@ int processcluster(char * data, int size, u32 addr) if (s < 8) goto shortpacket; - type = * ((u32*) p); - p += sizeof(u32); - s -= sizeof(u32); + type = *((uint32_t *) p); + p += sizeof(uint32_t); + s -= sizeof(uint32_t); - more = * ((u32*) p); - p += sizeof(u32); - s -= sizeof(u32); + more = *((uint32_t *) p); + p += sizeof(uint32_t); + s -= sizeof(uint32_t); switch (type) { case C_PING: // Update the peers table. - return cluster_add_peer(addr, more, (pingt*)p, s); + return cluster_add_peer(addr, more, (pingt *) p, s); case C_LASTSEEN: // Catch up a slave (slave missed a packet). return cluster_catchup_slave(more, addr); @@ -1346,7 +1346,7 @@ int processcluster(char * data, int size, u32 addr) struct sockaddr_in a; a.sin_addr.s_addr = more; - a.sin_port = * (int*) p; + a.sin_port = *(int *) p; s -= sizeof(int); p += sizeof(int); @@ -1481,11 +1481,11 @@ int cmd_show_cluster(struct cli_def *cli, char *command, char **argv, int argc) // // Worst case is a 50% expansion in space required (trying to // compress { 0x00, 0x01 } * N ) -static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize) +static int rle_compress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize) { int count; int orig_dsize = dsize; - u8 * x,*src; + uint8_t *x, *src; src = *src_p; while (ssize > 0 && dsize > 2) { @@ -1527,11 +1527,11 @@ static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize) // Return the number of dst bytes used. // Updates the 'src_p' pointer to point to the // first un-used byte. -static int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize) +static int rle_decompress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize) { int count; int orig_dsize = dsize; - char * src = *src_p; + char *src = *src_p; while (ssize >0 && dsize > 0) { // While there's more to decompress, and there's room in the decompress buffer... count = *src++; --ssize; // get the count byte from the source. diff --git a/cluster.h b/cluster.h index f986ab1..bd776f4 100644 --- a/cluster.h +++ b/cluster.h @@ -1,5 +1,5 @@ // L2TPNS Clustering Stuff -// $Id: cluster.h,v 1.8 2004/12/03 06:40:02 bodea Exp $ +// $Id: cluster.h,v 1.9 2004/12/16 08:49:53 bodea Exp $ #ifndef __CLUSTER_H__ #define __CLUSTER_H__ @@ -34,44 +34,44 @@ #define DEFAULT_MCAST_INTERFACE "eth0" typedef struct { - u32 version; // protocol version. - u32 seq; // Sequence number for this heatbeat. - u32 basetime; // What time I started - u32 clusterid; // Id for this cluster? + uint32_t version; // protocol version. + uint32_t seq; // Sequence number for this heatbeat. + uint32_t basetime; // What time I started + uint32_t clusterid; // Id for this cluster? - u32 highsession; // Id of the highest in-use session. - u32 freesession; // Id of the first free session. - u32 hightunnel; // Id of the highest used tunnel. - u32 size_sess; // Size of the session structure. + uint32_t highsession; // Id of the highest in-use session. + uint32_t freesession; // Id of the first free session. + uint32_t hightunnel; // Id of the highest used tunnel. + uint32_t size_sess; // Size of the session structure. - u32 size_tunn; // size of the tunnel structure. - u32 interval; // ping/heartbeat interval - u32 timeout; // heartbeat timeout + uint32_t size_tunn; // size of the tunnel structure. + uint32_t interval; // ping/heartbeat interval + uint32_t timeout; // heartbeat timeout - u64 table_version; // # state changes processed by cluster + uint64_t table_version; // # state changes processed by cluster - char reserved[128 - 13*sizeof(u32)]; // Pad out to 128 bytes. + char reserved[128 - 13*sizeof(uint32_t)]; // Pad out to 128 bytes. } heartt; typedef struct { /* Used to update byte counters on the */ /* master. */ - u32 sid; - u32 in; - u32 out; + uint32_t sid; + uint32_t in; + uint32_t out; } bytest; typedef struct { - u32 addr; // - u32 ver; // version of structure. - u32 undef; // Number of undefined structures. 0 if up-to-date. - u32 basetime; // start time of this peer. + in_addr_t addr; // peer address + uint32_t ver; // version of structure. + uint32_t undef; // Number of undefined structures. 0 if up-to-date. + uint32_t basetime; // start time of this peer. } pingt; int cluster_init(void); -int processcluster(char *buf, int size, u32 addr); +int processcluster(char *buf, int size, in_addr_t addr); int cluster_send_session(int sid); int cluster_send_tunnel(int tid); -int master_forward_packet(char *data, int size, u32 addr, int port); +int master_forward_packet(char *data, int size, in_addr_t addr, int port); int master_throttle_packet(int tid, char *data, int size); int master_garden_packet(sessionidt s, char *data, int size); void master_update_counts(void); diff --git a/control.c b/control.c index 4909648..d67a57c 100644 --- a/control.c +++ b/control.c @@ -1,12 +1,12 @@ // L2TPNS: control -char const *cvs_id_control = "$Id: control.c,v 1.3 2004/11/17 08:23:34 bodea Exp $"; +char const *cvs_id_control = "$Id: control.c,v 1.4 2004/12/16 08:49:53 bodea Exp $"; #include #include "l2tpns.h" #include "control.h" -int pack_control(char *data, int len, u8 type, int argc, char *argv[]) +int pack_control(char *data, int len, uint8_t type, int argc, char *argv[]) { struct nsctl_packet pkt; struct nsctl_args arg; @@ -102,7 +102,7 @@ int unpack_control(struct nsctl *control, char *data, int len) if (len < sz + 1) return NSCTL_ERR_SHORT; - s = (u8) *p; + s = (uint8_t) *p; *p++ = 0; // null terminate previous arg sz++; diff --git a/control.h b/control.h index 8dd159c..ee7ed7d 100644 --- a/control.h +++ b/control.h @@ -27,27 +27,27 @@ #define NSCTL_MAX_PKT_SZ 4096 struct nsctl_packet { - u16 magic; - u8 type; - u8 argc; + uint16_t magic; + uint8_t type; + uint8_t argc; char argv[NSCTL_MAX_PKT_SZ - 4]; } __attribute__ ((packed)); #define NSCTL_MAX_ARG_SZ 512 struct nsctl_args { - u8 len; + uint8_t len; char value[NSCTL_MAX_ARG_SZ - 1]; } __attribute__ ((packed)); /* parsed packet */ struct nsctl { - u8 type; - u8 argc; + uint8_t type; + uint8_t argc; char *argv[0xff]; }; -int pack_control(char *data, int len, u8 type, int argc, char *argv[]); +int pack_control(char *data, int len, uint8_t type, int argc, char *argv[]); int unpack_control(struct nsctl *packet, char *data, int len); void dump_control(struct nsctl *control, FILE *stream); diff --git a/garden.c b/garden.c index 1fa11b3..bda354b 100644 --- a/garden.c +++ b/garden.c @@ -9,7 +9,7 @@ /* walled garden */ -char const *cvs_id = "$Id: garden.c,v 1.19 2004/12/01 02:52:46 bodea Exp $"; +char const *cvs_id = "$Id: garden.c,v 1.20 2004/12/16 08:49:53 bodea Exp $"; int plugin_api_version = PLUGIN_API_VERSION; static struct pluginfuncs *p = 0; @@ -213,7 +213,7 @@ int garden_session(sessiont *s, int flag) if (flag != F_CLEANUP) { /* OK, we're up! */ - u16 r = p->radiusnew(p->get_id_by_session(s)); + uint16_t r = p->radiusnew(p->get_id_by_session(s)); p->radiussend(r, RADIUSSTART); } } diff --git a/icmp.c b/icmp.c index 0a50c39..c163a69 100644 --- a/icmp.c +++ b/icmp.c @@ -1,6 +1,6 @@ // L2TPNS: icmp -char const *cvs_id_icmp = "$Id: icmp.c,v 1.5 2004/11/16 07:54:32 bodea Exp $"; +char const *cvs_id_icmp = "$Id: icmp.c,v 1.6 2004/12/16 08:49:53 bodea Exp $"; #include #include @@ -17,9 +17,9 @@ char const *cvs_id_icmp = "$Id: icmp.c,v 1.5 2004/11/16 07:54:32 bodea Exp $"; #include "l2tpns.h" -static __u16 _checksum(unsigned char *addr, int count); +static uint16_t _checksum(unsigned char *addr, int count); -void host_unreachable(ipt destination, u16 id, ipt source, char *packet, int packet_len) +void host_unreachable(in_addr_t destination, uint16_t id, in_addr_t source, char *packet, int packet_len) { char buf[128] = {0}; struct iphdr *iph; @@ -60,21 +60,21 @@ void host_unreachable(ipt destination, u16 id, ipt source, char *packet, int pac icmp->type = ICMP_DEST_UNREACH; icmp->code = ICMP_HOST_UNREACH; - icmp->checksum = _checksum((char *)icmp, sizeof(struct icmphdr) + ((packet_len < 64) ? packet_len : 64)); + icmp->checksum = _checksum((char *) icmp, sizeof(struct icmphdr) + ((packet_len < 64) ? packet_len : 64)); - iph->check = _checksum((char *)iph, sizeof(struct iphdr)); + iph->check = _checksum((char *) iph, sizeof(struct iphdr)); sendto(icmp_socket, (char *)buf, len, 0, (struct sockaddr *)&whereto, sizeof(struct sockaddr)); close(icmp_socket); } -static __u16 _checksum(unsigned char *addr, int count) +static uint16_t _checksum(unsigned char *addr, int count) { register long sum = 0; for (; count > 1; count -= 2) { - sum += ntohs(*(u32 *)addr); + sum += ntohs(*(uint32_t *) addr); addr += 2; } @@ -87,5 +87,5 @@ static __u16 _checksum(unsigned char *addr, int count) // one's complement the result sum = ~sum; - return htons((u16) sum); + return htons((uint16_t) sum); } diff --git a/l2tpns.c b/l2tpns.c index 9a49c95..0bf5eb9 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -4,7 +4,7 @@ // Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced // vim: sw=8 ts=8 -char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.69 2004/12/16 03:03:41 bodea Exp $"; +char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.70 2004/12/16 08:49:53 bodea Exp $"; #include #include @@ -64,11 +64,11 @@ int *radfds = NULL; // RADIUS requests file handles int ifrfd = -1; // File descriptor for routing, etc time_t basetime = 0; // base clock char hostname[1000] = ""; // us. -static u32 sessionid = 0; // session id for radius accounting +static uint32_t sessionid = 0; // session id for radius accounting static int syslog_log = 0; // are we logging to syslog static FILE *log_stream = NULL; // file handle for direct logging (i.e. direct into file, not via syslog). extern int cluster_sockfd; // Intra-cluster communications socket. -u32 last_id = 0; // Last used PPP SID. Can I kill this?? -- mo +uint32_t last_id = 0; // Last used PPP SID. Can I kill this?? -- mo struct cli_session_actions *cli_session_actions = NULL; // Pending session changes requested by CLI struct cli_tunnel_actions *cli_tunnel_actions = NULL; // Pending tunnel changes required by CLI @@ -76,11 +76,11 @@ struct cli_tunnel_actions *cli_tunnel_actions = NULL; // Pending tunnel changes static void *ip_hash[256]; // Mapping from IP address to session structures. // Traffic counters. -static u32 udp_rx = 0, udp_rx_pkt = 0, udp_tx = 0; -static u32 eth_rx = 0, eth_rx_pkt = 0; -u32 eth_tx = 0; +static uint32_t udp_rx = 0, udp_rx_pkt = 0, udp_tx = 0; +static uint32_t eth_rx = 0, eth_rx_pkt = 0; +uint32_t eth_tx = 0; -static u32 ip_pool_size = 1; // Size of the pool of addresses used for dynamic address allocation. +static uint32_t ip_pool_size = 1; // Size of the pool of addresses used for dynamic address allocation. time_t time_now = 0; // Current time in seconds since epoch. static char time_now_string[64] = {0}; // Current time as a string. static char main_quit = 0; // True if we're in the process of exiting. @@ -157,8 +157,8 @@ struct Tstats *_statistics = NULL; struct Tringbuffer *ringbuffer = NULL; #endif -static void cache_ipmap(ipt ip, int s); -static void uncache_ipmap(ipt ip); +static void cache_ipmap(in_addr_t ip, int s); +static void uncache_ipmap(in_addr_t ip); static void free_ip_address(sessionidt s); static void dump_acct_info(int all); static void sighup_handler(int sig); @@ -168,16 +168,16 @@ static void sigquit_handler(int sig); static void sigchild_handler(int sig); static void read_state(void); static void dump_state(void); -static void build_chap_response(char *challenge, u8 id, u16 challenge_length, char **challenge_response); +static void build_chap_response(char *challenge, uint8_t id, uint16_t challenge_length, char **challenge_response); static void update_config(void); static void read_config_file(void); static void initplugins(void); static int add_plugin(char *plugin_name); static int remove_plugin(char *plugin_name); static void plugins_done(void); -static void processcontrol(u8 * buf, int len, struct sockaddr_in *addr, int alen); +static void processcontrol(uint8_t *buf, int len, struct sockaddr_in *addr, int alen); static tunnelidt new_tunnel(void); -static int unhide_avp(u8 *avp, tunnelidt t, sessionidt s, u16 length); +static int unhide_avp(uint8_t *avp, tunnelidt t, sessionidt s, uint16_t length); // return internal time (10ths since process startup) static clockt now(void) @@ -190,7 +190,7 @@ static clockt now(void) // work out a retry time based on try number // This is a straight bounded exponential backoff. // Maximum re-try time is 32 seconds. (2^5). -clockt backoff(u8 try) +clockt backoff(uint8_t try) { if (try > 5) try = 5; // max backoff return now() + 10 * (1 << try); @@ -245,7 +245,7 @@ void _log(int level, sessionidt s, tunnelidt t, const char *format, ...) void _log_hex(int level, const char *title, const char *data, int maxsize) { int i, j; - const u8 *d = (const u8 *)data; + const uint8_t *d = (const uint8_t *) data; if (config->debug < level) return; @@ -302,7 +302,7 @@ void _log_hex(int level, const char *title, const char *data, int maxsize) // // 'ip' and 'mask' must be in _host_ order. // -static void routeset(sessionidt s, ipt ip, ipt mask, ipt gw, u8 add) +static void routeset(sessionidt s, in_addr_t ip, in_addr_t mask, in_addr_t gw, int add) { struct rtentry r; int i; @@ -314,11 +314,11 @@ static void routeset(sessionidt s, ipt ip, ipt mask, ipt gw, u8 add) memset(&r, 0, sizeof(r)); r.rt_dev = config->tundevice; r.rt_dst.sa_family = AF_INET; - *(u32 *) & (((struct sockaddr_in *) &r.rt_dst)->sin_addr.s_addr) = htonl(ip); + *(uint32_t *) & (((struct sockaddr_in *) &r.rt_dst)->sin_addr.s_addr) = htonl(ip); r.rt_gateway.sa_family = AF_INET; - *(u32 *) & (((struct sockaddr_in *) &r.rt_gateway)->sin_addr.s_addr) = htonl(gw); + *(uint32_t *) & (((struct sockaddr_in *) &r.rt_gateway)->sin_addr.s_addr) = htonl(gw); r.rt_genmask.sa_family = AF_INET; - *(u32 *) & (((struct sockaddr_in *) &r.rt_genmask)->sin_addr.s_addr) = htonl(mask); + *(uint32_t *) & (((struct sockaddr_in *) &r.rt_genmask)->sin_addr.s_addr) = htonl(mask); r.rt_flags = (RTF_UP | RTF_STATIC); if (gw) r.rt_flags |= RTF_GATEWAY; @@ -461,27 +461,26 @@ static void initudp(void) // IP address. // -static int lookup_ipmap(ipt ip) +static int lookup_ipmap(in_addr_t ip) { - u8 *a = (u8 *)&ip; - char **d = (char **) ip_hash; - int s; + uint8_t *a = (uint8_t *) &ip; + uint8_t **d = (uint8_t **) ip_hash; - if (!(d = (char **) d[(size_t) *a++])) return 0; - if (!(d = (char **) d[(size_t) *a++])) return 0; - if (!(d = (char **) d[(size_t) *a++])) return 0; + if (!(d = (uint8_t **) d[(size_t) *a++])) return 0; + if (!(d = (uint8_t **) d[(size_t) *a++])) return 0; + if (!(d = (uint8_t **) d[(size_t) *a++])) return 0; - s = (ipt) d[(size_t) *a]; - return s; + return (int) (intptr_t) d[(size_t) *a]; } -sessionidt sessionbyip(ipt ip) +sessionidt sessionbyip(in_addr_t ip) { int s = lookup_ipmap(ip); CSTAT(call_sessionbyip); if (s > 0 && s < MAXSESSION && session[s].tunnel) - return s; + return (sessionidt) s; + return 0; } @@ -491,25 +490,25 @@ sessionidt sessionbyip(ipt ip) // // (It's actually cached in network order) // -static void cache_ipmap(ipt ip, int s) +static void cache_ipmap(in_addr_t ip, int s) { - ipt nip = htonl(ip); // MUST be in network order. I.e. MSB must in be ((char*)(&ip))[0] - u8 *a = (u8 *) &nip; - char **d = (char **) ip_hash; + in_addr_t nip = htonl(ip); // MUST be in network order. I.e. MSB must in be ((char *) (&ip))[0] + uint8_t *a = (uint8_t *) &nip; + uint8_t **d = (uint8_t **) ip_hash; int i; for (i = 0; i < 3; i++) { if (!d[(size_t) a[i]]) { - if (!(d[(size_t) a[i]] = calloc(256, sizeof (void *)))) + if (!(d[(size_t) a[i]] = calloc(256, sizeof(void *)))) return; } - d = (char **) d[(size_t) a[i]]; + d = (uint8_t **) d[(size_t) a[i]]; } - d[(size_t) a[3]] = (char *)((int)s); + d[(size_t) a[3]] = (uint8_t *) (intptr_t) s; if (s > 0) LOG(4, s, session[s].tunnel, "Caching ip address %s\n", fmtaddr(nip, 0)); @@ -519,7 +518,7 @@ static void cache_ipmap(ipt ip, int s) // else a map to an ip pool index. } -static void uncache_ipmap(ipt ip) +static void uncache_ipmap(in_addr_t ip) { cache_ipmap(ip, 0); // Assign it to the NULL session. } @@ -542,22 +541,22 @@ int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc) { if (!d[i]) continue; - e = (char**) d[i]; + e = (char **) d[i]; for (j = 0; j < 256; ++j) { if (!e[j]) continue; - f = (char**) e[j]; + f = (char **) e[j]; for (k = 0; k < 256; ++k) { if (!f[k]) continue; - g = (char**)f[k]; + g = (char **)f[k]; for (l = 0; l < 256; ++l) { if (!g[l]) continue; - cli_print(cli, "%7d %d.%d.%d.%d", (int) g[l], i, j, k, l); + cli_print(cli, "%7d %d.%d.%d.%d", (int) (intptr_t) g[l], i, j, k, l); ++count; } } @@ -591,11 +590,11 @@ sessionidt sessionbyuser(char *username) return 0; // Not found. } -void send_garp(ipt ip) +void send_garp(in_addr_t ip) { int s; struct ifreq ifr; - u8 mac[6]; + uint8_t mac[6]; s = socket(PF_INET, SOCK_DGRAM, 0); if (s < 0) @@ -637,7 +636,7 @@ static sessionidt sessionidtbysessiont(sessiont *s) } // actually send a control message for a specific tunnel -void tunnelsend(u8 * buf, u16 l, tunnelidt t) +void tunnelsend(uint8_t * buf, uint16_t l, tunnelidt t) { struct sockaddr_in addr; @@ -663,11 +662,11 @@ void tunnelsend(u8 * buf, u16 l, tunnelidt t) memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; - *(u32 *) & addr.sin_addr = htonl(tunnel[t].ip); + *(uint32_t *) & addr.sin_addr = htonl(tunnel[t].ip); addr.sin_port = htons(tunnel[t].port); // sequence expected, if sequence in message - if (*buf & 0x08) *(u16 *) (buf + ((*buf & 0x40) ? 10 : 8)) = htons(tunnel[t].nr); + if (*buf & 0x08) *(uint16_t *) (buf + ((*buf & 0x40) ? 10 : 8)) = htons(tunnel[t].nr); // If this is a control message, deal with retries if (*buf & 0x80) @@ -683,7 +682,7 @@ void tunnelsend(u8 * buf, u16 l, tunnelidt t) if (sendto(udpfd, buf, l, 0, (void *) &addr, sizeof(addr)) < 0) { - LOG(0, ntohs((*(u16 *) (buf + 6))), t, "Error sending data out tunnel: %s (udpfd=%d, buf=%p, len=%d, dest=%s)\n", + LOG(0, ntohs((*(uint16_t *) (buf + 6))), t, "Error sending data out tunnel: %s (udpfd=%d, buf=%p, len=%d, dest=%s)\n", strerror(errno), udpfd, buf, l, inet_ntoa(addr.sin_addr)); STAT(tunnel_tx_errors); return; @@ -698,24 +697,24 @@ void tunnelsend(u8 * buf, u16 l, tunnelidt t) // Tiny helper function to write data to // the 'tun' device. // -int tun_write(u8 * data, int size) +int tun_write(uint8_t * data, int size) { return write(tunfd, data, size); } // process outgoing (to tunnel) IP // -static void processipout(u8 * buf, int len) +static void processipout(uint8_t * buf, int len) { sessionidt s; sessiont *sp; tunnelidt t; - ipt ip; + in_addr_t ip; char * data = buf; // Keep a copy of the originals. int size = len; - u8 b[MAXETHER + 20]; + uint8_t b[MAXETHER + 20]; CSTAT(call_processipout); @@ -737,13 +736,13 @@ static void processipout(u8 * buf, int len) len -= 4; // Got an IP header now - if (*(u8 *)(buf) >> 4 != 4) + if (*(uint8_t *)(buf) >> 4 != 4) { LOG(1, 0, 0, "IP: Don't understand anything except IPv4\n"); return; } - ip = *(u32 *)(buf + 16); + ip = *(uint32_t *)(buf + 16); if (!(s = sessionbyip(ip))) { // Is this a packet for a session that doesn't exist? @@ -758,8 +757,8 @@ static void processipout(u8 * buf, int len) if (rate++ < config->icmp_rate) // Only send a max of icmp_rate per second. { - LOG(4, 0, 0, "IP: Sending ICMP host unreachable to %s\n", fmtaddr(*(u32 *)(buf + 12), 0)); - host_unreachable(*(u32 *)(buf + 12), *(u16 *)(buf + 4), ip, buf, (len < 64) ? 64 : len); + LOG(4, 0, 0, "IP: Sending ICMP host unreachable to %s\n", fmtaddr(*(in_addr_t *)(buf + 12), 0)); + host_unreachable(*(in_addr_t *)(buf + 12), *(uint16_t *)(buf + 4), ip, buf, (len < 64) ? 64 : len); } return; } @@ -790,7 +789,7 @@ static void processipout(u8 * buf, int len) // Add on L2TP header { - u8 *p = makeppp(b, sizeof(b), buf, len, t, s, PPPIP); + uint8_t *p = makeppp(b, sizeof(b), buf, len, t, s, PPPIP); if (!p) return; tunnelsend(b, len + (p-b), t); // send it... } @@ -810,13 +809,13 @@ static void processipout(u8 * buf, int len) // Helper routine for the TBF filters. // Used to send queued data in to the user! // -static void send_ipout(sessionidt s, u8 *buf, int len) +static void send_ipout(sessionidt s, uint8_t *buf, int len) { sessiont *sp; tunnelidt t; - ipt ip; + in_addr_t ip; - u8 b[MAXETHER + 20]; + uint8_t b[MAXETHER + 20]; if (len < 0 || len > MAXETHER) { @@ -828,7 +827,7 @@ static void send_ipout(sessionidt s, u8 *buf, int len) buf += 4; len -= 4; - ip = *(u32 *)(buf + 16); + ip = *(in_addr_t *)(buf + 16); if (!session[s].ip) return; @@ -840,7 +839,7 @@ static void send_ipout(sessionidt s, u8 *buf, int len) // Add on L2TP header { - u8 *p = makeppp(b, sizeof(b), buf, len, t, s, PPPIP); + uint8_t *p = makeppp(b, sizeof(b), buf, len, t, s, PPPIP); if (!p) return; tunnelsend(b, len + (p-b), t); // send it... } @@ -857,51 +856,51 @@ static void send_ipout(sessionidt s, u8 *buf, int len) } // add an AVP (16 bit) -static void control16(controlt * c, u16 avp, u16 val, u8 m) +static void control16(controlt * c, uint16_t avp, uint16_t val, uint8_t m) { - u16 l = (m ? 0x8008 : 0x0008); - *(u16 *) (c->buf + c->length + 0) = htons(l); - *(u16 *) (c->buf + c->length + 2) = htons(0); - *(u16 *) (c->buf + c->length + 4) = htons(avp); - *(u16 *) (c->buf + c->length + 6) = htons(val); + uint16_t l = (m ? 0x8008 : 0x0008); + *(uint16_t *) (c->buf + c->length + 0) = htons(l); + *(uint16_t *) (c->buf + c->length + 2) = htons(0); + *(uint16_t *) (c->buf + c->length + 4) = htons(avp); + *(uint16_t *) (c->buf + c->length + 6) = htons(val); c->length += 8; } // add an AVP (32 bit) -static void control32(controlt * c, u16 avp, u32 val, u8 m) +static void control32(controlt * c, uint16_t avp, uint32_t val, uint8_t m) { - u16 l = (m ? 0x800A : 0x000A); - *(u16 *) (c->buf + c->length + 0) = htons(l); - *(u16 *) (c->buf + c->length + 2) = htons(0); - *(u16 *) (c->buf + c->length + 4) = htons(avp); - *(u32 *) (c->buf + c->length + 6) = htonl(val); + uint16_t l = (m ? 0x800A : 0x000A); + *(uint16_t *) (c->buf + c->length + 0) = htons(l); + *(uint16_t *) (c->buf + c->length + 2) = htons(0); + *(uint16_t *) (c->buf + c->length + 4) = htons(avp); + *(uint32_t *) (c->buf + c->length + 6) = htonl(val); c->length += 10; } // add an AVP (32 bit) -static void controls(controlt * c, u16 avp, char *val, u8 m) +static void controls(controlt * c, uint16_t avp, char *val, uint8_t m) { - u16 l = ((m ? 0x8000 : 0) + strlen(val) + 6); - *(u16 *) (c->buf + c->length + 0) = htons(l); - *(u16 *) (c->buf + c->length + 2) = htons(0); - *(u16 *) (c->buf + c->length + 4) = htons(avp); + uint16_t l = ((m ? 0x8000 : 0) + strlen(val) + 6); + *(uint16_t *) (c->buf + c->length + 0) = htons(l); + *(uint16_t *) (c->buf + c->length + 2) = htons(0); + *(uint16_t *) (c->buf + c->length + 4) = htons(avp); memcpy(c->buf + c->length + 6, val, strlen(val)); c->length += 6 + strlen(val); } // add a binary AVP -static void controlb(controlt * c, u16 avp, char *val, unsigned int len, u8 m) +static void controlb(controlt * c, uint16_t avp, char *val, unsigned int len, uint8_t m) { - u16 l = ((m ? 0x8000 : 0) + len + 6); - *(u16 *) (c->buf + c->length + 0) = htons(l); - *(u16 *) (c->buf + c->length + 2) = htons(0); - *(u16 *) (c->buf + c->length + 4) = htons(avp); + uint16_t l = ((m ? 0x8000 : 0) + len + 6); + *(uint16_t *) (c->buf + c->length + 0) = htons(l); + *(uint16_t *) (c->buf + c->length + 2) = htons(0); + *(uint16_t *) (c->buf + c->length + 4) = htons(avp); memcpy(c->buf + c->length + 6, val, len); c->length += 6 + len; } // new control connection -static controlt *controlnew(u16 mtype) +static controlt *controlnew(uint16_t mtype) { controlt *c; if (!controlfree) @@ -913,7 +912,7 @@ static controlt *controlnew(u16 mtype) } assert(c); c->next = 0; - *(u16 *) (c->buf + 0) = htons(0xC802); // flags/ver + *(uint16_t *) (c->buf + 0) = htons(0xC802); // flags/ver c->length = 12; control16(c, 0, mtype, 1); return c; @@ -923,26 +922,26 @@ static controlt *controlnew(u16 mtype) // (ZLB send). static void controlnull(tunnelidt t) { - u8 buf[12]; + uint8_t buf[12]; if (tunnel[t].controlc) // Messages queued; They will carry the ack. return; - *(u16 *) (buf + 0) = htons(0xC802); // flags/ver - *(u16 *) (buf + 2) = htons(12); // length - *(u16 *) (buf + 4) = htons(tunnel[t].far); // tunnel - *(u16 *) (buf + 6) = htons(0); // session - *(u16 *) (buf + 8) = htons(tunnel[t].ns); // sequence - *(u16 *) (buf + 10) = htons(tunnel[t].nr); // sequence + *(uint16_t *) (buf + 0) = htons(0xC802); // flags/ver + *(uint16_t *) (buf + 2) = htons(12); // length + *(uint16_t *) (buf + 4) = htons(tunnel[t].far); // tunnel + *(uint16_t *) (buf + 6) = htons(0); // session + *(uint16_t *) (buf + 8) = htons(tunnel[t].ns); // sequence + *(uint16_t *) (buf + 10) = htons(tunnel[t].nr); // sequence tunnelsend(buf, 12, t); } // add a control message to a tunnel, and send if within window static void controladd(controlt * c, tunnelidt t, sessionidt s) { - *(u16 *) (c->buf + 2) = htons(c->length); // length - *(u16 *) (c->buf + 4) = htons(tunnel[t].far); // tunnel - *(u16 *) (c->buf + 6) = htons(s ? session[s].far : 0); // session - *(u16 *) (c->buf + 8) = htons(tunnel[t].ns); // sequence + *(uint16_t *) (c->buf + 2) = htons(c->length); // length + *(uint16_t *) (c->buf + 4) = htons(tunnel[t].far); // tunnel + *(uint16_t *) (c->buf + 6) = htons(s ? session[s].far : 0); // session + *(uint16_t *) (c->buf + 8) = htons(tunnel[t].ns); // sequence tunnel[t].ns++; // advance sequence // link in message in to queue if (tunnel[t].controlc) @@ -1070,7 +1069,7 @@ void sessionshutdown(sessionidt s, char *reason) if (session[s].opened && !walled_garden && !session[s].die) { // RADIUS Stop message - u16 r = session[s].radius; + uint16_t r = session[s].radius; if (!r) { if (!(r = radiusnew(s))) @@ -1139,9 +1138,9 @@ void sessionshutdown(sessionidt s, char *reason) void sendipcp(tunnelidt t, sessionidt s) { - u8 buf[MAXCONTROL]; - u16 r = session[s].radius; - u8 *q; + uint8_t buf[MAXCONTROL]; + uint16_t r = session[s].radius; + uint8_t *q; CSTAT(call_sendipcp); @@ -1167,12 +1166,12 @@ void sendipcp(tunnelidt t, sessionidt s) *q = ConfigReq; q[1] = r << RADIUS_SHIFT; // ID, dont care, we only send one type of request - *(u16 *) (q + 2) = htons(10); + *(uint16_t *) (q + 2) = htons(10); q[4] = 3; q[5] = 6; - *(u32 *) (q + 6) = config->peer_address ? config->peer_address : - config->bind_address ? config->bind_address : - my_address; // send my IP + *(in_addr_t *) (q + 6) = config->peer_address ? config->peer_address : + config->bind_address ? config->bind_address : + my_address; // send my IP tunnelsend(buf, 10 + (q - buf), t); // send it session[s].flags &= ~SF_IPCP_ACKED; // Clear flag. @@ -1270,11 +1269,11 @@ static void tunnelshutdown(tunnelidt t, char *reason) } // read and process packet on tunnel (UDP) -void processudp(u8 * buf, int len, struct sockaddr_in *addr) +void processudp(uint8_t * buf, int len, struct sockaddr_in *addr) { char *chapresponse = NULL; - u16 l = len, t = 0, s = 0, ns = 0, nr = 0; - u8 *p = buf + 2; + uint16_t l = len, t = 0, s = 0, ns = 0, nr = 0; + uint8_t *p = buf + 2; CSTAT(call_processudp); @@ -1298,12 +1297,12 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } if (*buf & 0x40) { // length - l = ntohs(*(u16 *) p); + l = ntohs(*(uint16_t *) p); p += 2; } - t = ntohs(*(u16 *) p); + t = ntohs(*(uint16_t *) p); p += 2; - s = ntohs(*(u16 *) p); + s = ntohs(*(uint16_t *) p); p += 2; if (s >= MAXSESSION) { @@ -1319,36 +1318,36 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } if (*buf & 0x08) { // ns/nr - ns = ntohs(*(u16 *) p); + ns = ntohs(*(uint16_t *) p); p += 2; - nr = ntohs(*(u16 *) p); + nr = ntohs(*(uint16_t *) p); p += 2; } if (*buf & 0x02) { // offset - u16 o = ntohs(*(u16 *) p); + uint16_t o = ntohs(*(uint16_t *) p); p += o + 2; } if ((p - buf) > l) { - LOG(1, s, t, "Bad length %d>%d\n", (p - buf), l); + LOG(1, s, t, "Bad length %d>%d\n", (int) (p - buf), l); STAT(tunnel_rx_errors); return; } l -= (p - buf); if (*buf & 0x80) { // control - u16 message = 0xFFFF; // message type - u8 fatal = 0; - u8 mandatorymessage = 0; - u8 chap = 0; // if CHAP being used - u16 asession = 0; // assigned session - u32 amagic = 0; // magic number - u8 aflags = 0; // flags from last LCF - u16 version = 0x0100; // protocol version (we handle 0.0 as well and send that back just in case) - int requestchap = 0; // do we request PAP instead of original CHAP request? - char called[MAXTEL] = ""; // called number - char calling[MAXTEL] = ""; // calling number + uint16_t message = 0xFFFF; // message type + uint8_t fatal = 0; + uint8_t mandatorymessage = 0; + uint8_t chap = 0; // if CHAP being used + uint16_t asession = 0; // assigned session + uint32_t amagic = 0; // magic number + uint8_t aflags = 0; // flags from last LCF + uint16_t version = 0x0100; // protocol version (we handle 0.0 as well and send that back just in case) + int requestchap = 0; // do we request PAP instead of original CHAP request? + char called[MAXTEL] = ""; // called number + char calling[MAXTEL] = ""; // calling number if (!config->cluster_iam_master) { @@ -1374,7 +1373,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) for (i = 1; i <= config->cluster_highest_tunnelid ; ++i) { if (tunnel[i].state != TUNNELOPENING || - tunnel[i].ip != ntohl(*(ipt *) & addr->sin_addr) || + tunnel[i].ip != ntohl(*(in_addr_t *) & addr->sin_addr) || tunnel[i].port != ntohs(addr->sin_port) ) continue; t = i; @@ -1396,7 +1395,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) return; } tunnelclear(t); - tunnel[t].ip = ntohl(*(ipt *) & addr->sin_addr); + tunnel[t].ip = ntohl(*(in_addr_t *) & addr->sin_addr); tunnel[t].port = ntohs(addr->sin_port); tunnel[t].window = 4; // default window STAT(tunnel_created); @@ -1469,10 +1468,10 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) // process AVPs while (l && !(fatal & 0x80)) { - u16 n = (ntohs(*(u16 *) p) & 0x3FF); - u8 *b = p; - u8 flags = *p; - u16 mtype; + uint16_t n = (ntohs(*(uint16_t *) p) & 0x3FF); + uint8_t *b = p; + uint8_t flags = *p; + uint16_t mtype; p += n; // next if (l < n) { @@ -1513,14 +1512,14 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) continue; // next } b += 2; - if (*(u16 *) (b)) + if (*(uint16_t *) (b)) { - LOG(2, s, t, "Unknown AVP vendor %d\n", ntohs(*(u16 *) (b))); + LOG(2, s, t, "Unknown AVP vendor %d\n", ntohs(*(uint16_t *) (b))); fatal = flags; continue; // next } b += 2; - mtype = ntohs(*(u16 *) (b)); + mtype = ntohs(*(uint16_t *) (b)); b += 2; n -= 6; @@ -1528,13 +1527,13 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) switch (mtype) { case 0: // message type - message = ntohs(*(u16 *) b); + message = ntohs(*(uint16_t *) b); LOG(4, s, t, " Message type = %d (%s)\n", *b, l2tp_message_types[message]); mandatorymessage = flags; break; case 1: // result code { - u16 rescode = ntohs(*(u16 *)(b)); + uint16_t rescode = ntohs(*(uint16_t *) b); const char* resdesc = "(unknown)"; if (message == 4) { /* StopCCN */ @@ -1550,7 +1549,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) LOG(4, s, t, " Result Code %d: %s\n", rescode, resdesc); if (n >= 4) { - u16 errcode = ntohs(*(u16 *)(b + 2)); + uint16_t errcode = ntohs(*(uint16_t *)(b + 2)); const char* errdesc = "(unknown)"; if (errcode <= MAX_ERROR_CODE) errdesc = error_codes[errcode]; @@ -1564,7 +1563,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) break; case 2: // protocol version { - version = ntohs(*(u16 *) (b)); + version = ntohs(*(uint16_t *) (b)); LOG(4, s, t, " Protocol version = %d\n", version); if (version && version != 0x0100) { // allow 0.0 and 1.0 @@ -1599,11 +1598,11 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) LOG(4, s, t, " Vendor name = \"%s\"\n", tunnel[t].vendor); break; case 9: // assigned tunnel - tunnel[t].far = ntohs(*(u16 *) (b)); + tunnel[t].far = ntohs(*(uint16_t *) (b)); LOG(4, s, t, " Remote tunnel id = %d\n", tunnel[t].far); break; case 10: // rx window - tunnel[t].window = ntohs(*(u16 *) (b)); + tunnel[t].window = ntohs(*(uint16_t *) (b)); if (!tunnel[t].window) tunnel[t].window = 1; // window of 0 is silly LOG(4, s, t, " rx window = %d\n", tunnel[t].window); @@ -1620,18 +1619,18 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) break; case 14: // assigned session - asession = session[s].far = ntohs(*(u16 *) (b)); + asession = session[s].far = ntohs(*(uint16_t *) (b)); LOG(4, s, t, " assigned session = %d\n", asession); break; case 15: // call serial number - LOG(4, s, t, " call serial number = %d\n", ntohl(*(u32 *)b)); + LOG(4, s, t, " call serial number = %d\n", ntohl(*(uint32_t *)b)); break; case 18: // bearer type - LOG(4, s, t, " bearer type = %d\n", ntohl(*(u32 *)b)); + LOG(4, s, t, " bearer type = %d\n", ntohl(*(uint32_t *)b)); // TBA - for RADIUS break; case 19: // framing type - LOG(4, s, t, " framing type = %d\n", ntohl(*(u32 *)b)); + LOG(4, s, t, " framing type = %d\n", ntohl(*(uint32_t *)b)); // TBA break; case 21: // called number @@ -1649,7 +1648,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) case 24: // tx connect speed if (n == 4) { - session[s].tx_connect_speed = ntohl(*(u32 *)b); + session[s].tx_connect_speed = ntohl(*(uint32_t *)b); } else { @@ -1663,7 +1662,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) case 38: // rx connect speed if (n == 4) { - session[s].rx_connect_speed = ntohl(*(u32 *)b); + session[s].rx_connect_speed = ntohl(*(uint32_t *)b); } else { @@ -1676,13 +1675,13 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) break; case 25: // Physical Channel ID { - u32 tmp = ntohl(*(u32 *)b); + uint32_t tmp = ntohl(*(uint32_t *) b); LOG(4, s, t, " Physical Channel ID <%X>\n", tmp); break; } case 29: // Proxy Authentication Type { - u16 authtype = ntohs(*(u16 *)b); + uint16_t authtype = ntohs(*(uint16_t *)b); LOG(4, s, t, " Proxy Auth Type %d (%s)\n", authtype, authtypes[authtype]); requestchap = (authtype == 2); break; @@ -1703,7 +1702,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } case 32: // Proxy Authentication ID { - u16 authid = ntohs(*(u16 *)(b)); + uint16_t authid = ntohs(*(uint16_t *)(b)); LOG(4, s, t, " Proxy Auth ID (%d)\n", authid); if (session[s].radius) radius[session[s].radius].id = authid; @@ -1718,12 +1717,12 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } case 27: // last send lcp { // find magic number - u8 *p = b, *e = p + n; + uint8_t *p = b, *e = p + n; while (p + 1 < e && p[1] && p + p[1] <= e) { if (*p == 5 && p[1] == 6) // Magic-Number - amagic = ntohl(*(u32 *) (p + 2)); - else if (*p == 3 && p[1] == 5 && *(u16 *) (p + 2) == htons(PPPCHAP) && p[4] == 5) // Authentication-Protocol + amagic = ntohl(*(uint32_t *) (p + 2)); + else if (*p == 3 && p[1] == 5 && *(uint16_t *) (p + 2) == htons(PPPCHAP) && p[4] == 5) // Authentication-Protocol chap = 1; else if (*p == 7) // Protocol-Field-Compression aflags |= SESSIONPFC; @@ -1801,7 +1800,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } else { - u16 r; + uint16_t r; controlt *c; s = sessionfree; @@ -1878,7 +1877,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } else { // data - u16 prot; + uint16_t prot; LOG_HEX(5, "Receive Tunnel Data", p, l); if (l > 2 && p[0] == 0xFF && p[1] == 0x03) @@ -1899,7 +1898,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } else { - prot = ntohs(*(u16 *) p); + prot = ntohs(*(uint16_t *) p); p += 2; l -= 2; } @@ -1977,7 +1976,7 @@ void processudp(u8 * buf, int len, struct sockaddr_in *addr) } // read and process packet on tun -static void processtun(u8 * buf, int len) +static void processtun(uint8_t * buf, int len) { LOG_HEX(5, "Receive TUN Data", buf, len); STAT(tun_rx_packets); @@ -1994,7 +1993,7 @@ static void processtun(u8 * buf, int len) return; } - if (*(u16 *) (buf + 2) == htons(PKTIP)) // IP + if (*(uint16_t *) (buf + 2) == htons(PKTIP)) // IP processipout(buf, len); // Else discard. } @@ -2010,7 +2009,7 @@ static int regular_cleanups(void) static sessionidt s = 0; // Next session to check for actions on. tunnelidt t; int count=0,i; - u16 r; + uint16_t r; static clockt next_acct = 0; static clockt next_shut_acct = 0; int a; @@ -2044,7 +2043,7 @@ static int regular_cleanups(void) if (tunnel[t].retry <= TIME) { controlt *c = tunnel[t].controls; - u8 w = tunnel[t].window; + uint8_t w = tunnel[t].window; tunnel[t].try++; // another try if (tunnel[t].try > 5) tunnelkill(t, "Timeout on control message"); // game over @@ -2114,15 +2113,15 @@ static int regular_cleanups(void) // No data in IDLE_TIMEOUT seconds, send LCP ECHO if (session[s].user[0] && (time_now - session[s].last_packet >= ECHO_TIMEOUT)) { - u8 b[MAXCONTROL] = {0}; + uint8_t b[MAXCONTROL] = {0}; - u8 *q = makeppp(b, sizeof(b), 0, 0, session[s].tunnel, s, PPPLCP); + uint8_t *q = makeppp(b, sizeof(b), 0, 0, session[s].tunnel, s, PPPLCP); if (!q) continue; *q = EchoReq; - *(u8 *)(q + 1) = (time_now % 255); // ID - *(u16 *)(q + 2) = htons(8); // Length - *(u32 *)(q + 4) = 0; // Magic Number (not supported) + *(uint8_t *)(q + 1) = (time_now % 255); // ID + *(uint16_t *)(q + 2) = htons(8); // Length + *(uint32_t *)(q + 4) = 0; // Magic Number (not supported) LOG(4, s, session[s].tunnel, "No data in %d seconds, sending LCP ECHO\n", (int)(time_now - session[s].last_packet)); @@ -2283,7 +2282,7 @@ static int readset_n = 0; static void mainloop(void) { int i; - u8 buf[65536]; + uint8_t buf[65536]; struct timeval to; clockt next_cluster_ping = 0; // send initial ping immediately time_t next_clean = time_now + config->cleanup_interval; @@ -2362,6 +2361,9 @@ static void mainloop(void) { struct sockaddr_in addr; int alen, c, s; + int udp_pkts = 0; + int tun_pkts = 0; + int cluster_pkts = 0; // nsctl commands if (FD_ISSET(controlfd, &r)) @@ -2421,6 +2423,7 @@ static void mainloop(void) if ((s = recvfrom(udpfd, buf, sizeof(buf), 0, (void *) &addr, &alen)) > 0) { processudp(buf, s, &addr); + udp_pkts++; } else { @@ -2435,6 +2438,7 @@ static void mainloop(void) if ((s = read(tunfd, buf, sizeof(buf))) > 0) { processtun(buf, s); + tun_pkts++; } else { @@ -2450,6 +2454,7 @@ static void mainloop(void) if ((s = recvfrom(cluster_sockfd, buf, sizeof(buf), MSG_WAITALL, (void *) &addr, &alen)) > 0) { processcluster(buf, s, addr.sin_addr.s_addr); + cluster_pkts++; } else { @@ -2458,6 +2463,10 @@ static void mainloop(void) } } } + + if (c >= config->multi_read_count) + LOG(3, 0, 0, "Reached multi_read_count (%d); processed %d udp, %d tun and %d cluster packets\n", + udp_pkts, tun_pkts, cluster_pkts); } // Runs on every machine (master and slaves). @@ -2705,7 +2714,7 @@ memset(ip_filters, 0, sizeof(ip_filtert) * MAXFILTER); static int assign_ip_address(sessionidt s) { - u32 i; + uint32_t i; int best = -1; time_t best_time = time_now; char *u = session[s].user; @@ -2866,7 +2875,7 @@ static void fix_address_pool(int sid) // // Add a block of addresses to the IP pool to hand out. // -static void add_to_ip_pool(u32 addr, u32 mask) +static void add_to_ip_pool(in_addr_t addr, in_addr_t mask) { int i; if (mask == 0) @@ -2917,7 +2926,7 @@ static void initippool() if ((p = (char *)strrchr(buf, '\n'))) *p = 0; if ((p = (char *)strchr(buf, ':'))) { - ipt src; + in_addr_t src; *p = '\0'; src = inet_addr(buf); if (src == INADDR_NONE) @@ -2935,7 +2944,7 @@ static void initippool() { // It's a range int numbits = 0; - u32 start = 0, mask = 0; + in_addr_t start = 0, mask = 0; LOG(2, 0, 0, "Adding IP address range %s\n", buf); *p++ = 0; @@ -2945,7 +2954,7 @@ static void initippool() continue; } start = ntohl(inet_addr(pool)); - mask = (u32)(pow(2, numbits) - 1) << (32 - numbits); + mask = (in_addr_t) (pow(2, numbits) - 1) << (32 - numbits); // Add a static route for this pool LOG(5, 0, 0, "Adding route for address pool %s/%u\n", @@ -2965,7 +2974,7 @@ static void initippool() LOG(1, 0, 0, "IP address pool is %d addresses\n", ip_pool_size - 1); } -void snoop_send_packet(char *packet, u16 size, ipt destination, u16 port) +void snoop_send_packet(char *packet, uint16_t size, in_addr_t destination, uint16_t port) { struct sockaddr_in snoop_addr = {0}; if (!destination || !port || snoopfd <= 0 || size <= 0 || !packet) @@ -3021,8 +3030,8 @@ static int dump_session(FILE **f, sessiont *s) s->user, // username fmtaddr(htonl(s->ip), 0), // ip (s->throttle_in || s->throttle_out) ? 2 : 1, // qos - (u32) s->cin, // uptxoctets - (u32) s->cout); // downrxoctets + (uint32_t) s->cin, // uptxoctets + (uint32_t) s->cout); // downrxoctets s->pin = s->cin = 0; s->pout = s->cout = 0; @@ -3308,7 +3317,7 @@ static void read_state() ippoolt itmp; FILE *f; char magic[sizeof(DUMP_MAGIC) - 1]; - u32 buf[2]; + uint32_t buf[2]; if (!config->save_state) { @@ -3429,7 +3438,7 @@ static void read_state() static void dump_state() { FILE *f; - u32 buf[2]; + uint32_t buf[2]; if (!config->save_state) return; @@ -3477,7 +3486,7 @@ static void dump_state() unlink(STATEFILE); } -static void build_chap_response(char *challenge, u8 id, u16 challenge_length, char **challenge_response) +static void build_chap_response(char *challenge, uint8_t id, uint16_t challenge_length, char **challenge_response) { MD5_CTX ctx; *challenge_response = NULL; @@ -3672,7 +3681,7 @@ static void read_config_file() int sessionsetup(tunnelidt t, sessionidt s) { // A session now exists, set it up - ipt ip; + in_addr_t ip; char *user; sessionidt i; int r; @@ -3881,8 +3890,8 @@ int load_session(sessionidt s, sessiont *new) // for walking the sessions to forward byte counts to the master. config->cluster_highest_sessionid = s; - // TEMP: old session struct used a u32 to define the throttle - // speed for both up/down, new uses a u16 for each. Deal with + // TEMP: old session struct used a uint32_t to define the throttle + // speed for both up/down, new uses a uint16_t for each. Deal with // sessions from an old master for migration. if (new->throttle_out == 0 && new->tbf_out) new->throttle_out = new->throttle_in; @@ -4071,7 +4080,7 @@ static void plugins_done() run_plugin_done(p); } -static void processcontrol(u8 * buf, int len, struct sockaddr_in *addr, int alen) +static void processcontrol(uint8_t * buf, int len, struct sockaddr_in *addr, int alen) { struct nsctl request; struct nsctl response; @@ -4383,16 +4392,16 @@ int cmd_show_hist_open(struct cli_def *cli, char *command, char **argv, int argc * * Based on code from rp-l2tpd by Roaring Penguin Software Inc. */ -static int unhide_avp(u8 *avp, tunnelidt t, sessionidt s, u16 length) +static int unhide_avp(uint8_t *avp, tunnelidt t, sessionidt s, uint16_t length) { MD5_CTX ctx; - u8 *cursor; - u8 digest[16]; - u8 working_vector[16]; + uint8_t *cursor; + uint8_t digest[16]; + uint8_t working_vector[16]; uint16_t hidden_length; - u8 type[2]; + uint8_t type[2]; size_t done, todo; - u8 *output; + uint8_t *output; // Find the AVP type. type[0] = *(avp + 4); @@ -4447,7 +4456,7 @@ static int unhide_avp(u8 *avp, tunnelidt t, sessionidt s, u16 length) return hidden_length + 6; } -static int ip_filter_port(ip_filter_portt *p, portt port) +static int ip_filter_port(ip_filter_portt *p, uint16_t port) { switch (p->op) { @@ -4461,7 +4470,7 @@ static int ip_filter_port(ip_filter_portt *p, portt port) return 0; } -static int ip_filter_flag(u8 op, u8 sflags, u8 cflags, u8 flags) +static int ip_filter_flag(uint8_t op, uint8_t sflags, uint8_t cflags, uint8_t flags) { switch (op) { @@ -4478,15 +4487,15 @@ static int ip_filter_flag(u8 op, u8 sflags, u8 cflags, u8 flags) return 0; } -int ip_filter(u8 *buf, int len, u8 filter) +int ip_filter(uint8_t *buf, int len, uint8_t filter) { - u16 frag_offset; - u8 proto; - ipt src_ip; - ipt dst_ip; - portt src_port = 0; - portt dst_port = 0; - u8 flags = 0; + uint16_t frag_offset; + uint8_t proto; + in_addr_t src_ip; + in_addr_t dst_ip; + uint16_t src_port = 0; + uint16_t dst_port = 0; + uint8_t flags = 0; ip_filter_rulet *rule; if (len < 20) // up to end of destination address @@ -4495,10 +4504,10 @@ int ip_filter(u8 *buf, int len, u8 filter) if ((*buf >> 4) != 4) // IPv4 return 0; - frag_offset = ntohs(*(u16 *) (buf + 6)) & 0x1fff; + frag_offset = ntohs(*(uint16_t *) (buf + 6)) & 0x1fff; proto = buf[9]; - src_ip = *(u32 *) (buf + 12); - dst_ip = *(u32 *) (buf + 16); + src_ip = *(in_addr_t *) (buf + 12); + dst_ip = *(in_addr_t *) (buf + 16); if (frag_offset == 0 && (proto == IPPROTO_TCP || proto == IPPROTO_UDP)) { @@ -4506,8 +4515,8 @@ int ip_filter(u8 *buf, int len, u8 filter) if (len < l + 4) // ports return 0; - src_port = ntohs(*(u16 *) (buf + l)); - dst_port = ntohs(*(u16 *) (buf + l + 2)); + src_port = ntohs(*(uint16_t *) (buf + l)); + dst_port = ntohs(*(uint16_t *) (buf + l + 2)); if (proto == IPPROTO_TCP) { if (len < l + 14) // flags diff --git a/l2tpns.h b/l2tpns.h index 7ba879e..db96836 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -1,5 +1,5 @@ // L2TPNS Global Stuff -// $Id: l2tpns.h,v 1.46 2004/12/13 02:27:31 bodea Exp $ +// $Id: l2tpns.h,v 1.47 2004/12/16 08:49:53 bodea Exp $ #ifndef __L2TPNS_H__ #define __L2TPNS_H__ @@ -108,22 +108,16 @@ enum }; // Types -typedef unsigned short u16; -typedef unsigned int u32; -typedef unsigned long long u64; -typedef unsigned char u8; -typedef u32 ipt; -typedef u16 portt; -typedef u16 sessionidt; -typedef u16 tunnelidt; -typedef u32 clockt; -typedef u8 hasht[16]; +typedef uint16_t sessionidt; +typedef uint16_t tunnelidt; +typedef uint32_t clockt; +typedef uint8_t hasht[16]; // CLI actions struct cli_session_actions { char action; - ipt snoop_ip; - u16 snoop_port; + in_addr_t snoop_ip; + uint16_t snoop_port; int throttle_in; int throttle_out; int filter_in; @@ -150,16 +144,16 @@ struct cli_tunnel_actions { // structures typedef struct // route { - ipt ip; - ipt mask; + in_addr_t ip; + in_addr_t mask; } routet; -typedef struct controls // control message +typedef struct controls // control message { - struct controls *next; // next in queue - u16 length; // length - u8 buf[MAXCONTROL]; + struct controls *next; // next in queue + uint16_t length; // length + uint8_t buf[MAXCONTROL]; } controlt; @@ -168,45 +162,45 @@ typedef struct sessionidt next; // next session in linked list sessionidt far; // far end session ID tunnelidt tunnel; // near end tunnel ID - ipt ip; // IP of session set by RADIUS response (host byte order). + in_addr_t ip; // IP of session set by RADIUS response (host byte order). int ip_pool_index; // index to IP pool unsigned long unique_id; // unique session id - u16 nr; // next receive - u16 ns; // next send - u32 magic; // ppp magic number - u32 cin, cout; // byte counts - u32 pin, pout; // packet counts - u32 total_cin; // This counter is never reset while a session is open - u32 total_cout; // This counter is never reset while a session is open - u32 id; // session id - u16 throttle_in; // upstream throttle rate (kbps) - u16 throttle_out; // downstream throttle rate + uint16_t nr; // next receive + uint16_t ns; // next send + uint32_t magic; // ppp magic number + uint32_t cin, cout; // byte counts + uint32_t pin, pout; // packet counts + uint32_t total_cin; // This counter is never reset while a session is open + uint32_t total_cout; // This counter is never reset while a session is open + uint32_t id; // session id + uint16_t throttle_in; // upstream throttle rate (kbps) + uint16_t throttle_out; // downstream throttle rate clockt opened; // when started clockt die; // being closed, when to finally free time_t last_packet; // Last packet from the user (used for idle timeouts) - ipt dns1, dns2; // DNS servers + in_addr_t dns1, dns2; // DNS servers routet route[MAXROUTE]; // static routes - u16 radius; // which radius session is being used (0 for not waiting on authentication) - u16 mru; // maximum receive unit - u16 tbf_in; // filter bucket for throttling in from the user. - u16 tbf_out; // filter bucket for throttling out to the user. - u8 l2tp_flags; // various bit flags from the ICCN on the l2tp tunnel. - u8 reserved_old_snoop; // No longer used - remove at some time - u8 walled_garden; // is this session gardened? - u8 flags1; // additional flags (currently unused); + uint16_t radius; // which radius session is being used (0 for not waiting on authentication) + uint16_t mru; // maximum receive unit + uint16_t tbf_in; // filter bucket for throttling in from the user. + uint16_t tbf_out; // filter bucket for throttling out to the user. + uint8_t l2tp_flags; // various bit flags from the ICCN on the l2tp tunnel. + uint8_t reserved_old_snoop; // No longer used - remove at some time + uint8_t walled_garden; // is this session gardened? + uint8_t flags1; // additional flags (currently unused); char random_vector[MAXTEL]; int random_vector_length; char user[129]; // user (needed in seesion for radius stop messages) (can we reduce this? --mo) char called[MAXTEL]; // called number char calling[MAXTEL]; // calling number - u32 tx_connect_speed; - u32 rx_connect_speed; - u32 flags; // Various session flags. - ipt snoop_ip; // Interception destination IP - u16 snoop_port; // Interception destination port - u16 sid; // near end session id. - u8 filter_in; // input filter index (to ip_filters[N-1]; 0 if none) - u8 filter_out; // output filter index + uint32_t tx_connect_speed; + uint32_t rx_connect_speed; + uint32_t flags; // Various session flags. + in_addr_t snoop_ip; // Interception destination IP + uint16_t snoop_port; // Interception destination port + uint16_t sid; // near end session id. + uint8_t filter_in; // input filter index (to ip_filters[N-1]; 0 if none) + uint8_t filter_out; // output filter index char reserved[18]; // Space to expand structure without changing HB_VERSION } sessiont; @@ -217,8 +211,8 @@ sessiont; typedef struct { - u32 cin; - u32 cout; + uint32_t cin; + uint32_t cout; } sessioncountt; #define SESSIONPFC 1 // PFC negotiated flags @@ -228,11 +222,11 @@ typedef struct typedef struct { tunnelidt far; // far end tunnel ID - ipt ip; // Ip for far end - portt port; // port for far end - u16 window; // Rx window - u16 nr; // next receive - u16 ns; // next send + in_addr_t ip; // Ip for far end + uint16_t port; // port for far end + uint16_t window; // Rx window + uint16_t nr; // next receive + uint16_t ns; // next send int state; // current state (tunnelstate enum) clockt last; // when last control message sent (used for resend timeout) clockt retry; // when to try resenting pending control @@ -240,8 +234,8 @@ typedef struct clockt lastrec; // when the last control message was received char hostname[128]; // tunnel hostname char vendor[128]; // LAC vendor - u8 try; // number of retrys on a control message - u16 controlc; // outstaind messages in queue + uint8_t try; // number of retrys on a control message + uint16_t controlc; // outstaind messages in queue controlt *controls; // oldest message controlt *controle; // newest message } @@ -255,16 +249,16 @@ typedef struct // outstanding RADIUS requests clockt retry; // when to try next char calling[MAXTEL]; // calling number char pass[129]; // password - u8 id; // ID for PPP response - u8 try; // which try we are on - u8 state; // state of radius requests - u8 chap; // set if CHAP used (is CHAP identifier) + uint8_t id; // ID for PPP response + uint8_t try; // which try we are on + uint8_t state; // state of radius requests + uint8_t chap; // set if CHAP used (is CHAP identifier) } radiust; typedef struct { - ipt address; // Host byte order.. + in_addr_t address; // Host byte order.. char assigned; // 1 if assigned, 0 if free sessionidt session; clockt last; // last used @@ -423,20 +417,20 @@ typedef struct char radiussecret[64]; int radius_accounting; - ipt radiusserver[MAXRADSERVER]; // radius servers - u16 radiusport[MAXRADSERVER]; // radius base ports - u8 numradiusservers; // radius server count + in_addr_t radiusserver[MAXRADSERVER]; // radius servers + uint16_t radiusport[MAXRADSERVER]; // radius base ports + uint8_t numradiusservers; // radius server count short num_radfds; // Number of radius filehandles allocated - ipt default_dns1, default_dns2; + in_addr_t default_dns1, default_dns2; unsigned long rl_rate; // default throttle rate int num_tbfs; // number of throttle buckets int save_state; char accounting_dir[128]; - ipt bind_address; - ipt peer_address; + in_addr_t bind_address; + in_addr_t peer_address; int send_garp; // Set to true to garp for vip address on startup int target_uid; @@ -449,12 +443,12 @@ typedef struct int lock_pages; // Lock pages into memory. int icmp_rate; // Max number of ICMP unreachable per second to send> - u32 cluster_address; // Multicast address of cluster. + in_addr_t cluster_address; // Multicast address of cluster. // Send to this address to have everyone hear. char cluster_interface[64]; // Which interface to listen for multicast on. int cluster_iam_master; // Are we the cluster master??? int cluster_iam_uptodate; // Set if we've got a full set of state from the master. - u32 cluster_master_address; // The network address of the cluster master. + in_addr_t cluster_master_address; // The network address of the cluster master. // Zero if i am the cluster master. int cluster_seq_number; // Sequence number of the next heartbeat we'll send out // (or the seq number we're next expecting if we're a slave). @@ -467,17 +461,17 @@ typedef struct int cluster_hb_interval; // How often to send a heartbeat. int cluster_hb_timeout; // How many missed heartbeats trigger an election. - u64 cluster_table_version; // # state changes processed by cluster + uint64_t cluster_table_version; // # state changes processed by cluster #ifdef BGP #define BGP_NUM_PEERS 2 - u16 as_number; + uint16_t as_number; struct { - char name[64]; - u16 as; - int keepalive; - int hold; - } neighbour[BGP_NUM_PEERS]; + char name[64]; + uint16_t as; + int keepalive; + int hold; + } neighbour[BGP_NUM_PEERS]; #endif } configt; @@ -492,15 +486,15 @@ typedef struct typedef struct { - u8 op; // operation + uint8_t op; // operation #define FILTER_PORT_OP_NONE 0 // all ports match #define FILTER_PORT_OP_EQ 1 #define FILTER_PORT_OP_NEQ 2 #define FILTER_PORT_OP_GT 3 #define FILTER_PORT_OP_LT 4 #define FILTER_PORT_OP_RANGE 5 - portt port; // port (host byte order) - portt port2; // range + uint16_t port; // port (host byte order) + uint16_t port2; // range } ip_filter_portt; typedef struct @@ -508,21 +502,21 @@ typedef struct int action; // permit/deny #define FILTER_ACTION_DENY 1 #define FILTER_ACTION_PERMIT 2 - u8 proto; // protocol: IPPROTO_* (netinet/in.h) - ipt src_ip; // source ip (network byte order) - ipt src_wild; + uint8_t proto; // protocol: IPPROTO_* (netinet/in.h) + in_addr_t src_ip; // source ip (network byte order) + in_addr_t src_wild; ip_filter_portt src_ports; - ipt dst_ip; // dest ip - ipt dst_wild; + in_addr_t dst_ip; // dest ip + in_addr_t dst_wild; ip_filter_portt dst_ports; - u8 frag; // apply to non-initial fragments - u8 tcp_flag_op; // match type: any, all, established + uint8_t frag; // apply to non-initial fragments + uint8_t tcp_flag_op; // match type: any, all, established #define FILTER_FLAG_OP_ANY 1 #define FILTER_FLAG_OP_ALL 2 #define FILTER_FLAG_OP_EST 3 - u8 tcp_sflags; // flags set - u8 tcp_cflags; // flags clear - u32 counter; // match count + uint8_t tcp_sflags; // flags set + uint8_t tcp_cflags; // flags clear + uint32_t counter; // match count } ip_filter_rulet; #define TCP_FLAG_FIN 0x01 @@ -543,42 +537,42 @@ typedef struct } ip_filtert; // arp.c -void sendarp(int ifr_idx, const unsigned char* mac, ipt ip); +void sendarp(int ifr_idx, const unsigned char* mac, in_addr_t ip); // ppp.c -void processpap(tunnelidt t, sessionidt s, u8 * p, u16 l); -void processchap(tunnelidt t, sessionidt s, u8 * p, u16 l); -void processlcp(tunnelidt t, sessionidt s, u8 * p, u16 l); -void processipcp(tunnelidt t, sessionidt s, u8 * p, u16 l); -void processipin(tunnelidt t, sessionidt s, u8 * p, u16 l); -void processccp(tunnelidt t, sessionidt s, u8 * p, u16 l); +void processpap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l); +void processchap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l); +void processlcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l); +void processipcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l); +void processipin(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l); +void processccp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l); void sendchap(tunnelidt t, sessionidt s); -u8 *makeppp(u8 * b, int size, u8 * p, int l, tunnelidt t, sessionidt s, u16 mtype); +uint8_t *makeppp(uint8_t *b, int size, uint8_t *p, int l, tunnelidt t, sessionidt s, uint16_t mtype); void initlcp(tunnelidt t, sessionidt s); -void send_ipin(sessionidt s, u8 * buf, int len); +void send_ipin(sessionidt s, uint8_t *buf, int len); // radius.c void initrad(void); -void radiussend(u16 r, u8 state); -void processrad(u8 *buf, int len, char socket_index); -void radiusretry(u16 r); -u16 radiusnew(sessionidt s); -void radiusclear(u16 r, sessionidt s); +void radiussend(uint16_t r, uint8_t state); +void processrad(uint8_t *buf, int len, char socket_index); +void radiusretry(uint16_t r); +uint16_t radiusnew(sessionidt s); +void radiusclear(uint16_t r, sessionidt s); // l2tpns.c -clockt backoff(u8 try); -sessionidt sessionbyip(ipt ip); +clockt backoff(uint8_t try); +sessionidt sessionbyip(in_addr_t ip); sessionidt sessionbyuser(char *username); void sessionshutdown(sessionidt s, char *reason); -void send_garp(ipt ip); -void tunnelsend(u8 * buf, u16 l, tunnelidt t); +void send_garp(in_addr_t ip); +void tunnelsend(uint8_t *buf, uint16_t l, tunnelidt t); void sendipcp(tunnelidt t, sessionidt s); -void processudp(u8 * buf, int len, struct sockaddr_in *addr); -void snoop_send_packet(char *packet, u16 size, ipt destination, u16 port); -int ip_filter(u8 *buf, int len, u8 filter); +void processudp(uint8_t *buf, int len, struct sockaddr_in *addr); +void snoop_send_packet(char *packet, uint16_t size, in_addr_t destination, uint16_t port); +int ip_filter(uint8_t *buf, int len, uint8_t filter); int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc); int cmd_show_hist_idle(struct cli_def *cli, char *command, char **argv, int argc); int cmd_show_hist_open(struct cli_def *cli, char *command, char **argv, int argc); @@ -607,7 +601,7 @@ int cli_arg_help(struct cli_def *cli, int cr_ok, char *entry, ...); // icmp.c -void host_unreachable(ipt destination, u16 id, ipt source, char *packet, int packet_len); +void host_unreachable(in_addr_t destination, uint16_t id, in_addr_t source, char *packet, int packet_len); extern tunnelt *tunnel; @@ -635,10 +629,10 @@ if (count++ < max) { \ extern configt *config; extern time_t basetime; // Time when this process started. extern time_t time_now; // Seconds since EPOCH. -extern u32 last_id; +extern uint32_t last_id; extern struct Tstats *_statistics; -extern ipt my_address; -extern int tun_write(u8 *data, int size); +extern in_addr_t my_address; +extern int tun_write(uint8_t *data, int size); extern int clifd; diff --git a/l2tpns.spec b/l2tpns.spec index 36f5fa9..8c70aa0 100644 --- a/l2tpns.spec +++ b/l2tpns.spec @@ -43,5 +43,5 @@ rm -rf %{buildroot} %attr(644,root,root) /usr/share/man/man[58]/* %changelog -* Mon Dec 13 2004 Brendan O'Dea 2.0.13-1 +* Thu Dec 16 2004 Brendan O'Dea 2.0.13-1 - 2.0.13 release, see /usr/share/doc/l2tpns-2.0.13/Changes diff --git a/plugin.h b/plugin.h index 8e151be..ca0368f 100644 --- a/plugin.h +++ b/plugin.h @@ -28,12 +28,12 @@ struct pluginfuncs { void (*log)(int level, sessionidt s, tunnelidt t, const char *format, ...); void (*log_hex)(int level, const char *title, const char *data, int maxsize); - char *(*fmtaddr)(ipt addr, int n); + char *(*fmtaddr)(in_addr_t addr, int n); sessionidt (*get_session_by_username)(char *username); sessiont *(*get_session_by_id)(sessionidt s); sessionidt (*get_id_by_session)(sessiont *s); - u16 (*radiusnew)(sessionidt s); - void (*radiussend)(u16 r, u8 state); + uint16_t (*radiusnew)(sessionidt s); + void (*radiussend)(uint16_t r, uint8_t state); void *(*getconfig)(char *key, enum config_typet type); void (*sessionkill)(sessionidt s, char *reason); void (*throttle)(sessionidt s, int rate_in, int rate_out); diff --git a/ppp.c b/ppp.c index e71be55..e627cda 100644 --- a/ppp.c +++ b/ppp.c @@ -1,6 +1,6 @@ // L2TPNS PPP Stuff -char const *cvs_id_ppp = "$Id: ppp.c,v 1.38 2004/11/30 19:34:57 bodea Exp $"; +char const *cvs_id_ppp = "$Id: ppp.c,v 1.39 2004/12/16 08:49:53 bodea Exp $"; #include #include @@ -19,18 +19,18 @@ extern sessiont *session; extern radiust *radius; extern int tunfd; extern char hostname[]; -extern u32 eth_tx; +extern uint32_t eth_tx; extern time_t time_now; extern configt *config; static void initccp(tunnelidt t, sessionidt s); // Process PAP messages -void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l) +void processpap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l) { char user[129]; char pass[129]; - u16 hl; + uint16_t hl; CSTAT(call_processpap); @@ -42,7 +42,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l) return ; } - if ((hl = ntohs(*(u16 *) (p + 2))) > l) + if ((hl = ntohs(*(uint16_t *) (p + 2))) > l) { LOG(1, s, t, "Length mismatch PAP %u/%u\n", hl, l); STAT(tunnel_rx_errors); @@ -58,7 +58,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l) } { - u8 *b = p; + uint8_t *b = p; b += 4; if (*b && *b < sizeof(user)) memcpy(user, b + 1, *b); @@ -72,18 +72,18 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l) if (session[s].ip || !session[s].radius) { // respond now, either no RADIUS available or already authenticated - u8 b[MAXCONTROL]; - u8 id = p[1]; - u8 *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP); + uint8_t b[MAXCONTROL]; + uint8_t id = p[1]; + uint8_t *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP); if (!p) return; if (session[s].ip) - *p = 2; // ACK + *p = 2; // ACK else - *p = 3; // cant authorise + *p = 3; // cant authorise p[1] = id; - *(u16 *) (p + 2) = htons(5); // length - p[4] = 0; // no message + *(uint16_t *) (p + 2) = htons(5); // length + p[4] = 0; // no message if (session[s].ip) { LOG(3, s, t, "Already an IP allocated: %s (%d)\n", @@ -101,7 +101,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l) else { // set up RADIUS request - u16 r = session[s].radius; + uint16_t r = session[s].radius; // Run PRE_AUTH plugins struct param_pre_auth packet = { &tunnel[t], &session[s], strdup(user), strdup(pass), PPPPAP, 1 }; @@ -127,10 +127,10 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l) } // Process CHAP messages -void processchap(tunnelidt t, sessionidt s, u8 *p, u16 l) +void processchap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l) { - u16 r; - u16 hl; + uint16_t r; + uint16_t hl; CSTAT(call_processchap); @@ -153,7 +153,7 @@ void processchap(tunnelidt t, sessionidt s, u8 *p, u16 l) return ; } - if ((hl = ntohs(*(u16 *) (p + 2))) > l) + if ((hl = ntohs(*(uint16_t *) (p + 2))) > l) { LOG(1, s, t, "Length mismatch CHAP %u/%u\n", hl, l); STAT(tunnel_rx_errors); @@ -240,13 +240,13 @@ static char *ppp_lcp_types[] = { "IdentRequest", }; -static void dumplcp(u8 *p, int l) +static void dumplcp(uint8_t *p, int l) { int x = l - 4; - u8 *o = (p + 4); + uint8_t *o = (p + 4); LOG_HEX(5, "PPP LCP Packet", p, l); - LOG(4, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p, ppp_lcp_types[(int)*p], ntohs( ((u16 *) p)[1]) ); + LOG(4, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p, ppp_lcp_types[(int)*p], ntohs( ((uint16_t *) p)[1]) ); LOG(4, 0, 0, "Length: %d\n", l); if (*p != ConfigReq && *p != ConfigRej && *p != ConfigAck) return; @@ -271,14 +271,14 @@ static void dumplcp(u8 *p, int l) { case 1: // Maximum-Receive-Unit if (length == 4) - LOG(4, 0, 0, " %s %d\n", lcp_types[type], ntohs(*(u16 *)(o + 2))); + LOG(4, 0, 0, " %s %d\n", lcp_types[type], ntohs(*(uint16_t *)(o + 2))); else LOG(4, 0, 0, " %s odd length %d\n", lcp_types[type], length); break; case 2: // Async-Control-Character-Map if (length == 6) { - u32 asyncmap = ntohl(*(u32 *)(o + 2)); + uint32_t asyncmap = ntohl(*(uint32_t *)(o + 2)); LOG(4, 0, 0, " %s %x\n", lcp_types[type], asyncmap); } else @@ -287,7 +287,7 @@ static void dumplcp(u8 *p, int l) case 3: // Authentication-Protocol if (length == 4) { - int proto = ntohs(*(u16 *)(o + 2)); + int proto = ntohs(*(uint16_t *)(o + 2)); LOG(4, 0, 0, " %s 0x%x (%s)\n", lcp_types[type], proto, proto == PPPCHAP ? "CHAP" : proto == PPPPAP ? "PAP" : "UNKNOWN"); @@ -297,14 +297,14 @@ static void dumplcp(u8 *p, int l) break; case 4: // Quality-Protocol { - u32 qp = ntohl(*(u32 *)(o + 2)); + uint32_t qp = ntohl(*(uint32_t *)(o + 2)); LOG(4, 0, 0, " %s %x\n", lcp_types[type], qp); } break; case 5: // Magic-Number if (length == 6) { - u32 magicno = ntohl(*(u32 *)(o + 2)); + uint32_t magicno = ntohl(*(uint32_t *)(o + 2)); LOG(4, 0, 0, " %s %x\n", lcp_types[type], magicno); } else @@ -324,12 +324,12 @@ static void dumplcp(u8 *p, int l) } // Process LCP messages -void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) +void processlcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l) { - u8 b[MAXCONTROL]; - u8 *q = NULL; - u32 magicno = 0; - u16 hl; + uint8_t b[MAXCONTROL]; + uint8_t *q = NULL; + uint32_t magicno = 0; + uint16_t hl; CSTAT(call_processlcp); @@ -341,7 +341,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) return ; } - if ((hl = ntohs(*(u16 *) (p + 2))) > l) + if ((hl = ntohs(*(uint16_t *) (p + 2))) > l) { LOG(1, s, t, "Length mismatch LCP %u/%u\n", hl, l); STAT(tunnel_rx_errors); @@ -357,8 +357,8 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) else if (*p == ConfigReq) { int x = l - 4; - u8 *o = (p + 4); - u8 *response = 0; + uint8_t *o = (p + 4); + uint8_t *response = 0; LOG(3, s, t, "LCP: ConfigReq (%d bytes)...\n", l); if (config->debug > 3) dumplcp(p, l); @@ -372,11 +372,11 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) switch (type) { case 1: // Maximum-Receive-Unit - session[s].mru = ntohs(*(u16 *)(o + 2)); + session[s].mru = ntohs(*(uint16_t *)(o + 2)); break; case 2: // Async-Control-Character-Map - if (!ntohl(*(u32 *)(o + 2))) // all bits zero is OK + if (!ntohl(*(uint32_t *)(o + 2))) // all bits zero is OK break; if (response && *response != ConfigNak) // rej already queued @@ -401,12 +401,12 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) *q++ = 6; memset(q, 0, 4); // asyncmap 0 q += 4; - *((u16 *) (response + 2)) = htons(q - response); // LCP header length + *((uint16_t *) (response + 2)) = htons(q - response); // LCP header length break; case 3: // Authentication-Protocol { - int proto = ntohs(*(u16 *)(o + 2)); + int proto = ntohs(*(uint16_t *)(o + 2)); char proto_name[] = "0x0000"; if (proto == PPPPAP) break; @@ -436,14 +436,14 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) } memcpy(q, o, length); - *(u16 *)(q += 2) = htons(PPPPAP); // NAK -> Use PAP instead + *(uint16_t *)(q += 2) = htons(PPPPAP); // NAK -> Use PAP instead q += length; - *((u16 *) (response + 2)) = htons(q - response); + *((uint16_t *) (response + 2)) = htons(q - response); } break; case 5: // Magic-Number - magicno = ntohl(*(u32 *)(o + 2)); + magicno = ntohl(*(uint32_t *)(o + 2)); break; case 4: // Quality-Protocol @@ -469,7 +469,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) memcpy(q, o, length); q += length; - *((u16 *) (response + 2)) = htons(q - response); // LCP header length + *((uint16_t *) (response + 2)) = htons(q - response); // LCP header length } x -= length; o += length; @@ -512,7 +512,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) { LOG(5, s, t, "LCP: Received EchoReq. Sending EchoReply\n"); *p = EchoReply; // reply - *(u32 *) (p + 4) = htonl(session[s].magic); // our magic number + *(uint32_t *) (p + 4) = htonl(session[s].magic); // our magic number q = makeppp(b, sizeof(b), p, l, t, s, PPPLCP); if (!q) return; tunnelsend(b, l + (q - b), t); // send it @@ -543,9 +543,9 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l) } // find a PPP option, returns point to option, or 0 if not found -static u8 *findppp(u8 *b, u8 mtype) +static uint8_t *findppp(uint8_t *b, uint8_t mtype) { - u16 l = ntohs(*(u16 *) (b + 2)); + uint16_t l = ntohs(*(uint16_t *) (b + 2)); if (l < 4) return 0; b += 4; @@ -563,9 +563,9 @@ static u8 *findppp(u8 *b, u8 mtype) } // Process IPCP messages -void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) +void processipcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l) { - u16 hl; + uint16_t hl; CSTAT(call_processipcp); @@ -577,7 +577,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) return ; } - if ((hl = ntohs(*(u16 *) (p + 2))) > l) + if ((hl = ntohs(*(uint16_t *) (p + 2))) > l) { LOG(1, s, t, "Length mismatch IPCP %u/%u\n", hl, l); STAT(tunnel_rx_errors); @@ -588,7 +588,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) if (*p == ConfigAck) { // happy with our IPCP - u16 r = session[s].radius; + uint16_t r = session[s].radius; if ((!r || radius[r].state == RADIUSIPCP) && !session[s].walled_garden) { if (!r) @@ -620,9 +620,8 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) } // form a config reply quoting the IP in the session { - u8 b[MAXCONTROL]; - u8 *i, - *q; + uint8_t b[MAXCONTROL]; + uint8_t *i, *q; q = p + 4; i = p + l; @@ -635,7 +634,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) if (q < i) { // reject - u16 n = 4; + uint16_t n = 4; i = p + l; if (!(q = makeppp(b, sizeof(b), p, l, t, s, PPPIPCP))) return; @@ -652,7 +651,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) } p += p[1]; } - *(u16 *) (q + 2) = htons(n); + *(uint16_t *) (q + 2) = htons(n); LOG(4, s, t, "Sending ConfigRej\n"); tunnelsend(b, n + (q - b), t); // send it } @@ -662,9 +661,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) *p = ConfigAck; if ((i = findppp(p, 0x81))) // Primary DNS address { - if (*(u32 *) (i + 2) != htonl(session[s].dns1)) + if (*(uint32_t *) (i + 2) != htonl(session[s].dns1)) { - *(u32 *) (i + 2) = htonl(session[s].dns1); + *(uint32_t *) (i + 2) = htonl(session[s].dns1); *p = ConfigNak; LOG(5, s, t, " DNS1 = %s\n", fmtaddr(htonl(session[s].dns1), 0)); @@ -672,9 +671,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) } if ((i = findppp(p, 0x83))) // Secondary DNS address (TBA, is it) { - if (*(u32 *) (i + 2) != htonl(session[s].dns2)) + if (*(uint32_t *) (i + 2) != htonl(session[s].dns2)) { - *(u32 *) (i + 2) = htonl(session[s].dns2); + *(uint32_t *) (i + 2) = htonl(session[s].dns2); *p = ConfigNak; LOG(5, s, t, " DNS2 = %s\n", fmtaddr(htonl(session[s].dns2), 0)); @@ -687,9 +686,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) STAT(tunnel_rx_errors); return ; } - if (*(u32 *) (i + 2) != htonl(session[s].ip)) + if (*(uint32_t *) (i + 2) != htonl(session[s].ip)) { - *(u32 *) (i + 2) = htonl(session[s].ip); + *(uint32_t *) (i + 2) = htonl(session[s].ip); *p = ConfigNak; LOG(4, s, t, " No, a ConfigNak, client is requesting IP - sending %s\n", fmtaddr(htonl(session[s].ip), 0)); @@ -706,15 +705,15 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l) // // This MUST be called with at least 4 byte behind 'p'. // (i.e. this routine writes to p[-4]). -void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l) +void processipin(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l) { - ipt ip; + in_addr_t ip; CSTAT(call_processipin); LOG_HEX(5, "IP", p, l); - ip = ntohl(*(u32 *)(p + 12)); + ip = ntohl(*(uint32_t *)(p + 12)); if (l > MAXETHER) { @@ -736,7 +735,7 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l) // Add on the tun header p -= 4; - *(u32 *)p = htonl(0x00000800); + *(uint32_t *) p = htonl(0x00000800); l += 4; if (session[s].tbf_in && !config->cluster_iam_master) { // Are we throttled and a slave? @@ -780,7 +779,7 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l) // Helper routine for the TBF filters. // Used to send queued data in from the user. // -void send_ipin(sessionidt s, u8 *buf, int len) +void send_ipin(sessionidt s, uint8_t *buf, int len) { LOG_HEX(5, "IP in throttled", buf, len); @@ -813,10 +812,10 @@ void send_ipin(sessionidt s, u8 *buf, int len) // Process CCP messages -void processccp(tunnelidt t, sessionidt s, u8 *p, u16 l) +void processccp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l) { - u8 b[MAXCONTROL]; - u8 *q; + uint8_t b[MAXCONTROL]; + uint8_t *q; CSTAT(call_processccp); @@ -866,9 +865,9 @@ void processccp(tunnelidt t, sessionidt s, u8 *p, u16 l) // send a CHAP PP packet void sendchap(tunnelidt t, sessionidt s) { - u8 b[MAXCONTROL]; - u16 r = session[s].radius; - u8 *q; + uint8_t b[MAXCONTROL]; + uint16_t r = session[s].radius; + uint8_t *q; CSTAT(call_sendchap); @@ -905,14 +904,14 @@ void sendchap(tunnelidt t, sessionidt s) q[4] = 16; // length memcpy(q + 5, radius[r].auth, 16); // challenge strcpy(q + 21, hostname); // our name - *(u16 *) (q + 2) = htons(strlen(hostname) + 21); // length + *(uint16_t *) (q + 2) = htons(strlen(hostname) + 21); // length tunnelsend(b, strlen(hostname) + 21 + (q - b), t); // send it } // fill in a L2TP message with a PPP frame, // copies existing PPP message and changes magic number if seen // returns start of PPP frame -u8 *makeppp(u8 *b, int size, u8 *p, int l, tunnelidt t, sessionidt s, u16 mtype) +uint8_t *makeppp(uint8_t *b, int size, uint8_t *p, int l, tunnelidt t, sessionidt s, uint16_t mtype) { if (size < 12) // Need more space than this!! { @@ -922,20 +921,20 @@ u8 *makeppp(u8 *b, int size, u8 *p, int l, tunnelidt t, sessionidt s, u16 mtype) return NULL; } - *(u16 *) (b + 0) = htons(0x0002); // L2TP with no options - *(u16 *) (b + 2) = htons(tunnel[t].far); // tunnel - *(u16 *) (b + 4) = htons(session[s].far); // session + *(uint16_t *) (b + 0) = htons(0x0002); // L2TP with no options + *(uint16_t *) (b + 2) = htons(tunnel[t].far); // tunnel + *(uint16_t *) (b + 4) = htons(session[s].far); // session b += 6; if (mtype == PPPLCP || !(session[s].l2tp_flags & SESSIONACFC)) { - *(u16 *) b = htons(0xFF03); // HDLC header + *(uint16_t *) b = htons(0xFF03); // HDLC header b += 2; } if (mtype < 0x100 && session[s].l2tp_flags & SESSIONPFC) *b++ = mtype; else { - *(u16 *) b = htons(mtype); + *(uint16_t *) b = htons(mtype); b += 2; } @@ -963,14 +962,14 @@ void initlcp(tunnelidt t, sessionidt s) LOG(4, s, t, "Sending LCP ConfigReq for PAP\n"); *q = ConfigReq; - *(u8 *)(q + 1) = (time_now % 255) + 1; // ID - *(u16 *)(q + 2) = htons(14); // Length - *(u8 *)(q + 4) = 5; - *(u8 *)(q + 5) = 6; - *(u32 *)(q + 6) = htonl(session[s].magic); - *(u8 *)(q + 10) = 3; - *(u8 *)(q + 11) = 4; - *(u16 *)(q + 12) = htons(PPPPAP); // PAP + *(uint8_t *)(q + 1) = (time_now % 255) + 1; // ID + *(uint16_t *)(q + 2) = htons(14); // Length + *(uint8_t *)(q + 4) = 5; + *(uint8_t *)(q + 5) = 6; + *(uint32_t *)(q + 6) = htonl(session[s].magic); + *(uint8_t *)(q + 10) = 3; + *(uint8_t *)(q + 11) = 4; + *(uint16_t *)(q + 12) = htons(PPPPAP); // PAP LOG_HEX(5, "PPPLCP", q, 14); tunnelsend(b, (q - b) + 14, t); @@ -986,8 +985,8 @@ static void initccp(tunnelidt t, sessionidt s) LOG(4, s, t, "Sending CCP ConfigReq for no compression\n"); *q = ConfigReq; - *(u8 *)(q + 1) = (time_now % 255) + 1; // ID - *(u16 *)(q + 2) = htons(4); // Length + *(uint8_t *)(q + 1) = (time_now % 255) + 1; // ID + *(uint16_t *)(q + 2) = htons(4); // Length LOG_HEX(5, "PPPCCP", q, 4); tunnelsend(b, (q - b) + 4 , t); diff --git a/radius.c b/radius.c index 735ae07..76c8a2e 100644 --- a/radius.c +++ b/radius.c @@ -1,6 +1,6 @@ // L2TPNS Radius Stuff -char const *cvs_id_radius = "$Id: radius.c,v 1.19 2004/11/30 06:50:26 bodea Exp $"; +char const *cvs_id_radius = "$Id: radius.c,v 1.20 2004/12/16 08:49:53 bodea Exp $"; #include #include @@ -21,7 +21,6 @@ char const *cvs_id_radius = "$Id: radius.c,v 1.19 2004/11/30 06:50:26 bodea Exp extern radiust *radius; extern sessiont *session; extern tunnelt *tunnel; -extern u32 sessionid; extern configt *config; extern int *radfds; extern ip_filtert *ip_filters; @@ -53,17 +52,17 @@ void initrad(void) } } -void radiusclear(u16 r, sessionidt s) +void radiusclear(uint16_t r, sessionidt s) { if (s) session[s].radius = 0; memset(&radius[r], 0, sizeof(radius[r])); // radius[r].state = RADIUSNULL; } -static u16 get_free_radius() +static uint16_t get_free_radius() { int count; - static u32 next_radius_id = 0; + static uint32_t next_radius_id = 0; for (count = MAXRADIUS; count > 0 ; --count) { @@ -81,9 +80,9 @@ static u16 get_free_radius() return 0; } -u16 radiusnew(sessionidt s) +uint16_t radiusnew(sessionidt s) { - u16 r = session[s].radius; + uint16_t r = session[s].radius; /* re-use */ if (r) @@ -110,13 +109,13 @@ u16 radiusnew(sessionidt s) } // Send a RADIUS request -void radiussend(u16 r, u8 state) +void radiussend(uint16_t r, uint8_t state) { struct sockaddr_in addr; - u8 b[4096]; // RADIUS packet + uint8_t b[4096]; // RADIUS packet char pass[129]; int pl; - u8 *p; + uint8_t *p; sessionidt s; CSTAT(call_radiussend); @@ -246,7 +245,7 @@ void radiussend(u16 r, u8 state) { // accounting *p = 40; // accounting type p[1] = 6; - *(u32 *) (p + 2) = htonl((state == RADIUSSTART) ? 1 : 2); + *(uint32_t *) (p + 2) = htonl((state == RADIUSSTART) ? 1 : 2); p += p[1]; if (s) { @@ -258,30 +257,30 @@ void radiussend(u16 r, u8 state) { // stop *p = 42; // input octets p[1] = 6; - *(u32 *) (p + 2) = htonl(session[s].cin); + *(uint32_t *) (p + 2) = htonl(session[s].cin); p += p[1]; *p = 43; // output octets p[1] = 6; - *(u32 *) (p + 2) = htonl(session[s].cout); + *(uint32_t *) (p + 2) = htonl(session[s].cout); p += p[1]; *p = 46; // session time p[1] = 6; - *(u32 *) (p + 2) = htonl(time(NULL) - session[s].opened); + *(uint32_t *) (p + 2) = htonl(time(NULL) - session[s].opened); p += p[1]; *p = 47; // input packets p[1] = 6; - *(u32 *) (p + 2) = htonl(session[s].pin); + *(uint32_t *) (p + 2) = htonl(session[s].pin); p += p[1]; *p = 48; // output spackets p[1] = 6; - *(u32 *) (p + 2) = htonl(session[s].pout); + *(uint32_t *) (p + 2) = htonl(session[s].pout); p += p[1]; } else { // start *p = 41; // delay p[1] = 6; - *(u32 *) (p + 2) = htonl(time(NULL) - session[s].opened); + *(uint32_t *) (p + 2) = htonl(time(NULL) - session[s].opened); p += p[1]; } } @@ -290,14 +289,14 @@ void radiussend(u16 r, u8 state) { *p = 5; // NAS-Port p[1] = 6; - *(u32 *) (p + 2) = htonl(s); + *(uint32_t *) (p + 2) = htonl(s); p += p[1]; } if (s && session[s].ip) { *p = 8; // Framed-IP-Address p[1] = 6; - *(u32 *) (p + 2) = htonl(session[s].ip); + *(uint32_t *) (p + 2) = htonl(session[s].ip); p += p[1]; } if (*session[s].called) @@ -324,11 +323,11 @@ void radiussend(u16 r, u8 state) // NAS-IP-Address *p = 4; p[1] = 6; - *(u32 *)(p + 2) = config->bind_address; + *(uint32_t *)(p + 2) = config->bind_address; p += p[1]; // All AVpairs added - *(u16 *) (b + 2) = htons(p - b); + *(uint16_t *) (b + 2) = htons(p - b); if (state != RADIUSAUTH) { // Build auth for accounting packet @@ -346,14 +345,14 @@ void radiussend(u16 r, u8 state) } memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; - *(u32 *) & addr.sin_addr = config->radiusserver[(radius[r].try - 1) % config->numradiusservers]; + *(uint32_t *) & addr.sin_addr = config->radiusserver[(radius[r].try - 1) % config->numradiusservers]; { - // get radius port - u16 port = config->radiusport[(radius[r].try - 1) % config->numradiusservers]; - // no need to define the accounting port for itself: - // the accounting port is as far as I know always one more - // than the auth port JK 20040713 - addr.sin_port = htons((state == RADIUSAUTH) ? port : port+1); + // get radius port + uint16_t port = config->radiusport[(radius[r].try - 1) % config->numradiusservers]; + // no need to define the accounting port for itself: + // the accounting port is as far as I know always one more + // than the auth port JK 20040713 + addr.sin_port = htons((state == RADIUSAUTH) ? port : port+1); } LOG_HEX(5, "RADIUS Send", b, (p - b)); @@ -361,15 +360,15 @@ void radiussend(u16 r, u8 state) } // process RADIUS response -void processrad(u8 *buf, int len, char socket_index) +void processrad(uint8_t *buf, int len, char socket_index) { - u8 b[MAXCONTROL]; + uint8_t b[MAXCONTROL]; MD5_CTX ctx; - u16 r; + uint16_t r; sessionidt s; tunnelidt t = 0; hasht hash; - u8 routes = 0; + uint8_t routes = 0; int r_code, r_id ; // Radius code. @@ -380,12 +379,12 @@ void processrad(u8 *buf, int len, char socket_index) CSTAT(call_processrad); LOG_HEX(5, "RADIUS Response", buf, len); - if (len < 20 || len < ntohs(*(u16 *) (buf + 2))) + if (len < 20 || len < ntohs(*(uint16_t *) (buf + 2))) { LOG(1, 0, 0, "Duff RADIUS response length %d\n", len); return ; } - len = ntohs(*(u16 *) (buf + 2)); + len = ntohs(*(uint16_t *) (buf + 2)); r = socket_index | (r_id << RADIUS_SHIFT); s = radius[r].session; LOG(3, s, session[s].tunnel, "Received %s, radius %d response for session %u (code %d, id %d)\n", @@ -427,7 +426,7 @@ void processrad(u8 *buf, int len, char socket_index) if (radius[r].chap) { // CHAP - u8 *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPCHAP); + uint8_t *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPCHAP); if (!p) return; // Abort! { @@ -440,13 +439,13 @@ void processrad(u8 *buf, int len, char socket_index) (*buf == 2) ? "allowed" : "denied"); *p = (*buf == 2) ? 3 : 4; // ack/nak p[1] = radius[r].id; - *(u16 *) (p + 2) = ntohs(4); // no message + *(uint16_t *) (p + 2) = ntohs(4); // no message tunnelsend(b, (p - b) + 4, t); // send it } else { // PAP - u8 *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP); + uint8_t *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP); if (!p) return; // Abort! { @@ -460,7 +459,7 @@ void processrad(u8 *buf, int len, char socket_index) // ack/nak *p = *buf; p[1] = radius[r].id; - *(u16 *) (p + 2) = ntohs(5); + *(uint16_t *) (p + 2) = ntohs(5); p[4] = 0; // no message tunnelsend(b, (p - b) + 5, t); // send it } @@ -469,15 +468,15 @@ void processrad(u8 *buf, int len, char socket_index) { // Login successful // Extract IP, routes, etc - u8 *p = buf + 20; - u8 *e = buf + len; + uint8_t *p = buf + 20; + uint8_t *e = buf + len; for (; p + 2 <= e && p[1] && p + p[1] <= e; p += p[1]) { if (*p == 8) { // Framed-IP-Address if (p[1] < 6) continue; - session[s].ip = ntohl(*(u32 *) (p + 2)); + session[s].ip = ntohl(*(uint32_t *) (p + 2)); session[s].ip_pool_index = -1; LOG(3, s, session[s].tunnel, " Radius reply contains IP address %s\n", fmtaddr(htonl(session[s].ip), 0)); @@ -486,7 +485,7 @@ void processrad(u8 *buf, int len, char socket_index) { // DNS address if (p[1] < 6) continue; - session[s].dns1 = ntohl(*(u32 *) (p + 2)); + session[s].dns1 = ntohl(*(uint32_t *) (p + 2)); LOG(3, s, session[s].tunnel, " Radius reply contains primary DNS address %s\n", fmtaddr(htonl(session[s].dns1), 0)); } @@ -494,18 +493,18 @@ void processrad(u8 *buf, int len, char socket_index) { // DNS address if (p[1] < 6) continue; - session[s].dns2 = ntohl(*(u32 *) (p + 2)); + session[s].dns2 = ntohl(*(uint32_t *) (p + 2)); LOG(3, s, session[s].tunnel, " Radius reply contains secondary DNS address %s\n", fmtaddr(htonl(session[s].dns2), 0)); } else if (*p == 22) { // Framed-Route - ipt ip = 0, mask = 0; - u8 u = 0; - u8 bits = 0; - u8 *n = p + 2; - u8 *e = p + p[1]; + in_addr_t ip = 0, mask = 0; + uint8_t u = 0; + uint8_t bits = 0; + uint8_t *n = p + 2; + uint8_t *e = p + p[1]; while (n < e && (isdigit(*n) || *n == '.')) { if (*n == '.') @@ -552,7 +551,7 @@ void processrad(u8 *buf, int len, char socket_index) char *filter = p + 2; int l = p[1] - 2; char *suffix; - u8 *f = 0; + uint8_t *f = 0; int i; LOG(3, s, session[s].tunnel, " Radius reply contains Filter-Id \"%.*s\"\n", l, filter); @@ -667,7 +666,7 @@ void processrad(u8 *buf, int len, char socket_index) } // Send a retry for RADIUS/CHAP message -void radiusretry(u16 r) +void radiusretry(uint16_t r) { sessionidt s = radius[r].session; tunnelidt t = 0; diff --git a/snoopctl.c b/snoopctl.c index 7c49e86..8afcbe1 100644 --- a/snoopctl.c +++ b/snoopctl.c @@ -5,7 +5,7 @@ /* snoop control */ -char const *cvs_id = "$Id: snoopctl.c,v 1.3 2004/11/18 06:41:03 bodea Exp $"; +char const *cvs_id = "$Id: snoopctl.c,v 1.4 2004/12/16 08:49:53 bodea Exp $"; int plugin_api_version = PLUGIN_API_VERSION; static struct pluginfuncs *p = 0; @@ -77,8 +77,8 @@ int plugin_control(struct param_control *data) if (flag) { - ipt ip = inet_addr(data->argv[2]); - u16 port = atoi(data->argv[3]); + in_addr_t ip = inet_addr(data->argv[2]); + uint16_t port = atoi(data->argv[3]); if (!ip || ip == INADDR_NONE) { diff --git a/tbf.c b/tbf.c index 6460a71..6107844 100644 --- a/tbf.c +++ b/tbf.c @@ -1,6 +1,6 @@ // L2TPNS: token bucket filters -char const *cvs_id_tbf = "$Id: tbf.c,v 1.10 2004/11/29 02:17:18 bodea Exp $"; +char const *cvs_id_tbf = "$Id: tbf.c,v 1.11 2004/12/16 08:49:53 bodea Exp $"; #include #include "l2tpns.h" @@ -91,7 +91,7 @@ int free_tbf(int tid) // // Allocate a new token bucket filter. // -int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int)) +int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, uint8_t *, int)) { int i; static int p = 0; diff --git a/tbf.h b/tbf.h index bad2c37..5c85c39 100644 --- a/tbf.h +++ b/tbf.h @@ -10,33 +10,33 @@ #define TBF_RATE 360 // 360 bytes per 1/10th of a second. typedef struct { - int credit; - int lasttime; - int queued; - int oldest; // Position of packet in the ring buffer. - sessionidt sid; // associated session ID. - int max_credit; // Maximum amount of credit available (burst size). - int rate; // How many bytes of credit per second we get? (sustained rate) - void (*send)(sessionidt s, u8 *, int); // Routine to actually send out the data. - int prev; // Timer chain position. - int next; // Timer chain position. - - u32 b_queued; // Total bytes sent through this TBF - u32 b_sent; // Total bytes sucessfully made it to the network. - u32 p_queued; // ditto packets. - u32 p_sent; // ditto packets. - u32 b_dropped; // Total bytes dropped. - u32 p_dropped; // Total packets dropped. - u32 p_delayed; // Total packets not sent immediately. - - int sizes[TBF_MAX_QUEUE]; - char packets[TBF_MAX_QUEUE][TBF_MAX_SIZE]; + int credit; + int lasttime; + int queued; + int oldest; // Position of packet in the ring buffer. + sessionidt sid; // associated session ID. + int max_credit; // Maximum amount of credit available (burst size). + int rate; // How many bytes of credit per second we get? (sustained rate) + void (*send)(sessionidt s, uint8_t *, int); // Routine to actually send out the data. + int prev; // Timer chain position. + int next; // Timer chain position. + + uint32_t b_queued; // Total bytes sent through this TBF + uint32_t b_sent; // Total bytes sucessfully made it to the network. + uint32_t p_queued; // ditto packets. + uint32_t p_sent; // ditto packets. + uint32_t b_dropped; // Total bytes dropped. + uint32_t p_dropped; // Total packets dropped. + uint32_t p_delayed; // Total packets not sent immediately. + + int sizes[TBF_MAX_QUEUE]; + char packets[TBF_MAX_QUEUE][TBF_MAX_SIZE]; } tbft; void init_tbf(int num_tbfs); int tbf_run_timer(void); int tbf_queue_packet(int tbf_id, char * data, int size); -int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int)); +int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, uint8_t *, int)); int free_tbf(int tid); void fsck_tbfs(void); diff --git a/util.c b/util.c index fccfa58..4316401 100644 --- a/util.c +++ b/util.c @@ -1,6 +1,6 @@ /* Misc util functions */ -char const *cvs_id_util = "$Id: util.c,v 1.7 2004/11/29 02:17:18 bodea Exp $"; +char const *cvs_id_util = "$Id: util.c,v 1.8 2004/12/16 08:49:53 bodea Exp $"; #include #include @@ -18,7 +18,7 @@ char const *cvs_id_util = "$Id: util.c,v 1.7 2004/11/29 02:17:18 bodea Exp $"; // format ipv4 addr as a dotted-quad; n chooses one of 4 static buffers // to use -char *fmtaddr(ipt addr, int n) +char *fmtaddr(in_addr_t addr, int n) { static char addrs[4][16]; struct in_addr in; diff --git a/util.h b/util.h index 91ab0bb..145559b 100644 --- a/util.h +++ b/util.h @@ -1,7 +1,7 @@ #ifndef __UTIL_H__ #define __UTIL_H__ -char *fmtaddr(ipt addr, int n); +char *fmtaddr(in_addr_t addr, int n); void *shared_malloc(unsigned int size); pid_t fork_and_close(void);