svn commit: r367554 - in stable/12: share/man/man4 sys/netinet sys/sys
Andrey V. Elsukov
ae at FreeBSD.org
Tue Nov 10 12:46:00 UTC 2020
Author: ae
Date: Tue Nov 10 12:45:59 2020
New Revision: 367554
URL: https://svnweb.freebsd.org/changeset/base/367554
Log:
MFC r366695:
Implement SIOCGIFALIAS.
It is lightweight way to check if an IPv4 address exists.
Submitted by: Roy Marples
Differential Revision: https://reviews.freebsd.org/D26636
Modified:
stable/12/share/man/man4/netintro.4
stable/12/sys/netinet/in.c
stable/12/sys/sys/sockio.h
Directory Properties:
stable/12/ (props changed)
Modified: stable/12/share/man/man4/netintro.4
==============================================================================
--- stable/12/share/man/man4/netintro.4 Tue Nov 10 12:13:18 2020 (r367553)
+++ stable/12/share/man/man4/netintro.4 Tue Nov 10 12:45:59 2020 (r367554)
@@ -28,7 +28,7 @@
.\" @(#)netintro.4 8.2 (Berkeley) 11/30/93
.\" $FreeBSD$
.\"
-.Dd January 26, 2012
+.Dd October 14, 2020
.Dt NETINTRO 4
.Os
.Sh NAME
@@ -349,6 +349,13 @@ multiple masks or destination addresses, and also adop
convention that specification of the default address means
to delete the first address for the interface belonging to
the address family in which the original socket was opened.
+.It Dv SIOCGIFALIAS
+This request provides means to get additional addresses
+together with netmask and broadcast/destination from an
+interface.
+It also uses the
+.Vt ifaliasreq
+structure.
.It Dv SIOCGIFCONF
Get interface configuration list.
This request takes an
Modified: stable/12/sys/netinet/in.c
==============================================================================
--- stable/12/sys/netinet/in.c Tue Nov 10 12:13:18 2020 (r367553)
+++ stable/12/sys/netinet/in.c Tue Nov 10 12:45:59 2020 (r367554)
@@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$");
static int in_aifaddr_ioctl(u_long, caddr_t, struct ifnet *, struct thread *);
static int in_difaddr_ioctl(u_long, caddr_t, struct ifnet *, struct thread *);
+static int in_gifaddr_ioctl(u_long, caddr_t, struct ifnet *, struct thread *);
static void in_socktrim(struct sockaddr_in *);
static void in_purgemaddrs(struct ifnet *);
@@ -240,6 +241,11 @@ in_control(struct socket *so, u_long cmd, caddr_t data
case SIOCGIFDSTADDR:
case SIOCGIFNETMASK:
break;
+ case SIOCGIFALIAS:
+ sx_xlock(&in_control_sx);
+ error = in_gifaddr_ioctl(cmd, data, ifp, td);
+ sx_xunlock(&in_control_sx);
+ return (error);
case SIOCDIFADDR:
sx_xlock(&in_control_sx);
error = in_difaddr_ioctl(cmd, data, ifp, td);
@@ -648,6 +654,60 @@ in_difaddr_ioctl(u_long cmd, caddr_t data, struct ifne
IFADDR_EVENT_DEL);
ifa_free(&ia->ia_ifa); /* in_ifaddrhead */
+ return (0);
+}
+
+static int
+in_gifaddr_ioctl(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td)
+{
+ struct in_aliasreq *ifra = (struct in_aliasreq *)data;
+ const struct sockaddr_in *addr = &ifra->ifra_addr;
+ struct epoch_tracker et;
+ struct ifaddr *ifa;
+ struct in_ifaddr *ia;
+
+ /*
+ * ifra_addr must be present and be of INET family.
+ */
+ if (addr->sin_len != sizeof(struct sockaddr_in) ||
+ addr->sin_family != AF_INET)
+ return (EINVAL);
+
+ /*
+ * See whether address exist.
+ */
+ ia = NULL;
+ NET_EPOCH_ENTER_ET(et);
+ CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
+ struct in_ifaddr *it;
+
+ if (ifa->ifa_addr->sa_family != AF_INET)
+ continue;
+
+ it = (struct in_ifaddr *)ifa;
+ if (it->ia_addr.sin_addr.s_addr == addr->sin_addr.s_addr &&
+ prison_check_ip4(td->td_ucred, &addr->sin_addr) == 0) {
+ ia = it;
+ break;
+ }
+ }
+ if (ia == NULL) {
+ NET_EPOCH_EXIT_ET(et);
+ return (EADDRNOTAVAIL);
+ }
+
+ ifra->ifra_mask = ia->ia_sockmask;
+ if ((ifp->if_flags & IFF_POINTOPOINT) &&
+ ia->ia_dstaddr.sin_family == AF_INET)
+ ifra->ifra_dstaddr = ia->ia_dstaddr;
+ else if ((ifp->if_flags & IFF_BROADCAST) &&
+ ia->ia_broadaddr.sin_family == AF_INET)
+ ifra->ifra_broadaddr = ia->ia_broadaddr;
+ else
+ memset(&ifra->ifra_broadaddr, 0,
+ sizeof(ifra->ifra_broadaddr));
+
+ NET_EPOCH_EXIT_ET(et);
return (0);
}
Modified: stable/12/sys/sys/sockio.h
==============================================================================
--- stable/12/sys/sys/sockio.h Tue Nov 10 12:13:18 2020 (r367553)
+++ stable/12/sys/sys/sockio.h Tue Nov 10 12:45:59 2020 (r367554)
@@ -83,6 +83,7 @@
#define SIOCSIFDESCR _IOW('i', 41, struct ifreq) /* set ifnet descr */
#define SIOCGIFDESCR _IOWR('i', 42, struct ifreq) /* get ifnet descr */
#define SIOCAIFADDR _IOW('i', 43, struct ifaliasreq)/* add/chg IF alias */
+#define SIOCGIFALIAS _IOWR('i', 45, struct ifaliasreq)/* get IF alias */
#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
More information about the svn-src-stable-12
mailing list