Savagedlight / libifconfig

A C API to do most things done by the FreeBSD 'ifconfig' program today
Other
26 stars 7 forks source link

Support for getting most bits of interface status #46

Closed asomers closed 4 years ago

asomers commented 7 years ago

This PR is still a WIP, but it demonstrates a large part of reading interface statuses. The biggest API change is the addition of ifconfig_foreach_iface and ifconfig_foreach_ifaddr, which iterate over all interfaces and addresses, respectively, and call a user-provided callback. This PR also demonstrates the need for issue #45 . The functions isnd6defif, ifconfig_get_nd6, ifconfig_get_groups, ifconfig_get_ifstatus, and ifconfig_get_media all call ioctl with a third argument that isn't a struct ifreq

asomers commented 7 years ago

So I got kind of carried away on this PR and did a whole lot of things. But now I've finished adding all of the functionality that I need for my project, so I'm going to cool off for awhile. Please do review these commits and I'll make any required changes, but I suggest that after you close this PR we permanently move libifconfig into FreeBSD head's subversion repo. That will attract more attention to it, and it will also let libifconfig use FreeBSD's testing infrastructure. I can get some tests going pretty quickly once we do that.

Savagedlight commented 7 years ago

I'll look through this once my dev environment is back up and running. I'm not sure about moving libifconfig development to FreeBSD's SVN, however, as it'd be very impractical considering I don't have any commit bit there.

asomers commented 7 years ago

Well that is an obstacle. But I have access, and I can push your stuff through. Another option is to push libifconfig into svn, then fork FreeBSD's git mirror at https://github.com/freebsd/freebsd for your own work. Would that work for you?

kprovost commented 7 years ago

There's already a first version in the repo. I'd like to start picking up patches and push them in, but I have a similar issue with life getting in the way. I certainly won't object to other people doing this for me!

asomers commented 7 years ago

Whenever you're ready to push to SVN, just let me know and I'll take care of it.

asomers commented 7 years ago

@Savagedlight have you had a chance to review this diff yet? There are only a few days left to get it into FreeBSD 11.1.

Savagedlight commented 7 years ago

@asomers Thank you for your awesome work. I've looked over some of it, but not really had a chance to review this yet, and won't be able to before 11.1 code slush. IRL just got a whole lot less busy though, so I'll catch up once I've had some much needed rest. :)

brd commented 6 years ago

@Savagedlight ping? :)

jpaetzel commented 6 years ago

I was pointed at this today and this code solves a problem we are facing.

Anything I can do to help get this moved along?

asomers commented 6 years ago

I would like make one more change to my copy (don't cache ifaddrs longer than necessary) and put it through a test cycle here at $WORK. If that succeeds, then I think we should commit this to subversion and make that the canonical repo.

I also have Ruby bindings, if anybody cares.

jpaetzel commented 6 years ago

If we do that we'll have to sponsor @Savagedlight for a commit bit. :)

asomers commented 6 years ago

Rebased onto master

Savagedlight commented 6 years ago

Great work @asomers!

One thing: Can you please revert/undo the change which removed braces for single-line IF statements? I know you cite style(9), but the guideline only requires consistency within a project, and I have a strong preference in this matter. :)

asomers commented 6 years ago

No braces for a single-line if statement is the preferred style for new code, and libifconfig is new code. Except the parts that are copied from ifconfig, that is, but those already use no braces. So I think we use the preferred style for this.

dag-erling commented 6 years ago

@asomers You may disagree with @Savagedlight about braces, but don't cite non-existent rules in support of your personal preferences. Here is the actual wording from style(9):

 Space after keywords (if, while, for, return, switch).  Two styles of
 braces (‘{’ and ‘}’) are allowed for single line statements.  Either they
 are used for all single statements, or they are used only where needed
 for clarity.  Usage within a function should be consistent.  Forever
 loops are done with for's, not while's.
Savagedlight commented 6 years ago

I've merged it into a new branch (asomers-fib) as this PR is huge, and requires a staging area outside of master for further review/fixes.

asomers commented 6 years ago

I see that you added back the braces around single-line if statements. I can live with that. What else would you like to see changed? I'd like to get this into SVN within the next two weeks.

asomers commented 6 years ago

Opened a review for integrating back into FreeBSD. https://reviews.freebsd.org/D14463 . Due to time constraints on my end, I intend to commit this within 24 hours unless major objections are raised.

koobs commented 6 years ago

@Savagedlight I'd be happy to help transfer this repository to sit under the FreeBSD Github organisation with an appropriate administrator role for you (and contributor roles for others), if that's something you'd like and would find helpful. We have other externally developed but otherwise official/authoritative projects (some of which push to SVN).

asomers commented 4 years ago

Closing this PR, because it's been committed upstream to FreeBSD. https://svnweb.freebsd.org/base/head/lib/libifconfig/libifconfig.c?revision=329853&view=markup