-/* If 'packet' is a TCP packet, returns the TCP flags. Otherwise, returns 0.
- *
- * 'flow' must be the flow corresponding to 'packet' and 'packet''s header
- * pointers must be properly initialized (e.g. with flow_extract()). */
-uint8_t
-packet_get_tcp_flags(const struct ofpbuf *packet, const struct flow *flow)
-{
- if (dl_type_is_ip_any(flow->dl_type) &&
- flow->nw_proto == IPPROTO_TCP && packet->l7) {
- const struct tcp_header *tcp = packet->l4;
- return TCP_FLAGS(tcp->tcp_ctl);
- } else {
- return 0;
+/* Sets the SCTP source and destination port ('src' and 'dst' respectively) of
+ * the SCTP header contained in 'packet'. 'packet' must be a valid SCTP packet
+ * with its l4 offset properly populated. */
+void
+packet_set_sctp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
+{
+ struct sctp_header *sh = ofpbuf_l4(packet);
+ ovs_be32 old_csum, old_correct_csum, new_csum;
+ uint16_t tp_len = ofpbuf_l4_size(packet);
+
+ old_csum = get_16aligned_be32(&sh->sctp_csum);
+ put_16aligned_be32(&sh->sctp_csum, 0);
+ old_correct_csum = crc32c((void *)sh, tp_len);
+
+ sh->sctp_src = src;
+ sh->sctp_dst = dst;
+
+ new_csum = crc32c((void *)sh, tp_len);
+ put_16aligned_be32(&sh->sctp_csum, old_csum ^ old_correct_csum ^ new_csum);
+}
+
+const char *
+packet_tcp_flag_to_string(uint32_t flag)
+{
+ switch (flag) {
+ case TCP_FIN:
+ return "fin";
+ case TCP_SYN:
+ return "syn";
+ case TCP_RST:
+ return "rst";
+ case TCP_PSH:
+ return "psh";
+ case TCP_ACK:
+ return "ack";
+ case TCP_URG:
+ return "urg";
+ case TCP_ECE:
+ return "ece";
+ case TCP_CWR:
+ return "cwr";
+ case TCP_NS:
+ return "ns";
+ case 0x200:
+ return "[200]";
+ case 0x400:
+ return "[400]";
+ case 0x800:
+ return "[800]";
+ default:
+ return NULL;