]>
Commit | Line | Data |
---|---|---|
b5d9ee5c MM |
1 | /* |
2 | * BIRD -- Declarations Common to Unix Port | |
3 | * | |
50fe90ed | 4 | * (c) 1998--2000 Martin Mares <mj@ucw.cz> |
b5d9ee5c MM |
5 | * |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | #ifndef _BIRD_UNIX_H_ | |
10 | #define _BIRD_UNIX_H_ | |
11 | ||
ff2857b0 OZ |
12 | #include <sys/socket.h> |
13 | ||
a0c37b45 | 14 | struct pool; |
05476c4d OZ |
15 | struct iface; |
16 | struct birdsock; | |
c68ba7d0 | 17 | struct rfile; |
a0c37b45 | 18 | |
4c9dd1e4 MM |
19 | /* main.c */ |
20 | ||
44d4ab7a | 21 | extern char *bird_name; |
4c9dd1e4 MM |
22 | void async_config(void); |
23 | void async_dump(void); | |
f4aabcee | 24 | void async_shutdown(void); |
a92cf57d | 25 | void cmd_check_config(char *name); |
3e405fb1 | 26 | void cmd_reconfig(char *name, int type, uint timeout); |
a92cf57d OZ |
27 | void cmd_reconfig_confirm(void); |
28 | void cmd_reconfig_undo(void); | |
9106a750 | 29 | void cmd_reconfig_status(void); |
e81b440f | 30 | void cmd_shutdown(void); |
4c9dd1e4 | 31 | |
8bcb5fb1 | 32 | #define UNIX_DEFAULT_CONFIGURE_TIMEOUT 300 |
a92cf57d | 33 | |
8bcb5fb1 OZ |
34 | #define UNIX_DEFAULT_LATENCY_LIMIT (1 S_) |
35 | #define UNIX_DEFAULT_WATCHDOG_WARNING (5 S_) | |
05476c4d | 36 | |
b5d9ee5c MM |
37 | /* io.c */ |
38 | ||
05476c4d OZ |
39 | #define ERR(c) do { s->err = c; return -1; } while (0) |
40 | #define ERR2(c) do { s->err = c; goto err; } while (0) | |
41 | #define ERR_MSG(c) do { errno = 0; s->err = c; return -1; } while (0) | |
42 | ||
43 | ||
44 | #define SOCKADDR_SIZE 32 | |
45 | ||
46 | typedef struct sockaddr_bird { | |
47 | struct sockaddr sa; | |
48 | char padding[SOCKADDR_SIZE - sizeof(struct sockaddr)]; | |
49 | } sockaddr; | |
50 | ||
4c9dd1e4 | 51 | |
05476c4d OZ |
52 | |
53 | /* This is sloppy hack, it should be detected by configure script */ | |
54 | /* Linux systems have it defined so this is definition for BSD systems */ | |
55 | #ifndef s6_addr32 | |
56 | #define s6_addr32 __u6_addr.__u6_addr32 | |
57 | #endif | |
58 | ||
59 | ||
60 | static inline ip_addr ipa_from_in4(struct in_addr a) | |
61 | { return ipa_from_u32(ntohl(a.s_addr)); } | |
62 | ||
63 | static inline ip_addr ipa_from_in6(struct in6_addr a) | |
88a183c6 | 64 | { return ipa_build6(ntohl(a.s6_addr32[0]), ntohl(a.s6_addr32[1]), ntohl(a.s6_addr32[2]), ntohl(a.s6_addr32[3])); } |
05476c4d OZ |
65 | |
66 | static inline ip_addr ipa_from_sa4(sockaddr *sa) | |
67 | { return ipa_from_in4(((struct sockaddr_in *) sa)->sin_addr); } | |
68 | ||
69 | static inline ip_addr ipa_from_sa6(sockaddr *sa) | |
70 | { return ipa_from_in6(((struct sockaddr_in6 *) sa)->sin6_addr); } | |
71 | ||
d7661fbe JMM |
72 | static inline ip_addr ipa_from_sa(sockaddr *sa) |
73 | { | |
74 | switch (sa->sa.sa_family) | |
75 | { | |
76 | case AF_INET: return ipa_from_sa4(sa); | |
77 | case AF_INET6: return ipa_from_sa6(sa); | |
78 | default: return IPA_NONE; | |
79 | } | |
80 | } | |
81 | ||
05476c4d OZ |
82 | static inline struct in_addr ipa_to_in4(ip_addr a) |
83 | { return (struct in_addr) { htonl(ipa_to_u32(a)) }; } | |
84 | ||
153f02da OZ |
85 | static inline struct in_addr ip4_to_in4(ip4_addr a) |
86 | { return (struct in_addr) { htonl(ip4_to_u32(a)) }; } | |
87 | ||
05476c4d OZ |
88 | static inline struct in6_addr ipa_to_in6(ip_addr a) |
89 | { return (struct in6_addr) { .s6_addr32 = { htonl(_I0(a)), htonl(_I1(a)), htonl(_I2(a)), htonl(_I3(a)) } }; } | |
90 | ||
91 | void sockaddr_fill(sockaddr *sa, int af, ip_addr a, struct iface *ifa, uint port); | |
92 | int sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *port); | |
93 | ||
94 | ||
4daf03e5 MM |
95 | #ifndef SUN_LEN |
96 | #define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen ((ptr)->sun_path)) | |
97 | #endif | |
98 | ||
7152e5ef JMM |
99 | extern volatile int async_config_flag; |
100 | extern volatile int async_dump_flag; | |
101 | extern volatile int async_shutdown_flag; | |
b93abffa | 102 | |
b5d9ee5c MM |
103 | void io_init(void); |
104 | void io_loop(void); | |
8bcb5fb1 | 105 | void io_log_dump(void); |
05476c4d | 106 | int sk_open_unix(struct birdsock *s, char *name); |
c68ba7d0 OZ |
107 | struct rfile *rf_open(struct pool *, char *name, char *mode); |
108 | void *rf_file(struct rfile *f); | |
109 | int rf_fileno(struct rfile *f); | |
41c8976e OF |
110 | void test_old_bird(char *path); |
111 | ||
7e5f5ffd MM |
112 | /* krt.c bits */ |
113 | ||
114 | void krt_io_init(void); | |
115 | ||
a0c37b45 MM |
116 | /* log.c */ |
117 | ||
4e398e34 | 118 | void main_thread_init(void); |
a0c37b45 | 119 | void log_init_debug(char *); /* Initialize debug dump to given file (NULL=stderr, ""=off) */ |
3fda08e4 | 120 | void log_switch(int initial, list *l, char *); |
a0c37b45 MM |
121 | |
122 | struct log_config { | |
123 | node n; | |
ae80a2de | 124 | uint mask; /* Classes to log */ |
a0c37b45 | 125 | void *fh; /* FILE to log to, NULL=syslog */ |
6712e772 OZ |
126 | struct rfile *rf; /* Resource for log file */ |
127 | char *filename; /* Log filename */ | |
128 | char *backup; /* Secondary filename (for log rotation) */ | |
129 | off_t pos; /* Position/size of current log */ | |
130 | off_t limit; /* Log size limit */ | |
a0c37b45 MM |
131 | int terminal_flag; |
132 | }; | |
133 | ||
b5d9ee5c | 134 | #endif |