use standard uintN_t types for portability
This commit is contained in:
parent
cd4f292462
commit
6b1075b65c
23 changed files with 664 additions and 657 deletions
3
Changes
3
Changes
|
|
@ -1,4 +1,4 @@
|
|||
* 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
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
attempt to avoid losing the cluster in high load (DoS) conditions.
|
||||
- Compress logs.
|
||||
- Retain counters of shutdown sessions to dump once per minute.
|
||||
- Use standard uintN_t types for portability.
|
||||
|
||||
* Wed Dec 1 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.12
|
||||
- The "This time, for sure!" release.
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -118,7 +118,6 @@ install: all
|
|||
|
||||
## Dependencies: (autogenerated) ##
|
||||
arp.o: arp.c l2tpns.h
|
||||
bgp.o: bgp.c l2tpns.h bgp.h util.h
|
||||
cli.o: cli.c l2tpns.h util.h cluster.h tbf.h ll.h bgp.h
|
||||
cluster.o: cluster.c l2tpns.h cluster.h util.h tbf.h bgp.h
|
||||
constants.o: constants.c constants.h
|
||||
|
|
@ -132,6 +131,7 @@ ppp.o: ppp.c l2tpns.h constants.h plugin.h util.h tbf.h cluster.h
|
|||
radius.o: radius.c md5.h constants.h l2tpns.h plugin.h util.h
|
||||
tbf.o: tbf.c l2tpns.h util.h tbf.h
|
||||
util.o: util.c l2tpns.h bgp.h
|
||||
bgp.o: bgp.c l2tpns.h bgp.h util.h
|
||||
garden.so: garden.c l2tpns.h plugin.h control.h
|
||||
throttlectl.so: throttlectl.c l2tpns.h plugin.h control.h
|
||||
autothrottle.so: autothrottle.c l2tpns.h plugin.h
|
||||
|
|
|
|||
8
arp.c
8
arp.c
|
|
@ -1,6 +1,6 @@
|
|||
// L2TPNS: arp
|
||||
|
||||
char const *cvs_id_arp = "$Id: arp.c,v 1.4 2004/07/08 16:19:09 bodea Exp $";
|
||||
char const *cvs_id_arp = "$Id: arp.c,v 1.5 2004/12/16 08:49:52 bodea Exp $";
|
||||
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
|
@ -18,12 +18,12 @@ struct arp_buf {
|
|||
|
||||
/* Data bit - variably sized, so not present in |struct arphdr| */
|
||||
unsigned char ar_sha[ETH_ALEN]; /* Sender hardware address */
|
||||
ipt ar_sip; /* Sender IP address. */
|
||||
in_addr_t ar_sip; /* Sender IP address. */
|
||||
unsigned char ar_tha[ETH_ALEN]; /* Target hardware address */
|
||||
ipt ar_tip; /* Target ip */
|
||||
in_addr_t ar_tip; /* Target ip */
|
||||
} __attribute__((packed));
|
||||
|
||||
void sendarp(int ifr_idx, const unsigned char* mac, ipt ip)
|
||||
void sendarp(int ifr_idx, const unsigned char* mac, in_addr_t ip)
|
||||
{
|
||||
int fd;
|
||||
struct sockaddr_ll sll;
|
||||
|
|
|
|||
41
bgp.c
41
bgp.c
|
|
@ -10,7 +10,7 @@
|
|||
* nor RFC2385 (which requires a kernel patch on 2.4 kernels).
|
||||
*/
|
||||
|
||||
char const *cvs_id_bgp = "$Id: bgp.c,v 1.8 2004/11/29 02:17:17 bodea Exp $";
|
||||
char const *cvs_id_bgp = "$Id: bgp.c,v 1.9 2004/12/16 08:49:52 bodea Exp $";
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
|
@ -34,7 +34,7 @@ static struct bgp_route_list *bgp_insert_route(struct bgp_route_list *head,
|
|||
struct bgp_route_list *new);
|
||||
|
||||
static void bgp_free_routes(struct bgp_route_list *routes);
|
||||
static char const *bgp_msg_type_str(u8 type);
|
||||
static char const *bgp_msg_type_str(uint8_t type);
|
||||
static int bgp_connect(struct bgp_peer *peer);
|
||||
static int bgp_handle_connect(struct bgp_peer *peer);
|
||||
static int bgp_write(struct bgp_peer *peer);
|
||||
|
|
@ -43,9 +43,10 @@ static int bgp_handle_input(struct bgp_peer *peer);
|
|||
static int bgp_send_open(struct bgp_peer *peer);
|
||||
static int bgp_send_keepalive(struct bgp_peer *peer);
|
||||
static int bgp_send_update(struct bgp_peer *peer);
|
||||
static int bgp_send_notification(struct bgp_peer *peer, u8 code, u8 subcode);
|
||||
static int bgp_send_notification(struct bgp_peer *peer, uint8_t code,
|
||||
uint8_t subcode);
|
||||
|
||||
static u16 our_as;
|
||||
static uint16_t our_as;
|
||||
static struct bgp_route_list *bgp_routes = 0;
|
||||
|
||||
int bgp_configured = 0;
|
||||
|
|
@ -89,7 +90,8 @@ int bgp_setup(int as)
|
|||
}
|
||||
|
||||
/* start connection with a peer */
|
||||
int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold, int enable)
|
||||
int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive,
|
||||
int hold, int enable)
|
||||
{
|
||||
struct hostent *h;
|
||||
int ibgp;
|
||||
|
|
@ -98,8 +100,8 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold
|
|||
char path_attrs[64];
|
||||
char *p = path_attrs;
|
||||
in_addr_t ip;
|
||||
u32 metric = htonl(BGP_METRIC);
|
||||
u32 no_export = htonl(BGP_COMMUNITY_NO_EXPORT);
|
||||
uint32_t metric = htonl(BGP_METRIC);
|
||||
uint32_t no_export = htonl(BGP_COMMUNITY_NO_EXPORT);
|
||||
|
||||
if (!our_as)
|
||||
return 0;
|
||||
|
|
@ -170,9 +172,9 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold
|
|||
{
|
||||
/* just our AS */
|
||||
struct {
|
||||
u8 type;
|
||||
u8 len;
|
||||
u16 value;
|
||||
uint8_t type;
|
||||
uint8_t len;
|
||||
uint16_t value;
|
||||
} as_path = {
|
||||
BGP_PATH_ATTR_CODE_AS_PATH_AS_SEQUENCE,
|
||||
1,
|
||||
|
|
@ -204,7 +206,7 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold
|
|||
|
||||
if (ibgp)
|
||||
{
|
||||
u32 local_pref = htonl(BGP_LOCAL_PREF);
|
||||
uint32_t local_pref = htonl(BGP_LOCAL_PREF);
|
||||
|
||||
/* LOCAL_PREF */
|
||||
a.flags = BGP_PATH_ATTR_FLAG_TRANS;
|
||||
|
|
@ -324,7 +326,7 @@ static void bgp_set_retry(struct bgp_peer *peer)
|
|||
static void bgp_cidr(in_addr_t ip, in_addr_t mask, struct bgp_ip_prefix *pfx)
|
||||
{
|
||||
int i;
|
||||
u32 b;
|
||||
uint32_t b;
|
||||
|
||||
/* convert to prefix notation */
|
||||
pfx->len = 32;
|
||||
|
|
@ -641,7 +643,7 @@ char const *bgp_state_str(enum bgp_state state)
|
|||
return "?";
|
||||
}
|
||||
|
||||
static char const *bgp_msg_type_str(u8 type)
|
||||
static char const *bgp_msg_type_str(uint8_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
|
|
@ -987,7 +989,7 @@ static int bgp_handle_input(struct bgp_peer *peer)
|
|||
static int bgp_send_open(struct bgp_peer *peer)
|
||||
{
|
||||
struct bgp_data_open data;
|
||||
u16 len = sizeof(peer->outbuf->packet.header);
|
||||
uint16_t len = sizeof(peer->outbuf->packet.header);
|
||||
|
||||
memset(peer->outbuf->packet.header.marker, 0xff,
|
||||
sizeof(peer->outbuf->packet.header.marker));
|
||||
|
|
@ -1029,9 +1031,9 @@ static int bgp_send_keepalive(struct bgp_peer *peer)
|
|||
/* send/buffer UPDATE message */
|
||||
static int bgp_send_update(struct bgp_peer *peer)
|
||||
{
|
||||
u16 unf_len = 0;
|
||||
u16 attr_len;
|
||||
u16 len = sizeof(peer->outbuf->packet.header);
|
||||
uint16_t unf_len = 0;
|
||||
uint16_t attr_len;
|
||||
uint16_t len = sizeof(peer->outbuf->packet.header);
|
||||
struct bgp_route_list *have = peer->routes;
|
||||
struct bgp_route_list *want = peer->routing ? bgp_routes : 0;
|
||||
struct bgp_route_list *e = 0;
|
||||
|
|
@ -1169,10 +1171,11 @@ static int bgp_send_update(struct bgp_peer *peer)
|
|||
}
|
||||
|
||||
/* send/buffer NOTIFICATION message */
|
||||
static int bgp_send_notification(struct bgp_peer *peer, u8 code, u8 subcode)
|
||||
static int bgp_send_notification(struct bgp_peer *peer, uint8_t code,
|
||||
uint8_t subcode)
|
||||
{
|
||||
struct bgp_data_notification data;
|
||||
u16 len = 0;
|
||||
uint16_t len = 0;
|
||||
|
||||
data.error_code = code;
|
||||
len += sizeof(data.error_code);
|
||||
|
|
|
|||
36
bgp.h
36
bgp.h
|
|
@ -1,5 +1,5 @@
|
|||
/* BGPv4 (RFC1771) */
|
||||
/* $Id: bgp.h,v 1.3 2004/11/11 03:07:42 bodea Exp $ */
|
||||
/* $Id: bgp.h,v 1.4 2004/12/16 08:49:52 bodea Exp $ */
|
||||
|
||||
#ifndef __BGP_H__
|
||||
#define __BGP_H__
|
||||
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
struct bgp_header {
|
||||
char marker[16];
|
||||
u16 len;
|
||||
u8 type;
|
||||
uint16_t len;
|
||||
uint8_t type;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* bgp_header.type */
|
||||
|
|
@ -33,33 +33,33 @@ struct bgp_packet {
|
|||
} __attribute__ ((packed));
|
||||
|
||||
struct bgp_data_open {
|
||||
u8 version;
|
||||
uint8_t version;
|
||||
#define BGP_VERSION 4
|
||||
u16 as;
|
||||
u16 hold_time;
|
||||
u32 identifier;
|
||||
u8 opt_len;
|
||||
uint16_t as;
|
||||
uint16_t hold_time;
|
||||
uint32_t identifier;
|
||||
uint8_t opt_len;
|
||||
#define BGP_DATA_OPEN_SIZE 10 /* size of struct excluding opt_params */
|
||||
char opt_params[sizeof(((struct bgp_packet *)0)->data) - BGP_DATA_OPEN_SIZE]; /* variable */
|
||||
} __attribute__ ((packed));
|
||||
|
||||
struct bgp_ip_prefix {
|
||||
u8 len;
|
||||
u32 prefix; /* variable */
|
||||
uint8_t len;
|
||||
uint32_t prefix; /* variable */
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define BGP_IP_PREFIX_SIZE(p) (1 + ((p).len / 8) + ((p).len % 8 != 0))
|
||||
|
||||
struct bgp_path_attr {
|
||||
u8 flags;
|
||||
u8 code;
|
||||
uint8_t flags;
|
||||
uint8_t code;
|
||||
union {
|
||||
struct {
|
||||
u8 len;
|
||||
uint8_t len;
|
||||
char value[29]; /* semi-random size, adequate for l2tpns */
|
||||
} __attribute__ ((packed)) s; /* short */
|
||||
struct {
|
||||
u16 len;
|
||||
uint16_t len;
|
||||
char value[28];
|
||||
} __attribute__ ((packed)) e; /* extended */
|
||||
} data; /* variable */
|
||||
|
|
@ -95,8 +95,8 @@ struct bgp_path_attr {
|
|||
#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 /* don't advertise to any other AS */
|
||||
|
||||
struct bgp_data_notification {
|
||||
u8 error_code;
|
||||
u8 error_subcode;
|
||||
uint8_t error_code;
|
||||
uint8_t error_subcode;
|
||||
char data[sizeof(((struct bgp_packet *)0)->data) - 2]; /* variable */
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
|
@ -185,7 +185,9 @@ extern int bgp_configured;
|
|||
|
||||
/* actions */
|
||||
int bgp_setup(int as);
|
||||
int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold, int enable);
|
||||
int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive,
|
||||
int hold, int enable);
|
||||
|
||||
void bgp_stop(struct bgp_peer *peer);
|
||||
void bgp_halt(struct bgp_peer *peer);
|
||||
int bgp_restart(struct bgp_peer *peer);
|
||||
|
|
|
|||
14
cli.c
14
cli.c
|
|
@ -2,7 +2,7 @@
|
|||
// vim: sw=8 ts=8
|
||||
|
||||
char const *cvs_name = "$Name: $";
|
||||
char const *cvs_id_cli = "$Id: cli.c,v 1.40 2004/12/15 03:09:56 bodea Exp $";
|
||||
char const *cvs_id_cli = "$Id: cli.c,v 1.41 2004/12/16 08:49:52 bodea Exp $";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
|
@ -1252,8 +1252,8 @@ static int cmd_drop_session(struct cli_def *cli, char *command, char **argv, int
|
|||
|
||||
static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc)
|
||||
{
|
||||
ipt ip;
|
||||
u16 port;
|
||||
in_addr_t ip;
|
||||
uint16_t port;
|
||||
sessionidt s;
|
||||
|
||||
if (CLI_HELP_REQUESTED)
|
||||
|
|
@ -2393,7 +2393,7 @@ static int cmd_no_ip_access_list(struct cli_def *cli, char *command, char **argv
|
|||
return access_list(cli, argv, argc, 0);
|
||||
}
|
||||
|
||||
static int show_ip_wild(char *buf, ipt ip, ipt wild)
|
||||
static int show_ip_wild(char *buf, in_addr_t ip, in_addr_t wild)
|
||||
{
|
||||
if (ip == INADDR_ANY && wild == INADDR_BROADCAST)
|
||||
return sprintf(buf, " any");
|
||||
|
|
@ -2524,8 +2524,8 @@ ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char *
|
|||
|
||||
for (a = 1, i = 0; i < 2; i++)
|
||||
{
|
||||
ipt *ip;
|
||||
ipt *wild;
|
||||
in_addr_t *ip;
|
||||
in_addr_t *wild;
|
||||
ip_filter_portt *port;
|
||||
|
||||
if (i == 0)
|
||||
|
|
@ -2667,7 +2667,7 @@ ip_filter_rulet *access_list_rule_ext(struct cli_def *cli, char *command, char *
|
|||
|
||||
while (a < argc && (argv[a][0] == '+' || argv[a][0] == '-'))
|
||||
{
|
||||
u8 *f;
|
||||
uint8_t *f;
|
||||
|
||||
f = (argv[a][0] == '+') ? &rule.tcp_sflags : &rule.tcp_cflags;
|
||||
|
||||
|
|
|
|||
160
cluster.c
160
cluster.c
|
|
@ -1,6 +1,6 @@
|
|||
// L2TPNS Clustering Stuff
|
||||
|
||||
char const *cvs_id_cluster = "$Id: cluster.c,v 1.24 2004/12/15 02:56:38 bodea Exp $";
|
||||
char const *cvs_id_cluster = "$Id: cluster.c,v 1.25 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/file.h>
|
||||
|
|
@ -18,6 +18,7 @@ char const *cvs_id_cluster = "$Id: cluster.c,v 1.24 2004/12/15 02:56:38 bodea Ex
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <libcli.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "l2tpns.h"
|
||||
#include "cluster.h"
|
||||
|
|
@ -40,7 +41,7 @@ char const *cvs_id_cluster = "$Id: cluster.c,v 1.24 2004/12/15 02:56:38 bodea Ex
|
|||
// Module variables.
|
||||
int cluster_sockfd = 0; // The filedescriptor for the cluster communications port.
|
||||
|
||||
ipt my_address = 0; // The network address of my ethernet port.
|
||||
in_addr_t my_address = 0; // The network address of my ethernet port.
|
||||
static int walk_session_number = 0; // The next session to send when doing the slow table walk.
|
||||
static int walk_tunnel_number = 0; // The next tunnel to send when doing the slow table walk.
|
||||
|
||||
|
|
@ -60,15 +61,15 @@ static struct {
|
|||
// we can re-transmit if needed.
|
||||
|
||||
static struct {
|
||||
u32 peer;
|
||||
time_t basetime;
|
||||
clockt timestamp;
|
||||
int uptodate;
|
||||
in_addr_t peer;
|
||||
time_t basetime;
|
||||
clockt timestamp;
|
||||
int uptodate;
|
||||
} peers[CLUSTER_MAX_SIZE]; // List of all the peers we've heard from.
|
||||
static int num_peers; // Number of peers in list.
|
||||
|
||||
static int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize);
|
||||
static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize);
|
||||
static int rle_decompress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize);
|
||||
static int rle_compress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize);
|
||||
|
||||
//
|
||||
// Create a listening socket
|
||||
|
|
@ -177,17 +178,17 @@ static int cluster_send_data(void *data, int datalen)
|
|||
// Maintains the format. Assumes that the caller
|
||||
// has passed in a big enough buffer!
|
||||
//
|
||||
static void add_type(char ** p, int type, int more, char * data, int size)
|
||||
static void add_type(char **p, int type, int more, char *data, int size)
|
||||
{
|
||||
* ( (u32*)(*p) ) = type;
|
||||
*p += sizeof(u32);
|
||||
*((uint32_t *) (*p)) = type;
|
||||
*p += sizeof(uint32_t);
|
||||
|
||||
* ( (u32*)(*p) ) = more;
|
||||
*p += sizeof(u32);
|
||||
*((uint32_t *)(*p)) = more;
|
||||
*p += sizeof(uint32_t);
|
||||
|
||||
if (data && size > 0) {
|
||||
memcpy(*p, data, size);
|
||||
(*p) += size;
|
||||
*p += size;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +222,7 @@ static void cluster_uptodate(void)
|
|||
// Send a unicast UDP packet to a peer with 'data' as the
|
||||
// contents.
|
||||
//
|
||||
static int peer_send_data(u32 peer, char * data, int size)
|
||||
static int peer_send_data(in_addr_t peer, char *data, int size)
|
||||
{
|
||||
struct sockaddr_in addr = {0};
|
||||
|
||||
|
|
@ -249,10 +250,10 @@ static int peer_send_data(u32 peer, char * data, int size)
|
|||
//
|
||||
// Send a structured message to a peer with a single element of type 'type'.
|
||||
//
|
||||
static int peer_send_message(u32 peer, int type, int more, char * data, int size)
|
||||
static int peer_send_message(in_addr_t peer, int type, int more, char *data, int size)
|
||||
{
|
||||
char buf[65536]; // Vast overkill.
|
||||
char * p = buf;
|
||||
char *p = buf;
|
||||
|
||||
LOG(4, 0, 0, "Sending message to peer (type %d, more %d, size %d)\n", type, more, size);
|
||||
add_type(&p, type, more, data, size);
|
||||
|
|
@ -266,7 +267,7 @@ static int peer_send_message(u32 peer, int type, int more, char * data, int size
|
|||
// The master just processes the payload as if it had
|
||||
// received it off the tun device.
|
||||
//
|
||||
int master_forward_packet(char *data, int size, u32 addr, int port)
|
||||
int master_forward_packet(char *data, int size, in_addr_t addr, int port)
|
||||
{
|
||||
char buf[65536]; // Vast overkill.
|
||||
char *p = buf;
|
||||
|
|
@ -277,12 +278,11 @@ int master_forward_packet(char *data, int size, u32 addr, int port)
|
|||
LOG(4, 0, 0, "Forwarding packet from %s to master (size %d)\n", fmtaddr(addr, 0), size);
|
||||
|
||||
STAT(c_forwarded);
|
||||
add_type(&p, C_FORWARD, addr, (char*) &port, sizeof(port) );
|
||||
add_type(&p, C_FORWARD, addr, (char *) &port, sizeof(port));
|
||||
memcpy(p, data, size);
|
||||
p += size;
|
||||
|
||||
return peer_send_data(config->cluster_master_address, buf, (p-buf) );
|
||||
|
||||
return peer_send_data(config->cluster_master_address, buf, (p - buf));
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -337,7 +337,7 @@ int master_garden_packet(sessionidt s, char *data, int size)
|
|||
// Send a chunk of data as a heartbeat..
|
||||
// We save it in the history buffer as we do so.
|
||||
//
|
||||
static void send_heartbeat(int seq, char * data, int size)
|
||||
static void send_heartbeat(int seq, char *data, int size)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
@ -426,7 +426,7 @@ void master_update_counts(void)
|
|||
|
||||
// Forward the data to the master.
|
||||
LOG(4, 0, 0, "Sending byte counters to master (%d elements)\n", c);
|
||||
peer_send_message(config->cluster_master_address, C_BYTES, c, (char*) &b, sizeof(b[0]) * c);
|
||||
peer_send_message(config->cluster_master_address, C_BYTES, c, (char *) &b, sizeof(b[0]) * c);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -688,9 +688,9 @@ static int hb_add_type(char **p, int type, int id)
|
|||
{
|
||||
switch (type) {
|
||||
case C_CSESSION: { // Compressed C_SESSION.
|
||||
u8 c[sizeof(sessiont) * 2]; // Bigger than worst case.
|
||||
u8 *d = (u8 *) &session[id];
|
||||
u8 *orig = d;
|
||||
uint8_t c[sizeof(sessiont) * 2]; // Bigger than worst case.
|
||||
uint8_t *d = (uint8_t *) &session[id];
|
||||
uint8_t *orig = d;
|
||||
int size;
|
||||
|
||||
size = rle_compress( &d, sizeof(sessiont), c, sizeof(c) );
|
||||
|
|
@ -698,19 +698,19 @@ static int hb_add_type(char **p, int type, int id)
|
|||
// Did we compress the full structure, and is the size actually
|
||||
// reduced??
|
||||
if ( (d - orig) == sizeof(sessiont) && size < sizeof(sessiont) ) {
|
||||
add_type(p, C_CSESSION, id, (char*) c, size);
|
||||
add_type(p, C_CSESSION, id, (char *) c, size);
|
||||
break;
|
||||
}
|
||||
// Failed to compress : Fall through.
|
||||
}
|
||||
case C_SESSION: add_type(p, C_SESSION, id,
|
||||
(char*) &session[id], sizeof(sessiont));
|
||||
(char *) &session[id], sizeof(sessiont));
|
||||
break;
|
||||
|
||||
case C_CTUNNEL: { // Compressed C_TUNNEL
|
||||
u8 c[sizeof(tunnelt) * 2]; // Bigger than worst case.
|
||||
u8 *d = (u8 *) &tunnel[id];
|
||||
u8 *orig = d;
|
||||
uint8_t c[sizeof(tunnelt) * 2]; // Bigger than worst case.
|
||||
uint8_t *d = (uint8_t *) &tunnel[id];
|
||||
uint8_t *orig = d;
|
||||
int size;
|
||||
|
||||
size = rle_compress( &d, sizeof(tunnelt), c, sizeof(c) );
|
||||
|
|
@ -724,7 +724,7 @@ static int hb_add_type(char **p, int type, int id)
|
|||
// Failed to compress : Fall through.
|
||||
}
|
||||
case C_TUNNEL: add_type(p, C_TUNNEL, id,
|
||||
(char*) &tunnel[id], sizeof(tunnelt));
|
||||
(char *) &tunnel[id], sizeof(tunnelt));
|
||||
break;
|
||||
default:
|
||||
LOG(0, 0, 0, "Found an invalid type in heart queue! (%d)\n", type);
|
||||
|
|
@ -766,14 +766,14 @@ void cluster_heartbeat()
|
|||
h.timeout = config->cluster_hb_timeout;
|
||||
h.table_version = config->cluster_table_version;
|
||||
|
||||
add_type(&p, C_HEARTBEAT, HB_VERSION, (char*) &h, sizeof(h));
|
||||
add_type(&p, C_HEARTBEAT, HB_VERSION, (char *) &h, sizeof(h));
|
||||
|
||||
for (i = 0; i < config->cluster_num_changes; ++i) {
|
||||
hb_add_type(&p, cluster_changes[i].type, cluster_changes[i].id);
|
||||
}
|
||||
|
||||
if (p > (buff + sizeof(buff))) { // Did we somehow manage to overun the buffer?
|
||||
LOG(0, 0, 0, "FATAL: Overran the heartbeat buffer! This is fatal. Exiting. (size %d)\n", p - buff);
|
||||
LOG(0, 0, 0, "FATAL: Overran the heartbeat buffer! This is fatal. Exiting. (size %d)\n", (int) (p - buff));
|
||||
kill(0, SIGTERM);
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -781,7 +781,7 @@ void cluster_heartbeat()
|
|||
//
|
||||
// Fill out the packet with sessions from the session table...
|
||||
// (not forgetting to leave space so we can get some tunnels in too )
|
||||
while ( (p + sizeof(u32) * 2 + sizeof(sessiont) * 2 ) < (buff + MAX_HEART_SIZE) ) {
|
||||
while ( (p + sizeof(uint32_t) * 2 + sizeof(sessiont) * 2 ) < (buff + MAX_HEART_SIZE) ) {
|
||||
|
||||
if (!walk_session_number) // session #0 isn't valid.
|
||||
++walk_session_number;
|
||||
|
|
@ -801,7 +801,7 @@ void cluster_heartbeat()
|
|||
// than the session table. This is good because stuffing up a
|
||||
// tunnel is a much bigger deal than stuffing up a session.
|
||||
//
|
||||
while ( (p + sizeof(u32) * 2 + sizeof(tunnelt) ) < (buff + MAX_HEART_SIZE) ) {
|
||||
while ( (p + sizeof(uint32_t) * 2 + sizeof(tunnelt) ) < (buff + MAX_HEART_SIZE) ) {
|
||||
|
||||
if (!walk_tunnel_number) // tunnel #0 isn't valid.
|
||||
++walk_tunnel_number;
|
||||
|
|
@ -818,16 +818,16 @@ void cluster_heartbeat()
|
|||
//
|
||||
// Did we do something wrong?
|
||||
if (p > (buff + sizeof(buff))) { // Did we somehow manage to overun the buffer?
|
||||
LOG(0, 0, 0, "Overran the heartbeat buffer now! This is fatal. Exiting. (size %d)\n", p - buff);
|
||||
LOG(0, 0, 0, "Overran the heartbeat buffer now! This is fatal. Exiting. (size %d)\n", (int) (p - buff));
|
||||
kill(0, SIGTERM);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
LOG(3, 0, 0, "Sending v%d heartbeat #%d, change #%llu with %d changes "
|
||||
LOG(3, 0, 0, "Sending v%d heartbeat #%d, change #%" PRIu64 " with %d changes "
|
||||
"(%d x-sess, %d x-tunnels, %d highsess, %d hightun, size %d)\n",
|
||||
HB_VERSION, h.seq, h.table_version, config->cluster_num_changes,
|
||||
count, tcount, config->cluster_highest_sessionid,
|
||||
config->cluster_highest_tunnelid, (p-buff));
|
||||
config->cluster_highest_tunnelid, (int) (p - buff));
|
||||
|
||||
config->cluster_num_changes = 0;
|
||||
|
||||
|
|
@ -887,7 +887,7 @@ int cluster_send_tunnel(int tid)
|
|||
// missed a packet. We'll resend it every packet since
|
||||
// the last one it's seen.
|
||||
//
|
||||
static int cluster_catchup_slave(int seq, u32 slave)
|
||||
static int cluster_catchup_slave(int seq, in_addr_t slave)
|
||||
{
|
||||
int s;
|
||||
int diff;
|
||||
|
|
@ -922,10 +922,10 @@ static int cluster_catchup_slave(int seq, u32 slave)
|
|||
// We've heard from another peer! Add it to the list
|
||||
// that we select from at election time.
|
||||
//
|
||||
static int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size)
|
||||
static int cluster_add_peer(in_addr_t peer, time_t basetime, pingt *pp, int size)
|
||||
{
|
||||
int i;
|
||||
u32 clusterid;
|
||||
in_addr_t clusterid;
|
||||
pingt p;
|
||||
|
||||
// Allow for backward compatability.
|
||||
|
|
@ -935,8 +935,8 @@ static int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size)
|
|||
if (size > sizeof(p))
|
||||
size = sizeof(p);
|
||||
|
||||
memset( (void*) &p, 0, sizeof(p) );
|
||||
memcpy( (void*) &p, (void*) pp, size);
|
||||
memset( (void *) &p, 0, sizeof(p) );
|
||||
memcpy( (void *) &p, (void *) pp, size);
|
||||
|
||||
clusterid = p.addr;
|
||||
if (clusterid != config->bind_address)
|
||||
|
|
@ -1006,11 +1006,11 @@ static int cluster_add_peer(u32 peer, time_t basetime, pingt *pp, int size)
|
|||
// Note that we don't mark the session as dirty; We rely on
|
||||
// the slow table walk to propogate this back out to the slaves.
|
||||
//
|
||||
static int cluster_handle_bytes(char * data, int size)
|
||||
static int cluster_handle_bytes(char *data, int size)
|
||||
{
|
||||
bytest * b;
|
||||
bytest *b;
|
||||
|
||||
b = (bytest*) data;
|
||||
b = (bytest *) data;
|
||||
|
||||
LOG(3, 0, 0, "Got byte counter update (size %d)\n", size);
|
||||
|
||||
|
|
@ -1043,7 +1043,7 @@ static int cluster_handle_bytes(char * data, int size)
|
|||
//
|
||||
// Handle receiving a session structure in a heartbeat packet.
|
||||
//
|
||||
static int cluster_recv_session(int more , u8 * p)
|
||||
static int cluster_recv_session(int more, uint8_t *p)
|
||||
{
|
||||
if (more >= MAXSESSION) {
|
||||
LOG(0, 0, 0, "DANGER: Received a heartbeat session id > MAXSESSION!\n");
|
||||
|
|
@ -1058,7 +1058,7 @@ static int cluster_recv_session(int more , u8 * p)
|
|||
}
|
||||
}
|
||||
|
||||
load_session(more, (sessiont*) p); // Copy session into session table..
|
||||
load_session(more, (sessiont *) p); // Copy session into session table..
|
||||
|
||||
LOG(5, more, 0, "Received session update (%d undef)\n", config->cluster_undefined_sessions);
|
||||
|
||||
|
|
@ -1068,7 +1068,7 @@ static int cluster_recv_session(int more , u8 * p)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cluster_recv_tunnel(int more, u8 *p)
|
||||
static int cluster_recv_tunnel(int more, uint8_t *p)
|
||||
{
|
||||
if (more >= MAXTUNNEL) {
|
||||
LOG(0, 0, 0, "DANGER: Received a tunnel session id > MAXTUNNEL!\n");
|
||||
|
|
@ -1106,9 +1106,9 @@ static int cluster_recv_tunnel(int more, u8 *p)
|
|||
//
|
||||
// v3: added interval, timeout
|
||||
// v4: added table_version
|
||||
static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32 addr)
|
||||
static int cluster_process_heartbeat(uint8_t *data, int size, int more, uint8_t *p, in_addr_t addr)
|
||||
{
|
||||
heartt * h;
|
||||
heartt *h;
|
||||
int s = size - (p-data);
|
||||
int i, type;
|
||||
|
||||
|
|
@ -1126,7 +1126,7 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32
|
|||
if (s < sizeof(*h))
|
||||
goto shortpacket;
|
||||
|
||||
h = (heartt*) p;
|
||||
h = (heartt *) p;
|
||||
p += sizeof(*h);
|
||||
s -= sizeof(*h);
|
||||
|
||||
|
|
@ -1144,7 +1144,7 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32
|
|||
|
||||
if (more >= 4) {
|
||||
if (h->table_version > config->cluster_table_version) {
|
||||
LOG(0, 0, 0, "They've seen more state changes (%llu vs my %llu) so I'm gone!\n",
|
||||
LOG(0, 0, 0, "They've seen more state changes (%" PRIu64 " vs my %" PRIu64 ") so I'm gone!\n",
|
||||
h->table_version, config->cluster_table_version);
|
||||
|
||||
kill(0, SIGTERM);
|
||||
|
|
@ -1220,21 +1220,21 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32
|
|||
// Ok. process the packet...
|
||||
while ( s > 0) {
|
||||
|
||||
type = * ((u32*) p);
|
||||
p += sizeof(u32);
|
||||
s -= sizeof(u32);
|
||||
type = *((uint32_t *) p);
|
||||
p += sizeof(uint32_t);
|
||||
s -= sizeof(uint32_t);
|
||||
|
||||
more = * ((u32*) p);
|
||||
p += sizeof(u32);
|
||||
s -= sizeof(u32);
|
||||
more = *((uint32_t *) p);
|
||||
p += sizeof(uint32_t);
|
||||
s -= sizeof(uint32_t);
|
||||
|
||||
switch (type) {
|
||||
case C_CSESSION: { // Compressed session structure.
|
||||
u8 c [ sizeof(sessiont) + 2];
|
||||
uint8_t c[ sizeof(sessiont) + 2];
|
||||
int size;
|
||||
u8 * orig_p = p;
|
||||
uint8_t *orig_p = p;
|
||||
|
||||
size = rle_decompress((u8 **) &p, s, c, sizeof(c) );
|
||||
size = rle_decompress((uint8_t **) &p, s, c, sizeof(c) );
|
||||
s -= (p - orig_p);
|
||||
|
||||
if (size != sizeof(sessiont) ) { // Ouch! Very very bad!
|
||||
|
|
@ -1257,11 +1257,11 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32
|
|||
break;
|
||||
|
||||
case C_CTUNNEL: { // Compressed tunnel structure.
|
||||
u8 c [ sizeof(tunnelt) + 2];
|
||||
uint8_t c[ sizeof(tunnelt) + 2];
|
||||
int size;
|
||||
u8 * orig_p = p;
|
||||
uint8_t *orig_p = p;
|
||||
|
||||
size = rle_decompress( (u8 **) &p, s, c, sizeof(c) );
|
||||
size = rle_decompress((uint8_t **) &p, s, c, sizeof(c));
|
||||
s -= (p - orig_p);
|
||||
|
||||
if (size != sizeof(tunnelt) ) { // Ouch! Very very bad!
|
||||
|
|
@ -1310,10 +1310,10 @@ shortpacket:
|
|||
// We got a packet on the cluster port!
|
||||
// Handle pings, lastseens, and heartbeats!
|
||||
//
|
||||
int processcluster(char * data, int size, u32 addr)
|
||||
int processcluster(char *data, int size, in_addr_t addr)
|
||||
{
|
||||
int type, more;
|
||||
char * p = data;
|
||||
char *p = data;
|
||||
int s = size;
|
||||
|
||||
if (addr == my_address)
|
||||
|
|
@ -1327,17 +1327,17 @@ int processcluster(char * data, int size, u32 addr)
|
|||
if (s < 8)
|
||||
goto shortpacket;
|
||||
|
||||
type = * ((u32*) p);
|
||||
p += sizeof(u32);
|
||||
s -= sizeof(u32);
|
||||
type = *((uint32_t *) p);
|
||||
p += sizeof(uint32_t);
|
||||
s -= sizeof(uint32_t);
|
||||
|
||||
more = * ((u32*) p);
|
||||
p += sizeof(u32);
|
||||
s -= sizeof(u32);
|
||||
more = *((uint32_t *) p);
|
||||
p += sizeof(uint32_t);
|
||||
s -= sizeof(uint32_t);
|
||||
|
||||
switch (type) {
|
||||
case C_PING: // Update the peers table.
|
||||
return cluster_add_peer(addr, more, (pingt*)p, s);
|
||||
return cluster_add_peer(addr, more, (pingt *) p, s);
|
||||
|
||||
case C_LASTSEEN: // Catch up a slave (slave missed a packet).
|
||||
return cluster_catchup_slave(more, addr);
|
||||
|
|
@ -1346,7 +1346,7 @@ int processcluster(char * data, int size, u32 addr)
|
|||
struct sockaddr_in a;
|
||||
a.sin_addr.s_addr = more;
|
||||
|
||||
a.sin_port = * (int*) p;
|
||||
a.sin_port = *(int *) p;
|
||||
s -= sizeof(int);
|
||||
p += sizeof(int);
|
||||
|
||||
|
|
@ -1481,11 +1481,11 @@ int cmd_show_cluster(struct cli_def *cli, char *command, char **argv, int argc)
|
|||
//
|
||||
// Worst case is a 50% expansion in space required (trying to
|
||||
// compress { 0x00, 0x01 } * N )
|
||||
static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize)
|
||||
static int rle_compress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize)
|
||||
{
|
||||
int count;
|
||||
int orig_dsize = dsize;
|
||||
u8 * x,*src;
|
||||
uint8_t *x, *src;
|
||||
src = *src_p;
|
||||
|
||||
while (ssize > 0 && dsize > 2) {
|
||||
|
|
@ -1527,11 +1527,11 @@ static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize)
|
|||
// Return the number of dst bytes used.
|
||||
// Updates the 'src_p' pointer to point to the
|
||||
// first un-used byte.
|
||||
static int rle_decompress(u8 ** src_p, int ssize, u8 *dst, int dsize)
|
||||
static int rle_decompress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize)
|
||||
{
|
||||
int count;
|
||||
int orig_dsize = dsize;
|
||||
char * src = *src_p;
|
||||
char *src = *src_p;
|
||||
|
||||
while (ssize >0 && dsize > 0) { // While there's more to decompress, and there's room in the decompress buffer...
|
||||
count = *src++; --ssize; // get the count byte from the source.
|
||||
|
|
|
|||
46
cluster.h
46
cluster.h
|
|
@ -1,5 +1,5 @@
|
|||
// L2TPNS Clustering Stuff
|
||||
// $Id: cluster.h,v 1.8 2004/12/03 06:40:02 bodea Exp $
|
||||
// $Id: cluster.h,v 1.9 2004/12/16 08:49:53 bodea Exp $
|
||||
|
||||
#ifndef __CLUSTER_H__
|
||||
#define __CLUSTER_H__
|
||||
|
|
@ -34,44 +34,44 @@
|
|||
#define DEFAULT_MCAST_INTERFACE "eth0"
|
||||
|
||||
typedef struct {
|
||||
u32 version; // protocol version.
|
||||
u32 seq; // Sequence number for this heatbeat.
|
||||
u32 basetime; // What time I started
|
||||
u32 clusterid; // Id for this cluster?
|
||||
uint32_t version; // protocol version.
|
||||
uint32_t seq; // Sequence number for this heatbeat.
|
||||
uint32_t basetime; // What time I started
|
||||
uint32_t clusterid; // Id for this cluster?
|
||||
|
||||
u32 highsession; // Id of the highest in-use session.
|
||||
u32 freesession; // Id of the first free session.
|
||||
u32 hightunnel; // Id of the highest used tunnel.
|
||||
u32 size_sess; // Size of the session structure.
|
||||
uint32_t highsession; // Id of the highest in-use session.
|
||||
uint32_t freesession; // Id of the first free session.
|
||||
uint32_t hightunnel; // Id of the highest used tunnel.
|
||||
uint32_t size_sess; // Size of the session structure.
|
||||
|
||||
u32 size_tunn; // size of the tunnel structure.
|
||||
u32 interval; // ping/heartbeat interval
|
||||
u32 timeout; // heartbeat timeout
|
||||
uint32_t size_tunn; // size of the tunnel structure.
|
||||
uint32_t interval; // ping/heartbeat interval
|
||||
uint32_t timeout; // heartbeat timeout
|
||||
|
||||
u64 table_version; // # state changes processed by cluster
|
||||
uint64_t table_version; // # state changes processed by cluster
|
||||
|
||||
char reserved[128 - 13*sizeof(u32)]; // Pad out to 128 bytes.
|
||||
char reserved[128 - 13*sizeof(uint32_t)]; // Pad out to 128 bytes.
|
||||
} heartt;
|
||||
|
||||
typedef struct { /* Used to update byte counters on the */
|
||||
/* master. */
|
||||
u32 sid;
|
||||
u32 in;
|
||||
u32 out;
|
||||
uint32_t sid;
|
||||
uint32_t in;
|
||||
uint32_t out;
|
||||
} bytest;
|
||||
|
||||
typedef struct {
|
||||
u32 addr; //
|
||||
u32 ver; // version of structure.
|
||||
u32 undef; // Number of undefined structures. 0 if up-to-date.
|
||||
u32 basetime; // start time of this peer.
|
||||
in_addr_t addr; // peer address
|
||||
uint32_t ver; // version of structure.
|
||||
uint32_t undef; // Number of undefined structures. 0 if up-to-date.
|
||||
uint32_t basetime; // start time of this peer.
|
||||
} pingt;
|
||||
|
||||
int cluster_init(void);
|
||||
int processcluster(char *buf, int size, u32 addr);
|
||||
int processcluster(char *buf, int size, in_addr_t addr);
|
||||
int cluster_send_session(int sid);
|
||||
int cluster_send_tunnel(int tid);
|
||||
int master_forward_packet(char *data, int size, u32 addr, int port);
|
||||
int master_forward_packet(char *data, int size, in_addr_t addr, int port);
|
||||
int master_throttle_packet(int tid, char *data, int size);
|
||||
int master_garden_packet(sessionidt s, char *data, int size);
|
||||
void master_update_counts(void);
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
// L2TPNS: control
|
||||
|
||||
char const *cvs_id_control = "$Id: control.c,v 1.3 2004/11/17 08:23:34 bodea Exp $";
|
||||
char const *cvs_id_control = "$Id: control.c,v 1.4 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
#include <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;
|
||||
|
|
@ -102,7 +102,7 @@ int unpack_control(struct nsctl *control, char *data, int len)
|
|||
if (len < sz + 1)
|
||||
return NSCTL_ERR_SHORT;
|
||||
|
||||
s = (u8) *p;
|
||||
s = (uint8_t) *p;
|
||||
*p++ = 0; // null terminate previous arg
|
||||
sz++;
|
||||
|
||||
|
|
|
|||
14
control.h
14
control.h
|
|
@ -27,27 +27,27 @@
|
|||
#define NSCTL_MAX_PKT_SZ 4096
|
||||
|
||||
struct nsctl_packet {
|
||||
u16 magic;
|
||||
u8 type;
|
||||
u8 argc;
|
||||
uint16_t magic;
|
||||
uint8_t type;
|
||||
uint8_t argc;
|
||||
char argv[NSCTL_MAX_PKT_SZ - 4];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define NSCTL_MAX_ARG_SZ 512
|
||||
|
||||
struct nsctl_args {
|
||||
u8 len;
|
||||
uint8_t len;
|
||||
char value[NSCTL_MAX_ARG_SZ - 1];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
/* parsed packet */
|
||||
struct nsctl {
|
||||
u8 type;
|
||||
u8 argc;
|
||||
uint8_t type;
|
||||
uint8_t argc;
|
||||
char *argv[0xff];
|
||||
};
|
||||
|
||||
int pack_control(char *data, int len, u8 type, int argc, char *argv[]);
|
||||
int pack_control(char *data, int len, uint8_t type, int argc, char *argv[]);
|
||||
int unpack_control(struct nsctl *packet, char *data, int len);
|
||||
void dump_control(struct nsctl *control, FILE *stream);
|
||||
|
||||
|
|
|
|||
4
garden.c
4
garden.c
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
/* walled garden */
|
||||
|
||||
char const *cvs_id = "$Id: garden.c,v 1.19 2004/12/01 02:52:46 bodea Exp $";
|
||||
char const *cvs_id = "$Id: garden.c,v 1.20 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
int plugin_api_version = PLUGIN_API_VERSION;
|
||||
static struct pluginfuncs *p = 0;
|
||||
|
|
@ -213,7 +213,7 @@ int garden_session(sessiont *s, int flag)
|
|||
if (flag != F_CLEANUP)
|
||||
{
|
||||
/* OK, we're up! */
|
||||
u16 r = p->radiusnew(p->get_id_by_session(s));
|
||||
uint16_t r = p->radiusnew(p->get_id_by_session(s));
|
||||
p->radiussend(r, RADIUSSTART);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
icmp.c
16
icmp.c
|
|
@ -1,6 +1,6 @@
|
|||
// L2TPNS: icmp
|
||||
|
||||
char const *cvs_id_icmp = "$Id: icmp.c,v 1.5 2004/11/16 07:54:32 bodea Exp $";
|
||||
char const *cvs_id_icmp = "$Id: icmp.c,v 1.6 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
|
|
@ -17,9 +17,9 @@ char const *cvs_id_icmp = "$Id: icmp.c,v 1.5 2004/11/16 07:54:32 bodea Exp $";
|
|||
|
||||
#include "l2tpns.h"
|
||||
|
||||
static __u16 _checksum(unsigned char *addr, int count);
|
||||
static uint16_t _checksum(unsigned char *addr, int count);
|
||||
|
||||
void host_unreachable(ipt destination, u16 id, ipt source, char *packet, int packet_len)
|
||||
void host_unreachable(in_addr_t destination, uint16_t id, in_addr_t source, char *packet, int packet_len)
|
||||
{
|
||||
char buf[128] = {0};
|
||||
struct iphdr *iph;
|
||||
|
|
@ -60,21 +60,21 @@ void host_unreachable(ipt destination, u16 id, ipt source, char *packet, int pac
|
|||
|
||||
icmp->type = ICMP_DEST_UNREACH;
|
||||
icmp->code = ICMP_HOST_UNREACH;
|
||||
icmp->checksum = _checksum((char *)icmp, sizeof(struct icmphdr) + ((packet_len < 64) ? packet_len : 64));
|
||||
icmp->checksum = _checksum((char *) icmp, sizeof(struct icmphdr) + ((packet_len < 64) ? packet_len : 64));
|
||||
|
||||
iph->check = _checksum((char *)iph, sizeof(struct iphdr));
|
||||
iph->check = _checksum((char *) iph, sizeof(struct iphdr));
|
||||
|
||||
sendto(icmp_socket, (char *)buf, len, 0, (struct sockaddr *)&whereto, sizeof(struct sockaddr));
|
||||
close(icmp_socket);
|
||||
}
|
||||
|
||||
static __u16 _checksum(unsigned char *addr, int count)
|
||||
static uint16_t _checksum(unsigned char *addr, int count)
|
||||
{
|
||||
register long sum = 0;
|
||||
|
||||
for (; count > 1; count -= 2)
|
||||
{
|
||||
sum += ntohs(*(u32 *)addr);
|
||||
sum += ntohs(*(uint32_t *) addr);
|
||||
addr += 2;
|
||||
}
|
||||
|
||||
|
|
@ -87,5 +87,5 @@ static __u16 _checksum(unsigned char *addr, int count)
|
|||
// one's complement the result
|
||||
sum = ~sum;
|
||||
|
||||
return htons((u16) sum);
|
||||
return htons((uint16_t) sum);
|
||||
}
|
||||
|
|
|
|||
222
l2tpns.h
222
l2tpns.h
|
|
@ -1,5 +1,5 @@
|
|||
// L2TPNS Global Stuff
|
||||
// $Id: l2tpns.h,v 1.46 2004/12/13 02:27:31 bodea Exp $
|
||||
// $Id: l2tpns.h,v 1.47 2004/12/16 08:49:53 bodea Exp $
|
||||
|
||||
#ifndef __L2TPNS_H__
|
||||
#define __L2TPNS_H__
|
||||
|
|
@ -108,22 +108,16 @@ enum
|
|||
};
|
||||
|
||||
// Types
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef unsigned char u8;
|
||||
typedef u32 ipt;
|
||||
typedef u16 portt;
|
||||
typedef u16 sessionidt;
|
||||
typedef u16 tunnelidt;
|
||||
typedef u32 clockt;
|
||||
typedef u8 hasht[16];
|
||||
typedef uint16_t sessionidt;
|
||||
typedef uint16_t tunnelidt;
|
||||
typedef uint32_t clockt;
|
||||
typedef uint8_t hasht[16];
|
||||
|
||||
// CLI actions
|
||||
struct cli_session_actions {
|
||||
char action;
|
||||
ipt snoop_ip;
|
||||
u16 snoop_port;
|
||||
in_addr_t snoop_ip;
|
||||
uint16_t snoop_port;
|
||||
int throttle_in;
|
||||
int throttle_out;
|
||||
int filter_in;
|
||||
|
|
@ -150,16 +144,16 @@ struct cli_tunnel_actions {
|
|||
// structures
|
||||
typedef struct // route
|
||||
{
|
||||
ipt ip;
|
||||
ipt mask;
|
||||
in_addr_t ip;
|
||||
in_addr_t mask;
|
||||
}
|
||||
routet;
|
||||
|
||||
typedef struct controls // control message
|
||||
typedef struct controls // control message
|
||||
{
|
||||
struct controls *next; // next in queue
|
||||
u16 length; // length
|
||||
u8 buf[MAXCONTROL];
|
||||
struct controls *next; // next in queue
|
||||
uint16_t length; // length
|
||||
uint8_t buf[MAXCONTROL];
|
||||
}
|
||||
controlt;
|
||||
|
||||
|
|
@ -168,45 +162,45 @@ typedef struct
|
|||
sessionidt next; // next session in linked list
|
||||
sessionidt far; // far end session ID
|
||||
tunnelidt tunnel; // near end tunnel ID
|
||||
ipt ip; // IP of session set by RADIUS response (host byte order).
|
||||
in_addr_t ip; // IP of session set by RADIUS response (host byte order).
|
||||
int ip_pool_index; // index to IP pool
|
||||
unsigned long unique_id; // unique session id
|
||||
u16 nr; // next receive
|
||||
u16 ns; // next send
|
||||
u32 magic; // ppp magic number
|
||||
u32 cin, cout; // byte counts
|
||||
u32 pin, pout; // packet counts
|
||||
u32 total_cin; // This counter is never reset while a session is open
|
||||
u32 total_cout; // This counter is never reset while a session is open
|
||||
u32 id; // session id
|
||||
u16 throttle_in; // upstream throttle rate (kbps)
|
||||
u16 throttle_out; // downstream throttle rate
|
||||
uint16_t nr; // next receive
|
||||
uint16_t ns; // next send
|
||||
uint32_t magic; // ppp magic number
|
||||
uint32_t cin, cout; // byte counts
|
||||
uint32_t pin, pout; // packet counts
|
||||
uint32_t total_cin; // This counter is never reset while a session is open
|
||||
uint32_t total_cout; // This counter is never reset while a session is open
|
||||
uint32_t id; // session id
|
||||
uint16_t throttle_in; // upstream throttle rate (kbps)
|
||||
uint16_t throttle_out; // downstream throttle rate
|
||||
clockt opened; // when started
|
||||
clockt die; // being closed, when to finally free
|
||||
time_t last_packet; // Last packet from the user (used for idle timeouts)
|
||||
ipt dns1, dns2; // DNS servers
|
||||
in_addr_t dns1, dns2; // DNS servers
|
||||
routet route[MAXROUTE]; // static routes
|
||||
u16 radius; // which radius session is being used (0 for not waiting on authentication)
|
||||
u16 mru; // maximum receive unit
|
||||
u16 tbf_in; // filter bucket for throttling in from the user.
|
||||
u16 tbf_out; // filter bucket for throttling out to the user.
|
||||
u8 l2tp_flags; // various bit flags from the ICCN on the l2tp tunnel.
|
||||
u8 reserved_old_snoop; // No longer used - remove at some time
|
||||
u8 walled_garden; // is this session gardened?
|
||||
u8 flags1; // additional flags (currently unused);
|
||||
uint16_t radius; // which radius session is being used (0 for not waiting on authentication)
|
||||
uint16_t mru; // maximum receive unit
|
||||
uint16_t tbf_in; // filter bucket for throttling in from the user.
|
||||
uint16_t tbf_out; // filter bucket for throttling out to the user.
|
||||
uint8_t l2tp_flags; // various bit flags from the ICCN on the l2tp tunnel.
|
||||
uint8_t reserved_old_snoop; // No longer used - remove at some time
|
||||
uint8_t walled_garden; // is this session gardened?
|
||||
uint8_t flags1; // additional flags (currently unused);
|
||||
char random_vector[MAXTEL];
|
||||
int random_vector_length;
|
||||
char user[129]; // user (needed in seesion for radius stop messages) (can we reduce this? --mo)
|
||||
char called[MAXTEL]; // called number
|
||||
char calling[MAXTEL]; // calling number
|
||||
u32 tx_connect_speed;
|
||||
u32 rx_connect_speed;
|
||||
u32 flags; // Various session flags.
|
||||
ipt snoop_ip; // Interception destination IP
|
||||
u16 snoop_port; // Interception destination port
|
||||
u16 sid; // near end session id.
|
||||
u8 filter_in; // input filter index (to ip_filters[N-1]; 0 if none)
|
||||
u8 filter_out; // output filter index
|
||||
uint32_t tx_connect_speed;
|
||||
uint32_t rx_connect_speed;
|
||||
uint32_t flags; // Various session flags.
|
||||
in_addr_t snoop_ip; // Interception destination IP
|
||||
uint16_t snoop_port; // Interception destination port
|
||||
uint16_t sid; // near end session id.
|
||||
uint8_t filter_in; // input filter index (to ip_filters[N-1]; 0 if none)
|
||||
uint8_t filter_out; // output filter index
|
||||
char reserved[18]; // Space to expand structure without changing HB_VERSION
|
||||
}
|
||||
sessiont;
|
||||
|
|
@ -217,8 +211,8 @@ sessiont;
|
|||
|
||||
typedef struct
|
||||
{
|
||||
u32 cin;
|
||||
u32 cout;
|
||||
uint32_t cin;
|
||||
uint32_t cout;
|
||||
} sessioncountt;
|
||||
|
||||
#define SESSIONPFC 1 // PFC negotiated flags
|
||||
|
|
@ -228,11 +222,11 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
tunnelidt far; // far end tunnel ID
|
||||
ipt ip; // Ip for far end
|
||||
portt port; // port for far end
|
||||
u16 window; // Rx window
|
||||
u16 nr; // next receive
|
||||
u16 ns; // next send
|
||||
in_addr_t ip; // Ip for far end
|
||||
uint16_t port; // port for far end
|
||||
uint16_t window; // Rx window
|
||||
uint16_t nr; // next receive
|
||||
uint16_t ns; // next send
|
||||
int state; // current state (tunnelstate enum)
|
||||
clockt last; // when last control message sent (used for resend timeout)
|
||||
clockt retry; // when to try resenting pending control
|
||||
|
|
@ -240,8 +234,8 @@ typedef struct
|
|||
clockt lastrec; // when the last control message was received
|
||||
char hostname[128]; // tunnel hostname
|
||||
char vendor[128]; // LAC vendor
|
||||
u8 try; // number of retrys on a control message
|
||||
u16 controlc; // outstaind messages in queue
|
||||
uint8_t try; // number of retrys on a control message
|
||||
uint16_t controlc; // outstaind messages in queue
|
||||
controlt *controls; // oldest message
|
||||
controlt *controle; // newest message
|
||||
}
|
||||
|
|
@ -255,16 +249,16 @@ typedef struct // outstanding RADIUS requests
|
|||
clockt retry; // when to try next
|
||||
char calling[MAXTEL]; // calling number
|
||||
char pass[129]; // password
|
||||
u8 id; // ID for PPP response
|
||||
u8 try; // which try we are on
|
||||
u8 state; // state of radius requests
|
||||
u8 chap; // set if CHAP used (is CHAP identifier)
|
||||
uint8_t id; // ID for PPP response
|
||||
uint8_t try; // which try we are on
|
||||
uint8_t state; // state of radius requests
|
||||
uint8_t chap; // set if CHAP used (is CHAP identifier)
|
||||
}
|
||||
radiust;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ipt address; // Host byte order..
|
||||
in_addr_t address; // Host byte order..
|
||||
char assigned; // 1 if assigned, 0 if free
|
||||
sessionidt session;
|
||||
clockt last; // last used
|
||||
|
|
@ -423,20 +417,20 @@ typedef struct
|
|||
|
||||
char radiussecret[64];
|
||||
int radius_accounting;
|
||||
ipt radiusserver[MAXRADSERVER]; // radius servers
|
||||
u16 radiusport[MAXRADSERVER]; // radius base ports
|
||||
u8 numradiusservers; // radius server count
|
||||
in_addr_t radiusserver[MAXRADSERVER]; // radius servers
|
||||
uint16_t radiusport[MAXRADSERVER]; // radius base ports
|
||||
uint8_t numradiusservers; // radius server count
|
||||
short num_radfds; // Number of radius filehandles allocated
|
||||
|
||||
ipt default_dns1, default_dns2;
|
||||
in_addr_t default_dns1, default_dns2;
|
||||
|
||||
unsigned long rl_rate; // default throttle rate
|
||||
int num_tbfs; // number of throttle buckets
|
||||
|
||||
int save_state;
|
||||
char accounting_dir[128];
|
||||
ipt bind_address;
|
||||
ipt peer_address;
|
||||
in_addr_t bind_address;
|
||||
in_addr_t peer_address;
|
||||
int send_garp; // Set to true to garp for vip address on startup
|
||||
|
||||
int target_uid;
|
||||
|
|
@ -449,12 +443,12 @@ typedef struct
|
|||
int lock_pages; // Lock pages into memory.
|
||||
int icmp_rate; // Max number of ICMP unreachable per second to send>
|
||||
|
||||
u32 cluster_address; // Multicast address of cluster.
|
||||
in_addr_t cluster_address; // Multicast address of cluster.
|
||||
// Send to this address to have everyone hear.
|
||||
char cluster_interface[64]; // Which interface to listen for multicast on.
|
||||
int cluster_iam_master; // Are we the cluster master???
|
||||
int cluster_iam_uptodate; // Set if we've got a full set of state from the master.
|
||||
u32 cluster_master_address; // The network address of the cluster master.
|
||||
in_addr_t cluster_master_address; // The network address of the cluster master.
|
||||
// Zero if i am the cluster master.
|
||||
int cluster_seq_number; // Sequence number of the next heartbeat we'll send out
|
||||
// (or the seq number we're next expecting if we're a slave).
|
||||
|
|
@ -467,17 +461,17 @@ typedef struct
|
|||
|
||||
int cluster_hb_interval; // How often to send a heartbeat.
|
||||
int cluster_hb_timeout; // How many missed heartbeats trigger an election.
|
||||
u64 cluster_table_version; // # state changes processed by cluster
|
||||
uint64_t cluster_table_version; // # state changes processed by cluster
|
||||
|
||||
#ifdef BGP
|
||||
#define BGP_NUM_PEERS 2
|
||||
u16 as_number;
|
||||
uint16_t as_number;
|
||||
struct {
|
||||
char name[64];
|
||||
u16 as;
|
||||
int keepalive;
|
||||
int hold;
|
||||
} neighbour[BGP_NUM_PEERS];
|
||||
char name[64];
|
||||
uint16_t as;
|
||||
int keepalive;
|
||||
int hold;
|
||||
} neighbour[BGP_NUM_PEERS];
|
||||
#endif
|
||||
} configt;
|
||||
|
||||
|
|
@ -492,15 +486,15 @@ typedef struct
|
|||
|
||||
typedef struct
|
||||
{
|
||||
u8 op; // operation
|
||||
uint8_t op; // operation
|
||||
#define FILTER_PORT_OP_NONE 0 // all ports match
|
||||
#define FILTER_PORT_OP_EQ 1
|
||||
#define FILTER_PORT_OP_NEQ 2
|
||||
#define FILTER_PORT_OP_GT 3
|
||||
#define FILTER_PORT_OP_LT 4
|
||||
#define FILTER_PORT_OP_RANGE 5
|
||||
portt port; // port (host byte order)
|
||||
portt port2; // range
|
||||
uint16_t port; // port (host byte order)
|
||||
uint16_t port2; // range
|
||||
} ip_filter_portt;
|
||||
|
||||
typedef struct
|
||||
|
|
@ -508,21 +502,21 @@ typedef struct
|
|||
int action; // permit/deny
|
||||
#define FILTER_ACTION_DENY 1
|
||||
#define FILTER_ACTION_PERMIT 2
|
||||
u8 proto; // protocol: IPPROTO_* (netinet/in.h)
|
||||
ipt src_ip; // source ip (network byte order)
|
||||
ipt src_wild;
|
||||
uint8_t proto; // protocol: IPPROTO_* (netinet/in.h)
|
||||
in_addr_t src_ip; // source ip (network byte order)
|
||||
in_addr_t src_wild;
|
||||
ip_filter_portt src_ports;
|
||||
ipt dst_ip; // dest ip
|
||||
ipt dst_wild;
|
||||
in_addr_t dst_ip; // dest ip
|
||||
in_addr_t dst_wild;
|
||||
ip_filter_portt dst_ports;
|
||||
u8 frag; // apply to non-initial fragments
|
||||
u8 tcp_flag_op; // match type: any, all, established
|
||||
uint8_t frag; // apply to non-initial fragments
|
||||
uint8_t tcp_flag_op; // match type: any, all, established
|
||||
#define FILTER_FLAG_OP_ANY 1
|
||||
#define FILTER_FLAG_OP_ALL 2
|
||||
#define FILTER_FLAG_OP_EST 3
|
||||
u8 tcp_sflags; // flags set
|
||||
u8 tcp_cflags; // flags clear
|
||||
u32 counter; // match count
|
||||
uint8_t tcp_sflags; // flags set
|
||||
uint8_t tcp_cflags; // flags clear
|
||||
uint32_t counter; // match count
|
||||
} ip_filter_rulet;
|
||||
|
||||
#define TCP_FLAG_FIN 0x01
|
||||
|
|
@ -543,42 +537,42 @@ typedef struct
|
|||
} ip_filtert;
|
||||
|
||||
// arp.c
|
||||
void sendarp(int ifr_idx, const unsigned char* mac, ipt ip);
|
||||
void sendarp(int ifr_idx, const unsigned char* mac, in_addr_t ip);
|
||||
|
||||
|
||||
// ppp.c
|
||||
void processpap(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
||||
void processchap(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
||||
void processlcp(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
||||
void processipcp(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
||||
void processipin(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
||||
void processccp(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
||||
void processpap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||
void processchap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||
void processlcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||
void processipcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||
void processipin(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||
void processccp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||
void sendchap(tunnelidt t, sessionidt s);
|
||||
u8 *makeppp(u8 * b, int size, u8 * p, int l, tunnelidt t, sessionidt s, u16 mtype);
|
||||
uint8_t *makeppp(uint8_t *b, int size, uint8_t *p, int l, tunnelidt t, sessionidt s, uint16_t mtype);
|
||||
void initlcp(tunnelidt t, sessionidt s);
|
||||
void send_ipin(sessionidt s, u8 * buf, int len);
|
||||
void send_ipin(sessionidt s, uint8_t *buf, int len);
|
||||
|
||||
|
||||
// radius.c
|
||||
void initrad(void);
|
||||
void radiussend(u16 r, u8 state);
|
||||
void processrad(u8 *buf, int len, char socket_index);
|
||||
void radiusretry(u16 r);
|
||||
u16 radiusnew(sessionidt s);
|
||||
void radiusclear(u16 r, sessionidt s);
|
||||
void radiussend(uint16_t r, uint8_t state);
|
||||
void processrad(uint8_t *buf, int len, char socket_index);
|
||||
void radiusretry(uint16_t r);
|
||||
uint16_t radiusnew(sessionidt s);
|
||||
void radiusclear(uint16_t r, sessionidt s);
|
||||
|
||||
|
||||
// l2tpns.c
|
||||
clockt backoff(u8 try);
|
||||
sessionidt sessionbyip(ipt ip);
|
||||
clockt backoff(uint8_t try);
|
||||
sessionidt sessionbyip(in_addr_t ip);
|
||||
sessionidt sessionbyuser(char *username);
|
||||
void sessionshutdown(sessionidt s, char *reason);
|
||||
void send_garp(ipt ip);
|
||||
void tunnelsend(u8 * buf, u16 l, tunnelidt t);
|
||||
void send_garp(in_addr_t ip);
|
||||
void tunnelsend(uint8_t *buf, uint16_t l, tunnelidt t);
|
||||
void sendipcp(tunnelidt t, sessionidt s);
|
||||
void processudp(u8 * buf, int len, struct sockaddr_in *addr);
|
||||
void snoop_send_packet(char *packet, u16 size, ipt destination, u16 port);
|
||||
int ip_filter(u8 *buf, int len, u8 filter);
|
||||
void processudp(uint8_t *buf, int len, struct sockaddr_in *addr);
|
||||
void snoop_send_packet(char *packet, uint16_t size, in_addr_t destination, uint16_t port);
|
||||
int ip_filter(uint8_t *buf, int len, uint8_t filter);
|
||||
int cmd_show_ipcache(struct cli_def *cli, char *command, char **argv, int argc);
|
||||
int cmd_show_hist_idle(struct cli_def *cli, char *command, char **argv, int argc);
|
||||
int cmd_show_hist_open(struct cli_def *cli, char *command, char **argv, int argc);
|
||||
|
|
@ -607,7 +601,7 @@ int cli_arg_help(struct cli_def *cli, int cr_ok, char *entry, ...);
|
|||
|
||||
|
||||
// icmp.c
|
||||
void host_unreachable(ipt destination, u16 id, ipt source, char *packet, int packet_len);
|
||||
void host_unreachable(in_addr_t destination, uint16_t id, in_addr_t source, char *packet, int packet_len);
|
||||
|
||||
|
||||
extern tunnelt *tunnel;
|
||||
|
|
@ -635,10 +629,10 @@ if (count++ < max) { \
|
|||
extern configt *config;
|
||||
extern time_t basetime; // Time when this process started.
|
||||
extern time_t time_now; // Seconds since EPOCH.
|
||||
extern u32 last_id;
|
||||
extern uint32_t last_id;
|
||||
extern struct Tstats *_statistics;
|
||||
extern ipt my_address;
|
||||
extern int tun_write(u8 *data, int size);
|
||||
extern in_addr_t my_address;
|
||||
extern int tun_write(uint8_t *data, int size);
|
||||
extern int clifd;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -43,5 +43,5 @@ rm -rf %{buildroot}
|
|||
%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
|
||||
|
|
|
|||
6
plugin.h
6
plugin.h
|
|
@ -28,12 +28,12 @@ struct pluginfuncs
|
|||
{
|
||||
void (*log)(int level, sessionidt s, tunnelidt t, const char *format, ...);
|
||||
void (*log_hex)(int level, const char *title, const char *data, int maxsize);
|
||||
char *(*fmtaddr)(ipt addr, int n);
|
||||
char *(*fmtaddr)(in_addr_t addr, int n);
|
||||
sessionidt (*get_session_by_username)(char *username);
|
||||
sessiont *(*get_session_by_id)(sessionidt s);
|
||||
sessionidt (*get_id_by_session)(sessiont *s);
|
||||
u16 (*radiusnew)(sessionidt s);
|
||||
void (*radiussend)(u16 r, u8 state);
|
||||
uint16_t (*radiusnew)(sessionidt s);
|
||||
void (*radiussend)(uint16_t r, uint8_t state);
|
||||
void *(*getconfig)(char *key, enum config_typet type);
|
||||
void (*sessionkill)(sessionidt s, char *reason);
|
||||
void (*throttle)(sessionidt s, int rate_in, int rate_out);
|
||||
|
|
|
|||
175
ppp.c
175
ppp.c
|
|
@ -1,6 +1,6 @@
|
|||
// L2TPNS PPP Stuff
|
||||
|
||||
char const *cvs_id_ppp = "$Id: ppp.c,v 1.38 2004/11/30 19:34:57 bodea Exp $";
|
||||
char const *cvs_id_ppp = "$Id: ppp.c,v 1.39 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
|
@ -19,18 +19,18 @@ extern sessiont *session;
|
|||
extern radiust *radius;
|
||||
extern int tunfd;
|
||||
extern char hostname[];
|
||||
extern u32 eth_tx;
|
||||
extern uint32_t eth_tx;
|
||||
extern time_t time_now;
|
||||
extern configt *config;
|
||||
|
||||
static void initccp(tunnelidt t, sessionidt s);
|
||||
|
||||
// Process PAP messages
|
||||
void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||
void processpap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l)
|
||||
{
|
||||
char user[129];
|
||||
char pass[129];
|
||||
u16 hl;
|
||||
uint16_t hl;
|
||||
|
||||
CSTAT(call_processpap);
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
return ;
|
||||
}
|
||||
|
||||
if ((hl = ntohs(*(u16 *) (p + 2))) > l)
|
||||
if ((hl = ntohs(*(uint16_t *) (p + 2))) > l)
|
||||
{
|
||||
LOG(1, s, t, "Length mismatch PAP %u/%u\n", hl, l);
|
||||
STAT(tunnel_rx_errors);
|
||||
|
|
@ -58,7 +58,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
}
|
||||
|
||||
{
|
||||
u8 *b = p;
|
||||
uint8_t *b = p;
|
||||
b += 4;
|
||||
if (*b && *b < sizeof(user))
|
||||
memcpy(user, b + 1, *b);
|
||||
|
|
@ -72,18 +72,18 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
if (session[s].ip || !session[s].radius)
|
||||
{
|
||||
// respond now, either no RADIUS available or already authenticated
|
||||
u8 b[MAXCONTROL];
|
||||
u8 id = p[1];
|
||||
u8 *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP);
|
||||
uint8_t b[MAXCONTROL];
|
||||
uint8_t id = p[1];
|
||||
uint8_t *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP);
|
||||
if (!p) return;
|
||||
|
||||
if (session[s].ip)
|
||||
*p = 2; // ACK
|
||||
*p = 2; // ACK
|
||||
else
|
||||
*p = 3; // cant authorise
|
||||
*p = 3; // cant authorise
|
||||
p[1] = id;
|
||||
*(u16 *) (p + 2) = htons(5); // length
|
||||
p[4] = 0; // no message
|
||||
*(uint16_t *) (p + 2) = htons(5); // length
|
||||
p[4] = 0; // no message
|
||||
if (session[s].ip)
|
||||
{
|
||||
LOG(3, s, t, "Already an IP allocated: %s (%d)\n",
|
||||
|
|
@ -101,7 +101,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
else
|
||||
{
|
||||
// set up RADIUS request
|
||||
u16 r = session[s].radius;
|
||||
uint16_t r = session[s].radius;
|
||||
|
||||
// Run PRE_AUTH plugins
|
||||
struct param_pre_auth packet = { &tunnel[t], &session[s], strdup(user), strdup(pass), PPPPAP, 1 };
|
||||
|
|
@ -127,10 +127,10 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
}
|
||||
|
||||
// Process CHAP messages
|
||||
void processchap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||
void processchap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l)
|
||||
{
|
||||
u16 r;
|
||||
u16 hl;
|
||||
uint16_t r;
|
||||
uint16_t hl;
|
||||
|
||||
CSTAT(call_processchap);
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ void processchap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
return ;
|
||||
}
|
||||
|
||||
if ((hl = ntohs(*(u16 *) (p + 2))) > l)
|
||||
if ((hl = ntohs(*(uint16_t *) (p + 2))) > l)
|
||||
{
|
||||
LOG(1, s, t, "Length mismatch CHAP %u/%u\n", hl, l);
|
||||
STAT(tunnel_rx_errors);
|
||||
|
|
@ -240,13 +240,13 @@ static char *ppp_lcp_types[] = {
|
|||
"IdentRequest",
|
||||
};
|
||||
|
||||
static void dumplcp(u8 *p, int l)
|
||||
static void dumplcp(uint8_t *p, int l)
|
||||
{
|
||||
int x = l - 4;
|
||||
u8 *o = (p + 4);
|
||||
uint8_t *o = (p + 4);
|
||||
|
||||
LOG_HEX(5, "PPP LCP Packet", p, l);
|
||||
LOG(4, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p, ppp_lcp_types[(int)*p], ntohs( ((u16 *) p)[1]) );
|
||||
LOG(4, 0, 0, "PPP LCP Packet type %d (%s len %d)\n", *p, ppp_lcp_types[(int)*p], ntohs( ((uint16_t *) p)[1]) );
|
||||
LOG(4, 0, 0, "Length: %d\n", l);
|
||||
if (*p != ConfigReq && *p != ConfigRej && *p != ConfigAck)
|
||||
return;
|
||||
|
|
@ -271,14 +271,14 @@ static void dumplcp(u8 *p, int l)
|
|||
{
|
||||
case 1: // Maximum-Receive-Unit
|
||||
if (length == 4)
|
||||
LOG(4, 0, 0, " %s %d\n", lcp_types[type], ntohs(*(u16 *)(o + 2)));
|
||||
LOG(4, 0, 0, " %s %d\n", lcp_types[type], ntohs(*(uint16_t *)(o + 2)));
|
||||
else
|
||||
LOG(4, 0, 0, " %s odd length %d\n", lcp_types[type], length);
|
||||
break;
|
||||
case 2: // Async-Control-Character-Map
|
||||
if (length == 6)
|
||||
{
|
||||
u32 asyncmap = ntohl(*(u32 *)(o + 2));
|
||||
uint32_t asyncmap = ntohl(*(uint32_t *)(o + 2));
|
||||
LOG(4, 0, 0, " %s %x\n", lcp_types[type], asyncmap);
|
||||
}
|
||||
else
|
||||
|
|
@ -287,7 +287,7 @@ static void dumplcp(u8 *p, int l)
|
|||
case 3: // Authentication-Protocol
|
||||
if (length == 4)
|
||||
{
|
||||
int proto = ntohs(*(u16 *)(o + 2));
|
||||
int proto = ntohs(*(uint16_t *)(o + 2));
|
||||
LOG(4, 0, 0, " %s 0x%x (%s)\n", lcp_types[type], proto,
|
||||
proto == PPPCHAP ? "CHAP" :
|
||||
proto == PPPPAP ? "PAP" : "UNKNOWN");
|
||||
|
|
@ -297,14 +297,14 @@ static void dumplcp(u8 *p, int l)
|
|||
break;
|
||||
case 4: // Quality-Protocol
|
||||
{
|
||||
u32 qp = ntohl(*(u32 *)(o + 2));
|
||||
uint32_t qp = ntohl(*(uint32_t *)(o + 2));
|
||||
LOG(4, 0, 0, " %s %x\n", lcp_types[type], qp);
|
||||
}
|
||||
break;
|
||||
case 5: // Magic-Number
|
||||
if (length == 6)
|
||||
{
|
||||
u32 magicno = ntohl(*(u32 *)(o + 2));
|
||||
uint32_t magicno = ntohl(*(uint32_t *)(o + 2));
|
||||
LOG(4, 0, 0, " %s %x\n", lcp_types[type], magicno);
|
||||
}
|
||||
else
|
||||
|
|
@ -324,12 +324,12 @@ static void dumplcp(u8 *p, int l)
|
|||
}
|
||||
|
||||
// Process LCP messages
|
||||
void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||
void processlcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l)
|
||||
{
|
||||
u8 b[MAXCONTROL];
|
||||
u8 *q = NULL;
|
||||
u32 magicno = 0;
|
||||
u16 hl;
|
||||
uint8_t b[MAXCONTROL];
|
||||
uint8_t *q = NULL;
|
||||
uint32_t magicno = 0;
|
||||
uint16_t hl;
|
||||
|
||||
CSTAT(call_processlcp);
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
return ;
|
||||
}
|
||||
|
||||
if ((hl = ntohs(*(u16 *) (p + 2))) > l)
|
||||
if ((hl = ntohs(*(uint16_t *) (p + 2))) > l)
|
||||
{
|
||||
LOG(1, s, t, "Length mismatch LCP %u/%u\n", hl, l);
|
||||
STAT(tunnel_rx_errors);
|
||||
|
|
@ -357,8 +357,8 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
else if (*p == ConfigReq)
|
||||
{
|
||||
int x = l - 4;
|
||||
u8 *o = (p + 4);
|
||||
u8 *response = 0;
|
||||
uint8_t *o = (p + 4);
|
||||
uint8_t *response = 0;
|
||||
|
||||
LOG(3, s, t, "LCP: ConfigReq (%d bytes)...\n", l);
|
||||
if (config->debug > 3) dumplcp(p, l);
|
||||
|
|
@ -372,11 +372,11 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
switch (type)
|
||||
{
|
||||
case 1: // Maximum-Receive-Unit
|
||||
session[s].mru = ntohs(*(u16 *)(o + 2));
|
||||
session[s].mru = ntohs(*(uint16_t *)(o + 2));
|
||||
break;
|
||||
|
||||
case 2: // Async-Control-Character-Map
|
||||
if (!ntohl(*(u32 *)(o + 2))) // all bits zero is OK
|
||||
if (!ntohl(*(uint32_t *)(o + 2))) // all bits zero is OK
|
||||
break;
|
||||
|
||||
if (response && *response != ConfigNak) // rej already queued
|
||||
|
|
@ -401,12 +401,12 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
*q++ = 6;
|
||||
memset(q, 0, 4); // asyncmap 0
|
||||
q += 4;
|
||||
*((u16 *) (response + 2)) = htons(q - response); // LCP header length
|
||||
*((uint16_t *) (response + 2)) = htons(q - response); // LCP header length
|
||||
break;
|
||||
|
||||
case 3: // Authentication-Protocol
|
||||
{
|
||||
int proto = ntohs(*(u16 *)(o + 2));
|
||||
int proto = ntohs(*(uint16_t *)(o + 2));
|
||||
char proto_name[] = "0x0000";
|
||||
if (proto == PPPPAP)
|
||||
break;
|
||||
|
|
@ -436,14 +436,14 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
}
|
||||
|
||||
memcpy(q, o, length);
|
||||
*(u16 *)(q += 2) = htons(PPPPAP); // NAK -> Use PAP instead
|
||||
*(uint16_t *)(q += 2) = htons(PPPPAP); // NAK -> Use PAP instead
|
||||
q += length;
|
||||
*((u16 *) (response + 2)) = htons(q - response);
|
||||
*((uint16_t *) (response + 2)) = htons(q - response);
|
||||
}
|
||||
break;
|
||||
|
||||
case 5: // Magic-Number
|
||||
magicno = ntohl(*(u32 *)(o + 2));
|
||||
magicno = ntohl(*(uint32_t *)(o + 2));
|
||||
break;
|
||||
|
||||
case 4: // Quality-Protocol
|
||||
|
|
@ -469,7 +469,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
|
||||
memcpy(q, o, length);
|
||||
q += length;
|
||||
*((u16 *) (response + 2)) = htons(q - response); // LCP header length
|
||||
*((uint16_t *) (response + 2)) = htons(q - response); // LCP header length
|
||||
}
|
||||
x -= length;
|
||||
o += length;
|
||||
|
|
@ -512,7 +512,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
{
|
||||
LOG(5, s, t, "LCP: Received EchoReq. Sending EchoReply\n");
|
||||
*p = EchoReply; // reply
|
||||
*(u32 *) (p + 4) = htonl(session[s].magic); // our magic number
|
||||
*(uint32_t *) (p + 4) = htonl(session[s].magic); // our magic number
|
||||
q = makeppp(b, sizeof(b), p, l, t, s, PPPLCP);
|
||||
if (!q) return;
|
||||
tunnelsend(b, l + (q - b), t); // send it
|
||||
|
|
@ -543,9 +543,9 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
}
|
||||
|
||||
// find a PPP option, returns point to option, or 0 if not found
|
||||
static u8 *findppp(u8 *b, u8 mtype)
|
||||
static uint8_t *findppp(uint8_t *b, uint8_t mtype)
|
||||
{
|
||||
u16 l = ntohs(*(u16 *) (b + 2));
|
||||
uint16_t l = ntohs(*(uint16_t *) (b + 2));
|
||||
if (l < 4)
|
||||
return 0;
|
||||
b += 4;
|
||||
|
|
@ -563,9 +563,9 @@ static u8 *findppp(u8 *b, u8 mtype)
|
|||
}
|
||||
|
||||
// Process IPCP messages
|
||||
void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||
void processipcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l)
|
||||
{
|
||||
u16 hl;
|
||||
uint16_t hl;
|
||||
|
||||
CSTAT(call_processipcp);
|
||||
|
||||
|
|
@ -577,7 +577,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
return ;
|
||||
}
|
||||
|
||||
if ((hl = ntohs(*(u16 *) (p + 2))) > l)
|
||||
if ((hl = ntohs(*(uint16_t *) (p + 2))) > l)
|
||||
{
|
||||
LOG(1, s, t, "Length mismatch IPCP %u/%u\n", hl, l);
|
||||
STAT(tunnel_rx_errors);
|
||||
|
|
@ -588,7 +588,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
if (*p == ConfigAck)
|
||||
{
|
||||
// happy with our IPCP
|
||||
u16 r = session[s].radius;
|
||||
uint16_t r = session[s].radius;
|
||||
if ((!r || radius[r].state == RADIUSIPCP) && !session[s].walled_garden)
|
||||
{
|
||||
if (!r)
|
||||
|
|
@ -620,9 +620,8 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
}
|
||||
// form a config reply quoting the IP in the session
|
||||
{
|
||||
u8 b[MAXCONTROL];
|
||||
u8 *i,
|
||||
*q;
|
||||
uint8_t b[MAXCONTROL];
|
||||
uint8_t *i, *q;
|
||||
|
||||
q = p + 4;
|
||||
i = p + l;
|
||||
|
|
@ -635,7 +634,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
if (q < i)
|
||||
{
|
||||
// reject
|
||||
u16 n = 4;
|
||||
uint16_t n = 4;
|
||||
i = p + l;
|
||||
if (!(q = makeppp(b, sizeof(b), p, l, t, s, PPPIPCP)))
|
||||
return;
|
||||
|
|
@ -652,7 +651,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
}
|
||||
p += p[1];
|
||||
}
|
||||
*(u16 *) (q + 2) = htons(n);
|
||||
*(uint16_t *) (q + 2) = htons(n);
|
||||
LOG(4, s, t, "Sending ConfigRej\n");
|
||||
tunnelsend(b, n + (q - b), t); // send it
|
||||
}
|
||||
|
|
@ -662,9 +661,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
*p = ConfigAck;
|
||||
if ((i = findppp(p, 0x81))) // Primary DNS address
|
||||
{
|
||||
if (*(u32 *) (i + 2) != htonl(session[s].dns1))
|
||||
if (*(uint32_t *) (i + 2) != htonl(session[s].dns1))
|
||||
{
|
||||
*(u32 *) (i + 2) = htonl(session[s].dns1);
|
||||
*(uint32_t *) (i + 2) = htonl(session[s].dns1);
|
||||
*p = ConfigNak;
|
||||
LOG(5, s, t, " DNS1 = %s\n",
|
||||
fmtaddr(htonl(session[s].dns1), 0));
|
||||
|
|
@ -672,9 +671,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
}
|
||||
if ((i = findppp(p, 0x83))) // Secondary DNS address (TBA, is it)
|
||||
{
|
||||
if (*(u32 *) (i + 2) != htonl(session[s].dns2))
|
||||
if (*(uint32_t *) (i + 2) != htonl(session[s].dns2))
|
||||
{
|
||||
*(u32 *) (i + 2) = htonl(session[s].dns2);
|
||||
*(uint32_t *) (i + 2) = htonl(session[s].dns2);
|
||||
*p = ConfigNak;
|
||||
LOG(5, s, t, " DNS2 = %s\n",
|
||||
fmtaddr(htonl(session[s].dns2), 0));
|
||||
|
|
@ -687,9 +686,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
STAT(tunnel_rx_errors);
|
||||
return ;
|
||||
}
|
||||
if (*(u32 *) (i + 2) != htonl(session[s].ip))
|
||||
if (*(uint32_t *) (i + 2) != htonl(session[s].ip))
|
||||
{
|
||||
*(u32 *) (i + 2) = htonl(session[s].ip);
|
||||
*(uint32_t *) (i + 2) = htonl(session[s].ip);
|
||||
*p = ConfigNak;
|
||||
LOG(4, s, t, " No, a ConfigNak, client is requesting IP - sending %s\n",
|
||||
fmtaddr(htonl(session[s].ip), 0));
|
||||
|
|
@ -706,15 +705,15 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
//
|
||||
// This MUST be called with at least 4 byte behind 'p'.
|
||||
// (i.e. this routine writes to p[-4]).
|
||||
void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||
void processipin(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l)
|
||||
{
|
||||
ipt ip;
|
||||
in_addr_t ip;
|
||||
|
||||
CSTAT(call_processipin);
|
||||
|
||||
LOG_HEX(5, "IP", p, l);
|
||||
|
||||
ip = ntohl(*(u32 *)(p + 12));
|
||||
ip = ntohl(*(uint32_t *)(p + 12));
|
||||
|
||||
if (l > MAXETHER)
|
||||
{
|
||||
|
|
@ -736,7 +735,7 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
|
||||
// Add on the tun header
|
||||
p -= 4;
|
||||
*(u32 *)p = htonl(0x00000800);
|
||||
*(uint32_t *) p = htonl(0x00000800);
|
||||
l += 4;
|
||||
|
||||
if (session[s].tbf_in && !config->cluster_iam_master) { // Are we throttled and a slave?
|
||||
|
|
@ -780,7 +779,7 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
// Helper routine for the TBF filters.
|
||||
// Used to send queued data in from the user.
|
||||
//
|
||||
void send_ipin(sessionidt s, u8 *buf, int len)
|
||||
void send_ipin(sessionidt s, uint8_t *buf, int len)
|
||||
{
|
||||
LOG_HEX(5, "IP in throttled", buf, len);
|
||||
|
||||
|
|
@ -813,10 +812,10 @@ void send_ipin(sessionidt s, u8 *buf, int len)
|
|||
|
||||
|
||||
// Process CCP messages
|
||||
void processccp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||
void processccp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l)
|
||||
{
|
||||
u8 b[MAXCONTROL];
|
||||
u8 *q;
|
||||
uint8_t b[MAXCONTROL];
|
||||
uint8_t *q;
|
||||
|
||||
CSTAT(call_processccp);
|
||||
|
||||
|
|
@ -866,9 +865,9 @@ void processccp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
|||
// send a CHAP PP packet
|
||||
void sendchap(tunnelidt t, sessionidt s)
|
||||
{
|
||||
u8 b[MAXCONTROL];
|
||||
u16 r = session[s].radius;
|
||||
u8 *q;
|
||||
uint8_t b[MAXCONTROL];
|
||||
uint16_t r = session[s].radius;
|
||||
uint8_t *q;
|
||||
|
||||
CSTAT(call_sendchap);
|
||||
|
||||
|
|
@ -905,14 +904,14 @@ void sendchap(tunnelidt t, sessionidt s)
|
|||
q[4] = 16; // length
|
||||
memcpy(q + 5, radius[r].auth, 16); // challenge
|
||||
strcpy(q + 21, hostname); // our name
|
||||
*(u16 *) (q + 2) = htons(strlen(hostname) + 21); // length
|
||||
*(uint16_t *) (q + 2) = htons(strlen(hostname) + 21); // length
|
||||
tunnelsend(b, strlen(hostname) + 21 + (q - b), t); // send it
|
||||
}
|
||||
|
||||
// fill in a L2TP message with a PPP frame,
|
||||
// copies existing PPP message and changes magic number if seen
|
||||
// returns start of PPP frame
|
||||
u8 *makeppp(u8 *b, int size, u8 *p, int l, tunnelidt t, sessionidt s, u16 mtype)
|
||||
uint8_t *makeppp(uint8_t *b, int size, uint8_t *p, int l, tunnelidt t, sessionidt s, uint16_t mtype)
|
||||
{
|
||||
if (size < 12) // Need more space than this!!
|
||||
{
|
||||
|
|
@ -922,20 +921,20 @@ u8 *makeppp(u8 *b, int size, u8 *p, int l, tunnelidt t, sessionidt s, u16 mtype)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
*(u16 *) (b + 0) = htons(0x0002); // L2TP with no options
|
||||
*(u16 *) (b + 2) = htons(tunnel[t].far); // tunnel
|
||||
*(u16 *) (b + 4) = htons(session[s].far); // session
|
||||
*(uint16_t *) (b + 0) = htons(0x0002); // L2TP with no options
|
||||
*(uint16_t *) (b + 2) = htons(tunnel[t].far); // tunnel
|
||||
*(uint16_t *) (b + 4) = htons(session[s].far); // session
|
||||
b += 6;
|
||||
if (mtype == PPPLCP || !(session[s].l2tp_flags & SESSIONACFC))
|
||||
{
|
||||
*(u16 *) b = htons(0xFF03); // HDLC header
|
||||
*(uint16_t *) b = htons(0xFF03); // HDLC header
|
||||
b += 2;
|
||||
}
|
||||
if (mtype < 0x100 && session[s].l2tp_flags & SESSIONPFC)
|
||||
*b++ = mtype;
|
||||
else
|
||||
{
|
||||
*(u16 *) b = htons(mtype);
|
||||
*(uint16_t *) b = htons(mtype);
|
||||
b += 2;
|
||||
}
|
||||
|
||||
|
|
@ -963,14 +962,14 @@ void initlcp(tunnelidt t, sessionidt s)
|
|||
|
||||
LOG(4, s, t, "Sending LCP ConfigReq for PAP\n");
|
||||
*q = ConfigReq;
|
||||
*(u8 *)(q + 1) = (time_now % 255) + 1; // ID
|
||||
*(u16 *)(q + 2) = htons(14); // Length
|
||||
*(u8 *)(q + 4) = 5;
|
||||
*(u8 *)(q + 5) = 6;
|
||||
*(u32 *)(q + 6) = htonl(session[s].magic);
|
||||
*(u8 *)(q + 10) = 3;
|
||||
*(u8 *)(q + 11) = 4;
|
||||
*(u16 *)(q + 12) = htons(PPPPAP); // PAP
|
||||
*(uint8_t *)(q + 1) = (time_now % 255) + 1; // ID
|
||||
*(uint16_t *)(q + 2) = htons(14); // Length
|
||||
*(uint8_t *)(q + 4) = 5;
|
||||
*(uint8_t *)(q + 5) = 6;
|
||||
*(uint32_t *)(q + 6) = htonl(session[s].magic);
|
||||
*(uint8_t *)(q + 10) = 3;
|
||||
*(uint8_t *)(q + 11) = 4;
|
||||
*(uint16_t *)(q + 12) = htons(PPPPAP); // PAP
|
||||
|
||||
LOG_HEX(5, "PPPLCP", q, 14);
|
||||
tunnelsend(b, (q - b) + 14, t);
|
||||
|
|
@ -986,8 +985,8 @@ static void initccp(tunnelidt t, sessionidt s)
|
|||
|
||||
LOG(4, s, t, "Sending CCP ConfigReq for no compression\n");
|
||||
*q = ConfigReq;
|
||||
*(u8 *)(q + 1) = (time_now % 255) + 1; // ID
|
||||
*(u16 *)(q + 2) = htons(4); // Length
|
||||
*(uint8_t *)(q + 1) = (time_now % 255) + 1; // ID
|
||||
*(uint16_t *)(q + 2) = htons(4); // Length
|
||||
|
||||
LOG_HEX(5, "PPPCCP", q, 4);
|
||||
tunnelsend(b, (q - b) + 4 , t);
|
||||
|
|
|
|||
99
radius.c
99
radius.c
|
|
@ -1,6 +1,6 @@
|
|||
// L2TPNS Radius Stuff
|
||||
|
||||
char const *cvs_id_radius = "$Id: radius.c,v 1.19 2004/11/30 06:50:26 bodea Exp $";
|
||||
char const *cvs_id_radius = "$Id: radius.c,v 1.20 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -21,7 +21,6 @@ char const *cvs_id_radius = "$Id: radius.c,v 1.19 2004/11/30 06:50:26 bodea Exp
|
|||
extern radiust *radius;
|
||||
extern sessiont *session;
|
||||
extern tunnelt *tunnel;
|
||||
extern u32 sessionid;
|
||||
extern configt *config;
|
||||
extern int *radfds;
|
||||
extern ip_filtert *ip_filters;
|
||||
|
|
@ -53,17 +52,17 @@ void initrad(void)
|
|||
}
|
||||
}
|
||||
|
||||
void radiusclear(u16 r, sessionidt s)
|
||||
void radiusclear(uint16_t r, sessionidt s)
|
||||
{
|
||||
if (s) session[s].radius = 0;
|
||||
memset(&radius[r], 0, sizeof(radius[r])); // radius[r].state = RADIUSNULL;
|
||||
}
|
||||
|
||||
|
||||
static u16 get_free_radius()
|
||||
static uint16_t get_free_radius()
|
||||
{
|
||||
int count;
|
||||
static u32 next_radius_id = 0;
|
||||
static uint32_t next_radius_id = 0;
|
||||
|
||||
for (count = MAXRADIUS; count > 0 ; --count)
|
||||
{
|
||||
|
|
@ -81,9 +80,9 @@ static u16 get_free_radius()
|
|||
return 0;
|
||||
}
|
||||
|
||||
u16 radiusnew(sessionidt s)
|
||||
uint16_t radiusnew(sessionidt s)
|
||||
{
|
||||
u16 r = session[s].radius;
|
||||
uint16_t r = session[s].radius;
|
||||
|
||||
/* re-use */
|
||||
if (r)
|
||||
|
|
@ -110,13 +109,13 @@ u16 radiusnew(sessionidt s)
|
|||
}
|
||||
|
||||
// Send a RADIUS request
|
||||
void radiussend(u16 r, u8 state)
|
||||
void radiussend(uint16_t r, uint8_t state)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
u8 b[4096]; // RADIUS packet
|
||||
uint8_t b[4096]; // RADIUS packet
|
||||
char pass[129];
|
||||
int pl;
|
||||
u8 *p;
|
||||
uint8_t *p;
|
||||
sessionidt s;
|
||||
|
||||
CSTAT(call_radiussend);
|
||||
|
|
@ -246,7 +245,7 @@ void radiussend(u16 r, u8 state)
|
|||
{ // accounting
|
||||
*p = 40; // accounting type
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl((state == RADIUSSTART) ? 1 : 2);
|
||||
*(uint32_t *) (p + 2) = htonl((state == RADIUSSTART) ? 1 : 2);
|
||||
p += p[1];
|
||||
if (s)
|
||||
{
|
||||
|
|
@ -258,30 +257,30 @@ void radiussend(u16 r, u8 state)
|
|||
{ // stop
|
||||
*p = 42; // input octets
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(session[s].cin);
|
||||
*(uint32_t *) (p + 2) = htonl(session[s].cin);
|
||||
p += p[1];
|
||||
*p = 43; // output octets
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(session[s].cout);
|
||||
*(uint32_t *) (p + 2) = htonl(session[s].cout);
|
||||
p += p[1];
|
||||
*p = 46; // session time
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(time(NULL) - session[s].opened);
|
||||
*(uint32_t *) (p + 2) = htonl(time(NULL) - session[s].opened);
|
||||
p += p[1];
|
||||
*p = 47; // input packets
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(session[s].pin);
|
||||
*(uint32_t *) (p + 2) = htonl(session[s].pin);
|
||||
p += p[1];
|
||||
*p = 48; // output spackets
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(session[s].pout);
|
||||
*(uint32_t *) (p + 2) = htonl(session[s].pout);
|
||||
p += p[1];
|
||||
}
|
||||
else
|
||||
{ // start
|
||||
*p = 41; // delay
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(time(NULL) - session[s].opened);
|
||||
*(uint32_t *) (p + 2) = htonl(time(NULL) - session[s].opened);
|
||||
p += p[1];
|
||||
}
|
||||
}
|
||||
|
|
@ -290,14 +289,14 @@ void radiussend(u16 r, u8 state)
|
|||
{
|
||||
*p = 5; // NAS-Port
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(s);
|
||||
*(uint32_t *) (p + 2) = htonl(s);
|
||||
p += p[1];
|
||||
}
|
||||
if (s && session[s].ip)
|
||||
{
|
||||
*p = 8; // Framed-IP-Address
|
||||
p[1] = 6;
|
||||
*(u32 *) (p + 2) = htonl(session[s].ip);
|
||||
*(uint32_t *) (p + 2) = htonl(session[s].ip);
|
||||
p += p[1];
|
||||
}
|
||||
if (*session[s].called)
|
||||
|
|
@ -324,11 +323,11 @@ void radiussend(u16 r, u8 state)
|
|||
// NAS-IP-Address
|
||||
*p = 4;
|
||||
p[1] = 6;
|
||||
*(u32 *)(p + 2) = config->bind_address;
|
||||
*(uint32_t *)(p + 2) = config->bind_address;
|
||||
p += p[1];
|
||||
|
||||
// All AVpairs added
|
||||
*(u16 *) (b + 2) = htons(p - b);
|
||||
*(uint16_t *) (b + 2) = htons(p - b);
|
||||
if (state != RADIUSAUTH)
|
||||
{
|
||||
// Build auth for accounting packet
|
||||
|
|
@ -346,14 +345,14 @@ void radiussend(u16 r, u8 state)
|
|||
}
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
*(u32 *) & addr.sin_addr = config->radiusserver[(radius[r].try - 1) % config->numradiusservers];
|
||||
*(uint32_t *) & addr.sin_addr = config->radiusserver[(radius[r].try - 1) % config->numradiusservers];
|
||||
{
|
||||
// get radius port
|
||||
u16 port = config->radiusport[(radius[r].try - 1) % config->numradiusservers];
|
||||
// no need to define the accounting port for itself:
|
||||
// the accounting port is as far as I know always one more
|
||||
// than the auth port JK 20040713
|
||||
addr.sin_port = htons((state == RADIUSAUTH) ? port : port+1);
|
||||
// get radius port
|
||||
uint16_t port = config->radiusport[(radius[r].try - 1) % config->numradiusservers];
|
||||
// no need to define the accounting port for itself:
|
||||
// the accounting port is as far as I know always one more
|
||||
// than the auth port JK 20040713
|
||||
addr.sin_port = htons((state == RADIUSAUTH) ? port : port+1);
|
||||
}
|
||||
|
||||
LOG_HEX(5, "RADIUS Send", b, (p - b));
|
||||
|
|
@ -361,15 +360,15 @@ void radiussend(u16 r, u8 state)
|
|||
}
|
||||
|
||||
// process RADIUS response
|
||||
void processrad(u8 *buf, int len, char socket_index)
|
||||
void processrad(uint8_t *buf, int len, char socket_index)
|
||||
{
|
||||
u8 b[MAXCONTROL];
|
||||
uint8_t b[MAXCONTROL];
|
||||
MD5_CTX ctx;
|
||||
u16 r;
|
||||
uint16_t r;
|
||||
sessionidt s;
|
||||
tunnelidt t = 0;
|
||||
hasht hash;
|
||||
u8 routes = 0;
|
||||
uint8_t routes = 0;
|
||||
|
||||
int r_code, r_id ; // Radius code.
|
||||
|
||||
|
|
@ -380,12 +379,12 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
CSTAT(call_processrad);
|
||||
|
||||
LOG_HEX(5, "RADIUS Response", buf, len);
|
||||
if (len < 20 || len < ntohs(*(u16 *) (buf + 2)))
|
||||
if (len < 20 || len < ntohs(*(uint16_t *) (buf + 2)))
|
||||
{
|
||||
LOG(1, 0, 0, "Duff RADIUS response length %d\n", len);
|
||||
return ;
|
||||
}
|
||||
len = ntohs(*(u16 *) (buf + 2));
|
||||
len = ntohs(*(uint16_t *) (buf + 2));
|
||||
r = socket_index | (r_id << RADIUS_SHIFT);
|
||||
s = radius[r].session;
|
||||
LOG(3, s, session[s].tunnel, "Received %s, radius %d response for session %u (code %d, id %d)\n",
|
||||
|
|
@ -427,7 +426,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
if (radius[r].chap)
|
||||
{
|
||||
// CHAP
|
||||
u8 *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPCHAP);
|
||||
uint8_t *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPCHAP);
|
||||
if (!p) return; // Abort!
|
||||
|
||||
{
|
||||
|
|
@ -440,13 +439,13 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
(*buf == 2) ? "allowed" : "denied");
|
||||
*p = (*buf == 2) ? 3 : 4; // ack/nak
|
||||
p[1] = radius[r].id;
|
||||
*(u16 *) (p + 2) = ntohs(4); // no message
|
||||
*(uint16_t *) (p + 2) = ntohs(4); // no message
|
||||
tunnelsend(b, (p - b) + 4, t); // send it
|
||||
}
|
||||
else
|
||||
{
|
||||
// PAP
|
||||
u8 *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP);
|
||||
uint8_t *p = makeppp(b, sizeof(b), 0, 0, t, s, PPPPAP);
|
||||
if (!p) return; // Abort!
|
||||
|
||||
{
|
||||
|
|
@ -460,7 +459,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
// ack/nak
|
||||
*p = *buf;
|
||||
p[1] = radius[r].id;
|
||||
*(u16 *) (p + 2) = ntohs(5);
|
||||
*(uint16_t *) (p + 2) = ntohs(5);
|
||||
p[4] = 0; // no message
|
||||
tunnelsend(b, (p - b) + 5, t); // send it
|
||||
}
|
||||
|
|
@ -469,15 +468,15 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
{
|
||||
// Login successful
|
||||
// Extract IP, routes, etc
|
||||
u8 *p = buf + 20;
|
||||
u8 *e = buf + len;
|
||||
uint8_t *p = buf + 20;
|
||||
uint8_t *e = buf + len;
|
||||
for (; p + 2 <= e && p[1] && p + p[1] <= e; p += p[1])
|
||||
{
|
||||
if (*p == 8)
|
||||
{
|
||||
// Framed-IP-Address
|
||||
if (p[1] < 6) continue;
|
||||
session[s].ip = ntohl(*(u32 *) (p + 2));
|
||||
session[s].ip = ntohl(*(uint32_t *) (p + 2));
|
||||
session[s].ip_pool_index = -1;
|
||||
LOG(3, s, session[s].tunnel, " Radius reply contains IP address %s\n",
|
||||
fmtaddr(htonl(session[s].ip), 0));
|
||||
|
|
@ -486,7 +485,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
{
|
||||
// DNS address
|
||||
if (p[1] < 6) continue;
|
||||
session[s].dns1 = ntohl(*(u32 *) (p + 2));
|
||||
session[s].dns1 = ntohl(*(uint32_t *) (p + 2));
|
||||
LOG(3, s, session[s].tunnel, " Radius reply contains primary DNS address %s\n",
|
||||
fmtaddr(htonl(session[s].dns1), 0));
|
||||
}
|
||||
|
|
@ -494,18 +493,18 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
{
|
||||
// DNS address
|
||||
if (p[1] < 6) continue;
|
||||
session[s].dns2 = ntohl(*(u32 *) (p + 2));
|
||||
session[s].dns2 = ntohl(*(uint32_t *) (p + 2));
|
||||
LOG(3, s, session[s].tunnel, " Radius reply contains secondary DNS address %s\n",
|
||||
fmtaddr(htonl(session[s].dns2), 0));
|
||||
}
|
||||
else if (*p == 22)
|
||||
{
|
||||
// Framed-Route
|
||||
ipt ip = 0, mask = 0;
|
||||
u8 u = 0;
|
||||
u8 bits = 0;
|
||||
u8 *n = p + 2;
|
||||
u8 *e = p + p[1];
|
||||
in_addr_t ip = 0, mask = 0;
|
||||
uint8_t u = 0;
|
||||
uint8_t bits = 0;
|
||||
uint8_t *n = p + 2;
|
||||
uint8_t *e = p + p[1];
|
||||
while (n < e && (isdigit(*n) || *n == '.'))
|
||||
{
|
||||
if (*n == '.')
|
||||
|
|
@ -552,7 +551,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
char *filter = p + 2;
|
||||
int l = p[1] - 2;
|
||||
char *suffix;
|
||||
u8 *f = 0;
|
||||
uint8_t *f = 0;
|
||||
int i;
|
||||
|
||||
LOG(3, s, session[s].tunnel, " Radius reply contains Filter-Id \"%.*s\"\n", l, filter);
|
||||
|
|
@ -667,7 +666,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
|||
}
|
||||
|
||||
// Send a retry for RADIUS/CHAP message
|
||||
void radiusretry(u16 r)
|
||||
void radiusretry(uint16_t r)
|
||||
{
|
||||
sessionidt s = radius[r].session;
|
||||
tunnelidt t = 0;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
/* snoop control */
|
||||
|
||||
char const *cvs_id = "$Id: snoopctl.c,v 1.3 2004/11/18 06:41:03 bodea Exp $";
|
||||
char const *cvs_id = "$Id: snoopctl.c,v 1.4 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
int plugin_api_version = PLUGIN_API_VERSION;
|
||||
static struct pluginfuncs *p = 0;
|
||||
|
|
@ -77,8 +77,8 @@ int plugin_control(struct param_control *data)
|
|||
|
||||
if (flag)
|
||||
{
|
||||
ipt ip = inet_addr(data->argv[2]);
|
||||
u16 port = atoi(data->argv[3]);
|
||||
in_addr_t ip = inet_addr(data->argv[2]);
|
||||
uint16_t port = atoi(data->argv[3]);
|
||||
|
||||
if (!ip || ip == INADDR_NONE)
|
||||
{
|
||||
|
|
|
|||
4
tbf.c
4
tbf.c
|
|
@ -1,6 +1,6 @@
|
|||
// L2TPNS: token bucket filters
|
||||
|
||||
char const *cvs_id_tbf = "$Id: tbf.c,v 1.10 2004/11/29 02:17:18 bodea Exp $";
|
||||
char const *cvs_id_tbf = "$Id: tbf.c,v 1.11 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
#include <string.h>
|
||||
#include "l2tpns.h"
|
||||
|
|
@ -91,7 +91,7 @@ int free_tbf(int tid)
|
|||
//
|
||||
// Allocate a new token bucket filter.
|
||||
//
|
||||
int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int))
|
||||
int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, uint8_t *, int))
|
||||
{
|
||||
int i;
|
||||
static int p = 0;
|
||||
|
|
|
|||
40
tbf.h
40
tbf.h
|
|
@ -10,33 +10,33 @@
|
|||
#define TBF_RATE 360 // 360 bytes per 1/10th of a second.
|
||||
|
||||
typedef struct {
|
||||
int credit;
|
||||
int lasttime;
|
||||
int queued;
|
||||
int oldest; // Position of packet in the ring buffer.
|
||||
sessionidt sid; // associated session ID.
|
||||
int max_credit; // Maximum amount of credit available (burst size).
|
||||
int rate; // How many bytes of credit per second we get? (sustained rate)
|
||||
void (*send)(sessionidt s, u8 *, int); // Routine to actually send out the data.
|
||||
int prev; // Timer chain position.
|
||||
int next; // Timer chain position.
|
||||
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.
|
||||
|
||||
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.
|
||||
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];
|
||||
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);
|
||||
|
||||
|
|
|
|||
4
util.c
4
util.c
|
|
@ -1,6 +1,6 @@
|
|||
/* Misc util functions */
|
||||
|
||||
char const *cvs_id_util = "$Id: util.c,v 1.7 2004/11/29 02:17:18 bodea Exp $";
|
||||
char const *cvs_id_util = "$Id: util.c,v 1.8 2004/12/16 08:49:53 bodea Exp $";
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
|
@ -18,7 +18,7 @@ char const *cvs_id_util = "$Id: util.c,v 1.7 2004/11/29 02:17:18 bodea Exp $";
|
|||
|
||||
// format ipv4 addr as a dotted-quad; n chooses one of 4 static buffers
|
||||
// to use
|
||||
char *fmtaddr(ipt addr, int n)
|
||||
char *fmtaddr(in_addr_t addr, int n)
|
||||
{
|
||||
static char addrs[4][16];
|
||||
struct in_addr in;
|
||||
|
|
|
|||
2
util.h
2
util.h
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __UTIL_H__
|
||||
#define __UTIL_H__
|
||||
|
||||
char *fmtaddr(ipt addr, int n);
|
||||
char *fmtaddr(in_addr_t addr, int n);
|
||||
void *shared_malloc(unsigned int size);
|
||||
pid_t fork_and_close(void);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue