added initial l2 mode support

This commit is contained in:
kashapovd 2021-11-01 10:55:27 +00:00
parent 84274bc0fd
commit 40b2bcbebb
7 changed files with 90 additions and 4 deletions

View File

@ -13,6 +13,11 @@
| link_start_ip_addr | Начальный адрес линков (192.168.56.2)
| link_ip_mask | Маска линков (255.255.255.252)
| ext_iface | Внешний интерфейс (eth0)
| stcp_level | Сетевой уровень, на котором работает сервер {(l3), l2}
| l2_bridge_name | Имя сетевого моста для уровня L2 (br_l2)
| l2_bridge_ipaddr | IP-адрес сетевого моста (10.100.0.1)
| l2_bridge_ipmask | IP-маска сетевого моста (255.255.255.0)
| l2_iface | Интерфейс, который включается в сетевой мост помимо stcp-tap (eth1)
| stcp_mode | Режим работы STCP-сервера {tun, tap, (tuntap)}
| stcp_runas | Имя пользователя, от которого запускается сервер
| run_stcp | Стартовать ли сервер после деплоя {(yes), no}

View File

@ -4,6 +4,7 @@ stcp_base_dir: /opt/stcp
stcp_binary_path: '{{stcp_base_dir}}/multi_srv_raw'
stcp_instance_name: '{{ server_port }}_{{ server_port + links_number-1 }}'
stcp_instance_dir: '{{ stcp_base_dir }}/{{ stcp_instance_name }}'
stcp_scripts_dir: '{{ stcp_instance_dir }}/scripts'
loop_script_path: '{{stcp_base_dir}}/loop'
init_scripts_dir: /etc/init.d
clients_log_file_path: '{{ stcp_instance_dir }}/logc'

View File

@ -27,7 +27,8 @@
state: link
- block:
- stat:
- name: Checking logging file existence
stat:
path: '{{ clients_log_file_path }}'
register: file
- name: Creating STCP logging file
@ -38,7 +39,8 @@
when: use_client_logging == true and not file.stat.exists
- block:
- stat:
- name: Checking users file existence
stat:
path: '{{ users_file_path }}'
register: file
- name: Creating STCP users file
@ -52,4 +54,20 @@
template:
src: server.ini.j2
dest: '{{ stcp_instance_dir }}/server.ini'
mode: '0600'
mode: '0600'
- block:
- file:
path: '{{ stcp_scripts_dir }}'
state: directory
mode: '0600'
- name: Templating L2 scripts
template:
src: up.j2
dest: '{{ stcp_scripts_dir }}/up.sh'
mode: '0700'
- template:
src: down.j2
dest: '{{ stcp_scripts_dir }}/down.sh'
mode: '0700'
when: stcp_level|lower == "l2"

View File

@ -0,0 +1,18 @@
#!/bin/bash
BRIDGE="{{ l2_bridge_name }}"
BRCTL=`which brctl`
IP=`which ip`
BRIDGE_ADDR="{{ l2_bridge_ipaddr }}/{{ l2_bridge_ipmask }}"
L2_EXT_IF="{{ l2_iface }}"
L2_STCP="{{ tap_iface_name }}"
# Bring links DOWN
${IP} link set dev ${L2_EXT_IF} down
${IP} link set dev ${L2_STCP} down
${IP} link set dev ${BRIDGE} down
# Remove bridge
${BRCTL} delbr ${BRIDGE}

View File

@ -3,16 +3,28 @@ link {{ internal_links_name }}{{ server_port + i }} {{ link_start_ip_addr | ipma
{% endfor %}
{% if stcp_mode == "tap" %}
{% if stcp_level|lower == "l2" %}
tap {{ tap_iface_name }}
{% else %}
tap {{ tap_iface_name }} {{ tap_iface_ip_addr }} {{ tap_iface_ip_mask }}
{% endif %}
{% endif %}
{% if stcp_mode == "tun" %}
tun {{ tun_iface_name }} {{ tun_iface_ip_addr }} {{ tun_iface_ip_mask }}
{% endif %}
{% if stcp_mode == "tuntap" or stcp_mode == "taptun" %}
tap {{ tap_iface_name }} {{ tap_iface_ip_addr }} {{ tap_iface_ip_mask }}
tun {{ tun_iface_name }} {{ tun_iface_ip_addr }} {{ tun_iface_ip_mask }}
{% if stcp_level|lower == "l2" %}
tap {{ tap_iface_name }}
{% else %}
tap {{ tap_iface_name }} {{ tap_iface_ip_addr }} {{ tap_iface_ip_mask }}
{% endif %}
{% endif %}
{% if stcp_level|lower == "l2" %}
ifup {{ stcp_scripts_dir }}/up.sh
ifdown {{ stcp_scripts_dir }}/down.sh
{% endif %}
{% if split_tcp_sessions is defined %}
SPLIT_TCP_SESSIONS {{ split_tcp_sessions }}
{% endif %}

View File

@ -0,0 +1,25 @@
#!/bin/bash
BRIDGE="{{ l2_bridge_name }}"
BRCTL=`which brctl`
IP=`which ip`
BRIDGE_ADDR="{{ l2_bridge_ipaddr }}/{{ l2_bridge_ipmask }}"
L2_EXT_IF="{{ l2_iface }}"
L2_STCP="{{ tap_iface_name }}"
# Create bridge
${BRCTL} addbr ${BRIDGE}
# Assign address to the bridge - for debug purposes
${IP} address add ${BRIDGE_ADDR} dev ${BRIDGE}
# Put corresponding interfaces to the bridge
${IP} link set dev ${L2_EXT_IF} master ${BRIDGE}
${IP} link set dev ${L2_STCP} master ${BRIDGE}
# Bring links UP
${IP} link set dev ${L2_EXT_IF} up
${IP} link set dev ${L2_STCP} up
${IP} link set dev ${BRIDGE} up

View File

@ -11,7 +11,14 @@ use_auth: no
use_client_logging: yes
run_stcp: yes
stcp_level: l3
stcp_mode: tuntap
l2_bridge_name: br_l2
l2_bridge_ipaddr: 10.100.0.1
l2_bridge_ipmask: 255.255.255.0
l2_iface: eth1
#stcp_tuntaps
tap_iface_name: 'tap_{{ stcp_instance_name }}'
tap_iface_ip_addr: 10.10.1.1