[LLC] use llc_mac_{match,null} in more places

parent a3571512
...@@ -30,4 +30,36 @@ static __inline__ char llc_backlog_type(struct sk_buff *skb) ...@@ -30,4 +30,36 @@ static __inline__ char llc_backlog_type(struct sk_buff *skb)
return skb->cb[sizeof(skb->cb) - 1]; return skb->cb[sizeof(skb->cb) - 1];
} }
extern u8 llc_mac_null_var[IFHWADDRLEN];
/**
* llc_mac_null - determines if a address is a null mac address
* @mac: Mac address to test if null.
*
* Determines if a given address is a null mac address. Returns 0 if the
* address is not a null mac, 1 if the address is a null mac.
*/
static __inline__ int llc_mac_null(u8 *mac)
{
return !memcmp(mac, llc_mac_null_var, IFHWADDRLEN);
}
static __inline__ int llc_addrany(struct llc_addr *addr)
{
return llc_mac_null(addr->mac) && !addr->lsap;
}
/**
* llc_mac_match - determines if two mac addresses are the same
* @mac1: First mac address to compare.
* @mac2: Second mac address to compare.
*
* Determines if two given mac address are the same. Returns 0 if there
* is not a complete match up to len, 1 if a complete match up to len is
* found.
*/
static __inline__ int llc_mac_match(u8 *mac1, u8 *mac2)
{
return !memcmp(mac1, mac2, IFHWADDRLEN);
}
#endif /* LLC_MAC_H */ #endif /* LLC_MAC_H */
...@@ -430,8 +430,8 @@ struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr, ...@@ -430,8 +430,8 @@ struct sock *llc_lookup_established(struct llc_sap *sap, struct llc_addr *daddr,
if (llc->laddr.lsap == laddr->lsap && if (llc->laddr.lsap == laddr->lsap &&
llc->daddr.lsap == daddr->lsap && llc->daddr.lsap == daddr->lsap &&
!memcmp(llc->laddr.mac, laddr->mac, ETH_ALEN) && llc_mac_match(llc->laddr.mac, laddr->mac) &&
!memcmp(llc->daddr.mac, daddr->mac, ETH_ALEN)) { llc_mac_match(llc->daddr.mac, daddr->mac)) {
rc = llc->sk; rc = llc->sk;
break; break;
} }
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#define dprintk(args...) #define dprintk(args...)
#endif #endif
u8 llc_mac_null_var[IFHWADDRLEN];
static void fix_up_incoming_skb(struct sk_buff *skb); static void fix_up_incoming_skb(struct sk_buff *skb);
static void llc_station_rcv(struct sk_buff *skb); static void llc_station_rcv(struct sk_buff *skb);
static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb); static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb);
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <net/llc_sap.h> #include <net/llc_sap.h>
#include <net/llc_pdu.h> #include <net/llc_pdu.h>
#include <net/llc_conn.h> #include <net/llc_conn.h>
#include <net/llc_mac.h>
#include <linux/llc.h> #include <linux/llc.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
...@@ -46,7 +47,6 @@ ...@@ -46,7 +47,6 @@
/* remember: uninitialized global data is zeroed because its in .bss */ /* remember: uninitialized global data is zeroed because its in .bss */
static u16 llc_ui_sap_last_autoport = LLC_SAP_DYN_START; static u16 llc_ui_sap_last_autoport = LLC_SAP_DYN_START;
static u16 llc_ui_sap_link_no_max[256]; static u16 llc_ui_sap_link_no_max[256];
static u8 llc_ui_addrany[IFHWADDRLEN];
static struct sockaddr_llc llc_ui_addrnull; static struct sockaddr_llc llc_ui_addrnull;
static struct proto_ops llc_ui_ops; static struct proto_ops llc_ui_ops;
static struct sock *llc_ui_sockets; static struct sock *llc_ui_sockets;
...@@ -69,32 +69,6 @@ static __inline__ u16 llc_ui_next_link_no(int sap) ...@@ -69,32 +69,6 @@ static __inline__ u16 llc_ui_next_link_no(int sap)
return llc_ui_sap_link_no_max[sap]++; return llc_ui_sap_link_no_max[sap]++;
} }
/**
* llc_ui_mac_match - determines if two mac addresses are the same
* @mac1: First mac address to compare.
* @mac2: Second mac address to compare.
*
* Determines if two given mac address are the same. Returns 0 if there
* is not a complete match up to len, 1 if a complete match up to len is
* found.
*/
static __inline__ u8 llc_ui_mac_match(u8 *mac1, u8 *mac2)
{
return !memcmp(mac1, mac2, IFHWADDRLEN);
}
/**
* llc_ui_mac_null - determines if a address is a null mac address
* @mac: Mac address to test if null.
*
* Determines if a given address is a null mac address. Returns 0 if the
* address is not a null mac, 1 if the address is a null mac.
*/
static __inline__ u8 llc_ui_mac_null(u8 *mac)
{
return !memcmp(mac, llc_ui_addrany, IFHWADDRLEN);
}
/** /**
* llc_ui_addr_null - determines if a address structure is null * llc_ui_addr_null - determines if a address structure is null
* @addr: Address to test if null. * @addr: Address to test if null.
...@@ -304,9 +278,9 @@ static struct sock *__llc_ui_find_sk_by_exact(struct llc_addr *laddr, ...@@ -304,9 +278,9 @@ static struct sock *__llc_ui_find_sk_by_exact(struct llc_addr *laddr,
if (llc_ui->addr.sllc_ssap == laddr->lsap && if (llc_ui->addr.sllc_ssap == laddr->lsap &&
llc_ui->addr.sllc_dsap == daddr->lsap && llc_ui->addr.sllc_dsap == daddr->lsap &&
llc_ui_mac_null(llc_ui->addr.sllc_mmac) && llc_mac_null(llc_ui->addr.sllc_mmac) &&
llc_ui_mac_match(llc_ui->addr.sllc_smac, laddr->mac) && llc_mac_match(llc_ui->addr.sllc_smac, laddr->mac) &&
llc_ui_mac_match(llc_ui->addr.sllc_dmac, daddr->mac)) llc_mac_match(llc_ui->addr.sllc_dmac, daddr->mac))
break; break;
} }
return sk; return sk;
...@@ -333,27 +307,27 @@ static struct sock *__llc_ui_find_sk_by_addr(struct llc_addr *laddr, ...@@ -333,27 +307,27 @@ static struct sock *__llc_ui_find_sk_by_addr(struct llc_addr *laddr,
if (llc_ui->addr.sllc_ssap != laddr->lsap) if (llc_ui->addr.sllc_ssap != laddr->lsap)
continue; continue;
if (llc_ui_mac_null(llc_ui->addr.sllc_smac)) { if (llc_mac_null(llc_ui->addr.sllc_smac)) {
if (!llc_ui_mac_null(llc_ui->addr.sllc_mmac) && if (!llc_mac_null(llc_ui->addr.sllc_mmac) &&
!llc_ui_mac_match(llc_ui->addr.sllc_mmac, !llc_mac_match(llc_ui->addr.sllc_mmac,
laddr->mac)) laddr->mac))
continue; continue;
break; break;
} }
if (dev && !llc_ui_mac_null(llc_ui->addr.sllc_mmac) && if (dev && !llc_mac_null(llc_ui->addr.sllc_mmac) &&
llc_ui_mac_match(llc_ui->addr.sllc_mmac, laddr->mac) && llc_mac_match(llc_ui->addr.sllc_mmac, laddr->mac) &&
llc_ui_mac_match(llc_ui->addr.sllc_smac, dev->dev_addr)) llc_mac_match(llc_ui->addr.sllc_smac, dev->dev_addr))
break; break;
if (dev->flags & IFF_LOOPBACK) if (dev->flags & IFF_LOOPBACK)
break; break;
if (!llc_ui_mac_match(llc_ui->addr.sllc_smac, laddr->mac)) if (!llc_mac_match(llc_ui->addr.sllc_smac, laddr->mac))
continue; continue;
tmp_sk = __llc_ui_find_sk_by_exact(laddr, daddr); tmp_sk = __llc_ui_find_sk_by_exact(laddr, daddr);
if (tmp_sk) { if (tmp_sk) {
sk = tmp_sk; sk = tmp_sk;
break; break;
} }
if (llc_ui_mac_null(llc_ui->addr.sllc_dmac)) if (llc_mac_null(llc_ui->addr.sllc_dmac))
break; break;
} }
return sk; return sk;
...@@ -597,7 +571,7 @@ static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr) ...@@ -597,7 +571,7 @@ static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
if (!sk->zapped) if (!sk->zapped)
goto out; goto out;
/* bind to a specific mac, optional. */ /* bind to a specific mac, optional. */
if (!llc_ui_mac_null(addr->sllc_smac)) { if (!llc_mac_null(addr->sllc_smac)) {
rtnl_lock(); rtnl_lock();
dev = dev_getbyhwaddr(addr->sllc_arphrd, addr->sllc_smac); dev = dev_getbyhwaddr(addr->sllc_arphrd, addr->sllc_smac);
rtnl_unlock(); rtnl_unlock();
...@@ -625,11 +599,11 @@ static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr) ...@@ -625,11 +599,11 @@ static int llc_ui_autobind(struct socket *sock, struct sockaddr_llc *addr)
struct sock *ask; struct sock *ask;
rc = -EUSERS; /* can't get exclusive use of sap */ rc = -EUSERS; /* can't get exclusive use of sap */
if (!dev && llc_ui_mac_null(addr->sllc_mmac)) if (!dev && llc_mac_null(addr->sllc_mmac))
goto out; goto out;
memset(&laddr, 0, sizeof(laddr)); memset(&laddr, 0, sizeof(laddr));
memset(&daddr, 0, sizeof(daddr)); memset(&daddr, 0, sizeof(daddr));
if (!llc_ui_mac_null(addr->sllc_mmac)) { if (!llc_mac_null(addr->sllc_mmac)) {
if (sk->type != SOCK_DGRAM) { if (sk->type != SOCK_DGRAM) {
rc = -EOPNOTSUPP; rc = -EOPNOTSUPP;
goto out; goto out;
...@@ -1630,14 +1604,14 @@ static int llc_ui_get_info(char *buffer, char **start, off_t offset, int length) ...@@ -1630,14 +1604,14 @@ static int llc_ui_get_info(char *buffer, char **start, off_t offset, int length)
for (s = llc_ui_sockets; s; s = s->next) { for (s = llc_ui_sockets; s; s = s->next) {
struct llc_ui_opt *llc_ui = llc_ui_sk(s); struct llc_ui_opt *llc_ui = llc_ui_sk(s);
len += sprintf(buffer + len, "%p %02X %02X ", s, s->type, len += sprintf(buffer + len, "%p %02X %02X ", s, s->type,
!llc_ui_mac_null(llc_ui->addr.sllc_mmac)); !llc_mac_null(llc_ui->addr.sllc_mmac));
if (llc_ui->sap) { if (llc_ui->sap) {
if (llc_ui->dev && if (llc_ui->dev &&
llc_ui_mac_null(llc_ui->addr.sllc_mmac)) llc_mac_null(llc_ui->addr.sllc_mmac))
llc_ui_format_mac(buffer + len, llc_ui_format_mac(buffer + len,
llc_ui->dev->dev_addr); llc_ui->dev->dev_addr);
else { else {
if (!llc_ui_mac_null(llc_ui->addr.sllc_mmac)) if (!llc_mac_null(llc_ui->addr.sllc_mmac))
llc_ui_format_mac(buffer + len, llc_ui_format_mac(buffer + len,
llc_ui->addr.sllc_mmac); llc_ui->addr.sllc_mmac);
else else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment