22 #ifndef LELY_IO2_INTERN_LINUX_IF_H_
23 #define LELY_IO2_INTERN_LINUX_IF_H_
35 static int io_if_get_txqlen(
36 unsigned short ifi_type,
int ifi_index, __u32 *ptxqlen);
37 static int io_if_set_txqlen(
38 unsigned short ifi_type,
int ifi_index, __u32 txqlen);
39 static int io_if_get_txqlen_parse(
struct nlmsghdr *nlh,
size_t len,
void *arg);
42 io_if_get_txqlen(
unsigned short ifi_type,
int ifi_index, __u32 *ptxqlen)
47 if (rtnl_open(&rth) == -1) {
52 if (rtnl_send_getlink_request(&rth, AF_UNSPEC, ifi_type, ifi_index)
55 goto error_rtnl_send_getlink_request;
59 unsigned short ifi_type;
60 unsigned int ifi_flags;
62 } arg = { ifi_type, 0, 0 };
63 if (rtnl_recv_type(&rth, RTM_NEWLINK, &io_if_get_txqlen_parse, &arg)
66 goto error_rtnl_recv_type;
70 *ptxqlen = arg.txqlen;
76 error_rtnl_send_getlink_request:
84 io_if_set_txqlen(
unsigned short ifi_type,
int ifi_index, __u32 txqlen)
89 if (rtnl_open(&rth) == -1) {
94 if (rtnl_send_getlink_request(&rth, AF_UNSPEC, ifi_type, ifi_index)
97 goto error_rtnl_send_getlink_request;
101 unsigned short ifi_type;
102 unsigned int ifi_flags;
104 } arg = { ifi_type, 0, 0 };
105 if (rtnl_recv_type(&rth, RTM_NEWLINK, &io_if_get_txqlen_parse, &arg)
108 goto error_rtnl_recv_type;
111 if (arg.txqlen < txqlen) {
113 struct rtattr *rta = (
struct rtattr *)buf;
114 *rta = (
struct rtattr){ .rta_len = RTA_LENGTH(
sizeof(__u32)),
115 .rta_type = IFLA_TXQLEN };
116 *(__u32 *)RTA_DATA(rta) = txqlen;
119 if (rtnl_send_newlink_request(&rth, AF_UNSPEC, ifi_type,
120 ifi_index, arg.ifi_flags, rta,
121 RTA_ALIGN(rta->rta_len)) == -1) {
124 goto error_rtnl_send_newlink_request;
127 if (rtnl_recv_ack(&rth) == -1) {
129 goto error_rtnl_recv_ack;
137 error_rtnl_send_newlink_request:
138 error_rtnl_recv_type:
139 error_rtnl_send_getlink_request:
147 io_if_get_txqlen_parse(
struct nlmsghdr *nlh,
size_t len,
void *arg_)
150 assert(NLMSG_OK(nlh, len));
151 assert(nlh->nlmsg_type == RTM_NEWLINK);
153 unsigned short ifi_type;
154 unsigned int ifi_flags;
159 struct ifinfomsg *ifi = NLMSG_DATA(nlh);
160 if (ifi->ifi_type != arg->ifi_type) {
165 arg->ifi_flags = ifi->ifi_flags;
168 rta_find(IFLA_RTA(ifi), IFLA_PAYLOAD(nlh), IFLA_TXQLEN);
169 if (!rta || RTA_PAYLOAD(rta) <
sizeof(__u32)) {
174 arg->txqlen = *(__u32 *)RTA_DATA(rta);
This is the internal header file of the rtnetlink functions.
This is the internal header file of the Windows-specific I/O declarations.