From 1ee606df2f4d5bc626cf62e605305bbddcadf58b Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Wed, 11 Aug 2010 12:31:02 +0200 Subject: [PATCH] Move some data structures and definitions to a header file --- Makefile | 2 +- main.c | 73 +++----------------------------------------------- relayd.h | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 71 deletions(-) create mode 100644 relayd.h diff --git a/Makefile b/Makefile index cc8f76f..20149c4 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ relayd: uloop.o main.o $(CC) -o $@ $^ $(LDFLAGS) uloop.c: uloop.h -main.c: uloop.h +main.c: uloop.h relayd.h list.h %.o: %.c $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $^ diff --git a/main.c b/main.c index 8689f32..bd9dea2 100644 --- a/main.c +++ b/main.c @@ -41,78 +41,11 @@ #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; diff --git a/relayd.h b/relayd.h new file mode 100644 index 0000000..0fb38e7 --- /dev/null +++ b/relayd.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2010 Felix Fietkau + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License v2 as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + * + */ +#ifndef __RELAYD_H +#define __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] + +#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; +} __packed; + +struct list_head interfaces; +extern int debug; + +#endif -- 2.11.0