Blame include/ndp.h

Packit 858112
/*
Packit 858112
 *   ndp.h - Neighbour discovery library
Packit 858112
 *   Copyright (C) 2013-2015 Jiri Pirko <jiri@resnulli.us>
Packit 858112
 *
Packit 858112
 *   This library is free software; you can redistribute it and/or
Packit 858112
 *   modify it under the terms of the GNU Lesser General Public
Packit 858112
 *   License as published by the Free Software Foundation; either
Packit 858112
 *   version 2.1 of the License, or (at your option) any later version.
Packit 858112
 *
Packit 858112
 *   This library is distributed in the hope that it will be useful,
Packit 858112
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 858112
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 858112
 *   Lesser General Public License for more details.
Packit 858112
 *
Packit 858112
 *   You should have received a copy of the GNU Lesser General Public
Packit 858112
 *   License along with this library; if not, write to the Free Software
Packit 858112
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 858112
 */
Packit 858112
Packit 858112
#ifndef _NDP_H_
Packit 858112
#define _NDP_H_
Packit 858112
Packit 858112
#include <stdarg.h>
Packit 858112
#include <stdbool.h>
Packit 858112
#include <netinet/in.h>
Packit 858112
Packit 858112
#ifdef __cplusplus
Packit 858112
extern "C" {
Packit 858112
#endif
Packit 858112
Packit 858112
struct ndp;
Packit 858112
Packit 858112
void ndp_set_log_fn(struct ndp *ndp,
Packit 858112
		    void (*log_fn)(struct ndp *ndp, int priority,
Packit 858112
				   const char *file, int line, const char *fn,
Packit 858112
				   const char *format, va_list args));
Packit 858112
int ndp_get_log_priority(struct ndp *ndp);
Packit 858112
void ndp_set_log_priority(struct ndp *ndp, int priority);
Packit 858112
Packit 858112
struct ndp_msg;
Packit 858112
struct ndp_msgrs;
Packit 858112
struct ndp_msgra;
Packit 858112
struct ndp_msgns;
Packit 858112
struct ndp_msgna;
Packit 858112
struct ndp_msgr;
Packit 858112
Packit 858112
enum ndp_msg_type {
Packit 858112
	NDP_MSG_RS, /* Router Solicitation */
Packit 858112
	NDP_MSG_RA, /* Router Advertisement */
Packit 858112
	NDP_MSG_NS, /* Neighbor Solicitation */
Packit 858112
	NDP_MSG_NA, /* Neighbor Advertisement */
Packit 858112
	NDP_MSG_R, /* Redirect */
Packit 858112
	NDP_MSG_ALL, /* Matches all */
Packit 858112
};
Packit 858112
Packit 858112
#define ND_OPT_NORMAL       0x0000    /* default, no change to ND message */
Packit 858112
#define ND_OPT_NA_UNSOL     0x0001    /* Unsolicited Neighbour Advertisement */
Packit 858112
Packit 858112
enum ndp_route_preference {
Packit 858112
	NDP_ROUTE_PREF_LOW = 3,
Packit 858112
	NDP_ROUTE_PREF_MEDIUM = 0,
Packit 858112
	NDP_ROUTE_PREF_HIGH = 1,
Packit 858112
};
Packit 858112
Packit 858112
int ndp_msg_new(struct ndp_msg **p_msg, enum ndp_msg_type msg_type);
Packit 858112
void ndp_msg_destroy(struct ndp_msg *msg);
Packit 858112
void *ndp_msg_payload(struct ndp_msg *msg);
Packit 858112
size_t ndp_msg_payload_maxlen(struct ndp_msg *msg);
Packit 858112
size_t ndp_msg_payload_len(struct ndp_msg *msg);
Packit 858112
void ndp_msg_payload_len_set(struct ndp_msg *msg, size_t len);
Packit 858112
void *ndp_msg_payload_opts(struct ndp_msg *msg);
Packit 858112
size_t ndp_msg_payload_opts_len(struct ndp_msg *msg);
Packit 858112
struct ndp_msgrs *ndp_msgrs(struct ndp_msg *msg);
Packit 858112
struct ndp_msgra *ndp_msgra(struct ndp_msg *msg);
Packit 858112
struct ndp_msgns *ndp_msgns(struct ndp_msg *msg);
Packit 858112
struct ndp_msgna *ndp_msgna(struct ndp_msg *msg);
Packit 858112
struct ndp_msgr *ndp_msgr(struct ndp_msg *msg);
Packit 858112
enum ndp_msg_type ndp_msg_type(struct ndp_msg *msg);
Packit 858112
struct in6_addr *ndp_msg_addrto(struct ndp_msg *msg);
Packit 858112
uint32_t ndp_msg_ifindex(struct ndp_msg *msg);
Packit 858112
void ndp_msg_ifindex_set(struct ndp_msg *msg, uint32_t ifindex);
Packit Bot 909ea9
void ndp_msg_target_set(struct ndp_msg *msg, struct in6_addr *target);
Packit Bot 021ea6
void ndp_msg_dest_set(struct ndp_msg *msg, struct in6_addr *dest);
Packit Bot 909ea9
void ndp_msg_opt_set(struct ndp_msg *msg);
Packit 858112
int ndp_msg_send(struct ndp *ndp, struct ndp_msg *msg);
Packit 858112
int ndp_msg_send_with_flags(struct ndp *ndp, struct ndp_msg *msg, uint8_t flags);
Packit 858112
Packit 858112
uint8_t ndp_msgra_curhoplimit(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_curhoplimit_set(struct ndp_msgra *msgra, uint8_t curhoplimit);
Packit 858112
bool ndp_msgra_flag_managed(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_flag_managed_set(struct ndp_msgra *msgra, bool flag_managed);
Packit 858112
bool ndp_msgra_flag_other(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_flag_other_set(struct ndp_msgra *msgra, bool flag_other);
Packit 858112
bool ndp_msgra_flag_home_agent(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_flag_home_agent_set(struct ndp_msgra *msgra,
Packit 858112
				   bool flag_home_agent);
Packit 858112
enum ndp_route_preference ndp_msgra_route_preference(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_route_preference_set(struct ndp_msgra *msgra,
Packit 858112
				    enum ndp_route_preference pref);
Packit 858112
uint16_t ndp_msgra_router_lifetime(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_router_lifetime_set(struct ndp_msgra *msgra,
Packit 858112
				   uint16_t router_lifetime);
Packit 858112
uint32_t ndp_msgra_reachable_time(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_reachable_time_set(struct ndp_msgra *msgra,
Packit 858112
				  uint32_t reachable_time);
Packit 858112
uint32_t ndp_msgra_retransmit_time(struct ndp_msgra *msgra);
Packit 858112
void ndp_msgra_retransmit_time_set(struct ndp_msgra *msgra,
Packit 858112
				   uint32_t retransmit_time);
Packit 858112
Packit 858112
bool ndp_msgna_flag_router(struct ndp_msgna *msgna);
Packit 858112
void ndp_msgna_flag_router_set(struct ndp_msgna *msgna, bool flag_router);
Packit 858112
bool ndp_msgna_flag_solicited(struct ndp_msgna *msgna);
Packit 858112
void ndp_msgna_flag_solicited_set(struct ndp_msgna *msgna,
Packit 858112
				  bool flag_solicited);
Packit 858112
bool ndp_msgna_flag_override(struct ndp_msgna *msgna);
Packit 858112
void ndp_msgna_flag_override_set(struct ndp_msgna *msgna, bool flag_override);
Packit 858112
Packit 858112
enum ndp_msg_opt_type {
Packit 858112
	NDP_MSG_OPT_SLLADDR, /* Source Link-layer Address */
Packit 858112
	NDP_MSG_OPT_TLLADDR, /* Target Link-layer Address */
Packit 858112
	NDP_MSG_OPT_PREFIX, /* Prefix Information */
Packit 858112
	NDP_MSG_OPT_REDIR, /* Redirected Header */
Packit 858112
	NDP_MSG_OPT_MTU, /* MTU */
Packit 858112
	NDP_MSG_OPT_ROUTE, /* Route Information */
Packit 858112
	NDP_MSG_OPT_RDNSS, /* Recursive DNS Server */
Packit 858112
	NDP_MSG_OPT_DNSSL, /* DNS Search List */
Packit 858112
};
Packit 858112
Packit 858112
int ndp_msg_next_opt_offset(struct ndp_msg *msg, int offset,
Packit 858112
			    enum ndp_msg_opt_type opt_type);
Packit 858112
Packit 858112
#define ndp_msg_opt_for_each_offset(offset, msg, type)			\
Packit 858112
	for (offset = ndp_msg_next_opt_offset(msg, -1, type);		\
Packit 858112
	     offset != -1;						\
Packit 858112
	     offset = ndp_msg_next_opt_offset(msg, offset, type))
Packit 858112
Packit 858112
unsigned char *ndp_msg_opt_slladdr(struct ndp_msg *msg, int offset);
Packit 858112
size_t ndp_msg_opt_slladdr_len(struct ndp_msg *msg, int offset);
Packit 858112
unsigned char *ndp_msg_opt_tlladdr(struct ndp_msg *msg, int offset);
Packit 858112
size_t ndp_msg_opt_tlladdr_len(struct ndp_msg *msg, int offset);
Packit 858112
Packit 858112
struct in6_addr *ndp_msg_opt_prefix(struct ndp_msg *msg, int offset);
Packit 858112
uint8_t ndp_msg_opt_prefix_len(struct ndp_msg *msg, int offset);
Packit 858112
uint32_t ndp_msg_opt_prefix_valid_time(struct ndp_msg *msg, int offset);
Packit 858112
uint32_t ndp_msg_opt_prefix_preferred_time(struct ndp_msg *msg, int offset);
Packit 858112
bool ndp_msg_opt_prefix_flag_on_link(struct ndp_msg *msg, int offset);
Packit 858112
bool ndp_msg_opt_prefix_flag_auto_addr_conf(struct ndp_msg *msg, int offset);
Packit 858112
bool ndp_msg_opt_prefix_flag_router_addr(struct ndp_msg *msg, int offset);
Packit 858112
Packit 858112
uint32_t ndp_msg_opt_mtu(struct ndp_msg *msg, int offset);
Packit 858112
Packit 858112
struct in6_addr *ndp_msg_opt_route_prefix(struct ndp_msg *msg, int offset);
Packit 858112
uint8_t ndp_msg_opt_route_prefix_len(struct ndp_msg *msg, int offset);
Packit 858112
uint32_t ndp_msg_opt_route_lifetime(struct ndp_msg *msg, int offset);
Packit 858112
enum ndp_route_preference
Packit 858112
ndp_msg_opt_route_preference(struct ndp_msg *msg, int offset);
Packit 858112
Packit 858112
uint32_t ndp_msg_opt_rdnss_lifetime(struct ndp_msg *msg, int offset);
Packit 858112
struct in6_addr *ndp_msg_opt_rdnss_addr(struct ndp_msg *msg, int offset,
Packit 858112
					int addr_index);
Packit 858112
Packit 858112
#define ndp_msg_opt_rdnss_for_each_addr(addr, addr_index, msg, offset)	\
Packit 858112
	for (addr_index = 0,						\
Packit 858112
	     addr = ndp_msg_opt_rdnss_addr(msg, offset, addr_index);	\
Packit 858112
	     addr;							\
Packit 858112
	     addr = ndp_msg_opt_rdnss_addr(msg, offset, ++addr_index))
Packit 858112
Packit 858112
uint32_t ndp_msg_opt_dnssl_lifetime(struct ndp_msg *msg, int offset);
Packit 858112
char *ndp_msg_opt_dnssl_domain(struct ndp_msg *msg, int offset,
Packit 858112
			       int domain_index);
Packit 858112
Packit 858112
#define ndp_msg_opt_dnssl_for_each_domain(domain, domain_index, msg, offset)	\
Packit 858112
	for (domain_index = 0,							\
Packit 858112
	     domain = ndp_msg_opt_dnssl_domain(msg, offset, domain_index);	\
Packit 858112
	     domain;								\
Packit 858112
	     domain = ndp_msg_opt_dnssl_domain(msg, offset, ++domain_index))
Packit 858112
Packit 858112
typedef int (*ndp_msgrcv_handler_func_t)(struct ndp *ndp, struct ndp_msg *msg,
Packit 858112
					 void *priv);
Packit 858112
int ndp_msgrcv_handler_register(struct ndp *ndp, ndp_msgrcv_handler_func_t func,
Packit 858112
				enum ndp_msg_type msg_type, uint32_t ifindex,
Packit 858112
				void *priv);
Packit 858112
void ndp_msgrcv_handler_unregister(struct ndp *ndp, ndp_msgrcv_handler_func_t func,
Packit 858112
				   enum ndp_msg_type msg_type, uint32_t ifindex,
Packit 858112
				   void *priv);
Packit 858112
Packit 858112
int ndp_get_eventfd(struct ndp *ndp);
Packit 858112
int ndp_call_eventfd_handler(struct ndp *ndp);
Packit 858112
int ndp_callall_eventfd_handler(struct ndp *ndp);
Packit 858112
Packit 858112
int ndp_open(struct ndp **p_ndp);
Packit 858112
void ndp_close(struct ndp *ndp);
Packit 858112
Packit 858112
Packit 858112
#ifdef __cplusplus
Packit 858112
} /* extern "C" */
Packit 858112
#endif
Packit 858112
Packit 858112
#endif /* _NDP_H_ */