diff options
author | Maxim Uvarov <maxim.uvarov@linaro.org> | 2014-11-20 11:44:12 +0300 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2014-11-21 18:38:20 +0300 |
commit | 553a993f5e323e89050b0f7b74009e9b4227157c (patch) | |
tree | b9409d7f9fa6308be81f8e19f9878440f4b90bc1 /platform | |
parent | 7c671645c1478dcabc2288c7d736e5bca4888037 (diff) |
pktio: add MTU manipulation functions
Implement pktio mtu functions:
odp_pktio_mtu() to get mtu value;
odp_pktio_set_mtu() to set mtu value.
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Reviewed-by: Mike Holmes <mike.holmes@linaro.org>
Reviewed-by: Anders Roxell <anders.roxell@linaro.org>
Diffstat (limited to 'platform')
-rw-r--r-- | platform/linux-generic/include/api/odp_packet_io.h | 23 | ||||
-rw-r--r-- | platform/linux-generic/include/odp_packet_io_internal.h | 4 | ||||
-rw-r--r-- | platform/linux-generic/odp_packet_io.c | 66 |
3 files changed, 93 insertions, 0 deletions
diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index 47daeda30..667395c3f 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -126,6 +126,29 @@ void odp_pktio_set_input(odp_packet_t pkt, odp_pktio_t id); odp_pktio_t odp_pktio_get_input(odp_packet_t pkt); /** + * Configure the MTU for a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * @param[in] mtu The value of MTU that the interface will be configured to + * use. + * + * @retval 0 on success. + * @retval -1 if specified mtu can not be handled. + * @retval -1 on any other error or illegal input parameters. + */ +int odp_pktio_set_mtu(odp_pktio_t id, int mtu); + +/** + * Return the currently configured MTU value of a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * + * @retval MTU value >0 on success. + * @retval -1 on any error or not existance pktio id. + */ +int odp_pktio_mtu(odp_pktio_t id); + +/** * @} */ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 23633ed69..0bc1e2197 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -21,6 +21,8 @@ extern "C" { #include <odp_spinlock.h> #include <odp_packet_socket.h> +#include <linux/if.h> + /** * Packet IO types */ @@ -38,6 +40,8 @@ struct pktio_entry { odp_pktio_type_t type; /**< pktio type */ pkt_sock_t pkt_sock; /**< using socket API for IO */ pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap API for IO */ + char name[IFNAMSIZ]; /**< name of pktio provided to + pktio_open() */ }; typedef union { diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index f78b7fd21..c5233509b 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -20,6 +20,7 @@ #include <odp_debug.h> #include <string.h> +#include <sys/ioctl.h> typedef struct { pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; @@ -203,6 +204,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) return ODP_PKTIO_INVALID; done: + strncpy(pktio_entry->s.name, dev, IFNAMSIZ); unlock_entry(pktio_entry); return id; } @@ -476,3 +478,67 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) queue_enq_multi(qentry, tmp_hdr_tbl, pkts); return nbr; } + +int odp_pktio_set_mtu(odp_pktio_t id, int mtu) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + if (mtu <= 0) { + ODP_DBG("illegal MTU value %d\n", mtu); + return -1; + } + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + ifr.ifr_mtu = mtu; + + ret = ioctl(sockfd, SIOCSIFMTU, (caddr_t)&ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCSIFMTU error\n"); + return -1; + } + + return 0; +} + +int odp_pktio_mtu(odp_pktio_t id) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + + ret = ioctl(sockfd, SIOCGIFMTU, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFMTU error\n"); + return -1; + } + + return ifr.ifr_mtu; +} |