[BACK]Return to ip_mroute.h CVS log [TXT][DIR] Up to [local] / sys / netinet

Annotation of sys/netinet/ip_mroute.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: ip_mroute.h,v 1.14 2006/04/25 15:49:35 claudio 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;      /* max rate */
                     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:        struct    mbuf *tbf_q, **tbf_t; /* packet queue */
                    224:        struct    timeval tbf_last_pkt_t; /* arr. time of last pkt */
                    225:        u_int32_t tbf_n_tok;            /* no of tokens in bucket */
                    226:        u_int32_t tbf_q_len;            /* length of queue at this vif */
                    227:        u_int32_t tbf_max_q_len;        /* max. queue length */
                    228:
                    229:        u_int8_t  v_flags;              /* VIFF_ flags defined above */
                    230:        u_int8_t  v_threshold;          /* min ttl required to forward on vif */
                    231:        u_int32_t v_rate_limit;         /* max rate */
                    232:        struct    in_addr v_lcl_addr;   /* local interface address */
                    233:        struct    in_addr v_rmt_addr;   /* remote address (tunnels only) */
                    234:        struct    ifnet *v_ifp;         /* pointer to interface */
                    235:        u_long    v_pkt_in;             /* # pkts in on interface */
                    236:        u_long    v_pkt_out;            /* # pkts out on interface */
                    237:        u_long    v_bytes_in;           /* # bytes in on interface */
                    238:        u_long    v_bytes_out;          /* # bytes out on interface */
                    239:        struct    route v_route;        /* cached route if this is a tunnel */
                    240:        struct    timeout v_repq_ch;    /* for tbf_reprocess_q() */
                    241: #ifdef RSVP_ISI
                    242:        int       v_rsvp_on;            /* # RSVP listening on this vif */
                    243:        struct    socket *v_rsvpd;      /* # RSVPD daemon */
                    244: #endif /* RSVP_ISI */
                    245: };
                    246:
                    247: /*
                    248:  * The kernel's multicast forwarding cache entry structure.
                    249:  * (A field for the type of service (mfc_tos) is to be added
                    250:  * at a future point.)
                    251:  */
                    252: struct mfc {
                    253:        LIST_ENTRY(mfc) mfc_hash;
                    254:        struct   in_addr mfc_origin;            /* ip origin of mcasts */
                    255:        struct   in_addr mfc_mcastgrp;          /* multicast group associated */
                    256:        vifi_t   mfc_parent;                    /* incoming vif */
                    257:        u_int8_t mfc_ttls[MAXVIFS];             /* forwarding ttls on vifs */
                    258:        u_long   mfc_pkt_cnt;                   /* pkt count for src-grp */
                    259:        u_long   mfc_byte_cnt;                  /* byte count for src-grp */
                    260:        u_long   mfc_wrong_if;                  /* wrong if for src-grp */
                    261:        int      mfc_expire;                    /* time to clean entry up */
                    262:        struct   timeval mfc_last_assert;       /* last time I sent an assert */
                    263:        struct   rtdetq *mfc_stall;             /* pkts waiting for route */
                    264:        u_int8_t mfc_flags[MAXVIFS];            /* the MRT_MFC_FLAGS_* flags */
                    265:        struct in_addr  mfc_rp;                 /* the RP address            */
                    266:        struct bw_meter *mfc_bw_meter;          /* list of bandwidth meters  */
                    267: };
                    268:
                    269: /*
                    270:  * Structure used to communicate from kernel to multicast router.
                    271:  * (Note the convenient similarity to an IP packet.)
                    272:  */
                    273: struct igmpmsg {
                    274:        u_int32_t unused1;
                    275:        u_int32_t unused2;
                    276:        u_int8_t  im_msgtype;           /* what type of message */
                    277: #define        IGMPMSG_NOCACHE         1       /* no MFC in the kernel             */
                    278: #define        IGMPMSG_WRONGVIF        2       /* packet came from wrong interface */
                    279: #define        IGMPMSG_WHOLEPKT        3       /* PIM pkt for user level encap.    */
                    280: #define        IGMPMSG_BW_UPCALL       4       /* BW monitoring upcall             */
                    281:        u_int8_t  im_mbz;               /* must be zero */
                    282:        u_int8_t  im_vif;               /* vif rec'd on */
                    283:        u_int8_t  unused3;
                    284:        struct    in_addr im_src, im_dst;
                    285: };
                    286:
                    287: /*
                    288:  * Argument structure used for pkt info. while upcall is made.
                    289:  */
                    290: struct rtdetq {
                    291:        struct  mbuf *m;                /* a copy of the packet */
                    292:        struct  ifnet *ifp;             /* interface pkt came in on */
                    293: #ifdef UPCALL_TIMING
                    294:        struct  timeval t;              /* timestamp */
                    295: #endif /* UPCALL_TIMING */
                    296:        struct  rtdetq *next;
                    297: };
                    298:
                    299: #define        MFCTBLSIZ       256
                    300: #define        MAX_UPQ         4               /* max. no of pkts in upcall Q */
                    301:
                    302: /*
                    303:  * Token bucket filter code
                    304:  */
                    305: #define        MAX_BKT_SIZE    10000           /* 10K bytes size */
                    306: #define        MAXQSIZE        10              /* max. no of pkts in token queue */
                    307:
                    308: /*
                    309:  * Structure for measuring the bandwidth and sending an upcall if the
                    310:  * measured bandwidth is above or below a threshold.
                    311:  */
                    312: struct bw_meter {
                    313:        struct bw_meter *bm_mfc_next;           /* next bw meter (same mfc)  */
                    314:        struct bw_meter *bm_time_next;          /* next bw meter (same time) */
                    315:        uint32_t        bm_time_hash;           /* the time hash value       */
                    316:        struct mfc      *bm_mfc;                /* the corresponding mfc     */
                    317:        uint32_t        bm_flags;               /* misc flags (see below)    */
                    318: #define        BW_METER_UNIT_PACKETS   (1 << 0)        /* threshold (in packets)    */
                    319: #define        BW_METER_UNIT_BYTES     (1 << 1)        /* threshold (in bytes)      */
                    320: #define        BW_METER_GEQ            (1 << 2)        /* upcall if bw >= threshold */
                    321: #define        BW_METER_LEQ            (1 << 3)        /* upcall if bw <= threshold */
                    322: #define        BW_METER_USER_FLAGS     (BW_METER_UNIT_PACKETS |                \
                    323:                                 BW_METER_UNIT_BYTES |                  \
                    324:                                 BW_METER_GEQ |                         \
                    325:                                 BW_METER_LEQ)
                    326:
                    327: #define        BW_METER_UPCALL_DELIVERED (1 << 24)     /* upcall was delivered      */
                    328:
                    329:        struct bw_data  bm_threshold;           /* the upcall threshold      */
                    330:        struct bw_data  bm_measured;            /* the measured bw           */
                    331:        struct timeval  bm_start_time;          /* abs. time                 */
                    332: };
                    333:
                    334: int    ip_mrouter_set(struct socket *, int, struct mbuf **);
                    335: int    ip_mrouter_get(struct socket *, int, struct mbuf **);
                    336: int    mrt_ioctl(struct socket *, u_long, caddr_t);
                    337: int    ip_mrouter_done(void);
                    338: void   ip_mrouter_detach(struct ifnet *);
                    339: void   reset_vif(struct vif *);
                    340: void   vif_delete(struct ifnet *);
                    341: #ifdef RSVP_ISI
                    342: int    ip_mforward(struct mbuf *, struct ifnet *, struct ip_moptions *);
                    343: int    legal_vif_num(int);
                    344: int    ip_rsvp_vif_init(struct socket *, struct mbuf *);
                    345: int    ip_rsvp_vif_done(struct socket *, struct mbuf *);
                    346: void   ip_rsvp_force_done(struct socket *);
                    347: void   rsvp_input(struct mbuf *, int, int);
                    348: #else
                    349: int    ip_mforward(struct mbuf *, struct ifnet *);
                    350: #endif /* RSVP_ISI */
                    351:
                    352: #endif /* _KERNEL */
                    353: #endif /* _NETINET_IP_MROUTE_H_ */

CVSweb