From: Daniel Salzman Date: Tue, 25 Feb 2020 10:49:42 +0000 (+0100) Subject: libknot/xdp: extend filter configuration with DROP mode X-Git-Tag: embedded_lmdb~35^2~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f4d8d7c689cc6a05d9d719a882bef2a2e80cbbca;p=thirdparty%2Fknot-dns.git libknot/xdp: extend filter configuration with DROP mode --- diff --git a/src/libknot/xdp/af_xdp.c b/src/libknot/xdp/af_xdp.c index 03a943f05b..e254535055 100644 --- a/src/libknot/xdp/af_xdp.c +++ b/src/libknot/xdp/af_xdp.c @@ -587,7 +587,7 @@ void knot_xsk_free_recvd(struct knot_xsk_socket *socket, const knot_xsk_msg_t ms _public_ int knot_xsk_init(struct knot_xsk_socket **socket, const char *ifname, int if_queue, - int listen_port, knot_xsk_load_bpf_t load_bpf) + uint32_t listen_port, knot_xsk_load_bpf_t load_bpf) { if (socket == NULL || *socket != NULL) { return KNOT_EINVAL; diff --git a/src/libknot/xdp/af_xdp.h b/src/libknot/xdp/af_xdp.h index 0a0041926a..fe4a5657c1 100644 --- a/src/libknot/xdp/af_xdp.h +++ b/src/libknot/xdp/af_xdp.h @@ -21,6 +21,12 @@ #include +enum { + KNOT_XDP_LISTEN_PORT_MASK = 0xFFFF0000, /*!< Listen port option mask. */ + KNOT_XDP_LISTEN_PORT_ALL = 1 << 16, /*!< Listen on all ports. */ + KNOT_XDP_LISTEN_PORT_DROP = 1 << 17, /*!< Drop all incoming messages. */ +}; + /*! \brief A packet with src & dst MAC & IP addrs + UDP payload. */ typedef struct { struct sockaddr_storage ip_from; @@ -52,13 +58,13 @@ struct knot_xsk_socket; * \param socket Socket ctx; call with *socket == NULL. * \param ifname Name of the net iface (e.g. eth0). * \param if_queue Network card queue to be used (normally 1 socket per each queue). - * \param listen_port Port to listen on, or (1 << 16) to listen on all ports. + * \param listen_port Port to listen on, or KNOT_XSK_LISTEN_PORT_ flag. * \param load_bpf Insert BPF program into packet processing. * * \return KNOT_E* */ int knot_xsk_init(struct knot_xsk_socket **socket, const char *ifname, int if_queue, - int listen_port, knot_xsk_load_bpf_t load_bpf); + uint32_t listen_port, knot_xsk_load_bpf_t load_bpf); /*! \brief De-init XDP socket. */ void knot_xsk_deinit(struct knot_xsk_socket *socket); diff --git a/src/libknot/xdp/bpf-kernel-obj.c b/src/libknot/xdp/bpf-kernel-obj.c index a055759404..9fbbf4a853 100644 --- a/src/libknot/xdp/bpf-kernel-obj.c +++ b/src/libknot/xdp/bpf-kernel-obj.c @@ -7,13 +7,13 @@ unsigned char bpf_kernel_o[] = { 0x07, 0x00, 0x01, 0x00, 0xb7, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x61, 0x12, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbf, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x07, 0x06, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x2d, 0x26, 0x3b, 0x00, + 0x07, 0x06, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x2d, 0x26, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x35, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x34, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x67, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4f, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x15, 0x04, 0x0f, 0x00, 0x86, 0xdd, 0x00, 0x00, 0x55, 0x04, 0x35, 0x00, + 0x15, 0x04, 0x0f, 0x00, 0x86, 0xdd, 0x00, 0x00, 0x55, 0x04, 0x39, 0x00, 0x08, 0x00, 0x00, 0x00, 0xbf, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x07, 0x04, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x2d, 0x24, 0x32, 0x00, + 0x07, 0x04, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x2d, 0x24, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x34, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x04, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x15, 0x04, 0x01, 0x00, 0x40, 0x00, 0x00, 0x00, @@ -23,78 +23,78 @@ unsigned char bpf_kernel_o[] = { 0x00, 0x00, 0x00, 0x00, 0x71, 0x34, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbf, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x06, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, - 0x2d, 0x26, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x07, 0x00, 0x00, + 0x2d, 0x26, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x34, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x04, 0x05, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x00, 0x2d, 0x23, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3e, 0x00, 0x00, 0x00, 0x2d, 0x23, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x07, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x71, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbf, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x55, 0x04, 0x1b, 0x00, 0x11, 0x00, 0x00, 0x00, 0xbf, 0x63, 0x00, 0x00, + 0x55, 0x04, 0x1f, 0x00, 0x11, 0x00, 0x00, 0x00, 0xbf, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x03, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, - 0x2d, 0x23, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x11, 0x10, 0x00, + 0x2d, 0x23, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x1a, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, 0xbf, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x02, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xbf, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x01, 0x0e, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x61, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xbf, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x57, 0x02, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x00, 0x55, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb7, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x69, 0x62, 0x02, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x5d, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xb7, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x55, 0x07, 0x05, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x61, 0xa2, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0xb7, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x85, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x15, 0x01, 0x12, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xb7, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x61, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x03, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xbf, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5f, 0x32, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x15, 0x02, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x15, 0x02, 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00, 0xb7, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x69, 0x62, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5d, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb7, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x55, 0x07, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x61, 0xa2, 0xfc, 0xff, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xb7, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, + 0x33, 0x00, 0x00, 0x00, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x28, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0xf0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0x28, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, + 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x10, 0x00, 0x05, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x10, 0x00, 0x05, 0x00, + 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x68, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, + 0x00, 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x6d, 0x61, 0x70, 0x73, 0x00, + 0x2e, 0x72, 0x65, 0x6c, 0x78, 0x64, 0x70, 0x5f, 0x72, 0x65, 0x64, 0x69, + 0x72, 0x65, 0x63, 0x74, 0x5f, 0x75, 0x64, 0x70, 0x00, 0x78, 0x73, 0x6b, + 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x00, 0x71, 0x69, 0x64, 0x63, 0x6f, 0x6e, + 0x66, 0x5f, 0x6d, 0x61, 0x70, 0x00, 0x78, 0x64, 0x70, 0x5f, 0x72, 0x65, + 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x5f, 0x75, 0x64, 0x70, 0x5f, 0x66, + 0x75, 0x6e, 0x63, 0x00, 0x2e, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00, + 0x2e, 0x73, 0x79, 0x6d, 0x74, 0x61, 0x62, 0x00, 0x4c, 0x42, 0x42, 0x30, + 0x5f, 0x31, 0x39, 0x00, 0x4c, 0x42, 0x42, 0x30, 0x5f, 0x37, 0x00, 0x4c, + 0x42, 0x42, 0x30, 0x5f, 0x31, 0x37, 0x00, 0x4c, 0x42, 0x42, 0x30, 0x5f, + 0x36, 0x00, 0x4c, 0x42, 0x42, 0x30, 0x5f, 0x31, 0x31, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0xf1, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x03, 0x00, 0x28, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x03, 0x00, 0xd0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x03, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x03, 0x00, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x03, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x05, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, - 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x74, 0x65, 0x78, 0x74, 0x00, 0x6d, - 0x61, 0x70, 0x73, 0x00, 0x2e, 0x72, 0x65, 0x6c, 0x78, 0x64, 0x70, 0x5f, - 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x5f, 0x75, 0x64, 0x70, - 0x00, 0x78, 0x73, 0x6b, 0x73, 0x5f, 0x6d, 0x61, 0x70, 0x00, 0x71, 0x69, - 0x64, 0x63, 0x6f, 0x6e, 0x66, 0x5f, 0x6d, 0x61, 0x70, 0x00, 0x78, 0x64, - 0x70, 0x5f, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x5f, 0x75, - 0x64, 0x70, 0x5f, 0x66, 0x75, 0x6e, 0x63, 0x00, 0x62, 0x70, 0x66, 0x2d, - 0x6b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x2e, 0x63, 0x00, 0x2e, 0x73, 0x74, - 0x72, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x73, 0x79, 0x6d, 0x74, 0x61, 0x62, - 0x00, 0x4c, 0x42, 0x42, 0x30, 0x5f, 0x31, 0x38, 0x00, 0x4c, 0x42, 0x42, - 0x30, 0x5f, 0x37, 0x00, 0x4c, 0x42, 0x42, 0x30, 0x5f, 0x36, 0x00, 0x4c, - 0x42, 0x42, 0x30, 0x5f, 0x31, 0x36, 0x00, 0x4c, 0x42, 0x42, 0x30, 0x5f, - 0x31, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x03, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x8f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, @@ -105,24 +105,24 @@ unsigned char bpf_kernel_o[] = { 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x10, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x03, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x50, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, + 0x70, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x78, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x98, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; unsigned int bpf_kernel_o_len = 1496; diff --git a/src/libknot/xdp/bpf-kernel.c b/src/libknot/xdp/bpf-kernel.c index 74e1d5163c..485b081ce0 100644 --- a/src/libknot/xdp/bpf-kernel.c +++ b/src/libknot/xdp/bpf-kernel.c @@ -46,16 +46,17 @@ struct ipv6_frag_hdr { unsigned char whatever[7]; } __attribute__((packed)); +/* NOTE: this implementation expects little-endian byte ordering! */ SEC("xdp_redirect_udp") int xdp_redirect_udp_func(struct xdp_md *ctx) { - void *data = (void *)(long)ctx->data; - void *data_end = (void *)(long)ctx->data_end; + const void *data = (void *)(long)ctx->data; + const void *data_end = (void *)(long)ctx->data_end; - struct ethhdr *eth = data; - struct iphdr *ip4; - struct ipv6hdr *ip6; - struct udphdr *udp; + const struct ethhdr *eth = data; + const struct iphdr *ip4; + const struct ipv6hdr *ip6; + const struct udphdr *udp; __u8 ip_proto; __u8 fragmented = 0; @@ -88,7 +89,7 @@ int xdp_redirect_udp_func(struct xdp_md *ctx) data += sizeof(*ip6); if (ip_proto == IPPROTO_FRAGMENT) { fragmented = 1; - struct ipv6_frag_hdr *frag = data; + const struct ipv6_frag_hdr *frag = data; if ((void *)frag + sizeof(*frag) > data_end) { return XDP_PASS; } @@ -117,10 +118,17 @@ int xdp_redirect_udp_func(struct xdp_md *ctx) return XDP_ABORTED; } - /* Treat destination (DNS) port only. */ + /* Treat specified destination ports only. */ __u32 port_info = *qidconf; - if (!(port_info & (1 << 16)) && udp->dest != port_info) { - return XDP_PASS; + switch (port_info & 0xFFFF0000) { + case (1 << 17): + return XDP_DROP; + case (1 << 16): + break; + default: + if (udp->dest != port_info) { + return XDP_PASS; + } } /* Drop fragmented UDP datagrams. */ diff --git a/src/utils/xdp-gun/main.c b/src/utils/xdp-gun/main.c index 641717af04..d7d921a3f7 100644 --- a/src/utils/xdp-gun/main.c +++ b/src/utils/xdp-gun/main.c @@ -51,6 +51,8 @@ uint64_t global_size_recv = 0; #define LOCAL_PORT_MIN 1024 #define LOCAL_PORT_MAX 65535 +#define LISTEN_PORT KNOT_XDP_LISTEN_PORT_ALL + typedef struct { char dev[IFNAMSIZ]; uint64_t qps, duration; @@ -140,12 +142,12 @@ void *dns_xdp_gun_thread(void *_ctx) uint64_t tot_sent = 0, tot_recv = 0, tot_size = 0; uint64_t duration = 0; - int ret = knot_xsk_init(&xsk, ctx->dev, ctx->thread_id, (1 << 16), ctx->thread_id == 0); + int ret = knot_xsk_init(&xsk, ctx->dev, ctx->thread_id, LISTEN_PORT, ctx->thread_id == 0); if (ret != KNOT_EOK) { printf("failed to init XDP socket#%u: %s\n", ctx->thread_id, knot_strerror(ret)); return NULL; } - + struct pollfd pfd = { knot_xsk_get_poll_fd(xsk), POLLIN, 0 }; while (!dns_xdp_trigger) { @@ -159,7 +161,7 @@ void *dns_xdp_gun_thread(void *_ctx) timer_start(&timer); while (duration < ctx->duration + 1000000) { - + // sending part if (duration < ctx->duration) { ret = alloc_pkts(pkts, ctx->at_once, xsk, ctx, tick, &payload_ptr); @@ -199,7 +201,7 @@ void *dns_xdp_gun_thread(void *_ctx) if (!pfd.revents) { break; } - + uint32_t recvd = 0; ret = knot_xsk_recvmmsg(xsk, pkts, ctx->at_once, &recvd); if (ret != KNOT_EOK) { @@ -247,7 +249,7 @@ static int dev2mac(const char *dev, uint8_t *mac) return -errno; } strncpy(ifr.ifr_name, dev, IFNAMSIZ); - + int ret = ioctl(fd, SIOCGIFHWADDR, &ifr); if (ret >= 0) { memcpy(mac, ifr.ifr_hwaddr.sa_data, 6); @@ -375,7 +377,7 @@ int main(int argc, char *argv[]) } else { goto pusage; } - + double argf = atof(argv[2]); if (argf > 0) { ctx.duration = argf * 1000000.0; @@ -457,7 +459,7 @@ int main(int argc, char *argv[]) } else { goto pusage; } - + struct rlimit no_limit = { RLIM_INFINITY, RLIM_INFINITY }; int ret = setrlimit(RLIMIT_MEMLOCK, &no_limit); if (ret) {