aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2021-06-06 14:25:46 +0000
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-06-06 14:25:46 +0000
commit5695ba4dcf388f17079b706dfbc984a42cd667ea (patch)
treedc674ff705f5278e957987ad8abd787683ede857
parentdfe1229fc8f707f76b3f4d09078ab5e9b5817469 (diff)
parent4bbfdff02214ba2c9185d1d4b5df0554b70b3a19 (diff)
downloadslirp-5695ba4dcf388f17079b706dfbc984a42cd667ea.zip
slirp-5695ba4dcf388f17079b706dfbc984a42cd667ea.tar.gz
slirp-5695ba4dcf388f17079b706dfbc984a42cd667ea.tar.bz2
Merge branch 'ncsi_pack' into 'master'
ncsi: make ncsi_calculate_checksum work with unaligned data Closes #43 See merge request slirp/libslirp!89
-rw-r--r--src/ncsi-pkt.h58
-rw-r--r--src/ncsi.c8
2 files changed, 33 insertions, 33 deletions
diff --git a/src/ncsi-pkt.h b/src/ncsi-pkt.h
index 7795ad8..39cf844 100644
--- a/src/ncsi-pkt.h
+++ b/src/ncsi-pkt.h
@@ -49,36 +49,36 @@ struct ncsi_pkt_hdr {
unsigned char channel; /* Network controller ID */
__be16 length; /* Payload length */
__be32 reserved1[2]; /* Reserved */
-};
+} SLIRP_PACKED;
struct ncsi_cmd_pkt_hdr {
struct ncsi_pkt_hdr common; /* Common NCSI packet header */
-};
+} SLIRP_PACKED;
struct ncsi_rsp_pkt_hdr {
struct ncsi_pkt_hdr common; /* Common NCSI packet header */
__be16 code; /* Response code */
__be16 reason; /* Response reason */
-};
+} SLIRP_PACKED;
struct ncsi_aen_pkt_hdr {
struct ncsi_pkt_hdr common; /* Common NCSI packet header */
unsigned char reserved2[3]; /* Reserved */
unsigned char type; /* AEN packet type */
-};
+} SLIRP_PACKED;
/* NCSI common command packet */
struct ncsi_cmd_pkt {
struct ncsi_cmd_pkt_hdr cmd; /* Command header */
__be32 checksum; /* Checksum */
unsigned char pad[26];
-};
+} SLIRP_PACKED;
struct ncsi_rsp_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* Select Package */
struct ncsi_cmd_sp_pkt {
@@ -87,7 +87,7 @@ struct ncsi_cmd_sp_pkt {
unsigned char hw_arbitration; /* HW arbitration */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* Disable Channel */
struct ncsi_cmd_dc_pkt {
@@ -96,7 +96,7 @@ struct ncsi_cmd_dc_pkt {
unsigned char ald; /* Allow link down */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* Reset Channel */
struct ncsi_cmd_rc_pkt {
@@ -104,7 +104,7 @@ struct ncsi_cmd_rc_pkt {
__be32 reserved; /* Reserved */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* AEN Enable */
struct ncsi_cmd_ae_pkt {
@@ -114,7 +114,7 @@ struct ncsi_cmd_ae_pkt {
__be32 mode; /* AEN working mode */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-};
+} SLIRP_PACKED;
/* Set Link */
struct ncsi_cmd_sl_pkt {
@@ -123,7 +123,7 @@ struct ncsi_cmd_sl_pkt {
__be32 oem_mode; /* OEM link mode */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-};
+} SLIRP_PACKED;
/* Set VLAN Filter */
struct ncsi_cmd_svf_pkt {
@@ -135,7 +135,7 @@ struct ncsi_cmd_svf_pkt {
unsigned char enable; /* Enable or disable */
__be32 checksum; /* Checksum */
unsigned char pad[14];
-};
+} SLIRP_PACKED;
/* Enable VLAN */
struct ncsi_cmd_ev_pkt {
@@ -144,7 +144,7 @@ struct ncsi_cmd_ev_pkt {
unsigned char mode; /* VLAN filter mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* Set MAC Address */
struct ncsi_cmd_sma_pkt {
@@ -154,7 +154,7 @@ struct ncsi_cmd_sma_pkt {
unsigned char at_e; /* Addr type and operation */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-};
+} SLIRP_PACKED;
/* Enable Broadcast Filter */
struct ncsi_cmd_ebf_pkt {
@@ -162,7 +162,7 @@ struct ncsi_cmd_ebf_pkt {
__be32 mode; /* Filter mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* Enable Global Multicast Filter */
struct ncsi_cmd_egmf_pkt {
@@ -170,7 +170,7 @@ struct ncsi_cmd_egmf_pkt {
__be32 mode; /* Global MC mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* Set NCSI Flow Control */
struct ncsi_cmd_snfc_pkt {
@@ -179,7 +179,7 @@ struct ncsi_cmd_snfc_pkt {
unsigned char mode; /* Flow control mode */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* Get Link Status */
struct ncsi_rsp_gls_pkt {
@@ -189,7 +189,7 @@ struct ncsi_rsp_gls_pkt {
__be32 oem_status; /* OEM link status */
__be32 checksum;
unsigned char pad[10];
-};
+} SLIRP_PACKED;
/* Get Version ID */
struct ncsi_rsp_gvi_pkt {
@@ -202,7 +202,7 @@ struct ncsi_rsp_gvi_pkt {
__be16 pci_ids[4]; /* PCI IDs */
__be32 mf_id; /* Manufacture ID */
__be32 checksum;
-};
+} SLIRP_PACKED;
/* Get Capabilities */
struct ncsi_rsp_gc_pkt {
@@ -220,7 +220,7 @@ struct ncsi_rsp_gc_pkt {
unsigned char vlan_mode; /* VLAN mode */
unsigned char channel_cnt; /* Channel count */
__be32 checksum; /* Checksum */
-};
+} SLIRP_PACKED;
/* Get Parameters */
struct ncsi_rsp_gp_pkt {
@@ -241,7 +241,7 @@ struct ncsi_rsp_gp_pkt {
unsigned char mac[6]; /* Supported MAC addr */
__be16 vlan; /* Supported VLAN tags */
__be32 checksum; /* Checksum */
-};
+} SLIRP_PACKED;
/* Get Controller Packet Statistics */
struct ncsi_rsp_gcps_pkt {
@@ -288,7 +288,7 @@ struct ncsi_rsp_gcps_pkt {
__be32 rx_runt_pkts; /* Rx error runt packets */
__be32 rx_jabber_pkts; /* Rx error jabber packets */
__be32 checksum; /* Checksum */
-};
+} SLIRP_PACKED;
/* Get NCSI Statistics */
struct ncsi_rsp_gns_pkt {
@@ -301,7 +301,7 @@ struct ncsi_rsp_gns_pkt {
__be32 tx_pkts; /* Tx NCSI packets */
__be32 tx_aen_pkts; /* Tx AEN packets */
__be32 checksum; /* Checksum */
-};
+} SLIRP_PACKED;
/* Get NCSI Pass-through Statistics */
struct ncsi_rsp_gnpts_pkt {
@@ -316,21 +316,21 @@ struct ncsi_rsp_gnpts_pkt {
__be32 rx_us_err; /* Rx undersize errors */
__be32 rx_os_err; /* Rx oversize errors */
__be32 checksum; /* Checksum */
-};
+} SLIRP_PACKED;
/* Get package status */
struct ncsi_rsp_gps_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
__be32 status; /* Hardware arbitration status */
__be32 checksum;
-};
+} SLIRP_PACKED;
/* Get package UUID */
struct ncsi_rsp_gpuuid_pkt {
struct ncsi_rsp_pkt_hdr rsp; /* Response header */
unsigned char uuid[16]; /* UUID */
__be32 checksum;
-};
+} SLIRP_PACKED;
/* AEN: Link State Change */
struct ncsi_aen_lsc_pkt {
@@ -339,14 +339,14 @@ struct ncsi_aen_lsc_pkt {
__be32 oem_status; /* OEM link status */
__be32 checksum; /* Checksum */
unsigned char pad[14];
-};
+} SLIRP_PACKED;
/* AEN: Configuration Required */
struct ncsi_aen_cr_pkt {
struct ncsi_aen_pkt_hdr aen; /* AEN header */
__be32 checksum; /* Checksum */
unsigned char pad[22];
-};
+} SLIRP_PACKED;
/* AEN: Host Network Controller Driver Status Change */
struct ncsi_aen_hncdsc_pkt {
@@ -354,7 +354,7 @@ struct ncsi_aen_hncdsc_pkt {
__be32 status; /* Status */
__be32 checksum; /* Checksum */
unsigned char pad[18];
-};
+} SLIRP_PACKED;
/* NCSI packet revision */
#define NCSI_PKT_REVISION 0x01
diff --git a/src/ncsi.c b/src/ncsi.c
index 75dcc08..f3427bd 100644
--- a/src/ncsi.c
+++ b/src/ncsi.c
@@ -38,7 +38,7 @@
#include "ncsi-pkt.h"
-static uint32_t ncsi_calculate_checksum(uint16_t *data, int len)
+static uint32_t ncsi_calculate_checksum(uint8_t *data, int len)
{
uint32_t checksum = 0;
int i;
@@ -47,8 +47,8 @@ static uint32_t ncsi_calculate_checksum(uint16_t *data, int len)
* 32-bit unsigned sum of the NC-SI packet header and NC-SI packet
* payload interpreted as a series of 16-bit unsigned integer values.
*/
- for (i = 0; i < len / 2; i++) {
- checksum += htons(data[i]);
+ for (i = 0; i < len; i += 2) {
+ checksum += (((uint16_t) data[i]) << 8) + data[i+1];
}
checksum = (~checksum + 1);
@@ -188,7 +188,7 @@ void ncsi_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
}
/* Add the optional checksum at the end of the frame. */
- checksum = ncsi_calculate_checksum((uint16_t *)rnh, ncsi_rsp_len);
+ checksum = ncsi_calculate_checksum((uint8_t *)rnh, ncsi_rsp_len);
pchecksum = (uint32_t *)((void *)rnh + ncsi_rsp_len);
*pchecksum = htonl(checksum);
ncsi_rsp_len += 4;