Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log expression Flags key not implented #113

Closed
greenpau opened this issue Aug 9, 2020 · 0 comments
Closed

Log expression Flags key not implented #113

greenpau opened this issue Aug 9, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@greenpau
Copy link
Contributor

greenpau commented Aug 9, 2020

Trying to add the following rule:

log prefix "ipv6 input drop: " flags all

The nft debug says:

  ip filter forward 
    [ log tcpseq tcpopt ipopt uid macdecode ]

The following snippet adds log prefix "ipv6 input drop: "

    r := &nftables.Rule{
        Table: tb,
        Chain: ch,
        Exprs: []expr.Any{},
    }

    r.Exprs = append(r.Exprs, &expr.Log{
        Key:  unix.NFTA_LOG_PREFIX,
        Data: []byte(prefix),
    })

The various keys are here:

nftables/expr/log.go

Lines 30 to 65 in c25e4f6

func (e *Log) marshal() ([]byte, error) {
var data []byte
var err error
switch e.Key {
case unix.NFTA_LOG_GROUP:
data, err = netlink.MarshalAttributes([]netlink.Attribute{
{Type: unix.NFTA_LOG_GROUP, Data: e.Data},
})
case unix.NFTA_LOG_PREFIX:
prefix := append(e.Data, '\x00')
data, err = netlink.MarshalAttributes([]netlink.Attribute{
{Type: unix.NFTA_LOG_PREFIX, Data: prefix},
})
case unix.NFTA_LOG_SNAPLEN:
data, err = netlink.MarshalAttributes([]netlink.Attribute{
{Type: unix.NFTA_LOG_SNAPLEN, Data: e.Data},
})
case unix.NFTA_LOG_QTHRESHOLD:
data, err = netlink.MarshalAttributes([]netlink.Attribute{
{Type: unix.NFTA_LOG_QTHRESHOLD, Data: e.Data},
})
case unix.NFTA_LOG_LEVEL:
level := append(e.Data, '\x00')
data, err = netlink.MarshalAttributes([]netlink.Attribute{
{Type: unix.NFTA_LOG_LEVEL, Data: level},
})
}
if err != nil {
return nil, err
}
return netlink.MarshalAttributes([]netlink.Attribute{
{Type: unix.NFTA_EXPR_NAME, Data: []byte("log\x00")},
{Type: unix.NLA_F_NESTED | unix.NFTA_EXPR_DATA, Data: data},
})
}

However, it is unclear how to use this library to get flags all.

Reading through the various key, the tcpseq tcpopt ipopt uid macdecode do not popup. My guess is this is something that needs to be added to this library.

The nftables include/linux/netfilter/nf_tables.h contains the following snippet. It does refer to NFTA_LOG_FLAGS.

enum nft_log_attributes {
    NFTA_LOG_UNSPEC,
    NFTA_LOG_GROUP,
    NFTA_LOG_PREFIX,
    NFTA_LOG_SNAPLEN,
    NFTA_LOG_QTHRESHOLD,
    NFTA_LOG_LEVEL,
    NFTA_LOG_FLAGS,
    __NFTA_LOG_MAX
};

Perhaps there is a need to pass FF with NFTA_LOG_FLAGS? .. 🤔 ...

 * @NFTA_LOG_LEVEL: log level (NLA_U32)
 * @NFTA_LOG_FLAGS: logging flags (NLA_U32)
@stapelberg stapelberg added the enhancement New feature or request label Aug 10, 2020
turekt added a commit to turekt/nftables that referenced this issue Feb 20, 2022
Fixes google#113 | Log expression implementation changed to better support different log options | Added uint16 support to the binaryutil package | Changed old log expression tests that were failing after change | Added a new test to check the implementation for multiple log options
turekt added a commit to turekt/nftables that referenced this issue Feb 20, 2022
Fixes google#113 | Log expression implementation changed to better support different log options | Added uint16 support to the binaryutil package | Changed old log expression tests that were failing after change | Added a new test to check the implementation for multiple log options
turekt added a commit to turekt/nftables that referenced this issue Feb 21, 2022
Fixes google#113 | Log expression implementation changed to better support different log options | Added uint16 support to the binaryutil package | Changed old log expression tests that were failing after change | Added a new test to check the implementation for multiple log options
turekt added a commit to turekt/nftables that referenced this issue Feb 21, 2022
Fixes google#113 | Log expression implementation changed to better support different log options | Added uint16 support to the binaryutil package | Changed old log expression tests that were failing after change | Added a new test to check the implementation for multiple log options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants