Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_log_ipv6: merge with nf_log_syslog

This removes the nf_log_ipv6 module, the functionality is now
provided by nf_log_syslog.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Florian Westphal and committed by
Pablo Neira Ayuso
f5466caa f11d61e7

+360 -433
+4 -1
net/ipv6/netfilter/Kconfig
··· 69 69 config NF_LOG_IPV6 70 70 tristate "IPv6 packet logging" 71 71 default m if NETFILTER_ADVANCED=n 72 - select NF_LOG_COMMON 72 + select NF_LOG_SYSLOG 73 + help 74 + This is a backwards-compat option for the user's convenience 75 + (e.g. when running oldconfig). It selects CONFIG_NF_LOG_SYSLOG. 73 76 74 77 config IP6_NF_IPTABLES 75 78 tristate "IP6 tables support (required for filtering)"
-3
net/ipv6/netfilter/Makefile
··· 18 18 obj-$(CONFIG_NF_SOCKET_IPV6) += nf_socket_ipv6.o 19 19 obj-$(CONFIG_NF_TPROXY_IPV6) += nf_tproxy_ipv6.o 20 20 21 - # logging 22 - obj-$(CONFIG_NF_LOG_IPV6) += nf_log_ipv6.o 23 - 24 21 # reject 25 22 obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o 26 23
-427
net/ipv6/netfilter/nf_log_ipv6.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* (C) 1999-2001 Paul `Rusty' Russell 3 - * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> 4 - */ 5 - 6 - #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7 - 8 - #include <linux/kernel.h> 9 - #include <linux/module.h> 10 - #include <linux/spinlock.h> 11 - #include <linux/skbuff.h> 12 - #include <linux/if_arp.h> 13 - #include <linux/ip.h> 14 - #include <net/ipv6.h> 15 - #include <net/icmp.h> 16 - #include <net/udp.h> 17 - #include <net/tcp.h> 18 - #include <net/route.h> 19 - 20 - #include <linux/netfilter.h> 21 - #include <linux/netfilter_ipv6.h> 22 - #include <linux/netfilter/xt_LOG.h> 23 - #include <net/netfilter/nf_log.h> 24 - 25 - static const struct nf_loginfo default_loginfo = { 26 - .type = NF_LOG_TYPE_LOG, 27 - .u = { 28 - .log = { 29 - .level = LOGLEVEL_NOTICE, 30 - .logflags = NF_LOG_DEFAULT_MASK, 31 - }, 32 - }, 33 - }; 34 - 35 - /* One level of recursion won't kill us */ 36 - static void dump_ipv6_packet(struct net *net, struct nf_log_buf *m, 37 - const struct nf_loginfo *info, 38 - const struct sk_buff *skb, unsigned int ip6hoff, 39 - int recurse) 40 - { 41 - u_int8_t currenthdr; 42 - int fragment; 43 - struct ipv6hdr _ip6h; 44 - const struct ipv6hdr *ih; 45 - unsigned int ptr; 46 - unsigned int hdrlen = 0; 47 - unsigned int logflags; 48 - 49 - if (info->type == NF_LOG_TYPE_LOG) 50 - logflags = info->u.log.logflags; 51 - else 52 - logflags = NF_LOG_DEFAULT_MASK; 53 - 54 - ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h); 55 - if (ih == NULL) { 56 - nf_log_buf_add(m, "TRUNCATED"); 57 - return; 58 - } 59 - 60 - /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000 " */ 61 - nf_log_buf_add(m, "SRC=%pI6 DST=%pI6 ", &ih->saddr, &ih->daddr); 62 - 63 - /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */ 64 - nf_log_buf_add(m, "LEN=%zu TC=%u HOPLIMIT=%u FLOWLBL=%u ", 65 - ntohs(ih->payload_len) + sizeof(struct ipv6hdr), 66 - (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20, 67 - ih->hop_limit, 68 - (ntohl(*(__be32 *)ih) & 0x000fffff)); 69 - 70 - fragment = 0; 71 - ptr = ip6hoff + sizeof(struct ipv6hdr); 72 - currenthdr = ih->nexthdr; 73 - while (currenthdr != NEXTHDR_NONE && nf_ip6_ext_hdr(currenthdr)) { 74 - struct ipv6_opt_hdr _hdr; 75 - const struct ipv6_opt_hdr *hp; 76 - 77 - hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr); 78 - if (hp == NULL) { 79 - nf_log_buf_add(m, "TRUNCATED"); 80 - return; 81 - } 82 - 83 - /* Max length: 48 "OPT (...) " */ 84 - if (logflags & NF_LOG_IPOPT) 85 - nf_log_buf_add(m, "OPT ( "); 86 - 87 - switch (currenthdr) { 88 - case IPPROTO_FRAGMENT: { 89 - struct frag_hdr _fhdr; 90 - const struct frag_hdr *fh; 91 - 92 - nf_log_buf_add(m, "FRAG:"); 93 - fh = skb_header_pointer(skb, ptr, sizeof(_fhdr), 94 - &_fhdr); 95 - if (fh == NULL) { 96 - nf_log_buf_add(m, "TRUNCATED "); 97 - return; 98 - } 99 - 100 - /* Max length: 6 "65535 " */ 101 - nf_log_buf_add(m, "%u ", ntohs(fh->frag_off) & 0xFFF8); 102 - 103 - /* Max length: 11 "INCOMPLETE " */ 104 - if (fh->frag_off & htons(0x0001)) 105 - nf_log_buf_add(m, "INCOMPLETE "); 106 - 107 - nf_log_buf_add(m, "ID:%08x ", 108 - ntohl(fh->identification)); 109 - 110 - if (ntohs(fh->frag_off) & 0xFFF8) 111 - fragment = 1; 112 - 113 - hdrlen = 8; 114 - 115 - break; 116 - } 117 - case IPPROTO_DSTOPTS: 118 - case IPPROTO_ROUTING: 119 - case IPPROTO_HOPOPTS: 120 - if (fragment) { 121 - if (logflags & NF_LOG_IPOPT) 122 - nf_log_buf_add(m, ")"); 123 - return; 124 - } 125 - hdrlen = ipv6_optlen(hp); 126 - break; 127 - /* Max Length */ 128 - case IPPROTO_AH: 129 - if (logflags & NF_LOG_IPOPT) { 130 - struct ip_auth_hdr _ahdr; 131 - const struct ip_auth_hdr *ah; 132 - 133 - /* Max length: 3 "AH " */ 134 - nf_log_buf_add(m, "AH "); 135 - 136 - if (fragment) { 137 - nf_log_buf_add(m, ")"); 138 - return; 139 - } 140 - 141 - ah = skb_header_pointer(skb, ptr, sizeof(_ahdr), 142 - &_ahdr); 143 - if (ah == NULL) { 144 - /* 145 - * Max length: 26 "INCOMPLETE [65535 146 - * bytes] )" 147 - */ 148 - nf_log_buf_add(m, "INCOMPLETE [%u bytes] )", 149 - skb->len - ptr); 150 - return; 151 - } 152 - 153 - /* Length: 15 "SPI=0xF1234567 */ 154 - nf_log_buf_add(m, "SPI=0x%x ", ntohl(ah->spi)); 155 - 156 - } 157 - 158 - hdrlen = ipv6_authlen(hp); 159 - break; 160 - case IPPROTO_ESP: 161 - if (logflags & NF_LOG_IPOPT) { 162 - struct ip_esp_hdr _esph; 163 - const struct ip_esp_hdr *eh; 164 - 165 - /* Max length: 4 "ESP " */ 166 - nf_log_buf_add(m, "ESP "); 167 - 168 - if (fragment) { 169 - nf_log_buf_add(m, ")"); 170 - return; 171 - } 172 - 173 - /* 174 - * Max length: 26 "INCOMPLETE [65535 bytes] )" 175 - */ 176 - eh = skb_header_pointer(skb, ptr, sizeof(_esph), 177 - &_esph); 178 - if (eh == NULL) { 179 - nf_log_buf_add(m, "INCOMPLETE [%u bytes] )", 180 - skb->len - ptr); 181 - return; 182 - } 183 - 184 - /* Length: 16 "SPI=0xF1234567 )" */ 185 - nf_log_buf_add(m, "SPI=0x%x )", 186 - ntohl(eh->spi)); 187 - } 188 - return; 189 - default: 190 - /* Max length: 20 "Unknown Ext Hdr 255" */ 191 - nf_log_buf_add(m, "Unknown Ext Hdr %u", currenthdr); 192 - return; 193 - } 194 - if (logflags & NF_LOG_IPOPT) 195 - nf_log_buf_add(m, ") "); 196 - 197 - currenthdr = hp->nexthdr; 198 - ptr += hdrlen; 199 - } 200 - 201 - switch (currenthdr) { 202 - case IPPROTO_TCP: 203 - if (nf_log_dump_tcp_header(m, skb, currenthdr, fragment, 204 - ptr, logflags)) 205 - return; 206 - break; 207 - case IPPROTO_UDP: 208 - case IPPROTO_UDPLITE: 209 - if (nf_log_dump_udp_header(m, skb, currenthdr, fragment, ptr)) 210 - return; 211 - break; 212 - case IPPROTO_ICMPV6: { 213 - struct icmp6hdr _icmp6h; 214 - const struct icmp6hdr *ic; 215 - 216 - /* Max length: 13 "PROTO=ICMPv6 " */ 217 - nf_log_buf_add(m, "PROTO=ICMPv6 "); 218 - 219 - if (fragment) 220 - break; 221 - 222 - /* Max length: 25 "INCOMPLETE [65535 bytes] " */ 223 - ic = skb_header_pointer(skb, ptr, sizeof(_icmp6h), &_icmp6h); 224 - if (ic == NULL) { 225 - nf_log_buf_add(m, "INCOMPLETE [%u bytes] ", 226 - skb->len - ptr); 227 - return; 228 - } 229 - 230 - /* Max length: 18 "TYPE=255 CODE=255 " */ 231 - nf_log_buf_add(m, "TYPE=%u CODE=%u ", 232 - ic->icmp6_type, ic->icmp6_code); 233 - 234 - switch (ic->icmp6_type) { 235 - case ICMPV6_ECHO_REQUEST: 236 - case ICMPV6_ECHO_REPLY: 237 - /* Max length: 19 "ID=65535 SEQ=65535 " */ 238 - nf_log_buf_add(m, "ID=%u SEQ=%u ", 239 - ntohs(ic->icmp6_identifier), 240 - ntohs(ic->icmp6_sequence)); 241 - break; 242 - case ICMPV6_MGM_QUERY: 243 - case ICMPV6_MGM_REPORT: 244 - case ICMPV6_MGM_REDUCTION: 245 - break; 246 - 247 - case ICMPV6_PARAMPROB: 248 - /* Max length: 17 "POINTER=ffffffff " */ 249 - nf_log_buf_add(m, "POINTER=%08x ", 250 - ntohl(ic->icmp6_pointer)); 251 - fallthrough; 252 - case ICMPV6_DEST_UNREACH: 253 - case ICMPV6_PKT_TOOBIG: 254 - case ICMPV6_TIME_EXCEED: 255 - /* Max length: 3+maxlen */ 256 - if (recurse) { 257 - nf_log_buf_add(m, "["); 258 - dump_ipv6_packet(net, m, info, skb, 259 - ptr + sizeof(_icmp6h), 0); 260 - nf_log_buf_add(m, "] "); 261 - } 262 - 263 - /* Max length: 10 "MTU=65535 " */ 264 - if (ic->icmp6_type == ICMPV6_PKT_TOOBIG) { 265 - nf_log_buf_add(m, "MTU=%u ", 266 - ntohl(ic->icmp6_mtu)); 267 - } 268 - } 269 - break; 270 - } 271 - /* Max length: 10 "PROTO=255 " */ 272 - default: 273 - nf_log_buf_add(m, "PROTO=%u ", currenthdr); 274 - } 275 - 276 - /* Max length: 15 "UID=4294967295 " */ 277 - if ((logflags & NF_LOG_UID) && recurse) 278 - nf_log_dump_sk_uid_gid(net, m, skb->sk); 279 - 280 - /* Max length: 16 "MARK=0xFFFFFFFF " */ 281 - if (recurse && skb->mark) 282 - nf_log_buf_add(m, "MARK=0x%x ", skb->mark); 283 - } 284 - 285 - static void dump_ipv6_mac_header(struct nf_log_buf *m, 286 - const struct nf_loginfo *info, 287 - const struct sk_buff *skb) 288 - { 289 - struct net_device *dev = skb->dev; 290 - unsigned int logflags = 0; 291 - 292 - if (info->type == NF_LOG_TYPE_LOG) 293 - logflags = info->u.log.logflags; 294 - 295 - if (!(logflags & NF_LOG_MACDECODE)) 296 - goto fallback; 297 - 298 - switch (dev->type) { 299 - case ARPHRD_ETHER: 300 - nf_log_buf_add(m, "MACSRC=%pM MACDST=%pM ", 301 - eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest); 302 - nf_log_dump_vlan(m, skb); 303 - nf_log_buf_add(m, "MACPROTO=%04x ", 304 - ntohs(eth_hdr(skb)->h_proto)); 305 - return; 306 - default: 307 - break; 308 - } 309 - 310 - fallback: 311 - nf_log_buf_add(m, "MAC="); 312 - if (dev->hard_header_len && 313 - skb->mac_header != skb->network_header) { 314 - const unsigned char *p = skb_mac_header(skb); 315 - unsigned int len = dev->hard_header_len; 316 - unsigned int i; 317 - 318 - if (dev->type == ARPHRD_SIT) { 319 - p -= ETH_HLEN; 320 - 321 - if (p < skb->head) 322 - p = NULL; 323 - } 324 - 325 - if (p != NULL) { 326 - nf_log_buf_add(m, "%02x", *p++); 327 - for (i = 1; i < len; i++) 328 - nf_log_buf_add(m, ":%02x", *p++); 329 - } 330 - nf_log_buf_add(m, " "); 331 - 332 - if (dev->type == ARPHRD_SIT) { 333 - const struct iphdr *iph = 334 - (struct iphdr *)skb_mac_header(skb); 335 - nf_log_buf_add(m, "TUNNEL=%pI4->%pI4 ", &iph->saddr, 336 - &iph->daddr); 337 - } 338 - } else { 339 - nf_log_buf_add(m, " "); 340 - } 341 - } 342 - 343 - static void nf_log_ip6_packet(struct net *net, u_int8_t pf, 344 - unsigned int hooknum, const struct sk_buff *skb, 345 - const struct net_device *in, 346 - const struct net_device *out, 347 - const struct nf_loginfo *loginfo, 348 - const char *prefix) 349 - { 350 - struct nf_log_buf *m; 351 - 352 - /* FIXME: Disabled from containers until syslog ns is supported */ 353 - if (!net_eq(net, &init_net) && !sysctl_nf_log_all_netns) 354 - return; 355 - 356 - m = nf_log_buf_open(); 357 - 358 - if (!loginfo) 359 - loginfo = &default_loginfo; 360 - 361 - nf_log_dump_packet_common(m, pf, hooknum, skb, in, out, 362 - loginfo, prefix); 363 - 364 - if (in != NULL) 365 - dump_ipv6_mac_header(m, loginfo, skb); 366 - 367 - dump_ipv6_packet(net, m, loginfo, skb, skb_network_offset(skb), 1); 368 - 369 - nf_log_buf_close(m); 370 - } 371 - 372 - static struct nf_logger nf_ip6_logger __read_mostly = { 373 - .name = "nf_log_ipv6", 374 - .type = NF_LOG_TYPE_LOG, 375 - .logfn = nf_log_ip6_packet, 376 - .me = THIS_MODULE, 377 - }; 378 - 379 - static int __net_init nf_log_ipv6_net_init(struct net *net) 380 - { 381 - return nf_log_set(net, NFPROTO_IPV6, &nf_ip6_logger); 382 - } 383 - 384 - static void __net_exit nf_log_ipv6_net_exit(struct net *net) 385 - { 386 - nf_log_unset(net, &nf_ip6_logger); 387 - } 388 - 389 - static struct pernet_operations nf_log_ipv6_net_ops = { 390 - .init = nf_log_ipv6_net_init, 391 - .exit = nf_log_ipv6_net_exit, 392 - }; 393 - 394 - static int __init nf_log_ipv6_init(void) 395 - { 396 - int ret; 397 - 398 - ret = register_pernet_subsys(&nf_log_ipv6_net_ops); 399 - if (ret < 0) 400 - return ret; 401 - 402 - ret = nf_log_register(NFPROTO_IPV6, &nf_ip6_logger); 403 - if (ret < 0) { 404 - pr_err("failed to register logger\n"); 405 - goto err1; 406 - } 407 - 408 - return 0; 409 - 410 - err1: 411 - unregister_pernet_subsys(&nf_log_ipv6_net_ops); 412 - return ret; 413 - } 414 - 415 - static void __exit nf_log_ipv6_exit(void) 416 - { 417 - unregister_pernet_subsys(&nf_log_ipv6_net_ops); 418 - nf_log_unregister(&nf_ip6_logger); 419 - } 420 - 421 - module_init(nf_log_ipv6_init); 422 - module_exit(nf_log_ipv6_exit); 423 - 424 - MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); 425 - MODULE_DESCRIPTION("Netfilter IPv6 packet logging"); 426 - MODULE_LICENSE("GPL"); 427 - MODULE_ALIAS_NF_LOGGER(AF_INET6, 0);
+356 -2
net/netfilter/nf_log_syslog.c
··· 18 18 #include <net/route.h> 19 19 20 20 #include <linux/netfilter.h> 21 + #include <linux/netfilter_ipv6.h> 21 22 #include <linux/netfilter/xt_LOG.h> 22 23 #include <net/netfilter/nf_log.h> 23 24 ··· 356 355 /* maxlen = 230+ 91 + 230 + 252 = 803 */ 357 356 } 358 357 358 + static noinline_for_stack void 359 + dump_ipv6_packet(struct net *net, struct nf_log_buf *m, 360 + const struct nf_loginfo *info, 361 + const struct sk_buff *skb, unsigned int ip6hoff, 362 + int recurse) 363 + { 364 + const struct ipv6hdr *ih; 365 + unsigned int hdrlen = 0; 366 + unsigned int logflags; 367 + struct ipv6hdr _ip6h; 368 + unsigned int ptr; 369 + u8 currenthdr; 370 + int fragment; 371 + 372 + if (info->type == NF_LOG_TYPE_LOG) 373 + logflags = info->u.log.logflags; 374 + else 375 + logflags = NF_LOG_DEFAULT_MASK; 376 + 377 + ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h); 378 + if (!ih) { 379 + nf_log_buf_add(m, "TRUNCATED"); 380 + return; 381 + } 382 + 383 + /* Max length: 88 "SRC=0000.0000.0000.0000.0000.0000.0000.0000 DST=0000.0000.0000.0000.0000.0000.0000.0000 " */ 384 + nf_log_buf_add(m, "SRC=%pI6 DST=%pI6 ", &ih->saddr, &ih->daddr); 385 + 386 + /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */ 387 + nf_log_buf_add(m, "LEN=%zu TC=%u HOPLIMIT=%u FLOWLBL=%u ", 388 + ntohs(ih->payload_len) + sizeof(struct ipv6hdr), 389 + (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20, 390 + ih->hop_limit, 391 + (ntohl(*(__be32 *)ih) & 0x000fffff)); 392 + 393 + fragment = 0; 394 + ptr = ip6hoff + sizeof(struct ipv6hdr); 395 + currenthdr = ih->nexthdr; 396 + while (currenthdr != NEXTHDR_NONE && nf_ip6_ext_hdr(currenthdr)) { 397 + struct ipv6_opt_hdr _hdr; 398 + const struct ipv6_opt_hdr *hp; 399 + 400 + hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr); 401 + if (!hp) { 402 + nf_log_buf_add(m, "TRUNCATED"); 403 + return; 404 + } 405 + 406 + /* Max length: 48 "OPT (...) " */ 407 + if (logflags & NF_LOG_IPOPT) 408 + nf_log_buf_add(m, "OPT ( "); 409 + 410 + switch (currenthdr) { 411 + case IPPROTO_FRAGMENT: { 412 + struct frag_hdr _fhdr; 413 + const struct frag_hdr *fh; 414 + 415 + nf_log_buf_add(m, "FRAG:"); 416 + fh = skb_header_pointer(skb, ptr, sizeof(_fhdr), 417 + &_fhdr); 418 + if (!fh) { 419 + nf_log_buf_add(m, "TRUNCATED "); 420 + return; 421 + } 422 + 423 + /* Max length: 6 "65535 " */ 424 + nf_log_buf_add(m, "%u ", ntohs(fh->frag_off) & 0xFFF8); 425 + 426 + /* Max length: 11 "INCOMPLETE " */ 427 + if (fh->frag_off & htons(0x0001)) 428 + nf_log_buf_add(m, "INCOMPLETE "); 429 + 430 + nf_log_buf_add(m, "ID:%08x ", 431 + ntohl(fh->identification)); 432 + 433 + if (ntohs(fh->frag_off) & 0xFFF8) 434 + fragment = 1; 435 + 436 + hdrlen = 8; 437 + break; 438 + } 439 + case IPPROTO_DSTOPTS: 440 + case IPPROTO_ROUTING: 441 + case IPPROTO_HOPOPTS: 442 + if (fragment) { 443 + if (logflags & NF_LOG_IPOPT) 444 + nf_log_buf_add(m, ")"); 445 + return; 446 + } 447 + hdrlen = ipv6_optlen(hp); 448 + break; 449 + /* Max Length */ 450 + case IPPROTO_AH: 451 + if (logflags & NF_LOG_IPOPT) { 452 + struct ip_auth_hdr _ahdr; 453 + const struct ip_auth_hdr *ah; 454 + 455 + /* Max length: 3 "AH " */ 456 + nf_log_buf_add(m, "AH "); 457 + 458 + if (fragment) { 459 + nf_log_buf_add(m, ")"); 460 + return; 461 + } 462 + 463 + ah = skb_header_pointer(skb, ptr, sizeof(_ahdr), 464 + &_ahdr); 465 + if (!ah) { 466 + /* Max length: 26 "INCOMPLETE [65535 bytes] )" */ 467 + nf_log_buf_add(m, "INCOMPLETE [%u bytes] )", 468 + skb->len - ptr); 469 + return; 470 + } 471 + 472 + /* Length: 15 "SPI=0xF1234567 */ 473 + nf_log_buf_add(m, "SPI=0x%x ", ntohl(ah->spi)); 474 + } 475 + 476 + hdrlen = ipv6_authlen(hp); 477 + break; 478 + case IPPROTO_ESP: 479 + if (logflags & NF_LOG_IPOPT) { 480 + struct ip_esp_hdr _esph; 481 + const struct ip_esp_hdr *eh; 482 + 483 + /* Max length: 4 "ESP " */ 484 + nf_log_buf_add(m, "ESP "); 485 + 486 + if (fragment) { 487 + nf_log_buf_add(m, ")"); 488 + return; 489 + } 490 + 491 + /* Max length: 26 "INCOMPLETE [65535 bytes] )" */ 492 + eh = skb_header_pointer(skb, ptr, sizeof(_esph), 493 + &_esph); 494 + if (!eh) { 495 + nf_log_buf_add(m, "INCOMPLETE [%u bytes] )", 496 + skb->len - ptr); 497 + return; 498 + } 499 + 500 + /* Length: 16 "SPI=0xF1234567 )" */ 501 + nf_log_buf_add(m, "SPI=0x%x )", 502 + ntohl(eh->spi)); 503 + } 504 + return; 505 + default: 506 + /* Max length: 20 "Unknown Ext Hdr 255" */ 507 + nf_log_buf_add(m, "Unknown Ext Hdr %u", currenthdr); 508 + return; 509 + } 510 + if (logflags & NF_LOG_IPOPT) 511 + nf_log_buf_add(m, ") "); 512 + 513 + currenthdr = hp->nexthdr; 514 + ptr += hdrlen; 515 + } 516 + 517 + switch (currenthdr) { 518 + case IPPROTO_TCP: 519 + if (nf_log_dump_tcp_header(m, skb, currenthdr, fragment, 520 + ptr, logflags)) 521 + return; 522 + break; 523 + case IPPROTO_UDP: 524 + case IPPROTO_UDPLITE: 525 + if (nf_log_dump_udp_header(m, skb, currenthdr, fragment, ptr)) 526 + return; 527 + break; 528 + case IPPROTO_ICMPV6: { 529 + struct icmp6hdr _icmp6h; 530 + const struct icmp6hdr *ic; 531 + 532 + /* Max length: 13 "PROTO=ICMPv6 " */ 533 + nf_log_buf_add(m, "PROTO=ICMPv6 "); 534 + 535 + if (fragment) 536 + break; 537 + 538 + /* Max length: 25 "INCOMPLETE [65535 bytes] " */ 539 + ic = skb_header_pointer(skb, ptr, sizeof(_icmp6h), &_icmp6h); 540 + if (!ic) { 541 + nf_log_buf_add(m, "INCOMPLETE [%u bytes] ", 542 + skb->len - ptr); 543 + return; 544 + } 545 + 546 + /* Max length: 18 "TYPE=255 CODE=255 " */ 547 + nf_log_buf_add(m, "TYPE=%u CODE=%u ", 548 + ic->icmp6_type, ic->icmp6_code); 549 + 550 + switch (ic->icmp6_type) { 551 + case ICMPV6_ECHO_REQUEST: 552 + case ICMPV6_ECHO_REPLY: 553 + /* Max length: 19 "ID=65535 SEQ=65535 " */ 554 + nf_log_buf_add(m, "ID=%u SEQ=%u ", 555 + ntohs(ic->icmp6_identifier), 556 + ntohs(ic->icmp6_sequence)); 557 + break; 558 + case ICMPV6_MGM_QUERY: 559 + case ICMPV6_MGM_REPORT: 560 + case ICMPV6_MGM_REDUCTION: 561 + break; 562 + 563 + case ICMPV6_PARAMPROB: 564 + /* Max length: 17 "POINTER=ffffffff " */ 565 + nf_log_buf_add(m, "POINTER=%08x ", 566 + ntohl(ic->icmp6_pointer)); 567 + fallthrough; 568 + case ICMPV6_DEST_UNREACH: 569 + case ICMPV6_PKT_TOOBIG: 570 + case ICMPV6_TIME_EXCEED: 571 + /* Max length: 3+maxlen */ 572 + if (recurse) { 573 + nf_log_buf_add(m, "["); 574 + dump_ipv6_packet(net, m, info, skb, 575 + ptr + sizeof(_icmp6h), 0); 576 + nf_log_buf_add(m, "] "); 577 + } 578 + 579 + /* Max length: 10 "MTU=65535 " */ 580 + if (ic->icmp6_type == ICMPV6_PKT_TOOBIG) { 581 + nf_log_buf_add(m, "MTU=%u ", 582 + ntohl(ic->icmp6_mtu)); 583 + } 584 + } 585 + break; 586 + } 587 + /* Max length: 10 "PROTO=255 " */ 588 + default: 589 + nf_log_buf_add(m, "PROTO=%u ", currenthdr); 590 + } 591 + 592 + /* Max length: 15 "UID=4294967295 " */ 593 + if ((logflags & NF_LOG_UID) && recurse) 594 + nf_log_dump_sk_uid_gid(net, m, skb->sk); 595 + 596 + /* Max length: 16 "MARK=0xFFFFFFFF " */ 597 + if (recurse && skb->mark) 598 + nf_log_buf_add(m, "MARK=0x%x ", skb->mark); 599 + } 600 + 359 601 static void dump_ipv4_mac_header(struct nf_log_buf *m, 360 602 const struct nf_loginfo *info, 361 603 const struct sk_buff *skb) ··· 674 430 .me = THIS_MODULE, 675 431 }; 676 432 433 + static void dump_ipv6_mac_header(struct nf_log_buf *m, 434 + const struct nf_loginfo *info, 435 + const struct sk_buff *skb) 436 + { 437 + struct net_device *dev = skb->dev; 438 + unsigned int logflags = 0; 439 + 440 + if (info->type == NF_LOG_TYPE_LOG) 441 + logflags = info->u.log.logflags; 442 + 443 + if (!(logflags & NF_LOG_MACDECODE)) 444 + goto fallback; 445 + 446 + switch (dev->type) { 447 + case ARPHRD_ETHER: 448 + nf_log_buf_add(m, "MACSRC=%pM MACDST=%pM ", 449 + eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest); 450 + nf_log_dump_vlan(m, skb); 451 + nf_log_buf_add(m, "MACPROTO=%04x ", 452 + ntohs(eth_hdr(skb)->h_proto)); 453 + return; 454 + default: 455 + break; 456 + } 457 + 458 + fallback: 459 + nf_log_buf_add(m, "MAC="); 460 + if (dev->hard_header_len && 461 + skb->mac_header != skb->network_header) { 462 + const unsigned char *p = skb_mac_header(skb); 463 + unsigned int len = dev->hard_header_len; 464 + unsigned int i; 465 + 466 + if (dev->type == ARPHRD_SIT) { 467 + p -= ETH_HLEN; 468 + 469 + if (p < skb->head) 470 + p = NULL; 471 + } 472 + 473 + if (p) { 474 + nf_log_buf_add(m, "%02x", *p++); 475 + for (i = 1; i < len; i++) 476 + nf_log_buf_add(m, ":%02x", *p++); 477 + } 478 + nf_log_buf_add(m, " "); 479 + 480 + if (dev->type == ARPHRD_SIT) { 481 + const struct iphdr *iph = 482 + (struct iphdr *)skb_mac_header(skb); 483 + nf_log_buf_add(m, "TUNNEL=%pI4->%pI4 ", &iph->saddr, 484 + &iph->daddr); 485 + } 486 + } else { 487 + nf_log_buf_add(m, " "); 488 + } 489 + } 490 + 491 + static void nf_log_ip6_packet(struct net *net, u_int8_t pf, 492 + unsigned int hooknum, const struct sk_buff *skb, 493 + const struct net_device *in, 494 + const struct net_device *out, 495 + const struct nf_loginfo *loginfo, 496 + const char *prefix) 497 + { 498 + struct nf_log_buf *m; 499 + 500 + /* FIXME: Disabled from containers until syslog ns is supported */ 501 + if (!net_eq(net, &init_net) && !sysctl_nf_log_all_netns) 502 + return; 503 + 504 + m = nf_log_buf_open(); 505 + 506 + if (!loginfo) 507 + loginfo = &default_loginfo; 508 + 509 + nf_log_dump_packet_common(m, pf, hooknum, skb, in, out, 510 + loginfo, prefix); 511 + 512 + if (in) 513 + dump_ipv6_mac_header(m, loginfo, skb); 514 + 515 + dump_ipv6_packet(net, m, loginfo, skb, skb_network_offset(skb), 1); 516 + 517 + nf_log_buf_close(m); 518 + } 519 + 520 + static struct nf_logger nf_ip6_logger __read_mostly = { 521 + .name = "nf_log_ipv6", 522 + .type = NF_LOG_TYPE_LOG, 523 + .logfn = nf_log_ip6_packet, 524 + .me = THIS_MODULE, 525 + }; 526 + 677 527 static int __net_init nf_log_syslog_net_init(struct net *net) 678 528 { 679 529 int ret = nf_log_set(net, NFPROTO_IPV4, &nf_ip_logger); ··· 778 440 ret = nf_log_set(net, NFPROTO_ARP, &nf_arp_logger); 779 441 if (ret) 780 442 goto err1; 781 - err1: 443 + 444 + ret = nf_log_set(net, NFPROTO_IPV6, &nf_ip6_logger); 445 + if (ret) 446 + goto err2; 447 + return 0; 448 + err2: 782 449 nf_log_unset(net, &nf_arp_logger); 450 + err1: 451 + nf_log_unset(net, &nf_ip_logger); 783 452 return ret; 784 453 } 785 454 ··· 817 472 if (ret < 0) 818 473 goto err2; 819 474 475 + ret = nf_log_register(NFPROTO_IPV6, &nf_ip6_logger); 476 + if (ret < 0) 477 + goto err3; 478 + 820 479 return 0; 821 - err2: 480 + err3: 822 481 nf_log_unregister(&nf_arp_logger); 482 + err2: 483 + nf_log_unregister(&nf_ip_logger); 823 484 err1: 824 485 pr_err("failed to register logger\n"); 825 486 unregister_pernet_subsys(&nf_log_syslog_net_ops); ··· 837 486 unregister_pernet_subsys(&nf_log_syslog_net_ops); 838 487 nf_log_unregister(&nf_ip_logger); 839 488 nf_log_unregister(&nf_arp_logger); 489 + nf_log_unregister(&nf_ip6_logger); 840 490 } 841 491 842 492 module_init(nf_log_syslog_init); ··· 848 496 MODULE_LICENSE("GPL"); 849 497 MODULE_ALIAS("nf_log_arp"); 850 498 MODULE_ALIAS("nf_log_ipv4"); 499 + MODULE_ALIAS("nf_log_ipv6"); 851 500 MODULE_ALIAS_NF_LOGGER(AF_INET, 0); 852 501 MODULE_ALIAS_NF_LOGGER(3, 0); 502 + MODULE_ALIAS_NF_LOGGER(AF_INET6, 0);