Lines Matching refs:packet

478 static void fill_envp(struct dhcp_packet *packet)  in fill_envp()  argument
486 if (!packet) in fill_envp()
489 init_scan_state(packet, &scan_state); in fill_envp()
495 while ((optptr = udhcp_scan_options(packet, &scan_state)) != NULL) { in fill_envp()
542 sprint_nip(new_opt, "ip=", (uint8_t *) &packet->yiaddr); in fill_envp()
545 if (packet->siaddr_nip) { in fill_envp()
548 sprint_nip(new_opt, "siaddr=", (uint8_t *) &packet->siaddr_nip); in fill_envp()
551 if (packet->gateway_nip) { in fill_envp()
554 sprint_nip(new_opt, "giaddr=", (uint8_t *) &packet->gateway_nip); in fill_envp()
557 if (!(scan_state.overload & FILE_FIELD) && packet->file[0]) { in fill_envp()
559 new_opt = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file); in fill_envp()
562 if (!(scan_state.overload & SNAME_FIELD) && packet->sname[0]) { in fill_envp()
564 new_opt = xasprintf("sname=%."DHCP_PKT_SNAME_LEN_STR"s", packet->sname); in fill_envp()
570 static void d4_run_script(struct dhcp_packet *packet, const char *name) in d4_run_script() argument
574 fill_envp(packet); in d4_run_script()
601 static void init_packet(struct dhcp_packet *packet, char type) in init_packet() argument
606 udhcp_init_header(packet, type); in init_packet()
608 packet->xid = client_data.xid; in init_packet()
614 packet->secs = (secs < 0xffff) ? htons(secs) : 0xffff; in init_packet()
616 memcpy(packet->chaddr, client_data.client_mac, 6); in init_packet()
619 static void add_client_options(struct dhcp_packet *packet) in add_client_options() argument
623 udhcp_add_simple_option(packet, DHCP_MAX_SIZE, htons(IP_UDP_DHCP_SIZE)); in add_client_options()
628 end = udhcp_end_option(packet->options); in add_client_options()
632 packet->options[end + OPT_DATA + len] = i; in add_client_options()
637 packet->options[end + OPT_CODE] = DHCP_PARAM_REQ; in add_client_options()
638 packet->options[end + OPT_LEN] = len; in add_client_options()
639 packet->options[end + OPT_DATA + len] = DHCP_END; in add_client_options()
643 if ((option_mask32 & OPT_B) && packet->ciaddr == 0) in add_client_options()
644 packet->flags |= htons(BROADCAST_FLAG); in add_client_options()
650 udhcp_add_binary_option(packet, curr->data); in add_client_options()
666 static void add_serverid_and_clientid_options(struct dhcp_packet *packet, uint32_t server) in add_serverid_and_clientid_options() argument
670 udhcp_add_simple_option(packet, DHCP_SERVER_ID, server); in add_serverid_and_clientid_options()
681 udhcp_add_binary_option(packet, ci->data); in add_serverid_and_clientid_options()
702 static int raw_bcast_from_client_data_ifindex(struct dhcp_packet *packet, uint32_t src_nip) in raw_bcast_from_client_data_ifindex() argument
704 return udhcp_send_raw_packet(packet, in raw_bcast_from_client_data_ifindex()
710 static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server) in bcast_or_ucast() argument
713 return udhcp_send_kernel_packet(packet, in bcast_or_ucast()
717 return raw_bcast_from_client_data_ifindex(packet, ciaddr); in bcast_or_ucast()
724 struct dhcp_packet packet; in send_discover() local
729 init_packet(&packet, DHCPDISCOVER); in send_discover()
732 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); in send_discover()
737 add_client_options(&packet); in send_discover()
740 return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); in send_discover()
750 struct dhcp_packet packet; in send_select() local
769 init_packet(&packet, DHCPREQUEST); in send_select()
771 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); in send_select()
773 udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server); in send_select()
778 add_client_options(&packet); in send_select()
787 return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); in send_select()
794 struct dhcp_packet packet; in send_renew() local
813 init_packet(&packet, DHCPREQUEST); in send_renew()
815 packet.ciaddr = ciaddr; in send_renew()
820 add_client_options(&packet); in send_renew()
830 return bcast_or_ucast(&packet, ciaddr, server); in send_renew()
838 struct dhcp_packet packet; in send_decline() local
843 init_packet(&packet, DHCPDECLINE); in send_decline()
846 udhcp_add_simple_option(&packet, DHCP_REQUESTED_IP, requested); in send_decline()
848 add_serverid_and_clientid_options(&packet, server); in send_decline()
851 return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY); in send_decline()
860 struct dhcp_packet packet; in send_release() local
865 init_packet(&packet, DHCPRELEASE); in send_release()
868 packet.ciaddr = ciaddr; in send_release()
870 add_serverid_and_clientid_options(&packet, server); in send_release()
877 return bcast_or_ucast(&packet, ciaddr, server); in send_release()
885 struct ip_udp_dhcp_packet packet; in d4_recv_raw_packet() local
895 iov.iov_base = &packet; in d4_recv_raw_packet()
896 iov.iov_len = sizeof(packet); in d4_recv_raw_packet()
914 if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) { in d4_recv_raw_packet()
919 if (bytes < ntohs(packet.ip.tot_len)) { in d4_recv_raw_packet()
926 bytes = ntohs(packet.ip.tot_len); in d4_recv_raw_packet()
929 if (packet.ip.protocol != IPPROTO_UDP in d4_recv_raw_packet()
930 || packet.ip.version != IPVERSION in d4_recv_raw_packet()
931 || packet.ip.ihl != (sizeof(packet.ip) >> 2) in d4_recv_raw_packet()
932 || packet.udp.dest != htons(CLIENT_PORT) in d4_recv_raw_packet()
934 || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip)) in d4_recv_raw_packet()
941 check = packet.ip.check; in d4_recv_raw_packet()
942 packet.ip.check = 0; in d4_recv_raw_packet()
943 if (check != inet_cksum(&packet.ip, sizeof(packet.ip))) { in d4_recv_raw_packet()
963 memset(&packet.ip, 0, offsetof(struct iphdr, protocol)); in d4_recv_raw_packet()
965 packet.ip.tot_len = packet.udp.len; /* yes, this is needed */ in d4_recv_raw_packet()
966 check = packet.udp.check; in d4_recv_raw_packet()
967 packet.udp.check = 0; in d4_recv_raw_packet()
968 if (check && check != inet_cksum(&packet, bytes)) { in d4_recv_raw_packet()
974 if (packet.data.cookie != htonl(DHCP_MAGIC)) { in d4_recv_raw_packet()
981 udhcp_dump_packet(&packet.data); in d4_recv_raw_packet()
983 bytes -= sizeof(packet.ip) + sizeof(packet.udp); in d4_recv_raw_packet()
984 memcpy(dhcp_pkt, &packet.data, bytes); in d4_recv_raw_packet()
1383 struct dhcp_packet packet; in udhcpc_main() local
1625 len = udhcp_recv_kernel_packet(&packet, client_data.sockfd); in udhcpc_main()
1627 len = d4_recv_raw_packet(&packet, client_data.sockfd); in udhcpc_main()
1638 if (packet.xid != client_data.xid) { in udhcpc_main()
1640 (unsigned)packet.xid, (unsigned)client_data.xid, in udhcpc_main()
1647 if (packet.hlen != 6 in udhcpc_main()
1648 || memcmp(packet.chaddr, client_data.client_mac, 6) != 0 in udhcpc_main()
1655 message = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); in udhcpc_main()
1693 temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); in udhcpc_main()
1701 temp_addr.s_addr = requested_ip = packet.yiaddr; in udhcpc_main()
1724 temp_addr.s_addr = packet.yiaddr; in udhcpc_main()
1727 temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME); in udhcpc_main()
1748 requested_ip = packet.yiaddr; in udhcpc_main()
1770 send_decline(server_id, packet.yiaddr); in udhcpc_main()
1785 d4_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew"); in udhcpc_main()
1815 uint8_t *temp = udhcp_get_option32(&packet, DHCP_SERVER_ID); in udhcpc_main()
1826 d4_run_script(&packet, "nak"); in udhcpc_main()