未验证 提交 a39fb478 编写于 作者: O openharmony_ci 提交者: Gitee

!20466 iptables rule

Merge pull request !20466 from 姚保华/master
......@@ -949,10 +949,10 @@ adminManager.unsubscribeManagedEvent(wantTemp, events).then(() => {
**系统API**: 此接口为系统接口。
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | --------| ---- | ----- | ------------------------------- |
| name | string | 是 | 否 | 表示设备管理员应用所属企业的名称。 |
| description | string | 是 | 否 | 表示设备管理员应用所属企业的描述。 |
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------| ---- | ------------------------------- |
| name | string | 是 | 表示设备管理员应用所属企业的名称。 |
| description | string | 是 | 表示设备管理员应用所属企业的描述。 |
## AdminType
......
......@@ -487,4 +487,425 @@ networkManager.setNetworkInterfaceDisabled(wantTemp, 'eth0', true).then(() => {
}).catch((err) => {
console.error(`Failed to set network interface disabled. Code: ${err.code}, message: ${err.message}`);
});
```
\ No newline at end of file
```
## networkManager.addIptablesFilterRule
addIptablesFilterRule(admin: Want, filterRule: AddFilterRule, callback: AsyncCallback\<void>): void
指定设备管理员应用添加网络包过滤规则,使用callback形式返回。
**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用。 |
| filterRule | [AddFilterRule](#addfilterrule) | 是 | 添加网络包过滤规则。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**示例:**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"ruleNo": 1,
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"method": networkManager.AddMethod.APPEND,
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.addIptablesFilterRule(wantTemp, filterRule, (err) => {
if (err) {
console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in setting iptables filter rule`);
});
```
## networkManager.addIptablesFilterRule
addIptablesFilterRule(admin: Want, filterRule: AddFilterRule): Promise\<void>
指定设备管理员应用添加网络包过滤规则,使用Promise形式返回。
**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用。 |
| filterRule | [AddFilterRule](#addfilterrule) | 是 | 添加网络包过滤规则。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。当添加网络包过滤规则失败时抛出错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**示例:**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"ruleNo": 1,
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"method": networkManager.AddMethod.APPEND,
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.addIptablesFilterRule(wantTemp, filterRule).then(() => {
console.info(`Succeeded in setting iptables filter rule`);
}).catch((err) => {
console.error(`Failed to set iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});
```
## networkManager.removeIptablesFilterRule
removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule, callback: AsyncCallback\<void>): void
指定设备管理员应用移除网络包过滤规则,使用callback形式返回。
**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用。 |
| filterRule | [RemoveFilterRule](#removefilterrule) | 是 | 移除网络包过滤规则。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**示例:**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.removeIptablesFilterRule(wantTemp, filterRule, (err) => {
if (err) {
console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in removing iptables filter rule`);
});
```
## networkManager.removeIptablesFilterRule
removeIptablesFilterRule(admin: Want, filterRule: RemoveFilterRule): Promise\<void>
指定设备管理员应用移除网络包过滤规则,使用Promise形式返回。
**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用。 |
| filterRule | [RemoveFilterRule](#removefilterrule) | 是 | 移除网络包过滤规则。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。当移除网络包过滤规则失败时抛出错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**示例:**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
let filterRule = {
"srcAddr": "192.168.1.1-192.188.22.66",
"destAddr": "10.1.1.1",
"srcPort": "8080",
"destPort": "8080",
"uid": "9696",
"direction": networkManager.Direction.OUTPUT,
"action": networkManager.Action.DENY,
"protocol": networkManager.Protocol.UDP,
}
networkManager.removeIptablesFilterRule(wantTemp, filterRule).then(() => {
console.info(`Succeeded in removing iptables filter rule`);
}).catch((err) => {
console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});
```
## networkManager.listIptablesFilterRules
listIptablesFilterRules(admin: Want, callback: AsyncCallback\<string>): void
指定设备管理员应用获取网络包过滤规则,使用callback形式返回。
**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用。 |
| callback | AsyncCallback&lt;string&gt; | 是 | 回调函数。当接口调用成功,err为null,否则err为错误对象。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**示例:**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.listIptablesFilterRules(wantTemp, (err, result) => {
if (err) {
console.error(`Failed to get iptables filter rule. Code: ${err.code}, message: ${err.message}`);
return;
}
console.info(`Succeeded in getting iptables filter rule, result : ${result}`);
});
```
## networkManager.listIptablesFilterRules
listIptablesFilterRules(admin: Want): Promise\<string>
指定设备管理员应用获取网络包过滤规则,使用Promise形式返回。
**需要权限:** ohos.permission.ENTERPRISE_MANAGE_NETWORK
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | 是 | 设备管理员应用。 |
**返回值:**
| 类型 | 说明 |
| --------------------- | ------------------------- |
| Promise&lt;string&gt; | Promise对象,返回网络包过滤规则。 |
**错误码**
以下的错误码的详细介绍请参见[企业设备管理错误码](../errorcodes/errorcode-enterpriseDeviceManager.md)
| 错误码ID | 错误信息 |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**示例:**
```js
let wantTemp = {
bundleName: 'com.example.myapplication',
abilityName: 'EntryAbility',
};
networkManager.listIptablesFilterRules(wantTemp).then((result) => {
console.info(`Succeeded in getting iptables filter rule, result: ${result}`);
}).catch((err) => {
console.error(`Failed to remove iptables filter rule. Code: ${err.code}, message: ${err.message}`);
});
```
## AddFilterRule
添加网络包过滤规则
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------| ---- | ------------------------------- |
| ruleNo | number | 否 | 规则序号。 |
| srcAddr | string | 否 | ip源地址。 |
| destAddr | string | 否 | ip目标地址。 |
| srcPort | string | 否 | ip源端口。 |
| destPort | string | 否 | ip目标端口。 |
| uid | string | 否 | 应用uid。 |
| method | [AddMethod](#addmethod) | 是 | 添加策略。 |
| direction | [Direction](#direction) | 是 | 规则链。 |
| action | [Action](#action) | 是 | 接收或者丢弃数据包。 |
| protocol | [Protocol](#protocol) | 否 | 网络协议。 |
## RemoveFilterRule
移除网络包过滤规则
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------| ---- | ------------------------------- |
| srcAddr | string | 否 | ip源地址。 |
| destAddr | string | 否 | ip目标地址。 |
| srcPort | string | 否 | ip源端口。 |
| destPort | string | 否 | ip目标端口。 |
| uid | string | 否 | 应用uid。 |
| direction | [Direction](#direction) | 是 | 规则链。 |
| action | [Action](#action) | 否 | 接收或者丢弃数据包。 |
| protocol | [Protocol](#protocol) | 否 | 网络协议。 |
## AddMethod
添加网络包方法。
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| APPEND | 0 | 追加。 |
| INSERT | 1 | 插入。 |
## Direction
规则链。
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| INPUT | 0 | 输入链。 |
| OUTPUT | 1 | 输出链。 |
## Action
数据包的行为。
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| ALLOW | 0 | 接收数据包。 |
| DENY | 1 | 丢弃数据包。 |
## Protocol
网络协议。
**系统能力:** SystemCapability.Customization.EnterpriseDeviceManager
**系统API**: 此接口为系统接口。
| 名称 | 值 | 说明 |
| -------- | -------- | -------- |
| ALL | 0 | 全部网络协议。 |
| TCP | 1 | 网络协议TCP。 |
| UDP | 2 | 网络协议UDP。 |
| ICMP | 3 | 网络协议ICMP。 |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册