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
Make fr_radius_encode_pair() a one-line wrapper around a dbuff version. #3463
Conversation
I'll hold off merging this until the rest of the encoder elements are done. Maybe use this PR to push up commits for each area of the encoder, and then squash it all down at the end. |
Will do; thanks.
…On Wed, May 20, 2020 at 10:58 AM Arran Cudbard-Bell < ***@***.***> wrote:
I'll hold off merging this until the rest of the encoder elements are
done. Maybe use this PR to push up commits for each area of the encoder,
and then squash it all down at the end.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#3463 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABV2HFCLWFF2IEHQVPFNIMTRSP43LANCNFSM4NGBYCHA>
.
|
e48ffd5
to
58006cb
Compare
This pull request introduces 1 alert when merging 58006cb into 12501cf - view on LGTM.com new alerts:
|
58006cb
to
3f03237
Compare
This pull request introduces 1 alert when merging 3f03237 into a02e21b - view on LGTM.com new alerts:
|
@jejones3141 looks like you tripped LGTM CI. Can you take a look and see what it's complaining about. |
Found it, and will send up a correction. (Also corrected a doxygen mistake.)
…On Fri, May 22, 2020 at 10:15 AM Arran Cudbard-Bell < ***@***.***> wrote:
@jejones3141 <https://github.com/jejones3141> looks like you tripped LGTM
CI. Can you take a look and see what it's complaining about.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3463 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABV2HFAHG7JHOVZ7GZIDJS3RS2JI3ANCNFSM4NGBYCHA>
.
|
9e87cdc
to
e4f83fb
Compare
src/protocols/radius/encode.c
Outdated
fr_da_stack_t *da_stack, unsigned int depth, | ||
fr_cursor_t *cursor, void *encoder_ctx) | ||
{ | ||
ssize_t slen; | ||
uint8_t *p = out; | ||
size_t init_remaining = fr_dbuff_remaining(dbuff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added FR_DBUFF_MAX_NO_ADVANCE
. Maybe it'd be better to use that here to initialise a fr_dbuff_t
on the stack, then we don't have to initialise a new dbuff for every call for encode_tlv_hdr[_internal]
.
You can then return at the end with:
return fr_dbuff_advance(dbuff, fr_dbuff_used(tlv))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I'll look for places I can use FR_DBUFF_MAX_NO_ADVANCE to advantage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been 4+ weeks. Can these commits be updated to use the new API?
The idea behind DBUFF was to avoid these manual length calculations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they can, once FR_DBUFF_MAX_NO_ADVANCE() gives you a dbuff with matching start and p.
* Fully migrating away from the original encode_value() will require a revision of | ||
* fr_struct_to_network() and revising the fr_encode_value_t type. | ||
*/ | ||
static ssize_t encode_value_dbuff(fr_dbuff_t *dbuff, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think encode_value
is used outside of this compilation unit, so there's no reason to wrap it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry; I thought replying to the email would show up here. The ptr/len version of encode_value() has to stay around because it's passed as a parameter to fr_struct_to_network(), which others use (and which, because it takes function pointer parameters, isn't easy to wrap); I wrote the one layer around it rather than doing it in each caller in src/protocols/radius/encode.c.
I wrapped it so that dbuff-using functions wouldn't have to switch back to
ptr/len to call encode_value(). encode_value() itself has to keep using
ptr/len for now because it is passed to fr_struct_to_network() which
expects that--one can't write a layer around it as one can for
fr_value_box_to_network(). It will have to wait until all callers of
fr_struct_to_network() use dbuffs.
…On Thu, May 28, 2020 at 12:24 PM Arran Cudbard-Bell < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/protocols/radius/encode.c
<#3463 (comment)>
:
> @@ -710,12 +709,46 @@ static ssize_t encode_value(uint8_t *out, size_t outlen,
return out_p - out;
}
-static ssize_t attr_shift(uint8_t const *start, uint8_t const *end,
+/** Encodes the data portion of an attribute into a dbuff
+ *
+ * Fully migrating away from the original encode_value() will require a revision of
+ * fr_struct_to_network() and revising the fr_encode_value_t type.
+ */
+static ssize_t encode_value_dbuff(fr_dbuff_t *dbuff,
I don't think encode_value is used outside of this compilation unit, so
there's no reason to wrap it?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3463 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABV2HFBFSQR5LRKK4ILXP3LRT2M3BANCNFSM4NGBYCHA>
.
|
Thank you. I will look into where I could use FR_DBUFF_MAX_NO_ADVANCE(),
and make sure that line in src/protocols/radius/encode.c is right.
…On Thu, May 28, 2020 at 12:21 PM Arran Cudbard-Bell < ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/protocols/radius/encode.c
<#3463 (comment)>
:
> fr_da_stack_t *da_stack, unsigned int depth,
fr_cursor_t *cursor, void *encoder_ctx)
{
ssize_t slen;
- uint8_t *p = out;
+ size_t init_remaining = fr_dbuff_remaining(dbuff);
I added FR_DBUFF_MAX_NO_ADVANCE. Maybe it'd be better to use that here to
initialise a fr_dbuff_t on the stack, then we don't have to initialise a
new dbuff for every call for encode_tlv_hdr[_internal].
You can then return at the end with:
return fr_dbuff_advance(dbuff, fr_dbuff_used(tlv))
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3463 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABV2HFBVQQJ2I2G4YGBQLWDRT2MQ7ANCNFSM4NGBYCHA>
.
|
f1587e9
to
a71fdd1
Compare
a71fdd1
to
b83b323
Compare
src/protocols/radius/encode.c
Outdated
FR_DBUFF_RETURN(encode_vsa_hdr, _dbuff, _da_stack, _depth, _cursor, _ctx) | ||
#define ENCODE_TLV_HDR_RETURN(_dbuff, _da_stack, _depth, _cursor, _ctx) \ | ||
FR_DBUFF_RETURN(encode_tlv_hdr, _dbuff, _da_stack, _depth, _cursor, _ctx) | ||
#define ENCODE_EXTENDED_HDR_RETURN(_dbuff, _da_stack, _depth, _cursor, _ctx) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these macros are only used once, there's no need to have them as macros.
src/protocols/radius/encode.c
Outdated
@@ -303,14 +319,16 @@ static ssize_t encode_tlv_hdr_internal(uint8_t *out, size_t outlen, | |||
vp = fr_cursor_current(cursor); | |||
} | |||
|
|||
return p - out; | |||
return init_remaining - fr_dbuff_remaining(dbuff); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should just be return fr_dbuff_used(dbuff)
here, and other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fr_dbuff_used(dbuff)
includes bytes already written to dbuff, so just doing that doesn't work. What is needed is no-advance dbuffs having start set to the parent's p (or more accurately the same thing as their p is set to; the FR_DBUFF_NO_ADVANCE_RESERVE()
macro has an edge case); actually, I'm not sure why that's not done for all children. Then you can write
fr_dbuff_t work_dbuff = FR_DBUFF_NO_ADVANCE(dbuff);
/* Do what's needed using work_dbuff */
return fr_dbuff_advance(dbuff, fr_dbuff_used(&work_dbuff));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's the pattern which should be used everywhere.
src/protocols/radius/encode.c
Outdated
fr_da_stack_t *da_stack, unsigned int depth, | ||
fr_cursor_t *cursor, void *encoder_ctx) | ||
{ | ||
ssize_t slen; | ||
ssize_t slen; | ||
uint8_t *hdr_field = dbuff->p; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a nitpick: we typically would use attr
here for radius. We don't generally use field
suffixes, as they're pretty much redundant.
Here, and other places in the commit.
src/protocols/radius/encode.c
Outdated
@@ -724,7 +772,7 @@ static ssize_t attr_shift(uint8_t const *start, uint8_t const *end, | |||
*/ | |||
|
|||
while (check_len > (255 - hdr_len)) { | |||
total += hdr_len; | |||
new_hdr_count++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why total
was changed to new_hdr_count
and then a later multiplication. It should just use total
as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; I will change it back.
src/protocols/radius/encode.c
Outdated
@@ -735,7 +783,7 @@ static ssize_t attr_shift(uint8_t const *start, uint8_t const *end, | |||
* "encode_value" function to take into account the header | |||
* lengths. | |||
*/ | |||
if ((ptr + ptr[1] + total) > end) return (ptr + ptr[1]) - start; | |||
if (fr_dbuff_advance(dbuff, new_hdr_count * hdr_len) < 0) return ptr[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning ptr[1]
changes the meaning of this return code. It should return the number of bytes necessary to encode this data.
The previous code returned the total amount of data encoded since start
. this change just returns the total amount of data in this particular attribute. So at the minimum, returning ptr[1]
is different from what it was before.
src/protocols/radius/encode.c
Outdated
@@ -1387,10 +1419,10 @@ ssize_t fr_radius_encode_pair(uint8_t *out, size_t outlen, fr_cursor_t *cursor, | |||
* using a different scheme than the "long | |||
* extended" one. | |||
*/ | |||
ret = encode_concat(out, outlen, &da_stack, 0, cursor, encoder_ctx); | |||
ENCODE_CONCAT_RETURN(dbuff, &da_stack, 0, cursor, encoder_ctx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear why macros are useful here.
d8ea999
to
66725a2
Compare
The conversion is not complete; encode_value() must wait until fr_struct_to_network(), which radius, dhcpv6, and arp use, can be converted to use dbuff.
66725a2
to
687886b
Compare
No description provided.