Skip to content

Conversation

@sigmundklaa
Copy link
Contributor

Implements a csp_iflist_remove function to go along with csp_iflist_add. This is useful to ensure full cleanup in case initialization of an interface fails for whatever reason.

Copy link
Member

@yashi yashi left a comment

Choose a reason for hiding this comment

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

I know it's frustrating not to fix white spaces, but let's keep focused on what the commit is intended to do. You can add white space fixes if you really want as a separate commit.

} else {
for (csp_iface_t * cur = interfaces; cur; cur = cur->next) {
if (cur->next == ifc) {
cur->next = ifc->next;
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to scan the rest of the list. break it. You can also if->next = NULL here so that when failed to find the target in the list, we don't need to touch the ifc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes will do. However is it better to not touch ifc when it is not found in the list? If for some reason an interface not in the list is passed in as argument, is it not better to ensure that it does not contain any reference to other elements in the list, so that any call to csp_iflist_remove guarantees ifc will be completely seperate from the list?

Copy link
Member

Choose a reason for hiding this comment

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

Well, IMO, if you don't find the given interface in the list, you are pretty much screwed up already. The csp_iflist API doesn't exclusively maintain all interfaces added. Once you add an interface to the list, all interfaces are linked. If you mess up one of the linked interfaces you get from, say, csp_iflist_get_by_subnet(), the whole list gets messed up.

So if you can't find the given interface, that means you passed:

  1. an already-removed interface,
  2. a completely wrong pointer, or
  3. you messed up the memory area.

If you passed an already removed interface, ifc->next should already be NULL.

If you passed a wrong pointer, assigning NULL to ifc->next would mean destroying some memory area.

If you have already messed up your memory, you are already done.

Therefore, I don't see the point of setting ifc->next to NULL. What am I missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thats fair, I'll fix it

@yashi
Copy link
Member

yashi commented Jul 10, 2023

LGTM. Please do me a last favor. Squash the three commits in one, and copy paste your first comment in this thread in the commit message. If you allow me, I can do that for you.

@yashi
Copy link
Member

yashi commented Jul 10, 2023

(just in case, please do not squash any other PRs! The squash request on this PR was that because the three commits are logically one change. It may or may not apply to others. Thanks)

Copy link
Member

@yashi yashi left a comment

Choose a reason for hiding this comment

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

As I said in the other place, it LGTM.

We should merge three commits in this PR in one commit because it's logically one thing. If you allow me to push to your branch, I can fix it, and let you check before merge. Otherwise, I can just do that locally and merge to the develop branch.

@sigmundklaa
Copy link
Contributor Author

As I said in the other place, it LGTM.

We should merge three commits in this PR in one commit because it's logically one thing. If you allow me to push to your branch, I can fix it, and let you check before merge. Otherwise, I can just do that locally and merge to the develop branch.

Yes sorry, I forgot about this. I have squashed the last three now

Implements a csp_iflist_remove function to go along with
csp_iflist_add. This is useful to ensure full cleanup in case
initialization of an interface fails for whatever reason.
@yashi
Copy link
Member

yashi commented Jul 13, 2023

@sigmundklaa Thank you for squashing!

I know I said "last" but would you please fold the commit message, like this?
git doesn't like long lines.

Implements a csp_iflist_remove function to go along with
csp_iflist_add. This is useful to ensure full cleanup in case
initialization of an interface fails for whatever reason.

@sigmundklaa
Copy link
Contributor Author

@sigmundklaa Thank you for squashing!

I know I said "last" but would you please fold the commit message, like this? git doesn't like long lines.

Implements a csp_iflist_remove function to go along with
csp_iflist_add. This is useful to ensure full cleanup in case
initialization of an interface fails for whatever reason.

Done

@yashi yashi merged commit 66ec4b3 into libcsp:develop Jul 13, 2023
@sigmundklaa sigmundklaa deleted the iflist-remove branch July 13, 2023 14:32
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.

2 participants