Skip to content

Commit 2c343d2

Browse files
jukkarAnas Nashif
authored andcommitted
drivers: net: slip: Add VLAN support
This enables VLAN support in slip tap ethernet driver. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 73b43e0 commit 2c343d2

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

drivers/net/slip.c

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,50 @@ static struct net_pkt *slip_poll_handler(struct slip_context *slip)
239239
return NULL;
240240
}
241241

242+
static inline struct net_if *get_iface(struct slip_context *context,
243+
u16_t vlan_tag)
244+
{
245+
#if defined(CONFIG_NET_VLAN)
246+
struct net_if *iface;
247+
248+
iface = net_eth_get_vlan_iface(context->iface, vlan_tag);
249+
if (!iface) {
250+
return context->iface;
251+
}
252+
253+
return iface;
254+
#else
255+
ARG_UNUSED(vlan_tag);
256+
257+
return context->iface;
258+
#endif
259+
}
260+
242261
static void process_msg(struct slip_context *slip)
243262
{
263+
u16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
244264
struct net_pkt *pkt;
245265

246266
pkt = slip_poll_handler(slip);
247267
if (!pkt || !pkt->frags) {
248268
return;
249269
}
250270

251-
if (net_recv_data(slip->iface, pkt) < 0) {
271+
#if defined(CONFIG_NET_VLAN)
272+
{
273+
struct net_eth_hdr *hdr = NET_ETH_HDR(pkt);
274+
275+
if (ntohs(hdr->type) == NET_ETH_PTYPE_VLAN) {
276+
struct net_eth_vlan_hdr *hdr_vlan =
277+
(struct net_eth_vlan_hdr *)NET_ETH_HDR(pkt);
278+
279+
net_pkt_set_vlan_tci(pkt, ntohs(hdr_vlan->vlan.tci));
280+
vlan_tag = net_pkt_vlan_tag(pkt);
281+
}
282+
}
283+
#endif
284+
285+
if (net_recv_data(get_iface(slip, vlan_tag), pkt) < 0) {
252286
net_pkt_unref(pkt);
253287
}
254288

@@ -441,8 +475,15 @@ static inline struct net_linkaddr *slip_get_mac(struct slip_context *slip)
441475
static void slip_iface_init(struct net_if *iface)
442476
{
443477
struct slip_context *slip = net_if_get_device(iface)->driver_data;
444-
struct net_linkaddr *ll_addr = slip_get_mac(slip);
478+
struct net_linkaddr *ll_addr;
479+
480+
ethernet_init(iface);
481+
482+
if (slip->init_done) {
483+
return;
484+
}
445485

486+
ll_addr = slip_get_mac(slip);
446487
slip->init_done = true;
447488
slip->iface = iface;
448489

@@ -467,15 +508,32 @@ static void slip_iface_init(struct net_if *iface)
467508

468509
static struct slip_context slip_context_data;
469510

511+
#if defined(CONFIG_NET_VLAN)
512+
static enum eth_hw_caps eth_capabilities(struct device *dev)
513+
{
514+
ARG_UNUSED(dev);
515+
516+
return ETH_HW_VLAN;
517+
}
518+
#endif
519+
470520
#if defined(CONFIG_SLIP_TAP) && defined(CONFIG_NET_L2_ETHERNET)
471521
static const struct ethernet_api slip_if_api = {
472522
.iface_api.init = slip_iface_init,
473523
.iface_api.send = slip_send,
524+
525+
#if defined(CONFIG_NET_VLAN)
526+
.get_capabilities = eth_capabilities,
527+
#endif
474528
};
475529

476530
#define _SLIP_L2_LAYER ETHERNET_L2
477531
#define _SLIP_L2_CTX_TYPE NET_L2_GET_CTX_TYPE(ETHERNET_L2)
478532
#define _SLIP_MTU 1500
533+
534+
ETH_NET_DEVICE_INIT(slip, CONFIG_SLIP_DRV_NAME, slip_init, &slip_context_data,
535+
NULL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &slip_if_api,
536+
_SLIP_MTU);
479537
#else
480538

481539
static const struct net_if_api slip_if_api = {
@@ -486,8 +544,8 @@ static const struct net_if_api slip_if_api = {
486544
#define _SLIP_L2_LAYER DUMMY_L2
487545
#define _SLIP_L2_CTX_TYPE NET_L2_GET_CTX_TYPE(DUMMY_L2)
488546
#define _SLIP_MTU 576
489-
#endif
490547

491548
NET_DEVICE_INIT(slip, CONFIG_SLIP_DRV_NAME, slip_init, &slip_context_data,
492549
NULL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &slip_if_api,
493550
_SLIP_L2_LAYER, _SLIP_L2_CTX_TYPE, _SLIP_MTU);
551+
#endif

subsys/net/ip/l2/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ config NET_VLAN
3232
config NET_VLAN_COUNT
3333
int "Max VLAN tags supported in the system"
3434
default 1
35-
range 1 1 if SLIP
3635
range 1 255
3736
depends on NET_VLAN
3837
help

0 commit comments

Comments
 (0)