net: Set the network link address type when setting link address

The interface L2 address type is set at the same time as the
L2 address is set to the network interface. This is most
convinient place to set the address type.

Change-Id: I712d7357d075959eb79df3463141cfbc6d163a74
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2017-02-15 13:20:31 +02:00
commit 4eb2020055
26 changed files with 45 additions and 23 deletions

View file

@ -684,7 +684,8 @@ static void eth_enc28j60_iface_init_0(struct net_if *iface)
SYS_LOG_DBG("");
net_if_set_link_addr(iface, mac_address_0, sizeof(mac_address_0));
net_if_set_link_addr(iface, mac_address_0, sizeof(mac_address_0),
NET_LINK_ETHERNET);
context->iface = iface;
}

View file

@ -474,7 +474,8 @@ static void eth_0_iface_init(struct net_if *iface)
struct eth_context *context = dev->driver_data;
net_if_set_link_addr(iface, context->mac_addr,
sizeof(context->mac_addr));
sizeof(context->mac_addr),
NET_LINK_ETHERNET);
context->iface = iface;
}

View file

@ -749,7 +749,8 @@ static void eth0_iface_init(struct net_if *iface)
/* Register Ethernet MAC Address with the upper layer */
net_if_set_link_addr(iface, dev_data->mac_addr,
sizeof(dev_data->mac_addr));
sizeof(dev_data->mac_addr),
NET_LINK_ETHERNET);
dev_data->iface = iface;
}

View file

@ -1056,7 +1056,7 @@ static void cc2520_iface_init(struct net_if *iface)
SYS_LOG_DBG("");
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
cc2520->iface = iface;

View file

@ -1423,7 +1423,7 @@ static void mcr20a_iface_init(struct net_if *iface)
struct mcr20a_context *mcr20a = dev->driver_data;
uint8_t *mac = get_mac(dev);
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
mcr20a->iface = iface;

View file

@ -257,7 +257,7 @@ static void upipe_iface_init(struct net_if *iface)
SYS_LOG_DBG("");
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
upipe_dev = dev;
upipe->iface = iface;

View file

@ -402,7 +402,8 @@ static void slip_iface_init(struct net_if *iface)
slip->init_done = true;
net_if_set_link_addr(iface, ll_addr->addr, ll_addr->len);
net_if_set_link_addr(iface, ll_addr->addr, ll_addr->len,
NET_LINK_ETHERNET);
}
static struct net_if_api slip_if_api = {

View file

@ -419,11 +419,13 @@ void net_if_start_rs(struct net_if *iface);
* @param iface Pointer to a network interface structure
* @param addr a pointer on a uint8_t buffer representing the address
* @param len length of the address buffer
* @param type network bearer type of this link address
*
* @return 0 on success
*/
static inline int net_if_set_link_addr(struct net_if *iface,
uint8_t *addr, uint8_t len)
uint8_t *addr, uint8_t len,
enum net_link_type type)
{
if (atomic_test_bit(iface->flags, NET_IF_UP)) {
return -EPERM;
@ -431,6 +433,7 @@ static inline int net_if_set_link_addr(struct net_if *iface,
iface->link_addr.addr = addr;
iface->link_addr.len = len;
iface->link_addr.type = type;
return 0;
}

View file

@ -73,6 +73,9 @@ static enum net_verdict net_bt_recv(struct net_if *iface, struct net_buf *buf)
net_nbuf_ll_src(buf)->addr = src ? net_nbuf_ll(buf) + src : NULL;
net_nbuf_ll_dst(buf)->addr = dst ? net_nbuf_ll(buf) + dst : NULL;
net_nbuf_ll_src(buf)->type = NET_LINK_BLUETOOTH;
net_nbuf_ll_dst(buf)->type = NET_LINK_BLUETOOTH;
return NET_CONTINUE;
}
@ -147,7 +150,8 @@ static void ipsp_connected(struct bt_l2cap_chan *chan)
sys_memcpy_swap(ctxt->src.val, info.le.src->a.val, sizeof(ctxt->src));
sys_memcpy_swap(ctxt->dst.val, info.le.dst->a.val, sizeof(ctxt->dst));
net_if_set_link_addr(ctxt->iface, ctxt->src.val, sizeof(ctxt->src.val));
net_if_set_link_addr(ctxt->iface, ctxt->src.val, sizeof(ctxt->src.val),
NET_LINK_BLUETOOTH);
ll.addr = ctxt->dst.val;
ll.len = sizeof(ctxt->dst.val);

View file

@ -14,8 +14,10 @@ static inline enum net_verdict dummy_recv(struct net_if *iface,
{
net_nbuf_ll_src(buf)->addr = NULL;
net_nbuf_ll_src(buf)->len = 0;
net_nbuf_ll_src(buf)->type = NET_LINK_DUMMY;
net_nbuf_ll_dst(buf)->addr = NULL;
net_nbuf_ll_dst(buf)->len = 0;
net_nbuf_ll_dst(buf)->type = NET_LINK_DUMMY;
return NET_CONTINUE;
}

View file

@ -109,10 +109,12 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
lladdr = net_nbuf_ll_src(buf);
lladdr->addr = ((struct net_eth_hdr *)net_nbuf_ll(buf))->src.addr;
lladdr->len = sizeof(struct net_eth_addr);
lladdr->type = NET_LINK_ETHERNET;
lladdr = net_nbuf_ll_dst(buf);
lladdr->addr = ((struct net_eth_hdr *)net_nbuf_ll(buf))->dst.addr;
lladdr->len = sizeof(struct net_eth_addr);
lladdr->type = NET_LINK_ETHERNET;
print_ll_addrs(buf, ntohs(hdr->type), net_buf_frags_len(buf));

View file

@ -140,6 +140,8 @@ static inline void set_buf_ll_addr(struct net_linkaddr *addr, bool comp,
addr->len = 0;
addr->addr = NULL;
}
addr->type = NET_LINK_IEEE802154;
}
#ifdef CONFIG_NET_6LO

View file

@ -195,7 +195,7 @@ int net_6lo_dev_init(struct device *dev)
static void net_6lo_iface_init(struct net_if *iface)
{
net_if_set_link_addr(iface, src_mac, 8);
net_if_set_link_addr(iface, src_mac, 8, NET_LINK_IEEE802154);
}
static int tester_send(struct net_if *iface, struct net_buf *buf)

View file

@ -64,7 +64,7 @@ static void net_arp_iface_init(struct net_if *iface)
{
uint8_t *mac = net_arp_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 6, NET_LINK_ETHERNET);
}
static struct net_buf *pending_buf;

View file

@ -1050,7 +1050,8 @@ static void net_context_iface_init(struct net_if *iface)
{
uint8_t *mac = net_context_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr),
NET_LINK_ETHERNET);
}
static int tester_send(struct net_if *iface, struct net_buf *buf)

View file

@ -198,7 +198,7 @@ static void net_dhcpv4_iface_init(struct net_if *iface)
{
uint8_t *mac = net_dhcpv4_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, 6);
net_if_set_link_addr(iface, mac, 6, NET_LINK_ETHERNET);
}
static struct net_buf *nbuf_get_data(struct net_if *iface)

View file

@ -152,7 +152,7 @@ static void net_fragment_iface_init(struct net_if *iface)
{
uint8_t mac[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb};
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
}
static int tester_send(struct net_if *iface, struct net_buf *buf)

View file

@ -111,7 +111,7 @@ static void fake_iface_init(struct net_if *iface)
static uint8_t mac[8] = { 0x00, 0x12, 0x4b, 0x00,
0x00, 0x9e, 0xa3, 0xc2 };
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
ctx->pan_id = 0xabcd;
ctx->channel = 26;

View file

@ -95,7 +95,8 @@ static void net_iface_init(struct net_if *iface)
{
uint8_t *mac = net_iface_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr),
NET_LINK_ETHERNET);
}
static int sender_iface(struct net_if *iface, struct net_buf *buf)

View file

@ -135,7 +135,7 @@ static void net_test_iface_init(struct net_if *iface)
{
uint8_t *mac = net_test_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 6, NET_LINK_ETHERNET);
}
static int tester_send(struct net_if *iface, struct net_buf *buf)

View file

@ -159,7 +159,8 @@ static void net_test_iface_init(struct net_if *iface)
{
uint8_t *mac = net_test_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr),
NET_LINK_ETHERNET);
}
static struct net_buf *prepare_ra_message(void)

View file

@ -60,7 +60,7 @@ static void fake_iface_init(struct net_if *iface)
{
uint8_t mac[8] = { 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d};
net_if_set_link_addr(iface, mac, 8);
net_if_set_link_addr(iface, mac, 8, NET_LINK_DUMMY);
}
static int fake_iface_send(struct net_if *iface, struct net_buf *buf)

View file

@ -116,7 +116,8 @@ static void net_route_iface_init(struct net_if *iface)
{
uint8_t *mac = net_route_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr),
NET_LINK_ETHERNET);
}
static int tester_send(struct net_if *iface, struct net_buf *buf)

View file

@ -101,7 +101,8 @@ static void net_rpl_iface_init(struct net_if *iface)
{
uint8_t *mac = net_rpl_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr));
net_if_set_link_addr(iface, mac, sizeof(struct net_eth_addr),
NET_LINK_ETHERNET);
}
static void set_buf_ll_addr(struct device *dev, struct net_buf *buf)

View file

@ -110,7 +110,7 @@ static void net_tcp_iface_init(struct net_if *iface)
{
uint8_t *mac = net_tcp_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, 6);
net_if_set_link_addr(iface, mac, 6, NET_LINK_ETHERNET);
}
static void v6_send_syn_ack(struct net_if *iface, struct net_buf *req)

View file

@ -72,7 +72,7 @@ static void net_udp_iface_init(struct net_if *iface)
{
uint8_t *mac = net_udp_get_mac(net_if_get_device(iface));
net_if_set_link_addr(iface, mac, 6);
net_if_set_link_addr(iface, mac, 6, NET_LINK_ETHERNET);
}
static int send_status = -EINVAL;