diff --git a/grpc/proto/plugin.pb.go b/grpc/proto/plugin.pb.go index 6b1557ee..b41a2988 100644 --- a/grpc/proto/plugin.pb.go +++ b/grpc/proto/plugin.pb.go @@ -91,6 +91,7 @@ const ( ColumnType_IPADDR ColumnType = 6 ColumnType_CIDR ColumnType = 7 ColumnType_TIMESTAMP ColumnType = 8 + ColumnType_INET ColumnType = 9 ColumnType_UNKNOWN ColumnType = -1 ) @@ -106,6 +107,7 @@ var ( 6: "IPADDR", 7: "CIDR", 8: "TIMESTAMP", + 9: "INET", -1: "UNKNOWN", } ColumnType_value = map[string]int32{ @@ -118,6 +120,7 @@ var ( "IPADDR": 6, "CIDR": 7, "TIMESTAMP": 8, + "INET": 9, "UNKNOWN": -1, } ) @@ -1633,32 +1636,32 @@ var file_plugin_proto_rawDesc = []byte{ 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x2a, 0x1b, 0x0a, 0x09, 0x4e, 0x75, 0x6c, 0x6c, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x0e, 0x0a, 0x0a, 0x4e, 0x55, 0x4c, 0x4c, 0x5f, 0x56, 0x41, - 0x4c, 0x55, 0x45, 0x10, 0x00, 0x2a, 0x8a, 0x01, 0x0a, 0x0a, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, + 0x4c, 0x55, 0x45, 0x10, 0x00, 0x2a, 0x94, 0x01, 0x0a, 0x0a, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x42, 0x4f, 0x4f, 0x4c, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x49, 0x4e, 0x54, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x44, 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x4a, 0x53, 0x4f, 0x4e, 0x10, 0x04, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x41, 0x54, 0x45, 0x54, 0x49, 0x4d, 0x45, 0x10, 0x05, 0x12, 0x0a, 0x0a, 0x06, 0x49, 0x50, 0x41, 0x44, 0x44, 0x52, 0x10, 0x06, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x49, 0x44, 0x52, 0x10, 0x07, 0x12, 0x0d, 0x0a, - 0x09, 0x54, 0x49, 0x4d, 0x45, 0x53, 0x54, 0x41, 0x4d, 0x50, 0x10, 0x08, 0x12, 0x14, 0x0a, 0x07, - 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x01, 0x32, 0xe9, 0x01, 0x0a, 0x0d, 0x57, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x50, 0x6c, - 0x75, 0x67, 0x69, 0x6e, 0x12, 0x3e, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, - 0x61, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x63, 0x68, - 0x65, 0x6d, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3a, 0x0a, 0x07, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x12, - 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, - 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, - 0x12, 0x5c, 0x0a, 0x13, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, - 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, - 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, - 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x09, 0x54, 0x49, 0x4d, 0x45, 0x53, 0x54, 0x41, 0x4d, 0x50, 0x10, 0x08, 0x12, 0x08, 0x0a, 0x04, + 0x49, 0x4e, 0x45, 0x54, 0x10, 0x09, 0x12, 0x14, 0x0a, 0x07, 0x55, 0x4e, 0x4b, 0x4e, 0x4f, 0x57, + 0x4e, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x32, 0xe9, 0x01, 0x0a, + 0x0d, 0x57, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x12, 0x3e, + 0x0a, 0x09, 0x47, 0x65, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x17, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, + 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3a, + 0x0a, 0x07, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x12, 0x15, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x12, 0x5c, 0x0a, 0x13, 0x53, 0x65, + 0x74, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x12, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x74, 0x43, 0x6f, 0x6e, + 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x22, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x53, 0x65, 0x74, + 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/grpc/proto/plugin.proto b/grpc/proto/plugin.proto index e2dfb1cb..633f25cb 100644 --- a/grpc/proto/plugin.proto +++ b/grpc/proto/plugin.proto @@ -156,5 +156,6 @@ enum ColumnType { IPADDR = 6; CIDR = 7; TIMESTAMP = 8; + INET = 9; UNKNOWN = -1; } \ No newline at end of file diff --git a/plugin/table_column.go b/plugin/table_column.go index 2ca3ab8b..4112d998 100644 --- a/plugin/table_column.go +++ b/plugin/table_column.go @@ -160,7 +160,7 @@ func (t *Table) interfaceToColumnValue(column *Column, val interface{}) (*proto. break case proto.ColumnType_IPADDR: ipString := types.SafeString(val) - // tread an empty string as a null ip address + // treat an empty string as a null ip address if ipString == "" { columnValue = &proto.Column{Value: &proto.Column_NullValue{}} } else { @@ -172,16 +172,30 @@ func (t *Table) interfaceToColumnValue(column *Column, val interface{}) (*proto. break case proto.ColumnType_CIDR: cidrRangeString := types.SafeString(val) - // tread an empty string as a null ip address + // treat an empty string as a null ip address if cidrRangeString == "" { columnValue = &proto.Column{Value: &proto.Column_NullValue{}} } else { if _, _, err := net.ParseCIDR(cidrRangeString); err != nil { - return nil, fmt.Errorf("interfaceToColumnValue failed for column '%s': %v", column.Name, err) + return nil, fmt.Errorf("%s: invalid ip address %s", column.Name, cidrRangeString) } columnValue = &proto.Column{Value: &proto.Column_CidrRangeValue{CidrRangeValue: cidrRangeString}} } break + case proto.ColumnType_INET: + inetString := types.SafeString(val) + // treat an empty string as a null ip address + if inetString == "" { + columnValue = &proto.Column{Value: &proto.Column_NullValue{}} + } else { + if ip := net.ParseIP(inetString); ip == nil { + if _, _, err := net.ParseCIDR(inetString); err != nil { + return nil, fmt.Errorf("%s: invalid ip address %s", column.Name, inetString) + } + } + columnValue = &proto.Column{Value: &proto.Column_CidrRangeValue{CidrRangeValue: inetString}} + } + break default: return nil, fmt.Errorf("unrecognised columnValue type '%s'", column.Type) } diff --git a/plugin/table_quals.go b/plugin/table_quals.go index 87c83066..865a5afb 100644 --- a/plugin/table_quals.go +++ b/plugin/table_quals.go @@ -89,7 +89,7 @@ func ColumnQualValue(qv *proto.QualValue, column *Column) interface{} { return qv.GetTimestampValue() case proto.ColumnType_JSON: return qv.GetJsonbValue() - case proto.ColumnType_IPADDR, proto.ColumnType_CIDR: + case proto.ColumnType_IPADDR, proto.ColumnType_CIDR, proto.ColumnType_INET: return qv.GetInetValue() default: return nil diff --git a/plugin/table_validate.go b/plugin/table_validate.go index 43644255..9c998df1 100644 --- a/plugin/table_validate.go +++ b/plugin/table_validate.go @@ -66,6 +66,8 @@ func columnTypeToString(columnType proto.ColumnType) string { return "ColumnType_IPADDR" case proto.ColumnType_CIDR: return "ColumnType_CIDR" + case proto.ColumnType_INET: + return "ColumnType_INET" case proto.ColumnType_TIMESTAMP: return "ColumnType_TIMESTAMP" default: