#include "uloop.h"
#include "list.h"
+#include "relayd.h"
-#define DEBUG
-#ifdef DEBUG
-#define DPRINTF(level, ...) if (debug >= level) fprintf(stderr, __VA_ARGS__);
-#else
-#define DPRINTF(...) do {} while(0)
-#endif
-
-#ifndef __packed
-#define __packed __attribute__((packed))
-#endif
-
-#define __uc(c) ((unsigned char *)(c))
-
-#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
-#define MAC_BUF(_c) __uc(_c)[0], __uc(_c)[1], __uc(_c)[2], __uc(_c)[3], __uc(_c)[4], __uc(_c)[5]
-
-#define IP_FMT "%d.%d.%d.%d"
-#define IP_BUF(_c) __uc(_c)[0], __uc(_c)[1], __uc(_c)[2], __uc(_c)[3]
+LIST_HEAD(interfaces);
+int debug;
-#define DUMMY_IP ((uint8_t *) "\x01\x01\x01\x01")
-
-#define DHCP_FLAG_BROADCAST (1 << 15)
-
-struct relayd_interface {
- struct list_head list;
- struct uloop_fd fd;
- struct uloop_fd bcast_fd;
- struct sockaddr_ll sll;
- struct sockaddr_ll bcast_sll;
- char ifname[IFNAMSIZ];
- struct list_head hosts;
- uint8_t src_ip[4];
- bool managed;
-};
-
-struct relayd_host {
- struct list_head list;
- struct relayd_interface *rif;
- uint8_t lladdr[ETH_ALEN];
- uint8_t ipaddr[4];
- struct uloop_timeout timeout;
- int cleanup_pending;
-};
-
-struct arp_packet {
- struct ether_header eth;
- struct ether_arp arp;
-} __packed;
-
-struct ip_packet {
- struct ether_header eth;
- struct iphdr iph;
-} __packed;
-
-struct dhcp_header {
- uint8_t op, htype, hlen, hops;
- uint32_t xit;
- uint16_t secs, flags;
- struct in_addr ciaddr, yiaddr, siaddr, giaddr;
- unsigned char chaddr[16];
- unsigned char sname[64];
- unsigned char file[128];
-} __packed;
-
-struct rtnl_req {
- struct nlmsghdr nl;
- struct rtmsg rt;
-};
-
-static int debug;
-static LIST_HEAD(interfaces);
static int host_timeout;
static int inet_sock;
static int forward_bcast;