From 5422bed9535af8ce82bdb31b2544c775c8cc62d0 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 29 Feb 2012 08:06:36 +0100 Subject: const-ify static data objects Signed-off-by: Jan Engelhardt --- src/libnetfilter_cttimeout.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/libnetfilter_cttimeout.c b/src/libnetfilter_cttimeout.c index 2f1ba79..6050514 100644 --- a/src/libnetfilter_cttimeout.c +++ b/src/libnetfilter_cttimeout.c @@ -21,7 +21,7 @@ #include -static char *tcp_state_to_name[] = { +static const char *const tcp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_TCP_SYN_SENT] = "SYN_SENT", [NFCT_TIMEOUT_ATTR_TCP_SYN_RECV] = "SYN_RECV", [NFCT_TIMEOUT_ATTR_TCP_ESTABLISHED] = "ESTABLISHED", @@ -35,16 +35,16 @@ static char *tcp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_TCP_UNACK] = "UNACKNOWLEDGED", }; -static char *generic_state_to_name[] = { +static const char *const generic_state_to_name[] = { [NFCT_TIMEOUT_ATTR_GENERIC] = "TIMEOUT", }; -static char *udp_state_to_name[] = { +static const char *const udp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_UDP_UNREPLIED] = "UNREPLIED", [NFCT_TIMEOUT_ATTR_UDP_REPLIED] = "REPLIED", }; -static char *sctp_state_to_name[] = { +static const char *const sctp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_SCTP_CLOSED] = "CLOSED", [NFCT_TIMEOUT_ATTR_SCTP_COOKIE_WAIT] = "COOKIE_WAIT", [NFCT_TIMEOUT_ATTR_SCTP_COOKIE_ECHOED] = "COOKIE_ECHOED", @@ -54,7 +54,7 @@ static char *sctp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_SCTP_SHUTDOWN_ACK_SENT] = "SHUTDOWN_ACK_SENT", }; -static char *dccp_state_to_name[] = { +static const char *const dccp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_DCCP_REQUEST] = "REQUEST", [NFCT_TIMEOUT_ATTR_DCCP_RESPOND] = "RESPOND", [NFCT_TIMEOUT_ATTR_DCCP_PARTOPEN] = "PARTOPEN", @@ -64,14 +64,14 @@ static char *dccp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_DCCP_TIMEWAIT] = "TIMEWAIT", }; -static char *icmp_state_to_name[] = { +static const char *const icmp_state_to_name[] = { [NFCT_TIMEOUT_ATTR_ICMP] = "TIMEOUT", }; static struct { uint32_t nlattr_max; uint32_t attr_max; - char **state_to_name; + const char *const *state_to_name; } timeout_protocol[IPPROTO_MAX] = { [IPPROTO_ICMP] = { .nlattr_max = __CTA_TIMEOUT_ICMP_MAX, -- cgit v1.2.3 From 6a56d048846547a5d5f5afded654f965b156c9b4 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 29 Feb 2012 08:07:23 +0100 Subject: Add stdint header and type corrections 1. stdint.h is needed since you use uintXX_t in various places. 2. mnl_attr_get_type yields uint16_t, prefer to use it. 3. Since ->nlattr_max is uint32_t, most dependent uses should be unsigned too. Signed-off-by: Jan Engelhardt --- src/libnetfilter_cttimeout.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/libnetfilter_cttimeout.c b/src/libnetfilter_cttimeout.c index 6050514..707543a 100644 --- a/src/libnetfilter_cttimeout.c +++ b/src/libnetfilter_cttimeout.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -432,7 +433,7 @@ static int timeout_nlmsg_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; - int type = mnl_attr_get_type(attr); + uint16_t type = mnl_attr_get_type(attr); if (mnl_attr_type_valid(attr, CTA_TIMEOUT_MAX) < 0) return MNL_CB_OK; @@ -468,7 +469,7 @@ timeout_nlmsg_parse_attr_cb(const struct nlattr *attr, void *data) } struct _container_policy_cb { - int nlattr_max; + unsigned int nlattr_max; void *tb; }; @@ -477,7 +478,7 @@ parse_timeout_attr_policy_cb(const struct nlattr *attr, void *data) { struct _container_policy_cb *data_cb = data; const struct nlattr **tb = data_cb->tb; - int type = mnl_attr_get_type(attr); + uint16_t type = mnl_attr_get_type(attr); if (mnl_attr_type_valid(attr, data_cb->nlattr_max) < 0) return MNL_CB_OK; @@ -495,13 +496,13 @@ parse_timeout_attr_policy_cb(const struct nlattr *attr, void *data) static void timeout_parse_attr_data(struct nfct_timeout *t, const struct nlattr *nest) { - int nlattr_max = timeout_protocol[t->l4num].nlattr_max; + unsigned int nlattr_max = timeout_protocol[t->l4num].nlattr_max; struct nlattr *tb[nlattr_max]; struct _container_policy_cb cnt = { .nlattr_max = nlattr_max, .tb = tb, }; - int i; + unsigned int i; memset(tb, 0, sizeof(struct nlattr *) * nlattr_max); -- cgit v1.2.3 From a250aaf6db151c812d06f2af380261935fa59b60 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 29 Feb 2012 08:09:35 +0100 Subject: Properly NUL-terminate name in nfct_timeout_attr_set Signed-off-by: Jan Engelhardt --- src/libnetfilter_cttimeout.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libnetfilter_cttimeout.c b/src/libnetfilter_cttimeout.c index 707543a..1f7c63e 100644 --- a/src/libnetfilter_cttimeout.c +++ b/src/libnetfilter_cttimeout.c @@ -177,7 +177,8 @@ nfct_timeout_attr_set(struct nfct_timeout *t, uint32_t type, const void *data) { switch(type) { case NFCT_TIMEOUT_ATTR_NAME: - strncpy(t->name, data, 32); + strncpy(t->name, data, sizeof(t->name)); + t->name[sizeof(t->name)-1] = '\0'; break; case NFCT_TIMEOUT_ATTR_L3PROTO: t->l3num = *((uint16_t *) data); -- cgit v1.2.3 From ad969d490a7c987c48a708e6a7bef0db30f68fb9 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 29 Feb 2012 08:09:45 +0100 Subject: const-ify arguments of functions Signed-off-by: Jan Engelhardt --- src/libnetfilter_cttimeout.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/libnetfilter_cttimeout.c b/src/libnetfilter_cttimeout.c index 1f7c63e..c7060ff 100644 --- a/src/libnetfilter_cttimeout.c +++ b/src/libnetfilter_cttimeout.c @@ -292,7 +292,7 @@ EXPORT_SYMBOL(nfct_timeout_policy_attr_unset); * This function returns -1 in case that some mandatory attributes are * missing. On sucess, it returns 0. */ -int nfct_timeout_snprintf(char *buf, size_t size, struct nfct_timeout *t, +int nfct_timeout_snprintf(char *buf, size_t size, const struct nfct_timeout *t, unsigned int flags) { int ret = 0; @@ -401,7 +401,8 @@ EXPORT_SYMBOL(nfct_timeout_nlmsg_build_hdr); * \param t: pointer to a conntrack timeout object */ void -nfct_timeout_nlmsg_build_payload(struct nlmsghdr *nlh, struct nfct_timeout *t) +nfct_timeout_nlmsg_build_payload(struct nlmsghdr *nlh, + const struct nfct_timeout *t) { int i; struct nlattr *nest; -- cgit v1.2.3