]> git.ipfire.org Git - thirdparty/bird.git/blame - sysdep/unix/unix.h
Refactoring of OSPF messages.
[thirdparty/bird.git] / sysdep / unix / unix.h
CommitLineData
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 14struct pool;
05476c4d
OZ
15struct iface;
16struct birdsock;
a0c37b45 17
4c9dd1e4
MM
18/* main.c */
19
44d4ab7a 20extern char *bird_name;
4c9dd1e4
MM
21void async_config(void);
22void async_dump(void);
f4aabcee 23void async_shutdown(void);
a92cf57d
OZ
24void cmd_check_config(char *name);
25void cmd_reconfig(char *name, int type, int timeout);
26void cmd_reconfig_confirm(void);
27void cmd_reconfig_undo(void);
e81b440f 28void cmd_shutdown(void);
4c9dd1e4 29
a92cf57d
OZ
30#define UNIX_DEFAULT_CONFIGURE_TIMEOUT 300
31
05476c4d 32
b5d9ee5c
MM
33/* io.c */
34
05476c4d
OZ
35#define ERR(c) do { s->err = c; return -1; } while (0)
36#define ERR2(c) do { s->err = c; goto err; } while (0)
37#define ERR_MSG(c) do { errno = 0; s->err = c; return -1; } while (0)
38
39
40#define SOCKADDR_SIZE 32
41
42typedef struct sockaddr_bird {
43 struct sockaddr sa;
44 char padding[SOCKADDR_SIZE - sizeof(struct sockaddr)];
45} sockaddr;
46
4c9dd1e4 47
4f22c981 48#ifdef IPV6
4532a89e 49#define BIRD_AF AF_INET6
05476c4d
OZ
50#define _MI6(x1,x2,x3,x4) _MI(x1, x2, x3, x4)
51#define ipa_is_link_local(x) ipa_has_link_scope(x)
52#define ipa_from_sa(x) ipa_from_sa6(x)
53#define ipa_from_u32(x) _MI6(0,0,0xffff,x)
54#define ipa_to_u32(x) _I3(x)
4f22c981 55#else
4532a89e 56#define BIRD_AF AF_INET
05476c4d
OZ
57#define _I0(X) 0
58#define _I1(X) 0
59#define _I2(X) 0
60#define _I3(X) 0
61#define _MI6(x1,x2,x3,x4) IPA_NONE
62#define ipa_is_link_local(x) 0
63#define ipa_from_sa(x) ipa_from_sa4(x)
4f22c981
MM
64#endif
65
05476c4d
OZ
66
67/* This is sloppy hack, it should be detected by configure script */
68/* Linux systems have it defined so this is definition for BSD systems */
69#ifndef s6_addr32
70#define s6_addr32 __u6_addr.__u6_addr32
71#endif
72
73
74static inline ip_addr ipa_from_in4(struct in_addr a)
75{ return ipa_from_u32(ntohl(a.s_addr)); }
76
77static inline ip_addr ipa_from_in6(struct in6_addr a)
78{ return _MI6(ntohl(a.s6_addr32[0]), ntohl(a.s6_addr32[1]), ntohl(a.s6_addr32[2]), ntohl(a.s6_addr32[3])); }
79
80static inline ip_addr ipa_from_sa4(sockaddr *sa)
81{ return ipa_from_in4(((struct sockaddr_in *) sa)->sin_addr); }
82
83static inline ip_addr ipa_from_sa6(sockaddr *sa)
84{ return ipa_from_in6(((struct sockaddr_in6 *) sa)->sin6_addr); }
85
86static inline struct in_addr ipa_to_in4(ip_addr a)
87{ return (struct in_addr) { htonl(ipa_to_u32(a)) }; }
88
89static inline struct in6_addr ipa_to_in6(ip_addr a)
90{ return (struct in6_addr) { .s6_addr32 = { htonl(_I0(a)), htonl(_I1(a)), htonl(_I2(a)), htonl(_I3(a)) } }; }
91
92void sockaddr_fill(sockaddr *sa, int af, ip_addr a, struct iface *ifa, uint port);
93int sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *port);
94
95
4daf03e5
MM
96#ifndef SUN_LEN
97#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen ((ptr)->sun_path))
98#endif
99
05476c4d
OZ
100volatile int async_config_flag;
101volatile int async_dump_flag;
102volatile int async_shutdown_flag;
b93abffa 103
b5d9ee5c
MM
104void io_init(void);
105void io_loop(void);
05476c4d 106int sk_open_unix(struct birdsock *s, char *name);
a0c37b45 107void *tracked_fopen(struct pool *, char *name, char *mode);
41c8976e
OF
108void test_old_bird(char *path);
109
af847acc 110
7e5f5ffd
MM
111/* krt.c bits */
112
113void krt_io_init(void);
114
a0c37b45
MM
115/* log.c */
116
4e398e34 117void main_thread_init(void);
a0c37b45 118void log_init_debug(char *); /* Initialize debug dump to given file (NULL=stderr, ""=off) */
44d4ab7a 119void log_switch(int debug, list *l, char *); /* Use l=NULL for initial switch */
a0c37b45
MM
120
121struct log_config {
122 node n;
123 unsigned int mask; /* Classes to log */
124 void *fh; /* FILE to log to, NULL=syslog */
125 int terminal_flag;
126};
127
b5d9ee5c 128#endif