| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: if_arp.c,v 1.158 2014/06/03 01:24:32 ozaki-r Exp $ */ | | 1 | /* $NetBSD: if_arp.c,v 1.158.2.1 2015/11/06 00:46:50 riz Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Public Access Networks Corporation ("Panix"). It was developed under | | 8 | * by Public Access Networks Corporation ("Panix"). It was developed under |
9 | * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon. | | 9 | * contract to Panix by Eric Haszlakiewicz and Thor Lancelot Simon. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -58,27 +58,27 @@ | | | @@ -58,27 +58,27 @@ |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
59 | * SUCH DAMAGE. | | 59 | * SUCH DAMAGE. |
60 | * | | 60 | * |
61 | * @(#)if_ether.c 8.2 (Berkeley) 9/26/94 | | 61 | * @(#)if_ether.c 8.2 (Berkeley) 9/26/94 |
62 | */ | | 62 | */ |
63 | | | 63 | |
64 | /* | | 64 | /* |
65 | * Ethernet address resolution protocol. | | 65 | * Ethernet address resolution protocol. |
66 | * TODO: | | 66 | * TODO: |
67 | * add "inuse/lock" bit (or ref. count) along with valid bit | | 67 | * add "inuse/lock" bit (or ref. count) along with valid bit |
68 | */ | | 68 | */ |
69 | | | 69 | |
70 | #include <sys/cdefs.h> | | 70 | #include <sys/cdefs.h> |
71 | __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.158 2014/06/03 01:24:32 ozaki-r Exp $"); | | 71 | __KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.158.2.1 2015/11/06 00:46:50 riz Exp $"); |
72 | | | 72 | |
73 | #include "opt_ddb.h" | | 73 | #include "opt_ddb.h" |
74 | #include "opt_inet.h" | | 74 | #include "opt_inet.h" |
75 | | | 75 | |
76 | #ifdef INET | | 76 | #ifdef INET |
77 | | | 77 | |
78 | #include "bridge.h" | | 78 | #include "bridge.h" |
79 | | | 79 | |
80 | #include <sys/param.h> | | 80 | #include <sys/param.h> |
81 | #include <sys/systm.h> | | 81 | #include <sys/systm.h> |
82 | #include <sys/callout.h> | | 82 | #include <sys/callout.h> |
83 | #include <sys/malloc.h> | | 83 | #include <sys/malloc.h> |
84 | #include <sys/mbuf.h> | | 84 | #include <sys/mbuf.h> |
| @@ -184,26 +184,27 @@ struct ifnet *myip_ifp = NULL; | | | @@ -184,26 +184,27 @@ struct ifnet *myip_ifp = NULL; |
184 | | | 184 | |
185 | #ifdef DDB | | 185 | #ifdef DDB |
186 | static void db_print_sa(const struct sockaddr *); | | 186 | static void db_print_sa(const struct sockaddr *); |
187 | static void db_print_ifa(struct ifaddr *); | | 187 | static void db_print_ifa(struct ifaddr *); |
188 | static void db_print_llinfo(void *); | | 188 | static void db_print_llinfo(void *); |
189 | static int db_show_rtentry(struct rtentry *, void *); | | 189 | static int db_show_rtentry(struct rtentry *, void *); |
190 | #endif | | 190 | #endif |
191 | | | 191 | |
192 | static int arp_drainwanted; | | 192 | static int arp_drainwanted; |
193 | | | 193 | |
194 | static int log_movements = 1; | | 194 | static int log_movements = 1; |
195 | static int log_permanent_modify = 1; | | 195 | static int log_permanent_modify = 1; |
196 | static int log_wrong_iface = 1; | | 196 | static int log_wrong_iface = 1; |
| | | 197 | static int log_unknown_network = 1; |
197 | | | 198 | |
198 | /* | | 199 | /* |
199 | * this should be elsewhere. | | 200 | * this should be elsewhere. |
200 | */ | | 201 | */ |
201 | | | 202 | |
202 | static char * | | 203 | static char * |
203 | lla_snprintf(u_int8_t *, int); | | 204 | lla_snprintf(u_int8_t *, int); |
204 | | | 205 | |
205 | static char * | | 206 | static char * |
206 | lla_snprintf(u_int8_t *adrp, int len) | | 207 | lla_snprintf(u_int8_t *adrp, int len) |
207 | { | | 208 | { |
208 | #define NUMBUFS 3 | | 209 | #define NUMBUFS 3 |
209 | static char buf[NUMBUFS][16*3]; | | 210 | static char buf[NUMBUFS][16*3]; |
| @@ -1295,37 +1296,40 @@ arplookup1(struct mbuf *m, const struct | | | @@ -1295,37 +1296,40 @@ arplookup1(struct mbuf *m, const struct |
1295 | rt->rt_refcnt--; | | 1296 | rt->rt_refcnt--; |
1296 | } else | | 1297 | } else |
1297 | rt = rt0; | | 1298 | rt = rt0; |
1298 | | | 1299 | |
1299 | #define IS_LLINFO(__rt) \ | | 1300 | #define IS_LLINFO(__rt) \ |
1300 | (((__rt)->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) == RTF_LLINFO && \ | | 1301 | (((__rt)->rt_flags & (RTF_GATEWAY | RTF_LLINFO)) == RTF_LLINFO && \ |
1301 | (__rt)->rt_gateway->sa_family == AF_LINK) | | 1302 | (__rt)->rt_gateway->sa_family == AF_LINK) |
1302 | | | 1303 | |
1303 | | | 1304 | |
1304 | if (IS_LLINFO(rt)) | | 1305 | if (IS_LLINFO(rt)) |
1305 | return (struct llinfo_arp *)rt->rt_llinfo; | | 1306 | return (struct llinfo_arp *)rt->rt_llinfo; |
1306 | | | 1307 | |
1307 | if (create) { | | 1308 | if (create) { |
1308 | if (rt->rt_flags & RTF_GATEWAY) | | 1309 | if (rt->rt_flags & RTF_GATEWAY) { |
1309 | why = "host is not on local network"; | | 1310 | if (log_unknown_network) |
1310 | else if ((rt->rt_flags & RTF_LLINFO) == 0) { | | 1311 | why = "host is not on local network"; |
| | | 1312 | } else if ((rt->rt_flags & RTF_LLINFO) == 0) { |
1311 | ARP_STATINC(ARP_STAT_ALLOCFAIL); | | 1313 | ARP_STATINC(ARP_STAT_ALLOCFAIL); |
1312 | why = "could not allocate llinfo"; | | 1314 | why = "could not allocate llinfo"; |
1313 | } else | | 1315 | } else |
1314 | why = "gateway route is not ours"; | | 1316 | why = "gateway route is not ours"; |
1315 | log(LOG_DEBUG, "arplookup: unable to enter address" | | 1317 | if (why) { |
1316 | " for %s@%s on %s (%s)\n", | | 1318 | log(LOG_DEBUG, "arplookup: unable to enter address" |
1317 | in_fmtaddr(*addr), lla_snprintf(ar_sha(ah), ah->ar_hln), | | 1319 | " for %s@%s on %s (%s)\n", in_fmtaddr(*addr), |
1318 | (ifp) ? ifp->if_xname : "null", why); | | 1320 | lla_snprintf(ar_sha(ah), ah->ar_hln), |
| | | 1321 | (ifp) ? ifp->if_xname : "null", why); |
| | | 1322 | } |
1319 | if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_CLONED) != 0) { | | 1323 | if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_CLONED) != 0) { |
1320 | rtrequest(RTM_DELETE, rt_getkey(rt), | | 1324 | rtrequest(RTM_DELETE, rt_getkey(rt), |
1321 | rt->rt_gateway, rt_mask(rt), rt->rt_flags, NULL); | | 1325 | rt->rt_gateway, rt_mask(rt), rt->rt_flags, NULL); |
1322 | } | | 1326 | } |
1323 | } | | 1327 | } |
1324 | return NULL; | | 1328 | return NULL; |
1325 | } | | 1329 | } |
1326 | | | 1330 | |
1327 | int | | 1331 | int |
1328 | arpioctl(u_long cmd, void *data) | | 1332 | arpioctl(u_long cmd, void *data) |
1329 | { | | 1333 | { |
1330 | | | 1334 | |
1331 | return EOPNOTSUPP; | | 1335 | return EOPNOTSUPP; |
| @@ -1694,16 +1698,23 @@ sysctl_net_inet_arp_setup(struct sysctll | | | @@ -1694,16 +1698,23 @@ sysctl_net_inet_arp_setup(struct sysctll |
1694 | CTLTYPE_INT, "log_permanent_modify", | | 1698 | CTLTYPE_INT, "log_permanent_modify", |
1695 | SYSCTL_DESCR("log ARP replies from MACs different than" | | 1699 | SYSCTL_DESCR("log ARP replies from MACs different than" |
1696 | " the one in the permanent arp entry"), | | 1700 | " the one in the permanent arp entry"), |
1697 | NULL, 0, &log_permanent_modify, 0, | | 1701 | NULL, 0, &log_permanent_modify, 0, |
1698 | CTL_NET,PF_INET, node->sysctl_num, CTL_CREATE, CTL_EOL); | | 1702 | CTL_NET,PF_INET, node->sysctl_num, CTL_CREATE, CTL_EOL); |
1699 | | | 1703 | |
1700 | sysctl_createv(clog, 0, NULL, NULL, | | 1704 | sysctl_createv(clog, 0, NULL, NULL, |
1701 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, | | 1705 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
1702 | CTLTYPE_INT, "log_wrong_iface", | | 1706 | CTLTYPE_INT, "log_wrong_iface", |
1703 | SYSCTL_DESCR("log ARP packets arriving on the wrong" | | 1707 | SYSCTL_DESCR("log ARP packets arriving on the wrong" |
1704 | " interface"), | | 1708 | " interface"), |
1705 | NULL, 0, &log_wrong_iface, 0, | | 1709 | NULL, 0, &log_wrong_iface, 0, |
1706 | CTL_NET,PF_INET, node->sysctl_num, CTL_CREATE, CTL_EOL); | | 1710 | CTL_NET,PF_INET, node->sysctl_num, CTL_CREATE, CTL_EOL); |
| | | 1711 | |
| | | 1712 | sysctl_createv(clog, 0, NULL, NULL, |
| | | 1713 | CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
| | | 1714 | CTLTYPE_INT, "log_unknown_network", |
| | | 1715 | SYSCTL_DESCR("log ARP packets from non-local network"), |
| | | 1716 | NULL, 0, &log_unknown_network, 0, |
| | | 1717 | CTL_NET,PF_INET, node->sysctl_num, CTL_CREATE, CTL_EOL); |
1707 | } | | 1718 | } |
1708 | | | 1719 | |
1709 | #endif /* INET */ | | 1720 | #endif /* INET */ |