Home | History | Annotate | Line # | Download | only in pppd
      1 /*	$NetBSD: ecp.c,v 1.6 2025/01/08 19:59:39 christos Exp $	*/
      2 
      3 /*
      4  * ecp.c - PPP Encryption Control Protocol.
      5  *
      6  * Copyright (c) 2002 Google, Inc.
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  *
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  *
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in
     18  *    the documentation and/or other materials provided with the
     19  *    distribution.
     20  *
     21  * 3. The name(s) of the authors of this software must not be used to
     22  *    endorse or promote products derived from this software without
     23  *    prior written permission.
     24  *
     25  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
     26  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
     27  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
     28  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     29  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
     30  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
     31  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     32  *
     33  * Derived from ccp.c, which is:
     34  *
     35  * Copyright (c) 1994-2024 Paul Mackerras. All rights reserved.
     36  *
     37  * Redistribution and use in source and binary forms, with or without
     38  * modification, are permitted provided that the following conditions
     39  * are met:
     40  *
     41  * 1. Redistributions of source code must retain the above copyright
     42  *    notice, this list of conditions and the following disclaimer.
     43  *
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in
     46  *    the documentation and/or other materials provided with the
     47  *    distribution.
     48  *
     49  * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
     50  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
     51  * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
     52  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     53  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
     54  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
     55  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     56  */
     57 
     58 #include <sys/cdefs.h>
     59 __RCSID("$NetBSD: ecp.c,v 1.6 2025/01/08 19:59:39 christos Exp $");
     60 
     61 #ifdef HAVE_CONFIG_H
     62 #include "config.h"
     63 #endif
     64 
     65 #include <string.h>
     66 
     67 #include "pppd-private.h"
     68 #include "options.h"
     69 #include "fsm.h"
     70 #include "ecp.h"
     71 
     72 static struct option ecp_option_list[] = {
     73     { "noecp", o_bool, &ecp_protent.enabled_flag,
     74       "Disable ECP negotiation" },
     75     { "-ecp", o_bool, &ecp_protent.enabled_flag,
     76       "Disable ECP negotiation", OPT_ALIAS },
     77 
     78     { NULL }
     79 };
     80 
     81 /*
     82  * Protocol entry points from main code.
     83  */
     84 static void ecp_init (int unit);
     85 /*
     86 static void ecp_open (int unit);
     87 static void ecp_close (int unit, char *);
     88 static void ecp_lowerup (int unit);
     89 static void ecp_lowerdown (int);
     90 static void ecp_input (int unit, u_char *pkt, int len);
     91 static void ecp_protrej (int unit);
     92 */
     93 static int  ecp_printpkt (u_char *pkt, int len,
     94 			  void (*printer)(void *, char *, ...),
     95 			  void *arg);
     96 /*
     97 static void ecp_datainput (int unit, u_char *pkt, int len);
     98 */
     99 
    100 struct protent ecp_protent = {
    101     PPP_ECP,
    102     ecp_init,
    103     NULL, /* ecp_input, */
    104     NULL, /* ecp_protrej, */
    105     NULL, /* ecp_lowerup, */
    106     NULL, /* ecp_lowerdown, */
    107     NULL, /* ecp_open, */
    108     NULL, /* ecp_close, */
    109     ecp_printpkt,
    110     NULL, /* ecp_datainput, */
    111     0,
    112     "ECP",
    113     "Encrypted",
    114     ecp_option_list,
    115     NULL,
    116     NULL,
    117     NULL
    118 };
    119 
    120 fsm ecp_fsm[NUM_PPP];
    121 ecp_options ecp_wantoptions[NUM_PPP];	/* what to request the peer to use */
    122 ecp_options ecp_gotoptions[NUM_PPP];	/* what the peer agreed to do */
    123 ecp_options ecp_allowoptions[NUM_PPP];	/* what we'll agree to do */
    124 ecp_options ecp_hisoptions[NUM_PPP];	/* what we agreed to do */
    125 
    126 static fsm_callbacks ecp_callbacks = {
    127     NULL, /* ecp_resetci, */
    128     NULL, /* ecp_cilen, */
    129     NULL, /* ecp_addci, */
    130     NULL, /* ecp_ackci, */
    131     NULL, /* ecp_nakci, */
    132     NULL, /* ecp_rejci, */
    133     NULL, /* ecp_reqci, */
    134     NULL, /* ecp_up, */
    135     NULL, /* ecp_down, */
    136     NULL,
    137     NULL,
    138     NULL,
    139     NULL,
    140     NULL, /* ecp_extcode, */
    141     "ECP"
    142 };
    143 
    144 /*
    145  * ecp_init - initialize ECP.
    146  */
    147 static void
    148 ecp_init(int unit)
    149 {
    150     fsm *f = &ecp_fsm[unit];
    151 
    152     f->unit = unit;
    153     f->protocol = PPP_ECP;
    154     f->callbacks = &ecp_callbacks;
    155     fsm_init(f);
    156 
    157     memset(&ecp_wantoptions[unit],  0, sizeof(ecp_options));
    158     memset(&ecp_gotoptions[unit],   0, sizeof(ecp_options));
    159     memset(&ecp_allowoptions[unit], 0, sizeof(ecp_options));
    160     memset(&ecp_hisoptions[unit],   0, sizeof(ecp_options));
    161 
    162 }
    163 
    164 
    165 static int
    166 ecp_printpkt(u_char *p, int plen,
    167 	     void (*printer)(void *, char *, ...), void *arg)
    168 {
    169     return 0;
    170 }
    171 
    172