| OLD | NEW |
| 1 /* | 1 /* |
| 2 * dhcpcd - DHCP client daemon | 2 * dhcpcd - DHCP client daemon |
| 3 * Copyright (c) 2006-2009 Roy Marples <roy@marples.name> | 3 * Copyright (c) 2006-2009 Roy Marples <roy@marples.name> |
| 4 * All rights reserved | 4 * All rights reserved |
| 5 | 5 |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 { DHCP_OFFER, "DHCP_OFFER" }, | 104 { DHCP_OFFER, "DHCP_OFFER" }, |
| 105 { DHCP_REQUEST, "DHCP_REQUEST" }, | 105 { DHCP_REQUEST, "DHCP_REQUEST" }, |
| 106 { DHCP_DECLINE, "DHCP_DECLINE" }, | 106 { DHCP_DECLINE, "DHCP_DECLINE" }, |
| 107 { DHCP_ACK, "DHCP_ACK" }, | 107 { DHCP_ACK, "DHCP_ACK" }, |
| 108 { DHCP_NAK, "DHCP_NAK" }, | 108 { DHCP_NAK, "DHCP_NAK" }, |
| 109 { DHCP_RELEASE, "DHCP_RELEASE" }, | 109 { DHCP_RELEASE, "DHCP_RELEASE" }, |
| 110 { DHCP_INFORM, "DHCP_INFORM" }, | 110 { DHCP_INFORM, "DHCP_INFORM" }, |
| 111 { 0, NULL } | 111 { 0, NULL } |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 static void send_release(struct interface *); | |
| 115 | |
| 116 static const char * | 114 static const char * |
| 117 get_dhcp_op(uint8_t type) | 115 get_dhcp_op(uint8_t type) |
| 118 { | 116 { |
| 119 const struct dhcp_op *d; | 117 const struct dhcp_op *d; |
| 120 | 118 |
| 121 for (d = dhcp_ops; d->name; d++) | 119 for (d = dhcp_ops; d->name; d++) |
| 122 if (d->value == type) | 120 if (d->value == type) |
| 123 return d->name; | 121 return d->name; |
| 124 return NULL; | 122 return NULL; |
| 125 } | 123 } |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 find_interface(const char *ifname) | 239 find_interface(const char *ifname) |
| 242 { | 240 { |
| 243 struct interface *ifp; | 241 struct interface *ifp; |
| 244 | 242 |
| 245 for (ifp = ifaces; ifp; ifp = ifp->next) | 243 for (ifp = ifaces; ifp; ifp = ifp->next) |
| 246 if (strcmp(ifp->name, ifname) == 0) | 244 if (strcmp(ifp->name, ifname) == 0) |
| 247 return ifp; | 245 return ifp; |
| 248 return NULL; | 246 return NULL; |
| 249 } | 247 } |
| 250 | 248 |
| 251 static void | 249 void |
| 252 stop_interface(struct interface *iface) | 250 stop_interface(struct interface *iface) |
| 253 { | 251 { |
| 254 struct interface *ifp, *ifl = NULL; | 252 struct interface *ifp, *ifl = NULL; |
| 255 | 253 |
| 256 syslog(LOG_INFO, "%s: removing interface", iface->name); | 254 syslog(LOG_INFO, "%s: removing interface", iface->name); |
| 257 if (strcmp(iface->state->reason, "RELEASE") != 0) | 255 if (strcmp(iface->state->reason, "RELEASE") != 0) |
| 258 drop_config(iface, "STOP"); | 256 drop_config(iface, "STOP"); |
| 259 close_sockets(iface); | 257 close_sockets(iface); |
| 260 delete_timeout(NULL, iface); | 258 delete_timeout(NULL, iface); |
| 261 for (ifp = ifaces; ifp; ifp = ifp->next) { | 259 for (ifp = ifaces; ifp; ifp = ifp->next) { |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 (errno != EADDRINUSE || iface->addr.s_addr != 0)) | 698 (errno != EADDRINUSE || iface->addr.s_addr != 0)) |
| 701 syslog(LOG_ERR, "%s: open_udp_socket: %m", iface->name); | 699 syslog(LOG_ERR, "%s: open_udp_socket: %m", iface->name); |
| 702 if (iface->raw_fd != -1) | 700 if (iface->raw_fd != -1) |
| 703 delete_event(iface->raw_fd); | 701 delete_event(iface->raw_fd); |
| 704 if (open_socket(iface, ETHERTYPE_IP) == -1) | 702 if (open_socket(iface, ETHERTYPE_IP) == -1) |
| 705 syslog(LOG_ERR, "%s: open_socket: %m", iface->name); | 703 syslog(LOG_ERR, "%s: open_socket: %m", iface->name); |
| 706 if (iface->raw_fd != -1) | 704 if (iface->raw_fd != -1) |
| 707 add_event(iface->raw_fd, handle_dhcp_packet, iface); | 705 add_event(iface->raw_fd, handle_dhcp_packet, iface); |
| 708 } | 706 } |
| 709 | 707 |
| 710 static void | 708 void |
| 711 send_release(struct interface *iface) | 709 send_release(struct interface *iface) |
| 712 { | 710 { |
| 713 struct timespec ts; | 711 struct timespec ts; |
| 714 | 712 |
| 715 if (iface->state->lease.addr.s_addr && | 713 if (iface->state->lease.addr.s_addr && |
| 716 !IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr))) | 714 !IN_LINKLOCAL(htonl(iface->state->lease.addr.s_addr))) |
| 717 { | 715 { |
| 718 syslog(LOG_INFO, "%s: releasing lease of %s", | 716 syslog(LOG_INFO, "%s: releasing lease of %s", |
| 719 iface->name, inet_ntoa(iface->state->lease.addr)); | 717 iface->name, inet_ntoa(iface->state->lease.addr)); |
| 720 open_sockets(iface); | 718 open_sockets(iface); |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 } | 1794 } |
| 1797 free_options(ifo); | 1795 free_options(ifo); |
| 1798 | 1796 |
| 1799 sort_interfaces(); | 1797 sort_interfaces(); |
| 1800 for (iface = ifaces; iface; iface = iface->next) | 1798 for (iface = ifaces; iface; iface = iface->next) |
| 1801 add_timeout_sec(0, start_interface, iface); | 1799 add_timeout_sec(0, start_interface, iface); |
| 1802 | 1800 |
| 1803 start_eloop(); | 1801 start_eloop(); |
| 1804 exit(EXIT_SUCCESS); | 1802 exit(EXIT_SUCCESS); |
| 1805 } | 1803 } |
| OLD | NEW |