-
Notifications
You must be signed in to change notification settings - Fork 39
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
Adding driver specific Netkit type, and possibly others like Vxlan, Bond etc... #216
Comments
Thank you very much for bringing this up. I have had earlier talks about something similar, however it never really got the attention it deserves. I had a look at your POC's, and I must say I like optie 2 the most, even though that means a breaking change. However, I would like to seperate all the drivers in a seperate 'driver' subpackage, to keep things a little cleaner. Thinking out loud, this boils down to something similar to: type LinkDriver interface {
// Encode the driver data into the netlink message attribute
Encode(*netlink.AttributeEncoder, *LinkMessage) error
// Decode the driver data from the netlink message attribute
Decode(*netlink.AttributeDecoder, *LinkMessage) error
// Return the driver kind as string, this will be matched with the LinkInfo.Kind to find a driver to decode the data
Kind() string
}
// registeredDrivers is the global map of registered drivers
var registeredDrivers = make(map[string]Driver)
// getDriver returns the driver instance for the given kind
// it returns the default (LinkData) driver if the driver is not found
func getDriver(kind string) Driver {
if d, ok := registeredDrivers[kind]; ok {
return d
}
return &LinkData{}
}
// RegisterDriver registers a driver with the link service
// This allows the driver to be used to encode/decode the link data
func (l *LinkService) RegisterDriver(d Driver) error {
if _, ok := registeredDrivers[d.Kind()]; ok {
return fmt.Errorf("driver %s already registered", d.Kind())
}
registeredDrivers[d.Kind()] = d
} All the regular drivers (such as netkit, vxlan, bonc, etc) can still be part of rtnetlink and could even be registered at By also passing the LinkMessage to the Driver, we can still make operational checks, as suggested in option 3. Is this something that would suit your needs and would be willing to contribute? |
I am willing to contribute to this effort. One thing is not very clear in your suggestion. In the proposed interface we are passing |
I am in doubt here. I am unsure if a perhaps just passing |
I am unsure if any driver besides Netkit uses any Another thing. Since we are considering a major library update, is there any other future we might want to implement? I was thinking about NetNamespace. |
So, I am thinking about changing the decode and encode function signatures. To make the Driver flexible enough I think we should do this: type LinkDriver interface {
// Encode the driver data into the netlink message attribute
Encode(*netlink.AttributeEncoder) error
// Decode the driver data from the netlink message attribute
Decode(*netlink.AttributeDecoder) error
// Return the driver kind as string, this will be matched with the LinkInfo.Kind to find a driver to decode the data
Kind() string
// After will perform any final checks. It will be called at the very end, after all unmarshalling of a LinkMessage has happened.
After(*LinkMessage)
// Before will perform any pre-check on the LinkMessage and LinkAttributes. It will be called before Marshalling a LinkMessage.
Before(*LinkMessage)
}
func (m *LinkMessage) MarshalBinary() ([]byte, error) {
if _, ok := m.Attributes.(LinkDriver); ok {
m.Attributes.Before(m)
}
b := make([]byte, unix.SizeofIfInfomsg)
...
}
func (m *LinkMessage) UnmarshalBinary(b []byte) error {
...
if _, ok := m.Attributes.(LinkDriver); ok {
m.Attributes.After(m)
}
return nil
} About Namespaces, I believe this library already works correctly, if you dial a rtnetlink.Dial(&netlink.Config{NetNS: 1234}) Though, to be fair, I have never actually tried if this works or not. |
I have been looking into known drivers and have not seen a need for an One thing seems problematic though. Creating a separate |
Drive by comment: there could be a public |
This would work. Thanks @lmb |
I am looking forward to it. |
I've initiated this discussion to explore incorporating driver-specific types within the library, with a particular interest in
Netkit
. However, the approach could extend to others such asVxlan
andBond
. Currently, driver-specific data is managed throughLinkInfo.Data
and/orLinkInfo.SlaveData
as byte slices. To define concrete types for these drivers, we need a new mechanism. I propose several approaches and have prepared POC branches to illustrate these ideas, though I'm open to further suggestions for the most effective implementation. Your input would be invaluable to refine these proposals.Interface Integration within LinkInfo: Adding a new interface within
LinkInfo
to handle driver types based on the Kind dynamically. This approach maintains backward compatibility. Example POC.Revision of Data Fields as Interfaces: Transforming
LinkInfo.Data
andSlaveData
into interfaces. This method would necessitate a major version update due to its backward-incompatible nature. Example POC.Driver Types in
LinkAttributes
: Embedding driver types directly withinLinkAttributes
. This method could provide operational benefits, such as compatibility checks. For example,Netkit
does not support setting ethernet address, in this way, we could check this condition Example POC.The text was updated successfully, but these errors were encountered: