1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
150
151
152
153
154
155
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
186
187
188
189
190
191
192
193
194
195
196
197
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
228
229
230
231
232
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
294
295
296
297
298
299
300
301
302
305
308
309
310
311
312
313
314
315
316
317
318
319
320
322
323
324
325
326
327
328
329
330
331
332
333
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
374
375
378
379
380
381
382
383
384
385
386
405
410
411
412
413
414
415
416
417
418
423
424
425
426
427
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
510
511
512
513
520
521
522
523
524
525
526
527
528
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
565
566
567
568
569
570
571
572
573
576
577
584
585
586
587
588
589
590
591
592
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
626
627
628
629
630
631
632
633
634
637
638
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
668
669
671
672
673
674
675
676
677
678
681
684
687
688
689
699
705
711
720
721
722
727
728
729
730
736
737
738
739
740
741
742
743
744
745
748
749
750
751
752
762
763
764
765
774
775
779
780
781
782
783
787
788
805
806
807
811
812
813
814
821
822
823
824
825
826
833
834
835
836
837
838
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
863
864
865
866
867
868
869
870
871
872
874
875
876
877
878
879
880
884
885
886
887
888
889
894
895
896
901
902
903
904
905
912
913
914
918
919
920
921
922
923
924
925
926
927
932
933
934
935
936
937
938
942
943
944
945
946
947
948
949
950
951
952
966
967
968
982
983
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1017
1018
1019
1020
1021
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1087
1088
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1135
1136
1137
1140
1141
1142
1147
1148
1149
1150
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1166
1167
1168
1169
1170
1171
1188
1189
1190
1191
1197
1198
1199
1200
1202
1203
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1234
1235
1236
1237
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1258
1259
1260
1261
1262
1263
1264
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1358
1359
1360
1361
1362
1366
1367
1368
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1413
1414
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1478
1479
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1548
1549
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1582
1583
1584
1585
1586
1587
1588
1589
1592
1593
1594
1595
1596
1599
1600
1601
1602
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1666
1667
1668
1669
1675
1676
1677
1678
1679
1680
1681
1682
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1711
1712
1713
1714
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1750
1751
1752
1753
1754
1755
1756
1757
1758
1761
1762
1775
1776
1777
1783
1784
1785
1786
1787
1788
1789
1790
1794
1795
/* ... */
/* ... */
#include "lwip/opt.h"
#include <string.h>
#include <stdlib.h>
#include "lwip/def.h"
#include "lwip/ip_addr.h"
#include "lwip/ip6_addr.h"
#include "lwip/netif.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/udp.h"
#include "lwip/priv/raw_priv.h"
#include "lwip/snmp.h"
#include "lwip/igmp.h"
#include "lwip/etharp.h"
#include "lwip/stats.h"
#include "lwip/sys.h"
#include "lwip/ip.h"
16 includes#if ENABLE_LOOPBACK
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
#include "lwip/tcpip.h"
#endif /* ... */
#endif
#include "netif/ethernet.h"
#if LWIP_AUTOIP
#include "lwip/autoip.h"
#endif
#if LWIP_DHCP
#include "lwip/dhcp.h"
#endif
#if LWIP_IPV6_DHCP6
#include "lwip/dhcp6.h"
#endif
#if LWIP_IPV6_MLD
#include "lwip/mld6.h"
#endif
#if LWIP_IPV6
#include "lwip/nd6.h"
#endif
#if LWIP_NETIF_STATUS_CALLBACK
#define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)
#else
#define NETIF_STATUS_CALLBACK(n)
#endif
#if LWIP_NETIF_LINK_CALLBACK
#define NETIF_LINK_CALLBACK(n) do{ if (n->link_callback) { (n->link_callback)(n); }}while(0)
#else
#define NETIF_LINK_CALLBACK(n)
#endif
#if LWIP_NETIF_EXT_STATUS_CALLBACK
static netif_ext_callback_t *ext_callback;
#endif
#if !LWIP_SINGLE_NETIF
struct netif *netif_list;
#endif
struct netif *netif_default;
#define netif_index_to_num(index) ((index) - 1)
static u8_t netif_num;
#if LWIP_NUM_NETIF_CLIENT_DATA > 0
static u8_t netif_client_id;
#endif
#define NETIF_REPORT_TYPE_IPV4 0x01
#define NETIF_REPORT_TYPE_IPV6 0x02
static void netif_issue_reports(struct netif *netif, u8_t report_type);
#if LWIP_IPV6
static err_t netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr);
#endif
#if LWIP_IPV4
static err_t netif_null_output_ip4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr);
#endif
#if LWIP_HAVE_LOOPIF
#if LWIP_IPV4
static err_t netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t *addr);
#endif
#if LWIP_IPV6
static err_t netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t *addr);
#endif
static struct netif loop_netif;
/* ... */
static err_t
netif_loopif_init(struct netif *netif)
{
LWIP_ASSERT("netif_loopif_init: invalid netif", netif != NULL);
/* ... */
MIB2_INIT_NETIF(netif, snmp_ifType_softwareLoopback, 0);
netif->name[0] = 'l';
netif->name[1] = 'o';
#if LWIP_IPV4
netif->output = netif_loop_output_ipv4;
#endif
#if LWIP_IPV6
netif->output_ip6 = netif_loop_output_ipv6;
#endif
#if LWIP_LOOPIF_MULTICAST
netif_set_flags(netif, NETIF_FLAG_IGMP);
#endif
NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_DISABLE_ALL);
return ERR_OK;
}netif_loopif_init (struct netif *netif) { ... }
/* ... */#endif
void
netif_init(void)
{
#if LWIP_HAVE_LOOPIF
#if LWIP_IPV4
#define LOOPIF_ADDRINIT &loop_ipaddr, &loop_netmask, &loop_gw,
ip4_addr_t loop_ipaddr, loop_netmask, loop_gw;
IP4_ADDR(&loop_gw, 127, 0, 0, 1);
IP4_ADDR(&loop_ipaddr, 127, 0, 0, 1);
IP4_ADDR(&loop_netmask, 255, 0, 0, 0);/* ... */
#else
#define LOOPIF_ADDRINIT
#endif
#if NO_SYS
netif_add(&loop_netif, LOOPIF_ADDRINIT NULL, netif_loopif_init, ip_input);
#else
netif_add(&loop_netif, LOOPIF_ADDRINIT NULL, netif_loopif_init, tcpip_input);
#endif
#if LWIP_IPV6
IP_ADDR6_HOST(loop_netif.ip6_addr, 0, 0, 0, 0x00000001UL);
loop_netif.ip6_addr_state[0] = IP6_ADDR_VALID;/* ... */
#endif
netif_set_link_up(&loop_netif);
netif_set_up(&loop_netif);
/* ... */
#endif
}{ ... }
/* ... */
err_t
netif_input(struct pbuf *p, struct netif *inp)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_input: invalid pbuf", p != NULL);
LWIP_ASSERT("netif_input: invalid netif", inp != NULL);
#if LWIP_ETHERNET
if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) {
return ethernet_input(p, inp);
}if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) { ... } else/* ... */
#endif
return ip_input(p, inp);
}{ ... }
/* ... */
struct netif *
netif_add_noaddr(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
{
return netif_add(netif,
#if LWIP_IPV4
NULL, NULL, NULL,
#endif
state, init, input);
}{ ... }
/* ... */
struct netif *
netif_add(struct netif *netif,
#if LWIP_IPV4
const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw,
#endif
void *state, netif_init_fn init, netif_input_fn input)
{
#if LWIP_IPV6
s8_t i;
#endif
LWIP_ASSERT_CORE_LOCKED();
#if LWIP_SINGLE_NETIF
if (netif_default != NULL) {
LWIP_ASSERT("single netif already set", 0);
return NULL;
}if (netif_default != NULL) { ... }
/* ... */#endif
LWIP_ERROR("netif_add: invalid netif", netif != NULL, return NULL);
LWIP_ERROR("netif_add: No init function given", init != NULL, return NULL);
#if LWIP_IPV4
if (ipaddr == NULL) {
ipaddr = ip_2_ip4(IP4_ADDR_ANY);
}if (ipaddr == NULL) { ... }
if (netmask == NULL) {
netmask = ip_2_ip4(IP4_ADDR_ANY);
}if (netmask == NULL) { ... }
if (gw == NULL) {
gw = ip_2_ip4(IP4_ADDR_ANY);
}if (gw == NULL) { ... }
ip_addr_set_zero_ip4(&netif->ip_addr);
ip_addr_set_zero_ip4(&netif->netmask);
ip_addr_set_zero_ip4(&netif->gw);
netif->output = netif_null_output_ip4;/* ... */
#endif
#if LWIP_IPV6
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
ip_addr_set_zero_ip6(&netif->ip6_addr[i]);
netif->ip6_addr_state[i] = IP6_ADDR_INVALID;
#if LWIP_IPV6_ADDRESS_LIFETIMES
netif->ip6_addr_valid_life[i] = IP6_ADDR_LIFE_STATIC;
netif->ip6_addr_pref_life[i] = IP6_ADDR_LIFE_STATIC;/* ... */
#endif
}for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { ... }
netif->output_ip6 = netif_null_output_ip6;/* ... */
#endif
NETIF_SET_CHECKSUM_CTRL(netif, NETIF_CHECKSUM_ENABLE_ALL);
netif->mtu = 0;
netif->flags = 0;
#ifdef netif_get_client_data
memset(netif->client_data, 0, sizeof(netif->client_data));
#endif
#if LWIP_IPV6
#if LWIP_IPV6_AUTOCONFIG
netif->ip6_autoconfig_enabled = 0;/* ... */
#endif
nd6_restart_netif(netif);/* ... */
#endif
#if LWIP_NETIF_STATUS_CALLBACK
netif->status_callback = NULL;
#endif
#if LWIP_NETIF_LINK_CALLBACK
netif->link_callback = NULL;
#endif
#if LWIP_IGMP
netif->igmp_mac_filter = NULL;
#endif
#if LWIP_IPV6 && LWIP_IPV6_MLD
netif->mld_mac_filter = NULL;
#endif
#if ENABLE_LOOPBACK
netif->loop_first = NULL;
netif->loop_last = NULL;/* ... */
#endif
netif->state = state;
netif->num = netif_num;
netif->input = input;
NETIF_RESET_HINTS(netif);
#if ENABLE_LOOPBACK && LWIP_LOOPBACK_MAX_PBUFS
netif->loop_cnt_current = 0;
#endif
#if LWIP_IPV4
netif_set_addr(netif, ipaddr, netmask, gw);
#endif
if (init(netif) != ERR_OK) {
return NULL;
}if (init(netif) != ERR_OK) { ... }
#if LWIP_IPV6 && LWIP_ND6_ALLOW_RA_UPDATES
/* ... */
netif->mtu6 = netif->mtu;/* ... */
#endif
#if !LWIP_SINGLE_NETIF
/* ... */
{
struct netif *netif2;
int num_netifs;
do {
if (netif->num == 255) {
netif->num = 0;
}if (netif->num == 255) { ... }
num_netifs = 0;
for (netif2 = netif_list; netif2 != NULL; netif2 = netif2->next) {
LWIP_ASSERT("netif already added", netif2 != netif);
num_netifs++;
LWIP_ASSERT("too many netifs, max. supported number is 255", num_netifs <= 255);
if (netif2->num == netif->num) {
netif->num++;
break;
}if (netif2->num == netif->num) { ... }
}for (netif2 = netif_list; netif2 != NULL; netif2 = netif2->next) { ... }
...} while (netif2 != NULL);
...}
if (netif->num == 254) {
netif_num = 0;
}if (netif->num == 254) { ... } else {
netif_num = (u8_t)(netif->num + 1);
}else { ... }
netif->next = netif_list;
netif_list = netif;/* ... */
#endif
mib2_netif_added(netif);
#if LWIP_IGMP
if (netif->flags & NETIF_FLAG_IGMP) {
igmp_start(netif);
}if (netif->flags & NETIF_FLAG_IGMP) { ... }
/* ... */#endif
LWIP_DEBUGF(NETIF_DEBUG, ("netif: added interface %c%c IP",
netif->name[0], netif->name[1]));
#if LWIP_IPV4
LWIP_DEBUGF(NETIF_DEBUG, (" addr "));
ip4_addr_debug_print(NETIF_DEBUG, ipaddr);
LWIP_DEBUGF(NETIF_DEBUG, (" netmask "));
ip4_addr_debug_print(NETIF_DEBUG, netmask);
LWIP_DEBUGF(NETIF_DEBUG, (" gw "));
ip4_addr_debug_print(NETIF_DEBUG, gw);/* ... */
#endif
LWIP_DEBUGF(NETIF_DEBUG, ("\n"));
netif_invoke_ext_callback(netif, LWIP_NSC_NETIF_ADDED, NULL);
return netif;
}{ ... }
static void
netif_do_ip_addr_changed(const ip_addr_t *old_addr, const ip_addr_t *new_addr)
{
#if LWIP_TCP
tcp_netif_ip_addr_changed(old_addr, new_addr);
#endif
#if LWIP_UDP
udp_netif_ip_addr_changed(old_addr, new_addr);
#endif
#if LWIP_RAW
raw_netif_ip_addr_changed(old_addr, new_addr);
#endif
}{ ... }
#if LWIP_IPV4
static int
netif_do_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr, ip_addr_t *old_addr)
{
LWIP_ASSERT("invalid pointer", ipaddr != NULL);
LWIP_ASSERT("invalid pointer", old_addr != NULL);
if (ip4_addr_cmp(ipaddr, netif_ip4_addr(netif)) == 0) {
ip_addr_t new_addr;
*ip_2_ip4(&new_addr) = *ipaddr;
IP_SET_TYPE_VAL(new_addr, IPADDR_TYPE_V4);
ip_addr_copy(*old_addr, *netif_ip_addr4(netif));
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: netif address being changed\n"));
netif_do_ip_addr_changed(old_addr, &new_addr);
mib2_remove_ip4(netif);
mib2_remove_route_ip4(0, netif);
ip4_addr_set(ip_2_ip4(&netif->ip_addr), ipaddr);
IP_SET_TYPE_VAL(netif->ip_addr, IPADDR_TYPE_V4);
mib2_add_ip4(netif);
mib2_add_route_ip4(0, netif);
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4);
NETIF_STATUS_CALLBACK(netif);
return 1;
}if (ip4_addr_cmp(ipaddr, netif_ip4_addr(netif)) == 0) { ... }
return 0;
}{ ... }
/* ... */
void
netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr)
{
ip_addr_t old_addr;
LWIP_ERROR("netif_set_ipaddr: invalid netif", netif != NULL, return);
if (ipaddr == NULL) {
ipaddr = IP4_ADDR_ANY4;
}if (ipaddr == NULL) { ... }
LWIP_ASSERT_CORE_LOCKED();
if (netif_do_set_ipaddr(netif, ipaddr, &old_addr)) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
netif_ext_callback_args_t args;
args.ipv4_changed.old_address = &old_addr;
netif_invoke_ext_callback(netif, LWIP_NSC_IPV4_ADDRESS_CHANGED, &args);/* ... */
#endif
}if (netif_do_set_ipaddr(netif, ipaddr, &old_addr)) { ... }
}{ ... }
static int
netif_do_set_netmask(struct netif *netif, const ip4_addr_t *netmask, ip_addr_t *old_nm)
{
if (ip4_addr_cmp(netmask, netif_ip4_netmask(netif)) == 0) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
LWIP_ASSERT("invalid pointer", old_nm != NULL);
ip_addr_copy(*old_nm, *netif_ip_netmask4(netif));/* ... */
#else
LWIP_UNUSED_ARG(old_nm);
#endif
mib2_remove_route_ip4(0, netif);
ip4_addr_set(ip_2_ip4(&netif->netmask), netmask);
IP_SET_TYPE_VAL(netif->netmask, IPADDR_TYPE_V4);
mib2_add_route_ip4(0, netif);
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: netmask of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1],
ip4_addr1_16(netif_ip4_netmask(netif)),
ip4_addr2_16(netif_ip4_netmask(netif)),
ip4_addr3_16(netif_ip4_netmask(netif)),
ip4_addr4_16(netif_ip4_netmask(netif))));
return 1;
}if (ip4_addr_cmp(netmask, netif_ip4_netmask(netif)) == 0) { ... }
return 0;
}{ ... }
/* ... */
void
netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask)
{
#if LWIP_NETIF_EXT_STATUS_CALLBACK
ip_addr_t old_nm_val;
ip_addr_t *old_nm = &old_nm_val;/* ... */
#else
ip_addr_t *old_nm = NULL;
#endif
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_netmask: invalid netif", netif != NULL, return);
if (netmask == NULL) {
netmask = IP4_ADDR_ANY4;
}if (netmask == NULL) { ... }
if (netif_do_set_netmask(netif, netmask, old_nm)) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
netif_ext_callback_args_t args;
args.ipv4_changed.old_netmask = old_nm;
netif_invoke_ext_callback(netif, LWIP_NSC_IPV4_NETMASK_CHANGED, &args);/* ... */
#endif
}if (netif_do_set_netmask(netif, netmask, old_nm)) { ... }
}{ ... }
static int
netif_do_set_gw(struct netif *netif, const ip4_addr_t *gw, ip_addr_t *old_gw)
{
if (ip4_addr_cmp(gw, netif_ip4_gw(netif)) == 0) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
LWIP_ASSERT("invalid pointer", old_gw != NULL);
ip_addr_copy(*old_gw, *netif_ip_gw4(netif));/* ... */
#else
LWIP_UNUSED_ARG(old_gw);
#endif
ip4_addr_set(ip_2_ip4(&netif->gw), gw);
IP_SET_TYPE_VAL(netif->gw, IPADDR_TYPE_V4);
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n",
netif->name[0], netif->name[1],
ip4_addr1_16(netif_ip4_gw(netif)),
ip4_addr2_16(netif_ip4_gw(netif)),
ip4_addr3_16(netif_ip4_gw(netif)),
ip4_addr4_16(netif_ip4_gw(netif))));
return 1;
}if (ip4_addr_cmp(gw, netif_ip4_gw(netif)) == 0) { ... }
return 0;
}{ ... }
/* ... */
void
netif_set_gw(struct netif *netif, const ip4_addr_t *gw)
{
#if LWIP_NETIF_EXT_STATUS_CALLBACK
ip_addr_t old_gw_val;
ip_addr_t *old_gw = &old_gw_val;/* ... */
#else
ip_addr_t *old_gw = NULL;
#endif
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_gw: invalid netif", netif != NULL, return);
if (gw == NULL) {
gw = IP4_ADDR_ANY4;
}if (gw == NULL) { ... }
if (netif_do_set_gw(netif, gw, old_gw)) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
netif_ext_callback_args_t args;
args.ipv4_changed.old_gw = old_gw;
netif_invoke_ext_callback(netif, LWIP_NSC_IPV4_GATEWAY_CHANGED, &args);/* ... */
#endif
}if (netif_do_set_gw(netif, gw, old_gw)) { ... }
}{ ... }
/* ... */
void
netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask,
const ip4_addr_t *gw)
{
#if LWIP_NETIF_EXT_STATUS_CALLBACK
netif_nsc_reason_t change_reason = LWIP_NSC_NONE;
netif_ext_callback_args_t cb_args;
ip_addr_t old_nm_val;
ip_addr_t old_gw_val;
ip_addr_t *old_nm = &old_nm_val;
ip_addr_t *old_gw = &old_gw_val;/* ... */
#else
ip_addr_t *old_nm = NULL;
ip_addr_t *old_gw = NULL;/* ... */
#endif
ip_addr_t old_addr;
int remove;
LWIP_ASSERT_CORE_LOCKED();
if (ipaddr == NULL) {
ipaddr = IP4_ADDR_ANY4;
}if (ipaddr == NULL) { ... }
if (netmask == NULL) {
netmask = IP4_ADDR_ANY4;
}if (netmask == NULL) { ... }
if (gw == NULL) {
gw = IP4_ADDR_ANY4;
}if (gw == NULL) { ... }
remove = ip4_addr_isany(ipaddr);
if (remove) {
/* ... */
if (netif_do_set_ipaddr(netif, ipaddr, &old_addr)) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
change_reason |= LWIP_NSC_IPV4_ADDRESS_CHANGED;
cb_args.ipv4_changed.old_address = &old_addr;/* ... */
#endif
}if (netif_do_set_ipaddr(netif, ipaddr, &old_addr)) { ... }
}if (remove) { ... }
if (netif_do_set_netmask(netif, netmask, old_nm)) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
change_reason |= LWIP_NSC_IPV4_NETMASK_CHANGED;
cb_args.ipv4_changed.old_netmask = old_nm;/* ... */
#endif
}if (netif_do_set_netmask(netif, netmask, old_nm)) { ... }
if (netif_do_set_gw(netif, gw, old_gw)) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
change_reason |= LWIP_NSC_IPV4_GATEWAY_CHANGED;
cb_args.ipv4_changed.old_gw = old_gw;/* ... */
#endif
}if (netif_do_set_gw(netif, gw, old_gw)) { ... }
if (!remove) {
if (netif_do_set_ipaddr(netif, ipaddr, &old_addr)) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
change_reason |= LWIP_NSC_IPV4_ADDRESS_CHANGED;
cb_args.ipv4_changed.old_address = &old_addr;/* ... */
#endif
}if (netif_do_set_ipaddr(netif, ipaddr, &old_addr)) { ... }
}if (!remove) { ... }
#if LWIP_NETIF_EXT_STATUS_CALLBACK
if (change_reason != LWIP_NSC_NONE) {
change_reason |= LWIP_NSC_IPV4_SETTINGS_CHANGED;
netif_invoke_ext_callback(netif, change_reason, &cb_args);
}if (change_reason != LWIP_NSC_NONE) { ... }
/* ... */#endif
}{ ... }
#endif/* ... */
/* ... */
void
netif_remove(struct netif *netif)
{
#if LWIP_IPV6
int i;
#endif
LWIP_ASSERT_CORE_LOCKED();
if (netif == NULL) {
return;
}if (netif == NULL) { ... }
netif_invoke_ext_callback(netif, LWIP_NSC_NETIF_REMOVED, NULL);
#if LWIP_IPV4
if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
netif_do_ip_addr_changed(netif_ip_addr4(netif), NULL);
}if (!ip4_addr_isany_val(*netif_ip4_addr(netif))) { ... }
#if LWIP_IGMP
if (netif->flags & NETIF_FLAG_IGMP) {
igmp_stop(netif);
}if (netif->flags & NETIF_FLAG_IGMP) { ... }
/* ... */#endif /* ... */
#endif
#if LWIP_IPV6
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) {
netif_do_ip_addr_changed(netif_ip_addr6(netif, i), NULL);
}if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i))) { ... }
}for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { ... }
#if LWIP_IPV6_MLD
mld6_stop(netif);/* ... */
#endif /* ... */
#endif
if (netif_is_up(netif)) {
netif_set_down(netif);
}if (netif_is_up(netif)) { ... }
mib2_remove_ip4(netif);
if (netif_default == netif) {
netif_set_default(NULL);
}if (netif_default == netif) { ... }
#if !LWIP_SINGLE_NETIF
if (netif_list == netif) {
netif_list = netif->next;
}if (netif_list == netif) { ... } else {
struct netif *tmp_netif;
NETIF_FOREACH(tmp_netif) {
if (tmp_netif->next == netif) {
tmp_netif->next = netif->next;
break;
}if (tmp_netif->next == netif) { ... }
}NETIF_FOREACH (tmp_netif) { ... }
if (tmp_netif == NULL) {
return;
}if (tmp_netif == NULL) { ... }
}else { ... }
/* ... */#endif
mib2_netif_removed(netif);
#if LWIP_NETIF_REMOVE_CALLBACK
if (netif->remove_callback) {
netif->remove_callback(netif);
}if (netif->remove_callback) { ... }
/* ... */#endif
LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") );
}{ ... }
/* ... */
void
netif_set_default(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
if (netif == NULL) {
mib2_remove_route_ip4(1, netif);
}if (netif == NULL) { ... } else {
mib2_add_route_ip4(1, netif);
}else { ... }
netif_default = netif;
LWIP_DEBUGF(NETIF_DEBUG, ("netif: setting default interface %c%c\n",
netif ? netif->name[0] : '\'', netif ? netif->name[1] : '\''));
}{ ... }
/* ... */
void
netif_set_up(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_up: invalid netif", netif != NULL, return);
if (!(netif->flags & NETIF_FLAG_UP)) {
netif_set_flags(netif, NETIF_FLAG_UP);
MIB2_COPY_SYSUPTIME_TO(&netif->ts);
NETIF_STATUS_CALLBACK(netif);
#if LWIP_NETIF_EXT_STATUS_CALLBACK
{
netif_ext_callback_args_t args;
args.status_changed.state = 1;
netif_invoke_ext_callback(netif, LWIP_NSC_STATUS_CHANGED, &args);
...}/* ... */
#endif
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4 | NETIF_REPORT_TYPE_IPV6);
#if LWIP_IPV6
nd6_restart_netif(netif);
#endif
}if (!(netif->flags & NETIF_FLAG_UP)) { ... }
}{ ... }
/* ... */
static void
netif_issue_reports(struct netif *netif, u8_t report_type)
{
LWIP_ASSERT("netif_issue_reports: invalid netif", netif != NULL);
if (!(netif->flags & NETIF_FLAG_LINK_UP) ||
!(netif->flags & NETIF_FLAG_UP)) {
return;
}if (!(netif->flags & NETIF_FLAG_LINK_UP) || !(netif->flags & NETIF_FLAG_UP)) { ... }
#if LWIP_IPV4
if ((report_type & NETIF_REPORT_TYPE_IPV4) &&
!ip4_addr_isany_val(*netif_ip4_addr(netif))) {
#if LWIP_ARP
if (netif->flags & (NETIF_FLAG_ETHARP)) {
etharp_gratuitous(netif);
}if (netif->flags & (NETIF_FLAG_ETHARP)) { ... }
/* ... */#endif
#if LWIP_IGMP
if (netif->flags & NETIF_FLAG_IGMP) {
igmp_report_groups(netif);
}if (netif->flags & NETIF_FLAG_IGMP) { ... }
/* ... */#endif
}if ((report_type & NETIF_REPORT_TYPE_IPV4) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) { ... }
/* ... */#endif
#if LWIP_IPV6
if (report_type & NETIF_REPORT_TYPE_IPV6) {
#if LWIP_IPV6_MLD
mld6_report_groups(netif);/* ... */
#endif
}if (report_type & NETIF_REPORT_TYPE_IPV6) { ... }
/* ... */#endif
}{ ... }
/* ... */
void
netif_set_down(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_down: invalid netif", netif != NULL, return);
if (netif->flags & NETIF_FLAG_UP) {
#if LWIP_NETIF_EXT_STATUS_CALLBACK
{
netif_ext_callback_args_t args;
args.status_changed.state = 0;
netif_invoke_ext_callback(netif, LWIP_NSC_STATUS_CHANGED, &args);
...}/* ... */
#endif
netif_clear_flags(netif, NETIF_FLAG_UP);
MIB2_COPY_SYSUPTIME_TO(&netif->ts);
#if LWIP_IPV4 && LWIP_ARP
if (netif->flags & NETIF_FLAG_ETHARP) {
etharp_cleanup_netif(netif);
}if (netif->flags & NETIF_FLAG_ETHARP) { ... }
/* ... */#endif
#if LWIP_IPV6
nd6_cleanup_netif(netif);
#endif
NETIF_STATUS_CALLBACK(netif);
}if (netif->flags & NETIF_FLAG_UP) { ... }
}{ ... }
#if LWIP_NETIF_STATUS_CALLBACK
/* ... */
void
netif_set_status_callback(struct netif *netif, netif_status_callback_fn status_callback)
{
LWIP_ASSERT_CORE_LOCKED();
if (netif) {
netif->status_callback = status_callback;
}if (netif) { ... }
}netif_set_status_callback (struct netif *netif, netif_status_callback_fn status_callback) { ... }
/* ... */#endif
#if LWIP_NETIF_REMOVE_CALLBACK
/* ... */
void
netif_set_remove_callback(struct netif *netif, netif_status_callback_fn remove_callback)
{
LWIP_ASSERT_CORE_LOCKED();
if (netif) {
netif->remove_callback = remove_callback;
}if (netif) { ... }
}netif_set_remove_callback (struct netif *netif, netif_status_callback_fn remove_callback) { ... }
/* ... */#endif
/* ... */
void
netif_set_link_up(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_link_up: invalid netif", netif != NULL, return);
if (!(netif->flags & NETIF_FLAG_LINK_UP)) {
netif_set_flags(netif, NETIF_FLAG_LINK_UP);
#if LWIP_DHCP
dhcp_network_changed(netif);
#endif
#if LWIP_AUTOIP
autoip_network_changed(netif);
#endif
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4 | NETIF_REPORT_TYPE_IPV6);
#if LWIP_IPV6
nd6_restart_netif(netif);
#endif
NETIF_LINK_CALLBACK(netif);
#if LWIP_NETIF_EXT_STATUS_CALLBACK
{
netif_ext_callback_args_t args;
args.link_changed.state = 1;
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
...}/* ... */
#endif
}if (!(netif->flags & NETIF_FLAG_LINK_UP)) { ... }
}{ ... }
/* ... */
void
netif_set_link_down(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif_set_link_down: invalid netif", netif != NULL, return);
if (netif->flags & NETIF_FLAG_LINK_UP) {
netif_clear_flags(netif, NETIF_FLAG_LINK_UP);
NETIF_LINK_CALLBACK(netif);
#if LWIP_NETIF_EXT_STATUS_CALLBACK
{
netif_ext_callback_args_t args;
args.link_changed.state = 0;
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
...}/* ... */
#endif
}if (netif->flags & NETIF_FLAG_LINK_UP) { ... }
}{ ... }
#if LWIP_NETIF_LINK_CALLBACK
/* ... */
void
netif_set_link_callback(struct netif *netif, netif_status_callback_fn link_callback)
{
LWIP_ASSERT_CORE_LOCKED();
if (netif) {
netif->link_callback = link_callback;
}if (netif) { ... }
}{ ... }
#endif/* ... */
#if ENABLE_LOOPBACK
/* ... */
err_t
netif_loop_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *r;
err_t err;
struct pbuf *last;
#if LWIP_LOOPBACK_MAX_PBUFS
u16_t clen = 0;
#endif
/* ... */
#if MIB2_STATS
#if LWIP_HAVE_LOOPIF
struct netif *stats_if = &loop_netif;
#else
struct netif *stats_if = netif;
#endif /* ... */
#endif
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
u8_t schedule_poll = 0;
#endif
SYS_ARCH_DECL_PROTECT(lev);
LWIP_ASSERT("netif_loop_output: invalid netif", netif != NULL);
LWIP_ASSERT("netif_loop_output: invalid pbuf", p != NULL);
r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
if (r == NULL) {
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
MIB2_STATS_NETIF_INC(stats_if, ifoutdiscards);
return ERR_MEM;
}if (r == NULL) { ... }
#if LWIP_LOOPBACK_MAX_PBUFS
clen = pbuf_clen(r);
if (((netif->loop_cnt_current + clen) < netif->loop_cnt_current) ||
((netif->loop_cnt_current + clen) > LWIP_MIN(LWIP_LOOPBACK_MAX_PBUFS, 0xFFFF))) {
pbuf_free(r);
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
MIB2_STATS_NETIF_INC(stats_if, ifoutdiscards);
return ERR_MEM;
}if (((netif->loop_cnt_current + clen) < netif->loop_cnt_current) || ((netif->loop_cnt_current + clen) > LWIP_MIN(LWIP_LOOPBACK_MAX_PBUFS, 0xFFFF))) { ... }
netif->loop_cnt_current = (u16_t)(netif->loop_cnt_current + clen);/* ... */
#endif
if ((err = pbuf_copy(r, p)) != ERR_OK) {
pbuf_free(r);
LINK_STATS_INC(link.memerr);
LINK_STATS_INC(link.drop);
MIB2_STATS_NETIF_INC(stats_if, ifoutdiscards);
return err;
}if ((err = pbuf_copy(r, p)) != ERR_OK) { ... }
/* ... */
for (last = r; last->next != NULL; last = last->next) {
}for (last = r; last->next != NULL; last = last->next) { ... }
SYS_ARCH_PROTECT(lev);
if (netif->loop_first != NULL) {
LWIP_ASSERT("if first != NULL, last must also be != NULL", netif->loop_last != NULL);
netif->loop_last->next = r;
netif->loop_last = last;
}if (netif->loop_first != NULL) { ... } else {
netif->loop_first = r;
netif->loop_last = last;
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
schedule_poll = 1;/* ... */
#endif
}else { ... }
SYS_ARCH_UNPROTECT(lev);
LINK_STATS_INC(link.xmit);
MIB2_STATS_NETIF_ADD(stats_if, ifoutoctets, p->tot_len);
MIB2_STATS_NETIF_INC(stats_if, ifoutucastpkts);
#if LWIP_NETIF_LOOPBACK_MULTITHREADING
if (schedule_poll) {
tcpip_try_callback((tcpip_callback_fn)netif_poll, netif);
}if (schedule_poll) { ... }
/* ... */#endif
return ERR_OK;
}netif_loop_output (struct netif *netif, struct pbuf *p) { ... }
#if LWIP_HAVE_LOOPIF
#if LWIP_IPV4
static err_t
netif_loop_output_ipv4(struct netif *netif, struct pbuf *p, const ip4_addr_t *addr)
{
LWIP_UNUSED_ARG(addr);
return netif_loop_output(netif, p);
}netif_loop_output_ipv4 (struct netif *netif, struct pbuf *p, const ip4_addr_t *addr) { ... }
/* ... */#endif
#if LWIP_IPV6
static err_t
netif_loop_output_ipv6(struct netif *netif, struct pbuf *p, const ip6_addr_t *addr)
{
LWIP_UNUSED_ARG(addr);
return netif_loop_output(netif, p);
}netif_loop_output_ipv6 (struct netif *netif, struct pbuf *p, const ip6_addr_t *addr) { ... }
/* ... */#endif /* ... */
#endif
/* ... */
void
netif_poll(struct netif *netif)
{
/* ... */
#if MIB2_STATS
#if LWIP_HAVE_LOOPIF
struct netif *stats_if = &loop_netif;
#else
struct netif *stats_if = netif;
#endif /* ... */
#endif
SYS_ARCH_DECL_PROTECT(lev);
LWIP_ASSERT("netif_poll: invalid netif", netif != NULL);
SYS_ARCH_PROTECT(lev);
while (netif->loop_first != NULL) {
struct pbuf *in, *in_end;
#if LWIP_LOOPBACK_MAX_PBUFS
u8_t clen = 1;
#endif
in = in_end = netif->loop_first;
while (in_end->len != in_end->tot_len) {
LWIP_ASSERT("bogus pbuf: len != tot_len but next == NULL!", in_end->next != NULL);
in_end = in_end->next;
#if LWIP_LOOPBACK_MAX_PBUFS
clen++;
#endif
}while (in_end->len != in_end->tot_len) { ... }
#if LWIP_LOOPBACK_MAX_PBUFS
LWIP_ASSERT("netif->loop_cnt_current underflow",
((netif->loop_cnt_current - clen) < netif->loop_cnt_current));
netif->loop_cnt_current = (u16_t)(netif->loop_cnt_current - clen);/* ... */
#endif
if (in_end == netif->loop_last) {
netif->loop_first = netif->loop_last = NULL;
}if (in_end == netif->loop_last) { ... } else {
netif->loop_first = in_end->next;
LWIP_ASSERT("should not be null since first != last!", netif->loop_first != NULL);
}else { ... }
in_end->next = NULL;
SYS_ARCH_UNPROTECT(lev);
in->if_idx = netif_get_index(netif);
LINK_STATS_INC(link.recv);
MIB2_STATS_NETIF_ADD(stats_if, ifinoctets, in->tot_len);
MIB2_STATS_NETIF_INC(stats_if, ifinucastpkts);
if (ip_input(in, netif) != ERR_OK) {
pbuf_free(in);
}if (ip_input(in, netif) != ERR_OK) { ... }
SYS_ARCH_PROTECT(lev);
}while (netif->loop_first != NULL) { ... }
SYS_ARCH_UNPROTECT(lev);
}netif_poll (struct netif *netif) { ... }
#if !LWIP_NETIF_LOOPBACK_MULTITHREADING
/* ... */
void
netif_poll_all(void)
{
struct netif *netif;
NETIF_FOREACH(netif) {
netif_poll(netif);
}NETIF_FOREACH (netif) { ... }
}netif_poll_all (void) { ... }
/* ... */#endif /* ... */
#endif
#if LWIP_NUM_NETIF_CLIENT_DATA > 0
/* ... */
u8_t
netif_alloc_client_data_id(void)
{
u8_t result = netif_client_id;
netif_client_id++;
LWIP_ASSERT_CORE_LOCKED();
#if LWIP_NUM_NETIF_CLIENT_DATA > 256
#error LWIP_NUM_NETIF_CLIENT_DATA must be <= 256
#endif
LWIP_ASSERT("Increase LWIP_NUM_NETIF_CLIENT_DATA in lwipopts.h", result < LWIP_NUM_NETIF_CLIENT_DATA);
return (u8_t)(result + LWIP_NETIF_CLIENT_DATA_INDEX_MAX);
}netif_alloc_client_data_id (void) { ... }
/* ... */#endif
#if LWIP_IPV6
/* ... */
void
netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_ip6_addr_set: invalid netif", netif != NULL);
LWIP_ASSERT("netif_ip6_addr_set: invalid addr6", addr6 != NULL);
netif_ip6_addr_set_parts(netif, addr_idx, addr6->addr[0], addr6->addr[1],
addr6->addr[2], addr6->addr[3]);
}netif_ip6_addr_set (struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6) { ... }
/* ... */
void
netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3)
{
ip_addr_t old_addr;
ip_addr_t new_ipaddr;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif != NULL", netif != NULL);
LWIP_ASSERT("invalid index", addr_idx < LWIP_IPV6_NUM_ADDRESSES);
ip6_addr_copy(*ip_2_ip6(&old_addr), *netif_ip6_addr(netif, addr_idx));
IP_SET_TYPE_VAL(old_addr, IPADDR_TYPE_V6);
if ((ip_2_ip6(&old_addr)->addr[0] != i0) || (ip_2_ip6(&old_addr)->addr[1] != i1) ||
(ip_2_ip6(&old_addr)->addr[2] != i2) || (ip_2_ip6(&old_addr)->addr[3] != i3)) {
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set: netif address being changed\n"));
IP_ADDR6(&new_ipaddr, i0, i1, i2, i3);
ip6_addr_assign_zone(ip_2_ip6(&new_ipaddr), IP6_UNICAST, netif);
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, addr_idx))) {
netif_do_ip_addr_changed(netif_ip_addr6(netif, addr_idx), &new_ipaddr);
}if (ip6_addr_isvalid(netif_ip6_addr_state(netif, addr_idx))) { ... }
ip_addr_copy(netif->ip6_addr[addr_idx], new_ipaddr);
if (ip6_addr_isvalid(netif_ip6_addr_state(netif, addr_idx))) {
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV6);
NETIF_STATUS_CALLBACK(netif);
}if (ip6_addr_isvalid(netif_ip6_addr_state(netif, addr_idx))) { ... }
#if LWIP_NETIF_EXT_STATUS_CALLBACK
{
netif_ext_callback_args_t args;
args.ipv6_set.addr_index = addr_idx;
args.ipv6_set.old_address = &old_addr;
netif_invoke_ext_callback(netif, LWIP_NSC_IPV6_SET, &args);
...}/* ... */
#endif
}if ((ip_2_ip6(&old_addr)->addr[0] != i0) || (ip_2_ip6(&old_addr)->addr[1] != i1) || (ip_2_ip6(&old_addr)->addr[2] != i2) || (ip_2_ip6(&old_addr)->addr[3] != i3)) { ... }
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n",
addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)),
netif_ip6_addr_state(netif, addr_idx)));
}netif_ip6_addr_set_parts (struct netif *netif, s8_t addr_idx, u32_t i0, u32_t i1, u32_t i2, u32_t i3) { ... }
/* ... */
void
netif_ip6_addr_set_state(struct netif *netif, s8_t addr_idx, u8_t state)
{
u8_t old_state;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif != NULL", netif != NULL);
LWIP_ASSERT("invalid index", addr_idx < LWIP_IPV6_NUM_ADDRESSES);
old_state = netif_ip6_addr_state(netif, addr_idx);
if (old_state != state) {
u8_t old_valid = old_state & IP6_ADDR_VALID;
u8_t new_valid = state & IP6_ADDR_VALID;
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_ip6_addr_set_state: netif address state being changed\n"));
#if LWIP_IPV6_MLD
if (netif->flags & NETIF_FLAG_MLD6) {
nd6_adjust_mld_membership(netif, addr_idx, state);
}if (netif->flags & NETIF_FLAG_MLD6) { ... }
/* ... */#endif
if (old_valid && !new_valid) {
netif_do_ip_addr_changed(netif_ip_addr6(netif, addr_idx), NULL);
}if (old_valid && !new_valid) { ... }
netif->ip6_addr_state[addr_idx] = state;
if (!old_valid && new_valid) {
IP6_ADDR_ZONECHECK_NETIF(netif_ip6_addr(netif, addr_idx), netif);
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV6);
}if (!old_valid && new_valid) { ... }
if ((old_state & ~IP6_ADDR_TENTATIVE_COUNT_MASK) !=
(state & ~IP6_ADDR_TENTATIVE_COUNT_MASK)) {
NETIF_STATUS_CALLBACK(netif);
}if ((old_state & ~IP6_ADDR_TENTATIVE_COUNT_MASK) != (state & ~IP6_ADDR_TENTATIVE_COUNT_MASK)) { ... }
#if LWIP_NETIF_EXT_STATUS_CALLBACK
{
netif_ext_callback_args_t args;
args.ipv6_addr_state_changed.addr_index = addr_idx;
args.ipv6_addr_state_changed.old_state = old_state;
args.ipv6_addr_state_changed.address = netif_ip_addr6(netif, addr_idx);
netif_invoke_ext_callback(netif, LWIP_NSC_IPV6_ADDR_STATE_CHANGED, &args);
...}/* ... */
#endif
}if (old_state != state) { ... }
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: IPv6 address %d of interface %c%c set to %s/0x%"X8_F"\n",
addr_idx, netif->name[0], netif->name[1], ip6addr_ntoa(netif_ip6_addr(netif, addr_idx)),
netif_ip6_addr_state(netif, addr_idx)));
}netif_ip6_addr_set_state (struct netif *netif, s8_t addr_idx, u8_t state) { ... }
/* ... */
s8_t
netif_get_ip6_addr_match(struct netif *netif, const ip6_addr_t *ip6addr)
{
s8_t i;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_get_ip6_addr_match: invalid netif", netif != NULL);
LWIP_ASSERT("netif_get_ip6_addr_match: invalid ip6addr", ip6addr != NULL);
#if LWIP_IPV6_SCOPES
if (ip6_addr_has_zone(ip6addr) && !ip6_addr_test_zone(ip6addr, netif)) {
return -1;
}if (ip6_addr_has_zone(ip6addr) && !ip6_addr_test_zone(ip6addr, netif)) { ... }
/* ... */#endif
for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (!ip6_addr_isinvalid(netif_ip6_addr_state(netif, i)) &&
ip6_addr_cmp_zoneless(netif_ip6_addr(netif, i), ip6addr)) {
return i;
}if (!ip6_addr_isinvalid(netif_ip6_addr_state(netif, i)) && ip6_addr_cmp_zoneless(netif_ip6_addr(netif, i), ip6addr)) { ... }
}for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { ... }
return -1;
}netif_get_ip6_addr_match (struct netif *netif, const ip6_addr_t *ip6addr) { ... }
/* ... */
void
netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
{
u8_t i, addr_index;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_create_ip6_linklocal_address: invalid netif", netif != NULL);
ip_2_ip6(&netif->ip6_addr[0])->addr[0] = PP_HTONL(0xfe800000ul);
ip_2_ip6(&netif->ip6_addr[0])->addr[1] = 0;
if (from_mac_48bit) {
ip_2_ip6(&netif->ip6_addr[0])->addr[2] = lwip_htonl((((u32_t)(netif->hwaddr[0] ^ 0x02)) << 24) |
((u32_t)(netif->hwaddr[1]) << 16) |
((u32_t)(netif->hwaddr[2]) << 8) |
(0xff));
ip_2_ip6(&netif->ip6_addr[0])->addr[3] = lwip_htonl((u32_t)(0xfeul << 24) |
((u32_t)(netif->hwaddr[3]) << 16) |
((u32_t)(netif->hwaddr[4]) << 8) |
(netif->hwaddr[5]));
}if (from_mac_48bit) { ... } else {
ip_2_ip6(&netif->ip6_addr[0])->addr[2] = 0;
ip_2_ip6(&netif->ip6_addr[0])->addr[3] = 0;
addr_index = 3;
for (i = 0; (i < 8) && (i < netif->hwaddr_len); i++) {
if (i == 4) {
addr_index--;
}if (i == 4) { ... }
ip_2_ip6(&netif->ip6_addr[0])->addr[addr_index] |= lwip_htonl(((u32_t)(netif->hwaddr[netif->hwaddr_len - i - 1])) << (8 * (i & 0x03)));
}for (i = 0; (i < 8) && (i < netif->hwaddr_len); i++) { ... }
}else { ... }
/* ... */
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[0]), IP6_UNICAST, netif);
#if LWIP_IPV6_DUP_DETECT_ATTEMPTS
netif_ip6_addr_set_state(netif, 0, IP6_ADDR_TENTATIVE);/* ... */
#else
netif_ip6_addr_set_state(netif, 0, IP6_ADDR_PREFERRED);/* ... */
#endif
}netif_create_ip6_linklocal_address (struct netif *netif, u8_t from_mac_48bit) { ... }
/* ... */
err_t
netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx)
{
s8_t i;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif_add_ip6_address: invalid netif", netif != NULL);
LWIP_ASSERT("netif_add_ip6_address: invalid ip6addr", ip6addr != NULL);
i = netif_get_ip6_addr_match(netif, ip6addr);
if (i >= 0) {
if (chosen_idx != NULL) {
*chosen_idx = i;
}if (chosen_idx != NULL) { ... }
return ERR_OK;
}if (i >= 0) { ... }
for (i = ip6_addr_islinklocal(ip6addr) ? 0 : 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) {
ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[i]), IP6_UNICAST, netif);
netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
if (chosen_idx != NULL) {
*chosen_idx = i;
}if (chosen_idx != NULL) { ... }
return ERR_OK;
}if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) { ... }
}for (i = ip6_addr_islinklocal(ip6addr) ? 0 : 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) { ... }
if (chosen_idx != NULL) {
*chosen_idx = -1;
}if (chosen_idx != NULL) { ... }
return ERR_VAL;
}netif_add_ip6_address (struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chosen_idx) { ... }
/* ... */
static err_t
netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr)
{
LWIP_UNUSED_ARG(netif);
LWIP_UNUSED_ARG(p);
LWIP_UNUSED_ARG(ipaddr);
return ERR_IF;
}netif_null_output_ip6 (struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr) { ... }
/* ... */#endif
#if LWIP_IPV4
/* ... */
static err_t
netif_null_output_ip4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr)
{
LWIP_UNUSED_ARG(netif);
LWIP_UNUSED_ARG(p);
LWIP_UNUSED_ARG(ipaddr);
return ERR_IF;
}{ ... }
#endif/* ... */
/* ... */
u8_t
netif_name_to_index(const char *name)
{
struct netif *netif = netif_find(name);
if (netif != NULL) {
return netif_get_index(netif);
}if (netif != NULL) { ... }
return NETIF_NO_INDEX;
}{ ... }
/* ... */
char *
netif_index_to_name(u8_t idx, char *name)
{
struct netif *netif = netif_get_by_index(idx);
if (netif != NULL) {
name[0] = netif->name[0];
name[1] = netif->name[1];
lwip_itoa(&name[2], NETIF_NAMESIZE - 2, netif_index_to_num(idx));
return name;
}if (netif != NULL) { ... }
return NULL;
}{ ... }
/* ... */
struct netif *
netif_get_by_index(u8_t idx)
{
struct netif *netif;
LWIP_ASSERT_CORE_LOCKED();
if (idx != NETIF_NO_INDEX) {
NETIF_FOREACH(netif) {
if (idx == netif_get_index(netif)) {
return netif;
}if (idx == netif_get_index(netif)) { ... }
}NETIF_FOREACH (netif) { ... }
}if (idx != NETIF_NO_INDEX) { ... }
return NULL;
}{ ... }
/* ... */
struct netif *
netif_find(const char *name)
{
struct netif *netif;
u8_t num;
LWIP_ASSERT_CORE_LOCKED();
if (name == NULL) {
return NULL;
}if (name == NULL) { ... }
num = (u8_t)atoi(&name[2]);
NETIF_FOREACH(netif) {
if (num == netif->num &&
name[0] == netif->name[0] &&
name[1] == netif->name[1]) {
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
return netif;
}if (num == netif->num && name[0] == netif->name[0] && name[1] == netif->name[1]) { ... }
}NETIF_FOREACH (netif) { ... }
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
return NULL;
}{ ... }
#if LWIP_NETIF_EXT_STATUS_CALLBACK
/* ... */
void
netif_add_ext_callback(netif_ext_callback_t *callback, netif_ext_callback_fn fn)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("callback must be != NULL", callback != NULL);
LWIP_ASSERT("fn must be != NULL", fn != NULL);
callback->callback_fn = fn;
callback->next = ext_callback;
ext_callback = callback;
}netif_add_ext_callback (netif_ext_callback_t *callback, netif_ext_callback_fn fn) { ... }
/* ... */
void
netif_remove_ext_callback(netif_ext_callback_t* callback)
{
netif_ext_callback_t *last, *iter;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("callback must be != NULL", callback != NULL);
if (ext_callback == NULL) {
return;
}if (ext_callback == NULL) { ... }
if (callback == ext_callback) {
ext_callback = ext_callback->next;
}if (callback == ext_callback) { ... } else {
last = ext_callback;
for (iter = ext_callback->next; iter != NULL; last = iter, iter = iter->next) {
if (iter == callback) {
LWIP_ASSERT("last != NULL", last != NULL);
last->next = callback->next;
callback->next = NULL;
return;
}if (iter == callback) { ... }
}for (iter = ext_callback->next; iter != NULL; last = iter, iter = iter->next) { ... }
}else { ... }
}netif_remove_ext_callback (netif_ext_callback_t* callback) { ... }
/* ... */
void
netif_invoke_ext_callback(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
{
netif_ext_callback_t *callback = ext_callback;
LWIP_ASSERT("netif must be != NULL", netif != NULL);
while (callback != NULL) {
callback->callback_fn(netif, reason, args);
callback = callback->next;
}while (callback != NULL) { ... }
}netif_invoke_ext_callback (struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args) { ... }
/* ... */#endif