cgnat test case added
[samplevnf.git] / VNFs / DPPD-PROX / handle_blockudp.c
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 #include <rte_ip.h>
18 #include <rte_ether.h>
19
20 #include "task_base.h"
21 #include "task_init.h"
22 #include "defines.h"
23 #include "etypes.h"
24 #include "prefetch.h"
25 #include "log.h"
26
27 struct task_blockudp {
28         struct task_base    base;
29 };
30
31 static int handle_blockudp_bulk(struct task_base *tbase, struct rte_mbuf **mbufs, uint16_t n_pkts)
32 {
33         struct task_blockudp *task = (struct task_blockudp *)tbase;
34         uint8_t out[MAX_PKT_BURST];
35         uint16_t j;
36
37         for (j = 0; j < n_pkts; ++j) {
38                 prox_rte_ether_hdr *peth = rte_pktmbuf_mtod(mbufs[j], prox_rte_ether_hdr *);
39                 prox_rte_ipv4_hdr *pip = (prox_rte_ipv4_hdr *) (peth + 1);
40                 out[j] = peth->ether_type == ETYPE_IPv4 && pip->next_proto_id == 0x11 ? OUT_DISCARD : 0;
41         }
42
43         return task->base.tx_pkt(&task->base, mbufs, n_pkts, out);
44 }
45
46 static void init_task_blockudp(__attribute__((unused)) struct task_base *tbase,
47                            __attribute__((unused)) struct task_args *targ)
48 {
49 }
50
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)
56 };
57
58 __attribute__((constructor)) static void reg_task_blockudp(void)
59 {
60         reg_task(&task_init_blockudp);
61 }