What's wrong with netgraph NG_FWD_NEW_DATA?

Chris Dionissopoulos dionch at freemail.gr
Mon Oct 17 03:02:08 PDT 2005


Hi ppl,

Trying to split inbound traffic based on layer2 characteristics,
 i have create a new netgraph module(ng_l2split) using
ng_vlan(4) as reference. The design and implementation is
pretty simple as ng_vlan :

xl0:upper
    |
+---------+
| ng_l2split|-----ng0 (ng_eiface on ngeth0)
+---------+   ( --- ng1,2,....)
   |
 xl0:lower

ng_l2plit has 2 basic hooks as descriped in ng_vlan(4) man page:
- downstream hook (attached to physical's "lower" )
- nomatch hook (attached to physical's "upper" )

and for every ng_eiface node you attach you must provide a
mac address for filtering  (later this will be automated).

i.e.
#!/bin/sh

ngctl -f- <<EOF
shutdown xl0:
mkpeer xl0: l2split lower downstream
name xl0:lower sp0
connect xl0: sp0: upper nomatch
EOF

ifconfig ngeth0 down
ifconfig ngeth0 link 01:02:03:04:05:00
ifconfig ngeth0 192.168.1.2/24
ifconfig ngeth0 up

ngctl msg xl0: setautosrc 0
ngctl msg xl0: setpromisc 1
ngctl msg ngeth0: setautosrc 0
ngctl msg ngeth0: setpromisc 1

ngctl connect ngeth0: sp0: lower link0
ngctl msg sp0: addfilter '{ addr=01:02:03:04:05:00 hook="link0" }'

gw0# ngctl list
There are 8 total nodes:
  Name: ngctl73383      Type: socket          ID: 000000fd   Num hooks: 0
  Name: sp0             Type: l2split         ID: 000000f4   Num hooks: 3
  Name: ngeth1          Type: ether           ID: 000000d7   Num hooks: 0
  Name: ng1             Type: eiface          ID: 000000d6   Num hooks: 0
  Name: ngeth0          Type: ether           ID: 0000000a   Num hooks: 0
  Name: ng0             Type: eiface          ID: 00000009   Num hooks: 1
  Name: xl0             Type: ether           ID: 00000001   Num hooks: 2
gw0# ngctl show sp0:
  Name: sp0             Type: l2split         ID: 000000f4   Num hooks: 3
  Local hook      Peer name       Peer type    Peer ID         Peer hook
  ----------      ---------       ---------    -------         ---------
  link0           ng0             eiface       00000009        ether
  nomatch         xl0             ether        00000001        upper
  downstream      xl0             ether        00000001        lower
gw0# ngctl msg ng0: getifname
Rec'd response "getifname" (1) from "[9]:":
Args:   "ngeth0"

gw0#ifconfig ngeth0
ngeth0: 
flags=28943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST,PPROMISC> mtu 
1500
        inet6 fe80::260:8ff:fee8:589e%ngeth0 prefixlen 64 scopeid 0x6
        inet 192.168.1.2 netmask 0xffffff00 broadcast 192.168.1.255
        ether 01:02:03:04:05:00

Traffic initiated localy flows prefectly through ngeth0 and xl0 
interfaces, but
this is not happen for traffic that comes from outside. It seems that 
doesn't
 arrive to ngeth0 upper level protocols.
Long story short:
o physical interface works fine.
o app:stack-->ngeth0--->ng0---->xl0:low--->wire   [WORKS]
o wire --->xl0:low--->ng0--->ngeth0--->stack:app  [FAILED]
                                           [works]      [failed to reply]

Here is my rcvdata function :
-------ng_l2split.c part-----------
static int
ng_l2split_rcvdata(hook_p hook, item_p item)
{
    const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook));
    struct ether_header *eh;
    struct ether_addr eaddr;
    int error;
    struct mbuf *m;
    struct filter *f;

    /* Make sure we have an entire header. */
    NGI_GET_M(item, m);
    if (m->m_len < sizeof(*eh) &&
        (m = m_pullup(m, sizeof(*eh))) == NULL) {
        NG_FREE_ITEM(item);
        return (EINVAL);
    }
    eh = mtod(m, struct ether_header *);
    if (hook == priv->downstream_hook) {
        /*
         * If from downstream, select between a match hook
         * or the nomatch hook.
         */
        bcopy(eh->ether_dhost,eaddr.octet, sizeof(eh->ether_dhost));
           
        if ((f = ng_l2split_findentry(priv, &eaddr)) != NULL) {
            NG_FWD_NEW_DATA(error, item, f->hook, m);
            printf("send");
            }
         else
            NG_FWD_NEW_DATA(error, item, priv->nomatch_hook, m);
    } else
        NG_FWD_NEW_DATA(error, item, priv->downstream_hook, m);
    return (error);
}
------------------------------------

Any idea what i'm doing wrong?
Is NG_FWD_NEW_DATA improperly used?

TIA,

Chris.

p.s. I'm using FreeBSD6-beta5 (Sept-30)

____________________________________________________________________
http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.


More information about the freebsd-net mailing list