l2tpns/cluster.c
David Parrish fc0a363208 * Fri Mar 5 2004 David Parrish <david@dparrish.com> 1.1.0
- Change all strcpy() calls to strncpy() to avoid buffer overflow potential
- Add ICMP host unreachable support
- Logging to syslog if log_file = "syslog:facility"
- Now requires libcli 1.5
- All configuration moves to a config structure
- Ability to modify and write config on the fly through command-line interface
- Config file support is removed, and now handled by the cli
- Show hostname in cli prompt
- Keep current state type for tunnels
- Add uptime command do CLI, which also shows real-time bandwidth utilisation
- Add goodbye command to cluster master, which forces droppping a slave
- Cache IP address allocation, so that reconnecting users get the same address
- Fix tunnel resend timeouts, so that dead tunnels will be cleaned up
- Allocate tunnels and radius without using a linked list which had issues
- Fix some off-by-one errors in tunnel and session and radius arrays
- Save and reload ip address pool when dieing
- Check version and size of reloaded data when restarting
- Remove plugin_config support
- Remove old support for TBF which didn't work anyway. HTB is required to do throttling now.
- Add COPYING and Changes files
2004-03-05 00:09:03 +00:00

85 lines
2.1 KiB
C

// L2TPNS Clustering Stuff
// $Id: cluster.c,v 1.2 2004-03-05 00:09:03 fred_nerk Exp $ #include <stdio.h> #include <sys/file.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <string.h>
#include <malloc.h>
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdio.h>
#include "cluster.h"
int cluster_sockfd = 0;
int cluster_server = 0;
uint32_t vip_address;
extern int debug;
void _log_hex(int level, const char *title, const char *data, int maxsize);
#define log_hex(a,b,c,d)
#ifndef log_hex
#define log_hex(a,b,c,d) do{if (a > debug) _log_hex(a,b,c,d);}while (0)
#endif
// Create a listening socket
int cluster_init(uint32_t bind_address, int server)
{
struct sockaddr_in addr;
vip_address = bind_address;
cluster_server = !!server;
cluster_sockfd = socket(AF_INET, SOCK_DGRAM, UDP);
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(cluster_server ? CLUSTERPORT : CLUSTERCLIENTPORT);
addr.sin_addr.s_addr = INADDR_ANY;
setsockopt(cluster_sockfd, SOL_SOCKET, SO_REUSEADDR, &addr, sizeof(addr));
if (bind(cluster_sockfd, (void *) &addr, sizeof(addr)) < 0)
{
perror("bind");
exit(-1);
}
return cluster_sockfd;
}
int cluster_send_message(unsigned long ip_address, uint32_t vip, char type, void *data, int datalen)
{
size_t l = 1 + sizeof(uint32_t) + datalen;
char *buf = NULL;
struct sockaddr_in addr = {0};
if (!cluster_sockfd) return -1;
if (!ip_address) return 0;
buf = calloc(l, 1);
*(uint32_t *)(buf) = htonl(vip);
*(char *)(buf+sizeof(uint32_t)) = type;
if (data && datalen > 0)
memcpy((char *)(buf + sizeof(uint32_t) + 1), data, datalen);
addr.sin_addr.s_addr = ip_address;
addr.sin_port = htons(cluster_server ? CLUSTERCLIENTPORT : CLUSTERPORT);
addr.sin_family = AF_INET;
log_hex(4, "Cluster send", buf, l);
if (sendto(cluster_sockfd, buf, l, MSG_NOSIGNAL, (void *) &addr, sizeof(addr)) < 0)
{
perror("sendto");
free(buf);
return -1;
}
free(buf);
return 0;
}