ipv4_misc.c
Go to the documentation of this file.
1 /**
2  * @file ipv4_misc.c
3  * @brief Helper functions for IPv4
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL IPV4_TRACE_LEVEL
33 
34 //Dependencies
35 #include <string.h>
36 #include <ctype.h>
37 #include "core/net.h"
38 #include "ipv4/ipv4.h"
39 #include "ipv4/ipv4_misc.h"
40 #include "mibs/mib2_module.h"
41 #include "mibs/ip_mib_module.h"
42 #include "debug.h"
43 
44 //Check TCP/IP stack configuration
45 #if (IPV4_SUPPORT == ENABLED)
46 
47 
48 /**
49  * @brief Source IPv4 address filtering
50  * @param[in] interface Underlying network interface
51  * @param[in] ipAddr Source IPv4 address to be checked
52  * @return Error code
53  **/
54 
56 {
57  //Broadcast and multicast addresses must not be used as source address
58  //(refer to RFC 1122, section 3.2.1.3)
60  {
61  //Debug message
62  TRACE_WARNING("Wrong source IPv4 address!\r\n");
63  //The source address not is acceptable
64  return ERROR_INVALID_ADDRESS;
65  }
66 
67  //The source address is acceptable
68  return NO_ERROR;
69 }
70 
71 
72 /**
73  * @brief Destination IPv4 address filtering
74  * @param[in] interface Underlying network interface
75  * @param[in] ipAddr Destination IPv4 address to be checked
76  * @return Error code
77  **/
78 
80 {
81  error_t error;
82  uint_t i;
83  Ipv4AddrEntry *entry;
84 
85  //Filter out any invalid addresses
86  error = ERROR_INVALID_ADDRESS;
87 
88  //Broadcast address?
89  if(ipv4IsBroadcastAddr(interface, ipAddr))
90  {
91  //Always accept broadcast address
92  error = NO_ERROR;
93  }
94  //Multicast address?
95  else if(ipv4IsMulticastAddr(ipAddr))
96  {
97  //Go through the multicast filter table
98  for(i = 0; i < IPV4_MULTICAST_FILTER_SIZE; i++)
99  {
100  Ipv4FilterEntry *entry;
101 
102  //Point to the current entry
103  entry = &interface->ipv4Context.multicastFilter[i];
104 
105  //Valid entry?
106  if(entry->refCount > 0)
107  {
108  //Check whether the destination IPv4 address matches
109  //a relevant multicast address
110  if(entry->addr == ipAddr)
111  {
112  //The multicast address is acceptable
113  error = NO_ERROR;
114  //Stop immediately
115  break;
116  }
117  }
118  }
119  }
120  //Unicast address?
121  else
122  {
123  //Loop through the list of IPv4 addresses assigned to the interface
124  for(i = 0; i < IPV4_ADDR_LIST_SIZE; i++)
125  {
126  //Point to the current entry
127  entry = &interface->ipv4Context.addrList[i];
128 
129  //Valid entry?
130  if(entry->state != IPV4_ADDR_STATE_INVALID)
131  {
132  //Check whether the destination address matches a valid unicast
133  //address assigned to the interface
134  if(entry->addr == ipAddr)
135  {
136  //The destination address is acceptable
137  error = NO_ERROR;
138  //We are done
139  break;
140  }
141  }
142  }
143  }
144 
145  //Return status code
146  return error;
147 }
148 
149 
150 /**
151  * @brief IPv4 source address selection
152  *
153  * This function selects the source address and the relevant network interface
154  * to be used in order to join the specified destination address
155  *
156  * @param[in,out] interface A pointer to a valid network interface may be provided as
157  * a hint. The function returns a pointer identifying the interface to be used
158  * @param[in] destAddr Destination IPv4 address
159  * @param[out] srcAddr Local IPv4 address to be used
160  * @return Error code
161  **/
162 
165 {
166  error_t error;
167  uint_t i;
168  uint_t j;
169  NetInterface *currentInterface;
170  NetInterface *bestInterface;
171  Ipv4AddrEntry *currentAddr;
172  Ipv4AddrEntry *bestAddr;
173 
174  //Initialize variables
175  bestInterface = NULL;
176  bestAddr = NULL;
177 
178  //Loop through network interfaces
179  for(i = 0; i < NET_INTERFACE_COUNT; i++)
180  {
181  //Point to the current interface
182  currentInterface = &netInterface[i];
183 
184  //A network interface may be provided as a hint
185  if(*interface != currentInterface && *interface != NULL)
186  {
187  //Select the next interface in the list
188  continue;
189  }
190 
191  //A sort of the candidate source addresses is being performed
192  for(j = 0; j < IPV4_ADDR_LIST_SIZE; j++)
193  {
194  //Point to the current entry
195  currentAddr = &currentInterface->ipv4Context.addrList[j];
196 
197  //Check the state of the address
198  if(currentAddr->state == IPV4_ADDR_STATE_VALID)
199  {
200  //Select the first address as default
201  if(bestAddr == NULL)
202  {
203  //Give the current source address the higher precedence
204  bestInterface = currentInterface;
205  bestAddr = currentAddr;
206 
207  //Select the next address in the list
208  continue;
209  }
210 
211  //Prefer same address
212  if(bestAddr->addr == destAddr)
213  {
214  //Select the next address in the list
215  continue;
216  }
217  else if(currentAddr->addr == destAddr)
218  {
219  //Give the current source address the higher precedence
220  bestInterface = currentInterface;
221  bestAddr = currentAddr;
222 
223  //Select the next address in the list
224  continue;
225  }
226 
227  //Check whether the destination address matches the default gateway
228  if(bestAddr->defaultGateway == destAddr)
229  {
230  //Select the next address in the list
231  continue;
232  }
233  else if(currentAddr->defaultGateway == destAddr)
234  {
235  //Give the current source address the higher precedence
236  bestInterface = currentInterface;
237  bestAddr = currentAddr;
238 
239  //Select the next address in the list
240  continue;
241  }
242 
243  //Prefer appropriate scope
244  if(ipv4GetAddrScope(currentAddr->addr) < ipv4GetAddrScope(bestAddr->addr))
245  {
246  if(ipv4GetAddrScope(currentAddr->addr) >= ipv4GetAddrScope(destAddr))
247  {
248  //Give the current source address the higher precedence
249  bestInterface = currentInterface;
250  bestAddr = currentAddr;
251  }
252 
253  //Select the next address in the list
254  continue;
255  }
256  else if(ipv4GetAddrScope(bestAddr->addr) < ipv4GetAddrScope(currentAddr->addr))
257  {
259  {
260  //Give the current source address the higher precedence
261  bestInterface = currentInterface;
262  bestAddr = currentAddr;
263  }
264 
265  //Select the next address in the list
266  continue;
267  }
268 
269  //If the destination address lies on one of the subnets to which
270  //the host is directly connected, the corresponding source address
271  //may be chosen (refer to RFC 1122, section 3.3.4.3)
272  if(ipv4IsOnSubnet(bestAddr, destAddr))
273  {
274  if(ipv4IsOnSubnet(currentAddr, destAddr))
275  {
276  //Use longest subnet mask
277  if(ipv4GetPrefixLength(currentAddr->subnetMask) >
278  ipv4GetPrefixLength(bestAddr->subnetMask))
279  {
280  //Give the current source address the higher precedence
281  bestInterface = currentInterface;
282  bestAddr = currentAddr;
283  }
284  }
285 
286  //Select the next address in the list
287  continue;
288  }
289  else
290  {
291  if(ipv4IsOnSubnet(currentAddr, destAddr))
292  {
293  //Give the current source address the higher precedence
294  bestInterface = currentInterface;
295  bestAddr = currentAddr;
296 
297  //Select the next address in the list
298  continue;
299  }
300  }
301 
302  //The default gateways may be consulted. If these gateways are
303  //assigned to different interfaces, the interface corresponding
304  //to the gateway with the highest preference may be chosen
305  if(bestAddr->defaultGateway != IPV4_UNSPECIFIED_ADDR)
306  {
307  //Select the next address in the list
308  continue;
309  }
310  else if(currentAddr->defaultGateway != IPV4_UNSPECIFIED_ADDR)
311  {
312  //Give the current source address the higher precedence
313  bestInterface = currentInterface;
314  bestAddr = currentAddr;
315 
316  //Select the next address in the list
317  continue;
318  }
319  }
320  }
321  }
322 
323  //Valid source address?
324  if(bestAddr != NULL)
325  {
326  //Return the out-going interface and the source address to be used
327  *interface = bestInterface;
328  *srcAddr = bestAddr->addr;
329 
330  //Successful source address selection
331  error = NO_ERROR;
332  }
333  else
334  {
335  //Report an error
336  error = ERROR_NO_ADDRESS;
337  }
338 
339  //Return status code
340  return error;
341 }
342 
343 
344 /**
345  * @brief Check whether an IPv4 address is on-link
346  * @param[in] interface Underlying network interface
347  * @param[in] ipAddr IPv4 address to be checked
348  * @return TRUE if the IPv4 address is on-link, else FALSE
349  **/
350 
352 {
353  uint_t i;
354  Ipv4AddrEntry *entry;
355 
356  //Loop through the list of IPv4 addresses assigned to the interface
357  for(i = 0; i < IPV4_ADDR_LIST_SIZE; i++)
358  {
359  //Point to the current entry
360  entry = &interface->ipv4Context.addrList[i];
361 
362  //Valid entry?
363  if(entry->state != IPV4_ADDR_STATE_INVALID)
364  {
365  //Check whether the specified IPv4 address belongs to the same subnet
366  if(ipv4IsOnSubnet(entry, ipAddr))
367  {
368  //The specified IPv4 address is on-link
369  return TRUE;
370  }
371  }
372  }
373 
374  //The specified IPv4 address is off-link
375  return FALSE;
376 }
377 
378 
379 /**
380  * @brief Check whether an IPv4 address is a broadcast address
381  * @param[in] interface Underlying network interface
382  * @param[in] ipAddr IPv4 address to be checked
383  * @return TRUE if the IPv4 address is a broadcast address, else FALSE
384  **/
385 
387 {
388  uint_t i;
389  Ipv4AddrEntry *entry;
390 
391  //Check whether the specified IPv4 address is the broadcast address
393  return TRUE;
394 
395  //Loop through the list of IPv4 addresses assigned to the interface
396  for(i = 0; i < IPV4_ADDR_LIST_SIZE; i++)
397  {
398  //Point to the current entry
399  entry = &interface->ipv4Context.addrList[i];
400 
401  //Valid entry?
402  if(entry->state != IPV4_ADDR_STATE_INVALID)
403  {
404  //Check whether the specified IPv4 address belongs to the same subnet
405  if(ipv4IsOnSubnet(entry, ipAddr))
406  {
407  //Make sure the subnet mask is not 255.255.255.255
408  if(entry->subnetMask != IPV4_BROADCAST_ADDR)
409  {
410  //Directed broadcast address?
411  if((ipAddr | entry->subnetMask) == IPV4_BROADCAST_ADDR)
412  {
413  return TRUE;
414  }
415  }
416  }
417  }
418  }
419 
420  //The specified IPv4 address is not a broadcast address
421  return FALSE;
422 }
423 
424 
425 /**
426  * @brief Check whether an IPv4 address is a tentative address
427  * @param[in] interface Underlying network interface
428  * @param[in] ipAddr IPv4 address to be checked
429  * @return TRUE if the IPv4 address is a tentative address, else FALSE
430  **/
431 
433 {
434  uint_t i;
435  Ipv4AddrEntry *entry;
436 
437  //Loop through the list of IPv4 addresses assigned to the interface
438  for(i = 0; i < IPV4_ADDR_LIST_SIZE; i++)
439  {
440  //Point to the current entry
441  entry = &interface->ipv4Context.addrList[i];
442 
443  //Tentative address?
444  if(entry->state == IPV4_ADDR_STATE_TENTATIVE)
445  {
446  //Check whether the specified address matches a valid unicast
447  //address assigned to the interface
448  if(entry->addr == ipAddr)
449  {
450  //The specified IPv4 address is a tentative address
451  return TRUE;
452  }
453  }
454  }
455 
456  //The specified IPv4 address is not a tentative address
457  return FALSE;
458 }
459 
460 
461 /**
462  * @brief Check whether the specified IPv4 is assigned to the host
463  * @param[in] ipAddr IPv4 address to be checked
464  * @return TRUE if the IPv4 address matches any address assigned to the host,
465  * else FALSE
466  **/
467 
469 {
470  uint_t i;
471  uint_t j;
472  bool_t flag;
473  NetInterface *interface;
474  Ipv4AddrEntry *entry;
475 
476  //Initialize flag
477  flag = FALSE;
478 
479  //Loopback address?
481  {
482  //The 127.0.0.0/8 block is assigned for use as the host loopback address.
483  //A datagram sent by a higher-level protocol to an address anywhere within
484  //this block loops back inside the host (refer to RFC 5735, section 3)
485  flag = TRUE;
486  }
487  else
488  {
489  //Loop through network interfaces
490  for(i = 0; i < NET_INTERFACE_COUNT && !flag; i++)
491  {
492  //Point to the current interface
493  interface = &netInterface[i];
494 
495  //Iterate through the list of addresses assigned to the interface
496  for(j = 0; j < IPV4_ADDR_LIST_SIZE && !flag; j++)
497  {
498  //Point to the current entry
499  entry = &interface->ipv4Context.addrList[j];
500 
501  //Check whether the specified IPv4 address matches any address
502  //assigned to the host
503  if(entry->state == IPV4_ADDR_STATE_VALID &&
504  entry->addr == ipAddr)
505  {
506  flag = TRUE;
507  }
508  }
509  }
510  }
511 
512  //Return TRUE if the specified address matches any address assigned to the host
513  return flag;
514 }
515 
516 
517 /**
518  * @brief Retrieve the scope of an IPv4 address
519  * @param[in] ipAddr IPv4 address
520  * @return IPv4 address scope
521  **/
522 
524 {
525  uint_t scope;
526 
527  //Broadcast address?
529  {
530  //The broadcast address is never forwarded by the routers connecting
531  //the local network to other networks
533  }
534  //Multicast address?
535  else if(ipv4IsMulticastAddr(ipAddr))
536  {
537  //Local Network Control Block?
539  {
540  //Addresses in the Local Network Control Block are used for protocol
541  //control traffic that is not forwarded off link
543  }
544  //Any other multicast address?
545  else
546  {
547  //Other addresses are assigned global scope
548  scope = IPV4_ADDR_SCOPE_GLOBAL;
549  }
550  }
551  //Unicast address?
552  else
553  {
554  //Loopback address?
556  {
557  //IPv4 loopback addresses, which have the prefix 127.0.0.0/8,
558  //are assigned interface-local scope
560  }
561  //Link-local address?
563  {
564  //IPv4 auto-configuration addresses, which have the prefix
565  //169.254.0.0/16, are assigned link-local scope
567  }
568  //Any other unicast address?
569  else
570  {
571  //Other addresses are assigned global scope
572  scope = IPV4_ADDR_SCOPE_GLOBAL;
573  }
574  }
575 
576  //Return the scope of the specified IPv4 address
577  return scope;
578 }
579 
580 
581 /**
582  * @brief Calculate prefix length for a given subnet mask
583  * @param[in] mask Subnet mask
584  * @return Prefix length
585  **/
586 
588 {
589  uint_t i;
590 
591  //Convert from network byte order to host byte order
592  mask = ntohl(mask);
593 
594  //Count of the number of leading 1 bits in the network mask
595  for(i = 0; i < 32; i++)
596  {
597  //Check the value of the current bit
598  if(!(mask & (1 << (31 - i))))
599  break;
600  }
601 
602  //Return prefix length
603  return i;
604 }
605 
606 
607 /**
608  * @brief Get IPv4 broadcast address
609  * @param[in] interface Pointer to the desired network interface
610  * @param[out] addr IPv4 broadcast address
611  **/
612 
614 {
615  //Check parameters
616  if(interface == NULL || addr == NULL)
618 
619  //The broadcast address is obtained by performing a bitwise OR operation
620  //between the bit complement of the subnet mask and the host IP address
621  *addr = interface->ipv4Context.addrList[0].addr;
622  *addr |= ~interface->ipv4Context.addrList[0].subnetMask;
623 
624  //Successful processing
625  return NO_ERROR;
626 }
627 
628 
629 /**
630  * @brief Map an host group address to a MAC-layer multicast address
631  * @param[in] ipAddr IPv4 host group address
632  * @param[out] macAddr Corresponding MAC-layer multicast address
633  * @return Error code
634  **/
635 
637 {
638  uint8_t *p;
639 
640  //Ensure the specified IPv4 address is a valid host group address
642  return ERROR_INVALID_ADDRESS;
643 
644  //Cast the address to byte array
645  p = (uint8_t *) &ipAddr;
646 
647  //An IP host group address is mapped to an Ethernet multicast address
648  //by placing the low-order 23-bits of the IP address into the low-order
649  //23 bits of the Ethernet multicast address 01-00-5E-00-00-00
650  macAddr->b[0] = 0x01;
651  macAddr->b[1] = 0x00;
652  macAddr->b[2] = 0x5E;
653  macAddr->b[3] = p[1] & 0x7F;
654  macAddr->b[4] = p[2];
655  macAddr->b[5] = p[3];
656 
657  //The specified host group address was successfully
658  //mapped to a MAC-layer address
659  return NO_ERROR;
660 }
661 
662 
663 /**
664  * @brief Update IPv4 input statistics
665  * @param[in] interface Underlying network interface
666  * @param[in] destIpAddr Destination IP address
667  * @param[in] length Length of the incoming IP packet
668  **/
669 
671  size_t length)
672 {
673  //Check whether the destination address is a unicast, broadcast or multicast address
674  if(ipv4IsBroadcastAddr(interface, destIpAddr))
675  {
676  //Number of IP broadcast datagrams transmitted
677  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsInBcastPkts, 1);
678  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCInBcastPkts, 1);
679  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsInBcastPkts, 1);
680  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCInBcastPkts, 1);
681  }
683  {
684  //Number of IP multicast datagrams transmitted
685  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsInMcastPkts, 1);
686  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCInMcastPkts, 1);
687  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsInMcastPkts, 1);
688  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCInMcastPkts, 1);
689 
690  //Total number of octets transmitted in IP multicast datagrams
691  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsInMcastOctets, length);
692  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCInMcastOctets, length);
693  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsInMcastOctets, length);
694  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCInMcastOctets, length);
695  }
696 }
697 
698 
699 /**
700  * @brief Update IPv4 output statistics
701  * @param[in] interface Underlying network interface
702  * @param[in] destIpAddr Destination IP address
703  * @param[in] length Length of the outgoing IP packet
704  **/
705 
707  size_t length)
708 {
709  //Check whether the destination address is a unicast, broadcast or multicast address
710  if(ipv4IsBroadcastAddr(interface, destIpAddr))
711  {
712  //Number of IP broadcast datagrams transmitted
713  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsOutBcastPkts, 1);
714  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCOutBcastPkts, 1);
715  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsOutBcastPkts, 1);
716  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCOutBcastPkts, 1);
717  }
719  {
720  //Number of IP multicast datagrams transmitted
721  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsOutMcastPkts, 1);
722  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCOutMcastPkts, 1);
723  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsOutMcastPkts, 1);
724  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCOutMcastPkts, 1);
725 
726  //Total number of octets transmitted in IP multicast datagrams
727  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsOutMcastOctets, length);
728  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCOutMcastOctets, length);
729  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsOutMcastOctets, length);
730  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCOutMcastOctets, length);
731  }
732 
733  //Total number of IP datagrams that this entity supplied to the lower
734  //layers for transmission
735  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsOutTransmits, 1);
736  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCOutTransmits, 1);
737  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsOutTransmits, 1);
738  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCOutTransmits, 1);
739 
740  //Total number of octets in IP datagrams delivered to the lower layers
741  //for transmission
742  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsOutOctets, length);
743  IP_MIB_INC_COUNTER64(ipv4SystemStats.ipSystemStatsHCOutOctets, length);
744  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsOutOctets, length);
745  IP_MIB_INC_COUNTER64(ipv4IfStatsTable[interface->index].ipIfStatsHCOutOctets, length);
746 }
747 
748 
749 /**
750  * @brief Update Ethernet error statistics
751  * @param[in] interface Underlying network interface
752  * @param[in] error Status code describing the error
753  **/
754 
756 {
757  //Check error code
758  switch(error)
759  {
761  //Number of input datagrams discarded due to errors in their IP headers
762  MIB2_INC_COUNTER32(ipGroup.ipInHdrErrors, 1);
763  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsInHdrErrors, 1);
764  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsInHdrErrors, 1);
765  break;
767  //Number of input datagrams discarded because the destination IP address
768  //was not a valid address
769  MIB2_INC_COUNTER32(ipGroup.ipInAddrErrors, 1);
770  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsInAddrErrors, 1);
771  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsInAddrErrors, 1);
772  break;
774  //Number of locally-addressed datagrams received successfully but discarded
775  //because of an unknown or unsupported protocol
776  MIB2_INC_COUNTER32(ipGroup.ipInUnknownProtos, 1);
777  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsInUnknownProtos, 1);
778  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsInUnknownProtos, 1);
779  break;
781  //Number of input IP datagrams discarded because the datagram frame
782  //didn't carry enough data
783  IP_MIB_INC_COUNTER32(ipv4SystemStats.ipSystemStatsInTruncatedPkts, 1);
784  IP_MIB_INC_COUNTER32(ipv4IfStatsTable[interface->index].ipIfStatsInTruncatedPkts, 1);
785  break;
786  default:
787  //Just for sanity
788  break;
789  }
790 }
791 
792 #endif
An address assigned to an interface whose use is unrestricted.
Definition: ipv4.h:187
error_t ipv4CheckSourceAddr(NetInterface *interface, Ipv4Addr ipAddr)
Source IPv4 address filtering.
Definition: ipv4_misc.c:55
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:235
bool_t ipv4IsLocalHostAddr(Ipv4Addr ipAddr)
Check whether the specified IPv4 is assigned to the host.
Definition: ipv4_misc.c:468
Ipv4AddrState state
IPv4 address state.
Definition: ipv4.h:309
#define IP_MIB_INC_COUNTER64(name, value)
Definition: ip_mib_module.h:47
TCP/IP stack core.
bool_t ipv4IsOnLink(NetInterface *interface, Ipv4Addr ipAddr)
Check whether an IPv4 address is on-link.
Definition: ipv4_misc.c:351
Debugging facilities.
#define IPV4_MULTICAST_LNCB_MASK
Definition: ipv4.h:123
uint8_t p
Definition: ndp.h:297
#define IPV4_ADDR_LIST_SIZE
Definition: ipv4.h:63
error_t ipv4CheckDestAddr(NetInterface *interface, Ipv4Addr ipAddr)
Destination IPv4 address filtering.
Definition: ipv4_misc.c:79
MIB-II module.
Invalid parameter.
Definition: error.h:47
error_t ipv4GetBroadcastAddr(NetInterface *interface, Ipv4Addr *addr)
Get IPv4 broadcast address.
Definition: ipv4_misc.c:613
#define MIB2_INC_COUNTER32(name, value)
Definition: mib2_module.h:156
#define IPV4_MULTICAST_LNCB_PREFIX
Definition: ipv4.h:122
#define IPV4_LOOPBACK_ADDR_MASK
Definition: ipv4.h:111
error_t ipv4MapMulticastAddrToMac(Ipv4Addr ipAddr, MacAddr *macAddr)
Map an host group address to a MAC-layer multicast address.
Definition: ipv4_misc.c:636
uint_t refCount
Reference count for the current entry.
Definition: ipv4.h:323
void ipv4UpdateOutStats(NetInterface *interface, Ipv4Addr destIpAddr, size_t length)
Update IPv4 output statistics.
Definition: ipv4_misc.c:706
#define TRUE
Definition: os_port.h:50
#define IPV4_LINK_LOCAL_PREFIX
Definition: ipv4.h:114
uint8_t ipAddr[4]
Definition: mib_common.h:187
#define ntohl(value)
Definition: cpu_endian.h:399
uint8_t mask
Definition: web_socket.h:317
void ipv4UpdateInStats(NetInterface *interface, Ipv4Addr destIpAddr, size_t length)
Update IPv4 input statistics.
Definition: ipv4_misc.c:670
Ipv4Addr defaultGateway
Default gateway.
Definition: ipv4.h:312
Helper functions for IPv4.
void ipv4UpdateErrorStats(NetInterface *interface, error_t error)
Update Ethernet error statistics.
Definition: ipv4_misc.c:755
An address that is not assigned to any interface.
Definition: ipv4.h:185
#define NET_INTERFACE_COUNT
Definition: net.h:109
IPv4 (Internet Protocol Version 4)
Ipv4Addr addr
Multicast address.
Definition: ipv4.h:322
uint_t ipv4GetPrefixLength(Ipv4Addr mask)
Calculate prefix length for a given subnet mask.
Definition: ipv4_misc.c:587
IPv4 address entry.
Definition: ipv4.h:306
An address whose uniqueness on a link is being verified.
Definition: ipv4.h:186
NetInterface netInterface[NET_INTERFACE_COUNT]
Definition: net.c:75
Ipv4Addr subnetMask
Subnet mask.
Definition: ipv4.h:311
#define ipv4IsOnSubnet(entry, ipAddr)
Definition: ipv4.h:150
uint_t ipv4GetAddrScope(Ipv4Addr ipAddr)
Retrieve the scope of an IPv4 address.
Definition: ipv4_misc.c:523
IP MIB module.
Success.
Definition: error.h:44
bool_t ipv4IsBroadcastAddr(NetInterface *interface, Ipv4Addr ipAddr)
Check whether an IPv4 address is a broadcast address.
Definition: ipv4_misc.c:386
error_t
Error codes.
Definition: error.h:42
#define IPV4_LINK_LOCAL_MASK
Definition: ipv4.h:115
#define TRACE_WARNING(...)
Definition: debug.h:84
#define IP_MIB_INC_COUNTER32(name, value)
Definition: ip_mib_module.h:46
Ipv4Addr destIpAddr
Definition: ipcp.h:78
unsigned int uint_t
Definition: compiler_port.h:45
__start_packed struct @112 MacAddr
MAC address.
#define NetInterface
Definition: net.h:36
#define ipv4IsMulticastAddr(ipAddr)
Definition: ipv4.h:158
MacAddr srcAddr
Definition: ethernet.h:190
error_t ipv4SelectSourceAddr(NetInterface **interface, Ipv4Addr destAddr, Ipv4Addr *srcAddr)
IPv4 source address selection.
Definition: ipv4_misc.c:163
#define IPV4_UNSPECIFIED_ADDR
Definition: ipv4.h:104
#define IPV4_MULTICAST_FILTER_SIZE
Definition: ipv4.h:77
uint8_t length
Definition: dtls_misc.h:142
bool_t ipv4IsTentativeAddr(NetInterface *interface, Ipv4Addr ipAddr)
Check whether an IPv4 address is a tentative address.
Definition: ipv4_misc.c:432
Ipv4Addr addr
IPv4 address.
Definition: ipv4.h:308
IPv4 multicast filter entry.
Definition: ipv4.h:320
#define FALSE
Definition: os_port.h:46
#define IPV4_LOOPBACK_ADDR_PREFIX
Definition: ipv4.h:110
int bool_t
Definition: compiler_port.h:49
Ipv4Addr addr
Definition: nbns_common.h:121
MacAddr destAddr
Definition: ethernet.h:189
#define IPV4_BROADCAST_ADDR
Definition: ipv4.h:106