-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathexterns.h
595 lines (534 loc) · 17.4 KB
/
externs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/*
* nsh externs, prototypes and macros
*/
#ifndef NSH_VERSION
#error "NSH_VERSION is undefined"
#endif
#define NSH_STRINGIFY(x) #x
#define NSH_STRINGVAL(x) NSH_STRINGIFY(x)
#define NSH_VERSION_STR NSH_STRINGVAL(NSH_VERSION)
#ifndef NSH_REXEC_PATH
#define NSH_REXEC_PATH /usr/local/bin/nsh
#endif
#ifndef NSHDOAS_PATH
#define NSHDOAS_PATH /usr/local/libexec/nshdoas
#endif
#define NSH_REXEC_PATH_STR NSH_STRINGVAL(NSH_REXEC_PATH)
#define NSH_REXEC_EXIT_CODE_QUIT 42
#define NSHDOAS_PATH_STR NSH_STRINGVAL(NSHDOAS_PATH)
#define NO_ARG(x) (strcasecmp(x, "no") == 0) /* absolute "no" */
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) /* sys/param.h */
struct rtdump {
char *buf; /* start of routing table */
char *lim; /* end of routing table */
};
extern char *vers; /* the version of nsh */
extern char saveline[1024]; /* command line */
#define NARGS (sizeof(line)/2) /* max arguments in char line[] */
extern char line[1024]; /* command line for makeargv() */
extern int margc; /* makeargv() arg count */
extern char *margv[]; /* makeargv() args */
extern int verbose; /* is verbose mode on? */
extern int editing; /* is command line editing mode on? */
extern int interactive_mode; /* are we in interactive mode? */
extern int config_mode; /* are we in comfig mode? */
extern int bridge; /* are we in bridge mode (or interface mode?) */
extern int priv; /* privileged mode or not? */
extern int privexec; /* process was started in privileged mode? */
extern pid_t pid; /* process id of nsh */
extern int cli_rtable; /* environment rtable */
struct hashtable;
extern struct hashtable *nsh_env;/* per-user session environment variables */
#define HSIZE 64
extern char hname[HSIZE]; /* prefix name to mode handler */
#ifdef _HISTEDIT_H_
extern HistEvent ev; /* ev */
#endif
/* defaults */
#define DEFAULT_MTU 1500 /* net.inet.ip.defmtu */
/* nopt.c */
#define no_arg 1
#define req_arg 2
#define req_2arg 3
struct nopts {
char *name;
int type;
int arg;
};
extern int noptind;
extern char *nopterr;
int nopt(int, char **, struct nopts *);
/* ppp.c */
int intsppp(int, char **, ...);
void pppoe_ipcp(char *, int, int);
int intpppoe(int, char **, ...);
int is_pppoe(char *, int);
#define NSH_PPPOE_IPADDR_IPCP 1
#define NSH_PPPOE_IPADDR_STATIC 2
int pppoe_get_ipaddrmode(char *);
void pppoe_conf_default_route(FILE *, char *, char *, char *, char *, char *);
void conf_pppoe(FILE *, int, char *);
void conf_sppp(FILE *, int, char *);
/* conf.c */
#define DHCPLEASECTL "/usr/sbin/dhcpleasectl"
#define SLAACCTL "/usr/sbin/slaacctl"
int conf(FILE *);
void conf_interfaces(FILE *, char *, int);
u_long default_mtu(char *);
int conf_routes(FILE *, char *, int, int, int);
int conf_dhcrelay(char *, char *, int);
int dhcpleased_has_address(char *, const char *, const char *);
/* show.c */
void p_rttables(int, u_int, int);
#ifdef _NETINET_IN_H_
char *routename4(in_addr_t);
char *netname4(in_addr_t, struct sockaddr_in *);
#endif
#ifdef _NETINET6_IN6_H_
char *routename6(struct sockaddr_in6 *);
char *netname6(struct sockaddr_in6 *, struct sockaddr_in6 *);
void in6_fillscopeid(struct sockaddr_in6 *);
void in6_clearscopeid(struct sockaddr_in6 *);
#endif
#ifdef _SYS_SOCKET_H_
char *routename(struct sockaddr *);
char *netname(struct sockaddr *, struct sockaddr *);
char *any_ntoa(const struct sockaddr *);
#endif
/* alignment constraint for routing socket */
#define ROUNDUP(a) \
((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long))
#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len))
/* routesys.c */
#ifdef _NET_ROUTE_H_
struct rtmsg {
struct rt_msghdr m_rtm;
char m_space[512];
};
extern struct rtmsg m_rtmsg;
#endif
#ifdef _WANT_SO_
union sockunion {
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
struct sockaddr_dl sdl;
struct sockaddr_inarp sinarp;
};
extern union sockunion so_dst, so_mask, so_gate, so_ifp;
#endif
#ifdef _NETINET6_IN6_H_
int prefixlen(int, struct sockaddr_in6 *);
#endif
extern int rtm_addrs;
extern u_long rtm_inits;
#define FLUSH 0
struct rtdump *getrtdump(int, int, int);
void freertdump(struct rtdump *);
int monitor(int, char **, ...);
int rtmsg(int, int, int, int, int);
void flushroutes(int, int, int);
void bprintf(FILE *, int, u_char *);
#ifdef _NET_IF_DL_H_
char *mylink_ntoa(const struct sockaddr_dl *);
#endif
extern char ifnetflags[];
extern char routeflags[];
extern char addrnames[];
extern char metricnames[];
/* ctl.c declarations moved to ctl.h */
/* cmdargs.c */
int cmdargs_output_setenv(char *, char **, int, int, char **, int);
int cmdargs_output(char *, char **, int, int);
int cmdargs(char *, char **);
int cmdargs_nowait(char *, char **, int);
int cmdargs_wait_for_child(void);
int nsh_setrtable(int);
/* commands.c */
extern pid_t child;
#define NOPTFILL 7
#define DEFAULT_EDITOR "/usr/bin/vi"
#define NSHRC_TEMP "/var/run/nshrc"
#define NSHRC "/etc/nshrc"
#define CLEAR "/usr/bin/clear"
#define LOGGER "/usr/bin/logger"
#define PING "/sbin/ping"
#define PING6 "/sbin/ping6"
#define TRACERT "/usr/sbin/traceroute"
#define TRACERT6 "/usr/sbin/traceroute6"
#define TELNET "/usr/bin/telnet"
#define SSH "/usr/bin/ssh"
#define PKILL "/usr/bin/pkill"
#define DIFF "/usr/bin/diff"
#define CRONTAB "/usr/bin/crontab"
#define REBOOT "/sbin/reboot"
#define HALT "/sbin/halt"
#define SU "/usr/bin/su"
#define DOAS "/usr/bin/doas"
#define SAVESCRIPT "/usr/local/bin/save.sh"
#ifndef DHCPLEASES
#define DHCPLEASES "/var/db/dhcpd.leases"
#endif
int quit(int, char **, ...);
void sigalarm(int);
void command(void);
int argvtostring(int, char **, char *, int);
int cmdrc(char rcname[FILENAME_MAX]);
/* prompt.c */
char *iprompt(void);
char *cprompt(void);
char *pprompt(void);
void setprompt(const char *);
void restoreprompt(void);
extern char prompt[128];
extern char saved_prompt[sizeof(prompt)];
int group (int, char **, ...);
void gen_help(char **, char *, char *, int);
void makeargv(void);
extern size_t cursor_argc;
extern size_t cursor_argo;
typedef struct cmd {
char *name; /* command name */
char *help; /* help string (NULL for no help) */
char *complete; /* context sensitive completion list */
char **table; /* next table for context completion */
int stlen; /* struct length (for rows in next table) */
int (*handler) (int, char **, ...); /* routine which executes command */
int needpriv; /* Do we need privilege to execute? */
int needconfig; /* Do we need config mode to execute? */
int nocmd; /* Can we specify 'no ...command...'? */
int modh; /* Is it a mode handler for cmdrc()? */
} Command;
typedef struct menu {
char *name; /* How user refers to it (case independent) */
char *help; /* Help information (0 ==> no help) */
char *complete; /* context sensitive completion list */
char **table; /* next table for context completion */
int stlen; /* struct length (for rows in next table) */
int minarg; /* Minimum number of arguments */
int maxarg; /* Maximum number of arguments */
int (*handler)(int, char **, ...); /* Routine to perform */
} Menu;
struct intlist {
char *name; /* How user refers to it (case independent) */
char *help; /* Help information (0 ==> no help) */
char *complete; /* context sensitive completion list */
char **table; /* next table for context completion */
int stlen; /* struct length (for rows in next table) */
int (*handler)(int, char **, ...); /* Routine to perform */
int nocmd; /* Can we specify 'no ...command...'? */
};
/* generic help /complt struct */
struct ghs {
char *name;
char *help;
char *complete;
char **table;
int stlen;
};
extern Command cmdtab[];
extern size_t cmdtab_nitems;
extern struct intlist Intlist[];
extern struct intlist Bridgelist[];
extern struct intlist *whichlist;
extern size_t Intlist_nitems;
extern size_t Bridgelist_nitems;
/* ieee80211.c */
#define NWID 0
#define NWKEY 1
#define POWERSAVE 2
#define TXPOWER 3
#define BSSID 4
#define DEFAULT_POWERSAVE 100 /* 100 ms */
const char *get_string(const char *, const char *, u_int8_t *, int *);
void make_string(char *str, int, const u_int8_t *buf, int);
int get_nwinfo(char *, char *, int, int);
int get_nwpowersave(int, char *);
int intnwkey(int, char **, ...);
int inttxpower(int, char **, ...);
int intbssid(int, char **, ...);
/* stats.c */
void rt_stats(void);
void tcp_stats(void);
void udp_stats(void);
void ip_stats(void);
void icmp_stats(void);
void igmp_stats(void);
void ah_stats(void);
void esp_stats(void);
void ipip_stats(void);
void carp_stats(void);
void pfsync_stats(void);
void ipcomp_stats(void);
/* mbuf.c */
void mbpr(void);
/* kread.c */
char *plural(int);
char *plurales(int);
/* genget.c */
int isprefix(char *, char*);
char **genget(char *, char **, int);
int Ambiguous(void *);
/* sysctl.c */
int sysctl_int(int[], int, int);
int ipsysctl(int, char **, ...);
void conf_sysctls(FILE *);
/* route.c */
#define NO_NETMASK 0
#define ASSUME_NETMASK 1
int route(int, char**, ...);
void show_route(char *, int);
int is_ip_addr(char *);
#ifdef _IP_T_
void parse_ip_pfx(char *, int, ip_t *);
int ip_route(ip_t *, ip_t *, u_short, int, int, struct rt_metrics, int inits);
#endif
int rtnameserver(int, char *[], int);
#ifdef _NETINET6_IN6_H_
int parse_ipv6(char *, struct in6_addr *);
#endif
/* if.c */
#define DHCRELAY "/usr/sbin/dhcrelay"
#define RAD "/usr/sbin/rad"
#define DHCPLEASED_SOCK "/dev/dhcpleased.sock"
#define SLAACD_SOCK "/dev/slaacd.sock"
#define IFDATA_MTU 1 /* request for if_data.ifi_mtu */
#define IFDATA_BAUDRATE 2 /* request for if_data.ifi_baudrate */
#define IFDATA_IFTYPE 3 /* request for if_data.ifi_type */
#define MBPS(bps) (bps / 1000 / 1000)
#define ROUNDMBPS(bps) ((float)bps == ((bps / 1000 / 1000) * 1000 * 1000))
#define ROUNDKBPS(bps) ((float)bps == ((bps / 1000) * 1000))
#define ROUNDKBYTES(bytes) ((float)bytes == ((bytes / 1024) * 1024))
#define DEFAULT_LLPRIORITY 3
void imr_init(char *);
int is_valid_ifname(char *);
int show_int(int, char **, ...);
int show_vlans(int, char **, ...);
int show_ip(int, char **, ...);
int show_autoconf(int, char **, ...);
int get_rdomain(int, char *);
int get_ifdata(char *, int);
int get_ifflags(char *, int);
int set_ifflags(char *, int, int);
int get_ifxflags(char *, int);
int set_ifxflags(char *, int, int);
u_int32_t in4_netaddr(u_int32_t, u_int32_t);
u_int32_t in4_brdaddr(u_int32_t, u_int32_t);
extern struct ghs intiphelp[];
extern struct ghs intip6help[];
int intip(int, char **, ...);
int intipcp(char *, int, int, char **);
int intmtu(int, char **, ...);
int intkeepalive(int, char **, ...);
int intrdomain(int, char **, ...);
int intdhcrelay(int, char **, ...);
int intmetric(int, char **, ...);
int intllprio(int, char **, ...);
int intflags(int, char **, ...);
int intxflags(int, char **, ...);
int intaf(char *, int, int, char **);
int intlink(int, char **, ...);
int intnwid(int, char **, ...);
int intpowersave(int, char **, ...);
int intdesc(int, char **, ...);
int intpflow(int, char **, ...);
int intlladdr(int, char **, ...);
int intgroup(int, char **, ...);
int intrtlabel(int, char **, ...);
int intparent(int, char **, ...);
int intpatch(int, char **, ...);
int intmpls(int, char **, ...);
int intpwe3(int, char **, ...);
int intvnetflowid(int, char **, ...);
int addaf(char *, int, int);
int removeaf(char *, int, int);
int check_daemon_control_socket(const char *);
int dhcpleased_is_running(void);
int slaacd_is_running(void);
char *get_hwdaddr(char *);
/* main.c */
void intr(void);
/* version.c */
int version(int, char **, ...);
/* compile.c */
extern char compiled[], compiledby[], compiledon[], compilehost[];
/* bridge.c */
long bridge_cfg(int, char *, int);
int bridge_confaddrs(int, char *, char *, FILE *);
int bridge_rules(int, char *, char *, char *, FILE *);
int bridge_list(int, char *, char *, char *, int, int);
int bridge_member_search(int, char *);
int bridge_addrs(int, char *, char *, char *, FILE *);
int set_ifflag(int, char *, short);
int clr_ifflag(int, char *, short);
int is_bridge(int, char *);
int brport(int, char **, ...);
int brval(int, char **, ...);
int brrule(int, char **, ...);
int brstatic(int, char **, ...);
int brpri(int, char **, ...);
int flush_bridgedyn(int , char **, ...);
int flush_bridgeall(int, char **, ...);
int flush_bridgerule(int, char **, ...);
int brprotect(int, char **, ...);
int show_bridges(int, char **, ...);
/* tunnel.c */
int inttunnel(int, char **, ...);
int intvnetid(int, char **, ...);
int get_physrtable(int, char *);
int get_physttl(int, char *);
int get_physecn(int, char *);
int get_physdf(int, char *);
int64_t get_vnetid(int, char *);
/* media.c */
#define DEFAULT_MEDIA_TYPE "autoselect"
int media_status(int, char *, char *, FILE *);
void media_supported(int, char *, char *, char *, FILE *);
int phys_status(int, char *, char *, char *, int, int);
int intmedia(int, char **, ...);
int intmediaopt(int, char **, ...);
int conf_media_status(FILE *, int, char *);
struct ifmediareq;
const char *get_ifm_linkstate_str(struct ifmediareq *);
const char *get_ifm_options_str(char *, size_t, uint64_t, uint64_t *);
const char *get_ifm_type_str(uint64_t);
const char *get_ifm_subtype_str(uint64_t);
/* passwd.c */
#define NSHPASSWD_TEMP "/var/run/nshpasswd"
int read_pass(char *, size_t);
int gen_salt(char *, size_t);
int enable(int, char **, ...);
/* pfsync.c */
#define PFSYNC_MAXUPDATES 128
int intsyncdev(int, char **, ...);
int intsyncpeer(int, char **, ...);
int intmaxupd(int, char **, ...);
int conf_pfsync(FILE *, int, char *);
/* carp.c */
#define CARP_ADVSKEW 0
#define CARP_ADVBASE 1
#define CARP_VHID 2
#define CARP_PEER 3
#define CARP_BALANCING 4
int intcarp(int, char **, ...);
int intcpass(int, char **, ...);
int intcnode(int, char **, ...);
int conf_carp(FILE *, int, char *);
int carp_state(int, char *, FILE *);
int intcdev(int, char **, ...);
int carplock(int);
/* trunk.c */
int inttrunkport(int, char **, ...);
int inttrunkproto(int, char **, ...);
int conf_trunk(FILE *output, int ifs, char *ifname);
void show_trunk(int ifs, char *ifname, FILE *);
/* who.c */
int who(int, char **, ...);
/* arp.c */
int arpget(const char *);
int arpset(int, char **, ...);
void arpdump(void);
void conf_arp(FILE *, char *);
char *sec2str(time_t);
struct sockaddr_dl;
char *ether_str(struct sockaddr_dl *);
/* ndp.c */
int ndpset(int, char **, ...);
void ndpget(const char *);
int ndpdelete(const char *);
struct sockaddr_in6;
void ndpdump(struct sockaddr_in6 *, int);
void conf_ndp(FILE *output, char *delim);
/* nameserver.c */
int nameserverset(int, char **, ...);
void conf_nameserver(FILE *);
/* more.c */
int more(char *);
int nsh_cbreak(void);
void nsh_nocbreak(void);
void setwinsize(int);
#ifdef _SYS_TTYCOM_H_
extern struct winsize winsize;
#endif
/* complete.c */
#define CMPL(x) __STRING(x),
#define CMPL0 "",
void inithist(void);
void endhist(void);
void initedit(void);
void endedit(void);
/* utils.c */
int string_index(char *, char **);
char *format_time(time_t);
char *format_k(uint64_t amt);
/* sqlite3.c */
#define SQ3DBFILE "/var/run/nsh.db"
#define DB_X_ENABLE 1 /* enable command */
#define DB_X_DISABLE 2 /* disable command */
#define DB_X_LOCAL 3 /* local control command */
#define DB_X_OTHER 4 /* other command */
#define DB_X_REMOVE 5 /* remove command */
#define DB_X_ENABLE_DEFAULT 6 /* enable command, always prints enable until disabled */
#define DB_X_DISABLE_ALWAYS 7 /* disable command, always prints if disabled */
int db_create_table_rtables(void);
int db_create_table_flag_x(char *);
int db_create_table_nameservers(void);
int db_insert_flag_x(char *, char *, int, int, char *);
int db_insert_rtables(int, char *);
int db_insert_nameserver(char *);
int db_delete_rtables_rtable(int);
int db_delete_flag_x_ctl(char *, char *, int);
int db_delete_flag_x_ctl_data(char *, char *, char *);
int db_delete_nameservers(void);
#ifdef _STRINGLIST_H
int db_select_flag_x_ctl_data(StringList *, char *, char *, char *);
int db_select_flag_x_ctl(StringList *, char *, char *);
int db_select_rtable_rtables(StringList *);
int db_select_rtables_rtable(StringList *, int);
int db_select_rtables_ctl(StringList *, char *);
int db_select_name_rtable(StringList *, int);
int db_select_flag_x_ctl_rtable(StringList *, char *, int);
int db_select_flag_x_data_ctl_rtable(StringList *, char *, char *, int);
int db_select_nameservers(StringList *);
#endif
int db_select_flag_x_dbflag_rtable(char *, char *, int);
/* pflow.c */
#define PFLOW_SENDER 0
#define PFLOW_RECEIVER 1
#define PFLOW_VERSION 2
#ifdef _SYS_SOCKET_H_
int pflow_addr(const char *, struct sockaddr_storage *);
#endif
int pflow_status(int, int, char *, char *);
/* wg.c */
int intwg(int, char **, ...);
int intwgpeer(int, char **, ...);
void conf_wg(FILE *, int, char *);
void show_wg(int, char *, FILE *);
/* umb.c */
int intumb(int, char **, ...);
void conf_umb(FILE *, int, char *);
void show_umb(int, char *, FILE *);
/* utf8.c */
#ifdef _WCHAR_H_
int mbs2ws(wchar_t **, size_t *, const char *);
#endif
int mbsavis(char**, int *, const char *);
/* ctlargs.c */
int pr_prot1(int, char **, ...);
char **step_optreq(char **, char **, int, char **, int);
/* hashtable.c */
struct hashtable;
struct hashtable *hashtable_alloc(void);
void hashtable_free(struct hashtable *);
int hashtable_add(struct hashtable *, void *key, size_t keysize,
void *value, size_t valsize);
void *hashtable_get_keyptr(struct hashtable *, void *key, size_t keysize);
void *hashtable_get_value(struct hashtable *, void *key, size_t keysize);
int hashtable_remove(struct hashtable *, void **keyptr, void **value,
size_t *valsize, void *key, size_t keysize);
int hashtable_contains(struct hashtable *, void *key, size_t keysize);
int hashtable_foreach(struct hashtable *,
int (*cb)(void *, size_t, void *, size_t, void *),
void *cb_arg);
int hashtable_num_entries(struct hashtable *);