From: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman)
To: Hongbing Wang <hongbingwang-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org>
Cc: "containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org"
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
Serge Hallyn
<serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
Subject: Re: allocate specific port range for container?
Date: Fri, 08 Nov 2013 17:41:59 -0800 [thread overview]
Message-ID: <87ppqal5aw.fsf@xmission.com> (raw)
In-Reply-To: <1383959661.2417.YahooMailNeo-abza1nB0wQvuQS8rMknbopOW+3bF1jUfVpNB7YpNyf8@public.gmane.org> (Hongbing Wang's message of "Fri, 8 Nov 2013 17:14:21 -0800 (PST)")
Hongbing Wang <hongbingwang-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> writes:
Eric W. Biederman <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org> writes:
> > I have been working on this recently.
> >
> > I have recently made ip_local_port range per netns to help support
> > this.
>
> [HB] That is exactly what I am looking for! Do u have any plan to
> open-source your work?
Baring typos this is it. In due course the code should will also appear
in Mesos.
Before you run this make certain to look and discover the environment
variables you need to set.
linkaddr=$(ip -o link show dev eth0 | sed -e 's|^.*link/ether \(..:..:..:..:..:..\).*$|\1|' )
ip netns add container
ip link add veth0 type veth peer name eth0 netns container address $linkaddr
tc qdisc add dev eth0 ingress
tc filter add dev eth0 ffff: protocol u32 \
match ether dst $linkaddr \
match ip dst $ip \
match ip dport $port_start $port_mask \
action mirred egress redirect dev $netns-device
tc filter add dev eth0 parent ffff: protocol ip u32 \
match ip dst $ip \
match ip protocol 1 0xff \
action mirred egress mirror dev veth0
tc filter add dev eth0 parent ffff: protocol arp basic \
action mirred egress mirror dev veth0
tc filter add dev lo parent ffff: protocol u32 \
match ip dst $ip \
match ip dport $port_start $port_mask \
action mirred egress redirect dev veth0
tc qdisc add dev veth0 ingress
tc filter add veth0 parent ffff: protocol arp basic
action mirred egress redirect dev eth0
tc filter add dev veth0 parent ffff: protocol ip u32 \
match ip protocol 1 0xff \
action mirred egress redirect dev eth0
tc filter add dev veth0 parent ffff: protocol ip u32 \
match ip sport $port_start $port_mask \
action mirred egress redirect dev eth0
tc filter add dev veth0 parent ffff: protocol ip u32 \
match ip dst $ip \
match ip sport $port_start $port_mask \
action mirred egress redirect dev lo
ip netns exec container ip link set lo up
ip netns exec container tc qdisc add dev lo ingress
ip netns exec container ip link set eth0 up
ip netns exec container ip addr add ${ip}/24 dev eth0
ip netns exec container sysctl net.ipv4.ip_local_port_range="$port_start $port_end"
ip netns exec container tc filter add dev lo parent ffff: protocol ip u32 \
match ip dst $ip
action mirred egress redirect dev eth0
ip netns exec container tc filter add dev lo parent ffff: protocol ip u32 \
match ip dst $ip
match ip dport $port_start $port_mask
Eric
next prev parent reply other threads:[~2013-11-09 1:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-05 19:37 allocate specific port range for container? Hongbing Wang
[not found] ` <1383680242.61814.YahooMailNeo-abza1nB0wQv35Xbc4wGBzZOW+3bF1jUfVpNB7YpNyf8@public.gmane.org>
2013-11-05 21:53 ` Serge Hallyn
2013-11-05 22:35 ` Hongbing Wang
[not found] ` <1383690907.99487.YahooMailNeo-abza1nB0wQu2Y7dhQGSVAJOW+3bF1jUfVpNB7YpNyf8@public.gmane.org>
2013-11-06 3:36 ` Zhu Yanhai
2013-11-08 23:40 ` Eric W. Biederman
[not found] ` <87vc02qx7i.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-11-09 1:14 ` Hongbing Wang
[not found] ` <1383959661.2417.YahooMailNeo-abza1nB0wQvuQS8rMknbopOW+3bF1jUfVpNB7YpNyf8@public.gmane.org>
2013-11-09 1:41 ` Eric W. Biederman [this message]
[not found] ` <87ppqal5aw.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-11-09 1:49 ` Hongbing Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ppqal5aw.fsf@xmission.com \
--to=ebiederm-as9lmozglivwk0htik3j/w@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=hongbingwang-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org \
--cc=serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.