diff --git a/cli/README.md b/cli/README.md index 1dcf991..e102d2a 100644 --- a/cli/README.md +++ b/cli/README.md @@ -34,7 +34,7 @@ intent only — `apply` binds it to the selected modem's live identity: { "slot": "Modem/0", "enabled": true, - "connection": { "apn": "auto", "ipFamily": "ipv4v6" }, + "connection": { "apn": "auto" }, "roaming": false, "radio": { "preferenceOrdered": ["5gnr", "lte", "umts", "gsm"] }, "recovery": { "enabled": false }, @@ -42,6 +42,11 @@ intent only — `apply` binds it to the selected modem's live identity: } ``` +`connection.ipFamily` is optional in JSON files and defaults to `ipv4v6` when +converted to the required 1.x policy field. `ipv4`, `ipv6`, or `ipv4v6` selects the +[profile method mapping](../control/README.md#opt-in-networkmanager-ip-family); +existing files with `ipv4v6` now explicitly request both automatic methods. + ## Develop From the repository root (single Bun workspace): diff --git a/cli/src/policy-family.test.ts b/cli/src/policy-family.test.ts new file mode 100644 index 0000000..3753d61 --- /dev/null +++ b/cli/src/policy-family.test.ts @@ -0,0 +1,32 @@ +import { expect, test } from 'bun:test'; +import { imeiEquipmentId } from '@ceralive/modem-control'; +import { parsePolicyText, toDesiredPolicy } from './policy-file'; + +const base = { + enabled: true, + connection: { apn: 'auto' }, + roaming: false, + radio: { preferenceOrdered: ['lte'] }, +}; +const binding = { equipmentId: imeiEquipmentId('490154203237518') }; + +test('policy files default omission to dual stack and preserve each explicit family', () => { + const omitted = toDesiredPolicy(parsePolicyText(JSON.stringify(base), 'policy.json'), binding); + expect(omitted.connection).toEqual({ apn: 'auto', ipFamily: 'ipv4v6' }); + for (const ipFamily of ['ipv4', 'ipv6', 'ipv4v6'] as const) { + const input = { ...base, connection: { apn: 'auto', ipFamily } }; + expect( + toDesiredPolicy(parsePolicyText(JSON.stringify(input), 'policy.json'), binding).connection + .ipFamily, + ).toBe(ipFamily); + } +}); + +test('policy files reject unknown family values', () => { + expect(() => + parsePolicyText( + JSON.stringify({ ...base, connection: { apn: 'auto', ipFamily: 'any' } }), + 'policy.json', + ), + ).toThrow('connection.ipFamily'); +}); diff --git a/cli/src/policy-file.ts b/cli/src/policy-file.ts index 1aab4cd..04a47e1 100644 --- a/cli/src/policy-file.ts +++ b/cli/src/policy-file.ts @@ -26,7 +26,7 @@ const authSchema = z const connectionSchema = z .object({ apn: z.string().min(1), - ipFamily: z.enum(['ipv4', 'ipv6', 'ipv4v6']), + ipFamily: z.enum(['ipv4', 'ipv6', 'ipv4v6']).optional(), auth: authSchema.optional(), networkId: z.string().optional(), }) @@ -106,7 +106,7 @@ export function toDesiredPolicy( enabled: spec.enabled, connection: { apn: spec.connection.apn, - ipFamily: spec.connection.ipFamily, + ipFamily: spec.connection.ipFamily ?? 'ipv4v6', ...(spec.connection.auth !== undefined ? { auth: toAuth(spec.connection.auth) } : {}), ...(spec.connection.networkId !== undefined ? { networkId: spec.connection.networkId } : {}), }, diff --git a/control/README.md b/control/README.md index ead8cf2..73105c9 100644 --- a/control/README.md +++ b/control/README.md @@ -420,6 +420,46 @@ The declared entries live in `scripts/entries.ts` and the test additionally spel seven specifiers out as a literal, so a subpath cannot be dropped without a reviewable change to the public contract. +## Opt-in NetworkManager IP family + +Set `connection.ipFamily` in a desired cellular policy, or `ipFamily` on a +`GsmProfileInput` / `GsmProfilePatch`, to request saved NetworkManager methods: + +| Request | `ipv4.method` | `ipv6.method` | +| -------- | ------------- | ------------- | +| `ipv4` | `auto` | `disabled` | +| `ipv6` | `disabled` | `auto` | +| `ipv4v6` | `auto` | `auto` | + +At the low-level port, omitting the family retains the previous writer behavior: +creation supplies neither method, and patches leave existing methods untouched. +`DesiredConnection.ipFamily` remains required for 1.x type compatibility, and +`defaultCellularPolicy()` retains `ipv4v6`. Policy-driven writes now honor that +value; CLI files that omit it default to `ipv4v6`. IPv4-only profiles use +`ipv6.method disabled`, which requires NetworkManager 1.20 or newer. + +NetworkManager's `nmcli --offline connection add type gsm con-name example gsm.auto-config yes` +produces `auto` for both methods (verified with NM 1.54.3), +so omission must not be described as an IPv4-only default. Existing profile values +and NetworkManager configuration remain authoritative. See the +[NetworkManager settings reference](https://networkmanager.pages.freedesktop.org/NetworkManager/NetworkManager/nm-settings-nmcli.html) +for `auto`, `disabled` and `may-fail` semantics. No `may-fail`, route, DNS, CLAT or +APN-ownership setting is changed by this option. + +Readback reports `GsmProfile.ipFamily` only for the exact method pairs above; +manual, ignored or unknown combinations leave it absent. This is saved intent, +not proof of the carrier-granted addresses. Feed this readback into the planner's +`AppliedCellularState.appliedIpFamily`: a known mismatch remains `pending`, +and matching saved methods yield an `applied` connection receipt. An absent +readback is unknown and causes no family reconciliation, so existing consumers +do not repeatedly update a profile until they add readback support. APN and +roaming changes still reconcile normally; creation includes the requested family. + +Profile writes do not reconnect an active device. The consumer still owns when +to activate a changed profile and must retain its disruption and recovery rules. +IPv6-only service also requires family-aware consumers and an IPv4 service path +such as CLAT for IPv4 hotspot clients; this option does not provide those. + ## License AGPL-3.0 diff --git a/control/src/backend/nm-gsm-fields.ts b/control/src/backend/nm-gsm-fields.ts index 30e268c..bb826f9 100644 --- a/control/src/backend/nm-gsm-fields.ts +++ b/control/src/backend/nm-gsm-fields.ts @@ -1,4 +1,5 @@ -// Pure nmcli GSM-connection argv builders — the FULL nine-field write parity today's +// Pure nmcli GSM-connection argv builders — base fields plus optional IP methods. +// Preserves the GSM write parity today's // CeraUI carried (modem-registration.ts `sanitizeModemConfigForNetworkManager` + // `addConnectionForModem`), rebuilt from scratch for the device-exact adapter so the // greenfield port loses nothing the wrap-first path wrote. @@ -14,6 +15,7 @@ // connection.autoconnect — always "yes" // connection.autoconnect-retries — "2" +import type { IpFamily } from '../domain'; import type { ConnectionId, GsmProfile, GsmProfileInput, GsmProfilePatch } from '../ports'; // Empty-string fallback; Bun runtime limitation with empty CLI args: a bare @@ -47,6 +49,18 @@ export function gsmFieldPairs(input: GsmProfileInput): Array<[string, string]> { ['gsm.auto-config', auto ? 'yes' : 'no'], ['connection.autoconnect', 'yes'], ['connection.autoconnect-retries', '2'], + ...ipMethodPairs(input.ipFamily), + ]; +} + +/** Only an explicit request owns the two IP methods; may-fail stays NM-owned. */ +function ipMethodPairs(family: IpFamily | undefined): Array<[string, string]> { + if (family === undefined) { + return []; + } + return [ + ['ipv4.method', family === 'ipv6' ? 'disabled' : 'auto'], + ['ipv6.method', family === 'ipv4' ? 'disabled' : 'auto'], ]; } @@ -55,7 +69,7 @@ export function flattenPairs(pairs: ReadonlyArray): s return pairs.flat(); } -/** `connection add type gsm con-name ` — device-exact create argv. */ +/** `connection add type gsm con-name [IP methods]` — device-exact create argv. */ export function createGsmArgs(input: GsmProfileInput): string[] { return [ 'connection', @@ -101,16 +115,28 @@ export function patchPairs(patch: GsmProfilePatch): string[] { } else if (patch.networkId !== undefined) { pairs.push('gsm.network-id', cliArg(patch.networkId)); } + pairs.push(...flattenPairs(ipMethodPairs(patch.ipFamily))); return pairs; } /** Map an nmcli terse readback back onto a `GsmProfile` (inverse of the write parity). */ export function buildProfile(id: ConnectionId, settings: Map): GsmProfile { + const v4 = settings.get('ipv4.method'); + const v6 = settings.get('ipv6.method'); + const ipFamily: IpFamily | undefined = + v4 === 'auto' && v6 === 'auto' + ? 'ipv4v6' + : v4 === 'auto' && v6 === 'disabled' + ? 'ipv4' + : v4 === 'disabled' && v6 === 'auto' + ? 'ipv6' + : undefined; const username = settings.get('gsm.username') ?? ''; const password = settings.get('gsm.password') ?? ''; const networkId = settings.get('gsm.network-id') ?? ''; return { connectionId: id, + ...(ipFamily !== undefined ? { ipFamily } : {}), connectionName: settings.get('connection.id') ?? '', apn: settings.get('gsm.apn') ?? '', homeOnly: settings.get('gsm.home-only') === 'yes', diff --git a/control/src/backend/nm-ip-family.test.ts b/control/src/backend/nm-ip-family.test.ts new file mode 100644 index 0000000..dc77c39 --- /dev/null +++ b/control/src/backend/nm-ip-family.test.ts @@ -0,0 +1,171 @@ +import { expect, test } from 'bun:test'; +import { FakeNetworkManagerPort } from '../../test-support/fake-nm/fake-network-manager'; +import { StatefulNmcliRunner } from '../../test-support/fake-nm/nmcli-runner'; +import { defaultCellularPolicy, type IpFamily, imeiEquipmentId } from '../domain'; +import { connectionId } from '../ports'; +import { planReconcile } from '../ports/reconcile'; +import { buildProfile, createGsmArgs, patchPairs } from './nm-gsm-fields'; +import { NmcliNmPort } from './nmcli-nm-port'; + +const profile = { connectionName: 'cellular', apn: '', homeOnly: true, autoConfig: true }; +const policy = defaultCellularPolicy({ equipmentId: imeiEquipmentId('490154203237518') }); +const capabilities = { + supportedRats: new Set(['lte'] as const), + simSlotCount: 1, + supportsAutoApn: true, +}; +const current = { + hasProfile: true, + connectionId: connectionId('test'), + nmActivation: 'activated' as const, + appliedApn: 'auto', + appliedRoaming: false, +}; + +for (const [family, v4, v6] of [ + ['ipv4', 'auto', 'disabled'], + ['ipv6', 'disabled', 'auto'], + ['ipv4v6', 'auto', 'auto'], +] as const) { + test(`${family}: create, patch and saved readback`, async () => { + const input = { ...profile, ipFamily: family }; + const methods = ['ipv4.method', v4, 'ipv6.method', v6]; + expect(createGsmArgs(input).slice(-4)).toEqual(methods); + expect(patchPairs({ ipFamily: family })).toEqual(methods); + const runner = new StatefulNmcliRunner(); + const port = new NmcliNmPort({ runner }); + const saved = await port.createGsmProfile(input); + expect(saved.ipFamily).toBe(family); + const fake = new FakeNetworkManagerPort(); + const fakeSaved = await fake.createGsmProfile(input); + expect(fakeSaved.ipFamily).toBe(family); + expect( + (await fake.updateGsmProfile(fakeSaved.connectionId, { ipFamily: 'ipv6' })).ipFamily, + ).toBe('ipv6'); + for (const next of ['ipv4', 'ipv6', 'ipv4v6'] as const) { + expect((await port.updateGsmProfile(saved.connectionId, { ipFamily: next })).ipFamily).toBe( + next, + ); + } + await port.updateGsmProfile(saved.connectionId, { apn: 'changed' }); + expect((await port.readGsmProfile(saved.connectionId))?.ipFamily).toBe('ipv4v6'); + expect(runner.calls.some((call) => call.includes('up') || call.includes('disconnect'))).toBe( + false, + ); + }); + test(`${family}: planner writes until readback matches, without reconnect`, () => { + const desired = { ...policy, connection: { apn: 'auto', ipFamily: family } }; + const plan = planReconcile( + { ...current, appliedIpFamily: family === 'ipv4' ? 'ipv6' : 'ipv4' }, + desired, + capabilities, + ); + const writes = plan.ops.filter((op) => op.port === 'nm'); + expect(writes).toEqual([ + { + port: 'nm', + op: { + kind: 'updateGsmProfile', + connectionId: current.connectionId, + patch: { ...profile, connectionName: 'ceralive-cellular', ipFamily: family }, + }, + }, + ]); + expect(plan.receipts.find((r) => r.dimension === 'connection')?.status).toBe('pending'); + const matched = planReconcile( + { ...current, appliedIpFamily: family as IpFamily }, + desired, + capabilities, + ); + expect(matched.ops.filter((op) => op.port === 'nm')).toEqual([]); + expect(matched.receipts.find((r) => r.dimension === 'connection')?.status).toBe('applied'); + const create = planReconcile({ ...current, hasProfile: false }, desired, capabilities); + expect(create.ops[0]).toMatchObject({ + port: 'nm', + op: { kind: 'createGsmProfile', profile: { ipFamily: family } }, + }); + }); +} + +test('omission preserves the legacy port argv and the default retains its 1.x family', () => { + expect(createGsmArgs(profile)).toEqual([ + 'connection', + 'add', + 'type', + 'gsm', + 'con-name', + 'cellular', + 'gsm.apn', + '', + 'gsm.username', + '', + 'gsm.password', + '', + 'gsm.password-flags', + '4', + 'gsm.home-only', + 'yes', + 'gsm.network-id', + '', + 'gsm.auto-config', + 'yes', + 'connection.autoconnect', + 'yes', + 'connection.autoconnect-retries', + '2', + ]); + expect(patchPairs({ apn: 'changed' })).toEqual(['gsm.apn', 'changed']); + const family: IpFamily = policy.connection.ipFamily; + expect(family).toBe('ipv4v6'); + expect(planReconcile(current, policy, capabilities).ops.filter((op) => op.port === 'nm')).toEqual( + [], + ); +}); + +test('readback never invents a family for unsupported method combinations', () => { + for (const [v4, v6] of [ + ['manual', 'auto'], + ['disabled', 'disabled'], + ['auto', 'ignore'], + ] as const) { + expect( + buildProfile( + connectionId('test'), + new Map([ + ['ipv4.method', v4], + ['ipv6.method', v6], + ]), + ).ipFamily, + ).toBeUndefined(); + } +}); + +for (const ipFamily of ['ipv4', 'ipv6', 'ipv4v6'] as const) { + test(`${ipFamily}: unknown applied family causes no reconcile write`, () => { + const desired = { ...policy, connection: { apn: 'auto', ipFamily } }; + for (let pass = 0; pass < 2; pass++) { + const plan = planReconcile(current, desired, capabilities); + expect(plan.ops.filter((op) => op.port === 'nm')).toEqual([]); + expect(plan.receipts.find((r) => r.dimension === 'connection')?.status).toBe('applied'); + } + }); +} + +test('saved readback follows independently written methods rather than the request', async () => { + const runner = new StatefulNmcliRunner(); + const port = new NmcliNmPort({ runner }); + const saved = await port.createGsmProfile({ ...profile, ipFamily: 'ipv4' }); + const fake = new FakeNetworkManagerPort(runner); + for (const [v4, v6, expected] of [ + ['disabled', 'auto', 'ipv6'], + ['auto', 'auto', 'ipv4v6'], + ['auto', 'disabled', 'ipv4'], + ['auto', 'ignore', undefined], + ['manual', 'auto', undefined], + ['disabled', 'disabled', undefined], + ] as const) { + runner.run(['connection', 'modify', saved.connectionId, 'ipv4.method', v4, 'ipv6.method', v6]); + expect((await port.readGsmProfile(saved.connectionId))?.ipFamily).toBe(expected); + expect((await fake.readGsmProfile(saved.connectionId))?.ipFamily).toBe(expected); + } +}); diff --git a/control/src/backend/nmcli-nm-port.ts b/control/src/backend/nmcli-nm-port.ts index a4c098f..6ea347f 100644 --- a/control/src/backend/nmcli-nm-port.ts +++ b/control/src/backend/nmcli-nm-port.ts @@ -28,6 +28,8 @@ import { buildProfile, createGsmArgs, patchPairs } from './nm-gsm-fields'; import { type NmcliResult, type NmcliRunner, parseTerse, runNmcli } from './nmcli-runner'; const READBACK_FIELDS = [ + 'ipv4.method', + 'ipv6.method', 'connection.id', 'gsm.apn', 'gsm.username', diff --git a/control/src/domain/policy.ts b/control/src/domain/policy.ts index c62f98f..7a789da 100644 --- a/control/src/domain/policy.ts +++ b/control/src/domain/policy.ts @@ -39,6 +39,7 @@ export interface DesiredAuth { /** The data-connection intent. `apn: "auto"` selects NM Auto-APN (A4.1). */ export interface DesiredConnection { readonly apn: 'auto' | string; + /** Requested saved-profile family; retained as a required field for 1.x consumers. */ readonly ipFamily: IpFamily; readonly auth?: DesiredAuth; /** @@ -107,7 +108,7 @@ export const RECOVERY_DISABLED: DesiredRecovery = { enabled: false }; /** * Build a sensible default policy for a bindable identity: NM activation on, - * Auto-APN, dual-stack IP, roaming off, prefer newest RAT down to GSM, recovery + * Auto-APN, dual-stack IP request, roaming off, prefer newest RAT down to GSM, recovery * disabled, no usage limits. Concrete adapters and the planner refine from here. */ export function defaultCellularPolicy(boundTo: PolicyBindingKey): DesiredCellularPolicy { diff --git a/control/src/ports/README.md b/control/src/ports/README.md index c1fee76..3fee2d8 100644 --- a/control/src/ports/README.md +++ b/control/src/ports/README.md @@ -25,17 +25,18 @@ the NM-owns-bearers architecture the whole package is built around (independent review correction, draft §Oracle #1): the controller is a reconciler over two adapters, never a second writer of the same resource. -| Resource | Sole writer | Port / owner | -| ------------------------------------------------ | ---------------- | ------------------------------------------------------ | -| APN | NetworkManager | `NetworkManagerPort` (`gsm.apn` / auto-config) | -| Connection auth (username / password) | NetworkManager | `NetworkManagerPort` (`gsm.username` / `gsm.password`) | -| Roaming | NetworkManager | `NetworkManagerPort` (`gsm.home-only`) | -| Autoconnect | NetworkManager | `NetworkManagerPort` (`connection.autoconnect`) | -| Activation (bearer lifecycle) | NetworkManager | `NetworkManagerPort` (`activate`/`deactivate`) | -| Radio access-technology modes | ModemManager | `ModemManagerPort.setRadioModes` | -| SIM operations (PIN / PUK / primary slot / scan) | ModemManager | `ModemManagerPort` | -| Recovery ladder | Local controller | policy `recovery` (disabled by default, A3.4) | -| Usage policy (cycle / threshold) | Local controller | policy `usage` (A4.3 sampler) | +| Resource | Sole writer | Port / owner | +| ------------------------------------------------ | ---------------- | --------------------------------------------------------------------------- | +| APN | NetworkManager | `NetworkManagerPort` (`gsm.apn` / auto-config) | +| Saved IP family methods | NetworkManager | `NetworkManagerPort` (explicit `ipFamily` only; omission preserves methods) | +| Connection auth (username / password) | NetworkManager | `NetworkManagerPort` (`gsm.username` / `gsm.password`) | +| Roaming | NetworkManager | `NetworkManagerPort` (`gsm.home-only`) | +| Autoconnect | NetworkManager | `NetworkManagerPort` (`connection.autoconnect`) | +| Activation (bearer lifecycle) | NetworkManager | `NetworkManagerPort` (`activate`/`deactivate`) | +| Radio access-technology modes | ModemManager | `ModemManagerPort.setRadioModes` | +| SIM operations (PIN / PUK / primary slot / scan) | ModemManager | `ModemManagerPort` | +| Recovery ladder | Local controller | policy `recovery` (disabled by default, A3.4) | +| Usage policy (cycle / threshold) | Local controller | policy `usage` (A4.3 sampler) | ### The bearer invariant (safety-critical) diff --git a/control/src/ports/network-manager.ts b/control/src/ports/network-manager.ts index c30c47c..261b801 100644 --- a/control/src/ports/network-manager.ts +++ b/control/src/ports/network-manager.ts @@ -3,7 +3,7 @@ // way the controller touches any of those resources; the ModemManager port has no // bearer / connection verbs at all. -import type { Brand, EpochMillis } from '../domain'; +import type { Brand, EpochMillis, IpFamily } from '../domain'; import { nonEmptyString } from '../domain'; import type { Receipt } from './receipts'; @@ -30,6 +30,8 @@ export function deviceIfname(value: string): DeviceIfname { * contract that adapter fulfils. */ export interface GsmProfileInput { + /** Explicit saved IP methods; omission leaves methods untouched. */ + readonly ipFamily?: IpFamily; readonly connectionName: string; /** Concrete APN, or the empty string when `autoConfig` drives it (A4.1). */ readonly apn: string; diff --git a/control/src/ports/reconcile.ts b/control/src/ports/reconcile.ts index a63f2eb..95b8492 100644 --- a/control/src/ports/reconcile.ts +++ b/control/src/ports/reconcile.ts @@ -4,7 +4,12 @@ // side effects: the same inputs always yield the same ops and receipts, which is // what makes re-applying a policy idempotent (see reconcile.test.ts). -import type { DesiredCellularPolicy, NmActivation, RadioAccessTechnology } from '../domain'; +import type { + DesiredCellularPolicy, + IpFamily, + NmActivation, + RadioAccessTechnology, +} from '../domain'; import type { ConnectionId, DeviceIfname, GsmProfileInput } from './network-manager'; import { mmOp, nmOp, type PortTaggedOp } from './ops'; import { type Receipt, receipt } from './receipts'; @@ -27,6 +32,8 @@ export interface AppliedCellularState { readonly connectionId?: ConnectionId; readonly deviceIfname?: DeviceIfname; readonly appliedApn?: 'auto' | string; + /** Saved profile methods, not carrier-granted addresses. Absent means unknown: no family drift. */ + readonly appliedIpFamily?: IpFamily; readonly appliedRoaming?: boolean; readonly appliedRadioPreference?: readonly RadioAccessTechnology[]; readonly activePrimarySlot?: number; @@ -83,6 +90,7 @@ function profileFromPolicy(desired: DesiredCellularPolicy): GsmProfileInput { const auto = desired.connection.apn === 'auto'; const base: GsmProfileInput = { connectionName: 'ceralive-cellular', + ...(desired.connection.ipFamily !== undefined ? { ipFamily: desired.connection.ipFamily } : {}), apn: auto ? '' : desired.connection.apn, homeOnly: !desired.roaming, autoConfig: auto, @@ -124,13 +132,15 @@ function planNmProfile( const needsWrite = !current.hasProfile || current.appliedApn !== desired.connection.apn || - current.appliedRoaming !== desired.roaming; + current.appliedRoaming !== desired.roaming || + (current.appliedIpFamily !== undefined && + current.appliedIpFamily !== desired.connection.ipFamily); if (!needsWrite) { return { connection: receipt( 'connection', 'applied', - `connection APN '${desired.connection.apn}' already configured`, + `connection APN '${desired.connection.apn}'${desired.connection.ipFamily ? ` (${desired.connection.ipFamily})` : ''} already configured`, ), roaming: receipt( 'roaming', @@ -152,7 +162,7 @@ function planNmProfile( connection: receipt( 'connection', 'pending', - `${verb} connection profile for APN '${desired.connection.apn}'`, + `${verb} connection profile for APN '${desired.connection.apn}'${desired.connection.ipFamily ? ` (${desired.connection.ipFamily})` : ''}`, ), roaming: receipt( 'roaming', diff --git a/control/test-support/fake-nm/fake-network-manager.ts b/control/test-support/fake-nm/fake-network-manager.ts index 7182fd7..95e3b62 100644 --- a/control/test-support/fake-nm/fake-network-manager.ts +++ b/control/test-support/fake-nm/fake-network-manager.ts @@ -5,7 +5,7 @@ // so a `readGsmProfile` after a `createGsmProfile`/`updateGsmProfile` returns exactly // what was written — a genuine readback double for reconcile/observer tests. It is a // TEST DOUBLE, not the shipping adapter: it wires only the fields the port interface -// carries. A4.1's `NmcliNmPort` owns the full nine-field GSM write parity and the +// carries. A4.1's `NmcliNmPort` owns the base GSM fields plus optional IP methods and the // atomic Auto-APN transitions; this harness is what A4.1 injects to assert them. import { epochMillis } from '../../src/domain'; @@ -24,6 +24,8 @@ import { import { type NmcliResult, StatefulNmcliRunner } from './nmcli-runner'; const READBACK_FIELDS = [ + 'ipv4.method', + 'ipv6.method', 'connection.id', 'gsm.apn', 'gsm.username', @@ -71,6 +73,14 @@ export class FakeNetworkManagerPort implements NetworkManagerPort { if (profile.networkId !== undefined) { argv.push('gsm.network-id', profile.networkId); } + if (profile.ipFamily !== undefined) { + argv.push( + 'ipv4.method', + profile.ipFamily === 'ipv6' ? 'disabled' : 'auto', + 'ipv6.method', + profile.ipFamily === 'ipv4' ? 'disabled' : 'auto', + ); + } const result = this.#runner.run(argv); const uuid = /\(([^)]+)\) successfully added/.exec(result.stdout)?.[1]; if (uuid === undefined) { @@ -121,6 +131,14 @@ export class FakeNetworkManagerPort implements NetworkManagerPort { if (patch.networkId !== undefined) { argv.push('gsm.network-id', patch.networkId); } + if (patch.ipFamily !== undefined) { + argv.push( + 'ipv4.method', + patch.ipFamily === 'ipv6' ? 'disabled' : 'auto', + 'ipv6.method', + patch.ipFamily === 'ipv4' ? 'disabled' : 'auto', + ); + } const result = this.#runner.run(argv); if (result.exitCode !== 0) { throw new Error(`fake nmcli: modify failed (${result.stderr})`); @@ -193,7 +211,18 @@ function buildProfile(id: ConnectionId, settings: Map): GsmProfi const username = settings.get('gsm.username') ?? ''; const password = settings.get('gsm.password') ?? ''; const networkId = settings.get('gsm.network-id') ?? ''; + const v4 = settings.get('ipv4.method'); + const v6 = settings.get('ipv6.method'); + const ipFamily = + v4 === 'auto' && v6 === 'disabled' + ? ('ipv4' as const) + : v4 === 'disabled' && v6 === 'auto' + ? ('ipv6' as const) + : v4 === 'auto' && v6 === 'auto' + ? ('ipv4v6' as const) + : undefined; return { + ...(ipFamily !== undefined ? { ipFamily } : {}), connectionId: id, connectionName: settings.get('connection.id') ?? '', apn: settings.get('gsm.apn') ?? '',