Skip to content
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

Add support for "can" type, and "bitrate" property #10

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions __tests__/safe/cmd-generation/fixtures/link-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,26 @@ export const Tests: TestFixture<LinkAddOptions>[] = [
OnOffToggle.On
],
expectedCmdToExec: ` ip link add link eth0 name macsec0 type ${ LinkTypes.Macsec } sci 0102030405060708 cipher gcm-aes-128 icvlen 16 encrypt on`
},
{
description: 'with `type can`',
options: {
name: 'can0',
type: {
[LinkTypes.Can]: true,
}
},
expectedCmd: [
'',
'ip',
'link',
'add',
'name',
'can0',
'type',
LinkTypes.Can
],
expectedCmdToExec: ` ip link add name can0 type ${ LinkTypes.Can }`
}
];

Expand Down
23 changes: 23 additions & 0 deletions __tests__/safe/cmd-generation/fixtures/link-set.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LinkSetOptions } from '../../../../src/commands/link/set.interfaces';
import { TestFixture } from '../../../../src/common/interfaces/tests';
import { XdpOptionTypes } from '../../../../src';
import { LinkTypes } from '../../../../src/commands/link.constants';

export const Tests: TestFixture<LinkSetOptions>[] = [
{
Expand Down Expand Up @@ -88,6 +89,28 @@ export const Tests: TestFixture<LinkSetOptions>[] = [
'/sys/fs/bpf/foo'
],
expectedCmdToExec: ` ip link set eth0 xdp ${XdpOptionTypes.Pinned} /sys/fs/bpf/foo`
},
{
description: 'with type can and bitrate',
options: {
dev: 'can0',
type: {
[LinkTypes.Can]: true,
},
bitrate: 500000
},
expectedCmd: [
'',
'ip',
'link',
'set',
'can0',
'type',
'can',
'bitrate',
500000
],
expectedCmdToExec: ` ip link set can0 type can bitrate 500000`
}
];

Expand Down
2 changes: 2 additions & 0 deletions src/commands/link.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const LinkTypes = {
Macvtap: 'macvtap',
/** Virtual Controller Area Network interface. */
Vcan: 'vcan',
/** Controller Area Network interface. */
Can: 'can',
/** Virtual Controller Area Network tunnel interface. */
Vxcan: 'vxcan',
/** Virtual ethernet interface. */
Expand Down
1 change: 1 addition & 0 deletions src/commands/link/add.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface LinkTypesMappings {
[LinkTypes.Dummy]: true;
[LinkTypes.Ifb]: true;
[LinkTypes.Vcan]: true;
[LinkTypes.Can]: true;
[LinkTypes.Ip6tnl]: true;
[LinkTypes.Vti]: true;
[LinkTypes.Nlmon]: true;
Expand Down
5 changes: 5 additions & 0 deletions src/commands/link/add.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const typePropertiesSchema: any = {
enum: [true],
nullable: true
},
[LinkTypes.Can]: {
type: 'boolean',
enum: [true],
nullable: true
},
[LinkTypes.Ip6tnl]: {
type: 'boolean',
enum: [true],
Expand Down
2 changes: 2 additions & 0 deletions src/commands/link/set.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export interface LinkSetCommonOptions {
trailers?: OnOffToggle;
/** Change the transmit queue length of the device. */
txqueuelen?: number;
/** Change the bitrate of the device. */
bitrate?: number;
/**
* Change the name of the device.
* This operation is not recommended if the device is running or has some addresses already configured.
Expand Down
5 changes: 5 additions & 0 deletions src/commands/link/set.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export const LinkSetSchema: JSONSchemaType<LinkSetOptions> = {
minimum: 1,
nullable: true
},
bitrate: {
type: 'integer',
minimum: 1,
nullable: true
},
name: {
type: 'string',
format: 'mac',
Expand Down
Loading