Lines Matching +full:magic +full:- +full:packet

1 // SPDX-License-Identifier: GPL-2.0
33 struct net_packet_attrs *packet; member
43 __be64 magic; member
65 size = attr->size + NET_TEST_PKT_SIZE; in net_test_get_skb()
67 if (attr->tcp) in net_test_get_skb()
72 if (attr->max_size && attr->max_size > size) in net_test_get_skb()
73 size = attr->max_size; in net_test_get_skb()
79 prefetchw(skb->data); in net_test_get_skb()
84 skb_set_network_header(skb, skb->len); in net_test_get_skb()
87 skb_set_transport_header(skb, skb->len); in net_test_get_skb()
88 if (attr->tcp) in net_test_get_skb()
93 eth_zero_addr(ehdr->h_dest); in net_test_get_skb()
95 if (attr->src) in net_test_get_skb()
96 ether_addr_copy(ehdr->h_source, attr->src); in net_test_get_skb()
97 if (attr->dst) in net_test_get_skb()
98 ether_addr_copy(ehdr->h_dest, attr->dst); in net_test_get_skb()
100 ehdr->h_proto = htons(ETH_P_IP); in net_test_get_skb()
102 if (attr->tcp) { in net_test_get_skb()
103 thdr->source = htons(attr->sport); in net_test_get_skb()
104 thdr->dest = htons(attr->dport); in net_test_get_skb()
105 thdr->doff = sizeof(struct tcphdr) / 4; in net_test_get_skb()
106 thdr->check = 0; in net_test_get_skb()
108 uhdr->source = htons(attr->sport); in net_test_get_skb()
109 uhdr->dest = htons(attr->dport); in net_test_get_skb()
110 uhdr->len = htons(sizeof(*shdr) + sizeof(*uhdr) + attr->size); in net_test_get_skb()
111 if (attr->max_size) in net_test_get_skb()
112 uhdr->len = htons(attr->max_size - in net_test_get_skb()
114 uhdr->check = 0; in net_test_get_skb()
117 ihdr->ihl = 5; in net_test_get_skb()
118 ihdr->ttl = 32; in net_test_get_skb()
119 ihdr->version = 4; in net_test_get_skb()
120 if (attr->tcp) in net_test_get_skb()
121 ihdr->protocol = IPPROTO_TCP; in net_test_get_skb()
123 ihdr->protocol = IPPROTO_UDP; in net_test_get_skb()
124 iplen = sizeof(*ihdr) + sizeof(*shdr) + attr->size; in net_test_get_skb()
125 if (attr->tcp) in net_test_get_skb()
130 if (attr->max_size) in net_test_get_skb()
131 iplen = attr->max_size - sizeof(*ehdr); in net_test_get_skb()
133 ihdr->tot_len = htons(iplen); in net_test_get_skb()
134 ihdr->frag_off = 0; in net_test_get_skb()
135 ihdr->saddr = htonl(attr->ip_src); in net_test_get_skb()
136 ihdr->daddr = htonl(attr->ip_dst); in net_test_get_skb()
137 ihdr->tos = 0; in net_test_get_skb()
138 ihdr->id = 0; in net_test_get_skb()
142 shdr->version = 0; in net_test_get_skb()
143 shdr->magic = cpu_to_be64(NET_TEST_PKT_MAGIC); in net_test_get_skb()
144 attr->id = net_test_next_id; in net_test_get_skb()
145 shdr->id = net_test_next_id++; in net_test_get_skb()
147 if (attr->size) in net_test_get_skb()
148 skb_put(skb, attr->size); in net_test_get_skb()
149 if (attr->max_size && attr->max_size > skb->len) in net_test_get_skb()
150 skb_put(skb, attr->max_size - skb->len); in net_test_get_skb()
152 skb->csum = 0; in net_test_get_skb()
153 skb->ip_summed = CHECKSUM_PARTIAL; in net_test_get_skb()
154 if (attr->tcp) { in net_test_get_skb()
155 thdr->check = ~tcp_v4_check(skb->len, ihdr->saddr, in net_test_get_skb()
156 ihdr->daddr, 0); in net_test_get_skb()
157 skb->csum_start = skb_transport_header(skb) - skb->head; in net_test_get_skb()
158 skb->csum_offset = offsetof(struct tcphdr, check); in net_test_get_skb()
160 udp4_hwcsum(skb, ihdr->saddr, ihdr->daddr); in net_test_get_skb()
163 skb->protocol = htons(ETH_P_IP); in net_test_get_skb()
164 skb->pkt_type = PACKET_HOST; in net_test_get_skb()
165 skb->dev = ndev; in net_test_get_skb()
175 struct net_test_priv *tpriv = pt->af_packet_priv; in net_test_loopback_validate()
176 const unsigned char *src = tpriv->packet->src; in net_test_loopback_validate()
177 const unsigned char *dst = tpriv->packet->dst; in net_test_loopback_validate()
190 if (skb_headlen(skb) < (NET_TEST_PKT_SIZE - ETH_HLEN)) in net_test_loopback_validate()
195 if (!ether_addr_equal_unaligned(ehdr->h_dest, dst)) in net_test_loopback_validate()
200 if (!ether_addr_equal_unaligned(ehdr->h_source, src)) in net_test_loopback_validate()
205 if (tpriv->double_vlan) in net_test_loopback_validate()
208 if (tpriv->packet->tcp) { in net_test_loopback_validate()
209 if (ihdr->protocol != IPPROTO_TCP) in net_test_loopback_validate()
212 thdr = (struct tcphdr *)((u8 *)ihdr + 4 * ihdr->ihl); in net_test_loopback_validate()
213 if (thdr->dest != htons(tpriv->packet->dport)) in net_test_loopback_validate()
218 if (ihdr->protocol != IPPROTO_UDP) in net_test_loopback_validate()
221 uhdr = (struct udphdr *)((u8 *)ihdr + 4 * ihdr->ihl); in net_test_loopback_validate()
222 if (uhdr->dest != htons(tpriv->packet->dport)) in net_test_loopback_validate()
228 if (shdr->magic != cpu_to_be64(NET_TEST_PKT_MAGIC)) in net_test_loopback_validate()
230 if (tpriv->packet->id != shdr->id) in net_test_loopback_validate()
233 tpriv->ok = true; in net_test_loopback_validate()
234 complete(&tpriv->comp); in net_test_loopback_validate()
249 return -ENOMEM; in __net_test_loopback()
251 tpriv->ok = false; in __net_test_loopback()
252 init_completion(&tpriv->comp); in __net_test_loopback()
254 tpriv->pt.type = htons(ETH_P_IP); in __net_test_loopback()
255 tpriv->pt.func = net_test_loopback_validate; in __net_test_loopback()
256 tpriv->pt.dev = ndev; in __net_test_loopback()
257 tpriv->pt.af_packet_priv = tpriv; in __net_test_loopback()
258 tpriv->packet = attr; in __net_test_loopback()
259 dev_add_pack(&tpriv->pt); in __net_test_loopback()
263 ret = -ENOMEM; in __net_test_loopback()
267 ret = dev_direct_xmit(skb, attr->queue_mapping); in __net_test_loopback()
271 ret = -ENETUNREACH; in __net_test_loopback()
275 if (!attr->timeout) in __net_test_loopback()
276 attr->timeout = NET_LB_TIMEOUT; in __net_test_loopback()
278 wait_for_completion_timeout(&tpriv->comp, attr->timeout); in __net_test_loopback()
279 ret = tpriv->ok ? 0 : -ETIMEDOUT; in __net_test_loopback()
282 dev_remove_pack(&tpriv->pt); in __net_test_loopback()
289 return netif_carrier_ok(ndev) ? 0 : -ENOLINK; in net_test_netif_carrier()
294 return ndev->phydev ? 0 : -EOPNOTSUPP; in net_test_phy_phydev()
299 if (!ndev->phydev) in net_test_phy_loopback_enable()
300 return -EOPNOTSUPP; in net_test_phy_loopback_enable()
302 return phy_loopback(ndev->phydev, true); in net_test_phy_loopback_enable()
307 if (!ndev->phydev) in net_test_phy_loopback_disable()
308 return -EOPNOTSUPP; in net_test_phy_loopback_disable()
310 return phy_loopback(ndev->phydev, false); in net_test_phy_loopback_disable()
317 attr.dst = ndev->dev_addr; in net_test_phy_loopback_udp()
325 attr.dst = ndev->dev_addr; in net_test_phy_loopback_udp_mtu()
326 attr.max_size = ndev->mtu; in net_test_phy_loopback_udp_mtu()
334 attr.dst = ndev->dev_addr; in net_test_phy_loopback_tcp()
377 if (etest->flags != ETH_TEST_FL_OFFLINE) { in net_selftest()
379 etest->flags |= ETH_TEST_FL_FAILED; in net_selftest()
386 if (buf[i] && (buf[i] != -EOPNOTSUPP)) in net_selftest()
387 etest->flags |= ETH_TEST_FL_FAILED; in net_selftest()