odhcpd: update hostfile more often
[openwrt-14.07/.git] / package / network / services / igmpproxy / patches / 001-Send-IGMP-packets-with-IP-Router-Alert-option-RFC-21.patch
1 From fed8c3db10bc9d3a1e799a774924c00522595d0c Mon Sep 17 00:00:00 2001
2 From: Evgeny Yurchenko <evg.yurch@rogers.com>
3 Date: Mon, 4 Jan 2010 05:13:59 +0500
4 Subject: [PATCH] Send IGMP packets with IP Router Alert option [RFC 2113] included in IP header
5
6 ---
7  src/igmp.c      |   17 ++++++++++++-----
8  src/igmpproxy.h |    1 +
9  2 files changed, 13 insertions(+), 5 deletions(-)
10
11 diff --git a/src/igmp.c b/src/igmp.c
12 index a0cd27d..b547688 100644
13 --- a/src/igmp.c
14 +++ b/src/igmp.c
15 @@ -67,7 +67,7 @@ void initIgmp() {
16       * - Checksum (let the kernel fill it in)
17       */
18      ip->ip_v   = IPVERSION;
19 -    ip->ip_hl  = sizeof(struct ip) >> 2;
20 +    ip->ip_hl  = (sizeof(struct ip) + 4) >> 2; /* +4 for Router Alert option */
21      ip->ip_tos = 0xc0;      /* Internet Control */
22      ip->ip_ttl = MAXTTL;    /* applies to unicasts only */
23      ip->ip_p   = IPPROTO_IGMP;
24 @@ -213,7 +213,7 @@ void buildIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, i
25      ip                      = (struct ip *)send_buf;
26      ip->ip_src.s_addr       = src;
27      ip->ip_dst.s_addr       = dst;
28 -    ip_set_len(ip, MIN_IP_HEADER_LEN + IGMP_MINLEN + datalen);
29 +    ip_set_len(ip, IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen);
30  
31      if (IN_MULTICAST(ntohl(dst))) {
32          ip->ip_ttl = curttl;
33 @@ -221,13 +221,20 @@ void buildIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, i
34          ip->ip_ttl = MAXTTL;
35      }
36  
37 -    igmp                    = (struct igmp *)(send_buf + MIN_IP_HEADER_LEN);
38 +    /* Add Router Alert option */
39 +    ((u_char*)send_buf+MIN_IP_HEADER_LEN)[0] = IPOPT_RA;
40 +    ((u_char*)send_buf+MIN_IP_HEADER_LEN)[1] = 0x04;
41 +    ((u_char*)send_buf+MIN_IP_HEADER_LEN)[2] = 0x00;
42 +    ((u_char*)send_buf+MIN_IP_HEADER_LEN)[3] = 0x00;
43 +
44 +    igmp                    = (struct igmp *)(send_buf + IP_HEADER_RAOPT_LEN);
45      igmp->igmp_type         = type;
46      igmp->igmp_code         = code;
47      igmp->igmp_group.s_addr = group;
48      igmp->igmp_cksum        = 0;
49      igmp->igmp_cksum        = inetChksum((u_short *)igmp,
50 -                                         IGMP_MINLEN + datalen);
51 +                                         IP_HEADER_RAOPT_LEN + datalen);
52 +
53  }
54  
55  /* 
56 @@ -257,7 +264,7 @@ void sendIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, in
57  #endif
58      sdst.sin_addr.s_addr = dst;
59      if (sendto(MRouterFD, send_buf,
60 -               MIN_IP_HEADER_LEN + IGMP_MINLEN + datalen, 0,
61 +               IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen, 0,
62                 (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
63          if (errno == ENETDOWN)
64              my_log(LOG_ERR, errno, "Sender VIF was down.");
65 diff --git a/src/igmpproxy.h b/src/igmpproxy.h
66 index 0de7791..4df8a79 100644
67 --- a/src/igmpproxy.h
68 +++ b/src/igmpproxy.h
69 @@ -64,6 +64,7 @@
70  #define MAX_IP_PACKET_LEN      576
71  #define MIN_IP_HEADER_LEN      20
72  #define MAX_IP_HEADER_LEN      60
73 +#define IP_HEADER_RAOPT_LEN    24
74  
75  #define MAX_MC_VIFS    32     // !!! check this const in the specific includes
76  
77 -- 
78 1.7.2.5
79