diff options
Diffstat (limited to 'net.h')
-rw-r--r-- | net.h | 114 |
1 files changed, 46 insertions, 68 deletions
@@ -1,6 +1,6 @@ /* * dhcpcd - DHCP client daemon - * Copyright 2006-2008 Roy Marples <roy@marples.name> + * Copyright (c) 2006-2010 Roy Marples <roy@marples.name> * All rights reserved * Redistribution and use in source and binary forms, with or without @@ -39,6 +39,8 @@ #include <limits.h> #include "config.h" +#include "dhcp.h" +#include "dhcpcd.h" #ifndef DUID_LEN # define DUID_LEN 128 + 2 @@ -57,7 +59,6 @@ # define ARPHRD_INFINIBAND 32 #endif -#define HWADDR_LEN 20 /* Work out if we have a private address or not * 10/8 @@ -65,9 +66,9 @@ * 192.168/16 */ #ifndef IN_PRIVATE -# define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \ - ((addr & 0xfff00000) == 0xac100000) || \ - ((addr & IN_CLASSB_NET) == 0xc0a80000)) +# define IN_PRIVATE(addr) (((addr & IN_CLASSA_NET) == 0x0a000000) || \ + ((addr & 0xfff00000) == 0xac100000) || \ + ((addr & IN_CLASSB_NET) == 0xc0a80000)) #endif #define LINKLOCAL_ADDR 0xa9fe0000 @@ -78,51 +79,24 @@ # define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR) #endif -/* There is an argument that this should be converted to an STAIL using - * queue(3). However, that isn't readily available on all libc's that - * dhcpcd works on. The only benefit of STAILQ over this is the ability to - * quickly loop backwards through the list - currently we reverse the list - * and then move through it forwards. This isn't that much of a big deal - * though as the norm is to just have one default route, and an IPV4LL route. - * You can (and do) get more routes in the DHCP message, but not enough to - * really warrant a change to STAIL queue for performance reasons. */ struct rt { struct in_addr dest; struct in_addr net; struct in_addr gate; + const struct interface *iface; struct rt *next; }; -struct interface -{ - char name[IF_NAMESIZE]; - sa_family_t family; - unsigned char hwaddr[HWADDR_LEN]; - size_t hwlen; - int arpable; - - int raw_fd; - int udp_fd; - int arp_fd; - int link_fd; - size_t buffer_size, buffer_len, buffer_pos; - unsigned char *buffer; - - struct in_addr addr; - struct in_addr net; - struct rt *routes; - - char leasefile[PATH_MAX]; - time_t start_uptime; - - unsigned char *clientid; -}; +extern int socket_afnet; uint32_t get_netmask(uint32_t); char *hwaddr_ntoa(const unsigned char *, size_t); size_t hwaddr_aton(unsigned char *, const char *); -struct interface *read_interface(const char *, int); +int getifssid(const char *, char *); +struct interface *init_interface(const char *); +struct interface *discover_interfaces(int, char * const *); +void free_interface(struct interface *); int do_mtu(const char *, short int); #define get_mtu(iface) do_mtu(iface, 0) #define set_mtu(iface, mtu) do_mtu(iface, mtu) @@ -130,48 +104,52 @@ int do_mtu(const char *, short int); int inet_ntocidr(struct in_addr); int inet_cidrtoaddr(int, struct in_addr *); -int up_interface(const char *); -int do_interface(const char *, unsigned char *, size_t *, - struct in_addr *, struct in_addr *, int); -int if_address(const char *, const struct in_addr *, const struct in_addr *, - const struct in_addr *, int); -#define add_address(ifname, addr, net, brd) \ - if_address(ifname, addr, net, brd, 1) -#define del_address(ifname, addr, net) \ - if_address(ifname, addr, net, NULL, -1) -#define has_address(ifname, addr, net) \ - do_interface(ifname, NULL, NULL, addr, net, 0) -#define get_address(ifname, addr, net) \ - do_interface(ifname, NULL, NULL, addr, net, 1) - -int if_route(const struct interface *, - const struct in_addr *,const struct in_addr *, - const struct in_addr *, int, int); -#define add_route(iface, dest, mask, gate, metric) \ +int up_interface(struct interface *); +int if_conf(struct interface *); +int if_init(struct interface *); + +int do_address(const char *, + struct in_addr *, struct in_addr *, struct in_addr *, int); +int if_address(const struct interface *, + const struct in_addr *, const struct in_addr *, + const struct in_addr *, int); +#define add_address(iface, addr, net, brd) \ + if_address(iface, addr, net, brd, 1) +#define del_address(iface, addr, net) \ + if_address(iface, addr, net, NULL, -1) +#define has_address(iface, addr, net) \ + do_address(iface, addr, net, NULL, 0) +#define get_address(iface, addr, net, dst) \ + do_address(iface, addr, net, dst, 1) + +int if_route(const struct interface *, const struct in_addr *, + const struct in_addr *, const struct in_addr *, int, int); +#define add_route(iface, dest, mask, gate, metric) \ if_route(iface, dest, mask, gate, metric, 1) -#define change_route(iface, dest, mask, gate, metric) \ +#define change_route(iface, dest, mask, gate, metric) \ if_route(iface, dest, mask, gate, metric, 0) -#define del_route(iface, dest, mask, gate, metric) \ +#define del_route(iface, dest, mask, gate, metric) \ if_route(iface, dest, mask, gate, metric, -1) +#define del_src_route(iface, dest, mask, gate, metric) \ + if_route(iface, dest, mask, gate, metric, -2) void free_routes(struct rt *); int open_udp_socket(struct interface *); -const size_t udp_dhcp_len; +extern const size_t udp_dhcp_len; ssize_t make_udp_packet(uint8_t **, const uint8_t *, size_t, - struct in_addr, struct in_addr); + struct in_addr, struct in_addr); ssize_t get_udp_data(const uint8_t **, const uint8_t *); -int valid_udp_packet(const uint8_t *, size_t); +int valid_udp_packet(const uint8_t *, size_t, struct in_addr *); int open_socket(struct interface *, int); ssize_t send_packet(const struct interface *, struct in_addr, - const uint8_t *, ssize_t); + const uint8_t *, ssize_t); ssize_t send_raw_packet(const struct interface *, int, - const void *, ssize_t); + const void *, ssize_t); ssize_t get_raw_packet(struct interface *, int, void *, ssize_t); -int send_arp(const struct interface *, int, in_addr_t, in_addr_t); - -int open_link_socket(struct interface *); -int link_changed(struct interface *); -int carrier_status(const char *); +int init_sockets(void); +int open_link_socket(void); +int manage_link(int); +int carrier_status(struct interface *); #endif |