datapath-windows/ovsext/Conntrack-nat.c
/*
 *----------------------------------------------------------------------------
 * OvsNatPacket
 *     Performs NAT operation on the packet by replacing the source/destinaton
 *     address/port based on natAction. If reverse is TRUE, perform unNAT
 *     instead.
 *----------------------------------------------------------------------------
 */
OvsNatPacket
Performs NAT operation on the packet by replacing the source/destinaton
address/port based on natAction. If reverse is TRUE, perform unNAT
instead.
OvsNatPacket Performs NAT operation on the packet by replacing the source / destinaton address / port based on natAction . If reverse is TRUE perform unNAT instead .
VOID
OvsNatPacket(OvsForwardingContext *ovsFwdCtx,
             const OVS_CT_ENTRY *entry,
             UINT16 natAction,
             OvsFlowKey *key,
             BOOLEAN reverse)
{
    UINT32 natFlag;
    const struct ct_endpoint* endpoint;
    const OVS_CT_KEY *ctKey = reverse ? &entry->key : &entry->rev_key;
    BOOLEAN isSrcNat;
    if (!(natAction & (NAT_ACTION_SRC | NAT_ACTION_DST))) {
        return;
    }
    isSrcNat = (((natAction & NAT_ACTION_SRC) && !reverse) ||
                ((natAction & NAT_ACTION_DST) && reverse));
    if (isSrcNat) {
        natFlag = OVS_CS_F_SRC_NAT;
        endpoint = &ctKey->dst;
    } else {
        natFlag = OVS_CS_F_DST_NAT;
        endpoint = &ctKey->src;
    }
    key->ct.state |= natFlag;
    if (ctKey->dl_type == htons(ETH_TYPE_IPV4)) {
        OvsUpdateAddressAndPort(ovsFwdCtx,
                                endpoint->addr.ipv4_aligned,
                                endpoint->port, isSrcNat,
                                !reverse);
        if (isSrcNat) {
            key->ipKey.nwSrc = endpoint->addr.ipv4_aligned;
        } else {
            key->ipKey.nwDst = endpoint->addr.ipv4_aligned;
        }
    } else if (ctKey->dl_type == htons(ETH_TYPE_IPV6)){
        return;
    }
    if (natAction & (NAT_ACTION_SRC_PORT | NAT_ACTION_DST_PORT)) {
        if (isSrcNat) {
            if (key->ipKey.l4.tpSrc != 0) {
                key->ipKey.l4.tpSrc = endpoint->port;
            }
        } else {
            if (key->ipKey.l4.tpDst != 0) {
                key->ipKey.l4.tpDst = endpoint->port;
            }
        }
    }
}
VOID OvsNatPacket ( OvsForwardingContext * ovsFwdCtx , const OVS_CT_ENTRY * entry , UINT16 natAction , OvsFlowKey * key , BOOLEAN reverse ) { UINT32 natFlag ; const struct ct_endpoint * endpoint ; const OVS_CT_KEY * ctKey = reverse ? & entry -> key : & entry -> rev_key ; BOOLEAN isSrcNat ; if ( ! ( natAction & ( NAT_ACTION_SRC | NAT_ACTION_DST ) ) ) { return ; } isSrcNat = ( ( ( natAction & NAT_ACTION_SRC ) && ! reverse ) || ( ( natAction & NAT_ACTION_DST ) && reverse ) ) ; if ( isSrcNat ) { natFlag = OVS_CS_F_SRC_NAT ; endpoint = & ctKey -> dst ; } else { natFlag = OVS_CS_F_DST_NAT ; endpoint = & ctKey -> src ; } key -> ct . state |= natFlag ; if ( ctKey -> dl_type == htons ( ETH_TYPE_IPV4 ) ) { OvsUpdateAddressAndPort ( ovsFwdCtx , endpoint -> addr . ipv4_aligned , endpoint -> port , isSrcNat , ! reverse ) ; if ( isSrcNat ) { key -> ipKey . nwSrc = endpoint -> addr . ipv4_aligned ; } else { key -> ipKey . nwDst = endpoint -> addr . ipv4_aligned ; } } else if ( ctKey -> dl_type == htons ( ETH_TYPE_IPV6 ) ) { return ; } if ( natAction & ( NAT_ACTION_SRC_PORT | NAT_ACTION_DST_PORT ) ) { if ( isSrcNat ) { if ( key -> ipKey . l4 . tpSrc != 0 ) { key -> ipKey . l4 . tpSrc = endpoint -> port ; } } else { if ( key -> ipKey . l4 . tpDst != 0 ) { key -> ipKey . l4 . tpDst = endpoint -> port ; } } } }
OvsNatPacket
     Performs NAT operation on the packet by replacing the source/destinaton
     address/port based on natAction.
OvsNatPacket Performs NAT operation on the packet by replacing the source / destinaton address / port based on natAction .
/* When it is NAT, only entry->rev_key contains NATTED address;
       When it is unNAT, only entry->key contains the UNNATTED address;*/ /* Flag is set to SNAT for SNAT case and the reverse DNAT case */ /* Note that ctKey is the key in the other direction, so
           endpoint has to be reverted, i.e. ctKey->dst for SNAT
           and ctKey->src for DNAT */ // XXX: IPv6 packet not supported yet.