1 /* 2 * options.h - header declarations for option processing for PPP. 3 * 4 * Copyright (c) 2000-2024 Paul Mackerras. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * 18 * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO 19 * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 20 * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY 21 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 23 * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 24 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 */ 26 27 #ifndef PPP_OPTIONS_H 28 #define PPP_OPTIONS_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 enum opt_type { 35 o_special_noarg, 36 o_special, 37 o_bool, 38 o_int, 39 o_uint32, 40 o_string, 41 o_wild 42 }; 43 44 struct option { 45 char *name; /* name of the option */ 46 enum opt_type type; 47 void *addr; 48 char *description; 49 unsigned int flags; 50 void *addr2; 51 int upper_limit; 52 int lower_limit; 53 const char *source; 54 short int priority; 55 short int winner; 56 }; 57 58 typedef struct option option_t; 59 60 /* Values for flags */ 61 #define OPT_VALUE 0xff /* mask for presupplied value */ 62 #define OPT_HEX 0x100 /* int option is in hex */ 63 #define OPT_NOARG 0x200 /* option doesn't take argument */ 64 #define OPT_OR 0x400 /* for u32, OR in argument to value */ 65 #define OPT_INC 0x400 /* for o_int, increment value */ 66 #define OPT_A2OR 0x800 /* for o_bool, OR arg to *(u_char *)addr2 */ 67 #define OPT_PRIV 0x1000 /* privileged option */ 68 #define OPT_STATIC 0x2000 /* string option goes into static array */ 69 #define OPT_NOINCR 0x2000 /* for o_int, value mustn't be increased */ 70 #define OPT_LLIMIT 0x4000 /* check value against lower limit */ 71 #define OPT_ULIMIT 0x8000 /* check value against upper limit */ 72 #define OPT_LIMITS (OPT_LLIMIT|OPT_ULIMIT) 73 #define OPT_ZEROOK 0x10000 /* 0 value is OK even if not within limits */ 74 #define OPT_HIDE 0x10000 /* for o_string, print value as ?????? */ 75 #define OPT_A2LIST 0x20000 /* for o_special, keep list of values */ 76 #define OPT_A2CLRB 0x20000 /* o_bool, clr val bits in *(u_char *)addr2 */ 77 #define OPT_ZEROINF 0x40000 /* with OPT_NOINCR, 0 == infinity */ 78 #define OPT_PRIO 0x80000 /* process option priorities for this option */ 79 #define OPT_PRIOSUB 0x100000 /* subsidiary member of priority group */ 80 #define OPT_ALIAS 0x200000 /* option is alias for previous option */ 81 #define OPT_A2COPY 0x400000 /* addr2 -> second location to rcv value */ 82 #define OPT_ENABLE 0x800000 /* use *addr2 as enable for option */ 83 #define OPT_A2CLR 0x1000000 /* clear *(bool *)addr2 */ 84 #define OPT_PRIVFIX 0x2000000 /* user can't override if set by root */ 85 #define OPT_INITONLY 0x4000000 /* option can only be set in init phase */ 86 #define OPT_DEVEQUIV 0x8000000 /* equiv to device name */ 87 #define OPT_DEVNAM (OPT_INITONLY | OPT_DEVEQUIV) 88 #define OPT_A2PRINTER 0x10000000 /* *addr2 printer_func to print option */ 89 #define OPT_A2STRVAL 0x20000000 /* *addr2 points to current string value */ 90 #define OPT_NOPRINT 0x40000000 /* don't print this option at all */ 91 92 #define OPT_VAL(x) ((x) & OPT_VALUE) 93 94 /* Values for priority */ 95 #define OPRIO_DEFAULT 0 /* a default value */ 96 #define OPRIO_CFGFILE 1 /* value from a configuration file */ 97 #define OPRIO_CMDLINE 2 /* value from the command line */ 98 #define OPRIO_SECFILE 3 /* value from options in a secrets file */ 99 #define OPRIO_ROOT 100 /* added to priority if OPT_PRIVFIX && root */ 100 101 /* Add additional supported options by e.g. plug-in */ 102 void ppp_add_options(struct option *options); 103 104 /* Parse options from an options file */ 105 int ppp_options_from_file(char *filename, int must_exist, int check_prot, 106 int privileged); 107 108 /* Simplified number_option for decimal ints */ 109 int ppp_int_option(char *name, int *value); 110 111 /* Print an error message about an option */ 112 void ppp_option_error(char *fmt, ...); 113 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 #endif // PPP_OPTIONS_H 120