[systemd-commits] 4 commits - src/libsystemd-network src/libudev src/network src/systemd src/udev TODO

Tom Gundersen tomegun at kemper.freedesktop.org
Fri Aug 1 07:36:09 PDT 2014


 TODO                                    |    2 -
 src/libsystemd-network/dhcp-protocol.h  |    3 +
 src/libsystemd-network/sd-dhcp-client.c |   27 +++++++++++++
 src/libudev/libudev-private.h           |    2 -
 src/libudev/libudev-util.c              |   64 --------------------------------
 src/network/networkd-link.c             |   27 +++++++++++--
 src/network/networkd.h                  |    1 
 src/systemd/sd-dhcp-client.h            |    1 
 src/udev/udev-rules.c                   |   20 ++++++++--
 9 files changed, 69 insertions(+), 78 deletions(-)

New commits:
commit afe7fd56f5b5b81294dcb794214f97fc5e39dfea
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 1 15:42:08 2014 +0200

    networkd: track the MTU of each link
    
    And inform the DHCPv4 clients about it.

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index ec1a97a..172be64 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -1835,6 +1835,12 @@ static int link_configure(Link *link) {
                 if (r < 0)
                         return r;
 
+                if (link->mtu) {
+                        r = sd_dhcp_client_set_mtu(link->dhcp_client, link->mtu);
+                        if (r < 0)
+                                return r;
+                }
+
                 if (link->network->dhcp_mtu) {
                         r = sd_dhcp_client_set_request_option(link->dhcp_client, DHCP_OPTION_INTERFACE_MTU);
                         if (r < 0)
@@ -2174,6 +2180,7 @@ int link_add(Manager *m, sd_rtnl_message *message, Link **ret) {
 int link_update(Link *link, sd_rtnl_message *m) {
         struct ether_addr mac;
         const char *ifname;
+        uint32_t mtu;
         int r;
 
         assert(link);
@@ -2196,11 +2203,23 @@ int link_update(Link *link, sd_rtnl_message *m) {
                         return -ENOMEM;
         }
 
-        if (!link->original_mtu) {
-                r = sd_rtnl_message_read_u16(m, IFLA_MTU, &link->original_mtu);
-                if (r >= 0)
+        r = sd_rtnl_message_read_u32(m, IFLA_MTU, &mtu);
+        if (r >= 0 && mtu > 0) {
+                link->mtu = mtu;
+                if (!link->original_mtu) {
+                        link->original_mtu = mtu;
                         log_debug_link(link, "saved original MTU: %"
-                                       PRIu16, link->original_mtu);
+                                       PRIu32, link->original_mtu);
+                }
+
+                if (link->dhcp_client) {
+                        r = sd_dhcp_client_set_mtu(link->dhcp_client, link->mtu);
+                        if (r < 0) {
+                                log_warning_link(link, "Could not update MTU in DHCP client: %s",
+                                                 strerror(-r));
+                                return r;
+                        }
+                }
         }
 
         /* The kernel may broadcast NEWLINK messages without the MAC address
diff --git a/src/network/networkd.h b/src/network/networkd.h
index 766297c..5d7a08b 100644
--- a/src/network/networkd.h
+++ b/src/network/networkd.h
@@ -174,6 +174,7 @@ struct Link {
         char *ifname;
         char *state_file;
         struct ether_addr mac;
+        uint32_t mtu;
         struct udev_device *udev_device;
 
         unsigned flags;

commit 324f818781a250b60f2fcfa74ff1c9101d2d1315
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 1 16:10:13 2014 +0200

    sd-dhcp-client: allow the max dhcp message size to be set to the MTU of the link

diff --git a/src/libsystemd-network/dhcp-protocol.h b/src/libsystemd-network/dhcp-protocol.h
index f5119a7..abca942 100644
--- a/src/libsystemd-network/dhcp-protocol.h
+++ b/src/libsystemd-network/dhcp-protocol.h
@@ -60,7 +60,8 @@ typedef struct DHCPPacket DHCPPacket;
 #define DHCP_IP_SIZE            (int32_t)(sizeof(struct iphdr))
 #define DHCP_IP_UDP_SIZE        (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
 #define DHCP_MESSAGE_SIZE       (int32_t)(sizeof(DHCPMessage))
-#define DHCP_MIN_OPTIONS_SIZE   308 /* spec says 312, but that includes the magic cookie */
+#define DHCP_DEFAULT_MIN_SIZE   576 /* the minimum internet hosts must be able to receive */
+#define DHCP_MIN_OPTIONS_SIZE   DHCP_DEFAULT_MIN_SIZE - DHCP_IP_UDP_SIZE - DHCP_MESSAGE_SIZE
 #define DHCP_MAGIC_COOKIE       (uint32_t)(0x63825363)
 
 enum {
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 8205ad0..f5910d9 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -59,6 +59,7 @@ struct sd_dhcp_client {
         } _packed_ client_id;
         char *hostname;
         char *vendor_class_identifier;
+        uint32_t mtu;
         uint32_t xid;
         usec_t start_time;
         uint16_t secs;
@@ -227,6 +228,15 @@ int sd_dhcp_client_set_vendor_class_identifier(sd_dhcp_client *client,
         return 0;
 }
 
+int sd_dhcp_client_set_mtu(sd_dhcp_client *client, uint32_t mtu) {
+        assert_return(client, -EINVAL);
+        assert_return(mtu >= DHCP_DEFAULT_MIN_SIZE, -ERANGE);
+
+        client->mtu = mtu;
+
+        return 0;
+}
+
 int sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret) {
         assert_return(client, -EINVAL);
         assert_return(ret, -EINVAL);
@@ -366,9 +376,23 @@ static int client_message_init(sd_dhcp_client *client, DHCPPacket **ret,
            Note (from ConnMan): Some DHCP servers will send bigger DHCP packets
            than the defined default size unless the Maximum Messge Size option
            is explicitely set
+
+           RFC3442 "Requirements to Avoid Sizing Constraints":
+           Because a full routing table can be quite large, the standard 576
+           octet maximum size for a DHCP message may be too short to contain
+           some legitimate Classless Static Route options.  Because of this,
+           clients implementing the Classless Static Route option SHOULD send a
+           Maximum DHCP Message Size [4] option if the DHCP client's TCP/IP
+           stack is capable of receiving larger IP datagrams.  In this case, the
+           client SHOULD set the value of this option to at least the MTU of the
+           interface that the client is configuring.  The client MAY set the
+           value of this option higher, up to the size of the largest UDP packet
+           it is prepared to accept.  (Note that the value specified in the
+           Maximum DHCP Message Size option is the total maximum packet size,
+           including IP and UDP headers.)
          */
         max_size = htobe16(size);
-        r = dhcp_option_append(&packet->dhcp, optlen, &optoffset, 0,
+        r = dhcp_option_append(&packet->dhcp, client->mtu, &optoffset, 0,
                                DHCP_OPTION_MAXIMUM_MESSAGE_SIZE,
                                2, &max_size);
         if (r < 0)
@@ -1505,6 +1529,7 @@ int sd_dhcp_client_new(sd_dhcp_client **ret) {
         client->index = -1;
         client->fd = -1;
         client->attempt = 1;
+        client->mtu = DHCP_DEFAULT_MIN_SIZE;
 
         client->req_opts_size = ELEMENTSOF(default_req_opts);
 
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index 36b8710..98c6782 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -51,6 +51,7 @@ int sd_dhcp_client_set_request_broadcast(sd_dhcp_client *client, int broadcast);
 int sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index);
 int sd_dhcp_client_set_mac(sd_dhcp_client *client,
                            const struct ether_addr *addr);
+int sd_dhcp_client_set_mtu(sd_dhcp_client *client, uint32_t mtu);
 int sd_dhcp_client_set_hostname(sd_dhcp_client *client, const char *hostname);
 int sd_dhcp_client_set_vendor_class_identifier(sd_dhcp_client *client, const char *vci);
 int sd_dhcp_client_get_lease(sd_dhcp_client *client, sd_dhcp_lease **ret);

commit c18126e8da7290725af9e3a86e25b2aefbc1ecae
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 1 15:26:30 2014 +0200

    TODO

diff --git a/TODO b/TODO
index feb7007..ec5cf2d 100644
--- a/TODO
+++ b/TODO
@@ -649,7 +649,6 @@ Features:
    - add reduced [Link] support to .network files
    - add Scope= parsing option for [Network]
    - properly handle routerless dhcp leases
-   - default to DHCP unicast, but make broadcast opt-in. detect devices that needs broadcast and opt-in automatically (needs kernel patch?)
    - add more attribute support for SIT tunnel
    - work with non-ethernet devices
    - add support for more bond options
@@ -660,7 +659,6 @@ Features:
 * dhcp:
    - figure out how much we can increase Maximum Message Size
    - export timezone information
-   - FORCERENEW
    - support RFC4702 (pass FQDN)
 
 * dhcp6:

commit a56ba6158b9649e01226dfaf3ff7082c82571090
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Aug 1 15:17:18 2014 +0200

    libudev: use get_*_creds from shared rather than util_lookup_*

diff --git a/src/libudev/libudev-private.h b/src/libudev/libudev-private.h
index af0f125..8fd86f2 100644
--- a/src/libudev/libudev-private.h
+++ b/src/libudev/libudev-private.h
@@ -168,8 +168,6 @@ uint64_t util_string_bloom64(const char *str);
 
 /* libudev-util-private.c */
 int util_delete_path(struct udev *udev, const char *path);
-uid_t util_lookup_user(struct udev *udev, const char *user);
-gid_t util_lookup_group(struct udev *udev, const char *group);
 int util_resolve_subsys_kernel(struct udev *udev, const char *string, char *result, size_t maxsize, int read_value);
 ssize_t print_kmsg(const char *fmt, ...) _printf_(1, 2);
 
diff --git a/src/libudev/libudev-util.c b/src/libudev/libudev-util.c
index d9cdde1..93e78d5 100644
--- a/src/libudev/libudev-util.c
+++ b/src/libudev/libudev-util.c
@@ -77,70 +77,6 @@ int util_delete_path(struct udev *udev, const char *path)
         return err;
 }
 
-uid_t util_lookup_user(struct udev *udev, const char *user)
-{
-        char *endptr;
-        struct passwd pwbuf;
-        struct passwd *pw;
-        uid_t uid;
-        size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
-        char *buf = alloca(buflen);
-
-        if (streq(user, "root"))
-                return 0;
-        uid = strtoul(user, &endptr, 10);
-        if (endptr[0] == '\0')
-                return uid;
-
-        errno = getpwnam_r(user, &pwbuf, buf, buflen, &pw);
-        if (pw != NULL)
-                return pw->pw_uid;
-        if (errno == 0 || errno == ENOENT || errno == ESRCH)
-                udev_err(udev, "specified user '%s' unknown\n", user);
-        else
-                udev_err(udev, "error resolving user '%s': %m\n", user);
-        return 0;
-}
-
-gid_t util_lookup_group(struct udev *udev, const char *group)
-{
-        char *endptr;
-        struct group grbuf;
-        struct group *gr;
-        gid_t gid = 0;
-        size_t buflen = sysconf(_SC_GETPW_R_SIZE_MAX);
-        char *buf = NULL;
-
-        if (streq(group, "root"))
-                return 0;
-        gid = strtoul(group, &endptr, 10);
-        if (endptr[0] == '\0')
-                return gid;
-        gid = 0;
-        for (;;) {
-                char *newbuf;
-
-                newbuf = realloc(buf, buflen);
-                if (!newbuf)
-                        break;
-                buf = newbuf;
-                errno = getgrnam_r(group, &grbuf, buf, buflen, &gr);
-                if (gr != NULL) {
-                        gid = gr->gr_gid;
-                } else if (errno == ERANGE) {
-                        buflen *= 2;
-                        continue;
-                } else if (errno == 0 || errno == ENOENT || errno == ESRCH) {
-                        udev_err(udev, "specified group '%s' unknown\n", group);
-                } else {
-                        udev_err(udev, "error resolving group '%s': %m\n", group);
-                }
-                break;
-        }
-        free(buf);
-        return gid;
-}
-
 /* handle "[<SUBSYSTEM>/<KERNEL>]<attribute>" format */
 int util_resolve_subsys_kernel(struct udev *udev, const char *string,
                                char *result, size_t maxsize, int read_value)
diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c
index cc56215..5518592 100644
--- a/src/udev/udev-rules.c
+++ b/src/udev/udev-rules.c
@@ -459,6 +459,7 @@ static uid_t add_uid(struct udev_rules *rules, const char *owner) {
         unsigned int i;
         uid_t uid;
         unsigned int off;
+        int r;
 
         /* lookup, if we know it already */
         for (i = 0; i < rules->uids_cur; i++) {
@@ -468,7 +469,9 @@ static uid_t add_uid(struct udev_rules *rules, const char *owner) {
                         return uid;
                 }
         }
-        uid = util_lookup_user(rules->udev, owner);
+        r = get_user_creds(&owner, &uid, NULL, NULL, NULL);
+        if (r < 0)
+                uid = 0;
 
         /* grow buffer if needed */
         if (rules->uids_cur+1 >= rules->uids_max) {
@@ -499,6 +502,7 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) {
         unsigned int i;
         gid_t gid;
         unsigned int off;
+        int r;
 
         /* lookup, if we know it already */
         for (i = 0; i < rules->gids_cur; i++) {
@@ -508,7 +512,9 @@ static gid_t add_gid(struct udev_rules *rules, const char *group) {
                         return gid;
                 }
         }
-        gid = util_lookup_group(rules->udev, group);
+        r = get_group_creds(&group, &gid);
+        if (r < 0)
+                gid = 0;
 
         /* grow buffer if needed */
         if (rules->gids_cur+1 >= rules->gids_max) {
@@ -2170,6 +2176,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
                         break;
                 case TK_A_OWNER: {
                         char owner[UTIL_NAME_SIZE];
+                        int r;
 
                         if (event->owner_final)
                                 break;
@@ -2177,7 +2184,9 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
                                 event->owner_final = true;
                         udev_event_apply_format(event, rules_str(rules, cur->key.value_off), owner, sizeof(owner));
                         event->owner_set = true;
-                        event->uid = util_lookup_user(event->udev, owner);
+                        r = get_user_creds(&owner, &event->uid, NULL, NULL, NULL);
+                        if (r < 0)
+                                event->uid = 0;
                         log_debug("OWNER %u %s:%u",
                                   event->uid,
                                   rules_str(rules, rule->rule.filename_off),
@@ -2186,6 +2195,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
                 }
                 case TK_A_GROUP: {
                         char group[UTIL_NAME_SIZE];
+                        int r;
 
                         if (event->group_final)
                                 break;
@@ -2193,7 +2203,9 @@ int udev_rules_apply_to_event(struct udev_rules *rules,
                                 event->group_final = true;
                         udev_event_apply_format(event, rules_str(rules, cur->key.value_off), group, sizeof(group));
                         event->group_set = true;
-                        event->gid = util_lookup_group(event->udev, group);
+                        r = get_group_creds(&group, &event->gid);
+                        if (r < 0)
+                                event->gid = 0;
                         log_debug("GROUP %u %s:%u",
                                   event->gid,
                                   rules_str(rules, rule->rule.filename_off),



More information about the systemd-commits mailing list