"Fossies" - the Fresh Open Source Software Archive

Member "mrouted-3.9.8/defs.h" (1 Jan 2017, 12137 Bytes) of package /linux/misc/mrouted-3.9.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "defs.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.9.7_vs_3.9.8.

    1 /*
    2  * The mrouted program is covered by the license in the accompanying file
    3  * named "LICENSE".  Use of the mrouted program represents acceptance of
    4  * the terms and conditions listed in that file.
    5  *
    6  * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
    7  * Leland Stanford Junior University.
    8  */
    9 #ifndef __MROUTED_DEFS_H__
   10 #define __MROUTED_DEFS_H__
   11 
   12 #include <stdio.h>
   13 #include <stdlib.h>
   14 #include <stdint.h>
   15 #include <unistd.h>
   16 #include <ctype.h>
   17 #include <errno.h>
   18 #include <syslog.h>
   19 #include <signal.h>
   20 #include <string.h>
   21 #include <sys/param.h>
   22 #include <sys/types.h>
   23 #include <sys/socket.h>
   24 #include <sys/ioctl.h>
   25 #if defined(__bsdi__) || (defined(SunOS) && SunOS < 50)
   26 #include <sys/sockio.h>
   27 #endif /* bsdi || SunOS 4.x */
   28 #include <time.h>
   29 #include <sys/time.h>
   30 #include <sys/uio.h>
   31 #include <net/if.h>
   32 #include <netinet/in.h>
   33 #include <netinet/ip.h>
   34 #include <netinet/ip_icmp.h>
   35 #include <netinet/igmp.h>
   36 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
   37 #include <osreldate.h>
   38 #endif /* __FreeBSD__ */
   39 #if defined(__bsdi__) || (defined(__FreeBSD__) && __FreeBSD_version >= 220000) || defined(__FreeBSD_kernel__)
   40 #define rtentry kernel_rtentry
   41 #include <net/route.h>
   42 #undef rtentry
   43 #endif /* bsdi or __FreeBSD_version >= 220000 */
   44 #ifdef __linux__
   45 #define _LINUX_IN_H             /* For Linux <= 2.6.25 */
   46 #include <linux/types.h>
   47 #include <linux/mroute.h>
   48 #else
   49 #include <netinet/ip_mroute.h>
   50 #endif
   51 #if defined(HAVE_STRLCPY)
   52 #include <string.h>
   53 #endif
   54 #if defined(HAVE_STRTONUM)
   55 #include <stdlib.h>
   56 #endif
   57 #if defined(HAVE_PIDFILE)
   58 #if defined(OpenBSD) || defined(NetBSD)
   59 #include <util.h>
   60 #else
   61 #include <libutil.h>
   62 #endif
   63 #endif
   64 #ifdef RSRR
   65 #include <sys/un.h>
   66 #endif /* RSRR */
   67 
   68 typedef void (*cfunc_t) (void*);
   69 typedef void (*ihfunc_t) (int);
   70 
   71 #include "dvmrp.h"
   72 #include "igmpv2.h"
   73 #include "vif.h"
   74 #include "route.h"
   75 #include "prune.h"
   76 #include "pathnames.h"
   77 #ifdef RSRR
   78 #include "rsrr.h"
   79 #include "rsrr_var.h"
   80 #endif /* RSRR */
   81 
   82 /*
   83  * Miscellaneous constants and macros.
   84  */
   85 
   86 /* Older versions of UNIX don't really give us true raw sockets.
   87  * Instead, they expect ip_len and ip_off in host byte order, and also
   88  * provide them to us in that format when receiving raw frames.
   89  *
   90  * This list could probably be made longer, e.g., SunOS and __bsdi__
   91  */
   92 #if defined(__NetBSD__) ||                  \
   93     (defined(__FreeBSD__) && (__FreeBSD_version < 1100030)) ||  \
   94     (defined(__OpenBSD__) && (OpenBSD < 200311))
   95 #define HAVE_IP_HDRINCL_BSD_ORDER
   96 #endif
   97 
   98 #define FALSE       0
   99 #define TRUE        1
  100 
  101 #define EQUAL(s1, s2)   (strcmp((s1), (s2)) == 0)
  102 #define ARRAY_LEN(a)    (sizeof((a)) / sizeof((a)[0]))
  103 
  104 #define TIMER_INTERVAL  ROUTE_MAX_REPORT_DELAY
  105 
  106 #define PROTOCOL_VERSION 3  /* increment when packet format/content changes */
  107 #define MROUTED_VERSION  9  /* not in DVMRP packets at all */
  108 
  109 #define DVMRP_CONSTANT  0x000eff00  /* constant portion of 'group' field */
  110 
  111 #define MROUTED_LEVEL  (DVMRP_CONSTANT | PROTOCOL_VERSION)
  112                 /* for IGMP 'group' field of DVMRP messages */
  113 
  114 #define LEAF_FLAGS  (( vifs_with_neighbors == 1 ) ? 0x010000 : 0)
  115                 /* more for IGMP 'group' field of DVMRP messages */
  116 
  117 #define DEL_RTE_GROUP   0
  118 #define DEL_ALL_ROUTES  1
  119                 /* for Deleting kernel table entries */
  120 
  121 #define JAN_1970    2208988800UL    /* 1970 - 1900 in seconds */
  122 
  123 #ifdef RSRR
  124 #define BIT_ZERO(X)      ((X) = 0)
  125 #define BIT_SET(X,n)     ((X) |= 1 << (n))
  126 #define BIT_CLR(X,n)     ((X) &= ~(1 << (n)))
  127 #define BIT_TST(X,n)     ((X) & 1 << (n))
  128 #endif /* RSRR */
  129 
  130 #if defined(_AIX) || (defined(BSD) && BSD >= 199103)
  131 #define HAVE_SA_LEN
  132 #endif
  133 
  134 /*
  135  * External declarations for global variables and functions.
  136  */
  137 #define RECV_BUF_SIZE 8192
  138 extern char     *recv_buf;
  139 extern char     *send_buf;
  140 extern int      igmp_socket;
  141 extern uint32_t     allhosts_group;
  142 extern uint32_t     allrtrs_group;
  143 extern uint32_t     dvmrp_group;
  144 extern uint32_t     dvmrp_genid;
  145 extern int      vifstatedefault;
  146 extern int      missingok;
  147 
  148 #define IF_DEBUG(l) if (debug && debug & (l))
  149 
  150 #define DEBUG_PKT   0x0001
  151 #define DEBUG_PRUNE 0x0002
  152 #define DEBUG_ROUTE 0x0004
  153 #define DEBUG_PEER  0x0008
  154 #define DEBUG_CACHE 0x0010
  155 #define DEBUG_TIMEOUT   0x0020
  156 #define DEBUG_IF    0x0040
  157 #define DEBUG_MEMBER    0x0080
  158 #define DEBUG_TRACE 0x0100
  159 #define DEBUG_IGMP  0x0200
  160 #define DEBUG_RTDETAIL  0x0400
  161 #define DEBUG_KERN  0x0800
  162 #define DEBUG_RSRR  0x1000
  163 #define DEBUG_ICMP  0x2000
  164 
  165 #define DEFAULT_DEBUG   0x02de  /* default if "-d" given without value */
  166 #define DEFAULT_STARTUP_DELAY 10  /* default startup delay before forwarding in seconds */
  167 
  168 extern int      debug;
  169 extern int      did_final_init;
  170 
  171 extern int      routes_changed;
  172 extern int      delay_change_reports;
  173 extern unsigned     nroutes;
  174 
  175 extern struct uvif  uvifs[MAXVIFS];
  176 extern vifi_t       numvifs;
  177 extern int      vifs_down;
  178 extern int      udp_socket;
  179 extern int      vifs_with_neighbors;
  180 
  181 #define MAX_INET_BUF_LEN 19
  182 extern char     s1[MAX_INET_BUF_LEN];
  183 extern char     s2[MAX_INET_BUF_LEN];
  184 extern char     s3[MAX_INET_BUF_LEN];
  185 extern char     s4[MAX_INET_BUF_LEN];
  186 
  187 #define MAX_VERSION_LEN 100
  188 extern char             versionstring[MAX_VERSION_LEN];
  189 
  190 #ifndef IGMP_PIM
  191 #define IGMP_PIM    0x14
  192 #endif
  193 #ifndef IPPROTO_IPIP
  194 #define IPPROTO_IPIP    4
  195 #endif
  196 
  197 /*
  198  * The original multicast releases defined
  199  * IGMP_HOST_{MEMBERSHIP_QUERY,MEMBERSHIP_REPORT,NEW_MEMBERSHIP_REPORT
  200  *   ,LEAVE_MESSAGE}.  Later releases removed the HOST and inserted
  201  * the IGMP version number.  NetBSD inserted the version number in
  202  * a different way.  mrouted uses the new names, so we #define them
  203  * to the old ones if needed.
  204  */
  205 #if !defined(IGMP_MEMBERSHIP_QUERY) && defined(IGMP_HOST_MEMBERSHIP_QUERY)
  206 #define IGMP_MEMBERSHIP_QUERY       IGMP_HOST_MEMBERSHIP_QUERY
  207 #define IGMP_V2_LEAVE_GROUP     IGMP_HOST_LEAVE_MESSAGE
  208 #endif
  209 #ifndef IGMP_V1_MEMBERSHIP_REPORT
  210 #ifdef  IGMP_HOST_MEMBERSHIP_REPORT
  211 #define IGMP_V1_MEMBERSHIP_REPORT   IGMP_HOST_MEMBERSHIP_REPORT
  212 #define IGMP_V2_MEMBERSHIP_REPORT   IGMP_HOST_NEW_MEMBERSHIP_REPORT
  213 #endif
  214 #ifdef  IGMP_v1_HOST_MEMBERSHIP_REPORT
  215 #define IGMP_V1_MEMBERSHIP_REPORT   IGMP_v1_HOST_MEMBERSHIP_REPORT
  216 #define IGMP_V2_MEMBERSHIP_REPORT   IGMP_v2_HOST_MEMBERSHIP_REPORT
  217 #endif
  218 #endif
  219 
  220 /*
  221  * NetBSD also renamed the mtrace types.
  222  */
  223 #if !defined(IGMP_MTRACE_RESP) && defined(IGMP_MTRACE_REPLY)
  224 #define IGMP_MTRACE_RESP        IGMP_MTRACE_REPLY
  225 #define IGMP_MTRACE         IGMP_MTRACE_QUERY
  226 #endif
  227 
  228 /* main.c */
  229 extern char *       scaletime(time_t);
  230 extern void     logit(int, int, const char *, ...);
  231 extern int      register_input_handler(int, ihfunc_t);
  232 
  233 /* igmp.c */
  234 extern void     init_igmp(void);
  235 extern void     accept_igmp(size_t);
  236 extern size_t       build_igmp(uint32_t, uint32_t, int, int, uint32_t, int);
  237 extern void     send_igmp(uint32_t, uint32_t, int, int, uint32_t, int);
  238 extern char *       igmp_packet_kind(uint32_t, uint32_t);
  239 extern int      igmp_debug_kind(uint32_t, uint32_t);
  240 
  241 /* icmp.c */
  242 extern void     init_icmp(void);
  243 
  244 /* ipip.c */
  245 extern void     init_ipip(void);
  246 extern void     init_ipip_on_vif(struct uvif *);
  247 extern void     send_ipip(uint32_t, uint32_t, int, int, uint32_t, int, struct uvif *);
  248 
  249 /* callout.c */
  250 extern void     callout_init(void);
  251 extern void     free_all_callouts(void);
  252 extern void     age_callout_queue(time_t);
  253 extern int      timer_nextTimer(void);
  254 extern int      timer_setTimer(time_t, cfunc_t, void *);
  255 extern int      timer_clearTimer(int);
  256 extern int      timer_leftTimer(int);
  257 
  258 /* route.c */
  259 extern void     init_routes(void);
  260 extern void     start_route_updates(void);
  261 extern void     update_route(uint32_t, uint32_t, uint32_t, uint32_t, vifi_t, struct listaddr *);
  262 extern void     age_routes(void);
  263 extern void     expire_all_routes(void);
  264 extern void     free_all_routes(void);
  265 extern void     accept_probe(uint32_t, uint32_t, char *, size_t, uint32_t);
  266 extern void     accept_report(uint32_t, uint32_t, char *, size_t, uint32_t);
  267 extern struct rtentry * determine_route(uint32_t src);
  268 extern void     report(int, vifi_t, uint32_t);
  269 extern void     report_to_all_neighbors(int);
  270 extern int      report_next_chunk(void);
  271 extern void     blaster_alloc(vifi_t);
  272 extern void     add_vif_to_routes(vifi_t);
  273 extern void     delete_vif_from_routes(vifi_t);
  274 extern void     add_neighbor_to_routes(vifi_t, uint32_t);
  275 extern void     delete_neighbor_from_routes(uint32_t, vifi_t, uint32_t);
  276 extern void     dump_routes(FILE *fp);
  277 
  278 /* vif.c */
  279 extern void     init_vifs(void);
  280 extern void     zero_vif(struct uvif *, int);
  281 extern void     init_installvifs(void);
  282 extern void     check_vif_state(void);
  283 extern void     send_on_vif(struct uvif *, uint32_t, int, size_t);
  284 extern vifi_t       find_vif(uint32_t, uint32_t);
  285 extern void     age_vifs(void);
  286 extern void     dump_vifs(FILE *);
  287 extern void     stop_all_vifs(void);
  288 extern struct listaddr *neighbor_info(vifi_t, uint32_t);
  289 extern void     accept_group_report(uint32_t, uint32_t, uint32_t, int);
  290 extern void     query_groups(void);
  291 extern void     probe_for_neighbors(void);
  292 extern struct listaddr *update_neighbor(vifi_t, uint32_t, int, char *, size_t, uint32_t);
  293 extern void     accept_neighbor_request(uint32_t, uint32_t);
  294 extern void     accept_neighbor_request2(uint32_t, uint32_t);
  295 extern void     accept_info_request(uint32_t, uint32_t, uint8_t *, size_t);
  296 extern void     accept_info_reply(uint32_t, uint32_t, uint8_t *, size_t);
  297 extern void     accept_neighbors(uint32_t, uint32_t, uint8_t *, size_t, uint32_t);
  298 extern void     accept_neighbors2(uint32_t, uint32_t, uint8_t *, size_t, uint32_t);
  299 extern void     accept_leave_message(uint32_t, uint32_t, uint32_t);
  300 extern void     accept_membership_query(uint32_t, uint32_t, uint32_t, int);
  301 
  302 /* config.c */
  303 extern void     config_vifs_from_kernel(void);
  304 
  305 /* cfparse.y */
  306 extern void     config_vifs_from_file(void);
  307 
  308 /* inet.c */
  309 extern int      inet_valid_host(uint32_t);
  310 extern int      inet_valid_mask(uint32_t);
  311 extern int      inet_valid_subnet(uint32_t, uint32_t);
  312 extern char *       inet_fmt(uint32_t, char *, size_t);
  313 extern char *       inet_fmts(uint32_t, uint32_t, char *, size_t);
  314 extern uint32_t     inet_parse(char *, int);
  315 extern int      inet_cksum(uint16_t *, uint32_t);
  316 
  317 /* prune.c */
  318 extern unsigned     kroutes;
  319 extern void     determine_forwvifs(struct gtable *);
  320 extern void     send_prune_or_graft(struct gtable *);
  321 extern void     add_table_entry(uint32_t, uint32_t);
  322 extern void         del_table_entry(struct rtentry *, uint32_t, uint32_t);
  323 extern void     update_table_entry(struct rtentry *, uint32_t);
  324 extern int      find_src_grp(uint32_t, uint32_t, uint32_t);
  325 extern void     init_ktable(void);
  326 extern void     steal_sources(struct rtentry *);
  327 extern void     reset_neighbor_state(vifi_t, uint32_t);
  328 extern int      grplst_mem(vifi_t, uint32_t);
  329 extern void     free_all_prunes(void);
  330 extern void         age_table_entry(void);
  331 extern void     dump_cache(FILE *);
  332 extern void         update_lclgrp(vifi_t, uint32_t);
  333 extern void     delete_lclgrp(vifi_t, uint32_t);
  334 extern void     chkgrp_graft(vifi_t, uint32_t);
  335 extern void         accept_prune(uint32_t, uint32_t, char *, size_t);
  336 extern void     accept_graft(uint32_t, uint32_t, char *, size_t);
  337 extern void         accept_g_ack(uint32_t, uint32_t, char *, size_t);
  338 /* uint32_t is promoted uint8_t */
  339 extern void     accept_mtrace(uint32_t, uint32_t, uint32_t, char *, uint8_t, size_t);
  340 
  341 /* kern.c */
  342 extern void     k_set_rcvbuf(int, int);
  343 extern void     k_hdr_include(int);
  344 extern void     k_set_ttl(int);
  345 extern void     k_set_loop(int);
  346 extern void     k_set_if(uint32_t);
  347 extern void     k_join(uint32_t, uint32_t);
  348 extern void     k_leave(uint32_t, uint32_t);
  349 extern void     k_init_dvmrp(void);
  350 extern void     k_stop_dvmrp(void);
  351 extern void     k_add_vif(vifi_t, struct uvif *);
  352 extern void     k_del_vif(vifi_t, struct uvif *);
  353 extern void     k_add_rg(uint32_t, struct gtable *);
  354 extern int      k_del_rg(uint32_t, struct gtable *);
  355 extern int      k_get_version(void);
  356 
  357 #ifdef RSRR
  358 /* prune.c */
  359 extern struct gtable    *kernel_table;
  360 extern struct gtable    *gtp;
  361 
  362 /* rsrr.c */
  363 extern void     rsrr_init(void);
  364 extern void     rsrr_clean(void);
  365 extern void     rsrr_cache_send(struct gtable *, int);
  366 extern void     rsrr_cache_clean(struct gtable *);
  367 #endif /* RSRR */
  368 
  369 #ifdef __GNUC__
  370 # define UNUSED __attribute__((unused))
  371 #else
  372 # define UNUSED /*empty*/
  373 #endif
  374 
  375 #ifndef HAVE_STRLCPY
  376 size_t strlcpy(char *dst, const char *src, size_t siz);
  377 #endif
  378 #ifndef HAVE_STRTONUM
  379 long long strtonum(const char *numstr, long long minval, long long maxval, const char **errstrp);
  380 #endif
  381 #ifndef HAVE_PIDFILE
  382 int pidfile(const char *basename);
  383 #endif
  384 
  385 #endif /* __MROUTED_DEFS_H__ */