diff options
author | 2021-01-04 11:28:33 +0100 | |
---|---|---|
committer | 2022-03-28 22:34:33 +0000 | |
commit | e74c04fc9fb2600470fe79a69d3ec6b0db95faec (patch) | |
tree | cc85fb480afcbe74184a56162d3d06af67cc4eb5 /extras/libmemif/examples/common/packet_handler.c | |
parent | 7d6f7d0d67face9889e43bdb5f71f352294b918a (diff) |
libmemif: refactor examples
- icmp_responder: responds to ICMPv4 and ARP requests
- loopback: connects two interfaces and sends a
verification packet from master memif to slave memif
where it is looped back
- loopback (reverse path): reverses direction of packet
in loopback application (slave memif to master memif)
Type: refactor
Signed-off-by: Jakub Grajciar <jgrajcia@cisco.com>
Change-Id: Ie90aaa3367269408efb6c5d538ad5aa827432238
Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Diffstat (limited to 'extras/libmemif/examples/common/packet_handler.c')
-rw-r--r-- | extras/libmemif/examples/common/packet_handler.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/extras/libmemif/examples/common/packet_handler.c b/extras/libmemif/examples/common/packet_handler.c new file mode 100644 index 00000000000..705cc728a36 --- /dev/null +++ b/extras/libmemif/examples/common/packet_handler.c @@ -0,0 +1,65 @@ +/* + *------------------------------------------------------------------ + * Copyright (c) 2020 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------ + */ + +#include <common.h> +#include <icmp_proto.h> + +/* reply with the same data */ +int +basic_packet_handler (memif_connection_t *c) +{ + int i; + memif_buffer_t *dest, *src; + + /* in case of zero-copy the tx_buf_num will be zero, so the loop body won't + * execute */ + for (i = 0; i < c->tx_buf_num; i++) + { + memcpy (c->tx_bufs[i].data, c->rx_bufs[i].data, c->rx_bufs[i].len); + } + + return 0; +} + +/* ICMPv4 and ARP handler */ +int +icmp_packet_handler (memif_connection_t *c) +{ + int i; + memif_buffer_t *dest, *src; + + /* if tx_buf_num > 0 we use non-zero-copy mode */ + if (c->tx_buf_num > 0) + { + for (i = 0; i < c->tx_buf_num; i++) + { + resolve_packet (c->rx_bufs[i].data, c->rx_bufs[i].len, + c->tx_bufs[i].data, &c->tx_bufs[i].len, c->ip_addr, + c->hw_addr); + } + } + else + { + for (i = 0; i < c->rx_buf_num; i++) + { + resolve_packet_zero_copy (c->rx_bufs[i].data, &c->rx_bufs[i].len, + c->ip_addr, c->hw_addr); + } + } + + return 0; +}
\ No newline at end of file |