Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETOBSERV-2055: Xlat ICMP code is redundant with icmp code field so removing it #508

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions bpf/pkt_translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#define s6_addr in6_u.u6_addr8

static inline void dump_xlated_flow(struct translated_flow_t *flow) {
BPF_PRINTK("zone_id %d sport %d dport %d icmpId %d\n", flow->zone_id, flow->sport, flow->dport,
flow->icmp_id);
BPF_PRINTK("zone_id %d sport %d dport %d\n", flow->zone_id, flow->sport, flow->dport);
int i;
for (i = 0; i < IP_MAX_LEN; i += 4) {
BPF_PRINTK("scrIP[%d]:%d.%d.%d.%d\n", i, flow->saddr[0 + i], flow->saddr[1 + i],
Expand All @@ -23,12 +22,15 @@ static inline void dump_xlated_flow(struct translated_flow_t *flow) {
}
}

static inline void parse_tuple(struct nf_conntrack_tuple *t, struct translated_flow_t *flow,
u16 zone_id, u16 family, bool invert) {
static void __always_inline parse_tuple(struct nf_conntrack_tuple *t,
struct translated_flow_t *flow, u16 zone_id, u16 family,
u8 protocol, bool invert) {
__builtin_memset(flow, 0, sizeof(*flow));
if (invert) {
flow->dport = bpf_ntohs(t->src.u.all);
flow->sport = bpf_ntohs(t->dst.u.all);
if (is_transport_protocol(protocol)) {
flow->dport = bpf_ntohs(t->src.u.all);
flow->sport = bpf_ntohs(t->dst.u.all);
}

switch (family) {
case AF_INET:
Expand All @@ -44,8 +46,10 @@ static inline void parse_tuple(struct nf_conntrack_tuple *t, struct translated_f
break;
}
} else {
flow->dport = bpf_ntohs(t->dst.u.all);
flow->sport = bpf_ntohs(t->src.u.all);
if (is_transport_protocol(protocol)) {
flow->dport = bpf_ntohs(t->dst.u.all);
flow->sport = bpf_ntohs(t->src.u.all);
}

switch (family) {
case AF_INET:
Expand All @@ -61,7 +65,6 @@ static inline void parse_tuple(struct nf_conntrack_tuple *t, struct translated_f
break;
}
}
flow->icmp_id = t->src.u.icmp.id;
flow->zone_id = zone_id;
dump_xlated_flow(flow);
}
Expand All @@ -73,7 +76,7 @@ static inline long translate_lookup_and_update_flow(flow_id *id, u16 flags,
long ret = 0;
struct translated_flow_t orig;

parse_tuple(orig_t, &orig, zone_id, family, false);
parse_tuple(orig_t, &orig, zone_id, family, id->transport_protocol, false);

// update id with original flow info
__builtin_memcpy(id->src_ip, orig.saddr, IP_MAX_LEN);
Expand All @@ -85,7 +88,8 @@ static inline long translate_lookup_and_update_flow(flow_id *id, u16 flags,
additional_metrics *extra_metrics = bpf_map_lookup_elem(&additional_flow_metrics, id);
if (extra_metrics != NULL) {
extra_metrics->end_mono_time_ts = current_time;
parse_tuple(reply_t, &extra_metrics->translated_flow, zone_id, family, true);
parse_tuple(reply_t, &extra_metrics->translated_flow, zone_id, family,
id->transport_protocol, true);
return ret;
}

Expand All @@ -95,7 +99,8 @@ static inline long translate_lookup_and_update_flow(flow_id *id, u16 flags,
.end_mono_time_ts = current_time,
.eth_protocol = eth_protocol,
};
parse_tuple(reply_t, &new_extra_metrics.translated_flow, zone_id, family, true);
parse_tuple(reply_t, &new_extra_metrics.translated_flow, zone_id, family,
id->transport_protocol, true);
ret = bpf_map_update_elem(&additional_flow_metrics, id, &new_extra_metrics, BPF_NOEXIST);
if (ret != 0) {
if (trace_messages && ret != -EEXIST) {
Expand All @@ -105,7 +110,8 @@ static inline long translate_lookup_and_update_flow(flow_id *id, u16 flags,
additional_metrics *extra_metrics = bpf_map_lookup_elem(&additional_flow_metrics, id);
if (extra_metrics != NULL) {
extra_metrics->end_mono_time_ts = current_time;
parse_tuple(reply_t, &extra_metrics->translated_flow, zone_id, family, true);
parse_tuple(reply_t, &extra_metrics->translated_flow, zone_id, family,
id->transport_protocol, true);
return 0;
}
}
Expand Down
1 change: 0 additions & 1 deletion bpf/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ typedef struct additional_metrics_t {
u16 sport;
u16 dport;
u16 zone_id;
u8 icmp_id;
} translated_flow;
struct observed_intf_t {
u8 direction;
Expand Down
10 changes: 10 additions & 0 deletions bpf/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,14 @@ static inline void fill_in_others_protocol(flow_id *id, u8 protocol) {
id->transport_protocol = protocol;
}

static inline bool is_transport_protocol(u8 protocol) {
switch (protocol) {
case IPPROTO_TCP:
case IPPROTO_UDP:
case IPPROTO_SCTP:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into the linux headers / nf_conntrack_man_proto, sounds like DCCP can also have port?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we don't support or parse that protocol in openshift

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah never mind .. no point doing it in xlat if we don't do it in the main path anyway

return true;
}
return false;
}

#endif // __UTILS_H__
9 changes: 6 additions & 3 deletions pkg/decode/decode_protobuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ func RecordToMap(fr *model.Record) config.GenericMap {
if !model.AllZeroIP(model.IP(fr.Metrics.AdditionalMetrics.TranslatedFlow.Daddr)) &&
!model.AllZeroIP(model.IP(fr.Metrics.AdditionalMetrics.TranslatedFlow.Saddr)) {
out["ZoneId"] = fr.Metrics.AdditionalMetrics.TranslatedFlow.ZoneId
out["XlatSrcPort"] = fr.Metrics.AdditionalMetrics.TranslatedFlow.Sport
out["XlatDstPort"] = fr.Metrics.AdditionalMetrics.TranslatedFlow.Dport
if fr.Metrics.AdditionalMetrics.TranslatedFlow.Sport != 0 {
out["XlatSrcPort"] = fr.Metrics.AdditionalMetrics.TranslatedFlow.Sport
}
if fr.Metrics.AdditionalMetrics.TranslatedFlow.Dport != 0 {
out["XlatDstPort"] = fr.Metrics.AdditionalMetrics.TranslatedFlow.Dport
}
out["XlatSrcAddr"] = model.IP(fr.Metrics.AdditionalMetrics.TranslatedFlow.Saddr).String()
out["XlatDstAddr"] = model.IP(fr.Metrics.AdditionalMetrics.TranslatedFlow.Daddr).String()
out["XlatIcmpId"] = fr.Metrics.AdditionalMetrics.TranslatedFlow.IcmpId
}
}

Expand Down
1 change: 0 additions & 1 deletion pkg/decode/decode_protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,5 @@ func TestPBFlowToMap(t *testing.T) {
"XlatSrcPort": uint16(1),
"XlatDstPort": uint16(2),
"ZoneId": uint16(100),
"XlatIcmpId": uint8(0),
}, out)
}
3 changes: 1 addition & 2 deletions pkg/ebpf/bpf_arm64_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/ebpf/bpf_arm64_bpfel.o
Binary file not shown.
3 changes: 1 addition & 2 deletions pkg/ebpf/bpf_powerpc_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/ebpf/bpf_powerpc_bpfel.o
Binary file not shown.
3 changes: 1 addition & 2 deletions pkg/ebpf/bpf_s390_bpfeb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/ebpf/bpf_s390_bpfeb.o
Binary file not shown.
3 changes: 1 addition & 2 deletions pkg/ebpf/bpf_x86_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/ebpf/bpf_x86_bpfel.o
Binary file not shown.
4 changes: 1 addition & 3 deletions pkg/model/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ func TestAdditionalMetricsBinaryEncoding(t *testing.T) {
0x00, 0x00,
0x00, 0x00,
0x02, 0x00,
0x00,
0x00, // 1 byte padding
0x00, 0x00, // 2bytes padding
// observed_intf_t[4]
0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, // [0]: u8 direction + 3 bytes padding + u32 if_index
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, // [1]: u8 direction + 3 bytes padding + u32 if_index
Expand Down Expand Up @@ -151,7 +150,6 @@ func TestAdditionalMetricsBinaryEncoding(t *testing.T) {
Sport: 0,
Dport: 0,
ZoneId: 2,
IcmpId: 0,
},
NbObservedIntf: 2,
ObservedIntf: [MaxObservedInterfaces]ebpf.BpfObservedIntfT{
Expand Down
28 changes: 9 additions & 19 deletions pkg/pbflow/flow.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pkg/pbflow/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func FlowToPB(fr *model.Record, s *ovnobserv.SampleDecoder) *Record {
SrcPort: uint32(fr.Metrics.AdditionalMetrics.TranslatedFlow.Sport),
DstPort: uint32(fr.Metrics.AdditionalMetrics.TranslatedFlow.Dport),
ZoneId: uint32(fr.Metrics.AdditionalMetrics.TranslatedFlow.ZoneId),
IcmpId: uint32(fr.Metrics.AdditionalMetrics.TranslatedFlow.IcmpId),
}
}
pbflowRecord.DupList = make([]*DupMapEntry, 0)
Expand Down Expand Up @@ -197,7 +196,6 @@ func PBToFlow(pb *Record) *model.Record {
Sport: uint16(pb.Xlat.GetSrcPort()),
Dport: uint16(pb.Xlat.GetDstPort()),
ZoneId: uint16(pb.Xlat.GetZoneId()),
IcmpId: uint8(pb.Xlat.GetIcmpId()),
},
},
},
Expand Down
1 change: 0 additions & 1 deletion proto/flow.proto
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ message Xlat {
uint32 src_port = 3;
uint32 dst_port = 4;
uint32 zone_id = 5;
uint32 icmp_id = 7;
}
Loading