Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This is a module which is used for logging packets. |
| 3 | */ |
| 4 | |
| 5 | /* (C) 1999-2001 Paul `Rusty' Russell |
| 6 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/skbuff.h> |
| 16 | #include <linux/ip.h> |
| 17 | #include <net/icmp.h> |
| 18 | #include <net/udp.h> |
| 19 | #include <net/tcp.h> |
| 20 | #include <net/route.h> |
| 21 | |
| 22 | #include <linux/netfilter.h> |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 23 | #include <linux/netfilter/x_tables.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/netfilter_ipv4/ipt_LOG.h> |
Patrick McHardy | f01ffbd | 2007-12-17 22:38:49 -0800 | [diff] [blame^] | 25 | #include <net/netfilter/nf_log.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | MODULE_LICENSE("GPL"); |
| 28 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); |
| 29 | MODULE_DESCRIPTION("iptables syslog logging module"); |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | /* Use lock to serialize, so printks don't overlap */ |
| 32 | static DEFINE_SPINLOCK(log_lock); |
| 33 | |
| 34 | /* One level of recursion won't kill us */ |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 35 | static void dump_packet(const struct nf_loginfo *info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | const struct sk_buff *skb, |
| 37 | unsigned int iphoff) |
| 38 | { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 39 | struct iphdr _iph; |
| 40 | const struct iphdr *ih; |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 41 | unsigned int logflags; |
| 42 | |
| 43 | if (info->type == NF_LOG_TYPE_LOG) |
| 44 | logflags = info->u.log.logflags; |
| 45 | else |
| 46 | logflags = NF_LOG_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph); |
| 49 | if (ih == NULL) { |
| 50 | printk("TRUNCATED"); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | /* Important fields: |
| 55 | * TOS, len, DF/MF, fragment offset, TTL, src, dst, options. */ |
| 56 | /* Max length: 40 "SRC=255.255.255.255 DST=255.255.255.255 " */ |
| 57 | printk("SRC=%u.%u.%u.%u DST=%u.%u.%u.%u ", |
| 58 | NIPQUAD(ih->saddr), NIPQUAD(ih->daddr)); |
| 59 | |
| 60 | /* Max length: 46 "LEN=65535 TOS=0xFF PREC=0xFF TTL=255 ID=65535 " */ |
| 61 | printk("LEN=%u TOS=0x%02X PREC=0x%02X TTL=%u ID=%u ", |
| 62 | ntohs(ih->tot_len), ih->tos & IPTOS_TOS_MASK, |
| 63 | ih->tos & IPTOS_PREC_MASK, ih->ttl, ntohs(ih->id)); |
| 64 | |
| 65 | /* Max length: 6 "CE DF MF " */ |
| 66 | if (ntohs(ih->frag_off) & IP_CE) |
| 67 | printk("CE "); |
| 68 | if (ntohs(ih->frag_off) & IP_DF) |
| 69 | printk("DF "); |
| 70 | if (ntohs(ih->frag_off) & IP_MF) |
| 71 | printk("MF "); |
| 72 | |
| 73 | /* Max length: 11 "FRAG:65535 " */ |
| 74 | if (ntohs(ih->frag_off) & IP_OFFSET) |
| 75 | printk("FRAG:%u ", ntohs(ih->frag_off) & IP_OFFSET); |
| 76 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 77 | if ((logflags & IPT_LOG_IPOPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | && ih->ihl * 4 > sizeof(struct iphdr)) { |
| 79 | unsigned char _opt[4 * 15 - sizeof(struct iphdr)], *op; |
| 80 | unsigned int i, optsize; |
| 81 | |
| 82 | optsize = ih->ihl * 4 - sizeof(struct iphdr); |
| 83 | op = skb_header_pointer(skb, iphoff+sizeof(_iph), |
| 84 | optsize, _opt); |
| 85 | if (op == NULL) { |
| 86 | printk("TRUNCATED"); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | /* Max length: 127 "OPT (" 15*4*2chars ") " */ |
| 91 | printk("OPT ("); |
| 92 | for (i = 0; i < optsize; i++) |
| 93 | printk("%02X", op[i]); |
| 94 | printk(") "); |
| 95 | } |
| 96 | |
| 97 | switch (ih->protocol) { |
| 98 | case IPPROTO_TCP: { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 99 | struct tcphdr _tcph; |
| 100 | const struct tcphdr *th; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | /* Max length: 10 "PROTO=TCP " */ |
| 103 | printk("PROTO=TCP "); |
| 104 | |
| 105 | if (ntohs(ih->frag_off) & IP_OFFSET) |
| 106 | break; |
| 107 | |
| 108 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ |
| 109 | th = skb_header_pointer(skb, iphoff + ih->ihl * 4, |
| 110 | sizeof(_tcph), &_tcph); |
| 111 | if (th == NULL) { |
| 112 | printk("INCOMPLETE [%u bytes] ", |
| 113 | skb->len - iphoff - ih->ihl*4); |
| 114 | break; |
| 115 | } |
| 116 | |
| 117 | /* Max length: 20 "SPT=65535 DPT=65535 " */ |
| 118 | printk("SPT=%u DPT=%u ", |
| 119 | ntohs(th->source), ntohs(th->dest)); |
| 120 | /* Max length: 30 "SEQ=4294967295 ACK=4294967295 " */ |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 121 | if (logflags & IPT_LOG_TCPSEQ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | printk("SEQ=%u ACK=%u ", |
| 123 | ntohl(th->seq), ntohl(th->ack_seq)); |
| 124 | /* Max length: 13 "WINDOW=65535 " */ |
| 125 | printk("WINDOW=%u ", ntohs(th->window)); |
| 126 | /* Max length: 9 "RES=0x3F " */ |
| 127 | printk("RES=0x%02x ", (u8)(ntohl(tcp_flag_word(th) & TCP_RESERVED_BITS) >> 22)); |
| 128 | /* Max length: 32 "CWR ECE URG ACK PSH RST SYN FIN " */ |
| 129 | if (th->cwr) |
| 130 | printk("CWR "); |
| 131 | if (th->ece) |
| 132 | printk("ECE "); |
| 133 | if (th->urg) |
| 134 | printk("URG "); |
| 135 | if (th->ack) |
| 136 | printk("ACK "); |
| 137 | if (th->psh) |
| 138 | printk("PSH "); |
| 139 | if (th->rst) |
| 140 | printk("RST "); |
| 141 | if (th->syn) |
| 142 | printk("SYN "); |
| 143 | if (th->fin) |
| 144 | printk("FIN "); |
| 145 | /* Max length: 11 "URGP=65535 " */ |
| 146 | printk("URGP=%u ", ntohs(th->urg_ptr)); |
| 147 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 148 | if ((logflags & IPT_LOG_TCPOPT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | && th->doff * 4 > sizeof(struct tcphdr)) { |
| 150 | unsigned char _opt[4 * 15 - sizeof(struct tcphdr)]; |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 151 | const unsigned char *op; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | unsigned int i, optsize; |
| 153 | |
| 154 | optsize = th->doff * 4 - sizeof(struct tcphdr); |
| 155 | op = skb_header_pointer(skb, |
| 156 | iphoff+ih->ihl*4+sizeof(_tcph), |
| 157 | optsize, _opt); |
| 158 | if (op == NULL) { |
| 159 | printk("TRUNCATED"); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | /* Max length: 127 "OPT (" 15*4*2chars ") " */ |
| 164 | printk("OPT ("); |
| 165 | for (i = 0; i < optsize; i++) |
| 166 | printk("%02X", op[i]); |
| 167 | printk(") "); |
| 168 | } |
| 169 | break; |
| 170 | } |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 171 | case IPPROTO_UDP: |
| 172 | case IPPROTO_UDPLITE: { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 173 | struct udphdr _udph; |
| 174 | const struct udphdr *uh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 176 | if (ih->protocol == IPPROTO_UDP) |
| 177 | /* Max length: 10 "PROTO=UDP " */ |
| 178 | printk("PROTO=UDP " ); |
| 179 | else /* Max length: 14 "PROTO=UDPLITE " */ |
| 180 | printk("PROTO=UDPLITE "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | if (ntohs(ih->frag_off) & IP_OFFSET) |
| 183 | break; |
| 184 | |
| 185 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ |
| 186 | uh = skb_header_pointer(skb, iphoff+ih->ihl*4, |
| 187 | sizeof(_udph), &_udph); |
| 188 | if (uh == NULL) { |
| 189 | printk("INCOMPLETE [%u bytes] ", |
| 190 | skb->len - iphoff - ih->ihl*4); |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | /* Max length: 20 "SPT=65535 DPT=65535 " */ |
| 195 | printk("SPT=%u DPT=%u LEN=%u ", |
| 196 | ntohs(uh->source), ntohs(uh->dest), |
| 197 | ntohs(uh->len)); |
| 198 | break; |
| 199 | } |
| 200 | case IPPROTO_ICMP: { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 201 | struct icmphdr _icmph; |
| 202 | const struct icmphdr *ich; |
Arjan van de Ven | 9b5b5cf | 2005-11-29 16:21:38 -0800 | [diff] [blame] | 203 | static const size_t required_len[NR_ICMP_TYPES+1] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | = { [ICMP_ECHOREPLY] = 4, |
| 205 | [ICMP_DEST_UNREACH] |
| 206 | = 8 + sizeof(struct iphdr), |
| 207 | [ICMP_SOURCE_QUENCH] |
| 208 | = 8 + sizeof(struct iphdr), |
| 209 | [ICMP_REDIRECT] |
| 210 | = 8 + sizeof(struct iphdr), |
| 211 | [ICMP_ECHO] = 4, |
| 212 | [ICMP_TIME_EXCEEDED] |
| 213 | = 8 + sizeof(struct iphdr), |
| 214 | [ICMP_PARAMETERPROB] |
| 215 | = 8 + sizeof(struct iphdr), |
| 216 | [ICMP_TIMESTAMP] = 20, |
| 217 | [ICMP_TIMESTAMPREPLY] = 20, |
| 218 | [ICMP_ADDRESS] = 12, |
| 219 | [ICMP_ADDRESSREPLY] = 12 }; |
| 220 | |
| 221 | /* Max length: 11 "PROTO=ICMP " */ |
| 222 | printk("PROTO=ICMP "); |
| 223 | |
| 224 | if (ntohs(ih->frag_off) & IP_OFFSET) |
| 225 | break; |
| 226 | |
| 227 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ |
| 228 | ich = skb_header_pointer(skb, iphoff + ih->ihl * 4, |
| 229 | sizeof(_icmph), &_icmph); |
| 230 | if (ich == NULL) { |
| 231 | printk("INCOMPLETE [%u bytes] ", |
| 232 | skb->len - iphoff - ih->ihl*4); |
| 233 | break; |
| 234 | } |
| 235 | |
| 236 | /* Max length: 18 "TYPE=255 CODE=255 " */ |
| 237 | printk("TYPE=%u CODE=%u ", ich->type, ich->code); |
| 238 | |
| 239 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ |
| 240 | if (ich->type <= NR_ICMP_TYPES |
| 241 | && required_len[ich->type] |
| 242 | && skb->len-iphoff-ih->ihl*4 < required_len[ich->type]) { |
| 243 | printk("INCOMPLETE [%u bytes] ", |
| 244 | skb->len - iphoff - ih->ihl*4); |
| 245 | break; |
| 246 | } |
| 247 | |
| 248 | switch (ich->type) { |
| 249 | case ICMP_ECHOREPLY: |
| 250 | case ICMP_ECHO: |
| 251 | /* Max length: 19 "ID=65535 SEQ=65535 " */ |
| 252 | printk("ID=%u SEQ=%u ", |
| 253 | ntohs(ich->un.echo.id), |
| 254 | ntohs(ich->un.echo.sequence)); |
| 255 | break; |
| 256 | |
| 257 | case ICMP_PARAMETERPROB: |
| 258 | /* Max length: 14 "PARAMETER=255 " */ |
| 259 | printk("PARAMETER=%u ", |
| 260 | ntohl(ich->un.gateway) >> 24); |
| 261 | break; |
| 262 | case ICMP_REDIRECT: |
| 263 | /* Max length: 24 "GATEWAY=255.255.255.255 " */ |
| 264 | printk("GATEWAY=%u.%u.%u.%u ", |
| 265 | NIPQUAD(ich->un.gateway)); |
| 266 | /* Fall through */ |
| 267 | case ICMP_DEST_UNREACH: |
| 268 | case ICMP_SOURCE_QUENCH: |
| 269 | case ICMP_TIME_EXCEEDED: |
| 270 | /* Max length: 3+maxlen */ |
| 271 | if (!iphoff) { /* Only recurse once. */ |
| 272 | printk("["); |
| 273 | dump_packet(info, skb, |
| 274 | iphoff + ih->ihl*4+sizeof(_icmph)); |
| 275 | printk("] "); |
| 276 | } |
| 277 | |
| 278 | /* Max length: 10 "MTU=65535 " */ |
| 279 | if (ich->type == ICMP_DEST_UNREACH |
| 280 | && ich->code == ICMP_FRAG_NEEDED) |
| 281 | printk("MTU=%u ", ntohs(ich->un.frag.mtu)); |
| 282 | } |
| 283 | break; |
| 284 | } |
| 285 | /* Max Length */ |
| 286 | case IPPROTO_AH: { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 287 | struct ip_auth_hdr _ahdr; |
| 288 | const struct ip_auth_hdr *ah; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | if (ntohs(ih->frag_off) & IP_OFFSET) |
| 291 | break; |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | /* Max length: 9 "PROTO=AH " */ |
| 294 | printk("PROTO=AH "); |
| 295 | |
| 296 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ |
| 297 | ah = skb_header_pointer(skb, iphoff+ih->ihl*4, |
| 298 | sizeof(_ahdr), &_ahdr); |
| 299 | if (ah == NULL) { |
| 300 | printk("INCOMPLETE [%u bytes] ", |
| 301 | skb->len - iphoff - ih->ihl*4); |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | /* Length: 15 "SPI=0xF1234567 " */ |
| 306 | printk("SPI=0x%x ", ntohl(ah->spi)); |
| 307 | break; |
| 308 | } |
| 309 | case IPPROTO_ESP: { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 310 | struct ip_esp_hdr _esph; |
| 311 | const struct ip_esp_hdr *eh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
| 313 | /* Max length: 10 "PROTO=ESP " */ |
| 314 | printk("PROTO=ESP "); |
| 315 | |
| 316 | if (ntohs(ih->frag_off) & IP_OFFSET) |
| 317 | break; |
| 318 | |
| 319 | /* Max length: 25 "INCOMPLETE [65535 bytes] " */ |
| 320 | eh = skb_header_pointer(skb, iphoff+ih->ihl*4, |
| 321 | sizeof(_esph), &_esph); |
| 322 | if (eh == NULL) { |
| 323 | printk("INCOMPLETE [%u bytes] ", |
| 324 | skb->len - iphoff - ih->ihl*4); |
| 325 | break; |
| 326 | } |
| 327 | |
| 328 | /* Length: 15 "SPI=0xF1234567 " */ |
| 329 | printk("SPI=0x%x ", ntohl(eh->spi)); |
| 330 | break; |
| 331 | } |
| 332 | /* Max length: 10 "PROTO 255 " */ |
| 333 | default: |
| 334 | printk("PROTO=%u ", ih->protocol); |
| 335 | } |
| 336 | |
| 337 | /* Max length: 15 "UID=4294967295 " */ |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 338 | if ((logflags & IPT_LOG_UID) && !iphoff && skb->sk) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | read_lock_bh(&skb->sk->sk_callback_lock); |
| 340 | if (skb->sk->sk_socket && skb->sk->sk_socket->file) |
Maciej Soltysiak | 17dfc93 | 2007-12-04 23:50:38 -0800 | [diff] [blame] | 341 | printk("UID=%u GID=%u", |
| 342 | skb->sk->sk_socket->file->f_uid, |
| 343 | skb->sk->sk_socket->file->f_gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | read_unlock_bh(&skb->sk->sk_callback_lock); |
| 345 | } |
| 346 | |
| 347 | /* Proto Max log string length */ |
| 348 | /* IP: 40+46+6+11+127 = 230 */ |
| 349 | /* TCP: 10+max(25,20+30+13+9+32+11+127) = 252 */ |
| 350 | /* UDP: 10+max(25,20) = 35 */ |
Gerrit Renker | ba4e58e | 2006-11-27 11:10:57 -0800 | [diff] [blame] | 351 | /* UDPLITE: 14+max(25,20) = 39 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* ICMP: 11+max(25, 18+25+max(19,14,24+3+n+10,3+n+10)) = 91+n */ |
| 353 | /* ESP: 10+max(25)+15 = 50 */ |
| 354 | /* AH: 9+max(25)+15 = 49 */ |
| 355 | /* unknown: 10 */ |
| 356 | |
| 357 | /* (ICMP allows recursion one level deep) */ |
| 358 | /* maxlen = IP + ICMP + IP + max(TCP,UDP,ICMP,unknown) */ |
| 359 | /* maxlen = 230+ 91 + 230 + 252 = 803 */ |
| 360 | } |
| 361 | |
Adrian Bunk | d127e94 | 2005-11-29 16:28:18 -0800 | [diff] [blame] | 362 | static struct nf_loginfo default_loginfo = { |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 363 | .type = NF_LOG_TYPE_LOG, |
| 364 | .u = { |
| 365 | .log = { |
| 366 | .level = 0, |
| 367 | .logflags = NF_LOG_MASK, |
| 368 | }, |
| 369 | }, |
| 370 | }; |
| 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | static void |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 373 | ipt_log_packet(unsigned int pf, |
| 374 | unsigned int hooknum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | const struct sk_buff *skb, |
| 376 | const struct net_device *in, |
| 377 | const struct net_device *out, |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 378 | const struct nf_loginfo *loginfo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | const char *prefix) |
| 380 | { |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 381 | if (!loginfo) |
| 382 | loginfo = &default_loginfo; |
| 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | spin_lock_bh(&log_lock); |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 385 | printk("<%d>%sIN=%s OUT=%s ", loginfo->u.log.level, |
| 386 | prefix, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | in ? in->name : "", |
| 388 | out ? out->name : ""); |
| 389 | #ifdef CONFIG_BRIDGE_NETFILTER |
| 390 | if (skb->nf_bridge) { |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 391 | const struct net_device *physindev; |
| 392 | const struct net_device *physoutdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 394 | physindev = skb->nf_bridge->physindev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | if (physindev && in != physindev) |
| 396 | printk("PHYSIN=%s ", physindev->name); |
Jan Engelhardt | a47362a | 2007-07-07 22:16:55 -0700 | [diff] [blame] | 397 | physoutdev = skb->nf_bridge->physoutdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (physoutdev && out != physoutdev) |
| 399 | printk("PHYSOUT=%s ", physoutdev->name); |
| 400 | } |
| 401 | #endif |
| 402 | |
| 403 | if (in && !out) { |
| 404 | /* MAC logging for input chain only. */ |
| 405 | printk("MAC="); |
| 406 | if (skb->dev && skb->dev->hard_header_len |
Arnaldo Carvalho de Melo | b0e380b | 2007-04-10 21:21:55 -0700 | [diff] [blame] | 407 | && skb->mac_header != skb->network_header) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | int i; |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 409 | const unsigned char *p = skb_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | for (i = 0; i < skb->dev->hard_header_len; i++,p++) |
| 411 | printk("%02x%c", *p, |
| 412 | i==skb->dev->hard_header_len - 1 |
| 413 | ? ' ':':'); |
| 414 | } else |
| 415 | printk(" "); |
| 416 | } |
| 417 | |
| 418 | dump_packet(loginfo, skb, 0); |
| 419 | printk("\n"); |
| 420 | spin_unlock_bh(&log_lock); |
| 421 | } |
| 422 | |
| 423 | static unsigned int |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 424 | log_tg(struct sk_buff *skb, const struct net_device *in, |
| 425 | const struct net_device *out, unsigned int hooknum, |
| 426 | const struct xt_target *target, const void *targinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | { |
| 428 | const struct ipt_log_info *loginfo = targinfo; |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 429 | struct nf_loginfo li; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 431 | li.type = NF_LOG_TYPE_LOG; |
| 432 | li.u.log.level = loginfo->level; |
| 433 | li.u.log.logflags = loginfo->logflags; |
| 434 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 435 | ipt_log_packet(PF_INET, hooknum, skb, in, out, &li, |
YOSHIFUJI Hideaki | e905a9e | 2007-02-09 23:24:47 +0900 | [diff] [blame] | 436 | loginfo->prefix); |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 437 | return XT_CONTINUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 440 | static bool |
| 441 | log_tg_check(const char *tablename, const void *e, |
| 442 | const struct xt_target *target, void *targinfo, |
| 443 | unsigned int hook_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { |
| 445 | const struct ipt_log_info *loginfo = targinfo; |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | if (loginfo->level >= 8) { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 448 | pr_debug("LOG: level %u >= 8\n", loginfo->level); |
Jan Engelhardt | e1931b7 | 2007-07-07 22:16:26 -0700 | [diff] [blame] | 449 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | if (loginfo->prefix[sizeof(loginfo->prefix)-1] != '\0') { |
Patrick McHardy | 0d53778 | 2007-07-07 22:39:38 -0700 | [diff] [blame] | 452 | pr_debug("LOG: prefix term %i\n", |
| 453 | loginfo->prefix[sizeof(loginfo->prefix)-1]); |
Jan Engelhardt | e1931b7 | 2007-07-07 22:16:26 -0700 | [diff] [blame] | 454 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
Jan Engelhardt | e1931b7 | 2007-07-07 22:16:26 -0700 | [diff] [blame] | 456 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | } |
| 458 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 459 | static struct xt_target log_tg_reg __read_mostly = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | .name = "LOG", |
Jan Engelhardt | 6709dbb | 2007-02-07 15:11:19 -0800 | [diff] [blame] | 461 | .family = AF_INET, |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 462 | .target = log_tg, |
Patrick McHardy | 1d5cd90 | 2006-03-20 18:01:14 -0800 | [diff] [blame] | 463 | .targetsize = sizeof(struct ipt_log_info), |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 464 | .checkentry = log_tg_check, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | .me = THIS_MODULE, |
| 466 | }; |
| 467 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 468 | static struct nf_logger ipt_log_logger ={ |
| 469 | .name = "ipt_LOG", |
| 470 | .logfn = &ipt_log_packet, |
| 471 | .me = THIS_MODULE, |
| 472 | }; |
| 473 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 474 | static int __init log_tg_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | { |
Jan Engelhardt | e1fd058 | 2007-02-07 15:10:34 -0800 | [diff] [blame] | 476 | int ret; |
| 477 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 478 | ret = xt_register_target(&log_tg_reg); |
Jan Engelhardt | e1fd058 | 2007-02-07 15:10:34 -0800 | [diff] [blame] | 479 | if (ret < 0) |
| 480 | return ret; |
Patrick McHardy | 7e2acc7 | 2007-07-24 15:29:55 -0700 | [diff] [blame] | 481 | nf_log_register(PF_INET, &ipt_log_logger); |
| 482 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 485 | static void __exit log_tg_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
Patrick McHardy | e92ad99 | 2007-02-12 11:11:55 -0800 | [diff] [blame] | 487 | nf_log_unregister(&ipt_log_logger); |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 488 | xt_unregister_target(&log_tg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 491 | module_init(log_tg_init); |
| 492 | module_exit(log_tg_exit); |