1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

Provide ABI compatibility shim to enable configuring of addresses

with ifconfig(8) prior to r228571.

Requested by:	brooks
This commit is contained in:
Gleb Smirnoff 2011-12-21 12:39:08 +00:00
parent b133becced
commit 7121247312
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=228768
5 changed files with 47 additions and 5 deletions

View File

@ -362,6 +362,14 @@ struct ifaliasreq {
int ifra_vhid;
};
/* Compat with pre-10.x */
struct oifaliasreq {
char ifra_name[IFNAMSIZ];
struct sockaddr ifra_addr;
struct sockaddr ifra_broadaddr;
struct sockaddr ifra_mask;
};
struct ifmediareq {
char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
int ifm_current; /* current media options */

View File

@ -223,6 +223,14 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
struct sockaddr_in oldaddr;
int error, hostIsNew, iaIsNew, maskIsNew;
int iaIsFirst;
u_long ocmd = cmd;
/*
* Pre-10.x compat: OSIOCAIFADDR passes a shorter
* struct in_aliasreq, without ifra_vhid.
*/
if (cmd == OSIOCAIFADDR)
cmd = SIOCAIFADDR;
ia = NULL;
iaIsFirst = 0;
@ -253,10 +261,18 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
sizeof(struct sockaddr_in) ||
ifra->ifra_broadaddr.sin_family != AF_INET))
return (EINVAL);
#if 0
/*
* ifconfig(8) in pre-10.x doesn't set sin_family for the
* mask. The code is disabled for the 10.x timeline, to
* make SIOCAIFADDR compatible with 9.x ifconfig(8).
* The code should be enabled in 11.x
*/
if (ifra->ifra_mask.sin_len != 0 &&
(ifra->ifra_mask.sin_len != sizeof(struct sockaddr_in) ||
ifra->ifra_mask.sin_family != AF_INET))
return (EINVAL);
#endif
break;
case SIOCSIFADDR:
case SIOCSIFBRDADDR:
@ -564,7 +580,7 @@ in_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp,
}
if (hostIsNew || maskIsNew)
error = in_ifinit(ifp, ia, &ifra->ifra_addr, 0,
maskIsNew, ifra->ifra_vhid);
maskIsNew, (ocmd == cmd ? ifra->ifra_vhid : 0));
if (error != 0 && iaIsNew)
break;

View File

@ -275,6 +275,13 @@ in6_control(struct socket *so, u_long cmd, caddr_t data,
struct sockaddr_in6 *sa6;
int carp_attached = 0;
int error;
u_long ocmd = cmd;
/*
* Compat to make pre-10.x ifconfig(8) operable.
*/
if (cmd == OSIOCAIFADDR_IN6)
cmd = SIOCAIFADDR_IN6;
switch (cmd) {
case SIOCGETSGCNT_IN6:
@ -654,7 +661,7 @@ in6_control(struct socket *so, u_long cmd, caddr_t data,
break;
}
if (ifra->ifra_vhid > 0) {
if (cmd == ocmd && ifra->ifra_vhid > 0) {
if (carp_attach_p != NULL)
error = (*carp_attach_p)(&ia->ia_ifa,
ifra->ifra_vhid);

View File

@ -290,6 +290,16 @@ struct in6_aliasreq {
int ifra_vhid;
};
/* pre-10.x compat */
struct oin6_aliasreq {
char ifra_name[IFNAMSIZ];
struct sockaddr_in6 ifra_addr;
struct sockaddr_in6 ifra_dstaddr;
struct sockaddr_in6 ifra_prefixmask;
int ifra_flags;
struct in6_addrlifetime ifra_lifetime;
};
/* prefix type macro */
#define IN6_PREFIX_ND 1
#define IN6_PREFIX_RR 2
@ -410,7 +420,8 @@ struct in6_rrenumreq {
#define SIOCGIFNETMASK_IN6 _IOWR('i', 37, struct in6_ifreq)
#define SIOCDIFADDR_IN6 _IOW('i', 25, struct in6_ifreq)
#define SIOCAIFADDR_IN6 _IOW('i', 26, struct in6_aliasreq)
#define OSIOCAIFADDR_IN6 _IOW('i', 26, struct oin6_aliasreq)
#define SIOCAIFADDR_IN6 _IOW('i', 27, struct in6_aliasreq)
#define SIOCSIFPHYADDR_IN6 _IOW('i', 70, struct in6_aliasreq)
#define SIOCGIFPSRCADDR_IN6 _IOWR('i', 71, struct in6_ifreq)

View File

@ -68,8 +68,7 @@
#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
#define OSIOCAIFADDR _IOW('i', 26, struct oifaliasreq)/* add/chg IF alias */
#define SIOCALIFADDR _IOW('i', 27, struct if_laddrreq) /* add IF addr */
#define SIOCGLIFADDR _IOWR('i', 28, struct if_laddrreq) /* get IF addr */
#define SIOCDLIFADDR _IOW('i', 29, struct if_laddrreq) /* delete IF addr */
@ -81,6 +80,7 @@
#define SIOCSIFNAME _IOW('i', 40, struct ifreq) /* set IF name */
#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 SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */