* [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const.
@ 2010-06-05 6:40 David Favro
2010-06-05 6:40 ` [PATCH libnetfilter_queue 2/3] Payload buffer datatypes are consistent David Favro
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: David Favro @ 2010-06-05 6:40 UTC (permalink / raw)
To: netfilter; +Cc: pablo, David Favro
The payload parameters to nfq_set_verdict(), nfq_set_verdict2(), and
nfq_set_verdict_mark() are not modified by those functions, and
therefore should have datatype pointer-to-const. This both causes the
source-code to more effectively represent what is the purpose of the
parameter, and eliminates the need to cast away const-ness when calling
the functions with compilers that enforce strict casting. All existing
calling code should not need modification as pointer-to-X automatically
converts to pointer-to-const-X.
Signed-off-by: David Favro <netfilter@meta-dynamic.com>
---
include/libnetfilter_queue/libnetfilter_queue.h | 6 +++---
src/libnetfilter_queue.c | 11 ++++++-----
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/include/libnetfilter_queue/libnetfilter_queue.h b/include/libnetfilter_queue/libnetfilter_queue.h
index 88a9b8c..2e2ca8b 100644
--- a/include/libnetfilter_queue/libnetfilter_queue.h
+++ b/include/libnetfilter_queue/libnetfilter_queue.h
@@ -60,14 +60,14 @@ extern int nfq_set_verdict(struct nfq_q_handle *qh,
u_int32_t id,
u_int32_t verdict,
u_int32_t data_len,
- unsigned char *buf);
+ const unsigned char *buf);
extern int nfq_set_verdict2(struct nfq_q_handle *qh,
u_int32_t id,
u_int32_t verdict,
u_int32_t mark,
u_int32_t datalen,
- unsigned char *buf);
+ const unsigned char *buf);
extern __attribute__((deprecated))
int nfq_set_verdict_mark(struct nfq_q_handle *qh,
@@ -75,7 +75,7 @@ int nfq_set_verdict_mark(struct nfq_q_handle *qh,
u_int32_t verdict,
u_int32_t mark,
u_int32_t datalen,
- unsigned char *buf);
+ const unsigned char *buf);
/* message parsing function */
diff --git a/src/libnetfilter_queue.c b/src/libnetfilter_queue.c
index cc19e6a..4cc4925 100644
--- a/src/libnetfilter_queue.c
+++ b/src/libnetfilter_queue.c
@@ -610,7 +610,7 @@ int nfq_set_queue_maxlen(struct nfq_q_handle *qh,
static int __set_verdict(struct nfq_q_handle *qh, u_int32_t id,
u_int32_t verdict, u_int32_t mark, int set_mark,
- u_int32_t data_len, unsigned char *data)
+ u_int32_t data_len, const unsigned char *data)
{
struct nfqnl_msg_verdict_hdr vh;
union {
@@ -646,8 +646,9 @@ static int __set_verdict(struct nfq_q_handle *qh, u_int32_t id,
nvecs = 1;
if (data_len) {
+ /* The typecast here is to cast away data's const-ness: */
nfnl_build_nfa_iovec(&iov[1], &data_attr, NFQA_PAYLOAD,
- data_len, data);
+ data_len, (unsigned char *) data);
nvecs += 2;
/* Add the length of the appended data to the message
* header. The size of the attribute is given in the
@@ -688,7 +689,7 @@ static int __set_verdict(struct nfq_q_handle *qh, u_int32_t id,
*/
int nfq_set_verdict(struct nfq_q_handle *qh, u_int32_t id,
u_int32_t verdict, u_int32_t data_len,
- unsigned char *buf)
+ const unsigned char *buf)
{
return __set_verdict(qh, id, verdict, 0, 0, data_len, buf);
}
@@ -704,7 +705,7 @@ int nfq_set_verdict(struct nfq_q_handle *qh, u_int32_t id,
*/
int nfq_set_verdict2(struct nfq_q_handle *qh, u_int32_t id,
u_int32_t verdict, u_int32_t mark,
- u_int32_t data_len, unsigned char *buf)
+ u_int32_t data_len, const unsigned char *buf)
{
return __set_verdict(qh, id, verdict, htonl(mark), 1, data_len, buf);
}
@@ -725,7 +726,7 @@ int nfq_set_verdict2(struct nfq_q_handle *qh, u_int32_t id,
*/
int nfq_set_verdict_mark(struct nfq_q_handle *qh, u_int32_t id,
u_int32_t verdict, u_int32_t mark,
- u_int32_t data_len, unsigned char *buf)
+ u_int32_t data_len, const unsigned char *buf)
{
return __set_verdict(qh, id, verdict, mark, 1, data_len, buf);
}
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH libnetfilter_queue 2/3] Payload buffer datatypes are consistent.
2010-06-05 6:40 [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const David Favro
@ 2010-06-05 6:40 ` David Favro
2010-06-10 13:06 ` Pablo Neira Ayuso
2010-06-05 6:40 ` [PATCH libnetfilter_queue 3/3] Added .gitignore for base directory David Favro
2010-06-10 13:06 ` [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const Pablo Neira Ayuso
2 siblings, 1 reply; 6+ messages in thread
From: David Favro @ 2010-06-05 6:40 UTC (permalink / raw)
To: netfilter; +Cc: pablo, David Favro
The 'data' parameter to nfq_get_payload() returns pointer to unsigned
char (rather than signed char) to make it consistent with the 'buf'
parameter of nfq_set_verdict(), nfq_set_verdict2(), and
nfq_set_verdict_mark(), all of which refer to the same data. Either
signed or unsigned is fine, but they should be consistent as the output
of nfq_get_payload() may be passed back into nfq_set_verdict*(); in that
case, this change eliminates the need for typecasting in the calling
code when using compilers that enforce strict typecasting.
Signed-off-by: David Favro <netfilter@meta-dynamic.com>
---
include/libnetfilter_queue/libnetfilter_queue.h | 2 +-
src/libnetfilter_queue.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/include/libnetfilter_queue/libnetfilter_queue.h b/include/libnetfilter_queue/libnetfilter_queue.h
index 2e2ca8b..53bda74 100644
--- a/include/libnetfilter_queue/libnetfilter_queue.h
+++ b/include/libnetfilter_queue/libnetfilter_queue.h
@@ -104,7 +104,7 @@ extern int nfq_get_physoutdev_name(struct nlif_handle *nlif_handle,
extern struct nfqnl_msg_packet_hw *nfq_get_packet_hw(struct nfq_data *nfad);
/* return -1 if problem, length otherwise */
-extern int nfq_get_payload(struct nfq_data *nfad, char **data);
+extern int nfq_get_payload(struct nfq_data *nfad, unsigned char **data);
#ifdef __cplusplus
} /* extern "C" */
diff --git a/src/libnetfilter_queue.c b/src/libnetfilter_queue.c
index 4cc4925..c543055 100644
--- a/src/libnetfilter_queue.c
+++ b/src/libnetfilter_queue.c
@@ -1003,7 +1003,7 @@ struct nfqnl_msg_packet_hw *nfq_get_packet_hw(struct nfq_data *nfad)
*
* \return -1 on error, otherwise > 0.
*/
-int nfq_get_payload(struct nfq_data *nfad, char **data)
+int nfq_get_payload(struct nfq_data *nfad, unsigned char **data)
{
*data = nfnl_get_pointer_to_data(nfad->data, NFQA_PAYLOAD, char);
if (*data)
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH libnetfilter_queue 3/3] Added .gitignore for base directory.
2010-06-05 6:40 [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const David Favro
2010-06-05 6:40 ` [PATCH libnetfilter_queue 2/3] Payload buffer datatypes are consistent David Favro
@ 2010-06-05 6:40 ` David Favro
2010-06-10 13:06 ` Pablo Neira Ayuso
2010-06-10 13:06 ` [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const Pablo Neira Ayuso
2 siblings, 1 reply; 6+ messages in thread
From: David Favro @ 2010-06-05 6:40 UTC (permalink / raw)
To: netfilter; +Cc: pablo, David Favro
Signed-off-by: David Favro <netfilter@meta-dynamic.com>
---
.gitignore | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..99e943d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,17 @@
+doxygen.cfg
+doxygen
+
+config.guess
+config.log
+config.sub
+config.status
+configure
+autom4te.cache
+libtool
+ltmain.sh
+missing
+install-sh
+depcomp
+aclocal.m4
+
+libnetfilter_queue.pc
--
1.7.0.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const.
2010-06-05 6:40 [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const David Favro
2010-06-05 6:40 ` [PATCH libnetfilter_queue 2/3] Payload buffer datatypes are consistent David Favro
2010-06-05 6:40 ` [PATCH libnetfilter_queue 3/3] Added .gitignore for base directory David Favro
@ 2010-06-10 13:06 ` Pablo Neira Ayuso
2 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2010-06-10 13:06 UTC (permalink / raw)
To: David Favro; +Cc: netfilter
David Favro wrote:
> The payload parameters to nfq_set_verdict(), nfq_set_verdict2(), and
> nfq_set_verdict_mark() are not modified by those functions, and
> therefore should have datatype pointer-to-const. This both causes the
> source-code to more effectively represent what is the purpose of the
> parameter, and eliminates the need to cast away const-ness when calling
> the functions with compilers that enforce strict casting. All existing
> calling code should not need modification as pointer-to-X automatically
> converts to pointer-to-const-X.
This doesn't seem to break ABI so I'm fine with them. Applied, thanks David.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH libnetfilter_queue 2/3] Payload buffer datatypes are consistent.
2010-06-05 6:40 ` [PATCH libnetfilter_queue 2/3] Payload buffer datatypes are consistent David Favro
@ 2010-06-10 13:06 ` Pablo Neira Ayuso
0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2010-06-10 13:06 UTC (permalink / raw)
To: David Favro; +Cc: netfilter
David Favro wrote:
> The 'data' parameter to nfq_get_payload() returns pointer to unsigned
> char (rather than signed char) to make it consistent with the 'buf'
> parameter of nfq_set_verdict(), nfq_set_verdict2(), and
> nfq_set_verdict_mark(), all of which refer to the same data. Either
> signed or unsigned is fine, but they should be consistent as the output
> of nfq_get_payload() may be passed back into nfq_set_verdict*(); in that
> case, this change eliminates the need for typecasting in the calling
> code when using compilers that enforce strict typecasting.
Applied, I have also added this chunk to avoid a warning in the example
file.
diff --git a/utils/nfqnl_test.c b/utils/nfqnl_test.c
index 036bdab..9eebd9b 100644
--- a/utils/nfqnl_test.c
+++ b/utils/nfqnl_test.c
@@ -16,7 +16,7 @@ static u_int32_t print_pkt (struct nfq_data *tb)
struct nfqnl_msg_packet_hw *hwph;
u_int32_t mark,ifi;
int ret;
- char *data;
+ unsigned char *data;
ph = nfq_get_msg_packet_hdr(tb);
if (ph) {
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH libnetfilter_queue 3/3] Added .gitignore for base directory.
2010-06-05 6:40 ` [PATCH libnetfilter_queue 3/3] Added .gitignore for base directory David Favro
@ 2010-06-10 13:06 ` Pablo Neira Ayuso
0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2010-06-10 13:06 UTC (permalink / raw)
To: David Favro; +Cc: netfilter
David Favro wrote:
> diff --git a/.gitignore b/.gitignore
> new file mode 100644
> index 0000000..99e943d
> --- /dev/null
> +++ b/.gitignore
Applied, thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-06-10 13:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-05 6:40 [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const David Favro
2010-06-05 6:40 ` [PATCH libnetfilter_queue 2/3] Payload buffer datatypes are consistent David Favro
2010-06-10 13:06 ` Pablo Neira Ayuso
2010-06-05 6:40 ` [PATCH libnetfilter_queue 3/3] Added .gitignore for base directory David Favro
2010-06-10 13:06 ` Pablo Neira Ayuso
2010-06-10 13:06 ` [PATCH libnetfilter_queue 1/3] Non-modified payload arguments are pointer-to-const Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.