From 9fe9a47916b38646a30bbceb60c7a2b7caba1112 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 11 Sep 2008 11:46:57 -0700 Subject: [PATCH] Make "struct vconn" opaque. --- include/vconn-provider.h | 10 +++++++++- lib/vconn-netlink.c | 2 +- lib/vconn-ssl.c | 4 ++-- lib/vconn-stream.c | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/vconn-provider.h b/include/vconn-provider.h index 57778e7bb..8bb8368a2 100644 --- a/include/vconn-provider.h +++ b/include/vconn-provider.h @@ -37,9 +37,12 @@ /* Provider interface, which provide a virtual connection to an OpenFlow * device. */ +#include #include "vconn.h" -/* Virtual connection to an OpenFlow device. */ +/* Virtual connection to an OpenFlow device. + * + * This structure should be treated as opaque by vconn implementations. */ struct vconn { struct vconn_class *class; int connect_status; @@ -49,6 +52,11 @@ struct vconn { void vconn_init(struct vconn *, struct vconn_class *, int connect_status, uint32_t ip, const char *name); +static inline void vconn_assert_class(const struct vconn *vconn, + const struct vconn_class *class) +{ + assert(vconn->class == class); +} struct vconn_class { /* Prefix for connection names, e.g. "nl", "tcp". */ diff --git a/lib/vconn-netlink.c b/lib/vconn-netlink.c index 4f609bb33..292123694 100644 --- a/lib/vconn-netlink.c +++ b/lib/vconn-netlink.c @@ -65,7 +65,7 @@ struct netlink_vconn static struct netlink_vconn * netlink_vconn_cast(struct vconn *vconn) { - assert(vconn->class == &netlink_vconn_class); + vconn_assert_class(vconn, &netlink_vconn_class); return CONTAINER_OF(vconn, struct netlink_vconn, vconn); } diff --git a/lib/vconn-ssl.c b/lib/vconn-ssl.c index d553834f0..d899e091f 100644 --- a/lib/vconn-ssl.c +++ b/lib/vconn-ssl.c @@ -251,7 +251,7 @@ error: static struct ssl_vconn * ssl_vconn_cast(struct vconn *vconn) { - assert(vconn->class == &ssl_vconn_class); + vconn_assert_class(vconn, &ssl_vconn_class); return CONTAINER_OF(vconn, struct ssl_vconn, vconn); } @@ -672,7 +672,7 @@ struct pssl_vconn static struct pssl_vconn * pssl_vconn_cast(struct vconn *vconn) { - assert(vconn->class == &pssl_vconn_class); + vconn_assert_class(vconn, &pssl_vconn_class); return CONTAINER_OF(vconn, struct pssl_vconn, vconn); } diff --git a/lib/vconn-stream.c b/lib/vconn-stream.c index 444778a9b..f58cc2c0c 100644 --- a/lib/vconn-stream.c +++ b/lib/vconn-stream.c @@ -85,7 +85,7 @@ new_stream_vconn(const char *name, int fd, int connect_status, static struct stream_vconn * stream_vconn_cast(struct vconn *vconn) { - assert(vconn->class == &stream_vconn_class); + vconn_assert_class(vconn, &stream_vconn_class); return CONTAINER_OF(vconn, struct stream_vconn, vconn); } @@ -269,7 +269,7 @@ static struct vconn_class pstream_vconn_class; static struct pstream_vconn * pstream_vconn_cast(struct vconn *vconn) { - assert(vconn->class == &pstream_vconn_class); + vconn_assert_class(vconn, &pstream_vconn_class); return CONTAINER_OF(vconn, struct pstream_vconn, vconn); } -- 2.43.0