Skip to content

Commit

Permalink
Pack IP structures directly used for access packet data.
Browse files Browse the repository at this point in the history
All structures used to access data in byte buffers shall be marked
as packed. Otherwise, this is undefined behavior - formally on
every platform.
  • Loading branch information
strejda committed Aug 5, 2023
1 parent 7678ce0 commit bd4390c
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sys/netinet/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct dccphdr {
uint8_t seq[6];
} longseq;
} d_seqno;
};
} __packed;

#define d_seqno_short d_seqno.shortseq;
#define d_seqno_long d_seqno.longseq.seq;
Expand Down
4 changes: 2 additions & 2 deletions sys/netinet/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct ip {
u_char ip_p; /* protocol */
u_short ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
} __packed __aligned(2);
} __packed;

#define IP_MAXPACKET 65535 /* maximum packet size */

Expand Down Expand Up @@ -189,7 +189,7 @@ struct ip_timestamp {
uint32_t ipt_time; /* network format */
} ipt_ta[1];
} ipt_timestamp;
};
} __packed;

/* Flag bits for ipt_flg. */
#define IPOPT_TS_TSONLY 0 /* timestamps only */
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/ip_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct ipovly {
u_short ih_len; /* protocol length */
struct in_addr ih_src; /* source internet address */
struct in_addr ih_dst; /* destination internet address */
};
} __packed;

#ifdef _KERNEL
/*
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/pim.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct pim {
#endif /* ! _PIM_VT */
uint8_t pim_reserved; /* Reserved */
uint16_t pim_cksum; /* IP-style checksum */
};
} __packed;
/* KAME-related name backward compatibility */
#define pim_ver pim_vers
#define pim_rsv pim_reserved
Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct tcphdr {
u_short th_win; /* window */
u_short th_sum; /* checksum */
u_short th_urp; /* urgent pointer */
};
} __packed;

#define PADTCPOLEN(len) ((((len) / 4) + !!((len) % 4)) * 4)

Expand Down
2 changes: 1 addition & 1 deletion sys/netinet/udp.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct udphdr {
u_short uh_dport; /* destination port */
u_short uh_ulen; /* udp length */
u_short uh_sum; /* udp checksum */
};
} __packed;

/*
* User-settable options (used with setsockopt).
Expand Down

0 comments on commit bd4390c

Please sign in to comment.