Mcast platform

This commit is contained in:
Sukru Senli 2023-02-01 11:46:10 +00:00
parent 116b9c4e70
commit 28fa1ed6f9
8 changed files with 158 additions and 147 deletions

View file

@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=mcastmngr
PKG_VERSION:=1.0.2
PKG_VERSION:=1.1.0
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
@ -16,8 +16,9 @@ PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
define Package/mcastmngr
CATEGORY:=Utilities
TITLE:=multicast packets manager daemon
CATEGORY:=Utilities
TITLE:=Multicast Proxy/Snooping Manager
DEPENDS:=+!TARGET_brcmbca:mcproxy
endef
define Package/mcastmngr/description
@ -32,7 +33,12 @@ define Build/Compile
endef
define Package/mcastmngr/install
$(CP) ./files/* $(1)/
$(CP) ./files/common/* $(1)/
ifneq ($(CONFIG_TARGET_brcmbca),)
$(CP) ./files/broadcom/* $(1)/
else
$(CP) ./files/linux/* $(1)/
endif
endef
$(eval $(call BuildPackage,mcastmngr))

View file

@ -420,128 +420,3 @@ configure_mcast() {
configure_mcpd
}
read_mcast_stats() {
cat /proc/net/igmp_snooping > /tmp/igmp_stats
local mcast_addrs=""
local ifaces=""
while read line; do
# reading each line
case $line in
br-*)
found_iface=0
snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')"
if [ -z "$ifaces" ]; then
ifaces="$snoop_iface"
continue
fi
IFS=" "
for ifx in $ifaces; do
if [ $ifx == $snoop_iface ]; then
found_iface=1
break
fi
done
if [ $found_iface -eq 0 ]; then
ifaces="$ifaces $snoop_iface"
continue
fi
;;
esac
done < /tmp/igmp_stats
while read line; do
# reading each line
case $line in
br-*)
found_ip=0
grp_ip="$(echo $line | awk -F ' ' '{ print $10 }')"
if [ -z "$mcast_addrs" ]; then
mcast_addrs="$grp_ip"
continue
fi
IFS=" "
for ip_addr in $mcast_addrs; do
if [ $ip_addr == $grp_ip ]; then
found_ip=1
break
fi
done
if [ $found_ip -eq 0 ]; then
mcast_addrs="$mcast_addrs $grp_ip"
continue
fi
;;
esac
done < /tmp/igmp_stats
json_init
json_add_array "snooping"
json_add_object ""
IFS=" "
for intf in $ifaces; do
while read line; do
# reading each line
case $line in
br-*)
snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')"
if [ "$snoop_iface" != "$intf" ]; then
continue
fi
json_add_string "interface" "$intf"
json_add_array "groups"
break
;;
esac
done < /tmp/igmp_stats
IFS=" "
for gip_addr in $mcast_addrs; do
grp_obj_added=0
while read line; do
# reading each line
case $line in
br-*)
snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')"
if [ "$snoop_iface" != "$intf" ]; then
continue
fi
grp_ip="$(echo $line | awk -F ' ' '{ print $10 }')"
if [ "$grp_ip" != "$gip_addr" ]; then
continue
fi
if [ $grp_obj_added -eq 0 ]; then
json_add_object ""
gip="$(ipcalc.sh $gip_addr | grep IP | awk '{print substr($0,4)}')"
json_add_string "groupaddr" "$gip"
json_add_array "clients"
grp_obj_added=1
fi
json_add_object ""
host_ip="$(echo $line | awk -F ' ' '{ print $14 }')"
h_ip="$(ipcalc.sh $host_ip | grep IP | awk '{print substr($0,4)}')"
json_add_string "ipaddr" "$h_ip"
src_port="$(echo $line | awk -F ' ' '{ print $2 }')"
json_add_string "device" "$src_port"
timeout="$(echo $line | awk -F ' ' '{ print $15 }')"
json_add_int "timeout" "$timeout"
json_close_object #close the associated device object
;;
esac
done < /tmp/igmp_stats
json_close_array #close the associated devices array
json_close_object # close the groups object
done # close the loop for group addresses
json_close_array #close the groups array
done # close the loop for interfaces
json_close_object # close the snooping object
json_close_array # close the snooping array
json_dump
rm -f /tmp/igmp_stats
}

View file

@ -0,0 +1,142 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
read_mcast_stats() {
cat /proc/net/igmp_snooping > /tmp/igmp_stats
local mcast_addrs=""
local ifaces=""
while read line; do
# reading each line
case $line in
br-*)
found_iface=0
snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')"
if [ -z "$ifaces" ]; then
ifaces="$snoop_iface"
continue
fi
IFS=" "
for ifx in $ifaces; do
if [ $ifx == $snoop_iface ]; then
found_iface=1
break
fi
done
if [ $found_iface -eq 0 ]; then
ifaces="$ifaces $snoop_iface"
continue
fi
;;
esac
done < /tmp/igmp_stats
while read line; do
# reading each line
case $line in
br-*)
found_ip=0
grp_ip="$(echo $line | awk -F ' ' '{ print $10 }')"
if [ -z "$mcast_addrs" ]; then
mcast_addrs="$grp_ip"
continue
fi
IFS=" "
for ip_addr in $mcast_addrs; do
if [ $ip_addr == $grp_ip ]; then
found_ip=1
break
fi
done
if [ $found_ip -eq 0 ]; then
mcast_addrs="$mcast_addrs $grp_ip"
continue
fi
;;
esac
done < /tmp/igmp_stats
json_init
json_add_array "snooping"
json_add_object ""
IFS=" "
for intf in $ifaces; do
while read line; do
# reading each line
case $line in
br-*)
snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')"
if [ "$snoop_iface" != "$intf" ]; then
continue
fi
json_add_string "interface" "$intf"
json_add_array "groups"
break
;;
esac
done < /tmp/igmp_stats
IFS=" "
for gip_addr in $mcast_addrs; do
grp_obj_added=0
while read line; do
# reading each line
case $line in
br-*)
snoop_iface="$(echo $line | awk -F ' ' '{ print $1 }')"
if [ "$snoop_iface" != "$intf" ]; then
continue
fi
grp_ip="$(echo $line | awk -F ' ' '{ print $10 }')"
if [ "$grp_ip" != "$gip_addr" ]; then
continue
fi
if [ $grp_obj_added -eq 0 ]; then
json_add_object ""
gip="$(ipcalc.sh $gip_addr | grep IP | awk '{print substr($0,4)}')"
json_add_string "groupaddr" "$gip"
json_add_array "clients"
grp_obj_added=1
fi
json_add_object ""
host_ip="$(echo $line | awk -F ' ' '{ print $14 }')"
h_ip="$(ipcalc.sh $host_ip | grep IP | awk '{print substr($0,4)}')"
json_add_string "ipaddr" "$h_ip"
src_port="$(echo $line | awk -F ' ' '{ print $2 }')"
json_add_string "device" "$src_port"
timeout="$(echo $line | awk -F ' ' '{ print $15 }')"
json_add_int "timeout" "$timeout"
json_close_object #close the associated device object
;;
esac
done < /tmp/igmp_stats
json_close_array #close the associated devices array
json_close_object # close the groups object
done # close the loop for group addresses
json_close_array #close the groups array
done # close the loop for interfaces
json_close_object # close the snooping object
json_close_array # close the snooping array
json_dump
rm -f /tmp/igmp_stats
}
case "$1" in
list)
echo '{ "stats":{} }'
;;
call)
case "$2" in
stats)
read_mcast_stats
;;
esac
;;
esac

View file

@ -0,0 +1,6 @@
#!/bin/sh
configure_mcast() {
#TODO
return 0
}

View file

@ -1,18 +0,0 @@
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
include /lib/mcast
case "$1" in
list)
echo '{ "stats":{} }'
;;
call)
case "$2" in
stats)
read_mcast_stats
;;
esac
;;
esac