每弄完一次,过不多久就忘了,这次决心记下来。
openwrt 的igmpproxy 包是干嘛的?原来,组播包并不能穿透路由,也就是我们在wan端播放的组播视频流,lan端是没法收到的,igmpproxy就是用来打通wan端到lan端的数据通道。
首先在编译配置文件开启igmpproxy:
CONFIG_PACKAGE_igmpproxy=y
然后编译并打包,生成的镜像烧入板子,一般来说这个时候igmpproxy 已经能正常工作了
它的配置文件在/etc/config/igmpproxy文件中,我们只需要改一个地方:
config igmpproxyoption quickleave 1config phyint wanoption network wanoption direction upstreamlist altnet 192.168.1.0/24config phyint lanoption network lanoption direction downstream
把文中的 192.168.1.0/24 换成0.0.0.0/0,这样所有情况都适合。
怎么测试呢?
1. 可以手动执行:
igmpproxy -d -v /etc/config/igmpproxy
这样就进入了调试模式,它可以把所有调试信息打印出来,方便我们排查问题。
2. 可以在wan,lan口用tcpdump 抓包结合协议分析
最后补充两个python 的脚本,方便测试:
发送脚本,放在wan端:
import timeimport structfrom socket import *SENDERIP = '192.168.10.162' #这个地方是本机地址,你的机器是什么就填什么SENDERPORT = 1501 MYPORT = 1234 MYGROUP = '224.1.1.112' MYTTL = 255 def sender():s = socket(AF_INET, SOCK_DGRAM,IPPROTO_UDP)s.bind((SENDERIP,SENDERPORT))ttl_bin = struct.pack('@i', MYTTL)s.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, ttl_bin) while True:data = 'cisco's.sendto(data + '\0', (MYGROUP, MYPORT))print "send data ok !"time.sleep(10)if __name__ == "__main__":sender()
接收脚本,放在lan端:
import timeimport socketSENDERIP = '0.0.0.0' #这里填本机地址收不到数据,故改为全地址MYPORT = 1234MYGROUP = '224.1.1.112'def receiver():#create a UDP socketsock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)#allow multiple sockets to use the same PORT numbersock.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)#Bind to the port that we know will receive multicast datasock.bind((SENDERIP,MYPORT))#tell the kernel that we are a multicast socket#sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 255)#Tell the kernel that we want to add ourselves to a multicast group#The address for the multicast group is the third paramstatus = sock.setsockopt(socket.IPPROTO_IP,socket.IP_ADD_MEMBERSHIP,socket.inet_aton(MYGROUP) + socket.inet_aton(SENDERIP));sock.setblocking(0)#ts = time.time()while 1:try:data, addr = sock.recvfrom(1024)except socket.error, e:passelse:print "Receive data!"print "TIME:" , time.time()print "FROM: ", addrprint "DATA: ", dataif __name__ == "__main__":receiver()
有三条命令可以查看系统igmp状态: