aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpd.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/dhcpd.c')
-rw-r--r--networking/udhcp/dhcpd.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 66750e2e6..2904119e5 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -649,7 +649,8 @@ static void init_packet(struct dhcp_packet *packet, struct dhcp_packet *oldpacke
649 packet->flags = oldpacket->flags; 649 packet->flags = oldpacket->flags;
650 packet->gateway_nip = oldpacket->gateway_nip; 650 packet->gateway_nip = oldpacket->gateway_nip;
651 packet->ciaddr = oldpacket->ciaddr; 651 packet->ciaddr = oldpacket->ciaddr;
652 udhcp_add_simple_option(packet, DHCP_SERVER_ID, server_data.server_nip); 652 IF_FEATURE_UDHCPD_BOOTP(if (type != MSGTYPE_BOOTP))
653 udhcp_add_simple_option(packet, DHCP_SERVER_ID, server_data.server_nip);
653} 654}
654 655
655/* Fill options field, siaddr_nip, and sname and boot_file fields. 656/* Fill options field, siaddr_nip, and sname and boot_file fields.
@@ -725,7 +726,12 @@ static uint32_t select_lease_time(struct dhcp_packet *packet)
725 726
726/* We got a DHCP DISCOVER. Send an OFFER. */ 727/* We got a DHCP DISCOVER. Send an OFFER. */
727/* NOINLINE: limit stack usage in caller */ 728/* NOINLINE: limit stack usage in caller */
728static NOINLINE void send_offer(struct dhcp_packet *oldpacket, 729#if !ENABLE_FEATURE_UDHCPD_BOOTP
730#define send_offer(is_dhcp_client, ...) \
731 send_offer(__VA_ARGS__)
732#endif
733static NOINLINE void send_offer(void *is_dhcp_client,
734 struct dhcp_packet *oldpacket,
729 uint32_t static_lease_nip, 735 uint32_t static_lease_nip,
730 struct dyn_lease *lease, 736 struct dyn_lease *lease,
731 uint32_t requested_nip, 737 uint32_t requested_nip,
@@ -734,7 +740,12 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
734 struct dhcp_packet packet; 740 struct dhcp_packet packet;
735 uint32_t lease_time_sec; 741 uint32_t lease_time_sec;
736 742
743#if ENABLE_FEATURE_UDHCPD_BOOTP
744 init_packet(&packet, oldpacket, is_dhcp_client ? DHCPOFFER : MSGTYPE_BOOTP);
745#else
746 enum { is_dhcp_client = 1 };
737 init_packet(&packet, oldpacket, DHCPOFFER); 747 init_packet(&packet, oldpacket, DHCPOFFER);
748#endif
738 749
739 /* If it is a static lease, use its IP */ 750 /* If it is a static lease, use its IP */
740 packet.yiaddr = static_lease_nip; 751 packet.yiaddr = static_lease_nip;
@@ -784,9 +795,16 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
784 } 795 }
785 } 796 }
786 797
787 lease_time_sec = select_lease_time(oldpacket); 798 if (is_dhcp_client) {
788 udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec)); 799 lease_time_sec = select_lease_time(oldpacket);
800 udhcp_add_simple_option(&packet, DHCP_LEASE_TIME, htonl(lease_time_sec));
801 }
802/* TODO: pass "is_dhcp_client" to add_server_options(), avoid adding confusing options to BOOTP clients? */
789 add_server_options(&packet); 803 add_server_options(&packet);
804 if (!is_dhcp_client && udhcp_end_option(packet.options) >= RFC1048_OPTIONS_BUFSIZE) {
805 bb_simple_error_msg("BOOTP reply too large, not sending");
806 return;
807 }
790 808
791 /* send_packet emits error message itself if it detects failure */ 809 /* send_packet emits error message itself if it detects failure */
792 send_packet_verbose(&packet, "sending OFFER to %s"); 810 send_packet_verbose(&packet, "sending OFFER to %s");
@@ -1050,8 +1068,12 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
1050 continue; 1068 continue;
1051 } 1069 }
1052 msg_type = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE); 1070 msg_type = udhcp_get_option(&packet, DHCP_MESSAGE_TYPE);
1053 if (!msg_type || msg_type[0] < DHCP_MINTYPE || msg_type[0] > DHCP_MAXTYPE) { 1071 if (
1054 bb_info_msg("no or bad message type option%s", ", ignoring packet"); 1072 IF_FEATURE_UDHCPD_BOOTP( msg_type && )
1073 IF_NOT_FEATURE_UDHCPD_BOOTP( !msg_type || )
1074 (msg_type[0] < DHCP_MINTYPE || msg_type[0] > DHCP_MAXTYPE)
1075 ) {
1076 bb_info_msg("bad message type option%s", ", ignoring packet");
1055 continue; 1077 continue;
1056 } 1078 }
1057 1079
@@ -1086,12 +1108,25 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
1086 move_from_unaligned32(requested_nip, requested_ip_opt); 1108 move_from_unaligned32(requested_nip, requested_ip_opt);
1087 } 1109 }
1088 1110
1111#if ENABLE_FEATURE_UDHCPD_BOOTP
1112 /* Handle old BOOTP clients */
1113 if (!msg_type) {
1114 log1("received %s", "BOOTP BOOTREQUEST");
1115 if (!static_lease_nip) {
1116 bb_info_msg("no static lease for BOOTP client%s", ", ignoring packet");
1117 continue;
1118 }
1119 send_offer(msg_type, &packet, static_lease_nip, lease, requested_nip, arpping_ms);
1120 continue;
1121 }
1122#endif
1123
1089 switch (msg_type[0]) { 1124 switch (msg_type[0]) {
1090 1125
1091 case DHCPDISCOVER: 1126 case DHCPDISCOVER:
1092 log1("received %s", "DISCOVER"); 1127 log1("received %s", "DISCOVER");
1093 1128
1094 send_offer(&packet, static_lease_nip, lease, requested_nip, arpping_ms); 1129 send_offer(msg_type, &packet, static_lease_nip, lease, requested_nip, arpping_ms);
1095 break; 1130 break;
1096 1131
1097 case DHCPREQUEST: 1132 case DHCPREQUEST: