/** * pass_on() - forwards dhcp packets from client to server * p - packet to send * client - number of the client */ static void pass_on(struct dhcpMessage *p, int packet_len, int client, int *fds, struct sockaddr_in *client_addr, struct sockaddr_in *server_addr) { int res, type; struct xid_item *item; /* check packet_type */ type = get_dhcp_packet_type(p); if (type != DHCPDISCOVER && type != DHCPREQUEST && type != DHCPDECLINE && type != DHCPRELEASE && type != DHCPINFORM ) { return; } /* create new xid entry */ item = xid_add(p->xid, client_addr, client); /* forward request to LAN (server) */ res = sendto(fds[0], p, packet_len, 0, (struct sockaddr*)server_addr, sizeof(struct sockaddr_in)); if (res != packet_len) { bb_perror_msg("pass_on"); return; } }
/** * pass_to_server() - forwards dhcp packets from client to server * p - packet to send * client - number of the client */ static void pass_to_server(struct dhcp_packet *p, int packet_len, int client, int *fds, struct sockaddr_in *client_addr, struct sockaddr_in *server_addr) { int type; /* check packet_type */ type = get_dhcp_packet_type(p); if (type != DHCPDISCOVER && type != DHCPREQUEST && type != DHCPDECLINE && type != DHCPRELEASE && type != DHCPINFORM ) { return; } /* create new xid entry */ xid_add(p->xid, client_addr, client); /* forward request to server */ /* note that we send from fds[0] which is bound to SERVER_PORT (67). * IOW: we send _from_ SERVER_PORT! Although this may look strange, * RFC 1542 not only allows, but prescribes this for BOOTP relays. */ sendto_ip4(fds[0], p, packet_len, server_addr); }