From 8dd10256cb24ceade8b40bd1604f03ddac8589e2 Mon Sep 17 00:00:00 2001 From: Jozsef Kadlecsik Date: Tue, 29 Jun 2010 21:14:40 +0200 Subject: ipset 5: Sparc related and compatibility fixes ipset 5 is tested on Sparc, which revealed some compatibility issues and those are fixed. Kernels from 2.6.31 onward are supported. The testsuite checkings are completed to run match/target checks. The README file is updated to reflect the requirements to install and run ipset 5. --- lib/parse.c | 14 ++++++++------ lib/print.c | 16 ++++++++-------- lib/session.c | 26 +++++++++++++++----------- lib/types.c | 2 +- 4 files changed, 32 insertions(+), 26 deletions(-) (limited to 'lib') diff --git a/lib/parse.c b/lib/parse.c index b1fecc7..84b6a3f 100644 --- a/lib/parse.c +++ b/lib/parse.c @@ -437,7 +437,7 @@ get_addrinfo##f(struct ipset_session *session, \ struct in##n##_addr **inaddr) \ { \ struct addrinfo *i; \ - struct sockaddr_in##n *saddr; \ + struct sockaddr_in##n saddr; \ int found; \ \ if ((*info = get_addrinfo(session, str, family)) == NULL) { \ @@ -447,16 +447,18 @@ get_addrinfo##f(struct ipset_session *session, \ } \ \ for (i = *info, found = 0; i != NULL; i = i->ai_next) { \ - if (i->ai_family != family) \ + if (i->ai_family != family \ + || i->ai_addrlen != sizeof(saddr)) \ continue; \ if (found == 0) { \ - saddr = (struct sockaddr_in##n *)i->ai_addr; \ - *inaddr = &saddr->sin##n##_addr; \ - } else if (found == 1) { \ + /* Workaround: can't cast on Sparc */ \ + memcpy(&saddr, i->ai_addr, sizeof(saddr)); \ + *inaddr = &saddr.sin##n##_addr; \ + } else if (found == 1) { \ ipset_warn(session, \ "%s resolves to multiple addresses: " \ "using only the first one returned by the resolver", \ - str); \ + str); \ } \ found++; \ } \ diff --git a/lib/print.c b/lib/print.c index 68f658a..77c283a 100644 --- a/lib/print.c +++ b/lib/print.c @@ -220,7 +220,7 @@ ipset_print_ip(char *buf, unsigned int len, family = ipset_data_family(data); cidropt = opt == IPSET_OPT_IP ? IPSET_OPT_CIDR : IPSET_OPT_CIDR2; if (ipset_data_test(data, cidropt)) { - cidr = *(uint8_t *) ipset_data_get(data, cidropt); + cidr = *(const uint8_t *) ipset_data_get(data, cidropt); D("CIDR: %u", cidr); } else cidr = family == AF_INET6 ? 128 : 32; @@ -287,7 +287,7 @@ ipset_print_ipaddr(char *buf, unsigned int len, family = ipset_data_family(data); cidropt = opt == IPSET_OPT_IP ? IPSET_OPT_CIDR : IPSET_OPT_CIDR2; if (ipset_data_test(data, cidropt)) - cidr = *(uint8_t *) ipset_data_get(data, cidropt); + cidr = *(const uint8_t *) ipset_data_get(data, cidropt); else cidr = family == AF_INET6 ? 128 : 32; flags = env & (1 << IPSET_ENV_RESOLVE) ? 0 : NI_NUMERICHOST; @@ -330,12 +330,12 @@ ipset_print_number(char *buf, unsigned int len, maxsize = ipset_data_sizeof(opt, AF_INET); D("opt: %u, maxsize %zu", opt, maxsize); if (maxsize == sizeof(uint8_t)) - return snprintf(buf, len, "%u", *(uint8_t *) number); + return snprintf(buf, len, "%u", *(const uint8_t *) number); else if (maxsize == sizeof(uint16_t)) - return snprintf(buf, len, "%u", *(uint16_t *) number); + return snprintf(buf, len, "%u", *(const uint16_t *) number); else if (maxsize == sizeof(uint32_t)) return snprintf(buf, len, "%lu", - (long unsigned) *(uint32_t *) number); + (long unsigned) *(const uint32_t *) number); else assert(0); return 0; @@ -377,8 +377,8 @@ ipset_print_name(char *buf, unsigned int len, if (ipset_data_test(data, IPSET_OPT_NAMEREF)) { bool before = false; if (ipset_data_flags_test(data, IPSET_FLAG(IPSET_OPT_FLAGS))) { - uint32_t *flags = - (uint32_t *)ipset_data_get(data, IPSET_OPT_FLAGS); + const uint32_t *flags = + ipset_data_get(data, IPSET_OPT_FLAGS); before = (*flags) & IPSET_FLAG_BEFORE; } size = snprintf(buf + offset, len, @@ -460,7 +460,7 @@ ipset_print_proto(char *buf, unsigned int len, assert(data); assert(opt == IPSET_OPT_PROTO); - proto = *(uint8_t *) ipset_data_get(data, IPSET_OPT_PROTO); + proto = *(const uint8_t *) ipset_data_get(data, IPSET_OPT_PROTO); assert(proto); if (proto == IPSET_IPPROTO_ANY) diff --git a/lib/session.c b/lib/session.c index fe1e178..8a0493a 100644 --- a/lib/session.c +++ b/lib/session.c @@ -50,7 +50,7 @@ struct ipset_session { uint8_t envopts; /* Session env opts */ /* Kernel message buffer */ size_t bufsize; - char buffer[0]; + void *buffer; }; /* @@ -494,7 +494,7 @@ attr2data(struct ipset_session *session, struct nlattr *nla[], case MNL_TYPE_U32: { uint32_t value; - value = ntohl(*(uint32_t *)d); + value = ntohl(*(const uint32_t *)d); d = &value; break; @@ -502,7 +502,7 @@ attr2data(struct ipset_session *session, struct nlattr *nla[], case MNL_TYPE_U16: { uint16_t value; - value = ntohs(*(uint16_t *)d); + value = ntohs(*(const uint16_t *)d); d = &value; break; @@ -513,13 +513,13 @@ attr2data(struct ipset_session *session, struct nlattr *nla[], } #ifdef IPSET_DEBUG if (type == IPSET_ATTR_TYPENAME) - D("nla typename %s", (char *) d); + D("nla typename %s", (const char *) d); #endif ret = ipset_data_set(data, attr->opt, d); #ifdef IPSET_DEBUG if (type == IPSET_ATTR_TYPENAME) D("nla typename %s", - (char *) ipset_data_get(data, IPSET_OPT_TYPENAME)); + (const char *) ipset_data_get(data, IPSET_OPT_TYPENAME)); #endif return ret; } @@ -907,7 +907,7 @@ callback_list(struct ipset_session *session, struct nlattr *nla[], ATTR2DATA(session, nla, IPSET_ATTR_REVISION, cmd_attrs); D("head: family %u, typename %s", ipset_data_family(data), - (char *) ipset_data_get(data, IPSET_OPT_TYPENAME)); + (const char *) ipset_data_get(data, IPSET_OPT_TYPENAME)); if (mnl_attr_parse_nested(nla[IPSET_ATTR_DATA], create_attr_cb, cattr) < 0) FAILURE("Broken %s kernel message: " @@ -1326,13 +1326,13 @@ rawdata2attr(struct nlmsghdr *nlh, switch (attr->type) { case MNL_TYPE_U32: { - uint32_t value = htonl(*(uint32_t *)d); + uint32_t value = htonl(*(const uint32_t *)d); d = &value; break; } case MNL_TYPE_U16: { - uint16_t value = htons(*(uint16_t *)d); + uint16_t value = htons(*(const uint16_t *)d); d = &value; break; @@ -1415,7 +1415,7 @@ static int build_send_private_msg(struct ipset_session *session, enum ipset_cmd cmd) { char buffer[PRIVATE_MSG_BUFLEN] __attribute__ ((aligned)); - struct nlmsghdr *nlh = (struct nlmsghdr *) buffer; + struct nlmsghdr *nlh = (struct nlmsghdr *) (void *) buffer; struct ipset_data *data = session->data; int len = PRIVATE_MSG_BUFLEN, ret; enum ipset_cmd saved = session->cmd; @@ -1469,7 +1469,10 @@ may_aggregate_ad(struct ipset_session *session, struct ipset_data *data, && STREQ(ipset_data_setname(data), session->saved_setname); } -static int +int +build_msg(struct ipset_session *session, bool aggregate); + +int build_msg(struct ipset_session *session, bool aggregate) { struct nlmsghdr *nlh = (struct nlmsghdr *) session->buffer; @@ -1768,12 +1771,13 @@ ipset_session_init(ipset_outfn outfn) { struct ipset_session *session; size_t bufsize = getpagesize(); - + /* Create session object */ session = calloc(1, sizeof(struct ipset_session) + bufsize); if (session == NULL) return NULL; session->bufsize = bufsize; + session->buffer = session + 1; /* The single transport method yet */ session->transport = &ipset_mnl_transport; diff --git a/lib/types.c b/lib/types.c index b39a04f..067abcb 100644 --- a/lib/types.c +++ b/lib/types.c @@ -404,7 +404,7 @@ ipset_type_check(struct ipset_session *session) typename = ipset_data_get(data, IPSET_OPT_TYPENAME); family = ipset_data_family(data); - revision = *(uint8_t *) ipset_data_get(data, IPSET_OPT_REVISION); + revision = *(const uint8_t *) ipset_data_get(data, IPSET_OPT_REVISION); /* Check registered types */ for (t = typelist; t != NULL && match == NULL; t = t->next) { -- cgit v1.2.3