Move some data structures and definitions to a header file
[project/relayd.git] / relayd.h
1 /*
2  *   Copyright (C) 2010 Felix Fietkau <nbd@openwrt.org>
3  *
4  *   This program is free software; you can redistribute it and/or modify
5  *   it under the terms of the GNU General Public License v2 as published by
6  *   the Free Software Foundation.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *   GNU General Public License for more details.
12  *
13  *   You should have received a copy of the GNU General Public License
14  *   along with this program; if not, write to the Free Software
15  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16  *
17  */
18 #ifndef __RELAYD_H
19 #define __RELAYD_H
20
21 #define DEBUG
22 #ifdef DEBUG
23 #define DPRINTF(level, ...) if (debug >= level) fprintf(stderr, __VA_ARGS__);
24 #else
25 #define DPRINTF(...) do {} while(0)
26 #endif
27
28 #ifndef __packed
29 #define __packed __attribute__((packed))
30 #endif
31
32 #define __uc(c) ((unsigned char *)(c))
33
34 #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
35 #define MAC_BUF(_c) __uc(_c)[0], __uc(_c)[1], __uc(_c)[2], __uc(_c)[3], __uc(_c)[4], __uc(_c)[5]
36
37 #define IP_FMT  "%d.%d.%d.%d"
38 #define IP_BUF(_c) __uc(_c)[0], __uc(_c)[1], __uc(_c)[2], __uc(_c)[3]
39
40 #define DUMMY_IP ((uint8_t *) "\x01\x01\x01\x01")
41
42 #define DHCP_FLAG_BROADCAST     (1 << 15)
43
44 struct relayd_interface {
45         struct list_head list;
46         struct uloop_fd fd;
47         struct uloop_fd bcast_fd;
48         struct sockaddr_ll sll;
49         struct sockaddr_ll bcast_sll;
50         char ifname[IFNAMSIZ];
51         struct list_head hosts;
52         uint8_t src_ip[4];
53         bool managed;
54 };
55
56 struct relayd_host {
57         struct list_head list;
58         struct relayd_interface *rif;
59         uint8_t lladdr[ETH_ALEN];
60         uint8_t ipaddr[4];
61         struct uloop_timeout timeout;
62         int cleanup_pending;
63 };
64
65 struct arp_packet {
66         struct ether_header eth;
67         struct ether_arp arp;
68 } __packed;
69
70 struct ip_packet {
71         struct ether_header eth;
72         struct iphdr iph;
73 } __packed;
74
75 struct dhcp_header {
76         uint8_t op, htype, hlen, hops;
77         uint32_t xit;
78         uint16_t secs, flags;
79         struct in_addr ciaddr, yiaddr, siaddr, giaddr;
80         unsigned char chaddr[16];
81         unsigned char sname[64];
82         unsigned char file[128];
83 } __packed;
84
85 struct rtnl_req {
86         struct nlmsghdr nl;
87         struct rtmsg rt;
88 } __packed;
89
90 struct list_head interfaces;
91 extern int debug;
92
93 #endif