On Tue, Mar 18, 2014 at 12:28:41PM +0100, Martin Pieuchot wrote:
> On 18/03/14(Tue) 11:26, Mike Belopuhov wrote:
> > On 18 March 2014 07:20, Claudio Jeker <[email protected]> wrote:
> > > On Mon, Mar 17, 2014 at 11:41:38AM -0600, Theo de Raadt wrote:
> > >> > What about using a more generic name which is not bound to 80211 since 
> > >> > the
> > >> > field is a generic pointer. This may allow us to use something similar 
> > >> > in
> > >> > other drivers like mpe(4), gif(4), gre(4).
> > >>
> > >> That is basically the only thought I had.  I mean you could also start
> > >> passing it as a mbuf tag, but probably don't want the allocate/free
> > >> overhead.
> > >
> > > It would only make sense to use mbuf tags if the allocate/lookup/free
> > > path of mbuf tags can be made very small.
> > 
> > meh.  i'd say the cookie pointer is fine here.
> > 
> > > Did somebody profile them after the switch to a pool backend?
> > >
> > 
> > that i did, yes.
> 
> So here's a diff with a more generic name for the pointer and an update
> of the structure in the manpage, ok?

Yeah, lets go with this. OK claudio@
 
> diff --git share/man/man9/mbuf.9 share/man/man9/mbuf.9
> index e3db548..ed0a511 100644
> --- share/man/man9/mbuf.9
> +++ share/man/man9/mbuf.9
> @@ -119,6 +119,7 @@ struct pkthdr {
>       u_int16_t csum_flags;
>       u_int16_t ether_vtag;
>       u_int   rdomain;
> +     void    *ph_cookie;
>       struct  pkthdr_pf pf;
>  };
>  
> diff --git sys/dev/ic/acx.c sys/dev/ic/acx.c
> index 39910bc..07c04e6 100644
> --- sys/dev/ic/acx.c
> +++ sys/dev/ic/acx.c
> @@ -948,8 +948,7 @@ acx_start(struct ifnet *ifp)
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               /* first dequeue management frames */
>               if (m != NULL) {
> -                     ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
> -                     m->m_pkthdr.rcvif = NULL;
> +                     ni = m->m_pkthdr.ph_cookie;
>  
>                       /*
>                        * probe response mgmt frames are handled by the
> @@ -976,8 +975,7 @@ acx_start(struct ifnet *ifp)
>                       /* then dequeue packets on the powersave queue */
>                       IF_DEQUEUE(&ic->ic_pwrsaveq, m);
>                       if (m != NULL) {
> -                             ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
> -                             m->m_pkthdr.rcvif = NULL;
> +                             ni = m->m_pkthdr.ph_cookie;
>                               goto encapped;
>                       } else {
>                               IFQ_DEQUEUE(&ifp->if_snd, m);
> diff --git sys/dev/ic/ath.c sys/dev/ic/ath.c
> index 83cd233..6c1bdca 100644
> --- sys/dev/ic/ath.c
> +++ sys/dev/ic/ath.c
> @@ -897,17 +897,7 @@ ath_start(struct ifnet *ifp)
>                       }
>                       wh = mtod(m, struct ieee80211_frame *);
>               } else {
> -                     /*
> -                      * Hack!  The referenced node pointer is in the
> -                      * rcvif field of the packet header.  This is
> -                      * placed there by ieee80211_mgmt_output because
> -                      * we need to hold the reference with the frame
> -                      * and there's no other way (other than packet
> -                      * tags which we consider too expensive to use)
> -                      * to pass it along.
> -                      */
> -                     ni = (struct ieee80211_node *) m->m_pkthdr.rcvif;
> -                     m->m_pkthdr.rcvif = NULL;
> +                     ni = m->m_pkthdr.ph_cookie;
>  
>                       wh = mtod(m, struct ieee80211_frame *);
>                       if ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) ==
> diff --git sys/dev/ic/athn.c sys/dev/ic/athn.c
> index 3aa4f0b..dafd00a 100644
> --- sys/dev/ic/athn.c
> +++ sys/dev/ic/athn.c
> @@ -2554,7 +2554,7 @@ athn_start(struct ifnet *ifp)
>               /* Send pending management frames first. */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> @@ -2562,7 +2562,7 @@ athn_start(struct ifnet *ifp)
>  
>               IF_DEQUEUE(&ic->ic_pwrsaveq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/ic/atw.c sys/dev/ic/atw.c
> index 443c1c0..8a0fd64 100644
> --- sys/dev/ic/atw.c
> +++ sys/dev/ic/atw.c
> @@ -3605,8 +3605,7 @@ atw_start(struct ifnet *ifp)
>                */
>               IF_DEQUEUE(&ic->ic_mgtq, m0);
>               if (m0 != NULL) {
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>               } else {
>                       /* send no data packets until we are associated */
>                       if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/ic/bwi.c sys/dev/ic/bwi.c
> index 1ac1cde..923b315 100644
> --- sys/dev/ic/bwi.c
> +++ sys/dev/ic/bwi.c
> @@ -7202,8 +7202,7 @@ bwi_start(struct ifnet *ifp)
>               if (m != NULL) {
>                       IF_DEQUEUE(&ic->ic_mgtq, m);
>  
> -                     ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
> -                     m->m_pkthdr.rcvif = NULL;
> +                     ni = m->m_pkthdr.ph_cookie;
>  
>                       mgt_pkt = 1;
>               } else {
> diff --git sys/dev/ic/malo.c sys/dev/ic/malo.c
> index 1d4e370..7f80e2c 100644
> --- sys/dev/ic/malo.c
> +++ sys/dev/ic/malo.c
> @@ -1026,8 +1026,7 @@ malo_start(struct ifnet *ifp)
>                       }
>                       IF_DEQUEUE(&ic->ic_mgtq, m0);
>  
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
> diff --git sys/dev/ic/rt2560.c sys/dev/ic/rt2560.c
> index 199fe8f..3d4c350 100644
> --- sys/dev/ic/rt2560.c
> +++ sys/dev/ic/rt2560.c
> @@ -1945,8 +1945,7 @@ rt2560_start(struct ifnet *ifp)
>                       }
>                       IF_DEQUEUE(&ic->ic_mgtq, m0);
>  
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
> diff --git sys/dev/ic/rt2661.c sys/dev/ic/rt2661.c
> index 393b84c..498ae26 100644
> --- sys/dev/ic/rt2661.c
> +++ sys/dev/ic/rt2661.c
> @@ -1947,8 +1947,7 @@ rt2661_start(struct ifnet *ifp)
>                       }
>                       IF_DEQUEUE(&ic->ic_mgtq, m0);
>  
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
> diff --git sys/dev/ic/rt2860.c sys/dev/ic/rt2860.c
> index 21ed2f2..17f1672 100644
> --- sys/dev/ic/rt2860.c
> +++ sys/dev/ic/rt2860.c
> @@ -1758,7 +1758,7 @@ rt2860_start(struct ifnet *ifp)
>               /* send pending management frames first */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> @@ -1767,7 +1767,7 @@ rt2860_start(struct ifnet *ifp)
>               /* send buffered frames for power-save mode */
>               IF_DEQUEUE(&ic->ic_pwrsaveq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>  
> diff --git sys/dev/ic/rtw.c sys/dev/ic/rtw.c
> index 0262242..c126dec 100644
> --- sys/dev/ic/rtw.c
> +++ sys/dev/ic/rtw.c
> @@ -1504,7 +1504,7 @@ rtw_intr_beacon(struct rtw_softc *sc, u_int16_t isr)
>                           sc->sc_dev.dv_xname);
>                       return;
>               }
> -             m->m_pkthdr.rcvif = (void *)ieee80211_ref_node(ic->ic_bss);
> +             m->m_pkthdr.ph_cookie = ieee80211_ref_node(ic->ic_bss);
>               IF_ENQUEUE(&sc->sc_beaconq, m);
>               rtw_start(&sc->sc_if);
>       }
> @@ -2706,8 +2706,7 @@ rtw_80211_dequeue(struct rtw_softc *sc, struct ifqueue 
> *ifq, int pri,
>               return NULL;
>       }
>       IF_DEQUEUE(ifq, m);
> -     *nip = (struct ieee80211_node *)m->m_pkthdr.rcvif;
> -     m->m_pkthdr.rcvif = NULL;
> +     *nip = m->m_pkthdr.ph_cookie;
>       return m;
>  }
>  
> diff --git sys/dev/pci/if_iwn.c sys/dev/pci/if_iwn.c
> index 65a9da5..1a7a260 100644
> --- sys/dev/pci/if_iwn.c
> +++ sys/dev/pci/if_iwn.c
> @@ -3064,7 +3064,7 @@ iwn_start(struct ifnet *ifp)
>               /* Send pending management frames first. */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/pci/if_wpi.c sys/dev/pci/if_wpi.c
> index 635fc73..79bbf73 100644
> --- sys/dev/pci/if_wpi.c
> +++ sys/dev/pci/if_wpi.c
> @@ -1926,7 +1926,7 @@ wpi_start(struct ifnet *ifp)
>               /* Send pending management frames first. */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/usb/if_athn_usb.c sys/dev/usb/if_athn_usb.c
> index 0b46741..c7b31b5 100644
> --- sys/dev/usb/if_athn_usb.c
> +++ sys/dev/usb/if_athn_usb.c
> @@ -2009,7 +2009,7 @@ athn_usb_start(struct ifnet *ifp)
>               /* Send pending management frames first. */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/usb/if_atu.c sys/dev/usb/if_atu.c
> index e5a698a..cab5d54 100644
> --- sys/dev/usb/if_atu.c
> +++ sys/dev/usb/if_atu.c
> @@ -2013,17 +2013,7 @@ atu_start(struct ifnet *ifp)
>                       DPRINTFN(25, ("%s: atu_start: mgmt packet\n",
>                           sc->atu_dev.dv_xname));
>  
> -                     /*
> -                      * Hack!  The referenced node pointer is in the
> -                      * rcvif field of the packet header.  This is
> -                      * placed there by ieee80211_mgmt_output because
> -                      * we need to hold the reference with the frame
> -                      * and there's no other way (other than packet
> -                      * tags which we consider too expensive to use)
> -                      * to pass it along.
> -                      */
> -                     ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
> -                     m->m_pkthdr.rcvif = NULL;
> +                     ni = m->m_pkthdr.ph_cookie;
>  
>                       wh = mtod(m, struct ieee80211_frame *);
>                       /* sc->sc_stats.ast_tx_mgmt++; */
> diff --git sys/dev/usb/if_otus.c sys/dev/usb/if_otus.c
> index 7075713..2ef985c 100644
> --- sys/dev/usb/if_otus.c
> +++ sys/dev/usb/if_otus.c
> @@ -1438,7 +1438,7 @@ otus_start(struct ifnet *ifp)
>               /* Send pending management frames first. */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/usb/if_ral.c sys/dev/usb/if_ral.c
> index ac663f7..55c9fc9 100644
> --- sys/dev/usb/if_ral.c
> +++ sys/dev/usb/if_ral.c
> @@ -1255,8 +1255,7 @@ ural_start(struct ifnet *ifp)
>                       }
>                       IF_DEQUEUE(&ic->ic_mgtq, m0);
>  
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
> diff --git sys/dev/usb/if_rum.c sys/dev/usb/if_rum.c
> index 548b23a..9fa8b83 100644
> --- sys/dev/usb/if_rum.c
> +++ sys/dev/usb/if_rum.c
> @@ -1274,8 +1274,7 @@ rum_start(struct ifnet *ifp)
>                       }
>                       IF_DEQUEUE(&ic->ic_mgtq, m0);
>  
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
> diff --git sys/dev/usb/if_run.c sys/dev/usb/if_run.c
> index 214cf12..a7e1863 100644
> --- sys/dev/usb/if_run.c
> +++ sys/dev/usb/if_run.c
> @@ -2273,7 +2273,7 @@ run_start(struct ifnet *ifp)
>               /* send pending management frames first */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/usb/if_uath.c sys/dev/usb/if_uath.c
> index ec68522..2e61140 100644
> --- sys/dev/usb/if_uath.c
> +++ sys/dev/usb/if_uath.c
> @@ -1492,8 +1492,7 @@ uath_start(struct ifnet *ifp)
>                       }
>                       IF_DEQUEUE(&ic->ic_mgtq, m0);
>  
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
> diff --git sys/dev/usb/if_upgt.c sys/dev/usb/if_upgt.c
> index 3d371f1..c2fd616 100644
> --- sys/dev/usb/if_upgt.c
> +++ sys/dev/usb/if_upgt.c
> @@ -1410,8 +1410,7 @@ upgt_start(struct ifnet *ifp)
>                       /* management frame */
>                       IF_DEQUEUE(&ic->ic_mgtq, m);
>  
> -                     ni = (struct ieee80211_node *)m->m_pkthdr.rcvif;
> -                     m->m_pkthdr.rcvif = NULL;
> +                     ni = m->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m, BPF_DIRECTION_OUT);
> diff --git sys/dev/usb/if_urtw.c sys/dev/usb/if_urtw.c
> index 1bc4c5c..f3e6372 100644
> --- sys/dev/usb/if_urtw.c
> +++ sys/dev/usb/if_urtw.c
> @@ -2496,8 +2496,7 @@ urtw_start(struct ifnet *ifp)
>                               break;
>                       }
>                       IF_DEQUEUE(&ic->ic_mgtq, m0);
> -                     ni = (struct ieee80211_node *)m0->m_pkthdr.rcvif;
> -                     m0->m_pkthdr.rcvif = NULL;
> +                     ni = m0->m_pkthdr.ph_cookie;
>  #if NBPFILTER > 0
>                       if (ic->ic_rawbpf != NULL)
>                               bpf_mtap(ic->ic_rawbpf, m0, BPF_DIRECTION_OUT);
> diff --git sys/dev/usb/if_urtwn.c sys/dev/usb/if_urtwn.c
> index f78f185..7ac5d21 100644
> --- sys/dev/usb/if_urtwn.c
> +++ sys/dev/usb/if_urtwn.c
> @@ -1919,7 +1919,7 @@ urtwn_start(struct ifnet *ifp)
>               /* Send pending management frames first. */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/dev/usb/if_zyd.c sys/dev/usb/if_zyd.c
> index e75c267..fbc17b2 100644
> --- sys/dev/usb/if_zyd.c
> +++ sys/dev/usb/if_zyd.c
> @@ -2230,7 +2230,7 @@ zyd_start(struct ifnet *ifp)
>               /* send pending management frames first */
>               IF_DEQUEUE(&ic->ic_mgtq, m);
>               if (m != NULL) {
> -                     ni = (void *)m->m_pkthdr.rcvif;
> +                     ni = m->m_pkthdr.ph_cookie;
>                       goto sendit;
>               }
>               if (ic->ic_state != IEEE80211_S_RUN)
> diff --git sys/net80211/ieee80211_output.c sys/net80211/ieee80211_output.c
> index 3c77605..2563e16 100644
> --- sys/net80211/ieee80211_output.c
> +++ sys/net80211/ieee80211_output.c
> @@ -202,17 +202,16 @@ ieee80211_mgmt_output(struct ifnet *ifp, struct 
> ieee80211_node *ni,
>       ni->ni_inact = 0;
>  
>       /*
> -      * Yech, hack alert!  We want to pass the node down to the
> -      * driver's start routine.  We could stick this in an m_tag
> -      * and tack that on to the mbuf.  However that's rather
> -      * expensive to do for every frame so instead we stuff it in
> -      * the rcvif field since outbound frames do not (presently)
> -      * use this.
> +      * We want to pass the node down to the driver's start
> +      * routine.  We could stick this in an m_tag and tack that
> +      * on to the mbuf.  However that's rather expensive to do
> +      * for every frame so instead we stuff it in a special pkthdr
> +      * field.
>        */
>       M_PREPEND(m, sizeof(struct ieee80211_frame), M_DONTWAIT);
>       if (m == NULL)
>               return ENOMEM;
> -     m->m_pkthdr.rcvif = (void *)ni;
> +     m->m_pkthdr.ph_cookie = ni;
>  
>       wh = mtod(m, struct ieee80211_frame *);
>       wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | IEEE80211_FC0_TYPE_MGT | type;
> @@ -1864,7 +1863,7 @@ ieee80211_beacon_alloc(struct ieee80211com *ic, struct 
> ieee80211_node *ni)
>  #endif
>  
>       m->m_pkthdr.len = m->m_len = frm - mtod(m, u_int8_t *);
> -     m->m_pkthdr.rcvif = (void *)ni;
> +     m->m_pkthdr.ph_cookie = ni;
>  
>       return m;
>  }
> @@ -1914,10 +1913,10 @@ ieee80211_pwrsave(struct ieee80211com *ic, struct 
> mbuf *m,
>       } else {
>               IF_ENQUEUE(&ni->ni_savedq, m);
>               /*
> -              * Similar to ieee80211_mgmt_output, store the node in the
> -              * rcvif field.
> +              * Similar to ieee80211_mgmt_output, store the node in a
> +              * special pkthdr field.
>                */
> -             m->m_pkthdr.rcvif = (void *)ni;
> +             m->m_pkthdr.ph_cookie = ni;
>       }
>       return 1;
>  }
> diff --git sys/sys/mbuf.h sys/sys/mbuf.h
> index 3a9d0ff..40f8fea 100644
> --- sys/sys/mbuf.h
> +++ sys/sys/mbuf.h
> @@ -111,13 +111,14 @@ struct pkthdr_pf {
>  /* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
>  struct       pkthdr {
>       struct ifnet            *rcvif;         /* rcv interface */
> -     SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */
> +     SLIST_HEAD(packet_tags, m_tag) tags;    /* list of packet tags */
>       int                      len;           /* total packet length */
>       u_int16_t                tagsset;       /* mtags attached */
>       u_int16_t                pad;
>       u_int16_t                csum_flags;    /* checksum flags */
>       u_int16_t                ether_vtag;    /* Ethernet 802.1p+Q vlan tag */
>       u_int                    rdomain;       /* routing domain id */
> +     void                    *ph_cookie;     /* additional data */
>       struct pkthdr_pf         pf;
>  };
>  
> 

-- 
:wq Claudio

Reply via email to