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
|
- Better cluster master collision resolution: keep a counter of state
|
||||||
changes, propagated in the heartbeats; the master with the highest #
|
changes, propagated in the heartbeats; the master with the highest #
|
||||||
of changes (that has kept in contact with the LAC through the
|
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.
|
attempt to avoid losing the cluster in high load (DoS) conditions.
|
||||||
- Compress logs.
|
- Compress logs.
|
||||||
- Retain counters of shutdown sessions to dump once per minute.
|
- 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
|
* Wed Dec 1 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.12
|
||||||
- The "This time, for sure!" release.
|
- The "This time, for sure!" release.
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -118,7 +118,6 @@ install: all
|
||||||
|
|
||||||
## Dependencies: (autogenerated) ##
|
## Dependencies: (autogenerated) ##
|
||||||
arp.o: arp.c l2tpns.h
|
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
|
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
|
cluster.o: cluster.c l2tpns.h cluster.h util.h tbf.h bgp.h
|
||||||
constants.o: constants.c constants.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
|
radius.o: radius.c md5.h constants.h l2tpns.h plugin.h util.h
|
||||||
tbf.o: tbf.c l2tpns.h util.h tbf.h
|
tbf.o: tbf.c l2tpns.h util.h tbf.h
|
||||||
util.o: util.c l2tpns.h bgp.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
|
garden.so: garden.c l2tpns.h plugin.h control.h
|
||||||
throttlectl.so: throttlectl.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
|
autothrottle.so: autothrottle.c l2tpns.h plugin.h
|
||||||
|
|
|
||||||
8
arp.c
8
arp.c
|
|
@ -1,6 +1,6 @@
|
||||||
// L2TPNS: arp
|
// 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 <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -18,12 +18,12 @@ struct arp_buf {
|
||||||
|
|
||||||
/* Data bit - variably sized, so not present in |struct arphdr| */
|
/* Data bit - variably sized, so not present in |struct arphdr| */
|
||||||
unsigned char ar_sha[ETH_ALEN]; /* Sender hardware address */
|
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 */
|
unsigned char ar_tha[ETH_ALEN]; /* Target hardware address */
|
||||||
ipt ar_tip; /* Target ip */
|
in_addr_t ar_tip; /* Target ip */
|
||||||
} __attribute__((packed));
|
} __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;
|
int fd;
|
||||||
struct sockaddr_ll sll;
|
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).
|
* 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 <stdlib.h>
|
||||||
#include <unistd.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);
|
struct bgp_route_list *new);
|
||||||
|
|
||||||
static void bgp_free_routes(struct bgp_route_list *routes);
|
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_connect(struct bgp_peer *peer);
|
||||||
static int bgp_handle_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_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_open(struct bgp_peer *peer);
|
||||||
static int bgp_send_keepalive(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_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;
|
static struct bgp_route_list *bgp_routes = 0;
|
||||||
|
|
||||||
int bgp_configured = 0;
|
int bgp_configured = 0;
|
||||||
|
|
@ -89,7 +90,8 @@ int bgp_setup(int as)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* start connection with a peer */
|
/* 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;
|
struct hostent *h;
|
||||||
int ibgp;
|
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 path_attrs[64];
|
||||||
char *p = path_attrs;
|
char *p = path_attrs;
|
||||||
in_addr_t ip;
|
in_addr_t ip;
|
||||||
u32 metric = htonl(BGP_METRIC);
|
uint32_t metric = htonl(BGP_METRIC);
|
||||||
u32 no_export = htonl(BGP_COMMUNITY_NO_EXPORT);
|
uint32_t no_export = htonl(BGP_COMMUNITY_NO_EXPORT);
|
||||||
|
|
||||||
if (!our_as)
|
if (!our_as)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -170,9 +172,9 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold
|
||||||
{
|
{
|
||||||
/* just our AS */
|
/* just our AS */
|
||||||
struct {
|
struct {
|
||||||
u8 type;
|
uint8_t type;
|
||||||
u8 len;
|
uint8_t len;
|
||||||
u16 value;
|
uint16_t value;
|
||||||
} as_path = {
|
} as_path = {
|
||||||
BGP_PATH_ATTR_CODE_AS_PATH_AS_SEQUENCE,
|
BGP_PATH_ATTR_CODE_AS_PATH_AS_SEQUENCE,
|
||||||
1,
|
1,
|
||||||
|
|
@ -204,7 +206,7 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, int hold
|
||||||
|
|
||||||
if (ibgp)
|
if (ibgp)
|
||||||
{
|
{
|
||||||
u32 local_pref = htonl(BGP_LOCAL_PREF);
|
uint32_t local_pref = htonl(BGP_LOCAL_PREF);
|
||||||
|
|
||||||
/* LOCAL_PREF */
|
/* LOCAL_PREF */
|
||||||
a.flags = BGP_PATH_ATTR_FLAG_TRANS;
|
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)
|
static void bgp_cidr(in_addr_t ip, in_addr_t mask, struct bgp_ip_prefix *pfx)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
u32 b;
|
uint32_t b;
|
||||||
|
|
||||||
/* convert to prefix notation */
|
/* convert to prefix notation */
|
||||||
pfx->len = 32;
|
pfx->len = 32;
|
||||||
|
|
@ -641,7 +643,7 @@ char const *bgp_state_str(enum bgp_state state)
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
|
|
||||||
static char const *bgp_msg_type_str(u8 type)
|
static char const *bgp_msg_type_str(uint8_t type)
|
||||||
{
|
{
|
||||||
switch (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)
|
static int bgp_send_open(struct bgp_peer *peer)
|
||||||
{
|
{
|
||||||
struct bgp_data_open data;
|
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,
|
memset(peer->outbuf->packet.header.marker, 0xff,
|
||||||
sizeof(peer->outbuf->packet.header.marker));
|
sizeof(peer->outbuf->packet.header.marker));
|
||||||
|
|
@ -1029,9 +1031,9 @@ static int bgp_send_keepalive(struct bgp_peer *peer)
|
||||||
/* send/buffer UPDATE message */
|
/* send/buffer UPDATE message */
|
||||||
static int bgp_send_update(struct bgp_peer *peer)
|
static int bgp_send_update(struct bgp_peer *peer)
|
||||||
{
|
{
|
||||||
u16 unf_len = 0;
|
uint16_t unf_len = 0;
|
||||||
u16 attr_len;
|
uint16_t attr_len;
|
||||||
u16 len = sizeof(peer->outbuf->packet.header);
|
uint16_t len = sizeof(peer->outbuf->packet.header);
|
||||||
struct bgp_route_list *have = peer->routes;
|
struct bgp_route_list *have = peer->routes;
|
||||||
struct bgp_route_list *want = peer->routing ? bgp_routes : 0;
|
struct bgp_route_list *want = peer->routing ? bgp_routes : 0;
|
||||||
struct bgp_route_list *e = 0;
|
struct bgp_route_list *e = 0;
|
||||||
|
|
@ -1169,10 +1171,11 @@ static int bgp_send_update(struct bgp_peer *peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send/buffer NOTIFICATION message */
|
/* 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;
|
struct bgp_data_notification data;
|
||||||
u16 len = 0;
|
uint16_t len = 0;
|
||||||
|
|
||||||
data.error_code = code;
|
data.error_code = code;
|
||||||
len += sizeof(data.error_code);
|
len += sizeof(data.error_code);
|
||||||
|
|
|
||||||
36
bgp.h
36
bgp.h
|
|
@ -1,5 +1,5 @@
|
||||||
/* BGPv4 (RFC1771) */
|
/* 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__
|
#ifndef __BGP_H__
|
||||||
#define __BGP_H__
|
#define __BGP_H__
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
|
|
||||||
struct bgp_header {
|
struct bgp_header {
|
||||||
char marker[16];
|
char marker[16];
|
||||||
u16 len;
|
uint16_t len;
|
||||||
u8 type;
|
uint8_t type;
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
/* bgp_header.type */
|
/* bgp_header.type */
|
||||||
|
|
@ -33,33 +33,33 @@ struct bgp_packet {
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
struct bgp_data_open {
|
struct bgp_data_open {
|
||||||
u8 version;
|
uint8_t version;
|
||||||
#define BGP_VERSION 4
|
#define BGP_VERSION 4
|
||||||
u16 as;
|
uint16_t as;
|
||||||
u16 hold_time;
|
uint16_t hold_time;
|
||||||
u32 identifier;
|
uint32_t identifier;
|
||||||
u8 opt_len;
|
uint8_t opt_len;
|
||||||
#define BGP_DATA_OPEN_SIZE 10 /* size of struct excluding opt_params */
|
#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 */
|
char opt_params[sizeof(((struct bgp_packet *)0)->data) - BGP_DATA_OPEN_SIZE]; /* variable */
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
struct bgp_ip_prefix {
|
struct bgp_ip_prefix {
|
||||||
u8 len;
|
uint8_t len;
|
||||||
u32 prefix; /* variable */
|
uint32_t prefix; /* variable */
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
#define BGP_IP_PREFIX_SIZE(p) (1 + ((p).len / 8) + ((p).len % 8 != 0))
|
#define BGP_IP_PREFIX_SIZE(p) (1 + ((p).len / 8) + ((p).len % 8 != 0))
|
||||||
|
|
||||||
struct bgp_path_attr {
|
struct bgp_path_attr {
|
||||||
u8 flags;
|
uint8_t flags;
|
||||||
u8 code;
|
uint8_t code;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
u8 len;
|
uint8_t len;
|
||||||
char value[29]; /* semi-random size, adequate for l2tpns */
|
char value[29]; /* semi-random size, adequate for l2tpns */
|
||||||
} __attribute__ ((packed)) s; /* short */
|
} __attribute__ ((packed)) s; /* short */
|
||||||
struct {
|
struct {
|
||||||
u16 len;
|
uint16_t len;
|
||||||
char value[28];
|
char value[28];
|
||||||
} __attribute__ ((packed)) e; /* extended */
|
} __attribute__ ((packed)) e; /* extended */
|
||||||
} data; /* variable */
|
} data; /* variable */
|
||||||
|
|
@ -95,8 +95,8 @@ struct bgp_path_attr {
|
||||||
#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 /* don't advertise to any other AS */
|
#define BGP_COMMUNITY_NO_EXPORT_SUBCONFED 0xffffff03 /* don't advertise to any other AS */
|
||||||
|
|
||||||
struct bgp_data_notification {
|
struct bgp_data_notification {
|
||||||
u8 error_code;
|
uint8_t error_code;
|
||||||
u8 error_subcode;
|
uint8_t error_subcode;
|
||||||
char data[sizeof(((struct bgp_packet *)0)->data) - 2]; /* variable */
|
char data[sizeof(((struct bgp_packet *)0)->data) - 2]; /* variable */
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
|
@ -185,7 +185,9 @@ extern int bgp_configured;
|
||||||
|
|
||||||
/* actions */
|
/* actions */
|
||||||
int bgp_setup(int as);
|
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_stop(struct bgp_peer *peer);
|
||||||
void bgp_halt(struct bgp_peer *peer);
|
void bgp_halt(struct bgp_peer *peer);
|
||||||
int bgp_restart(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
|
// vim: sw=8 ts=8
|
||||||
|
|
||||||
char const *cvs_name = "$Name: $";
|
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 <stdio.h>
|
||||||
#include <stdarg.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)
|
static int cmd_snoop(struct cli_def *cli, char *command, char **argv, int argc)
|
||||||
{
|
{
|
||||||
ipt ip;
|
in_addr_t ip;
|
||||||
u16 port;
|
uint16_t port;
|
||||||
sessionidt s;
|
sessionidt s;
|
||||||
|
|
||||||
if (CLI_HELP_REQUESTED)
|
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);
|
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)
|
if (ip == INADDR_ANY && wild == INADDR_BROADCAST)
|
||||||
return sprintf(buf, " any");
|
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++)
|
for (a = 1, i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
ipt *ip;
|
in_addr_t *ip;
|
||||||
ipt *wild;
|
in_addr_t *wild;
|
||||||
ip_filter_portt *port;
|
ip_filter_portt *port;
|
||||||
|
|
||||||
if (i == 0)
|
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] == '-'))
|
while (a < argc && (argv[a][0] == '+' || argv[a][0] == '-'))
|
||||||
{
|
{
|
||||||
u8 *f;
|
uint8_t *f;
|
||||||
|
|
||||||
f = (argv[a][0] == '+') ? &rule.tcp_sflags : &rule.tcp_cflags;
|
f = (argv[a][0] == '+') ? &rule.tcp_sflags : &rule.tcp_cflags;
|
||||||
|
|
||||||
|
|
|
||||||
110
cluster.c
110
cluster.c
|
|
@ -1,6 +1,6 @@
|
||||||
// L2TPNS Clustering Stuff
|
// 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 <stdio.h>
|
||||||
#include <sys/file.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 <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <libcli.h>
|
#include <libcli.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "l2tpns.h"
|
#include "l2tpns.h"
|
||||||
#include "cluster.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.
|
// Module variables.
|
||||||
int cluster_sockfd = 0; // The filedescriptor for the cluster communications port.
|
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_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.
|
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.
|
// we can re-transmit if needed.
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
u32 peer;
|
in_addr_t peer;
|
||||||
time_t basetime;
|
time_t basetime;
|
||||||
clockt timestamp;
|
clockt timestamp;
|
||||||
int uptodate;
|
int uptodate;
|
||||||
} peers[CLUSTER_MAX_SIZE]; // List of all the peers we've heard from.
|
} peers[CLUSTER_MAX_SIZE]; // List of all the peers we've heard from.
|
||||||
static int num_peers; // Number of peers in list.
|
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_decompress(uint8_t **src_p, int ssize, uint8_t *dst, int dsize);
|
||||||
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);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Create a listening socket
|
// Create a listening socket
|
||||||
|
|
@ -179,15 +180,15 @@ static int cluster_send_data(void *data, int datalen)
|
||||||
//
|
//
|
||||||
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;
|
*((uint32_t *) (*p)) = type;
|
||||||
*p += sizeof(u32);
|
*p += sizeof(uint32_t);
|
||||||
|
|
||||||
* ( (u32*)(*p) ) = more;
|
*((uint32_t *)(*p)) = more;
|
||||||
*p += sizeof(u32);
|
*p += sizeof(uint32_t);
|
||||||
|
|
||||||
if (data && size > 0) {
|
if (data && size > 0) {
|
||||||
memcpy(*p, data, size);
|
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
|
// Send a unicast UDP packet to a peer with 'data' as the
|
||||||
// contents.
|
// 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};
|
struct sockaddr_in addr = {0};
|
||||||
|
|
||||||
|
|
@ -249,7 +250,7 @@ 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'.
|
// 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 buf[65536]; // Vast overkill.
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
|
|
@ -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
|
// The master just processes the payload as if it had
|
||||||
// received it off the tun device.
|
// 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 buf[65536]; // Vast overkill.
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
|
|
@ -282,7 +283,6 @@ int master_forward_packet(char *data, int size, u32 addr, int port)
|
||||||
p += 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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -688,9 +688,9 @@ static int hb_add_type(char **p, int type, int id)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case C_CSESSION: { // Compressed C_SESSION.
|
case C_CSESSION: { // Compressed C_SESSION.
|
||||||
u8 c[sizeof(sessiont) * 2]; // Bigger than worst case.
|
uint8_t c[sizeof(sessiont) * 2]; // Bigger than worst case.
|
||||||
u8 *d = (u8 *) &session[id];
|
uint8_t *d = (uint8_t *) &session[id];
|
||||||
u8 *orig = d;
|
uint8_t *orig = d;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
size = rle_compress( &d, sizeof(sessiont), c, sizeof(c) );
|
size = rle_compress( &d, sizeof(sessiont), c, sizeof(c) );
|
||||||
|
|
@ -708,9 +708,9 @@ static int hb_add_type(char **p, int type, int id)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case C_CTUNNEL: { // Compressed C_TUNNEL
|
case C_CTUNNEL: { // Compressed C_TUNNEL
|
||||||
u8 c[sizeof(tunnelt) * 2]; // Bigger than worst case.
|
uint8_t c[sizeof(tunnelt) * 2]; // Bigger than worst case.
|
||||||
u8 *d = (u8 *) &tunnel[id];
|
uint8_t *d = (uint8_t *) &tunnel[id];
|
||||||
u8 *orig = d;
|
uint8_t *orig = d;
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
size = rle_compress( &d, sizeof(tunnelt), c, sizeof(c) );
|
size = rle_compress( &d, sizeof(tunnelt), c, sizeof(c) );
|
||||||
|
|
@ -773,7 +773,7 @@ void cluster_heartbeat()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p > (buff + sizeof(buff))) { // Did we somehow manage to overun the buffer?
|
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);
|
kill(0, SIGTERM);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
@ -781,7 +781,7 @@ void cluster_heartbeat()
|
||||||
//
|
//
|
||||||
// Fill out the packet with sessions from the session table...
|
// Fill out the packet with sessions from the session table...
|
||||||
// (not forgetting to leave space so we can get some tunnels in too )
|
// (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.
|
if (!walk_session_number) // session #0 isn't valid.
|
||||||
++walk_session_number;
|
++walk_session_number;
|
||||||
|
|
@ -801,7 +801,7 @@ void cluster_heartbeat()
|
||||||
// than the session table. This is good because stuffing up a
|
// than the session table. This is good because stuffing up a
|
||||||
// tunnel is a much bigger deal than stuffing up a session.
|
// 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.
|
if (!walk_tunnel_number) // tunnel #0 isn't valid.
|
||||||
++walk_tunnel_number;
|
++walk_tunnel_number;
|
||||||
|
|
@ -818,16 +818,16 @@ void cluster_heartbeat()
|
||||||
//
|
//
|
||||||
// Did we do something wrong?
|
// Did we do something wrong?
|
||||||
if (p > (buff + sizeof(buff))) { // Did we somehow manage to overun the buffer?
|
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);
|
kill(0, SIGTERM);
|
||||||
exit(1);
|
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",
|
"(%d x-sess, %d x-tunnels, %d highsess, %d hightun, size %d)\n",
|
||||||
HB_VERSION, h.seq, h.table_version, config->cluster_num_changes,
|
HB_VERSION, h.seq, h.table_version, config->cluster_num_changes,
|
||||||
count, tcount, config->cluster_highest_sessionid,
|
count, tcount, config->cluster_highest_sessionid,
|
||||||
config->cluster_highest_tunnelid, (p-buff));
|
config->cluster_highest_tunnelid, (int) (p - buff));
|
||||||
|
|
||||||
config->cluster_num_changes = 0;
|
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
|
// missed a packet. We'll resend it every packet since
|
||||||
// the last one it's seen.
|
// 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 s;
|
||||||
int diff;
|
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
|
// We've heard from another peer! Add it to the list
|
||||||
// that we select from at election time.
|
// 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;
|
int i;
|
||||||
u32 clusterid;
|
in_addr_t clusterid;
|
||||||
pingt p;
|
pingt p;
|
||||||
|
|
||||||
// Allow for backward compatability.
|
// Allow for backward compatability.
|
||||||
|
|
@ -1043,7 +1043,7 @@ static int cluster_handle_bytes(char * data, int size)
|
||||||
//
|
//
|
||||||
// Handle receiving a session structure in a heartbeat packet.
|
// 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) {
|
if (more >= MAXSESSION) {
|
||||||
LOG(0, 0, 0, "DANGER: Received a heartbeat session id > MAXSESSION!\n");
|
LOG(0, 0, 0, "DANGER: Received a heartbeat session id > MAXSESSION!\n");
|
||||||
|
|
@ -1068,7 +1068,7 @@ static int cluster_recv_session(int more , u8 * p)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cluster_recv_tunnel(int more, u8 *p)
|
static int cluster_recv_tunnel(int more, uint8_t *p)
|
||||||
{
|
{
|
||||||
if (more >= MAXTUNNEL) {
|
if (more >= MAXTUNNEL) {
|
||||||
LOG(0, 0, 0, "DANGER: Received a tunnel session id > MAXTUNNEL!\n");
|
LOG(0, 0, 0, "DANGER: Received a tunnel session id > MAXTUNNEL!\n");
|
||||||
|
|
@ -1106,7 +1106,7 @@ static int cluster_recv_tunnel(int more, u8 *p)
|
||||||
//
|
//
|
||||||
// v3: added interval, timeout
|
// v3: added interval, timeout
|
||||||
// v4: added table_version
|
// 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 s = size - (p-data);
|
||||||
|
|
@ -1144,7 +1144,7 @@ static int cluster_process_heartbeat(u8 * data, int size, int more, u8 * p, u32
|
||||||
|
|
||||||
if (more >= 4) {
|
if (more >= 4) {
|
||||||
if (h->table_version > config->cluster_table_version) {
|
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);
|
h->table_version, config->cluster_table_version);
|
||||||
|
|
||||||
kill(0, SIGTERM);
|
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...
|
// Ok. process the packet...
|
||||||
while ( s > 0) {
|
while ( s > 0) {
|
||||||
|
|
||||||
type = * ((u32*) p);
|
type = *((uint32_t *) p);
|
||||||
p += sizeof(u32);
|
p += sizeof(uint32_t);
|
||||||
s -= sizeof(u32);
|
s -= sizeof(uint32_t);
|
||||||
|
|
||||||
more = * ((u32*) p);
|
more = *((uint32_t *) p);
|
||||||
p += sizeof(u32);
|
p += sizeof(uint32_t);
|
||||||
s -= sizeof(u32);
|
s -= sizeof(uint32_t);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case C_CSESSION: { // Compressed session structure.
|
case C_CSESSION: { // Compressed session structure.
|
||||||
u8 c [ sizeof(sessiont) + 2];
|
uint8_t c[ sizeof(sessiont) + 2];
|
||||||
int size;
|
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);
|
s -= (p - orig_p);
|
||||||
|
|
||||||
if (size != sizeof(sessiont) ) { // Ouch! Very very bad!
|
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;
|
break;
|
||||||
|
|
||||||
case C_CTUNNEL: { // Compressed tunnel structure.
|
case C_CTUNNEL: { // Compressed tunnel structure.
|
||||||
u8 c [ sizeof(tunnelt) + 2];
|
uint8_t c[ sizeof(tunnelt) + 2];
|
||||||
int size;
|
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);
|
s -= (p - orig_p);
|
||||||
|
|
||||||
if (size != sizeof(tunnelt) ) { // Ouch! Very very bad!
|
if (size != sizeof(tunnelt) ) { // Ouch! Very very bad!
|
||||||
|
|
@ -1310,7 +1310,7 @@ shortpacket:
|
||||||
// We got a packet on the cluster port!
|
// We got a packet on the cluster port!
|
||||||
// Handle pings, lastseens, and heartbeats!
|
// 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;
|
int type, more;
|
||||||
char *p = data;
|
char *p = data;
|
||||||
|
|
@ -1327,13 +1327,13 @@ int processcluster(char * data, int size, u32 addr)
|
||||||
if (s < 8)
|
if (s < 8)
|
||||||
goto shortpacket;
|
goto shortpacket;
|
||||||
|
|
||||||
type = * ((u32*) p);
|
type = *((uint32_t *) p);
|
||||||
p += sizeof(u32);
|
p += sizeof(uint32_t);
|
||||||
s -= sizeof(u32);
|
s -= sizeof(uint32_t);
|
||||||
|
|
||||||
more = * ((u32*) p);
|
more = *((uint32_t *) p);
|
||||||
p += sizeof(u32);
|
p += sizeof(uint32_t);
|
||||||
s -= sizeof(u32);
|
s -= sizeof(uint32_t);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case C_PING: // Update the peers table.
|
case C_PING: // Update the peers table.
|
||||||
|
|
@ -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
|
// Worst case is a 50% expansion in space required (trying to
|
||||||
// compress { 0x00, 0x01 } * N )
|
// 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 count;
|
||||||
int orig_dsize = dsize;
|
int orig_dsize = dsize;
|
||||||
u8 * x,*src;
|
uint8_t *x, *src;
|
||||||
src = *src_p;
|
src = *src_p;
|
||||||
|
|
||||||
while (ssize > 0 && dsize > 2) {
|
while (ssize > 0 && dsize > 2) {
|
||||||
|
|
@ -1527,7 +1527,7 @@ static int rle_compress(u8 ** src_p, int ssize, u8 *dst, int dsize)
|
||||||
// Return the number of dst bytes used.
|
// Return the number of dst bytes used.
|
||||||
// Updates the 'src_p' pointer to point to the
|
// Updates the 'src_p' pointer to point to the
|
||||||
// first un-used byte.
|
// 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 count;
|
||||||
int orig_dsize = dsize;
|
int orig_dsize = dsize;
|
||||||
|
|
|
||||||
46
cluster.h
46
cluster.h
|
|
@ -1,5 +1,5 @@
|
||||||
// L2TPNS Clustering Stuff
|
// 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__
|
#ifndef __CLUSTER_H__
|
||||||
#define __CLUSTER_H__
|
#define __CLUSTER_H__
|
||||||
|
|
@ -34,44 +34,44 @@
|
||||||
#define DEFAULT_MCAST_INTERFACE "eth0"
|
#define DEFAULT_MCAST_INTERFACE "eth0"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 version; // protocol version.
|
uint32_t version; // protocol version.
|
||||||
u32 seq; // Sequence number for this heatbeat.
|
uint32_t seq; // Sequence number for this heatbeat.
|
||||||
u32 basetime; // What time I started
|
uint32_t basetime; // What time I started
|
||||||
u32 clusterid; // Id for this cluster?
|
uint32_t clusterid; // Id for this cluster?
|
||||||
|
|
||||||
u32 highsession; // Id of the highest in-use session.
|
uint32_t highsession; // Id of the highest in-use session.
|
||||||
u32 freesession; // Id of the first free session.
|
uint32_t freesession; // Id of the first free session.
|
||||||
u32 hightunnel; // Id of the highest used tunnel.
|
uint32_t hightunnel; // Id of the highest used tunnel.
|
||||||
u32 size_sess; // Size of the session structure.
|
uint32_t size_sess; // Size of the session structure.
|
||||||
|
|
||||||
u32 size_tunn; // size of the tunnel structure.
|
uint32_t size_tunn; // size of the tunnel structure.
|
||||||
u32 interval; // ping/heartbeat interval
|
uint32_t interval; // ping/heartbeat interval
|
||||||
u32 timeout; // heartbeat timeout
|
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;
|
} heartt;
|
||||||
|
|
||||||
typedef struct { /* Used to update byte counters on the */
|
typedef struct { /* Used to update byte counters on the */
|
||||||
/* master. */
|
/* master. */
|
||||||
u32 sid;
|
uint32_t sid;
|
||||||
u32 in;
|
uint32_t in;
|
||||||
u32 out;
|
uint32_t out;
|
||||||
} bytest;
|
} bytest;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 addr; //
|
in_addr_t addr; // peer address
|
||||||
u32 ver; // version of structure.
|
uint32_t ver; // version of structure.
|
||||||
u32 undef; // Number of undefined structures. 0 if up-to-date.
|
uint32_t undef; // Number of undefined structures. 0 if up-to-date.
|
||||||
u32 basetime; // start time of this peer.
|
uint32_t basetime; // start time of this peer.
|
||||||
} pingt;
|
} pingt;
|
||||||
|
|
||||||
int cluster_init(void);
|
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_session(int sid);
|
||||||
int cluster_send_tunnel(int tid);
|
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_throttle_packet(int tid, char *data, int size);
|
||||||
int master_garden_packet(sessionidt s, char *data, int size);
|
int master_garden_packet(sessionidt s, char *data, int size);
|
||||||
void master_update_counts(void);
|
void master_update_counts(void);
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
// L2TPNS: control
|
// 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 <string.h>
|
||||||
#include "l2tpns.h"
|
#include "l2tpns.h"
|
||||||
#include "control.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_packet pkt;
|
||||||
struct nsctl_args arg;
|
struct nsctl_args arg;
|
||||||
|
|
@ -102,7 +102,7 @@ int unpack_control(struct nsctl *control, char *data, int len)
|
||||||
if (len < sz + 1)
|
if (len < sz + 1)
|
||||||
return NSCTL_ERR_SHORT;
|
return NSCTL_ERR_SHORT;
|
||||||
|
|
||||||
s = (u8) *p;
|
s = (uint8_t) *p;
|
||||||
*p++ = 0; // null terminate previous arg
|
*p++ = 0; // null terminate previous arg
|
||||||
sz++;
|
sz++;
|
||||||
|
|
||||||
|
|
|
||||||
14
control.h
14
control.h
|
|
@ -27,27 +27,27 @@
|
||||||
#define NSCTL_MAX_PKT_SZ 4096
|
#define NSCTL_MAX_PKT_SZ 4096
|
||||||
|
|
||||||
struct nsctl_packet {
|
struct nsctl_packet {
|
||||||
u16 magic;
|
uint16_t magic;
|
||||||
u8 type;
|
uint8_t type;
|
||||||
u8 argc;
|
uint8_t argc;
|
||||||
char argv[NSCTL_MAX_PKT_SZ - 4];
|
char argv[NSCTL_MAX_PKT_SZ - 4];
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
#define NSCTL_MAX_ARG_SZ 512
|
#define NSCTL_MAX_ARG_SZ 512
|
||||||
|
|
||||||
struct nsctl_args {
|
struct nsctl_args {
|
||||||
u8 len;
|
uint8_t len;
|
||||||
char value[NSCTL_MAX_ARG_SZ - 1];
|
char value[NSCTL_MAX_ARG_SZ - 1];
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
/* parsed packet */
|
/* parsed packet */
|
||||||
struct nsctl {
|
struct nsctl {
|
||||||
u8 type;
|
uint8_t type;
|
||||||
u8 argc;
|
uint8_t argc;
|
||||||
char *argv[0xff];
|
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);
|
int unpack_control(struct nsctl *packet, char *data, int len);
|
||||||
void dump_control(struct nsctl *control, FILE *stream);
|
void dump_control(struct nsctl *control, FILE *stream);
|
||||||
|
|
||||||
|
|
|
||||||
4
garden.c
4
garden.c
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
/* walled garden */
|
/* 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;
|
int plugin_api_version = PLUGIN_API_VERSION;
|
||||||
static struct pluginfuncs *p = 0;
|
static struct pluginfuncs *p = 0;
|
||||||
|
|
@ -213,7 +213,7 @@ int garden_session(sessiont *s, int flag)
|
||||||
if (flag != F_CLEANUP)
|
if (flag != F_CLEANUP)
|
||||||
{
|
{
|
||||||
/* OK, we're up! */
|
/* 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);
|
p->radiussend(r, RADIUSSTART);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
icmp.c
12
icmp.c
|
|
@ -1,6 +1,6 @@
|
||||||
// L2TPNS: icmp
|
// 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 <arpa/inet.h>
|
||||||
#include <netdb.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"
|
#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};
|
char buf[128] = {0};
|
||||||
struct iphdr *iph;
|
struct iphdr *iph;
|
||||||
|
|
@ -68,13 +68,13 @@ void host_unreachable(ipt destination, u16 id, ipt source, char *packet, int pac
|
||||||
close(icmp_socket);
|
close(icmp_socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
static __u16 _checksum(unsigned char *addr, int count)
|
static uint16_t _checksum(unsigned char *addr, int count)
|
||||||
{
|
{
|
||||||
register long sum = 0;
|
register long sum = 0;
|
||||||
|
|
||||||
for (; count > 1; count -= 2)
|
for (; count > 1; count -= 2)
|
||||||
{
|
{
|
||||||
sum += ntohs(*(u32 *)addr);
|
sum += ntohs(*(uint32_t *) addr);
|
||||||
addr += 2;
|
addr += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,5 +87,5 @@ static __u16 _checksum(unsigned char *addr, int count)
|
||||||
// one's complement the result
|
// one's complement the result
|
||||||
sum = ~sum;
|
sum = ~sum;
|
||||||
|
|
||||||
return htons((u16) sum);
|
return htons((uint16_t) sum);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
210
l2tpns.h
210
l2tpns.h
|
|
@ -1,5 +1,5 @@
|
||||||
// L2TPNS Global Stuff
|
// 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__
|
#ifndef __L2TPNS_H__
|
||||||
#define __L2TPNS_H__
|
#define __L2TPNS_H__
|
||||||
|
|
@ -108,22 +108,16 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
typedef unsigned short u16;
|
typedef uint16_t sessionidt;
|
||||||
typedef unsigned int u32;
|
typedef uint16_t tunnelidt;
|
||||||
typedef unsigned long long u64;
|
typedef uint32_t clockt;
|
||||||
typedef unsigned char u8;
|
typedef uint8_t hasht[16];
|
||||||
typedef u32 ipt;
|
|
||||||
typedef u16 portt;
|
|
||||||
typedef u16 sessionidt;
|
|
||||||
typedef u16 tunnelidt;
|
|
||||||
typedef u32 clockt;
|
|
||||||
typedef u8 hasht[16];
|
|
||||||
|
|
||||||
// CLI actions
|
// CLI actions
|
||||||
struct cli_session_actions {
|
struct cli_session_actions {
|
||||||
char action;
|
char action;
|
||||||
ipt snoop_ip;
|
in_addr_t snoop_ip;
|
||||||
u16 snoop_port;
|
uint16_t snoop_port;
|
||||||
int throttle_in;
|
int throttle_in;
|
||||||
int throttle_out;
|
int throttle_out;
|
||||||
int filter_in;
|
int filter_in;
|
||||||
|
|
@ -150,16 +144,16 @@ struct cli_tunnel_actions {
|
||||||
// structures
|
// structures
|
||||||
typedef struct // route
|
typedef struct // route
|
||||||
{
|
{
|
||||||
ipt ip;
|
in_addr_t ip;
|
||||||
ipt mask;
|
in_addr_t mask;
|
||||||
}
|
}
|
||||||
routet;
|
routet;
|
||||||
|
|
||||||
typedef struct controls // control message
|
typedef struct controls // control message
|
||||||
{
|
{
|
||||||
struct controls *next; // next in queue
|
struct controls *next; // next in queue
|
||||||
u16 length; // length
|
uint16_t length; // length
|
||||||
u8 buf[MAXCONTROL];
|
uint8_t buf[MAXCONTROL];
|
||||||
}
|
}
|
||||||
controlt;
|
controlt;
|
||||||
|
|
||||||
|
|
@ -168,45 +162,45 @@ typedef struct
|
||||||
sessionidt next; // next session in linked list
|
sessionidt next; // next session in linked list
|
||||||
sessionidt far; // far end session ID
|
sessionidt far; // far end session ID
|
||||||
tunnelidt tunnel; // near end tunnel 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
|
int ip_pool_index; // index to IP pool
|
||||||
unsigned long unique_id; // unique session id
|
unsigned long unique_id; // unique session id
|
||||||
u16 nr; // next receive
|
uint16_t nr; // next receive
|
||||||
u16 ns; // next send
|
uint16_t ns; // next send
|
||||||
u32 magic; // ppp magic number
|
uint32_t magic; // ppp magic number
|
||||||
u32 cin, cout; // byte counts
|
uint32_t cin, cout; // byte counts
|
||||||
u32 pin, pout; // packet counts
|
uint32_t pin, pout; // packet counts
|
||||||
u32 total_cin; // This counter is never reset while a session is open
|
uint32_t 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
|
uint32_t total_cout; // This counter is never reset while a session is open
|
||||||
u32 id; // session id
|
uint32_t id; // session id
|
||||||
u16 throttle_in; // upstream throttle rate (kbps)
|
uint16_t throttle_in; // upstream throttle rate (kbps)
|
||||||
u16 throttle_out; // downstream throttle rate
|
uint16_t throttle_out; // downstream throttle rate
|
||||||
clockt opened; // when started
|
clockt opened; // when started
|
||||||
clockt die; // being closed, when to finally free
|
clockt die; // being closed, when to finally free
|
||||||
time_t last_packet; // Last packet from the user (used for idle timeouts)
|
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
|
routet route[MAXROUTE]; // static routes
|
||||||
u16 radius; // which radius session is being used (0 for not waiting on authentication)
|
uint16_t radius; // which radius session is being used (0 for not waiting on authentication)
|
||||||
u16 mru; // maximum receive unit
|
uint16_t mru; // maximum receive unit
|
||||||
u16 tbf_in; // filter bucket for throttling in from the user.
|
uint16_t tbf_in; // filter bucket for throttling in from the user.
|
||||||
u16 tbf_out; // filter bucket for throttling out to the user.
|
uint16_t tbf_out; // filter bucket for throttling out to the user.
|
||||||
u8 l2tp_flags; // various bit flags from the ICCN on the l2tp tunnel.
|
uint8_t l2tp_flags; // various bit flags from the ICCN on the l2tp tunnel.
|
||||||
u8 reserved_old_snoop; // No longer used - remove at some time
|
uint8_t reserved_old_snoop; // No longer used - remove at some time
|
||||||
u8 walled_garden; // is this session gardened?
|
uint8_t walled_garden; // is this session gardened?
|
||||||
u8 flags1; // additional flags (currently unused);
|
uint8_t flags1; // additional flags (currently unused);
|
||||||
char random_vector[MAXTEL];
|
char random_vector[MAXTEL];
|
||||||
int random_vector_length;
|
int random_vector_length;
|
||||||
char user[129]; // user (needed in seesion for radius stop messages) (can we reduce this? --mo)
|
char user[129]; // user (needed in seesion for radius stop messages) (can we reduce this? --mo)
|
||||||
char called[MAXTEL]; // called number
|
char called[MAXTEL]; // called number
|
||||||
char calling[MAXTEL]; // calling number
|
char calling[MAXTEL]; // calling number
|
||||||
u32 tx_connect_speed;
|
uint32_t tx_connect_speed;
|
||||||
u32 rx_connect_speed;
|
uint32_t rx_connect_speed;
|
||||||
u32 flags; // Various session flags.
|
uint32_t flags; // Various session flags.
|
||||||
ipt snoop_ip; // Interception destination IP
|
in_addr_t snoop_ip; // Interception destination IP
|
||||||
u16 snoop_port; // Interception destination port
|
uint16_t snoop_port; // Interception destination port
|
||||||
u16 sid; // near end session id.
|
uint16_t sid; // near end session id.
|
||||||
u8 filter_in; // input filter index (to ip_filters[N-1]; 0 if none)
|
uint8_t filter_in; // input filter index (to ip_filters[N-1]; 0 if none)
|
||||||
u8 filter_out; // output filter index
|
uint8_t filter_out; // output filter index
|
||||||
char reserved[18]; // Space to expand structure without changing HB_VERSION
|
char reserved[18]; // Space to expand structure without changing HB_VERSION
|
||||||
}
|
}
|
||||||
sessiont;
|
sessiont;
|
||||||
|
|
@ -217,8 +211,8 @@ sessiont;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u32 cin;
|
uint32_t cin;
|
||||||
u32 cout;
|
uint32_t cout;
|
||||||
} sessioncountt;
|
} sessioncountt;
|
||||||
|
|
||||||
#define SESSIONPFC 1 // PFC negotiated flags
|
#define SESSIONPFC 1 // PFC negotiated flags
|
||||||
|
|
@ -228,11 +222,11 @@ typedef struct
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
tunnelidt far; // far end tunnel ID
|
tunnelidt far; // far end tunnel ID
|
||||||
ipt ip; // Ip for far end
|
in_addr_t ip; // Ip for far end
|
||||||
portt port; // port for far end
|
uint16_t port; // port for far end
|
||||||
u16 window; // Rx window
|
uint16_t window; // Rx window
|
||||||
u16 nr; // next receive
|
uint16_t nr; // next receive
|
||||||
u16 ns; // next send
|
uint16_t ns; // next send
|
||||||
int state; // current state (tunnelstate enum)
|
int state; // current state (tunnelstate enum)
|
||||||
clockt last; // when last control message sent (used for resend timeout)
|
clockt last; // when last control message sent (used for resend timeout)
|
||||||
clockt retry; // when to try resenting pending control
|
clockt retry; // when to try resenting pending control
|
||||||
|
|
@ -240,8 +234,8 @@ typedef struct
|
||||||
clockt lastrec; // when the last control message was received
|
clockt lastrec; // when the last control message was received
|
||||||
char hostname[128]; // tunnel hostname
|
char hostname[128]; // tunnel hostname
|
||||||
char vendor[128]; // LAC vendor
|
char vendor[128]; // LAC vendor
|
||||||
u8 try; // number of retrys on a control message
|
uint8_t try; // number of retrys on a control message
|
||||||
u16 controlc; // outstaind messages in queue
|
uint16_t controlc; // outstaind messages in queue
|
||||||
controlt *controls; // oldest message
|
controlt *controls; // oldest message
|
||||||
controlt *controle; // newest message
|
controlt *controle; // newest message
|
||||||
}
|
}
|
||||||
|
|
@ -255,16 +249,16 @@ typedef struct // outstanding RADIUS requests
|
||||||
clockt retry; // when to try next
|
clockt retry; // when to try next
|
||||||
char calling[MAXTEL]; // calling number
|
char calling[MAXTEL]; // calling number
|
||||||
char pass[129]; // password
|
char pass[129]; // password
|
||||||
u8 id; // ID for PPP response
|
uint8_t id; // ID for PPP response
|
||||||
u8 try; // which try we are on
|
uint8_t try; // which try we are on
|
||||||
u8 state; // state of radius requests
|
uint8_t state; // state of radius requests
|
||||||
u8 chap; // set if CHAP used (is CHAP identifier)
|
uint8_t chap; // set if CHAP used (is CHAP identifier)
|
||||||
}
|
}
|
||||||
radiust;
|
radiust;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
ipt address; // Host byte order..
|
in_addr_t address; // Host byte order..
|
||||||
char assigned; // 1 if assigned, 0 if free
|
char assigned; // 1 if assigned, 0 if free
|
||||||
sessionidt session;
|
sessionidt session;
|
||||||
clockt last; // last used
|
clockt last; // last used
|
||||||
|
|
@ -423,20 +417,20 @@ typedef struct
|
||||||
|
|
||||||
char radiussecret[64];
|
char radiussecret[64];
|
||||||
int radius_accounting;
|
int radius_accounting;
|
||||||
ipt radiusserver[MAXRADSERVER]; // radius servers
|
in_addr_t radiusserver[MAXRADSERVER]; // radius servers
|
||||||
u16 radiusport[MAXRADSERVER]; // radius base ports
|
uint16_t radiusport[MAXRADSERVER]; // radius base ports
|
||||||
u8 numradiusservers; // radius server count
|
uint8_t numradiusservers; // radius server count
|
||||||
short num_radfds; // Number of radius filehandles allocated
|
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
|
unsigned long rl_rate; // default throttle rate
|
||||||
int num_tbfs; // number of throttle buckets
|
int num_tbfs; // number of throttle buckets
|
||||||
|
|
||||||
int save_state;
|
int save_state;
|
||||||
char accounting_dir[128];
|
char accounting_dir[128];
|
||||||
ipt bind_address;
|
in_addr_t bind_address;
|
||||||
ipt peer_address;
|
in_addr_t peer_address;
|
||||||
int send_garp; // Set to true to garp for vip address on startup
|
int send_garp; // Set to true to garp for vip address on startup
|
||||||
|
|
||||||
int target_uid;
|
int target_uid;
|
||||||
|
|
@ -449,12 +443,12 @@ typedef struct
|
||||||
int lock_pages; // Lock pages into memory.
|
int lock_pages; // Lock pages into memory.
|
||||||
int icmp_rate; // Max number of ICMP unreachable per second to send>
|
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.
|
// Send to this address to have everyone hear.
|
||||||
char cluster_interface[64]; // Which interface to listen for multicast on.
|
char cluster_interface[64]; // Which interface to listen for multicast on.
|
||||||
int cluster_iam_master; // Are we the cluster master???
|
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.
|
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.
|
// Zero if i am the cluster master.
|
||||||
int cluster_seq_number; // Sequence number of the next heartbeat we'll send out
|
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).
|
// (or the seq number we're next expecting if we're a slave).
|
||||||
|
|
@ -467,14 +461,14 @@ typedef struct
|
||||||
|
|
||||||
int cluster_hb_interval; // How often to send a heartbeat.
|
int cluster_hb_interval; // How often to send a heartbeat.
|
||||||
int cluster_hb_timeout; // How many missed heartbeats trigger an election.
|
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
|
#ifdef BGP
|
||||||
#define BGP_NUM_PEERS 2
|
#define BGP_NUM_PEERS 2
|
||||||
u16 as_number;
|
uint16_t as_number;
|
||||||
struct {
|
struct {
|
||||||
char name[64];
|
char name[64];
|
||||||
u16 as;
|
uint16_t as;
|
||||||
int keepalive;
|
int keepalive;
|
||||||
int hold;
|
int hold;
|
||||||
} neighbour[BGP_NUM_PEERS];
|
} neighbour[BGP_NUM_PEERS];
|
||||||
|
|
@ -492,15 +486,15 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
u8 op; // operation
|
uint8_t op; // operation
|
||||||
#define FILTER_PORT_OP_NONE 0 // all ports match
|
#define FILTER_PORT_OP_NONE 0 // all ports match
|
||||||
#define FILTER_PORT_OP_EQ 1
|
#define FILTER_PORT_OP_EQ 1
|
||||||
#define FILTER_PORT_OP_NEQ 2
|
#define FILTER_PORT_OP_NEQ 2
|
||||||
#define FILTER_PORT_OP_GT 3
|
#define FILTER_PORT_OP_GT 3
|
||||||
#define FILTER_PORT_OP_LT 4
|
#define FILTER_PORT_OP_LT 4
|
||||||
#define FILTER_PORT_OP_RANGE 5
|
#define FILTER_PORT_OP_RANGE 5
|
||||||
portt port; // port (host byte order)
|
uint16_t port; // port (host byte order)
|
||||||
portt port2; // range
|
uint16_t port2; // range
|
||||||
} ip_filter_portt;
|
} ip_filter_portt;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
@ -508,21 +502,21 @@ typedef struct
|
||||||
int action; // permit/deny
|
int action; // permit/deny
|
||||||
#define FILTER_ACTION_DENY 1
|
#define FILTER_ACTION_DENY 1
|
||||||
#define FILTER_ACTION_PERMIT 2
|
#define FILTER_ACTION_PERMIT 2
|
||||||
u8 proto; // protocol: IPPROTO_* (netinet/in.h)
|
uint8_t proto; // protocol: IPPROTO_* (netinet/in.h)
|
||||||
ipt src_ip; // source ip (network byte order)
|
in_addr_t src_ip; // source ip (network byte order)
|
||||||
ipt src_wild;
|
in_addr_t src_wild;
|
||||||
ip_filter_portt src_ports;
|
ip_filter_portt src_ports;
|
||||||
ipt dst_ip; // dest ip
|
in_addr_t dst_ip; // dest ip
|
||||||
ipt dst_wild;
|
in_addr_t dst_wild;
|
||||||
ip_filter_portt dst_ports;
|
ip_filter_portt dst_ports;
|
||||||
u8 frag; // apply to non-initial fragments
|
uint8_t frag; // apply to non-initial fragments
|
||||||
u8 tcp_flag_op; // match type: any, all, established
|
uint8_t tcp_flag_op; // match type: any, all, established
|
||||||
#define FILTER_FLAG_OP_ANY 1
|
#define FILTER_FLAG_OP_ANY 1
|
||||||
#define FILTER_FLAG_OP_ALL 2
|
#define FILTER_FLAG_OP_ALL 2
|
||||||
#define FILTER_FLAG_OP_EST 3
|
#define FILTER_FLAG_OP_EST 3
|
||||||
u8 tcp_sflags; // flags set
|
uint8_t tcp_sflags; // flags set
|
||||||
u8 tcp_cflags; // flags clear
|
uint8_t tcp_cflags; // flags clear
|
||||||
u32 counter; // match count
|
uint32_t counter; // match count
|
||||||
} ip_filter_rulet;
|
} ip_filter_rulet;
|
||||||
|
|
||||||
#define TCP_FLAG_FIN 0x01
|
#define TCP_FLAG_FIN 0x01
|
||||||
|
|
@ -543,42 +537,42 @@ typedef struct
|
||||||
} ip_filtert;
|
} ip_filtert;
|
||||||
|
|
||||||
// arp.c
|
// 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
|
// ppp.c
|
||||||
void processpap(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, u8 * p, u16 l);
|
void processchap(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||||
void processlcp(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
void processlcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||||
void processipcp(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
void processipcp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||||
void processipin(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
void processipin(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||||
void processccp(tunnelidt t, sessionidt s, u8 * p, u16 l);
|
void processccp(tunnelidt t, sessionidt s, uint8_t *p, uint16_t l);
|
||||||
void sendchap(tunnelidt t, sessionidt s);
|
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 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
|
// radius.c
|
||||||
void initrad(void);
|
void initrad(void);
|
||||||
void radiussend(u16 r, u8 state);
|
void radiussend(uint16_t r, uint8_t state);
|
||||||
void processrad(u8 *buf, int len, char socket_index);
|
void processrad(uint8_t *buf, int len, char socket_index);
|
||||||
void radiusretry(u16 r);
|
void radiusretry(uint16_t r);
|
||||||
u16 radiusnew(sessionidt s);
|
uint16_t radiusnew(sessionidt s);
|
||||||
void radiusclear(u16 r, sessionidt s);
|
void radiusclear(uint16_t r, sessionidt s);
|
||||||
|
|
||||||
|
|
||||||
// l2tpns.c
|
// l2tpns.c
|
||||||
clockt backoff(u8 try);
|
clockt backoff(uint8_t try);
|
||||||
sessionidt sessionbyip(ipt ip);
|
sessionidt sessionbyip(in_addr_t ip);
|
||||||
sessionidt sessionbyuser(char *username);
|
sessionidt sessionbyuser(char *username);
|
||||||
void sessionshutdown(sessionidt s, char *reason);
|
void sessionshutdown(sessionidt s, char *reason);
|
||||||
void send_garp(ipt ip);
|
void send_garp(in_addr_t ip);
|
||||||
void tunnelsend(u8 * buf, u16 l, tunnelidt t);
|
void tunnelsend(uint8_t *buf, uint16_t l, tunnelidt t);
|
||||||
void sendipcp(tunnelidt t, sessionidt s);
|
void sendipcp(tunnelidt t, sessionidt s);
|
||||||
void processudp(u8 * buf, int len, struct sockaddr_in *addr);
|
void processudp(uint8_t *buf, int len, struct sockaddr_in *addr);
|
||||||
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);
|
||||||
int ip_filter(u8 *buf, int len, u8 filter);
|
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_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_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);
|
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
|
// 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 tunnelt *tunnel;
|
||||||
|
|
@ -635,10 +629,10 @@ if (count++ < max) { \
|
||||||
extern configt *config;
|
extern configt *config;
|
||||||
extern time_t basetime; // Time when this process started.
|
extern time_t basetime; // Time when this process started.
|
||||||
extern time_t time_now; // Seconds since EPOCH.
|
extern time_t time_now; // Seconds since EPOCH.
|
||||||
extern u32 last_id;
|
extern uint32_t last_id;
|
||||||
extern struct Tstats *_statistics;
|
extern struct Tstats *_statistics;
|
||||||
extern ipt my_address;
|
extern in_addr_t my_address;
|
||||||
extern int tun_write(u8 *data, int size);
|
extern int tun_write(uint8_t *data, int size);
|
||||||
extern int clifd;
|
extern int clifd;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,5 +43,5 @@ rm -rf %{buildroot}
|
||||||
%attr(644,root,root) /usr/share/man/man[58]/*
|
%attr(644,root,root) /usr/share/man/man[58]/*
|
||||||
|
|
||||||
%changelog
|
%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
|
- 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)(int level, sessionidt s, tunnelidt t, const char *format, ...);
|
||||||
void (*log_hex)(int level, const char *title, const char *data, int maxsize);
|
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);
|
sessionidt (*get_session_by_username)(char *username);
|
||||||
sessiont *(*get_session_by_id)(sessionidt s);
|
sessiont *(*get_session_by_id)(sessionidt s);
|
||||||
sessionidt (*get_id_by_session)(sessiont *s);
|
sessionidt (*get_id_by_session)(sessiont *s);
|
||||||
u16 (*radiusnew)(sessionidt s);
|
uint16_t (*radiusnew)(sessionidt s);
|
||||||
void (*radiussend)(u16 r, u8 state);
|
void (*radiussend)(uint16_t r, uint8_t state);
|
||||||
void *(*getconfig)(char *key, enum config_typet type);
|
void *(*getconfig)(char *key, enum config_typet type);
|
||||||
void (*sessionkill)(sessionidt s, char *reason);
|
void (*sessionkill)(sessionidt s, char *reason);
|
||||||
void (*throttle)(sessionidt s, int rate_in, int rate_out);
|
void (*throttle)(sessionidt s, int rate_in, int rate_out);
|
||||||
|
|
|
||||||
169
ppp.c
169
ppp.c
|
|
@ -1,6 +1,6 @@
|
||||||
// L2TPNS PPP Stuff
|
// 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 <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -19,18 +19,18 @@ extern sessiont *session;
|
||||||
extern radiust *radius;
|
extern radiust *radius;
|
||||||
extern int tunfd;
|
extern int tunfd;
|
||||||
extern char hostname[];
|
extern char hostname[];
|
||||||
extern u32 eth_tx;
|
extern uint32_t eth_tx;
|
||||||
extern time_t time_now;
|
extern time_t time_now;
|
||||||
extern configt *config;
|
extern configt *config;
|
||||||
|
|
||||||
static void initccp(tunnelidt t, sessionidt s);
|
static void initccp(tunnelidt t, sessionidt s);
|
||||||
|
|
||||||
// Process PAP messages
|
// 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 user[129];
|
||||||
char pass[129];
|
char pass[129];
|
||||||
u16 hl;
|
uint16_t hl;
|
||||||
|
|
||||||
CSTAT(call_processpap);
|
CSTAT(call_processpap);
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
return ;
|
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);
|
LOG(1, s, t, "Length mismatch PAP %u/%u\n", hl, l);
|
||||||
STAT(tunnel_rx_errors);
|
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;
|
b += 4;
|
||||||
if (*b && *b < sizeof(user))
|
if (*b && *b < sizeof(user))
|
||||||
memcpy(user, b + 1, *b);
|
memcpy(user, b + 1, *b);
|
||||||
|
|
@ -72,9 +72,9 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
if (session[s].ip || !session[s].radius)
|
if (session[s].ip || !session[s].radius)
|
||||||
{
|
{
|
||||||
// respond now, either no RADIUS available or already authenticated
|
// respond now, either no RADIUS available or already authenticated
|
||||||
u8 b[MAXCONTROL];
|
uint8_t b[MAXCONTROL];
|
||||||
u8 id = p[1];
|
uint8_t id = p[1];
|
||||||
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;
|
if (!p) return;
|
||||||
|
|
||||||
if (session[s].ip)
|
if (session[s].ip)
|
||||||
|
|
@ -82,7 +82,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
else
|
else
|
||||||
*p = 3; // cant authorise
|
*p = 3; // cant authorise
|
||||||
p[1] = id;
|
p[1] = id;
|
||||||
*(u16 *) (p + 2) = htons(5); // length
|
*(uint16_t *) (p + 2) = htons(5); // length
|
||||||
p[4] = 0; // no message
|
p[4] = 0; // no message
|
||||||
if (session[s].ip)
|
if (session[s].ip)
|
||||||
{
|
{
|
||||||
|
|
@ -101,7 +101,7 @@ void processpap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// set up RADIUS request
|
// set up RADIUS request
|
||||||
u16 r = session[s].radius;
|
uint16_t r = session[s].radius;
|
||||||
|
|
||||||
// Run PRE_AUTH plugins
|
// Run PRE_AUTH plugins
|
||||||
struct param_pre_auth packet = { &tunnel[t], &session[s], strdup(user), strdup(pass), PPPPAP, 1 };
|
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
|
// 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;
|
uint16_t r;
|
||||||
u16 hl;
|
uint16_t hl;
|
||||||
|
|
||||||
CSTAT(call_processchap);
|
CSTAT(call_processchap);
|
||||||
|
|
||||||
|
|
@ -153,7 +153,7 @@ void processchap(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
return ;
|
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);
|
LOG(1, s, t, "Length mismatch CHAP %u/%u\n", hl, l);
|
||||||
STAT(tunnel_rx_errors);
|
STAT(tunnel_rx_errors);
|
||||||
|
|
@ -240,13 +240,13 @@ static char *ppp_lcp_types[] = {
|
||||||
"IdentRequest",
|
"IdentRequest",
|
||||||
};
|
};
|
||||||
|
|
||||||
static void dumplcp(u8 *p, int l)
|
static void dumplcp(uint8_t *p, int l)
|
||||||
{
|
{
|
||||||
int x = l - 4;
|
int x = l - 4;
|
||||||
u8 *o = (p + 4);
|
uint8_t *o = (p + 4);
|
||||||
|
|
||||||
LOG_HEX(5, "PPP LCP Packet", p, l);
|
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);
|
LOG(4, 0, 0, "Length: %d\n", l);
|
||||||
if (*p != ConfigReq && *p != ConfigRej && *p != ConfigAck)
|
if (*p != ConfigReq && *p != ConfigRej && *p != ConfigAck)
|
||||||
return;
|
return;
|
||||||
|
|
@ -271,14 +271,14 @@ static void dumplcp(u8 *p, int l)
|
||||||
{
|
{
|
||||||
case 1: // Maximum-Receive-Unit
|
case 1: // Maximum-Receive-Unit
|
||||||
if (length == 4)
|
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
|
else
|
||||||
LOG(4, 0, 0, " %s odd length %d\n", lcp_types[type], length);
|
LOG(4, 0, 0, " %s odd length %d\n", lcp_types[type], length);
|
||||||
break;
|
break;
|
||||||
case 2: // Async-Control-Character-Map
|
case 2: // Async-Control-Character-Map
|
||||||
if (length == 6)
|
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);
|
LOG(4, 0, 0, " %s %x\n", lcp_types[type], asyncmap);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -287,7 +287,7 @@ static void dumplcp(u8 *p, int l)
|
||||||
case 3: // Authentication-Protocol
|
case 3: // Authentication-Protocol
|
||||||
if (length == 4)
|
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,
|
LOG(4, 0, 0, " %s 0x%x (%s)\n", lcp_types[type], proto,
|
||||||
proto == PPPCHAP ? "CHAP" :
|
proto == PPPCHAP ? "CHAP" :
|
||||||
proto == PPPPAP ? "PAP" : "UNKNOWN");
|
proto == PPPPAP ? "PAP" : "UNKNOWN");
|
||||||
|
|
@ -297,14 +297,14 @@ static void dumplcp(u8 *p, int l)
|
||||||
break;
|
break;
|
||||||
case 4: // Quality-Protocol
|
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);
|
LOG(4, 0, 0, " %s %x\n", lcp_types[type], qp);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5: // Magic-Number
|
case 5: // Magic-Number
|
||||||
if (length == 6)
|
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);
|
LOG(4, 0, 0, " %s %x\n", lcp_types[type], magicno);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -324,12 +324,12 @@ static void dumplcp(u8 *p, int l)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process LCP messages
|
// 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];
|
uint8_t b[MAXCONTROL];
|
||||||
u8 *q = NULL;
|
uint8_t *q = NULL;
|
||||||
u32 magicno = 0;
|
uint32_t magicno = 0;
|
||||||
u16 hl;
|
uint16_t hl;
|
||||||
|
|
||||||
CSTAT(call_processlcp);
|
CSTAT(call_processlcp);
|
||||||
|
|
||||||
|
|
@ -341,7 +341,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
return ;
|
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);
|
LOG(1, s, t, "Length mismatch LCP %u/%u\n", hl, l);
|
||||||
STAT(tunnel_rx_errors);
|
STAT(tunnel_rx_errors);
|
||||||
|
|
@ -357,8 +357,8 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
else if (*p == ConfigReq)
|
else if (*p == ConfigReq)
|
||||||
{
|
{
|
||||||
int x = l - 4;
|
int x = l - 4;
|
||||||
u8 *o = (p + 4);
|
uint8_t *o = (p + 4);
|
||||||
u8 *response = 0;
|
uint8_t *response = 0;
|
||||||
|
|
||||||
LOG(3, s, t, "LCP: ConfigReq (%d bytes)...\n", l);
|
LOG(3, s, t, "LCP: ConfigReq (%d bytes)...\n", l);
|
||||||
if (config->debug > 3) dumplcp(p, l);
|
if (config->debug > 3) dumplcp(p, l);
|
||||||
|
|
@ -372,11 +372,11 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case 1: // Maximum-Receive-Unit
|
case 1: // Maximum-Receive-Unit
|
||||||
session[s].mru = ntohs(*(u16 *)(o + 2));
|
session[s].mru = ntohs(*(uint16_t *)(o + 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // Async-Control-Character-Map
|
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;
|
break;
|
||||||
|
|
||||||
if (response && *response != ConfigNak) // rej already queued
|
if (response && *response != ConfigNak) // rej already queued
|
||||||
|
|
@ -401,12 +401,12 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
*q++ = 6;
|
*q++ = 6;
|
||||||
memset(q, 0, 4); // asyncmap 0
|
memset(q, 0, 4); // asyncmap 0
|
||||||
q += 4;
|
q += 4;
|
||||||
*((u16 *) (response + 2)) = htons(q - response); // LCP header length
|
*((uint16_t *) (response + 2)) = htons(q - response); // LCP header length
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // Authentication-Protocol
|
case 3: // Authentication-Protocol
|
||||||
{
|
{
|
||||||
int proto = ntohs(*(u16 *)(o + 2));
|
int proto = ntohs(*(uint16_t *)(o + 2));
|
||||||
char proto_name[] = "0x0000";
|
char proto_name[] = "0x0000";
|
||||||
if (proto == PPPPAP)
|
if (proto == PPPPAP)
|
||||||
break;
|
break;
|
||||||
|
|
@ -436,14 +436,14 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(q, o, length);
|
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;
|
q += length;
|
||||||
*((u16 *) (response + 2)) = htons(q - response);
|
*((uint16_t *) (response + 2)) = htons(q - response);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5: // Magic-Number
|
case 5: // Magic-Number
|
||||||
magicno = ntohl(*(u32 *)(o + 2));
|
magicno = ntohl(*(uint32_t *)(o + 2));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4: // Quality-Protocol
|
case 4: // Quality-Protocol
|
||||||
|
|
@ -469,7 +469,7 @@ void processlcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
|
|
||||||
memcpy(q, o, length);
|
memcpy(q, o, length);
|
||||||
q += length;
|
q += length;
|
||||||
*((u16 *) (response + 2)) = htons(q - response); // LCP header length
|
*((uint16_t *) (response + 2)) = htons(q - response); // LCP header length
|
||||||
}
|
}
|
||||||
x -= length;
|
x -= length;
|
||||||
o += 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");
|
LOG(5, s, t, "LCP: Received EchoReq. Sending EchoReply\n");
|
||||||
*p = EchoReply; // reply
|
*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);
|
q = makeppp(b, sizeof(b), p, l, t, s, PPPLCP);
|
||||||
if (!q) return;
|
if (!q) return;
|
||||||
tunnelsend(b, l + (q - b), t); // send it
|
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
|
// 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)
|
if (l < 4)
|
||||||
return 0;
|
return 0;
|
||||||
b += 4;
|
b += 4;
|
||||||
|
|
@ -563,9 +563,9 @@ static u8 *findppp(u8 *b, u8 mtype)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process IPCP messages
|
// 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);
|
CSTAT(call_processipcp);
|
||||||
|
|
||||||
|
|
@ -577,7 +577,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
return ;
|
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);
|
LOG(1, s, t, "Length mismatch IPCP %u/%u\n", hl, l);
|
||||||
STAT(tunnel_rx_errors);
|
STAT(tunnel_rx_errors);
|
||||||
|
|
@ -588,7 +588,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
if (*p == ConfigAck)
|
if (*p == ConfigAck)
|
||||||
{
|
{
|
||||||
// happy with our IPCP
|
// 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 || radius[r].state == RADIUSIPCP) && !session[s].walled_garden)
|
||||||
{
|
{
|
||||||
if (!r)
|
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
|
// form a config reply quoting the IP in the session
|
||||||
{
|
{
|
||||||
u8 b[MAXCONTROL];
|
uint8_t b[MAXCONTROL];
|
||||||
u8 *i,
|
uint8_t *i, *q;
|
||||||
*q;
|
|
||||||
|
|
||||||
q = p + 4;
|
q = p + 4;
|
||||||
i = p + l;
|
i = p + l;
|
||||||
|
|
@ -635,7 +634,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
if (q < i)
|
if (q < i)
|
||||||
{
|
{
|
||||||
// reject
|
// reject
|
||||||
u16 n = 4;
|
uint16_t n = 4;
|
||||||
i = p + l;
|
i = p + l;
|
||||||
if (!(q = makeppp(b, sizeof(b), p, l, t, s, PPPIPCP)))
|
if (!(q = makeppp(b, sizeof(b), p, l, t, s, PPPIPCP)))
|
||||||
return;
|
return;
|
||||||
|
|
@ -652,7 +651,7 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
}
|
}
|
||||||
p += p[1];
|
p += p[1];
|
||||||
}
|
}
|
||||||
*(u16 *) (q + 2) = htons(n);
|
*(uint16_t *) (q + 2) = htons(n);
|
||||||
LOG(4, s, t, "Sending ConfigRej\n");
|
LOG(4, s, t, "Sending ConfigRej\n");
|
||||||
tunnelsend(b, n + (q - b), t); // send it
|
tunnelsend(b, n + (q - b), t); // send it
|
||||||
}
|
}
|
||||||
|
|
@ -662,9 +661,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
*p = ConfigAck;
|
*p = ConfigAck;
|
||||||
if ((i = findppp(p, 0x81))) // Primary DNS address
|
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;
|
*p = ConfigNak;
|
||||||
LOG(5, s, t, " DNS1 = %s\n",
|
LOG(5, s, t, " DNS1 = %s\n",
|
||||||
fmtaddr(htonl(session[s].dns1), 0));
|
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 ((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;
|
*p = ConfigNak;
|
||||||
LOG(5, s, t, " DNS2 = %s\n",
|
LOG(5, s, t, " DNS2 = %s\n",
|
||||||
fmtaddr(htonl(session[s].dns2), 0));
|
fmtaddr(htonl(session[s].dns2), 0));
|
||||||
|
|
@ -687,9 +686,9 @@ void processipcp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
STAT(tunnel_rx_errors);
|
STAT(tunnel_rx_errors);
|
||||||
return ;
|
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;
|
*p = ConfigNak;
|
||||||
LOG(4, s, t, " No, a ConfigNak, client is requesting IP - sending %s\n",
|
LOG(4, s, t, " No, a ConfigNak, client is requesting IP - sending %s\n",
|
||||||
fmtaddr(htonl(session[s].ip), 0));
|
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'.
|
// This MUST be called with at least 4 byte behind 'p'.
|
||||||
// (i.e. this routine writes to p[-4]).
|
// (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);
|
CSTAT(call_processipin);
|
||||||
|
|
||||||
LOG_HEX(5, "IP", p, l);
|
LOG_HEX(5, "IP", p, l);
|
||||||
|
|
||||||
ip = ntohl(*(u32 *)(p + 12));
|
ip = ntohl(*(uint32_t *)(p + 12));
|
||||||
|
|
||||||
if (l > MAXETHER)
|
if (l > MAXETHER)
|
||||||
{
|
{
|
||||||
|
|
@ -736,7 +735,7 @@ void processipin(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
|
|
||||||
// Add on the tun header
|
// Add on the tun header
|
||||||
p -= 4;
|
p -= 4;
|
||||||
*(u32 *)p = htonl(0x00000800);
|
*(uint32_t *) p = htonl(0x00000800);
|
||||||
l += 4;
|
l += 4;
|
||||||
|
|
||||||
if (session[s].tbf_in && !config->cluster_iam_master) { // Are we throttled and a slave?
|
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.
|
// Helper routine for the TBF filters.
|
||||||
// Used to send queued data in from the user.
|
// 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);
|
LOG_HEX(5, "IP in throttled", buf, len);
|
||||||
|
|
||||||
|
|
@ -813,10 +812,10 @@ void send_ipin(sessionidt s, u8 *buf, int len)
|
||||||
|
|
||||||
|
|
||||||
// Process CCP messages
|
// 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];
|
uint8_t b[MAXCONTROL];
|
||||||
u8 *q;
|
uint8_t *q;
|
||||||
|
|
||||||
CSTAT(call_processccp);
|
CSTAT(call_processccp);
|
||||||
|
|
||||||
|
|
@ -866,9 +865,9 @@ void processccp(tunnelidt t, sessionidt s, u8 *p, u16 l)
|
||||||
// send a CHAP PP packet
|
// send a CHAP PP packet
|
||||||
void sendchap(tunnelidt t, sessionidt s)
|
void sendchap(tunnelidt t, sessionidt s)
|
||||||
{
|
{
|
||||||
u8 b[MAXCONTROL];
|
uint8_t b[MAXCONTROL];
|
||||||
u16 r = session[s].radius;
|
uint16_t r = session[s].radius;
|
||||||
u8 *q;
|
uint8_t *q;
|
||||||
|
|
||||||
CSTAT(call_sendchap);
|
CSTAT(call_sendchap);
|
||||||
|
|
||||||
|
|
@ -905,14 +904,14 @@ void sendchap(tunnelidt t, sessionidt s)
|
||||||
q[4] = 16; // length
|
q[4] = 16; // length
|
||||||
memcpy(q + 5, radius[r].auth, 16); // challenge
|
memcpy(q + 5, radius[r].auth, 16); // challenge
|
||||||
strcpy(q + 21, hostname); // our name
|
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
|
tunnelsend(b, strlen(hostname) + 21 + (q - b), t); // send it
|
||||||
}
|
}
|
||||||
|
|
||||||
// fill in a L2TP message with a PPP frame,
|
// fill in a L2TP message with a PPP frame,
|
||||||
// copies existing PPP message and changes magic number if seen
|
// copies existing PPP message and changes magic number if seen
|
||||||
// returns start of PPP frame
|
// 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!!
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(u16 *) (b + 0) = htons(0x0002); // L2TP with no options
|
*(uint16_t *) (b + 0) = htons(0x0002); // L2TP with no options
|
||||||
*(u16 *) (b + 2) = htons(tunnel[t].far); // tunnel
|
*(uint16_t *) (b + 2) = htons(tunnel[t].far); // tunnel
|
||||||
*(u16 *) (b + 4) = htons(session[s].far); // session
|
*(uint16_t *) (b + 4) = htons(session[s].far); // session
|
||||||
b += 6;
|
b += 6;
|
||||||
if (mtype == PPPLCP || !(session[s].l2tp_flags & SESSIONACFC))
|
if (mtype == PPPLCP || !(session[s].l2tp_flags & SESSIONACFC))
|
||||||
{
|
{
|
||||||
*(u16 *) b = htons(0xFF03); // HDLC header
|
*(uint16_t *) b = htons(0xFF03); // HDLC header
|
||||||
b += 2;
|
b += 2;
|
||||||
}
|
}
|
||||||
if (mtype < 0x100 && session[s].l2tp_flags & SESSIONPFC)
|
if (mtype < 0x100 && session[s].l2tp_flags & SESSIONPFC)
|
||||||
*b++ = mtype;
|
*b++ = mtype;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*(u16 *) b = htons(mtype);
|
*(uint16_t *) b = htons(mtype);
|
||||||
b += 2;
|
b += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -963,14 +962,14 @@ void initlcp(tunnelidt t, sessionidt s)
|
||||||
|
|
||||||
LOG(4, s, t, "Sending LCP ConfigReq for PAP\n");
|
LOG(4, s, t, "Sending LCP ConfigReq for PAP\n");
|
||||||
*q = ConfigReq;
|
*q = ConfigReq;
|
||||||
*(u8 *)(q + 1) = (time_now % 255) + 1; // ID
|
*(uint8_t *)(q + 1) = (time_now % 255) + 1; // ID
|
||||||
*(u16 *)(q + 2) = htons(14); // Length
|
*(uint16_t *)(q + 2) = htons(14); // Length
|
||||||
*(u8 *)(q + 4) = 5;
|
*(uint8_t *)(q + 4) = 5;
|
||||||
*(u8 *)(q + 5) = 6;
|
*(uint8_t *)(q + 5) = 6;
|
||||||
*(u32 *)(q + 6) = htonl(session[s].magic);
|
*(uint32_t *)(q + 6) = htonl(session[s].magic);
|
||||||
*(u8 *)(q + 10) = 3;
|
*(uint8_t *)(q + 10) = 3;
|
||||||
*(u8 *)(q + 11) = 4;
|
*(uint8_t *)(q + 11) = 4;
|
||||||
*(u16 *)(q + 12) = htons(PPPPAP); // PAP
|
*(uint16_t *)(q + 12) = htons(PPPPAP); // PAP
|
||||||
|
|
||||||
LOG_HEX(5, "PPPLCP", q, 14);
|
LOG_HEX(5, "PPPLCP", q, 14);
|
||||||
tunnelsend(b, (q - b) + 14, t);
|
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");
|
LOG(4, s, t, "Sending CCP ConfigReq for no compression\n");
|
||||||
*q = ConfigReq;
|
*q = ConfigReq;
|
||||||
*(u8 *)(q + 1) = (time_now % 255) + 1; // ID
|
*(uint8_t *)(q + 1) = (time_now % 255) + 1; // ID
|
||||||
*(u16 *)(q + 2) = htons(4); // Length
|
*(uint16_t *)(q + 2) = htons(4); // Length
|
||||||
|
|
||||||
LOG_HEX(5, "PPPCCP", q, 4);
|
LOG_HEX(5, "PPPCCP", q, 4);
|
||||||
tunnelsend(b, (q - b) + 4 , t);
|
tunnelsend(b, (q - b) + 4 , t);
|
||||||
|
|
|
||||||
89
radius.c
89
radius.c
|
|
@ -1,6 +1,6 @@
|
||||||
// L2TPNS Radius Stuff
|
// 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 <time.h>
|
||||||
#include <stdio.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 radiust *radius;
|
||||||
extern sessiont *session;
|
extern sessiont *session;
|
||||||
extern tunnelt *tunnel;
|
extern tunnelt *tunnel;
|
||||||
extern u32 sessionid;
|
|
||||||
extern configt *config;
|
extern configt *config;
|
||||||
extern int *radfds;
|
extern int *radfds;
|
||||||
extern ip_filtert *ip_filters;
|
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;
|
if (s) session[s].radius = 0;
|
||||||
memset(&radius[r], 0, sizeof(radius[r])); // radius[r].state = RADIUSNULL;
|
memset(&radius[r], 0, sizeof(radius[r])); // radius[r].state = RADIUSNULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static u16 get_free_radius()
|
static uint16_t get_free_radius()
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
static u32 next_radius_id = 0;
|
static uint32_t next_radius_id = 0;
|
||||||
|
|
||||||
for (count = MAXRADIUS; count > 0 ; --count)
|
for (count = MAXRADIUS; count > 0 ; --count)
|
||||||
{
|
{
|
||||||
|
|
@ -81,9 +80,9 @@ static u16 get_free_radius()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 radiusnew(sessionidt s)
|
uint16_t radiusnew(sessionidt s)
|
||||||
{
|
{
|
||||||
u16 r = session[s].radius;
|
uint16_t r = session[s].radius;
|
||||||
|
|
||||||
/* re-use */
|
/* re-use */
|
||||||
if (r)
|
if (r)
|
||||||
|
|
@ -110,13 +109,13 @@ u16 radiusnew(sessionidt s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a RADIUS request
|
// Send a RADIUS request
|
||||||
void radiussend(u16 r, u8 state)
|
void radiussend(uint16_t r, uint8_t state)
|
||||||
{
|
{
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
u8 b[4096]; // RADIUS packet
|
uint8_t b[4096]; // RADIUS packet
|
||||||
char pass[129];
|
char pass[129];
|
||||||
int pl;
|
int pl;
|
||||||
u8 *p;
|
uint8_t *p;
|
||||||
sessionidt s;
|
sessionidt s;
|
||||||
|
|
||||||
CSTAT(call_radiussend);
|
CSTAT(call_radiussend);
|
||||||
|
|
@ -246,7 +245,7 @@ void radiussend(u16 r, u8 state)
|
||||||
{ // accounting
|
{ // accounting
|
||||||
*p = 40; // accounting type
|
*p = 40; // accounting type
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *) (p + 2) = htonl((state == RADIUSSTART) ? 1 : 2);
|
*(uint32_t *) (p + 2) = htonl((state == RADIUSSTART) ? 1 : 2);
|
||||||
p += p[1];
|
p += p[1];
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
|
|
@ -258,30 +257,30 @@ void radiussend(u16 r, u8 state)
|
||||||
{ // stop
|
{ // stop
|
||||||
*p = 42; // input octets
|
*p = 42; // input octets
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *) (p + 2) = htonl(session[s].cin);
|
*(uint32_t *) (p + 2) = htonl(session[s].cin);
|
||||||
p += p[1];
|
p += p[1];
|
||||||
*p = 43; // output octets
|
*p = 43; // output octets
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *) (p + 2) = htonl(session[s].cout);
|
*(uint32_t *) (p + 2) = htonl(session[s].cout);
|
||||||
p += p[1];
|
p += p[1];
|
||||||
*p = 46; // session time
|
*p = 46; // session time
|
||||||
p[1] = 6;
|
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 += p[1];
|
||||||
*p = 47; // input packets
|
*p = 47; // input packets
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *) (p + 2) = htonl(session[s].pin);
|
*(uint32_t *) (p + 2) = htonl(session[s].pin);
|
||||||
p += p[1];
|
p += p[1];
|
||||||
*p = 48; // output spackets
|
*p = 48; // output spackets
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *) (p + 2) = htonl(session[s].pout);
|
*(uint32_t *) (p + 2) = htonl(session[s].pout);
|
||||||
p += p[1];
|
p += p[1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // start
|
{ // start
|
||||||
*p = 41; // delay
|
*p = 41; // delay
|
||||||
p[1] = 6;
|
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 += p[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -290,14 +289,14 @@ void radiussend(u16 r, u8 state)
|
||||||
{
|
{
|
||||||
*p = 5; // NAS-Port
|
*p = 5; // NAS-Port
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *) (p + 2) = htonl(s);
|
*(uint32_t *) (p + 2) = htonl(s);
|
||||||
p += p[1];
|
p += p[1];
|
||||||
}
|
}
|
||||||
if (s && session[s].ip)
|
if (s && session[s].ip)
|
||||||
{
|
{
|
||||||
*p = 8; // Framed-IP-Address
|
*p = 8; // Framed-IP-Address
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *) (p + 2) = htonl(session[s].ip);
|
*(uint32_t *) (p + 2) = htonl(session[s].ip);
|
||||||
p += p[1];
|
p += p[1];
|
||||||
}
|
}
|
||||||
if (*session[s].called)
|
if (*session[s].called)
|
||||||
|
|
@ -324,11 +323,11 @@ void radiussend(u16 r, u8 state)
|
||||||
// NAS-IP-Address
|
// NAS-IP-Address
|
||||||
*p = 4;
|
*p = 4;
|
||||||
p[1] = 6;
|
p[1] = 6;
|
||||||
*(u32 *)(p + 2) = config->bind_address;
|
*(uint32_t *)(p + 2) = config->bind_address;
|
||||||
p += p[1];
|
p += p[1];
|
||||||
|
|
||||||
// All AVpairs added
|
// All AVpairs added
|
||||||
*(u16 *) (b + 2) = htons(p - b);
|
*(uint16_t *) (b + 2) = htons(p - b);
|
||||||
if (state != RADIUSAUTH)
|
if (state != RADIUSAUTH)
|
||||||
{
|
{
|
||||||
// Build auth for accounting packet
|
// Build auth for accounting packet
|
||||||
|
|
@ -346,10 +345,10 @@ void radiussend(u16 r, u8 state)
|
||||||
}
|
}
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.sin_family = AF_INET;
|
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
|
// get radius port
|
||||||
u16 port = config->radiusport[(radius[r].try - 1) % config->numradiusservers];
|
uint16_t port = config->radiusport[(radius[r].try - 1) % config->numradiusservers];
|
||||||
// no need to define the accounting port for itself:
|
// no need to define the accounting port for itself:
|
||||||
// the accounting port is as far as I know always one more
|
// the accounting port is as far as I know always one more
|
||||||
// than the auth port JK 20040713
|
// than the auth port JK 20040713
|
||||||
|
|
@ -361,15 +360,15 @@ void radiussend(u16 r, u8 state)
|
||||||
}
|
}
|
||||||
|
|
||||||
// process RADIUS response
|
// 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;
|
MD5_CTX ctx;
|
||||||
u16 r;
|
uint16_t r;
|
||||||
sessionidt s;
|
sessionidt s;
|
||||||
tunnelidt t = 0;
|
tunnelidt t = 0;
|
||||||
hasht hash;
|
hasht hash;
|
||||||
u8 routes = 0;
|
uint8_t routes = 0;
|
||||||
|
|
||||||
int r_code, r_id ; // Radius code.
|
int r_code, r_id ; // Radius code.
|
||||||
|
|
||||||
|
|
@ -380,12 +379,12 @@ void processrad(u8 *buf, int len, char socket_index)
|
||||||
CSTAT(call_processrad);
|
CSTAT(call_processrad);
|
||||||
|
|
||||||
LOG_HEX(5, "RADIUS Response", buf, len);
|
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);
|
LOG(1, 0, 0, "Duff RADIUS response length %d\n", len);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
len = ntohs(*(u16 *) (buf + 2));
|
len = ntohs(*(uint16_t *) (buf + 2));
|
||||||
r = socket_index | (r_id << RADIUS_SHIFT);
|
r = socket_index | (r_id << RADIUS_SHIFT);
|
||||||
s = radius[r].session;
|
s = radius[r].session;
|
||||||
LOG(3, s, session[s].tunnel, "Received %s, radius %d response for session %u (code %d, id %d)\n",
|
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)
|
if (radius[r].chap)
|
||||||
{
|
{
|
||||||
// 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!
|
if (!p) return; // Abort!
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -440,13 +439,13 @@ void processrad(u8 *buf, int len, char socket_index)
|
||||||
(*buf == 2) ? "allowed" : "denied");
|
(*buf == 2) ? "allowed" : "denied");
|
||||||
*p = (*buf == 2) ? 3 : 4; // ack/nak
|
*p = (*buf == 2) ? 3 : 4; // ack/nak
|
||||||
p[1] = radius[r].id;
|
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
|
tunnelsend(b, (p - b) + 4, t); // send it
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// PAP
|
// 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!
|
if (!p) return; // Abort!
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -460,7 +459,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
||||||
// ack/nak
|
// ack/nak
|
||||||
*p = *buf;
|
*p = *buf;
|
||||||
p[1] = radius[r].id;
|
p[1] = radius[r].id;
|
||||||
*(u16 *) (p + 2) = ntohs(5);
|
*(uint16_t *) (p + 2) = ntohs(5);
|
||||||
p[4] = 0; // no message
|
p[4] = 0; // no message
|
||||||
tunnelsend(b, (p - b) + 5, t); // send it
|
tunnelsend(b, (p - b) + 5, t); // send it
|
||||||
}
|
}
|
||||||
|
|
@ -469,15 +468,15 @@ void processrad(u8 *buf, int len, char socket_index)
|
||||||
{
|
{
|
||||||
// Login successful
|
// Login successful
|
||||||
// Extract IP, routes, etc
|
// Extract IP, routes, etc
|
||||||
u8 *p = buf + 20;
|
uint8_t *p = buf + 20;
|
||||||
u8 *e = buf + len;
|
uint8_t *e = buf + len;
|
||||||
for (; p + 2 <= e && p[1] && p + p[1] <= e; p += p[1])
|
for (; p + 2 <= e && p[1] && p + p[1] <= e; p += p[1])
|
||||||
{
|
{
|
||||||
if (*p == 8)
|
if (*p == 8)
|
||||||
{
|
{
|
||||||
// Framed-IP-Address
|
// Framed-IP-Address
|
||||||
if (p[1] < 6) continue;
|
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;
|
session[s].ip_pool_index = -1;
|
||||||
LOG(3, s, session[s].tunnel, " Radius reply contains IP address %s\n",
|
LOG(3, s, session[s].tunnel, " Radius reply contains IP address %s\n",
|
||||||
fmtaddr(htonl(session[s].ip), 0));
|
fmtaddr(htonl(session[s].ip), 0));
|
||||||
|
|
@ -486,7 +485,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
||||||
{
|
{
|
||||||
// DNS address
|
// DNS address
|
||||||
if (p[1] < 6) continue;
|
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",
|
LOG(3, s, session[s].tunnel, " Radius reply contains primary DNS address %s\n",
|
||||||
fmtaddr(htonl(session[s].dns1), 0));
|
fmtaddr(htonl(session[s].dns1), 0));
|
||||||
}
|
}
|
||||||
|
|
@ -494,18 +493,18 @@ void processrad(u8 *buf, int len, char socket_index)
|
||||||
{
|
{
|
||||||
// DNS address
|
// DNS address
|
||||||
if (p[1] < 6) continue;
|
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",
|
LOG(3, s, session[s].tunnel, " Radius reply contains secondary DNS address %s\n",
|
||||||
fmtaddr(htonl(session[s].dns2), 0));
|
fmtaddr(htonl(session[s].dns2), 0));
|
||||||
}
|
}
|
||||||
else if (*p == 22)
|
else if (*p == 22)
|
||||||
{
|
{
|
||||||
// Framed-Route
|
// Framed-Route
|
||||||
ipt ip = 0, mask = 0;
|
in_addr_t ip = 0, mask = 0;
|
||||||
u8 u = 0;
|
uint8_t u = 0;
|
||||||
u8 bits = 0;
|
uint8_t bits = 0;
|
||||||
u8 *n = p + 2;
|
uint8_t *n = p + 2;
|
||||||
u8 *e = p + p[1];
|
uint8_t *e = p + p[1];
|
||||||
while (n < e && (isdigit(*n) || *n == '.'))
|
while (n < e && (isdigit(*n) || *n == '.'))
|
||||||
{
|
{
|
||||||
if (*n == '.')
|
if (*n == '.')
|
||||||
|
|
@ -552,7 +551,7 @@ void processrad(u8 *buf, int len, char socket_index)
|
||||||
char *filter = p + 2;
|
char *filter = p + 2;
|
||||||
int l = p[1] - 2;
|
int l = p[1] - 2;
|
||||||
char *suffix;
|
char *suffix;
|
||||||
u8 *f = 0;
|
uint8_t *f = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
LOG(3, s, session[s].tunnel, " Radius reply contains Filter-Id \"%.*s\"\n", l, filter);
|
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
|
// Send a retry for RADIUS/CHAP message
|
||||||
void radiusretry(u16 r)
|
void radiusretry(uint16_t r)
|
||||||
{
|
{
|
||||||
sessionidt s = radius[r].session;
|
sessionidt s = radius[r].session;
|
||||||
tunnelidt t = 0;
|
tunnelidt t = 0;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
/* snoop control */
|
/* 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;
|
int plugin_api_version = PLUGIN_API_VERSION;
|
||||||
static struct pluginfuncs *p = 0;
|
static struct pluginfuncs *p = 0;
|
||||||
|
|
@ -77,8 +77,8 @@ int plugin_control(struct param_control *data)
|
||||||
|
|
||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
ipt ip = inet_addr(data->argv[2]);
|
in_addr_t ip = inet_addr(data->argv[2]);
|
||||||
u16 port = atoi(data->argv[3]);
|
uint16_t port = atoi(data->argv[3]);
|
||||||
|
|
||||||
if (!ip || ip == INADDR_NONE)
|
if (!ip || ip == INADDR_NONE)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
4
tbf.c
4
tbf.c
|
|
@ -1,6 +1,6 @@
|
||||||
// L2TPNS: token bucket filters
|
// 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 <string.h>
|
||||||
#include "l2tpns.h"
|
#include "l2tpns.h"
|
||||||
|
|
@ -91,7 +91,7 @@ int free_tbf(int tid)
|
||||||
//
|
//
|
||||||
// Allocate a new token bucket filter.
|
// 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;
|
int i;
|
||||||
static int p = 0;
|
static int p = 0;
|
||||||
|
|
|
||||||
18
tbf.h
18
tbf.h
|
|
@ -17,17 +17,17 @@ typedef struct {
|
||||||
sessionidt sid; // associated session ID.
|
sessionidt sid; // associated session ID.
|
||||||
int max_credit; // Maximum amount of credit available (burst size).
|
int max_credit; // Maximum amount of credit available (burst size).
|
||||||
int rate; // How many bytes of credit per second we get? (sustained rate)
|
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.
|
void (*send)(sessionidt s, uint8_t *, int); // Routine to actually send out the data.
|
||||||
int prev; // Timer chain position.
|
int prev; // Timer chain position.
|
||||||
int next; // Timer chain position.
|
int next; // Timer chain position.
|
||||||
|
|
||||||
u32 b_queued; // Total bytes sent through this TBF
|
uint32_t b_queued; // Total bytes sent through this TBF
|
||||||
u32 b_sent; // Total bytes sucessfully made it to the network.
|
uint32_t b_sent; // Total bytes sucessfully made it to the network.
|
||||||
u32 p_queued; // ditto packets.
|
uint32_t p_queued; // ditto packets.
|
||||||
u32 p_sent; // ditto packets.
|
uint32_t p_sent; // ditto packets.
|
||||||
u32 b_dropped; // Total bytes dropped.
|
uint32_t b_dropped; // Total bytes dropped.
|
||||||
u32 p_dropped; // Total packets dropped.
|
uint32_t p_dropped; // Total packets dropped.
|
||||||
u32 p_delayed; // Total packets not sent immediately.
|
uint32_t p_delayed; // Total packets not sent immediately.
|
||||||
|
|
||||||
int sizes[TBF_MAX_QUEUE];
|
int sizes[TBF_MAX_QUEUE];
|
||||||
char packets[TBF_MAX_QUEUE][TBF_MAX_SIZE];
|
char packets[TBF_MAX_QUEUE][TBF_MAX_SIZE];
|
||||||
|
|
@ -36,7 +36,7 @@ typedef struct {
|
||||||
void init_tbf(int num_tbfs);
|
void init_tbf(int num_tbfs);
|
||||||
int tbf_run_timer(void);
|
int tbf_run_timer(void);
|
||||||
int tbf_queue_packet(int tbf_id, char * data, int size);
|
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);
|
int free_tbf(int tid);
|
||||||
void fsck_tbfs(void);
|
void fsck_tbfs(void);
|
||||||
|
|
||||||
|
|
|
||||||
4
util.c
4
util.c
|
|
@ -1,6 +1,6 @@
|
||||||
/* Misc util functions */
|
/* 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 <unistd.h>
|
||||||
#include <errno.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
|
// format ipv4 addr as a dotted-quad; n chooses one of 4 static buffers
|
||||||
// to use
|
// to use
|
||||||
char *fmtaddr(ipt addr, int n)
|
char *fmtaddr(in_addr_t addr, int n)
|
||||||
{
|
{
|
||||||
static char addrs[4][16];
|
static char addrs[4][16];
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
|
|
|
||||||
2
util.h
2
util.h
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef __UTIL_H__
|
#ifndef __UTIL_H__
|
||||||
#define __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);
|
void *shared_malloc(unsigned int size);
|
||||||
pid_t fork_and_close(void);
|
pid_t fork_and_close(void);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue