Statistics
| Branch: | Revision:

iof-bird-daemon / sysdep / unix / unix.h @ 153f02da

History | View | Annotate | Download (3.29 KB)

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