FreeBSD networking question

ithilgore advent.cloud.strife at gmail.com
Fri Feb 1 22:43:07 EET 2008


Christos Ricudis wrote:
> ithilgore wrote:
>   
>> Kalhspera,
>>    thelw na asxolh8w me ta networking internals tou FreeBSD (kai giati 
>> oxi genika twn *BSD) gia peraiterw emba8unsh ston tomea tou low level 
>> networking kai 8a h8ela merikes sumboules :
>>
>> 1) Exw ksekinhsei na diabazw to tcp-ip illustrated volume 2 (stevens) 
>> alla anaferetai se sxetika palio implementation (4.4 BSD-Lite) pou shmainei oti afenos o 
>> kwdikas stis teleutaies dianomes einai safws pio periplokos kai pio megalos,
>>     
> Ayto to ebgales apo to myalo sou, h ka8hses ontws kai synekrines to 
> TCP/IP implementation tou 4.4BSD-Lite me tou FreeBSD-current?
>
> ...ase, mhn apanthseis.
>
>
>   

den kserw gia sena padws egw blepw ais8htes diafores ston kwdika :
pare paradeigma thn func rip_input apo to raw_ip.c tou FreeBSD 2.0.5 kai 
tou FreeBSD 7.0-RC1

POC:
/********************** 2.0.5 *************************/

void
rip_input(m)
    struct mbuf *m;
{
    register struct ip *ip = mtod(m, struct ip *);
    register struct inpcb *inp;
    struct socket *last = 0;

    ripsrc.sin_addr = ip->ip_src;
    for (inp = ripcb.lh_first; inp != NULL; inp = inp->inp_list.le_next) {
        if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != ip->ip_p)
            continue;
        if (inp->inp_laddr.s_addr &&
                  inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
            continue;
        if (inp->inp_faddr.s_addr &&
                  inp->inp_faddr.s_addr != ip->ip_src.s_addr)
            continue;
        if (last) {
            struct mbuf *n = m_copy(m, 0, (int)M_COPYALL);
            if (n) {
                if (sbappendaddr(&last->so_rcv,
                    (struct sockaddr *)&ripsrc, n,
                    (struct mbuf *)0) == 0)
                    /* should notify about lost packet */
                    m_freem(n);
                else
                    sorwakeup(last);
            }
        }
        last = inp->inp_socket;
    }
    if (last) {
        if (sbappendaddr(&last->so_rcv, (struct sockaddr *)&ripsrc,
            m, (struct mbuf *)0) == 0)
            m_freem(m);
        else
            sorwakeup(last);
    } else {
        m_freem(m);
              ipstat.ips_noproto++;
              ipstat.ips_delivered--;
      }
}

/********************** 7.0-RC1 *************************/

void
rip_input(struct mbuf *m, int off)
{
    struct ip *ip = mtod(m, struct ip *);
    int proto = ip->ip_p;
    struct inpcb *inp, *last;

    INP_INFO_RLOCK(&ripcbinfo);
    ripsrc.sin_addr = ip->ip_src;
    last = NULL;
    LIST_FOREACH(inp, &ripcb, inp_list) {
        INP_LOCK(inp);
        if (inp->inp_ip_p && inp->inp_ip_p != proto) {
    docontinue:
            INP_UNLOCK(inp);
            continue;
        }
#ifdef INET6
        if ((inp->inp_vflag & INP_IPV4) == 0)
            goto docontinue;
#endif
        if (inp->inp_laddr.s_addr &&
            inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
            goto docontinue;
        if (inp->inp_faddr.s_addr &&
            inp->inp_faddr.s_addr != ip->ip_src.s_addr)
            goto docontinue;
        if (jailed(inp->inp_socket->so_cred))
            if (htonl(prison_getip(inp->inp_socket->so_cred)) !=
                ip->ip_dst.s_addr)
                goto docontinue;
        if (last) {
            struct mbuf *n;

            n = m_copy(m, 0, (int)M_COPYALL);
            if (n != NULL)
                (void) raw_append(last, ip, n);
            /* XXX count dropped packet */
            INP_UNLOCK(last);
        }
        last = inp;
    }
    if (last != NULL) {
        if (raw_append(last, ip, m) != 0)
            ipstat.ips_delivered--;
        INP_UNLOCK(last);
    } else {
        m_freem(m);
        ipstat.ips_noproto++;
        ipstat.ips_delivered--;
    }
    INP_INFO_RUNLOCK(&ripcbinfo);
}

kai auto den einai para 1 apo ta polla shmeia.
allwste kai o keramidas to anefere kseka8ara gia tis diafores

ithilgore




More information about the Linux-greek-users mailing list