in.c (2144431c11529d1107f4440a5fe57559fb20002c) in.c (c8ee75f2315e8267ad814dc5b4645ef205f0e0e1)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (C) 2001 WIDE Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 32 unchanged lines hidden (view full) ---

41#include <sys/sockio.h>
42#include <sys/malloc.h>
43#include <sys/priv.h>
44#include <sys/socket.h>
45#include <sys/jail.h>
46#include <sys/kernel.h>
47#include <sys/lock.h>
48#include <sys/proc.h>
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1982, 1986, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (C) 2001 WIDE Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 32 unchanged lines hidden (view full) ---

41#include <sys/sockio.h>
42#include <sys/malloc.h>
43#include <sys/priv.h>
44#include <sys/socket.h>
45#include <sys/jail.h>
46#include <sys/kernel.h>
47#include <sys/lock.h>
48#include <sys/proc.h>
49#include <sys/rmlock.h>
50#include <sys/sysctl.h>
51#include <sys/syslog.h>
52#include <sys/sx.h>
53
54#include <net/if.h>
55#include <net/if_var.h>
56#include <net/if_arp.h>
57#include <net/if_dl.h>

--- 61 unchanged lines hidden (view full) ---

119
120 return (0);
121}
122
123/*
124 * Return 1 if an internet address is for the local host and configured
125 * on one of its interfaces.
126 */
49#include <sys/sysctl.h>
50#include <sys/syslog.h>
51#include <sys/sx.h>
52
53#include <net/if.h>
54#include <net/if_var.h>
55#include <net/if_arp.h>
56#include <net/if_dl.h>

--- 61 unchanged lines hidden (view full) ---

118
119 return (0);
120}
121
122/*
123 * Return 1 if an internet address is for the local host and configured
124 * on one of its interfaces.
125 */
127int
126bool
128in_localip(struct in_addr in)
129{
127in_localip(struct in_addr in)
128{
130 struct rm_priotracker in_ifa_tracker;
131 struct in_ifaddr *ia;
132
129 struct in_ifaddr *ia;
130
133 IN_IFADDR_RLOCK(&in_ifa_tracker);
134 LIST_FOREACH(ia, INADDR_HASH(in.s_addr), ia_hash) {
135 if (IA_SIN(ia)->sin_addr.s_addr == in.s_addr) {
136 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
137 return (1);
138 }
139 }
140 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
141 return (0);
131 NET_EPOCH_ASSERT();
132
133 CK_LIST_FOREACH(ia, INADDR_HASH(in.s_addr), ia_hash)
134 if (IA_SIN(ia)->sin_addr.s_addr == in.s_addr)
135 return (true);
136
137 return (false);
142}
143
144/*
145 * Return 1 if an internet address is configured on an interface.
146 */
147int
148in_ifhasaddr(struct ifnet *ifp, struct in_addr in)
149{

--- 15 unchanged lines hidden (view full) ---

165
166/*
167 * Return a reference to the interface address which is different to
168 * the supplied one but with same IP address value.
169 */
170static struct in_ifaddr *
171in_localip_more(struct in_ifaddr *original_ia)
172{
138}
139
140/*
141 * Return 1 if an internet address is configured on an interface.
142 */
143int
144in_ifhasaddr(struct ifnet *ifp, struct in_addr in)
145{

--- 15 unchanged lines hidden (view full) ---

161
162/*
163 * Return a reference to the interface address which is different to
164 * the supplied one but with same IP address value.
165 */
166static struct in_ifaddr *
167in_localip_more(struct in_ifaddr *original_ia)
168{
173 struct rm_priotracker in_ifa_tracker;
169 struct epoch_tracker et;
174 in_addr_t original_addr = IA_SIN(original_ia)->sin_addr.s_addr;
175 uint32_t original_fib = original_ia->ia_ifa.ifa_ifp->if_fib;
176 struct in_ifaddr *ia;
177
170 in_addr_t original_addr = IA_SIN(original_ia)->sin_addr.s_addr;
171 uint32_t original_fib = original_ia->ia_ifa.ifa_ifp->if_fib;
172 struct in_ifaddr *ia;
173
178 IN_IFADDR_RLOCK(&in_ifa_tracker);
179 LIST_FOREACH(ia, INADDR_HASH(original_addr), ia_hash) {
174 NET_EPOCH_ENTER(et);
175 CK_LIST_FOREACH(ia, INADDR_HASH(original_addr), ia_hash) {
180 in_addr_t addr = IA_SIN(ia)->sin_addr.s_addr;
181 uint32_t fib = ia->ia_ifa.ifa_ifp->if_fib;
182 if (!V_rt_add_addr_allfibs && (original_fib != fib))
183 continue;
184 if ((original_ia != ia) && (original_addr == addr)) {
185 ifa_ref(&ia->ia_ifa);
176 in_addr_t addr = IA_SIN(ia)->sin_addr.s_addr;
177 uint32_t fib = ia->ia_ifa.ifa_ifp->if_fib;
178 if (!V_rt_add_addr_allfibs && (original_fib != fib))
179 continue;
180 if ((original_ia != ia) && (original_addr == addr)) {
181 ifa_ref(&ia->ia_ifa);
186 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
182 NET_EPOCH_EXIT(et);
187 return (ia);
188 }
189 }
183 return (ia);
184 }
185 }
190 IN_IFADDR_RUNLOCK(&in_ifa_tracker);
186 NET_EPOCH_EXIT(et);
191
192 return (NULL);
193}
194
195/*
196 * Tries to find first IPv4 address in the provided fib.
197 * Prefers non-loopback addresses and return loopback IFF
198 * @loopback_ok is set.

--- 296 unchanged lines hidden (view full) ---

495 }
496
497 /* if_addrhead is already referenced by ifa_alloc() */
498 IF_ADDR_WLOCK(ifp);
499 CK_STAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
500 IF_ADDR_WUNLOCK(ifp);
501
502 ifa_ref(ifa); /* in_ifaddrhead */
187
188 return (NULL);
189}
190
191/*
192 * Tries to find first IPv4 address in the provided fib.
193 * Prefers non-loopback addresses and return loopback IFF
194 * @loopback_ok is set.

--- 296 unchanged lines hidden (view full) ---

491 }
492
493 /* if_addrhead is already referenced by ifa_alloc() */
494 IF_ADDR_WLOCK(ifp);
495 CK_STAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);
496 IF_ADDR_WUNLOCK(ifp);
497
498 ifa_ref(ifa); /* in_ifaddrhead */
503 IN_IFADDR_WLOCK();
499 sx_assert(&in_control_sx, SA_XLOCKED);
504 CK_STAILQ_INSERT_TAIL(&V_in_ifaddrhead, ia, ia_link);
500 CK_STAILQ_INSERT_TAIL(&V_in_ifaddrhead, ia, ia_link);
505 LIST_INSERT_HEAD(INADDR_HASH(ia->ia_addr.sin_addr.s_addr), ia, ia_hash);
506 IN_IFADDR_WUNLOCK();
501 CK_LIST_INSERT_HEAD(INADDR_HASH(ia->ia_addr.sin_addr.s_addr), ia,
502 ia_hash);
507
508 /*
509 * Give the interface a chance to initialize
510 * if this is its first address,
511 * and to validate the address if necessary.
512 */
513 if (ifp->if_ioctl != NULL) {
514 error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);

--- 55 unchanged lines hidden (view full) ---

570 if (ia->ia_ifa.ifa_carp)
571 (*carp_detach_p)(&ia->ia_ifa, false);
572
573 IF_ADDR_WLOCK(ifp);
574 CK_STAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifaddr, ifa_link);
575 IF_ADDR_WUNLOCK(ifp);
576 ifa_free(&ia->ia_ifa); /* if_addrhead */
577
503
504 /*
505 * Give the interface a chance to initialize
506 * if this is its first address,
507 * and to validate the address if necessary.
508 */
509 if (ifp->if_ioctl != NULL) {
510 error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia);

--- 55 unchanged lines hidden (view full) ---

566 if (ia->ia_ifa.ifa_carp)
567 (*carp_detach_p)(&ia->ia_ifa, false);
568
569 IF_ADDR_WLOCK(ifp);
570 CK_STAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifaddr, ifa_link);
571 IF_ADDR_WUNLOCK(ifp);
572 ifa_free(&ia->ia_ifa); /* if_addrhead */
573
578 IN_IFADDR_WLOCK();
574 sx_assert(&in_control_sx, SA_XLOCKED);
579 CK_STAILQ_REMOVE(&V_in_ifaddrhead, ia, in_ifaddr, ia_link);
575 CK_STAILQ_REMOVE(&V_in_ifaddrhead, ia, in_ifaddr, ia_link);
580 LIST_REMOVE(ia, ia_hash);
581 IN_IFADDR_WUNLOCK();
576 CK_LIST_REMOVE(ia, ia_hash);
582 ifa_free(&ia->ia_ifa); /* in_ifaddrhead */
583
584 return (error);
585}
586
587static int
588in_difaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td)
589{

--- 44 unchanged lines hidden (view full) ---

634 IF_ADDR_WUNLOCK(ifp);
635 return (EADDRNOTAVAIL);
636 }
637
638 CK_STAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifaddr, ifa_link);
639 IF_ADDR_WUNLOCK(ifp);
640 ifa_free(&ia->ia_ifa); /* if_addrhead */
641
577 ifa_free(&ia->ia_ifa); /* in_ifaddrhead */
578
579 return (error);
580}
581
582static int
583in_difaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td)
584{

--- 44 unchanged lines hidden (view full) ---

629 IF_ADDR_WUNLOCK(ifp);
630 return (EADDRNOTAVAIL);
631 }
632
633 CK_STAILQ_REMOVE(&ifp->if_addrhead, &ia->ia_ifa, ifaddr, ifa_link);
634 IF_ADDR_WUNLOCK(ifp);
635 ifa_free(&ia->ia_ifa); /* if_addrhead */
636
642 IN_IFADDR_WLOCK();
637 sx_assert(&in_control_sx, SA_XLOCKED);
643 CK_STAILQ_REMOVE(&V_in_ifaddrhead, ia, in_ifaddr, ia_link);
638 CK_STAILQ_REMOVE(&V_in_ifaddrhead, ia, in_ifaddr, ia_link);
644 LIST_REMOVE(ia, ia_hash);
645 IN_IFADDR_WUNLOCK();
639 CK_LIST_REMOVE(ia, ia_hash);
646
647 /*
648 * in_scrubprefix() kills the interface route.
649 */
650 in_scrubprefix(ia, LLE_STATIC);
651
652 /*
653 * in_ifadown gets rid of all the rest of

--- 1053 unchanged lines hidden ---
640
641 /*
642 * in_scrubprefix() kills the interface route.
643 */
644 in_scrubprefix(ia, LLE_STATIC);
645
646 /*
647 * in_ifadown gets rid of all the rest of

--- 1053 unchanged lines hidden ---