[ovs-discuss] [PATCH 04/20] netdev: Change netdev_get_mtu() to return an error code.

Ben Pfaff blp at nicira.com
Fri Jul 24 21:19:47 UTC 2009


To make the netdev code more portable, it needs to support returning error
codes from functions that don't have them.  This commit changes
netdev_get_mtu() to return an error code and updates its caller.
---
 CodingStyle       |    2 +-
 lib/dhcp-client.c |    2 +-
 lib/dpif-netdev.c |    2 +-
 lib/netdev.c      |   15 ++++++++++-----
 lib/netdev.h      |    2 +-
 5 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/CodingStyle b/CodingStyle
index 126b45a..69df907 100644
--- a/CodingStyle
+++ b/CodingStyle
@@ -168,7 +168,7 @@ prototype:
   Omit parameter names from function prototypes when the names do not
 give useful information, e.g.:
 
-    int netdev_get_mtu(const struct netdev *);
+    int netdev_get_mtu(const struct netdev *, int *mtup);
 
 
 STATEMENTS
diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c
index 561562b..a9163c7 100644
--- a/lib/dhcp-client.c
+++ b/lib/dhcp-client.c
@@ -909,7 +909,7 @@ do_receive_msg(struct dhclient *cli, struct dhcp_msg *msg)
     struct ofpbuf b;
     int mtu;
 
-    mtu = netdev_get_mtu(cli->netdev);
+    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++) {
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index cae6d23..6bf92f2 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -396,7 +396,7 @@ do_add_port(struct dp_netdev *dp, const char *devname, uint16_t flags,
     port->netdev = netdev;
     port->internal = internal;
 
-    mtu = netdev_get_mtu(netdev);
+    netdev_get_mtu(netdev, &mtu);
     if (mtu > max_mtu) {
         max_mtu = mtu;
     }
diff --git a/lib/netdev.c b/lib/netdev.c
index 7b5a330..191ed51 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -706,13 +706,18 @@ netdev_get_name(const struct netdev *netdev)
     return netdev->name;
 }
 
-/* Returns the maximum size of transmitted (and received) packets on 'netdev',
- * in bytes, not including the hardware header; thus, this is typically 1500
- * bytes for Ethernet devices. */
+/* Retrieves the MTU of 'netdev'.  The MTU is the maximum size of transmitted
+ * (and received) packets, in bytes, not including the hardware header; thus,
+ * this is typically 1500 bytes for Ethernet devices.
+ *
+ * If successful, returns 0 and stores the MTU size in '*mtup'.  On failure,
+ * returns a positive errno value and stores ETH_PAYLOAD_MAX (1500) in
+ * '*mtup'. */
 int
-netdev_get_mtu(const struct netdev *netdev) 
+netdev_get_mtu(const struct netdev *netdev, int *mtup)
 {
-    return netdev->mtu;
+    *mtup = netdev->mtu;
+    return 0;
 }
 
 /* Stores the features supported by 'netdev' into each of '*current',
diff --git a/lib/netdev.h b/lib/netdev.h
index fca86a1..6ce28ef 100644
--- a/lib/netdev.h
+++ b/lib/netdev.h
@@ -86,7 +86,7 @@ void netdev_send_wait(struct netdev *);
 int netdev_set_etheraddr(struct netdev *, const uint8_t mac[6]);
 int netdev_get_etheraddr(const struct netdev *, uint8_t mac[6]);
 const char *netdev_get_name(const struct netdev *);
-int netdev_get_mtu(const struct netdev *);
+int netdev_get_mtu(const struct netdev *, int *mtup);
 int netdev_get_features(struct netdev *,
                         uint32_t *current, uint32_t *advertised,
                         uint32_t *supported, uint32_t *peer);
-- 
1.6.3.3





More information about the discuss mailing list