Repository: netty/netty
Issue: netty-transport-native-* Bundles missing a Fragment-Host

### Initial Position
The netty-transport-native-epoll and -kqueue bundles ship native libraries, e.g. for linux_x86_64.
The do declare this in their manifest via Bundle-NativeCode header to make it available in an OSGi environment.

### Actual behavior
However, when the native library gets loaded via e.g. io.netty.channel.epoll.Epoll, it is not found with the following error:

```
java.lang.UnsatisfiedLinkError: could not load a native library: netty_transport_native_epoll_x86_64
caused by:
    java.io.FileNotFoundException: META-INF/native/libnetty_transport_native_epoll_x86_64.so
```

You see that the file location is correctly retrieved from manifest header of bundle netty-transport-native-epoll, but class EPoll is trying to load the resource from its bundle classloader (netty-transport-classes-epoll), which the resource does not reside in.

### Evaluation and Proposal for Fix
What is missing from my point of view is the declaration of the Fragement-Host, this bundle shipping the native lib should get attached to. In case of epoll:
`Fragment-Host: io.netty.transport-classes-epoll`
Altered this in my environment (Karaf with Artemis using Netty) and it immediately works then - class EPoll can the nsuccessfully load the native lib being shipped in the fragment bundle.


### Netty version
4.1.73

### JVM version
openjdk version "17.0.1" 2021-10-19 LTS

### OS version
Ubuntu 21.10, 5.13.0-25-generic

Issue comments:
@MrEasy can you provide a PR ?
> @MrEasy can you provide a PR ?

Sure, can do if you agree.
Would do it for epoll and kqueue. Not for netty-transport-native-unix-common/linux-x86_64, since it does not ship a library, only sources as far as I see.
@MrEasy yes sounds good... thanks!
PR#12018 for main. Also applicable for `4.1` branch

Pull request review comments:
@MrEasy this doesn't look correct
@MrEasy this doesn't look correct
thx, of course - updated.
thx, of course - updated.
```suggestion
                      <Fragment-Host>io.netty.resolver-dns-classes-macos</Fragment-Host>
```
```suggestion
                      <Fragment-Host>io.netty.resolver-dns-classes-macos</Fragment-Host>
```

Patch that resolved the issue:
diff --git a/resolver-dns-native-macos/pom.xml b/resolver-dns-native-macos/pom.xml
index 536a4bf9396..82edc515075 100644
--- a/resolver-dns-native-macos/pom.xml
+++ b/resolver-dns-native-macos/pom.xml
@@ -107,6 +107,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_resolver_dns_native_macos_${os.detected.arch}.jnilib; osname=MacOSX; processor=${os.detected.arch}</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.resolver-dns-classes-macos</Fragment-Host>
                       <Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
                     </manifestEntries>
                     <index>true</index>
@@ -213,6 +214,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_resolver_dns_native_macos_aarch_64.jnilib; osname=MacOSX; processor=aarch_64</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.resolver-dns-classes-macos</Fragment-Host>
                       <Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
                     </manifestEntries>
                     <index>true</index>
diff --git a/transport-native-epoll/pom.xml b/transport-native-epoll/pom.xml
index aba50c9d968..11ddb94ff38 100644
--- a/transport-native-epoll/pom.xml
+++ b/transport-native-epoll/pom.xml
@@ -181,6 +181,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_transport_native_epoll_${os.detected.arch}.so; osname=Linux; processor=${os.detected.arch},*</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.transport-classes-epoll</Fragment-Host>
                       <Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
                     </manifestEntries>
                     <index>true</index>
@@ -331,6 +332,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_transport_native_epoll_aarch_64.so; osname=Linux; processor=aarch_64,*</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.transport-classes-epoll</Fragment-Host>
                       <Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
                     </manifestEntries>
                     <index>true</index>
diff --git a/transport-native-kqueue/pom.xml b/transport-native-kqueue/pom.xml
index 91f5ee07d8b..297a0a10cc9 100644
--- a/transport-native-kqueue/pom.xml
+++ b/transport-native-kqueue/pom.xml
@@ -110,6 +110,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue_${os.detected.arch}.jnilib; osname=MacOSX; processor=${os.detected.arch}</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.transport-classes-kqueue</Fragment-Host>
                       <Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
                     </manifestEntries>
                     <index>true</index>
@@ -216,6 +217,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue_aarch_64.jnilib; osname=MacOSX; processor=aarch_64</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.transport-classes-kqueue</Fragment-Host>
                       <Automatic-Module-Name>${javaModuleName}</Automatic-Module-Name>
                     </manifestEntries>
                     <index>true</index>
@@ -320,6 +322,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue_${os.detected.arch}.jnilib; osname=OpenBSD; processor=${os.detected.arch}</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.transport-classes-kqueue</Fragment-Host>
                     </manifestEntries>
                     <index>true</index>
                     <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
@@ -423,6 +426,7 @@
                     </manifest>
                     <manifestEntries>
                       <Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue_${os.detected.arch}.jnilib; osname=FreeBSD; processor=${os.detected.arch}</Bundle-NativeCode>
+                      <Fragment-Host>io.netty.transport-classes-kqueue</Fragment-Host>
                     </manifestEntries>
                     <index>true</index>
                     <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>


Test patch: