summaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
Diffstat (limited to 'networking')
-rw-r--r--networking/udhcp/dhcprelay.c63
1 files changed, 20 insertions, 43 deletions
diff --git a/networking/udhcp/dhcprelay.c b/networking/udhcp/dhcprelay.c
index 3e1758d..08dc23f 100644
--- a/networking/udhcp/dhcprelay.c
+++ b/networking/udhcp/dhcprelay.c
@@ -19,16 +19,16 @@
#define MAX_LIFETIME 2*60 /* lifetime of an xid entry in sec. */
#define MAX_INTERFACES 9
-
/* This list holds information about clients. The xid_* functions manipulate this list. */
-static struct xid_item {
+struct xid_item {
+ time_t timestamp;
+ int client;
uint32_t xid;
struct sockaddr_in ip;
- int client;
- time_t timestamp;
struct xid_item *next;
-} dhcprelay_xid_list = {0, {0}, 0, 0, NULL};
+};
+#define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1)
static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client)
{
@@ -114,17 +114,6 @@ static int get_dhcp_packet_type(struct dhcpMessage *p)
}
/**
- * signal_handler - handles signals ;-)
- * sig - sent signal
- */
-static smallint dhcprelay_stopflag;
-
-static void dhcprelay_signal_handler(int sig)
-{
- dhcprelay_stopflag = 1;
-}
-
-/**
* get_client_devices - parses the devices list
* dev_list - comma separated list of devices
* returns array
@@ -160,27 +149,23 @@ static char **get_client_devices(char *dev_list, int *client_number)
}
-/* Creates listen sockets (in fds) and returns the number allocated. */
+/* Creates listen sockets (in fds) and returns numerically max fd. */
static int init_sockets(char **client, int num_clients,
- char *server, int *fds, int *max_socket)
+ char *server, int *fds)
{
- int i;
+ int i, n;
/* talk to real server on bootps */
fds[0] = listen_socket(/*INADDR_ANY,*/ 67, server);
- *max_socket = fds[0];
-
- /* array starts at 1 since server is 0 */
- num_clients++;
+ n = fds[0];
for (i = 1; i < num_clients; i++) {
/* listen for clients on bootps */
fds[i] = listen_socket(/*NADDR_ANY,*/ 67, client[i-1]);
- if (fds[i] > *max_socket)
- *max_socket = fds[i];
+ if (fds[i] > n)
+ n = fds[i];
}
-
- return i;
+ return n;
}
@@ -253,6 +238,8 @@ static void pass_back(struct dhcpMessage *p, int packet_len, int *fds)
}
static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **clients,
+ struct sockaddr_in *server_addr, uint32_t gw_ip) ATTRIBUTE_NORETURN;
+static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **clients,
struct sockaddr_in *server_addr, uint32_t gw_ip)
{
struct dhcpMessage dhcp_msg;
@@ -263,7 +250,7 @@ static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **cli
struct timeval tv;
int i;
- while (!dhcprelay_stopflag) {
+ while (1) {
FD_ZERO(&rfds);
for (i = 0; i < num_sockets; i++)
FD_SET(fds[i], &rfds);
@@ -298,7 +285,7 @@ static void dhcprelay_loop(int *fds, int num_sockets, int max_socket, char **cli
int dhcprelay_main(int argc, char **argv);
int dhcprelay_main(int argc, char **argv)
{
- int i, num_sockets, max_socket, fds[MAX_INTERFACES];
+ int num_sockets, max_socket, fds[MAX_INTERFACES];
uint32_t gw_ip;
char **clients;
struct sockaddr_in server_addr;
@@ -316,23 +303,13 @@ int dhcprelay_main(int argc, char **argv)
clients = get_client_devices(argv[1], &num_sockets);
if (!clients) return 0;
- signal(SIGTERM, dhcprelay_signal_handler);
- signal(SIGQUIT, dhcprelay_signal_handler);
- signal(SIGINT, dhcprelay_signal_handler);
-
- num_sockets = init_sockets(clients, num_sockets, argv[2], fds, &max_socket);
+ num_sockets++; /* for server socket at fds[0] */
+ max_socket = init_sockets(clients, num_sockets, argv[2], fds);
if (read_interface(argv[2], NULL, &gw_ip, NULL))
return 1;
+ /* doesn't return */
dhcprelay_loop(fds, num_sockets, max_socket, clients, &server_addr, gw_ip);
-
- if (ENABLE_FEATURE_CLEAN_UP) {
- for (i = 0; i < num_sockets; i++) {
- close(fds[i]);
- free(clients[i]);
- }
- }
-
- return 0;
+ /* return 0; - not reached */
}