#ifndef _DHCPD_H_
#define _DHCPD_H_
#include <sys/queue.h>
#define DHCRELAY6_USER "_dhcp"
#define CHADDR_SIZE 16
struct packet_ctx {
int pc_sd;
uint8_t pc_htype;
uint8_t pc_hlen;
uint8_t pc_smac[CHADDR_SIZE];
uint8_t pc_dmac[CHADDR_SIZE];
uint16_t pc_ethertype;
struct sockaddr_storage pc_srcorig;
struct sockaddr_storage pc_src;
struct sockaddr_storage pc_dst;
uint8_t *pc_raidata;
size_t pc_raidatalen;
uint32_t pc_enterpriseno;
uint8_t *pc_remote;
size_t pc_remotelen;
};
struct hardware {
u_int8_t htype;
u_int8_t hlen;
u_int8_t haddr[CHADDR_SIZE];
};
enum dhcp_relay_mode {
DRM_UNKNOWN,
DRM_LAYER2,
DRM_LAYER3,
};
struct interface_info {
struct hardware hw_address;
struct in_addr primary_address;
char name[IFNAMSIZ];
int rfdesc;
int wfdesc;
unsigned char *rbuf;
size_t rbuf_max;
size_t rbuf_offset;
size_t rbuf_len;
struct ifreq ifr;
int noifmedia;
int errors;
int dead;
uint16_t index;
int ipv6;
int gipv6;
struct in6_addr linklocal;
TAILQ_ENTRY(interface_info) entry;
};
TAILQ_HEAD(intfq, interface_info);
struct timeout {
struct timeout *next;
time_t when;
void (*func)(void *);
void *what;
};
struct protocol {
struct protocol *next;
int fd;
void (*handler)(struct protocol *);
void *local;
};
struct server_list {
struct interface_info *intf;
struct sockaddr_storage to;
int fd;
int siteglobaladdr;
TAILQ_ENTRY(server_list) entry;
};
TAILQ_HEAD(serverq, server_list);
int if_register_bpf(struct interface_info *);
void if_register_send(struct interface_info *);
void if_register_receive(struct interface_info *);
ssize_t send_packet(struct interface_info *,
void *, size_t, struct packet_ctx *);
ssize_t receive_packet(struct interface_info *, unsigned char *, size_t,
struct packet_ctx *);
extern void (*bootp_packet_handler)(struct interface_info *,
void *, size_t, struct packet_ctx *);
void setup_iflist(void);
struct interface_info *iflist_getbyname(const char *);
struct interface_info *iflist_getbyindex(unsigned int);
struct interface_info *iflist_getbyaddr6(struct in6_addr *);
struct interface_info *register_interface(const char *,
void (*)(struct protocol *));
void dispatch(void);
void got_one(struct protocol *);
void add_protocol(char *, int, void (*)(struct protocol *), void *);
void remove_protocol(struct protocol *);
void assemble_hw_header(unsigned char *, int *, struct packet_ctx *);
void assemble_udp_ip6_header(unsigned char *, int *, struct packet_ctx *,
unsigned char *, int);
ssize_t decode_hw_header(unsigned char *, int, struct packet_ctx *);
ssize_t decode_udp_ip6_header(unsigned char *, int, struct packet_ctx *,
size_t, u_int16_t);
const char *v6addr2str(struct in6_addr *);
extern struct intfq intflist;
extern struct serverq svlist;
extern time_t cur_time;
static inline struct sockaddr_in6 *
ss2sin6(struct sockaddr_storage *ss)
{
return ((struct sockaddr_in6 *)ss);
}
#endif