Skip to content
Snippets Groups Projects
Unverified Commit 472038bb authored by Mohamed S. Mahmoud's avatar Mohamed S. Mahmoud Committed by GitHub
Browse files

Merge pull request #508 from msherif1234/xlat-icmp

NETOBSERV-2055: Xlat ICMP code is redundant with icmp code field so removing it
parents 73256abe 63dcf7c3
No related branches found
No related tags found
No related merge requests found
......@@ -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],
......@@ -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:
......@@ -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:
......@@ -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);
}
......@@ -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);
......@@ -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;
}
......@@ -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) {
......@@ -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;
}
}
......
......@@ -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;
......
......@@ -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:
return true;
}
return false;
}
#endif // __UTILS_H__
......@@ -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
}
}
......
......@@ -150,6 +150,5 @@ func TestPBFlowToMap(t *testing.T) {
"XlatSrcPort": uint16(1),
"XlatDstPort": uint16(2),
"ZoneId": uint16(100),
"XlatIcmpId": uint8(0),
}, out)
}
......@@ -20,6 +20,7 @@ type BpfAdditionalMetrics struct {
FlowRtt uint64
NetworkEvents [4][8]uint8
TranslatedFlow BpfTranslatedFlowT
_ [2]byte
ObservedIntf [4]BpfObservedIntfT
EthProtocol uint16
NetworkEventsIdx uint8
......@@ -181,8 +182,6 @@ type BpfTranslatedFlowT struct {
Sport uint16
Dport uint16
ZoneId uint16
IcmpId uint8
_ [1]byte
}
// LoadBpf returns the embedded CollectionSpec for Bpf.
......
No preview for this file type
......@@ -20,6 +20,7 @@ type BpfAdditionalMetrics struct {
FlowRtt uint64
NetworkEvents [4][8]uint8
TranslatedFlow BpfTranslatedFlowT
_ [2]byte
ObservedIntf [4]BpfObservedIntfT
EthProtocol uint16
NetworkEventsIdx uint8
......@@ -181,8 +182,6 @@ type BpfTranslatedFlowT struct {
Sport uint16
Dport uint16
ZoneId uint16
IcmpId uint8
_ [1]byte
}
// LoadBpf returns the embedded CollectionSpec for Bpf.
......
No preview for this file type
......@@ -20,6 +20,7 @@ type BpfAdditionalMetrics struct {
FlowRtt uint64
NetworkEvents [4][8]uint8
TranslatedFlow BpfTranslatedFlowT
_ [2]byte
ObservedIntf [4]BpfObservedIntfT
EthProtocol uint16
NetworkEventsIdx uint8
......@@ -181,8 +182,6 @@ type BpfTranslatedFlowT struct {
Sport uint16
Dport uint16
ZoneId uint16
IcmpId uint8
_ [1]byte
}
// LoadBpf returns the embedded CollectionSpec for Bpf.
......
No preview for this file type
......@@ -20,6 +20,7 @@ type BpfAdditionalMetrics struct {
FlowRtt uint64
NetworkEvents [4][8]uint8
TranslatedFlow BpfTranslatedFlowT
_ [2]byte
ObservedIntf [4]BpfObservedIntfT
EthProtocol uint16
NetworkEventsIdx uint8
......@@ -181,8 +182,6 @@ type BpfTranslatedFlowT struct {
Sport uint16
Dport uint16
ZoneId uint16
IcmpId uint8
_ [1]byte
}
// LoadBpf returns the embedded CollectionSpec for Bpf.
......
No preview for this file type
......@@ -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
......@@ -151,7 +150,6 @@ func TestAdditionalMetricsBinaryEncoding(t *testing.T) {
Sport: 0,
Dport: 0,
ZoneId: 2,
IcmpId: 0,
},
NbObservedIntf: 2,
ObservedIntf: [MaxObservedInterfaces]ebpf.BpfObservedIntfT{
......
......@@ -791,7 +791,6 @@ type Xlat struct {
SrcPort uint32 `protobuf:"varint,3,opt,name=src_port,json=srcPort,proto3" json:"src_port,omitempty"`
DstPort uint32 `protobuf:"varint,4,opt,name=dst_port,json=dstPort,proto3" json:"dst_port,omitempty"`
ZoneId uint32 `protobuf:"varint,5,opt,name=zone_id,json=zoneId,proto3" json:"zone_id,omitempty"`
IcmpId uint32 `protobuf:"varint,7,opt,name=icmp_id,json=icmpId,proto3" json:"icmp_id,omitempty"`
}
func (x *Xlat) Reset() {
......@@ -859,13 +858,6 @@ func (x *Xlat) GetZoneId() uint32 {
return 0
}
func (x *Xlat) GetIcmpId() uint32 {
if x != nil {
return x.IcmpId
}
return 0
}
var File_proto_flow_proto protoreflect.FileDescriptor
var file_proto_flow_proto_rawDesc = []byte{
......@@ -990,7 +982,7 @@ var file_proto_flow_proto_rawDesc = []byte{
0x6f, 0x72, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x64, 0x73, 0x74, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x64, 0x73, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x1a,
0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x22, 0xbc, 0x01, 0x0a, 0x04, 0x58,
0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x22, 0xa3, 0x01, 0x0a, 0x04, 0x58,
0x6c, 0x61, 0x74, 0x12, 0x25, 0x0a, 0x08, 0x73, 0x72, 0x63, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18,
0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x70, 0x62, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x49,
0x50, 0x52, 0x07, 0x73, 0x72, 0x63, 0x41, 0x64, 0x64, 0x72, 0x12, 0x25, 0x0a, 0x08, 0x64, 0x73,
......@@ -1001,16 +993,14 @@ var file_proto_flow_proto_rawDesc = []byte{
0x64, 0x73, 0x74, 0x5f, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07,
0x64, 0x73, 0x74, 0x50, 0x6f, 0x72, 0x74, 0x12, 0x17, 0x0a, 0x07, 0x7a, 0x6f, 0x6e, 0x65, 0x5f,
0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x7a, 0x6f, 0x6e, 0x65, 0x49, 0x64,
0x12, 0x17, 0x0a, 0x07, 0x69, 0x63, 0x6d, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x06, 0x69, 0x63, 0x6d, 0x70, 0x49, 0x64, 0x2a, 0x24, 0x0a, 0x09, 0x44, 0x69, 0x72,
0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0b, 0x0a, 0x07, 0x49, 0x4e, 0x47, 0x52, 0x45, 0x53,
0x53, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x47, 0x52, 0x45, 0x53, 0x53, 0x10, 0x01, 0x32,
0x3e, 0x0a, 0x09, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x31, 0x0a, 0x04,
0x53, 0x65, 0x6e, 0x64, 0x12, 0x0f, 0x2e, 0x70, 0x62, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x52, 0x65,
0x63, 0x6f, 0x72, 0x64, 0x73, 0x1a, 0x16, 0x2e, 0x70, 0x62, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x43,
0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42,
0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x70, 0x62, 0x66, 0x6c, 0x6f, 0x77, 0x62, 0x06, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x33,
0x2a, 0x24, 0x0a, 0x09, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0b, 0x0a,
0x07, 0x49, 0x4e, 0x47, 0x52, 0x45, 0x53, 0x53, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x47,
0x52, 0x45, 0x53, 0x53, 0x10, 0x01, 0x32, 0x3e, 0x0a, 0x09, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63,
0x74, 0x6f, 0x72, 0x12, 0x31, 0x0a, 0x04, 0x53, 0x65, 0x6e, 0x64, 0x12, 0x0f, 0x2e, 0x70, 0x62,
0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x73, 0x1a, 0x16, 0x2e, 0x70,
0x62, 0x66, 0x6c, 0x6f, 0x77, 0x2e, 0x43, 0x6f, 0x6c, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x52,
0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2f, 0x70, 0x62, 0x66, 0x6c,
0x6f, 0x77, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
......
......@@ -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)
......@@ -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()),
},
},
},
......
......@@ -108,5 +108,4 @@ message Xlat {
uint32 src_port = 3;
uint32 dst_port = 4;
uint32 zone_id = 5;
uint32 icmp_id = 7;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment