Skip to contentSkip to conversation

net/netfilter/ipvs/ip_vs_ftp.c: Remove use of NIPQUAD

PATCH In review Joe Perches 4 participants 6 messages Mar 9, 2010 – Mar 15, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/netfilter/ipvs/ip_vs_ftp.c: Remove use of NIPQUAD

NIPQUAD has very few uses left.

Remove this use and make the code have the identical form of the only other use of "%u,%u,%u,%u,%u,%u" in net/ipv4/netfilter/nf_nat_ftp.c

---
 net/netfilter/ipvs/ip_vs_ftp.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/net/netfilter/ipvs/ip_vs_ftp.c
index 73f38ea..9f63283 100644

net/netfilter/ipvs/ip_vs_ftp.c +0 -0
@@ -208,8 +208,14 @@ static int ip_vs_ftp_out(struct ip_vs_app *app,

struct ip_vs_conn *cp,
*/
from.ip = n_cp->vaddr.ip;
port = n_cp->vport;
- sprintf(buf, "%u,%u,%u,%u,%u,%u", NIPQUAD(from.ip),
- (ntohs(port)>>8)&255, ntohs(port)&255);
+ snprintf(buf, sizeof(buf), "%u,%u,%u,%u,%u,%u",
+ ((unsigned char *)&from.ip)[0],
+ ((unsigned char *)&from.ip)[1],
+ ((unsigned char *)&from.ip)[2],
+ ((unsigned char *)&from.ip)[3],
+ ntohs(port) >> 8,
+ ntohs(port) & 0xFF);
+
buf_len = strlen(buf);

/*

maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Joe Perches

NIPQUAD has very few uses left.

Remove this use and make the code have the identical form of the only other use of "%u,%u,%u,%u,%u,%u" in net/ipv4/netfilter/nf_nat_ftp.c

Quoted 33 lines
---
 net/netfilter/ipvs/ip_vs_ftp.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
net/netfilter/ipvs/ip_vs_ftp.c +8 -2
index 73f38ea..9f63283 100644
@@ -208,8 +208,14 @@ static int ip_vs_ftp_out(struct ip_vs_app *app,
 struct ip_vs_conn *cp,
 		 */
 		from.ip = n_cp->vaddr.ip;
 		port = n_cp->vport;
-		sprintf(buf, "%u,%u,%u,%u,%u,%u", NIPQUAD(from.ip),
-			(ntohs(port)>>8)&255, ntohs(port)&255);
+		snprintf(buf, sizeof(buf), "%u,%u,%u,%u,%u,%u",
+			 ((unsigned char *)&from.ip)[0],
+			 ((unsigned char *)&from.ip)[1],
+			 ((unsigned char *)&from.ip)[2],
+			 ((unsigned char *)&from.ip)[3],
+			 ntohs(port) >> 8,
+			 ntohs(port) & 0xFF);
+
 		buf_len = strlen(buf);
 

/*

--
To unsubscribe from this list: send the line "unsubscribe lvs-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Joe Perches
Quoted 4 lines · Joe Perches

NIPQUAD has very few uses left.

Remove this use and make the code have the identical form of the only other use of "%u,%u,%u,%u,%u,%u" in net/ipv4/netfilter/nf_nat_ftp.c

Are we trying to remove NIPQUAD? In my opinion the current code is preferrable to open-coding NIPQUAD.

#3 lore raw
Quoted 6 lines · Patrick McHardy
Quoted 3 lines · Joe Perches

NIPQUAD has very few uses left.
Remove this use and make the code have the identical form of the only other use of "%u,%u,%u,%u,%u,%u" in net/ipv4/netfilter/nf_nat_ftp.c

Are we trying to remove NIPQUAD?

That is a goal for me yes.
Elimination of unnecessary stuff from kernel.h is useful.

Quoted 2 lines

In my opinion the current code is
preferrable to open-coding NIPQUAD.

$ grep -r --include=*.[ch] NIPQUAD *
include/linux/kernel.h:#define NIPQUAD(addr) \
include/linux/kernel.h:#define NIPQUAD_FMT "%u.%u.%u.%u"
net/netfilter/ipvs/ip_vs_ftp.c:		sprintf(buf, "%u,%u,%u,%u,%u,%u", NIPQUAD(from.ip),

As of right now NIPQUAD_FMT is unused and could be removed from kernel.h

There's 1 use of NIPQUAD.

Maybe instead of removal the #define could be moved to netfilter.h or netfilter_ipv4.h

Another is to consolidate the two uses of "%u,%u,%u,%u,%u,%u"

$ grep -r --include=*.[ch] "%u,%u,%u,%u,%u,u%" *
fs/cachefiles/bind.c:	_enter("{%u,%u,%u,%u,%u,%u},%s",
net/ipv4/netfilter/nf_nat_ftp.c:		return snprintf(buffer, buflen, "%u,%u,%u,%u,%u,%u",
net/netfilter/ipvs/ip_vs_ftp.c:		sprintf(buf, "%u,%u,%u,%u,%u,%u", NIPQUAD(from.ip),

Maybe these 2 open coded sprintf/snprintf could be consolidated and moved to an appropriate include like netfilter_ipv4 or another.

What do you suggest?

#4 lore raw
Quoted 34 lines · Joe Perches
Quoted 5 lines · Patrick McHardy
Quoted 3 lines · Joe Perches

NIPQUAD has very few uses left.
Remove this use and make the code have the identical form of the only other use of "%u,%u,%u,%u,%u,%u" in net/ipv4/netfilter/nf_nat_ftp.c

Are we trying to remove NIPQUAD?

That is a goal for me yes.
Elimination of unnecessary stuff from kernel.h is useful.

Quoted 2 lines

In my opinion the current code is
preferrable to open-coding NIPQUAD.

$ grep -r --include=*.[ch] NIPQUAD *
include/linux/kernel.h:#define NIPQUAD(addr) \
include/linux/kernel.h:#define NIPQUAD_FMT "%u.%u.%u.%u"
net/netfilter/ipvs/ip_vs_ftp.c:		sprintf(buf, "%u,%u,%u,%u,%u,%u", NIPQUAD(from.ip),

As of right now NIPQUAD_FMT is unused and could be removed from kernel.h

There's 1 use of NIPQUAD.

Maybe instead of removal the #define could be moved to netfilter.h or netfilter_ipv4.h

Another is to consolidate the two uses of "%u,%u,%u,%u,%u,%u"

$ grep -r --include=*.[ch] "%u,%u,%u,%u,%u,u%" *
fs/cachefiles/bind.c:	_enter("{%u,%u,%u,%u,%u,%u},%s",
net/ipv4/netfilter/nf_nat_ftp.c:		return snprintf(buffer, buflen, "%u,%u,%u,%u,%u,%u",
net/netfilter/ipvs/ip_vs_ftp.c:		sprintf(buf, "%u,%u,%u,%u,%u,%u", NIPQUAD(from.ip),
Quoted 5 lines

Maybe these 2 open coded sprintf/snprintf could be consolidated and moved to an appropriate include like netfilter_ipv4 or another.

What do you suggest?

Well, removing the last user sounds acceptable :) Applied, thanks.

maintainer
#5 lore raw
In reply to Patrick McHardy

From: Patrick McHardy <[email protected]>
Date: Mon, 15 Mar 2010 17:20:19 +0100

Quoted 7 lines
Quoted 4 lines · Joe Perches

NIPQUAD has very few uses left.

Remove this use and make the code have the identical form of the only other use of "%u,%u,%u,%u,%u,%u" in net/ipv4/netfilter/nf_nat_ftp.c

Are we trying to remove NIPQUAD?

Yes.