Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions source/scripts/init/c_registration/16_vlan_ts.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* If not stated otherwise in this file or this component's Licenses.txt file the
* following copyright and licenses apply:
*
* Copyright 2015 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**********************************************************************
Copyright [2014] [Cisco Systems, Inc.]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
**********************************************************************/

#include <stdio.h>
#include "srvmgr.h"

const char* SERVICE_NAME = "vlan_ts";
const char* SERVICE_DEFAULT_HANDLER = "/etc/utopia/service.d/service_vlan_ts.sh";
const char* SERVICE_CUSTOM_EVENTS[] = { NULL };
/*const char* SERVICE_CUSTOM_EVENTS[] = {
"lan-status|/etc/utopia/service.d/service_xhs.sh",
"multinet_2-status|/etc/utopia/service.d/service_xhs.sh",
"ipv4_5-status|/etc/utopia/service.d/service_xhs.sh",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation to be corrected

NULL
}; */

void srv_register(void) {
printf("%s %d : START \n", __func__,__LINE__);
sm_register(SERVICE_NAME, SERVICE_DEFAULT_HANDLER, SERVICE_CUSTOM_EVENTS);
}

void srv_unregister(void) {
printf("%s %d : START \n", __func__,__LINE__);
sm_unregister(SERVICE_NAME);
}

int main(int argc, char **argv)
{
cmd_type_t choice = parse_cmd_line(argc, argv);
printf("%s %d : START \n", __func__,__LINE__);
switch(choice) {
case(nochoice):
case(start):
printf("%s %d : case start \n", __func__,__LINE__);
srv_register();
break;
case(stop):
printf("%s %d : case stop \n", __func__,__LINE__);
srv_unregister();
break;
case(restart):
printf("%s %d : case restart \n", __func__,__LINE__);
srv_unregister();
srv_register();
break;
default:
printf("%s called with invalid parameter (%s)\n", argv[0], 1==argc ? "" : argv[1]);
}
return(0);
}

4 changes: 4 additions & 0 deletions source/scripts/init/defaults/system_defaults_arm
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ $$lan_ifname=brlan0
# This setting is not meant for users to manipulate.
#$lan_ethernet_virtual_ifnums=1

+$$vlan_id_pvt =12
+$$vlan_id_mesh=13
+$$vlan_id_iot=14

# lan_ethernet_physical_ifnames - a list of names of ethernet interfaces,
# which will be enslaved into the lan bridge (which is known as lan_ifname
# as described above)
Expand Down
159 changes: 159 additions & 0 deletions source/scripts/init/service.d/service_vlan_ts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
SERVICE_NAME="vlan_ts"
source /etc/utopia/service.d/ulog_functions.sh
source /etc/utopia/service.d/ut_plat.sh


SELF_NAME="`basename "$0"`"

service_start() {
vlan_pvt=`syscfg get vlan_id_pvt`
vlan_mesh=`syscfg get vlan_id_mesh`
vlan_iot=`syscfg get vlan_id_iot`

echo "service_start : START" >> /tmp/abc.txt

ip link set brlan0 type bridge vlan_filtering 1
bridge vlan add dev wifi0 vid $vlan_pvt pvid untagged
bridge vlan add dev wifi0.1 vid $vlan_mesh pvid untagged
bridge vlan add dev wifi0.2 vid $vlan_iot pvid untagged
bridge vlan add dev wifi1 vid $vlan_pvt pvid untagged
bridge vlan add dev wifi1.1 vid $vlan_mesh pvid untagged
bridge vlan add dev wifi1.2 vid $vlan_iot pvid untagged
bridge vlan add dev wifi2 vid $vlan_pvt pvid untagged
bridge vlan add dev wifi2.1 vid $vlan_mesh pvid untagged
bridge vlan add dev wifi2.2 vid $vlan_iot pvid untagged
bridge vlan add dev mld0 vid $vlan_pvt pvid untagged

ip link add link brlan0 name brlan0.$vlan_pvt type vlan id $vlan_pvt
ip link add link brlan0 name brlan0.$vlan_mesh type vlan id $vlan_mesh
ip link add link brlan0 name brlan0.$vlan_iot type vlan id $vlan_iot

bridge vlan add dev brlan0 vid $vlan_pvt self
bridge vlan add dev brlan0 vid $vlan_mesh self
bridge vlan add dev brlan0 vid $vlan_iot self

ifconfig brlan0.$vlan_pvt 192.168.13.1 netmask 255.255.255.0 up
ifconfig brlan0.$vlan_mesh 192.168.14.1 netmask 255.255.255.0 up
ifconfig brlan0.$vlan_iot 192.168.15.1 netmask 255.255.255.0 up

iptables -I FORWARD -i brlan0.$vlan_pvt -o brlan0.$vlan_mesh -j DROP
iptables -I FORWARD -i brlan0.$vlan_mesh -o brlan0.$vlan_pvt -j DROP

iptables -I FORWARD -i brlan0.$vlan_mesh -o brlan0.$vlan_iot -j DROP
iptables -I FORWARD -i brlan0.$vlan_iot -o brlan0.$vlan_mesh -j DROP

iptables -I FORWARD -i brlan0.$vlan_pvt -o brlan0.$vlan_iot -j DROP
iptables -I FORWARD -i brlan0.$vlan_iot -o brlan0.$vlan_pvt -j DROP

iptables -I INPUT -i brlan0.$vlan_pvt -p udp --dport 67:68 -j ACCEPT
iptables -I INPUT -i brlan0.$vlan_pvt -p udp --sport 67:68 -j ACCEPT
iptables -I INPUT -i brlan0.$vlan_mesh -p udp --dport 67:68 -j ACCEPT
iptables -I INPUT -i brlan0.$vlan_mesh -p udp --sport 67:68 -j ACCEPT
iptables -I INPUT -i brlan0.$vlan_iot -p udp --dport 67:68 -j ACCEPT
iptables -I INPUT -i brlan0.$vlan_iot -p udp --sport 67:68 -j ACCEPT
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation to be checked above


echo "interface=brlan0.$vlan_pvt" >> /var/dnsmasq.conf
echo "dhcp-range=192.168.13.2,192.168.13.253,255.255.255.0,7d" >> /var/dnsmasq.conf
echo "interface=brlan0.$vlan_mesh" >> /var/dnsmasq.conf
echo "dhcp-range=192.168.14.2,192.168.14.253,255.255.255.0,7d" >> /var/dnsmasq.conf
echo "interface=brlan0.$vlan_iot" >> /var/dnsmasq.conf
echo "dhcp-range=192.168.15.2,192.168.15.253,255.255.255.0,7d" >> /var/dnsmasq.conf

killall dnsmasq
dnsmasq -P 4096 -C /var/dnsmasq.conf --dhcp-authoritative
}

service_stop () {
ip link set brlan0 type bridge vlan_filtering 1

vlan_pvt=`syscfg get vlan_id_pvt`
vlan_mesh=`syscfg get vlan_id_mesh`
vlan_iot=`syscfg get vlan_id_iot`

echo "service_stop : START " >> /tmp/abc.txt

bridge vlan del vid $vlan_pvt dev wifi0
bridge vlan del vid $vlan_mesh dev wifi0.1
bridge vlan del vid $vlan_iot dev wifi0.2
bridge vlan del vid $vlan_pvt dev wifi1
bridge vlan del vid $vlan_mesh dev wifi1.1
bridge vlan del vid $vlan_iot dev wifi1.2
bridge vlan del vid $vlan_pvt dev wifi2
bridge vlan del vid $vlan_mesh dev wifi2.1
bridge vlan del vid $vlan_iot dev wifi2.2
bridge vlan del vid $vlan_pvt dev mld0

bridge vlan del dev brlan0 vid $vlan_pvt self
bridge vlan del dev brlan0 vid $vlan_mesh self
bridge vlan del dev brlan0 vid $vlan_iot self

ip link del link brlan0 name brlan0.$vlan_pvt type vlan id $vlan_pvt
ip link del link brlan0 name brlan0.$vlan_mesh type vlan id $vlan_mesh
ip link del link brlan0 name brlan0.$vlan_iot type vlan id $vlan_iot

bridge vlan del vid 1 dev wifi0
bridge vlan del vid 1 dev wifi0.1
bridge vlan del vid 1 dev wifi02
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there seems to be a typo as wifi02, there is already wifi0.2 in the below line

bridge vlan del vid 1 dev wifi0.2
bridge vlan del vid 1 dev wifi1.2
bridge vlan del vid 1 dev wifi1.1
bridge vlan del vid 1 dev wifi1
bridge vlan del vid 1 dev wifi2
bridge vlan del vid 1 dev wifi2.1
bridge vlan del vid 1 dev wifi2.2
bridge vlan del vid 1 dev mld0

sed -i '/brlan0./d' /var/dnsmasq.conf
sed -i '/brlan0./d' /var/dnsmasq.conf
sed -i '/brlan0./d' /var/dnsmasq.conf

sed -i '/192.168.13.2/d' /var/dnsmasq.conf
sed -i '/192.168.14.2/d' /var/dnsmasq.conf
sed -i '/192.168.15.2/d' /var/dnsmasq.conf

killall dnsmasq
dnsmasq -P 4096 -C /var/dnsmasq.conf --dhcp-authoritative

iptables -D FORWARD -i brlan0.$vlan_pvt -o brlan0.$vlan_mesh -j DROP
iptables -D FORWARD -i brlan0.$vlan_mesh -o brlan0.$vlan_pvt -j DROP

iptables -D FORWARD -i brlan0.$vlan_mesh -o brlan0.$vlan_iot -j DROP
iptables -D FORWARD -i brlan0.$vlan_iot -o brlan0.$vlan_mesh -j DROP

iptables -D FORWARD -i brlan0.$vlan_pvt -o brlan0.$vlan_iot -j DROP
iptables -D FORWARD -i brlan0.$vlan_iot -o brlan0.$vlan_pvt -j DROP

iptables -D INPUT -i brlan0.$vlan_pvt -p udp --dport 67:68 -j ACCEPT
iptables -D INPUT -i brlan0.$vlan_pvt -p udp --sport 67:68 -j ACCEPT
iptables -D INPUT -i brlan0.$vlan_mesh -p udp --dport 67:68 -j ACCEPT
iptables -D INPUT -i brlan0.$vlan_mesh -p udp --sport 67:68 -j ACCEPT
iptables -D INPUT -i brlan0.$vlan_iot -p udp --dport 67:68 -j ACCEPT
iptables -D INPUT -i brlan0.$vlan_iot -p udp --sport 67:68 -j ACCEPT
}


service_init() {
echo "service_init : START " >> /tmp/abc.txt
}

#---------------------------------------------------------------

service_init

case "$1" in
start)
service_start
;;
stop)
service_stop
;;
restart)
service_stop
service_start
;;
*)
echo "Usage: $SERVICE_NAME [ start | stop | restart]" > /dev/console
exit 3
;;
esac

Loading