Description: Autogenerated patch header for a single-debian-patch file.
 The delta against upstream is either kept as a single patch, or maintained
 in some VCS, and exported as a single patch instead of more manageable
 atomic patches.
Forwarded: not-needed

---
--- /dev/null
+++ nbd-3.27.1/.dir-locals.el
@@ -0,0 +1,2 @@
+((c-mode . ((c-file-style . "linux")
+	    (indent-tabs-mode . t))))
--- /dev/null
+++ nbd-3.27.1/.github/workflows/build.yml
@@ -0,0 +1,31 @@
+name: Build NBD
+on: [push]
+jobs:
+  Build-NBD:
+    runs-on: ubuntu-latest
+    steps:
+      - name: install dependencies
+        run: sudo apt-get update && sudo apt-get -y install docbook-utils libglib2.0-dev libgnutls28-dev libnl-genl-3-dev autoconf-archive gcovr
+      - name: Check out repository
+        uses: actions/checkout@v4
+      - run: ./autogen.sh
+      - run: ./configure --enable-syslog
+      - name: Build and run tests (coverage)
+        run: |
+          make CFLAGS="--coverage -O0 -g" CXXFLAGS="--coverage -O0 -g" LDFLAGS="--coverage"
+          make check CFLAGS="--coverage -O0 -g" CXXFLAGS="--coverage -O0 -g" LDFLAGS="--coverage"
+      - name: Generate coverage reports
+        run: |
+          gcovr -r . --exclude-directories tests --print-summary --xml-pretty -o coverage.xml --html=coverage.html --html-details
+      - name: Submit coverage to Coveralls
+        uses: coverallsapp/github-action@v2
+        with:
+          file: coverage.xml
+          format: cobertura
+      - name: Upload coverage reports
+        uses: actions/upload-artifact@v4
+        with:
+          name: coverage
+          path: |
+            coverage.xml
+            coverage.html
--- /dev/null
+++ nbd-3.27.1/.gitlab-ci.yml
@@ -0,0 +1,14 @@
+before_script:
+  - apt-get update
+  - apt-get install -y devscripts fakeroot build-essential git autoconf automake docbook-utils pkg-config
+  - mk-build-deps -t "apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends" -i -r
+  - rm -f nbd-build-deps*
+  - ./autogen.sh
+build_unstable:
+  image: debian:sid
+  script:
+  - dpkg-buildpackage -rfakeroot -b
+build_testing:
+  image: debian:testing
+  script:
+  - dpkg-buildpackage -rfakeroot -b
--- nbd-3.27.1.orig/configure.ac
+++ nbd-3.27.1/configure.ac
@@ -2,7 +2,7 @@ dnl Configure script for NBD system
 dnl (c) 1998 Martin Mares <mj@ucw.cz>, (c) 2000 Pavel Machek <pavel@ucw.cz>,
 dnl (c) 2003-2024 Wouter Verhelst <wouter@debian.org>
 AC_INIT([nbd],
-  m4_esyscmd(support/genver.sh | tr -d '\n'),
+  [3.26.1],
   [nbd@other.debian.org],,
   [http://nbd.sourceforge.net/])
 m4_define([serial_tests], [
--- /dev/null
+++ nbd-3.27.1/coverity_model.c
@@ -0,0 +1,7 @@
+
+typedef struct _GArray GArray;
+#define g_array_append_val(a, v) g_array_append_vals(a, &(v), 1)
+
+GArray* g_array_append_vals(GArray*, void*, unsigned int) {
+	__coverity_escape__;
+}
--- /dev/null
+++ nbd-3.27.1/doc/netlink-proto.md
@@ -0,0 +1,257 @@
+# The NBD Netlink Control Protocol
+
+NOTE: this documentation is AI-generated and still needs review. Use with
+caution.
+
+## Introduction
+
+The NBD kernel driver provides a netlink-based control interface that allows userspace
+tools to configure, manage, and monitor NBD devices. This interface is used by the
+nbd-client utility to establish connections, configure devices, and query status.
+
+The netlink protocol uses the generic netlink (genl) framework with family name "nbd"
+and version 0x1. It supports both unicast commands/responses and multicast notifications
+for link death events.
+
+## Protocol Overview
+
+### Family Information
+
+- **Family Name**: `nbd`
+- **Version**: `0x1`
+- **Multicast Group**: `nbd_mc_group`
+
+### Message Types
+
+The protocol defines the following command types:
+
+- `NBD_CMD_CONNECT` - Connect and configure an NBD device
+- `NBD_CMD_DISCONNECT` - Disconnect an NBD device
+- `NBD_CMD_RECONFIGURE` - Reconfigure an existing connection
+- `NBD_CMD_STATUS` - Query device status
+- `NBD_CMD_LINK_DEAD` - Multicast notification of link failure (kernel → userspace)
+
+## Attributes
+
+### Configuration Attributes
+
+These attributes are used with various commands:
+
+- `NBD_ATTR_INDEX` (u32) - NBD device index
+- `NBD_ATTR_SIZE_BYTES` (u64) - Device size in bytes
+- `NBD_ATTR_BLOCK_SIZE_BYTES` (u64) - Block size in bytes
+- `NBD_ATTR_TIMEOUT` (u64) - Connection timeout
+- `NBD_ATTR_SERVER_FLAGS` (u64) - Server flags from negotiation
+- `NBD_ATTR_CLIENT_FLAGS` (u64) - Client flags
+- `NBD_ATTR_SOCKETS` (nested) - Socket configuration
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` (u64) - Dead connection timeout
+- `NBD_ATTR_DEVICE_LIST` (nested) - List of devices (for STATUS response)
+- `NBD_ATTR_BACKEND_IDENTIFIER` (string) - Backend identifier
+
+### Socket Attributes
+
+Nested within `NBD_ATTR_SOCKETS`:
+
+- `NBD_SOCK_ITEM` (nested) - Individual socket item
+  - `NBD_SOCK_FD` (u32) - File descriptor for the socket
+
+### Device List Attributes
+
+Nested within `NBD_ATTR_DEVICE_LIST`:
+
+- `NBD_DEVICE_ITEM` (nested) - Individual device item
+  - `NBD_DEVICE_INDEX` (u32) - Device index
+  - `NBD_DEVICE_CONNECTED` (u8) - Connection status (1 = connected, 0 = disconnected)
+
+## Command Details
+
+### NBD_CMD_CONNECT
+
+Connect and configure an NBD device.
+
+**Request Attributes:**
+- `NBD_ATTR_INDEX` (optional) - Device index to use, kernel assigns if not specified
+- `NBD_ATTR_SIZE_BYTES` (required) - Export size in bytes
+- `NBD_ATTR_BLOCK_SIZE_BYTES` (required) - Block size in bytes
+- `NBD_ATTR_SERVER_FLAGS` (required) - Flags from server negotiation
+- `NBD_ATTR_TIMEOUT` (optional) - Connection timeout in seconds
+- `NBD_ATTR_SOCKETS` (required) - Nested socket configuration
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` (optional) - Dead connection timeout
+- `NBD_ATTR_BACKEND_IDENTIFIER` (optional) - Backend identifier string
+
+**Response Attributes:**
+- `NBD_ATTR_INDEX` - Assigned device index
+
+**Example Request Structure:**
+```
+NBD_CMD_CONNECT
+├── NBD_ATTR_SIZE_BYTES: 10737418240
+├── NBD_ATTR_BLOCK_SIZE_BYTES: 4096
+├── NBD_ATTR_SERVER_FLAGS: 0x123
+├── NBD_ATTR_TIMEOUT: 30
+└── NBD_ATTR_SOCKETS
+    ├── NBD_SOCK_ITEM
+    │   └── NBD_SOCK_FD: 5
+    └── NBD_SOCK_ITEM
+        └── NBD_SOCK_FD: 6
+```
+
+### NBD_CMD_DISCONNECT
+
+Disconnect an NBD device.
+
+**Request Attributes:**
+- `NBD_ATTR_INDEX` (required) - Device index to disconnect
+
+**Response Attributes:**
+- None (success/failure indicated by return code)
+
+### NBD_CMD_RECONFIGURE
+
+Reconfigure an existing NBD connection.
+
+**Request Attributes:**
+- `NBD_ATTR_INDEX` (required) - Device index to reconfigure
+- `NBD_ATTR_SOCKETS` (required) - New socket configuration
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` (optional) - New dead connection timeout
+
+**Response Attributes:**
+- None (success/failure indicated by return code)
+
+### NBD_CMD_STATUS
+
+Query the status of NBD devices.
+
+**Request Attributes:**
+- `NBD_ATTR_INDEX` (optional) - Specific device index, or all devices if not specified
+
+**Response Attributes:**
+- `NBD_ATTR_DEVICE_LIST` - Nested list of device statuses
+  - `NBD_DEVICE_ITEM` (repeated)
+    - `NBD_DEVICE_INDEX` - Device index
+    - `NBD_DEVICE_CONNECTED` - Connection status
+
+**Example Response Structure:**
+```
+NBD_CMD_STATUS Response
+└── NBD_ATTR_DEVICE_LIST
+    ├── NBD_DEVICE_ITEM
+    │   ├── NBD_DEVICE_INDEX: 0
+    │   └── NBD_DEVICE_CONNECTED: 1
+    ├── NBD_DEVICE_ITEM
+    │   ├── NBD_DEVICE_INDEX: 1
+    │   └── NBD_DEVICE_CONNECTED: 0
+    └── NBD_DEVICE_ITEM
+        ├── NBD_DEVICE_INDEX: 2
+        └── NBD_DEVICE_CONNECTED: 1
+```
+
+### NBD_CMD_LINK_DEAD
+
+Multicast notification sent by kernel when a link dies.
+
+**Message Attributes:**
+- `NBD_ATTR_INDEX` - Device index whose link died
+
+**Delivery:**
+- Sent via multicast group `nbd_mc_group`
+- No direct response expected
+
+## Error Handling
+
+Commands return standard netlink error codes:
+- Success: 0
+- Invalid parameters: `-EINVAL`
+- Device not found: `-ENOENT`
+- Device busy: `-EBUSY`
+- Memory allocation failure: `-ENOMEM`
+- Permission denied: `-EPERM`
+
+## Implementation Notes
+
+### Socket Management
+
+The kernel expects file descriptors for already-connected sockets to be passed
+via `NBD_ATTR_SOCKETS`. This allows userspace to handle:
+- TCP connections
+- TLS negotiations
+- Authentication
+- Connection establishment
+
+The kernel takes ownership of these file descriptors and will close them
+when the device is disconnected.
+
+### Timeout Handling
+
+Two timeout types are supported:
+- `NBD_ATTR_TIMEOUT` - Initial connection timeout
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` - Timeout for detecting dead connections
+
+### Multicast Notifications
+
+Userspace applications can subscribe to the `nbd_mc_group` multicast group
+to receive asynchronous notifications about link death events.
+
+## Security Considerations
+
+- Netlink communications require appropriate capabilities (typically CAP_NET_ADMIN)
+- File descriptors passed to the kernel are validated
+- Backend identifiers should be treated as opaque strings
+- Timeout values should be reasonable to avoid resource exhaustion
+
+## Protocol Evolution
+
+The protocol version is 0x1. Future versions will maintain backward compatibility
+where possible, with new attributes being optional. Unknown attributes should be
+ignored by implementations.
+
+## Usage Examples
+
+### Connecting a Device
+
+```c
+// Create netlink message
+struct nl_msg *msg = nlmsg_alloc();
+genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, driver_id, 0, 0,
+           NBD_CMD_CONNECT, 0);
+
+// Add attributes
+NLA_PUT_U64(msg, NBD_ATTR_SIZE_BYTES, size);
+NLA_PUT_U64(msg, NBD_ATTR_BLOCK_SIZE_BYTES, blocksize);
+NLA_PUT_U64(msg, NBD_ATTR_SERVER_FLAGS, flags);
+
+// Add sockets
+struct nlattr *socks = nla_nest_start(msg, NBD_ATTR_SOCKETS);
+for (i = 0; i < num_sockets; i++) {
+    struct nlattr *sock = nla_nest_start(msg, NBD_SOCK_ITEM);
+    NLA_PUT_U32(msg, NBD_SOCK_FD, sock_fds[i]);
+    nla_nest_end(msg, sock);
+}
+nla_nest_end(msg, socks);
+
+// Send message
+nl_send_sync(socket, msg);
+```
+
+### Querying Status
+
+```c
+struct nl_msg *msg = nlmsg_alloc();
+genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, driver_id, 0, 0,
+           NBD_CMD_STATUS, 0);
+
+// Optional: query specific device
+NLA_PUT_U32(msg, NBD_ATTR_INDEX, device_index);
+
+nl_send_sync(socket, msg);
+```
+
+### Disconnecting a Device
+
+```c
+struct nl_msg *msg = nlmsg_alloc();
+genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, driver_id, 0, 0,
+           NBD_CMD_DISCONNECT, 0);
+NLA_PUT_U32(msg, NBD_ATTR_INDEX, device_index);
+nl_send_sync(socket, msg);
+```
--- nbd-3.27.1.orig/nbd-server.c
+++ nbd-3.27.1/nbd-server.c
@@ -777,14 +777,6 @@ GArray* do_cfile_dir(gchar* dir, struct
 }
 
 /**
- * To be called by GArray clearing function.
- * @param server pointer to server element
- */
-static void serve_clear_element(SERVER **server) {
-	serve_dec_ref(*server);
-}
-
-/**
  * Parse the config file.
  *
  * @param f the name of the config file
--- nbd-3.27.1.orig/nbdsrv.h
+++ nbd-3.27.1/nbdsrv.h
@@ -238,6 +238,13 @@ SERVER* serve_inc_ref(SERVER *s);
 SERVER* serve_dec_ref(SERVER *s);
 
 /**
+ * call serve_dec_ref on *s
+ *
+ * @param s a pointer to a pointer to a SERVER to decrement
+ **/
+void serve_clear_element(SERVER **s);
+
+/**
  * Punch a hole in the backend file (if supported by the current system).
  *
  * @param req the request for which this is being processed
--- nbd-3.27.1.orig/systemd/nbd@.service.sh.in
+++ nbd-3.27.1/systemd/nbd@.service.sh.in
@@ -10,7 +10,9 @@ Description=NBD client connection for %i
 Documentation=man:nbd-client
 PartOf=nbd.service
 Before=dev-%i.device
+Before=remote-fs-pre.target
 After=network-online.target
+Before=shutdown.target
 Conflicts=shutdown.target
 DefaultDependencies=no
 [Service]
@@ -18,6 +20,8 @@ Type=oneshot
 RemainAfterExit=yes
 ExecStart=@sbindir@/nbd-client %i
 ExecStop=@sbindir@/nbd-client -d /dev/%i
+NoNewPrivileges=true
+ProtectSystem=full
 [Install]
 RequiredBy=dev-%i.device
 RequiredBy=dev-%ip1.device
--- nbd-3.27.1.orig/systemd/nbd@.service.tmpl
+++ nbd-3.27.1/systemd/nbd@.service.tmpl
@@ -10,8 +10,10 @@ After=modprobe@nbd.service
 Conflicts=shutdown.target
 DefaultDependencies=no
 [Service]
-Type=forking
+Type=oneshot
+RemainAfterExit=yes
 ExecStart=@sbindir@/nbd-client %i
+ExecStop=@sbindir@/nbd-client -d /dev/%i
 [Install]
 RequiredBy=dev-%i.device
 RequiredBy=dev-%ip1.device
--- nbd-3.27.1.orig/tests/parse/ipv6
+++ nbd-3.27.1/tests/parse/ipv6
@@ -1,5 +1,3 @@
-
-
 # This config file contains a few empty lines.
 
 # It also contains an IPv6 address
--- nbd-3.27.1.orig/configure
+++ nbd-3.27.1/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.72 for nbd 3.27.1.
+# Generated by GNU Autoconf 2.72 for nbd 3.26.1.
 #
 # Report bugs to <nbd@other.debian.org>.
 #
@@ -614,8 +614,8 @@ MAKEFLAGS=
 # Identity of this package.
 PACKAGE_NAME='nbd'
 PACKAGE_TARNAME='nbd'
-PACKAGE_VERSION='3.27.1'
-PACKAGE_STRING='nbd 3.27.1'
+PACKAGE_VERSION='3.26.1'
+PACKAGE_STRING='nbd 3.26.1'
 PACKAGE_BUGREPORT='nbd@other.debian.org'
 PACKAGE_URL='http://nbd.sourceforge.net/'
 
@@ -1413,7 +1413,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-'configure' configures nbd 3.27.1 to adapt to many kinds of systems.
+'configure' configures nbd 3.26.1 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1484,7 +1484,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of nbd 3.27.1:";;
+     short | recursive ) echo "Configuration of nbd 3.26.1:";;
    esac
   cat <<\_ACEOF
 
@@ -1632,7 +1632,7 @@ fi
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-nbd configure 3.27.1
+nbd configure 3.26.1
 generated by GNU Autoconf 2.72
 
 Copyright (C) 2023 Free Software Foundation, Inc.
@@ -2310,7 +2310,7 @@ cat >config.log <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by nbd $as_me 3.27.1, which was
+It was created by nbd $as_me 3.26.1, which was
 generated by GNU Autoconf 2.72.  Invocation command line was
 
   $ $0$ac_configure_args_raw
@@ -3791,7 +3791,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE='nbd'
- VERSION='3.27.1'
+ VERSION='3.26.1'
 
 
 printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
@@ -18846,7 +18846,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_wri
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by nbd $as_me 3.27.1, which was
+This file was extended by nbd $as_me 3.26.1, which was
 generated by GNU Autoconf 2.72.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -18919,7 +18919,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config='$ac_cs_config_escaped'
 ac_cs_version="\\
-nbd config.status 3.27.1
+nbd config.status 3.26.1
 configured by $0, generated by GNU Autoconf 2.72,
   with options \\"\$ac_cs_config\\"
 
