001-Send-IGMP-packets-with-IP-Router-Alert-option-RFC-21.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. src/igmp.c | 17 ++++++++++++-----
  7. src/igmpproxy.h | 1 +
  8. 2 files changed, 13 insertions(+), 5 deletions(-)
  9. diff --git a/src/igmp.c b/src/igmp.c
  10. index a0cd27d..b547688 100644
  11. --- a/src/igmp.c
  12. +++ b/src/igmp.c
  13. @@ -67,7 +67,7 @@ void initIgmp() {
  14. * - Checksum (let the kernel fill it in)
  15. */
  16. ip->ip_v = IPVERSION;
  17. - ip->ip_hl = sizeof(struct ip) >> 2;
  18. + ip->ip_hl = (sizeof(struct ip) + 4) >> 2; /* +4 for Router Alert option */
  19. ip->ip_tos = 0xc0; /* Internet Control */
  20. ip->ip_ttl = MAXTTL; /* applies to unicasts only */
  21. ip->ip_p = IPPROTO_IGMP;
  22. @@ -213,7 +213,7 @@ void buildIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, i
  23. ip = (struct ip *)send_buf;
  24. ip->ip_src.s_addr = src;
  25. ip->ip_dst.s_addr = dst;
  26. - ip_set_len(ip, MIN_IP_HEADER_LEN + IGMP_MINLEN + datalen);
  27. + ip_set_len(ip, IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen);
  28. if (IN_MULTICAST(ntohl(dst))) {
  29. ip->ip_ttl = curttl;
  30. @@ -221,13 +221,20 @@ void buildIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, i
  31. ip->ip_ttl = MAXTTL;
  32. }
  33. - igmp = (struct igmp *)(send_buf + MIN_IP_HEADER_LEN);
  34. + /* Add Router Alert option */
  35. + ((u_char*)send_buf+MIN_IP_HEADER_LEN)[0] = IPOPT_RA;
  36. + ((u_char*)send_buf+MIN_IP_HEADER_LEN)[1] = 0x04;
  37. + ((u_char*)send_buf+MIN_IP_HEADER_LEN)[2] = 0x00;
  38. + ((u_char*)send_buf+MIN_IP_HEADER_LEN)[3] = 0x00;
  39. +
  40. + igmp = (struct igmp *)(send_buf + IP_HEADER_RAOPT_LEN);
  41. igmp->igmp_type = type;
  42. igmp->igmp_code = code;
  43. igmp->igmp_group.s_addr = group;
  44. igmp->igmp_cksum = 0;
  45. igmp->igmp_cksum = inetChksum((u_short *)igmp,
  46. - IGMP_MINLEN + datalen);
  47. + IP_HEADER_RAOPT_LEN + datalen);
  48. +
  49. }
  50. /*
  51. @@ -257,7 +264,7 @@ void sendIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, in
  52. #endif
  53. sdst.sin_addr.s_addr = dst;
  54. if (sendto(MRouterFD, send_buf,
  55. - MIN_IP_HEADER_LEN + IGMP_MINLEN + datalen, 0,
  56. + IP_HEADER_RAOPT_LEN + IGMP_MINLEN + datalen, 0,
  57. (struct sockaddr *)&sdst, sizeof(sdst)) < 0) {
  58. if (errno == ENETDOWN)
  59. my_log(LOG_ERR, errno, "Sender VIF was down.");
  60. diff --git a/src/igmpproxy.h b/src/igmpproxy.h
  61. index 0de7791..4df8a79 100644
  62. --- a/src/igmpproxy.h
  63. +++ b/src/igmpproxy.h
  64. @@ -64,6 +64,7 @@
  65. #define MAX_IP_PACKET_LEN 576
  66. #define MIN_IP_HEADER_LEN 20
  67. #define MAX_IP_HEADER_LEN 60
  68. +#define IP_HEADER_RAOPT_LEN 24
  69. #define MAX_MC_VIFS 32 // !!! check this const in the specific includes
  70. --
  71. 1.7.2.5