From 3d222126b4f4620dfacf41c61860772da8626e03 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 28 Jul 2009 13:43:35 -0700 Subject: [PATCH] netdev: Change netdev_get_mtu() to return an error code. 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. (Currently netdev_get_mtu() won't ever return an error, but other future implementations might.) --- 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 126b45a89..69df907a2 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 561562b05..a9163c78a 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 cae6d2319..6bf92f264 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 7b5a330cf..191ed516a 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 fca86a18e..6ce28ef66 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); -- 2.43.0