lwip-devel
[Top][All Lists]
Advanced

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

Re: [lwip-devel] [patch #7993] Add support for transmitting packets with


From: Andreas Bachmann
Subject: Re: [lwip-devel] [patch #7993] Add support for transmitting packets with VLAN headers
Date: Fri, 08 Aug 2014 15:10:37 +0200
User-agent: Roundcube Webmail/1.0.1


Right. Done as in the patch, thanks for it.

I'm using this patch resp. the git master repository git://git.sv.gnu.org/lwip.git
I wrote check- and set-functions in lwipopts.h:

#define LWIP_HOOK_VLAN_CHECK(netif, eth_hdr, vlan_hdr) etherarp_vlan_check(netif, eth_hdr, vlan_hdr) #define LWIP_HOOK_VLAN_SET(netif, eth_hdr, vlan_hdr) etherarp_vlan_set(netif, eth_hdr, vlan_hdr)

Receiving VLAN-tagged frames and reply to it works fine, for example ICMP echo requests and replies. When receiving non-VLAN-tagged frames, it allocated a new pbuf in RAM [icmp.c:icmp_input()] (should not!!) and gets an error when making room for the Ethernet header [etharp.c:etharp_output()]. I think SIZEOF_VLAN_HDR is hard coded and doesn't allow handling non-VLAN-tagged frames and therefore can't be used for both, VLAN-tagged and non-VLAN-tagged frames.

Regards,

Andreas Bachmann


VLAN-tagged frame:
enet_input:
AA BB CC DD EE FF 00 1B 21 5C 22 01 81 00 00 01 ........!\"..... 08 00 45 00 00 4C 00 00 00 00 FF 01 9D 53 0A 29 ..E..L.......S.) 00 02 0A 29 0A 0A 08 00 CD BC 00 00 00 01 00 01 ...)............ 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 ................ 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 .............. ! 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F "#$%&'()*+,-./
pbuf_alloc(length=94)
pbuf_alloc: allocated pbuf 0x101379e4
pbuf_alloc(length=94) == 0x101379e4
lwip_enet_input(): now it's lwIP's time
ethernet_input: dest:aa:bb:cc:dd:ee:ff, src:00:1b:21:5c:22:01, type:8100
etharp_ip_input: updating ETHARP table.
etharp_update_arp_entry: 10.41.0.2 - 00:1B:21:5C:22:01
etharp_find_entry: found matching entry 0
etharp_update_arp_entry: updating stable entry 0
pbuf_header: old 0x10137a04 new 0x10137a16 (-18)
pbuf_header: old 0x10137a16 new 0x10137a2a (-20)
icmp_input: ping
pbuf_header: old 0x10137a2a new 0x101379f4 (54)
pbuf_header: old 0x101379f4 new 0x10137a2a (-54)
pbuf_header: old 0x10137a2a new 0x10137a16 (20)
pbuf_header: old 0x10137a16 new 0x10137a04 (18)
etharp_send_ip: sending packet 0x101379e4
enet_output:
00 1B 21 5C 22 01 AA BB CC DD EE FF 81 00 00 01 ..!\"........... 08 00 45 00 00 4C 00 00 00 00 FF 01 9D 53 0A 29 ..E..L.......S.) 0A 0A 0A 29 00 02 00 00 D5 BC 00 00 00 01 00 01 ...)............ 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 ................ 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 .............. ! 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F "#$%&'()*+,-./
pbuf_free(0x101379e4)
pbuf_free: deallocating 0x101379e4


non-VLAN-tagged frame:
enet_input:
AA BB CC DD EE FF 00 1B 21 5C 22 01 08 00 45 00 ........!\"...E. 00 4C 00 00 00 00 FF 01 9D 53 0A 29 00 02 0A 29 .L.......S.)...) 0A 0A 08 00 CD BC 00 00 00 01 00 01 02 03 04 05 ................ 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 ................ 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 .......... !"#$%
    26 27 28 29 2A 2B 2C 2D  2E 2F                           &'()*+,-./
pbuf_alloc(length=90)
pbuf_alloc: allocated pbuf 0x101379e4
pbuf_alloc(length=90) == 0x101379e4
lwip_enet_input(): now it's lwIP's time
ethernet_input: dest:aa:bb:cc:dd:ee:ff, src:00:1b:21:5c:22:01, type:800
etharp_ip_input: updating ETHARP table.
etharp_update_arp_entry: 10.41.0.2 - 00:1B:21:5C:22:01
etharp_find_entry: found matching entry 0
etharp_update_arp_entry: updating stable entry 0
pbuf_header: old 0x10137a04 new 0x10137a12 (-14)
pbuf_header: old 0x10137a12 new 0x10137a26 (-20)
icmp_input: ping
pbuf_header: failed as 0x101379f0 < 0x101379f4 (not enough space for new header size)
pbuf_header: old 0x10137a26 new 0x10137a12 (20)
pbuf_alloc(length=76)
pbuf_alloc(length=76) == 0x1013865c
pbuf_copy(0x1013865c, 0x101379e4)
pbuf_copy: end of chain reached.
pbuf_header: old 0x1013867c new 0x10138690 (-20)
pbuf_free(0x101379e4)
pbuf_free: deallocating 0x101379e4
pbuf_header: old 0x10138690 new 0x1013867c (20)
pbuf_header: failed as 0x1013866a < 0x1013866c (not enough space for new header size)
etharp_output: could not allocate room for header.
icmp_input: ip_output_if returned an error: �.
pbuf_free(0x1013865c)
pbuf_free: deallocating 0x1013865c


Thread [1] (Suspended)
    11 pbuf_alloc() pbuf.c:212 0x100359e0
    10 icmp_input() icmp.c:157 0x10024df0
    9 ip_input() ip4.c:576 0x10025c48
    8 ethernet_input() etharp.c:1443 0x10048b2c
    7 lwip_enet_input() lwip_enet.c:83 0x10020558
    6 YYY() YYY:554 0x1001bfa8
    5 YYY() YYY:478 0x1001bbd8
    4 XXX() XXX.c:154 0x10014df0
    3 main() main.c:65 0x10048dc8
    2 alt_main() alt_main.c:154 0x10062c18
    1 _start() crt0.S:437 0x10000044

void
icmp_input(struct pbuf *p, struct netif *inp)
{
  [...]

  switch (type) {
  case ICMP_ECHO:

    [...]

#if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
    if (pbuf_header(p, (PBUF_IP_HLEN + PBUF_LINK_HLEN))) {
      /* p is not big enough to contain link headers
       * allocate a new one and copy p into it
       */
      struct pbuf *r;
      /* switch p->payload to ip header */
      if (pbuf_header(p, hlen)) {
LWIP_ASSERT("icmp_input: moving p->payload to ip header failed\n", 0);
        goto memerr;
      }
      /* allocate new packet buffer with space for link headers */
      r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
      if (r == NULL) {
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: allocating new pbuf failed\n"));
        goto memerr;
      }
LWIP_ASSERT("check that first pbuf can hold struct the ICMP header",
                  (r->len >= hlen + sizeof(struct icmp_echo_hdr)));
      /* copy the whole packet including ip header */
      if (pbuf_copy(r, p) != ERR_OK) {
        LWIP_ASSERT("icmp_input: copying to new pbuf failed\n", 0);
        goto memerr;
      }
      iphdr = (struct ip_hdr *)r->payload;
      /* switch r->payload back to icmp header */
      if (pbuf_header(r, -hlen)) {
LWIP_ASSERT("icmp_input: restoring original p->payload failed\n", 0);
        goto memerr;
      }
      /* free the original p */
      pbuf_free(p);
/* we now have an identical copy of p that has room for link headers */
      p = r;
    }

    [...]

  }

  [...]

}


Thread [1] (Suspended)
    14 pbuf_header() pbuf.c:554 0x10036320
    13 etharp_output() etharp.c:908 0x10047904
    12 ip_output_if_src() ip4.c:833 0x100262e4
    11 ip_output_if() ip4.c:670 0x10025dec
    10 icmp_input() icmp.c:223 0x100250d8
    9 ip_input() ip4.c:576 0x10025c48
    8 ethernet_input() etharp.c:1435 0x100489ac
    7 lwip_enet_input() lwip_enet.c:83 0x10020558
    6 YYY() YYY.c:554 0x1001bfa8
    5 YYY() YYY.c:478 0x1001bbd8
    4 XXX() XXX.c:154 0x10014df0
    3 main() main.c:65 0x10048c48
    2 alt_main() alt_main.c:154 0x10062a98
    1 _start() crt0.S:437 0x10000044

err_t
etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr)
{
  struct eth_addr *dest;
  struct eth_addr mcastaddr;
  ip_addr_t *dst_addr = ipaddr;

  LWIP_ASSERT("netif != NULL", netif != NULL);
  LWIP_ASSERT("q != NULL", q != NULL);
  LWIP_ASSERT("ipaddr != NULL", ipaddr != NULL);

  /* make room for Ethernet header - should not fail */
#if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET)
  if (pbuf_header(q, sizeof(struct eth_hdr) + SIZEOF_VLAN_HDR) != 0) {
#else /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */
  if (pbuf_header(q, sizeof(struct eth_hdr)) != 0) {
#endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */
    /* bail out */
    LWIP_DEBUGF(ETHARP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
      ("etharp_output: could not allocate room for header.\n"));
    LINK_STATS_INC(link.lenerr);
    return ERR_BUF;
  }

  [...]

}





reply via email to

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