@@ -108,6 +108,7 @@ static inline struct in_addr *if_get_addr(struct net_if *iface)
108
108
}
109
109
110
110
static inline struct net_buf * prepare_arp (struct net_if * iface ,
111
+ struct in_addr * next_addr ,
111
112
struct arp_entry * entry ,
112
113
struct net_buf * pending )
113
114
{
@@ -143,7 +144,7 @@ static inline struct net_buf *prepare_arp(struct net_if *iface,
143
144
entry -> pending = net_buf_ref (pending );
144
145
entry -> iface = net_nbuf_iface (buf );
145
146
146
- net_ipaddr_copy (& entry -> ip , & NET_IPV4_BUF ( pending ) -> dst );
147
+ net_ipaddr_copy (& entry -> ip , next_addr );
147
148
148
149
memcpy (& eth -> src .addr ,
149
150
net_if_get_link_addr (entry -> iface )-> addr ,
@@ -165,12 +166,7 @@ static inline struct net_buf *prepare_arp(struct net_if *iface,
165
166
166
167
memset (& hdr -> dst_hwaddr .addr , 0x00 , sizeof (struct net_eth_addr ));
167
168
168
- /* Is the destination in local network */
169
- if (!net_if_ipv4_addr_mask_cmp (iface , & NET_IPV4_BUF (pending )-> dst )) {
170
- net_ipaddr_copy (& hdr -> dst_ipaddr , & iface -> ipv4 .gw );
171
- } else {
172
- net_ipaddr_copy (& hdr -> dst_ipaddr , & NET_IPV4_BUF (pending )-> dst );
173
- }
169
+ net_ipaddr_copy (& hdr -> dst_ipaddr , next_addr );
174
170
175
171
memcpy (hdr -> src_hwaddr .addr , eth -> src .addr ,
176
172
sizeof (struct net_eth_addr ));
@@ -203,6 +199,7 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
203
199
struct arp_entry * entry , * free_entry = NULL , * non_pending = NULL ;
204
200
struct net_linkaddr * ll ;
205
201
struct net_eth_hdr * hdr ;
202
+ struct in_addr * addr ;
206
203
207
204
if (!buf || !buf -> frags ) {
208
205
return NULL ;
@@ -239,12 +236,21 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
239
236
240
237
hdr = (struct net_eth_hdr * )net_nbuf_ll (buf );
241
238
239
+ /* Is the destination in the local network, if not route via
240
+ * the gateway address.
241
+ */
242
+ if (!net_if_ipv4_addr_mask_cmp (net_nbuf_iface (buf ),
243
+ & NET_IPV4_BUF (buf )-> dst )) {
244
+ addr = & net_nbuf_iface (buf )-> ipv4 .gw ;
245
+ } else {
246
+ addr = & NET_IPV4_BUF (buf )-> dst ;
247
+ }
248
+
242
249
/* If the destination address is already known, we do not need
243
250
* to send any ARP packet.
244
251
*/
245
252
entry = find_entry (net_nbuf_iface (buf ),
246
- & NET_IPV4_BUF (buf )-> dst ,
247
- & free_entry , & non_pending );
253
+ addr , & free_entry , & non_pending );
248
254
if (!entry ) {
249
255
if (!free_entry ) {
250
256
/* So all the slots are occupied, use the first
@@ -259,7 +265,7 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
259
265
struct net_buf * req ;
260
266
261
267
req = prepare_arp (net_nbuf_iface (buf ),
262
- NULL , buf );
268
+ addr , NULL , buf );
263
269
NET_DBG ("Resending ARP %p" , req );
264
270
265
271
net_nbuf_unref (buf );
@@ -270,7 +276,7 @@ struct net_buf *net_arp_prepare(struct net_buf *buf)
270
276
free_entry = non_pending ;
271
277
}
272
278
273
- return prepare_arp (net_nbuf_iface (buf ), free_entry , buf );
279
+ return prepare_arp (net_nbuf_iface (buf ), addr , free_entry , buf );
274
280
}
275
281
276
282
ll = net_if_get_link_addr (entry -> iface );
0 commit comments