netdeviceのヘルプ・マニュアル
日本語 英語
netdevice --help
man netdevice
NETDEVICE(7) Linux Programmer’s Manual NETDEVICE(7)
名前
netdevice - Linux ネットワークデバイスへの低レベルアクセス
書式
#include
#include
説明
この man ページでは、ネットワークデバイスを設定するために用いるソケット
インターフェースについて解説する。
Linux はネットワークデバイスを設定するための標準的な ioctl をいくつか備
え ている。これらはどんなソケットのファイルディスクリプタにも用いること
ができる。ファミリーやタイプは何でもよい。これらの ioctl は ifreq 構 造
体を渡す。
struct ifreq {
char ifr_name[IFNAMSIZ]; /* Interface name */
union {
struct sockaddr ifr_addr;
struct sockaddr ifr_dstaddr;
struct sockaddr ifr_broadaddr;
struct sockaddr ifr_netmask;
struct sockaddr ifr_hwaddr;
short ifr_flags;
int ifr_ifindex;
int ifr_metric;
int ifr_mtu;
struct ifmap ifr_map;
char ifr_slave[IFNAMSIZ];
char ifr_newname[IFNAMSIZ];
char *ifr_data;
};
};
struct ifconf {
int ifc_len; /* size of buffer */
union {
char *ifc_buf; /* buffer address */
struct ifreq *ifc_req; /* array of structures */
};
};
通 常、ユーザーによる設定対象デバイスの指定は、 ifr_name にインターフェ
ースの名前をセットすることによって行う。他の構造体の全てのメンバは、 メ
モリを共有する。
ioctl
「特権が必要」と記述されている ioctl を実行するには、実効ユーザー ID が
0 か、 CAP_NET_ADMIN 権限が必要である。これが満たされていな い 場 合 は
EPERM が返される。
SIOCGIFNAME
ifr_ifindex を受け取り、インターフェースの名前を ifr_name に入れ
て返す。これは結果を ifr_name として返す唯一の ioctl である。
SIOCGIFINDEX
インターフェースの interface index を取得し、 ifr_ifindex に入れ
て返す。
SIOCGIFFLAGS, SIOCSIFFLAGS
デ バ イスの active フラグワードを取得または設定する。 ifr_flags
には以下の値のビットマスクが入る。
デバイスフラグ
IFF_UP インターフェースは動作中。
IFF_BROADCAST 有効なブロードキャストアドレスがセットされている。
IFF_DEBUG 内部のデバッグフラグ。
IFF_LOOPBACK インターフェースはループバックである。
IFF_POINTOPOINT インターフェースは point-to-point リンクである。
IFF_RUNNING リソースが割り当て済み。
IFF_NOARP arp プロトコルがない。
IFF_PROMISC インターフェースは promiscuous モードである。
IFF_NOTRAILERS trailer の利用を避ける。
IFF_ALLMULTI 全てのマルチキャストパケットを受信する。
IFF_MASTER 負荷分散グループのマスターである。
IFF_SLAVE 負荷分散グループのスレーブである。
IFF_MULTICAST マルチキャストをサポートしている。
IFF_PORTSEL ifmap によってメディアタイプを選択できる。
IFF_AUTOMEDIA 自動メディア選択が有効になっている。
IFF_DYNAMIC このインターフェースが閉じると、アドレスは失われる
。
IFF_LOWER_UP ドライバからの L1 アップの通知 (Linux 2.6.17 以降)
IFF_DORMANT ドライバからの休止状態の通知 (Linux 2.6.17 以降)
IFF_ECHO 送られたパケットをエコーする (Linux 2.6.25 以降)
active フラグワードの設定は特権が必要な操作である。しかし読み 出
しはどんなプロセスからも可能である。
SIOCGIFMETRIC, SIOCSIFMETRIC
デバイスのメトリックを ifr_metric を用いて取得・設定する。これは
まだ実装されていない。読み出そうとすると ifr_metric に 0 をセ ッ
トして返り、設定しようとすると EOPNOTSUPP が返る。
SIOCGIFMTU, SIOCSIFMTU
デバイスの MTU (Maximum Transfer Unit) を ifr_mtu を用いて取得・
設定する。 MTU の設定は特権が必要な操作である。 MTU の値を小さく
しすぎるとカーネルがクラッシュするかもしれない。
SIOCGIFHWADDR, SIOCSIFHWADDR
デバイスのハードウェアアドレスを ifr_hwaddr を用いて取得・設定す
る。ハードウェアアドレスは sockaddr 構造体に設定される。 sa_fam-
ily には ARPHRD_* デバイスタイプが入り、 sa_data にはバイト 0 か
ら始まる L2 ハードウェアアドレスが入る。ハードウェアアドレスの設
定は特権が必要な操作である。
SIOCSIFHWBROADCAST
デバイスのハードウェアブロードキャストアドレスを ifr_hwaddr の値
に設定する。この操作には特権が必要である。
SIOCGIFMAP, SIOCSIFMAP
インターフェースのハードウェアのパラメータを ifr_map を用いて 取
得・設定する。パラメータの設定は特権が必要な操作である。
struct ifmap {
unsigned long mem_start;
unsigned long mem_end;
unsigned short base_addr;
unsigned char irq;
unsigned char dma;
unsigned char port;
};
ifmap 構造体の解釈はデバイスドライバとアーキテクチャに依存する。
SIOCADDMULTI, SIOCDELMULTI
デバイスのリンク層のマルチキャストフィルターから、 ifr_hwaddr の
アドレスを追加・削除する。これらの操作には特権が必要である。別の
方法が packet(7) で解説されている。
SIOCGIFTXQLEN, SIOCSIFTXQLEN
デバイスの送信キューの長さを ifr_qlen に取得・設定する。送信キュ
ーの長さの設定には特権が必要である。
SIOCSIFNAME
ifr_name で指定したインターフェースの名前を ifr_newname に変更す
る。この操作には特権が必要である。インターフェースが up していな
い時にのみ使用できる。
SIOCGIFCONF
インターフェース(トランスポート層)アドレスのリストを返す。現在の
ところ、互換性のために AF_INET (IPv4) ファミリーのアドレスのみで
ある。ユーザーは ifconf 構造体を ioctl の引数として渡す。 ifconf
構造体には、 ifreq 構造体の配列へのポインタである ifc_req と、バ
イ ト 単 位の配列の長さを指定する ifc_len が含まれる。カーネルは
ifreqs を現在動作している全ての L3 インターフェースアドレスで 埋
め る 。 ifr_name にはインターフェース名 (eth0:1 など) が入り、
ifr_addr にはアドレスが入る。カーネルは実際の長さを ifc_len に返
す 。 ifc_len が元のバッファの長さと同じだった場合、オーバーフロ
ーを起こしている可能性があるので、全てのアドレスを取得するために
より大きなバッファで再試行するべきである。エラーがなかった場合は
ioctl は 0 を返す。エラーがあった場合は -1 を返す。オーバーフ ロ
ーはエラーとは見なされない。
ほ とんどのプロトコルには、専用のインターフェースオプションを設定するた
めの独自の ioctl が存在する。説明は各プロトコルの man ページを見よ。
さらに、デバイスによってはプライベートな ioctl がある。これらはここでは
説明しない。
注意
厳密にいうと、 SIOCGIFCONF は IP 固有であり、 ip(7) に属する。
アドレスがなかったり、 IFF_RUNNING フラグがセットされていないインターフ
ェースの名前は /proc/net/dev で知ることができる。
ローカル IPV6 IP アドレスは /proc/net か rtnetlink(7) で知ることがで き
る。
バグ
glibc 2.1 では に ifr_newname マクロがない。とりあえずの対応
策として、以下のコードを追加しておくこと。
#ifndef ifr_newname
#define ifr_newname ifr_ifru.ifru_slave
#endif
関連項目
proc(5), capabilities(7), ip(7), rtnetlink(7)
Linux 2009-01-14 NETDEVICE(7)
NETDEVICE(7) Linux Programmer’s Manual NETDEVICE(7)
NAME
netdevice - Low level access to Linux network devices
SYNOPSIS
#include
#include
DESCRIPTION
This man page describes the sockets interface which is used to config-
ure network devices.
Linux supports some standard ioctls to configure network devices. They
can be used on any socket’s file descriptor regardless of the family or
type. They pass an ifreq structure:
struct ifreq {
char ifr_name[IFNAMSIZ]; /* Interface name */
union {
struct sockaddr ifr_addr;
struct sockaddr ifr_dstaddr;
struct sockaddr ifr_broadaddr;
struct sockaddr ifr_netmask;
struct sockaddr ifr_hwaddr;
short ifr_flags;
int ifr_ifindex;
int ifr_metric;
int ifr_mtu;
struct ifmap ifr_map;
char ifr_slave[IFNAMSIZ];
char ifr_newname[IFNAMSIZ];
char *ifr_data;
};
};
struct ifconf {
int ifc_len; /* size of buffer */
union {
char *ifc_buf; /* buffer address */
struct ifreq *ifc_req; /* array of structures */
};
};
Normally, the user specifies which device to affect by setting ifr_name
to the name of the interface. All other members of the structure may
share memory.
Ioctls
If an ioctl is marked as privileged then using it requires an effective
user ID of 0 or the CAP_NET_ADMIN capability. If this is not the case
EPERM will be returned.
SIOCGIFNAME
Given the ifr_ifindex, return the name of the interface in
ifr_name. This is the only ioctl which returns its result in
ifr_name.
SIOCGIFINDEX
Retrieve the interface index of the interface into ifr_ifindex.
SIOCGIFFLAGS, SIOCSIFFLAGS
Get or set the active flag word of the device. ifr_flags con-
tains a bit mask of the following values:
Device flags
IFF_UP Interface is running.
IFF_BROADCAST Valid broadcast address set.
IFF_DEBUG Internal debugging flag.
IFF_LOOPBACK Interface is a loopback interface.
IFF_POINTOPOINT Interface is a point-to-point link.
IFF_RUNNING Resources allocated.
IFF_NOARP No arp protocol, L2 destination address not set.
IFF_PROMISC Interface is in promiscuous mode.
IFF_NOTRAILERS Avoid use of trailers.
IFF_ALLMULTI Receive all multicast packets.
IFF_MASTER Master of a load balancing bundle.
IFF_SLAVE Slave of a load balancing bundle.
IFF_MULTICAST Supports multicast
IFF_PORTSEL Is able to select media type via ifmap.
IFF_AUTOMEDIA Auto media selection active.
IFF_DYNAMIC The addresses are lost when the interface goes
down.
IFF_LOWER_UP Driver signals L1 up (since Linux 2.6.17)
IFF_DORMANT Driver signals dormant (since Linux 2.6.17)
IFF_ECHO Echo sent packets (since Linux 2.6.25)
Setting the active flag word is a privileged operation, but any
process may read it.
SIOCGIFMETRIC, SIOCSIFMETRIC
Get or set the metric of the device using ifr_metric. This is
currently not implemented; it sets ifr_metric to 0 if you
attempt to read it and returns EOPNOTSUPP if you attempt to set
it.
SIOCGIFMTU, SIOCSIFMTU
Get or set the MTU (Maximum Transfer Unit) of a device using
ifr_mtu. Setting the MTU is a privileged operation. Setting
the MTU to too small values may cause kernel crashes.
SIOCGIFHWADDR, SIOCSIFHWADDR
Get or set the hardware address of a device using ifr_hwaddr.
The hardware address is specified in a struct sockaddr. sa_fam-
ily contains the ARPHRD_* device type, sa_data the L2 hardware
address starting from byte 0. Setting the hardware address is a
privileged operation.
SIOCSIFHWBROADCAST
Set the hardware broadcast address of a device from ifr_hwaddr.
This is a privileged operation.
SIOCGIFMAP, SIOCSIFMAP
Get or set the interface’s hardware parameters using ifr_map.
Setting the parameters is a privileged operation.
struct ifmap {
unsigned long mem_start;
unsigned long mem_end;
unsigned short base_addr;
unsigned char irq;
unsigned char dma;
unsigned char port;
};
The interpretation of the ifmap structure depends on the device
driver and the architecture.
SIOCADDMULTI, SIOCDELMULTI
Add an address to or delete an address from the device’s link
layer multicast filters using ifr_hwaddr. These are privileged
operations. See also packet(7) for an alternative.
SIOCGIFTXQLEN, SIOCSIFTXQLEN
Get or set the transmit queue length of a device using ifr_qlen.
Setting the transmit queue length is a privileged operation.
SIOCSIFNAME
Changes the name of the interface specified in ifr_name to
ifr_newname. This is a privileged operation. It is only
allowed when the interface is not up.
SIOCGIFCONF
Return a list of interface (transport layer) addresses. This
currently means only addresses of the AF_INET (IPv4) family for
compatibility. The user passes a ifconf structure as argument
to the ioctl. It contains a pointer to an array of ifreq struc-
tures in ifc_req and its length in bytes in ifc_len. The kernel
fills the ifreqs with all current L3 interface addresses that
are running: ifr_name contains the interface name (eth0:1 etc.),
ifr_addr the address. The kernel returns with the actual length
in ifc_len. If ifc_len is equal to the original length the
buffer probably has overflowed and you should retry with a big-
ger buffer to get all addresses. When no error occurs the ioctl
returns 0; otherwise -1. Overflow is not an error.
Most protocols support their own ioctls to configure protocol-specific
interface options. See the protocol man pages for a description. For
configuring IP addresses see ip(7).
In addition some devices support private ioctls. These are not
described here.
NOTES
Strictly speaking, SIOCGIFCONF is IP specific and belongs in ip(7).
The names of interfaces with no addresses or that don’t have the
IFF_RUNNING flag set can be found via /proc/net/dev.
Local IPv6 IP addresses can be found via /proc/net or via rtnetlink(7).
BUGS
glibc 2.1 is missing the ifr_newname macro in . Add the fol-
lowing to your program as a workaround:
#ifndef ifr_newname
#define ifr_newname ifr_ifru.ifru_slave
#endif
SEE ALSO
proc(5), capabilities(7), ip(7), rtnetlink(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2009-01-14 NETDEVICE(7)