This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Support caching more than 1 IP address per DNS cache entry #1981
Support caching more than 1 IP address per DNS cache entry #1981
Changes from all commits
e9f59e6
bdc8a7e
1c5c5e0
efefc8f
3333db7
c00c26d
8a6af51
75d55fe
aff590a
a08fe63
fb54b45
1a5025c
78f4ead
ef30a6c
8f298fd
770ad8a
73abe57
6ed9398
8876e93
39028b5
10e168b
d9cd0ef
3faa9ee
1d56c77
14d0cbb
0fea8a9
ac6172e
196f145
f43e68b
b407fa4
46c1993
91ce414
34ff898
fd22213
327f188
b794e20
5f2ba3a
d2a4bb0
1597707
c636a40
8c612a6
f41125c
48ebb12
5414fbd
5ff6831
23a4ca2
5f4b529
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Suppose that 10 addresses were found. When calling this function repeatedly, I would see the addresses 0..9, 0..9, and when
ucCurrentIPAddress
becomes 255, I would see 0..5, followed by 0..9 again?Why not:
Making
ucCurrentIPAddress
auint8_t
is no problem, DNS can not return more than +/- 27 answers.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.
One more general question about the change:
Suppose I'm looking up the addresses of some host and it receives 5 IP-addresses.
I will call
FreeRTOS_gethostbyname()
repeatedly to see all addresses.How do I know when I've seen all IP-addresses? Should I remember the first IP-address received?
Why not return 0 after the last IP-address was returned? And then the first IP-address again?
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.
Applications using
FreeRTOS_gethostbyname()
should interpret the result as an independent scalar value rather than a member of a list, and they should not prefer any value over any other. When we have an implementation ofFreeRTOS_getaddrinfo()
, applications will have the option of choosing a particular address, which could be useful in some circumstances.The reasoning behind this change is to give app developers an easy way to increase reliability of their app when connecting to a load-balanced service, without requiring them to change any application logic. As just one example, the amazon-freertos repo has dozens of tests and demos which can benefit immediately without any modification.
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 didn't choose this option because I didn't want to have to do anything for thread safety for cases where two tasks both call
FreeRTOS_gethostbyname()
. In the event that there was a context switch after theif
but before the statement in{...}
, we could have a TOCTOU error resulting in an out-of-bound array access.The side effect of doing the modulo approach as you have pointed out is that you the order that addresses appear may not reflect how they are stored internally, but this isn't important since the caller should make no assumption about these values. The only thing that is promised is that
FreeRTOS_gethostbyname()
will return an answer if one is available.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.
What if we do
Would it remove TOCTOU error? I could not think of a case where it fails. Do correct me if I am wrong.
I am just trying to reduce computation as much as we can. Modulo operation is quite expensive than a comparison statement in a lot of architectures.
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.
Remember that if interrupts aren't masked, a context switch can happen at any time. And since this code is not protected by any mutual-exclusion mechanism such as a mutex or semaphore (and we don't want to add those if we don't have to), you can still have the error.
In any case, the code as written is simpler and avoids any possibility of this occurring.
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.
Do we want to have a similar note to this for a scenario where ipconfigUSE_DNS_CACHE == 1 and ipconfigDNS_CACHE_ADDRESSES_PER_ENTRY == 1? This seems like it would have the same issue that this note addresses.
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 would, that's a good point. I'll add a note in the example FreeRTOSIPConfig.h about this.
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.
Added a clarifying comment in FreeRTOSIPConfigDefaults.h
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.
Can we make this
6U
? MISRA tends to dislike operations between signed and unsigned values. (Such as modulo operation in FreeRTOS_DNS.c)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 vendor code and it likely has the same issues throughout (see line 77). If Coverity raises a warning, we'll address that in a separate PR.
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.
Can we make this
6U
? MISRA tends to dislike arithmetic operations between signed and unsigned variables,.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.
See previous comment, that will be addressed in a PR if Coverity raises a warning.
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.
Can we make this 6U? MISRA tends to dislike arithmetic operations between signed and unsigned variables.
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.
Correction in other ports as well if possible.
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.
See previous comment.