400-udhcpc-remove-code-which-requires-server-ID-to-be-on.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. From 148788eb0ee96026105755cf3fd1ad3d94f49cd2 Mon Sep 17 00:00:00 2001
  2. From: Denys Vlasenko <[email protected]>
  3. Date: Thu, 21 Jun 2018 17:36:22 +0200
  4. Subject: [PATCH] udhcpc: remove code which requires server ID to be on local
  5. network
  6. This reverts "udhcpc: paranoia when using kernel UDP mode
  7. for sending renew: server ID may be bogus".
  8. Users complain that they do have servers behind routers
  9. (with DHCP relays).
  10. function old new delta
  11. send_packet 168 166 -2
  12. bcast_or_ucast 25 23 -2
  13. udhcp_send_kernel_packet 301 295 -6
  14. ------------------------------------------------------------------------------
  15. (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-10) Total: -10 bytes
  16. Signed-off-by: Denys Vlasenko <[email protected]>
  17. ---
  18. networking/udhcp/common.h | 4 +---
  19. networking/udhcp/d6_dhcpc.c | 4 +---
  20. networking/udhcp/dhcpc.c | 10 ++--------
  21. networking/udhcp/dhcpd.c | 4 +---
  22. networking/udhcp/packet.c | 7 +++----
  23. 5 files changed, 8 insertions(+), 21 deletions(-)
  24. --- a/networking/udhcp/common.h
  25. +++ b/networking/udhcp/common.h
  26. @@ -308,9 +308,7 @@ int udhcp_send_raw_packet(struct dhcp_pa
  27. int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
  28. uint32_t source_nip, int source_port,
  29. - uint32_t dest_nip, int dest_port,
  30. - int send_flags
  31. -) FAST_FUNC;
  32. + uint32_t dest_nip, int dest_port) FAST_FUNC;
  33. void udhcp_sp_setup(void) FAST_FUNC;
  34. void udhcp_sp_fd_set(struct pollfd *pfds, int extra_fd) FAST_FUNC;
  35. --- a/networking/udhcp/d6_dhcpc.c
  36. +++ b/networking/udhcp/d6_dhcpc.c
  37. @@ -702,15 +702,13 @@ static NOINLINE int send_d6_renew(uint32
  38. opt_ptr = add_d6_client_options(opt_ptr);
  39. bb_error_msg("sending %s", "renew");
  40. - if (server_ipv6) {
  41. + if (server_ipv6)
  42. return d6_send_kernel_packet(
  43. &packet, (opt_ptr - (uint8_t*) &packet),
  44. our_cur_ipv6, CLIENT_PORT6,
  45. server_ipv6, SERVER_PORT6,
  46. client_config.ifindex
  47. - /* TODO? send_flags: MSG_DONTROUTE (see IPv4 code for reason why) */
  48. );
  49. - }
  50. return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
  51. }
  52. --- a/networking/udhcp/dhcpc.c
  53. +++ b/networking/udhcp/dhcpc.c
  54. @@ -693,16 +693,10 @@ static int raw_bcast_from_client_config_
  55. static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server)
  56. {
  57. - if (server) {
  58. - /* Without MSG_DONTROUTE, the packet was seen routed over
  59. - * _other interface_ if server ID is bogus (example: 1.1.1.1).
  60. - */
  61. + if (server)
  62. return udhcp_send_kernel_packet(packet,
  63. ciaddr, CLIENT_PORT,
  64. - server, SERVER_PORT,
  65. - /*send_flags: "to hosts only on directly connected networks" */ MSG_DONTROUTE
  66. - );
  67. - }
  68. + server, SERVER_PORT);
  69. return raw_bcast_from_client_config_ifindex(packet, ciaddr);
  70. }
  71. --- a/networking/udhcp/dhcpd.c
  72. +++ b/networking/udhcp/dhcpd.c
  73. @@ -588,9 +588,7 @@ static void send_packet_to_relay(struct
  74. udhcp_send_kernel_packet(dhcp_pkt,
  75. server_config.server_nip, SERVER_PORT,
  76. - dhcp_pkt->gateway_nip, SERVER_PORT,
  77. - /*send_flags:*/ 0
  78. - );
  79. + dhcp_pkt->gateway_nip, SERVER_PORT);
  80. }
  81. static void send_packet(struct dhcp_packet *dhcp_pkt, int force_broadcast)
  82. --- a/networking/udhcp/packet.c
  83. +++ b/networking/udhcp/packet.c
  84. @@ -189,8 +189,7 @@ int FAST_FUNC udhcp_send_raw_packet(stru
  85. /* Let the kernel do all the work for packet generation */
  86. int FAST_FUNC udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
  87. uint32_t source_nip, int source_port,
  88. - uint32_t dest_nip, int dest_port,
  89. - int send_flags)
  90. + uint32_t dest_nip, int dest_port)
  91. {
  92. struct sockaddr_in sa;
  93. unsigned padding;
  94. @@ -227,8 +226,8 @@ int FAST_FUNC udhcp_send_kernel_packet(s
  95. padding = DHCP_OPTIONS_BUFSIZE - 1 - udhcp_end_option(dhcp_pkt->options);
  96. if (padding > DHCP_SIZE - 300)
  97. padding = DHCP_SIZE - 300;
  98. - result = send(fd, dhcp_pkt, DHCP_SIZE - padding, send_flags);
  99. - msg = "send";
  100. + result = safe_write(fd, dhcp_pkt, DHCP_SIZE - padding);
  101. + msg = "write";
  102. ret_close:
  103. close(fd);
  104. if (result < 0) {