connectivity/networking/api/net_if.html · connectivity/networking/api/net_if.rst 공식 원문 ↗

Zephyr 3.7.0 · Connectivity · Networking API

Network Interface

Link-time interface가 driver와 stack을 연결하고 admin·carrier·dormant 상태로 readiness를 결정합니다.

Official pathconnectivity/networking/api/net_if.html
Source fileconnectivity/networking/api/net_if.rst
Source versionZephyr 3.7.0
TranslationFull · reviewed

본문 기준: Zephyr 3.7.0 LTS3 · 이후 유지보수 패치는 별도입니다.

Part 1

요약·해설

Interface 생성, default·IP·traffic class와 RFC 2863 administrative/operational state 계산을 설명합니다.

Creation

Link time

State

Admin · Carrier · Dormant

Ready

NET_IF_OPER_UP

Part 2

접을 수 있는 영어 원문 전체

영어 원문 전체 펼치기
원문 SHA-256 26C8D0B131E83C0EB33C81AFE2153615F30AE5C8775F8972B66BB5401C9E8470
.. _net_if_interface:

Network Interface
#################

.. contents::
    :local:
    :depth: 2

Overview
********

The network interface is a nexus that ties the network device drivers
and the upper part of the network stack together. All the sent and received
data is transferred via a network interface. The network interfaces cannot be
created at runtime. A special linker section will contain information about them
and that section is populated at linking time.

Network interfaces are created by ``NET_DEVICE_INIT()`` macro.
For Ethernet network, a macro called ``ETH_NET_DEVICE_INIT()`` should be used
instead as it will create VLAN interfaces automatically if
:kconfig:option:`CONFIG_NET_VLAN` is enabled. These macros are typically used in
network device driver source code.

The network interface can be turned ON by calling ``net_if_up()`` and OFF
by calling ``net_if_down()``. When the device is powered ON, the network
interface is also turned ON by default.

The network interfaces can be referenced either by a ``struct net_if *``
pointer or by a network interface index. The network interface can be
resolved from its index by calling ``net_if_get_by_index()`` and from interface
pointer by calling ``net_if_get_by_iface()``.

.. _net_if_interface_ip_management:

The IP address for network devices must be set for them to be connectable.
In a typical dynamic network environment, IP addresses are set automatically
by DHCPv4, for example. If needed though, the application can set a device's
IP address manually.  See the API documentation below for functions such as
``net_if_ipv4_addr_add()`` that do that.

The ``net_if_get_default()`` returns a *default* network interface. What
this default interface means can be configured via options like
:kconfig:option:`CONFIG_NET_DEFAULT_IF_FIRST` and
:kconfig:option:`CONFIG_NET_DEFAULT_IF_ETHERNET`.
See Kconfig file :zephyr_file:`subsys/net/ip/Kconfig` what options are available for
selecting the default network interface.

The transmitted and received network packets can be classified via a network
packet priority. This is typically done in Ethernet networks when virtual LANs
(VLANs) are used. Higher priority packets can be sent or received earlier than
lower priority packets. The traffic class setup can be configured by
:kconfig:option:`CONFIG_NET_TC_TX_COUNT` and :kconfig:option:`CONFIG_NET_TC_RX_COUNT` options.

If the :kconfig:option:`CONFIG_NET_PROMISCUOUS_MODE` is enabled and if the underlying
network technology supports promiscuous mode, then it is possible to receive
all the network packets that the network device driver is able to receive.
See :ref:`promiscuous_interface` API for more details.

.. _net_if_interface_state_management:

Network interface state management
**********************************

Zephyr distinguishes between two interface states: administrative state and
operational state, as described in RFC 2863. The administrative state indicate
whether an interface is turned ON or OFF. This state is represented by
:c:enumerator:`NET_IF_UP` flag and is controlled by the application. It can be
changed by calling :c:func:`net_if_up` or :c:func:`net_if_down` functions.
Network drivers or L2 implementations should not change administrative state on
their own.

Bringing an interface up however not always means that the interface is ready to
transmit packets. Because of that, operational state, which represents the
internal interface status, was implemented. The operational state is updated
whenever one of the following conditions take place:

  * The interface is brought up/down by the application (administrative state
    changes).
  * The interface is notified by the driver/L2 that PHY status has changed.
  * The interface is notified by the driver/L2 that it joined/left a network.

The PHY status is represented with :c:enumerator:`NET_IF_LOWER_UP` flag and can
be changed with :c:func:`net_if_carrier_on` and :c:func:`net_if_carrier_off`. By
default, the flag is set on a newly initialized interface. An example of an
event that changes the carrier state is Ethernet cable being plugged in or out.

The network association status is represented with :c:enumerator:`NET_IF_DORMANT`
flag and can be changed with :c:func:`net_if_dormant_on` and
:c:func:`net_if_dormant_off`. By default, the flag is cleared on a newly
initialized interface. An example of an event that changes the dormant state is
a Wi-Fi driver successfully connecting to an access point. In this scenario,
driver should set the dormant state to ON during initialization, and once it
detects that it connected to a Wi-Fi network, the dormant state should be set
to OFF.

The operational state of an interface is updated as follows:

  * ``!net_if_is_admin_up()``

    Interface is in :c:enumerator:`NET_IF_OPER_DOWN`.

  * ``net_if_is_admin_up() && !net_if_is_carrier_ok()``

    Interface is in :c:enumerator:`NET_IF_OPER_DOWN` or
    :c:enumerator:`NET_IF_OPER_LOWERLAYERDOWN` if the interface is stacked
    (virtual).

  * ``net_if_is_admin_up() && net_if_is_carrier_ok() && net_if_is_dormant()``

    Interface is in :c:enumerator:`NET_IF_OPER_DORMANT`.

  * ``net_if_is_admin_up() && net_if_is_carrier_ok() && !net_if_is_dormant()``

    Interface is in :c:enumerator:`NET_IF_OPER_UP`.

Only after an interface enters :c:enumerator:`NET_IF_OPER_UP` state the
:c:enumerator:`NET_IF_RUNNING` flag is set on the interface indicating that the
interface is ready to be used by the application.

API Reference
*************

.. doxygengroup:: net_if

Part 3

한국어 전문 번역

Network Interface

Overview

Network interface는 network device driver와 network stack 상위 부분을 연결하는 nexus입니다. 송수신 data는 모두 network interface를 통과합니다. Interface는 runtime에 만들 수 없고 link time에 채워지는 전용 linker section에 정보가 들어갑니다.

NET_DEVICE_INIT() macro로 network interface를 만듭니다. Ethernet은 CONFIG_NET_VLAN이 활성화된 경우 VLAN interface까지 자동 생성하는 ETH_NET_DEVICE_INIT()을 사용해야 합니다. 이 macro들은 일반적으로 network device driver source code에서 사용합니다.

net_if_up()으로 interface를 ON, net_if_down()으로 OFF로 전환합니다. Device power가 ON이면 network interface도 기본적으로 ON입니다.

struct net_if * pointer 또는 interface index로 network interface를 참조합니다. Index에서 interface를 얻을 때 net_if_get_by_index(), pointer에서 index를 얻을 때 net_if_get_by_iface()를 사용합니다.

IP management and traffic behavior

Network device가 연결 가능하려면 IP address를 설정해야 합니다. Dynamic network에서는 일반적으로 DHCPv4가 자동 설정하지만 필요하면 application이 net_if_ipv4_addr_add() 같은 함수로 수동 설정할 수 있습니다.

net_if_get_default()는 default network interface를 반환합니다. Default 의미는 CONFIG_NET_DEFAULT_IF_FIRST, CONFIG_NET_DEFAULT_IF_ETHERNET 같은 option으로 설정하며 전체 선택 option은 subsys/net/ip/Kconfig에 있습니다.

송수신 packet은 network packet priority로 분류할 수 있습니다. VLAN을 사용하는 Ethernet에서 흔하며 높은 priority packet을 먼저 처리할 수 있습니다. Traffic class 수는 CONFIG_NET_TC_TX_COUNT와 CONFIG_NET_TC_RX_COUNT로 설정합니다.

CONFIG_NET_PROMISCUOUS_MODE가 활성화되고 underlying network technology가 지원하면 device driver가 받을 수 있는 모든 packet을 수신할 수 있습니다. 자세한 내용은 promiscuous-mode API를 참고합니다.

Network interface state management

RFC 2863에 따라 administrative state와 operational state를 구분합니다. Administrative state는 interface ON/OFF를 나타내고 NET_IF_UP flag로 표현합니다. Application이 net_if_up()·net_if_down()으로 바꾸며 driver나 L2 implementation이 스스로 변경하면 안 됩니다.

Interface를 up으로 바꿨다고 packet 송신 준비가 끝난 것은 아닙니다. 내부 interface 상태를 나타내는 operational state는 다음 사건마다 갱신됩니다.

  • Application이 interface를 up/down해 administrative state가 바뀔 때
  • Driver/L2가 PHY status 변경을 interface에 알릴 때
  • Driver/L2가 network join/leave를 interface에 알릴 때

NET_IF_LOWER_UP은 PHY status를 나타내며 net_if_carrier_on()·net_if_carrier_off()으로 바꿉니다. 새 interface에서는 기본적으로 set됩니다. Ethernet cable 연결·해제가 carrier state 변경 예입니다.

NET_IF_DORMANT은 network association status를 나타내며 net_if_dormant_on()·net_if_dormant_off()으로 바꿉니다. 새 interface에서는 기본적으로 clear됩니다. Wi-Fi driver는 initialization 중 dormant를 ON으로 두고 access point connection 성공 후 OFF로 바꿔야 합니다.

Interface operational state는 다음 조건으로 결정됩니다.

  • !net_if_is_admin_up() → NET_IF_OPER_DOWN
  • net_if_is_admin_up() && !net_if_is_carrier_ok() → NET_IF_OPER_DOWN; stacked virtual interface면 NET_IF_OPER_LOWERLAYERDOWN
  • net_if_is_admin_up() && net_if_is_carrier_ok() && net_if_is_dormant() → NET_IF_OPER_DORMANT
  • net_if_is_admin_up() && net_if_is_carrier_ok() && !net_if_is_dormant() → NET_IF_OPER_UP

NET_IF_OPER_UP에 들어간 뒤에만 NET_IF_RUNNING flag가 set되어 application이 interface를 사용할 준비가 됐음을 나타냅니다.

API Reference

Doxygen group net_if가 API reference를 제공합니다.

Source

출처

영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.