Skip to content

Commit cd11d11

Browse files
julianwiedmanndavem330
authored andcommitted
net/af_iucv: locate IUCV header via skb_network_header()
This patch attempts to untangle the TX and RX code in qeth from af_iucv's respective HiperTransport path: On the TX side, pointing skb_network_header() at the IUCV header means that qeth_l3_fill_af_iucv_hdr() no longer needs a magical offset to access the header. On the RX side, qeth pulls the (fake) L2 header off the skb like any normal ethernet driver would. This makes working with the IUCV header in af_iucv easier, since we no longer have to assume a fixed skb layout. While at it, replace the open-coded length checks in af_iucv's RX path with pskb_may_pull(). Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a2eb0ad commit cd11d11

3 files changed

Lines changed: 23 additions & 36 deletions

File tree

‎drivers/s390/net/qeth_l3_main.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,7 @@ static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb,
13481348
static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
13491349
int budget, int *done)
13501350
{
1351+
struct net_device *dev = card->dev;
13511352
int work_done = 0;
13521353
struct sk_buff *skb;
13531354
struct qeth_hdr *hdr;
@@ -1369,11 +1370,10 @@ static int qeth_l3_process_inbound_buffer(struct qeth_card *card,
13691370
magic = *(__u16 *)skb->data;
13701371
if ((card->info.type == QETH_CARD_TYPE_IQD) &&
13711372
(magic == ETH_P_AF_IUCV)) {
1372-
skb->protocol = cpu_to_be16(ETH_P_AF_IUCV);
13731373
len = skb->len;
1374-
card->dev->header_ops->create(skb, card->dev, 0,
1375-
card->dev->dev_addr, "FAKELL", len);
1376-
skb_reset_mac_header(skb);
1374+
dev_hard_header(skb, dev, ETH_P_AF_IUCV,
1375+
dev->dev_addr, "FAKELL", len);
1376+
skb->protocol = eth_type_trans(skb, dev);
13771377
netif_receive_skb(skb);
13781378
} else {
13791379
qeth_l3_rebuild_skb(card, skb, hdr);
@@ -2005,17 +2005,15 @@ static void qeth_l3_fill_af_iucv_hdr(struct qeth_hdr *hdr, struct sk_buff *skb,
20052005
unsigned int data_len)
20062006
{
20072007
char daddr[16];
2008-
struct af_iucv_trans_hdr *iucv_hdr;
20092008

20102009
hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
20112010
hdr->hdr.l3.length = data_len;
20122011
hdr->hdr.l3.flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
20132012

2014-
iucv_hdr = (struct af_iucv_trans_hdr *)(skb_mac_header(skb) + ETH_HLEN);
20152013
memset(daddr, 0, sizeof(daddr));
20162014
daddr[0] = 0xfe;
20172015
daddr[1] = 0x80;
2018-
memcpy(&daddr[8], iucv_hdr->destUserID, 8);
2016+
memcpy(&daddr[8], iucv_trans_hdr(skb)->destUserID, 8);
20192017
memcpy(hdr->hdr.l3.next_hop.ipv6_addr, daddr, 16);
20202018
}
20212019

‎include/net/iucv/af_iucv.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ struct af_iucv_trans_hdr {
8080
u8 pad; /* total 104 bytes */
8181
} __packed;
8282

83+
static inline struct af_iucv_trans_hdr *iucv_trans_hdr(struct sk_buff *skb)
84+
{
85+
return (struct af_iucv_trans_hdr *)skb_network_header(skb);
86+
}
87+
8388
enum iucv_tx_notify {
8489
/* transmission of skb is completed and was successful */
8590
TX_NOTIFY_OK = 0,

‎net/iucv/af_iucv.c‎

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,9 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
320320
struct sk_buff *nskb;
321321
int err, confirm_recv = 0;
322322

323-
memset(skb->head, 0, ETH_HLEN);
324-
phs_hdr = skb_push(skb, sizeof(struct af_iucv_trans_hdr));
325-
skb_reset_mac_header(skb);
323+
phs_hdr = skb_push(skb, sizeof(*phs_hdr));
324+
memset(phs_hdr, 0, sizeof(*phs_hdr));
326325
skb_reset_network_header(skb);
327-
skb_push(skb, ETH_HLEN);
328-
skb_reset_mac_header(skb);
329-
memset(phs_hdr, 0, sizeof(struct af_iucv_trans_hdr));
330326

331327
phs_hdr->magic = ETH_P_AF_IUCV;
332328
phs_hdr->version = 1;
@@ -350,6 +346,9 @@ static int afiucv_hs_send(struct iucv_message *imsg, struct sock *sock,
350346
if (imsg)
351347
memcpy(&phs_hdr->iucv_hdr, imsg, sizeof(struct iucv_message));
352348

349+
skb_push(skb, ETH_HLEN);
350+
memset(skb->data, 0, ETH_HLEN);
351+
353352
skb->dev = iucv->hs_dev;
354353
if (!skb->dev) {
355354
err = -ENODEV;
@@ -1943,8 +1942,7 @@ static void iucv_callback_shutdown(struct iucv_path *path, u8 ipuser[16])
19431942
/***************** HiperSockets transport callbacks ********************/
19441943
static void afiucv_swap_src_dest(struct sk_buff *skb)
19451944
{
1946-
struct af_iucv_trans_hdr *trans_hdr =
1947-
(struct af_iucv_trans_hdr *)skb->data;
1945+
struct af_iucv_trans_hdr *trans_hdr = iucv_trans_hdr(skb);
19481946
char tmpID[8];
19491947
char tmpName[8];
19501948

@@ -1967,13 +1965,12 @@ static void afiucv_swap_src_dest(struct sk_buff *skb)
19671965
**/
19681966
static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb)
19691967
{
1968+
struct af_iucv_trans_hdr *trans_hdr = iucv_trans_hdr(skb);
19701969
struct sock *nsk;
19711970
struct iucv_sock *iucv, *niucv;
1972-
struct af_iucv_trans_hdr *trans_hdr;
19731971
int err;
19741972

19751973
iucv = iucv_sk(sk);
1976-
trans_hdr = (struct af_iucv_trans_hdr *)skb->data;
19771974
if (!iucv) {
19781975
/* no sock - connection refused */
19791976
afiucv_swap_src_dest(skb);
@@ -2034,15 +2031,13 @@ static int afiucv_hs_callback_syn(struct sock *sk, struct sk_buff *skb)
20342031
static int afiucv_hs_callback_synack(struct sock *sk, struct sk_buff *skb)
20352032
{
20362033
struct iucv_sock *iucv = iucv_sk(sk);
2037-
struct af_iucv_trans_hdr *trans_hdr =
2038-
(struct af_iucv_trans_hdr *)skb->data;
20392034

20402035
if (!iucv)
20412036
goto out;
20422037
if (sk->sk_state != IUCV_BOUND)
20432038
goto out;
20442039
bh_lock_sock(sk);
2045-
iucv->msglimit_peer = trans_hdr->window;
2040+
iucv->msglimit_peer = iucv_trans_hdr(skb)->window;
20462041
sk->sk_state = IUCV_CONNECTED;
20472042
sk->sk_state_change(sk);
20482043
bh_unlock_sock(sk);
@@ -2098,16 +2093,14 @@ static int afiucv_hs_callback_fin(struct sock *sk, struct sk_buff *skb)
20982093
static int afiucv_hs_callback_win(struct sock *sk, struct sk_buff *skb)
20992094
{
21002095
struct iucv_sock *iucv = iucv_sk(sk);
2101-
struct af_iucv_trans_hdr *trans_hdr =
2102-
(struct af_iucv_trans_hdr *)skb->data;
21032096

21042097
if (!iucv)
21052098
return NET_RX_SUCCESS;
21062099

21072100
if (sk->sk_state != IUCV_CONNECTED)
21082101
return NET_RX_SUCCESS;
21092102

2110-
atomic_sub(trans_hdr->window, &iucv->msg_sent);
2103+
atomic_sub(iucv_trans_hdr(skb)->window, &iucv->msg_sent);
21112104
iucv_sock_wake_msglim(sk);
21122105
return NET_RX_SUCCESS;
21132106
}
@@ -2170,22 +2163,13 @@ static int afiucv_hs_rcv(struct sk_buff *skb, struct net_device *dev,
21702163
int err = NET_RX_SUCCESS;
21712164
char nullstring[8];
21722165

2173-
if (skb->len < (ETH_HLEN + sizeof(struct af_iucv_trans_hdr))) {
2174-
WARN_ONCE(1, "AF_IUCV too short skb, len=%d, min=%d",
2175-
(int)skb->len,
2176-
(int)(ETH_HLEN + sizeof(struct af_iucv_trans_hdr)));
2166+
if (!pskb_may_pull(skb, sizeof(*trans_hdr))) {
2167+
WARN_ONCE(1, "AF_IUCV failed to receive skb, len=%u", skb->len);
21772168
kfree_skb(skb);
21782169
return NET_RX_SUCCESS;
21792170
}
2180-
if (skb_headlen(skb) < (ETH_HLEN + sizeof(struct af_iucv_trans_hdr)))
2181-
if (skb_linearize(skb)) {
2182-
WARN_ONCE(1, "AF_IUCV skb_linearize failed, len=%d",
2183-
(int)skb->len);
2184-
kfree_skb(skb);
2185-
return NET_RX_SUCCESS;
2186-
}
2187-
skb_pull(skb, ETH_HLEN);
2188-
trans_hdr = (struct af_iucv_trans_hdr *)skb->data;
2171+
2172+
trans_hdr = iucv_trans_hdr(skb);
21892173
EBCASC(trans_hdr->destAppName, sizeof(trans_hdr->destAppName));
21902174
EBCASC(trans_hdr->destUserID, sizeof(trans_hdr->destUserID));
21912175
EBCASC(trans_hdr->srcAppName, sizeof(trans_hdr->srcAppName));

0 commit comments

Comments
 (0)