aboutsummaryrefslogtreecommitdiff
path: root/lib/netdev-vport.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2013-07-31 14:09:30 -0700
committerBen Pfaff <blp@nicira.com>2013-08-09 21:23:19 -0700
commit161b6042d853f54e609415a671aaebe859ee94a2 (patch)
treedebecfcb12690abeee31d14dc4f1eb8610bbb83f /lib/netdev-vport.c
parent9dc63482bbeae23dd57b0f885a3fd26b44656844 (diff)
netdev-vport: Make netdev_vport_patch_peer() return a malloc()'d string.
When threading comes into the picture there arises the possibility of a race between netdev_vport_patch_peer()'s caller using the returned string and another caller changing the peer. It is safer to return a copy. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/netdev-vport.c')
-rw-r--r--lib/netdev-vport.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c
index ac3da634..287edae3 100644
--- a/lib/netdev-vport.c
+++ b/lib/netdev-vport.c
@@ -553,12 +553,23 @@ get_tunnel_config(const struct netdev *dev, struct smap *args)
/* Code specific to patch ports. */
-const char *
-netdev_vport_patch_peer(const struct netdev *netdev)
+/* If 'netdev' is a patch port, returns the name of its peer as a malloc()'d
+ * string that the caller must free.
+ *
+ * If 'netdev' is not a patch port, returns NULL. */
+char *
+netdev_vport_patch_peer(const struct netdev *netdev_)
{
- return (netdev_vport_is_patch(netdev)
- ? netdev_vport_cast(netdev)->peer
- : NULL);
+ char *peer = NULL;
+
+ if (netdev_vport_is_patch(netdev_)) {
+ struct netdev_vport *netdev = netdev_vport_cast(netdev_);
+ if (netdev->peer) {
+ peer = xstrdup(netdev->peer);
+ }
+ }
+
+ return peer;
}
void