A bug fix for the automatic creation logic of the LOCAL_IFNAME and GUEST_IFNAME vars values.
1. Problem description
Pipework always automatically computes the value of the $GUEST_IFNAME var. This var is used to define the name of the guest interface before it's added to the guest's NS and it's subsequently renamed to the value of the $CONTAINER_IFNAME. The actual value is computed as follow:
- GUEST_IFNAME=v${CONTAINER_IFNAME}pg${NSPID} if the IFTYPE is "bridge"
- GUEST_IFNAME=ph$NSPID$CONTAINER_IFNAME if the $IFTYPE is "phys"
- GUEST_IFNAME=du$NSPID$CONTAINER_IFNAME if the $IFTYPE is "dummy"
However, specifying a long but valid $CONTAINER_IFNAME (up to i.e. IF_NAMSIZ chars in linux) does rise and error, because the concatenated string for the $GUEST_IFNAME var will be then larger than the maximum allowed value (again IF_NAMSIZ in the linux case).
The same issue arises in this scenario if a -i option isn't passed to pipework to specify a valid $LOCAL_IFNAME, as the value for this var is computed in the exact same way described above (using "pg" instead of "pl" in the concatenated string)
2. Example
# pipework br_pub_5 -i pub_lan_7 base 192.168.4.27/24
Error: argument "vpub_lan_7pl28223" is wrong: "name" too long
3. Fix
To fix this issue, the algorith to compute the value of $GUEST_IFNAME and $LOCAL_IFNAME has been modified in this way:
- a $IF_NAME_MAX_SIZE constant is added to the script to define the max size for a valid network interface name. I'm unaware of a multi-platform, reliable way to autodetect this value, so I've used a constant to store it
- the name of the interface is computed as: veth${NSPID}_${RANDOM_STRING} for the $LOCAL_IFNAME var (if -i isn't specified)
- the name of the interface is computed as: teth${NSPID}_${RANDOM_STRING} for the $GUEST_IFNAME var
- in both cases, the lenght of $LOCAL_IFNAME and $GUEST_IFNAME will be guaranteed lower than the $IF_NAME_MAX_SIZE
4. ToDo
The $GUEST_IFNAME var is automatically computed also if the $IFTYPE var is "ipoib". The same issue could potentially arise if $IFNAME is as long as IF_NAMSIZ, as the $GUEST_IFNAME is computed longer than $IFTYPE. However I'm unsure about the interface naming requirements for this networking layer and cannot test it. So this case should be checked and the automatic value should be computed accordingly