mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
drivers: Move driver_wired_get_ifstatus() 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
d718a5d975
commit
5a55ec38ed
@ -99,35 +99,6 @@ static int macsec_qca_get_capa(void *priv, struct wpa_driver_capa *capa)
|
||||
}
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
static int macsec_qca_get_ifstatus(const char *ifname, int *status)
|
||||
{
|
||||
struct ifmediareq ifmr;
|
||||
int s;
|
||||
|
||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
wpa_print(MSG_ERROR, "socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_memset(&ifmr, 0, sizeof(ifmr));
|
||||
os_strlcpy(ifmr.ifm_name, ifname, IFNAMSIZ);
|
||||
if (ioctl(s, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0) {
|
||||
wpa_printf(MSG_ERROR, "ioctl[SIOCGIFMEDIA]: %s",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
close(s);
|
||||
*status = (ifmr.ifm_status & (IFM_ACTIVE | IFM_AVALID)) ==
|
||||
(IFM_ACTIVE | IFM_AVALID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||
|
||||
|
||||
static void __macsec_drv_init(struct macsec_qca_data *drv)
|
||||
{
|
||||
int ret = 0;
|
||||
@ -243,7 +214,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
||||
int status;
|
||||
wpa_printf(MSG_DEBUG, "%s: waiting for link to become active",
|
||||
__func__);
|
||||
while (macsec_qca_get_ifstatus(ifname, &status) == 0 &&
|
||||
while (driver_wired_get_ifstatus(ifname, &status) == 0 &&
|
||||
status == 0)
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -390,35 +390,6 @@ static int wpa_driver_wired_get_capa(void *priv, struct wpa_driver_capa *capa)
|
||||
}
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
static int wpa_driver_wired_get_ifstatus(const char *ifname, int *status)
|
||||
{
|
||||
struct ifmediareq ifmr;
|
||||
int s;
|
||||
|
||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_memset(&ifmr, 0, sizeof(ifmr));
|
||||
os_strlcpy(ifmr.ifm_name, ifname, IFNAMSIZ);
|
||||
if (ioctl(s, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0) {
|
||||
wpa_printf(MSG_ERROR, "ioctl[SIOCGIFMEDIA]: %s",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
close(s);
|
||||
*status = (ifmr.ifm_status & (IFM_ACTIVE | IFM_AVALID)) ==
|
||||
(IFM_ACTIVE | IFM_AVALID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||
|
||||
|
||||
static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
||||
{
|
||||
struct wpa_driver_wired_data *drv;
|
||||
@ -477,7 +448,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
||||
int status;
|
||||
wpa_printf(MSG_DEBUG, "%s: waiting for link to become active",
|
||||
__func__);
|
||||
while (wpa_driver_wired_get_ifstatus(ifname, &status) == 0 &&
|
||||
while (driver_wired_get_ifstatus(ifname, &status) == 0 &&
|
||||
status == 0)
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -162,3 +162,32 @@ int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add)
|
||||
return -1;
|
||||
#endif /* __linux__ */
|
||||
}
|
||||
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
int driver_wired_get_ifstatus(const char *ifname, int *status)
|
||||
{
|
||||
struct ifmediareq ifmr;
|
||||
int s;
|
||||
|
||||
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||
if (s < 0) {
|
||||
wpa_printf(MSG_ERROR, "socket: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_memset(&ifmr, 0, sizeof(ifmr));
|
||||
os_strlcpy(ifmr.ifm_name, ifname, IFNAMSIZ);
|
||||
if (ioctl(s, SIOCGIFMEDIA, (caddr_t) &ifmr) < 0) {
|
||||
wpa_printf(MSG_ERROR, "ioctl[SIOCGIFMEDIA]: %s",
|
||||
strerror(errno));
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
close(s);
|
||||
*status = (ifmr.ifm_status & (IFM_ACTIVE | IFM_AVALID)) ==
|
||||
(IFM_ACTIVE | IFM_AVALID);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||
|
@ -26,5 +26,6 @@ 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);
|
||||
int driver_wired_get_ifstatus(const char *ifname, int *status);
|
||||
|
||||
#endif /* DRIVER_WIRED_COMMON_H */
|
||||
|
Loading…
Reference in New Issue
Block a user