summaryrefslogtreecommitdiffhomepage
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-09-28 10:29:17 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-09-28 10:29:17 +0000
commitb9256054419582dc35917b1cb39c7e09f489dfad (patch)
tree2ce3a816b788b3af5fa54109b765ee22d5550c5e /networking/udhcp
parentc3122bca53255799f052fcc0e911b68237faa12d (diff)
assorted static vars removal
function old new delta tcpudpsvd_main 1829 1839 +10 update_status 567 569 +2 sigterm 1 - -1 ......... dhcprelay_signal_handler 8 - -8 nfs_strerror 60 49 -11 singlemount 4579 4564 -15 static.p 16 - -16 svstatus 20 - -20 dhcprelay_xid_list 32 - -32 runsv_main 1785 1746 -39 static.buf 74 28 -46 svd 56 - -56 dhcprelay_main 1141 1080 -61 ------------------------------------------------------------------------------ (add/remove: 0/20 grow/shrink: 2/10 up/down: 12/-386) Total: -374 bytes
Diffstat (limited to 'networking/udhcp')
-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 3e1758d5c..08dc23f23 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 */
}