2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include <rte_ether.h>
20 #include "task_base.h"
21 #include "task_init.h"
27 struct task_blockudp {
28 struct task_base base;
31 static int handle_blockudp_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts)
33 struct task_blockudp *task = (struct task_blockudp *)tbase;
34 uint8_t out[MAX_PKT_BURST];
37 for (j = 0; j < n_pkts; ++j) {
38 struct ether_hdr *peth = rte_pktmbuf_mtod(mbufs[j], struct ether_hdr *);
39 struct ipv4_hdr *pip = (struct ipv4_hdr *) (peth + 1);
40 out[j] = peth->ether_type == ETYPE_IPv4 && pip->next_proto_id == 0x11 ? OUT_DISCARD : 0;
43 return task->base.tx_pkt(&task->base, mbufs, n_pkts, out);
46 static void init_task_blockudp(__attribute__((unused)) struct task_base *tbase,
47 __attribute__((unused)) struct task_args *targ)
51 static struct task_init task_init_blockudp = {
52 .mode_str = "blockudp",
53 .init = init_task_blockudp,
54 .handle = handle_blockudp_bulk,
55 .size = sizeof(struct task_blockudp)
58 __attribute__((constructor)) static void reg_task_blockudp(void)
60 reg_task(&task_init_blockudp);