Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Jun 2002 17:10:21 +0200
From:      Sebastien Petit <spe@selectbourse.net>
To:        freebsd-net@freebsd.org
Subject:   Problem using ng_ether
Message-ID:  <20020614150130.56E86BAE9@sbserv0.intra.selectbourse.net>

next in thread | raw e-mail | index | archive | help
Hi,

I've a problem with ng_ether and xl0 driver, when I connect upper <-> lower 
directly, packets have ip sum to 0 and a wrong tcp and udp cksum. I try to 
use my test code on rl0 driver, and it work fine.
Julian or Archie, can you say me if I must recompute ip/tcp/udp checksum for 
all packets read on upper and then writed on lower hook ?

Here is my code:
This code must normally connect upper and lower together and so the packets 
flow normally upwards and downwards (like if there is nothing connected to 
hooks)

#include <netgraph.h>
#include <netgraph/ng_ether.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <net/ethernet.h>
#include <netinet/tcp.h>

#define HOOKNAME "myhook"
#define HOOKNAME2 "myhook2"

int main(int argc, char **argv)
{
        int csock, dsock;
        int csock2, dsock2;
        struct ngm_connect ngc;
        struct ngm_connect ngc2;
        int bytesread;
        size_t bytesread2;
        unsigned char buf[4096];
        char buf2[4096];
        char hookname[4096];
        fd_set fds;
        u_short *csum;
        int cpt;
        struct ether_header *eth = (struct ether_header *)buf;
        struct ip *iph = (struct ip *)&buf[sizeof(struct ether_header)];
        struct tcphdr *tcph = (struct tcphdr *)&buf[sizeof(struct 
ether_header)+sizeof(struct ip)];

        NgMkSockNode(NULL, &csock, &dsock);
        snprintf(ngc.path, sizeof(ngc.path), "xl0:");
        snprintf(ngc.ourhook, sizeof(ngc.ourhook), HOOKNAME);
        snprintf(ngc.peerhook, sizeof(ngc.peerhook), "upper");
        NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, NGM_CONNECT, &ngc, 
sizeof(ngc));
        snprintf(ngc.path, sizeof(ngc.path), "xl0:");
        snprintf(ngc.ourhook, sizeof(ngc.ourhook), HOOKNAME2);
        snprintf(ngc.peerhook, sizeof(ngc.peerhook), "lower");
        NgSendMsg(csock, ".", NGM_GENERIC_COOKIE, NGM_CONNECT, &ngc, 
sizeof(ngc));
        for (;;) {
                bzero(buf, sizeof(buf));
                bytesread = NgRecvData(dsock, buf, sizeof(buf), hookname);
                printf("bytes = %d\n", bytesread);
                printf("name = %s\n", hookname);
                if (! strcmp(hookname, "myhook")) {
                        printf("%s !\n", hookname);
                        NgSendData(dsock, HOOKNAME2, buf, bytesread);
                }
                else
                if (! strcmp(hookname, "myhook2")) {
                        printf("%s !\n", hookname);
                        NgSendData(dsock, HOOKNAME, buf, bytesread);
                }
        }
}

Output of 'ngctl show xl0:':

[root@artik ~]# ngctl show xl0:
  Name: xl0             Type: ether           ID: 00000001   Num hooks: 2
  Local hook      Peer name       Peer type    Peer ID         Peer hook      
  ----------      ---------       ---------    -------         ---------      
  lower           <unnamed>       socket       00000055        myhook2        
  upper           <unnamed>       socket       00000055        myhook         

If now I try to telnet an other host on the same lan on ssh port, here there 
is the result of tcpdump on this another host:

16:56:06.971008 172.16.2.3.1218 > 172.16.1.1.22: S [bad tcp cksum ea9c!] 
2063189250:2063189250(0) win 65535 <mss 1460> (DF) [tos 0x10]  (ttl 64, id 
4078, len 44, bad cksum 0!)
0x0000   4510 002c 0fee 4000 4006 0000 ac10 0203        E..,..@.@.......
0x0010   ac10 0101 04c2 0016 7af9 c502 0000 0000        ........z.......
0x0020   6002 ffff 5b43 0000 0204 05b4 0000             `...[C........
16:56:09.965572 172.16.2.3.1218 > 172.16.1.1.22: S [bad tcp cksum ea9c!] 
2063189250:2063189250(0) win 65535 <mss 1460> (DF) [tos 0x10]  (ttl 64, id 
54488, len 44, bad cksum 0!)
0x0000   4510 002c d4d8 4000 4006 0000 ac10 0203        E..,..@.@.......
0x0010   ac10 0101 04c2 0016 7af9 c502 0000 0000        ........z.......
0x0020   6002 ffff 5b43 0000 0204 05b4 0000             `...[C........
16:56:12.964827 172.16.2.3.1218 > 172.16.1.1.22: S [bad tcp cksum ea9c!] 
2063189250:2063189250(0) win 65535 <mss 1460> (DF) [tos 0x10]  (ttl 64, id 
5274, len 44, bad cksum 0!)
0x0000   4510 002c 149a 4000 4006 0000 ac10 0203        E..,..@.@.......
0x0010   ac10 0101 04c2 0016 7af9 c502 0000 0000        ........z.......
0x0020   6002 ffff 5b43 0000 0204 05b4 0000             `...[C........
16:56:15.965646 172.16.2.3.1218 > 172.16.1.1.22: S [bad tcp cksum ea9c!] 
2063189250:2063189250(0) win 65535 <mss 1460> (DF) [tos 0x10]  (ttl 64, id 
58146, len 44, bad cksum 0!)
0x0000   4510 002c e322 4000 4006 0000 ac10 0203        E..,."@.@.......
0x0010   ac10 0101 04c2 0016 7af9 c502 0000 0000        ........z.......
0x0020   6002 ffff 5b43 0000 0204 05b4 0000             `...[C........
16:56:18.965003 172.16.2.3.1218 > 172.16.1.1.22: S [bad tcp cksum ea9c!] 
2063189250:2063189250(0) win 65535 <mss 1460> (DF) [tos 0x10]  (ttl 64, id 
25692, len 44, bad cksum 0!)
0x0000   4510 002c 645c 4000 4006 0000 ac10 0203        E..,d\@.@.......
0x0010   ac10 0101 04c2 0016 7af9 c502 0000 0000        ........z.......
0x0020   6002 ffff 5b43 0000 0204 05b4 0000             `...[C........

As you can see, the ip cksum is 0 and tcp cksum is invalid...

This problem doesn't seem to appear on rl driver (I just replace xl0: with 
rl0: on the code) for example and packets flow normally upwards and downwards.

Any ideas ? does my code work perfectly for you or not ?

Thanks
Sebastien.
-- 
spe@selectbourse.net

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020614150130.56E86BAE9>