Projectname large_stringclasses 15
values | Filepath large_stringlengths 4 106 ⌀ | Function large_stringlengths 11 3.45k | Label list |
|---|---|---|---|
Linux Kernel | tools/testing/selftests/net/nettest.c |
static void set_recv_attr(int sd, int version) {
if (version == AF_INET6) {
set_recvpktinfo_v6(sd);
set_recverr_v6(sd);
} else {
set_pktinfo_v4(sd);
set_recverr_v4(sd);
}
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/nettest.c | static int msg_loop(int client, int sd, void *addr, socklen_t alen,
struct sock_args *args) {
struct timeval timeout = {.tv_sec = prog_timeout}, *ptval = NULL;
fd_set rfds;
int nfds;
int rc;
if (args->type != SOCK_STREAM)
set_recv_attr(sd, args->version);
if (msg) {
msglen = st... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/nettest.c |
static int msock_server(struct sock_args *args) { return msock_init(args, 1); } | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/nettest.c |
static int msock_client(struct sock_args *args) { return msock_init(args, 0); } | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/nettest.c |
static int bind_socket(int sd, struct sock_args *args) {
struct sockaddr_in serv_addr = {
.sin_family = AF_INET,
};
struct sockaddr_in6 serv6_addr = {
.sin6_family = AF_INET6,
};
void *addr;
socklen_t alen;
if (!args->has_local_ip && args->type == SOCK_RAW)
return 0;
switch (args->ver... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/nettest.c |
static int lsock_init(struct sock_args *args) {
long flags;
int sd;
sd = socket(args->version, args->type, args->protocol);
if (sd < 0) {
log_err_errno("Error opening socket");
return -1;
}
if (set_reuseaddr(sd) != 0)
goto err;
if (set_reuseport(sd) != 0)
goto err;
if (args->dev && ... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/nettest.c | static void ipc_write(int fd, int message) {
if (fd < 0)
return;
if (write(fd, &message, sizeof(message)) < 0)
log_err_errno("Failed to send client status");
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_fanout.c | static void sock_fanout_set_cbpf(int fd) {
struct sock_filter bpf_filter[] = {
BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 80),
BPF_STMT(BPF_RET | BPF_A, 0), /* ret A */
};
struct sock_fprog bpf_prog;
bpf_prog.filter = bpf_filter;
bpf_prog.len = ARRAY_SIZE(bpf_filter);
if (setsockopt(fd, SOL_PACKET, PA... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_fanout.c |
static void sock_fanout_getopts(int fd, uint16_t *typeflags,
uint16_t *group_id) {
int sockopt;
socklen_t sockopt_len = sizeof(sockopt);
if (getsockopt(fd, SOL_PACKET, PACKET_FANOUT, &sockopt, &sockopt_len)) {
perror("failed to getsockopt");
exit(1);
}
*typeflags = so... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_fanout.c | static void test_control_single(void) {
fprintf(stderr, "test: control single socket\n");
if (sock_fanout_open(PACKET_FANOUT_ROLLOVER | PACKET_FANOUT_FLAG_ROLLOVER,
0) != -1) {
fprintf(stderr, "ERROR: opened socket with dual rollover\n");
exit(1);
}
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_fanout.c | static void test_control_group_max_num_members(void) {
int fds[3];
fprintf(stderr, "test: control multiple sockets, max_num_members\n");
cfg_max_num_members = (1 << 16) + 1;
if (sock_fanout_open(PACKET_FANOUT_HASH, 0) != -1) {
fprintf(stderr, "ERROR: max_num_members > PACKET_FANOUT_MAX\n");
exit(1);
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_snd.c |
static unsigned long add_csum_hword(const uint16_t *start, int num_u16) {
unsigned long sum = 0;
int i;
for (i = 0; i < num_u16; i++)
sum += start[i];
return sum;
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_snd.c |
static int build_ipv4_header(void *header, int payload_len) {
struct iphdr *iph = header;
iph->ihl = 5;
iph->version = 4;
iph->ttl = 8;
iph->tot_len = htons(sizeof(*iph) + sizeof(struct udphdr) + payload_len);
iph->id = htons(1337);
iph->protocol = IPPROTO_UDP;
iph->saddr = htonl((172 << 24) | (17 << ... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_snd.c |
static int build_packet(int payload_len) {
int off = 0;
off += build_vnet_header(tbuf);
off += build_eth_header(tbuf + off);
off += build_ipv4_header(tbuf + off, payload_len);
off += build_udp_header(tbuf + off, payload_len);
if (off + payload_len > sizeof(tbuf))
error(1, 0, "payload length exceeds m... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_snd.c |
static void do_rx(int fd, int expected_len, char *expected) {
int ret;
ret = recv(fd, rbuf, sizeof(rbuf), 0);
if (ret == -1)
error(1, errno, "recv");
if (ret != expected_len)
error(1, 0, "recv: %u != %u", ret, expected_len);
if (memcmp(rbuf, expected, ret))
error(1, 0, "recv: data mismatch");
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_snd.c |
static void parse_opts(int argc, char **argv) {
int c;
while ((c = getopt(argc, argv, "bcCdgl:qt:vV")) != -1) {
switch (c) {
case 'b':
cfg_use_bind = true;
break;
case 'c':
cfg_use_csum_off = true;
break;
case 'C':
cfg_use_csum_off_bad = true;
break;
case 'd... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
static void test_payload(void *pay, size_t len) {
struct ethhdr *eth = pay;
if (len < sizeof(struct ethhdr)) {
fprintf(stderr,
"test_payload: packet too "
"small: %zu bytes!\n",
len);
exit(1);
}
if (eth->h_proto != htons(ETH_P_IP)) {
fprintf(stderr,
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
static inline void __v1_tx_user_ready(struct tpacket_hdr *hdr) {
hdr->tp_status = TP_STATUS_SEND_REQUEST;
__sync_synchronize();
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
static inline void __v2_tx_user_ready(struct tpacket2_hdr *hdr) {
hdr->tp_status = TP_STATUS_SEND_REQUEST;
__sync_synchronize();
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
static inline int __tx_kernel_ready(void *base, int version) {
switch (version) {
case TPACKET_V1:
return __v1_tx_kernel_ready(base);
case TPACKET_V2:
return __v2_tx_kernel_ready(base);
case TPACKET_V3:
return __v3_tx_kernel_ready(base);
default:
bug_on(1);
return 0;
}
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
static void __v1_v2_set_packet_loss_discard(int sock) {
int ret, discard = 1;
ret = setsockopt(sock, SOL_PACKET, PACKET_LOSS, (void *)&discard,
sizeof(discard));
if (ret == -1) {
perror("setsockopt");
exit(1);
}
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
void __v3_test_block_seq_num(struct block_desc *pbd) {
if (__v3_prev_block_seq_num + 1 != pbd->h1.seq_num) {
fprintf(stderr,
"\nprev_block_seq_num:%" PRIu64 ", expected "
"seq:%" PRIu64 " != actual seq:%" PRIu64 "\n",
__v3_prev_block_seq_num, __v3_prev_block_seq_num + 1,
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
static void walk_v3_rx(int sock, struct ring *ring) {
unsigned int block_num = 0;
struct pollfd pfd;
struct block_desc *pbd;
int udp_sock[2];
bug_on(ring->type != PACKET_RX_RING);
pair_udp_open(udp_sock, PORT_BASE);
memset(&pfd, 0, sizeof(pfd));
pfd.fd = sock;
pfd.events = POLLIN | POLLERR;
pfd.... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/psock_tpacket.c |
static int test_tpacket(int version, int type) {
int sock;
struct ring ring;
fprintf(stderr, "test: %s with %s ", tpacket_str[version], type_str[type]);
fflush(stderr);
if (version == TPACKET_V1 &&
test_kernel_bit_width() != test_user_bit_width()) {
fprintf(stderr,
"test: skip %s %s s... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseaddr_conflict.c |
int open_port(int ipv6, int any) {
int fd = -1;
int reuseaddr = 1;
int v6only = 1;
int addrlen;
int ret = -1;
struct sockaddr *addr;
int family = ipv6 ? AF_INET6 : AF_INET;
struct sockaddr_in6 addr6 = {.sin6_family = AF_INET6,
.sin6_port = htons(PORT),
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_addr_any.c |
static void test(int *rcv_fds, int count, int family, int proto, int fd) {
struct epoll_event ev;
int epfd, i, send_fd, recv_fd;
epfd = epoll_create(1);
if (epfd < 0)
error(1, errno, "failed to create epoll");
ev.events = EPOLLIN;
for (i = 0; i < count; ++i) {
ev.data.fd = rcv_fds[i];
if (epo... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_addr_any.c |
int main(void) {
test_proto(SOCK_DGRAM, "UDP");
test_proto(SOCK_STREAM, "TCP");
test_proto(SOCK_DCCP, "DCCP");
fprintf(stderr, "SUCCESS\n");
return 0;
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_bpf.c |
static size_t sockaddr_size(void) { return sizeof(struct sockaddr_storage); } | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_bpf.c |
static void test_reuseport_cbpf(struct test_params p) {
int i, fd[p.recv_socks];
fprintf(stderr, "Testing CBPF mod %zd...\n", p.recv_socks);
build_recv_group(p, fd, p.recv_socks, attach_cbpf);
test_recv_order(p, fd, p.recv_socks);
p.send_port_min += p.recv_socks * 2;
fprintf(stderr, "Reprograming, testin... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_bpf.c |
static void test_extra_filter(const struct test_params p) {
struct sockaddr *const addr = new_any_sockaddr(p.recv_family, p.recv_port);
int fd1, fd2, opt;
fprintf(stderr, "Testing too many filters...\n");
fd1 = socket(p.recv_family, p.protocol, 0);
if (fd1 < 0)
error(1, errno, "failed to create socket 1... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_bpf_cpu.c |
static void build_rcv_group(int *rcv_fd, size_t len, int family, int proto) {
struct sockaddr_storage addr;
struct sockaddr_in *addr4;
struct sockaddr_in6 *addr6;
size_t i;
int opt;
switch (family) {
case AF_INET:
addr4 = (struct sockaddr_in *)&addr;
addr4->sin_family = AF_INET;
addr4->sin_a... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_bpf_cpu.c |
static void receive_on_cpu(int *rcv_fd, int len, int epfd, int cpu_id,
int proto) {
struct epoll_event ev;
int i, fd;
char buf[8];
i = epoll_wait(epfd, &ev, 1, -1);
if (i < 0)
error(1, errno, "epoll_wait failed");
if (proto == SOCK_STREAM) {
fd = accept(ev.data.fd, NULL... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_bpf_cpu.c |
int main(void) {
int *rcv_fd, cpus;
cpus = sysconf(_SC_NPROCESSORS_ONLN);
if (cpus <= 0)
error(1, errno, "failed counting cpus");
rcv_fd = calloc(cpus, sizeof(int));
if (!rcv_fd)
error(1, 0, "failed to allocate array");
fprintf(stderr, "---- IPv4 UDP ----\n");
test(rcv_fd, cpus, AF_INET, SOCK_... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_bpf_numa.c | static void test(int *rcv_fd, int len, int family, int proto) {
struct epoll_event ev;
int epfd, node;
build_rcv_group(rcv_fd, len, family, proto);
attach_bpf(rcv_fd[0]);
epfd = epoll_create(1);
if (epfd < 0)
error(1, errno, "failed to create epoll");
for (node = 0; node < len; ++node) {
ev.even... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_dualstack.c |
static void send_from_v4(int proto) {
struct sockaddr_in saddr, daddr;
int fd;
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
saddr.sin_port = 0;
daddr.sin_family = AF_INET;
daddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
daddr.sin_port = htons(PORT);
fd = socket(AF_INET, p... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/reuseport_dualstack.c |
static int receive_once(int epfd, int proto) {
struct epoll_event ev;
int i, fd;
char buf[8];
i = epoll_wait(epfd, &ev, 1, -1);
if (i < 0)
error(1, errno, "epoll_wait failed");
if (proto == SOCK_STREAM) {
fd = accept(ev.data.fd, NULL, NULL);
if (fd < 0)
error(1, errno, "failed to accept... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/rxtimestamp.c |
void config_so_flags(int rcv, struct options o) {
int on = 1;
if (setsockopt(rcv, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0)
error(1, errno, "Failed to enable SO_REUSEADDR");
if (o.so_timestamp && setsockopt(rcv, SOL_SOCKET, SO_TIMESTAMP,
&o.so_timestamp, sizeof(o.so... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/sctp_hello.c |
static int do_client(int argc, char *argv[]) {
struct sockaddr_storage ss;
char buf[] = "hello";
int csk, ret, len;
if (argc < 5) {
printf("%s client -4|6 IP PORT [IP PORT]\n", argv[0]);
return -1;
}
bzero((void *)&ss, sizeof(ss));
ss.ss_family = !strcmp(argv[2], "-4") ? AF_INET : AF_INET6;
c... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/sk_connect_zero_addr.c |
int main(void) {
int fd1, fd2, one = 1;
struct sockaddr_in6 bind_addr = {
.sin6_family = AF_INET6,
.sin6_port = htons(20000),
.sin6_flowinfo = htonl(0),
.sin6_addr = {},
.sin6_scope_id = 0,
};
inet_pton(AF_INET6, "::", &bind_addr.sin6_addr);
fd1 = socket(AF_INET6, SOCK_STREAM,... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/socket.c |
int main(void) {
int err = run_tests();
return err;
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/so_incoming_cpu.c |
void set_so_incoming_cpu(struct __test_metadata *_metadata, int fd, int cpu) {
int ret;
ret = setsockopt(fd, SOL_SOCKET, SO_INCOMING_CPU, &cpu, sizeof(int));
ASSERT_EQ(ret, 0);
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/so_netns_cookie.c |
int main(int argc, char *argvp[]) {
uint64_t cookie1, cookie2;
socklen_t vallen;
int sock1, sock2;
sock1 = socket(AF_INET, SOCK_STREAM, 0);
if (sock1 < 0)
return pr_err("Unable to create TCP socket");
vallen = sizeof(cookie1);
if (getsockopt(sock1, SOL_SOCKET, SO_NETNS_COOKIE, &cookie1, &vallen) !=... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/so_txtime.c |
static uint64_t gettime_ns(clockid_t clock) {
struct timespec ts;
if (clock_gettime(clock, &ts))
error(1, errno, "gettime");
return ts.tv_sec * (1000ULL * 1000 * 1000) + ts.tv_nsec;
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/so_txtime.c |
static void do_recv_one(int fdr, struct timed_send *ts) {
int64_t tstop, texpect;
char rbuf[2];
int ret;
ret = recv(fdr, rbuf, sizeof(rbuf), 0);
if (ret == -1 && errno == EAGAIN)
error(1, EAGAIN, "recv: timeout");
if (ret == -1)
error(1, errno, "read");
if (ret != 1)
error(1, 0, "read: %dB",... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/so_txtime.c |
static void do_recv_verify_empty(int fdr) {
char rbuf[1];
int ret;
ret = recv(fdr, rbuf, sizeof(rbuf), 0);
if (ret != -1 || errno != EAGAIN)
error(1, 0, "recv: not empty as expected (%d, %d)", ret, errno);
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/so_txtime.c |
static void setsockopt_txtime(int fd) {
struct sock_txtime so_txtime_val = {.clockid = cfg_clockid};
struct sock_txtime so_txtime_val_read = {0};
socklen_t vallen = sizeof(so_txtime_val);
so_txtime_val.flags = SOF_TXTIME_REPORT_ERRORS;
if (setsockopt(fd, SOL_SOCKET, SO_TXTIME, &so_txtime_val,
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/so_txtime.c |
static void do_test_tx(struct sockaddr *addr, socklen_t alen) {
int fdt, i;
fprintf(stderr, "\nSO_TXTIME ipv%c clock %s\n",
addr->sa_family == PF_INET ? '4' : '6',
cfg_clockid == CLOCK_TAI ? "tai" : "monotonic");
fdt = setup_tx(addr, alen);
start_time_wait();
glob_tstart = gettime_ns(c... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/so_txtime.c |
static void do_test_rx(struct sockaddr *addr, socklen_t alen) {
int fdr, i;
fdr = setup_rx(addr, alen);
start_time_wait();
glob_tstart = gettime_ns(cfg_clockid);
for (i = 0; i < cfg_num_pkt; i++)
do_recv_one(fdr, &cfg_buf[i]);
do_recv_verify_empty(fdr);
if (close(fdr))
error(1, errno, "close... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/so_txtime.c |
static void usage(const char *progname) {
fprintf(stderr,
"\nUsage: %s [options] <payload>\n"
"Options:\n"
" -4 only IPv4\n"
" -6 only IPv6\n"
" -c <clock> monotonic or tai (default)\n"
" -D <addr> destination IP address (se... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
static struct rtattr *rtattr_begin(struct nlmsghdr *nh, unsigned short type) {
return rtattr_add(nh, type, 0);
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
static void rtattr_end(struct nlmsghdr *nh, struct rtattr *attr) {
uint8_t *end = (uint8_t *)nh + nh->nlmsg_len;
attr->rta_len = end - (uint8_t *)attr;
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
static int dev_create(const char *dev, const char *link_type,
int (*fill_rtattr)(struct nlmsghdr *nh),
int (*fill_info_data)(struct nlmsghdr *nh)) {
struct {
struct nlmsghdr nh;
struct ifinfomsg info;
unsigned char data[MAX_RTNL_PAYLOAD];
} req;
struct rtat... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
static int macvtap_fill_rtattr(struct nlmsghdr *nh) {
int ifindex;
ifindex = if_nametoindex(param_dev_dummy_name);
if (ifindex == 0) {
fprintf(stderr, "%s: ifindex %s\n", __func__, strerror(errno));
return -errno;
}
rtattr_add_any(nh, IFLA_LINK, &ifindex, sizeof(ifindex));
rtattr_add_any(nh, IFL... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
static uint32_t add_csum(const uint8_t *buf, int len) {
uint32_t sum = 0;
uint16_t *sbuf = (uint16_t *)buf;
while (len > 1) {
sum += *sbuf++;
len -= 2;
}
if (len)
sum += *(uint8_t *)sbuf;
return sum;
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
static uint16_t finish_ip_csum(uint32_t sum) {
uint16_t lo = sum & 0xffff;
uint16_t hi = sum >> 16;
return ~(lo + hi);
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
static uint16_t build_ip_csum(const uint8_t *buf, int len, uint32_t sum) {
sum += add_csum(buf, len);
return finish_ip_csum(sum);
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/tap.c |
size_t build_test_packet_crash_tap_invalid_eth_proto(uint8_t *buf,
size_t payload_len) {
uint8_t *cur = buf;
struct virtio_net_hdr *vh = (struct virtio_net_hdr *)buf;
vh->hdr_len = ETH_HLEN + sizeof(struct iphdr) + sizeof(struct udphdr);
vh->flags = 0;
vh... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tcp_fastopen_backup_key.c |
static void get_keys(int fd, uint32_t *keys) {
char buf[128];
socklen_t len = KEY_LENGTH * 2;
if (do_sockopt) {
if (getsockopt(fd, SOL_TCP, TCP_FASTOPEN_KEY, keys, &len))
error(1, errno, "Unable to get key");
return;
}
lseek(proc_fd, 0, SEEK_SET);
if (read(proc_fd, buf, sizeof(buf)) <= 0)
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tcp_fastopen_backup_key.c |
static void set_keys(int fd, uint32_t *keys) {
char buf[128];
if (do_sockopt) {
if (setsockopt(fd, SOL_TCP, TCP_FASTOPEN_KEY, keys, key_len))
error(1, errno, "Unable to set key");
return;
}
if (do_rotate)
snprintf(buf, 128, "%08x-%08x-%08x-%08x,%08x-%08x-%08x-%08x", keys[0],
key... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tcp_fastopen_backup_key.c | static void rotate_key(int fd) {
static int iter;
static uint32_t new_key[4];
uint32_t keys[8];
uint32_t tmp_key[4];
int i;
if (iter < N_LISTEN) {
if (iter == 0) {
for (i = 0; i < ARRAY_SIZE(new_key); i++)
new_key[i] = rand();
}
get_keys(fd, keys);
memcpy(keys + 4, new_key, K... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tcp_fastopen_backup_key.c |
static void run_one_test(int family) {
struct epoll_event ev;
int i, send_fd;
int n_loops = 10000;
int rotate_key_fd = 0;
int key_rotate_interval = 50;
int fd, epfd;
char buf[1];
build_rcv_fd(family, SOCK_STREAM, rcv_fds);
epfd = epoll_create(1);
if (epfd < 0)
error(1, errno, "failed to create... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tcp_fastopen_backup_key.c |
static void parse_opts(int argc, char **argv) {
int c;
while ((c = getopt(argc, argv, "46sr")) != -1) {
switch (c) {
case '4':
do_ipv6 = false;
break;
case '6':
do_ipv6 = true;
break;
case 's':
do_sockopt = true;
break;
case 'r':
do_rotate = true;
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tcp_mmap.c |
static inline void prefetch(const void *x) {
#if defined(__x86_64__)
asm volatile("prefetcht0 %P0" : : "m"(*(const char *)x));
#endif
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/tcp_mmap.c | static unsigned long default_huge_page_size(void) {
FILE *f = fopen("/proc/meminfo", "r");
unsigned long hps = 0;
size_t linelen = 0;
char *line = NULL;
if (!f)
return 0;
while (getline(&line, &linelen, f) > 0) {
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
hps <<= 10;
b... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/toeplitz.c |
static inline uint32_t toeplitz(const unsigned char *four_tuple,
const unsigned char *key) {
int i, bit, ret = 0;
uint32_t key32;
key32 = ntohl(*((uint32_t *)key));
key += 4;
for (i = 0; i < FOUR_TUPLE_MAX_LEN; i++) {
for (bit = 7; bit >= 0; bit--) {
if (four_tuple... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/toeplitz.c | static void set_filter(int fd) {
const int off_dport = offsetof(struct tcphdr, dest);
uint8_t proto;
proto = cfg_type == SOCK_STREAM ? IPPROTO_TCP : IPPROTO_UDP;
if (cfg_family == AF_INET)
__set_filter(fd, offsetof(struct iphdr, protocol), proto,
sizeof(struct iphdr) + off_dport);
else
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/toeplitz.c | static void setup_rings(void) {
int i;
for (i = 0; i < num_cpus; i++) {
rings[i].cpu = i;
rings[i].fd = create_ring(&rings[i].mmap);
}
for (i = 0; i < num_cpus; i++)
set_filter(rings[i].fd);
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/toeplitz.c | static void parse_cpulist(const char *arg) {
do {
rx_irq_cpus[cfg_num_queues++] = strtol(arg, NULL, 10);
arg = strchr(arg, ',');
if (!arg)
break;
arg++;
} while (1);
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/toeplitz.c |
static void show_silos(void) {
int i;
for (i = 0; i < cfg_num_rps_cpus; i++)
fprintf(stderr, "silo %d: cpu %d\n", i, rps_silo_to_cpu[i]);
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/toeplitz.c |
static void parse_toeplitz_key(const char *str, int slen, unsigned char *key) {
int i, ret, off;
if (slen < TOEPLITZ_STR_MIN_LEN || slen > TOEPLITZ_STR_MAX_LEN + 1)
error(1, 0, "invalid toeplitz key");
for (i = 0, off = 0; off < slen; i++, off += 3) {
ret = sscanf(str + off, "%hhx", &key[i]);
if (r... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/tun.c |
static int tun_detach(int fd, char *dev) {
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, dev);
ifr.ifr_flags = IFF_DETACH_QUEUE;
return ioctl(fd, TUNSETQUEUE, (void *)&ifr);
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/txring_overwrite.c |
static void send_pkt(int fdt, void *slot, char payload_char) {
struct tpacket_hdr *header = slot;
int ret;
while (header->tp_status != TP_STATUS_AVAILABLE)
usleep(1000);
build_packet(slot + eth_off, cfg_frame_size, payload_char);
header->tp_len = cfg_frame_size;
header->tp_status = TP_STATUS_SEND_RE... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/txring_overwrite.c |
static int read_verify_pkt(int fdr, char payload_char) {
char buf[100];
int ret;
ret = read(fdr, buf, sizeof(buf));
if (ret != sizeof(buf))
error(1, errno, "read");
if (buf[60] != payload_char) {
printf("wrong pattern: 0x%x != 0x%x\n", buf[60], payload_char);
return 1;
}
printf("read: %c (... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/txtimestamp.c |
static void add_timing_event(struct timing_event *te, struct timespec *t_start,
struct timespec *t_end) {
int64_t ts_delta = timespec_to_ns64(t_end) - timespec_to_ns64(t_start);
te->count++;
if (ts_delta < te->min)
te->min = ts_delta;
if (ts_delta > te->max)
te->max = ts_d... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/txtimestamp.c | static void validate_key(int tskey, int tstype) {
int stepsize;
if (saved_tskey == -1)
saved_tskey_type = tstype;
else if (saved_tskey_type != tstype)
return;
stepsize = cfg_proto == SOCK_STREAM ? cfg_payload_len : 1;
if (tskey != saved_tskey + stepsize) {
fprintf(stderr, "ERROR: key %d, expecte... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/txtimestamp.c |
static void __print_ts_delta_formatted(int64_t ts_delta) {
if (cfg_print_nsec)
fprintf(stderr, "%" PRId64 " ns", ts_delta);
else
fprintf(stderr, "%" PRId64 " us", ts_delta / NSEC_PER_USEC);
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/txtimestamp.c |
static void print_timestamp(struct scm_timestamping *tss, int tstype, int tskey,
int payload_len) {
const char *tsname;
validate_key(tskey, tstype);
switch (tstype) {
case SCM_TSTAMP_SCHED:
tsname = " ENQ";
validate_timestamp(&tss->ts[0], 0);
add_timing_event(&usr_enq... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/txtimestamp.c |
static void __poll(int fd) {
struct pollfd pollfd;
int ret;
memset(&pollfd, 0, sizeof(pollfd));
pollfd.fd = fd;
ret = poll(&pollfd, 1, cfg_poll_timeout);
if (ret != 1)
error(1, errno, "poll");
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/txtimestamp.c | static uint16_t get_udp_csum(const struct udphdr *udph, int alen) {
unsigned long pseudo_sum, csum_len;
const void *csum_start = udph;
pseudo_sum = htons(IPPROTO_UDP);
pseudo_sum += udph->len;
csum_start -= alen * 2;
csum_len = ntohs(udph->len) + alen * 2;
return get_ip_csum(csum_start, csum_len >> 1, ... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/txtimestamp.c | static void do_listen(int family, void *addr, int alen) {
int fd, type;
type = cfg_proto == SOCK_RAW ? SOCK_DGRAM : cfg_proto;
fd = socket(family, type, 0);
if (fd == -1)
error(1, errno, "socket rx");
if (bind(fd, addr, alen))
error(1, errno, "bind rx");
if (type == SOCK_STREAM && listen(fd, 10)... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso.c |
static unsigned int get_device_mtu(int fd, const char *ifname) {
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, ifname);
if (ioctl(fd, SIOCGIFMTU, &ifr))
error(1, errno, "ioctl get mtu");
return ifr.ifr_mtu;
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso.c |
static void set_device_mtu(int fd, int mtu) {
int val;
val = get_device_mtu(fd, cfg_ifname);
fprintf(stderr, "device mtu (orig): %u\n", val);
__set_device_mtu(fd, cfg_ifname, mtu);
val = get_device_mtu(fd, cfg_ifname);
if (val != mtu)
error(1, 0, "unable to set device mtu to %u\n", val);
fprintf(s... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso.c |
static int recv_one(int fd, int flags) {
int ret;
ret = recv(fd, buf, sizeof(buf), flags);
if (ret == -1 && errno == EAGAIN && (flags & MSG_DONTWAIT))
return 0;
if (ret == -1)
error(1, errno, "recv");
return ret;
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso.c |
static void run_test_v4(void) {
struct sockaddr_in addr = {0};
addr.sin_family = AF_INET;
addr.sin_port = htons(cfg_port);
addr.sin_addr = addr4;
run_test((void *)&addr, sizeof(addr));
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso_bench_rx.c |
static void setup_sockaddr(int domain, const char *str_addr, void *sockaddr) {
struct sockaddr_in6 *addr6 = (void *)sockaddr;
struct sockaddr_in *addr4 = (void *)sockaddr;
switch (domain) {
case PF_INET:
addr4->sin_family = AF_INET;
addr4->sin_port = htons(cfg_port);
if (inet_pton(AF_INET, str_add... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso_bench_rx.c | static void do_poll(int fd, int timeout_ms) {
struct pollfd pfd;
int ret;
pfd.events = POLLIN;
pfd.revents = 0;
pfd.fd = fd;
do {
ret = poll(&pfd, 1, 10);
if (interrupted)
break;
if (ret == -1)
error(1, errno, "poll");
if (ret == 0) {
if (!timeout_ms)
continue;
... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso_bench_rx.c | static void do_flush_tcp(int fd) {
int ret;
while (true) {
ret = recv(fd, NULL, 1 << 21, MSG_TRUNC | MSG_DONTWAIT);
if (ret == -1 && errno == EAGAIN)
return;
if (ret == -1)
error(1, errno, "flush");
if (ret == 0) {
/* client detached */
exit(0);
}
packets++;
by... | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso_bench_tx.c |
static int set_cpu(int cpu) {
cpu_set_t mask;
CPU_ZERO(&mask);
CPU_SET(cpu, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
error(1, 0, "setaffinity %d", cpu);
return 0;
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso_bench_tx.c |
static int send_tcp(int fd, char *data) {
int ret, done = 0, count = 0;
while (done < cfg_payload_len) {
ret = send(fd, data + done, cfg_payload_len - done,
cfg_zerocopy ? MSG_ZEROCOPY : 0);
if (ret == -1)
error(1, errno, "write");
done += ret;
count++;
}
return count;
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso_bench_tx.c |
static int send_udp(int fd, char *data) {
int ret, total_len, len, count = 0;
total_len = cfg_payload_len;
while (total_len) {
len = total_len < cfg_mss ? total_len : cfg_mss;
ret = sendto(fd, data, len, cfg_zerocopy ? MSG_ZEROCOPY : 0,
cfg_connected ? NULL : (void *)&cfg_dst_addr,
... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/net/udpgso_bench_tx.c |
static void set_pmtu_discover(int fd, bool is_ipv4) {
int level, name, val;
if (is_ipv4) {
level = SOL_IP;
name = IP_MTU_DISCOVER;
val = IP_PMTUDISC_DO;
} else {
level = SOL_IPV6;
name = IPV6_MTU_DISCOVER;
val = IPV6_PMTUDISC_DO;
}
if (setsockopt(fd, level, name, &val, sizeof(val)))... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/connect_close.c |
static void handler(int sig) { _exit(sig == SIGALRM ? 0 : 1); } | [
0,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/connect_close.c |
static void do_connect(const struct sockaddr_in *dst) {
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s >= 0)
fcntl(s, F_SETFL, O_NONBLOCK);
connect(s, (struct sockaddr *)dst, sizeof(*dst));
close(s);
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/connect_close.c |
static void do_accept(const struct sockaddr_in *src) {
int c, one = 1, s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0)
return;
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one));
bind(s, (struct sockaddr *)src, sizeof(*src))... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/connect_close.c |
static int accept_loop(void) {
struct sockaddr_in src = {
.sin_family = AF_INET,
.sin_port = htons(opts.port),
};
inet_pton(AF_INET, "127.0.0.1", &src.sin_addr);
set_timeout();
for (;;)
do_accept(&src);
return 1;
} | [
0,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/connect_close.c |
int main(int argc, char *argv[]) {
pid_t p;
parse_opts(argc, argv);
p = fork();
if (p < 0)
return 111;
if (p > 0)
return accept_loop();
return connect_loop();
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/nf-queue.c |
static void help(const char *p) {
printf("Usage: %s [-c|-v [-vv] ] [-t timeout] [-q queue_num] [-Qdst_queue ] "
"[ -d ms_delay ] [-G]\n",
p);
} | [
1,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/nf-queue.c | static int parse_attr_cb(const struct nlattr *attr, void *data) {
const struct nlattr **tb = data;
int type = mnl_attr_get_type(attr);
if (mnl_attr_type_valid(attr, NFQA_MAX) < 0)
return MNL_CB_OK;
switch (type) {
case NFQA_MARK:
case NFQA_IFINDEX_INDEV:
case NFQA_IFINDEX_OUTDEV:
case NFQA_IFINDEX... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/netfilter/nf-queue.c |
struct mnl_socket *open_queue(void) {
char buf[MNL_SOCKET_BUFFER_SIZE];
unsigned int queue_num;
struct mnl_socket *nl;
struct nlmsghdr *nlh;
struct timeval tv;
uint32_t flags;
nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
perror("mnl_socket_open");
exit(EXIT_FAILURE);
}
if (m... | [
1,
0
] |
Linux Kernel | tools/testing/selftests/nolibc/nolibc-test.c |
static int expect_zr(int expr, int llen) {
int ret = !(expr == 0);
llen += printf(" = %d ", expr);
pad_spc(llen, 40, ret ? "[FAIL]\n" : " [OK]\n");
return ret;
}
#define EXPECT_NZ(cond, expr, val) \
do { ... | [
0,
0
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.