Control network channel using a gateway

Overview

Macros and functions for gateway configuration to be used in tests. More…

// typedefs

typedef struct tapi_route_gateway tapi_route_gateway;

// structs

struct tapi_route_gateway;

// global functions

te_errno tapi_add_dynamic_arp(const char* ta_src, const char* ifname_src, const char* ta_dest, const char* ifname_dest, const struct sockaddr* addr_dest, const struct sockaddr* link_addr_dest);
te_errno tapi_add_static_arp(const char* ta_src, const char* ifname_src, const char* ta_dest, const char* ifname_dest, const struct sockaddr* addr_dest, const struct sockaddr* link_addr_dest);
te_errno tapi_update_arp(const char* ta_src, const char* ifname_src, const char* ta_dest, const char* ifname_dest, const struct sockaddr* addr_dest, const void* link_addr_dest, te_bool is_static);
te_errno tapi_remove_arp(const char* ta, const char* if_name, const struct sockaddr* net_addr);
te_errno tapi_route_gateway_init(tapi_route_gateway* gw, const char* iut_ta, const char* tst_ta, const char* gw_ta, const struct if_nameindex* iut_if, const struct if_nameindex* tst_if, const struct if_nameindex* gw_iut_if, const struct if_nameindex* gw_tst_if, const struct sockaddr* iut_addr, const struct sockaddr* tst_addr, const struct sockaddr* gw_iut_addr, const struct sockaddr* gw_tst_addr, const struct sockaddr* alien_link_addr);
te_errno tapi_route_gateway_configure(tapi_route_gateway* gw);
te_errno tapi_route_gateway_set_forwarding(tapi_route_gateway* gw, te_bool enabled);
te_errno tapi_route_gateway_break_gw_iut(tapi_route_gateway* gw);
te_errno tapi_route_gateway_repair_gw_iut(tapi_route_gateway* gw);
te_errno tapi_route_gateway_break_gw_tst(tapi_route_gateway* gw);
te_errno tapi_route_gateway_repair_gw_tst(tapi_route_gateway* gw);
te_errno tapi_route_gateway_break_iut_gw(tapi_route_gateway* gw);
te_errno tapi_route_gateway_repair_iut_gw(tapi_route_gateway* gw);
te_errno tapi_route_gateway_break_tst_gw(tapi_route_gateway* gw);
te_errno tapi_route_gateway_repair_tst_gw(tapi_route_gateway* gw);
te_errno tapi_route_gateway_down_up_ifaces(tapi_route_gateway* gw);

// macros

#define TAPI_DECLARE_ROUTE_GATEWAY_PARAMS
#define TAPI_GET_ROUTE_GATEWAY_PARAMS
#define TAPI_INIT_ROUTE_GATEWAY(gw_)

Detailed Documentation

Macros and functions for gateway configuration to be used in tests. “Gateway” here is the third host which forwards packets between two testing hosts not connected directly. The header must be included from test sources only. It is allowed to use the macros only from main() function of the test.

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Typedefs

typedef struct tapi_route_gateway tapi_route_gateway

Structure describing gateway connecting IUT and Tester hosts.

Global Functions

te_errno tapi_add_dynamic_arp(const char* ta_src, const char* ifname_src, const char* ta_dest, const char* ifname_dest, const struct sockaddr* addr_dest, const struct sockaddr* link_addr_dest)

Add dynamic entry to neighbour table.

Netlink does not allow to make address resolution at a reasonable time if it does not know where to send the request. Therefore the dst MAC address is required.

Parameters:

ta_src

Source TA.

ifname_src

Source interface name.

ta_dest

Destination TA.

ifname_dest

Destination interface name.

addr_dest

Destination address.

link_addr_dest

New destination MAC or NULL. If NULL link address of ta_dest interface will be used.

Returns:

Status code.

te_errno tapi_add_static_arp(const char* ta_src, const char* ifname_src, const char* ta_dest, const char* ifname_dest, const struct sockaddr* addr_dest, const struct sockaddr* link_addr_dest)

Add static entry to neighbour table with fake or actual MAC address.

Parameters:

ta_src

Source TA.

ifname_src

Source interface name.

ta_dest

Destination TA.

ifname_dest

Destination interface name.

addr_dest

Destination address.

link_addr_dest

New destination MAC or NULL. If NULL link address of ta_dest interface will be used.

Returns:

Status code.

te_errno tapi_update_arp(const char* ta_src, const char* ifname_src, const char* ta_dest, const char* ifname_dest, const struct sockaddr* addr_dest, const void* link_addr_dest, te_bool is_static)

Update entry in the neighbour table.

Parameters:

ta_src

Source TA.

ifname_src

Source interface name.

ta_dest

Destination TA.

ifname_dest

Destination interface name.

addr_dest

Destination address.

link_addr_dest

New destination MAC or NULL.

is_static

If the new ARP row should be static.

Returns:

Status code.

See also:

tapi_add_static_arp, tapi_add_dynmaic_arp

te_errno tapi_remove_arp(const char* ta, const char* if_name, const struct sockaddr* net_addr)

Remove existing ARP table entry, wait for a while, check that it did not reappear automatically. If it did, try to remove it again a few times before giving up.

Parameters:

ta

Test Agent name.

if_name

Interface name.

net_addr

IP address.

Returns:

Status code.

te_errno tapi_route_gateway_init(tapi_route_gateway* gw, const char* iut_ta, const char* tst_ta, const char* gw_ta, const struct if_nameindex* iut_if, const struct if_nameindex* tst_if, const struct if_nameindex* gw_iut_if, const struct if_nameindex* gw_tst_if, const struct sockaddr* iut_addr, const struct sockaddr* tst_addr, const struct sockaddr* gw_iut_addr, const struct sockaddr* gw_tst_addr, const struct sockaddr* alien_link_addr)

Initialize gateway structure.

Parameters:

gw

Pointer to gateway structure.

iut_ta

TA on IUT.

tst_ta

TA on Tester.

gw_ta

TA on gateway.

iut_if

Network interface on IUT.

tst_if

Network interface on Tester.

gw_iut_if

Network interface on gateway connected to IUT.

gw_tst_if

Network interface on gateway connected to Tester.

iut_addr

Network address on IUT.

tst_addr

Network address on Tester.

gw_iut_addr

Network address on gw_iut_if.

gw_tst_addr

Network address on gw_tst_if.

alien_link_addr

Alien ethernet address.

Returns:

Status code.

te_errno tapi_route_gateway_configure(tapi_route_gateway* gw)

Configure connection via gateway.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_set_forwarding(tapi_route_gateway* gw, te_bool enabled)

Enable or disable IPv4 or IPv6 forwarding on gateway.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_break_gw_iut(tapi_route_gateway* gw)

Break connection from gateway to IUT.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_repair_gw_iut(tapi_route_gateway* gw)

Repair connection from gateway to IUT.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_break_gw_tst(tapi_route_gateway* gw)

Break connection from gateway to Tester.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_repair_gw_tst(tapi_route_gateway* gw)

Repair connection from gateway to Tester.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_break_iut_gw(tapi_route_gateway* gw)

Break connection from IUT to gateway.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_repair_iut_gw(tapi_route_gateway* gw)

Repair connection from IUT to gateway.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_break_tst_gw(tapi_route_gateway* gw)

Break connection from Tester to gateway.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_repair_tst_gw(tapi_route_gateway* gw)

Repair connection from Tester to gateway.

Parameters:

gw

Gateway description.

Returns:

Status code.

te_errno tapi_route_gateway_down_up_ifaces(tapi_route_gateway* gw)

Down up all interfaces that were in gateway connection.

Caller should take care about wait for the interfaces to be raised.

Parameters:

gw

Gateway description.

Returns:

Status code.

Macros

#define TAPI_DECLARE_ROUTE_GATEWAY_PARAMS

Declare test parameters related to gateway configuration.

#define TAPI_GET_ROUTE_GATEWAY_PARAMS

Get test parameters related to gateway configuration.

#define TAPI_INIT_ROUTE_GATEWAY(gw_)

Initialize gateway structure.

Parameters:

gw_

Gateway structure.