/*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void *aux, struct dhclient **cli_)
{
struct dhclient *cli;
+ struct netdev_options netdev_options;
struct netdev *netdev;
int error;
*cli_ = NULL;
- error = netdev_open(netdev_name, ETH_TYPE_IP, &netdev);
+ memset(&netdev_options, 0, sizeof netdev_options);
+ netdev_options.name = netdev_name;
+ netdev_options.ethertype = ETH_TYPE_IP;
+ netdev_options.may_create = true;
+ netdev_options.may_open = true;
+
+ error = netdev_open(&netdev_options, &netdev);
/* XXX install socket filter to catch only DHCP packets. */
if (error) {
VLOG_ERR("could not open %s network device: %s",
return error;
}
- cli = xcalloc(1, sizeof *cli);
+ cli = xzalloc(sizeof *cli);
cli->modify_request = modify_request;
cli->validate_offer = validate_offer;
cli->aux = aux;
flow_extract(&b, 0, &flow);
if (flow.dl_type != htons(ETH_TYPE_IP)
|| flow.nw_proto != IP_TYPE_UDP
- || flow.tp_dst != htons(68)
+ || flow.tp_dst != htons(DHCP_CLIENT_PORT)
|| !(eth_addr_is_broadcast(flow.dl_dst)
|| eth_addr_equals(flow.dl_dst, cli_mac))) {
continue;
nh.ip_dst = INADDR_BROADCAST;
nh.ip_csum = csum(&nh, sizeof nh);
- th.udp_src = htons(66);
- th.udp_dst = htons(67);
+ th.udp_src = htons(DHCP_CLIENT_PORT);
+ th.udp_dst = htons(DHCP_SERVER_PORT);
th.udp_len = htons(UDP_HEADER_LEN + b.size);
th.udp_csum = 0;
udp_csum = csum_add32(0, nh.ip_src);