Changeset 2f1b930 in rtems for cpukit/pppd


Ignore:
Timestamp:
Aug 16, 2001, 8:42:09 PM (18 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
f7691e3
Parents:
4b3c197f
Message:

2001-08-16 Mike Siers <mikes@…>

  • Update of PPPD to 2.3.11 from 2.3.5 and addition of an example application. Mike's notes on the modifications:
    • renamed error() function because of namespace problems
    • removed calls to the exit() funciton
    • removed extra files from the pppd source directory
    • defined pppd task constant values in rtemspppd.h
    • modifyied example code to get actual tick per second value
    • placed the pppd 2.3.11 man page file (pppd.8) into the pppd directory
  • pppd/cbcp.c, pppd/cbcp.h, pppd/main.c, pppd/ppp_tty.c, pppd/pppmain.c, pppd/rtems-ppp.c, pppd/rtems-ppp.c: Deleted.
  • pppd/pppd.8, pppd/rtemsmain.c, pppd/rtemspppd.c, pppd/rtemspppd.h, pppd/sys-rtems.c, pppd/utils.c, pppd/example/Makefile, pppd/example/README, pppd/example/init.c, pppd/example/netconfig.h, pppd/example/ppp.conf, pppd/example/pppdapp.c, pppd/example/system.h: New files.
  • modem/ppp_tty.c, net/if_ppp.h, pppd/Makefile.am, pppd/README, pppd/STATUS, pppd/auth.c, pppd/ccp.c, pppd/ccp.h, pppd/chap.c, pppd/chap.h, pppd/chap_ms.c, pppd/chap_ms.h, pppd/chat.c, pppd/demand.c, pppd/fsm.c, pppd/fsm.h, pppd/ipcp.c, pppd/ipcp.h, pppd/ipxcp.c, pppd/ipxcp.h, pppd/lcp.c, pppd/lcp.h, pppd/magic.c, pppd/magic.h, pppd/options.c, pppd/patchlevel.h, pppd/pathnames.h, pppd/pppd.h, pppd/upap.c, pppd/upap.h: Modified.
Location:
cpukit/pppd
Files:
12 added
2 deleted
26 edited

Legend:

Unmodified
Added
Removed
  • cpukit/pppd/Makefile.am

    r4b3c197f r2f1b930  
    55AUTOMAKE_OPTIONS = foreign 1.4
    66
     7
     8
     9
    710LIBNAME = lib.a
    811LIB = $(ARCH)/$(LIBNAME)
    912
    10 # renamed main.c to pppmain.c
    11 C_FILES = auth.c cbcp.c ccp.c chap.c chap_ms.c chat.c demand.c fsm.c ipcp.c \
    12     ipxcp.c lcp.c magic.c options.c upap.c md4.c md5.c rtems-ppp.c \
    13     pppmain.c
     13C_FILES = auth.c ccp.c chap.c chap_ms.c chat.c demand.c fsm.c ipcp.c lcp.c magic.c options.c upap.c md4.c md5.c utils.c sys-rtems.c rtemsmain.c rtemspppd.c
    1414C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
    1515
     
    2424#
    2525
    26 # DEFINES += -D_COMPILING_BSD_KERNEL_ -DKERNEL -DINET -DNFS -DDIAGNOSTIC \
    27 #     -DBOOTP_COMPAT
    28 
    2926$(LIB): $(OBJS)
    3027        $(make-library)
    3128
    32 EXTRA_FILES = modem_example/16550.h modem_example/README \
    33     modem_example/modem.c modem_example/modem.h modem_example/ppp.c \
    34     modem_example/ppp.h modem_example/pppcompress.c
    35 
    36 all-local: $(ARCH) $(OBJS) $(LIB)
     29all-local: $(PREINSTALL_FILES) $(ARCH) $(OBJS) $(LIB)
    3730
    3831.PRECIOUS: $(LIB)
    3932
    40 EXTRA_DIST = README STATUS auth.c cbcp.c cbcp.h ccp.c ccp.h chap.c chap.h \
    41     chap_ms.c chap_ms.h chat.c demand.c fsm.c fsm.h ipcp.c ipcp.h ipxcp.c \
    42     ipxcp.h lcp.c lcp.h magic.c magic.h main.c md4.c md4.h md5.c md5.h \
    43     options.c patchlevel.h pathnames.h ppp_tty.c pppd.h rtems-ppp.c upap.c \
    44     upap.h pppmain.c $(EXTRA_FILES)
     33EXTRA_DIST = auth.c ccp.c ccp.h chap.c chap.h chap_ms.c chap_ms.h \
     34chat.c demand.c fsm.c fsm.h ipcp.c ipcp.h ipxcp.c ipxcp.h \
     35lcp.c lcp.h magic.c magic.h md4.c md4.h md5.c md5.h options.c \
     36patchlevel.h pathnames.h pppd.h rtemsmain.c rtemspppd.c rtemspppd.h \
     37sys-rtems.c upap.c upap.h utils.c
     38
     39include_HEADERS = rtemspppd.h
     40
     41
     42PREINSTALL_FILES += $(PROJECT_INCLUDE) $(include_HEADERS:%=$(PROJECT_INCLUDE)/%)
     43
     44$(PROJECT_INCLUDE)/%.h: %.h
     45        $(INSTALL_DATA) $< $@
    4546
    4647include $(top_srcdir)/../../../automake/local.am
  • cpukit/pppd/README

    r4b3c197f r2f1b930  
    33#
    44
    5 This directory contains a port of ppp-2.3.5.  The official site for
     5This directory contains a port of ppp-2.3.11.  The official site for
    66the original source for this PPP implementation is:
    77
    88ftp://cs.anu.edu.au/pub/software/ppp
    99
    10 NOTE:  As of 11/30/1999, the current version of this source is 2.3.10.
     10================================================================
     11History
    1112
    12 The port was performed by Tomasz Domin <dot@comarch.pl> of ComArch SA
    13 and has only been tested on the mpc823.  The modem driver should
    14 work with minor modifications on other systems.
     13The original port was of 2.3.5 by Tomasz Domin <dot@comarch.pl> of
     14ComArch SA and was initially only tested on the mpc823.  He
     15provided the modem driver as well.
     16
     17The port was updated to 2.3.11 by Mike Siers <mikes@poliac.com>
     18who added an example test.
    1519=================================================================
    16 Some comments:
    1720
    18 + "SetStatusInfo is a function which displays given message on
    19   bottom side of the screen."
    20 
    21   The issue of how to deal with SetStatusInfo in a generic, portable
    22   fashion is still open.
    23 
    24 + "Dialer returns positive integer when an error occurs, and negative one
    25   which is parsed from modem aswer, when connection is done (for example
    26   -28000 if connection speed is 28000 baud ...)"
    27 
    28 +   PPP_User/PPP_Password
    29    "When this field is set, it is sent to the server when there is need
    30    to login ....
    31    When it is blank - it is using other method of authentification ... or
    32    none ...
    33    PPP_Password is also used in CHAT and PAP  - because there is no
    34    configuration files in RTEMS ..."
    35 
    36    This falls into the general question of how to generally configure this.
    37 
    38 + ConnectionStatus
    39 
    40   This is the method of synchronization between pppd task and others.
    41   ConnectionStatus field is set by pppd - when connection occurs it`s state
    42   is set to Connected. WantConnection is set by client application (and
    43   the appriopriate event is sent then) so pppd knows what user wants to do ...
    44 
    45 + Around line 270 of main.c, there is code to change the default
    46   nameserver... why?
    47 
    48   Becouse in my application user can change it anytime  ... - without need of
    49   rebooting the system
    50   When PPP connection is configured there is needed additional info about
    51   nameservers - PPP layer cant discover them itself
    52 
    53 
    54 
    55 
    56 
    57 
    58 
  • cpukit/pppd/STATUS

    r4b3c197f r2f1b930  
    33#
    44
    5 Overall, this code should still be considered in its early stages.  It
    6 works but has some distance to go before it is fully documented and
    7 easily configurable.
    8 
    9 + Compare the code to the original 2.3.5 and eliminate spurious changes.
    10 
    11 + Update the code to 2.3.10.
    12 
    13 + Eliminate items specific to Tomasz' system.  In particular, the
    14   code reports status and gets configuration information in a system
    15   specific manner.   main.c is particularly guilty of this although
    16   other files suffer from this also.
    17 
    18 + Find comments in Polish and get Tomasz to translate them. :)
    19  (DONE but not sure if completely
    20   Radzislaw Galler <rgaller@et.put.poznan.pl>)
    21 
    22 + Add netdemo showing configuration and initialization.
    23 
    24 + Get feature list.
    25 
    26 + Document dialer setup.
    27 
    28 + Only modem driver is system specific so there is the possibility
    29   that shareable code exists in it.
     5This file needs to be redone to reflect tasks left after the 2.3.11
     6update.
  • cpukit/pppd/auth.c

    r4b3c197f r2f1b930  
    3333 */
    3434
    35 #ifndef lint
    36 /* static char rcsid[] = "$Id$"; */
    37 #endif
     35#define RCSID   "$Id$"
    3836
    3937#include <stdio.h>
    4038#include <stddef.h>
    41 #include <stdlib.h> 
     39#include <stdlib.h>
    4240#include <unistd.h>
    43 #include <syslog.h>
    4441#include <pwd.h>
     42#include <grp.h>
    4543#include <string.h>
    4644#include <sys/types.h>
    4745#include <sys/stat.h>
    4846#include <sys/socket.h>
    49 
    5047#include <fcntl.h>
    5148#if defined(_PATH_LASTLOG) && defined(_linux_)
     
    5653#include <netinet/in.h>
    5754#include <arpa/inet.h>
    58 /* #include <stbconfig.h> */
     55
     56#ifdef USE_PAM
     57#include <security/pam_appl.h>
     58#endif
     59
     60#ifdef HAS_SHADOW
     61#include <shadow.h>
     62#ifndef PW_PPP
     63#define PW_PPP PW_LOGIN
     64#endif
     65#endif
    5966
    6067#include "pppd.h"
     
    6976#include "pathnames.h"
    7077
    71 /* Used for storing a sequence of words.  Usually malloced. */
    72 struct wordlist {
    73     struct wordlist     *next;
    74     char                word[1];
    75 };
    76 
    77 /* Bits in scan_authfile return value */
    78 #define NONWILD_SERVER  1
    79 #define NONWILD_CLIENT  2
    80 
    81 #define ISWILD(word)    (word[0] == '*' && word[1] == 0)
    82 
    83 #define FALSE   0
    84 #define TRUE    1
     78static const char rcsid[] = RCSID;
    8579
    8680/* The name by which the peer authenticated itself to us. */
     
    9084static int auth_pending[NUM_PPP];
    9185
    92 /* Set if we have successfully called plogin() */
    93 static int logged_in;
    94 
    95 /* Set if we have run the /etc/ppp/auth-up script. */
    96 static int did_authup;
    97 
    9886/* List of addresses which the peer may use. */
    99 static struct wordlist *addresses[NUM_PPP];
     87static struct permitted_ip *addresses[NUM_PPP];
     88
     89/* Wordlist giving addresses which the peer may use
     90   without authenticating itself. */
     91static struct wordlist *noauth_addrs;
     92
     93/* Extra options to apply, from the secrets file entry for the peer. */
     94static struct wordlist *extra_options;
    10095
    10196/* Number of network protocols which we have opened. */
     
    107102/* Set if we got the contents of passwd[] from the pap-secrets file. */
    108103static int passwd_from_file;
     104
     105/* Set if we require authentication only because we have a default route. */
     106static bool default_auth;
     107
     108/* Hook for a link status */
     109void (*auth_linkup_hook)__P((void)) = NULL;
     110void (*auth_linkdown_hook)__P((void)) = NULL;
     111
     112/* Hook to enable a plugin to control the idle time limit */
     113int (*idle_time_hook) __P((struct ppp_idle *)) = NULL;
     114
     115/* Hook for a plugin to say whether we can possibly authenticate any peer */
     116int (*pap_check_hook) __P((void)) = NULL;
     117
     118/* Hook for a plugin to check the PAP user and password */
     119int (*pap_auth_hook) __P((char *user, char *passwd, char **msgp,
     120                          struct wordlist **paddrs,
     121                          struct wordlist **popts)) = NULL;
     122
     123/* Hook for a plugin to know about the PAP user logout */
     124void (*pap_logout_hook) __P((void)) = NULL;
     125
     126/* Hook for a plugin to get the PAP password for authenticating us */
     127int (*pap_passwd_hook) __P((char *user, char *passwd)) = NULL;
     128
     129/*
     130 * This is used to ensure that we don't start an auth-up/down
     131 * script while one is already running.
     132 */
     133enum script_state {
     134    s_down,
     135    s_up
     136};
     137
     138static enum script_state auth_state = s_down;
     139static enum script_state auth_script_state = s_down;
     140
     141/*
     142 * Option variables.
     143 */
     144bool uselogin = 0;              /* Use /etc/passwd for checking PAP */
     145bool cryptpap = 0;              /* Passwords in pap-secrets are encrypted */
     146bool refuse_pap = 0;            /* Don't wanna auth. ourselves with PAP */
     147bool refuse_chap = 0;           /* Don't wanna auth. ourselves with CHAP */
     148bool usehostname = 0;           /* Use hostname for our_name */
     149bool auth_required = 0;         /* Always require authentication from peer */
     150bool allow_any_ip = 0;          /* Allow peer to use any IP address */
     151bool explicit_remote = 0;       /* User specified explicit remote name */
     152char remote_name[MAXNAMELEN];   /* Peer's name for authentication */
    109153
    110154/* Bits in auth_pending[] */
     
    121165static void check_idle __P((void *));
    122166static void connect_time_expired __P((void *));
    123 static int  plogin __P((char *, char *, char **, int *));
    124 static void plogout __P((void));
    125167static int  null_login __P((int));
    126168static int  get_pap_passwd __P((char *));
    127 static int  have_pap_secret __P((void));
    128 static int  have_chap_secret __P((char *, char *, u_int32_t));
    129 static int  ip_addr_check __P((u_int32_t, struct wordlist *));
    130 static int  scan_authfile __P((FILE *, char *, char *, u_int32_t, char *,
    131                                struct wordlist **, char *));
     169static int  have_pap_secret __P((int *));
     170static int  have_chap_secret __P((char *, char *, int, int *));
     171static int  ip_addr_check __P((u_int32_t, struct permitted_ip *));
    132172static void free_wordlist __P((struct wordlist *));
    133 static void auth_script __P((char *));
    134 static void set_allowed_addrs __P((int, struct wordlist *));
     173static void auth_script __P((enum script_state s));
     174static void set_allowed_addrs __P((int, struct wordlist *, struct wordlist *));
     175
     176
     177/*
     178 * Authentication-related options.
     179 */
     180option_t auth_options[] = {
     181    { "require-pap", o_bool, &lcp_wantoptions[0].neg_upap,
     182      "Require PAP authentication from peer", 1, &auth_required },
     183    { "+pap", o_bool, &lcp_wantoptions[0].neg_upap,
     184      "Require PAP authentication from peer", 1, &auth_required },
     185    { "refuse-pap", o_bool, &refuse_pap,
     186      "Don't agree to auth to peer with PAP", 1 },
     187    { "-pap", o_bool, &refuse_pap,
     188      "Don't allow PAP authentication with peer", 1 },
     189    { "require-chap", o_bool, &lcp_wantoptions[0].neg_chap,
     190      "Require CHAP authentication from peer", 1, &auth_required },
     191    { "+chap", o_bool, &lcp_wantoptions[0].neg_chap,
     192      "Require CHAP authentication from peer", 1, &auth_required },
     193    { "refuse-chap", o_bool, &refuse_chap,
     194      "Don't agree to auth to peer with CHAP", 1 },
     195    { "-chap", o_bool, &refuse_chap,
     196      "Don't allow CHAP authentication with peer", 1 },
     197    { "name", o_string, our_name,
     198      "Set local name for authentication",
     199      OPT_PRIV|OPT_STATIC, NULL, MAXNAMELEN },
     200    { "user", o_string, user,
     201      "Set name for auth with peer", OPT_STATIC, NULL, MAXNAMELEN },
     202    { "usehostname", o_bool, &usehostname,
     203      "Must use hostname for authentication", 1 },
     204    { "remotename", o_string, remote_name,
     205      "Set remote name for authentication", OPT_STATIC,
     206      &explicit_remote, MAXNAMELEN },
     207    { "auth", o_bool, &auth_required,
     208      "Require authentication from peer", 1 },
     209    { "noauth", o_bool, &auth_required,
     210      "Don't require peer to authenticate", OPT_PRIV, &allow_any_ip },
     211    {  "login", o_bool, &uselogin,
     212      "Use system password database for PAP", 1 },
     213    { "papcrypt", o_bool, &cryptpap,
     214      "PAP passwords are encrypted", 1 },
     215/* Removed for RTEMS PORT
     216    { "+ua", o_special, setupapfile,
     217      "Get PAP user and password from file" },
     218*/
     219    { "password", o_string, passwd,
     220      "Password for authenticating us to the peer", OPT_STATIC,
     221      NULL, MAXSECRETLEN },
     222/* Removed for RTEMS_PORT
     223    { "privgroup", o_special, privgroup,
     224      "Allow group members to use privileged options", OPT_PRIV },
     225    { "allow-ip", o_special, set_noauth_addr,
     226      "Set IP address(es) which can be used without authentication",
     227      OPT_PRIV },
     228*/
     229    { NULL }
     230};
    135231
    136232/*
     
    154250    if (phase == PHASE_DEAD)
    155251        return;
    156     if (logged_in)
    157         plogout();
    158     phase = PHASE_DEAD;
    159     syslog(LOG_NOTICE, "Connection terminated.");
     252    if (pap_logout_hook) {
     253        pap_logout_hook();
     254    }
     255    new_phase(PHASE_DEAD);
     256    notice("Connection terminated.");
    160257}
    161258
     
    170267    struct protent *protp;
    171268
    172         did_authup = 0;
     269    auth_state = s_down;
     270    if (auth_script_state == s_up) {
     271        update_link_stats(unit);
     272        auth_script(s_down);
     273    }
    173274    for (i = 0; (protp = protocols[i]) != NULL; ++i) {
    174275        if (!protp->enabled_flag)
     
    182283    num_np_up = 0;
    183284    if (phase != PHASE_DEAD)
    184         phase = PHASE_TERMINATE;
     285        new_phase(PHASE_TERMINATE);
    185286}
    186287
     
    211312        /*
    212313         * We wanted the peer to authenticate itself, and it refused:
    213          * treat it as though it authenticated with PAP using a username
    214          * of "" and a password of "".  If that's not OK, boot it out.
     314         * if we have some address(es) it can use without auth, fine,
     315         * otherwise treat it as though it authenticated with PAP using
     316         * a username * of "" and a password of "".  If that's not OK,
     317         * boot it out.
    215318         */
    216         if (!wo->neg_upap || !null_login(unit)) {
     319        if (noauth_addrs != NULL) {
     320            set_allowed_addrs(unit, noauth_addrs, NULL);
     321        } else if (!wo->neg_upap || !null_login(unit)) {
     322            warn("peer refused to authenticate: terminating link");
    217323            lcp_close(unit, "peer refused to authenticate");
     324            status = EXIT_PEER_AUTH_FAILED;
    218325            return;
    219326        }
    220327    }
    221328
    222     phase = PHASE_AUTHENTICATE;
     329    new_phase(PHASE_AUTHENTICATE);
    223330    auth = 0;
    224331    if (go->neg_chap) {
     
    235342        if (passwd[0] == 0) {
    236343            passwd_from_file = 1;
    237             get_pap_passwd(passwd);
     344            if (!get_pap_passwd(passwd))
     345                error("No secret found for PAP login");
    238346        }
    239347        upap_authwithpeer(unit, user, passwd);
     
    253361    int unit;
    254362{
     363#ifdef CBCP_SUPPORT
     364    lcp_options *go = &lcp_gotoptions[unit];
     365#endif
     366
     367    /* always run the auth-up script */
     368    auth_state = s_up;
     369    if (auth_script_state == s_down) {
     370        auth_script(s_up);
     371    }
     372
     373#ifdef CBCP_SUPPORT
     374    /*
     375     * If we negotiated callback, do it now.
     376     */
     377    if (go->neg_cbcp) {
     378        new_phase(PHASE_CALLBACK);
     379        (*cbcp_protent.open)(unit);
     380        return;
     381    }
     382#endif
     383
     384    /*
     385     * Process extra options from the secrets file
     386     */
     387    if (extra_options) {
     388        options_from_list(extra_options, 1);
     389        free_wordlist(extra_options);
     390        extra_options = 0;
     391    }
     392    start_networks();
     393}
     394
     395void
     396start_networks()
     397{
    255398    int i;
    256399    struct protent *protp;
    257     lcp_options *go = &lcp_gotoptions[unit];
    258 
    259     /*
    260      * If the peer had to authenticate, run the auth-up script now.
    261      */
    262     if ((go->neg_chap || go->neg_upap) && !did_authup) {
    263         auth_script(_PATH_AUTHUP);
    264         did_authup = 1;
    265     }
    266 
    267 #ifdef CBCP_SUPPORT
    268     /*
    269      * If we negotiated callback, do it now.
    270      */
    271     if (go->neg_cbcp) {
    272         phase = PHASE_CALLBACK;
    273         (*cbcp_protent.open)(unit);
    274         return;
    275     }
    276 #endif
    277 
    278     phase = PHASE_NETWORK;
    279 
     400
     401    new_phase(PHASE_NETWORK);
    280402    for (i = 0; (protp = protocols[i]) != NULL; ++i)
    281403        if (protp->protocol < 0xC000 && protp->enabled_flag
    282404            && protp->open != NULL) {
    283             (*protp->open)(unit);
     405            (*protp->open)(0);
    284406            if (protp->protocol != PPP_CCP)
    285407                ++num_np_open;
     
    302424     */
    303425    lcp_close(unit, "Authentication failed");
     426    status = EXIT_PEER_AUTH_FAILED;
    304427}
    305428
     
    323446        break;
    324447    default:
    325         syslog(LOG_WARNING, "auth_peer_success: unknown protocol %x",
    326                protocol);
     448        warn("auth_peer_success: unknown protocol %x", protocol);
    327449        return;
    328450    }
     
    335457    BCOPY(name, peer_authname, namelen);
    336458    peer_authname[namelen] = 0;
     459
    337460    /*
    338461     * If there is no more authentication still to be done,
     
    354477    /*
    355478     * We've failed to authenticate ourselves to our peer.
    356      * He'll probably take the link down, and there's not much
    357      * we can do except wait for that.
    358      */
     479     * Some servers keep sending CHAP challenges, but there
     480     * is no point in persisting without any way to get updated
     481     * authentication secrets.
     482     */
     483    lcp_close(unit, "Failed to authenticate ourselves to peer");
     484    status = EXIT_AUTH_TOPEER_FAILED;
    359485}
    360486
     
    378504        break;
    379505    default:
    380 
     506        warn("auth_withpeer_success: unknown protocol %x", protocol);
    381507        bit = 0;
    382508    }
     
    398524    int unit, proto;
    399525{
     526    int tlim;
     527
    400528    if (num_np_up == 0) {
    401529        /*
    402530         * At this point we consider that the link has come up successfully.
    403531         */
    404         need_holdoff = 0;
    405 
    406         if (idle_time_limit > 0)
    407             TIMEOUT(check_idle, NULL, idle_time_limit);
     532        status = EXIT_OK;
     533        unsuccess = 0;
     534        new_phase(PHASE_RUNNING);
     535
     536        if (idle_time_hook != 0)
     537            tlim = (*idle_time_hook)(NULL);
     538        else
     539            tlim = idle_time_limit;
     540        if (tlim > 0)
     541            TIMEOUT(check_idle, NULL, tlim);
    408542
    409543        /*
     
    413547        if (maxconnect > 0)
    414548            TIMEOUT(connect_time_expired, 0, maxconnect);
    415 
    416         /*
    417          * Detach now, if the updetach option was given.
    418          */
    419         if (nodetach == -1)
    420             detach();
    421549    }
    422550    ++num_np_up;
     
    430558    int unit, proto;
    431559{
    432     if (--num_np_up == 0 && idle_time_limit > 0) {
     560    if (--num_np_up == 0) {
    433561        UNTIMEOUT(check_idle, NULL);
     562        new_phase(PHASE_NETWORK);
    434563    }
    435564}
     
    454583static void
    455584check_idle(arg)
    456      void *arg;
     585    void *arg;
    457586{
    458587    struct ppp_idle idle;
    459588    time_t itime;
     589    int tlim;
    460590
    461591    if (!get_idle_time(0, &idle))
    462592        return;
    463     itime = MIN(idle.xmit_idle, idle.recv_idle);
    464     if (itime >= idle_time_limit) {
     593    if (idle_time_hook != 0) {
     594        tlim = idle_time_hook(&idle);
     595    } else {
     596        itime = MIN(idle.xmit_idle, idle.recv_idle);
     597        tlim = idle_time_limit - itime;
     598    }
     599    if (tlim <= 0) {
    465600        /* link is idle: shut it down. */
    466         syslog(LOG_INFO, "Terminating connection due to lack of activity.");
     601        notice("Terminating connection due to lack of activity.");
    467602        lcp_close(0, "Link inactive");
     603        need_holdoff = 0;
     604        status = EXIT_IDLE_TIMEOUT;
    468605    } else {
    469         TIMEOUT(check_idle, NULL, idle_time_limit - itime);
     606        TIMEOUT(check_idle, NULL, tlim);
    470607    }
    471608}
     
    478615    void *arg;
    479616{
    480     syslog(LOG_INFO, "Connect time expired");
     617    info("Connect time expired");
    481618    lcp_close(0, "Connect time expired");       /* Close connection */
     619    status = EXIT_CONNECT_TIME;
    482620}
    483621
     
    485623 * auth_check_options - called to check authentication options.
    486624 */
    487 void
     625int
    488626auth_check_options()
    489627{
    490628    lcp_options *wo = &lcp_wantoptions[0];
     629    int status      = 1;
    491630    int can_auth;
    492     ipcp_options *ipwo = &ipcp_wantoptions[0];
    493     u_int32_t remote;
     631    int lacks_ip;
    494632
    495633    /* Default our_name to hostname, and user to our_name */
    496634    if (our_name[0] == 0 || usehostname)
    497         strcpy(our_name, hostname);
     635        strlcpy(our_name, hostname, sizeof(our_name));
    498636    if (user[0] == 0)
    499         strcpy(user, our_name);
     637        strlcpy(user, our_name, sizeof(user));
     638
     639    /*
     640     * If we have a default route, require the peer to authenticate
     641     * unless the noauth option was given or the real user is root.
     642     */
     643    if (!auth_required && !allow_any_ip && have_route_to(0) && !privileged) {
     644        printf("auth_check_options: turning on\n");
     645        auth_required = 1;
     646        default_auth = 1;
     647    }
    500648
    501649    /* If authentication is required, ask peer for CHAP or PAP. */
    502     if (auth_required && !wo->neg_chap && !wo->neg_upap) {
    503         wo->neg_chap = 1;
    504         wo->neg_upap = 1;
     650    if (auth_required) {
     651        if (!wo->neg_chap && !wo->neg_upap) {
     652            wo->neg_chap = 1;
     653            wo->neg_upap = 1;
     654        }
     655    } else {
     656        wo->neg_chap = 0;
     657        wo->neg_upap = 0;
    505658    }
    506659
     
    509662     * to authenticate the peer.
    510663     */
    511     can_auth = wo->neg_upap && (uselogin || have_pap_secret());
     664    lacks_ip = 0;
     665    can_auth = wo->neg_upap && (uselogin || have_pap_secret(&lacks_ip));
    512666    if (!can_auth && wo->neg_chap) {
    513         remote = ipwo->accept_remote? 0: ipwo->hisaddr;
    514         can_auth = have_chap_secret(remote_name, our_name, remote);
    515     }
    516 
    517     if (auth_required && !can_auth) {
    518         option_error("peer authentication required but no suitable secret(s) found\n");
    519         if (remote_name[0] == 0)
    520             option_error("for authenticating any peer to us (%s)\n", our_name);
     667        can_auth = have_chap_secret((explicit_remote? remote_name: NULL),
     668                                    our_name, 1, &lacks_ip);
     669    }
     670
     671    if (auth_required && !can_auth && noauth_addrs == NULL) {
     672        if (default_auth) {
     673            option_error(
     674"By default the remote system is required to authenticate itself");
     675            option_error(
     676"(because this system has a default route to the internet)");
     677        } else if (explicit_remote)
     678            option_error(
     679"The remote system (%s) is required to authenticate itself",
     680                         remote_name);
    521681        else
    522             option_error("for authenticating peer %s to us (%s)\n",
    523                          remote_name, our_name);
    524         exit(1);
    525     }
    526 
    527     /*
    528      * Check whether the user tried to override certain values
    529      * set by root.
    530      */
    531     if (!auth_required && auth_req_info.priv > 0) {
    532         if (!default_device && devnam_info.priv == 0) {
    533             option_error("can't override device name when noauth option used");
    534             exit(1);
    535         }
    536         if ((connector != NULL && connector_info.priv == 0)
    537             || (disconnector != NULL && disconnector_info.priv == 0)
    538             || (welcomer != NULL && welcomer_info.priv == 0)) {
    539             option_error("can't override connect, disconnect or welcome");
    540             option_error("option values when noauth option used");
    541             exit(1);
    542         }
    543     }
     682            option_error(
     683"The remote system is required to authenticate itself");
     684        option_error(
     685"but I couldn't find any suitable secret (password) for it to use to do so.");
     686        if (lacks_ip)
     687            option_error(
     688"(None of the available passwords would let it use an IP address.)");
     689
     690        status = 0;
     691    }
     692    return ( status );
    544693}
    545694
     
    555704    lcp_options *go = &lcp_gotoptions[unit];
    556705    lcp_options *ao = &lcp_allowoptions[0];
    557     ipcp_options *ipwo = &ipcp_wantoptions[0];
    558     u_int32_t remote;
    559 
    560     ao->neg_upap = !refuse_pap /*&& (passwd[0] != 0 || get_pap_passwd(NULL))*/;
     706
     707    ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(NULL));
    561708    ao->neg_chap = !refuse_chap
    562         && have_chap_secret(user, remote_name, (u_int32_t)0);
    563 
    564     if (go->neg_upap && !uselogin && !have_pap_secret())
     709        && (passwd[0] != 0
     710            || have_chap_secret(user, (explicit_remote? remote_name: NULL),
     711                                0, NULL));
     712
     713    if (go->neg_upap && !uselogin && !have_pap_secret(NULL))
    565714        go->neg_upap = 0;
    566715    if (go->neg_chap) {
    567         remote = ipwo->accept_remote? 0: ipwo->hisaddr;
    568         if (!have_chap_secret(remote_name, our_name, remote))
     716        if (!have_chap_secret((explicit_remote? remote_name: NULL),
     717                              our_name, 1, NULL))
    569718            go->neg_chap = 0;
    570719    }
     
    583732 */
    584733int
    585 check_passwd(unit, auser, userlen, apasswd, passwdlen, msg, msglen)
     734check_passwd(unit, auser, userlen, apasswd, passwdlen, msg)
    586735    int unit;
    587736    char *auser;
     
    590739    int passwdlen;
    591740    char **msg;
    592     int *msglen;
    593 {
    594 
    595 
    596     return UPAP_AUTHNAK;
    597 }
    598 
    599 
    600 /*
    601  * plogin - Check the user name and password against the system
    602  * password database, and login the user if OK.
    603  *
    604  * returns:
    605  *      UPAP_AUTHNAK: Login failed.
    606  *      UPAP_AUTHACK: Login succeeded.
    607  * In either case, msg points to an appropriate message.
    608  */
    609 
    610 static int
    611 plogin(user, passwd, msg, msglen)
    612     char *user;
    613     char *passwd;
    614     char **msg;
    615     int *msglen;
    616 {
    617     syslog(LOG_INFO, "user %s logged in", user);
    618     logged_in = TRUE;
    619 
    620     return (UPAP_AUTHACK);
    621 }
    622 
    623 /*
    624  * plogout - Logout the user.
    625  */
    626 static void
    627 plogout()
    628 {
    629 
    630     logged_in = FALSE;
    631 }
    632 
     741{
     742    int    ret = (int)UPAP_AUTHNAK;
     743
     744    if (( userlen == 0 ) && ( passwdlen == 0 )) {
     745      ret = (int)UPAP_AUTHACK;
     746    }
     747    printf("check_passwd: %d\n", ret);
     748
     749    return ret;
     750}
    633751
    634752/*
     
    641759    int unit;
    642760{
    643     return 1;
     761    return 0;
    644762}
    645763
     
    649767 * our peer using PAP.  Returns 1 on success, 0 if no suitable password
    650768 * could be found.
    651  */
    652 
     769 * Assumes passwd points to MAXSECRETLEN bytes of space (if non-null).
     770 */
    653771static int
    654772get_pap_passwd(passwd)
    655773    char *passwd;
    656774{
    657 #if 0
    658 /* XXX PPPConfiguration */
    659         GlobalSystemStatus *stat;
    660         stat=LockSTBSystemParam();
    661         strncpy(passwd,  stat->PPP_Password, MAXSECRETLEN);
    662         UnlockSTBSystemParam();
    663 #endif
    664     return 1;
     775    int ret = (int)0;
     776
     777    /*
     778     * Check whether a plugin wants to supply this.
     779     */
     780    if (pap_passwd_hook) {
     781        ret = (*pap_passwd_hook)(user, passwd);
     782    }
     783
     784    return ( ret );
    665785}
    666786
     
    671791 */
    672792static int
    673 have_pap_secret()
    674 {
    675     return 1;
     793have_pap_secret(lacks_ipp)
     794    int *lacks_ipp;
     795{
     796    int ret = (int)0;
     797
     798    /* let the plugin decide, if there is one */
     799    printf("have_pap_secret:\n");
     800    if (pap_check_hook) {
     801        ret = (*pap_check_hook)();
     802    }
     803
     804    return ( ret );
    676805}
    677806
     
    684813 */
    685814static int
    686 have_chap_secret(client, server, remote)
     815have_chap_secret(client, server, need_ip, lacks_ipp)
    687816    char *client;
    688817    char *server;
    689     u_int32_t remote;
    690 {
    691 
    692     return 1;
     818    int need_ip;
     819    int *lacks_ipp;
     820{
     821    return 0;
    693822}
    694823
     
    700829 */
    701830int
    702 get_secret(unit, client, server, secret, secret_len, save_addrs)
     831get_secret(unit, client, server, secret, secret_len, am_server)
    703832    int unit;
    704833    char *client;
     
    706835    char *secret;
    707836    int *secret_len;
    708     int save_addrs;
    709 {
    710 #if 0
    711 /* XXX PPPConfiguration */
     837    int am_server;
     838{
    712839    int len;
    713         GlobalSystemStatus *stat;
    714         stat=LockSTBSystemParam();
    715     len=strlen(stat->PPP_Password);
    716     strcpy( secret,stat->PPP_Password);
    717         UnlockSTBSystemParam();
    718 
     840    char secbuf[MAXWORDLEN];
     841
     842    if (!am_server && passwd[0] != 0) {
     843        strlcpy(secbuf, passwd, sizeof(secbuf));
     844    } else {
     845        return 0;
     846    }
     847
     848    len = strlen(secbuf);
     849    if (len > MAXSECRETLEN) {
     850        error("Secret for %s on %s is too long", client, server);
     851        len = MAXSECRETLEN;
     852    }
     853    BCOPY(secbuf, secret, len);
     854    BZERO(secbuf, sizeof(secbuf));
    719855    *secret_len = len;
    720 #endif
     856
    721857    return 1;
    722858}
     
    724860/*
    725861 * set_allowed_addrs() - set the list of allowed addresses.
     862 * Also looks for `--' indicating options to apply for this peer
     863 * and leaves the following words in extra_options.
    726864 */
    727865static void
    728 set_allowed_addrs(unit, addrs)
     866set_allowed_addrs(unit, addrs, opts)
    729867    int unit;
    730868    struct wordlist *addrs;
    731 {
    732 
     869    struct wordlist *opts;
     870{
     871    int n;
     872    struct wordlist *ap, **pap;
     873    struct permitted_ip *ip;
     874    char *ptr_word, *ptr_mask;
     875    struct hostent *hp;
     876    struct netent *np;
     877    u_int32_t a, mask, ah, offset;
     878    struct ipcp_options *wo = &ipcp_wantoptions[unit];
     879    u_int32_t suggested_ip = 0;
     880
     881    if (addresses[unit] != NULL)
     882        free(addresses[unit]);
     883    addresses[unit] = NULL;
     884    if (extra_options != NULL)
     885        free_wordlist(extra_options);
     886    extra_options = opts;
     887
     888    /*
     889     * Count the number of IP addresses given.
     890     */
     891    for (n = 0, pap = &addrs; (ap = *pap) != NULL; pap = &ap->next)
     892        ++n;
     893    if (n == 0)
     894        return;
     895    ip = (struct permitted_ip *) malloc((n + 1) * sizeof(struct permitted_ip));
     896    if (ip == 0)
     897        return;
     898
     899    n = 0;
     900    for (ap = addrs; ap != NULL; ap = ap->next) {
     901        /* "-" means no addresses authorized, "*" means any address allowed */
     902        ptr_word = ap->word;
     903        if (strcmp(ptr_word, "-") == 0)
     904            break;
     905        if (strcmp(ptr_word, "*") == 0) {
     906            ip[n].permit = 1;
     907            ip[n].base = ip[n].mask = 0;
     908            ++n;
     909            break;
     910        }
     911
     912        ip[n].permit = 1;
     913        if (*ptr_word == '!') {
     914            ip[n].permit = 0;
     915            ++ptr_word;
     916        }
     917
     918        mask = ~ (u_int32_t) 0;
     919        offset = 0;
     920        ptr_mask = strchr (ptr_word, '/');
     921        if (ptr_mask != NULL) {
     922            int bit_count;
     923            char *endp;
     924
     925            bit_count = (int) strtol (ptr_mask+1, &endp, 10);
     926            if (bit_count <= 0 || bit_count > 32) {
     927                warn("invalid address length %v in auth. address list",
     928                     ptr_mask+1);
     929                continue;
     930            }
     931            bit_count = 32 - bit_count; /* # bits in host part */
     932            if (*endp == '+') {
     933                offset = pppifunit + 1;
     934                ++endp;
     935            }
     936            if (*endp != 0) {
     937                warn("invalid address length syntax: %v", ptr_mask+1);
     938                continue;
     939            }
     940            *ptr_mask = '\0';
     941            mask <<= bit_count;
     942        }
     943
     944        hp = gethostbyname(ptr_word);
     945        if (hp != NULL && hp->h_addrtype == AF_INET) {
     946            a = *(u_int32_t *)hp->h_addr;
     947        } else {
     948            np = getnetbyname (ptr_word);
     949            if (np != NULL && np->n_addrtype == AF_INET) {
     950                a = htonl (*(u_int32_t *)np->n_net);
     951                if (ptr_mask == NULL) {
     952                    /* calculate appropriate mask for net */
     953                    ah = ntohl(a);
     954                    if (IN_CLASSA(ah))
     955                        mask = IN_CLASSA_NET;
     956                    else if (IN_CLASSB(ah))
     957                        mask = IN_CLASSB_NET;
     958                    else if (IN_CLASSC(ah))
     959                        mask = IN_CLASSC_NET;
     960                }
     961            } else {
     962                a = inet_addr (ptr_word);
     963            }
     964        }
     965
     966        if (ptr_mask != NULL)
     967            *ptr_mask = '/';
     968
     969        if (a == (u_int32_t)-1L) {
     970            warn("unknown host %s in auth. address list", ap->word);
     971            continue;
     972        }
     973        if (offset != 0) {
     974            if (offset >= ~mask) {
     975                warn("interface unit %d too large for subnet %v",
     976                     pppifunit, ptr_word);
     977                continue;
     978            }
     979            a = htonl((ntohl(a) & mask) + offset);
     980            mask = ~(u_int32_t)0;
     981        }
     982        ip[n].mask = htonl(mask);
     983        ip[n].base = a & ip[n].mask;
     984        ++n;
     985        if (~mask == 0 && suggested_ip == 0)
     986            suggested_ip = a;
     987    }
     988
     989    ip[n].permit = 0;           /* make the last entry forbid all addresses */
     990    ip[n].base = 0;             /* to terminate the list */
     991    ip[n].mask = 0;
     992
     993    addresses[unit] = ip;
     994
     995    /*
     996     * If the address given for the peer isn't authorized, or if
     997     * the user hasn't given one, AND there is an authorized address
     998     * which is a single host, then use that if we find one.
     999     */
     1000    if (suggested_ip != 0
     1001        && (wo->hisaddr == 0 || !auth_ip_addr(unit, wo->hisaddr)))
     1002        wo->hisaddr = suggested_ip;
    7331003}
    7341004
     
    7421012    u_int32_t addr;
    7431013{
    744     return ip_addr_check(addr, addresses[unit]);
     1014    int ok;
     1015
     1016    /* don't allow loopback or multicast address */
     1017    if (bad_ip_adrs(addr))
     1018        return 0;
     1019
     1020    if (addresses[unit] != NULL) {
     1021        ok = ip_addr_check(addr, addresses[unit]);
     1022        if (ok >= 0)
     1023            return ok;
     1024    }
     1025    if (auth_required)
     1026        return 0;               /* no addresses authorized */
     1027    return allow_any_ip || !have_route_to(addr);
    7451028}
    7461029
     
    7481031ip_addr_check(addr, addrs)
    7491032    u_int32_t addr;
    750     struct wordlist *addrs;
    751 {
    752 #if 0
    753     u_int32_t a, mask, ah;
    754     int accept;
    755     char *ptr_word, *ptr_mask;
    756     struct hostent *hp;
    757     struct netent *np;
    758 #endif
    759 
    760     /* don't allow loopback or multicast address */
    761     if (bad_ip_adrs(addr))
    762         return 0;
    763 
    764     if (addrs == NULL)
    765         return !auth_required;          /* no addresses authorized */
    766 
    767         return 1;
     1033    struct permitted_ip *addrs;
     1034{
     1035    for (; ; ++addrs)
     1036        if ((addr & addrs->mask) == addrs->base)
     1037            return addrs->permit;
    7681038}
    7691039
     
    7801050    return (addr >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET
    7811051        || IN_MULTICAST(addr) || IN_BADCLASS(addr);
    782 }
    783 
    784 /*
    785  * check_access - complain if a secret file has too-liberal permissions.
    786  */
    787 void
    788 check_access(f, filename)
    789     FILE *f;
    790     char *filename;
    791 {
    792 
    793 }
    794 
    795 
    796 /*
    797  * scan_authfile - Scan an authorization file for a secret suitable
    798  * for authenticating `client' on `server'.  The return value is -1
    799  * if no secret is found, otherwise >= 0.  The return value has
    800  * NONWILD_CLIENT set if the secret didn't have "*" for the client, and
    801  * NONWILD_SERVER set if the secret didn't have "*" for the server.
    802  * Any following words on the line (i.e. address authorization
    803  * info) are placed in a wordlist and returned in *addrs. 
    804  */
    805 static int
    806 scan_authfile(f, client, server, ipaddr, secret, addrs, filename)
    807     FILE *f;
    808     char *client;
    809     char *server;
    810     u_int32_t ipaddr;
    811     char *secret;
    812     struct wordlist **addrs;
    813     char *filename;
    814 {
    815 
    816     return -1;
    8171052}
    8181053
     
    8381073 */
    8391074static void
    840 auth_script(script)
    841     char *script;
    842 {
    843 }
     1075auth_script(s)
     1076    enum script_state s;
     1077{
     1078    switch (s) {
     1079    case s_up:
     1080        auth_script_state = s_up;
     1081        if ( auth_linkup_hook ) {
     1082          (*auth_linkup_hook)();
     1083        }
     1084        break;
     1085    case s_down:
     1086        auth_script_state = s_down;
     1087        if ( auth_linkdown_hook ) {
     1088          (*auth_linkdown_hook)();
     1089        }
     1090        break;
     1091    }
     1092}
  • cpukit/pppd/ccp.c

    r4b3c197f r2f1b930  
    2626 */
    2727
    28 #ifndef lint
    29 /* static char rcsid[] = "$Id$"; */
    30 #endif
    31 
     28#define RCSID   "$Id$"
     29
     30#include <stdlib.h>
    3231#include <string.h>
    33 #include <syslog.h>
    34 #include <sys/ioctl.h>
    35 #include <sys/types.h>
    3632
    3733#include "pppd.h"
     
    3935#include "ccp.h"
    4036#include <net/ppp-comp.h>
     37
     38static const char rcsid[] = RCSID;
     39
     40/*
     41 * Command-line options.
     42 */
     43static int setbsdcomp __P((char **));
     44static int setdeflate __P((char **));
     45
     46static option_t ccp_option_list[] = {
     47    { "noccp", o_bool, &ccp_protent.enabled_flag,
     48      "Disable CCP negotiation" },
     49    { "-ccp", o_bool, &ccp_protent.enabled_flag,
     50      "Disable CCP negotiation" },
     51    { "bsdcomp", o_special, setbsdcomp,
     52      "Request BSD-Compress packet compression" },
     53    { "nobsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
     54      "don't allow BSD-Compress", OPT_A2COPY,
     55      &ccp_allowoptions[0].bsd_compress },
     56    { "-bsdcomp", o_bool, &ccp_wantoptions[0].bsd_compress,
     57      "don't allow BSD-Compress", OPT_A2COPY,
     58      &ccp_allowoptions[0].bsd_compress },
     59    { "deflate", 1, setdeflate,
     60      "request Deflate compression" },
     61    { "nodeflate", o_bool, &ccp_wantoptions[0].deflate,
     62      "don't allow Deflate compression", OPT_A2COPY,
     63      &ccp_allowoptions[0].deflate },
     64    { "-deflate", o_bool, &ccp_wantoptions[0].deflate,
     65      "don't allow Deflate compression", OPT_A2COPY,
     66      &ccp_allowoptions[0].deflate },
     67    { "nodeflatedraft", o_bool, &ccp_wantoptions[0].deflate_draft,
     68      "don't use draft deflate #", OPT_A2COPY,
     69      &ccp_allowoptions[0].deflate_draft },
     70    { "predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
     71      "request Predictor-1", 1, &ccp_allowoptions[0].predictor_1 },
     72    { "nopredictor1", o_bool, &ccp_wantoptions[0].predictor_1,
     73      "don't allow Predictor-1", OPT_A2COPY,
     74      &ccp_allowoptions[0].predictor_1 },
     75    { "-predictor1", o_bool, &ccp_wantoptions[0].predictor_1,
     76      "don't allow Predictor-1", OPT_A2COPY,
     77      &ccp_allowoptions[0].predictor_1 },
     78
     79    { NULL }
     80};
    4181
    4282/*
     
    68108    1,
    69109    "CCP",
     110    "Compressed",
     111    ccp_option_list,
    70112    NULL,
    71113    NULL,
     
    131173
    132174/*
     175 * Option parsing.
     176 */
     177static int
     178setbsdcomp(argv)
     179    char **argv;
     180{
     181    int rbits, abits;
     182    char *str, *endp;
     183
     184    str = *argv;
     185    abits = rbits = strtol(str, &endp, 0);
     186    if (endp != str && *endp == ',') {
     187        str = endp + 1;
     188        abits = strtol(str, &endp, 0);
     189    }
     190    if (*endp != 0 || endp == str) {
     191        option_error("invalid parameter '%s' for bsdcomp option", *argv);
     192        return 0;
     193    }
     194    if ((rbits != 0 && (rbits < BSD_MIN_BITS || rbits > BSD_MAX_BITS))
     195        || (abits != 0 && (abits < BSD_MIN_BITS || abits > BSD_MAX_BITS))) {
     196        option_error("bsdcomp option values must be 0 or %d .. %d",
     197                     BSD_MIN_BITS, BSD_MAX_BITS);
     198        return 0;
     199    }
     200    if (rbits > 0) {
     201        ccp_wantoptions[0].bsd_compress = 1;
     202        ccp_wantoptions[0].bsd_bits = rbits;
     203    } else
     204        ccp_wantoptions[0].bsd_compress = 0;
     205    if (abits > 0) {
     206        ccp_allowoptions[0].bsd_compress = 1;
     207        ccp_allowoptions[0].bsd_bits = abits;
     208    } else
     209        ccp_allowoptions[0].bsd_compress = 0;
     210    return 1;
     211}
     212
     213static int
     214setdeflate(argv)
     215    char **argv;
     216{
     217    int rbits, abits;
     218    char *str, *endp;
     219
     220    str = *argv;
     221    abits = rbits = strtol(str, &endp, 0);
     222    if (endp != str && *endp == ',') {
     223        str = endp + 1;
     224        abits = strtol(str, &endp, 0);
     225    }
     226    if (*endp != 0 || endp == str) {
     227        option_error("invalid parameter '%s' for deflate option", *argv);
     228        return 0;
     229    }
     230    if ((rbits != 0 && (rbits < DEFLATE_MIN_SIZE || rbits > DEFLATE_MAX_SIZE))
     231        || (abits != 0 && (abits < DEFLATE_MIN_SIZE
     232                          || abits > DEFLATE_MAX_SIZE))) {
     233        option_error("deflate option values must be 0 or %d .. %d",
     234                     DEFLATE_MIN_SIZE, DEFLATE_MAX_SIZE);
     235        return 0;
     236    }
     237    if (rbits > 0) {
     238        ccp_wantoptions[0].deflate = 1;
     239        ccp_wantoptions[0].deflate_size = rbits;
     240    } else
     241        ccp_wantoptions[0].deflate = 0;
     242    if (abits > 0) {
     243        ccp_allowoptions[0].deflate = 1;
     244        ccp_allowoptions[0].deflate_size = abits;
     245    } else
     246        ccp_allowoptions[0].deflate = 0;
     247    return 1;
     248}
     249
     250
     251/*
    133252 * ccp_init - initialize CCP.
    134253 */
     
    238357    oldstate = f->state;
    239358    fsm_input(f, p, len);
    240     if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED);
    241         syslog(LOG_NOTICE, "Compression disabled by peer.");
     359    if (oldstate == OPENED && p[0] == TERMREQ && f->state != OPENED)
     360        notice("Compression disabled by peer.");
    242361
    243362    /*
     
    590709     * Predictor-1 and 2 have no options, so they can't be Naked.
    591710     *
    592      * XXX What should we do with any remaining options?
     711     * There may be remaining options but we ignore them.
    593712     */
    594 
    595     if (len != 0)
    596         return 0;
    597713
    598714    if (f->state != OPENED)
     
    873989    case CI_DEFLATE_DRAFT:
    874990        if (opt2 != NULL && opt2->deflate_size != opt->deflate_size)
    875             sprintf(result, "Deflate%s (%d/%d)",
    876                     (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
    877                     opt->deflate_size, opt2->deflate_size);
     991            slprintf(result, sizeof(result), "Deflate%s (%d/%d)",
     992                     (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
     993                     opt->deflate_size, opt2->deflate_size);
    878994        else
    879             sprintf(result, "Deflate%s (%d)",
    880                     (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
    881                     opt->deflate_size);
     995            slprintf(result, sizeof(result), "Deflate%s (%d)",
     996                     (opt->method == CI_DEFLATE_DRAFT? "(old#)": ""),
     997                     opt->deflate_size);
    882998        break;
    883999    case CI_BSD_COMPRESS:
    8841000        if (opt2 != NULL && opt2->bsd_bits != opt->bsd_bits)
    885             sprintf(result, "BSD-Compress (%d/%d)", opt->bsd_bits,
    886                     opt2->bsd_bits);
     1001            slprintf(result, sizeof(result), "BSD-Compress (%d/%d)",
     1002                     opt->bsd_bits, opt2->bsd_bits);
    8871003        else
    888             sprintf(result, "BSD-Compress (%d)", opt->bsd_bits);
     1004            slprintf(result, sizeof(result), "BSD-Compress (%d)",
     1005                     opt->bsd_bits);
    8891006        break;
    8901007    case CI_PREDICTOR_1:
     
    8931010        return "Predictor 2";
    8941011    default:
    895         sprintf(result, "Method %d", opt->method);
     1012        slprintf(result, sizeof(result), "Method %d", opt->method);
    8961013    }
    8971014    return result;
     
    9131030        if (ANY_COMPRESS(*ho)) {
    9141031            if (go->method == ho->method) {
    915                 syslog(LOG_NOTICE, "%s compression enabled",
    916                        method_name(go, ho))
    917 ;
     1032                notice("%s compression enabled", method_name(go, ho));
    9181033            } else {
    919                 strcpy(method1, method_name(go, NULL));
    920                 syslog(LOG_NOTICE, "%s / %s compression enabled",
    921                        method1, method_name(ho, NULL))
    922 ;
     1034                strlcpy(method1, method_name(go, NULL), sizeof(method1));
     1035                notice("%s / %s compression enabled",
     1036                       method1, method_name(ho, NULL));
    9231037            }
    9241038        } else
    925             syslog(LOG_NOTICE, "%s receive compression enabled",
    926                    method_name(go, NULL))
    927 ;
     1039            notice("%s receive compression enabled", method_name(go, NULL));
    9281040    } else if (ANY_COMPRESS(*ho))
    929         syslog(LOG_NOTICE, "%s transmit compression enabled",
    930                method_name(ho, NULL))
    931 ;
     1041        notice("%s transmit compression enabled", method_name(ho, NULL));
    9321042}
    9331043
     
    10321142                break;
    10331143            }
    1034 /*          while (p < optend)
     1144            while (p < optend)
    10351145                printer(arg, " %.2x", *p++);
    10361146            printer(arg, ">");
    1037 */      }
     1147        }
    10381148        break;
    10391149
    10401150    case TERMACK:
    10411151    case TERMREQ:
    1042 /*      if (len > 0 && *p >= ' ' && *p < 0x7f) {
     1152        if (len > 0 && *p >= ' ' && *p < 0x7f) {
    10431153            print_string(p, len, printer, arg);
    10441154            p += len;
    10451155            len = 0;
    10461156        }
    1047 */      break;
     1157        break;
    10481158    }
    10491159
    10501160    /* dump out the rest of the packet in hex */
    1051 /*    while (--len >= 0)
     1161    while (--len >= 0)
    10521162        printer(arg, " %.2x", *p++);
    1053 */
     1163
    10541164    return p - p0;
    10551165}
     
    10811191             * Disable compression by taking CCP down.
    10821192             */
    1083             syslog(LOG_ERR, "Lost compression sync: disabling compression");
     1193            error("Lost compression sync: disabling compression");
    10841194            ccp_close(unit, "Lost compression sync");
    10851195        } else {
  • cpukit/pppd/ccp.h

    r4b3c197f r2f1b930  
    2929
    3030typedef struct ccp_options {
    31     u_int bsd_compress: 1;      /* do BSD Compress? */
    32     u_int deflate: 1;           /* do Deflate? */
    33     u_int predictor_1: 1;       /* do Predictor-1? */
    34     u_int predictor_2: 1;       /* do Predictor-2? */
    35     u_int deflate_correct: 1;   /* use correct code for deflate? */
    36     u_int deflate_draft: 1;     /* use draft RFC code for deflate? */
     31    bool bsd_compress;          /* do BSD Compress? */
     32    bool deflate;               /* do Deflate? */
     33    bool predictor_1;           /* do Predictor-1? */
     34    bool predictor_2;           /* do Predictor-2? */
     35    bool deflate_correct;       /* use correct code for deflate? */
     36    bool deflate_draft;         /* use draft RFC code for deflate? */
    3737    u_short bsd_bits;           /* # bits/code for BSD Compress */
    3838    u_short deflate_size;       /* lg(window size) for Deflate */
  • cpukit/pppd/chap.c

    r4b3c197f r2f1b930  
    3434 */
    3535
    36 #ifndef lint
    37 /* static char rcsid[] = "$Id$"; */
    38 #endif
     36#define RCSID   "$Id$"
    3937
    4038/*
     
    4644#include <sys/types.h>
    4745#include <sys/time.h>
    48 #include <syslog.h>
    4946
    5047#include "pppd.h"
     
    5451#include "chap_ms.h"
    5552#endif
     53
     54static const char rcsid[] = RCSID;
     55
     56/*
     57 * Command-line options.
     58 */
     59static option_t chap_option_list[] = {
     60    { "chap-restart", o_int, &chap[0].timeouttime,
     61      "Set timeout for CHAP" },
     62    { "chap-max-challenge", o_int, &chap[0].max_transmits,
     63      "Set max #xmits for challenge" },
     64    { "chap-interval", o_int, &chap[0].chal_interval,
     65      "Set interval for rechallenge" },
     66#ifdef MSLANMAN
     67    { "ms-lanman", o_bool, &ms_lanman,
     68      "Use LanMan passwd when using MS-CHAP", 1 },
     69#endif
     70    { NULL }
     71};
    5672
    5773/*
     
    8096    "CHAP",
    8197    NULL,
     98    chap_option_list,
     99    NULL,
    82100    NULL,
    83101    NULL
     
    97115static void ChapSendResponse __P((chap_state *));
    98116static void ChapGenChallenge __P((chap_state *));
    99 /* #include <stdlib.h> */
    100117
    101118extern double drand48 __P((void));
    102 /*{
    103         return (((double)rand())/RAND_MAX);
    104 }
    105 */
    106119extern void srand48 __P((long));
    107120
     
    200213    if (cstate->chal_transmits >= cstate->max_transmits) {
    201214        /* give up on peer */
    202         syslog(LOG_ERR, "Peer failed to respond to CHAP challenge");
     215        error("Peer failed to respond to CHAP challenge");
    203216        cstate->serverstate = CHAPSS_BADAUTH;
    204217        auth_peer_fail(cstate->unit, PPP_CHAP);
     
    337350    inp = inpacket;
    338351    if (packet_len < CHAP_HEADERLEN) {
    339         CHAPDEBUG((LOG_INFO, "ChapInput: rcvd short header."));
     352        CHAPDEBUG(("ChapInput: rcvd short header."));
    340353        return;
    341354    }
     
    344357    GETSHORT(len, inp);
    345358    if (len < CHAP_HEADERLEN) {
    346         CHAPDEBUG((LOG_INFO, "ChapInput: rcvd illegal length."));
     359        CHAPDEBUG(("ChapInput: rcvd illegal length."));
    347360        return;
    348361    }
    349362    if (len > packet_len) {
    350         CHAPDEBUG((LOG_INFO, "ChapInput: rcvd short packet."));
     363        CHAPDEBUG(("ChapInput: rcvd short packet."));
    351364        return;
    352365    }
     
    374387
    375388    default:                            /* Need code reject? */
    376         syslog(LOG_WARNING, "Unknown CHAP code (%d) received.", code);
     389        warn("Unknown CHAP code (%d) received.", code);
    377390        break;
    378391    }
     
    398411    u_char hash[MD5_SIGNATURE_SIZE];
    399412 
    400     CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: Rcvd id %d.", id));
    401413    if (cstate->clientstate == CHAPCS_CLOSED ||
    402414        cstate->clientstate == CHAPCS_PENDING) {
    403         CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: in state %d",
    404                    cstate->clientstate));
     415        CHAPDEBUG(("ChapReceiveChallenge: in state %d", cstate->clientstate));
    405416        return;
    406417    }
    407418
    408419    if (len < 2) {
    409         CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: rcvd short packet."));
     420        CHAPDEBUG(("ChapReceiveChallenge: rcvd short packet."));
    410421        return;
    411422    }
     
    414425    len -= sizeof (u_char) + rchallenge_len;    /* now name field length */
    415426    if (len < 0) {
    416         CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: rcvd short packet."));
     427        CHAPDEBUG(("ChapReceiveChallenge: rcvd short packet."));
    417428        return;
    418429    }
     
    425436    rhostname[len] = '\000';
    426437
    427     CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: received name field '%s'",
    428                rhostname));
    429 
    430438    /* Microsoft doesn't send their name back in the PPP packet */
    431     if (remote_name[0] != 0 && (explicit_remote || rhostname[0] == 0)) {
    432         strncpy(rhostname, remote_name, sizeof(rhostname));
    433         rhostname[sizeof(rhostname) - 1] = 0;
    434         CHAPDEBUG((LOG_INFO, "ChapReceiveChallenge: using '%s' as remote name",
     439    if (explicit_remote || (remote_name[0] != 0 && rhostname[0] == 0)) {
     440        strlcpy(rhostname, remote_name, sizeof(rhostname));
     441        CHAPDEBUG(("ChapReceiveChallenge: using '%q' as remote name",
    435442                   rhostname));
    436443    }
     
    440447                    secret, &secret_len, 0)) {
    441448        secret_len = 0;         /* assume null secret if can't find one */
    442         syslog(LOG_WARNING, "No CHAP secret found for authenticating us to %s",
    443                rhostname);
     449        warn("No CHAP secret found for authenticating us to %q", rhostname);
    444450    }
    445451
     
    471477
    472478    default:
    473         CHAPDEBUG((LOG_INFO, "unknown digest type %d", cstate->resp_type));
     479        CHAPDEBUG(("unknown digest type %d", cstate->resp_type));
    474480        return;
    475481    }
     
    498504    u_char hash[MD5_SIGNATURE_SIZE];
    499505
    500     CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: Rcvd id %d.", id));
    501 
    502506    if (cstate->serverstate == CHAPSS_CLOSED ||
    503507        cstate->serverstate == CHAPSS_PENDING) {
    504         CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: in state %d",
    505                    cstate->serverstate));
     508        CHAPDEBUG(("ChapReceiveResponse: in state %d", cstate->serverstate));
    506509        return;
    507510    }
     
    525528
    526529    if (len < 2) {
    527         CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: rcvd short packet."));
     530        CHAPDEBUG(("ChapReceiveResponse: rcvd short packet."));
    528531        return;
    529532    }
     
    534537    len -= sizeof (u_char) + remmd_len;
    535538    if (len < 0) {
    536         CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: rcvd short packet."));
     539        CHAPDEBUG(("ChapReceiveResponse: rcvd short packet."));
    537540        return;
    538541    }
     
    544547    BCOPY(inp, rhostname, len);
    545548    rhostname[len] = '\000';
    546 
    547     CHAPDEBUG((LOG_INFO, "ChapReceiveResponse: received name field: %s",
    548                rhostname));
    549549
    550550    /*
     
    553553     */
    554554    code = CHAP_FAILURE;
    555     if (!get_secret(cstate->unit, rhostname, cstate->chal_name,
    556                    secret, &secret_len, 1)) {
    557         syslog(LOG_WARNING, "No CHAP secret found for authenticating %s",
    558                rhostname);
     555    if (!get_secret(cstate->unit, (explicit_remote? remote_name: rhostname),
     556                    cstate->chal_name, secret, &secret_len, 1)) {
     557        warn("No CHAP secret found for authenticating %q", rhostname);
    559558    } else {
    560559
     
    577576
    578577        default:
    579             CHAPDEBUG((LOG_INFO, "unknown digest type %d", cstate->chal_type));
     578            CHAPDEBUG(("unknown digest type %d", cstate->chal_type));
    580579        }
    581580    }
     
    592591        if (cstate->chal_interval != 0)
    593592            TIMEOUT(ChapRechallenge, cstate, cstate->chal_interval);
    594         syslog(LOG_NOTICE, "CHAP peer authentication succeeded for %s",
    595                rhostname);
     593        notice("CHAP peer authentication succeeded for %q", rhostname);
    596594
    597595    } else {
    598         syslog(LOG_ERR, "CHAP peer authentication failed for remote host %s",
    599                rhostname);
     596        error("CHAP peer authentication failed for remote host %q", rhostname);
    600597        cstate->serverstate = CHAPSS_BADAUTH;
    601598        auth_peer_fail(cstate->unit, PPP_CHAP);
     
    610607    chap_state *cstate;
    611608    u_char *inp;
    612     int id;  /* was u_char id */
     609    u_char id;
    613610    int len;
    614611{
    615 
    616     CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: Rcvd id %d.", id));
    617612
    618613    if (cstate->clientstate == CHAPCS_OPEN)
     
    622617    if (cstate->clientstate != CHAPCS_RESPONSE) {
    623618        /* don't know what this is */
    624         CHAPDEBUG((LOG_INFO, "ChapReceiveSuccess: in state %d\n",
    625                    cstate->clientstate));
     619        CHAPDEBUG(("ChapReceiveSuccess: in state %d\n", cstate->clientstate));
    626620        return;
    627621    }
     
    648642    chap_state *cstate;
    649643    u_char *inp;
    650     int id;  /* was u_char id; */
     644    u_char id;
    651645    int len;
    652646{
    653     CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: Rcvd id %d.", id));
    654 
    655647    if (cstate->clientstate != CHAPCS_RESPONSE) {
    656648        /* don't know what this is */
    657         CHAPDEBUG((LOG_INFO, "ChapReceiveFailure: in state %d\n",
    658                    cstate->clientstate));
     649        CHAPDEBUG(("ChapReceiveFailure: in state %d\n", cstate->clientstate));
    659650        return;
    660651    }
     
    668659        PRINTMSG(inp, len);
    669660
    670     syslog(LOG_ERR, "CHAP authentication failed");
     661    error("CHAP authentication failed");
    671662    auth_withpeer_fail(cstate->unit, PPP_CHAP);
    672663}
     
    703694    output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
    704695 
    705     CHAPDEBUG((LOG_INFO, "ChapSendChallenge: Sent id %d.", cstate->chal_id));
    706 
    707696    TIMEOUT(ChapChallengeTimeout, cstate, cstate->timeouttime);
    708697    ++cstate->chal_transmits;
     
    723712
    724713    if (code == CHAP_SUCCESS)
    725         sprintf(msg, "Welcome to %s.", hostname);
     714        slprintf(msg, sizeof(msg), "Welcome to %s.", hostname);
    726715    else
    727         sprintf(msg, "I don't like you.  Go 'way.");
     716        slprintf(msg, sizeof(msg), "I don't like you.  Go 'way.");
    728717    msglen = strlen(msg);
    729718
     
    738727    BCOPY(msg, outp, msglen);
    739728    output(cstate->unit, outpacket_buf, outlen + PPP_HDRLEN);
    740  
    741     CHAPDEBUG((LOG_INFO, "ChapSendStatus: Sent code %d, id %d.", code,
    742                cstate->chal_id));
    743729}
    744730
     
    756742    int chal_len;
    757743    u_char *ptr = cstate->challenge;
    758     unsigned int i;
     744    int i;
    759745
    760746    /* pick a random challenge length between MIN_CHALLENGE_LENGTH and
     
    768754
    769755    /* generate a random string */
    770     for (i = 0; i < chal_len; i++ )
     756    for (i = 0; i < chal_len; i++)
    771757        *ptr++ = (char) (drand48() * 0xff);
    772758}
     
    826812    int clen, nlen;
    827813    u_char x;
     814
    828815    if (plen < CHAP_HEADERLEN)
    829816        return 0;
     
    869856        }
    870857    }
     858
    871859    return len + CHAP_HEADERLEN;
    872860}
  • cpukit/pppd/chap.h

    r4b3c197f r2f1b930  
    5656 *  Challenge lengths (for challenges we send) and other limits.
    5757 */
    58 #define MIN_CHALLENGE_LENGTH    32
    59 #define MAX_CHALLENGE_LENGTH    64
     58#define MIN_CHALLENGE_LENGTH    16
     59#define MAX_CHALLENGE_LENGTH    24
    6060#define MAX_RESPONSE_LENGTH     64      /* sufficient for MD5 or MS-CHAP */
    6161
  • cpukit/pppd/chap_ms.c

    r4b3c197f r2f1b930  
    3232 */
    3333
    34 #ifndef lint
    35 /* static char rcsid[] = "$Id$"; */
    36 #endif
     34#define RCSID   "$Id$"
    3735
    3836#ifdef CHAPMS
    3937
    4038#include <stdio.h>
     39#include <stdlib.h>
    4140#include <string.h>
    4241#include <ctype.h>
    4342#include <sys/types.h>
    4443#include <sys/time.h>
    45 #include <syslog.h>
    4644#include <unistd.h>
    4745#ifdef HAVE_CRYPT_H
     
    5755#include <des.h>
    5856#endif
     57
     58static const char rcsid[] = RCSID;
    5959
    6060typedef struct {
     
    8181#endif
    8282
     83#ifdef MSLANMAN
     84bool    ms_lanman = 0;          /* Use LanMan password instead of NT */
     85                                /* Has meaning only with MS-CHAP challenges */
     86#endif
     87
    8388static void
    8489ChallengeResponse(challenge, pwHash, response)
     
    9398
    9499#if 0
    95     log_packet(ZPasswordHash, sizeof(ZPasswordHash), "ChallengeResponse - ZPasswordHash", LOG_DEBUG);
     100    dbglog("ChallengeResponse - ZPasswordHash %.*B",
     101           sizeof(ZPasswordHash), ZPasswordHash);
    96102#endif
    97103
     
    101107
    102108#if 0
    103     log_packet(response, 24, "ChallengeResponse - response", LOG_DEBUG);
     109    dbglog("ChallengeResponse - response %.24B", response);
    104110#endif
    105111}
     
    123129
    124130#if 0
    125     CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X",
    126                clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
     131    CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %.8B", clear));
    127132#endif
    128133
     
    132137
    133138#if 0
    134     CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X",
    135                cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
     139    CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %.8B", cipher));
    136140#endif
    137141}
     
    153157
    154158#if 0
    155     CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %02X%02X%02X%02X%02X%02X%02X%02X",
    156                clear[0], clear[1], clear[2], clear[3], clear[4], clear[5], clear[6], clear[7]));
     159    CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet input : %.8B", clear));
    157160#endif
    158161
     
    160163
    161164#if 0
    162     CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %02X%02X%02X%02X%02X%02X%02X%02X",
    163                cipher[0], cipher[1], cipher[2], cipher[3], cipher[4], cipher[5], cipher[6], cipher[7]));
     165    CHAPDEBUG((LOG_INFO, "DesEncrypt: 8 octet output: %.8B", cipher));
    164166#endif
    165167}
     
    240242
    241243#if 0
    242     CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %02X%02X%02X%02X%02X%02X%02X",
    243                key[0], key[1], key[2], key[3], key[4], key[5], key[6]));
    244     CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %02X%02X%02X%02X%02X%02X%02X%02X",
    245                des_key[0], des_key[1], des_key[2], des_key[3], des_key[4], des_key[5], des_key[6], des_key[7]));
     244    CHAPDEBUG((LOG_INFO, "MakeKey: 56-bit input : %.7B", key));
     245    CHAPDEBUG((LOG_INFO, "MakeKey: 64-bit output: %.8B", des_key));
    246246#endif
    247247}
     
    256256{
    257257    int                 i;
     258#ifdef __NetBSD__
     259    /* NetBSD uses the libc md4 routines which take bytes instead of bits */
     260    int                 mdlen = secret_len * 2;
     261#else
     262    int                 mdlen = secret_len * 2 * 8;
     263#endif
    258264    MD4_CTX             md4Context;
    259265    u_char              hash[MD4_SIGNATURE_SIZE];
     
    267273
    268274    MD4Init(&md4Context);
    269     MD4Update(&md4Context, unicodePassword, secret_len * 2 * 8);        /* Unicode is 2 bytes/char, *8 for bit count */
     275    MD4Update(&md4Context, unicodePassword, mdlen);
    270276
    271277    MD4Final(hash, &md4Context);        /* Tell MD4 we're done */
     
    308314{
    309315    MS_ChapResponse     response;
    310 #ifdef MSLANMAN
    311     extern int ms_lanman;
    312 #endif
    313316
    314317#if 0
  • cpukit/pppd/chat.c

    r4b3c197f r2f1b930  
    157157int report        = 0;
    158158int exit_code     = 0;
    159 static int speed=0;
    160159char *report_file = (char *) 0;
    161160char *chat_file   = (char *) 0;
     
    168167#ifdef TERMIOS
    169168#define term_parms struct termios
    170 #define get_term_param(param) tcgetattr(modem_fd, param)
    171 #define set_term_param(param) tcsetattr(modem_fd, TCSANOW, param)
     169#define get_term_param(param) tcgetattr(ttyfd, param)
     170#define set_term_param(param) tcsetattr(ttyfd, TCSANOW, param)
    172171struct termios saved_tty_parameters;
    173172#endif
     
    261260
    262261 
    263 extern int modem_fd;
    264 int
    265         chatmain(argv)
    266      char *argv;
    267 {
    268     char *arg;
    269         int i;
    270         char *t;
    271         exit_code=0;
    272         speed=0;
    273 /*
    274  * Default the report file to the stderr location
    275  */
    276 /*    if (report_fp == NULL)
    277         report_fp = stderr;
    278 */
    279     init();
    280         while ( (arg = getnextcommand(&argv)) != NULL) {
    281             chat_expect(arg);
    282                 if (exit_code>0) break;
    283             t=temp2;
    284 
    285                 while(*t)
    286                 {
    287                         if (strncmp("CARRIER",t,7)==0)
    288                         {/* parse speed information */
    289                                 i=0;
    290                                 while(!isdigit(t[i]))
    291                                         i++;
    292                                 t=&t[i];
    293                                 i=0;
    294                                 while(isdigit(t[i]))
    295                                         i++;
    296                                 t[i]=0;
    297                                 sscanf(t,"%d",&speed);
    298                                 break;                         
    299                         }
    300                         t++;
    301                 }
    302             if ((arg = getnextcommand(&argv)) != NULL)
    303                 chat_send(arg);
    304                 if (exit_code>0) break;
    305         }
    306 
    307     if (exit_code) return exit_code;
    308     return -speed;
     262extern int ttyfd;
     263int chatmain(argv)
     264char *argv;
     265{
     266  char    *arg;
     267
     268  /* initialize exit code */
     269  exit_code = 0;
     270
     271printf("chat_main: %s\n", argv);
     272
     273  /* get first expect string */
     274  arg = getnextcommand(&argv);
     275  while ( arg != NULL ) {
     276    /* process the expect string */
     277    chat_expect(arg);
     278
     279    /* get the next send string */
     280    arg = getnextcommand(&argv);
     281    if ( arg != NULL ) {
     282      /* process the send string */
     283      chat_send(arg);
     284
     285      /* get the next expect string */
     286      arg = getnextcommand(&argv);
     287    }
     288  }
     289
     290  return 0;
    309291}
    310292
     
    318300{
    319301    set_tty_parameters();
    320         speed=0;
    321302}
    322303
     
    658639        say_next = 0;
    659640        s = clean(s,0);
    660         write(modem_fd, s, strlen(s));
     641        write(ttyfd, s, strlen(s));
    661642        free(s);
    662643        return;
     
    682663        return;
    683664    }
    684 
    685 
    686 /*    if (report_next) {
    687         char *s1;
    688        
    689         report_next = 0;
    690         if (n_reports >= MAX_REPORTS)
    691             {
    692               exit_code=2;
    693               return;
    694             }
    695        
    696         s1 = clean(s, 0);
    697        
    698         if (strlen(s1) > strlen(s) || strlen(s1) > sizeof fail_buffer - 1)
    699             {
    700               exit_code=1;
    701               return;
    702             }
    703        
    704         report_string[n_reports++] = s1;
    705        
    706         return;
    707     }
    708 */
    709 /*    if (clear_report_next) {
    710         char *s1;
    711         int   i;
    712         int   old_max;
    713         int   pack = 0;
    714        
    715         clear_report_next = 0;
    716        
    717         s1 = clean(s, 0);
    718        
    719         if (strlen(s1) > strlen(s) || strlen(s1) > sizeof fail_buffer - 1)
    720             {
    721               exit_code=1;
    722               return;
    723             }
    724 
    725         old_max = n_reports;
    726         for (i=0; i < n_reports; i++) {
    727             if ( strcmp(s1,report_string[i]) == 0 ) {
    728                 free(report_string[i]);
    729                 report_string[i] = NULL;
    730                 pack++;
    731                 n_reports--;
    732             }
    733         }
    734         free(s1);
    735         if (pack)
    736             pack_array(report_string,old_max);
    737        
    738         return;
    739     }
    740 */
    741665
    742666    if (timeout_next) {
     
    771695        while(tries)
    772696        {
    773             status = read(modem_fd, &c, 1);
     697            status = read(ttyfd, &c, 1);
    774698            switch (status) {
    775699                   case 1:
     
    790714        /* inter-character typing delay (?) */
    791715
    792     status = write(modem_fd, &ch, 1);
     716    status = write(ttyfd, &ch, 1);
    793717
    794718    switch (status) {
     
    815739register char *s;
    816740{
    817 
    818 
    819741    quiet = 0;
    820742    s = clean(s, 1);
     
    899821    struct termios tios;
    900822
    901     tcgetattr(modem_fd, &tios);
     823    tcgetattr(ttyfd, &tios);
    902824    tios.c_cc[VMIN] = 0;
    903825    tios.c_cc[VTIME] = timeout*10/MAX_TIMEOUTS;
    904     tcsetattr(modem_fd, TCSANOW, &tios);
     826    tcsetattr(ttyfd, TCSANOW, &tios);
    905827               
    906828    string = clean(string, 0);
  • cpukit/pppd/demand.c

    r4b3c197f r2f1b930  
    1818 */
    1919
    20 #ifndef lint
    21 /* static char rcsid[] = "$Id$"; */
    22 #endif
     20#define RCSID   "$Id$";
    2321
    2422#include <stdio.h>
     
    2725#include <errno.h>
    2826#include <fcntl.h>
    29 #include <syslog.h>
    3027#include <netdb.h>
    3128#include <sys/param.h>
     
    4643#include "ipcp.h"
    4744#include "lcp.h"
     45
     46static const char rcsid[] = RCSID;
    4847
    4948char *frame;
     
    263262    struct packet *pkt;
    264263
    265     /* log_packet(frame, len, "from loop: ", LOG_DEBUG); */
     264    /* dbglog("from loop: %P", frame, len); */
    266265    if (len < PPP_HDRLEN)
    267266        return 0;
  • cpukit/pppd/fsm.c

    r4b3c197f r2f1b930  
    1818 */
    1919
    20 #ifndef lint
    21 /* static char rcsid[] = "$Id$"; */
    22 #endif
    23 #define log_packet(p, len, prefix, level)
     20#define RCSID   "$Id$"
     21
    2422/*
    2523 * TODO:
     
    3129#include <string.h>
    3230#include <sys/types.h>
    33 #include <syslog.h>
    3431
    3532#include "pppd.h"
    3633#include "fsm.h"
     34
     35static const char rcsid[] = RCSID;
    3736
    3837static void fsm_timeout __P((void *));
     
    9392
    9493    default:
    95         FSMDEBUG((LOG_INFO, "%s: Up event in state %d!",
    96                   PROTO_NAME(f), f->state));
     94        FSMDEBUG(("%s: Up event in state %d!", PROTO_NAME(f), f->state));
    9795    }
    9896}
     
    139137
    140138    default:
    141         FSMDEBUG((LOG_INFO, "%s: Down event in state %d!",
    142                   PROTO_NAME(f), f->state));
     139        FSMDEBUG(("%s: Down event in state %d!", PROTO_NAME(f), f->state));
    143140    }
    144141}
     
    261258    case ACKSENT:
    262259        if (f->retransmits <= 0) {
    263             syslog(LOG_WARNING, "%s: timeout sending Config-Requests",
    264                    PROTO_NAME(f));
     260            warn("%s: timeout sending Config-Requests\n", PROTO_NAME(f));
    265261            f->state = STOPPED;
    266262            if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished )
     
    278274
    279275    default:
    280         FSMDEBUG((LOG_INFO, "%s: Timeout event in state %d!",
    281                   PROTO_NAME(f), f->state));
     276        FSMDEBUG(("%s: Timeout event in state %d!", PROTO_NAME(f), f->state));
    282277    }
    283278}
     
    303298    inp = inpacket;
    304299    if (l < HEADERLEN) {
    305         FSMDEBUG((LOG_WARNING, "fsm_input(%x): Rcvd short header.",
    306                   f->protocol));
     300        FSMDEBUG(("fsm_input(%x): Rcvd short header.", f->protocol));
    307301        return;
    308302    }
     
    311305    GETSHORT(len, inp);
    312306    if (len < HEADERLEN) {
    313         FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd illegal length.",
    314                   f->protocol));
     307        FSMDEBUG(("fsm_input(%x): Rcvd illegal length.", f->protocol));
    315308        return;
    316309    }
    317310    if (len > l) {
    318         FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd short packet.",
    319                   f->protocol));
     311        FSMDEBUG(("fsm_input(%x): Rcvd short packet.", f->protocol));
    320312        return;
    321313    }
     
    323315
    324316    if( f->state == INITIAL || f->state == STARTING ){
    325         FSMDEBUG((LOG_INFO, "fsm_input(%x): Rcvd packet in state %d.",
     317        FSMDEBUG(("fsm_input(%x): Rcvd packet in state %d.",
    326318                  f->protocol, f->state));
    327319        return;
     
    372364fsm_rconfreq(f, id, inp, len)
    373365    fsm *f;
    374     int id;
     366    u_char id;
    375367    u_char *inp;
    376368    int len;
     
    378370    int code, reject_if_disagree;
    379371
    380     FSMDEBUG((LOG_INFO, "fsm_rconfreq(%s): Rcvd id %d.", PROTO_NAME(f), id));
    381372    switch( f->state ){
    382373    case CLOSED:
     
    447438    int len;
    448439{
    449     FSMDEBUG((LOG_INFO, "fsm_rconfack(%s): Rcvd id %d.",
    450               PROTO_NAME(f), id));
    451 
    452440    if (id != f->reqid || f->seen_ack)          /* Expected id? */
    453441        return;                                 /* Nope, toss... */
     
    455443          (len == 0)) ){
    456444        /* Ack is bad - ignore it */
    457         log_packet(inp, len, "Received bad configure-ack: ", LOG_ERR);
    458         FSMDEBUG((LOG_INFO, "%s: received bad Ack (length %d)",
    459                   PROTO_NAME(f), len));
     445        error("Received bad configure-ack: %P", inp, len);
    460446        return;
    461447    }
     
    512498    int ret;
    513499
    514     FSMDEBUG((LOG_INFO, "fsm_rconfnakrej(%s): Rcvd id %d.",
    515               PROTO_NAME(f), id));
    516 
    517500    if (id != f->reqid || f->seen_ack)  /* Expected id? */
    518501        return;                         /* Nope, toss... */
     
    520503    if (!proc || !(ret = proc(f, inp, len))) {
    521504        /* Nak/reject is bad - ignore it */
    522         log_packet(inp, len, "Received bad configure-nak/rej: ", LOG_ERR);
    523         FSMDEBUG((LOG_INFO, "%s: received bad %s (length %d)",
    524                   PROTO_NAME(f), (code==CONFNAK? "Nak": "reject"), len));
     505        error("Received bad configure-nak/rej: %P", inp, len);
    525506        return;
    526507    }
     
    571552    int len;
    572553{
    573     char str[80];
    574 
    575     FSMDEBUG((LOG_INFO, "fsm_rtermreq(%s): Rcvd id %d.",
    576               PROTO_NAME(f), id));
    577 
    578554    switch (f->state) {
    579555    case ACKRCVD:
     
    584560    case OPENED:
    585561        if (len > 0) {
    586             fmtmsg(str, sizeof(str), "%0.*v", len, p);
    587             syslog(LOG_INFO, "%s terminated by peer (%s)", PROTO_NAME(f), str);
     562            info("%s terminated by peer (%0.*v)", PROTO_NAME(f), len, p);
    588563        } else
    589             syslog(LOG_INFO, "%s terminated by peer", PROTO_NAME(f));
     564            info("%s terminated by peer", PROTO_NAME(f));
    590565        if (f->callbacks->down)
    591566            (*f->callbacks->down)(f);   /* Inform upper layers */
     
    607582    fsm *f;
    608583{
    609     FSMDEBUG((LOG_INFO, "fsm_rtermack(%s).", PROTO_NAME(f)));
    610 
    611584    switch (f->state) {
    612585    case CLOSING:
     
    647620    u_char code, id;
    648621
    649     FSMDEBUG((LOG_INFO, "fsm_rcoderej(%s).", PROTO_NAME(f)));
    650 
    651622    if (len < HEADERLEN) {
    652         FSMDEBUG((LOG_INFO, "fsm_rcoderej: Rcvd short Code-Reject packet!"));
     623        FSMDEBUG(("fsm_rcoderej: Rcvd short Code-Reject packet!"));
    653624        return;
    654625    }
    655626    GETCHAR(code, inp);
    656627    GETCHAR(id, inp);
    657     syslog(LOG_WARNING, "%s: Rcvd Code-Reject for code %d, id %d",
    658            PROTO_NAME(f), code, id);
     628    warn("%s: Rcvd Code-Reject for code %d, id %d", PROTO_NAME(f), code, id);
    659629
    660630    if( f->state == ACKRCVD )
     
    709679
    710680    default:
    711         FSMDEBUG((LOG_INFO, "%s: Protocol-reject event in state %d!",
     681        FSMDEBUG(("%s: Protocol-reject event in state %d!",
    712682                  PROTO_NAME(f), f->state));
    713683    }
     
    760730    --f->retransmits;
    761731    TIMEOUT(fsm_timeout, f, f->timeouttime);
    762 
    763     FSMDEBUG((LOG_INFO, "%s: sending Configure-Request, id %d",
    764               PROTO_NAME(f), f->reqid));
    765732}
    766733
     
    774741fsm_sdata(f, code, id, data, datalen)
    775742    fsm *f;
    776     int code, id;
     743    u_char code, id;
    777744    u_char *data;
    778745    int datalen;
     
    793760    PUTSHORT(outlen, outp);
    794761    output(f->unit, outpacket_buf, outlen + PPP_HDRLEN);
    795 
    796     FSMDEBUG((LOG_INFO, "fsm_sdata(%s): Sent code %d, id %d.",
    797               PROTO_NAME(f), code, id));
    798 }
     762}
  • cpukit/pppd/fsm.h

    r4b3c197f r2f1b930  
    2323 * Packet header = Code, id, length.
    2424 */
    25 #define HEADERLEN       (sizeof (u_char) + sizeof (u_char) + sizeof (u_short))
     25#define HEADERLEN       4
    2626
    2727
  • cpukit/pppd/ipcp.c

    r4b3c197f r2f1b930  
    1818 */
    1919
    20 #ifndef lint
    21 /* static char rcsid[] = "$Id$"; */
    22 #endif
     20#define RCSID   "$Id$"
    2321
    2422/*
     
    2826#include <stdio.h>
    2927#include <string.h>
    30 #include <syslog.h>
    3128#include <netdb.h>
    3229#include <sys/param.h>
     
    3431#include <sys/socket.h>
    3532#include <netinet/in.h>
    36 /* #include <stbconfig.h> */
     33#include <arpa/inet.h>
    3734
    3835#include "pppd.h"
     
    4037#include "ipcp.h"
    4138#include "pathnames.h"
     39
     40static const char rcsid[] = RCSID;
    4241
    4342/* global vars */
     
    4746ipcp_options ipcp_hisoptions[NUM_PPP];  /* Options that we ack'd */
    4847
     48bool    disable_defaultip = 0;  /* Don't use hostname for default IP adrs */
     49
     50/* Hook for a plugin to know when IP protocol has come up */
     51void (*ip_up_hook) __P((void)) = NULL;
     52
     53/* Hook for a plugin to know when IP protocol has come down */
     54void (*ip_down_hook) __P((void)) = NULL;
     55
    4956/* local vars */
    50 static int cis_received[NUM_PPP];       /* # Conf-Reqs received */
    5157static int default_route_set[NUM_PPP];  /* Have set up a default route */
    5258static int proxy_arp_set[NUM_PPP];      /* Have created proxy arp entry */
     59static bool usepeerdns;                 /* Ask peer for DNS addrs */
     60static int ipcp_is_up;                  /* have called np_up() */
    5361
    5462/*
     
    6472static void ipcp_up __P((fsm *));               /* We're UP */
    6573static void ipcp_down __P((fsm *));             /* We're DOWN */
    66 #if 0
    67 static void ipcp_script __P((fsm *, char *)); /* Run an up/down script */
    68 #endif
    6974static void ipcp_finished __P((fsm *)); /* Don't need lower layer */
    7075
     
    9095
    9196/*
     97 * Command-line options.
     98 */
     99static int setvjslots __P((char **));
     100static int setdnsaddr __P((char **));
     101static int setwinsaddr __P((char **));
     102
     103static option_t ipcp_option_list[] = {
     104    { "noip", o_bool, &ipcp_protent.enabled_flag,
     105      "Disable IP and IPCP" },
     106    { "-ip", o_bool, &ipcp_protent.enabled_flag,
     107      "Disable IP and IPCP" },
     108    { "novj", o_bool, &ipcp_wantoptions[0].neg_vj,
     109      "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
     110    { "-vj", o_bool, &ipcp_wantoptions[0].neg_vj,
     111      "Disable VJ compression", OPT_A2COPY, &ipcp_allowoptions[0].neg_vj },
     112    { "novjccomp", o_bool, &ipcp_wantoptions[0].cflag,
     113      "Disable VJ connection-ID compression", OPT_A2COPY,
     114      &ipcp_allowoptions[0].cflag },
     115    { "-vjccomp", o_bool, &ipcp_wantoptions[0].cflag,
     116      "Disable VJ connection-ID compression", OPT_A2COPY,
     117      &ipcp_allowoptions[0].cflag },
     118    { "vj-max-slots", 1, setvjslots,
     119      "Set maximum VJ header slots" },
     120    { "ipcp-accept-local", o_bool, &ipcp_wantoptions[0].accept_local,
     121      "Accept peer's address for us", 1 },
     122    { "ipcp-accept-remote", o_bool, &ipcp_wantoptions[0].accept_remote,
     123      "Accept peer's address for it", 1 },
     124    { "ipparam", o_string, &ipparam,
     125      "Set ip script parameter" },
     126    { "noipdefault", o_bool, &disable_defaultip,
     127      "Don't use name for default IP adrs", 1 },
     128    { "ms-dns", 1, setdnsaddr,
     129      "DNS address for the peer's use" },
     130    { "ms-wins", 1, setwinsaddr,
     131      "Nameserver for SMB over TCP/IP for peer" },
     132    { "ipcp-restart", o_int, &ipcp_fsm[0].timeouttime,
     133      "Set timeout for IPCP" },
     134    { "ipcp-max-terminate", o_int, &ipcp_fsm[0].maxtermtransmits,
     135      "Set max #xmits for term-reqs" },
     136    { "ipcp-max-configure", o_int, &ipcp_fsm[0].maxconfreqtransmits,
     137      "Set max #xmits for conf-reqs" },
     138    { "ipcp-max-failure", o_int, &ipcp_fsm[0].maxnakloops,
     139      "Set max #conf-naks for IPCP" },
     140    { "defaultroute", o_bool, &ipcp_wantoptions[0].default_route,
     141      "Add default route", OPT_ENABLE|1, &ipcp_allowoptions[0].default_route },
     142    { "nodefaultroute", o_bool, &ipcp_allowoptions[0].default_route,
     143      "disable defaultroute option", OPT_A2COPY,
     144      &ipcp_wantoptions[0].default_route },
     145    { "-defaultroute", o_bool, &ipcp_allowoptions[0].default_route,
     146      "disable defaultroute option", OPT_A2COPY,
     147      &ipcp_wantoptions[0].default_route },
     148    { "proxyarp", o_bool, &ipcp_wantoptions[0].proxy_arp,
     149      "Add proxy ARP entry", OPT_ENABLE|1, &ipcp_allowoptions[0].proxy_arp },
     150    { "noproxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
     151      "disable proxyarp option", OPT_A2COPY,
     152      &ipcp_wantoptions[0].proxy_arp },
     153    { "-proxyarp", o_bool, &ipcp_allowoptions[0].proxy_arp,
     154      "disable proxyarp option", OPT_A2COPY,
     155      &ipcp_wantoptions[0].proxy_arp },
     156    { "usepeerdns", o_bool, &usepeerdns,
     157      "Ask peer for DNS address(es)", 1 },
     158    { NULL }
     159};
     160
     161/*
    92162 * Protocol entry points from main code.
    93163 */
     
    104174static int  ip_demand_conf __P((int));
    105175static int  ip_active_pkt __P((u_char *, int));
     176static void create_resolv __P((u_int32_t, u_int32_t));
    106177
    107178struct protent ipcp_protent = {
     
    118189    1,
    119190    "IPCP",
     191    "IP",
     192    ipcp_option_list,
    120193    ip_check_options,
    121194    ip_demand_conf,
     
    123196};
    124197
    125 static void ipcp_clear_addrs __P((int));
     198static void ipcp_clear_addrs __P((int, u_int32_t, u_int32_t));
    126199
    127200/*
     
    138211                         (x) == CONFNAK ? "NAK" : "REJ")
    139212
    140 
    141213/*
    142214 * Make a string representation of a network IP address.
     
    148220    static char b[64];
    149221
    150     ipaddr = ntohl(ipaddr);
    151 
    152     sprintf(b, "%d.%d.%d.%d",
    153             (u_char)(ipaddr >> 24),
    154             (u_char)(ipaddr >> 16),
    155             (u_char)(ipaddr >> 8),
    156             (u_char)(ipaddr));
     222    slprintf(b, sizeof(b), "%I", ipaddr);
    157223    return b;
     224}
     225
     226/*
     227 * Option parsing.
     228 */
     229
     230/*
     231 * setvjslots - set maximum number of connection slots for VJ compression
     232 */
     233static int
     234setvjslots(argv)
     235    char **argv;
     236{
     237    int value;
     238
     239    if (!int_option(*argv, &value))
     240        return 0;
     241    if (value < 2 || value > 16) {
     242        option_error("vj-max-slots value must be between 2 and 16");
     243        return 0;
     244    }
     245    ipcp_wantoptions [0].maxslotindex =
     246        ipcp_allowoptions[0].maxslotindex = value - 1;
     247    return 1;
     248}
     249
     250/*
     251 * setdnsaddr - set the dns address(es)
     252 */
     253static int
     254setdnsaddr(argv)
     255    char **argv;
     256{
     257    u_int32_t dns;
     258    struct hostent *hp;
     259
     260    dns = inet_addr(*argv);
     261    if (dns == (u_int32_t) -1) {
     262        if ((hp = gethostbyname(*argv)) == NULL) {
     263            option_error("invalid address parameter '%s' for ms-dns option",
     264                         *argv);
     265            return 0;
     266        }
     267        dns = *(u_int32_t *)hp->h_addr;
     268    }
     269
     270    /* if there is no primary then update it. */
     271    if (ipcp_allowoptions[0].dnsaddr[0] == 0)
     272        ipcp_allowoptions[0].dnsaddr[0] = dns;
     273
     274    /* always set the secondary address value to the same value. */
     275    ipcp_allowoptions[0].dnsaddr[1] = dns;
     276
     277    return (1);
     278}
     279
     280/*
     281 * setwinsaddr - set the wins address(es)
     282 * This is primrarly used with the Samba package under UNIX or for pointing
     283 * the caller to the existing WINS server on a Windows NT platform.
     284 */
     285static int
     286setwinsaddr(argv)
     287    char **argv;
     288{
     289    u_int32_t wins;
     290    struct hostent *hp;
     291
     292    wins = inet_addr(*argv);
     293    if (wins == (u_int32_t) -1) {
     294        if ((hp = gethostbyname(*argv)) == NULL) {
     295            option_error("invalid address parameter '%s' for ms-wins option",
     296                         *argv);
     297            return 0;
     298        }
     299        wins = *(u_int32_t *)hp->h_addr;
     300    }
     301
     302    /* if there is no primary then update it. */
     303    if (ipcp_allowoptions[0].winsaddr[0] == 0)
     304        ipcp_allowoptions[0].winsaddr[0] = wins;
     305
     306    /* always set the secondary address value to the same value. */
     307    ipcp_allowoptions[0].winsaddr[1] = wins;
     308
     309    return (1);
    158310}
    159311
     
    183335    wo->maxslotindex = MAX_STATES - 1; /* really max index */
    184336    wo->cflag = 1;
    185         ipcp_wantoptions[0].default_route = 1;
     337
    186338    /* max slots and slot-id compression are currently hardwired in */
    187339    /* ppp_if.c to 16 and 1, this needs to be changed (among other */
     
    275427/*
    276428 * ipcp_resetci - Reset our CI.
     429 * Called by fsm_sconfreq, Send Configure Request.
    277430 */
    278431static void
     
    281434{
    282435    ipcp_options *wo = &ipcp_wantoptions[f->unit];
     436    ipcp_options *go = &ipcp_gotoptions[f->unit];
    283437
    284438    wo->req_addr = wo->neg_addr && ipcp_allowoptions[f->unit].neg_addr;
    285     if (wo->ouraddr == 0)
     439    if (wo->ouraddr == 0 || disable_defaultip)
    286440        wo->accept_local = 1;
    287441    if (wo->hisaddr == 0)
    288442        wo->accept_remote = 1;
    289     ipcp_gotoptions[f->unit] = *wo;
    290     cis_received[f->unit] = 0;
     443    wo->req_dns1 = usepeerdns;  /* Request DNS addresses from the peer */
     444    wo->req_dns2 = usepeerdns;
     445    *go = *wo;
     446    if (disable_defaultip)
     447        go->ouraddr = 0;
    291448}
    292449
     
    294451/*
    295452 * ipcp_cilen - Return length of our CI.
     453 * Called by fsm_sconfreq, Send Configure Request.
    296454 */
    297455static int
     
    305463#define LENCIVJ(neg, old)       (neg ? (old? CILEN_COMPRESS : CILEN_VJ) : 0)
    306464#define LENCIADDR(neg, old)     (neg ? (old? CILEN_ADDRS : CILEN_ADDR) : 0)
     465#define LENCIDNS(neg)           (neg ? (CILEN_ADDR) : 0)
    307466
    308467    /*
     
    317476    if (wo->neg_vj && !go->neg_vj && !go->old_vj) {
    318477        /* try an older style of VJ negotiation */
    319         if (cis_received[f->unit] == 0) {
    320             /* keep trying the new style until we see some CI from the peer */
     478        /* use the old style only if the peer did */
     479        if (ho->neg_vj && ho->old_vj) {
    321480            go->neg_vj = 1;
    322         } else {
    323             /* use the old style only if the peer did */
    324             if (ho->neg_vj && ho->old_vj) {
    325                 go->neg_vj = 1;
    326                 go->old_vj = 1;
    327                 go->vj_protocol = ho->vj_protocol;
    328             }
     481            go->old_vj = 1;
     482            go->vj_protocol = ho->vj_protocol;
    329483        }
    330484    }
    331485
    332486    return (LENCIADDR(go->neg_addr, go->old_addrs) +
    333             LENCIVJ(go->neg_vj, go->old_vj));
     487            LENCIVJ(go->neg_vj, go->old_vj) +
     488            LENCIDNS(go->req_dns1) +
     489            LENCIDNS(go->req_dns2)) ;
    334490}
    335491
     
    337493/*
    338494 * ipcp_addci - Add our desired CIs to a packet.
     495 * Called by fsm_sconfreq, Send Configure Request.
    339496 */
    340497static void
     
    381538    }
    382539
     540#define ADDCIDNS(opt, neg, addr) \
     541    if (neg) { \
     542        if (len >= CILEN_ADDR) { \
     543            u_int32_t l; \
     544            PUTCHAR(opt, ucp); \
     545            PUTCHAR(CILEN_ADDR, ucp); \
     546            l = ntohl(addr); \
     547            PUTLONG(l, ucp); \
     548            len -= CILEN_ADDR; \
     549        } else \
     550            neg = 0; \
     551    }
     552
    383553    ADDCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
    384554              go->old_addrs, go->ouraddr, go->hisaddr);
     
    387557            go->maxslotindex, go->cflag);
    388558
     559    ADDCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
     560
     561    ADDCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
     562
    389563    *lenp -= len;
    390564}
     
    393567/*
    394568 * ipcp_ackci - Ack our CIs.
     569 * Called by fsm_rconfack, Receive Configure ACK.
    395570 *
    396571 * Returns:
     
    461636    }
    462637
     638#define ACKCIDNS(opt, neg, addr) \
     639    if (neg) { \
     640        u_int32_t l; \
     641        if ((len -= CILEN_ADDR) < 0) \
     642            goto bad; \
     643        GETCHAR(citype, p); \
     644        GETCHAR(cilen, p); \
     645        if (cilen != CILEN_ADDR || citype != opt) \
     646            goto bad; \
     647        GETLONG(l, p); \
     648        cilong = htonl(l); \
     649        if (addr != cilong) \
     650            goto bad; \
     651    }
     652
    463653    ACKCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), go->neg_addr,
    464654              go->old_addrs, go->ouraddr, go->hisaddr);
     
    466656    ACKCIVJ(CI_COMPRESSTYPE, go->neg_vj, go->vj_protocol, go->old_vj,
    467657            go->maxslotindex, go->cflag);
     658
     659    ACKCIDNS(CI_MS_DNS1, go->req_dns1, go->dnsaddr[0]);
     660
     661    ACKCIDNS(CI_MS_DNS2, go->req_dns2, go->dnsaddr[1]);
    468662
    469663    /*
     
    475669
    476670bad:
    477     IPCPDEBUG((LOG_INFO, "ipcp_ackci: received bad Ack!"));
     671    IPCPDEBUG(("ipcp_ackci: received bad Ack!"));
    478672    return (0);
    479673}
     
    483677 * This should not modify any state if the Nak is bad
    484678 * or if IPCP is in the OPENED state.
     679 * Calback from fsm_rconfnakrej - Receive Configure-Nak or Configure-Reject.
    485680 *
    486681 * Returns:
     
    498693    u_char citype, cilen, *next;
    499694    u_short cishort;
    500     u_int32_t ciaddr1, ciaddr2, l;
     695    u_int32_t ciaddr1, ciaddr2, l, cidnsaddr;
    501696    ipcp_options no;            /* options we've seen Naks for */
    502697    ipcp_options try;           /* options to request next time */
     
    541736    }
    542737
     738#define NAKCIDNS(opt, neg, code) \
     739    if (go->neg && \
     740        ((cilen = p[1]) == CILEN_ADDR) && \
     741        len >= cilen && \
     742        p[0] == opt) { \
     743        len -= cilen; \
     744        INCPTR(2, p); \
     745        GETLONG(l, p); \
     746        cidnsaddr = htonl(l); \
     747        no.neg = 1; \
     748        code \
     749    }
     750
    543751    /*
    544752     * Accept the peer's idea of {our,his} address, if different
     
    548756              if (go->accept_local && ciaddr1) { /* Do we know our address? */
    549757                  try.ouraddr = ciaddr1;
    550                   IPCPDEBUG((LOG_INFO, "local IP address %s",
    551                              ip_ntoa(ciaddr1)));
    552758              }
    553759              if (go->accept_remote && ciaddr2) { /* Does he know his? */
    554760                  try.hisaddr = ciaddr2;
    555                   IPCPDEBUG((LOG_INFO, "remote IP address %s",
    556                              ip_ntoa(ciaddr2)));
    557761              }
    558762              );
     
    585789                }
    586790            }
     791            );
     792
     793    NAKCIDNS(CI_MS_DNS1, req_dns1,
     794            try.dnsaddr[0] = cidnsaddr;
     795            );
     796
     797    NAKCIDNS(CI_MS_DNS2, req_dns2,
     798            try.dnsaddr[1] = cidnsaddr;
    587799            );
    588800
     
    639851    }
    640852
    641     /* If there is still anything left, this packet is bad. */
    642     if (len != 0)
    643         goto bad;
    644 
    645853    /*
    646854     * OK, the Nak is good.  Now we can update state.
     855     * If there are any remaining options, we ignore them.
    647856     */
    648857    if (f->state != OPENED)
     
    652861
    653862bad:
    654     IPCPDEBUG((LOG_INFO, "ipcp_nakci: received bad Nak!"));
     863    IPCPDEBUG(("ipcp_nakci: received bad Nak!"));
    655864    return 0;
    656865}
     
    659868/*
    660869 * ipcp_rejci - Reject some of our CIs.
     870 * Callback from fsm_rconfnakrej.
    661871 */
    662872static int
     
    723933     }
    724934
     935#define REJCIDNS(opt, neg, dnsaddr) \
     936    if (go->neg && \
     937        ((cilen = p[1]) == CILEN_ADDR) && \
     938        len >= cilen && \
     939        p[0] == opt) { \
     940        u_int32_t l; \
     941        len -= cilen; \
     942        INCPTR(2, p); \
     943        GETLONG(l, p); \
     944        cilong = htonl(l); \
     945        /* Check rejected value. */ \
     946        if (cilong != dnsaddr) \
     947            goto bad; \
     948        try.neg = 0; \
     949    }
     950
     951
    725952    REJCIADDR((go->old_addrs? CI_ADDRS: CI_ADDR), neg_addr,
    726953              go->old_addrs, go->ouraddr, go->hisaddr);
     
    728955    REJCIVJ(CI_COMPRESSTYPE, neg_vj, go->vj_protocol, go->old_vj,
    729956            go->maxslotindex, go->cflag);
     957
     958    REJCIDNS(CI_MS_DNS1, req_dns1, go->dnsaddr[0]);
     959
     960    REJCIDNS(CI_MS_DNS2, req_dns2, go->dnsaddr[1]);
    730961
    731962    /*
     
    742973
    743974bad:
    744     IPCPDEBUG((LOG_INFO, "ipcp_rejci: received bad Reject!"));
     975    IPCPDEBUG(("ipcp_rejci: received bad Reject!"));
    745976    return 0;
    746977}
     
    749980/*
    750981 * ipcp_reqci - Check the peer's requested CIs and send appropriate response.
     982 * Callback from fsm_rconfreq, Receive Configure Request
    751983 *
    752984 * Returns: CONFACK, CONFNAK or CONFREJ and input packet modified
     
    7771009    int d;
    7781010
    779     cis_received[f->unit] = 1;
    780 
    7811011    /*
    7821012     * Reset all his options.
     
    7941024            p[1] < 2 ||                 /*  CI length too small or */
    7951025            p[1] > l) {                 /*  CI length too big? */
    796             IPCPDEBUG((LOG_INFO, "ipcp_reqci: bad CI length!"));
     1026            IPCPDEBUG(("ipcp_reqci: bad CI length!"));
    7971027            orc = CONFREJ;              /* Reject bad CI */
    7981028            cilen = l;                  /* Reject till end of packet */
     
    8071037        switch (citype) {               /* Check CI type */
    8081038        case CI_ADDRS:
    809             IPCPDEBUG((LOG_INFO, "ipcp: received ADDRS "));
    8101039            if (!ao->neg_addr ||
    8111040                cilen != CILEN_ADDRS) { /* Check CI length */
     
    8221051            GETLONG(tl, p);             /* Parse source address (his) */
    8231052            ciaddr1 = htonl(tl);
    824             IPCPDEBUG((LOG_INFO, "(%s:", ip_ntoa(ciaddr1)));
    8251053            if (ciaddr1 != wo->hisaddr
    8261054                && (ciaddr1 == 0 || !wo->accept_remote)) {
     
    8461074            GETLONG(tl, p);             /* Parse desination address (ours) */
    8471075            ciaddr2 = htonl(tl);
    848             IPCPDEBUG((LOG_INFO, "%s)", ip_ntoa(ciaddr2)));
    8491076            if (ciaddr2 != wo->ouraddr) {
    8501077                if (ciaddr2 == 0 || !wo->accept_local) {
     
    8671094
    8681095        case CI_ADDR:
    869             IPCPDEBUG((LOG_INFO, "ipcp: received ADDR "));
    870 
    8711096            if (!ao->neg_addr ||
    8721097                cilen != CILEN_ADDR) {  /* Check CI length */
     
    8831108            GETLONG(tl, p);     /* Parse source address (his) */
    8841109            ciaddr1 = htonl(tl);
    885             IPCPDEBUG((LOG_INFO, "(%s)", ip_ntoa(ciaddr1)));
    8861110            if (ciaddr1 != wo->hisaddr
    8871111                && (ciaddr1 == 0 || !wo->accept_remote)) {
     
    9091133            /* Microsoft primary or secondary DNS request */
    9101134            d = citype == CI_MS_DNS2;
    911             IPCPDEBUG((LOG_INFO, "ipcp: received DNS%d Request ", d+1));
    9121135
    9131136            /* If we do not have a DNS address then we cannot send it */
     
    9301153            /* Microsoft primary or secondary WINS request */
    9311154            d = citype == CI_MS_WINS2;
    932             IPCPDEBUG((LOG_INFO, "ipcp: received WINS%d Request ", d+1));
    9331155
    9341156            /* If we do not have a DNS address then we cannot send it */
     
    9481170       
    9491171        case CI_COMPRESSTYPE:
    950             IPCPDEBUG((LOG_INFO, "ipcp: received COMPRESSTYPE "));
    9511172            if (!ao->neg_vj ||
    9521173                (cilen != CILEN_VJ && cilen != CILEN_COMPRESS)) {
     
    9551176            }
    9561177            GETSHORT(cishort, p);
    957             IPCPDEBUG((LOG_INFO, "(%d)", cishort));
    9581178
    9591179            if (!(cishort == IPCP_VJ_COMP ||
     
    9951215            break;
    9961216        }
    997 
    9981217endswitch:
    999         IPCPDEBUG((LOG_INFO, " (%s)\n", CODENAME(orc)));
    1000 
    10011218        if (orc == CONFACK &&           /* Good CI */
    10021219            rc != CONFACK)              /*  but prior CI wasnt? */
     
    10511268
    10521269    *len = ucp - inp;                   /* Compute output length */
    1053     IPCPDEBUG((LOG_INFO, "ipcp: returning Configure-%s", CODENAME(rc)));
     1270    IPCPDEBUG(("ipcp: returning Configure-%s", CODENAME(rc)));
    10541271    return (rc);                        /* Return final code */
    10551272}
     
    10711288     * If local IP address already given, don't bother.
    10721289     */
    1073     if (wo->ouraddr == 0 && !disable_defaultip) {
     1290    if (wo->ouraddr == 0) {
    10741291        /*
    10751292         * Look up our hostname (possibly with domain name appended)
     
    10841301        }
    10851302    }
    1086 
    10871303}
    10881304
     
    10981314    ipcp_options *wo = &ipcp_wantoptions[u];
    10991315
     1316    if (wo->hisaddr == 0) {
     1317        /* make up an arbitrary address for the peer */
     1318        wo->hisaddr = htonl(0x0a707070 + pppifunit);
     1319        wo->accept_remote = 1;
     1320    }
     1321    if (wo->ouraddr == 0) {
     1322        /* make up an arbitrary address for us */
     1323        wo->ouraddr = htonl(0x0a404040 + pppifunit);
     1324        wo->accept_local = 1;
     1325        disable_defaultip = 1;  /* don't tell the peer this address */
     1326    }
    11001327    if (!sifaddr(u, wo->ouraddr, wo->hisaddr, GetMask(wo->ouraddr)))
    11011328        return 0;
     
    11111338            proxy_arp_set[u] = 1;
    11121339
    1113     syslog(LOG_NOTICE, "local  IP address %s", ip_ntoa(wo->ouraddr));
    1114     syslog(LOG_NOTICE, "remote IP address %s", ip_ntoa(wo->hisaddr));
     1340    notice("local  IP address %I", wo->ouraddr);
     1341    notice("remote IP address %I", wo->hisaddr);
    11151342
    11161343    return 1;
     
    11231350 * Configure the IP network interface appropriately and bring it up.
    11241351 */
    1125 #define  script_setenv(a,b)
    1126 
    1127 
    11281352static void
    11291353ipcp_up(f)
     
    11351359    ipcp_options *wo = &ipcp_wantoptions[f->unit];
    11361360
    1137     np_up(f->unit, PPP_IP);
    1138     IPCPDEBUG((LOG_INFO, "ipcp: up"));
     1361    IPCPDEBUG(("ipcp: up"));
    11391362
    11401363    /*
     
    11451368
    11461369    if (ho->hisaddr == 0) {
    1147         syslog(LOG_ERR, "Could not determine remote IP address");
     1370        error("Could not determine remote IP address");
    11481371        ipcp_close(f->unit, "Could not determine remote IP address");
    11491372        return;
    11501373    }
    11511374    if (go->ouraddr == 0) {
    1152         syslog(LOG_ERR, "Could not determine local IP address");
     1375        error("Could not determine local IP address");
    11531376        ipcp_close(f->unit, "Could not determine local IP address");
    11541377        return;
    11551378    }
    1156 /*    script_setenv("IPLOCAL", ip_ntoa(go->ouraddr));
    1157     script_setenv("IPREMOTE", ip_ntoa(ho->hisaddr));
    1158 */
     1379
     1380    if (usepeerdns && (go->dnsaddr[0] || go->dnsaddr[1])) {
     1381        create_resolv(go->dnsaddr[0], go->dnsaddr[1]);
     1382    }
     1383
    11591384    /*
    11601385     * Check that the peer is allowed to use the IP address it wants.
    11611386     */
    11621387    if (!auth_ip_addr(f->unit, ho->hisaddr)) {
    1163         syslog(LOG_ERR, "Peer is not authorized to use remote address %s",
    1164                ip_ntoa(ho->hisaddr));
     1388        error("Peer is not authorized to use remote address %I", ho->hisaddr);
    11651389        ipcp_close(f->unit, "Unauthorized remote IP address");
    11661390        return;
     
    11751399     * interface to pass IP packets.
    11761400     */
    1177         {
     1401    if (demand) {
     1402        if (go->ouraddr != wo->ouraddr || ho->hisaddr != wo->hisaddr) {
     1403            ipcp_clear_addrs(f->unit, wo->ouraddr, wo->hisaddr);
     1404            if (go->ouraddr != wo->ouraddr) {
     1405                warn("Local IP address changed to %I", go->ouraddr);
     1406                wo->ouraddr = go->ouraddr;
     1407            }
     1408            if (ho->hisaddr != wo->hisaddr) {
     1409                warn("Remote IP address changed to %I", ho->hisaddr);
     1410                wo->hisaddr = ho->hisaddr;
     1411            }
     1412
     1413            /* Set the interface to the new addresses */
     1414            mask = GetMask(go->ouraddr);
     1415            if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
     1416                if (debug)
     1417                    warn("Interface configuration failed");
     1418                ipcp_close(f->unit, "Interface configuration failed");
     1419                return;
     1420            }
     1421
     1422            /* assign a default route through the interface if required */
     1423            if (ipcp_wantoptions[f->unit].default_route)
     1424                if (sifdefaultroute(f->unit, go->ouraddr, ho->hisaddr))
     1425                    default_route_set[f->unit] = 1;
     1426
     1427            /* Make a proxy ARP entry if requested. */
     1428            if (ipcp_wantoptions[f->unit].proxy_arp)
     1429                if (sifproxyarp(f->unit, ho->hisaddr))
     1430                    proxy_arp_set[f->unit] = 1;
     1431
     1432        }
     1433        demand_rexmit(PPP_IP);
     1434        sifnpmode(f->unit, PPP_IP, NPMODE_PASS);
     1435
     1436    } else {
    11781437        /*
    11791438         * Set IP addresses and (if specified) netmask.
     
    11831442#if !(defined(SVR4) && (defined(SNI) || defined(__USLC__)))
    11841443        if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
    1185             IPCPDEBUG((LOG_WARNING, "sifaddr failed"));
     1444            if (debug)
     1445                warn("Interface configuration failed");
    11861446            ipcp_close(f->unit, "Interface configuration failed");
    11871447            return;
     
    11911451        /* bring the interface up for IP */
    11921452        if (!sifup(f->unit)) {
    1193             IPCPDEBUG((LOG_WARNING, "sifup failed"));
     1453            if (debug)
     1454                warn("Interface failed to come up");
    11941455            ipcp_close(f->unit, "Interface configuration failed");
    11951456            return;
     
    11981459#if (defined(SVR4) && (defined(SNI) || defined(__USLC__)))
    11991460        if (!sifaddr(f->unit, go->ouraddr, ho->hisaddr, mask)) {
    1200             IPCPDEBUG((LOG_WARNING, "sifaddr failed"));
     1461            if (debug)
     1462                warn("Interface configuration failed");
    12011463            ipcp_close(f->unit, "Interface configuration failed");
    12021464            return;
     
    12151477                proxy_arp_set[f->unit] = 1;
    12161478
    1217         syslog(LOG_NOTICE, "local  IP address %s", ip_ntoa(go->ouraddr));
    1218         syslog(LOG_NOTICE, "remote IP address %s", ip_ntoa(ho->hisaddr));
    1219     }
    1220 
    1221     /*
    1222      * Execute the ip-up script, like this:
    1223      *  /etc/ppp/ip-up interface tty speed local-IP remote-IP
    1224      */
    1225         {
    1226 #if 0
    1227 /* XXX PPPConfiguration */
    1228                 GlobalSystemStatus *stat;
    1229                 stat=LockSTBSystemParam();
    1230                 stat->ConnectionStatus=Connected;
    1231                 UnlockSTBSystemParam();
    1232 #endif
    1233         }
     1479        ipcp_wantoptions[0].ouraddr = go->ouraddr;
     1480
     1481        notice("local  IP address %I", go->ouraddr);
     1482        notice("remote IP address %I", ho->hisaddr);
     1483        if (go->dnsaddr[0])
     1484            notice("primary   DNS address %I", go->dnsaddr[0]);
     1485        if (go->dnsaddr[1])
     1486            notice("secondary DNS address %I", go->dnsaddr[1]);
     1487    }
     1488
     1489    np_up(f->unit, PPP_IP);
     1490    ipcp_is_up = 1;
     1491
     1492    if (ip_up_hook)
     1493        ip_up_hook();
    12341494}
    12351495
     
    12451505    fsm *f;
    12461506{
    1247     IPCPDEBUG((LOG_INFO, "ipcp: down"));
    1248     np_down(f->unit, PPP_IP);
     1507    IPCPDEBUG(("ipcp: down"));
     1508    /* XXX a bit IPv4-centric here, we only need to get the stats
     1509     * before the interface is marked down. */
     1510    update_link_stats(f->unit);
     1511    if (ip_down_hook)
     1512        ip_down_hook();
     1513    if (ipcp_is_up) {
     1514        ipcp_is_up = 0;
     1515        np_down(f->unit, PPP_IP);
     1516    }
    12491517    sifvjcomp(f->unit, 0, 0, 0);
    12501518
     
    12531521     * to queue up outgoing packets (for now).
    12541522     */
     1523    if (demand) {
     1524        sifnpmode(f->unit, PPP_IP, NPMODE_QUEUE);
     1525    } else {
     1526        sifnpmode(f->unit, PPP_IP, NPMODE_DROP);
    12551527        sifdown(f->unit);
    1256         ipcp_clear_addrs(f->unit);
    1257 
    1258     /* Execute the ip-down script */
    1259         {
    1260 #if 0
    1261 /* XXX PPPConfiguration */
    1262                 GlobalSystemStatus *stat;
    1263                 stat=LockSTBSystemParam();
    1264                 stat->ConnectionStatus=NotConnected;
    1265                 UnlockSTBSystemParam();
    1266 #endif
    1267         }
     1528        ipcp_clear_addrs(f->unit, ipcp_gotoptions[f->unit].ouraddr,
     1529                         ipcp_hisoptions[f->unit].hisaddr);
     1530    }
    12681531}
    12691532
     
    12741537 */
    12751538static void
    1276 ipcp_clear_addrs(unit)
     1539ipcp_clear_addrs(unit, ouraddr, hisaddr)
    12771540    int unit;
    1278 {
    1279     u_int32_t ouraddr, hisaddr;
    1280 
    1281     ouraddr = ipcp_gotoptions[unit].ouraddr;
    1282     hisaddr = ipcp_hisoptions[unit].hisaddr;
     1541    u_int32_t ouraddr;  /* local address */
     1542    u_int32_t hisaddr;  /* remote address */
     1543{
    12831544    if (proxy_arp_set[unit]) {
    12841545        cifproxyarp(unit, hisaddr);
     
    13031564}
    13041565
    1305 
    1306 #if 0
    1307 /*
    1308  * ipcp_script - Execute a script with arguments
    1309  * interface-name tty-name speed local-IP remote-IP.
     1566/*
     1567 * create_resolv - create the replacement resolv.conf file
    13101568 */
    13111569static void
    1312 ipcp_script(f, script)
    1313     fsm *f;
    1314     char *script;
    1315 {
    1316     char strspeed[32], strlocal[32], strremote[32];
    1317     char *argv[8];
    1318 
    1319     sprintf(strspeed, "%d", baud_rate);
    1320     strcpy(strlocal, ip_ntoa(ipcp_gotoptions[f->unit].ouraddr));
    1321     strcpy(strremote, ip_ntoa(ipcp_hisoptions[f->unit].hisaddr));
    1322 
    1323     argv[0] = script;
    1324     argv[1] = ifname;
    1325     argv[2] = devnam;
    1326     argv[3] = strspeed;
    1327     argv[4] = strlocal;
    1328     argv[5] = strremote;
    1329     argv[6] = ipparam;
    1330     argv[7] = NULL;
    1331     run_program(script, argv, 0);
    1332 }
    1333 #endif
     1570create_resolv(peerdns1, peerdns2)
     1571    u_int32_t peerdns1, peerdns2;
     1572{
     1573    FILE *f;
     1574
     1575    f = fopen(_PATH_RESOLV, "w");
     1576    if (f == NULL) {
     1577        error("Failed to create %s: %m", _PATH_RESOLV);
     1578        return;
     1579    }
     1580
     1581    if (peerdns1)
     1582        fprintf(f, "nameserver %s\n", ip_ntoa(peerdns1));
     1583
     1584    if (peerdns2)
     1585        fprintf(f, "nameserver %s\n", ip_ntoa(peerdns2));
     1586
     1587    if (ferror(f))
     1588        error("Write failed to %s: %m", _PATH_RESOLV);
     1589
     1590    fclose(f);
     1591}
    13341592
    13351593/*
     
    13731631    case CONFNAK:
    13741632    case CONFREJ:
    1375  
     1633        /* print option list */
    13761634        while (len >= 2) {
    13771635            GETCHAR(code, p);
     
    14221680                p += 2;
    14231681                GETLONG(cilong, p);
    1424                 printer(arg, "ms-dns %I", htonl(cilong));
     1682                printer(arg, "ms-dns%d %I", code - CI_MS_DNS1 + 1,
     1683                        htonl(cilong));
    14251684                break;
    14261685            case CI_MS_WINS1:
     
    14431702        if (len > 0 && *p >= ' ' && *p < 0x7f) {
    14441703            printer(arg, " ");
    1445     print_string(p, len, printer, arg);
     1704            print_string(p, len, printer, arg);
    14461705            p += len;
    14471706            len = 0;
     
    14491708        break;
    14501709    }
    1451  
     1710
     1711    /* print the rest of the bytes in the packet */
    14521712    for (; len > 0; --len) {
    14531713        GETCHAR(code, p);
  • cpukit/pppd/ipcp.h

    r4b3c197f r2f1b930  
    4444
    4545typedef struct ipcp_options {
    46     int neg_addr : 1;           /* Negotiate IP Address? */
    47     int old_addrs : 1;          /* Use old (IP-Addresses) option? */
    48     int req_addr : 1;           /* Ask peer to send IP address? */
    49     int default_route : 1;      /* Assign default route through interface? */
    50     int proxy_arp : 1;          /* Make proxy ARP entry for peer? */
    51     int neg_vj : 1;             /* Van Jacobson Compression? */
    52     int old_vj : 1;             /* use old (short) form of VJ option? */
    53     int accept_local : 1;       /* accept peer's value for ouraddr */
    54     int accept_remote : 1;      /* accept peer's value for hisaddr */
    55     u_short vj_protocol;        /* protocol value to use in VJ option */
    56     u_char maxslotindex, cflag; /* values for RFC1332 VJ compression neg. */
     46    bool neg_addr;              /* Negotiate IP Address? */
     47    bool old_addrs;             /* Use old (IP-Addresses) option? */
     48    bool req_addr;              /* Ask peer to send IP address? */
     49    bool default_route;         /* Assign default route through interface? */
     50    bool proxy_arp;             /* Make proxy ARP entry for peer? */
     51    bool neg_vj;                /* Van Jacobson Compression? */
     52    bool old_vj;                /* use old (short) form of VJ option? */
     53    bool accept_local;          /* accept peer's value for ouraddr */
     54    bool accept_remote;         /* accept peer's value for hisaddr */
     55    bool req_dns1;              /* Ask peer to send primary DNS address? */
     56    bool req_dns2;              /* Ask peer to send secondary DNS address? */
     57    int  vj_protocol;           /* protocol value to use in VJ option */
     58    int  maxslotindex;          /* values for RFC1332 VJ compression neg. */
     59    bool cflag;
    5760    u_int32_t ouraddr, hisaddr; /* Addresses in NETWORK BYTE ORDER */
    5861    u_int32_t dnsaddr[2];       /* Primary and secondary MS DNS entries */
  • cpukit/pppd/ipxcp.c

    r4b3c197f r2f1b930  
    1919
    2020#ifdef IPX_CHANGE
    21 #ifndef lint
    22 /* static char rcsid[] = "$Id$"; */
    23 #endif
     21
     22#define RCSID   "$Id$"
    2423
    2524/*
     
    2928#include <stdio.h>
    3029#include <string.h>
    31 #include <syslog.h>
     30#include <unistd.h>
     31#include <ctype.h>
    3232#include <sys/types.h>
    3333#include <sys/socket.h>
     
    3838#include "ipxcp.h"
    3939#include "pathnames.h"
     40#include "magic.h"
     41
     42static const char rcsid[] = RCSID;
    4043
    4144/* global vars */
     
    6265static void ipxcp_up __P((fsm *));              /* We're UP */
    6366static void ipxcp_down __P((fsm *));            /* We're DOWN */
    64 static void ipxcp_script __P((fsm *, char *)); /* Run an up/down script */
     67static void ipxcp_finished __P((fsm *));        /* Don't need lower layer */
    6568
    6669fsm ipxcp_fsm[NUM_PPP];         /* IPXCP fsm structure */
     
    7780    ipxcp_down,                 /* Called when fsm leaves OPENED state */
    7881    NULL,                       /* Called when we want the lower layer up */
    79     NULL,                       /* Called when we want the lower layer down */
     82    ipxcp_finished,             /* Called when we want the lower layer down */
    8083    NULL,                       /* Called when Protocol-Reject received */
    8184    NULL,                       /* Retransmission is necessary */
    8285    NULL,                       /* Called to handle protocol-specific codes */
    8386    "IPXCP"                     /* String name of protocol */
     87};
     88
     89/*
     90 * Command-line options.
     91 */
     92static int setipxnode __P((char **));
     93static int setipxname __P((char **));
     94
     95static option_t ipxcp_option_list[] = {
     96    { "ipx", o_bool, &ipxcp_protent.enabled_flag,
     97      "Enable IPXCP (and IPX)", 1 },
     98    { "+ipx", o_bool, &ipxcp_protent.enabled_flag,
     99      "Enable IPXCP (and IPX)", 1 },
     100    { "noipx", o_bool, &ipxcp_protent.enabled_flag,
     101      "Disable IPXCP (and IPX)" },
     102    { "-ipx", o_bool, &ipxcp_protent.enabled_flag,
     103      "Disable IPXCP (and IPX)" } ,
     104    { "ipx-network", o_uint32, &ipxcp_wantoptions[0].our_network,
     105      "Set our IPX network number", 0, &ipxcp_wantoptions[0].neg_nn },
     106    { "ipxcp-accept-network", o_bool, &ipxcp_wantoptions[0].accept_network,
     107      "Accept peer IPX network number", 1,
     108      &ipxcp_allowoptions[0].accept_network },
     109    { "ipx-node", o_special, setipxnode,
     110      "Set IPX node number" },
     111    { "ipxcp-accept-local", o_bool, &ipxcp_wantoptions[0].accept_local,
     112      "Accept our IPX address", 1,
     113      &ipxcp_allowoptions[0].accept_local },
     114    { "ipxcp-accept-remote", o_bool, &ipxcp_wantoptions[0].accept_remote,
     115      "Accept peer's IPX address", 1,
     116      &ipxcp_allowoptions[0].accept_remote },
     117    { "ipx-routing", o_int, &ipxcp_wantoptions[0].router,
     118      "Set IPX routing proto number", 0,
     119      &ipxcp_wantoptions[0].neg_router },
     120    { "ipx-router-name", o_special, setipxname,
     121      "Set IPX router name" },
     122    { "ipxcp-restart", o_int, &ipxcp_fsm[0].timeouttime,
     123      "Set timeout for IPXCP" },
     124    { "ipxcp-max-terminate", o_int, &ipxcp_fsm[0].maxtermtransmits,
     125      "Set max #xmits for IPXCP term-reqs" },
     126    { "ipxcp-max-configure", o_int, &ipxcp_fsm[0].maxconfreqtransmits,
     127      "Set max #xmits for IPXCP conf-reqs" },
     128    { "ipxcp-max-failure", o_int, &ipxcp_fsm[0].maxnakloops,
     129      "Set max #conf-naks for IPXCP" },
     130    { NULL }
    84131};
    85132
     
    111158    0,
    112159    "IPXCP",
     160    "IPX",
     161    ipxcp_option_list,
    113162    NULL,
    114163    NULL,
     
    131180                         (x) == CONFNAK ? "NAK" : "REJ")
    132181
     182static int ipxcp_is_up;
     183
     184static char *ipx_ntoa __P((u_int32_t));
     185
    133186/* Used in printing the node number */
    134187#define NODE(base) base[0], base[1], base[2], base[3], base[4], base[5]
     
    147200    short int  external;
    148201
    149     if (internal & IPX_NONE)
     202    if (internal & BIT(IPX_NONE) )
    150203        external = IPX_NONE;
    151204    else
     
    159212 */
    160213
    161 char *
     214static char *
    162215ipx_ntoa(ipxaddr)
    163216u_int32_t ipxaddr;
    164217{
    165218    static char b[64];
    166     sprintf(b, "%x", ipxaddr);
     219    slprintf(b, sizeof(b), "%x", ipxaddr);
    167220    return b;
    168221}
    169222
     223
     224static u_char *
     225setipxnodevalue(src,dst)
     226u_char *src, *dst;
     227{
     228    int indx;
     229    int item;
     230
     231    for (;;) {
     232        if (!isxdigit (*src))
     233            break;
     234       
     235        for (indx = 0; indx < 5; ++indx) {
     236            dst[indx] <<= 4;
     237            dst[indx] |= (dst[indx + 1] >> 4) & 0x0F;
     238        }
     239
     240        item = toupper (*src) - '0';
     241        if (item > 9)
     242            item -= 7;
     243
     244        dst[5] = (dst[5] << 4) | item;
     245        ++src;
     246    }
     247    return src;
     248}
     249
     250static int
     251setipxnode(argv)
     252    char **argv;
     253{
     254    char *end;
     255
     256    memset (&ipxcp_wantoptions[0].our_node[0], 0, 6);
     257    memset (&ipxcp_wantoptions[0].his_node[0], 0, 6);
     258
     259    end = setipxnodevalue (*argv, &ipxcp_wantoptions[0].our_node[0]);
     260    if (*end == ':')
     261        end = setipxnodevalue (++end, &ipxcp_wantoptions[0].his_node[0]);
     262
     263    if (*end == '\0') {
     264        ipxcp_wantoptions[0].neg_node = 1;
     265        return 1;
     266    }
     267
     268    option_error("invalid parameter '%s' for ipx-node option", *argv);
     269    return 0;
     270}
     271
     272static int
     273setipxname (argv)
     274    char **argv;
     275{
     276    char *dest = ipxcp_wantoptions[0].name;
     277    char *src  = *argv;
     278    int  count;
     279    char ch;
     280
     281    ipxcp_wantoptions[0].neg_name  = 1;
     282    ipxcp_allowoptions[0].neg_name = 1;
     283    memset (dest, '\0', sizeof (ipxcp_wantoptions[0].name));
     284
     285    count = 0;
     286    while (*src) {
     287        ch = *src++;
     288        if (! isalnum (ch) && ch != '_') {
     289            option_error("IPX router name must be alphanumeric or _");
     290            return 0;
     291        }
     292
     293        if (count >= sizeof (ipxcp_wantoptions[0].name)) {
     294            option_error("IPX router name is limited to %d characters",
     295                         sizeof (ipxcp_wantoptions[0].name) - 1);
     296            return 0;
     297        }
     298
     299        dest[count++] = toupper (ch);
     300    }
     301
     302    return 1;
     303}
    170304
    171305/*
     
    533667        ACKCINODE     (IPX_NODE_NUMBER,     go->neg_node,   go->our_node);
    534668        ACKCINAME     (IPX_ROUTER_NAME,     go->neg_name,   go->name);
    535         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
    536         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
    537         ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
     669        if (len > 0)
     670                ACKCIPROTO    (IPX_ROUTER_PROTOCOL, go->neg_router, go->router);
    538671/*
    539672 * This is the end of the record.
     
    545678 * The frame is invalid
    546679 */
    547     IPXCPDEBUG((LOG_INFO, "ipxcp_ackci: received bad Ack!"));
     680    IPXCPDEBUG(("ipxcp_ackci: received bad Ack!"));
    548681    return (0);
    549682}
     
    589722
    590723            GETLONG(l, p);
    591             IPXCPDEBUG((LOG_INFO, "local IP address %d", l));
    592724            if (l && ao->accept_network)
    593725                try.our_network = l;
     
    599731            no.neg_node = 1;
    600732
    601             IPXCPDEBUG((LOG_INFO,
    602                         "local node number %02X%02X%02X%02X%02X%02X",
    603                         NODE(p)));
    604 
    605733            if (!zero_node (p) && ao->accept_local &&
    606734                ! compare_node (p, ho->his_node))
     
    630758            try.router     |= s;
    631759            try.neg_router  = 1;
    632 
    633             IPXCPDEBUG((LOG_INFO, "Router protocol number %d", s));
    634760            break;
    635761
     
    645771        p = next;
    646772    }
    647 
    648     /* If there is still anything left, this packet is bad. */
    649     if (len != 0)
    650         goto bad;
    651773
    652774    /*
     
    663785    /*
    664786     * OK, the Nak is good.  Now we can update state.
     787     * If there are any options left, we ignore them.
    665788     */
    666789    if (f->state != OPENED)
     
    670793
    671794bad:
    672     IPXCPDEBUG((LOG_INFO, "ipxcp_nakci: received bad Nak!"));
     795    IPXCPDEBUG(("ipxcp_nakci: received bad Nak!"));
    673796    return 0;
    674797}
     
    700823        if (cilong != val) \
    701824            break; \
    702         IPXCPDEBUG((LOG_INFO,"ipxcp_rejci rejected long opt %d", opt)); \
    703825        neg = 0; \
    704826    }
     
    722844        if (indx != count) \
    723845            break; \
    724         IPXCPDEBUG((LOG_INFO,"ipxcp_rejci rejected opt %d", opt)); \
    725846        neg = 0; \
    726847    }
     
    729850#define REJCINAME(opt,neg,val) REJCICHARS(opt,neg,val,strlen(val))
    730851
    731 #define REJCIVOID(gpt, neg) \
     852#define REJCIVOID(opt, neg) \
    732853    if (neg && p[0] == opt) { \
    733854        if ((len -= CILEN_VOID) < 0) \
     
    737858        if (cilen != CILEN_VOID || citype != opt) \
    738859            break; \
    739         IPXCPDEBUG((LOG_INFO, "ipxcp_rejci rejected void opt %d", opt)); \
    740860        neg = 0; \
    741861    }
     
    754874        if (cishort != to_external (val) || cishort == RIP_SAP) \
    755875            break; \
    756         IPXCPDEBUG((LOG_INFO, "ipxcp_rejci short opt %d", opt)); \
    757876        neg = 0; \
    758877    }
     
    781900 * The frame is invalid at this point.
    782901 */
    783     IPXCPDEBUG((LOG_INFO, "ipxcp_rejci: received bad Reject!"));
     902    IPXCPDEBUG(("ipxcp_rejci: received bad Reject!"));
    784903    return 0;
    785904}
     
    824943            p[1] < 2 ||                 /*  CI length too small or */
    825944            p[1] > l) {                 /*  CI length too big? */
    826             IPXCPDEBUG((LOG_INFO, "ipxcp_reqci: bad CI length!"));
     945            IPXCPDEBUG(("ipxcp_reqci: bad CI length!"));
    827946            orc = CONFREJ;              /* Reject bad CI */
    828947            cilen = l;                  /* Reject till end of packet */
     
    840959 */
    841960        case IPX_NETWORK_NUMBER:
    842             IPXCPDEBUG((LOG_INFO, "ipxcp: received Network Number request"));
    843            
    844961            /* if we wont negotiate the network number or the length is wrong
    845962               then reject the option */
     
    849966            }
    850967            GETLONG(cinetwork, p);
    851             IPXCPDEBUG((LOG_INFO,"Remote proposed IPX network number is %8Lx",tl));
    852968
    853969            /* If the network numbers match then acknowledge them. */
     
    8861002 */
    8871003        case IPX_NODE_NUMBER:
    888             IPXCPDEBUG((LOG_INFO, "ipxcp: received Node Number request"));
    889 
    8901004            /* if we wont negotiate the node number or the length is wrong
    8911005               then reject the option */
     
    9451059 */
    9461060        case IPX_COMPRESSION_PROTOCOL:
    947             IPXCPDEBUG((LOG_INFO, "ipxcp: received Compression Protocol request "));
    9481061            orc = CONFREJ;
    9491062            break;
     
    9601073
    9611074            GETSHORT (cishort, p);
    962             IPXCPDEBUG((LOG_INFO,
    963                         "Remote router protocol number 0x%04x",
    964                         cishort));
    9651075
    9661076            if (wo->neg_router == 0) {
     
    10071117 */
    10081118        case IPX_ROUTER_NAME:
    1009             IPXCPDEBUG((LOG_INFO, "ipxcp: received Router Name request"));
    10101119            if (cilen >= CILEN_NAME) {
    10111120                int name_size = cilen - CILEN_NAME;
     
    10251134 */
    10261135        case IPX_COMPLETE:
    1027             IPXCPDEBUG((LOG_INFO, "ipxcp: received Complete request"));
    10281136            if (cilen != CILEN_COMPLETE)
    10291137                orc = CONFREJ;
     
    10371145 */
    10381146        default:
    1039             IPXCPDEBUG((LOG_INFO, "ipxcp: received Complete request"));
    10401147            orc = CONFREJ;
    10411148            break;
    10421149        }
    1043 
    10441150endswitch:
    1045         IPXCPDEBUG((LOG_INFO, " (%s)\n", CODENAME(orc)));
    1046 
    10471151        if (orc == CONFACK &&           /* Good CI */
    10481152            rc != CONFACK)              /*  but prior CI wasnt? */
     
    11001204
    11011205    *len = ucp - inp;                   /* Compute output length */
    1102     IPXCPDEBUG((LOG_INFO, "ipxcp: returning Configure-%s", CODENAME(rc)));
     1206    IPXCPDEBUG(("ipxcp: returning Configure-%s", CODENAME(rc)));
    11031207    return (rc);                        /* Return final code */
    11041208}
     
    11161220    int unit = f->unit;
    11171221
    1118     IPXCPDEBUG((LOG_INFO, "ipxcp: up"));
     1222    IPXCPDEBUG(("ipxcp: up"));
    11191223
    11201224    /* The default router protocol is RIP/SAP. */
     
    11371241    if (zero_node (go->our_node)) {
    11381242        static char errmsg[] = "Could not determine local IPX node address";
    1139         IPXCPDEBUG((LOG_ERR, errmsg));
     1243        if (debug)
     1244            error(errmsg);
    11401245        ipxcp_close(f->unit, errmsg);
    11411246        return;
     
    11481253    if (go->network == 0) {
    11491254        static char errmsg[] = "Can not determine network number";
    1150         IPXCPDEBUG((LOG_ERR, errmsg));
     1255        if (debug)
     1256            error(errmsg);
    11511257        ipxcp_close (unit, errmsg);
    11521258        return;
     
    11551261    /* bring the interface up */
    11561262    if (!sifup(unit)) {
    1157         IPXCPDEBUG((LOG_WARNING, "sifup failed"));
     1263        if (debug)
     1264            warn("sifup failed (IPX)");
    11581265        ipxcp_close(unit, "Interface configuration failed");
    11591266        return;
    11601267    }
     1268    ipxcp_is_up = 1;
    11611269
    11621270    /* set the network number for IPX */
    11631271    if (!sipxfaddr(unit, go->network, go->our_node)) {
    1164         IPXCPDEBUG((LOG_WARNING, "sipxfaddr failed"));
     1272        if (debug)
     1273            warn("sipxfaddr failed");
    11651274        ipxcp_close(unit, "Interface configuration failed");
    11661275        return;
    11671276    }
    11681277
    1169     /*
    1170      * Execute the ipx-up script, like this:
    1171      *  /etc/ppp/ipx-up interface tty speed local-IPX remote-IPX
    1172      */
    1173 
    1174     ipxcp_script (f, _PATH_IPXUP);
     1278    np_up(f->unit, PPP_IPX);
    11751279}
    11761280
     
    11861290    fsm *f;
    11871291{
    1188     IPXCPDEBUG((LOG_INFO, "ipxcp: down"));
    1189 
    1190     cipxfaddr (f->unit);
     1292    IPXCPDEBUG(("ipxcp: down"));
     1293
     1294    if (!ipxcp_is_up)
     1295        return;
     1296    ipxcp_is_up = 0;
     1297    np_down(f->unit, PPP_IPX);
     1298    cipxfaddr(f->unit);
     1299    sifnpmode(f->unit, PPP_IPX, NPMODE_DROP);
    11911300    sifdown(f->unit);
    1192     ipxcp_script (f, _PATH_IPXDOWN);
    1193 }
    1194 
    1195 
    1196 /*
    1197  * ipxcp_script - Execute a script with arguments
    1198  * interface-name tty-name speed local-IPX remote-IPX networks.
     1301}
     1302
     1303
     1304/*
     1305 * ipxcp_finished - possibly shut down the lower layers.
    11991306 */
    12001307static void
    1201 ipxcp_script(f, script)
     1308ipxcp_finished(f)
    12021309    fsm *f;
    1203     char *script;
    1204 {
    1205     char strspeed[32],   strlocal[32],     strremote[32];
    1206     char strnetwork[32], strpid[32];
    1207     char *argv[14],      strproto_lcl[32], strproto_rmt[32];
    1208 
    1209     sprintf (strpid,   "%d", getpid());
    1210     sprintf (strspeed, "%d", baud_rate);
    1211 
    1212     strproto_lcl[0] = '\0';
    1213     if (go->neg_router && ((go->router & BIT(IPX_NONE)) == 0)) {
    1214         if (go->router & BIT(RIP_SAP))
    1215             strcpy (strproto_lcl, "RIP ");
    1216         if (go->router & BIT(NLSP))
    1217             strcat (strproto_lcl, "NLSP ");
    1218     }
    1219 
    1220     if (strproto_lcl[0] == '\0')
    1221         strcpy (strproto_lcl, "NONE ");
    1222 
    1223     strproto_lcl[strlen (strproto_lcl)-1] = '\0';
    1224 
    1225     strproto_rmt[0] = '\0';
    1226     if (ho->neg_router && ((ho->router & BIT(IPX_NONE)) == 0)) {
    1227         if (ho->router & BIT(RIP_SAP))
    1228             strcpy (strproto_rmt, "RIP ");
    1229         if (ho->router & BIT(NLSP))
    1230             strcat (strproto_rmt, "NLSP ");
    1231     }
    1232 
    1233     if (strproto_rmt[0] == '\0')
    1234         strcpy (strproto_rmt, "NONE ");
    1235 
    1236     strproto_rmt[strlen (strproto_rmt)-1] = '\0';
    1237 
    1238     strcpy (strnetwork, ipx_ntoa (go->network));
    1239 
    1240     sprintf (strlocal,
    1241              "%02X%02X%02X%02X%02X%02X",
    1242              NODE(go->our_node));
    1243 
    1244     sprintf (strremote,
    1245              "%02X%02X%02X%02X%02X%02X",
    1246              NODE(ho->his_node));
    1247 
    1248     argv[0]  = script;
    1249     argv[1]  = ifname;
    1250     argv[2]  = devnam;
    1251     argv[3]  = strspeed;
    1252     argv[4]  = strnetwork;
    1253     argv[5]  = strlocal;
    1254     argv[6]  = strremote;
    1255     argv[7]  = strproto_lcl;
    1256     argv[8]  = strproto_rmt;
    1257     argv[9]  = go->name;
    1258     argv[10] = ho->name;
    1259     argv[11] = ipparam;
    1260     argv[12] = strpid;
    1261     argv[13] = NULL;
    1262     run_program(script, argv, 0);
    1263 }
     1310{
     1311    np_finished(f->unit, PPP_IPX);
     1312}
     1313
    12641314
    12651315/*
  • cpukit/pppd/ipxcp.h

    r4b3c197f r2f1b930  
    3636
    3737typedef struct ipxcp_options {
    38     int neg_node       : 1;     /* Negotiate IPX node number? */
    39     int req_node       : 1;     /* Ask peer to send IPX node number? */
     38    bool neg_node;              /* Negotiate IPX node number? */
     39    bool req_node;              /* Ask peer to send IPX node number? */
    4040
    41     int neg_nn         : 1;     /* Negotiate IPX network number? */
    42     int req_nn         : 1;     /* Ask peer to send IPX network number */
     41    bool neg_nn;                /* Negotiate IPX network number? */
     42    bool req_nn;                /* Ask peer to send IPX network number */
    4343
    44     int neg_name       : 1;     /* Negotiate IPX router name */
    45     int neg_complete   : 1;     /* Negotiate completion */
    46     int neg_router     : 1;     /* Negotiate IPX router number */
     44    bool neg_name;              /* Negotiate IPX router name */
     45    bool neg_complete;          /* Negotiate completion */
     46    bool neg_router;            /* Negotiate IPX router number */
    4747
    48     int accept_local   : 1;     /* accept peer's value for ournode */
    49     int accept_remote  : 1;     /* accept peer's value for hisnode */
    50     int accept_network : 1;     /* accept network number */
     48    bool accept_local;          /* accept peer's value for ournode */
     49    bool accept_remote;         /* accept peer's value for hisnode */
     50    bool accept_network;        /* accept network number */
    5151
    52     int tried_nlsp     : 1;     /* I have suggested NLSP already */
    53     int tried_rip      : 1;     /* I have suggested RIP/SAP already */
     52    bool tried_nlsp;            /* I have suggested NLSP already */
     53    bool tried_rip;             /* I have suggested RIP/SAP already */
    5454
    5555    u_int32_t his_network;      /* base network number */
  • cpukit/pppd/lcp.c

    r4b3c197f r2f1b930  
    1818 */
    1919
    20 #ifndef lint
    21 /* static char rcsid[] = "$Id$"; */
    22 #endif
     20#define RCSID   "$Id$";
    2321
    2422/*
     
    2826#include <stdio.h>
    2927#include <string.h>
    30 #include <syslog.h>
    31 #include <assert.h>
    32 #include <sys/ioctl.h>
    33 #include <sys/types.h>
    34 #include <sys/socket.h>
    35 #include <sys/time.h>
    36 #include <netinet/in.h>
     28#include <stdlib.h>
    3729
    3830#include "pppd.h"
     
    4133#include "chap.h"
    4234#include "magic.h"
     35
     36static const char rcsid[] = RCSID;
     37
     38/*
     39 * LCP-related command-line options.
     40 */
     41int     lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
     42int     lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
     43bool    lax_recv = 0;           /* accept control chars in asyncmap */
     44
     45static int setescape __P((char **));
     46
     47static option_t lcp_option_list[] = {
     48    /* LCP options */
     49    { "noaccomp", o_bool, &lcp_wantoptions[0].neg_accompression,
     50      "Disable address/control compression",
     51      OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
     52    { "-ac", o_bool, &lcp_wantoptions[0].neg_accompression,
     53      "Disable address/control compression",
     54      OPT_A2COPY, &lcp_allowoptions[0].neg_accompression },
     55    { "default-asyncmap", o_bool, &lcp_wantoptions[0].neg_asyncmap,
     56      "Disable asyncmap negotiation",
     57      OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
     58    { "-am", o_bool, &lcp_wantoptions[0].neg_asyncmap,
     59      "Disable asyncmap negotiation",
     60      OPT_A2COPY, &lcp_allowoptions[0].neg_asyncmap },
     61    { "asyncmap", o_uint32, &lcp_wantoptions[0].asyncmap,
     62      "Set asyncmap (for received packets)",
     63      OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
     64    { "-as", o_uint32, &lcp_wantoptions[0].asyncmap,
     65      "Set asyncmap (for received packets)",
     66      OPT_OR, &lcp_wantoptions[0].neg_asyncmap },
     67    { "nomagic", o_bool, &lcp_wantoptions[0].neg_magicnumber,
     68      "Disable magic number negotiation (looped-back line detection)",
     69      OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
     70    { "-mn", o_bool, &lcp_wantoptions[0].neg_magicnumber,
     71      "Disable magic number negotiation (looped-back line detection)",
     72      OPT_A2COPY, &lcp_allowoptions[0].neg_magicnumber },
     73    { "default-mru", o_bool, &lcp_wantoptions[0].neg_mru,
     74      "Disable MRU negotiation (use default 1500)",
     75      OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
     76    { "-mru", o_bool, &lcp_wantoptions[0].neg_mru,
     77      "Disable MRU negotiation (use default 1500)",
     78      OPT_A2COPY, &lcp_allowoptions[0].neg_mru },
     79    { "mru", o_int, &lcp_wantoptions[0].mru,
     80      "Set MRU (maximum received packet size) for negotiation",
     81      0, &lcp_wantoptions[0].neg_mru },
     82    { "nopcomp", o_bool, &lcp_wantoptions[0].neg_pcompression,
     83      "Disable protocol field compression",
     84      OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
     85    { "-pc", o_bool, &lcp_wantoptions[0].neg_pcompression,
     86      "Disable protocol field compression",
     87      OPT_A2COPY, &lcp_allowoptions[0].neg_pcompression },
     88    { "-p", o_bool, &lcp_wantoptions[0].passive,
     89      "Set passive mode", 1 },
     90    { "passive", o_bool, &lcp_wantoptions[0].passive,
     91      "Set passive mode", 1 },
     92    { "silent", o_bool, &lcp_wantoptions[0].silent,
     93      "Set silent mode", 1 },
     94    { "escape", o_special, setescape,
     95      "List of character codes to escape on transmission" },
     96    { "lcp-echo-failure", o_int, &lcp_echo_fails,
     97      "Set number of consecutive echo failures to indicate link failure" },
     98    { "lcp-echo-interval", o_int, &lcp_echo_interval,
     99      "Set time in seconds between LCP echo requests" },
     100    { "lcp-restart", o_int, &lcp_fsm[0].timeouttime,
     101      "Set time in seconds between LCP retransmissions" },
     102    { "lcp-max-terminate", o_int, &lcp_fsm[0].maxtermtransmits,
     103      "Set maximum number of LCP terminate-request transmissions" },
     104    { "lcp-max-configure", o_int, &lcp_fsm[0].maxconfreqtransmits,
     105      "Set maximum number of LCP configure-request transmissions" },
     106    { "lcp-max-failure", o_int, &lcp_fsm[0].maxnakloops,
     107      "Set limit on number of LCP configure-naks" },
     108    { "receive-all", o_bool, &lax_recv,
     109      "Accept all received control characters", 1 },
     110    {NULL}
     111};
    43112
    44113/* global vars */
     
    50119u_int32_t xmit_accm[NUM_PPP][8];                /* extended transmit ACCM */
    51120
    52 static u_int32_t lcp_echos_pending = 0; /* Number of outstanding echo msgs */
    53 static u_int32_t lcp_echo_number   = 0; /* ID number of next echo frame */
    54 static u_int32_t lcp_echo_timer_running = 0;  /* TRUE if a timer is running */
     121static int lcp_echos_pending = 0;       /* Number of outstanding echo msgs */
     122static int lcp_echo_number   = 0;       /* ID number of next echo frame */
     123static int lcp_echo_timer_running = 0;  /* set if a timer is running */
    55124
    56125static u_char nak_buffer[PPP_MRU];      /* where we construct a nak packet */
     
    128197    "LCP",
    129198    NULL,
     199    lcp_option_list,
     200    NULL,
    130201    NULL,
    131202    NULL
     
    139210#define CILEN_VOID      2
    140211#define CILEN_CHAR      3
    141 #define CILEN_SHORT     4       /* CILEN_VOID + sizeof(short) */
    142 #define CILEN_CHAP      5       /* CILEN_VOID + sizeof(short) + 1 */
    143 #define CILEN_LONG      6       /* CILEN_VOID + sizeof(long) */
    144 #define CILEN_LQR       8       /* CILEN_VOID + sizeof(short) + sizeof(long) */
     212#define CILEN_SHORT     4       /* CILEN_VOID + 2 */
     213#define CILEN_CHAP      5       /* CILEN_VOID + 2 + 1 */
     214#define CILEN_LONG      6       /* CILEN_VOID + 4 */
     215#define CILEN_LQR       8       /* CILEN_VOID + 2 + 4 */
    145216#define CILEN_CBCP      3
    146217
     
    148219                         (x) == CONFNAK ? "NAK" : "REJ")
    149220
     221
     222/*
     223 * setescape - add chars to the set we escape on transmission.
     224 */
     225static int
     226setescape(argv)
     227    char **argv;
     228{
     229    int n, ret;
     230    char *p, *endp;
     231
     232    p = *argv;
     233    ret = 1;
     234    while (*p) {
     235        n = strtol(p, &endp, 16);
     236        if (p == endp) {
     237            option_error("escape parameter contains invalid hex number '%s'",
     238                         p);
     239            return 0;
     240        }
     241        p = endp;
     242        if (n < 0 || n == 0x5E || n > 0xFF) {
     243            option_error("can't escape character 0x%x", n);
     244            ret = 0;
     245        } else
     246            xmit_accm[0][n >> 5] |= 1 << (n & 0x1F);
     247        while (*p == ',' || *p == ' ')
     248            ++p;
     249    }
     250    return ret;
     251}
    150252
    151253/*
     
    172274    wo->neg_mru = 1;
    173275    wo->mru = DEFMRU;
    174     wo->neg_asyncmap = 0;
     276    wo->neg_asyncmap = 1;
    175277    wo->asyncmap = 0;
    176278    wo->neg_chap = 0;                   /* Set to 1 on server */
     
    235337
    236338    if (phase != PHASE_DEAD)
    237         phase = PHASE_TERMINATE;
     339        new_phase(PHASE_TERMINATE);
    238340    if (f->state == STOPPED && f->flags & (OPT_PASSIVE|OPT_SILENT)) {
    239341        /*
     
    267369    ppp_set_xaccm(unit, xmit_accm[unit]);
    268370    ppp_send_config(unit, PPP_MRU, 0xffffffff, 0, 0);
    269     ppp_recv_config(unit, PPP_MRU, 0xffffffff,
     371    ppp_recv_config(unit, PPP_MRU, (lax_recv? 0: 0xffffffff),
    270372                    wo->neg_pcompression, wo->neg_accompression);
    271373    peer_mru[unit] = PPP_MRU;
     
    322424        if (f->state != OPENED)
    323425            break;
    324         LCPDEBUG((LOG_INFO, "lcp: Echo-Request, Rcvd id %d", id));
    325426        magp = inp;
    326427        PUTLONG(lcp_gotoptions[f->unit].magicnumber, magp);
     
    357458    u_short prot;
    358459
    359     LCPDEBUG((LOG_INFO, "lcp_rprotrej."));
    360 
    361     if (len < sizeof (u_short)) {
    362         LCPDEBUG((LOG_INFO,
    363                   "lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
     460    if (len < 2) {
     461        LCPDEBUG(("lcp_rprotrej: Rcvd short Protocol-Reject packet!"));
    364462        return;
    365463    }
    366464
    367465    GETSHORT(prot, inp);
    368 
    369     LCPDEBUG((LOG_INFO,
    370               "lcp_rprotrej: Rcvd Protocol-Reject packet for %x!",
    371               prot));
    372466
    373467    /*
     
    376470     */
    377471    if( f->state != OPENED ){
    378         LCPDEBUG((LOG_INFO, "Protocol-Reject discarded: LCP in state %d",
    379                   f->state));
     472        LCPDEBUG(("Protocol-Reject discarded: LCP in state %d", f->state));
    380473        return;
    381474    }
     
    390483        }
    391484
    392     syslog(LOG_WARNING, "Protocol-Reject for unsupported protocol 0x%x",
    393            prot);
     485    warn("Protocol-Reject for unsupported protocol 0x%x", prot);
    394486}
    395487
     
    406498     * Can't reject LCP!
    407499     */
    408     LCPDEBUG((LOG_WARNING,
    409               "lcp_protrej: Received Protocol-Reject for LCP!"));
     500    error("Received Protocol-Reject for LCP!");
    410501    fsm_protreject(&lcp_fsm[unit]);
    411502}
     
    542633    if (ucp - start_ucp != *lenp) {
    543634        /* this should never happen, because peer_mtu should be 1500 */
    544         syslog(LOG_ERR, "Bug in lcp_addci: wrong length")
    545 ;
     635        error("Bug in lcp_addci: wrong length");
    546636    }
    547637}
     
    672762    return (1);
    673763bad:
    674     LCPDEBUG((LOG_WARNING, "lcp_acki: received bad Ack!"));
     764    LCPDEBUG(("lcp_acki: received bad Ack!"));
    675765    return (0);
    676766}
     
    830920                /*
    831921                 * We were asking for CHAP/MD5; they must want a different
    832                  * algorithm.  If they can't do MD5, we'll have to stop
     922                 * algorithm.  If they can't do MD5, we can ask for M$-CHAP
     923                 * if we support it, otherwise we'll have to stop
    833924                 * asking for CHAP.
    834925                 */
    835                 if (cichar != go->chap_mdtype)
    836                     try.neg_chap = 0;
     926                if (cichar != go->chap_mdtype) {
     927#ifdef CHAPMS
     928                    if (cichar == CHAP_MICROSOFT)
     929                        go->chap_mdtype = CHAP_MICROSOFT;
     930                    else
     931#endif /* CHAPMS */
     932                        try.neg_chap = 0;
     933                }
    837934            } else {
    838935                /*
     
    9581055    }
    9591056
    960     /* If there is still anything left, this packet is bad. */
    961     if (len != 0)
    962         goto bad;
    963 
    9641057    /*
    9651058     * OK, the Nak is good.  Now we can update state.
     1059     * If there are any options left we ignore them.
    9661060     */
    9671061    if (f->state != OPENED) {
    9681062        if (looped_back) {
    9691063            if (++try.numloops >= lcp_loopbackfail) {
    970                 syslog(LOG_NOTICE, "Serial line is looped back.");
     1064                notice("Serial line is looped back.");
    9711065                lcp_close(f->unit, "Loopback detected");
     1066                status = EXIT_LOOPBACK;
    9721067            }
    9731068        } else
     
    9791074
    9801075bad:
    981     LCPDEBUG((LOG_WARNING, "lcp_nakci: received bad Nak!"));
     1076    LCPDEBUG(("lcp_nakci: received bad Nak!"));
    9821077    return 0;
    9831078}
     
    10201115        INCPTR(CILEN_VOID, p); \
    10211116        try.neg = 0; \
    1022         LCPDEBUG((LOG_INFO, "lcp_rejci rejected void opt %d", opt)); \
    10231117    }
    10241118#define REJCISHORT(opt, neg, val) \
     
    10341128            goto bad; \
    10351129        try.neg = 0; \
    1036         LCPDEBUG((LOG_INFO,"lcp_rejci rejected short opt %d", opt)); \
    10371130    }
    10381131#define REJCICHAP(opt, neg, val, digest) \
     
    10501143        try.neg = 0; \
    10511144        try.neg_upap = 0; \
    1052         LCPDEBUG((LOG_INFO,"lcp_rejci rejected chap opt %d", opt)); \
    10531145    }
    10541146#define REJCILONG(opt, neg, val) \
     
    10641156            goto bad; \
    10651157        try.neg = 0; \
    1066         LCPDEBUG((LOG_INFO,"lcp_rejci rejected long opt %d", opt)); \
    10671158    }
    10681159#define REJCILQR(opt, neg, val) \
     
    10791170            goto bad; \
    10801171        try.neg = 0; \
    1081         LCPDEBUG((LOG_INFO,"lcp_rejci rejected LQR opt %d", opt)); \
    10821172    }
    10831173#define REJCICBCP(opt, neg, val) \
     
    10931183            goto bad; \
    10941184        try.neg = 0; \
    1095         LCPDEBUG((LOG_INFO,"lcp_rejci rejected Callback opt %d", opt)); \
    10961185    }
    10971186
     
    11211210
    11221211bad:
    1123     LCPDEBUG((LOG_WARNING, "lcp_rejci: received bad Reject!"));
     1212    LCPDEBUG(("lcp_rejci: received bad Reject!"));
    11241213    return 0;
    11251214}
     
    11711260            p[1] < 2 ||                 /*  CI length too small or */
    11721261            p[1] > l) {                 /*  CI length too big? */
    1173             LCPDEBUG((LOG_WARNING, "lcp_reqci: bad CI length!"));
     1262            LCPDEBUG(("lcp_reqci: bad CI length!"));
    11741263            orc = CONFREJ;              /* Reject bad CI */
    11751264            cilen = l;                  /* Reject till end of packet */
     
    11851274        switch (citype) {               /* Check CI type */
    11861275        case CI_MRU:
    1187             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MRU"));
    11881276            if (!ao->neg_mru ||         /* Allow option? */
    11891277                cilen != CILEN_SHORT) { /* Check CI length */
     
    11921280            }
    11931281            GETSHORT(cishort, p);       /* Parse MRU */
    1194             LCPDEBUG((LOG_INFO, "(%d)", cishort));
    11951282
    11961283            /*
     
    12111298
    12121299        case CI_ASYNCMAP:
    1213             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ASYNCMAP"));
    12141300            if (!ao->neg_asyncmap ||
    12151301                cilen != CILEN_LONG) {
     
    12181304            }
    12191305            GETLONG(cilong, p);
    1220             LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong));
    12211306
    12221307            /*
     
    12361321
    12371322        case CI_AUTHTYPE:
    1238             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd AUTHTYPE"));
    12391323            if (cilen < CILEN_SHORT ||
    12401324                !(ao->neg_upap || ao->neg_chap)) {
     
    12461330            }
    12471331            GETSHORT(cishort, p);
    1248             LCPDEBUG((LOG_INFO, "(%x)", cishort));
    12491332
    12501333            /*
    1251              * Authtype must be UPAP or CHAP.
     1334             * Authtype must be PAP or CHAP.
    12521335             *
    12531336             * Note: if both ao->neg_upap and ao->neg_chap are set,
     
    12621345                if (ho->neg_chap ||     /* we've already accepted CHAP */
    12631346                    cilen != CILEN_SHORT) {
    1264                     LCPDEBUG((LOG_WARNING,
    1265                               "lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
     1347                    LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE PAP, rejecting..."));
    12661348                    orc = CONFREJ;
    12671349                    break;
     
    12731355                    PUTSHORT(PPP_CHAP, nakp);
    12741356                    PUTCHAR(ao->chap_mdtype, nakp);
     1357                    /* XXX if we can do CHAP_MICROSOFT as well, we should
     1358                       probably put in another option saying so */
    12751359                    break;
    12761360                }
     
    12811365                if (ho->neg_upap ||     /* we've already accepted PAP */
    12821366                    cilen != CILEN_CHAP) {
    1283                     LCPDEBUG((LOG_INFO,
    1284                               "lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
     1367                    LCPDEBUG(("lcp_reqci: rcvd AUTHTYPE CHAP, rejecting..."));
    12851368                    orc = CONFREJ;
    12861369                    break;
     
    13291412
    13301413        case CI_QUALITY:
    1331             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd QUALITY"));
    13321414            if (!ao->neg_lqr ||
    13331415                cilen != CILEN_LQR) {
     
    13381420            GETSHORT(cishort, p);
    13391421            GETLONG(cilong, p);
    1340             LCPDEBUG((LOG_INFO, "(%x %x)", cishort, (unsigned int) cilong));
    13411422
    13421423            /*
     
    13551436
    13561437        case CI_MAGICNUMBER:
    1357             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd MAGICNUMBER"));
    13581438            if (!(ao->neg_magicnumber || go->neg_magicnumber) ||
    13591439                cilen != CILEN_LONG) {
     
    13621442            }
    13631443            GETLONG(cilong, p);
    1364             LCPDEBUG((LOG_INFO, "(%x)", (unsigned int) cilong));
    13651444
    13661445            /*
     
    13821461
    13831462        case CI_PCOMPRESSION:
    1384             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd PCOMPRESSION"));
    13851463            if (!ao->neg_pcompression ||
    13861464                cilen != CILEN_VOID) {
     
    13921470
    13931471        case CI_ACCOMPRESSION:
    1394             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd ACCOMPRESSION"));
    13951472            if (!ao->neg_accompression ||
    13961473                cilen != CILEN_VOID) {
     
    14021479
    14031480        default:
    1404             LCPDEBUG((LOG_INFO, "lcp_reqci: rcvd unknown option %d",
    1405                       citype));
     1481            LCPDEBUG(("lcp_reqci: rcvd unknown option %d", citype));
    14061482            orc = CONFREJ;
    14071483            break;
     
    14091485
    14101486endswitch:
    1411         LCPDEBUG((LOG_INFO, " (%s)", CODENAME(orc)));
    14121487        if (orc == CONFACK &&           /* Good CI */
    14131488            rc != CONFACK)              /*  but prior CI wasnt? */
     
    14551530    }
    14561531
    1457     LCPDEBUG((LOG_INFO, "lcp_reqci: returning CONF%s.", CODENAME(rc)));
     1532    LCPDEBUG(("lcp_reqci: returning CONF%s.", CODENAME(rc)));
    14581533    return (rc);                        /* Return final code */
    14591534}
     
    14871562                    ho->neg_pcompression, ho->neg_accompression);
    14881563    ppp_recv_config(f->unit, (go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU),
    1489                     (go->neg_asyncmap? go->asyncmap: 0xffffffff),
     1564                    (lax_recv? 0: go->neg_asyncmap? go->asyncmap: 0xffffffff),
    14901565                    go->neg_pcompression, go->neg_accompression);
    14911566
     
    15851660    case CONFNAK:
    15861661    case CONFREJ:
    1587          
     1662        /* print option list */
    15881663        while (len >= 2) {
    15891664            GETCHAR(code, p);
     
    16221697                    case PPP_CHAP:
    16231698                        printer(arg, "chap");
     1699                        if (p < optend) {
     1700                            switch (*p) {
     1701                            case CHAP_DIGEST_MD5:
     1702                                printer(arg, " MD5");
     1703                                ++p;
     1704                                break;
     1705#ifdef CHAPMS
     1706                            case CHAP_MICROSOFT:
     1707                                printer(arg, " m$oft");
     1708                                ++p;
     1709                                break;
     1710#endif
     1711                            }
     1712                        }
    16241713                        break;
    16251714                    default:
     
    16461735                    p += 2;
    16471736                    printer(arg, "callback ");
    1648                     GETSHORT(cishort, p);
     1737                    GETCHAR(cishort, p);
    16491738                    switch (cishort) {
    16501739                    case CBCP_OPT:
     
    17061795    }
    17071796
    1708    
     1797    /* print the rest of the bytes in the packet */
    17091798    for (; len > 0; --len) {
    17101799        GETCHAR(code, p);
     
    17241813{
    17251814    if (f->state == OPENED) {
    1726         syslog(LOG_INFO, "No response to %d echo-requests", lcp_echos_pending);
    1727         syslog(LOG_NOTICE, "Serial link appears to be disconnected.");
     1815        info("No response to %d echo-requests", lcp_echos_pending);
     1816        notice("Serial link appears to be disconnected.");
    17281817        lcp_close(f->unit, "Peer not responding");
     1818        status = EXIT_PEER_DEAD;
    17291819    }
    17301820}
     
    17391829{
    17401830    LcpSendEchoRequest (f);
     1831    if (f->state != OPENED)
     1832        return;
    17411833
    17421834    /*
    17431835     * Start the timer for the next interval.
    17441836     */
    1745     assert (lcp_echo_timer_running==0);
     1837    if (lcp_echo_timer_running)
     1838        warn("assertion lcp_echo_timer_running==0 failed");
    17461839    TIMEOUT (LcpEchoTimeout, f, lcp_echo_interval);
    17471840    lcp_echo_timer_running = 1;
     
    17691862lcp_received_echo_reply (f, id, inp, len)
    17701863    fsm *f;
    1771     int id; u_char *inp; int len;
     1864    int id;
     1865    u_char *inp;
     1866    int len;
    17721867{
    17731868    u_int32_t magic;
     
    17751870    /* Check the magic number - don't count replies from ourselves. */
    17761871    if (len < 4) {
    1777         syslog(LOG_DEBUG, "lcp: received short Echo-Reply, length %d", len);
     1872        dbglog("lcp: received short Echo-Reply, length %d", len);
    17781873        return;
    17791874    }
     
    17811876    if (lcp_gotoptions[f->unit].neg_magicnumber
    17821877        && magic == lcp_gotoptions[f->unit].magicnumber) {
    1783         syslog(LOG_WARNING, "appear to have received our own echo-reply!");
     1878        warn("appear to have received our own echo-reply!");
    17841879        return;
    17851880    }
  • cpukit/pppd/lcp.h

    r4b3c197f r2f1b930  
    4545 */
    4646typedef struct lcp_options {
    47     int passive : 1;            /* Don't die if we don't get a response */
    48     int silent : 1;             /* Wait for the other end to start first */
    49     int restart : 1;            /* Restart vs. exit after close */
    50     int neg_mru : 1;            /* Negotiate the MRU? */
    51     int neg_asyncmap : 1;       /* Negotiate the async map? */
    52     int neg_upap : 1;           /* Ask for UPAP authentication? */
    53     int neg_chap : 1;           /* Ask for CHAP authentication? */
    54     int neg_magicnumber : 1;    /* Ask for magic number? */
    55     int neg_pcompression : 1;   /* HDLC Protocol Field Compression? */
    56     int neg_accompression : 1;  /* HDLC Address/Control Field Compression? */
    57     int neg_lqr : 1;            /* Negotiate use of Link Quality Reports */
    58     int neg_cbcp : 1;           /* Negotiate use of CBCP */
    59     u_short mru;                /* Value of MRU */
     47    bool passive;               /* Don't die if we don't get a response */
     48    bool silent;                /* Wait for the other end to start first */
     49    bool restart;               /* Restart vs. exit after close */
     50    bool neg_mru;               /* Negotiate the MRU? */
     51    bool neg_asyncmap;          /* Negotiate the async map? */
     52    bool neg_upap;              /* Ask for UPAP authentication? */
     53    bool neg_chap;              /* Ask for CHAP authentication? */
     54    bool neg_magicnumber;       /* Ask for magic number? */
     55    bool neg_pcompression;      /* HDLC Protocol Field Compression? */
     56    bool neg_accompression;     /* HDLC Address/Control Field Compression? */
     57    bool neg_lqr;               /* Negotiate use of Link Quality Reports */
     58    bool neg_cbcp;              /* Negotiate use of CBCP */
     59    int  mru;                   /* Value of MRU */
    6060    u_char chap_mdtype;         /* which MD type (hashing algorithm) */
    6161    u_int32_t asyncmap;         /* Value of async map */
  • cpukit/pppd/magic.c

    r4b3c197f r2f1b930  
    1818 */
    1919
    20 #ifndef lint
    21 /* static char rcsid[] = "$Id$"; */
    22 #endif
     20#define RCSID   "$Id$"
    2321
    2422#include <stdio.h>
     23#include <stdlib.h>
    2524#include <unistd.h>
    26 #include <stdlib.h>
    2725#include <sys/types.h>
    2826#include <sys/time.h>
     
    3028#include "pppd.h"
    3129#include "magic.h"
     30
     31static const char rcsid[] = RCSID;
    3232
    3333extern long mrand48 __P((void));
     
    6565 * drand48 et al.
    6666 */
    67 /* #include <stdlib.h> */
     67
    6868double
    6969drand48()
     
    8484    srand((int)seedval);
    8585}
    86 
  • cpukit/pppd/options.c

    r4b3c197f r2f1b930  
    1818 */
    1919
    20 #ifndef lint
    21 /* static char rcsid[] = "$Id$"; */
    22 #endif
     20#define RCSID   "$Id$"
    2321
    2422#include <ctype.h>
     
    2624#include <errno.h>
    2725#include <unistd.h>
    28 #include <limits.h>
    29 /* #include <stdlib.h> */
     26#include <fcntl.h>
     27#include <stdlib.h>
    3028#include <termios.h>
    31 #include <syslog.h>
    3229#include <string.h>
    3330#include <netdb.h>
     
    3734#include <netinet/in.h>
    3835#include <arpa/inet.h>
     36#ifdef PLUGIN
     37#include <dlfcn.h>
     38#endif
    3939#ifdef PPP_FILTER
    4040#include <pcap.h>
     
    5151#include "chap.h"
    5252#include "ccp.h"
    53 #ifdef CBCP_SUPPORT
    54 #include "cbcp.h"
     53
     54#include <net/ppp-comp.h>
     55
     56#if defined(ultrix) || defined(NeXT)
     57char *strdup __P((char *));
    5558#endif
    5659
    57 #ifdef IPX_CHANGE
    58 #include "ipxcp.h"
    59 #endif /* IPX_CHANGE */
    60 
    61 #include <net/ppp-comp.h>
    62 
    63 #define FALSE   0
    64 #define TRUE    1
    65 
    66 
    67 #ifndef GIDSET_TYPE
    68 #define GIDSET_TYPE     gid_t
    69 #endif
    70 #if 0
    71 static int privileged_option;   /* set iff the current option came from root */
    72 static char *option_source;     /* string saying where the option came from */
    73 #endif
     60static const char rcsid[] = RCSID;
    7461
    7562/*
     
    7966int     dflag = 0;              /* Tell libpcap we want debugging */
    8067#endif
    81 int     debug = 1;              /* Debug flag */
    82 int     kdebugflag = 1;         /* Tell kernel to print debug messages */
     68int     debug = 0;              /* Debug flag */
     69int     kdebugflag = 0;         /* Tell kernel to print debug messages */
    8370int     default_device = 1;     /* Using /dev/tty or equivalent */
    84 char    devnam[MAXPATHLEN] = "/dev/sccppp";     /* Device name */
     71char    devnam[MAXPATHLEN];     /* Device name */
    8572int     crtscts = 0;            /* Use hardware flow control */
    86 int     modem = 0;              /* Use modem control lines */
    87 int     inspeed = B115200;              /* Input/Output speed requested */
     73bool    modem = 1;              /* Use modem control lines */
     74int     inspeed = 0;            /* Input/Output speed requested */
    8875u_int32_t netmask = 0;          /* IP netmask to set on interface */
    89 int     lockflag = 0;           /* Create lock file to lock the serial dev */
    90 int     nodetach = 0;           /* Don't detach from controlling tty */
    91 char *connector[]={"TIMEOUT","3","ABORT","\nBUSY\r","ABORT","\nNO DIALTONE\r","ABORT","\nNO CARRIER\r","ABORT","\nNO ANSWER\r","ABORT","\nRINGING\r\n\r\nRINGING\r",
    92                                                                                                 "","\rAT","OK-+++\\c-OK","ATH0","TIMEOUT","30","OK","ATDT13","CONNECT",""};
    93 /*char *connector[]={"TIMEOUT","3","ABORT","\nBUSY\r","ABORT","\nNO DIALTONE\r","ABORT","\nNO CARRIER\r","ABORT","\nNO ANSWER\r","ABORT","\nRINGING\r\n\r\nRINGING\r",
    94                                                                                                 "","\rAT","OK-+++\\c-OK","ATH0","TIMEOUT","30","OK","ATDT0202122","CONNECT","","ppp","","Username:","ppp","Password:","ppp"};
    95 */
    96 char    **disconnector; /* Script to disestablish physical link */
    97 char    **welcomer;     /* Script to run after phys link estab. */
     76bool    lockflag = 0;           /* Create lock file to lock the serial dev */
     77bool    nodetach = 0;           /* Don't detach from controlling tty */
     78bool    updetach = 0;           /* Detach once link is up */
     79char    *initializer = NULL;    /* Script to initialize physical link */
     80char    *connect_script = NULL; /* Script to establish physical link */
     81char    *disconnect_script = NULL; /* Script to disestablish physical link */
     82char    *welcomer = NULL;       /* Script to run after phys link estab. */
     83char    *ptycommand = NULL;     /* Command to run on other side of pty */
    9884int     maxconnect = 0;         /* Maximum connect time */
    99 char    user[MAXNAMELEN]="stb"; /* Username for PAP */
    100 char    passwd[MAXSECRETLEN]="stb";     /* Password for PAP */
    101 int     auth_required = 0;      /* Peer is required to authenticate */
    102 int     defaultroute = 1;       /* assign default route through interface */
    103 int     proxyarp = 0;           /* Set up proxy ARP entry for peer */
    104 int     persist = 1;            /* Reopen link after it goes down */
    105 int     uselogin = 0;           /* Use /etc/passwd for checking PAP */
    106 int     lcp_echo_interval = 0;  /* Interval between LCP echo-requests */
    107 int     lcp_echo_fails = 0;     /* Tolerance to unanswered echo-requests */
    108 char    our_name[MAXNAMELEN]="infotel"; /* Our name for authentication purposes */
    109 char    remote_name[MAXNAMELEN]; /* Peer's name for authentication */
    110 int     explicit_remote = 0;    /* User specified explicit remote name */
    111 int     usehostname = 0;        /* Use hostname for our_name */
    112 int     disable_defaultip = 1;  /* Don't use hostname for default IP adrs */
    113 int     demand = 0;             /* do dial-on-demand */
     85char    user[MAXNAMELEN];       /* Username for PAP */
     86char    passwd[MAXSECRETLEN];   /* Password for PAP */
     87bool    persist = 0;            /* Reopen link after it goes down */
     88char    our_name[MAXNAMELEN];   /* Our name for authentication purposes */
     89bool    demand = 0;             /* do dial-on-demand */
    11490char    *ipparam = NULL;        /* Extra parameter for ip up/down scripts */
    115 int     cryptpap;               /* Passwords in pap-secrets are encrypted */
    11691int     idle_time_limit = 0;    /* Disconnect if idle for this many seconds */
    11792int     holdoff = 30;           /* # seconds to pause before reconnecting */
    118 int     refuse_pap = 0;         /* Set to say we won't do PAP */
    119 int     refuse_chap = 1;        /* Set to say we won't do CHAP */
    120 
    121 #ifdef MSLANMAN
    122 int     ms_lanman = 0;          /* Nonzero if use LanMan password instead of NT */
    123                                 /* Has meaning only with MS-CHAP challenges */
    124 #endif
    125 
    126 struct option_info auth_req_info;
    127 struct option_info connector_info;
    128 struct option_info disconnector_info;
     93bool    holdoff_specified;      /* true if a holdoff value has been given */
     94bool    notty = 0;              /* Stdin/out is not a tty */
     95char    *record_file = NULL;    /* File to record chars sent/received */
     96int     using_pty = 0;
     97bool    sync_serial = 0;        /* Device is synchronous serial device */
     98int     log_to_fd = 1;          /* send log messages to this fd too */
     99int     maxfail = 10;           /* max # of unsuccessful connection attempts */
     100char    linkname[MAXPATHLEN];   /* logical name for link */
     101bool    tune_kernel;            /* may alter kernel settings */
     102int     connect_delay = 1000;   /* wait this many ms after connect script */
     103
     104extern option_t auth_options[];
     105extern struct stat devstat;
     106extern int prepass;             /* Doing pre-pass to find device name */
     107
     108struct option_info initializer_info;
     109struct option_info connect_script_info;
     110struct option_info disconnect_script_info;
    129111struct option_info welcomer_info;
    130112struct option_info devnam_info;
     113struct option_info ptycommand_info;
     114
    131115#ifdef PPP_FILTER
    132116struct  bpf_program pass_filter;/* Filter program for packets to pass */
     
    135119#endif
    136120
     121char *current_option;           /* the name of the option being parsed */
     122int  privileged_option;         /* set iff the current option came from root */
     123char *option_source;            /* string saying where the option came from */
     124bool log_to_file;               /* log_to_fd is a file opened by us */
     125
    137126/*
    138127 * Prototypes
    139128 */
    140 #if 0
    141 static int setdevname __P((char *, int));
     129static int setdevname __P((char *));
    142130static int setipaddr __P((char *));
    143131static int setspeed __P((char *));
    144 static int setdebug __P((char **));
    145 static int setkdebug __P((char **));
    146 static int setpassive __P((char **));
    147 static int setsilent __P((char **));
    148132static int noopt __P((char **));
    149 static int setnovj __P((char **));
    150 static int setnovjccomp __P((char **));
    151 static int setvjslots __P((char **));
    152 static int reqpap __P((char **));
    153 static int nopap __P((char **));
    154 #ifdef OLD_OPTIONS
    155 static int setupapfile __P((char **));
    156 #endif
    157 static int nochap __P((char **));
    158 static int reqchap __P((char **));
    159 static int noaccomp __P((char **));
    160 static int noasyncmap __P((char **));
    161 static int noip __P((char **));
    162 static int nomagicnumber __P((char **));
    163 static int setasyncmap __P((char **));
    164 static int setescape __P((char **));
    165 static int setmru __P((char **));
    166 static int setmtu __P((char **));
    167 #ifdef CBCP_SUPPORT
    168 static int setcbcp __P((char **));
    169 #endif
    170 static int nomru __P((char **));
    171 static int nopcomp __P((char **));
    172 static int setconnector __P((char **));
    173 static int setdisconnector __P((char **));
    174 static int setwelcomer __P((char **));
    175 static int setmaxconnect __P((char **));
    176133static int setdomain __P((char **));
    177134static int setnetmask __P((char **));
    178 static int setcrtscts __P((char **));
    179 static int setnocrtscts __P((char **));
    180135static int setxonxoff __P((char **));
    181 static int setnodetach __P((char **));
    182 static int setupdetach __P((char **));
    183 static int setmodem __P((char **));
    184 static int setlocal __P((char **));
    185 static int setlock __P((char **));
    186 static int setname __P((char **));
    187 static int setuser __P((char **));
    188 static int setremote __P((char **));
    189 static int setauth __P((char **));
    190 static int setnoauth __P((char **));
    191136static int readfile __P((char **));
    192137static int callfile __P((char **));
    193 static int setdefaultroute __P((char **));
    194 static int setnodefaultroute __P((char **));
    195 static int setproxyarp __P((char **));
    196 static int setnoproxyarp __P((char **));
    197 static int setpersist __P((char **));
    198 static int setnopersist __P((char **));
    199 static int setdologin __P((char **));
    200 static int setusehostname __P((char **));
    201 static int setnoipdflt __P((char **));
    202 static int setlcptimeout __P((char **));
    203 static int setlcpterm __P((char **));
    204 static int setlcpconf __P((char **));
    205 static int setlcpfails __P((char **));
    206 static int setipcptimeout __P((char **));
    207 static int setipcpterm __P((char **));
    208 static int setipcpconf __P((char **));
    209 static int setipcpfails __P((char **));
    210 static int setpaptimeout __P((char **));
    211 static int setpapreqs __P((char **));
    212 static int setpapreqtime __P((char **));
    213 static int setchaptimeout __P((char **));
    214 static int setchapchal __P((char **));
    215 static int setchapintv __P((char **));
    216 static int setipcpaccl __P((char **));
    217 static int setipcpaccr __P((char **));
    218 static int setlcpechointv __P((char **));
    219 static int setlcpechofails __P((char **));
    220 static int noccp __P((char **));
    221 static int setbsdcomp __P((char **));
    222 static int setnobsdcomp __P((char **));
    223 static int setdeflate __P((char **));
    224 static int setnodeflate __P((char **));
    225 static int setnodeflatedraft __P((char **));
    226 static int setdemand __P((char **));
    227 static int setpred1comp __P((char **));
    228 static int setnopred1comp __P((char **));
    229 static int setipparam __P((char **));
    230 static int setpapcrypt __P((char **));
    231 static int setidle __P((char **));
    232 static int setholdoff __P((char **));
    233 static int setdnsaddr __P((char **));
    234 static int resetipxproto __P((char **));
    235 static int setwinsaddr __P((char **));
    236 static int showversion __P((char **));
    237 static int showhelp __P((char **));
     138static void usage __P((void));
     139static int setlogfile __P((char **));
     140#ifdef PLUGIN
     141static int loadplugin __P((char **));
     142#endif
    238143
    239144#ifdef PPP_FILTER
    240 static int setpdebug __P((char **));
    241145static int setpassfilter __P((char **));
    242146static int setactivefilter __P((char **));
    243147#endif
    244148
    245 #ifdef IPX_CHANGE
    246 static int setipxproto __P((char **));
    247 static int setipxanet __P((char **));
    248 static int setipxalcl __P((char **));
    249 static int setipxarmt __P((char **));
    250 static int setipxnetwork __P((char **));
    251 static int setipxnode __P((char **));
    252 static int setipxrouter __P((char **));
    253 static int setipxname __P((char **));
    254 static int setipxcptimeout __P((char **));
    255 static int setipxcpterm __P((char **));
    256 static int setipxcpconf __P((char **));
    257 static int setipxcpfails __P((char **));
    258 #endif /* IPX_CHANGE */
    259 
    260 #ifdef MSLANMAN
    261 static int setmslanman __P((char **));
     149static option_t *find_option __P((char *name));
     150static int process_option __P((option_t *, char **));
     151static int n_arguments __P((option_t *));
     152static int number_option __P((char *, u_int32_t *, int));
     153
     154/*
     155 * Structure to store extra lists of options.
     156 */
     157struct option_list {
     158    option_t *options;
     159    struct option_list *next;
     160};
     161
     162static struct option_list *extra_options = NULL;
     163
     164/*
     165 * Valid arguments.
     166 */
     167option_t general_options[] = {
     168    { "debug", o_int, &debug,
     169      "Increase debugging level", OPT_INC|OPT_NOARG|1 },
     170    { "-d", o_int, &debug,
     171      "Increase debugging level", OPT_INC|OPT_NOARG|1 },
     172    { "kdebug", o_int, &kdebugflag,
     173      "Set kernel driver debug level" },
     174    { "nodetach", o_bool, &nodetach,
     175      "Don't detach from controlling tty", 1 },
     176    { "-detach", o_bool, &nodetach,
     177      "Don't detach from controlling tty", 1 },
     178    { "updetach", o_bool, &updetach,
     179      "Detach from controlling tty once link is up", 1 },
     180    { "holdoff", o_int, &holdoff,
     181      "Set time in seconds before retrying connection" },
     182    { "idle", o_int, &idle_time_limit,
     183      "Set time in seconds before disconnecting idle link" },
     184    { "lock", o_bool, &lockflag,
     185      "Lock serial device with UUCP-style lock file", 1 },
     186    { "-all", o_special_noarg, noopt,
     187      "Don't request/allow any LCP or IPCP options (useless)" },
     188    { "init", o_string, &initializer,
     189      "A program to initialize the device",
     190      OPT_A2INFO | OPT_PRIVFIX, &initializer_info },
     191    { "connect", o_string, &connect_script,
     192      "A program to set up a connection",
     193      OPT_A2INFO | OPT_PRIVFIX, &connect_script_info },
     194    { "disconnect", o_string, &disconnect_script,
     195      "Program to disconnect serial device",
     196      OPT_A2INFO | OPT_PRIVFIX, &disconnect_script_info },
     197    { "welcome", o_string, &welcomer,
     198      "Script to welcome client",
     199      OPT_A2INFO | OPT_PRIVFIX, &welcomer_info },
     200    { "pty", o_string, &ptycommand,
     201      "Script to run on pseudo-tty master side",
     202      OPT_A2INFO | OPT_PRIVFIX | OPT_DEVNAM, &ptycommand_info },
     203    { "notty", o_bool, &notty,
     204      "Input/output is not a tty", OPT_DEVNAM | 1 },
     205    { "record", o_string, &record_file,
     206      "Record characters sent/received to file" },
     207    { "maxconnect", o_int, &maxconnect,
     208      "Set connection time limit", OPT_LLIMIT|OPT_NOINCR|OPT_ZEROINF },
     209    { "crtscts", o_int, &crtscts,
     210      "Set hardware (RTS/CTS) flow control", OPT_NOARG|OPT_VAL(1) },
     211    { "nocrtscts", o_int, &crtscts,
     212      "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
     213    { "-crtscts", o_int, &crtscts,
     214      "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
     215    { "cdtrcts", o_int, &crtscts,
     216      "Set alternate hardware (DTR/CTS) flow control", OPT_NOARG|OPT_VAL(2) },
     217    { "nocdtrcts", o_int, &crtscts,
     218      "Disable hardware flow control", OPT_NOARG|OPT_VAL(-1) },
     219    { "xonxoff", o_special_noarg, setxonxoff,
     220      "Set software (XON/XOFF) flow control" },
     221    { "domain", o_special, setdomain,
     222      "Add given domain name to hostname" },
     223    { "mtu", o_int, &lcp_allowoptions[0].mru,
     224      "Set our MTU", OPT_LIMITS, NULL, MAXMRU, MINMRU },
     225    { "netmask", o_special, setnetmask,
     226      "set netmask" },
     227    { "modem", o_bool, &modem,
     228      "Use modem control lines", 1 },
     229    { "local", o_bool, &modem,
     230      "Don't use modem control lines" },
     231    { "file", o_special, readfile,
     232      "Take options from a file", OPT_PREPASS },
     233    { "call", o_special, callfile,
     234      "Take options from a privileged file", OPT_PREPASS },
     235    { "persist", o_bool, &persist,
     236      "Keep on reopening connection after close", 1 },
     237    { "nopersist", o_bool, &persist,
     238      "Turn off persist option" },
     239    { "demand", o_bool, &demand,
     240      "Dial on demand", OPT_INITONLY | 1, &persist },
     241    { "sync", o_bool, &sync_serial,
     242      "Use synchronous HDLC serial encoding", 1 },
     243    { "logfd", o_int, &log_to_fd,
     244      "Send log messages to this file descriptor" },
     245    { "logfile", o_special, setlogfile,
     246      "Append log messages to this file" },
     247    { "nolog", o_int, &log_to_fd,
     248      "Don't send log messages to any file",
     249      OPT_NOARG | OPT_VAL(-1) },
     250    { "nologfd", o_int, &log_to_fd,
     251      "Don't send log messages to any file descriptor",
     252      OPT_NOARG | OPT_VAL(-1) },
     253    { "linkname", o_string, linkname,
     254      "Set logical name for link",
     255      OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN },
     256    { "maxfail", o_int, &maxfail,
     257      "Maximum number of unsuccessful connection attempts to allow" },
     258    { "ktune", o_bool, &tune_kernel,
     259      "Alter kernel settings as necessary", 1 },
     260    { "noktune", o_bool, &tune_kernel,
     261      "Don't alter kernel settings", 0 },
     262    { "connect-delay", o_int, &connect_delay,
     263      "Maximum time (in ms) to wait after connect script finishes" },
     264#ifdef PLUGIN
     265    { "plugin", o_special, loadplugin,
     266      "Load a plug-in module into pppd", OPT_PRIV },
    262267#endif
    263268
    264 static int number_option __P((char *, u_int32_t *, int));
    265 static int int_option __P((char *, int *));
    266 static int readable __P((int fd));
     269#ifdef PPP_FILTER
     270    { "pdebug", o_int, &dflag,
     271      "libpcap debugging" },
     272    { "pass-filter", 1, setpassfilter,
     273      "set filter for packets to pass" },
     274    { "active-filter", 1, setactivefilter,
     275      "set filter for active pkts" },
    267276#endif
    268277
    269 /*
    270  * Valid arguments.
    271  */
    272  
     278    { NULL }
     279};
     280
     281#ifndef IMPLEMENTATION
     282#define IMPLEMENTATION ""
     283#endif
     284
     285static char *usage_string = "\
     286pppd version %s.%d%s\n\
     287Usage: %s [ options ], where options are:\n\
     288        <device>        Communicate over the named device\n\
     289        <speed>         Set the baud rate to <speed>\n\
     290        <loc>:<rem>     Set the local and/or remote interface IP\n\
     291                        addresses.  Either one may be omitted.\n\
     292        asyncmap <n>    Set the desired async map to hex <n>\n\
     293        auth            Require authentication from peer\n\
     294        connect <p>     Invoke shell command <p> to set up the serial line\n\
     295        crtscts         Use hardware RTS/CTS flow control\n\
     296        defaultroute    Add default route through interface\n\
     297        file <f>        Take options from file <f>\n\
     298        modem           Use modem control lines\n\
     299        mru <n>         Set MRU value to <n> for negotiation\n\
     300See pppd(8) for more options.\n\
     301";
     302
    273303/*
    274304 * parse_args - parse a string of arguments from the command line.
     305 * If prepass is true, we are scanning for the device name and only
     306 * processing a few options, so error messages are suppressed.
    275307 */
    276308int
     
    279311    char **argv;
    280312{
    281 
    282 
    283 return 0;
    284 }
    285 
     313    char *arg;
     314    option_t *opt;
     315    int ret;
     316
     317    privileged_option = privileged;
     318    option_source = "command line";
     319    while (argc > 0) {
     320        arg = *argv++;
     321        --argc;
     322
     323        /*
     324         * First see if it's an option in the new option list.
     325         */
     326        opt = find_option(arg);
     327        if (opt != NULL) {
     328            int n = n_arguments(opt);
     329            if (argc < n) {
     330                option_error("too few parameters for option %s", arg);
     331                return 0;
     332            }
     333            current_option = arg;
     334            if (!process_option(opt, argv))
     335                return 0;
     336            argc -= n;
     337            argv += n;
     338            continue;
     339        }
     340
     341        /*
     342         * Maybe a tty name, speed or IP address?
     343         */
     344        if ((ret = setdevname(arg)) == 0
     345            && (ret = setspeed(arg)) == 0
     346            && (ret = setipaddr(arg)) == 0
     347            && !prepass) {
     348            option_error("unrecognized option '%s'", arg);
     349            usage();
     350            return 0;
     351        }
     352        if (ret < 0)    /* error */
     353            return 0;
     354    }
     355    return 1;
     356}
     357
     358#if 0
    286359/*
    287360 * scan_args - scan the command line arguments to get the tty name,
    288  * if specified.
    289  */
     361 * if specified.  Also checks whether the notty or pty option was given.
     362 */
     363void
     364scan_args(argc, argv)
     365    int argc;
     366    char **argv;
     367{
     368    char *arg;
     369    option_t *opt;
     370
     371    privileged_option = privileged;
     372    while (argc > 0) {
     373        arg = *argv++;
     374        --argc;
     375
     376        if (strcmp(arg, "notty") == 0 || strcmp(arg, "pty") == 0)
     377            using_pty = 1;
     378
     379        /* Skip options and their arguments */
     380        opt = find_option(arg);
     381        if (opt != NULL) {
     382            int n = n_arguments(opt);
     383            argc -= n;
     384            argv += n;
     385            continue;
     386        }
     387
     388        /* Check if it's a tty name and copy it if so */
     389        (void) setdevname(arg, 1);
     390    }
     391}
     392#endif
     393
     394/*
     395 * options_from_file - Read a string of options from a file,
     396 * and interpret them.
     397 */
     398int
     399options_from_file(filename, must_exist, check_prot, priv)
     400    char *filename;
     401    int must_exist;
     402    int check_prot;
     403    int priv;
     404{
     405    FILE *f;
     406    int i, newline, ret, err;
     407    option_t *opt;
     408    int oldpriv;
     409    char *oldsource;
     410    char *argv[MAXARGS];
     411    char args[MAXARGS][MAXWORDLEN];
     412    char cmd[MAXWORDLEN];
     413
     414    f = fopen(filename, "r");
     415    err = errno;
     416    if (f == NULL) {
     417        if (!must_exist && err == ENOENT)
     418            return 1;
     419        errno = err;
     420        option_error("Can't open options file %s: %m", filename);
     421        return 0;
     422    }
     423
     424    oldpriv = privileged_option;
     425    privileged_option = priv;
     426    oldsource = option_source;
     427    option_source = strdup(filename);
     428    if (option_source == NULL)
     429        option_source = "file";
     430    ret = 0;
     431    while (getword(f, cmd, &newline, filename)) {
     432        /*
     433         * First see if it's a command.
     434         */
     435        opt = find_option(cmd);
     436        if (opt != NULL) {
     437            int n = n_arguments(opt);
     438            for (i = 0; i < n; ++i) {
     439                if (!getword(f, args[i], &newline, filename)) {
     440                    option_error(
     441                        "In file %s: too few parameters for option '%s'",
     442                        filename, cmd);
     443                    goto err;
     444                }
     445                argv[i] = args[i];
     446            }
     447            current_option = cmd;
     448            if ((opt->flags & OPT_DEVEQUIV) && devnam_fixed) {
     449                option_error("the %s option may not be used in the %s file",
     450                             cmd, filename);
     451                goto err;
     452            }
     453            if (!process_option(opt, argv))
     454                goto err;
     455            continue;
     456        }
     457
     458        /*
     459         * Maybe a tty name, speed or IP address?
     460         */
     461        if ((i = setdevname(cmd)) == 0
     462            && (i = setspeed(cmd)) == 0
     463            && (i = setipaddr(cmd)) == 0) {
     464            option_error("In file %s: unrecognized option '%s'",
     465                         filename, cmd);
     466            goto err;
     467        }
     468        if (i < 0)              /* error */
     469            goto err;
     470    }
     471    ret = 1;
     472
     473err:
     474    fclose(f);
     475    privileged_option = oldpriv;
     476    option_source = oldsource;
     477    return ret;
     478}
     479
     480/*
     481 * options_from_user - See if the use has a ~/.ppprc file,
     482 * and if so, interpret options from it.
     483 */
     484int
     485options_from_user()
     486{
     487    return 0;
     488}
     489
     490/*
     491 * options_for_tty - See if an options file exists for the serial
     492 * device, and if so, interpret options from it.
     493 */
     494int
     495options_for_tty()
     496{
     497    char *dev, *path, *p;
     498    int ret;
     499    size_t pl;
     500
     501    dev = devnam;
     502    if (strncmp(dev, "/dev/", 5) == 0)
     503        dev += 5;
     504    if (dev[0] == 0 || strcmp(dev, "tty") == 0)
     505        return 1;               /* don't look for /etc/ppp/options.tty */
     506    pl = strlen(_PATH_TTYOPT) + strlen(dev) + 1;
     507    path = malloc(pl);
     508    if (path == NULL)
     509        novm("tty init file name");
     510    slprintf(path, pl, "%s%s", _PATH_TTYOPT, dev);
     511    /* Turn slashes into dots, for Solaris case (e.g. /dev/term/a) */
     512    for (p = path + strlen(_PATH_TTYOPT); *p != 0; ++p)
     513        if (*p == '/')
     514            *p = '.';
     515    ret = options_from_file(path, 0, 0, 1);
     516    free(path);
     517    return ret;
     518}
     519
     520/*
     521 * options_from_list - process a string of options in a wordlist.
     522 */
     523int
     524options_from_list(w, priv)
     525    struct wordlist *w;
     526    int priv;
     527{
     528    char *argv[MAXARGS];
     529    option_t *opt;
     530    int i, ret = 0;
     531
     532    privileged_option = priv;
     533    option_source = "secrets file";
     534
     535    while (w != NULL) {
     536        /*
     537         * First see if it's a command.
     538         */
     539        opt = find_option(w->word);
     540        if (opt != NULL) {
     541            int n = n_arguments(opt);
     542            struct wordlist *w0 = w;
     543            for (i = 0; i < n; ++i) {
     544                w = w->next;
     545                if (w == NULL) {
     546                    option_error(
     547                        "In secrets file: too few parameters for option '%s'",
     548                        w0->word);
     549                    goto err;
     550                }
     551                argv[i] = w->word;
     552            }
     553            current_option = w0->word;
     554            if (!process_option(opt, argv))
     555                goto err;
     556            w = w->next;
     557            continue;
     558        }
     559
     560        /*
     561         * Maybe a tty name, speed or IP address?
     562         */
     563        if ((i = setdevname(w->word)) == 0
     564            && (i = setspeed(w->word)) == 0
     565            && (i = setipaddr(w->word)) == 0) {
     566            option_error("In secrets file: unrecognized option '%s'",
     567                         w->word);
     568            goto err;
     569        }
     570        if (i < 0)              /* error */
     571            goto err;
     572        w = w->next;
     573    }
     574    ret = 1;
     575
     576err:
     577    return ret;
     578}
     579
     580/*
     581 * find_option - scan the option lists for the various protocols
     582 * looking for an entry with the given name.
     583 * This could be optimized by using a hash table.
     584 */
     585static option_t *
     586find_option(name)
     587    char *name;
     588{
     589    option_t *opt;
     590    struct option_list *list;
     591    int i;
     592
     593    for (list = extra_options; list != NULL; list = list->next)
     594        for (opt = list->options; opt->name != NULL; ++opt)
     595            if (strcmp(name, opt->name) == 0)
     596                return opt;
     597    for (opt = general_options; opt->name != NULL; ++opt)
     598        if (strcmp(name, opt->name) == 0)
     599            return opt;
     600    for (opt = auth_options; opt->name != NULL; ++opt)
     601        if (strcmp(name, opt->name) == 0)
     602            return opt;
     603    for (i = 0; protocols[i] != NULL; ++i)
     604        if ((opt = protocols[i]->options) != NULL)
     605            for (; opt->name != NULL; ++opt)
     606                if (strcmp(name, opt->name) == 0)
     607                    return opt;
     608    return NULL;
     609}
     610
     611/*
     612 * process_option - process one new-style option.
     613 */
     614static int
     615process_option(opt, argv)
     616    option_t *opt;
     617    char **argv;
     618{
     619    u_int32_t v;
     620    int iv, a;
     621    char *sv;
     622    int (*parser) __P((c