]> git.ozlabs.org Git - ppp.git/blob - pppd/pppd.h
CI: Updated the 'checkout' actions that were using Node.js 16 to Node.js 20. (#489)
[ppp.git] / pppd / pppd.h
1 /*
2  * pppd.h - PPP daemon global declarations.
3  *
4  * Copyright (c) 1984-2000 Carnegie Mellon University. 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  * 3. The name "Carnegie Mellon University" must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission. For permission or any legal
21  *    details, please contact
22  *      Office of Technology Transfer
23  *      Carnegie Mellon University
24  *      5000 Forbes Avenue
25  *      Pittsburgh, PA  15213-3890
26  *      (412) 268-4387, fax: (412) 268-7395
27  *      tech-transfer@andrew.cmu.edu
28  *
29  * 4. Redistributions of any form whatsoever must retain the following
30  *    acknowledgment:
31  *    "This product includes software developed by Computing Services
32  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33  *
34  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41  */
42
43 #ifndef PPP_PPPD_H
44 #define PPP_PPPD_H
45
46 #ifdef HAVE_STDARG_H
47 #include <stdarg.h>
48 #endif
49
50 #ifdef HAVE_STDBOOL_H
51 #include <stdbool.h>
52 #endif
53
54 #ifdef HAVE_STDDEF_H
55 #include <stddef.h>
56 #endif
57
58 #ifdef HAVE_STDINT_H
59 #include <stdint.h>
60 #endif
61
62 #ifdef HAVE_SYS_TYPES_H
63 #include <sys/types.h>
64 #endif
65
66 #include "pppdconf.h"
67
68 /*
69  * Limits
70  */
71 #define NUM_PPP         1       /* One PPP interface supported (per process) */
72 #define MAXWORDLEN      1024    /* max length of word in file (incl null) */
73 #define MAXARGS         1       /* max # args to a command */
74 #define MAXNAMELEN      256     /* max length of hostname or name for auth */
75 #define MAXSECRETLEN    256     /* max length of password or secret */
76
77
78 /*
79  * Values for phase.
80  */
81 typedef enum ppp_phase
82 {
83     PHASE_DEAD,
84     PHASE_INITIALIZE,
85     PHASE_SERIALCONN,
86     PHASE_DORMANT,
87     PHASE_ESTABLISH,
88     PHASE_AUTHENTICATE,
89     PHASE_CALLBACK,
90     PHASE_NETWORK,
91     PHASE_RUNNING,
92     PHASE_TERMINATE,
93     PHASE_DISCONNECT,
94     PHASE_HOLDOFF,
95     PHASE_MASTER,
96 } ppp_phase_t;
97
98 /*
99  * Values for exit codes
100  */
101 typedef enum ppp_exit_code
102 {
103     EXIT_OK                 = 0,
104     EXIT_FATAL_ERROR        = 1,
105     EXIT_OPTION_ERROR       = 2,
106     EXIT_NOT_ROOT           = 3,
107     EXIT_NO_KERNEL_SUPPORT  = 4,
108     EXIT_USER_REQUEST       = 5,
109     EXIT_LOCK_FAILED        = 6,
110     EXIT_OPEN_FAILED        = 7,
111     EXIT_CONNECT_FAILED     = 8,
112     EXIT_PTYCMD_FAILED      = 9,
113     EXIT_NEGOTIATION_FAILED = 10,
114     EXIT_PEER_AUTH_FAILED   = 11,
115     EXIT_IDLE_TIMEOUT       = 12,
116     EXIT_CONNECT_TIME       = 13,
117     EXIT_CALLBACK           = 14,
118     EXIT_PEER_DEAD          = 15,
119     EXIT_HANGUP             = 16,
120     EXIT_LOOPBACK           = 17,
121     EXIT_INIT_FAILED        = 18,
122     EXIT_AUTH_TOPEER_FAILED = 19,
123     EXIT_TRAFFIC_LIMIT      = 20,
124     EXIT_CNID_AUTH_FAILED   = 21
125 } ppp_exit_code_t;
126
127 /*
128  * Type of notifier callbacks
129  */
130 typedef enum
131 {
132     NF_PID_CHANGE,
133     NF_PHASE_CHANGE,
134     NF_EXIT,
135     NF_SIGNALED,
136     NF_IP_UP,
137     NF_IP_DOWN,
138     NF_IPV6_UP,
139     NF_IPV6_DOWN,
140     NF_AUTH_UP,
141     NF_LINK_DOWN,
142     NF_FORK,
143     NF_MAX_NOTIFY
144 } ppp_notify_t;
145
146 typedef enum
147 {
148     PPP_DIR_LOG,
149     PPP_DIR_RUNTIME,
150     PPP_DIR_CONF,
151     PPP_DIR_PLUGIN,
152 } ppp_path_t;
153
154 /*
155  * Unfortunately, the linux kernel driver uses a different structure
156  * for statistics from the rest of the ports.
157  * This structure serves as a common representation for the bits
158  * pppd needs.
159  */
160 struct pppd_stats
161 {
162     uint64_t            bytes_in;
163     uint64_t            bytes_out;
164     unsigned int        pkts_in;
165     unsigned int        pkts_out;
166 };
167 typedef struct pppd_stats ppp_link_stats_st;
168
169 /*
170  * Used for storing a sequence of words.  Usually malloced.
171  */
172 struct wordlist {
173     struct wordlist     *next;
174     char                *word;
175 };
176
177 struct option;
178 typedef void (*printer_func)(void *, char *, ...);
179
180 /*
181  * The following struct gives the addresses of procedures to call for a particular protocol.
182  */
183 struct protent {
184     /* PPP protocol number */
185     unsigned short protocol;
186     /* Initialization procedure */
187     void (*init)(int unit);
188     /* Process a received packet */
189     void (*input)(int unit, unsigned char *pkt, int len);
190     /* Process a received protocol-reject */
191     void (*protrej)(int unit);
192     /* Lower layer has come up */
193     void (*lowerup)(int unit);
194     /* Lower layer has gone down */
195     void (*lowerdown)(int unit);
196     /* Open the protocol */
197     void (*open)(int unit);
198     /* Close the protocol */
199     void (*close)(int unit, char *reason);
200     /* Print a packet in readable form */
201     int  (*printpkt)(unsigned char *pkt, int len, printer_func printer, void *arg);
202     /* Process a received data packet */
203     void (*datainput)(int unit, unsigned char *pkt, int len);
204     /* 0 iff protocol is disabled */
205     bool enabled_flag;
206     /* Text name of protocol */
207     char *name;
208     /* Text name of corresponding data protocol */
209     char *data_name;
210     /* List of command-line options */
211     struct option *options;
212     /* Check requested options, assign defaults */
213     void (*check_options)(void);
214     /* Configure interface for demand-dial */
215     int  (*demand_conf)(int unit);
216     /* Say whether to bring up link for this pkt */
217     int  (*active_pkt)(unsigned char *pkt, int len);
218 };
219
220 /* Table of pointers to supported protocols */
221 extern struct protent *protocols[];
222
223
224 /*
225  * This struct contains pointers to a set of procedures for doing operations on a "channel".  
226  * A channel provides a way to send and receive PPP packets - the canonical example is a serial 
227  * port device in PPP line discipline (or equivalently with PPP STREAMS modules pushed onto it).
228  */
229 struct channel {
230         /* set of options for this channel */
231         struct option *options;
232         /* find and process a per-channel options file */
233         void (*process_extra_options)(void);
234         /* check all the options that have been given */
235         void (*check_options)(void);
236         /* get the channel ready to do PPP, return a file descriptor */
237         int  (*connect)(void);
238         /* we're finished with the channel */
239         void (*disconnect)(void);
240         /* put the channel into PPP `mode' */
241         int  (*establish_ppp)(int);
242         /* take the channel out of PPP `mode', restore loopback if demand */
243         void (*disestablish_ppp)(int);
244         /* set the transmit-side PPP parameters of the channel */
245         void (*send_config)(int, uint32_t, int, int);
246         /* set the receive-side PPP parameters of the channel */
247         void (*recv_config)(int, uint32_t, int, int);
248         /* cleanup on error or normal exit */
249         void (*cleanup)(void);
250         /* close the device, called in children after fork */
251         void (*close)(void);
252 };
253
254 extern struct channel *the_channel;
255
256
257 /*
258  * Functions for string formatting and debugging
259  */
260
261 /* Is debug enabled */
262 bool debug_on();
263
264 /* Safe sprintf++ */
265 int slprintf(char *, int, char *, ...);         
266
267 /* vsprintf++ */
268 int vslprintf(char *, int, char *, va_list);
269
270 /* safe strcpy */
271 size_t strlcpy(char *, const char *, size_t);
272
273 /* safe strncpy */
274 size_t strlcat(char *, const char *, size_t);
275
276 /* log a debug message */
277 void dbglog(char *, ...);
278
279 /* log an informational message */
280 void info(char *, ...);
281
282 /* log a notice-level message */
283 void notice(char *, ...);
284
285 /* log a warning message */
286 void warn(char *, ...);
287
288 /* log an error message */
289 void error(char *, ...);        
290
291 /* log an error message and die(1) */
292 void fatal(char *, ...);        
293
294 /* Say we ran out of memory, and die */
295 void novm(char *);
296
297 /* Format a packet and log it with syslog */
298 void log_packet(unsigned char *, int, char *, int);
299
300 /* dump packet to debug log if interesting */
301 void dump_packet(const char *, unsigned char *, int);
302
303 /* initialize for using pr_log */
304 void init_pr_log(const char *, int);
305
306 /* printer fn, output to syslog */
307 void pr_log(void *, char *, ...);
308
309 /* finish up after using pr_log */
310 void end_pr_log(void);
311
312 /*
313  * Get the current exist status of pppd
314  */
315 ppp_exit_code_t ppp_status();
316
317 /*
318  * Set the exit status
319  */
320 void ppp_set_status(ppp_exit_code_t code);
321
322 /*
323  * Configure the session's maximum number of octets
324  */
325 void ppp_set_session_limit(unsigned int octets);
326
327 /*
328  * Which direction to limit the number of octets
329  */
330 void ppp_set_session_limit_dir(unsigned int direction);
331
332 /*
333  * Get the current link stats, returns true when valid and false if otherwise
334  */
335 bool ppp_get_link_stats(ppp_link_stats_st *stats);
336
337 /*
338  * Get pppd's notion of time
339  */
340 int ppp_get_time(struct timeval *);
341
342 /*
343  * Schedule a callback in s.us seconds from now
344  */
345 typedef void (*ppp_timer_cb)(void *arg);
346 void ppp_timeout(ppp_timer_cb func, void *arg, int s, int us);
347
348 /*
349  * Cancel any pending timer callbacks
350  */
351 void ppp_untimeout(void (*func)(void *), void *arg);
352
353 /*
354  * Clean up in a child before execing
355  */
356 void ppp_sys_close(void);
357
358 /*
359  * Fork & close stuff in child
360  */
361 pid_t ppp_safe_fork(int, int, int);
362
363 /*
364  * Get the current hostname
365  */
366 const char *ppp_hostname();
367
368 /*
369  * Is pppd using pty as a device (opposed to notty or pty opt).
370  */
371 bool ppp_using_pty();
372
373 /*
374  * Device is synchronous serial device
375  */
376 bool ppp_sync_serial();
377
378 /*
379  * Modem mode
380  */
381 bool ppp_get_modem();
382
383 /*
384  * Control the mode of the tty terminal
385  */
386 void ppp_set_modem(bool on);
387
388 /*
389  * Set the current session number, e.g. for PPPoE
390  */
391 void ppp_set_session_number(int number);
392
393 /*
394  * Set the current session number, e.g. for PPPoE
395  */
396 int ppp_get_session_number(void);
397
398 /*
399  * Check if pppd got signaled, returns 0 if not signaled, returns -1 on failure, and the signal number when signaled.
400  */
401 bool ppp_signaled(int sig);
402
403 /*
404  * Maximum connect time in seconds
405  */
406 int ppp_get_max_connect_time(void);
407
408 /*
409  * Set the maximum connect time in seconds
410  */
411 void ppp_set_max_connect_time(unsigned int max);
412
413 /*
414  * Get the link idle time before shutting the link down
415  */
416 int ppp_get_max_idle_time(void);
417
418 /*
419  * Set the link idle time before shutting the link down
420  */
421 void ppp_set_max_idle_time(unsigned int idle);
422
423 /*
424  * Get the duration the link was up (uptime)
425  */
426 int ppp_get_link_uptime();
427
428 /*
429  * Get the ipparam configured with pppd
430  */
431 const char *ppp_ipparam();
432
433 /*
434  * check if IP address is unreasonable
435  */
436 bool ppp_bad_ip_addr(uint32_t);
437
438 /*
439  * Expose an environment variable to scripts
440  */
441 void ppp_script_setenv(char *, char *, int);
442
443 /*
444  * Unexpose an environment variable to scripts
445  */
446 void ppp_script_unsetenv(char *);
447
448 /*
449  * Test whether ppp kernel support exists
450  */
451 int ppp_check_kernel_support(void);
452
453 /*
454  * Restore device setting
455  */
456 void ppp_generic_disestablish(int dev_fd);
457
458 /*
459  * Set the interface MTU
460  */
461 void ppp_set_mtu(int, int);
462
463 /*
464  * Get the interface MTU
465  */
466 int  ppp_get_mtu(int);
467
468 /*
469  * Make a ppp interface
470  */
471 int ppp_generic_establish(int dev_fd);
472
473 /*
474  * Get the peer's authentication name
475  */
476 const char *ppp_peer_authname(char *buf, size_t bufsz);
477
478 /*
479  * Get the remote name
480  */
481 const char *ppp_remote_name();
482
483 /*
484  * Get the remote number (if set), otherwise return NULL
485  */
486 const char *ppp_get_remote_number(void);
487
488 /*
489  * Set the remote number, typically it's a MAC address
490  */
491 void ppp_set_remote_number(const char *buf);
492
493 /*
494  * Get the current interface unit for the pppX device
495  */
496 int ppp_ifunit();
497
498 /*
499  * Get the current interface name
500  */
501 const char *ppp_ifname();
502
503 /*
504  * Get the current interface name
505  */
506 int ppp_get_ifname(char *buf, size_t bufsz);
507
508 /*
509  * Set the current interface name, ifname is a \0 terminated string
510  */
511 void ppp_set_ifname(const char *ifname);
512
513 /*
514  * Set the original devnam (prior to any renaming, etc).
515  */
516 int ppp_set_pppdevnam(const char *name);
517
518 /*
519  * Get the original devnam (prior to any renaming, etc).
520  */
521 const char *ppp_pppdevnam();
522
523 /*
524  * Get the current devnam, e.g. /dev/ttyS0, /dev/ptmx
525  */
526 const char *ppp_devnam();
527
528 /*
529  * Set the device name
530  */
531 int ppp_set_devnam(const char *name);
532
533 /*
534  * Definition for the notify callback function
535  *   ctx - contextual argument provided with the registration
536  *   arg - anything passed by the notification, e.g. phase, pid, etc
537  */
538 typedef void (ppp_notify_fn)(void *ctx, int arg);
539
540 /*
541  * Add a callback notification for when a given event has occured
542  */
543 void ppp_add_notify(ppp_notify_t type, ppp_notify_fn *func, void *ctx);
544
545 /*
546  * Remove a callback notification previously registered
547  */
548 void ppp_del_notify(ppp_notify_t type, ppp_notify_fn *func, void *ctx);
549
550 /*
551  * Get the path prefix in which a file is installed
552  */
553 int ppp_get_path(ppp_path_t type, char *buf, size_t bufsz);
554
555 /*
556  * Get the file with path prefix
557  */
558 int ppp_get_filepath(ppp_path_t type, const char *name, char *buf, size_t bufsz);
559
560 /*
561  * Check if pppd is to re-open link after it goes down
562  */
563 bool ppp_persist();
564
565 /*
566  * Hooks to enable plugins to hook into various parts of the code
567  */
568
569 struct ppp_idle; /* Declared in <linux/ppp_defs.h> */
570 extern int (*idle_time_hook)(struct ppp_idle *);
571 extern int (*new_phase_hook)(int);
572 extern int (*holdoff_hook)(void);
573 extern int  (*allowed_address_hook)(uint32_t addr);
574 extern void (*snoop_recv_hook)(unsigned char *p, int len);
575 extern void (*snoop_send_hook)(unsigned char *p, int len);
576
577 #endif /* PPP_PPPD_H */