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