Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 19 Jun 2002 09:44:20 -0700
From:      Luigi Rizzo <rizzo@icir.org>
To:        julian@freebsd.org
Cc:        net@freebsd.org
Subject:   removing global variables from the network stack
Message-ID:  <20020619094420.C58636@iguana.icir.org>

next in thread | raw e-mail | index | archive | help
Hi,
I am trying to cleanup as much as possible the use of global
variables in the network stack, both for code clarity, and
to ease the use of this code in an SMP context.

The two offenders I am concentrating upon are IPFW/DUMMYNET and DIVERT.
For the former, I am the guilty one:) I know how to fix it.

For DIVERT, I think this is someone else's code, so here's my
understanding of the problem and proposed fix:

The global variable in question is "ip_divert_cookie",
declared in ip_divert.c and used to pass the divert port
to divert_packet(), and from div_output() to ip_output()/ip_input()

For the former the fix is trivial, we just need to add an additional
argument to divert_packet().

For the latter, it *would* be easy to add an argument to ip_output()
but if we do not want to change the interface, perhaps the easiest
trick is to pass the annotation in the same way as it is done for
dummynet info, i.e. using a fake mbuf prepended to the actual chain.
Something like this:

    ip_divert.c::div_output()

        ... make ip_divert_cookie a local variable ...

	struct m_hdr fake_mbuf;

	fake_mbuf.mh_type = MT_DIVERT;
	fake_mbuf.mh_next = m;
	fake_mbuf.mh_len = ip_divert_cookie;
	...
        if ( <outgoing packet> ) {
                error = ip_output(&fake_mbuf, ...);
                ...
        } else { /* incoming packet */
                ...
                ip_input(&fake_mbuf);
        }

    ip_output.c::ip_output()
    ip_output.c::ip_input()

        ... right after local variables instead of fetching ip_divert_cookie

        if (m->m_type == MT_DIVERT) {
                divert_cookie = m->mh_len;
                m = m->mh_next;
        }
        ... continue with regular processing ...

Does this look right ?
As a matter of fact, ip_input() is used only in a couple of places
so it might be possible to change the interface and add a second
parameter to carry the divert_cookie. However the use of an annotation
block in front of it seems a bit less intrusive and easier to extend
to other annotations we might want to add.

	cheers
	luigi
-----------------------------------+-------------------------------------
  Luigi RIZZO, luigi@iet.unipi.it  . Dip. di Ing. dell'Informazione
  http://www.iet.unipi.it/~luigi/  . Universita` di Pisa
  TEL/FAX: +39-050-568.533/522     . via Diotisalvi 2, 56126 PISA (Italy)
  Mobile   +39-347-0373137
-----------------------------------+-------------------------------------

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?20020619094420.C58636>