tech-net archive

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

Question about pfil


I'm implementing a loadable kernel module for source routing in netbsd system.
Its function is to set ip option for every packet which goes out.
By doing that, I'd like to make every packet follow the predefined path.
At the initialization of my LKM, it registers a hook like following.

sr_insert_routing_path(void *arg, struct mbuf **m,
                struct ifnet *ifp, int dir )
        struct mbuf * optionM;
        struct ipoption * p;
        int hlen=0;
        struct ip *ip = mtod(*m, struct ip *);

        optionM = m_get(M_DONTWAIT, MT_DATA);
        if( optionM!=0 && ip->ip_v == IPVERSION && ip->ip_hl==5 )
                p = mtod(optionM, struct ipoption *);

                struct in_addr tmpAddr;
                inet_aton("", &tmpAddr);

                p->ipopt_dst.s_addr = tmpAddr.s_addr;
                p->ipopt_list[0] = IPOPT_NOP;   // NOP
                p->ipopt_list[1] = IPOPT_SSRR;
                p->ipopt_list[2] = 3 + (1)*sizeof(struct in_addr);
                p->ipopt_list[3] = 4;                   // ptr

                *((in_addr_t *)&(p->ipopt_list[4]))=ip->ip_dst.s_addr;
                optionM->m_len = 12;

                *m = ip_insertoptions(*m, optionM, &hlen);
        if(optionM!=0) m_free( optionM );
        return 0;

I brought ip_insertoptions function, and slightly modified to change
the ip_hl variable of the packet.
As you see, it's not fully implemented, so it just add an intermediate
address before the destination.
The problem is that even though I changed the ip_dst value of the
packet(through ip_insertoption) to the intermediate address, when I
captured the output packet, the mac address did not change.
It was the mac address of the original destination.
According to my understanding, when this hook was called, the mac
header does not exist, and
after processing of this hook, the mac processing is done.
So, I think the mac address is determined by the new ip address.
Am I right? And do you have any suggestion to solve this problem?

Youngbin Im

Home | Main Index | Thread Index | Old Index