hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/ipv4/arp.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* linux/net/ipv4/arp.c
23 *
34 * Copyright (C) 1994 by Florian La Roche
....@@ -6,11 +7,6 @@
67 * which is used to convert IP addresses (or in the future maybe other
78 * high-level addresses) into a low-level hardware address (like an Ethernet
89 * address).
9
- *
10
- * This program is free software; you can redistribute it and/or
11
- * modify it under the terms of the GNU General Public License
12
- * as published by the Free Software Foundation; either version
13
- * 2 of the License, or (at your option) any later version.
1410 *
1511 * Fixes:
1612 * Alan Cox : Removed the Ethernet assumptions in
....@@ -129,6 +125,7 @@
129125 static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb);
130126 static void arp_error_report(struct neighbour *neigh, struct sk_buff *skb);
131127 static void parp_redo(struct sk_buff *skb);
128
+static int arp_is_multicast(const void *pkey);
132129
133130 static const struct neigh_ops arp_generic_ops = {
134131 .family = AF_INET,
....@@ -160,6 +157,7 @@
160157 .key_eq = arp_key_eq,
161158 .constructor = arp_constructor,
162159 .proxy_redo = parp_redo,
160
+ .is_multicast = arp_is_multicast,
163161 .id = "arp_cache",
164162 .parms = {
165163 .tbl = &arp_tbl,
....@@ -932,6 +930,10 @@
932930 arp_process(dev_net(skb->dev), NULL, skb);
933931 }
934932
933
+static int arp_is_multicast(const void *pkey)
934
+{
935
+ return ipv4_is_multicast(*((__be32 *)pkey));
936
+}
935937
936938 /*
937939 * Receive an arp request from the device layer.
....@@ -1114,13 +1116,18 @@
11141116 return err;
11151117 }
11161118
1117
-static int arp_invalidate(struct net_device *dev, __be32 ip)
1119
+int arp_invalidate(struct net_device *dev, __be32 ip, bool force)
11181120 {
11191121 struct neighbour *neigh = neigh_lookup(&arp_tbl, &ip, dev);
11201122 int err = -ENXIO;
11211123 struct neigh_table *tbl = &arp_tbl;
11221124
11231125 if (neigh) {
1126
+ if ((neigh->nud_state & NUD_VALID) && !force) {
1127
+ neigh_release(neigh);
1128
+ return 0;
1129
+ }
1130
+
11241131 if (neigh->nud_state & ~NUD_NOARP)
11251132 err = neigh_update(neigh, NULL, NUD_FAILED,
11261133 NEIGH_UPDATE_F_OVERRIDE|
....@@ -1167,7 +1174,7 @@
11671174 if (!dev)
11681175 return -EINVAL;
11691176 }
1170
- return arp_invalidate(dev, ip);
1177
+ return arp_invalidate(dev, ip, true);
11711178 }
11721179
11731180 /*
....@@ -1185,7 +1192,7 @@
11851192 case SIOCSARP:
11861193 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
11871194 return -EPERM;
1188
- /* fall through */
1195
+ fallthrough;
11891196 case SIOCGARP:
11901197 err = copy_from_user(&r, arg, sizeof(struct arpreq));
11911198 if (err)
....@@ -1255,6 +1262,8 @@
12551262 change_info = ptr;
12561263 if (change_info->flags_changed & IFF_NOARP)
12571264 neigh_changeaddr(&arp_tbl, dev);
1265
+ if (!netif_carrier_ok(dev))
1266
+ neigh_carrier_down(&arp_tbl, dev);
12581267 break;
12591268 default:
12601269 break;