Skip to content

Commit e21d7cc

Browse files
committed
net: gptp: Refactor the gPTP header addition
Increase the net_buf length in proper places. So when gPTP header is added, increase the buf->len properly, and then when gPTP packet type is added, increase it again properly. This way the net_buf length is updated in more logical way. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 3e8b2a0 commit e21d7cc

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

subsys/net/l2/ethernet/gptp/gptp_messages.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ static struct net_pkt *setup_gptp_frame(struct net_if *iface)
169169
net_pkt_lladdr_dst(pkt)->addr = (u8_t *)&gptp_multicast_eth_addr;
170170
net_pkt_lladdr_dst(pkt)->len = sizeof(struct net_eth_addr);
171171

172+
net_buf_add(frag, sizeof(struct gptp_hdr));
173+
172174
return pkt;
173175
}
174176

@@ -220,8 +222,7 @@ struct net_pkt *gptp_prepare_sync(int port)
220222
/* PTP configuration. */
221223
(void)memset(&sync->reserved, 0, sizeof(sync->reserved));
222224

223-
net_buf_add(pkt->frags, sizeof(struct gptp_hdr) +
224-
sizeof(struct gptp_sync));
225+
net_buf_add(pkt->frags, sizeof(struct gptp_sync));
225226

226227
/* Update sequence number. */
227228
port_ds->sync_seq_id++;
@@ -277,8 +278,7 @@ struct net_pkt *gptp_prepare_follow_up(int port, struct net_pkt *sync)
277278

278279
/* PTP configuration will be set by the MDSyncSend state machine. */
279280

280-
net_buf_add(pkt->frags, sizeof(struct gptp_hdr) +
281-
sizeof(struct gptp_follow_up));
281+
net_buf_add(pkt->frags, sizeof(struct gptp_follow_up));
282282

283283
return pkt;
284284
}
@@ -334,8 +334,7 @@ struct net_pkt *gptp_prepare_pdelay_req(int port)
334334
(void)memset(&req->reserved1, 0, sizeof(req->reserved1));
335335
(void)memset(&req->reserved2, 0, sizeof(req->reserved2));
336336

337-
net_buf_add(pkt->frags, sizeof(struct gptp_hdr) +
338-
sizeof(struct gptp_pdelay_req));
337+
net_buf_add(pkt->frags, sizeof(struct gptp_pdelay_req));
339338

340339
/* Update sequence number. */
341340
port_ds->pdelay_req_seq_id++;
@@ -400,8 +399,7 @@ struct net_pkt *gptp_prepare_pdelay_resp(int port,
400399
memcpy(&pdelay_resp->requesting_port_id,
401400
&query->port_id, sizeof(struct gptp_port_identity));
402401

403-
net_buf_add(pkt->frags, sizeof(struct gptp_hdr) +
404-
sizeof(struct gptp_pdelay_resp));
402+
net_buf_add(pkt->frags, sizeof(struct gptp_pdelay_resp));
405403

406404
return pkt;
407405
}
@@ -464,8 +462,7 @@ struct net_pkt *gptp_prepare_pdelay_follow_up(int port,
464462
&pdelay_resp->requesting_port_id,
465463
sizeof(struct gptp_port_identity));
466464

467-
net_buf_add(pkt->frags, sizeof(struct gptp_hdr) +
468-
sizeof(struct gptp_pdelay_resp_follow_up));
465+
net_buf_add(pkt->frags, sizeof(struct gptp_pdelay_resp_follow_up));
469466

470467
return pkt;
471468
}
@@ -563,8 +560,7 @@ struct net_pkt *gptp_prepare_announce(int port)
563560
sizeof(struct gptp_announce) - 8 +
564561
ntohs(global_ds->path_trace.len));
565562

566-
net_buf_add(pkt->frags, sizeof(struct gptp_hdr) +
567-
sizeof(struct gptp_announce) - 8);
563+
net_buf_add(pkt->frags, sizeof(struct gptp_announce) - 8);
568564

569565
ann->tlv.len = global_ds->path_trace.len;
570566

0 commit comments

Comments
 (0)