Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* Port to Busybox Copyright (C) 2006 Jesse Dutton <jessedutton@gmail.com> |
| 3 | * |
| 4 | * Licensed under GPL v2, see file LICENSE in this tarball for details. |
| 5 | * |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 6 | * DHCP Relay for 'DHCPv4 Configuration of IPSec Tunnel Mode' support |
| 7 | * Copyright (C) 2002 Mario Strasser <mast@gmx.net>, |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 8 | * Zuercher Hochschule Winterthur, |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 9 | * Netbeat AG |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 10 | * Upstream has GPL v2 or later |
| 11 | */ |
| 12 | |
| 13 | #include "common.h" |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 14 | #include "options.h" |
| 15 | |
Denis Vlasenko | d55fe3e | 2008-02-04 13:12:16 +0000 | [diff] [blame] | 16 | #define SERVER_PORT 67 |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 17 | #define SELECT_TIMEOUT 5 /* select timeout in sec. */ |
| 18 | #define MAX_LIFETIME 2*60 /* lifetime of an xid entry in sec. */ |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 19 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 20 | /* This list holds information about clients. The xid_* functions manipulate this list. */ |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 21 | struct xid_item { |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 22 | unsigned timestamp; |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 23 | int client; |
Denis Vlasenko | 35d4da0 | 2007-01-22 14:04:27 +0000 | [diff] [blame] | 24 | uint32_t xid; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 25 | struct sockaddr_in ip; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 26 | struct xid_item *next; |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 27 | }; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 28 | |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 29 | #define dhcprelay_xid_list (*(struct xid_item*)&bb_common_bufsiz1) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 30 | |
Denis Vlasenko | 80edead | 2007-08-02 22:31:05 +0000 | [diff] [blame] | 31 | static struct xid_item *xid_add(uint32_t xid, struct sockaddr_in *ip, int client) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 32 | { |
| 33 | struct xid_item *item; |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 34 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 35 | /* create new xid entry */ |
| 36 | item = xmalloc(sizeof(struct xid_item)); |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 37 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 38 | /* add xid entry */ |
| 39 | item->ip = *ip; |
| 40 | item->xid = xid; |
| 41 | item->client = client; |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 42 | item->timestamp = monotonic_sec(); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 43 | item->next = dhcprelay_xid_list.next; |
| 44 | dhcprelay_xid_list.next = item; |
| 45 | |
| 46 | return item; |
| 47 | } |
| 48 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 49 | static void xid_expire(void) |
| 50 | { |
| 51 | struct xid_item *item = dhcprelay_xid_list.next; |
| 52 | struct xid_item *last = &dhcprelay_xid_list; |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 53 | unsigned current_time = monotonic_sec(); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 54 | |
| 55 | while (item != NULL) { |
Denis Vlasenko | 80edead | 2007-08-02 22:31:05 +0000 | [diff] [blame] | 56 | if ((current_time - item->timestamp) > MAX_LIFETIME) { |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 57 | last->next = item->next; |
| 58 | free(item); |
| 59 | item = last->next; |
| 60 | } else { |
| 61 | last = item; |
| 62 | item = item->next; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
Denis Vlasenko | 80edead | 2007-08-02 22:31:05 +0000 | [diff] [blame] | 67 | static struct xid_item *xid_find(uint32_t xid) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 68 | { |
| 69 | struct xid_item *item = dhcprelay_xid_list.next; |
| 70 | while (item != NULL) { |
| 71 | if (item->xid == xid) { |
| 72 | return item; |
| 73 | } |
| 74 | item = item->next; |
| 75 | } |
| 76 | return NULL; |
| 77 | } |
| 78 | |
Denis Vlasenko | 35d4da0 | 2007-01-22 14:04:27 +0000 | [diff] [blame] | 79 | static void xid_del(uint32_t xid) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 80 | { |
| 81 | struct xid_item *item = dhcprelay_xid_list.next; |
| 82 | struct xid_item *last = &dhcprelay_xid_list; |
| 83 | while (item != NULL) { |
| 84 | if (item->xid == xid) { |
| 85 | last->next = item->next; |
| 86 | free(item); |
| 87 | item = last->next; |
| 88 | } else { |
| 89 | last = item; |
| 90 | item = item->next; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 95 | /** |
| 96 | * get_dhcp_packet_type - gets the message type of a dhcp packet |
| 97 | * p - pointer to the dhcp packet |
| 98 | * returns the message type on success, -1 otherwise |
| 99 | */ |
Denys Vlasenko | 31af3d5 | 2009-06-17 11:57:09 +0200 | [diff] [blame] | 100 | static int get_dhcp_packet_type(struct dhcp_packet *p) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 101 | { |
Denis Vlasenko | 2870301 | 2006-12-19 20:32:02 +0000 | [diff] [blame] | 102 | uint8_t *op; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 103 | |
| 104 | /* it must be either a BOOTREQUEST or a BOOTREPLY */ |
| 105 | if (p->op != BOOTREQUEST && p->op != BOOTREPLY) |
| 106 | return -1; |
| 107 | /* get message type option */ |
| 108 | op = get_option(p, DHCP_MESSAGE_TYPE); |
| 109 | if (op != NULL) |
| 110 | return op[0]; |
| 111 | return -1; |
| 112 | } |
| 113 | |
| 114 | /** |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 115 | * get_client_devices - parses the devices list |
| 116 | * dev_list - comma separated list of devices |
| 117 | * returns array |
| 118 | */ |
Denis Vlasenko | 80edead | 2007-08-02 22:31:05 +0000 | [diff] [blame] | 119 | static char **get_client_devices(char *dev_list, int *client_number) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 120 | { |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 121 | char *s, **client_dev; |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 122 | int i, cn; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 123 | |
| 124 | /* copy list */ |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 125 | dev_list = xstrdup(dev_list); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 126 | |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 127 | /* get number of items, replace ',' with NULs */ |
| 128 | s = dev_list; |
| 129 | cn = 1; |
| 130 | while (*s) { |
| 131 | if (*s == ',') { |
| 132 | *s = '\0'; |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 133 | cn++; |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 134 | } |
| 135 | s++; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 136 | } |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 137 | *client_number = cn; |
Denis Vlasenko | d7b3350 | 2007-09-30 17:54:10 +0000 | [diff] [blame] | 138 | |
| 139 | /* create vector of pointers */ |
| 140 | client_dev = xzalloc(cn * sizeof(*client_dev)); |
| 141 | client_dev[0] = dev_list; |
| 142 | i = 1; |
| 143 | while (i != cn) { |
| 144 | client_dev[i] = client_dev[i - 1] + strlen(client_dev[i - 1]) + 1; |
| 145 | i++; |
| 146 | } |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 147 | return client_dev; |
| 148 | } |
| 149 | |
| 150 | |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 151 | /* Creates listen sockets (in fds) bound to client and server ifaces, |
| 152 | * and returns numerically max fd. |
| 153 | */ |
| 154 | static int init_sockets(char **client_ifaces, int num_clients, |
| 155 | char *server_iface, int *fds) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 156 | { |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 157 | int i, n; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 158 | |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 159 | /* talk to real server on bootps */ |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 160 | fds[0] = udhcp_listen_socket(/*INADDR_ANY,*/ SERVER_PORT, server_iface); |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 161 | n = fds[0]; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 162 | |
Denis Vlasenko | a27a11b | 2007-08-18 14:16:39 +0000 | [diff] [blame] | 163 | for (i = 1; i < num_clients; i++) { |
Bernhard Reutner-Fischer | a838194 | 2006-11-21 11:23:11 +0000 | [diff] [blame] | 164 | /* listen for clients on bootps */ |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 165 | fds[i] = udhcp_listen_socket(/*INADDR_ANY,*/ SERVER_PORT, client_ifaces[i-1]); |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 166 | if (fds[i] > n) |
| 167 | n = fds[i]; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 168 | } |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 169 | return n; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | /** |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 174 | * pass_to_server() - forwards dhcp packets from client to server |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 175 | * p - packet to send |
| 176 | * client - number of the client |
| 177 | */ |
Denys Vlasenko | 31af3d5 | 2009-06-17 11:57:09 +0200 | [diff] [blame] | 178 | static void pass_to_server(struct dhcp_packet *p, int packet_len, int client, int *fds, |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 179 | struct sockaddr_in *client_addr, struct sockaddr_in *server_addr) |
| 180 | { |
| 181 | int res, type; |
| 182 | struct xid_item *item; |
| 183 | |
| 184 | /* check packet_type */ |
| 185 | type = get_dhcp_packet_type(p); |
| 186 | if (type != DHCPDISCOVER && type != DHCPREQUEST |
| 187 | && type != DHCPDECLINE && type != DHCPRELEASE |
| 188 | && type != DHCPINFORM |
| 189 | ) { |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | /* create new xid entry */ |
| 194 | item = xid_add(p->xid, client_addr, client); |
| 195 | |
| 196 | /* forward request to LAN (server) */ |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 197 | errno = 0; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 198 | res = sendto(fds[0], p, packet_len, 0, (struct sockaddr*)server_addr, |
| 199 | sizeof(struct sockaddr_in)); |
| 200 | if (res != packet_len) { |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 201 | bb_perror_msg("sendto"); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
| 205 | /** |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 206 | * pass_to_client() - forwards dhcp packets from server to client |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 207 | * p - packet to send |
| 208 | */ |
Denys Vlasenko | 31af3d5 | 2009-06-17 11:57:09 +0200 | [diff] [blame] | 209 | static void pass_to_client(struct dhcp_packet *p, int packet_len, int *fds) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 210 | { |
| 211 | int res, type; |
| 212 | struct xid_item *item; |
| 213 | |
| 214 | /* check xid */ |
| 215 | item = xid_find(p->xid); |
| 216 | if (!item) { |
| 217 | return; |
| 218 | } |
| 219 | |
| 220 | /* check packet type */ |
| 221 | type = get_dhcp_packet_type(p); |
| 222 | if (type != DHCPOFFER && type != DHCPACK && type != DHCPNAK) { |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | if (item->ip.sin_addr.s_addr == htonl(INADDR_ANY)) |
| 227 | item->ip.sin_addr.s_addr = htonl(INADDR_BROADCAST); |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 228 | errno = 0; |
| 229 | res = sendto(fds[item->client], p, packet_len, 0, (struct sockaddr*) &(item->ip), |
| 230 | sizeof(item->ip)); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 231 | if (res != packet_len) { |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 232 | bb_perror_msg("sendto"); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
| 236 | /* remove xid entry */ |
| 237 | xid_del(p->xid); |
| 238 | } |
| 239 | |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 240 | int dhcprelay_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 241 | int dhcprelay_main(int argc, char **argv) |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 242 | { |
Denys Vlasenko | 31af3d5 | 2009-06-17 11:57:09 +0200 | [diff] [blame] | 243 | struct dhcp_packet dhcp_msg; |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 244 | struct sockaddr_in server_addr; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 245 | struct sockaddr_in client_addr; |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 246 | fd_set rfds; |
| 247 | char **client_ifaces; |
| 248 | int *fds; |
| 249 | int num_sockets, max_socket; |
Denys Vlasenko | 990a617 | 2009-06-16 10:23:55 +0200 | [diff] [blame] | 250 | uint32_t our_nip; |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 251 | |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 252 | server_addr.sin_family = AF_INET; |
| 253 | server_addr.sin_port = htons(SERVER_PORT); |
| 254 | |
| 255 | /* dhcprelay client_iface1,client_iface2,... server_iface [server_IP] */ |
| 256 | if (argc == 4) { |
| 257 | if (!inet_aton(argv[3], &server_addr.sin_addr)) |
| 258 | bb_perror_msg_and_die("bad server IP"); |
| 259 | } else if (argc == 3) { |
| 260 | server_addr.sin_addr.s_addr = htonl(INADDR_BROADCAST); |
| 261 | } else { |
| 262 | bb_show_usage(); |
| 263 | } |
| 264 | |
| 265 | /* Produce list of client ifaces */ |
| 266 | client_ifaces = get_client_devices(argv[1], &num_sockets); |
| 267 | |
| 268 | num_sockets++; /* for server socket at fds[0] */ |
| 269 | fds = xmalloc(num_sockets * sizeof(fds[0])); |
| 270 | |
| 271 | /* Create sockets and bind one to every iface */ |
| 272 | max_socket = init_sockets(client_ifaces, num_sockets, argv[2], fds); |
| 273 | |
| 274 | /* Get our IP on server_iface */ |
Denys Vlasenko | 990a617 | 2009-06-16 10:23:55 +0200 | [diff] [blame] | 275 | if (udhcp_read_interface(argv[2], NULL, &our_nip, NULL)) |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 276 | return 1; |
| 277 | |
| 278 | /* Main loop */ |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 279 | while (1) { |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 280 | //reinit stuff from time to time? go back to get_client_devices |
| 281 | //every N minutes? |
| 282 | struct timeval tv; |
| 283 | size_t packlen; |
| 284 | socklen_t addr_size; |
| 285 | int i; |
| 286 | |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 287 | FD_ZERO(&rfds); |
| 288 | for (i = 0; i < num_sockets; i++) |
| 289 | FD_SET(fds[i], &rfds); |
| 290 | tv.tv_sec = SELECT_TIMEOUT; |
| 291 | tv.tv_usec = 0; |
| 292 | if (select(max_socket + 1, &rfds, NULL, NULL, &tv) > 0) { |
| 293 | /* server */ |
| 294 | if (FD_ISSET(fds[0], &rfds)) { |
Denis Vlasenko | 6de8994 | 2008-05-21 07:05:06 +0000 | [diff] [blame] | 295 | packlen = udhcp_recv_kernel_packet(&dhcp_msg, fds[0]); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 296 | if (packlen > 0) { |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 297 | pass_to_client(&dhcp_msg, packlen, fds); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 300 | /* clients */ |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 301 | for (i = 1; i < num_sockets; i++) { |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 302 | if (!FD_ISSET(fds[i], &rfds)) |
| 303 | continue; |
| 304 | addr_size = sizeof(struct sockaddr_in); |
| 305 | packlen = recvfrom(fds[i], &dhcp_msg, sizeof(dhcp_msg), 0, |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 306 | (struct sockaddr *)(&client_addr), &addr_size); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 307 | if (packlen <= 0) |
| 308 | continue; |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 309 | |
| 310 | /* Get our IP on corresponding client_iface */ |
| 311 | //why? what if server can't route such IP? |
Denys Vlasenko | 990a617 | 2009-06-16 10:23:55 +0200 | [diff] [blame] | 312 | if (udhcp_read_interface(client_ifaces[i-1], NULL, &dhcp_msg.gateway_nip, NULL)) { |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 313 | /* Fall back to our server_iface's IP */ |
| 314 | //this makes more sense! |
Denys Vlasenko | 990a617 | 2009-06-16 10:23:55 +0200 | [diff] [blame] | 315 | dhcp_msg.gateway_nip = our_nip; |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 316 | } |
| 317 | //maybe set dhcp_msg.flags |= BROADCAST_FLAG too? |
| 318 | pass_to_server(&dhcp_msg, packlen, i, fds, &client_addr, &server_addr); |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | xid_expire(); |
Denis Vlasenko | e8a7968 | 2009-04-13 03:33:46 +0000 | [diff] [blame] | 322 | } /* while (1) */ |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 323 | |
Denis Vlasenko | b925605 | 2007-09-28 10:29:17 +0000 | [diff] [blame] | 324 | /* return 0; - not reached */ |
Denis Vlasenko | 736230e | 2006-11-20 19:40:36 +0000 | [diff] [blame] | 325 | } |