drivers: Move driver_wired_multi() 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
b0906ef770
commit
693124a1e4
4 changed files with 62 additions and 114 deletions
|
@ -178,61 +178,6 @@ static int macsec_qca_get_ifstatus(const char *ifname, int *status)
|
||||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||||
|
|
||||||
|
|
||||||
static int macsec_qca_multi(const char *ifname, const u8 *addr, int add)
|
|
||||||
{
|
|
||||||
struct ifreq ifr;
|
|
||||||
int s;
|
|
||||||
|
|
||||||
#ifdef __sun__
|
|
||||||
return -1;
|
|
||||||
#endif /* __sun__ */
|
|
||||||
|
|
||||||
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);
|
|
||||||
#ifdef __linux__
|
|
||||||
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
|
|
||||||
os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
|
|
||||||
#endif /* __linux__ */
|
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
|
||||||
{
|
|
||||||
struct sockaddr_dl *dlp;
|
|
||||||
dlp = (struct sockaddr_dl *) &ifr.ifr_addr;
|
|
||||||
dlp->sdl_len = sizeof(struct sockaddr_dl);
|
|
||||||
dlp->sdl_family = AF_LINK;
|
|
||||||
dlp->sdl_index = 0;
|
|
||||||
dlp->sdl_nlen = 0;
|
|
||||||
dlp->sdl_alen = ETH_ALEN;
|
|
||||||
dlp->sdl_slen = 0;
|
|
||||||
os_memcpy(LLADDR(dlp), addr, ETH_ALEN);
|
|
||||||
}
|
|
||||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
|
||||||
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
|
|
||||||
{
|
|
||||||
struct sockaddr *sap;
|
|
||||||
sap = (struct sockaddr *) &ifr.ifr_addr;
|
|
||||||
sap->sa_len = sizeof(struct sockaddr);
|
|
||||||
sap->sa_family = AF_UNSPEC;
|
|
||||||
os_memcpy(sap->sa_data, addr, ETH_ALEN);
|
|
||||||
}
|
|
||||||
#endif /* defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) */
|
|
||||||
|
|
||||||
if (ioctl(s, add ? SIOCADDMULTI : SIOCDELMULTI, (caddr_t) &ifr) < 0) {
|
|
||||||
wpa_printf(MSG_ERROR, "ioctl[SIOC{ADD/DEL}MULTI]: %s",
|
|
||||||
strerror(errno));
|
|
||||||
close(s);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(s);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void __macsec_drv_init(struct macsec_qca_data *drv)
|
static void __macsec_drv_init(struct macsec_qca_data *drv)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -320,7 +265,7 @@ static void * macsec_qca_init(void *ctx, const char *ifname)
|
||||||
"%s: Added multicast membership with packet socket",
|
"%s: Added multicast membership with packet socket",
|
||||||
__func__);
|
__func__);
|
||||||
drv->common.membership = 1;
|
drv->common.membership = 1;
|
||||||
} else if (macsec_qca_multi(ifname, pae_group_addr, 1) == 0) {
|
} else if (driver_wired_multi(ifname, pae_group_addr, 1) == 0) {
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
"%s: Added multicast membership with SIOCADDMULTI",
|
"%s: Added multicast membership with SIOCADDMULTI",
|
||||||
__func__);
|
__func__);
|
||||||
|
@ -373,7 +318,7 @@ static void macsec_qca_deinit(void *priv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drv->common.multi &&
|
if (drv->common.multi &&
|
||||||
macsec_qca_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
|
driver_wired_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG,
|
||||||
"%s: Failed to remove PAE multicast group (SIOCDELMULTI)",
|
"%s: Failed to remove PAE multicast group (SIOCDELMULTI)",
|
||||||
__func__);
|
__func__);
|
||||||
|
|
|
@ -469,61 +469,6 @@ static int wpa_driver_wired_get_ifstatus(const char *ifname, int *status)
|
||||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||||
|
|
||||||
|
|
||||||
static int wpa_driver_wired_multi(const char *ifname, const u8 *addr, int add)
|
|
||||||
{
|
|
||||||
struct ifreq ifr;
|
|
||||||
int s;
|
|
||||||
|
|
||||||
#ifdef __sun__
|
|
||||||
return -1;
|
|
||||||
#endif /* __sun__ */
|
|
||||||
|
|
||||||
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);
|
|
||||||
#ifdef __linux__
|
|
||||||
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
|
|
||||||
os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
|
|
||||||
#endif /* __linux__ */
|
|
||||||
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
|
||||||
{
|
|
||||||
struct sockaddr_dl *dlp;
|
|
||||||
dlp = (struct sockaddr_dl *) &ifr.ifr_addr;
|
|
||||||
dlp->sdl_len = sizeof(struct sockaddr_dl);
|
|
||||||
dlp->sdl_family = AF_LINK;
|
|
||||||
dlp->sdl_index = 0;
|
|
||||||
dlp->sdl_nlen = 0;
|
|
||||||
dlp->sdl_alen = ETH_ALEN;
|
|
||||||
dlp->sdl_slen = 0;
|
|
||||||
os_memcpy(LLADDR(dlp), addr, ETH_ALEN);
|
|
||||||
}
|
|
||||||
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
|
||||||
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
|
|
||||||
{
|
|
||||||
struct sockaddr *sap;
|
|
||||||
sap = (struct sockaddr *) &ifr.ifr_addr;
|
|
||||||
sap->sa_len = sizeof(struct sockaddr);
|
|
||||||
sap->sa_family = AF_UNSPEC;
|
|
||||||
os_memcpy(sap->sa_data, addr, ETH_ALEN);
|
|
||||||
}
|
|
||||||
#endif /* defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) */
|
|
||||||
|
|
||||||
if (ioctl(s, add ? SIOCADDMULTI : SIOCDELMULTI, (caddr_t) &ifr) < 0) {
|
|
||||||
wpa_printf(MSG_ERROR, "ioctl[SIOC{ADD/DEL}MULTI]: %s",
|
|
||||||
strerror(errno));
|
|
||||||
close(s);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
close(s);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
||||||
{
|
{
|
||||||
struct wpa_driver_wired_data *drv;
|
struct wpa_driver_wired_data *drv;
|
||||||
|
@ -555,7 +500,7 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
|
||||||
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
||||||
"packet socket", __func__);
|
"packet socket", __func__);
|
||||||
drv->common.membership = 1;
|
drv->common.membership = 1;
|
||||||
} else if (wpa_driver_wired_multi(ifname, pae_group_addr, 1) == 0) {
|
} else if (driver_wired_multi(ifname, pae_group_addr, 1) == 0) {
|
||||||
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
wpa_printf(MSG_DEBUG, "%s: Added multicast membership with "
|
||||||
"SIOCADDMULTI", __func__);
|
"SIOCADDMULTI", __func__);
|
||||||
drv->common.multi = 1;
|
drv->common.multi = 1;
|
||||||
|
@ -607,7 +552,7 @@ static void wpa_driver_wired_deinit(void *priv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drv->common.multi &&
|
if (drv->common.multi &&
|
||||||
wpa_driver_wired_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
|
driver_wired_multi(drv->common.ifname, pae_group_addr, 0) < 0) {
|
||||||
wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
|
wpa_printf(MSG_DEBUG, "%s: Failed to remove PAE multicast "
|
||||||
"group (SIOCDELMULTI)", __func__);
|
"group (SIOCDELMULTI)", __func__);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,63 @@
|
||||||
#endif /* __sun__ */
|
#endif /* __sun__ */
|
||||||
|
|
||||||
|
|
||||||
|
int driver_wired_multi(const char *ifname, const u8 *addr, int add)
|
||||||
|
{
|
||||||
|
struct ifreq ifr;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
#ifdef __sun__
|
||||||
|
return -1;
|
||||||
|
#endif /* __sun__ */
|
||||||
|
|
||||||
|
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);
|
||||||
|
#ifdef __linux__
|
||||||
|
ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
|
||||||
|
os_memcpy(ifr.ifr_hwaddr.sa_data, addr, ETH_ALEN);
|
||||||
|
#endif /* __linux__ */
|
||||||
|
#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
|
||||||
|
{
|
||||||
|
struct sockaddr_dl *dlp;
|
||||||
|
|
||||||
|
dlp = (struct sockaddr_dl *) &ifr.ifr_addr;
|
||||||
|
dlp->sdl_len = sizeof(struct sockaddr_dl);
|
||||||
|
dlp->sdl_family = AF_LINK;
|
||||||
|
dlp->sdl_index = 0;
|
||||||
|
dlp->sdl_nlen = 0;
|
||||||
|
dlp->sdl_alen = ETH_ALEN;
|
||||||
|
dlp->sdl_slen = 0;
|
||||||
|
os_memcpy(LLADDR(dlp), addr, ETH_ALEN);
|
||||||
|
}
|
||||||
|
#endif /* defined(__FreeBSD__) || defined(__DragonFly__) || defined(FreeBSD_kernel__) */
|
||||||
|
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
|
||||||
|
{
|
||||||
|
struct sockaddr *sap;
|
||||||
|
|
||||||
|
sap = (struct sockaddr *) &ifr.ifr_addr;
|
||||||
|
sap->sa_len = sizeof(struct sockaddr);
|
||||||
|
sap->sa_family = AF_UNSPEC;
|
||||||
|
os_memcpy(sap->sa_data, addr, ETH_ALEN);
|
||||||
|
}
|
||||||
|
#endif /* defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__) */
|
||||||
|
|
||||||
|
if (ioctl(s, add ? SIOCADDMULTI : SIOCDELMULTI, (caddr_t) &ifr) < 0) {
|
||||||
|
wpa_printf(MSG_ERROR, "ioctl[SIOC{ADD/DEL}MULTI]: %s",
|
||||||
|
strerror(errno));
|
||||||
|
close(s);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
close(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add)
|
int wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add)
|
||||||
{
|
{
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
|
@ -22,6 +22,7 @@ struct driver_wired_common_data {
|
||||||
static const u8 pae_group_addr[ETH_ALEN] =
|
static const u8 pae_group_addr[ETH_ALEN] =
|
||||||
{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
|
{ 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
|
||||||
|
|
||||||
|
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 wired_multicast_membership(int sock, int ifindex, const u8 *addr, int add);
|
||||||
|
|
||||||
#endif /* DRIVER_WIRED_COMMON_H */
|
#endif /* DRIVER_WIRED_COMMON_H */
|
||||||
|
|
Loading…
Add table
Reference in a new issue