]> git.ipfire.org Git - thirdparty/bird.git/blame - sysdep/unix/unix.h
BIRD coding conventions
[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;
c68ba7d0 17struct rfile;
a0c37b45 18
4c9dd1e4
MM
19/* main.c */
20
44d4ab7a 21extern char *bird_name;
4c9dd1e4
MM
22void async_config(void);
23void async_dump(void);
f4aabcee 24void async_shutdown(void);
a92cf57d 25void cmd_check_config(char *name);
3e405fb1 26void cmd_reconfig(char *name, int type, uint timeout);
a92cf57d
OZ
27void cmd_reconfig_confirm(void);
28void cmd_reconfig_undo(void);
e81b440f 29void cmd_shutdown(void);
4c9dd1e4 30
8bcb5fb1 31#define UNIX_DEFAULT_CONFIGURE_TIMEOUT 300
a92cf57d 32
8bcb5fb1
OZ
33#define UNIX_DEFAULT_LATENCY_LIMIT (1 S_)
34#define UNIX_DEFAULT_WATCHDOG_WARNING (5 S_)
05476c4d 35
b5d9ee5c
MM
36/* io.c */
37
05476c4d
OZ
38#define ERR(c) do { s->err = c; return -1; } while (0)
39#define ERR2(c) do { s->err = c; goto err; } while (0)
40#define ERR_MSG(c) do { errno = 0; s->err = c; return -1; } while (0)
41
42
43#define SOCKADDR_SIZE 32
44
45typedef struct sockaddr_bird {
46 struct sockaddr sa;
47 char padding[SOCKADDR_SIZE - sizeof(struct sockaddr)];
48} sockaddr;
49
4c9dd1e4 50
05476c4d
OZ
51
52/* This is sloppy hack, it should be detected by configure script */
53/* Linux systems have it defined so this is definition for BSD systems */
54#ifndef s6_addr32
55#define s6_addr32 __u6_addr.__u6_addr32
56#endif
57
58
59static inline ip_addr ipa_from_in4(struct in_addr a)
60{ return ipa_from_u32(ntohl(a.s_addr)); }
61
62static inline ip_addr ipa_from_in6(struct in6_addr a)
88a183c6 63{ 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
64
65static inline ip_addr ipa_from_sa4(sockaddr *sa)
66{ return ipa_from_in4(((struct sockaddr_in *) sa)->sin_addr); }
67
68static inline ip_addr ipa_from_sa6(sockaddr *sa)
69{ return ipa_from_in6(((struct sockaddr_in6 *) sa)->sin6_addr); }
70
d7661fbe
JMM
71static inline ip_addr ipa_from_sa(sockaddr *sa)
72{
73 switch (sa->sa.sa_family)
74 {
75 case AF_INET: return ipa_from_sa4(sa);
76 case AF_INET6: return ipa_from_sa6(sa);
77 default: return IPA_NONE;
78 }
79}
80
05476c4d
OZ
81static inline struct in_addr ipa_to_in4(ip_addr a)
82{ return (struct in_addr) { htonl(ipa_to_u32(a)) }; }
83
153f02da
OZ
84static inline struct in_addr ip4_to_in4(ip4_addr a)
85{ return (struct in_addr) { htonl(ip4_to_u32(a)) }; }
86
05476c4d
OZ
87static inline struct in6_addr ipa_to_in6(ip_addr a)
88{ return (struct in6_addr) { .s6_addr32 = { htonl(_I0(a)), htonl(_I1(a)), htonl(_I2(a)), htonl(_I3(a)) } }; }
89
90void sockaddr_fill(sockaddr *sa, int af, ip_addr a, struct iface *ifa, uint port);
91int sockaddr_read(sockaddr *sa, int af, ip_addr *a, struct iface **ifa, uint *port);
92
93
4daf03e5
MM
94#ifndef SUN_LEN
95#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) + strlen ((ptr)->sun_path))
96#endif
97
7152e5ef
JMM
98extern volatile int async_config_flag;
99extern volatile int async_dump_flag;
100extern volatile int async_shutdown_flag;
b93abffa 101
b5d9ee5c
MM
102void io_init(void);
103void io_loop(void);
8bcb5fb1 104void io_log_dump(void);
05476c4d 105int sk_open_unix(struct birdsock *s, char *name);
c68ba7d0
OZ
106struct rfile *rf_open(struct pool *, char *name, char *mode);
107void *rf_file(struct rfile *f);
108int rf_fileno(struct rfile *f);
41c8976e
OF
109void test_old_bird(char *path);
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) */
3fda08e4 119void log_switch(int initial, list *l, char *);
a0c37b45
MM
120
121struct log_config {
122 node n;
ae80a2de 123 uint mask; /* Classes to log */
a0c37b45 124 void *fh; /* FILE to log to, NULL=syslog */
6712e772
OZ
125 struct rfile *rf; /* Resource for log file */
126 char *filename; /* Log filename */
127 char *backup; /* Secondary filename (for log rotation) */
128 off_t pos; /* Position/size of current log */
129 off_t limit; /* Log size limit */
a0c37b45
MM
130 int terminal_flag;
131};
132
b5d9ee5c 133#endif