Skip to content

Instantly share code, notes, and snippets.

@dvdhrm
Created January 11, 2017 12:03
Show Gist options
  • Save dvdhrm/0d9d0173e50888f497dbb0b30b265a94 to your computer and use it in GitHub Desktop.
Save dvdhrm/0d9d0173e50888f497dbb0b30b265a94 to your computer and use it in GitHub Desktop.
#pragma once
/*
* IPv6 Neighbor Discovery Protocol
*
* This is the public header of the n-ndp library, implementing IPv6 Neighbor
* Discovery Protocol as described in RFC-4861. This header defines the public
* API and all entry points of n-ndp.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <net/ethernet.h> /* struct ether_addr */
#include <netinet/in.h> /* struct in6_addr */
#include <stdbool.h>
#include <stdlib.h>
#define N_NDP_IFINDEX_INVALID (0U)
#define N_NDP_IP_INVALID (&(struct in6_addr){})
typedef struct NNdp NNdp;
typedef struct NNdpSlot NNdpSlot;
typedef void (*NNdpFn) (NNdp *ndp, void *userdata, unsigned int event);
enum {
N_NDP_LINK_FLAG_DHCP_MANAGED = (1U << 0),
N_NDP_LINK_FLAG_DHCP_OTHER = (1U << 1),
};
enum {
N_NDP_PREFIX_FLAG_ONLINK = (1U << 0),
N_NDP_PREFIX_FLAG_AUTONOMOUS = (1U << 1),
};
enum {
N_NDP_PREFERENCE_LOW = -1,
N_NDP_PREFERENCE_MEDIUM = 0,
N_NDP_PREFERENCE_HIGH = 1,
};
/* context */
enum {
N_NDP_EVENT_DOWN,
_N_NDP_EVENT_N,
};
int n_ndp_new(NNdp **ndpp);
NNdp *n_ndp_ref(NNdp *ndp);
NNdp *n_ndp_unref(NNdp *ndp);
bool n_ndp_is_running(NNdp *ndp);
void n_ndp_get_fd(NNdp *ndp, int *fdp);
void n_ndp_get_ifindex(NNdp *ndp, unsigned int *ifindexp);
void n_ndp_get_mac(NNdp *ndp, const uint8_t **macp, size_t *n_macp);
void n_ndp_get_ip(NNdp *ndp, struct in6_addr *ipp);
int n_ndp_set_ifindex(NNdp *ndp, unsigned int ifindex);
int n_ndp_set_mac(NNdp *ndp, const uint8_t *mac, size_t n_mac);
int n_ndp_set_ip(NNdp *ndp, const struct in6_addr *ip);
int n_ndp_dispatch(NNdp *ndp);
int n_ndp_listen_routers(NNdp *ndp, NNdpSlot **slotp, NNdpFn fn, void *userdata);
int n_ndp_probe_neighbor(NNdp *ndp, NNdpSlot **slotp, NNdpFn fn, void *userdata, const uint8_t *mac, size_t n_mac, const struct in6_addr *ip);
int n_ndp_advertise_router(NNdp *ndp, NNdpLink *link, NNdpRouter *router);
int n_ndp_announce_prefix(NNdp *ndp, NNdpPrefix *prefix);
int n_ndp_announce_route(NNdp *ndp, NNdpRoute *route);
void n_ndp_discontinue_prefix(NNdp *ndp, NNdpPrefix *prefix);
void n_ndp_discontinue_route(NNdp *ndp, NNdpRoute *route);
/* slot */
NNdpSlot *n_ndp_slot_free(NNdpSlot *slot);
/* link */
int n_ndp_link_new(NNdpLink **linkp);
NNdpLink *n_ndp_link_ref(NNdpLink *link);
NNdpLink *n_ndp_link_unref(NNdpLink *link);
void n_ndp_link_get_flags(NNdpLink *link, unsigned int *flagsp);
void n_ndp_link_get_hop_limit(NNdpLink *link, uint8_t *limitp);
void n_ndp_link_get_reachable_time(NNdpLink *link, uint32_t *timep);
void n_ndp_link_get_retrans_time(NNdpLink *link, uint32_t *time);
void n_ndp_link_get_mtu(NNdpLink *link, uint32_t *mtup);
int n_ndp_link_set_flags(NNdpLink *link, unsigned int flags);
int n_ndp_link_set_hop_limit(NNdpLink *link, uint8_t limit);
int n_ndp_link_set_reachable_time(NNdpLink *link, uint32_t time);
int n_ndp_link_set_retrans_time(NNdpLink *link, uint32_t time);
int n_ndp_link_set_mtu(NNdpLink *link, uint32_t mtu);
/* router */
int n_ndp_router_set_mac(NNdpRouter *router, const struct ether_addr *mac);
int n_ndp_router_set_ip(NNdpRouter *router, const struct in6_addr *ip);
int n_ndp_router_set_lifetime(NNdpRouter *router, uint16_t time);
int n_ndp_router_set_preference(NNdpRouter *router, int preference);
/* prefix */
int n_ndp_prefix_set_prefix(NNdpPrefix *prefix, const struct in6_addr *prefix, uint8_t length);
int n_ndp_prefix_set_valid_lifetime(NNdpPrefix *prefix, uint32_t time);
int n_ndp_prefix_set_preferred_lifetime(NNdpPrefix *prefix, uint32_t time);
int n_ndp_prefix_set_flags(NNdpPrefix *prefix, unsigned int flags);
/* route */
int n_ndp_route_set_prefix(NNdpRoute *route, const struct in6_addr *prefix, uint8_t length);
int n_ndp_route_set_lifetime(NNdpRoute *route, uint32_t time);
int n_ndp_route_set_preference(NNdpRoute *route, int preference);
/* helpers */
static inline void n_ndp_unrefp(NNdp **ndp) {
if (*ndp)
n_ndp_unref(*ndp);
}
static inline void n_ndp_link_unrefp(NNdpLink **link) {
if (*link)
n_ndp_link_unref(*link);
}
#ifdef __cplusplus
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment