Lines Matching +full:static +full:- +full:address
1 /* main.c - Application main entry point */
7 * SPDX-License-Identifier: Apache-2.0
42 static struct in6_addr my_addr1 = { { { 0x20, 0x01, 0x0d, 0xb8, 1, 0, 0, 0,
44 static ZTEST_BMEM struct in_addr my_ipv4_addr1 = { { { 192, 0, 2, 1 } } };
47 static struct in6_addr my_addr2 = { { { 0x20, 0x01, 0x0d, 0xb8, 2, 0, 0, 0,
51 static struct in6_addr my_addr3 = { { { 0x20, 0x01, 0x0d, 0xb8, 3, 0, 0, 0,
54 /* Extra address is assigned to ll_addr */
55 static struct in6_addr ll_addr = { { { 0xfe, 0x80, 0x43, 0xb8, 0, 0, 0, 0,
59 static struct in_addr inaddr_mcast = { { { 224, 0, 0, 1 } } };
60 static struct in6_addr in6addr_mcast;
62 static struct net_if *iface1;
63 static struct net_if *iface2;
64 static struct net_if *iface3;
65 static struct net_if *iface4;
66 static struct net_if *eth_iface;
68 static bool test_failed;
69 static bool test_started;
70 static struct k_sem wait_data;
71 static bool device_ok;
81 static uint8_t *net_iface_get_mac(const struct device *dev) in net_iface_get_mac()
83 struct net_if_test *data = dev->data; in net_iface_get_mac()
85 if (data->mac_addr[2] == 0x00) { in net_iface_get_mac()
86 /* 00-00-5E-00-53-xx Documentation RFC 7042 */ in net_iface_get_mac()
87 data->mac_addr[0] = 0x00; in net_iface_get_mac()
88 data->mac_addr[1] = 0x00; in net_iface_get_mac()
89 data->mac_addr[2] = 0x5E; in net_iface_get_mac()
90 data->mac_addr[3] = 0x00; in net_iface_get_mac()
91 data->mac_addr[4] = 0x53; in net_iface_get_mac()
92 data->mac_addr[5] = sys_rand8_get(); in net_iface_get_mac()
95 data->ll_addr.addr = data->mac_addr; in net_iface_get_mac()
96 data->ll_addr.len = 6U; in net_iface_get_mac()
98 return data->mac_addr; in net_iface_get_mac()
101 static void net_iface_init(struct net_if *iface) in net_iface_init()
109 static int dev_init(const struct device *dev) in dev_init()
112 return -EAGAIN; in dev_init()
118 static int sender_iface(const struct device *dev, struct net_pkt *pkt) in sender_iface()
120 if (!pkt->buffer) { in sender_iface()
122 return -ENODATA; in sender_iface()
126 struct net_if_test *data = dev->data; in sender_iface()
132 if (net_if_get_by_iface(net_pkt_iface(pkt)) != data->idx) { in sender_iface()
134 data->idx, net_if_get_by_iface(net_pkt_iface(pkt))); in sender_iface()
148 static struct dummy_api net_iface_api = {
201 static struct eth_fake_context eth_fake_data;
203 static void eth_fake_iface_init(struct net_if *iface) in eth_fake_iface_init()
206 struct eth_fake_context *ctx = dev->data; in eth_fake_iface_init()
208 ctx->iface = iface; in eth_fake_iface_init()
210 net_if_set_link_addr(iface, ctx->mac_address, in eth_fake_iface_init()
211 sizeof(ctx->mac_address), in eth_fake_iface_init()
217 static int eth_fake_send(const struct device *dev, in eth_fake_send()
226 static enum ethernet_hw_caps eth_fake_get_capabilities(const struct device *dev) in eth_fake_get_capabilities()
231 static int eth_fake_set_config(const struct device *dev, in eth_fake_set_config()
235 struct eth_fake_context *ctx = dev->data; in eth_fake_set_config()
239 if (config->promisc_mode == ctx->promisc_mode) { in eth_fake_set_config()
240 return -EALREADY; in eth_fake_set_config()
243 ctx->promisc_mode = config->promisc_mode; in eth_fake_set_config()
248 return -EINVAL; in eth_fake_set_config()
254 static struct ethernet_api eth_fake_api_funcs = {
262 static int eth_fake_init(const struct device *dev) in eth_fake_init()
264 struct eth_fake_context *ctx = dev->data; in eth_fake_init()
266 ctx->promisc_mode = false; in eth_fake_init()
276 static const char *iface2str(struct net_if *iface) in iface2str()
290 static void iface_cb(struct net_if *iface, void *user_data) in iface_cb()
292 static int if_count; in iface_cb()
299 net_if_get_device(iface)->api; in iface_cb()
304 if (api->get_capabilities == in iface_cb()
326 static void *iface_setup(void) in iface_setup()
341 net_if_get_device(iface1)->data)->idx = idx; in iface_setup()
345 net_if_get_device(iface2)->data)->idx = idx; in iface_setup()
349 net_if_get_device(iface3)->data)->idx = idx; in iface_setup()
366 dev->name, dev); in iface_setup()
370 zassert_equal(ret, -ENXIO, "Interface 1 is up (%d)", ret); in iface_setup()
376 zassert_equal(iface1->if_dev->oper_state, NET_IF_OPER_DOWN, in iface_setup()
378 iface1->if_dev->oper_state); in iface_setup()
381 dev->state->init_res = 0; in iface_setup()
387 zassert_equal(iface1->if_dev->oper_state, NET_IF_OPER_DORMANT, in iface_setup()
389 iface1->if_dev->oper_state); in iface_setup()
392 zassert_equal(iface1->if_dev->oper_state, NET_IF_OPER_UP, in iface_setup()
394 iface1->if_dev->oper_state); in iface_setup()
399 DBG("Cannot add IPv6 address %s\n", in iface_setup()
407 DBG("Cannot add IPv4 address %s\n", in iface_setup()
413 ifaddr->addr_state = NET_ADDR_PREFERRED; in iface_setup()
418 DBG("Cannot add IPv6 address %s\n", in iface_setup()
423 ifaddr->addr_state = NET_ADDR_PREFERRED; in iface_setup()
428 DBG("Cannot add IPv6 address %s\n", in iface_setup()
433 ifaddr->addr_state = NET_ADDR_PREFERRED; in iface_setup()
438 DBG("Cannot add IPv6 address %s\n", in iface_setup()
443 ifaddr->addr_state = NET_ADDR_PREFERRED; in iface_setup()
447 DBG("Cannot add multicast IPv4 address %s\n", in iface_setup()
456 DBG("Cannot add multicast IPv6 address %s\n", in iface_setup()
477 static void iface_teardown(void *dummy) in iface_teardown()
491 static void test_iface_init(struct net_if *iface, bool carrier, bool dormant) in test_iface_init()
512 /* Carrier OFF, Dormant OFF - interface should remain down */ in ZTEST()
518 /* Carrier ON transition - interface should go up */ in ZTEST()
524 /* Carrier ON, Dormant ON - interface should remain down */ in ZTEST()
530 /* Dormant OFF transition - interface should go up */ in ZTEST()
536 /* Carrier ON, Dormant OFF - interface should go up right away */ in ZTEST()
542 /* Carrier OFF transition - interface should go down */ in ZTEST()
548 /* Carrier ON, Dormant OFF - interface should go up right away */ in ZTEST()
554 /* Dormant ON transition - interface should go down */ in ZTEST()
560 /* Carrier ON, Dormant OFF - interface should go up right away */ in ZTEST()
566 /* Admin down transition - interface should go down */ in ZTEST()
577 static bool send_iface(struct net_if *iface, int val, bool expect_fail) in send_iface()
579 static uint8_t data[] = { 't', 'e', 's', 't', '\0' }; in send_iface()
640 static void send_iface1_down(void) in send_iface1_down()
653 static void send_iface1_up(void) in send_iface1_up()
710 ifaddr->addr_state = NET_ADDR_TENTATIVE; in ZTEST()
735 static void check_promisc_mode_off(void) in check_promisc_mode_off()
746 static void check_promisc_mode_on(void) in check_promisc_mode_on()
757 static void set_promisc_mode_on_again(void) in set_promisc_mode_on_again()
765 zassert_equal(ret, -EALREADY, "iface 1 promiscuous mode OFF"); in set_promisc_mode_on_again()
768 static void set_promisc_mode_on(void) in set_promisc_mode_on()
779 static void set_promisc_mode_off(void) in set_promisc_mode_off()
796 static struct in_addr my_ipv4_addr_test = { { { 10, 0, 0, 1 } } };
797 static struct in_addr my_ipv4_addr_not_found = { { { 1, 2, 3, 4 } } };
799 static void v4_addr_add(void) in v4_addr_add()
805 zassert_true(ret, "Cannot add IPv4 address"); in v4_addr_add()
808 static void v4_addr_lookup(void) in v4_addr_lookup()
813 zassert_equal(ret, 1, "IPv4 address not found"); in v4_addr_lookup()
816 zassert_not_equal(ret, 1, "IPv4 address found"); in v4_addr_lookup()
819 static void v4_addr_rm(void) in v4_addr_rm()
824 zassert_true(ret, "Cannot remove IPv4 address"); in v4_addr_rm()
837 static void v4_addr_add_user(void *p1, void *p2, void *p3) in v4_addr_add_user()
847 zassert_true(ret, "Could not add IPv4 address"); in v4_addr_add_user()
850 static void v4_addr_add_user_from_userspace(void) in v4_addr_add_user_from_userspace()
857 static void v4_addr_lookup_user(void) in v4_addr_lookup_user()
864 zassert_equal(ret, 1, "IPv4 address not found (%d)", ret); in v4_addr_lookup_user()
867 zassert_equal(ret, 0, "IPv4 address found"); in v4_addr_lookup_user()
870 static void v4_addr_rm_user(void *p1, void *p2, void *p3) in v4_addr_rm_user()
880 zassert_true(ret, "Cannot remove IPv4 address"); in v4_addr_rm_user()
883 static void v4_addr_rm_user_from_userspace(void) in v4_addr_rm_user_from_userspace()
897 static
901 static
905 static void v6_addr_add(void) in v6_addr_add()
911 zassert_true(ret, "Cannot add IPv6 address"); in v6_addr_add()
914 static void v6_addr_add_mcast_twice(void) in v6_addr_add_mcast_twice()
919 zassert_equal(maddr, NULL, "Address was added twice"); in v6_addr_add_mcast_twice()
922 static void v6_addr_lookup(void) in v6_addr_lookup()
927 zassert_equal(ret, 1, "IPv6 address not found"); in v6_addr_lookup()
930 zassert_not_equal(ret, 1, "IPv6 address found"); in v6_addr_lookup()
933 static void v6_addr_rm(void) in v6_addr_rm()
938 zassert_true(ret, "Cannot remove IPv6 address"); in v6_addr_rm()
961 /* Add a link-local address based on the interface identifier */ in ZTEST()
965 zassert_not_null(ifaddr, "Cannot add IPv6 link-local address"); in ZTEST()
967 /* Add the corresponding solicited-node multicast address */ in ZTEST()
970 zassert_not_null(maddr, "Cannot add solicited-node multicast address"); in ZTEST()
972 /* Add an autoconfigured global unicast address */ in ZTEST()
977 zassert_not_null(ifaddr, "Cannot add IPv6 global unicast address"); in ZTEST()
979 /* Add the corresponding solicited-node multicast address (should exist) */ in ZTEST()
984 zassert_is_null(maddr, "Solicited-node multicast address was added twice"); in ZTEST()
986 /* Remove the global unicast address */ in ZTEST()
988 zassert_true(ret, "Cannot remove IPv6 global unicast address"); in ZTEST()
990 /* The solicited-node multicast address should stay */ in ZTEST()
992 zassert_not_null(maddr, "Solicited-node multicast address was removed"); in ZTEST()
994 /* Remove the link-local address */ in ZTEST()
996 zassert_true(ret, "Cannot remove IPv6 link-local address"); in ZTEST()
998 /* The solicited-node multicast address should be gone */ in ZTEST()
1000 zassert_is_null(maddr, "Solicited-node multicast address was not removed"); in ZTEST()
1009 static void v6_addr_add_user(void *p1, void *p2, void *p3) in v6_addr_add_user()
1019 zassert_true(ret, "Could not add IPv6 address"); in v6_addr_add_user()
1022 static void v6_addr_add_user_from_userspace(void) in v6_addr_add_user_from_userspace()
1029 static void v6_addr_lookup_user(void) in v6_addr_lookup_user()
1036 zassert_equal(ret, 1, "IPv6 address not found (%d)", ret); in v6_addr_lookup_user()
1039 zassert_equal(ret, 0, "IPv6 address found"); in v6_addr_lookup_user()
1042 static void v6_addr_rm_user(void *p1, void *p2, void *p3) in v6_addr_rm_user()
1055 zassert_true(ret, "Cannot remove IPv6 address"); in v6_addr_rm_user()
1058 static void v6_addr_rm_user_from_userspace(void) in v6_addr_rm_user_from_userspace()
1072 static void netmask_addr_add(void *p1, void *p2, void *p3) in netmask_addr_add()
1090 static void netmask_addr_add_from_userspace(void) in netmask_addr_add_from_userspace()
1102 static void gw_addr_add(void *p1, void *p2, void *p3) in gw_addr_add()
1120 static void gw_addr_add_from_userspace(void) in gw_addr_add_from_userspace()
1132 static void get_by_index(void *p1, void *p2, void *p3) in get_by_index()
1147 static void get_by_index_from_userspace(void) in get_by_index_from_userspace()
1159 static void foreach_ipv4_addr_check(struct net_if *iface, in foreach_ipv4_addr_check()
1168 zassert_mem_equal(&if_addr->address.in_addr, &my_ipv4_addr1, in foreach_ipv4_addr_check()
1169 sizeof(struct in_addr), "Wrong IPv4 address"); in foreach_ipv4_addr_check()
1176 /* iface1 has one IPv4 address configured */ in ZTEST()
1182 /* iface4 has no IPv4 address configured */ in ZTEST()
1187 static void foreach_ipv4_maddr_check(struct net_if *iface, in foreach_ipv4_maddr_check()
1196 zassert_mem_equal(&if_addr->address.in_addr, &inaddr_mcast, in foreach_ipv4_maddr_check()
1197 sizeof(struct in_addr), "Wrong IPv4 multicast address"); in foreach_ipv4_maddr_check()
1204 /* iface1 has one IPv4 multicast address configured */ in ZTEST()
1210 /* iface4 has no IPv4 multicast address configured */ in ZTEST()
1215 static void foreach_ipv6_addr_check(struct net_if *iface, in foreach_ipv6_addr_check()
1225 if (net_ipv6_is_ll_addr(&if_addr->address.in6_addr)) { in foreach_ipv6_addr_check()
1226 zassert_mem_equal(&if_addr->address.in6_addr, &ll_addr, in foreach_ipv6_addr_check()
1227 sizeof(struct in6_addr), "Wrong IPv6 address"); in foreach_ipv6_addr_check()
1229 zassert_mem_equal(&if_addr->address.in6_addr, &my_addr1, in foreach_ipv6_addr_check()
1230 sizeof(struct in6_addr), "Wrong IPv6 address"); in foreach_ipv6_addr_check()
1244 /* iface4 has no IPv6 address configured */ in ZTEST()
1249 static void foreach_ipv6_maddr_check(struct net_if *iface, in foreach_ipv6_maddr_check()
1258 zassert_mem_equal(&if_addr->address.in6_addr, &in6addr_mcast, sizeof(struct in6_addr), in foreach_ipv6_maddr_check()
1259 "Wrong IPv6 multicast address"); in foreach_ipv6_maddr_check()
1266 /* iface1 has one IPv6 multicast address configured */ in ZTEST()
1272 /* iface4 has no IPv6 multicast address configured */ in ZTEST()
1289 ret = net_if_get_name(NULL, NULL, -1); in ZTEST()
1290 zassert_equal(ret, -EINVAL, "Unexpected value returned"); in ZTEST()
1292 ret = net_if_get_name(iface, NULL, -1); in ZTEST()
1293 zassert_equal(ret, -EINVAL, "Unexpected value returned"); in ZTEST()
1296 zassert_equal(ret, -EINVAL, "Unexpected value returned"); in ZTEST()
1300 zassert_equal(ret, -ENAMETOOLONG, "Unexpected value (%d) returned", ret); in ZTEST()
1308 zassert_equal(ret, -EALREADY, "Unexpected value (%d) returned", ret); in ZTEST()
1317 zassert_equal(ret, -ERANGE, "Unexpected value (%d) returned", ret); in ZTEST()
1319 ret = net_if_get_name(iface, buf, strlen(name) - 1); in ZTEST()
1320 zassert_equal(ret, -ERANGE, "Unexpected value (%d) returned", ret); in ZTEST()
1322 ret = net_if_get_name(iface, buf, sizeof(buf) - 1); in ZTEST()
1330 zassert_equal(ret, -ENOENT, "Unexpected value (%d) returned", ret); in ZTEST()
1332 ret = net_if_get_name(NULL, NULL, -1); in ZTEST()
1333 zassert_equal(ret, -ENOTSUP, "Invalid value returned"); in ZTEST()
1337 static void generate_iid(struct net_if *iface, in generate_iid()
1350 mac = lladdr->addr; in generate_iid()
1353 memcpy(&expected_addr->s6_addr[8], &mac[0], 3); in generate_iid()
1354 expected_addr->s6_addr[11] = 0xff; in generate_iid()
1355 expected_addr->s6_addr[12] = 0xfe; in generate_iid()
1356 memcpy(&expected_addr->s6_addr[13], &mac[3], 3); in generate_iid()
1358 expected_addr->s6_addr[8] ^= 0x02; /* Universal bit toggle */ in generate_iid()
1387 /* Make sure that EUI-64 bytes are not there */ in ZTEST()
1392 "IID is EUI-64 instead of randomized"); in ZTEST()