diff --git a/postplug.d/20network b/postplug.d/20network index cf69faf..237ef55 100644 --- a/postplug.d/20network +++ b/postplug.d/20network @@ -59,45 +59,86 @@ _EOF function cdc_usb() { local CDC_IPADDR=10.99.99.1 + local CDC_SUBNET=10.99.99.0 + local CDC_RANGE_FROM=10.99.99.100 + local CDC_RANGE_TO=10.99.99.199 + local CDC_NETMASK=255.255.255.0 ifconfig usb0 &>/dev/null && { + [ "$NETWORK_CDC_NETMASK" ] && CDC_NETMASK=$NETWORK_CDC_NETMASK [ -e $network_devices/ifcng-usb0 ] || { [ "$NETWORK_CDC_IPADDR" ] && CDC_IPADDR=$NETWORK_CDC_IPADDR cat > $network_devices/ifcfg-usb0 << _EOF DEVICE=usb0 BOOTPROTO=none IPADDR=$CDC_IPADDR +NETMASK=$CDC_NETMASK ONBOOT=yes NM_CONTROLLED=no _EOF } + [ -e /etc/dhcpd-usb0.conf ] || { + [ "$NETWORK_CDC_SUBNET" ] && CDC_SUBNET=$NETWORK_CDC_SUBNET + [ "$NETWORK_CDC_RANGE_FROM" ] && CDC_RANGE_FROM=$NETWORK_CDC_RANGE_FROM + [ "$NETWORK_CDC_RANGE_TO" ] && CDC_RANGE_TO=$NETWORK_CDC_RANGE_TO + cat > /etc/dhcpd-usb0.conf << _EOF +# Created by postplug +subnet $NETWORK_CDC_SUBNET netmask $NETWORK_CDC_NETMASK { + range dynamic-bootp $NETWORK_CDC_RANGE_FROM $NETWORK_CDC_RANGE_TO; +} +_EOF + } + ifup usb0 + touch /var/lib/dhcp/dhcpd-usb0.leases + /sbin/dhcpd -q usb0 -pf /run/dhcpd-usb0.pid -cf /etc/dhcpd-usb0.conf -lf /var/lib/dhcp/dhcpd-usb0.leases } } function android_usb() { local ANDROID_IPADDR=10.99.99.1 local ANDROID_ETHADDR=80:00:60:0F:E8:00 + local ANDROID_SUBNET=10.99.99.0 + local ANDROID_RANGE_FROM=10.99.99.100 + local ANDROID_RANGE_TO=10.99.99.199 + local ANDROID_NETMASK=255.255.255.0 # FIXME: hardcoded values if [ -e /sys/class/android_usb/android0 ]; then [ "$NETWORK_ANDROID_ETHADDR" ] && ANDROID_ETHADDR=$NETWORK_ANDROID_ETHADDR + [ "$NETWORK_ANDORID_NETMASK" ] && ANDORID_NETMASK=$NETWORK_ANDORID_NETMASK echo 0 > /sys/class/android_usb/android0/enable echo rndis,acm > /sys/class/android_usb/android0/functions echo 2 > /sys/class/android_usb/android0/f_acm/instances echo $ANDROID_ETHADDR > /sys/class/android_usb/android0/f_rndis/ethaddr echo 2d01 > /sys/class/android_usb/android0/idProduct echo 1 > /sys/class/android_usb/android0/enable - fi - [ -e $network_devices/ifcfg-rndis0 ] || { - [ "$NETWORK_ANDROID_IPADDR" ] && ANDROID_IPADDR=$NETWORK_ANDROID_IPADDR - cat > $network_devices/ifcfg-rndis0 << _EOF + + [ -e $network_devices/ifcfg-rndis0 ] || { + [ "$NETWORK_ANDROID_IPADDR" ] && ANDROID_IPADDR=$NETWORK_ANDROID_IPADDR + cat > $network_devices/ifcfg-rndis0 << _EOF DEVICE=rndis0 BOOTPROTO=none IPADDR=$ANDROID_IPADDR +NETMASK=$ANDROID_NETMASK ONBOOT=yes NM_CONTROLLED=no _EOF - } + } + [ -e /etc/dhcpd-rndis0.conf ] || { + [ "$NETWORK_ANDROID_SUBNET" ] && ANDROID_SUBNET=$NETWORK_ANDROID_SUBNET + [ "$NETWORK_ANDROID_RANGE_FROM" ] && ANDORID_RANGE_FROM=$NETWORK_ANDROID_RANGE_FROM + [ "$NETWORK_ANDROID_RANGE_TO" ] && ANDROID_RANGE_TO=$NETWORK_ANDROID_RANGE_TO + cat > /etc/dhcpd-rndis0.conf << _EOF +# Created by postplug +subnet $ANDROID_SUBNET netmask $ANDROID_NETMASK { + range dynamic-bootp $ANDROID_RANGE_FROM $ANDROID_RANGE_TO; +} +_EOF + } + ifup rndis0 + touch /var/lib/dhcp/dhcpd-rndis0.leases + /sbin/dhcpd -q rndis0 -pf /run/dhcpd-rndis0.pid -cf /etc/dhcpd-rndis0.conf -lf /var/lib/dhcp/dhcpd-rndis0.leases + fi } [ "$NETWORK_CDC_DISABLE" = "1" ] || cdc_usb diff --git a/sysconfig/postplug b/sysconfig/postplug index 24a1a5c..b7a85fb 100644 --- a/sysconfig/postplug +++ b/sysconfig/postplug @@ -31,13 +31,23 @@ FS_NO_DEV_REMOVE=yes NETWORK_NEWDEVICE=off # network parameters for CDC ethernet interface +# (default: enabled) #NETWORK_CDC_DISABLE=1 #NETWORK_CDC_IPADDR=10.99.99.1 +#NETWORK_CDC_SUBNET=10.99.99.0 +#NETWORK_CDC_RANGE_FROM=10.99.99.100 +#NETWORK_CDC_RANGE_TO=10.99.99.199 +#NETWORK_CDC_NETMASK=255.255.255.0 # network parameters for Android rndis ethernet interface +# (default: enabled) #NETWORK_ANDROID_DISABLE=1 #NETWORK_ANDROID_IPADDR=10.99.99.1 #NETWOKR_ANDROID_ETHADDR=01:02:03:04:05:06 +#NETWORK_ANDROID_SUBNET=10.99.99.0 +#NETWORK_ANDROID_RANGE_FROM=10.99.99.100 +#NETWORK_ANDROID_RANGE_TO=10.99.99.199 +#NETWORK_ANDROID_NETMASK=255.255.255.0 # xorg server: automatically add DRI section # (on/off, default: on)