Editing
Util-vserver:SplitSharedNetworks
(section)
From Linix VServer
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== The Script == This script should be symlinked from /etc/vservers/<name>/scripts/(initialiaze,prepre-start...).d . <PRE> function createMacVidId() { ( printf "02" printf "%04x" $1 # I usually use VID printf "%04x" $S_CONTEXT printf "%02x" $2 # IFACE number f.i. )| sed 's/\(..\)\(..\)\(..\)\(..\)\(..\)\(..\)/\1:\2:\3:\4:\5:\6/' } function usesipnetns() { local netspace if [ -s "$VSERVER_DIR/spaces/net" ] then read netspace < "$VSERVER_DIR/spaces/net" [ "$netspace" = "$VSERVER_NAME" ] return $? fi return 1 } case "${1}" in initialize) if usesipnetns then _HIP="$_IP" _IP="$_HIP netns exec ${2} $_HIP" $_HIP netns add ${2} $_IP link set dev lo up fi ;; prepre-start) if usesipnetns then $_HIP link add link eth0 name fw-vlan2 type vlan id 2 $_HIP link set dev fw-vlan2 address $(createMacVidId 2 0) $_HIP link set dev fw-vlan2 netns ${2} $_HIP netns exec ${2} $_VPROCUNHIDE fi ;; # By now all options are generated, time to override them pre-start) # NICE_CMD=(/sbin/ip netns exec ${2} "${NICE_CMD[@]}") if usesipnetns then local index local NEWVSPACE_CMDS declare -a NEWVSPACE_CMDS index=0; while [ $index -lt ${#VSPACE_SHARED_CMD[@]} ] do if [ "${VSPACE_SHARED_CMD[$((${index}+0))]}" = "$_VSPACE" ] && [ "${VSPACE_SHARED_CMD[$((${index}+1))]}" = "--enter" ] && [ "${VSPACE_SHARED_CMD[$((${index}+2))]}" = "${2}" ] && [ "${VSPACE_SHARED_CMD[$((${index}+3))]}" = "--net" ] then NEWSPACE_CMDS=("${NEWSPACE_CMDS[@]}" $_HIP netns exec "$2") index=$(($index+5)) else NEWSPACE_CMDS=("${NEWSPACE_CMDS[@]}" "${VSPACE_SHARED_CMD[$index]}") index=$(($index+1)) fi done VSPACE_SHARED_CMD=("${NEWSPACE_CMDS[@]}") unset NEWVSPACE_CMDS unset index fi ;; post-start) ;; pre-stop) if usesipnetns then _HIP=_IP _IP="$_HIP netns exec ${2} $_HIP" $_HIP netns add ${2} $_IP link set dev lo up fi ;; post-stop) $_IP link del fw-vlan2 $_HIP netns delete ${2} ;; esac </PRE>
Summary:
Please note that all contributions to Linix VServer may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Linix VServer:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Page actions
Page
Discussion
Read
Edit
History
Page actions
Page
Discussion
More
Tools
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
About
Overview
Paper
News
Developers
Donations
Search
Getting Started
Downloads
FAQs
Documentation
Support
Participate
How to participate
Report a Bug
Communicate
Teams/Projects
Hall of Fame
Resources
Archives
Recent Wiki Changes
Pastebin
Related Projects
VServer Hosting
Happy VServer Users
Tools
What links here
Related changes
Special pages
Page information