| 1 | /* |
|---|
| 2 | * igmp.c |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2007 Sebastian Gottschall <gottschall@dd-wrt.com> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | * modify it under the terms of the GNU General Public License |
|---|
| 8 | * as published by the Free Software Foundation; either version 2 |
|---|
| 9 | * of the License. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | * |
|---|
| 20 | * $Id: |
|---|
| 21 | */ |
|---|
| 22 | #ifdef HAVE_MULTICAST |
|---|
| 23 | #include <stdlib.h> |
|---|
| 24 | #include <bcmnvram.h> |
|---|
| 25 | #include <shutils.h> |
|---|
| 26 | #include <utils.h> |
|---|
| 27 | #include <syslog.h> |
|---|
| 28 | #include <signal.h> |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | int |
|---|
| 32 | start_igmp_proxy (void) |
|---|
| 33 | { |
|---|
| 34 | int ret = 0; |
|---|
| 35 | pid_t pid; |
|---|
| 36 | char name[80], *next, *svbuf; |
|---|
| 37 | char *argv[] = { "igmprt", NULL }; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | stop_igmp_proxy (); |
|---|
| 42 | int ifcount = 0; |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | FILE *fp = fopen ("/tmp/igmpproxy.conf", "wb"); |
|---|
| 46 | fprintf (fp, "quickleave\n"); |
|---|
| 47 | fprintf (fp, "phyint %s upstream ratelimit 0 threshold 1\n", |
|---|
| 48 | nvram_safe_get ("wan_iface")); |
|---|
| 49 | if (nvram_match ("block_multicast", "0")) |
|---|
| 50 | { |
|---|
| 51 | fprintf (fp, "phyint %s downstream ratelimit 0 threshold 1\n", |
|---|
| 52 | nvram_safe_get ("lan_ifname")); |
|---|
| 53 | ifcount++; |
|---|
| 54 | } |
|---|
| 55 | foreach (name, nvram_safe_get ("lan_ifnames"), next) |
|---|
| 56 | { |
|---|
| 57 | if (nvram_nmatch ("0", "%s_bridged", name) |
|---|
| 58 | && nvram_nmatch ("1", "%s_multicast", name)) |
|---|
| 59 | { |
|---|
| 60 | fprintf (fp, "phyint %s downstream ratelimit 0 threshold 1\n", |
|---|
| 61 | name); |
|---|
| 62 | ifcount++; |
|---|
| 63 | } |
|---|
| 64 | else |
|---|
| 65 | fprintf (fp, "phyint %s disabled\n", name); |
|---|
| 66 | } |
|---|
| 67 | fprintf (fp, "phyint lo disabled\n"); |
|---|
| 68 | fclose (fp); |
|---|
| 69 | if (nvram_match ("wan_proto", "disabled")) //todo: add upstream config |
|---|
| 70 | { |
|---|
| 71 | // ret = _evalpid (igmp_proxybr_argv, NULL, 0, &pid); |
|---|
| 72 | return ret; |
|---|
| 73 | } |
|---|
| 74 | else |
|---|
| 75 | { |
|---|
| 76 | if (ifcount) |
|---|
| 77 | { |
|---|
| 78 | ret = _evalpid (argv, NULL, 0, &pid); |
|---|
| 79 | syslog (LOG_INFO, |
|---|
| 80 | "igmprt : multicast daemon successfully started\n"); |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | cprintf ("done\n"); |
|---|
| 85 | return ret; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | int |
|---|
| 89 | stop_igmp_proxy (void) |
|---|
| 90 | { |
|---|
| 91 | if (pidof ("igmprt") > 0) |
|---|
| 92 | syslog (LOG_INFO, "igmprt : multicast daemon successfully stopped\n"); |
|---|
| 93 | int ret = killall ("igmprt", SIGKILL); |
|---|
| 94 | |
|---|
| 95 | cprintf ("done\n"); |
|---|
| 96 | return ret; |
|---|
| 97 | } |
|---|
| 98 | #endif |
|---|