jagornet/dhcp

Can't allocate IP

jiangwh opened this issue · 11 comments

If in vlan ,the server can't allocate ip addr.Because the server drop the package that source ip is 0.0.0.0

Source IP of 0.0.0.0 is invalid for non-broadcast packets.

I do some test about the source code. used the TP-LINK.

  1. close the device's dhcp server(TP-LINK).

  2. start dhcp server(jaornet).
    The config:
    <ns:dhcpServerConfig xmlns:ns="http://jagornet.com/dhcp/xml"> <v6ServerIdOption> <opaqueData> <hexValue>000100015744174164006A3F5CA9</hexValue> </opaqueData> </v6ServerIdOption> <v4ServerIdOption> <ipAddress>10.10.156.100</ipAddress> </v4ServerIdOption> <policies> <policy> <name>dhcp.ignoreSelfPackets</name> <value>false</value> </policy> </policies> <links> <link> <name>IPv4 Client Link</name> <address>10.10.156.0/24</address> <v4ConfigOptions> <v4SubnetMaskOption> <ipAddress>255.255.255.0</ipAddress> </v4SubnetMaskOption> <v4RoutersOption> <ipAddress>10.10.156.1</ipAddress> </v4RoutersOption> <v4DomainServersOption> <ipAddress>192.168.58.110</ipAddress> <ipAddress>192.168.58.111</ipAddress> <ipAddress>8.8.8.8</ipAddress> </v4DomainServersOption> </v4ConfigOptions> <v4AddrPools> <pool> <range>10.10.156.210-10.10.156.250</range> </pool> </v4AddrPools> </link> </links> </ns:dhcpServerConfig>

  3. iphone connect the wifi.
    I found the server drop the dhcp request package.
    try to change the code
    File:DhcpV4UnicastChannelDecoder.java ,line 64, let the server deal with the package that source ip of 0.0.0.0
    `
    protected Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
    {
    if (remoteSocketAddress.getAddress().equals(DhcpConstants.ZEROADDR_V4) && false) {
    // can't unicast to 0.0.0.0, so a broadcast channel is needed
    // this is a workaround for Windows implementation which will
    // see duplicate packets on the unicast and broadcast channels
    log.debug("Ignoring packet from 0.0.0.0 received on unicast channel");
    return null;
    }

    Object obj = super.decode(ctx, channel, msg);
    if (obj instanceof DhcpV4Message) {
        // this decoder is in the pipeline for unicast
        // channels only, so this must be a unicast packet
        ((DhcpV4Message)obj).setUnicast(true);
    }
    return obj;
    

    }
    `

And the File:DhcpV4ChannelHandler.java line 94
send the respone to 255.255.255.255 not the source ip 0.0.0.0
`
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
Object message = e.getMessage();
if (message instanceof DhcpV4Message) {

        DhcpV4Message dhcpMessage = (DhcpV4Message) message;
        if (log.isDebugEnabled()) {
            log.debug("Received: " + dhcpMessage.toStringWithOptions());
        } else {
            log.info("Received: " + dhcpMessage.toString());
        }

        DhcpV4Message replyMessage = DhcpV4MessageHandler.handleMessage(dhcpMessage.getLocalAddress().getAddress(),dhcpMessage);

        if (replyMessage != null) {
            if ((broadcastSendChannel != null)
                    && (replyMessage.getRemoteAddress().getAddress().equals(DhcpConstants.ZEROADDR_V4))) {
                if (log.isDebugEnabled())
                    log.debug("Client request received from zero address," + " replying to broadcast address.");
                replyMessage.setRemoteAddress(
                        new InetSocketAddress(DhcpConstants.BROADCAST, replyMessage.getRemoteAddress().getPort()));
                // ensure the packet is sent on the proper broadcast
                // interface
                broadcastSendChannel.write(replyMessage, replyMessage.getRemoteAddress());
            } else {
                // client request was unicast, so reply via receive channel
                log.debug(replyMessage.getRemoteAddress().toString());
                log.debug(e.getChannel().getLocalAddress().toString());
                InetSocketAddress address = new InetSocketAddress("255.255.255.255", 68);
                replyMessage.setRemoteAddress(address);
                e.getChannel().write(replyMessage,address);
            }
        } else {
            log.warn("Null DHCP reply message returned from handler");
        }
    } else {
        // Note: in theory, we can't get here, because the
        // codec would have thrown an exception beforehand
        log.error("Received unknown message object: " + message.getClass());
    }
}

`

after change the source code , it works ,The iphone can get the ip address. Of cause the changes are limited,because not understand all of the business.

What options did you use to start the server? What platform is the server running on? Please provide the server's logfile for the test you describe.

Can you provide an email for sending the detail info?

You may attach the files in your reply to this Github issue. Please include the information regarding what startup parameters were specified on the command line, or if running as a Windows Service, then include the JAGORNET_DHCP_HOME\bin\yajsw-stable-11.0\conf\wrapper.conf file along with the log files.

jinfo.txt
wrapper.conf.txt
dhcpserver.log.txt
dhcpserver.xm.txt

I thought the issue could not upload attachments~ nice function~
The jinfo.txt contain the jvm info and os info use the jinfo command to generate.

This is a configuration issue. The DHCP client(s) are on the same subnet as the Jagornet DHCP server. In order to service those clients, the server must be configured to listen for broadcast messages from the interface for that subnet. Your configuration does not specify any broadcast interfaces, as evidenced by this log message:
2016-04-18 16:03:19,081 [main] INFO server.JagornetDhcpServer - DHCPv4 Broadcast interface: none

As indicated in the comment in the JAGORNET_DHCP_HOME\conf\dhcpserver-sample.xml file:

        <!-- All DHCPv4 links are defined in CIDR notation.
             For local links, specify the interface as a
             startup command-line option, and configure the
             subnet for that interface's IPv4 address. -->

Your dhcpserver.xml file indicates that the server's IP is 10.10.156.100:
<v4ServerIdOption>
<ipAddress>10.10.156.100</ipAddress>
</v4ServerIdOption>

And the server's local subnet is configured in this link:
<link>
<name>IPv4 Client Link</name>
<address>10.10.156.0/24</address>

Please refer to this [http://www.jagornet.com/products/dhcp-server/docs#id1026846] section of the documentation to configure the -4b parameter and value based upon the name of the interface configured with the server's IP address. If you are unsure of the interface name, you can use the server's built-in function to list all of the interfaces on the system:

%JAGORNET_DHCP_HOME%\bin\dhcpserver start --list-interfaces

Once you have determined the name of the interface associated with the server's IP address (10.10.156.100), then you can specify it in the wrapper.conf file as follows:

wrapper.app.parameter.1=-4b
wrapper.app.parameter.2=<interface-name>

Thank you & Try again ~

add code
v4BcastNetIf = NetworkInterface.getByName("eth3");
it works~and the log print:

Client request received from zero address, replying to broadcast address.

Thank you again~

It is not recommended to modify the code to use hard-coded interface names. Please use the wrapper.conf file to configure the interface name using the -4b option as described in the documentation.

get it