-* Mon Dec 13 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.13
+* Thu Dec 16 2004 Brendan O'Dea <bod@optusnet.com.au> 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
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 <bod@optusnet.com.au> 2.0.12
- The "This time, for sure!" release.
## 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
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
// 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 <string.h>
#include <unistd.h>
/* 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;
* 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 <stdlib.h>
#include <unistd.h>
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);
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;
}
/* 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;
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;
{
/* 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,
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;
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;
return "?";
}
-static char const *bgp_msg_type_str(u8 type)
+static char const *bgp_msg_type_str(uint8_t type)
{
switch (type)
{
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));
/* 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;
}
/* 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);
/* 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__
struct bgp_header {
char marker[16];
- u16 len;
- u8 type;
+ uint16_t len;
+ uint8_t type;
} __attribute__ ((packed));
/* bgp_header.type */
} __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 */
#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));
/* 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);
// 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 <stdio.h>
#include <stdarg.h>
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)
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");
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)
while (a < argc && (argv[a][0] == '+' || argv[a][0] == '-'))
{
- u8 *f;
+ uint8_t *f;
f = (argv[a][0] == '+') ? &rule.tcp_sflags : &rule.tcp_cflags;
// 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 <stdio.h>
#include <sys/file.h>
#include <unistd.h>
#include <stdio.h>
#include <libcli.h>
+#include <inttypes.h>
#include "l2tpns.h"
#include "cluster.h"
// 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.
// 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
// 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;
}
}
// 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};
//
// 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);
// 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;
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));
}
//
// 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;
// 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;
}
{
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) );
// 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) );
// 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);
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);
}
//
// 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;
// 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;
//
// 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;
// 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;
// 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.
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)
// 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);
//
// 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");
}
}
- 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);
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");
//
// 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;
if (s < sizeof(*h))
goto shortpacket;
- h = (heartt*) p;
+ h = (heartt *) p;
p += sizeof(*h);
s -= sizeof(*h);
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);
// 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!
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!
// 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)
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);
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);
//
// 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) {
// 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.
// 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__
#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);
// 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 <string.h>
#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;
if (len < sz + 1)
return NSCTL_ERR_SHORT;
- s = (u8) *p;
+ s = (uint8_t) *p;
*p++ = 0; // null terminate previous arg
sz++;
#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);
/* 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;
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);
}
}
// 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 <arpa/inet.h>
#include <netdb.h>
#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;
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;
}
// one's complement the result
sum = ~sum;
- return htons((u16) sum);
+ return htons((uint16_t) sum);
}
// 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 <arpa/inet.h>
#include <assert.h>
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
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.
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);
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)
// 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);
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;
//
// '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;
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;
// 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;
}
//
// (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));
// 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.
}
{
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;
}
}
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)
}
// 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;
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)
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;
// 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);
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?
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;
}
// 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...
}
// 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)
{
buf += 4;
len -= 4;
- ip = *(u32 *)(buf + 16);
+ ip = *(in_addr_t *)(buf + 16);
if (!session[s].ip)
return;
// 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...
}
}
// 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)
}
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;
// (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)
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)))
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);
*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.
}
// 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);
}
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)
{
}
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)
{
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;
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);
// 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)
{
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;
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 */
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];
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
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);
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
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
{
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
{
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;
}
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;
}
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;
}
else
{
- u16 r;
+ uint16_t r;
controlt *c;
s = sessionfree;
}
else
{ // data
- u16 prot;
+ uint16_t prot;
LOG_HEX(5, "Receive Tunnel Data", p, l);
if (l > 2 && p[0] == 0xFF && p[1] == 0x03)
}
else
{
- prot = ntohs(*(u16 *) p);
+ prot = ntohs(*(uint16_t *) p);
p += 2;
l -= 2;
}
}
// 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);
return;
}
- if (*(u16 *) (buf + 2) == htons(PKTIP)) // IP
+ if (*(uint16_t *) (buf + 2) == htons(PKTIP)) // IP
processipout(buf, len);
// Else discard.
}
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;
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
// 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));
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;
{
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))
if ((s = recvfrom(udpfd, buf, sizeof(buf), 0, (void *) &addr, &alen)) > 0)
{
processudp(buf, s, &addr);
+ udp_pkts++;
}
else
{
if ((s = read(tunfd, buf, sizeof(buf))) > 0)
{
processtun(buf, s);
+ tun_pkts++;
}
else
{
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
{
}
}
}
+
+ 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).
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;
//
// 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)
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)
{
// 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;
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",
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)
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;
ippoolt itmp;
FILE *f;
char magic[sizeof(DUMP_MAGIC) - 1];
- u32 buf[2];
+ uint32_t buf[2];
if (!config->save_state)
{
static void dump_state()
{
FILE *f;
- u32 buf[2];
+ uint32_t buf[2];
if (!config->save_state)
return;
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;
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;
// 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;
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;
*
* 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);
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)
{
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)
{
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
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))
{
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
// 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__
};
// 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;
// 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;
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;
typedef struct
{
- u32 cin;
- u32 cout;
+ uint32_t cin;
+ uint32_t cout;
} sessioncountt;
#define SESSIONPFC 1 // PFC negotiated flags
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
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
}
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
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;
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).
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;
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
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
} 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);
// 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;
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;
%attr(644,root,root) /usr/share/man/man[58]/*
%changelog
-* Mon Dec 13 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.13-1
+* Thu Dec 16 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.13-1
- 2.0.13 release, see /usr/share/doc/l2tpns-2.0.13/Changes
{
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);
// 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 <stdio.h>
#include <string.h>
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);
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);
}
{
- u8 *b = p;
+ uint8_t *b = p;
b += 4;
if (*b && *b < sizeof(user))
memcpy(user, b + 1, *b);
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",
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 };
}
// 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);
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);
"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;
{
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
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");
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
}
// 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);
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);
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);
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
*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;
}
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
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;
{
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
}
// 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;
}
// 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);
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);
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)
}
// 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;
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;
}
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
}
*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));
}
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));
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));
//
// 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)
{
// 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?
// 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);
// 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);
// 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);
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!!
{
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;
}
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);
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);
// 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 <time.h>
#include <stdio.h>
extern radiust *radius;
extern sessiont *session;
extern tunnelt *tunnel;
-extern u32 sessionid;
extern configt *config;
extern int *radfds;
extern ip_filtert *ip_filters;
}
}
-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)
{
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)
}
// 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);
{ // 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)
{
{ // 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];
}
}
{
*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)
// 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
}
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));
}
// 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.
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",
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!
{
(*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!
{
// 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
}
{
// 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));
{
// 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));
}
{
// 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 == '.')
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);
}
// Send a retry for RADIUS/CHAP message
-void radiusretry(u16 r)
+void radiusretry(uint16_t r)
{
sessionidt s = radius[r].session;
tunnelidt t = 0;
/* 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;
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)
{
// 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 <string.h>
#include "l2tpns.h"
//
// 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;
#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);
/* 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 <unistd.h>
#include <errno.h>
// 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;
#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);