📄 igmp_snoop.h
字号:
/*
#ifndef _U_24_IGMPSNOOPING_
#define _U_24_IGMPSNOOPING_
#endif
*/
#ifndef _FLEX_HAMMER_
#define _FLEX_HAMMER_
#endif
#include <linux/in.h>
#ifdef _FLEX_HAMMER_
#include "../net/switch/macaddr.h"
#endif
#ifdef _U_24_IGMPSNOOPING_
#include "macaddr.h"
#endif
#include <route/thread.h>
#include <hos_time.h>
#include "default.h"
#ifndef _NETINET_IGMP_SNOOP_H_
#define _NETINET_IGMP_SNOOP_H_
/*#define MAX_PORT_NO 24 temporary value*/
#ifndef OK
#define OK 0
#endif
#ifndef ERROR
#define ERROR -1
#endif
#ifndef NULL
#define NULL 0
#endif
struct igmphdr
{
__u8 type;
__u8 code; /* For newer IGMP ,temporarily defiend here*/
__u16 csum;
__u32 group;
};
/*
* IGMP snoop group format.
*/
struct igmp_snoop_group{
struct igmp_snoop_group *isgnext;
unsigned int group_addr;
short port_no_list[MAXPortNum]; /* 一个组里最多可有多少个端口号?*/
long timer_id[MAXPortNum + 1]; /*the timer id for the group lifetime*/
long igmpv1_timer_id[MAXPortNum +1]; /*if the group has a igmpv1 host ,this is the timer id for the igmpv1 lifetiime*/
int host_v1flag[MAXPortNum + 1]; /*the flag indicates a v1 host exist when true*/
long timer; /*the lifetime of the group*/
/*
* whenever we new a group ,we should register a timer(10s) to decide whether or not to send the general report
*/
long general_query_timer_id; /*it will reports every 10s*/
int send_general_report; /*whether or not to send the general report*/
struct igmp_snoop_pkt_msg *rec_pkt_msg[MAXPortNum +1];
struct igmp_snoop_pkt_msg *rec_igmpv1_pkt_msg[MAXPortNum +1];
struct igmp_snoop_pkt_msg *rec_general_pkt_msg;
};
/*
* IGMP snoop mac for group format.
*/
struct igmp_snoop_mac_group{
struct igmp_snoop_mac_group *ismnext;
struct igmp_snoop_group *igmp_snoop_group_list; /*the group list belongs to the mac group*/
mac_addr macaddr; /*the mac addr of the mac group*/
int VIDX;
int VID; /*vlan's id*/
short port_no_list[MAXPortNum];
};
/*
* IGMP snoop router format.
*/
struct igmp_snoop_router_entry{
struct igmp_snoop_router_entry *isrnext;
short port_no; /*the port no to which the router attaches*/
long router_timer; /*the lifetime of the router*/
long timer_id; /*the timer id for the router lifetime*/
long igmpv1_timer_id; /*the timer id for the igmpv1 router's lifetime*/
int router_v1flag; /*indicates this is a igmpv1 router*/
struct igmp_snoop_pkt_msg *rec_pkt_msg;
struct igmp_snoop_pkt_msg *rec_igmpv1_pkt_msg;
short VID;
};
/*
* IGMP snoop msg format.
*/
struct igmp_snoop_pkt_msg{
short time_out_type; /*if the msg is caused by time out ,it represents the time out type*/
short port_no; /*the port no from which the msg is received*/
char *pkt; /*the packet of the message*/
int len; /*the length of the pkt*/
int VID; /*vlan's id*/
unsigned int group_addr; /*the group addr in the pkt.
although it has existed in the pkt,
sometimes we use it to get the value without passing the pkt.
*/
};
/*
void aa(short port_no)
{
struct igmp_snoop_mac_group * _mac_group;
struct igmp_snoop_group * _group;
_mac_group = igmp_snoop_mac_list;
while(_mac_group)
{
_group = _mac_group->igmp_snoop_group_list;
while(_group)
{
router_port_add_to_every_group(_group,port_no,_mac_group->VID);
_group = _group->isgnext;
}
_mac_group = _mac_group->ismnext;
}
}
*/
/*BEGIN_PARSE_ALL_GROUP_PORT*/
#define BEGIN_PARSE_ALL_GROUP_PORT(port_no) { struct igmp_snoop_mac_group * _mac_group; struct igmp_snoop_group * _group;_mac_group = igmp_snoop_mac_list;while(_mac_group)\
{ _group = _mac_group->igmp_snoop_group_list; while(_group) {
#define END_PARSE_ALL_GROUP_PORT(port_no) _group = _group->isgnext;}_mac_group = _mac_group->ismnext;}}
/*
*time out type (temporary defined here,maybe it need some modification)
*/
#define ROUTER_TIME_OUT 1
#define GROUP_TIME_OUT 2
#define ROUTER_V1_TIME_OUT 3
#define GROUP_V1_TIME_OUT 4
#define OTHER_ROUTER_TIME_OUT 5
#define GENERAL_QEURY_10S_TIMEOUT 6
/*#define IGMP_MTRACE_RESP 7
* #define IGMP_MTRACE 8
*/
#define IGMP_MINLEN 8
#define IGMP_SNOOP_MAX_MSGS 50 /*temporary 10*/
/* Macro to map an IP multicast address to an Ethernet multicast address.
* The high-order 25 bits of the Ethernet address are statically assigned,
* and the low-order 23 bits are taken from the low end of the IP address.
*/
#define IGMP_ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
/* struct in_addr *ipaddr; */ \
/* u_char enaddr[ETHER_ADDR_LEN]; */ \
{ \
(enaddr)[0] = 0x01; \
(enaddr)[1] = 0x00; \
(enaddr)[2] = 0x5e; \
(enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
(enaddr)[4] = ((u_char *)ipaddr)[2]; \
(enaddr)[5] = ((u_char *)ipaddr)[3]; \
}
/*
* Macro to map an IP6 multicast address to an Ethernet multicast address.
* The high-order 16 bits o the low end of the IP6 adf the Ethernet address are statically assigned,
* and the low-order 32 bits are taken fromdress.
*/
#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \
/* struct in6_addr *ip6addr; */ \
/* u_char enaddr[ETHER_ADDR_LEN]; */ \
{ \
(enaddr)[0] = 0x33; \
(enaddr)[1] = 0x33; \
(enaddr)[2] = ((u_char *)ip6addr)[12]; \
(enaddr)[3] = ((u_char *)ip6addr)[13]; \
(enaddr)[4] = ((u_char *)ip6addr)[14]; \
(enaddr)[5] = ((u_char *)ip6addr)[15]; \
}
/*
* Message types, including version number.
*/
#define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */
#define IGMP_V1_MEMBERSHIP_REPORT 0x12 /* Ver. 1 membership report */
#define IGMP_V2_MEMBERSHIP_REPORT 0x16 /* Ver. 2 membership report */
#define IGMP_V2_LEAVE_GROUP 0x17 /* Leave-group message */
/*
*#define IGMP_DVMRP 0x13 DVMRP routing message
*#define IGMP_PIM 0x14 PIM routing message
#define IGMP_MTRACE_RESP 0x1e traceroute resp.(to sender)
#define IGMP_MTRACE 0x1f mcast traceroute messages
#define IGMP_MAX_HOST_REPORT_DELAY 10 max delay for response to
query (in seconds) according to RFC1112
*/
/*
* States for IGMPv2's leave processing
*/
/*
* #define IGMP_OTHERMEMBER 0
* #define IGMP_IREPORTEDLAST 1
*/
#define IGMP_TIMER_SCALE 10 /* denotes that the igmp code field */
/* specifies time in 10th of seconds*/
/*
*Multicast groups of known
*/
#define M_PIMV1_ROUTERS_GROUP 224.0.0.2
#define M_PIMV2_ROUTERS_GROUP 224.0.0.13
#define M_DVMRP_ROUTERS_GROUP 224.0.0.4
#define M_MOSPF_ROUTERS_GROUP 224.0.0.5
#define M_MOSPF_DESIGNED_ROUTERS_GROUP 224.0.0.6
#define M_IGMP_MEMBERSHIP_ROUTERS_GROUP 224.0.0.1
/*
*the timer for router and group
*/
/*#define TASK_TIMER_NOTIFY 0x0505 This is for task notify message*/
#define IGMP_SNOOP_RECV_PKT 0x0506 /*This is for igmp snoop pkt notify message,temporarilay defined here*/
/*function declaration*/
int igmp_snoop_main (int argc, char **argv);
int igmp_snoop_msg_read(struct thread *t);
int igmp_snoop_recv(int port_no, char *pkt, int len, int VID);
struct igmp_snoop_group *igmp_snoop_group_find(struct igmp_snoop_mac_group *igmp_snoop_mac_to_join, __u32 group_to_find );
struct igmp_snoop_group *igmp_snoop_group_add(struct igmp_snoop_mac_group *igmp_snoop_mac_to_join, unsigned int new_group) ;
int add_each_router_port_to_group(struct igmp_snoop_mac_group *_mac_group,struct igmp_snoop_group * _group,short port_no);
int igmp_snoop_group_delete(struct igmp_snoop_mac_group *igmp_snoop_mac_to_join, unsigned int group_to_delete) ;
int igmp_snoop_group_port_delete(struct igmp_snoop_mac_group *igmp_snoop_mac_to_join, unsigned int group_addr, int port_to_delete);
struct igmp_snoop_mac_group *igmp_snoop_mac_find(int VID, unsigned char enaddr[6] ) ;
struct igmp_snoop_mac_group *igmp_snoop_mac_add(int VID, unsigned char enaddr[6]) ;
int igmp_memebership_query_process(int port_no, long timer ,int VID );
struct igmp_snoop_router_entry *igmp_snoop_router_find(int port_no_to_find,int VID);
struct igmp_snoop_router_entry *igmp_snoop_router_add(int port_no_to_add, long timer, int VID);
int igmp_snoop_mac_process(unsigned char enaddr[6], int port_no);
int router_port_timeout_process(TIMERMSG_S *msg);
int group_port_timeout_process(TIMERMSG_S *msg);
int igmp_memebership_report_process(int port_no,short ih_type, int VID, unsigned char enaddr[6], unsigned int group_addr );
int router_v1_timeout_process(TIMERMSG_S *msg);
int igmp_other_router_pkt_process(short VID,short port_no, char *pkt ,int len ,unsigned char enaddr[6],unsigned char saenaddr[6],unsigned char daenaddr[6]);
int other_router_port_timeout_process(TIMERMSG_S *msg);
int group_v1_timeout_process(TIMERMSG_S *msg);
int general_query_10s_timeout_process(TIMERMSG_S *msg);
int igmp_snoop_router_del(int port_no_to_del, int VID);
int igmp_snoop_send(short VID, short port_no, char *pkt, long len, unsigned char enaddr[6], unsigned char saenaddr[6], unsigned char daenaddr[6],unsigned char vlanhdr_for_send[4],int tag_flag);
int router_port_add_to_every_group(struct igmp_snoop_mac_group *_mac_group, struct igmp_snoop_group * _group, short port_no,short VID);
int igmp_snoop_group_list_free();
int send_query(short VID,char *pkt,long len,short from_port_no,unsigned char enaddr[6] ,unsigned char saenaddr[6],unsigned char daenaddr[6],unsigned char vlanhdr_for_send[4],int tag_flag);
/*int igmp_snoop_group_list_free();*/
#endif /* _NETINET_IGMP__SNOOP_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -