X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fdhcp-client.c;h=0abf115b025937b3d897582968fe1b6e397469f1;hb=7103dec49eb569c3196239da6c178a29c3003e2b;hp=225be3de79bee6f81962a6c43484ba60e4271fbe;hpb=064af42167bf4fc9aaea2702d80ce08074b889c0;p=openvswitch diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c index 225be3de..0abf115b 100644 --- a/lib/dhcp-client.c +++ b/lib/dhcp-client.c @@ -1,17 +1,17 @@ /* - * Copyright (c) 2008, 2009 Nicira Networks. + * Copyright (c) 2008, 2009, 2010 Nicira Networks. * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include @@ -151,12 +151,19 @@ dhclient_create(const char *netdev_name, 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", @@ -172,7 +179,7 @@ dhclient_create(const char *netdev_name, return error; } - cli = xcalloc(1, sizeof *cli); + cli = xzalloc(sizeof *cli); cli->modify_request = modify_request; cli->validate_offer = validate_offer; cli->aux = aux; @@ -411,7 +418,7 @@ dhclient_configure_netdev(struct dhclient *cli) } if (!error && router.s_addr) { - error = netdev_add_router(router); + error = netdev_add_router(cli->netdev, router); if (error) { VLOG_ERR("failed to add default route to "IP_FMT" on %s: %s", IP_ARGS(&router), netdev_get_name(cli->netdev), @@ -768,7 +775,7 @@ dhclient_run_REBINDING(struct dhclient *cli) } static void -dhclient_run_RELEASED(struct dhclient *cli UNUSED) +dhclient_run_RELEASED(struct dhclient *cli OVS_UNUSED) { /* Nothing to do. */ } @@ -882,7 +889,7 @@ dhclient_msg_init(struct dhclient *cli, enum dhcp_msg_type type, msg->xid = cli->xid; msg->secs = cli->secs; msg->type = type; - memcpy(msg->chaddr, netdev_get_etheraddr(cli->netdev), ETH_ADDR_LEN); + netdev_get_etheraddr(cli->netdev, msg->chaddr); } /* If time goes backward this returns a large number, which makes it look like @@ -905,9 +912,13 @@ timeout(struct dhclient *cli, unsigned int secs) static bool do_receive_msg(struct dhclient *cli, struct dhcp_msg *msg) { + uint8_t cli_mac[ETH_ADDR_LEN]; struct ofpbuf b; + int mtu; - ofpbuf_init(&b, netdev_get_mtu(cli->netdev) + VLAN_ETH_HEADER_LEN); + netdev_get_mtu(cli->netdev, &mtu); + ofpbuf_init(&b, mtu + VLAN_ETH_HEADER_LEN); + netdev_get_etheraddr(cli->netdev, cli_mac); for (; cli->received < 50; cli->received++) { const struct ip_header *ip; const struct dhcp_header *dhcp; @@ -920,13 +931,12 @@ do_receive_msg(struct dhclient *cli, struct dhcp_msg *msg) goto drained; } - flow_extract(&b, 0, &flow); + flow_extract(&b, 0, 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, - netdev_get_etheraddr(cli->netdev)))) { + || eth_addr_equals(flow.dl_dst, cli_mac))) { continue; } @@ -977,7 +987,7 @@ do_send_msg(struct dhclient *cli, const struct dhcp_msg *msg) dhcp_assemble(msg, &b); - memcpy(eh.eth_src, netdev_get_etheraddr(cli->netdev), ETH_ADDR_LEN); + netdev_get_etheraddr(cli->netdev, eh.eth_src); memcpy(eh.eth_dst, eth_addr_broadcast, ETH_ADDR_LEN); eh.eth_type = htons(ETH_TYPE_IP); @@ -1006,8 +1016,8 @@ do_send_msg(struct dhclient *cli, const struct dhcp_msg *msg) 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);