| 1 |
Description: Autogenerated patch header for a single-debian-patch file. |
| 2 |
The delta against upstream is either kept as a single patch, or maintained |
| 3 |
in some VCS, and exported as a single patch instead of more manageable |
| 4 |
atomic patches. |
| 5 |
Forwarded: not-needed |
| 6 |
|
| 7 |
--- |
| 8 |
--- /dev/null |
| 9 |
+++ nbd-3.27.1/.dir-locals.el |
| 10 |
@@ -0,0 +1,2 @@ |
| 11 |
+((c-mode . ((c-file-style . "linux") |
| 12 |
+ (indent-tabs-mode . t)))) |
| 13 |
--- /dev/null |
| 14 |
+++ nbd-3.27.1/.github/workflows/build.yml |
| 15 |
@@ -0,0 +1,31 @@ |
| 16 |
+name: Build NBD |
| 17 |
+on: [push] |
| 18 |
+jobs: |
| 19 |
+ Build-NBD: |
| 20 |
+ runs-on: ubuntu-latest |
| 21 |
+ steps: |
| 22 |
+ - name: install dependencies |
| 23 |
+ run: sudo apt-get update && sudo apt-get -y install docbook-utils libglib2.0-dev libgnutls28-dev libnl-genl-3-dev autoconf-archive gcovr |
| 24 |
+ - name: Check out repository |
| 25 |
+ uses: actions/checkout@v4 |
| 26 |
+ - run: ./autogen.sh |
| 27 |
+ - run: ./configure --enable-syslog |
| 28 |
+ - name: Build and run tests (coverage) |
| 29 |
+ run: | |
| 30 |
+ make CFLAGS="--coverage -O0 -g" CXXFLAGS="--coverage -O0 -g" LDFLAGS="--coverage" |
| 31 |
+ make check CFLAGS="--coverage -O0 -g" CXXFLAGS="--coverage -O0 -g" LDFLAGS="--coverage" |
| 32 |
+ - name: Generate coverage reports |
| 33 |
+ run: | |
| 34 |
+ gcovr -r . --exclude-directories tests --print-summary --xml-pretty -o coverage.xml --html=coverage.html --html-details |
| 35 |
+ - name: Submit coverage to Coveralls |
| 36 |
+ uses: coverallsapp/github-action@v2 |
| 37 |
+ with: |
| 38 |
+ file: coverage.xml |
| 39 |
+ format: cobertura |
| 40 |
+ - name: Upload coverage reports |
| 41 |
+ uses: actions/upload-artifact@v4 |
| 42 |
+ with: |
| 43 |
+ name: coverage |
| 44 |
+ path: | |
| 45 |
+ coverage.xml |
| 46 |
+ coverage.html |
| 47 |
--- /dev/null |
| 48 |
+++ nbd-3.27.1/.gitlab-ci.yml |
| 49 |
@@ -0,0 +1,14 @@ |
| 50 |
+before_script: |
| 51 |
+ - apt-get update |
| 52 |
+ - apt-get install -y devscripts fakeroot build-essential git autoconf automake docbook-utils pkg-config |
| 53 |
+ - mk-build-deps -t "apt-get -y -o Debug::pkgProblemResolver=yes --no-install-recommends" -i -r |
| 54 |
+ - rm -f nbd-build-deps* |
| 55 |
+ - ./autogen.sh |
| 56 |
+build_unstable: |
| 57 |
+ image: debian:sid |
| 58 |
+ script: |
| 59 |
+ - dpkg-buildpackage -rfakeroot -b |
| 60 |
+build_testing: |
| 61 |
+ image: debian:testing |
| 62 |
+ script: |
| 63 |
+ - dpkg-buildpackage -rfakeroot -b |
| 64 |
--- nbd-3.27.1.orig/configure.ac |
| 65 |
+++ nbd-3.27.1/configure.ac |
| 66 |
@@ -2,7 +2,7 @@ dnl Configure script for NBD system |
| 67 |
dnl (c) 1998 Martin Mares <[email protected]>, (c) 2000 Pavel Machek <[email protected]>, |
| 68 |
dnl (c) 2003-2024 Wouter Verhelst <[email protected]> |
| 69 |
AC_INIT([nbd], |
| 70 |
- m4_esyscmd(support/genver.sh | tr -d '\n'), |
| 71 |
+ [3.26.1], |
| 72 |
[[email protected]],, |
| 73 |
[http://nbd.sourceforge.net/]) |
| 74 |
m4_define([serial_tests], [ |
| 75 |
--- /dev/null |
| 76 |
+++ nbd-3.27.1/coverity_model.c |
| 77 |
@@ -0,0 +1,7 @@ |
| 78 |
+ |
| 79 |
+typedef struct _GArray GArray; |
| 80 |
+#define g_array_append_val(a, v) g_array_append_vals(a, &(v), 1) |
| 81 |
+ |
| 82 |
+GArray* g_array_append_vals(GArray*, void*, unsigned int) { |
| 83 |
+ __coverity_escape__; |
| 84 |
+} |
| 85 |
--- /dev/null |
| 86 |
+++ nbd-3.27.1/doc/netlink-proto.md |
| 87 |
@@ -0,0 +1,257 @@ |
| 88 |
+# The NBD Netlink Control Protocol |
| 89 |
+ |
| 90 |
+NOTE: this documentation is AI-generated and still needs review. Use with |
| 91 |
+caution. |
| 92 |
+ |
| 93 |
+## Introduction |
| 94 |
+ |
| 95 |
+The NBD kernel driver provides a netlink-based control interface that allows userspace |
| 96 |
+tools to configure, manage, and monitor NBD devices. This interface is used by the |
| 97 |
+nbd-client utility to establish connections, configure devices, and query status. |
| 98 |
+ |
| 99 |
+The netlink protocol uses the generic netlink (genl) framework with family name "nbd" |
| 100 |
+and version 0x1. It supports both unicast commands/responses and multicast notifications |
| 101 |
+for link death events. |
| 102 |
+ |
| 103 |
+## Protocol Overview |
| 104 |
+ |
| 105 |
+### Family Information |
| 106 |
+ |
| 107 |
+- **Family Name**: `nbd` |
| 108 |
+- **Version**: `0x1` |
| 109 |
+- **Multicast Group**: `nbd_mc_group` |
| 110 |
+ |
| 111 |
+### Message Types |
| 112 |
+ |
| 113 |
+The protocol defines the following command types: |
| 114 |
+ |
| 115 |
+- `NBD_CMD_CONNECT` - Connect and configure an NBD device |
| 116 |
+- `NBD_CMD_DISCONNECT` - Disconnect an NBD device |
| 117 |
+- `NBD_CMD_RECONFIGURE` - Reconfigure an existing connection |
| 118 |
+- `NBD_CMD_STATUS` - Query device status |
| 119 |
+- `NBD_CMD_LINK_DEAD` - Multicast notification of link failure (kernel → userspace) |
| 120 |
+ |
| 121 |
+## Attributes |
| 122 |
+ |
| 123 |
+### Configuration Attributes |
| 124 |
+ |
| 125 |
+These attributes are used with various commands: |
| 126 |
+ |
| 127 |
+- `NBD_ATTR_INDEX` (u32) - NBD device index |
| 128 |
+- `NBD_ATTR_SIZE_BYTES` (u64) - Device size in bytes |
| 129 |
+- `NBD_ATTR_BLOCK_SIZE_BYTES` (u64) - Block size in bytes |
| 130 |
+- `NBD_ATTR_TIMEOUT` (u64) - Connection timeout |
| 131 |
+- `NBD_ATTR_SERVER_FLAGS` (u64) - Server flags from negotiation |
| 132 |
+- `NBD_ATTR_CLIENT_FLAGS` (u64) - Client flags |
| 133 |
+- `NBD_ATTR_SOCKETS` (nested) - Socket configuration |
| 134 |
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` (u64) - Dead connection timeout |
| 135 |
+- `NBD_ATTR_DEVICE_LIST` (nested) - List of devices (for STATUS response) |
| 136 |
+- `NBD_ATTR_BACKEND_IDENTIFIER` (string) - Backend identifier |
| 137 |
+ |
| 138 |
+### Socket Attributes |
| 139 |
+ |
| 140 |
+Nested within `NBD_ATTR_SOCKETS`: |
| 141 |
+ |
| 142 |
+- `NBD_SOCK_ITEM` (nested) - Individual socket item |
| 143 |
+ - `NBD_SOCK_FD` (u32) - File descriptor for the socket |
| 144 |
+ |
| 145 |
+### Device List Attributes |
| 146 |
+ |
| 147 |
+Nested within `NBD_ATTR_DEVICE_LIST`: |
| 148 |
+ |
| 149 |
+- `NBD_DEVICE_ITEM` (nested) - Individual device item |
| 150 |
+ - `NBD_DEVICE_INDEX` (u32) - Device index |
| 151 |
+ - `NBD_DEVICE_CONNECTED` (u8) - Connection status (1 = connected, 0 = disconnected) |
| 152 |
+ |
| 153 |
+## Command Details |
| 154 |
+ |
| 155 |
+### NBD_CMD_CONNECT |
| 156 |
+ |
| 157 |
+Connect and configure an NBD device. |
| 158 |
+ |
| 159 |
+**Request Attributes:** |
| 160 |
+- `NBD_ATTR_INDEX` (optional) - Device index to use, kernel assigns if not specified |
| 161 |
+- `NBD_ATTR_SIZE_BYTES` (required) - Export size in bytes |
| 162 |
+- `NBD_ATTR_BLOCK_SIZE_BYTES` (required) - Block size in bytes |
| 163 |
+- `NBD_ATTR_SERVER_FLAGS` (required) - Flags from server negotiation |
| 164 |
+- `NBD_ATTR_TIMEOUT` (optional) - Connection timeout in seconds |
| 165 |
+- `NBD_ATTR_SOCKETS` (required) - Nested socket configuration |
| 166 |
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` (optional) - Dead connection timeout |
| 167 |
+- `NBD_ATTR_BACKEND_IDENTIFIER` (optional) - Backend identifier string |
| 168 |
+ |
| 169 |
+**Response Attributes:** |
| 170 |
+- `NBD_ATTR_INDEX` - Assigned device index |
| 171 |
+ |
| 172 |
+**Example Request Structure:** |
| 173 |
+``` |
| 174 |
+NBD_CMD_CONNECT |
| 175 |
+├── NBD_ATTR_SIZE_BYTES: 10737418240 |
| 176 |
+├── NBD_ATTR_BLOCK_SIZE_BYTES: 4096 |
| 177 |
+├── NBD_ATTR_SERVER_FLAGS: 0x123 |
| 178 |
+├── NBD_ATTR_TIMEOUT: 30 |
| 179 |
+└── NBD_ATTR_SOCKETS |
| 180 |
+ ├── NBD_SOCK_ITEM |
| 181 |
+ │ └── NBD_SOCK_FD: 5 |
| 182 |
+ └── NBD_SOCK_ITEM |
| 183 |
+ └── NBD_SOCK_FD: 6 |
| 184 |
+``` |
| 185 |
+ |
| 186 |
+### NBD_CMD_DISCONNECT |
| 187 |
+ |
| 188 |
+Disconnect an NBD device. |
| 189 |
+ |
| 190 |
+**Request Attributes:** |
| 191 |
+- `NBD_ATTR_INDEX` (required) - Device index to disconnect |
| 192 |
+ |
| 193 |
+**Response Attributes:** |
| 194 |
+- None (success/failure indicated by return code) |
| 195 |
+ |
| 196 |
+### NBD_CMD_RECONFIGURE |
| 197 |
+ |
| 198 |
+Reconfigure an existing NBD connection. |
| 199 |
+ |
| 200 |
+**Request Attributes:** |
| 201 |
+- `NBD_ATTR_INDEX` (required) - Device index to reconfigure |
| 202 |
+- `NBD_ATTR_SOCKETS` (required) - New socket configuration |
| 203 |
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` (optional) - New dead connection timeout |
| 204 |
+ |
| 205 |
+**Response Attributes:** |
| 206 |
+- None (success/failure indicated by return code) |
| 207 |
+ |
| 208 |
+### NBD_CMD_STATUS |
| 209 |
+ |
| 210 |
+Query the status of NBD devices. |
| 211 |
+ |
| 212 |
+**Request Attributes:** |
| 213 |
+- `NBD_ATTR_INDEX` (optional) - Specific device index, or all devices if not specified |
| 214 |
+ |
| 215 |
+**Response Attributes:** |
| 216 |
+- `NBD_ATTR_DEVICE_LIST` - Nested list of device statuses |
| 217 |
+ - `NBD_DEVICE_ITEM` (repeated) |
| 218 |
+ - `NBD_DEVICE_INDEX` - Device index |
| 219 |
+ - `NBD_DEVICE_CONNECTED` - Connection status |
| 220 |
+ |
| 221 |
+**Example Response Structure:** |
| 222 |
+``` |
| 223 |
+NBD_CMD_STATUS Response |
| 224 |
+└── NBD_ATTR_DEVICE_LIST |
| 225 |
+ ├── NBD_DEVICE_ITEM |
| 226 |
+ │ ├── NBD_DEVICE_INDEX: 0 |
| 227 |
+ │ └── NBD_DEVICE_CONNECTED: 1 |
| 228 |
+ ├── NBD_DEVICE_ITEM |
| 229 |
+ │ ├── NBD_DEVICE_INDEX: 1 |
| 230 |
+ │ └── NBD_DEVICE_CONNECTED: 0 |
| 231 |
+ └── NBD_DEVICE_ITEM |
| 232 |
+ ├── NBD_DEVICE_INDEX: 2 |
| 233 |
+ └── NBD_DEVICE_CONNECTED: 1 |
| 234 |
+``` |
| 235 |
+ |
| 236 |
+### NBD_CMD_LINK_DEAD |
| 237 |
+ |
| 238 |
+Multicast notification sent by kernel when a link dies. |
| 239 |
+ |
| 240 |
+**Message Attributes:** |
| 241 |
+- `NBD_ATTR_INDEX` - Device index whose link died |
| 242 |
+ |
| 243 |
+**Delivery:** |
| 244 |
+- Sent via multicast group `nbd_mc_group` |
| 245 |
+- No direct response expected |
| 246 |
+ |
| 247 |
+## Error Handling |
| 248 |
+ |
| 249 |
+Commands return standard netlink error codes: |
| 250 |
+- Success: 0 |
| 251 |
+- Invalid parameters: `-EINVAL` |
| 252 |
+- Device not found: `-ENOENT` |
| 253 |
+- Device busy: `-EBUSY` |
| 254 |
+- Memory allocation failure: `-ENOMEM` |
| 255 |
+- Permission denied: `-EPERM` |
| 256 |
+ |
| 257 |
+## Implementation Notes |
| 258 |
+ |
| 259 |
+### Socket Management |
| 260 |
+ |
| 261 |
+The kernel expects file descriptors for already-connected sockets to be passed |
| 262 |
+via `NBD_ATTR_SOCKETS`. This allows userspace to handle: |
| 263 |
+- TCP connections |
| 264 |
+- TLS negotiations |
| 265 |
+- Authentication |
| 266 |
+- Connection establishment |
| 267 |
+ |
| 268 |
+The kernel takes ownership of these file descriptors and will close them |
| 269 |
+when the device is disconnected. |
| 270 |
+ |
| 271 |
+### Timeout Handling |
| 272 |
+ |
| 273 |
+Two timeout types are supported: |
| 274 |
+- `NBD_ATTR_TIMEOUT` - Initial connection timeout |
| 275 |
+- `NBD_ATTR_DEAD_CONN_TIMEOUT` - Timeout for detecting dead connections |
| 276 |
+ |
| 277 |
+### Multicast Notifications |
| 278 |
+ |
| 279 |
+Userspace applications can subscribe to the `nbd_mc_group` multicast group |
| 280 |
+to receive asynchronous notifications about link death events. |
| 281 |
+ |
| 282 |
+## Security Considerations |
| 283 |
+ |
| 284 |
+- Netlink communications require appropriate capabilities (typically CAP_NET_ADMIN) |
| 285 |
+- File descriptors passed to the kernel are validated |
| 286 |
+- Backend identifiers should be treated as opaque strings |
| 287 |
+- Timeout values should be reasonable to avoid resource exhaustion |
| 288 |
+ |
| 289 |
+## Protocol Evolution |
| 290 |
+ |
| 291 |
+The protocol version is 0x1. Future versions will maintain backward compatibility |
| 292 |
+where possible, with new attributes being optional. Unknown attributes should be |
| 293 |
+ignored by implementations. |
| 294 |
+ |
| 295 |
+## Usage Examples |
| 296 |
+ |
| 297 |
+### Connecting a Device |
| 298 |
+ |
| 299 |
+```c |
| 300 |
+// Create netlink message |
| 301 |
+struct nl_msg *msg = nlmsg_alloc(); |
| 302 |
+genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, driver_id, 0, 0, |
| 303 |
+ NBD_CMD_CONNECT, 0); |
| 304 |
+ |
| 305 |
+// Add attributes |
| 306 |
+NLA_PUT_U64(msg, NBD_ATTR_SIZE_BYTES, size); |
| 307 |
+NLA_PUT_U64(msg, NBD_ATTR_BLOCK_SIZE_BYTES, blocksize); |
| 308 |
+NLA_PUT_U64(msg, NBD_ATTR_SERVER_FLAGS, flags); |
| 309 |
+ |
| 310 |
+// Add sockets |
| 311 |
+struct nlattr *socks = nla_nest_start(msg, NBD_ATTR_SOCKETS); |
| 312 |
+for (i = 0; i < num_sockets; i++) { |
| 313 |
+ struct nlattr *sock = nla_nest_start(msg, NBD_SOCK_ITEM); |
| 314 |
+ NLA_PUT_U32(msg, NBD_SOCK_FD, sock_fds[i]); |
| 315 |
+ nla_nest_end(msg, sock); |
| 316 |
+} |
| 317 |
+nla_nest_end(msg, socks); |
| 318 |
+ |
| 319 |
+// Send message |
| 320 |
+nl_send_sync(socket, msg); |
| 321 |
+``` |
| 322 |
+ |
| 323 |
+### Querying Status |
| 324 |
+ |
| 325 |
+```c |
| 326 |
+struct nl_msg *msg = nlmsg_alloc(); |
| 327 |
+genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, driver_id, 0, 0, |
| 328 |
+ NBD_CMD_STATUS, 0); |
| 329 |
+ |
| 330 |
+// Optional: query specific device |
| 331 |
+NLA_PUT_U32(msg, NBD_ATTR_INDEX, device_index); |
| 332 |
+ |
| 333 |
+nl_send_sync(socket, msg); |
| 334 |
+``` |
| 335 |
+ |
| 336 |
+### Disconnecting a Device |
| 337 |
+ |
| 338 |
+```c |
| 339 |
+struct nl_msg *msg = nlmsg_alloc(); |
| 340 |
+genlmsg_put(msg, NL_AUTO_PORT, NL_AUTO_SEQ, driver_id, 0, 0, |
| 341 |
+ NBD_CMD_DISCONNECT, 0); |
| 342 |
+NLA_PUT_U32(msg, NBD_ATTR_INDEX, device_index); |
| 343 |
+nl_send_sync(socket, msg); |
| 344 |
+``` |
| 345 |
--- nbd-3.27.1.orig/nbd-client.c |
| 346 |
+++ nbd-3.27.1/nbd-client.c |
| 347 |
@@ -209,12 +209,12 @@ static void netlink_configure(int index, |
| 348 |
|
| 349 |
ret = nl_send_sync(socket, msg); |
| 350 |
if (ret < 0) { |
| 351 |
- if(geteuid() != 0) { |
| 352 |
- err_code("Failed to setup device. Are you root?\n", ret); |
| 353 |
- } else { |
| 354 |
- err_code("Failed to setup device, check dmesg\n", ret); |
| 355 |
- } |
| 356 |
- } |
| 357 |
+ if(geteuid() != 0) { |
| 358 |
+ err_code("Failed to setup device. Are you root?\n", ret); |
| 359 |
+ } else { |
| 360 |
+ err_code("Failed to setup device, check dmesg\n", ret); |
| 361 |
+ } |
| 362 |
+ } |
| 363 |
return; |
| 364 |
nla_put_failure: |
| 365 |
err("Failed to create netlink message\n"); |
| 366 |
@@ -225,10 +225,14 @@ static void netlink_disconnect(char *nbd |
| 367 |
struct nl_msg *msg; |
| 368 |
int driver_id; |
| 369 |
int ret; |
| 370 |
+ char *local_dev = nbddev; |
| 371 |
|
| 372 |
int index = -1; |
| 373 |
if (nbddev) { |
| 374 |
- if (sscanf(nbddev, "nbd%d", &index) != 1) |
| 375 |
+ if (!strncmp(local_dev, "/dev/", 5)) { |
| 376 |
+ local_dev += 5; |
| 377 |
+ } |
| 378 |
+ if (sscanf(local_dev, "nbd%d", &index) != 1) |
| 379 |
err("Invalid nbd device target\n"); |
| 380 |
} |
| 381 |
if (index < 0) |
| 382 |
@@ -313,13 +317,15 @@ static int netlink_check_conn(char* devn |
| 383 |
struct nl_msg *msg; |
| 384 |
int driver_id, ret; |
| 385 |
int index = -1; |
| 386 |
+ char *local_dev = devname; |
| 387 |
int connected = -1; /* -1 = unknown, 0 = connected, 1 = disconnected */ |
| 388 |
|
| 389 |
/* Parse device index from name */ |
| 390 |
- if (sscanf(devname, "/dev/nbd%d", &index) != 1) { |
| 391 |
- if (sscanf(devname, "nbd%d", &index) != 1) { |
| 392 |
- return 2; /* Invalid device name */ |
| 393 |
- } |
| 394 |
+ if (!strncmp(local_dev, "/dev/", 5)) { |
| 395 |
+ local_dev += 5; |
| 396 |
+ } |
| 397 |
+ if (sscanf(local_dev, "nbd%d", &index) != 1) { |
| 398 |
+ return 2; /* Invalid device name */ |
| 399 |
} |
| 400 |
|
| 401 |
/* Setup netlink socket */ |
| 402 |
@@ -513,7 +519,7 @@ err: |
| 403 |
|
| 404 |
int openunix() { |
| 405 |
int sock; |
| 406 |
- char *path = cur_client->hostn; |
| 407 |
+ char *path = cur_client->hostn; |
| 408 |
struct sockaddr_un un_addr; |
| 409 |
memset(&un_addr, 0, sizeof(un_addr)); |
| 410 |
|
| 411 |
@@ -770,8 +776,8 @@ void negotiate(int *sockp, uint16_t *fla |
| 412 |
err("Failed/2.1: %m"); |
| 413 |
|
| 414 |
#if HAVE_GNUTLS && !defined(NOTLS) |
| 415 |
- /* TLS */ |
| 416 |
- if (cur_client->tls) { |
| 417 |
+ /* TLS */ |
| 418 |
+ if (cur_client->tls) { |
| 419 |
int plainfd[2]; // [0] is used by the proxy, [1] is used by NBD |
| 420 |
tlssession_t *s = NULL; |
| 421 |
int ret; |
| 422 |
@@ -1224,7 +1230,7 @@ bool get_from_config() { |
| 423 |
goto out; |
| 424 |
} |
| 425 |
|
| 426 |
- retval = true; |
| 427 |
+ retval = true; |
| 428 |
out: |
| 429 |
if(yyin != NULL) { |
| 430 |
fclose(yyin); |
| 431 |
@@ -1377,10 +1383,10 @@ int main(int argc, char *argv[]) { |
| 432 |
logging(MY_NAME); |
| 433 |
|
| 434 |
#if HAVE_GNUTLS && !defined(NOTLS) |
| 435 |
- tlssession_init(); |
| 436 |
+ tlssession_init(); |
| 437 |
#endif |
| 438 |
- cur_client = calloc(sizeof(CLIENT), 1); |
| 439 |
- init_client(cur_client); |
| 440 |
+ cur_client = calloc(sizeof(CLIENT), 1); |
| 441 |
+ init_client(cur_client); |
| 442 |
|
| 443 |
// Use refactored argument parsing |
| 444 |
parse_result_t parse_result = parse_nbd_client_args(argc, argv, cur_client); |
| 445 |
@@ -1435,7 +1441,7 @@ int main(int argc, char *argv[]) { |
| 446 |
if(cur_client->hostn) { |
| 447 |
if((!cur_client->name || !cur_client->dev) && !(opts & NBDC_DO_LIST)) { |
| 448 |
if(!strncmp(cur_client->hostn, "nbd", 3) || !strncmp(cur_client->hostn, "/dev/nbd", 8)) { |
| 449 |
- cur_client->dev = cur_client->hostn; |
| 450 |
+ cur_client->dev = cur_client->hostn; |
| 451 |
if(!get_from_config()) { |
| 452 |
usage("no valid configuration for specified device found", cur_client->hostn); |
| 453 |
exit(EXIT_FAILURE); |
| 454 |
@@ -1450,7 +1456,7 @@ int main(int argc, char *argv[]) { |
| 455 |
exit(EXIT_FAILURE); |
| 456 |
} |
| 457 |
|
| 458 |
- if (cur_client->key && !cur_client->cert) |
| 459 |
+ if (cur_client->key && !cur_client->cert) |
| 460 |
cur_client->cert = strdup(cur_client->key); |
| 461 |
|
| 462 |
if (cur_client->cert != NULL || cur_client->key != NULL || cur_client->cacert != NULL || cur_client->tlshostn != NULL) { |
| 463 |
@@ -1468,8 +1474,8 @@ int main(int argc, char *argv[]) { |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
- if (!cur_client->tlshostn && cur_client->hostn && !cur_client->b_unix) |
| 468 |
- cur_client->tlshostn = strdup(cur_client->hostn); |
| 469 |
+ if (!cur_client->tlshostn && cur_client->hostn && !cur_client->b_unix) |
| 470 |
+ cur_client->tlshostn = strdup(cur_client->hostn); |
| 471 |
|
| 472 |
if (netlink) |
| 473 |
nofork = 1; |
| 474 |
@@ -1539,7 +1545,11 @@ int main(int argc, char *argv[]) { |
| 475 |
if (netlink) { |
| 476 |
int index = -1; |
| 477 |
if (cur_client->dev) { |
| 478 |
- if (sscanf(cur_client->dev, "nbd%d", &index) != 1) |
| 479 |
+ char *local_dev = cur_client->dev; |
| 480 |
+ if(!strncmp(local_dev, "/dev/", 5)) { |
| 481 |
+ local_dev += 5; |
| 482 |
+ } |
| 483 |
+ if (sscanf(local_dev, "nbd%d", &index) != 1) |
| 484 |
err("Invalid nbd device target\n"); |
| 485 |
} |
| 486 |
netlink_configure(index, sockfds, flags, identifier); |
| 487 |
@@ -1613,7 +1623,7 @@ int main(int argc, char *argv[]) { |
| 488 |
if(error==EBADR) { |
| 489 |
/* The user probably did 'nbd-client -d' on us. |
| 490 |
* quit */ |
| 491 |
- cur_client->persist_mode = false; |
| 492 |
+ cur_client->persist_mode = false; |
| 493 |
} else { |
| 494 |
if(cur_client->persist_mode) { |
| 495 |
uint64_t old_size = cur_client->size64; |
| 496 |
@@ -1649,7 +1659,7 @@ int main(int argc, char *argv[]) { |
| 497 |
* happened at this point. Probably best to quit, now |
| 498 |
*/ |
| 499 |
fprintf(stderr, "Kernel call returned.\n"); |
| 500 |
- cur_client->persist_mode = false; |
| 501 |
+ cur_client->persist_mode = false; |
| 502 |
} |
| 503 |
} while(cur_client->persist_mode); |
| 504 |
printf("sock, "); |
| 505 |
--- nbd-3.27.1.orig/nbd-server.c |
| 506 |
+++ nbd-3.27.1/nbd-server.c |
| 507 |
@@ -777,14 +777,6 @@ GArray* do_cfile_dir(gchar* dir, struct |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
- * To be called by GArray clearing function. |
| 512 |
- * @param server pointer to server element |
| 513 |
- */ |
| 514 |
-static void serve_clear_element(SERVER **server) { |
| 515 |
- serve_dec_ref(*server); |
| 516 |
-} |
| 517 |
- |
| 518 |
-/** |
| 519 |
* Parse the config file. |
| 520 |
* |
| 521 |
* @param f the name of the config file |
| 522 |
--- nbd-3.27.1.orig/nbdsrv.h |
| 523 |
+++ nbd-3.27.1/nbdsrv.h |
| 524 |
@@ -238,6 +238,13 @@ SERVER* serve_inc_ref(SERVER *s); |
| 525 |
SERVER* serve_dec_ref(SERVER *s); |
| 526 |
|
| 527 |
/** |
| 528 |
+ * call serve_dec_ref on *s |
| 529 |
+ * |
| 530 |
+ * @param s a pointer to a pointer to a SERVER to decrement |
| 531 |
+ **/ |
| 532 |
+void serve_clear_element(SERVER **s); |
| 533 |
+ |
| 534 |
+/** |
| 535 |
* Punch a hole in the backend file (if supported by the current system). |
| 536 |
* |
| 537 |
* @param req the request for which this is being processed |
| 538 |
--- nbd-3.27.1.orig/systemd/[email protected] |
| 539 |
+++ nbd-3.27.1/systemd/[email protected] |
| 540 |
@@ -10,7 +10,9 @@ Description=NBD client connection for %i |
| 541 |
Documentation=man:nbd-client |
| 542 |
PartOf=nbd.service |
| 543 |
Before=dev-%i.device |
| 544 |
+Before=remote-fs-pre.target |
| 545 |
After=network-online.target |
| 546 |
+Before=shutdown.target |
| 547 |
Conflicts=shutdown.target |
| 548 |
DefaultDependencies=no |
| 549 |
[Service] |
| 550 |
@@ -18,6 +20,8 @@ Type=oneshot |
| 551 |
RemainAfterExit=yes |
| 552 |
ExecStart=@sbindir@/nbd-client %i |
| 553 |
ExecStop=@sbindir@/nbd-client -d /dev/%i |
| 554 |
+NoNewPrivileges=true |
| 555 |
+ProtectSystem=full |
| 556 |
[Install] |
| 557 |
RequiredBy=dev-%i.device |
| 558 |
RequiredBy=dev-%ip1.device |
| 559 |
--- nbd-3.27.1.orig/systemd/[email protected] |
| 560 |
+++ nbd-3.27.1/systemd/[email protected] |
| 561 |
@@ -10,8 +10,10 @@ [email protected] |
| 562 |
Conflicts=shutdown.target |
| 563 |
DefaultDependencies=no |
| 564 |
[Service] |
| 565 |
-Type=forking |
| 566 |
+Type=oneshot |
| 567 |
+RemainAfterExit=yes |
| 568 |
ExecStart=@sbindir@/nbd-client %i |
| 569 |
+ExecStop=@sbindir@/nbd-client -d /dev/%i |
| 570 |
[Install] |
| 571 |
RequiredBy=dev-%i.device |
| 572 |
RequiredBy=dev-%ip1.device |
| 573 |
--- nbd-3.27.1.orig/tests/parse/ipv6 |
| 574 |
+++ nbd-3.27.1/tests/parse/ipv6 |
| 575 |
@@ -1,5 +1,3 @@ |
| 576 |
- |
| 577 |
- |
| 578 |
# This config file contains a few empty lines. |
| 579 |
|
| 580 |
# It also contains an IPv6 address |