drivers: Move driver_wired_init_common() 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
5a55ec38ed
commit
ed5ae61193
4 changed files with 72 additions and 108 deletions
|
@ -149,76 +149,23 @@ static void __macsec_drv_deinit(struct macsec_qca_data *drv)
|
|||
static void * macsec_qca_init(void *ctx, const char *ifname)
|
||||
{
|
||||
struct macsec_qca_data *drv;
|
||||
int flags;
|
||||
|
||||
drv = os_zalloc(sizeof(*drv));
|
||||
if (drv == NULL)
|
||||
return NULL;
|
||||
os_strlcpy(drv->common.ifname, ifname, sizeof(drv->common.ifname));
|
||||
drv->common.ctx = ctx;
|
||||
|
||||
/* Board specific settings */
|
||||
if (os_memcmp("eth2", drv->common.ifname, 4) == 0)
|
||||
if (os_memcmp("eth2", ifname, 4) == 0)
|
||||
drv->secy_id = 1;
|
||||
else if (os_memcmp("eth3", drv->common.ifname, 4) == 0)
|
||||
else if (os_memcmp("eth3", ifname, 4) == 0)
|
||||
drv->secy_id = 2;
|
||||
else
|
||||
drv->secy_id = -1;
|
||||
|
||||
#ifdef __linux__
|
||||
drv->common.pf_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
|
||||
if (drv->common.pf_sock < 0)
|
||||
wpa_printf(MSG_ERROR, "socket(PF_PACKET): %s", strerror(errno));
|
||||
#else /* __linux__ */
|
||||
drv->common.pf_sock = -1;
|
||||
#endif /* __linux__ */
|
||||
|
||||
if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
||||
!(flags & IFF_UP) &&
|
||||
driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
||||
drv->common.iff_up = 1;
|
||||
}
|
||||
|
||||
if (wired_multicast_membership(drv->common.pf_sock,
|
||||
if_nametoindex(drv->common.ifname),
|
||||
pae_group_addr, 1) == 0) {
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"%s: Added multicast membership with packet socket",
|
||||
__func__);
|
||||
drv->common.membership = 1;
|
||||
} else if (driver_wired_multi(ifname, pae_group_addr, 1) == 0) {
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"%s: Added multicast membership with SIOCADDMULTI",
|
||||
__func__);
|
||||
drv->common.multi = 1;
|
||||
} else if (driver_wired_get_ifflags(ifname, &flags) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Could not get interface flags",
|
||||
__func__);
|
||||
if (driver_wired_init_common(&drv->common, ifname, ctx) < 0) {
|
||||
os_free(drv);
|
||||
return NULL;
|
||||
} else if (flags & IFF_ALLMULTI) {
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"%s: Interface is already configured for multicast",
|
||||
__func__);
|
||||
} else if (driver_wired_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Failed to enable allmulti",
|
||||
__func__);
|
||||
os_free(drv);
|
||||
return NULL;
|
||||
} else {
|
||||
wpa_printf(MSG_DEBUG, "%s: Enabled allmulti mode", __func__);
|
||||
drv->common.iff_allmulti = 1;
|
||||
}
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
{
|
||||
int status;
|
||||
wpa_printf(MSG_DEBUG, "%s: waiting for link to become active",
|
||||
__func__);
|
||||
while (driver_wired_get_ifstatus(ifname, &status) == 0 &&
|
||||
status == 0)
|
||||
sleep(1);
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||
|
||||
return drv;
|
||||
}
|
||||
|
|
|
@ -393,66 +393,15 @@ static int wpa_driver_wired_get_capa(void *priv, struct wpa_driver_capa *capa)
|
|||
static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
||||
{
|
||||
struct wpa_driver_wired_data *drv;
|
||||
int flags;
|
||||
|
||||
drv = os_zalloc(sizeof(*drv));
|
||||
if (drv == NULL)
|
||||
return NULL;
|
||||
os_strlcpy(drv->common.ifname, ifname, sizeof(drv->common.ifname));
|
||||
drv->common.ctx = ctx;
|
||||
|
||||
#ifdef __linux__
|
||||
drv->common.pf_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
|
||||
if (drv->common.pf_sock < 0)
|
||||
wpa_printf(MSG_ERROR, "socket(PF_PACKET): %s", strerror(errno));
|
||||
#else /* __linux__ */
|
||||
drv->common.pf_sock = -1;
|
||||
#endif /* __linux__ */
|
||||
|
||||
if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
||||
!(flags & IFF_UP) &&
|
||||
driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
|
||||
drv->common.iff_up = 1;
|
||||
}
|
||||
|
||||
if (wired_multicast_membership(drv->common.pf_sock,
|
||||
if_nametoindex(drv->common.ifname),
|
||||
pae_group_addr, 1) == 0) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
||||
"packet socket", __func__);
|
||||
drv->common.membership = 1;
|
||||
} else if (driver_wired_multi(ifname, pae_group_addr, 1) == 0) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
||||
"SIOCADDMULTI", __func__);
|
||||
drv->common.multi = 1;
|
||||
} else if (driver_wired_get_ifflags(ifname, &flags) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Could not get interface "
|
||||
"flags", __func__);
|
||||
if (driver_wired_init_common(&drv->common, ifname, ctx) < 0) {
|
||||
os_free(drv);
|
||||
return NULL;
|
||||
} else if (flags & IFF_ALLMULTI) {
|
||||
wpa_printf(MSG_DEBUG, "%s: Interface is already configured "
|
||||
"for multicast", __func__);
|
||||
} else if (driver_wired_set_ifflags(ifname, flags | IFF_ALLMULTI) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Failed to enable allmulti",
|
||||
__func__);
|
||||
os_free(drv);
|
||||
return NULL;
|
||||
} else {
|
||||
wpa_printf(MSG_DEBUG, "%s: Enabled allmulti mode",
|
||||
__func__);
|
||||
drv->common.iff_allmulti = 1;
|
||||
}
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
{
|
||||
int status;
|
||||
wpa_printf(MSG_DEBUG, "%s: waiting for link to become active",
|
||||
__func__);
|
||||
while (driver_wired_get_ifstatus(ifname, &status) == 0 &&
|
||||
status == 0)
|
||||
sleep(1);
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||
|
||||
return drv;
|
||||
}
|
||||
|
|
|
@ -191,3 +191,68 @@ int driver_wired_get_ifstatus(const char *ifname, int *status)
|
|||
return 0;
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||
|
||||
|
||||
int driver_wired_init_common(struct driver_wired_common_data *common,
|
||||
const char *ifname, void *ctx)
|
||||
{
|
||||
int flags;
|
||||
|
||||
os_strlcpy(common->ifname, ifname, sizeof(common->ifname));
|
||||
common->ctx = ctx;
|
||||
|
||||
#ifdef __linux__
|
||||
common->pf_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
|
||||
if (common->pf_sock < 0)
|
||||
wpa_printf(MSG_ERROR, "socket(PF_PACKET): %s", strerror(errno));
|
||||
#else /* __linux__ */
|
||||
common->pf_sock = -1;
|
||||
#endif /* __linux__ */
|
||||
|
||||
if (driver_wired_get_ifflags(ifname, &flags) == 0 &&
|
||||
!(flags & IFF_UP) &&
|
||||
driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0)
|
||||
common->iff_up = 1;
|
||||
|
||||
if (wired_multicast_membership(common->pf_sock,
|
||||
if_nametoindex(common->ifname),
|
||||
pae_group_addr, 1) == 0) {
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"%s: Added multicast membership with packet socket",
|
||||
__func__);
|
||||
common->membership = 1;
|
||||
} else if (driver_wired_multi(ifname, pae_group_addr, 1) == 0) {
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"%s: Added multicast membership with SIOCADDMULTI",
|
||||
__func__);
|
||||
common->multi = 1;
|
||||
} else if (driver_wired_get_ifflags(ifname, &flags) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Could not get interface flags",
|
||||
__func__);
|
||||
return -1;
|
||||
} else if (flags & IFF_ALLMULTI) {
|
||||
wpa_printf(MSG_DEBUG,
|
||||
"%s: Interface is already configured for multicast",
|
||||
__func__);
|
||||
} else if (driver_wired_set_ifflags(ifname,
|
||||
flags | IFF_ALLMULTI) < 0) {
|
||||
wpa_printf(MSG_INFO, "%s: Failed to enable allmulti", __func__);
|
||||
return -1;
|
||||
} else {
|
||||
wpa_printf(MSG_DEBUG, "%s: Enabled allmulti mode", __func__);
|
||||
common->iff_allmulti = 1;
|
||||
}
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||
{
|
||||
int status;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "%s: waiting for link to become active",
|
||||
__func__);
|
||||
while (driver_wired_get_ifstatus(ifname, &status) == 0 &&
|
||||
status == 0)
|
||||
sleep(1);
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,4 +28,7 @@ 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);
|
||||
|
||||
int driver_wired_init_common(struct driver_wired_common_data *common,
|
||||
const char *ifname, void *ctx);
|
||||
|
||||
#endif /* DRIVER_WIRED_COMMON_H */
|
||||
|
|
Loading…
Reference in a new issue