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 "doc/mrouted-LINCESE" file. 31** 32*/ 33 34 35#include "defs.h" 36 37int curttl = 0; 38 39void k_set_rcvbuf(int bufsize, int minsize) { 40 int delta = bufsize / 2; 41 int iter = 0; 42 43 /* 44 * Set the socket buffer. If we can't set it as large as we 45 * want, search around to try to find the highest acceptable 46 * value. The highest acceptable value being smaller than 47 * minsize is a fatal error. 48 */ 49 if (setsockopt(MRouterFD, SOL_SOCKET, SO_RCVBUF, 50 (char *)&bufsize, sizeof(bufsize)) < 0) { 51 bufsize -= delta; 52 while (1) { 53 iter++; 54 if (delta > 1) 55 delta /= 2; 56 57 if (setsockopt(MRouterFD, SOL_SOCKET, SO_RCVBUF, 58 (char *)&bufsize, sizeof(bufsize)) < 0) { 59 bufsize -= delta; 60 } else { 61 if (delta < 1024) 62 break; 63 bufsize += delta; 64 } 65 } 66 if (bufsize < minsize) { 67 igmp_syslog(LOG_ERR, 0, "OS-allowed buffer size %u < app min %u", 68 bufsize, minsize); 69 /*NOTREACHED*/ 70 } 71 } 72 IF_DEBUG igmp_syslog(LOG_DEBUG, 0, "Got %d byte buffer size in %d iterations", bufsize, iter); 73} 74 75 76void k_hdr_include(int bool) { 77#ifdef IP_HDRINCL 78 if (setsockopt(MRouterFD, IPPROTO_IP, IP_HDRINCL, 79 (char *)&bool, sizeof(bool)) < 0) 80 igmp_syslog(LOG_ERR, errno, "setsockopt IP_HDRINCL %u", bool); 81#endif 82} 83 84 85void k_set_ttl(int t) { 86#ifndef RAW_OUTPUT_IS_RAW 87 u_char ttl; 88 89 ttl = t; 90 if (setsockopt(MRouterFD, IPPROTO_IP, IP_MULTICAST_TTL, 91 (char *)&ttl, sizeof(ttl)) < 0) 92 igmp_syslog(LOG_ERR, errno, "setsockopt IP_MULTICAST_TTL %u", ttl); 93#endif 94 curttl = t; 95} 96 97 98void k_set_loop(int l) { 99 u_char loop; 100 101 loop = l; 102 if (setsockopt(MRouterFD, IPPROTO_IP, IP_MULTICAST_LOOP, 103 (char *)&loop, sizeof(loop)) < 0) 104 igmp_syslog(LOG_ERR, errno, "setsockopt IP_MULTICAST_LOOP %u", loop); 105} 106 107void k_set_if(uint32 ifa) { 108 struct in_addr adr; 109 110 adr.s_addr = ifa; 111 if (setsockopt(MRouterFD, IPPROTO_IP, IP_MULTICAST_IF, 112 (char *)&adr, sizeof(adr)) < 0) 113 igmp_syslog(LOG_ERR, errno, "setsockopt IP_MULTICAST_IF %s", 114 inetFmt(ifa, s1)); 115} 116 117/* 118void k_join(uint32 grp, uint32 ifa) { 119 struct ip_mreq mreq; 120 121 mreq.imr_multiaddr.s_addr = grp; 122 mreq.imr_interface.s_addr = ifa; 123 124 if (setsockopt(MRouterFD, IPPROTO_IP, IP_ADD_MEMBERSHIP, 125 (char *)&mreq, sizeof(mreq)) < 0) 126 igmp_syslog(LOG_WARNING, errno, "can't join group %s on interface %s", 127 inetFmt(grp, s1), inetFmt(ifa, s2)); 128} 129 130 131void k_leave(uint32 grp, uint32 ifa) { 132 struct ip_mreq mreq; 133 134 mreq.imr_multiaddr.s_addr = grp; 135 mreq.imr_interface.s_addr = ifa; 136 137 if (setsockopt(MRouterFD, IPPROTO_IP, IP_DROP_MEMBERSHIP, 138 (char *)&mreq, sizeof(mreq)) < 0) 139 igmp_syslog(LOG_WARNING, errno, "can't leave group %s on interface %s", 140 inetFmt(grp, s1), inetFmt(ifa, s2)); 141} 142*/ 143