net: replace NIPQUAD() in net/ipv4/netfilter/
Subsystems (3)
PATCH 1/7 net: replace NIPQUAD() in net/ipv4/netfilter/
Using NIPQUAD() with NIPQUAD_FMT, %d.%d.%d.%d or %u.%u.%u.%u can be replaced with %pI4
---
Dave, these should all be _exact_ replacements, the few remaining in tree occurences of NIPQUAD will need looking at, especially the ones using %u,%u,%u,%u (note the commas)
net/ipv4/netfilter/arp_tables.c | 16 +++--- net/ipv4/netfilter/ip_tables.c | 12 ++--- net/ipv4/netfilter/ipt_CLUSTERIP.c | 9 ++-- net/ipv4/netfilter/ipt_LOG.c | 7 +-- net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c | 15 +++--- net/ipv4/netfilter/nf_nat_h323.c | 58 +++++++++++------------- net/ipv4/netfilter/nf_nat_irc.c | 4 +- net/ipv4/netfilter/nf_nat_rule.c | 6 +-- net/ipv4/netfilter/nf_nat_sip.c | 18 +++---- net/ipv4/netfilter/nf_nat_snmp_basic.c | 9 ++-- 10 files changed, 69 insertions(+), 85 deletions(-)
net/ipv4/netfilter/arp_tables.c +8 -8
@@ -142,15 +142,15 @@ static inline int arp_packet_match(const struct arphdr *arphdr, ARPT_INV_TGTIP)) {dprintf ("Source or target IP address mismatch.\n" ); -dprintf ("SRC: %u.%u.%u.%u. Mask: %u.%u.%u.%u. Target: %u.%u.%u.%u.%s\n" , -NIPQUAD (src_ipaddr), -NIPQUAD (arpinfo->smsk.s_addr), -NIPQUAD (arpinfo->src.s_addr), +dprintf ("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n" , + &src_ipaddr, + &arpinfo->smsk.s_addr, + &arpinfo->src.s_addr, arpinfo->invflags &ARPT_INV_SRCIP ?" (INV)" :"" ); -dprintf ("TGT: %u.%u.%u.%u Mask: %u.%u.%u.%u Target: %u.%u.%u.%u.%s\n" , -NIPQUAD (tgt_ipaddr), -NIPQUAD (arpinfo->tmsk.s_addr), -NIPQUAD (arpinfo->tgt.s_addr), +dprintf ("TGT: %pI4 Mask: %pI4 Target: %pI4.%s\n" , + &tgt_ipaddr, + &arpinfo->tmsk.s_addr, + &arpinfo->tgt.s_addr, arpinfo->invflags &ARPT_INV_TGTIP ?" (INV)" :"" );return 0 ; }
net/ipv4/netfilter/ip_tables.c +4 -8
@@ -94,15 +94,11 @@ ip_packet_match(const struct iphdr *ip, IPT_INV_DSTIP)) {dprintf ("Source or dest mismatch.\n" ); -dprintf ("SRC: %u.%u.%u.%u. Mask: %u.%u.%u.%u. Target: %u.%u.%u.%u.%s\n" , -NIPQUAD (ip->saddr), -NIPQUAD (ipinfo->smsk.s_addr), -NIPQUAD (ipinfo->src.s_addr), +dprintf ("SRC: %pI4. Mask: %pI4. Target: %pI4.%s\n" , + &ip->saddr, &ipinfo->smsk.s_addr, &ipinfo->src.s_addr, ipinfo->invflags &IPT_INV_SRCIP ?" (INV)" :"" ); -dprintf ("DST: %u.%u.%u.%u Mask: %u.%u.%u.%u Target: %u.%u.%u.%u.%s\n" , -NIPQUAD (ip->daddr), -NIPQUAD (ipinfo->dmsk.s_addr), -NIPQUAD (ipinfo->dst.s_addr), +dprintf ("DST: %pI4 Mask: %pI4 Target: %pI4.%s\n" , + &ip->daddr, &ipinfo->dmsk.s_addr, &ipinfo->dst.s_addr, ipinfo->invflags &IPT_INV_DSTIP ?" (INV)" :"" );return false; }
net/ipv4/netfilter/ipt_CLUSTERIP.c +4 -5
@@ -168,7 +168,7 @@ clusterip_config_init(const struct ipt_clusterip_tgt_info *i, __be32 ip,char buffer[16 ];/* create proc dir entry */ -sprintf (buffer,"%u.%u.%u.%u" ,NIPQUAD (ip)); +sprintf (buffer,"%pI4" , &ip); c->pde =proc_create_data (buffer,S_IWUSR |S_IRUSR , clusterip_procdir, &clusterip_proc_fops, c);
@@ -373,7 +373,7 @@ static bool clusterip_tg_check(const struct xt_tgchk_param *par) config =clusterip_config_find_get (e->ip.dst.s_addr,1 );if (!config) {if (!(cipinfo->flags &CLUSTERIP_FLAG_NEW )) { -printk (KERN_WARNING "CLUSTERIP: no config found for %u.%u.%u.%u, need 'new'\n" ,NIPQUAD (e->ip.dst.s_addr)); +printk (KERN_WARNING "CLUSTERIP: no config found for %pI4, need 'new'\n" , &e->ip.dst.s_addr);return false; }else {struct net_device *dev;
@@ -478,9 +478,8 @@ static void arp_print(struct arp_payload *payload) } hbuffer[--k]='\0' ; -printk ("src %u.%u.%u.%u@%s, dst %u.%u.%u.%u\n" , -NIPQUAD (payload->src_ip), hbuffer, -NIPQUAD (payload->dst_ip)); +printk ("src %pI4@%s, dst %pI4\n" , + &payload->src_ip, hbuffer, &payload->dst_ip); }#endif
net/ipv4/netfilter/ipt_LOG.c +3 -4
@@ -54,8 +54,8 @@ static void dump_packet(const struct nf_loginfo *info,/* Important fields: * TOS, len, DF/MF, fragment offset, TTL, src, dst, options. */ /* Max length: 40 "SRC=255.255.255.255 DST=255.255.255.255 " */ -printk ("SRC=%u.%u.%u.%u DST=%u.%u.%u.%u " , -NIPQUAD (ih->saddr),NIPQUAD (ih->daddr)); +printk ("SRC=%pI4 DST=%pI4 " , + &ih->saddr, &ih->daddr);/* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */ printk("LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ",
@@ -262,8 +262,7 @@ static void dump_packet(const struct nf_loginfo *info,break ;case ICMP_REDIRECT :/* Max length: 24 "GATEWAY=255.255.255.255 " */ -printk ("GATEWAY=%u.%u.%u.%u " , -NIPQUAD (ich->un.gateway)); +printk ("GATEWAY=%pI4 " , &ich->un.gateway);/* Fall through */ case ICMP_DEST_UNREACH :case ICMP_SOURCE_QUENCH :
net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c +7 -8
@@ -60,9 +60,8 @@ static bool ipv4_invert_tuple(struct nf_conntrack_tuple *tuple,static int ipv4_print_tuple (struct seq_file *s,const struct nf_conntrack_tuple *tuple) { -return seq_printf (s,"src=%u.%u.%u.%u dst=%u.%u.%u.%u " , -NIPQUAD (tuple->src.u3.ip), -NIPQUAD (tuple->dst.u3.ip)); +return seq_printf (s,"src=%pI4 dst=%pI4 " , + &tuple->src.u3.ip, &tuple->dst.u3.ip); } static int ipv4_get_l4proto(const struct sk_buff *skb, unsigned int nhoff,
@@ -284,17 +283,17 @@ getorigdst(struct sock *sk, int optval, void __user *user, int *len) .tuple.dst.u3.ip;memset (sin.sin_zero,0 ,sizeof (sin.sin_zero)); -pr_debug ("SO_ORIGINAL_DST: %u.%u.%u.%u %u\n" , -NIPQUAD (sin.sin_addr.s_addr),ntohs (sin.sin_port)); +pr_debug ("SO_ORIGINAL_DST: %pI4 %u\n" , + &sin.sin_addr.s_addr,ntohs (sin.sin_port));nf_ct_put (ct);if (copy_to_user (user, &sin,sizeof (sin)) !=0 )return -EFAULT ;else return 0 ; } -pr_debug ("SO_ORIGINAL_DST: Can't find %u.%u.%u.%u/%u-%u.%u.%u.%u/%u.\n" , -NIPQUAD (tuple.src.u3.ip),ntohs (tuple.src.u.tcp.port), -NIPQUAD (tuple.dst.u3.ip),ntohs (tuple.dst.u.tcp.port)); +pr_debug ("SO_ORIGINAL_DST: Can't find %pI4/%u-%pI4/%u.\n" , + &tuple.src.u3.ip,ntohs (tuple.src.u.tcp.port), + &tuple.dst.u3.ip,ntohs (tuple.dst.u.tcp.port));return -ENOENT ; }
net/ipv4/netfilter/nf_nat_h323.c +27 -31
113 lines not on this page · raw message
net/ipv4/netfilter/nf_nat_irc.c +2 -2
@@ -55,8 +55,8 @@ static unsigned int help(struct sk_buff *skb, ip =ntohl (exp->master->tuplehash[IP_CT_DIR_REPLY ].tuple.dst.u3.ip);sprintf (buffer,"%u %u" , ip, port); -pr_debug ("nf_nat_irc: inserting '%s' == %u.%u.%u.%u, port %u\n" , - buffer,NIPQUAD (ip), port); +pr_debug ("nf_nat_irc: inserting '%s' == %pI4, port %u\n" , + buffer, &ip, port); ret = nf_nat_mangle_tcp_packet(skb, exp->master, ctinfo, matchoff, matchlen, buffer,
net/ipv4/netfilter/nf_nat_rule.c +2 -4
@@ -98,8 +98,7 @@ static void warn_if_extra_mangle(struct net *net, __be32 dstip, __be32 srcip)if (rt->rt_src != srcip && !warned) {printk ("NAT: no longer support implicit source local NAT\n" ); -printk ("NAT: packet src %u.%u.%u.%u -> dst %u.%u.%u.%u\n" , -NIPQUAD (srcip),NIPQUAD (dstip)); +printk ("NAT: packet src %pI4 -> dst %pI4\n" , &srcip, &dstip); warned =1 ; }ip_rt_put (rt);
@@ -166,8 +165,7 @@ alloc_null_binding(struct nf_conn *ct, unsigned int hooknum)struct nf_nat_range range = {IP_NAT_RANGE_MAP_IPS , ip, ip, {0 }, {0 } }; -pr_debug ("Allocating NULL binding for %p (%u.%u.%u.%u)\n" , - ct,NIPQUAD (ip)); +pr_debug ("Allocating NULL binding for %p (%pI4)\n" , ct, &ip);return nf_nat_setup_info (ct, &range,HOOK2MANIP (hooknum)); }
net/ipv4/netfilter/nf_nat_sip.c +8 -10
@@ -74,8 +74,7 @@ static int map_addr(struct sk_buff *skb,if (newaddr == addr->ip && newport == port)return 1 ; - buflen =sprintf (buffer,"%u.%u.%u.%u:%u" , -NIPQUAD (newaddr),ntohs (newport)); + buflen =sprintf (buffer,"%pI4:%u" , &newaddr,ntohs (newport));return mangle_packet (skb, dptr, datalen, matchoff, matchlen, buffer, buflen);
@@ -152,8 +151,8 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, &addr) > 0 && addr.ip == ct->tuplehash[dir].tuple.src.u3.ip && addr.ip != ct->tuplehash[!dir].tuple.dst.u3.ip) { -__be32 ip = ct->tuplehash[!dir].tuple.dst.u3.ip; - buflen =sprintf (buffer,"%u.%u.%u.%u" ,NIPQUAD (ip)); + buflen =sprintf (buffer,"%pI4" , + &ct->tuplehash[!dir].tuple.dst.u3.ip);if (!mangle_packet (skb, dptr, datalen, poff, plen, buffer, buflen))return NF_DROP ;
@@ -166,8 +165,8 @@ static unsigned int ip_nat_sip(struct sk_buff *skb, &addr) > 0 && addr.ip == ct->tuplehash[dir].tuple.dst.u3.ip && addr.ip != ct->tuplehash[!dir].tuple.src.u3.ip) { -__be32 ip = ct->tuplehash[!dir].tuple.src.u3.ip; - buflen =sprintf (buffer,"%u.%u.%u.%u" ,NIPQUAD (ip)); + buflen =sprintf (buffer,"%pI4" , + &ct->tuplehash[!dir].tuple.src.u3.ip);if (!mangle_packet (skb, dptr, datalen, poff, plen, buffer, buflen))return NF_DROP ;
@@ -279,8 +278,7 @@ static unsigned int ip_nat_sip_expect(struct sk_buff *skb,if (exp->tuple.dst.u3.ip != exp->saved_ip || exp->tuple.dst.u.udp.port != exp->saved_proto.udp.port) { - buflen =sprintf (buffer,"%u.%u.%u.%u:%u" , -NIPQUAD (newip), port); + buflen =sprintf (buffer,"%pI4:%u" , &newip, port);if (!mangle_packet (skb, dptr, datalen, matchoff, matchlen, buffer, buflen)) goto err;
@@ -345,7 +343,7 @@ static unsigned int ip_nat_sdp_addr(struct sk_buff *skb, const char **dptr,char buffer[sizeof ("nnn.nnn.nnn.nnn" )];unsigned int buflen; - buflen =sprintf (buffer,NIPQUAD_FMT ,NIPQUAD (addr->ip)); + buflen =sprintf (buffer,"%pI4" , &addr->ip);if (mangle_sdp_packet (skb, dptr, dataoff, datalen, type, term, buffer, buflen))return 0 ;
@@ -380,7 +378,7 @@ static unsigned int ip_nat_sdp_session(struct sk_buff *skb, const char **dptr,unsigned int buflen;/* Mangle session description owner and contact addresses */ - buflen =sprintf (buffer,"%u.%u.%u.%u" ,NIPQUAD (addr->ip)); + buflen =sprintf (buffer,"%pI4" , &addr->ip);if (mangle_sdp_packet (skb, dptr, dataoff, datalen,SDP_HDR_OWNER_IP4 ,SDP_HDR_MEDIA , buffer, buflen))
net/ipv4/netfilter/nf_nat_snmp_basic.c +4 -5
@@ -930,8 +930,8 @@ static inline void mangle_address(unsigned char *begin, }if (debug) -printk (KERN_DEBUG "bsalg: mapped %u.%u.%u.%u to " -"%u.%u.%u.%u\n" ,NIPQUAD (old),NIPQUAD (*addr)); +printk (KERN_DEBUG "bsalg: mapped %pI4 to %pI4\n" , + &old, addr); } }
@@ -1267,9 +1267,8 @@ static int help(struct sk_buff *skb, unsigned int protoff,*/ if (ntohs (udph->len) != skb->len - (iph->ihl <<2 )) {if (net_ratelimit ()) -printk (KERN_WARNING "SNMP: dropping malformed packet " -"src=%u.%u.%u.%u dst=%u.%u.%u.%u\n" , -NIPQUAD (iph->saddr),NIPQUAD (iph->daddr)); +printk (KERN_WARNING "SNMP: dropping malformed packet src=%pI4 dst=%pI4\n" , + &iph->saddr, &iph->daddr);return NF_DROP ; }
Signature · 1 line
1.6.0.3.756.gb776d
From: Harvey Harrison <[email protected]>
Date: Thu, 30 Oct 2008 17:13:43 -0700
Quoted 4 lines
Using
NIPQUAD()withNIPQUAD_FMT, %d.%d.%d.%d or %u.%u.%u.%u can be replaced with %pI4Signed-off-by Harvey Harrison <[email protected]>
Applied, thanks Harvey.
Quoted 3 lines
Dave, these should all be _exact_ replacements, the few remaining in tree occurences of NIPQUAD will need looking at, especially the ones using %u,%u,%u,%u (note the commas)
Looks like we'll have yet another modifier :-)