Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Add commands to refer params of control protocols in...



details:   https://anonhg.NetBSD.org/src/rev/61649c97786a
branches:  trunk
changeset: 957363:61649c97786a
user:      yamaguchi <yamaguchi%NetBSD.org@localhost>
date:      Wed Nov 25 10:30:51 2020 +0000

description:
Add commands to refer params of control protocols in if_spppsubr.c

reviewed by knakahara@n.o.

diffstat:

 sys/net/if_sppp.h     |   69 ++++++++++++++++++++-
 sys/net/if_spppsubr.c |  165 ++++++++++++++++++++++++++++++++++++-------------
 sys/net/if_spppvar.h  |    5 +-
 3 files changed, 192 insertions(+), 47 deletions(-)

diffs (truncated from 519 to 300 lines):

diff -r 1782d4b8872c -r 61649c97786a sys/net/if_sppp.h
--- a/sys/net/if_sppp.h Wed Nov 25 10:27:18 2020 +0000
+++ b/sys/net/if_sppp.h Wed Nov 25 10:30:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_sppp.h,v 1.28 2015/09/06 06:01:01 dholland Exp $    */
+/*     $NetBSD: if_sppp.h,v 1.29 2020/11/25 10:30:51 yamaguchi Exp $   */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -165,5 +165,72 @@
 
 /* 134 already used! */
 
+/* states are named and numbered according to RFC 1661 */
+#define SPPP_STATE_INITIAL     0
+#define SPPP_STATE_STARTING    1
+#define SPPP_STATE_CLOSED      2
+#define SPPP_STATE_STOPPED     3
+#define SPPP_STATE_CLOSING     4
+#define SPPP_STATE_STOPPING    5
+#define SPPP_STATE_REQ_SENT    6
+#define SPPP_STATE_ACK_RCVD    7
+#define SPPP_STATE_ACK_SENT    8
+#define SPPP_STATE_OPENED      9
+
+#define SPPP_LCP_OPT_MRU               __BIT(1)
+#define SPPP_LCP_OPT_ASYNC_MAP         __BIT(2)
+#define SPPP_LCP_OPT_AUTH_PROTO                __BIT(3)
+#define SPPP_LCP_OPT_QUAL_PROTO                __BIT(4)
+#define SPPP_LCP_OPT_MAGIC             __BIT(5)
+#define SPPP_LCP_OPT_RESERVED          __BIT(6)
+#define SPPP_LCP_OPT_PROTO_COMP                __BIT(7)
+#define SPPP_LCP_OPT_ADDR_COMP         __BIT(8)
+#define SPPP_LCP_OPT_FCS_ALTS          __BIT(9)
+#define SPPP_LCP_OPT_SELF_DESC_PAD     __BIT(10)
+#define SPPP_LCP_OPT_CALL_BACK         __BIT(13)
+#define SPPP_LCP_OPT_COMPOUND_FRMS     __BIT(15)
+#define SPPP_LCP_OPT_MP_MRRU           __BIT(17)
+#define SPPP_LCP_OPT_MP_SSNHF          __BIT(18)
+#define SPPP_LCP_OPT_MP_EID            __BIT(19)
+
+/* #define SPPP_OPT_ADDRESSES  __BIT(0) */
+#define SPPP_IPCP_OPT_COMPRESSION      __BIT(1)
+#define SPPP_IPCP_OPT_ADDRESS          __BIT(2)
+#define SPPP_IPCP_OPT_PRIMDNS          __BIT(3)
+#define SPPP_IPCP_OPT_SECDNS           __BIT(4)
+
+#define SPPP_IPV6CP_OPT_IFID           __BIT(1)
+#define SPPP_IPV6CP_OPT_COMPRESSION    __BIT(2)
+
+struct sppplcpstatus {
+       char    ifname[IFNAMSIZ];
+       int     state;
+       int     timeout;
+       u_long  opts;
+       u_long  magic;
+       u_long  mru;
+};
+
+#define SPPPGETLCPSTATUS       _IOWR('i', 135, struct sppplcpstatus)
+
+struct spppipcpstatus {
+       char            ifname[IFNAMSIZ];
+       int             state;
+       u_long          opts;
+       u_int32_t       myaddr;
+};
+
+#define SPPPGETIPCPSTATUS      _IOWR('i', 136, struct spppipcpstatus)
+
+struct spppipv6cpstatus {
+       char            ifname[IFNAMSIZ];
+       int             state;
+       u_long          opts;
+       u_int8_t        my_ifid[8];
+       u_int8_t        his_ifid[8];
+};
+
+#define SPPPGETIPV6CPSTATUS    _IOWR('i', 137, struct spppipv6cpstatus)
+
 #endif /* !_NET_IF_SPPP_H_ */
 
diff -r 1782d4b8872c -r 61649c97786a sys/net/if_spppsubr.c
--- a/sys/net/if_spppsubr.c     Wed Nov 25 10:27:18 2020 +0000
+++ b/sys/net/if_spppsubr.c     Wed Nov 25 10:30:51 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_spppsubr.c,v 1.212 2020/11/25 10:27:18 yamaguchi Exp $       */
+/*     $NetBSD: if_spppsubr.c,v 1.213 2020/11/25 10:30:51 yamaguchi Exp $       */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.212 2020/11/25 10:27:18 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.213 2020/11/25 10:30:51 yamaguchi Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -185,17 +185,18 @@
 #define CISCO_ADDR_REPLY       1       /* Cisco address reply */
 #define CISCO_KEEPALIVE_REQ    2       /* Cisco keepalive request */
 
-/* states are named and numbered according to RFC 1661 */
-#define STATE_INITIAL  0
-#define STATE_STARTING 1
-#define STATE_CLOSED   2
-#define STATE_STOPPED  3
-#define STATE_CLOSING  4
-#define STATE_STOPPING 5
-#define STATE_REQ_SENT 6
-#define STATE_ACK_RCVD 7
-#define STATE_ACK_SENT 8
-#define STATE_OPENED   9
+enum {
+       STATE_INITIAL = SPPP_STATE_INITIAL,
+       STATE_STARTING = SPPP_STATE_STARTING,
+       STATE_CLOSED = SPPP_STATE_CLOSED,
+       STATE_STOPPED = SPPP_STATE_STOPPED,
+       STATE_CLOSING = SPPP_STATE_CLOSING,
+       STATE_STOPPING = SPPP_STATE_STOPPING,
+       STATE_REQ_SENT = SPPP_STATE_REQ_SENT,
+       STATE_ACK_RCVD = SPPP_STATE_ACK_RCVD,
+       STATE_ACK_SENT = SPPP_STATE_ACK_SENT,
+       STATE_OPENED = SPPP_STATE_OPENED,
+};
 
 enum cp_rcr_type {
        CP_RCR_NONE = 0,        /* initial value */
@@ -1268,6 +1269,9 @@
        case __SPPPGETIDLETO50:
        case __SPPPGETKEEPALIVE50:
 #endif /* COMPAT_50 || MODULAR */
+       case SPPPGETLCPSTATUS:
+       case SPPPGETIPCPSTATUS:
+       case SPPPGETIPV6CPSTATUS:
                error = sppp_params(sp, cmd, data);
                break;
 
@@ -2420,7 +2424,7 @@
 
        sppp_cp_init(&lcp, sp);
 
-       sp->lcp.opts = (1 << LCP_OPT_MAGIC);
+       SET(sp->lcp.opts, SPPP_LCP_OPT_MAGIC);
        sp->lcp.magic = 0;
        sp->lcp.protos = 0;
        sp->lcp.max_terminate = 2;
@@ -2537,7 +2541,7 @@
 
        if (sp->pp_if.if_mtu < PP_MTU) {
                sp->lcp.mru = sp->pp_if.if_mtu;
-               sp->lcp.opts |= (1 << LCP_OPT_MRU);
+               SET(sp->lcp.opts, SPPP_LCP_OPT_MRU);
        } else
                sp->lcp.mru = PP_MTU;
        sp->lcp.their_mru = PP_MTU;
@@ -2546,9 +2550,9 @@
         * If we are authenticator, negotiate LCP_AUTH
         */
        if (sp->hisauth.proto != 0)
-               sp->lcp.opts |= (1 << LCP_OPT_AUTH_PROTO);
+               SET(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO);
        else
-               sp->lcp.opts &= ~(1 << LCP_OPT_AUTH_PROTO);
+               CLR(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO);
        sp->pp_flags &= ~PP_NEEDAUTH;
        sppp_open_event(sp, xcp);
 }
@@ -2925,7 +2929,7 @@
                switch (p[0]) {
                case LCP_OPT_MAGIC:
                        /* Magic number -- can't use it, use 0 */
-                       sp->lcp.opts &= ~(1 << LCP_OPT_MAGIC);
+                       CLR(sp->lcp.opts, SPPP_LCP_OPT_MAGIC);
                        sp->lcp.magic = 0;
                        break;
                case LCP_OPT_MRU:
@@ -2940,7 +2944,7 @@
                                    "%ld bytes. Defaulting to %d bytes\n",
                                    ifp->if_xname, sp->lcp.mru, PP_MTU);
                        }
-                       sp->lcp.opts &= ~(1 << LCP_OPT_MRU);
+                       CLR(sp->lcp.opts, SPPP_LCP_OPT_MRU);
                        sp->lcp.mru = PP_MTU;
                        break;
                case LCP_OPT_AUTH_PROTO:
@@ -2954,7 +2958,7 @@
                                if (debug)
                                        addlog(" [don't insist on auth "
                                               "for callout]");
-                               sp->lcp.opts &= ~(1 << LCP_OPT_AUTH_PROTO);
+                               CLR(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO);
                                break;
                        }
                        if (debug)
@@ -3007,7 +3011,7 @@
                switch (p[0]) {
                case LCP_OPT_MAGIC:
                        /* Magic number -- renegotiate */
-                       if ((sp->lcp.opts & (1 << LCP_OPT_MAGIC)) &&
+                       if (ISSET(sp->lcp.opts, SPPP_LCP_OPT_MAGIC) &&
                            len >= 6 && l == 6) {
                                magic = (uint32_t)p[2] << 24 |
                                        (uint32_t)p[3] << 16 | p[4] << 8 | p[5];
@@ -3040,7 +3044,7 @@
                                if (mru < PPP_MINMRU || mru > sp->pp_if.if_mtu)
                                        mru = sp->pp_if.if_mtu;
                                sp->lcp.mru = mru;
-                               sp->lcp.opts |= (1 << LCP_OPT_MRU);
+                               SET(sp->lcp.opts, SPPP_LCP_OPT_MRU);
                        }
                        break;
                case LCP_OPT_AUTH_PROTO:
@@ -3077,7 +3081,7 @@
                SPPP_LOCK(sp, RW_WRITER);
        }
 
-       if ((sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) != 0 ||
+       if (ISSET(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO) ||
            (sp->pp_flags & PP_NEEDAUTH) != 0)
                sppp_change_phase(sp, SPPP_PHASE_AUTHENTICATE);
        else
@@ -3195,7 +3199,7 @@
 
        KASSERT(SPPP_WLOCKED(sp));
 
-       if (sp->lcp.opts & (1 << LCP_OPT_MAGIC)) {
+       if (ISSET(sp->lcp.opts, SPPP_LCP_OPT_MAGIC)) {
                if (! sp->lcp.magic)
                        sp->lcp.magic = cprng_fast32();
                opt[i++] = LCP_OPT_MAGIC;
@@ -3206,14 +3210,14 @@
                opt[i++] = sp->lcp.magic;
        }
 
-       if (sp->lcp.opts & (1 << LCP_OPT_MRU)) {
+       if (ISSET(sp->lcp.opts,SPPP_LCP_OPT_MRU)) {
                opt[i++] = LCP_OPT_MRU;
                opt[i++] = 4;
                opt[i++] = sp->lcp.mru >> 8;
                opt[i++] = sp->lcp.mru;
        }
 
-       if (sp->lcp.opts & (1 << LCP_OPT_AUTH_PROTO)) {
+       if (ISSET(sp->lcp.opts, SPPP_LCP_OPT_AUTH_PROTO)) {
                authproto = sp->hisauth.proto;
                opt[i++] = LCP_OPT_AUTH_PROTO;
                opt[i++] = authproto == PPP_CHAP? 5: 4;
@@ -3327,7 +3331,7 @@
                 * negotiate my address.
                 */
                sp->ipcp.flags |= IPCP_MYADDR_DYN;
-               sp->ipcp.opts |= (1 << IPCP_OPT_ADDRESS);
+               SET(sp->ipcp.opts, SPPP_IPCP_OPT_ADDRESS);
        }
        if (hisaddr == 1) {
                /*
@@ -3336,6 +3340,18 @@
                 */
                sp->ipcp.flags |= IPCP_HISADDR_DYN;
        }
+
+       if (sp->query_dns & 1) {
+               SET(sp->ipcp.opts, SPPP_IPCP_OPT_PRIMDNS);
+       } else {
+               CLR(sp->ipcp.opts, SPPP_IPCP_OPT_PRIMDNS);
+       }
+
+       if (sp->query_dns & 2) {
+               SET(sp->ipcp.opts, SPPP_IPCP_OPT_SECDNS);
+       } else {
+               CLR(sp->ipcp.opts, SPPP_IPCP_OPT_SECDNS);
+       }
        sppp_open_event(sp, xcp);
 }
 
@@ -3624,13 +3640,20 @@
                         * Peer doesn't grok address option.  This is
                         * bad.  XXX  Should we better give up here?
                         */
-                       sp->ipcp.opts &= ~(1 << IPCP_OPT_ADDRESS);
+                       CLR(sp->ipcp.opts, SPPP_IPCP_OPT_ADDRESS);
                        break;
 #ifdef notyet
                case IPCP_OPT_COMPRESS:
-                       sp->ipcp.opts &= ~(1 << IPCP_OPT_COMPRESS);
+                       CLR(sp->ipcp.opts, SPPP_IPCP_OPT_COMPRESS);
                        break;
 #endif
+               case IPCP_OPT_PRIMDNS:
+                       CLR(sp->ipcp.opts, SPPP_IPCP_OPT_PRIMDNS);
+                       break;
+
+               case IPCP_OPT_SECDNS:
+                       CLR(sp->ipcp.opts, SPPP_IPCP_OPT_SECDNS);
+                       break;
                }
        }



Home | Main Index | Thread Index | Old Index