Annotation of embedaddon/pimd/include/openbsd/netinet/ip_mroute.h, revision 1.1
1.1 ! misho 1: /* $OpenBSD: ip_mroute.h,v 1.15 2009/07/13 19:14:29 michele Exp $ */
! 2: /* $NetBSD: ip_mroute.h,v 1.23 2004/04/21 17:49:46 itojun Exp $ */
! 3:
! 4: #ifndef _NETINET_IP_MROUTE_H_
! 5: #define _NETINET_IP_MROUTE_H_
! 6:
! 7: /*
! 8: * Definitions for IP multicast forwarding.
! 9: *
! 10: * Written by David Waitzman, BBN Labs, August 1988.
! 11: * Modified by Steve Deering, Stanford, February 1989.
! 12: * Modified by Ajit Thyagarajan, PARC, August 1993.
! 13: * Modified by Ajit Thyagarajan, PARC, August 1994.
! 14: * Modified by Ahmed Helmy, SGI, June 1996.
! 15: * Modified by Pavlin Radoslavov, ICSI, October 2002.
! 16: *
! 17: * MROUTING Revision: 1.2
! 18: * and PIM-SMv2 and PIM-DM support, advanced API support,
! 19: * bandwidth metering and signaling.
! 20: */
! 21:
! 22: #include <sys/queue.h>
! 23: #include <sys/timeout.h>
! 24:
! 25: /*
! 26: * Multicast Routing set/getsockopt commands.
! 27: */
! 28: #define MRT_INIT 100 /* initialize forwarder */
! 29: #define MRT_DONE 101 /* shut down forwarder */
! 30: #define MRT_ADD_VIF 102 /* create virtual interface */
! 31: #define MRT_DEL_VIF 103 /* delete virtual interface */
! 32: #define MRT_ADD_MFC 104 /* insert forwarding cache entry */
! 33: #define MRT_DEL_MFC 105 /* delete forwarding cache entry */
! 34: #define MRT_VERSION 106 /* get kernel version number */
! 35: #define MRT_ASSERT 107 /* enable assert processing */
! 36: #define MRT_PIM MRT_ASSERT /* enable PIM processing */
! 37: #define MRT_API_SUPPORT 109 /* supported MRT API */
! 38: #define MRT_API_CONFIG 110 /* config MRT API */
! 39: #define MRT_ADD_BW_UPCALL 111 /* create bandwidth monitor */
! 40: #define MRT_DEL_BW_UPCALL 112 /* delete bandwidth monitor */
! 41:
! 42:
! 43: /*
! 44: * Types and macros for handling bitmaps with one bit per virtual interface.
! 45: */
! 46: #define MAXVIFS 32
! 47: typedef u_int32_t vifbitmap_t;
! 48: typedef u_int16_t vifi_t; /* type of a vif index */
! 49:
! 50: #define VIFM_SET(n, m) ((m) |= (1 << (n)))
! 51: #define VIFM_CLR(n, m) ((m) &= ~(1 << (n)))
! 52: #define VIFM_ISSET(n, m) ((m) & (1 << (n)))
! 53: #define VIFM_SETALL(m) ((m) = 0xffffffff)
! 54: #define VIFM_CLRALL(m) ((m) = 0x00000000)
! 55: #define VIFM_COPY(mfrom, mto) ((mto) = (mfrom))
! 56: #define VIFM_SAME(m1, m2) ((m1) == (m2))
! 57:
! 58: #define VIFF_TUNNEL 0x1 /* vif represents a tunnel end-point */
! 59: #define VIFF_SRCRT 0x2 /* tunnel uses IP src routing */
! 60: #define VIFF_REGISTER 0x4 /* used for PIM Register encap/decap */
! 61:
! 62: /*
! 63: * Argument structure for MRT_ADD_VIF.
! 64: * (MRT_DEL_VIF takes a single vifi_t argument.)
! 65: */
! 66: struct vifctl {
! 67: vifi_t vifc_vifi; /* the index of the vif to be added */
! 68: u_int8_t vifc_flags; /* VIFF_ flags defined above */
! 69: u_int8_t vifc_threshold; /* min ttl required to forward on vif */
! 70: u_int32_t vifc_rate_limit; /* ignored */
! 71: struct in_addr vifc_lcl_addr;/* local interface address */
! 72: struct in_addr vifc_rmt_addr;/* remote address (tunnels only) */
! 73: };
! 74:
! 75: /*
! 76: * Argument structure for MRT_ADD_MFC and MRT_DEL_MFC.
! 77: * XXX if you change this, make sure to change struct mfcctl2 as well.
! 78: */
! 79: struct mfcctl {
! 80: struct in_addr mfcc_origin; /* ip origin of mcasts */
! 81: struct in_addr mfcc_mcastgrp; /* multicast group associated */
! 82: vifi_t mfcc_parent; /* incoming vif */
! 83: u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
! 84: };
! 85:
! 86: /*
! 87: * The new argument structure for MRT_ADD_MFC and MRT_DEL_MFC overlays
! 88: * and extends the old struct mfcctl.
! 89: */
! 90: struct mfcctl2 {
! 91: /* the mfcctl fields */
! 92: struct in_addr mfcc_origin; /* ip origin of mcasts */
! 93: struct in_addr mfcc_mcastgrp; /* multicast group associated*/
! 94: vifi_t mfcc_parent; /* incoming vif */
! 95: u_int8_t mfcc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
! 96:
! 97: /* extension fields */
! 98: u_int8_t mfcc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */
! 99: struct in_addr mfcc_rp; /* the RP address */
! 100: };
! 101: /*
! 102: * The advanced-API flags.
! 103: *
! 104: * The MRT_MFC_FLAGS_XXX API flags are also used as flags
! 105: * for the mfcc_flags field.
! 106: */
! 107: #define MRT_MFC_FLAGS_DISABLE_WRONGVIF (1 << 0) /* disable WRONGVIF signals */
! 108: #define MRT_MFC_FLAGS_BORDER_VIF (1 << 1) /* border vif */
! 109: #define MRT_MFC_RP (1 << 8) /* enable RP address */
! 110: #define MRT_MFC_BW_UPCALL (1 << 9) /* enable bw upcalls */
! 111: #define MRT_MFC_FLAGS_ALL (MRT_MFC_FLAGS_DISABLE_WRONGVIF | \
! 112: MRT_MFC_FLAGS_BORDER_VIF)
! 113: #define MRT_API_FLAGS_ALL (MRT_MFC_FLAGS_ALL | \
! 114: MRT_MFC_RP | \
! 115: MRT_MFC_BW_UPCALL)
! 116:
! 117: /*
! 118: * Structure for installing or delivering an upcall if the
! 119: * measured bandwidth is above or below a threshold.
! 120: *
! 121: * User programs (e.g. daemons) may have a need to know when the
! 122: * bandwidth used by some data flow is above or below some threshold.
! 123: * This interface allows the userland to specify the threshold (in
! 124: * bytes and/or packets) and the measurement interval. Flows are
! 125: * all packet with the same source and destination IP address.
! 126: * At the moment the code is only used for multicast destinations
! 127: * but there is nothing that prevents its use for unicast.
! 128: *
! 129: * The measurement interval cannot be shorter than some Tmin (currently, 3s).
! 130: * The threshold is set in packets and/or bytes per_interval.
! 131: *
! 132: * Measurement works as follows:
! 133: *
! 134: * For >= measurements:
! 135: * The first packet marks the start of a measurement interval.
! 136: * During an interval we count packets and bytes, and when we
! 137: * pass the threshold we deliver an upcall and we are done.
! 138: * The first packet after the end of the interval resets the
! 139: * count and restarts the measurement.
! 140: *
! 141: * For <= measurement:
! 142: * We start a timer to fire at the end of the interval, and
! 143: * then for each incoming packet we count packets and bytes.
! 144: * When the timer fires, we compare the value with the threshold,
! 145: * schedule an upcall if we are below, and restart the measurement
! 146: * (reschedule timer and zero counters).
! 147: */
! 148:
! 149: struct bw_data {
! 150: struct timeval b_time;
! 151: u_int64_t b_packets;
! 152: u_int64_t b_bytes;
! 153: };
! 154:
! 155: struct bw_upcall {
! 156: struct in_addr bu_src; /* source address */
! 157: struct in_addr bu_dst; /* destination address */
! 158: u_int32_t bu_flags; /* misc flags (see below) */
! 159: #define BW_UPCALL_UNIT_PACKETS (1 << 0) /* threshold (in packets) */
! 160: #define BW_UPCALL_UNIT_BYTES (1 << 1) /* threshold (in bytes) */
! 161: #define BW_UPCALL_GEQ (1 << 2) /* upcall if bw >= threshold */
! 162: #define BW_UPCALL_LEQ (1 << 3) /* upcall if bw <= threshold */
! 163: #define BW_UPCALL_DELETE_ALL (1 << 4) /* delete all upcalls for s,d*/
! 164: struct bw_data bu_threshold; /* the bw threshold */
! 165: struct bw_data bu_measured; /* the measured bw */
! 166: };
! 167:
! 168: /* max. number of upcalls to deliver together */
! 169: #define BW_UPCALLS_MAX 128
! 170: /* min. threshold time interval for bandwidth measurement */
! 171: #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_SEC 3
! 172: #define BW_UPCALL_THRESHOLD_INTERVAL_MIN_USEC 0
! 173:
! 174: /*
! 175: * Argument structure used by mrouted to get src-grp pkt counts.
! 176: */
! 177: struct sioc_sg_req {
! 178: struct in_addr src;
! 179: struct in_addr grp;
! 180: u_long pktcnt;
! 181: u_long bytecnt;
! 182: u_long wrong_if;
! 183: };
! 184:
! 185: /*
! 186: * Argument structure used by mrouted to get vif pkt counts.
! 187: */
! 188: struct sioc_vif_req {
! 189: vifi_t vifi; /* vif number */
! 190: u_long icount; /* input packet count on vif */
! 191: u_long ocount; /* output packet count on vif */
! 192: u_long ibytes; /* input byte count on vif */
! 193: u_long obytes; /* output byte count on vif */
! 194: };
! 195:
! 196:
! 197: /*
! 198: * The kernel's multicast routing statistics.
! 199: */
! 200: struct mrtstat {
! 201: u_long mrts_mfc_lookups; /* # forw. cache hash table hits */
! 202: u_long mrts_mfc_misses; /* # forw. cache hash table misses */
! 203: u_long mrts_upcalls; /* # calls to mrouted */
! 204: u_long mrts_no_route; /* no route for packet's origin */
! 205: u_long mrts_bad_tunnel; /* malformed tunnel options */
! 206: u_long mrts_cant_tunnel; /* no room for tunnel options */
! 207: u_long mrts_wrong_if; /* arrived on wrong interface */
! 208: u_long mrts_upq_ovflw; /* upcall Q overflow */
! 209: u_long mrts_cache_cleanups; /* # entries with no upcalls */
! 210: u_long mrts_drop_sel; /* pkts dropped selectively */
! 211: u_long mrts_q_overflow; /* pkts dropped - Q overflow */
! 212: u_long mrts_pkt2large; /* pkts dropped - size > BKT SIZE */
! 213: u_long mrts_upq_sockfull; /* upcalls dropped - socket full */
! 214: };
! 215:
! 216:
! 217: #ifdef _KERNEL
! 218:
! 219: /*
! 220: * The kernel's virtual-interface structure.
! 221: */
! 222: struct vif {
! 223: u_int8_t v_flags; /* VIFF_ flags defined above */
! 224: u_int8_t v_threshold; /* min ttl required to forward on vif */
! 225: struct in_addr v_lcl_addr; /* local interface address */
! 226: struct in_addr v_rmt_addr; /* remote address (tunnels only) */
! 227: struct ifnet *v_ifp; /* pointer to interface */
! 228: u_long v_pkt_in; /* # pkts in on interface */
! 229: u_long v_pkt_out; /* # pkts out on interface */
! 230: u_long v_bytes_in; /* # bytes in on interface */
! 231: u_long v_bytes_out; /* # bytes out on interface */
! 232: struct route v_route; /* cached route if this is a tunnel */
! 233: struct timeout v_repq_ch; /* for tbf_reprocess_q() */
! 234: #ifdef RSVP_ISI
! 235: int v_rsvp_on; /* # RSVP listening on this vif */
! 236: struct socket *v_rsvpd; /* # RSVPD daemon */
! 237: #endif /* RSVP_ISI */
! 238: };
! 239:
! 240: /*
! 241: * The kernel's multicast forwarding cache entry structure.
! 242: * (A field for the type of service (mfc_tos) is to be added
! 243: * at a future point.)
! 244: */
! 245: struct mfc {
! 246: LIST_ENTRY(mfc) mfc_hash;
! 247: struct in_addr mfc_origin; /* ip origin of mcasts */
! 248: struct in_addr mfc_mcastgrp; /* multicast group associated */
! 249: vifi_t mfc_parent; /* incoming vif */
! 250: u_int8_t mfc_ttls[MAXVIFS]; /* forwarding ttls on vifs */
! 251: u_long mfc_pkt_cnt; /* pkt count for src-grp */
! 252: u_long mfc_byte_cnt; /* byte count for src-grp */
! 253: u_long mfc_wrong_if; /* wrong if for src-grp */
! 254: int mfc_expire; /* time to clean entry up */
! 255: struct timeval mfc_last_assert; /* last time I sent an assert */
! 256: struct rtdetq *mfc_stall; /* pkts waiting for route */
! 257: u_int8_t mfc_flags[MAXVIFS]; /* the MRT_MFC_FLAGS_* flags */
! 258: struct in_addr mfc_rp; /* the RP address */
! 259: struct bw_meter *mfc_bw_meter; /* list of bandwidth meters */
! 260: };
! 261:
! 262: /*
! 263: * Structure used to communicate from kernel to multicast router.
! 264: * (Note the convenient similarity to an IP packet.)
! 265: */
! 266: struct igmpmsg {
! 267: u_int32_t unused1;
! 268: u_int32_t unused2;
! 269: u_int8_t im_msgtype; /* what type of message */
! 270: #define IGMPMSG_NOCACHE 1 /* no MFC in the kernel */
! 271: #define IGMPMSG_WRONGVIF 2 /* packet came from wrong interface */
! 272: #define IGMPMSG_WHOLEPKT 3 /* PIM pkt for user level encap. */
! 273: #define IGMPMSG_BW_UPCALL 4 /* BW monitoring upcall */
! 274: u_int8_t im_mbz; /* must be zero */
! 275: u_int8_t im_vif; /* vif rec'd on */
! 276: u_int8_t unused3;
! 277: struct in_addr im_src, im_dst;
! 278: };
! 279:
! 280: /*
! 281: * Argument structure used for pkt info. while upcall is made.
! 282: */
! 283: struct rtdetq {
! 284: struct mbuf *m; /* a copy of the packet */
! 285: struct ifnet *ifp; /* interface pkt came in on */
! 286: #ifdef UPCALL_TIMING
! 287: struct timeval t; /* timestamp */
! 288: #endif /* UPCALL_TIMING */
! 289: struct rtdetq *next;
! 290: };
! 291:
! 292: #define MFCTBLSIZ 256
! 293: #define MAX_UPQ 4 /* max. no of pkts in upcall Q */
! 294:
! 295: /*
! 296: * Structure for measuring the bandwidth and sending an upcall if the
! 297: * measured bandwidth is above or below a threshold.
! 298: */
! 299: struct bw_meter {
! 300: struct bw_meter *bm_mfc_next; /* next bw meter (same mfc) */
! 301: struct bw_meter *bm_time_next; /* next bw meter (same time) */
! 302: uint32_t bm_time_hash; /* the time hash value */
! 303: struct mfc *bm_mfc; /* the corresponding mfc */
! 304: uint32_t bm_flags; /* misc flags (see below) */
! 305: #define BW_METER_UNIT_PACKETS (1 << 0) /* threshold (in packets) */
! 306: #define BW_METER_UNIT_BYTES (1 << 1) /* threshold (in bytes) */
! 307: #define BW_METER_GEQ (1 << 2) /* upcall if bw >= threshold */
! 308: #define BW_METER_LEQ (1 << 3) /* upcall if bw <= threshold */
! 309: #define BW_METER_USER_FLAGS (BW_METER_UNIT_PACKETS | \
! 310: BW_METER_UNIT_BYTES | \
! 311: BW_METER_GEQ | \
! 312: BW_METER_LEQ)
! 313:
! 314: #define BW_METER_UPCALL_DELIVERED (1 << 24) /* upcall was delivered */
! 315:
! 316: struct bw_data bm_threshold; /* the upcall threshold */
! 317: struct bw_data bm_measured; /* the measured bw */
! 318: struct timeval bm_start_time; /* abs. time */
! 319: };
! 320:
! 321: int ip_mrouter_set(struct socket *, int, struct mbuf **);
! 322: int ip_mrouter_get(struct socket *, int, struct mbuf **);
! 323: int mrt_ioctl(struct socket *, u_long, caddr_t);
! 324: int ip_mrouter_done(void);
! 325: void ip_mrouter_detach(struct ifnet *);
! 326: void reset_vif(struct vif *);
! 327: void vif_delete(struct ifnet *);
! 328: #ifdef RSVP_ISI
! 329: int ip_mforward(struct mbuf *, struct ifnet *, struct ip_moptions *);
! 330: int legal_vif_num(int);
! 331: int ip_rsvp_vif_init(struct socket *, struct mbuf *);
! 332: int ip_rsvp_vif_done(struct socket *, struct mbuf *);
! 333: void ip_rsvp_force_done(struct socket *);
! 334: void rsvp_input(struct mbuf *, int, int);
! 335: #else
! 336: int ip_mforward(struct mbuf *, struct ifnet *);
! 337: #endif /* RSVP_ISI */
! 338:
! 339: #endif /* _KERNEL */
! 340: #endif /* _NETINET_IP_MROUTE_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>