Annotation of embedaddon/igmpproxy/src/igmpproxy.h, revision 1.1

1.1     ! misho       1: /*
        !             2: **  igmpproxy - IGMP proxy based multicast router 
        !             3: **  Copyright (C) 2005 Johnny Egeland <johnny@rlo.org>
        !             4: **
        !             5: **  This program is free software; you can redistribute it and/or modify
        !             6: **  it under the terms of the GNU General Public License as published by
        !             7: **  the Free Software Foundation; either version 2 of the License, or
        !             8: **  (at your option) any later version.
        !             9: **
        !            10: **  This program is distributed in the hope that it will be useful,
        !            11: **  but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            12: **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            13: **  GNU General Public License for more details.
        !            14: **
        !            15: **  You should have received a copy of the GNU General Public License
        !            16: **  along with this program; if not, write to the Free Software
        !            17: **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            18: **
        !            19: **----------------------------------------------------------------------------
        !            20: **
        !            21: **  This software is derived work from the following software. The original
        !            22: **  source code has been modified from it's original state by the author
        !            23: **  of igmpproxy.
        !            24: **
        !            25: **  smcroute 0.92 - Copyright (C) 2001 Carsten Schill <carsten@cschill.de>
        !            26: **  - Licensed under the GNU General Public License, version 2
        !            27: **  
        !            28: **  mrouted 3.9-beta3 - COPYRIGHT 1989 by The Board of Trustees of 
        !            29: **  Leland Stanford Junior University.
        !            30: **  - Original license can be found in the Stanford.txt file.
        !            31: **
        !            32: */
        !            33: /**
        !            34: *   igmpproxy.h - Header file for common includes.
        !            35: */
        !            36: 
        !            37: #include <errno.h>
        !            38: #include <stdarg.h>
        !            39: #include <stdio.h>
        !            40: #include <stdlib.h>
        !            41: #include <syslog.h>
        !            42: #include <signal.h>
        !            43: #include <unistd.h>
        !            44: #include <string.h>
        !            45: #include <fcntl.h>
        !            46: #include <stdbool.h>
        !            47: 
        !            48: #include <sys/socket.h>
        !            49: #include <sys/un.h>
        !            50: #include <sys/time.h>
        !            51: #include <sys/ioctl.h>
        !            52: #include <sys/param.h>
        !            53: 
        !            54: #include <net/if.h>
        !            55: #include <netinet/in.h>
        !            56: #include <arpa/inet.h>
        !            57: 
        !            58: #include "os.h"
        !            59: #include "config.h"
        !            60: 
        !            61: /*
        !            62:  * Limit on length of route data
        !            63:  */
        !            64: #define MAX_IP_PACKET_LEN      576
        !            65: #define MIN_IP_HEADER_LEN      20
        !            66: #define MAX_IP_HEADER_LEN      60
        !            67: 
        !            68: #define MAX_MC_VIFS    32     // !!! check this const in the specific includes
        !            69: 
        !            70: // Useful macros..          
        !            71: #define VCMC( Vc )  (sizeof( Vc ) / sizeof( (Vc)[ 0 ] ))
        !            72: #define VCEP( Vc )  (&(Vc)[ VCMC( Vc ) ])
        !            73: 
        !            74: // Bit manipulation macros...
        !            75: #define BIT_ZERO(X)      ((X) = 0)
        !            76: #define BIT_SET(X,n)     ((X) |= 1 << (n))
        !            77: #define BIT_CLR(X,n)     ((X) &= ~(1 << (n)))
        !            78: #define BIT_TST(X,n)     ((X) & 1 << (n))
        !            79: 
        !            80: 
        !            81: //#################################################################################
        !            82: //  Globals
        !            83: //#################################################################################
        !            84: 
        !            85: /*
        !            86:  * External declarations for global variables and functions.
        !            87:  */
        !            88: #define RECV_BUF_SIZE 8192
        !            89: extern char     *recv_buf;
        !            90: extern char     *send_buf;
        !            91: 
        !            92: extern char     s1[];
        !            93: extern char     s2[];
        !            94: extern char            s3[];
        !            95: extern char            s4[];
        !            96: 
        !            97: 
        !            98: 
        !            99: //#################################################################################
        !           100: //  Lib function prototypes.
        !           101: //#################################################################################
        !           102: 
        !           103: /* syslog.c
        !           104:  */
        !           105: extern bool Log2Stderr;           // Log to stderr instead of to syslog
        !           106: extern int  LogLevel;             // Log threshold, LOG_WARNING .... LOG_DEBUG 
        !           107: 
        !           108: void my_log( int Serverity, int Errno, const char *FmtSt, ... );
        !           109: 
        !           110: /* ifvc.c
        !           111:  */
        !           112: #define MAX_IF         40     // max. number of interfaces recognized 
        !           113: 
        !           114: // Interface states
        !           115: #define IF_STATE_DISABLED      0   // Interface should be ignored.
        !           116: #define IF_STATE_UPSTREAM      1   // Interface is the upstream interface
        !           117: #define IF_STATE_DOWNSTREAM    2   // Interface is a downstream interface
        !           118: 
        !           119: // Multicast default values...
        !           120: #define DEFAULT_ROBUSTNESS     2
        !           121: #define DEFAULT_THRESHOLD      1
        !           122: #define DEFAULT_RATELIMIT      0
        !           123: 
        !           124: // Define timer constants (in seconds...)
        !           125: #define INTERVAL_QUERY          125
        !           126: #define INTERVAL_QUERY_RESPONSE  10
        !           127: //#define INTERVAL_QUERY_RESPONSE  10
        !           128: 
        !           129: #define ROUTESTATE_NOTJOINED            0   // The group corresponding to route is not joined
        !           130: #define ROUTESTATE_JOINED               1   // The group corresponding to route is joined
        !           131: #define ROUTESTATE_CHECK_LAST_MEMBER    2   // The router is checking for hosts
        !           132: 
        !           133: 
        !           134: 
        !           135: // Linked list of networks... 
        !           136: struct SubnetList {
        !           137:     uint32_t              subnet_addr;
        !           138:     uint32_t              subnet_mask;
        !           139:     struct SubnetList*  next;
        !           140: };
        !           141: 
        !           142: struct IfDesc {
        !           143:     char                Name[IF_NAMESIZE];
        !           144:     struct in_addr      InAdr;          /* == 0 for non IP interfaces */            
        !           145:     short               Flags;
        !           146:     short               state;
        !           147:     struct SubnetList*  allowednets;
        !           148:     unsigned int        robustness;
        !           149:     unsigned char       threshold;   /* ttl limit */
        !           150:     unsigned int        ratelimit; 
        !           151:     unsigned int        index;
        !           152: };
        !           153: 
        !           154: // Keeps common configuration settings 
        !           155: struct Config {
        !           156:     unsigned int        robustnessValue;
        !           157:     unsigned int        queryInterval;
        !           158:     unsigned int        queryResponseInterval;
        !           159:     // Used on startup..
        !           160:     unsigned int        startupQueryInterval;
        !           161:     unsigned int        startupQueryCount;
        !           162:     // Last member probe...
        !           163:     unsigned int        lastMemberQueryInterval;
        !           164:     unsigned int        lastMemberQueryCount;
        !           165:     // Set if upstream leave messages should be sent instantly..
        !           166:     unsigned short      fastUpstreamLeave;
        !           167: };
        !           168: 
        !           169: // Defines the Index of the upstream VIF...
        !           170: extern int upStreamVif;
        !           171: 
        !           172: /* ifvc.c
        !           173:  */
        !           174: void buildIfVc( void );
        !           175: struct IfDesc *getIfByName( const char *IfName );
        !           176: struct IfDesc *getIfByIx( unsigned Ix );
        !           177: struct IfDesc *getIfByAddress( uint32_t Ix );
        !           178: int isAdressValidForIf(struct IfDesc* intrface, uint32_t ipaddr);
        !           179: 
        !           180: /* mroute-api.c
        !           181:  */
        !           182: struct MRouteDesc {
        !           183:     struct in_addr  OriginAdr, McAdr;
        !           184:     short           InVif;
        !           185:     uint8_t           TtlVc[ MAX_MC_VIFS ];
        !           186: };
        !           187: 
        !           188: // IGMP socket as interface for the mrouted API
        !           189: // - receives the IGMP messages
        !           190: extern int MRouterFD;
        !           191: 
        !           192: int enableMRouter( void );
        !           193: void disableMRouter( void );
        !           194: void addVIF( struct IfDesc *Dp );
        !           195: int addMRoute( struct MRouteDesc * Dp );
        !           196: int delMRoute( struct MRouteDesc * Dp );
        !           197: int getVifIx( struct IfDesc *IfDp );
        !           198: 
        !           199: /* config.c
        !           200:  */
        !           201: int loadConfig(char *configFile);
        !           202: void configureVifs();
        !           203: struct Config *getCommonConfig();
        !           204: 
        !           205: /* igmp.c
        !           206: */
        !           207: extern uint32_t allhosts_group;
        !           208: extern uint32_t allrouters_group;
        !           209: void initIgmp(void);
        !           210: void acceptIgmp(int);
        !           211: void sendIgmp (uint32_t, uint32_t, int, int, uint32_t,int);
        !           212: 
        !           213: /* lib.c
        !           214:  */
        !           215: char   *fmtInAdr( char *St, struct in_addr InAdr );
        !           216: char   *inetFmt(uint32_t addr, char *s);
        !           217: char   *inetFmts(uint32_t addr, uint32_t mask, char *s);
        !           218: uint16_t inetChksum(uint16_t *addr, int len);
        !           219: 
        !           220: /* kern.c
        !           221:  */
        !           222: void k_set_rcvbuf(int bufsize, int minsize);
        !           223: void k_hdr_include(int hdrincl);
        !           224: void k_set_ttl(int t);
        !           225: void k_set_loop(int l);
        !           226: void k_set_if(uint32_t ifa);
        !           227: /*
        !           228: void k_join(uint32_t grp, uint32_t ifa);
        !           229: void k_leave(uint32_t grp, uint32_t ifa);
        !           230: */
        !           231: 
        !           232: /* udpsock.c
        !           233:  */
        !           234: int openUdpSocket( uint32_t PeerInAdr, uint16_t PeerPort );
        !           235: 
        !           236: /* mcgroup.c
        !           237:  */
        !           238: int joinMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr );
        !           239: int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr );
        !           240: 
        !           241: 
        !           242: /* rttable.c
        !           243:  */
        !           244: void initRouteTable();
        !           245: void clearAllRoutes();
        !           246: int insertRoute(uint32_t group, int ifx);
        !           247: int activateRoute(uint32_t group, uint32_t originAddr);
        !           248: void ageActiveRoutes();
        !           249: void setRouteLastMemberMode(uint32_t group);
        !           250: int lastMemberGroupAge(uint32_t group);
        !           251: 
        !           252: /* request.c
        !           253:  */
        !           254: void acceptGroupReport(uint32_t src, uint32_t group, uint8_t type);
        !           255: void acceptLeaveMessage(uint32_t src, uint32_t group);
        !           256: void sendGeneralMembershipQuery();
        !           257: 
        !           258: /* callout.c 
        !           259: */
        !           260: typedef void (*timer_f)(void *);
        !           261: 
        !           262: void callout_init();
        !           263: void free_all_callouts();
        !           264: void age_callout_queue(int);
        !           265: int timer_nextTimer();
        !           266: int timer_setTimer(int, timer_f, void *);
        !           267: int timer_clearTimer(int);
        !           268: int timer_leftTimer(int);
        !           269: 
        !           270: /* confread.c
        !           271:  */
        !           272: #define MAX_TOKEN_LENGTH    30
        !           273: 
        !           274: int openConfigFile(char *filename);
        !           275: void closeConfigFile();
        !           276: char* nextConfigToken();
        !           277: char* getCurrentConfigToken();
        !           278: 
        !           279: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>