iptv无线桥接
9 min read

iptv无线桥接

联通宽带,光猫上有个4个端口,其中一个正常上网,另一个可以接IPTV。

  1. 通过有线连接光猫IPTV端口与机顶盒,是可以正常播放的。

  2. 通过一个TP-LINK-300N迷你无线路由器连接光猫IPTV端口,并创建一个AP,然后机顶盒连接AP也可以正常播放。

  3. 通过在主路由器上的闲置LAN口创建新的VLAN并连接到光猫IPTV端口,然后创建一个新的无线AP,并创建一个bridge接口(br-iptv)对两者进行桥接。

机顶盒可以连接AP,界面显示都正常,点播业务也可以播放,但是直播却黑屏!

这应该是IP多播出问题了。

记得openwrt文档有提到过,需要禁用multicast_snooping
https://oldwiki.archive.openwrt.org/doc/howto/udp_multicast

试着在路由器上执行
echo "0" > /sys/devices/virtual/net/br-iptv/bridge/multicast_snooping

画面还是黑的,但是有卡顿的背景声,感觉是数据不流畅。

又试着启动
echo "1" > /sys/devices/virtual/net/br-iptv/bridge/multicast_snooping

画面就正常了,可是换台不行。试了几次,发现是禁用multicast_snooping时可以换台但是卡顿,
启用multicast_snooping流畅播放但是不能换台!

然后搜索到这个,说不需要禁用snooping,而只要启用querier即可
https://unix.stackexchange.com/questions/391672/what-is-multicast-snooping-and-why-does-it-break-upnp-dlna

echo 1 > /sys/devices/virtual/net/br-iptv/bridge/multicast_querier

然后,果然就一切正常了。

原理大概是这样的,如果禁用multicast_snooping会导致大量广播数据进入wifi网络,拥堵了。启用multicast_snooping之后,却因为某种原因没有收到机顶盒发出的muticast_membership报告,所以就不会转发数据。而启用querier之后,会主动查询muticast_membership!

....

等等,第二天打开机顶盒,又黑屏了,这是什么回事?!

实际上,multicast_snooping和multicast_querier默认都是1,已经是正确设置了!

如果每次机顶盒打开之后,都要先设置multicast_snooping为0,出画面之后,再设为1就可以了。但换台经常出问题,大概率失败,也不知道以前是怎么成功的。

。。。

一直不换台,播了半个小时之后,就可以随便换台了!原来前面是这么搞定的?

。。。

关掉机顶盒,再立即打开,也一切正常。

。。。

关机一个晚上,明天再开会怎样?

。。。

过了一段时间重新开机,果然不行。
原因跟igmp member report有关,br-iptv接口没有转发report。

查看光猫的端口
[root@PandoraBox:/root]#tcpdump -ni eth0.3 igmp
tcpdump: WARNING: eth0.3: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0.3, link-type EN10MB (Ethernet), capture size 65535 bytes

这条是multicast_querier的定时查询,没有回应
11:46:25.809495 IP 0.0.0.0 > 224.0.0.1: igmp query v2
...
下面是换台,只有离开leave,没有join,所以不会有包发过来!黑屏
11:46:32.822295 IP 10.126.98.253 > 224.0.0.2: igmp leave 239.2.1.131
11:46:41.430880 IP 10.126.98.253 > 224.0.0.2: igmp leave 239.2.1.131
11:46:42.612277 IP 10.126.98.253 > 224.0.0.2: igmp leave 239.2.1.242
11:46:43.667862 IP 10.126.98.253 > 224.0.0.2: igmp leave 239.2.1.243
11:47:43.766221 IP 10.126.98.253 > 224.0.0.2: igmp leave 239.2.1.251
...
禁用multicast_snooping,可以看到join了,画面正常了
11:49:15.747256 IP 10.126.98.253 > 239.2.1.102: igmp v2 report 239.2.1.102
11:49:19.517697 IP 10.126.98.253 > 239.2.1.102: igmp v2 report 239.2.1.102
11:49:23.867292 IP 10.126.98.253 > 239.2.1.102: igmp v2 report 239.2.1.102
...
过了一段时间,重新启用multicast_snooping,画面还是正常,而且可以正常换台
11:58:22.437686 IP 10.126.98.253 > 224.0.0.2: igmp leave 239.2.1.251
11:58:22.521208 IP 10.126.98.253 > 239.2.1.243: igmp v2 report 239.2.1.243

....

重新启动,正常

12:05:38.455466 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250
12:05:38.865149 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:05:43.406442 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:05:43.975250 IP 10.126.98.253 > 239.2.1.131: igmp v2 report 239.2.1.131
12:05:48.015228 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250
12:05:50.735182 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:05:52.655473 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250
12:05:53.535934 IP 10.126.98.253 > 239.2.1.131: igmp v2 report 239.2.1.131

从上面数据看,只要能收到report,画面就正常。否则,就黑屏。

关掉机顶盒,等几分钟,再开机。只有leave,没有join,黑屏。

[root@PandoraBox:/root]#tcpdump -ni eth0.3 igmp
12:19:15.550062 IP 10.126.98.253 > 224.0.0.2: igmp leave 231.10.23.71
12:19:17.009457 IP 0.0.0.0 > 224.0.0.1: igmp query v2
12:19:30.585364 IP 10.126.98.253 > 224.0.0.2: igmp leave 231.10.23.71

而在br-iptv上,join是有的
[root@PandoraBox:/root]#tcpdump -ni br-iptv igmp
12:18:59.628222 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250
12:19:00.558357 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:00.688523 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250
12:19:04.677832 IP 10.126.98.253 > 239.2.1.131: igmp v2 report 239.2.1.131
12:19:05.290020 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:06.597871 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:07.658097 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250
12:19:12.257920 IP 10.126.98.253 > 239.2.1.131: igmp v2 report 239.2.1.131
12:19:13.517900 IP 10.126.98.253 > 239.2.1.131: igmp v2 report 239.2.1.131
12:19:15.550103 IP 10.126.98.253 > 224.0.0.2: igmp leave 231.10.23.71
12:19:15.577927 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:15.947910 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:17.009508 IP 0.0.0.0 > 224.0.0.1: igmp query v2
12:19:18.898047 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250
12:19:24.998098 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:25.898005 IP 10.126.98.253 > 239.2.1.131: igmp v2 report 239.2.1.131
12:19:30.585400 IP 10.126.98.253 > 224.0.0.2: igmp leave 231.10.23.71
12:19:30.608025 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:31.528110 IP 10.126.98.253 > 231.10.23.71: igmp v2 report 231.10.23.71
12:19:35.548104 IP 10.126.98.253 > 239.255.255.250: igmp v2 report 239.255.255.250

。。。

现在要重新思考multicast_snooping的真正作用了,因为在当前的配置里,无线客户端只有一个机顶盒,并不需要隔离,不用担心拥堵整个网络影响别人。

禁用和启用multicast_snooping并不会导致数据增加和减少,为什么会有卡顿的区别呢?

#brctl show
bridge name bridge id STP enabled interfaces
br-iptv 7fff.2076932b9a88 no eth0.3
rai1
br-lan 7fff.2076932b9a88 no eth0.1
ra0
rai0

实际抓包,发现也只有rai1有multicast数据,ra0/rai0并没有。

。。。

也不知道从哪里看到的,试了一下

echo 2 > /sys/devices/virtual/net/eth0.3/brport/multicast_router

貌似就好了!

其默认值是1,让系统通过query来探测,这个显然失败了。现在改为2,直接表明自己连着multicast_router呢,请发multicast消息都发过来吧!

参考文档:

bridge: Add multicast_router sysfs entries

This patch allows the user to forcibly enable/disable ports as
having multicast routers attached. A port with a multicast router
will receive all multicast traffic.

The value 0 disables it completely. The default is 1 which lets
the system automatically detect the presence of routers (currently
this is limited to picking up queries), and 2 means that the port
will always receive all multicast traffic.
https://patchwork.ozlabs.org/patch/46340/

IGMP snooping
https://en.wikipedia.org/wiki/IGMP_snooping

Multicast Querier
Multicast querier is a service that sends at regular intervals multicast queries into the local network to find multicast listeners (clients). Implements IGMP for ipv4 and MLD for ipv6. Configuration done through sysfs.
sys/class/net//bridge/
multicast_querier - (default 0) send ipv4 and ipv6 multicast queries when set to 1
multicast_query_interval - (default 10000) how often to send multicast queries (in 10ms units, 1000 = 10 seconds)
multicast_query_response_interval - (default 1000) maximum interval in which the listener must respond. listeners use random timers so they won't overwhelm the switch with mld responses at the same time.
multicast_querier_interval - (default 25500) how much time to wait for a query from the current multicast querier. there should be only a single multicast querier on the network. one querier is elected to be the active one, others become passive and only send if they don't hear a multicast query from the active one within this interval.
https://wiki.wuji.cz/linux:networking:bridge

bridge: Add multicast_querier toggle and disable queries by default

Sending general queries was implemented as an optimisation to speed
up convergence on start-up. In order to prevent interference with
multicast routers a zero source address has to be used.

Unfortunately these packets appear to cause some multicast-aware
switches to misbehave, e.g., by disrupting multicast packets to us.

Since the multicast snooping feature still functions without sending
our own queries, this patch will change the default to not send
queries.

For those that need queries in order to speed up convergence on start-up,
a toggle is provided to restore the previous behaviour.

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/net/bridge/br_multicast.c?id=c5c23260594c5701af66ef754916775ba6a46bbc

bridge: allow enabling or disabling the multicast querier independently of IGMP snooping

In larger networks, especially big batman-adv meshes, it may be desirable to
enable IGMP snooping on every bridge without enabling the multicast querier
to specifically put the querier on a well-connected node.

https://patchwork.ozlabs.org/patch/433170/

IPTV / UDP multicast
netgear路由器上有一个桥接iptv流量的功能,估计是igmproxy,允许multicast穿过。
https://openwrt.org/docs/guide-user/network/wan/udp_multicast

原文时间:2019.2