Skip to content

Commit

Permalink
netfilter: nf_log: do not assume ethernet header in netdev family
Browse files Browse the repository at this point in the history
In netdev family, we will handle non ethernet packets, so using
eth_hdr(skb)->h_proto is incorrect.

Meanwhile, we can use socket(AF_PACKET...) to sending packets, so
skb->protocol is not always set in bridge family.

Add an extra parameter into nf_log_l2packet to solve this issue.

Fixes: 1fddf4b ("netfilter: nf_log: add packet logging for netdev family")
Signed-off-by: Liping Zhang <zlpnobody@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Liping Zhang authored and Pablo Neira Ayuso committed Dec 4, 2016
1 parent b8ad652 commit 673ab46
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion include/net/netfilter/nf_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ void nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf,
const struct net_device *out,
const struct nf_loginfo *loginfo,
const char *prefix);
void nf_log_l2packet(struct net *net, u_int8_t pf, unsigned int hooknum,
void nf_log_l2packet(struct net *net, u_int8_t pf,
__be16 protocol,
unsigned int hooknum,
const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
Expand Down
3 changes: 2 additions & 1 deletion net/bridge/netfilter/nf_log_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static void nf_log_bridge_packet(struct net *net, u_int8_t pf,
const struct nf_loginfo *loginfo,
const char *prefix)
{
nf_log_l2packet(net, pf, hooknum, skb, in, out, loginfo, prefix);
nf_log_l2packet(net, pf, eth_hdr(skb)->h_proto, hooknum, skb,
in, out, loginfo, prefix);
}

static struct nf_logger nf_bridge_logger __read_mostly = {
Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nf_log_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,15 @@ EXPORT_SYMBOL_GPL(nf_log_dump_packet_common);

/* bridge and netdev logging families share this code. */
void nf_log_l2packet(struct net *net, u_int8_t pf,
__be16 protocol,
unsigned int hooknum,
const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
const struct nf_loginfo *loginfo,
const char *prefix)
{
switch (eth_hdr(skb)->h_proto) {
switch (protocol) {
case htons(ETH_P_IP):
nf_log_packet(net, NFPROTO_IPV4, hooknum, skb, in, out,
loginfo, "%s", prefix);
Expand Down
3 changes: 2 additions & 1 deletion net/netfilter/nf_log_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static void nf_log_netdev_packet(struct net *net, u_int8_t pf,
const struct nf_loginfo *loginfo,
const char *prefix)
{
nf_log_l2packet(net, pf, hooknum, skb, in, out, loginfo, prefix);
nf_log_l2packet(net, pf, skb->protocol, hooknum, skb, in, out,
loginfo, prefix);
}

static struct nf_logger nf_netdev_logger __read_mostly = {
Expand Down

0 comments on commit 673ab46

Please sign in to comment.