From owner-freebsd-net@FreeBSD.ORG Mon Aug 29 07:42:18 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EF16C16A41F; Mon, 29 Aug 2005 07:42:18 +0000 (GMT) (envelope-from doconnor@gsoft.com.au) Received: from cain.gsoft.com.au (cain.gsoft.com.au [203.31.81.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id F400343D49; Mon, 29 Aug 2005 07:42:17 +0000 (GMT) (envelope-from doconnor@gsoft.com.au) Received: from inchoate.gsoft.com.au (inchoate.gsoft.com.au [203.31.81.47]) (authenticated bits=0) by cain.gsoft.com.au (8.13.4/8.13.4) with ESMTP id j7T7g6FQ012944 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO); Mon, 29 Aug 2005 17:12:12 +0930 (CST) (envelope-from doconnor@gsoft.com.au) From: "Daniel O'Connor" To: Gleb Smirnoff Date: Mon, 29 Aug 2005 17:11:47 +0930 User-Agent: KMail/1.8.1 References: <200507290834.10268.doconnor@gsoft.com.au> <200508291449.15427.doconnor@gsoft.com.au> <20050829064040.GB48425@cell.sick.ru> In-Reply-To: <20050829064040.GB48425@cell.sick.ru> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart20461195.PJtWxlt2JW"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200508291712.02881.doconnor@gsoft.com.au> X-Spam-Score: -2.82 () ALL_TRUSTED X-Scanned-By: MIMEDefang 2.51 on 203.31.81.10 Cc: freebsd-net@freebsd.org, Julian Elischer Subject: Re: AltQ + ng_iface X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Aug 2005 07:42:19 -0000 --nextPart20461195.PJtWxlt2JW Content-Type: multipart/mixed; boundary="Boundary-01=_9wrEDOABlgXfhqY" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_9wrEDOABlgXfhqY Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On Monday 29 August 2005 16:10, Gleb Smirnoff wrote: > D> (I'll try it later but a definitive answer would be nice :) > > If you have put smth into ng_iface_start(), then you should do this > stuff via ng_send_fn(). OK. > Sorry, that I haven't yet feedbacked on your patches. I'll probably look > at them after 6.0-RELEASE. No problem :) I have attached an updated (untested - but it compiles! version) =2D-=20 Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au "The nice thing about standards is that there are so many of them to choose from." -- Andrew Tanenbaum GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C --Boundary-01=_9wrEDOABlgXfhqY Content-Type: text/x-diff; charset="koi8-r"; name="ng_iface-altq2.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="ng_iface-altq2.diff" Index: sys/netgraph/ng_iface.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/CVS-Repository/src/sys/netgraph/ng_iface.c,v retrieving revision 1.44 diff -u -p -r1.44 ng_iface.c =2D-- sys/netgraph/ng_iface.c 9 Aug 2005 10:19:59 -0000 1.44 +++ sys/netgraph/ng_iface.c 29 Aug 2005 06:05:19 -0000 @@ -107,6 +107,14 @@ const static struct iffam gFamilies[] =3D=20 }; #define NUM_FAMILIES (sizeof(gFamilies) / sizeof(*gFamilies)) =20 +#define NGM_MTAG_ID_IFFAM 29 + +/* Tag for mbufs to tell ng_iface_start where to send them */ +struct iffamtag { + struct m_tag tag; + iffam_p iffam_p; +}; + /* Node private data */ struct ng_iface_private { struct ifnet *ifp; /* Our interface */ @@ -118,6 +126,7 @@ typedef struct ng_iface_private *priv_p; =20 /* Interface methods */ static void ng_iface_start(struct ifnet *ifp); +static void ng_iface_start2(node_p node, hook_p hook, void *arg1, int arg2= ); static int ng_iface_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data); static int ng_iface_output(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst, struct rtentry *rt0); @@ -351,11 +360,11 @@ static int ng_iface_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt0) { =2D const priv_p priv =3D (priv_p) ifp->if_softc; const iffam_p iffam =3D get_iffam_from_af(dst->sa_family); =2D int len, error =3D 0; + int error =3D 0; u_int32_t af; =2D + struct iffamtag *mtag; +=09 /* Check interface flags */ if (!((ifp->if_flags & IFF_UP) && (ifp->if_drv_flags & IFF_DRV_RUNNING))) { @@ -380,28 +389,71 @@ ng_iface_output(struct ifnet *ifp, struc return (EAFNOSUPPORT); } =20 =2D /* Copy length before the mbuf gets invalidated */ =2D len =3D m->m_pkthdr.len; + /* Tag mbuf with hook information */ + /* XXX: kind of dumb that the alloc routine adds the size of + * struct mtag adds to our length, this make it hard to + * allocate the correct size.. */ + mtag =3D (struct iffamtag *)m_tag_alloc(NGM_MTAG_ID_IFFAM, NGM_MTAG_ID_IF= =46AM,=20 + sizeof(struct iffamtag) - sizeof(struct m_tag), M_NOWAIT); + if (mtag =3D=3D NULL) + return (ENOBUFS); + mtag->iffam_p =3D iffam; + m_tag_prepend(m, (struct m_tag *)mtag); +=09 + IFQ_HANDOFF(ifp, m, error); +=09 + return (error); =20 =2D /* Send packet; if hook is not connected, mbuf will get freed. */ =2D NG_SEND_DATA_ONLY(error, *get_hook_from_iffam(priv, iffam), m); =20 =2D /* Update stats */ =2D if (error =3D=3D 0) { =2D ifp->if_obytes +=3D len; =2D ifp->if_opackets++; =2D } =2D return (error); } =20 /* =2D * This routine should never be called + * Called to move queued packets off the interface. + * + * We wait for netgraph to call us back when we can really move the + * data */ =2D static void ng_iface_start(struct ifnet *ifp) { =2D if_printf(ifp, "%s called?", __func__); + const priv_p priv =3D (priv_p)ifp->if_softc; + + ng_send_fn(priv->node, NULL, &ng_iface_start2, ifp, 0); +} + +static void +ng_iface_start2(node_p node, hook_p hook, void *arg1, int arg2) +{ + struct ifnet *ifp =3D arg1; + const priv_p priv =3D (priv_p) ifp->if_softc; + struct iffamtag *mtag; + struct mbuf *m; + int error =3D 0, len; +=09 + if_printf(ifp, "%s called\n", __func__); + while (1) { + IFQ_DRV_DEQUEUE(&ifp->if_snd, m); + if (m =3D=3D NULL) + break; + =20 + mtag =3D (struct iffamtag *)m_tag_locate(m, NGM_MTAG_ID_IFFAM, NGM_MTAG_= ID_IFFAM, NULL); + if (mtag =3D=3D NULL) { /* mbuf with no tag? shouldn't be possible */ + if_printf(ifp, "mbuf found without a tag, discarding\n"); + m_freem(m); /* XXX: does this free tags too? */ + } + =09 + /* Copy length before the mbuf gets invalidated */ + len =3D m->m_pkthdr.len; + + /* Send packet; if hook is not connected, mbuf will get freed. */ + NG_SEND_DATA_ONLY(error, *get_hook_from_iffam(priv, mtag->iffam_p), m); + + /* Update stats */ + if (error =3D=3D 0) { + ifp->if_obytes +=3D len; + ifp->if_opackets++; + } + } } =20 /* @@ -493,13 +545,15 @@ ng_iface_constructor(node_p node) ifp->if_start =3D ng_iface_start; ifp->if_ioctl =3D ng_iface_ioctl; ifp->if_watchdog =3D NULL; =2D ifp->if_snd.ifq_maxlen =3D IFQ_MAXLEN; ifp->if_mtu =3D NG_IFACE_MTU_DEFAULT; ifp->if_flags =3D (IFF_SIMPLEX|IFF_POINTOPOINT|IFF_NOARP|IFF_MULTICAST); ifp->if_type =3D IFT_PROPVIRTUAL; /* XXX */ ifp->if_addrlen =3D 0; /* XXX */ ifp->if_hdrlen =3D 0; /* XXX */ ifp->if_baudrate =3D 64000; /* XXX */ + IFQ_SET_MAXLEN(&ifp->if_snd, IFQ_MAXLEN); + ifp->if_snd.ifq_drv_maxlen =3D IFQ_MAXLEN; + IFQ_SET_READY(&ifp->if_snd); =20 /* Give this node the same name as the interface (if possible) */ if (ng_name_node(node, ifp->if_xname) !=3D 0) --Boundary-01=_9wrEDOABlgXfhqY-- --nextPart20461195.PJtWxlt2JW Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (FreeBSD) iD8DBQBDErxK5ZPcIHs/zowRAoIsAKCnYjXo4N65AlKpyQtuia9Qtk/khgCfYTAp SrEFAJ/bypozOY8KouvrlNY= =snMo -----END PGP SIGNATURE----- --nextPart20461195.PJtWxlt2JW--