| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 54 #include <unistd.h> | 54 #include <unistd.h> | 
| 55 #include <time.h> | 55 #include <time.h> | 
| 56 | 56 | 
| 57 #include "arp.h" | 57 #include "arp.h" | 
| 58 #include "bind.h" | 58 #include "bind.h" | 
| 59 #include "config.h" | 59 #include "config.h" | 
| 60 #include "common.h" | 60 #include "common.h" | 
| 61 #include "configure.h" | 61 #include "configure.h" | 
| 62 #include "control.h" | 62 #include "control.h" | 
| 63 #include "dhcpcd.h" | 63 #include "dhcpcd.h" | 
|  | 64 #include "dhcpcd-dbus.h" | 
| 64 #include "duid.h" | 65 #include "duid.h" | 
| 65 #include "eloop.h" | 66 #include "eloop.h" | 
| 66 #include "if-options.h" | 67 #include "if-options.h" | 
| 67 #include "if-pref.h" | 68 #include "if-pref.h" | 
| 68 #include "ipv4ll.h" | 69 #include "ipv4ll.h" | 
| 69 #include "net.h" | 70 #include "net.h" | 
| 70 #include "signals.h" | 71 #include "signals.h" | 
| 71 | 72 | 
| 72 /* We should define a maximum for the NAK exponential backoff */ | 73 /* We should define a maximum for the NAK exponential backoff */ | 
| 73 #define NAKOFF_MAX              60 | 74 #define NAKOFF_MAX              60 | 
| (...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1291                 ifp->dst.s_addr = dst ? dst->s_addr : INADDR_ANY; | 1292                 ifp->dst.s_addr = dst ? dst->s_addr : INADDR_ANY; | 
| 1292                 if (dst) { | 1293                 if (dst) { | 
| 1293                         for (i = 1; i < 255; i++) | 1294                         for (i = 1; i < 255; i++) | 
| 1294                                 if (i != DHO_ROUTER && | 1295                                 if (i != DHO_ROUTER && | 
| 1295                                     has_option_mask(ifo->dstmask, i)) | 1296                                     has_option_mask(ifo->dstmask, i)) | 
| 1296                                         dhcp_message_add_addr( | 1297                                         dhcp_message_add_addr( | 
| 1297                                                 ifp->state->new, | 1298                                                 ifp->state->new, | 
| 1298                                                 i, *dst); | 1299                                                 i, *dst); | 
| 1299                 } | 1300                 } | 
| 1300                 ifp->state->reason = "STATIC"; | 1301                 ifp->state->reason = "STATIC"; | 
| 1301                 build_routes(); |  | 
| 1302                 run_script(ifp); | 1302                 run_script(ifp); | 
| 1303                 if (ifo->options & DHCPCD_INFORM) { | 1303                 if (ifo->options & DHCPCD_INFORM) { | 
| 1304                         ifp->state->state = DHS_INFORM; | 1304                         ifp->state->state = DHS_INFORM; | 
| 1305                         ifp->state->xid = arc4random(); | 1305                         ifp->state->xid = arc4random(); | 
| 1306                         ifp->state->lease.server.s_addr = | 1306                         ifp->state->lease.server.s_addr = | 
| 1307                             dst ? dst->s_addr : INADDR_ANY; | 1307                             dst ? dst->s_addr : INADDR_ANY; | 
| 1308                         ifp->addr = *addr; | 1308                         ifp->addr = *addr; | 
| 1309                         ifp->net = *net; | 1309                         ifp->net = *net; | 
| 1310                         open_sockets(ifp); | 1310                         open_sockets(ifp); | 
| 1311                         send_inform(ifp); | 1311                         send_inform(ifp); | 
| 1312                 } | 1312                 } | 
| 1313                 break; | 1313                 break; | 
| 1314         } | 1314         } | 
| 1315 } | 1315 } | 
| 1316 | 1316 | 
| 1317 /* ARGSUSED */ | 1317 /* ARGSUSED */ | 
| 1318 static void | 1318 static void | 
| 1319 handle_link(_unused void *arg) | 1319 handle_link(_unused void *arg) | 
| 1320 { | 1320 { | 
| 1321         if (manage_link(linkfd) == -1) | 1321         if (manage_link(linkfd) == -1) | 
| 1322                 syslog(LOG_ERR, "manage_link: %m"); | 1322                 syslog(LOG_ERR, "manage_link: %m"); | 
| 1323 } | 1323 } | 
| 1324 | 1324 | 
| 1325 /* ARGSUSED */ | 1325 /* ARGSUSED */ | 
| 1326 static void | 1326 void | 
| 1327 handle_signal(_unused void *arg) | 1327 handle_signal(_unused void *arg) | 
| 1328 { | 1328 { | 
| 1329         struct interface *iface, *ifl; | 1329         struct interface *iface, *ifl; | 
| 1330         int sig = signal_read(); | 1330         int sig = signal_read(); | 
| 1331         int do_release = 0; | 1331         int do_release = 0; | 
| 1332 | 1332 | 
| 1333         switch (sig) { | 1333         switch (sig) { | 
| 1334         case SIGINT: | 1334         case SIGINT: | 
| 1335                 syslog(LOG_INFO, "received SIGINT, stopping"); | 1335                 syslog(LOG_INFO, "received SIGINT, stopping"); | 
| 1336                 break; | 1336                 break; | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1413 handle_args(struct fd_list *fd, int argc, char **argv) | 1413 handle_args(struct fd_list *fd, int argc, char **argv) | 
| 1414 { | 1414 { | 
| 1415         struct interface *ifs, *ifp, *ifl, *ifn, *ift; | 1415         struct interface *ifs, *ifp, *ifl, *ifn, *ift; | 
| 1416         int do_exit = 0, do_release = 0, do_reboot = 0, do_reconf = 0; | 1416         int do_exit = 0, do_release = 0, do_reboot = 0, do_reconf = 0; | 
| 1417         int opt, oi = 0; | 1417         int opt, oi = 0; | 
| 1418         ssize_t len; | 1418         ssize_t len; | 
| 1419         size_t l; | 1419         size_t l; | 
| 1420         struct iovec iov[2]; | 1420         struct iovec iov[2]; | 
| 1421         char *tmp, *p; | 1421         char *tmp, *p; | 
| 1422 | 1422 | 
| 1423         if (fd != NULL) { |  | 
| 1424                 /* Special commands for our control socket */ |  | 
| 1425                 if (strcmp(*argv, "--version") == 0) { |  | 
| 1426                         len = strlen(VERSION) + 1; |  | 
| 1427                         iov[0].iov_base = &len; |  | 
| 1428                         iov[0].iov_len = sizeof(ssize_t); |  | 
| 1429                         iov[1].iov_base = UNCONST(VERSION); |  | 
| 1430                         iov[1].iov_len = len; |  | 
| 1431                         if (writev(fd->fd, iov, 2) == -1) { |  | 
| 1432                                 syslog(LOG_ERR, "writev: %m"); |  | 
| 1433                                 return -1; |  | 
| 1434                         } |  | 
| 1435                         return 0; |  | 
| 1436                 } else if (strcmp(*argv, "--getconfigfile") == 0) { |  | 
| 1437                         len = strlen(cffile ? cffile : CONFIG) + 1; |  | 
| 1438                         iov[0].iov_base = &len; |  | 
| 1439                         iov[0].iov_len = sizeof(ssize_t); |  | 
| 1440                         iov[1].iov_base = cffile ? cffile : UNCONST(CONFIG); |  | 
| 1441                         iov[1].iov_len = len; |  | 
| 1442                         if (writev(fd->fd, iov, 2) == -1) { |  | 
| 1443                                 syslog(LOG_ERR, "writev: %m"); |  | 
| 1444                                 return -1; |  | 
| 1445                         } |  | 
| 1446                         return 0; |  | 
| 1447                 } else if (strcmp(*argv, "--getinterfaces") == 0) { |  | 
| 1448                         len = 0; |  | 
| 1449                         if (argc == 1) { |  | 
| 1450                                 for (ifp = ifaces; ifp; ifp = ifp->next) |  | 
| 1451                                         len++; |  | 
| 1452                                 len = write(fd->fd, &len, sizeof(len)); |  | 
| 1453                                 if (len != sizeof(len)) |  | 
| 1454                                         return -1; |  | 
| 1455                                 for (ifp = ifaces; ifp; ifp = ifp->next) |  | 
| 1456                                         send_interface(fd->fd, ifp); |  | 
| 1457                                 return 0; |  | 
| 1458                         } |  | 
| 1459                         opt = 0; |  | 
| 1460                         while (argv[++opt] != NULL) { |  | 
| 1461                                 for (ifp = ifaces; ifp; ifp = ifp->next) |  | 
| 1462                                         if (strcmp(argv[opt], ifp->name) == 0) |  | 
| 1463                                                 len++; |  | 
| 1464                         } |  | 
| 1465                         len = write(fd->fd, &len, sizeof(len)); |  | 
| 1466                         if (len != sizeof(len)) |  | 
| 1467                                 return -1; |  | 
| 1468                         opt = 0; |  | 
| 1469                         while (argv[++opt] != NULL) { |  | 
| 1470                                 for (ifp = ifaces; ifp; ifp = ifp->next) |  | 
| 1471                                         if (strcmp(argv[opt], ifp->name) == 0) |  | 
| 1472                                                 send_interface(fd->fd, ifp); |  | 
| 1473                         } |  | 
| 1474                         return 0; |  | 
| 1475                 } else if (strcmp(*argv, "--listen") == 0) { |  | 
| 1476                         fd->listener = 1; |  | 
| 1477                         return 0; |  | 
| 1478                 } |  | 
| 1479         } |  | 
| 1480 |  | 
| 1481         /* Log the command */ | 1423         /* Log the command */ | 
| 1482         len = 0; | 1424         len = 0; | 
| 1483         for (opt = 0; opt < argc; opt++) | 1425         for (opt = 0; opt < argc; opt++) | 
| 1484                 len += strlen(argv[opt]) + 1; | 1426                 len += strlen(argv[opt]) + 1; | 
| 1485         tmp = p = xmalloc(len + 1); | 1427         tmp = p = xmalloc(len + 1); | 
| 1486         for (opt = 0; opt < argc; opt++) { | 1428         for (opt = 0; opt < argc; opt++) { | 
| 1487                 l = strlen(argv[opt]); | 1429                 l = strlen(argv[opt]); | 
| 1488                 strlcpy(p, argv[opt], l + 1); | 1430                 strlcpy(p, argv[opt], l + 1); | 
| 1489                 p += l; | 1431                 p += l; | 
| 1490                 *p++ = ' '; | 1432                 *p++ = ' '; | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1568 main(int argc, char **argv) | 1510 main(int argc, char **argv) | 
| 1569 { | 1511 { | 
| 1570         struct if_options *ifo; | 1512         struct if_options *ifo; | 
| 1571         struct interface *iface; | 1513         struct interface *iface; | 
| 1572         int opt, oi = 0, signal_fd, sig = 0, i, control_fd; | 1514         int opt, oi = 0, signal_fd, sig = 0, i, control_fd; | 
| 1573         size_t len; | 1515         size_t len; | 
| 1574         pid_t pid; | 1516         pid_t pid; | 
| 1575         struct timespec ts; | 1517         struct timespec ts; | 
| 1576 | 1518 | 
| 1577         closefrom(3); | 1519         closefrom(3); | 
| 1578 »       openlog(PACKAGE, LOG_PERROR, LOG_DAEMON); | 1520 »       openlog(PACKAGE, LOG_PID | LOG_PERROR, LOG_DAEMON); | 
| 1579         setlogmask(LOG_UPTO(LOG_INFO)); | 1521         setlogmask(LOG_UPTO(LOG_INFO)); | 
| 1580 | 1522 | 
| 1581         /* Test for --help and --version */ | 1523         /* Test for --help and --version */ | 
| 1582         if (argc > 1) { | 1524         if (argc > 1) { | 
| 1583                 if (strcmp(argv[1], "--help") == 0) { | 1525                 if (strcmp(argv[1], "--help") == 0) { | 
| 1584                         usage(); | 1526                         usage(); | 
| 1585                         exit(EXIT_SUCCESS); | 1527                         exit(EXIT_SUCCESS); | 
| 1586                 } else if (strcmp(argv[1], "--version") == 0) { | 1528                 } else if (strcmp(argv[1], "--version") == 0) { | 
| 1587                         printf(""PACKAGE" "VERSION"\n%s\n", copyright); | 1529                         printf(""PACKAGE" "VERSION"\n%s\n", copyright); | 
| 1588                         exit(EXIT_SUCCESS); | 1530                         exit(EXIT_SUCCESS); | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1627         if (opt != 1) { | 1569         if (opt != 1) { | 
| 1628                 if (opt == 0) | 1570                 if (opt == 0) | 
| 1629                         usage(); | 1571                         usage(); | 
| 1630                 exit(EXIT_FAILURE); | 1572                 exit(EXIT_FAILURE); | 
| 1631         } | 1573         } | 
| 1632         options = ifo->options; | 1574         options = ifo->options; | 
| 1633         if (i != 0) { | 1575         if (i != 0) { | 
| 1634                 options |= DHCPCD_TEST | DHCPCD_PERSISTENT; | 1576                 options |= DHCPCD_TEST | DHCPCD_PERSISTENT; | 
| 1635                 options &= ~DHCPCD_DAEMONISE; | 1577                 options &= ~DHCPCD_DAEMONISE; | 
| 1636         } | 1578         } | 
| 1637 » | 1579 | 
| 1638 #ifdef THERE_IS_NO_FORK | 1580 #ifdef THERE_IS_NO_FORK | 
| 1639         options &= ~DHCPCD_DAEMONISE; | 1581         options &= ~DHCPCD_DAEMONISE; | 
| 1640 #endif | 1582 #endif | 
| 1641 | 1583 | 
| 1642         if (options & DHCPCD_DEBUG) | 1584         if (options & DHCPCD_DEBUG) | 
| 1643                 setlogmask(LOG_UPTO(LOG_DEBUG)); | 1585                 setlogmask(LOG_UPTO(LOG_DEBUG)); | 
| 1644         else if (options & DHCPCD_QUIET) | 1586         else if (options & DHCPCD_QUIET) | 
| 1645                 close(STDERR_FILENO); | 1587                 close(STDERR_FILENO); | 
| 1646 | 1588 | 
| 1647         if (!(options & DHCPCD_TEST)) { | 1589         if (!(options & DHCPCD_TEST)) { | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1710                                 nanosleep(&ts, NULL); | 1652                                 nanosleep(&ts, NULL); | 
| 1711                                 if (read_pid() == 0) | 1653                                 if (read_pid() == 0) | 
| 1712                                         exit(EXIT_SUCCESS); | 1654                                         exit(EXIT_SUCCESS); | 
| 1713                         } | 1655                         } | 
| 1714                         syslog(LOG_ERR, "pid %d failed to exit", pid); | 1656                         syslog(LOG_ERR, "pid %d failed to exit", pid); | 
| 1715                         exit(EXIT_FAILURE); | 1657                         exit(EXIT_FAILURE); | 
| 1716                 } | 1658                 } | 
| 1717         } | 1659         } | 
| 1718 | 1660 | 
| 1719         if (!(options & DHCPCD_TEST)) { | 1661         if (!(options & DHCPCD_TEST)) { | 
| 1720 »       »       if ((pid = read_pid()) > 0 && | 1662 »       »       if ((pid = read_pid()) > 0 && kill(pid, 0) == 0) { | 
| 1721 »       »           kill(pid, 0) == 0) |  | 
| 1722 »       »       { |  | 
| 1723                         syslog(LOG_ERR, ""PACKAGE | 1663                         syslog(LOG_ERR, ""PACKAGE | 
| 1724                             " already running on pid %d (%s)", | 1664                             " already running on pid %d (%s)", | 
| 1725                             pid, pidfile); | 1665                             pid, pidfile); | 
| 1726                         exit(EXIT_FAILURE); | 1666                         exit(EXIT_FAILURE); | 
| 1727                 } | 1667                 } | 
| 1728 | 1668 | 
| 1729                 /* Ensure we have the needed directories */ | 1669                 /* Ensure we have the needed directories */ | 
| 1730                 if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST) { | 1670                 if (mkdir(RUNDIR, 0755) == -1 && errno != EEXIST) { | 
| 1731                         syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR); | 1671                         syslog(LOG_ERR, "mkdir `%s': %m", RUNDIR); | 
| 1732                         exit(EXIT_FAILURE); | 1672                         exit(EXIT_FAILURE); | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1764                 if (start_control() == -1) { | 1704                 if (start_control() == -1) { | 
| 1765                         syslog(LOG_ERR, "start_control: %m"); | 1705                         syslog(LOG_ERR, "start_control: %m"); | 
| 1766                         exit(EXIT_FAILURE); | 1706                         exit(EXIT_FAILURE); | 
| 1767                 } | 1707                 } | 
| 1768         } | 1708         } | 
| 1769 | 1709 | 
| 1770         if (init_sockets() == -1) { | 1710         if (init_sockets() == -1) { | 
| 1771                 syslog(LOG_ERR, "init_socket: %m"); | 1711                 syslog(LOG_ERR, "init_socket: %m"); | 
| 1772                 exit(EXIT_FAILURE); | 1712                 exit(EXIT_FAILURE); | 
| 1773         } | 1713         } | 
|  | 1714         if (dhcpcd_dbus_init() == -1) { | 
|  | 1715                 /* NB: dhcpcd_dbus_init generates a syslog msg */ | 
|  | 1716                 exit(EXIT_FAILURE); | 
|  | 1717         } | 
| 1774         if (ifo->options & DHCPCD_LINK) { | 1718         if (ifo->options & DHCPCD_LINK) { | 
| 1775                 linkfd = open_link_socket(); | 1719                 linkfd = open_link_socket(); | 
| 1776                 if (linkfd == -1) | 1720                 if (linkfd == -1) | 
| 1777                         syslog(LOG_ERR, "open_link_socket: %m"); | 1721                         syslog(LOG_ERR, "open_link_socket: %m"); | 
| 1778                 else | 1722                 else | 
| 1779                         add_event(linkfd, handle_link, NULL); | 1723                         add_event(linkfd, handle_link, NULL); | 
| 1780         } | 1724         } | 
| 1781 | 1725 | 
| 1782         ifc = argc - optind; | 1726         ifc = argc - optind; | 
| 1783         ifv = argv + optind; | 1727         ifv = argv + optind; | 
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1852         } | 1796         } | 
| 1853         free_options(ifo); | 1797         free_options(ifo); | 
| 1854 | 1798 | 
| 1855         sort_interfaces(); | 1799         sort_interfaces(); | 
| 1856         for (iface = ifaces; iface; iface = iface->next) | 1800         for (iface = ifaces; iface; iface = iface->next) | 
| 1857                 add_timeout_sec(0, start_interface, iface); | 1801                 add_timeout_sec(0, start_interface, iface); | 
| 1858 | 1802 | 
| 1859         start_eloop(); | 1803         start_eloop(); | 
| 1860         exit(EXIT_SUCCESS); | 1804         exit(EXIT_SUCCESS); | 
| 1861 } | 1805 } | 
| OLD | NEW | 
|---|