mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
drivers: Move driver_wired_set_ifflags() to a common file
This continues refactoring of the common parts of wired drivers code into a shared file, so that they can be reused by other drivers. Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
This commit is contained in:
parent
567b7d4ec2
commit
d718a5d975
@ -99,31 +99,6 @@ static int macsec_qca_get_capa(void *priv, struct wpa_driver_capa *capa)
|
||||
}
|
||||
|
||||
|
||||
static int macsec_qca_set_ifflags(const char *ifname, int flags)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int s;
|
||||
|
||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_memset(&ifr, 0, sizeof(ifr));
|
||||
os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
||||
ifr.ifr_flags = flags & 0xffff;
|
||||
if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
|
||||
wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
static int macsec_qca_get_ifstatus(const char *ifname, int *status)
|
||||
{
|
||||
@ -229,7 +204,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
||||
|
||||
if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
||||
!(flags & IFF_UP) &&
|
||||
macsec_qca_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
||||
driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
||||
drv->common.iff_up = 1;
|
||||
}
|
||||
|
||||
@ -254,7 +229,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"%s: Interface is already configured for multicast",
|
||||
__func__);
|
||||
} else if (macsec_qca_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
||||
} else if (driver_wired_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Failed to enable allmulti",
|
||||
__func__);
|
||||
os_free(drv);
|
||||
@ -301,7 +276,7 @@ static void macsec_qca_deinit(void *priv)
|
||||
|
||||
if (drv->common.iff_allmulti &&
|
||||
(driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
|
||||
macsec_qca_set_ifflags(drv->common.ifname,
|
||||
driver_wired_set_ifflags(drv->common.ifname,
|
||||
flags & ~IFF_ALLMULTI) < 0)) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
|
||||
__func__);
|
||||
@ -310,7 +285,7 @@ static void macsec_qca_deinit(void *priv)
|
||||
if (drv->common.iff_up &&
|
||||
driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
|
||||
(flags & IFF_UP) &&
|
||||
macsec_qca_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
|
||||
driver_wired_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
|
||||
__func__);
|
||||
}
|
||||
|
@ -390,31 +390,6 @@ static int wpa_driver_wired_get_capa(void *priv, struct wpa_driver_capa *capa)
|
||||
}
|
||||
|
||||
|
||||
static int wpa_driver_wired_set_ifflags(const char *ifname, int flags)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int s;
|
||||
|
||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_memset(&ifr, 0, sizeof(ifr));
|
||||
os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
||||
ifr.ifr_flags = flags & 0xffff;
|
||||
if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
|
||||
wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
static int wpa_driver_wired_get_ifstatus(const char *ifname, int *status)
|
||||
{
|
||||
@ -465,7 +440,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
||||
|
||||
if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
||||
!(flags & IFF_UP) &&
|
||||
wpa_driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
||||
driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
||||
drv->common.iff_up = 1;
|
||||
}
|
||||
|
||||
@ -487,8 +462,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
||||
} else if (flags & IFF_ALLMULTI) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Interface is already configured "
|
||||
"for multicast", __func__);
|
||||
} else if (wpa_driver_wired_set_ifflags(ifname,
|
||||
flags | IFF_ALLMULTI) < 0) {
|
||||
} else if (driver_wired_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Failed to enable allmulti",
|
||||
__func__);
|
||||
os_free(drv);
|
||||
@ -534,7 +508,7 @@ static void wpa_driver_wired_deinit(void *priv)
|
||||
|
||||
if (drv->common.iff_allmulti &&
|
||||
(driver_wired_get_ifflags(drv->common.ifname, &flags) < 0 ||
|
||||
wpa_driver_wired_set_ifflags(drv->common.ifname,
|
||||
driver_wired_set_ifflags(drv->common.ifname,
|
||||
flags & ~IFF_ALLMULTI) < 0)) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Failed to disable allmulti mode",
|
||||
__func__);
|
||||
@ -543,8 +517,7 @@ static void wpa_driver_wired_deinit(void *priv)
|
||||
if (drv->common.iff_up &&
|
||||
driver_wired_get_ifflags(drv->common.ifname, &flags) == 0 &&
|
||||
(flags & IFF_UP) &&
|
||||
wpa_driver_wired_set_ifflags(drv->common.ifname,
|
||||
flags & ~IFF_UP) < 0) {
|
||||
driver_wired_set_ifflags(drv->common.ifname, flags & ~IFF_UP) < 0) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Failed to set the interface down",
|
||||
__func__);
|
||||
}
|
||||
|
@ -55,6 +55,31 @@ int driver_wired_get_ifflags(const char *ifname, int *flags)
|
||||
}
|
||||
|
||||
|
||||
int driver_wired_set_ifflags(const char *ifname, int flags)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
int s;
|
||||
|
||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_memset(&ifr, 0, sizeof(ifr));
|
||||
os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
|
||||
ifr.ifr_flags = flags & 0xffff;
|
||||
if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
|
||||
wpa_printf(MSG_ERROR, "ioctl[SIOCSIFFLAGS]: %s",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int driver_wired_multi(const char *ifname, const u8 *addr, int add)
|
||||
{
|
||||
struct ifreq ifr;
|
||||
|
@ -23,6 +23,7 @@ static const u8 pae_group_addr[ETH_ALEN] =
|
||||
{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
|
||||
|
||||
int driver_wired_get_ifflags(const char *ifname, int *flags);
|
||||
int driver_wired_set_ifflags(const char *ifname, int flags);
|
||||
int driver_wired_multi(const char *ifname, const u8 *addr, int add);
|
||||
int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user