dhcp problem with several routers
ftrenc
ftrenc at e2s.net
Thu Dec 20 16:13:07 UTC 2007
Hi
I've been having problems with the dhcp when connecting to several
routers. I saw you aplied this solution to the problem:
http://busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/networking/udhcp/clientpacket.c?rev=20565&r1=20483&r2=20565
but I still having the same problems.
The problem it's that router answers us with 1090 bytes frame. Finally
we saw that making the dhcp discover to not send the amount of padding
it sends though the router at the end of frame, there was no problem,
and also the router don't send us that amount of padding to.
Our solution to the problem (Packet.c):
int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip,
int source_port,
uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex)
{
int fd;
int result;
struct sockaddr_ll dest;
struct udp_dhcp_packet packet;
int sizeDhcpMessage= sizeof(struct dhcpMessage) -
sizeof(payload->options) + end_option(payload->options) +1 ;
if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
DEBUG(LOG_ERR, "socket call failed: %m");
return -1;
}
memset(&dest, 0, sizeof(dest));
memset(&packet, 0, sizeof(packet));
dest.sll_family = AF_PACKET;
dest.sll_protocol = htons(ETH_P_IP);
dest.sll_ifindex = ifindex;
dest.sll_halen = 6;
memcpy(dest.sll_addr, dest_arp, 6);
if (bind(fd, (struct sockaddr *)&dest, sizeof(struct sockaddr_ll)) <
0) {
DEBUG(LOG_ERR, "bind call failed: %m");
close(fd);
return -1;
}
packet.ip.protocol = IPPROTO_UDP;
packet.ip.saddr = source_ip;
packet.ip.daddr = dest_ip;
packet.udp.source = htons(source_port);
packet.udp.dest = htons(dest_port);
//packet.udp.len = htons(sizeof(packet.udp) + sizeof(struct
dhcpMessage)); /* cheat on the psuedo-header */
packet.udp.len = htons(sizeof(packet.udp) + sizeDhcpMessage); /*
cheat on the psuedo-header */
packet.ip.tot_len = packet.udp.len;
//memcpy(&(packet.data), payload, sizeof(struct dhcpMessage));
memcpy(&(packet.data), payload, sizeDhcpMessage);
//packet.udp.check = udhcp_checksum(&packet, sizeof(struct
udp_dhcp_packet));
packet.udp.check = udhcp_checksum(&packet, sizeof(packet.ip) +
sizeof(packet.udp) + sizeDhcpMessage);
//packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet));
packet.ip.tot_len = htons(sizeof(packet.ip) + sizeof(packet.udp) +
sizeDhcpMessage);
packet.ip.ihl = sizeof(packet.ip) >> 2;
packet.ip.version = IPVERSION;
packet.ip.ttl = IPDEFTTL;
packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip));
//result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0,
(struct sockaddr *) &dest, sizeof(dest));
result = sendto(fd, &packet, sizeof(packet.ip) + sizeof(packet.udp) +
sizeDhcpMessage, 0, (struct sockaddr *) &dest, sizeof(dest));
if (result <= 0) {
DEBUG(LOG_ERR, "write on socket failed: %m");
}
close(fd);
return result;
}
We also did this in clientpacket.c:
/* initialize a packet with the proper defaults */
static void init_packet(struct dhcpMessage *packet, char type)
{
udhcp_init_header(packet, type);
memcpy(packet->chaddr, client_config.arp, 6);
//if (client_config.clientid)
//add_option_string(packet->options, client_config.clientid);
if (client_config.hostname) add_option_string(packet->options,
client_config.hostname);
if (client_config.fqdn) add_option_string(packet->options,
client_config.fqdn);
//add_option_string(packet->options, client_config.vendorclass);
}
Please let me know if that's been usefoul for you, or if our solution
it's not complete or could become in having other bugs or, and also of
course if you know more about this problem.
Thanks. Frank.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ftrenc.vcf
Type: text/x-vcard
Size: 371 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20071220/c755a0be/attachment-0002.vcf
More information about the busybox
mailing list