2014-06-05 09:35:40 +00:00
|
|
|
/** Interface related functions
|
2014-07-14 11:49:44 +00:00
|
|
|
*
|
|
|
|
* These functions are used to manage a network interface.
|
|
|
|
* Most of them make use of Linux-specific APIs.
|
2014-06-05 09:35:40 +00:00
|
|
|
*
|
2014-06-28 06:40:52 +00:00
|
|
|
* @file
|
2015-06-02 21:53:04 +02:00
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
2017-03-03 20:20:13 -04:00
|
|
|
* @copyright 2017, Institute for Automation of Complex Power Systems, EONERC
|
2017-04-27 12:56:43 +02:00
|
|
|
* @license GNU General Public License (version 3)
|
|
|
|
*
|
|
|
|
* VILLASnode
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* any later version.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2017-05-05 19:24:16 +00:00
|
|
|
*
|
2017-04-27 12:56:43 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-06-02 21:53:04 +02:00
|
|
|
*********************************************************************************/
|
2014-06-05 09:35:40 +00:00
|
|
|
|
2017-03-03 20:20:13 -04:00
|
|
|
/** @addtogroup fpga Kernel @{ */
|
|
|
|
|
2017-02-16 09:04:12 -03:00
|
|
|
#pragma once
|
2014-06-05 09:35:40 +00:00
|
|
|
|
2014-06-25 01:53:46 +00:00
|
|
|
#include <sys/types.h>
|
2015-08-22 17:42:02 +02:00
|
|
|
#include <sys/socket.h>
|
2014-06-05 09:35:40 +00:00
|
|
|
|
2015-03-21 15:19:41 +01:00
|
|
|
#include "list.h"
|
|
|
|
|
2016-06-08 22:36:38 +02:00
|
|
|
#define IF_IRQ_MAX 3 /**< Maxmimal number of IRQs of an interface */
|
2014-06-25 01:53:46 +00:00
|
|
|
|
2015-03-20 18:55:14 +01:00
|
|
|
#ifndef SO_MARK
|
2015-09-19 12:24:11 +02:00
|
|
|
#define SO_MARK 36 /**< Workaround: add missing constant for OPAL-RT Redhawk target */
|
2015-03-20 18:55:14 +01:00
|
|
|
#endif
|
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
struct socket;
|
2015-08-22 17:42:02 +02:00
|
|
|
struct nl_addr;
|
|
|
|
struct rtnl_link;
|
2014-12-05 12:39:52 +01:00
|
|
|
|
2014-06-25 01:53:46 +00:00
|
|
|
/** Interface data structure */
|
|
|
|
struct interface {
|
2015-10-11 13:22:58 +02:00
|
|
|
struct rtnl_link *nl_link; /**< libnl3: Handle of interface. */
|
|
|
|
struct rtnl_qdisc *tc_qdisc; /**< libnl3: Root priority queuing discipline (qdisc). */
|
2015-08-22 17:42:02 +02:00
|
|
|
|
2015-10-11 13:22:58 +02:00
|
|
|
char irqs[IF_IRQ_MAX]; /**< List of IRQs of the NIC. */
|
2017-03-29 04:25:30 +02:00
|
|
|
int affinity; /**< IRQ / Core Affinity of this interface. */
|
2014-06-25 01:53:46 +00:00
|
|
|
|
2015-10-11 13:22:58 +02:00
|
|
|
struct list sockets; /**< Linked list of associated sockets. */
|
2014-06-25 01:53:46 +00:00
|
|
|
};
|
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
/** Add a new interface to the global list and lookup name, irqs...
|
|
|
|
*
|
2015-08-22 17:42:02 +02:00
|
|
|
* @param link The libnl3 link handle
|
2014-12-05 12:39:52 +01:00
|
|
|
* @retval >0 Success. A pointer to the new interface.
|
|
|
|
* @retval 0 Error. The creation failed.
|
|
|
|
*/
|
2017-03-12 17:08:04 -03:00
|
|
|
int if_init(struct interface * , struct rtnl_link *link);
|
2014-12-05 12:39:52 +01:00
|
|
|
|
2015-03-21 15:23:57 +01:00
|
|
|
|
|
|
|
/** Destroy interface by freeing dynamically allocated memory.
|
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure.
|
|
|
|
*/
|
2017-02-18 10:45:05 -05:00
|
|
|
int if_destroy(struct interface *i);
|
2015-03-21 15:23:57 +01:00
|
|
|
|
2014-12-05 12:39:52 +01:00
|
|
|
/** Start interface.
|
|
|
|
*
|
|
|
|
* This setups traffic controls queue discs, network emulation and
|
|
|
|
* maps interface IRQs according to affinity.
|
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
2017-03-29 04:25:30 +02:00
|
|
|
int if_start(struct interface *i);
|
2014-12-05 12:39:52 +01:00
|
|
|
|
|
|
|
/** Stop interface
|
|
|
|
*
|
|
|
|
* This resets traffic qdiscs ant network emulation
|
|
|
|
* and maps interface IRQs to all CPUs.
|
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
|
|
|
*/
|
|
|
|
int if_stop(struct interface *i);
|
|
|
|
|
2015-08-22 17:42:02 +02:00
|
|
|
/** Lookup routing tables to get the interface on which packets for a certain destination
|
|
|
|
* will leave the system.
|
2014-06-25 01:53:46 +00:00
|
|
|
*
|
2015-08-22 17:42:02 +02:00
|
|
|
* @param[in] sa The destination address for outgoing packets.
|
|
|
|
* @param[out] link The egress interface.
|
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
2014-06-25 01:53:46 +00:00
|
|
|
*/
|
2015-08-22 17:42:02 +02:00
|
|
|
int if_get_egress(struct sockaddr *sa, struct rtnl_link **link);
|
2014-06-25 01:53:46 +00:00
|
|
|
|
2014-07-14 11:49:44 +00:00
|
|
|
/** Get all IRQs for this interface.
|
2014-06-05 09:35:40 +00:00
|
|
|
*
|
2014-06-25 01:53:46 +00:00
|
|
|
* Only MSI IRQs are determined by looking at:
|
|
|
|
* /sys/class/net/{ifname}/device/msi_irqs/
|
|
|
|
*
|
|
|
|
* @param i A pointer to the interface structure
|
2014-12-05 12:26:47 +01:00
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
2014-06-05 09:35:40 +00:00
|
|
|
*/
|
2015-08-22 17:42:02 +02:00
|
|
|
int if_get_irqs(struct interface *i);
|
2014-06-05 09:35:40 +00:00
|
|
|
|
|
|
|
/** Change the SMP affinity of NIC interrupts.
|
|
|
|
*
|
2014-06-25 01:53:46 +00:00
|
|
|
* @param i A pointer to the interface structure
|
2014-06-05 09:35:40 +00:00
|
|
|
* @param affinity A mask specifying which cores should handle this interrupt.
|
2014-12-05 12:26:47 +01:00
|
|
|
* @retval 0 Success. Everything went well.
|
|
|
|
* @retval <0 Error. Something went wrong.
|
2014-06-05 09:35:40 +00:00
|
|
|
*/
|
2017-03-03 20:20:13 -04:00
|
|
|
int if_set_affinity(struct interface *i, int affinity);
|
|
|
|
|
|
|
|
/** @} */
|