[lxc-devel] [PATCH] lxc-alpine: autodetect standard bridges and set hwaddress

Stéphane Graber stgraber at ubuntu.com
Mon Feb 18 20:58:59 UTC 2013


On 02/13/2013 10:30 AM, Serge Hallyn wrote:
> Quoting Natanael Copa (ncopa at alpinelinux.org):
>> Check for lxcbr0, virbr0 and br0 and use one of those if they exist.
>>
>> Set mac address if network type is veth.
>>
>> Signed-off-by: Natanael Copa <ncopa at alpinelinux.org>
> 
> Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

Pushed to staging. Thanks

>> ---
>>  templates/lxc-alpine.in | 38 +++++++++++++++++++++++++++++---------
>>  1 file changed, 29 insertions(+), 9 deletions(-)
>>
>> diff --git a/templates/lxc-alpine.in b/templates/lxc-alpine.in
>> index b06215f..962d274 100644
>> --- a/templates/lxc-alpine.in
>> +++ b/templates/lxc-alpine.in
>> @@ -76,7 +76,36 @@ copy_configuration() {
>>      if [ -n "$lxc_arch" ]; then
>>          echo "lxc.arch = $lxc_arch" >> $path/config
>>      fi
>> +
>> +    lxc_network_link_line="# lxc.network.link = br0"
>> +    for br in lxcbr0 virbr0 br0; do
>> +        if [ -d /sys/class/net/$br/bridge ]; then
>> +            lxc_network_link_line="lxc.network.link = $br"
>> +            break
>> +        fi
>> +    done
>> +
>> +    if ! grep -q "^lxc.network.type" $path/config 2>/dev/null; then
>> +        cat <<EOF >> $path/config
>> +lxc.network.type = veth
>> +$lxc_network_link_line
>> +lxc.network.flags = up
>> +EOF
>> +    fi
>> +
>> +    # if there is exactly one veth network entry, make sure it has an
>> +    # associated mac address.
>> +    nics=$(grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l)
>> +    if [ "$nics" -eq 1 ] && ! grep -q "^lxc.network.hwaddr" $path/config; then
>> +        # see http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303
>> +        hwaddr="fe:$(dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \
>> +                      head -1 |awk '{print $2}' | cut -c1-10 |\
>> +                      sed 's/\(..\)/\1:/g; s/.$//')"
>> +        echo "lxc.network.hwaddr = $hwaddr" >> $path/config
>> +    fi
>> +
>>      cat <<EOF >> $path/config
>> +
>>  lxc.tty = 4
>>  lxc.pts = 1024
>>  lxc.utsname = $hostname
>> @@ -84,15 +113,6 @@ lxc.utsname = $hostname
>>  # When using LXC with apparmor, uncomment the next line to run unconfined:
>>  #lxc.aa_profile = unconfined
>>  
>> -# network interface
>> -lxc.network.name = eth0
>> -lxc.network.type = veth
>> -lxc.network.flags = up
>> -# enable for bridging
>> -#lxc.network.link = br0
>> -#lxc.network.ipv4 = n.n.n.n
>> -#lxc.network.ipv4.gateway = auto
>> -
>>  # devices
>>  lxc.cgroup.devices.deny = a
>>  # /dev/null and zero
>> -- 
>> 1.8.1.2
>>
>>
>> ------------------------------------------------------------------------------
>> Free Next-Gen Firewall Hardware Offer
>> Buy your Sophos next-gen firewall before the end March 2013 
>> and get the hardware for free! Learn more.
>> http://p.sf.net/sfu/sophos-d2d-feb
>> _______________________________________________
>> Lxc-devel mailing list
>> Lxc-devel at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/lxc-devel
> 
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013 
> and get the hardware for free! Learn more.
> http://p.sf.net/sfu/sophos-d2d-feb
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
> 


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 901 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130218/a2c09fce/attachment.pgp>


More information about the lxc-devel mailing list