@@ -96,17 +96,11 @@ pkt_push_udp(lbuf_t *b, uint16_t sp, uint16_t dp)
9696 udp_len = sizeof (struct udphdr ) + lbuf_size (b );
9797 uh = lbuf_push_uninit (b , sizeof (struct udphdr ));
9898
99- #ifdef BSD
100- uh -> uh_sport = htons (port_from );
101- uh -> uh_dport = htons (port_dest );
102- uh -> uh_ulen = htons (udp_payload_len );
103- uh -> uh_sum = 0 ;
104- #else
105- uh -> source = htons (sp );
106- uh -> dest = htons (dp );
107- uh -> len = htons (udp_len );
108- uh -> check = 0 ; /* to be filled in after IP is pushed */
109- #endif
99+ udpsport (uh ) = htons (sp );
100+ udpdport (uh ) = htons (dp );
101+ udplen (uh ) = htons (udp_len );
102+ udpsum (uh ) = 0 ; /* to be filled in after IP is pushed */
103+
110104 return (uh );
111105}
112106
@@ -199,7 +193,7 @@ pkt_push_udp_and_ip(lbuf_t *b, uint16_t sp, uint16_t dp, ip_addr_t *sip,
199193 lbuf_reset_ip (b );
200194
201195 uh = lbuf_udp (b );
202- udpsum = udp_checksum (uh , ntohs (uh -> len ), lbuf_ip (b ), ip_addr_afi (sip ));
196+ udpsum = udp_checksum (uh , ntohs (udplen ( uh ) ), lbuf_ip (b ), ip_addr_afi (sip ));
203197 if (udpsum == -1 ) {
204198 OOR_LOG (LDBG_1 , "Failed UDP checksum! Discarding" );
205199 return (BAD );
@@ -246,12 +240,12 @@ pkt_parse_5_tuple(lbuf_t *b, packet_tuple_t *tuple)
246240
247241 if (tuple -> protocol == IPPROTO_UDP ) {
248242 udp = lbuf_data (& packet );
249- tuple -> src_port = ntohs (udp -> source );
250- tuple -> dst_port = ntohs (udp -> dest );
243+ tuple -> src_port = ntohs (udpsport ( udp ) );
244+ tuple -> dst_port = ntohs (udpdport ( udp ) );
251245 } else if (tuple -> protocol == IPPROTO_TCP ) {
252246 tcp = lbuf_data (& packet );
253- tuple -> src_port = ntohs (tcp -> source );
254- tuple -> dst_port = ntohs (tcp -> dest );
247+ tuple -> src_port = ntohs (tcpsport ( tcp ) );
248+ tuple -> dst_port = ntohs (tcpdport ( tcp ) );
255249 } else {
256250 /* If protocol is not TCP or UDP, ports of the tuple set to 0 */
257251 tuple -> src_port = 0 ;
@@ -560,18 +554,11 @@ build_ip_udp_pcket(uint8_t *orig_pkt, int orig_pkt_len,lisp_addr_t *addr_from,
560554 }
561555
562556 /* UDP header */
557+ udpsport (udph_ptr ) = htons (port_from );
558+ udpdport (udph_ptr ) = htons (port_dest );
559+ udplen (udph_ptr ) = htons (udp_hdr_and_payload_len );
560+ udpsum (udph_ptr ) = 0 ;
563561
564- #ifdef BSD
565- udph_ptr -> uh_sport = htons (port_from );
566- udph_ptr -> uh_dport = htons (port_dest );
567- udph_ptr -> uh_ulen = htons (udp_payload_len );
568- udph_ptr -> uh_sum = 0 ;
569- #else
570- udph_ptr -> source = htons (port_from );
571- udph_ptr -> dest = htons (port_dest );
572- udph_ptr -> len = htons (udp_hdr_and_payload_len );
573- udph_ptr -> check = 0 ;
574- #endif
575562
576563 /* Copy original packet after the headers */
577564 memcpy (CO (udph_ptr , udp_hdr_len ), orig_pkt , orig_pkt_len );
0 commit comments