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