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

Fix diameter AVP filter matching #164

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fholzhauser
Copy link
Contributor

Condition matching didn't work and expected when there were path branches behind the condition. AVP filter condition value matching made more flexible.

@fholzhauser fholzhauser requested a review from a team July 14, 2021 21:51
vkatsuba
vkatsuba previously approved these changes Jul 14, 2021
@@ -74,6 +74,7 @@ It is also possible to use conditions on the top level, conditioning the deletio

NOTE: Of course removing an AVP marked as positional/mandatory in the dictionary definion will result in encoding failure. I.e. we are not referring to the M bit in the AVP definition, but APVs marked `<avp>` or `{avp}` in the ABNF definition of the messages.

To prepare for not Erlang native configuration inputs, the matching of AVP values in the conditions are made somewhat flexible. The value matching will attempt to match the condition to the type of the AVP value including the single element list OTP diameter uses for optional AVP values. E.g. an IP address condition given in binary `<<"192.168.0.1">>` format is going to match with AVP values in formats `<<"192.168.0.1">>`, `{192,168,0,1}` or in case of optional AVP `[<<"192.168.0.1">>]`, `[{192,168,0,1}]`. Currently matching string, integer and IP address types are supported.
Copy link

Choose a reason for hiding this comment

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

Is it possible to normalise the input/condition ? Allow Erlang, JSON, xxx input, but change it to binary, integer, tuple? Or is that too complex ? You would have to know what Erlang/OTP Diameter type of that condition is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, however it is inconvenient. Some parameters are allowed (and used in the code) in different formats (e.g. ip addresses that can be tuple or binary). It could work if OTP diameter would be somewhat more consistent in the data formats in the prepare request stage (and e.g. do away with the single element list marking of message optional values). I'm not sure we can put that burden to get it right to anyone operationally configuring the filter.

Copy link
Member

Choose a reason for hiding this comment

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

travelping/ergw#417 adds DIAMETER type annotations to fields in the JSON/YAML config.
We could opt for not striping them out and using them here to check the correct type as well.

BTW: the only type that are somewhat arbitrary are Address and OctetString (from base/diameter.erl):

-type 'OctetString'() :: iolist().
-type 'Address'()
   :: inet:ip_address()
    | string().

Time could be called annoying, but nothing a config parse can't handle:

-type 'Time'()             :: {{integer(), 1..12, 1..31},
                               {0..23, 0..59, 0..59}}.

Floats are also problematic, but we don't use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what benefit it'd bring to check the types here in the filter. IMO the AVP structure is coming from code and code errors we should try to catch elsewhere.

Adding the types in the filter config might not be sufficient. Without such format/type matching here, we'd need to make sure to unify the format of Address and OctetString (can be list or binary too) we put in the messages we compose (may not be many places, didn't look yet). Also make sure whenever someone changes code, it stays unified (despite what diameter allows). Whoever makes the configuration should also understand what AVP is message/group optional or mandatory (most will probably look at the M flag in the pcap and get confused 😉) and put it into the config accordingly.

Since we have the message available, we can deduct the used format/type here, sounds safer to me, even if one could argue that in principle it is somewhat less correct.

I guess the generic question for the discussion is: how much of the complexity of the OTP internal diameter implementation we want to expose to this configuration. My preference is : as little as we can get away with. Which is kind of the idea behind this at the moment.

Time format is indeed not too difficult, but I didn't consider it (yet) : just like floats, it sounds too variable by nature to make sense for filtering.

AVPVal == binary_to_integer(ConditionVal);
match_avp_value(ConditionVal, AVPVal)
when is_binary(ConditionVal) andalso is_atom(AVPVal) ->
AVPVal == binary_to_existing_atom(ConditionVal, utf8);
Copy link

Choose a reason for hiding this comment

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

Might fail with badardg. You have to have it inside ''when''.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, binary_to_atom/2 should do here. The binary is coming from config, the chance for significant atom table pollution is minimal. Fixing.

src/ergw_aaa_diameter_srv.erl Show resolved Hide resolved
],
{Before, After} = do_filter_test(Filter),

Copy link
Contributor

Choose a reason for hiding this comment

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

extra spaces here and at 219 line

@RoadRunnr
Copy link
Member

this PR is not need when we use travelping/ergw#417

@fholzhauser
Copy link
Contributor Author

this PR is not need when we use travelping/ergw#417

I'm not (yet) convinced about that ...

@fholzhauser fholzhauser marked this pull request as draft July 22, 2021 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants