rancher / old-vm

(OBSOLETE) Package and Run Virtual Machines as Docker Containers
Apache License 2.0
645 stars 133 forks source link

kvm dose not get ip #85

Closed hmodaresi closed 7 years ago

hmodaresi commented 7 years ago

Hi guys. There is a problem that KVM dose not get IP. This is the scenario: As you know KVM gets ip from dnsmasq and dhcp packets comes from br0 to dnsmasq. Now if the IP of br0 interface dose not exist in range of the lease dnsmasq gives kvm, dnsmasq dose not release the lease. read here

And also as you know there is a algorithm in startvm script which generates an IP for br0. Now the problem is that the generated IP sometimes is not in the range of KVM IP.

Look this is the code which generates IP for br0:

    let "NEWCIDR=$CIDR-1"
    #NEWNETMASK=`cidr2mask $NEWCIDR`

    i=`atoi $IP`
    let "i=$i^(1<<$CIDR)"
    NEWIP=`itoa i`

And this little change fixes anything:

    let "NEWCIDR=$CIDR-1"
    #NEWNETMASK=`cidr2mask $NEWCIDR`

    i=`atoi $IP`
    let "i=$i^(1<<(32-$CIDR))"
    NEWIP=`itoa i`

Let me know if I am correct :)