diff options
author | Darrell Ball <dlu998@gmail.com> | 2017-12-04 08:13:06 -0800 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-12-11 14:14:11 -0800 |
commit | bd7d93f8b4855ff8edc14dc094cd91a48ea10d17 (patch) | |
tree | b3f8695287f26468c0aaf3e7a6a93baa3173b3e1 /lib/conntrack.c | |
parent | 94e711433c34c4f0b21779d24ee3a22136c8f4be (diff) | |
download | openvswitch-bd7d93f8b4855ff8edc14dc094cd91a48ea10d17.tar.gz |
conntrack: Allow specified alg port numbers.
Algs can use variable control port numbers for servers.
The main use case is a kind of feeble security measure; the
thinking being by some is that it obscures the alg traffic.
It is really not very effective, but the kernel has this
capability. This patch mimics the capability.
Signed-off-by: Darrell Ball <dlu998@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
Diffstat (limited to 'lib/conntrack.c')
-rw-r--r-- | lib/conntrack.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/lib/conntrack.c b/lib/conntrack.c index b37038414..61f3a79e8 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -462,23 +462,37 @@ is_ftp_ctl(const enum ct_alg_ctl_type ct_alg_ctl) } static enum ct_alg_ctl_type -get_alg_ctl_type(const struct dp_packet *pkt) +get_alg_ctl_type(const struct dp_packet *pkt, ovs_be16 tp_src, ovs_be16 tp_dst, + const char *helper) { - uint8_t ip_proto = get_ip_proto(pkt); - struct udp_header *uh = dp_packet_l4(pkt); - struct tcp_header *th = dp_packet_l4(pkt); - /* CT_IPPORT_FTP/TFTP is used because IPPORT_FTP/TFTP in not defined * in OSX, at least in in.h. Since these values will never change, remove * the external dependency. */ enum { CT_IPPORT_FTP = 21 }; enum { CT_IPPORT_TFTP = 69 }; + uint8_t ip_proto = get_ip_proto(pkt); + struct udp_header *uh = dp_packet_l4(pkt); + struct tcp_header *th = dp_packet_l4(pkt); + ovs_be16 ftp_src_port = htons(CT_IPPORT_FTP); + ovs_be16 ftp_dst_port = htons(CT_IPPORT_FTP); + ovs_be16 tftp_dst_port = htons(CT_IPPORT_TFTP); + + if (OVS_UNLIKELY(tp_dst)) { + if (helper && !strncmp(helper, "ftp", strlen("ftp"))) { + ftp_dst_port = tp_dst; + } else if (helper && !strncmp(helper, "tftp", strlen("tftp"))) { + tftp_dst_port = tp_dst; + } + } else if (OVS_UNLIKELY(tp_src)) { + if (helper && !strncmp(helper, "ftp", strlen("ftp"))) { + ftp_src_port = tp_src; + } + } - if (ip_proto == IPPROTO_UDP && uh->udp_dst == htons(CT_IPPORT_TFTP)) { + if (ip_proto == IPPROTO_UDP && uh->udp_dst == tftp_dst_port) { return CT_ALG_CTL_TFTP; } else if (ip_proto == IPPROTO_TCP && - (th->tcp_src == htons(CT_IPPORT_FTP) || - th->tcp_dst == htons(CT_IPPORT_FTP))) { + (th->tcp_src == ftp_src_port || th->tcp_dst == ftp_dst_port)) { return CT_ALG_CTL_FTP; } return CT_ALG_CTL_NONE; @@ -1134,7 +1148,7 @@ process_one(struct conntrack *ct, struct dp_packet *pkt, bool force, bool commit, long long now, const uint32_t *setmark, const struct ovs_key_ct_labels *setlabel, const struct nat_action_info_t *nat_action_info, - const char *helper) + ovs_be16 tp_src, ovs_be16 tp_dst, const char *helper) { struct conn *conn; unsigned bucket = hash_to_bucket(ctx->hash); @@ -1181,7 +1195,8 @@ process_one(struct conntrack *ct, struct dp_packet *pkt, struct conn conn_for_un_nat_copy; conn_for_un_nat_copy.conn_type = CT_CONN_TYPE_DEFAULT; - enum ct_alg_ctl_type ct_alg_ctl = get_alg_ctl_type(pkt); + enum ct_alg_ctl_type ct_alg_ctl = get_alg_ctl_type(pkt, tp_src, tp_dst, + helper); if (OVS_LIKELY(conn)) { if (OVS_LIKELY(!conn_update_state_alg(ct, pkt, ctx, conn, @@ -1264,7 +1279,7 @@ conntrack_execute(struct conntrack *ct, struct dp_packet_batch *pkt_batch, ovs_be16 dl_type, bool force, bool commit, uint16_t zone, const uint32_t *setmark, const struct ovs_key_ct_labels *setlabel, - const char *helper, + ovs_be16 tp_src, ovs_be16 tp_dst, const char *helper, const struct nat_action_info_t *nat_action_info, long long now) { @@ -1279,7 +1294,7 @@ conntrack_execute(struct conntrack *ct, struct dp_packet_batch *pkt_batch, continue; } process_one(ct, packet, &ctx, zone, force, commit, now, setmark, - setlabel, nat_action_info, helper); + setlabel, nat_action_info, tp_src, tp_dst, helper); } return 0; |