DF-3303 / ip_mroute_common.h
/* shared helpers for ip_mroute PoCs (DF-3302..DF-3306) */ #ifndef IP_MROUTE_COMMON_H #define IP_MROUTE_COMMON_H #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <stdint.h> #include <string.h> /* from sys/net/ip_mroute/ip_mroute.h (kept in sync) */ #define MRT_INIT 100 #define MRT_DONE 101 #define MRT_ADD_VIF 102 #define MRT_DEL_VIF 103 #define MRT_ADD_MFC 104 #define MRT_DEL_MFC 105 #define MRT_VERSION 106 #define MRT_ASSERT 107 #define MRT_API_SUPPORT 109 #define MRT_API_CONFIG 110 #define MRT_ADD_BW_UPCALL 111 #define MRT_DEL_BW_UPCALL 112 #define MAXVIFS 32 typedef u_short vifi_t; #define VIFF_TUNNEL 0x1 #define VIFF_SRCRT 0x2 #define VIFF_REGISTER 0x4 struct vifctl { vifi_t vifc_vifi; u_char vifc_flags; u_char vifc_threshold; u_int vifc_rate_limit; struct in_addr vifc_lcl_addr; struct in_addr vifc_rmt_addr; }; struct mfcctl2 { struct in_addr mfcc_origin; struct in_addr mfcc_mcastgrp; vifi_t mfcc_parent; u_char mfcc_ttls[MAXVIFS]; uint8_t mfcc_flags[MAXVIFS]; struct in_addr mfcc_rp; }; #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) #define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) #define MRT_MFC_RP (1 << 8) #define MRT_MFC_BW_UPCALL (1 << 9) struct bw_data { struct timeval b_time; uint64_t b_packets; uint64_t b_bytes; }; struct bw_upcall { struct in_addr bu_src; struct in_addr bu_dst; uint32_t bu_flags; #define BW_UPCALL_UNIT_PACKETS (1 << 0) #define BW_UPCALL_UNIT_BYTES (1 << 1) #define BW_UPCALL_GEQ (1 << 2) #define BW_UPCALL_LEQ (1 << 3) #define BW_UPCALL_DELETE_ALL (1 << 4) struct bw_data bu_threshold; struct bw_data bu_measured; }; static inline int mrt_init(int fd) { int v = 1; return setsockopt(fd, IPPROTO_IP, MRT_INIT, &v, sizeof(v)); } static inline int mrt_del_vif(int fd, vifi_t vifi) { return setsockopt(fd, IPPROTO_IP, MRT_DEL_VIF, &vifi, sizeof(vifi)); } static inline uint16_t in_cksum_hdr(const struct ip *ip) { /* ones-complement sum over the 20 byte header */ const uint16_t *w = (const uint16_t *)ip; uint32_t sum = 0; int i; for (i = 0; i < 10; i++) sum += w[i]; sum = (sum >> 16) + (sum & 0xffff); sum += (sum >> 16); return (~sum & 0xffff); } #endif |