X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpackets.c;h=8fb7f6b0320fac2a7fabcb02f6bd820420a91e8a;hb=6e492d81450217a5c90cbb4ad31d81b1e611989b;hp=eaf3e43f4c1cb86d5bbe1f10cfbc7135b9674ecd;hpb=c97664b30f65d3a087076cb33242ffe2cc52a814;p=openvswitch diff --git a/lib/packets.c b/lib/packets.c index eaf3e43f..8fb7f6b0 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011 Nicira Networks. + * Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include "byte-order.h" #include "csum.h" +#include "flow.h" #include "dynamic-string.h" #include "ofpbuf.h" @@ -478,3 +479,20 @@ packet_set_udp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst) uh->udp_dst = dst; } } + +/* 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 ((flow->dl_type == htons(ETH_TYPE_IP) || + flow->dl_type == htons(ETH_TYPE_IPV6)) && + flow->nw_proto == IPPROTO_TCP && packet->l7) { + const struct tcp_header *tcp = packet->l4; + return TCP_FLAGS(tcp->tcp_ctl); + } else { + return 0; + } +}