Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't allocate IP #12

Closed
jiangwh opened this Issue May 30, 2016 · 11 comments

Comments

Projects
None yet
2 participants
@jiangwh
Copy link

jiangwh commented May 30, 2016

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

@agrabil agrabil closed this May 30, 2016

@agrabil agrabil reopened this May 30, 2016

@agrabil

This comment has been minimized.

Copy link
Contributor

agrabil commented May 30, 2016

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

@agrabil agrabil closed this May 30, 2016

@jiangwh

This comment has been minimized.

Copy link
Author

jiangwh commented May 31, 2016

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.

@agrabil

This comment has been minimized.

Copy link
Contributor

agrabil commented May 31, 2016

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.

@jiangwh

This comment has been minimized.

Copy link
Author

jiangwh commented May 31, 2016

Can you provide an email for sending the detail info?

@agrabil

This comment has been minimized.

Copy link
Contributor

agrabil commented Jun 1, 2016

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.

@jiangwh

This comment has been minimized.

Copy link
Author

jiangwh commented Jun 1, 2016

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.

@agrabil

This comment has been minimized.

Copy link
Contributor

agrabil commented Jun 1, 2016

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>

@jiangwh

This comment has been minimized.

Copy link
Author

jiangwh commented Jun 1, 2016

Thank you & Try again ~

@jiangwh

This comment has been minimized.

Copy link
Author

jiangwh commented Jun 1, 2016

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~

@agrabil

This comment has been minimized.

Copy link
Contributor

agrabil commented Jun 1, 2016

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.

@jiangwh

This comment has been minimized.

Copy link
Author

jiangwh commented Jun 5, 2016

get it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.