This follows the example set by pppoe and uses the interfaces llprio
setting to determine the value of the tos in keepalive packets.

My understanding is that there are 8 precedence or class selector levels
in IP packets, which correlates quite nicely with the 8 prio levels we
carry around on mbufs.
 
Cisco default the prio on these type of packets to (Inter)Network Control,
which the driver currently does, and this diff maintains.

ok?

Index: if_gre.c
===================================================================
RCS file: /cvs/src/sys/net/if_gre.c,v
retrieving revision 1.131
diff -u -p -r1.131 if_gre.c
--- if_gre.c    25 Oct 2018 01:05:19 -0000      1.131
+++ if_gre.c    29 Oct 2018 01:33:10 -0000
@@ -589,6 +589,8 @@ gre_clone_create(struct if_clone *ifc, i
        bpfattach(&ifp->if_bpf, ifp, DLT_LOOP, sizeof(uint32_t));
 #endif
 
+       ifp->if_llprio = IFQ_TOS2PRIO(IPTOS_PREC_INTERNETCONTROL);
+
        NET_LOCK();
        TAILQ_INSERT_TAIL(&gre_list, sc, sc_entry);
        NET_UNLOCK();
@@ -2817,6 +2819,7 @@ gre_keepalive_send(void *arg)
        int linkhdr, len;
        uint16_t proto;
        uint8_t ttl;
+       uint8_t tos;
 
        /*
         * re-schedule immediately, so we deal with incomplete configuation
@@ -2869,6 +2872,7 @@ gre_keepalive_send(void *arg)
        SipHash24_Final(gk->gk_digest, &ctx);
 
        ttl = sc->sc_tunnel.t_ttl == -1 ? ip_defttl : sc->sc_tunnel.t_ttl;
+       tos = IFQ_PRIO2TOS(sc->sc_if.if_llprio);
 
        t.t_af = sc->sc_tunnel.t_af;
        t.t_df = sc->sc_tunnel.t_df;
@@ -2877,7 +2881,7 @@ gre_keepalive_send(void *arg)
        t.t_key = sc->sc_tunnel.t_key;
        t.t_key_mask = sc->sc_tunnel.t_key_mask;
 
-       m = gre_encap(&t, m, htons(0), ttl, IPTOS_PREC_INTERNETCONTROL);
+       m = gre_encap(&t, m, htons(0), ttl, tos);
        if (m == NULL)
                return;
 
@@ -2906,8 +2910,7 @@ gre_keepalive_send(void *arg)
        /*
         * put it in the tunnel
         */
-       m = gre_encap(&sc->sc_tunnel, m, proto, ttl,
-           IPTOS_PREC_INTERNETCONTROL);
+       m = gre_encap(&sc->sc_tunnel, m, proto, ttl, tos);
        if (m == NULL)
                return;
 
@@ -3751,10 +3754,11 @@ static void
 eoip_keepalive_send(void *arg)
 {
        struct eoip_softc *sc = arg;
+       struct ifnet *ifp = &sc->sc_ac.ac_if;
        struct mbuf *m;
        int linkhdr;
 
-       if (!ISSET(sc->sc_ac.ac_if.if_flags, IFF_RUNNING))
+       if (!ISSET(ifp->if_flags, IFF_RUNNING))
                return;
 
        /* this is really conservative */
@@ -3780,7 +3784,7 @@ eoip_keepalive_send(void *arg)
        m->m_pkthdr.len = m->m_len = linkhdr;
        m_adj(m, linkhdr);
 
-       m = eoip_encap(sc, m, IPTOS_PREC_INTERNETCONTROL);
+       m = eoip_encap(sc, m, IFQ_PRIO2TOS(ifp->if_llprio));
        if (m == NULL)
                return;
 
Index: if.h
===================================================================
RCS file: /cvs/src/sys/net/if.h,v
retrieving revision 1.194
diff -u -p -r1.194 if.h
--- if.h        30 May 2018 22:20:41 -0000      1.194
+++ if.h        29 Oct 2018 01:33:10 -0000
@@ -129,6 +129,8 @@ struct      if_data {
 #define IFQ_MINPRIO    0
 #define IFQ_MAXPRIO    IFQ_NQUEUES - 1
 #define IFQ_DEFPRIO    3
+#define IFQ_PRIO2TOS(_p) ((_p) << 5)
+#define IFQ_TOS2PRIO(_t) ((_t) >> 5)
 
 /*
  * Values for if_link_state.

Reply via email to