'const fooPtr' is the same as 'foo * const' (the pointer won't change, but it's contents can). But in general, if an interface is trying to be const-correct, it should be using 'const foo *' (the pointer is to data that can't be changed). Fix up offenders in src/util outside of the virnet namespace. Also, make a few virSocketAddr functions const-correct, for easier conversions in future patches. * src/util/virbuffer.h (virBufferError, virBufferUse) (virBufferGetIndent): Use intended type. * src/util/virmacaddr.h (virMacAddrCmp, virMacAddrCmpRaw) (virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast) (virMacAddrIsMulticast): Likewise. * src/util/virebtables.h (ebtablesAddForwardAllowIn) (ebtablesRemoveForwardAllowIn): Likewise. * src/util/virsocketaddr.h (virSocketAddrSetIPv4Addr): Drop incorrect const. (virMacAddrGetRaw, virSocketAddrFormat, virSocketAddrFormatFull): Make const-correct. (virSocketAddrMask, virSocketAddrMaskByPrefix) (virSocketAddrBroadcast, virSocketAddrBroadcastByPrefix) (virSocketAddrGetNumNetmaskBits, virSocketAddrGetIpPrefix) (virSocketAddrEqual, virSocketAddrIsPrivate) (virSocketAddrIsWildcard): Use intended type. * src/util/virbuffer.c (virBufferError, virBufferUse) (virBufferGetIndent): Fix fallout. * src/util/virmacaddr.c (virMacAddrCmp, virMacAddrCmpRaw) (virMacAddrSet, virMcAddrFormat, virMacAddrIsUnicast) (virMacAddrIsMulticast): Likewise. * src/util/virebtables.c (ebtablesAddForwardAllowIn) (ebtablesRemoveForwardAllowIn): Likewise. * src/util/virsocketaddr.c (virSocketAddrMask, virMacAddrGetRaw) (virSocketAddrMaskByPrefix, virSocketAddrBroadcast) (virSocketAddrBroadcastByPrefix, virSocketAddrGetNumNetmaskBits) (virSocketAddrGetIpPrefix, virSocketAddrEqual) (virSocketAddrIsPrivate, virSocketAddrIsWildcard) (virSocketAddrGetIPv4Addr, virSocketAddrGetIPv6Addr) (virSocketAddrFormat, virSocketAddrFormatFull): Likewise. Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> --- src/util/virbuffer.c | 8 +++---- src/util/virbuffer.h | 8 +++---- src/util/virebtables.c | 4 ++-- src/util/virebtables.h | 6 +++--- src/util/virmacaddr.c | 16 +++++++------- src/util/virmacaddr.h | 16 +++++++------- src/util/virsocketaddr.c | 54 +++++++++++++++++++++++++++--------------------- src/util/virsocketaddr.h | 52 +++++++++++++++++++++++----------------------- 8 files changed, 85 insertions(+), 79 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index ee0be6c..eb29012 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -1,7 +1,7 @@ /* * virbuffer.c: buffers for libvirt * - * Copyright (C) 2005-2008, 2010-2012 Red Hat, Inc. + * Copyright (C) 2005-2008, 2010-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -95,7 +95,7 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) * Return the current auto-indent value, or -1 if there has been an error. */ int -virBufferGetIndent(const virBufferPtr buf, bool dynamic) +virBufferGetIndent(const virBuffer *buf, bool dynamic) { if (!buf || buf->error) return -1; @@ -255,7 +255,7 @@ void virBufferFreeAndReset(virBufferPtr buf) * Return positive errno value or -1 on usage error, 0 if normal */ int -virBufferError(const virBufferPtr buf) +virBufferError(const virBuffer *buf) { if (buf == NULL) return -1; @@ -270,7 +270,7 @@ virBufferError(const virBufferPtr buf) * Return the string usage in bytes */ unsigned int -virBufferUse(const virBufferPtr buf) +virBufferUse(const virBuffer *buf) { if (buf == NULL) return 0; diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index e0b77ab..a0cc4e6 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -1,7 +1,7 @@ /* * virbuffer.h: buffers for libvirt * - * Copyright (C) 2005-2008, 2011, 2012 Red Hat, Inc. + * Copyright (C) 2005-2008, 2011-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -52,8 +52,8 @@ struct _virBuffer { const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); -int virBufferError(const virBufferPtr buf); -unsigned int virBufferUse(const virBufferPtr buf); +int virBufferError(const virBuffer *buf); +unsigned int virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddChar(virBufferPtr buf, char c); void virBufferAsprintf(virBufferPtr buf, const char *format, ...) @@ -75,7 +75,7 @@ void virBufferURIEncodeString(virBufferPtr buf, const char *str); virBufferAdd(buf_, "" literal_string_ "", sizeof(literal_string_) - 1) void virBufferAdjustIndent(virBufferPtr buf, int indent); -int virBufferGetIndent(const virBufferPtr buf, bool dynamic); +int virBufferGetIndent(const virBuffer *buf, bool dynamic); void virBufferTrim(virBufferPtr buf, const char *trim, int len); diff --git a/src/util/virebtables.c b/src/util/virebtables.c index 6819686..67f281c 100644 --- a/src/util/virebtables.c +++ b/src/util/virebtables.c @@ -449,7 +449,7 @@ ebtablesForwardAllowIn(ebtablesContext *ctx, int ebtablesAddForwardAllowIn(ebtablesContext *ctx, const char *iface, - const virMacAddrPtr mac) + const virMacAddr *mac) { char macaddr[VIR_MAC_STRING_BUFLEN]; @@ -472,7 +472,7 @@ ebtablesAddForwardAllowIn(ebtablesContext *ctx, int ebtablesRemoveForwardAllowIn(ebtablesContext *ctx, const char *iface, - const virMacAddrPtr mac) + const virMacAddr *mac) { char macaddr[VIR_MAC_STRING_BUFLEN]; diff --git a/src/util/virebtables.h b/src/util/virebtables.h index 3dfe32b..c0d443d 100644 --- a/src/util/virebtables.h +++ b/src/util/virebtables.h @@ -1,8 +1,8 @@ /* * virebtables.c: Helper APIs for managing ebtables * + * Copyright (C) 2007-2008, 2013 Red Hat, Inc. * Copyright (C) 2009 IBM Corp. - * Copyright (C) 2007, 2008 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -54,10 +54,10 @@ void ebtablesSaveRules (ebtablesContext *ctx); int ebtablesAddForwardAllowIn (ebtablesContext *ctx, const char *iface, - const virMacAddrPtr mac); + const virMacAddr *mac); int ebtablesRemoveForwardAllowIn (ebtablesContext *ctx, const char *iface, - const virMacAddrPtr mac); + const virMacAddr *mac); int ebtablesAddForwardPolicyReject(ebtablesContext *ctx); diff --git a/src/util/virmacaddr.c b/src/util/virmacaddr.c index 2e9328d..ebd1182 100644 --- a/src/util/virmacaddr.c +++ b/src/util/virmacaddr.c @@ -1,7 +1,7 @@ /* * virmacaddr.c: MAC address handling * - * Copyright (C) 2006-2012 Red Hat, Inc. + * Copyright (C) 2006-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -74,7 +74,7 @@ virMacAddrCompare(const char *p, const char *q) * > 0 if mac1 > mac2 */ int -virMacAddrCmp(const virMacAddrPtr mac1, const virMacAddrPtr mac2) +virMacAddrCmp(const virMacAddr *mac1, const virMacAddr *mac2) { return memcmp(mac1->addr, mac2->addr, VIR_MAC_BUFLEN); } @@ -89,7 +89,7 @@ virMacAddrCmp(const virMacAddrPtr mac1, const virMacAddrPtr mac2) * > 0 if mac1 > mac2 */ int -virMacAddrCmpRaw(const virMacAddrPtr mac1, +virMacAddrCmpRaw(const virMacAddr *mac1, const unsigned char mac2[VIR_MAC_BUFLEN]) { return memcmp(mac1->addr, mac2, VIR_MAC_BUFLEN); @@ -103,7 +103,7 @@ virMacAddrCmpRaw(const virMacAddrPtr mac1, * Copy src to dst */ void -virMacAddrSet(virMacAddrPtr dst, const virMacAddrPtr src) +virMacAddrSet(virMacAddrPtr dst, const virMacAddr *src) { memcpy(dst, src, sizeof(*src)); } @@ -129,7 +129,7 @@ virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char src[VIR_MAC_BUFLEN]) * Copies the MAC address into raw memory */ void -virMacAddrGetRaw(virMacAddrPtr src, unsigned char dst[VIR_MAC_BUFLEN]) +virMacAddrGetRaw(const virMacAddr *src, unsigned char dst[VIR_MAC_BUFLEN]) { memcpy(dst, src->addr, VIR_MAC_BUFLEN); } @@ -187,7 +187,7 @@ virMacAddrParse(const char* str, virMacAddrPtr addr) * Returns a pointer to the resulting character string. */ const char * -virMacAddrFormat(const virMacAddrPtr addr, +virMacAddrFormat(const virMacAddr *addr, char *str) { snprintf(str, VIR_MAC_STRING_BUFLEN, @@ -211,13 +211,13 @@ void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN], /* The low order bit of the first byte is the "multicast" bit. */ bool -virMacAddrIsMulticast(const virMacAddrPtr mac) +virMacAddrIsMulticast(const virMacAddr *mac) { return !!(mac->addr[0] & 1); } bool -virMacAddrIsUnicast(const virMacAddrPtr mac) +virMacAddrIsUnicast(const virMacAddr *mac) { return !(mac->addr[0] & 1); } diff --git a/src/util/virmacaddr.h b/src/util/virmacaddr.h index 3697a5c..49efc36 100644 --- a/src/util/virmacaddr.h +++ b/src/util/virmacaddr.h @@ -1,7 +1,7 @@ /* * virmacaddr.h: MAC address handling * - * Copyright (C) 2006-2012 Red Hat, Inc. + * Copyright (C) 2006-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -38,20 +38,20 @@ struct _virMacAddr { }; int virMacAddrCompare(const char *mac1, const char *mac2); -int virMacAddrCmp(const virMacAddrPtr mac1, const virMacAddrPtr mac2); -int virMacAddrCmpRaw(const virMacAddrPtr mac1, +int virMacAddrCmp(const virMacAddr *mac1, const virMacAddr *mac2); +int virMacAddrCmpRaw(const virMacAddr *mac1, const unsigned char s[VIR_MAC_BUFLEN]); -void virMacAddrSet(virMacAddrPtr dst, const virMacAddrPtr src); +void virMacAddrSet(virMacAddrPtr dst, const virMacAddr *src); void virMacAddrSetRaw(virMacAddrPtr dst, const unsigned char s[VIR_MAC_BUFLEN]); -void virMacAddrGetRaw(virMacAddrPtr src, unsigned char dst[VIR_MAC_BUFLEN]); -const char *virMacAddrFormat(const virMacAddrPtr addr, +void virMacAddrGetRaw(const virMacAddr *src, unsigned char dst[VIR_MAC_BUFLEN]); +const char *virMacAddrFormat(const virMacAddr *addr, char *str); void virMacAddrGenerate(const unsigned char prefix[VIR_MAC_PREFIX_BUFLEN], virMacAddrPtr addr); int virMacAddrParse(const char* str, virMacAddrPtr addr) ATTRIBUTE_RETURN_CHECK; -bool virMacAddrIsUnicast(const virMacAddrPtr addr); -bool virMacAddrIsMulticast(const virMacAddrPtr addr); +bool virMacAddrIsUnicast(const virMacAddr *addr); +bool virMacAddrIsMulticast(const virMacAddr *addr); bool virMacAddrIsBroadcastRaw(const unsigned char s[VIR_MAC_BUFLEN]); #endif /* __VIR_MACADDR_H__ */ diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c index 3e01baf..03de62b 100644 --- a/src/util/virsocketaddr.c +++ b/src/util/virsocketaddr.c @@ -40,11 +40,14 @@ typedef virSocketAddrIPv4 *virSocketAddrIPv4Ptr; typedef unsigned short virSocketAddrIPv6[8]; typedef virSocketAddrIPv6 *virSocketAddrIPv6Ptr; -static int virSocketAddrGetIPv4Addr(virSocketAddrPtr addr, virSocketAddrIPv4Ptr tab) { +static int +virSocketAddrGetIPv4Addr(const virSocketAddr *addr, + virSocketAddrIPv4Ptr tab) +{ unsigned long val; size_t i; - if ((addr == NULL) || (tab == NULL) || (addr->data.stor.ss_family != AF_INET)) + if (!addr || !tab || addr->data.stor.ss_family != AF_INET) return -1; val = ntohl(addr->data.inet4.sin_addr.s_addr); @@ -57,10 +60,12 @@ static int virSocketAddrGetIPv4Addr(virSocketAddrPtr addr, virSocketAddrIPv4Ptr return 0; } -static int virSocketAddrGetIPv6Addr(virSocketAddrPtr addr, virSocketAddrIPv6Ptr tab) { +static int +virSocketAddrGetIPv6Addr(const virSocketAddr *addr, virSocketAddrIPv6Ptr tab) +{ size_t i; - if ((addr == NULL) || (tab == NULL) || (addr->data.stor.ss_family != AF_INET6)) + if (!addr || !tab || addr->data.stor.ss_family != AF_INET6) return -1; for (i = 0; i < 8; i++) { @@ -173,7 +178,7 @@ virSocketAddrSetIPv4Addr(virSocketAddrPtr addr, uint32_t val) * if their IP addresses and ports are equal. */ bool -virSocketAddrEqual(const virSocketAddrPtr s1, const virSocketAddrPtr s2) +virSocketAddrEqual(const virSocketAddr *s1, const virSocketAddr *s2) { if (s1->data.stor.ss_family != s2->data.stor.ss_family) return false; @@ -206,7 +211,7 @@ virSocketAddrEqual(const virSocketAddrPtr s1, const virSocketAddrPtr s2) * See RFC1918, RFC3484, and RFC4193 for details. */ bool -virSocketAddrIsPrivate(const virSocketAddrPtr addr) +virSocketAddrIsPrivate(const virSocketAddr *addr) { unsigned long val; @@ -233,7 +238,7 @@ virSocketAddrIsPrivate(const virSocketAddrPtr addr) * Check if passed address is a variant of ANYCAST address. */ bool -virSocketAddrIsWildcard(const virSocketAddrPtr addr) +virSocketAddrIsWildcard(const virSocketAddr *addr) { struct in_addr tmp = { .s_addr = INADDR_ANY }; switch (addr->data.stor.ss_family) { @@ -255,7 +260,8 @@ virSocketAddrIsWildcard(const virSocketAddrPtr addr) * Caller must free the returned string */ char * -virSocketAddrFormat(virSocketAddrPtr addr) { +virSocketAddrFormat(const virSocketAddr *addr) +{ return virSocketAddrFormatFull(addr, false, NULL); } @@ -271,7 +277,7 @@ virSocketAddrFormat(virSocketAddrPtr addr) { * Caller must free the returned string */ char * -virSocketAddrFormatFull(virSocketAddrPtr addr, +virSocketAddrFormatFull(const virSocketAddr *addr, bool withService, const char *separator) { @@ -399,9 +405,9 @@ int virSocketAddrIsNetmask(virSocketAddrPtr netmask) { * Returns 0 in case of success, or -1 on error. */ int -virSocketAddrMask(const virSocketAddrPtr addr, - const virSocketAddrPtr netmask, - virSocketAddrPtr network) +virSocketAddrMask(const virSocketAddr *addr, + const virSocketAddr *netmask, + virSocketAddrPtr network) { if (addr->data.stor.ss_family != netmask->data.stor.ss_family) { network->data.stor.ss_family = AF_UNSPEC; @@ -445,9 +451,9 @@ virSocketAddrMask(const virSocketAddrPtr addr, * Returns 0 in case of success, or -1 on error. */ int -virSocketAddrMaskByPrefix(const virSocketAddrPtr addr, - unsigned int prefix, - virSocketAddrPtr network) +virSocketAddrMaskByPrefix(const virSocketAddr *addr, + unsigned int prefix, + virSocketAddrPtr network) { virSocketAddr netmask; @@ -472,9 +478,9 @@ virSocketAddrMaskByPrefix(const virSocketAddrPtr addr, * Returns 0 in case of success, or -1 on error. */ int -virSocketAddrBroadcast(const virSocketAddrPtr addr, - const virSocketAddrPtr netmask, - virSocketAddrPtr broadcast) +virSocketAddrBroadcast(const virSocketAddr *addr, + const virSocketAddr *netmask, + virSocketAddrPtr broadcast) { if ((addr->data.stor.ss_family != AF_INET) || (netmask->data.stor.ss_family != AF_INET)) { @@ -502,9 +508,9 @@ virSocketAddrBroadcast(const virSocketAddrPtr addr, * Returns 0 in case of success, or -1 on error. */ int -virSocketAddrBroadcastByPrefix(const virSocketAddrPtr addr, - unsigned int prefix, - virSocketAddrPtr broadcast) +virSocketAddrBroadcastByPrefix(const virSocketAddr *addr, + unsigned int prefix, + virSocketAddrPtr broadcast) { virSocketAddr netmask; @@ -639,7 +645,7 @@ int virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end) { * Returns the number of bits in the netmask or -1 if an error occurred * or the netmask is invalid. */ -int virSocketAddrGetNumNetmaskBits(const virSocketAddrPtr netmask) +int virSocketAddrGetNumNetmaskBits(const virSocketAddr *netmask) { size_t i, j; int c = 0; @@ -786,8 +792,8 @@ error: */ int -virSocketAddrGetIpPrefix(const virSocketAddrPtr address, - const virSocketAddrPtr netmask, +virSocketAddrGetIpPrefix(const virSocketAddr *address, + const virSocketAddr *netmask, int prefix) { if (prefix > 0) { diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h index b28fe6c..0bb9187 100644 --- a/src/util/virsocketaddr.h +++ b/src/util/virsocketaddr.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2012 Red Hat, Inc. + * Copyright (C) 2009-2013 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -80,12 +80,12 @@ int virSocketAddrParseIPv4(virSocketAddrPtr addr, int virSocketAddrParseIPv6(virSocketAddrPtr addr, const char *val); -void virSocketAddrSetIPv4Addr(const virSocketAddrPtr s, uint32_t addr); +void virSocketAddrSetIPv4Addr(virSocketAddrPtr s, uint32_t addr); -char * virSocketAddrFormat(virSocketAddrPtr addr); -char * virSocketAddrFormatFull(virSocketAddrPtr addr, - bool withService, - const char *separator); +char *virSocketAddrFormat(const virSocketAddr *addr); +char *virSocketAddrFormatFull(const virSocketAddr *addr, + bool withService, + const char *separator); int virSocketAddrSetPort(virSocketAddrPtr addr, int port); @@ -99,29 +99,29 @@ int virSocketAddrIsNetmask(virSocketAddrPtr netmask); int virSocketAddrCheckNetmask(virSocketAddrPtr addr1, virSocketAddrPtr addr2, virSocketAddrPtr netmask); -int virSocketAddrMask(const virSocketAddrPtr addr, - const virSocketAddrPtr netmask, - virSocketAddrPtr network); -int virSocketAddrMaskByPrefix(const virSocketAddrPtr addr, - unsigned int prefix, - virSocketAddrPtr network); -int virSocketAddrBroadcast(const virSocketAddrPtr addr, - const virSocketAddrPtr netmask, - virSocketAddrPtr broadcast); -int virSocketAddrBroadcastByPrefix(const virSocketAddrPtr addr, - unsigned int prefix, - virSocketAddrPtr broadcast); - -int virSocketAddrGetNumNetmaskBits(const virSocketAddrPtr netmask); +int virSocketAddrMask(const virSocketAddr *addr, + const virSocketAddr *netmask, + virSocketAddrPtr network); +int virSocketAddrMaskByPrefix(const virSocketAddr *addr, + unsigned int prefix, + virSocketAddrPtr network); +int virSocketAddrBroadcast(const virSocketAddr *addr, + const virSocketAddr *netmask, + virSocketAddrPtr broadcast); +int virSocketAddrBroadcastByPrefix(const virSocketAddr *addr, + unsigned int prefix, + virSocketAddrPtr broadcast); + +int virSocketAddrGetNumNetmaskBits(const virSocketAddr *netmask); int virSocketAddrPrefixToNetmask(unsigned int prefix, virSocketAddrPtr netmask, int family); -int virSocketAddrGetIpPrefix(const virSocketAddrPtr address, - const virSocketAddrPtr netmask, +int virSocketAddrGetIpPrefix(const virSocketAddr *address, + const virSocketAddr *netmask, int prefix); -bool virSocketAddrEqual(const virSocketAddrPtr s1, - const virSocketAddrPtr s2); -bool virSocketAddrIsPrivate(const virSocketAddrPtr addr); +bool virSocketAddrEqual(const virSocketAddr *s1, + const virSocketAddr *s2); +bool virSocketAddrIsPrivate(const virSocketAddr *addr); -bool virSocketAddrIsWildcard(const virSocketAddrPtr addr); +bool virSocketAddrIsWildcard(const virSocketAddr *addr); #endif /* __VIR_SOCKETADDR_H__ */ -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list