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