[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Add support for outgoing VLAN tags?

From: web
Subject: Re: [lwip-users] Add support for outgoing VLAN tags?
Date: Mon, 28 Nov 2011 14:09:39 +0100

On 8 nov 2011 21:05 "address@hidden" <address@hidden> wrote:
address@hidden wrote:
Yes, it is. It is a mandatory feature for certain protocols, such as
the industrial control protocol "EtherNet/IP"

That's interesting. Since I know of at least one Ethernet/IP stack being
ported to linux, do you know whether/how linux allows changing the VLAN
header per socket?
The problem with adding VLAN PCP to LwIP is that a socket level
variable must somehow be communicated down to the link layer for each
frame. There does not seem to be a easy way of doing this.
Thinkig about it, we already have a mechanism for that: the per-pcb ARP
entry cache. In the same manner as this, we could add members to struct
netif which configure VLAN settings and change them before calling one
of the ip_output functions (although that set/reset code would be
scattered around tcp, udp, raw, icmp and igmp).


I have rewritten our VLAN PCP implementation, taking advantage of the ARP entry cache feature.

In short, these are the modifications I have done.

This snippet of code occurs in several places in LwIP:
  netif->addr_hint = &(pcb->addr_hint);
  err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
  netif->addr_hint = NULL;

In all places I have replaced it with macros like this:
  LWIP_SET_HINTS( netif, pcb );
  err = ip_output_if(q, src_ip, dst_ip, pcb->ttl, pcb->tos, IP_PROTO_UDPLITE, netif);
  LWIP_RESET_HINTS( netif );
The macro copies both the ARP entry cache hint, as well as the VLAN PCP variable.

I have changed the last argument of the function ip_output_hinted() from "u8_t *addr_hint" to "struct ip_pcb* pcb_hint".
This allows other information besides the ARP entry cache to be copied from the pcb to the netif.

The function tcp_rst did not support the ARP entry cache feature. I have added it by modifying tcp_rst like this:
tcp_rst(u32_t seqno, u32_t ackno,
  ip_addr_t *local_ip, ip_addr_t *remote_ip,
  u16_t local_port, u16_t remote_port
  , struct ip_pcb *pcb
#endif /* LWIP_USE_HINTS */

I have modified pbuf_alloc to allocate room for the VLAN tag, like this:
  case PBUF_LINK:
    /* add room for link layer header */
    offset += PBUF_LINK_HLEN;
    /* add room for VLAN header */
    offset += PBUF_VLAN_HLEN;
#endif /* LWIP_VLAN_PCP */

There is also new code in place in etharp_output to actually add the VLAN tag.

What do you think about this solution?

Timmy Brolin

reply via email to

[Prev in Thread] Current Thread [Next in Thread]