aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/packet.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* udhcpd: optional BOOTP supportDenys Vlasenko2023-06-121-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | from Adam Goldman <adamg@pobox.com> This patch makes udhcpd respond correctly to queries from BOOTP clients. It contains the following changes: The end field, or DHCP_END option, is required in DHCP requests but optional in BOOTP requests. However, we still send an end field in all replies, because some BOOTP clients expect one in replies even if they didn't send one in the request. Requests without a DHCP_MESSAGE_TYPE are recognized as BOOTP requests and handled appropriately, instead of being discarded. We still require an RFC 1048 options field, but we allow it to be empty. Since a BOOTP client will keep using the assigned IP forever, we only send a BOOTP reply if a static lease exists for that client. BOOTP replies shouldn't contain DHCP_* options, so we omit them if there was no DHCP_MESSAGE_TYPE in the request. Options other than DHCP_* options are still sent. The options field of a BOOTP reply must be exactly 64 bytes. If we construct a reply with more than 64 bytes of options, we give up and log an error instead of sending it. udhcp_send_raw_packet already pads the options field to 64 bytes if it is too short. This implementation has been tested against an HP PA-RISC client. function old new delta .rodata 105247 105321 +74 udhcpd_main 1520 1591 +71 send_offer 419 470 +51 init_packet 81 97 +16 udhcp_init_header 75 88 +13 udhcp_scan_options 192 203 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 6/0 up/down: 236/0) Total: 236 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: add a few comments, no code changesDenys Vlasenko2022-12-151-0/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc: improve logs - show offer as it is receivedDenys Vlasenko2021-06-021-1/+2
| | | | | | | | | | | | function old new delta udhcpc_main 2566 2608 +42 .rodata 103248 103272 +24 udhcp_recv_raw_packet 559 562 +3 d6_recv_raw_packet 254 255 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 70/0) Total: 70 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: bind to device even for ucast packetsMichal Kazior2020-12-151-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are cases where binding to source IP and destination IP is insufficient to guarantee sane xmit netdev. One case where this can fail is when route-matching netdev carrier is down (cable unplugged, wifi disconnected), or the netdev is admin down. Then all the IP based bindings (bind() + connect()) will seemingly succeed but the actual packet can go out through a default gw path. Depending on the network this happens on it can create issues or false alarms. It can also leak some subnet info across networks that shouldn't be routed. As such better be safe than sorry and bind to a netdev to be sure it's used for xmit. function old new delta udhcp_send_kernel_packet 293 336 +43 send_packet 182 188 +6 bcast_or_ucast 37 43 +6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 3/0 up/down: 55/0) Total: 55 bytes Signed-off-by: Michal Kazior <michal@plume.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* gcc-9.x warning fixesDenys Vlasenko2020-10-011-2/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne2019-07-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Optionally re-introduce bb_info_msg()James Byrne2019-04-301-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Between Busybox 1.24.2 and 1.25.0 the bb_info_msg() function was eliminated and calls to it changed to be bb_error_msg(). The downside of this is that daemons now log all messages to syslog at the LOG_ERR level which makes it hard to filter errors from informational messages. This change optionally re-introduces bb_info_msg(), controlled by a new option FEATURE_SYSLOG_INFO, restores all the calls to bb_info_msg() that were removed (only in applets that set logmode to LOGMODE_SYSLOG or LOGMODE_BOTH), and also changes informational messages in ifplugd and ntpd. The code size change of this is as follows (using 'defconfig' on x86_64 with gcc 7.3.0-27ubuntu1~18.04) function old new delta bb_info_msg - 182 +182 bb_vinfo_msg - 27 +27 static.log7 194 198 +4 log8 190 191 +1 log5 190 191 +1 crondlog 45 - -45 ------------------------------------------------------------------------------ (add/remove: 2/1 grow/shrink: 3/0 up/down: 215/-45) Total: 170 bytes If you don't care about everything being logged at LOG_ERR level then when FEATURE_SYSLOG_INFO is disabled Busybox actually gets smaller: function old new delta static.log7 194 200 +6 log8 190 193 +3 log5 190 193 +3 syslog_level 1 - -1 bb_verror_msg 583 581 -2 crondlog 45 - -45 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 3/1 up/down: 12/-48) Total: -36 bytes Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc: remove code which requires server ID to be on local networkDenys Vlasenko2018-06-211-4/+3
| | | | | | | | | | | | | | | | | This reverts "udhcpc: paranoia when using kernel UDP mode for sending renew: server ID may be bogus". Users complain that they do have servers behind routers (with DHCP relays). function old new delta send_packet 168 166 -2 bcast_or_ucast 25 23 -2 udhcp_send_kernel_packet 301 295 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-10) Total: -10 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc[6]: make log2 messages for chaddr field indented like the restDenys Vlasenko2017-09-291-4/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc: paranoia when using kernel UDP mode for sending renew: server ID may ↵Denys Vlasenko2017-09-291-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | be bogus With new code, we request that target IP (server ID) must be directly reachable. If it's not, this happens: udhcpc: waiting 2000 seconds udhcpc: entering listen mode: kernel udhcpc: opening listen socket on *:68 wlan0 udhcpc: entering renew state udhcpc: sending renew to 1.1.1.1 udhcpc: send: Network is unreachable ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1.1.1.1 needs routing, this is fishy! udhcpc: entering rebinding state udhcpc: entering listen mode: raw udhcpc: created raw socket udhcpc: sending renew to 0.0.0.0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ going to use broadcast which is the desired behavior. Before the patch, packet to 1.1.1.1 was routed over eth0 (!) and maybe even into Internet (!!!). function old new delta udhcpc_main 2752 2763 +11 udhcp_send_kernel_packet 295 301 +6 send_renew 82 84 +2 send_packet 166 168 +2 bcast_or_ucast 23 25 +2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/0 up/down: 23/0) Total: 23 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc[6]: initialize entire sockaddr_llDenys Vlasenko2017-09-291-0/+2
| | | | | | | | | | | I see random field values like sll_hatype=0x267 when I strace. They seem to not matter, but just in case they sometimes do, let's at least have deterministic values (via memset(0)). function old new delta change_listen_mode 308 322 +14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* randomconfig fixesDenys Vlasenko2017-07-031-0/+2
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: get rid of bb_info_msg()Denys Vlasenko2016-03-301-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | function old new delta udhcpd_main 1501 1531 +30 d6_recv_raw_packet 251 264 +13 perform_d6_release 188 198 +10 udhcpc6_main 2443 2449 +6 udhcp_recv_raw_packet 582 588 +6 udhcp_recv_kernel_packet 132 138 +6 send_d6_renew 140 146 +6 d6_recv_kernel_packet 118 124 +6 send_renew 77 82 +5 send_discover 85 90 +5 send_decline 84 89 +5 send_d6_select 97 102 +5 send_d6_discover 174 179 +5 perform_release 167 172 +5 count_lines 72 74 +2 udhcpc_main 2836 2837 +1 bb_info_msg 125 - -125 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 17/4 up/down: 117/-180) Total: -63 bytes text data bss dec hex filename 924935 906 17160 943001 e6399 busybox_old 924736 906 17160 942802 e62d2 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc: make DHCP packets to have at least 300 DHCP bytesJohannes Stezenbach2013-10-281-0/+9
| | | | | | | | | | | | | | | | | | Commit b8b72f02 removed all padding from DHCP packets to fix operation with buggy servers which can't handle maximum sized packets. But it introduced a regression with buggy routers which drop DHCP packets smaller than 300 bytes (i.e. 342 byte ethernet packets). Add back some padding to work around. function old new delta udhcp_send_kernel_packet 268 292 +24 udhcp_send_raw_packet 462 473 +11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 35/0) Total: 35 bytes Signed-off-by: Johannes Stezenbach <js@sig21.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc: trim help text, rename badly-named variableDenys Vlasenko2011-11-071-12/+11
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpc: remove workaround for bugs in Win98 dhcp server ("MSFT 98" vendor ↵Denys Vlasenko2011-11-051-31/+3
| | | | | | | | | | | | | | | | | | | string) Stats for last three commits: function old new delta udhcpc_main 2635 2646 +11 udhcp_recv_raw_packet 425 414 -11 udhcp_recv_kernel_packet 210 134 -76 packed_usage 28940 28857 -83 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 11/-170) Total: -159 bytes text data bss dec hex filename 879524 493 7584 887601 d8b31 busybox_old 879340 493 7584 887417 d8a79 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* networking: consolidate the IP checksum code. -129 bytes.Baruch Siach2011-09-071-31/+3
| | | | | Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* *: simplify Ethernet header includesDan Fandrich2011-06-101-10/+3
| | | | | Signed-off-by: Dan Fandrich <dan@coneharvesters.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* dhcp: typo fix: UPD_DHCP_SIZE -> UDP_DHCP_SIZEDenys Vlasenko2010-10-201-4/+4
| | | | Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* *: make GNU licensing statement forms more regularDenys Vlasenko2010-08-161-1/+1
| | | | | | | This change retains "or later" state! No licensing _changes_ here, only form is adjusted (article, space between "GPL" and "v2" and so on). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* dhcp: truncate packets instead of padding them to 574 bytes. closes bug 1849Denys Vlasenko2010-05-311-12/+20
| | | | | | | | function old new delta udhcp_send_raw_packet 411 456 +45 udhcp_send_kernel_packet 259 271 +12 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* dhcp: readability cleanups and small code shrinkDenys Vlasenko2010-05-301-27/+19
| | | | | | | function old new delta udhcp_run_script 654 617 -37 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: cosmetic cleanups; one case of s/full_read/xread/Denys Vlasenko2010-03-261-6/+7
| | | | | | | function old new delta dumpleases_main 632 623 -9 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: pass pointer to whole packet to "add option" functionsDenys Vlasenko2010-03-261-1/+1
| | | | | | | | | | | | | | | | | | | | | This is needed for "overflow option" support function old new delta udhcp_find_option - 34 +34 udhcp_add_binary_option 94 106 +12 write_leases 227 223 -4 udhcp_init_header 86 82 -4 send_release 104 99 -5 init_packet 87 81 -6 add_client_options 160 154 -6 add_server_options 100 92 -8 udhcpd_main 1964 1954 -10 udhcpc_main 2859 2837 -22 find_option 34 - -34 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/8 up/down: 46/-99) Total: -53 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: handle errors in read_staticleaseDenys Vlasenko2010-03-231-3/+3
| | | | | | | | | also gets rid of ether-aton's static buffer in ether-wake: text data bss dec hexfilename 838664 441 7572 846677 ceb55busybox_old 838650 441 7564 846655 ceb3fbusybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: merge options.h into common.h, script.c into dhcpc.cDenys Vlasenko2010-03-221-4/+3
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcpd: untangle incredibly messy handling of DHCPREQUESTDenys Vlasenko2010-03-211-4/+7
| | | | | | | | | | | | | | Also fixes attacks possible via DHCPDECLINE / DHCPRELEASE function old new delta udhcpd_main 1846 1949 +103 send_renew 105 142 +37 send_NAK 61 - -61 send_ACK 180 - -180 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 2/0 up/down: 140/-241) Total: -101 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* remove trailing whitespaceDenys Vlasenko2009-07-151-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: fix trivial compile errorDenys Vlasenko2009-06-191-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: logging improvements, field and variable renamesDenys Vlasenko2009-06-171-1/+1
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: shorten mac len from 16 to 6 in lease fileDenys Vlasenko2009-06-171-10/+10
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* udhcp: change UDHCP_DEBUG into int, make verbosity selectable with -vDenys Vlasenko2009-06-171-16/+60
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Fix forgotten license commentsDenis Vlasenko2008-12-071-0/+6
|
* udhcp: add inline docs; small code shrinkDenis Vlasenko2008-09-261-4/+4
| | | | | | | function old new delta send_packet 103 87 -16 udhcpc_main 2359 2323 -36
* udhcp: added some FIXMEs; code shrink. -49 bytesDenis Vlasenko2008-09-261-1/+2
|
* dhcp: add FAST_FUNC as appropriate. -160 bytes.Denis Vlasenko2008-09-261-5/+5
|
* udhcpc: regularize the names of receiving functions,Denis Vlasenko2008-05-211-1/+1
| | | | | | pause on "serious failure to receive". Some misc fixes are also folded in here.
* udhcp: we were forgetting to set right op byte in tha packetDenis Vlasenko2008-02-201-6/+1
| | | | | for DHCPDECLINE. Fixing, and making code smaller.
* Makefile: change version to 1.10.0.svnDenis Vlasenko2007-12-241-32/+41
| | | | | | | | | | | udhcpc: make UDP packet sending the same as raw sending in regards to error messages. Minor code size shrink. Total size grows due to added messages: text data bss dec hex filename 770312 683 7244 778239 bdfff busybox_old 770327 683 7244 778254 be00e busybox_unstripped
* udhcp: decided to not send "short" dhcp packets,Denis Vlasenko2007-12-211-1/+6
| | | | | but lets add comments how to do it if needed.
* udhcp: fix oversized packet sending (introduced by "slack for bad dhcp ↵Denis Vlasenko2007-12-201-13/+23
| | | | | | | | | | | | | | | | | servers" options); slight optimizations and function renaming udhcp_send_raw_packet - 391 +391 udhcp_send_kernel_packet - 197 +197 udhcp_recv_packet - 134 +134 get_raw_packet 353 326 -27 udhcp_get_packet 134 - -134 udhcp_kernel_packet 197 - -197 udhcp_raw_packet 391 - -391 ------------------------------------------------------------------------------ (add/remove: 3/3 grow/shrink: 0/1 up/down: 722/-749) Total: -27 bytes
* dhcp: stop using magic constants; use (htonl(CONST) != a) - it's smallerDenis Vlasenko2007-11-231-5/+1
| | | | | | | function old new delta udhcp_get_packet 146 134 -12 get_raw_packet 368 353 -15
* introduce and use xdup2(int, int)Denis Vlasenko2007-08-181-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | stop checking whether setsockopt_reuseaddr(int fd) was successful (it always is) remove second parameter (sockllen) from xmalloc_sockaddr2xxxxx functions sockaddr2str 142 156 +14 collect_blk 467 474 +7 xdup2 28 33 +5 singlemount 4456 4454 -2 print_host 214 212 -2 nslookup_main 139 137 -2 ftpgetput_main 414 412 -2 udhcpd_main 1258 1255 -3 udhcpc_main 2405 2402 -3 traceroute_main 4125 4122 -3 nc_main 1072 1069 -3 buffer_fill_and_print 76 73 -3 xmalloc_sockaddr2hostonly_noport 18 14 -4 xmalloc_sockaddr2host_noport 18 14 -4 xmalloc_sockaddr2host 15 11 -4 xmalloc_sockaddr2dotted_noport 18 14 -4 xmalloc_sockaddr2dotted 18 14 -4 wget_main 2618 2614 -4 ping_main 393 389 -4 ip_port_str 120 115 -5 dhcprelay_main 1146 1141 -5 dnsd_main 1531 1525 -6 passwd_main 1110 1102 -8 udhcp_kernel_packet 206 197 -9 udhcp_listen_socket 154 144 -10 getty_main 2576 2566 -10 setup 655 640 -15 xmove_fd 51 34 -17 dolisten 759 742 -17 tcpudpsvd_main 1866 1836 -30 startservice 339 299 -40
* udhcp: many small fixes:Denis Vlasenko2007-07-031-10/+24
| | | | | | | | | | | | | | | | | | | | | | | | * arpping(): smaller and even probably fixed * lots of variables/params converted: ulong -> uint32_t * uptime() nuked in favor of monotonic_sec() * udhcp_get_packet(): only one "bad vendor", simplify function old new delta reservedIp 36 35 -1 udhcpc_main 2462 2460 -2 addStaticLease 64 62 -2 static.broken_vendors 16 - -16 uptime 19 - -19 udhcpd_main 1273 1238 -35 udhcp_get_packet 223 184 -39 .rodata 144162 144106 -56 arpping 690 609 -81 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-251) Total: -251 bytes text data bss dec hex filename 734241 3028 14400 751669 b7835 busybox_old 734005 3028 14400 751433 b7749 busybox_unstripped
* udhcp: MAC_BCAST_ADDR and blank_chaddr are in fact constant, move to rodata.Denis Vlasenko2007-04-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | a few global variables reduced to smallints function old new delta add_lease 75 227 +152 static.blank_chaddr - 16 +16 MAC_BCAST_ADDR - 6 +6 sockfd 4 8 +4 udhcp_run_script 1153 1155 +2 state 8 5 -3 listen_mode 4 1 -3 perform_release 152 148 -4 fd 8 4 -4 blank_chaddr 16 - -16 udhcpc_main 2518 2497 -21 .rodata 131864 131832 -32 oldest_expired_lease 61 - -61 clear_lease 127 - -127 ------------------------------------------------------------------------------ (add/remove: 2/3 grow/shrink: 3/6 up/down: 180/-271) Total: -91 bytes
* A bunch of defined(__GLIBC__) added. static-linking warning expandedDenis Vlasenko2006-12-181-1/+1
|
* introduce setsockopt_reuseaddr(int fd), setsockopt_broadcast(int fd),Denis Vlasenko2006-11-221-2/+1
| | | | | use them where appropriate. 200 bytes saved
* add compile-time check for correct DHCP packet sizeDenis Vlasenko2006-11-201-0/+4
|
* udhcp: fix indentation and style.Denis Vlasenko2006-11-181-16/+16
| | | | | Eliminate (group) a lot of smallish *.h files Remove lots of unneeded #includes
* add -Wundef, fix uncovered bugsDenis Vlasenko2006-11-171-1/+1
|