Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created April 10, 2021 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inklesspen/539f734d6044c29da14c75a8166ee744 to your computer and use it in GitHub Desktop.
Save inklesspen/539f734d6044c29da14c75a8166ee744 to your computer and use it in GitHub Desktop.
Clara HD kernel changes, 2018 to 2021
diff --git a/kernel-2018/arch/arm/boot/dts/imx6sll-ntx.dtsi b/kernel-2021/arch/arm/boot/dts/imx6sll-ntx.dtsi
index 5121ada..f6c7d09 100644
--- a/kernel-2018/arch/arm/boot/dts/imx6sll-ntx.dtsi
+++ b/kernel-2021/arch/arm/boot/dts/imx6sll-ntx.dtsi
@@ -52,15 +52,15 @@
operating-points = < /* Core2_1V3_ARM */
/* kHz uV */
996000 1275000
- 792000 1175000
- 396000 1175000
+ 792000 1275000
+ 396000 1275000
198000 1175000
>;
fsl,soc-operating-points = < /* Core2_1V3_SOC */
/* ARM kHz SOC-PU uV */
996000 1275000
- 792000 1175000
- 396000 1175000
+ 792000 1275000
+ 396000 1275000
198000 1175000
>;
clock-latency = <61036>; /* two CLK32 periods */
diff --git a/kernel-2018/arch/arm/boot/dts/imx6sll-ntx_emmc.dtsi b/kernel-2021/arch/arm/boot/dts/imx6sll-ntx_emmc.dtsi
index 4d93e57..6de50be 100644
--- a/kernel-2018/arch/arm/boot/dts/imx6sll-ntx_emmc.dtsi
+++ b/kernel-2021/arch/arm/boot/dts/imx6sll-ntx_emmc.dtsi
@@ -52,15 +52,15 @@
operating-points = < /* Core2_1V3_ARM */
/* kHz uV */
996000 1275000
- 792000 1175000
- 396000 1175000
+ 792000 1275000
+ 396000 1275000
198000 1175000
>;
fsl,soc-operating-points = < /* Core2_1V3_SOC */
/* ARM kHz SOC-PU uV */
996000 1275000
- 792000 1175000
- 396000 1175000
+ 792000 1275000
+ 396000 1275000
198000 1175000
>;
clock-latency = <61036>; /* two CLK32 periods */
diff --git a/kernel-2018/arch/arm/configs/imx_v7_kobo_defconfig b/kernel-2021/arch/arm/configs/imx_v7_kobo_defconfig
index 2a11e24..c0332a0 100644
--- a/kernel-2018/arch/arm/configs/imx_v7_kobo_defconfig
+++ b/kernel-2021/arch/arm/configs/imx_v7_kobo_defconfig
@@ -1614,7 +1614,7 @@ CONFIG_SENSORS_FP9928=y
# CONFIG_SENSORS_W83627HF is not set
# CONFIG_SENSORS_W83627EHF is not set
# CONFIG_SENSORS_MAG3110 is not set
-# CONFIG_MXC_MMA8451 is not set
+# CONFIG_SENSORS_MMA8X5X is not set
CONFIG_THERMAL=y
CONFIG_THERMAL_HWMON=y
CONFIG_THERMAL_OF=y
diff --git a/kernel-2018/arch/arm/mach-imx/busfreq-imx.c b/kernel-2021/arch/arm/mach-imx/busfreq-imx.c
index 55b246e..6b98974 100644
--- a/kernel-2018/arch/arm/mach-imx/busfreq-imx.c
+++ b/kernel-2021/arch/arm/mach-imx/busfreq-imx.c
@@ -53,11 +53,11 @@ unsigned long ddr_freq_change_iram_base;
unsigned long ddr_freq_change_iram_phys;
static int ddr_type;
-static int low_bus_freq_mode;
-static int audio_bus_freq_mode;
-static int ultra_low_bus_freq_mode;
-static int high_bus_freq_mode;
-static int med_bus_freq_mode;
+int low_bus_freq_mode;
+int audio_bus_freq_mode;
+int ultra_low_bus_freq_mode;
+int high_bus_freq_mode;
+int med_bus_freq_mode;
static int bus_freq_scaling_initialized;
static struct device *busfreq_dev;
static int busfreq_suspended;
@@ -67,6 +67,9 @@ static unsigned int ddr_low_rate;
static int cur_bus_freq_mode;
static u32 org_arm_rate;
static int origin_arm_volt, origin_soc_volt;
+int giBusFreqDebugLvl=0;
+static int giLowBufFreqDelayus=5000000;
+static int giAlwaysLowBufFreq=0;
extern unsigned long iram_tlb_phys_addr;
extern int unsigned long iram_tlb_base_addr;
@@ -170,6 +173,9 @@ static struct clk *origin_step_parent;
static void imx6ull_lower_cpu_rate(bool enter)
{
int ret;
+
+ if (arm_reg == NULL || soc_reg == NULL)
+ return;
if (enter) {
org_arm_rate = clk_get_rate(arm_clk);
@@ -722,7 +728,7 @@ int set_low_bus_freq(void)
* the conditions still remain the same.
*/
schedule_delayed_work(&low_bus_freq_handler,
- usecs_to_jiffies(5000000));
+ usecs_to_jiffies(giLowBufFreqDelayus));
return 0;
}
@@ -794,14 +800,42 @@ void request_bus_freq(enum bus_freq_mode mode)
return;
}
- if (mode == BUS_FREQ_HIGH)
+ if (mode == BUS_FREQ_HIGH) {
high_bus_count++;
- else if (mode == BUS_FREQ_MED)
+ if(giBusFreqDebugLvl) {
+ printk("request high busfreq %d\n",high_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
+ }
+ else if (mode == BUS_FREQ_MED) {
med_bus_count++;
- else if (mode == BUS_FREQ_AUDIO)
+ if(giBusFreqDebugLvl) {
+ printk("request med busfreq %d\n",med_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
+ }
+ else if (mode == BUS_FREQ_AUDIO) {
audio_bus_count++;
- else if (mode == BUS_FREQ_LOW)
+ if(giBusFreqDebugLvl) {
+ printk("request audio busfreq %d\n",audio_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
+ }
+ else if (mode == BUS_FREQ_LOW) {
low_bus_count++;
+ if(giBusFreqDebugLvl) {
+ printk("request low busfreq %d\n",low_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
+ }
if (busfreq_suspended || !bus_freq_scaling_initialized ||
!bus_freq_scaling_is_active) {
@@ -851,6 +885,12 @@ void release_bus_freq(enum bus_freq_mode mode)
return;
}
high_bus_count--;
+ if(giBusFreqDebugLvl) {
+ printk("release high busfreq %d\n",high_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
} else if (mode == BUS_FREQ_MED) {
if (med_bus_count == 0) {
dev_err(busfreq_dev, "med bus count mismatch!\n");
@@ -859,6 +899,12 @@ void release_bus_freq(enum bus_freq_mode mode)
return;
}
med_bus_count--;
+ if(giBusFreqDebugLvl) {
+ printk("release med busfreq %d\n",med_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
} else if (mode == BUS_FREQ_AUDIO) {
if (audio_bus_count == 0) {
dev_err(busfreq_dev, "audio bus count mismatch!\n");
@@ -867,6 +913,12 @@ void release_bus_freq(enum bus_freq_mode mode)
return;
}
audio_bus_count--;
+ if(giBusFreqDebugLvl) {
+ printk("release audio busfreq %d\n",audio_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
} else if (mode == BUS_FREQ_LOW) {
if (low_bus_count == 0) {
dev_err(busfreq_dev, "low bus count mismatch!\n");
@@ -875,6 +927,12 @@ void release_bus_freq(enum bus_freq_mode mode)
return;
}
low_bus_count--;
+ if(giBusFreqDebugLvl) {
+ printk("release low busfreq %d\n",low_bus_count);
+ if(giBusFreqDebugLvl>=10) {
+ dump_stack();
+ }
+ }
}
if (busfreq_suspended || !bus_freq_scaling_initialized ||
@@ -987,6 +1045,10 @@ static void bus_freq_daemon_handler(struct work_struct *work)
static ssize_t bus_freq_scaling_enable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
+ if(giBusFreqDebugLvl) {
+ printk("debuglvl=%d,lowfreq_delayus=%d\n",giBusFreqDebugLvl,giLowBufFreqDelayus);
+ }
+
if (bus_freq_scaling_is_active)
return sprintf(buf, "Bus frequency scaling is enabled\n");
else
@@ -1013,6 +1075,16 @@ static ssize_t bus_freq_scaling_enable_store(struct device *dev,
set_high_bus_freq(1);
bus_freq_scaling_is_active = 0;
}
+ else {
+ if (strncmp(buf, "debug:", 6) == 0)
+ {
+ sscanf(&buf[6],"%d\n",&giBusFreqDebugLvl);
+ }
+ else if (strncmp(buf, "lowfreq_delayus:", 16) == 0)
+ {
+ sscanf(&buf[16],"%d\n",&giLowBufFreqDelayus);
+ }
+ }
return size;
}
@@ -1062,6 +1134,67 @@ static struct notifier_block imx_busfreq_reboot_notifier = {
static DEVICE_ATTR(enable, 0644, bus_freq_scaling_enable_show,
bus_freq_scaling_enable_store);
+static ssize_t bus_freq_mmdc_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int i;
+ char cbuf[20];
+
+ sprintf (buf,"================== mmdc0 registers ==================");
+ for (i=0; i<= 0x40; i+=4) {
+ if (!(i & 0x0F)) {
+ sprintf (cbuf,"\n%04X\t", i);
+ strcat (buf,cbuf);
+ }
+ sprintf (cbuf,"%08x ", readl_relaxed(IMX_IO_P2V(MX6Q_MMDC_P0_BASE_ADDR)+i));
+ strcat (buf,cbuf);
+ }
+ strcat (buf,"\n");
+ return strlen (buf);
+}
+
+static ssize_t bus_freq_mmdc_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ return size;
+}
+static DEVICE_ATTR(mmdc, 0644, bus_freq_mmdc_show,
+ bus_freq_mmdc_store);
+
+static ssize_t bus_freq_mode_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int i;
+
+ sprintf (buf,
+ "cur_bus_freq_mode=%d\n"
+ "high_bus_freq_mode=%d\n"
+ "med_bus_freq_mode=%d\n"
+ "low_bus_freq_mode=%d\n"
+ "audio_bus_freq_mode=%d\n"
+ "ultra_low_bus_freq_mode=%d\n"
+ ,
+ cur_bus_freq_mode,
+ high_bus_freq_mode,
+ med_bus_freq_mode,
+ low_bus_freq_mode,
+ audio_bus_freq_mode,
+ ultra_low_bus_freq_mode);
+
+ return strlen (buf);
+}
+
+static ssize_t bus_freq_mode_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ return size;
+}
+static DEVICE_ATTR(mode, 0644, bus_freq_mode_show,
+ bus_freq_mode_store);
+
+
/*!
* This is the probe routine for the bus frequency driver.
*
diff --git a/kernel-2018/arch/arm/mach-imx/imx6sll_low_power_idle.S b/kernel-2021/arch/arm/mach-imx/imx6sll_low_power_idle.S
index a7e206e..9200212 100644
--- a/kernel-2018/arch/arm/mach-imx/imx6sll_low_power_idle.S
+++ b/kernel-2021/arch/arm/mach-imx/imx6sll_low_power_idle.S
@@ -576,7 +576,7 @@ mx6sll_lpm_wfi_start:
ldr r10, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
ldr r7, =0x1
str r7, [r10, #0x2a0]
-
+
disable_l1_dcache
#ifdef CONFIG_CACHE_L2X0
@@ -668,7 +668,7 @@ save_and_set_mmdc_io_lpm:
/*
* now delay for a short while (3usec)
- * ARM is at 24MHz at this point
+ * ARM is at 198MHz at this point
* so a short loop should be enough.
* this delay is required to ensure that
* the RBC counter can start counting in
@@ -676,7 +676,7 @@ save_and_set_mmdc_io_lpm:
* or in case an interrupt arrives just
* as ARM is about to assert DSM_request.
*/
- ldr r4, =50
+ ldr r4, =400
rbc_loop:
subs r4, r4, #0x1
bne rbc_loop
diff --git a/kernel-2018/arch/arm/mach-imx/imx6ull_low_power_idle.S b/kernel-2021/arch/arm/mach-imx/imx6ull_low_power_idle.S
index 76ceac7..4d32c32 100644
--- a/kernel-2018/arch/arm/mach-imx/imx6ull_low_power_idle.S
+++ b/kernel-2021/arch/arm/mach-imx/imx6ull_low_power_idle.S
@@ -663,7 +663,7 @@ save_and_set_mmdc_io_lpm:
/*
* now delay for a short while (3usec)
- * ARM is at 24MHz at this point
+ * ARM is at 198MHz at this point
* so a short loop should be enough.
* this delay is required to ensure that
* the RBC counter can start counting in
@@ -671,7 +671,7 @@ save_and_set_mmdc_io_lpm:
* or in case an interrupt arrives just
* as ARM is about to assert DSM_request.
*/
- ldr r4, =50
+ ldr r4, =400
rbc_loop:
subs r4, r4, #0x1
bne rbc_loop
diff --git a/kernel-2018/drivers/cpufreq/imx6q-cpufreq.c b/kernel-2021/drivers/cpufreq/imx6q-cpufreq.c
index 258c9b7..3b6affe 100644
--- a/kernel-2018/drivers/cpufreq/imx6q-cpufreq.c
+++ b/kernel-2021/drivers/cpufreq/imx6q-cpufreq.c
@@ -57,12 +57,22 @@ static u32 soc_opp_count;
static bool ignore_dc_reg;
static bool low_power_run_support;
+extern int giBusFreqDebugLvl;
+
+extern int low_bus_freq_mode;
+extern int audio_bus_freq_mode;
+extern int ultra_low_bus_freq_mode;
+extern int high_bus_freq_mode;
+extern int med_bus_freq_mode;
+
+
static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
{
struct dev_pm_opp *opp;
unsigned long freq_hz, volt, volt_old;
unsigned int old_freq, new_freq;
int ret;
+ int iSwitchHighBusFreq = 0;
mutex_lock(&set_cpufreq_lock);
@@ -94,20 +104,40 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
rcu_read_unlock();
volt_old = regulator_get_voltage(arm_reg);
- dev_dbg(cpu_dev, "%u MHz, %ld mV --> %u MHz, %ld mV\n",
- old_freq / 1000, volt_old / 1000,
- new_freq / 1000, volt / 1000);
+ if( giBusFreqDebugLvl >= 2 ) {
+ dev_info(cpu_dev, "%u MHz, %ld mV --> %u MHz, %ld mV\n,idx=%d",
+ old_freq / 1000, volt_old / 1000,
+ new_freq / 1000, volt / 1000,index);
+#if 0
+ printk (
+ "high_bus_freq_mode=%d\n"
+ "med_bus_freq_mode=%d\n"
+ "low_bus_freq_mode=%d\n"
+ "audio_bus_freq_mode=%d\n"
+ "ultra_low_bus_freq_mode=%d\n"
+ ,
+ high_bus_freq_mode,
+ med_bus_freq_mode,
+ low_bus_freq_mode,
+ audio_bus_freq_mode,
+ ultra_low_bus_freq_mode);
+#endif
+
+ }
+
/*
* CPU freq is increasing, so need to ensure
* that bus frequency is increased too.
*/
if (low_power_run_support) {
if (old_freq == freq_table[0].frequency)
- request_bus_freq(BUS_FREQ_HIGH);
+ iSwitchHighBusFreq = 1;
} else if (old_freq <= FREQ_396_MHZ && new_freq > FREQ_396_MHZ) {
- request_bus_freq(BUS_FREQ_HIGH);
+ iSwitchHighBusFreq = 1;
}
+
+
/* scaling up? scale voltage before frequency */
if (new_freq > old_freq) {
if (!IS_ERR(pu_reg)) {
@@ -133,6 +163,10 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
}
}
+ if(iSwitchHighBusFreq) {
+ request_bus_freq(BUS_FREQ_HIGH);
+ }
+
/*
* The setpoints are selected per PLL/PDF frequencies, so we need to
* reprogram PLL for frequency scaling. The procedure of reprogramming
@@ -191,8 +225,19 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
return ret;
}
+ /*
+ * If CPU is dropped to the lowest level, release the need
+ * for a high bus frequency.
+ */
+ if (low_power_run_support) {
+ if (new_freq == freq_table[0].frequency)
+ release_bus_freq(BUS_FREQ_HIGH);
+ } else if (old_freq > FREQ_396_MHZ && new_freq <= FREQ_396_MHZ) {
+ release_bus_freq(BUS_FREQ_HIGH);
+ }
+
/* scaling down? scale voltage after frequency */
- if (new_freq < old_freq) {
+ if (new_freq < old_freq && ultra_low_bus_freq_mode ) {
ret = regulator_set_voltage_tol(arm_reg, volt, 0);
if (ret) {
dev_warn(cpu_dev,
@@ -212,16 +257,6 @@ static int imx6q_set_target(struct cpufreq_policy *policy, unsigned int index)
}
}
}
- /*
- * If CPU is dropped to the lowest level, release the need
- * for a high bus frequency.
- */
- if (low_power_run_support) {
- if (new_freq == freq_table[0].frequency)
- release_bus_freq(BUS_FREQ_HIGH);
- } else if (old_freq > FREQ_396_MHZ && new_freq <= FREQ_396_MHZ) {
- release_bus_freq(BUS_FREQ_HIGH);
- }
mutex_unlock(&set_cpufreq_lock);
return 0;
diff --git a/kernel-2018/drivers/input/misc/usb_plug.c b/kernel-2021/drivers/input/misc/usb_plug.c
index ff58a06..7e78af8 100755
--- a/kernel-2018/drivers/input/misc/usb_plug.c
+++ b/kernel-2021/drivers/input/misc/usb_plug.c
@@ -53,7 +53,7 @@ void usb_plug_handler(void *dummy)
}
if (NO_CHARGER_PLUGGED != plugged) {
- if (SDP_CHARGER == plugged) {
+ if ((SDP_CHARGER==plugged)||(CDP_CHARGER==plugged)) {
kobject_rename(&mxc_usbplug->ddev->kobj, "usb_host");
}
else {
diff --git a/kernel-2018/drivers/input/touchscreen/cyttsp5_core.c b/kernel-2021/drivers/input/touchscreen/cyttsp5_core.c
index 69c0a3e..45edbd0 100644
--- a/kernel-2018/drivers/input/touchscreen/cyttsp5_core.c
+++ b/kernel-2021/drivers/input/touchscreen/cyttsp5_core.c
@@ -4783,6 +4783,8 @@ static int cyttsp5_core_resume(struct device *dev)
{
struct cyttsp5_core_data *cd = dev_get_drvdata(dev);
int rc;
+ extern int cyttsp5_get_g_touch_status (void);
+ extern void cyttsp5_set_g_touch_status(int status);
if (cd->cpdata->irq_stat) {
if (0 == cd->cpdata->irq_stat(cd->cpdata, dev)){
@@ -4817,6 +4819,14 @@ static int cyttsp5_core_resume(struct device *dev)
dev_dbg(dev, "%s Device MAY NOT wakeup\n", __func__);
}
+ if(gSleep_Mode_Suspend)
+ {
+ if(cyttsp5_get_g_touch_status()>0)
+ {
+ cyttsp5_set_g_touch_status(0);
+ printk(KERN_WARNING"[%s_%d] Reset g_touch_status to 0 \n",__FUNCTION__,__LINE__);
+ }
+ }
exit:
cyttsp5_core_wake(cd);
@@ -5680,8 +5690,8 @@ EXPORT_SYMBOL(cyttsp5_get_module_data);
static void cyttsp5_early_suspend(struct early_suspend *h)
{
struct cyttsp5_core_data *cd =
- container_of(h, struct cyttsp5_core_data, es);
-
+ container_of(h, struct cyttsp5_core_data, es);
+
call_atten_cb(cd, CY_ATTEN_SUSPEND, 0);
}
diff --git a/kernel-2018/drivers/input/touchscreen/cyttsp5_mt_common.c b/kernel-2021/drivers/input/touchscreen/cyttsp5_mt_common.c
index 6d1e831..5aeeff2 100644
--- a/kernel-2018/drivers/input/touchscreen/cyttsp5_mt_common.c
+++ b/kernel-2021/drivers/input/touchscreen/cyttsp5_mt_common.c
@@ -268,7 +268,7 @@ static void cyttsp5_get_mt_touches(struct cyttsp5_mt_data *md,
/* If touch type is hover, send P as distance, reset P */
if (tch->abs[CY_TCH_O] == CY_OBJ_HOVER) {
- /* CY_ABS_D_OST signal must be in touch framework */
+ /* CY_ABS_D_OST signal must be in touch framework */
cyttsp5_report_event(md, CY_ABS_D_OST,
tch->abs[CY_TCH_P]);
tch->abs[CY_TCH_P] = 0;
@@ -326,7 +326,7 @@ cyttsp5_get_mt_touches_pr_tch:
}
extern int giSuspendingState;
-unsigned long glEventReportTick;
+static unsigned long glEventReportTick;
/* read xy_data for all current touches */
static int cyttsp5_xy_worker(struct cyttsp5_mt_data *md)
{
@@ -337,6 +337,7 @@ static int cyttsp5_xy_worker(struct cyttsp5_mt_data *md)
u8 num_cur_tch;
int rc = 0;
+ glEventReportTick = 0;
cyttsp5_get_touch_hdr(md, &tch, si->xy_mode + 3);
num_cur_tch = tch.hdr[CY_TCH_NUM];
@@ -778,13 +779,35 @@ int cyttsp5_mt_release(struct device *dev)
return 0;
}
+int cyttsp5_get_g_touch_status(void)
+{
+ return g_touch_status;
+}
+
+void cyttsp5_set_g_touch_status(int status)
+{
+ g_touch_status = status;
+}
+
+
int cyttsp5_mt_check_busy (void)
{
// Do not enter suspend if touch pressed or event not reported.
- if (g_touch_status || (glEventReportTick && time_after ((glEventReportTick+50),jiffies))) {
- printk ("[%s-%d] report event when suspending...\n", __func__, __LINE__);
- return -EBUSY;
+ if (g_touch_status) {
+ return -EBUSY;
}
- else
- return 0;
+
+ if( glEventReportTick )
+ {
+ unsigned long dwTickNow=jiffies;
+#define EVT_NOT_PROCCESSED_TIMEOUT_SECS 2
+
+ if(time_after ((glEventReportTick+(HZ*EVT_NOT_PROCCESSED_TIMEOUT_SECS)),dwTickNow)) {
+ printk ("[%s-%d] events not processed in %d secs...\n", __FUNCTION__, __LINE__);
+ }
+ else if(time_after ((glEventReportTick+HZ/2),dwTickNow)) {
+ printk ("[%s-%d] report event when suspending...\n", __FUNCTION__, __LINE__);
+ return -EBUSY;
+ }
+ }
}
diff --git a/kernel-2018/drivers/regulator/ricoh619-regulator.c b/kernel-2021/drivers/regulator/ricoh619-regulator.c
index baf7b28..c86ffd4 100755
--- a/kernel-2018/drivers/regulator/ricoh619-regulator.c
+++ b/kernel-2021/drivers/regulator/ricoh619-regulator.c
@@ -39,6 +39,10 @@
#include <linux/of.h>
#include <linux/regulator/of_regulator.h>
+extern int giBusFreqDebugLvl;
+
+#include "../../arch/arm/mach-imx/hardware.h"
+
#include "../../arch/arm/mach-imx/ntx_hwconfig.h"
struct ricoh61x_regulator {
int id;
@@ -196,6 +200,14 @@ static int ricoh61x_set_voltage(struct regulator_dev *rdev,
if (ricoh61x_suspend_status)
return -EBUSY;
+ if( giBusFreqDebugLvl >= 2 ) {
+ printk("%s()-%s (%d~%d)uV \n",__FUNCTION__,rdev->desc->name,min_uV,max_uV);
+
+ if( 9 == giBusFreqDebugLvl ) {
+ dump_stack();
+ }
+
+ }
return __ricoh61x_set_voltage(parent, ri, min_uV, max_uV, selector);
}
diff --git a/kernel-2018/drivers/usb/chipidea/ci_hdrc_imx.c b/kernel-2021/drivers/usb/chipidea/ci_hdrc_imx.c
index d2898ec..9a9a8ad 100644
--- a/kernel-2018/drivers/usb/chipidea/ci_hdrc_imx.c
+++ b/kernel-2021/drivers/usb/chipidea/ci_hdrc_imx.c
@@ -28,6 +28,8 @@
#include "ci.h"
#include "ci_hdrc_imx.h"
+static int giUsbBusFreqEnable=1;
+static int giBusFreqRequested = 0;
struct ci_hdrc_imx_platform_flag {
unsigned int flags;
bool runtime_pm;
@@ -440,6 +442,32 @@ static int imx_usb_register_charger(struct usb_charger *charger,
return 0;
}
+static ssize_t usb_busfreq_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ int i;
+
+ sprintf(buf,"%d\n",giUsbBusFreqEnable);
+
+ return strlen (buf);
+}
+
+static ssize_t usb_busfreq_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ if(0==strncmp(buf,"1",1)) {
+ giUsbBusFreqEnable = 1;
+ }
+ else
+ if(0==strncmp(buf,"0",1)) {
+ giUsbBusFreqEnable = 0;
+ }
+
+ return size;
+}
+static DEVICE_ATTR(busfreq, 0644, usb_busfreq_show,
+ usb_busfreq_store);
static int ci_hdrc_imx_probe(struct platform_device *pdev)
{
@@ -449,7 +477,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
.capoffset = DEF_CAPOFFSET,
.notify_event = ci_hdrc_imx_notify_event,
};
- int ret;
+ int ret,err;
const struct of_device_id *of_id =
of_match_device(ci_hdrc_imx_dt_ids, &pdev->dev);
const struct ci_hdrc_imx_platform_flag *imx_platform_flag = of_id->data;
@@ -499,8 +527,11 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
ret = imx_get_clks(&pdev->dev);
if (ret)
return ret;
+ if(giUsbBusFreqEnable) {
+ request_bus_freq(BUS_FREQ_HIGH);
+ giBusFreqRequested = 1;
+ }
- request_bus_freq(BUS_FREQ_HIGH);
ret = imx_prepare_enable_clks(&pdev->dev);
if (ret)
goto err_bus_freq;
@@ -607,6 +638,12 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev)
goto disable_device;
}
+ err = sysfs_create_file(&pdev->dev.kobj, &dev_attr_busfreq.attr);
+ if (err) {
+ dev_err(&pdev->dev,
+ "Unable to register sysdev entry for busfreq request when plugged .");
+ }
+
/* usbmisc needs to know dr mode to choose wakeup setting */
if (data->usbmisc_data)
data->usbmisc_data->available_role =
@@ -629,7 +666,10 @@ disable_hsic_regulator:
err_clk:
imx_disable_unprepare_clks(&pdev->dev);
err_bus_freq:
- release_bus_freq(BUS_FREQ_HIGH);
+ if(giBusFreqRequested) {
+ release_bus_freq(BUS_FREQ_HIGH);
+ giBusFreqRequested = 0;
+ }
return ret;
}
@@ -644,7 +684,10 @@ static int ci_hdrc_imx_remove(struct platform_device *pdev)
}
ci_hdrc_remove_device(data->ci_pdev);
imx_disable_unprepare_clks(&pdev->dev);
- release_bus_freq(BUS_FREQ_HIGH);
+ if(giBusFreqRequested) {
+ release_bus_freq(BUS_FREQ_HIGH);
+ giBusFreqRequested = 0;
+ }
if (data->hsic_pad_regulator)
regulator_disable(data->hsic_pad_regulator);
@@ -669,7 +712,10 @@ static int imx_controller_suspend(struct device *dev)
}
imx_disable_unprepare_clks(dev);
- release_bus_freq(BUS_FREQ_HIGH);
+ if(giBusFreqRequested) {
+ release_bus_freq(BUS_FREQ_HIGH);
+ giBusFreqRequested = 0;
+ }
data->in_lpm = true;
return 0;
@@ -687,7 +733,10 @@ static int imx_controller_resume(struct device *dev)
return 0;
}
- request_bus_freq(BUS_FREQ_HIGH);
+ if(giUsbBusFreqEnable) {
+ request_bus_freq(BUS_FREQ_HIGH);
+ giBusFreqRequested = 1;
+ }
ret = imx_prepare_enable_clks(dev);
if (ret)
return ret;
diff --git a/kernel-2018/drivers/video/fbdev/mxc/mxc_epdc_v2_fb.c b/kernel-2021/drivers/video/fbdev/mxc/mxc_epdc_v2_fb.c
index 8f9aca4..b4d4322 100644
--- a/kernel-2018/drivers/video/fbdev/mxc/mxc_epdc_v2_fb.c
+++ b/kernel-2021/drivers/video/fbdev/mxc/mxc_epdc_v2_fb.c
@@ -7798,7 +7798,7 @@ static int mxc_epdc_fb_remove(struct platform_device *pdev)
static int mxc_epdc_fb_suspend(struct device *dev)
{
struct mxc_epdc_fb_data *data = dev_get_drvdata(dev);
- int ret;
+ int ret = 0;
if (POWER_STATE_OFF != data->power_state)
diff --git a/kernel-2018/include/uapi/linux/netfilter/xt_CONNMARK.h b/kernel-2018/include/uapi/linux/netfilter/xt_CONNMARK.h
deleted file mode 100644
index 2f2e48e..0000000
--- a/kernel-2018/include/uapi/linux/netfilter/xt_CONNMARK.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _XT_CONNMARK_H_target
-#define _XT_CONNMARK_H_target
-
-#include <linux/netfilter/xt_connmark.h>
-
-#endif /*_XT_CONNMARK_H_target*/
diff --git a/kernel-2018/include/uapi/linux/netfilter/xt_DSCP.h b/kernel-2018/include/uapi/linux/netfilter/xt_DSCP.h
deleted file mode 100644
index 648e0b3..0000000
--- a/kernel-2018/include/uapi/linux/netfilter/xt_DSCP.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* x_tables module for setting the IPv4/IPv6 DSCP field
- *
- * (C) 2002 Harald Welte <laforge@gnumonks.org>
- * based on ipt_FTOS.c (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
- * This software is distributed under GNU GPL v2, 1991
- *
- * See RFC2474 for a description of the DSCP field within the IP Header.
- *
- * xt_DSCP.h,v 1.7 2002/03/14 12:03:13 laforge Exp
-*/
-#ifndef _XT_DSCP_TARGET_H
-#define _XT_DSCP_TARGET_H
-#include <linux/netfilter/xt_dscp.h>
-#include <linux/types.h>
-
-/* target info */
-struct xt_DSCP_info {
- __u8 dscp;
-};
-
-struct xt_tos_target_info {
- __u8 tos_value;
- __u8 tos_mask;
-};
-
-#endif /* _XT_DSCP_TARGET_H */
diff --git a/kernel-2018/include/uapi/linux/netfilter/xt_MARK.h b/kernel-2018/include/uapi/linux/netfilter/xt_MARK.h
deleted file mode 100644
index 41c456d..0000000
--- a/kernel-2018/include/uapi/linux/netfilter/xt_MARK.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _XT_MARK_H_target
-#define _XT_MARK_H_target
-
-#include <linux/netfilter/xt_mark.h>
-
-#endif /*_XT_MARK_H_target */
diff --git a/kernel-2018/include/uapi/linux/netfilter/xt_RATEEST.h b/kernel-2018/include/uapi/linux/netfilter/xt_RATEEST.h
deleted file mode 100644
index 6605e20..0000000
--- a/kernel-2018/include/uapi/linux/netfilter/xt_RATEEST.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef _XT_RATEEST_TARGET_H
-#define _XT_RATEEST_TARGET_H
-
-#include <linux/types.h>
-
-struct xt_rateest_target_info {
- char name[IFNAMSIZ];
- __s8 interval;
- __u8 ewma_log;
-
- /* Used internally by the kernel */
- struct xt_rateest *est __attribute__((aligned(8)));
-};
-
-#endif /* _XT_RATEEST_TARGET_H */
diff --git a/kernel-2018/include/uapi/linux/netfilter/xt_TCPMSS.h b/kernel-2018/include/uapi/linux/netfilter/xt_TCPMSS.h
deleted file mode 100644
index 9a6960a..0000000
--- a/kernel-2018/include/uapi/linux/netfilter/xt_TCPMSS.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef _XT_TCPMSS_H
-#define _XT_TCPMSS_H
-
-#include <linux/types.h>
-
-struct xt_tcpmss_info {
- __u16 mss;
-};
-
-#define XT_TCPMSS_CLAMP_PMTU 0xffff
-
-#endif /* _XT_TCPMSS_H */
diff --git a/kernel-2021/include/uapi/linux/netfilter/xt_connmark.h b/kernel-2021/include/uapi/linux/netfilter/xt_connmark.h
new file mode 100644
index 0000000..efc17a8
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter/xt_connmark.h
@@ -0,0 +1,31 @@
+#ifndef _XT_CONNMARK_H
+#define _XT_CONNMARK_H
+
+#include <linux/types.h>
+
+/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
+ * by Henrik Nordstrom <hno@marasystems.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+enum {
+ XT_CONNMARK_SET = 0,
+ XT_CONNMARK_SAVE,
+ XT_CONNMARK_RESTORE
+};
+
+struct xt_connmark_tginfo1 {
+ __u32 ctmark, ctmask, nfmask;
+ __u8 mode;
+};
+
+struct xt_connmark_mtinfo1 {
+ __u32 mark, mask;
+ __u8 invert;
+};
+
+#endif /*_XT_CONNMARK_H*/
diff --git a/kernel-2021/include/uapi/linux/netfilter/xt_dscp.h b/kernel-2021/include/uapi/linux/netfilter/xt_dscp.h
new file mode 100644
index 0000000..15f8932
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter/xt_dscp.h
@@ -0,0 +1,31 @@
+/* x_tables module for matching the IPv4/IPv6 DSCP field
+ *
+ * (C) 2002 Harald Welte <laforge@gnumonks.org>
+ * This software is distributed under GNU GPL v2, 1991
+ *
+ * See RFC2474 for a description of the DSCP field within the IP Header.
+ *
+ * xt_dscp.h,v 1.3 2002/08/05 19:00:21 laforge Exp
+*/
+#ifndef _XT_DSCP_H
+#define _XT_DSCP_H
+
+#include <linux/types.h>
+
+#define XT_DSCP_MASK 0xfc /* 11111100 */
+#define XT_DSCP_SHIFT 2
+#define XT_DSCP_MAX 0x3f /* 00111111 */
+
+/* match info */
+struct xt_dscp_info {
+ __u8 dscp;
+ __u8 invert;
+};
+
+struct xt_tos_match_info {
+ __u8 tos_mask;
+ __u8 tos_value;
+ __u8 invert;
+};
+
+#endif /* _XT_DSCP_H */
diff --git a/kernel-2021/include/uapi/linux/netfilter/xt_mark.h b/kernel-2021/include/uapi/linux/netfilter/xt_mark.h
new file mode 100644
index 0000000..ecadc40
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter/xt_mark.h
@@ -0,0 +1,15 @@
+#ifndef _XT_MARK_H
+#define _XT_MARK_H
+
+#include <linux/types.h>
+
+struct xt_mark_tginfo2 {
+ __u32 mark, mask;
+};
+
+struct xt_mark_mtinfo1 {
+ __u32 mark, mask;
+ __u8 invert;
+};
+
+#endif /*_XT_MARK_H*/
diff --git a/kernel-2021/include/uapi/linux/netfilter/xt_rateest.h b/kernel-2021/include/uapi/linux/netfilter/xt_rateest.h
new file mode 100644
index 0000000..d40a619
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter/xt_rateest.h
@@ -0,0 +1,37 @@
+#ifndef _XT_RATEEST_MATCH_H
+#define _XT_RATEEST_MATCH_H
+
+#include <linux/types.h>
+
+enum xt_rateest_match_flags {
+ XT_RATEEST_MATCH_INVERT = 1<<0,
+ XT_RATEEST_MATCH_ABS = 1<<1,
+ XT_RATEEST_MATCH_REL = 1<<2,
+ XT_RATEEST_MATCH_DELTA = 1<<3,
+ XT_RATEEST_MATCH_BPS = 1<<4,
+ XT_RATEEST_MATCH_PPS = 1<<5,
+};
+
+enum xt_rateest_match_mode {
+ XT_RATEEST_MATCH_NONE,
+ XT_RATEEST_MATCH_EQ,
+ XT_RATEEST_MATCH_LT,
+ XT_RATEEST_MATCH_GT,
+};
+
+struct xt_rateest_match_info {
+ char name1[IFNAMSIZ];
+ char name2[IFNAMSIZ];
+ __u16 flags;
+ __u16 mode;
+ __u32 bps1;
+ __u32 pps1;
+ __u32 bps2;
+ __u32 pps2;
+
+ /* Used internally by the kernel */
+ struct xt_rateest *est1 __attribute__((aligned(8)));
+ struct xt_rateest *est2 __attribute__((aligned(8)));
+};
+
+#endif /* _XT_RATEEST_MATCH_H */
diff --git a/kernel-2021/include/uapi/linux/netfilter/xt_tcpmss.h b/kernel-2021/include/uapi/linux/netfilter/xt_tcpmss.h
new file mode 100644
index 0000000..fbac56b
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter/xt_tcpmss.h
@@ -0,0 +1,11 @@
+#ifndef _XT_TCPMSS_MATCH_H
+#define _XT_TCPMSS_MATCH_H
+
+#include <linux/types.h>
+
+struct xt_tcpmss_match_info {
+ __u16 mss_min, mss_max;
+ __u8 invert;
+};
+
+#endif /*_XT_TCPMSS_MATCH_H*/
diff --git a/kernel-2018/include/uapi/linux/netfilter_ipv4/ipt_ECN.h b/kernel-2018/include/uapi/linux/netfilter_ipv4/ipt_ECN.h
deleted file mode 100644
index bb88d53..0000000
--- a/kernel-2018/include/uapi/linux/netfilter_ipv4/ipt_ECN.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Header file for iptables ipt_ECN target
- *
- * (C) 2002 by Harald Welte <laforge@gnumonks.org>
- *
- * This software is distributed under GNU GPL v2, 1991
- *
- * ipt_ECN.h,v 1.3 2002/05/29 12:17:40 laforge Exp
-*/
-#ifndef _IPT_ECN_TARGET_H
-#define _IPT_ECN_TARGET_H
-
-#include <linux/types.h>
-#include <linux/netfilter/xt_DSCP.h>
-
-#define IPT_ECN_IP_MASK (~XT_DSCP_MASK)
-
-#define IPT_ECN_OP_SET_IP 0x01 /* set ECN bits of IPv4 header */
-#define IPT_ECN_OP_SET_ECE 0x10 /* set ECE bit of TCP header */
-#define IPT_ECN_OP_SET_CWR 0x20 /* set CWR bit of TCP header */
-
-#define IPT_ECN_OP_MASK 0xce
-
-struct ipt_ECN_info {
- __u8 operation; /* bitset of operations */
- __u8 ip_ect; /* ECT codepoint of IPv4 header, pre-shifted */
- union {
- struct {
- __u8 ece:1, cwr:1; /* TCP ECT bits */
- } tcp;
- } proto;
-};
-
-#endif /* _IPT_ECN_TARGET_H */
diff --git a/kernel-2018/include/uapi/linux/netfilter_ipv4/ipt_TTL.h b/kernel-2018/include/uapi/linux/netfilter_ipv4/ipt_TTL.h
deleted file mode 100644
index f6ac169..0000000
--- a/kernel-2018/include/uapi/linux/netfilter_ipv4/ipt_TTL.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* TTL modification module for IP tables
- * (C) 2000 by Harald Welte <laforge@netfilter.org> */
-
-#ifndef _IPT_TTL_H
-#define _IPT_TTL_H
-
-#include <linux/types.h>
-
-enum {
- IPT_TTL_SET = 0,
- IPT_TTL_INC,
- IPT_TTL_DEC
-};
-
-#define IPT_TTL_MAXMODE IPT_TTL_DEC
-
-struct ipt_TTL_info {
- __u8 mode;
- __u8 ttl;
-};
-
-
-#endif
diff --git a/kernel-2021/include/uapi/linux/netfilter_ipv4/ipt_ecn.h b/kernel-2021/include/uapi/linux/netfilter_ipv4/ipt_ecn.h
new file mode 100644
index 0000000..0e0c063
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter_ipv4/ipt_ecn.h
@@ -0,0 +1,15 @@
+#ifndef _IPT_ECN_H
+#define _IPT_ECN_H
+
+#include <linux/netfilter/xt_ecn.h>
+#define ipt_ecn_info xt_ecn_info
+
+enum {
+ IPT_ECN_IP_MASK = XT_ECN_IP_MASK,
+ IPT_ECN_OP_MATCH_IP = XT_ECN_OP_MATCH_IP,
+ IPT_ECN_OP_MATCH_ECE = XT_ECN_OP_MATCH_ECE,
+ IPT_ECN_OP_MATCH_CWR = XT_ECN_OP_MATCH_CWR,
+ IPT_ECN_OP_MATCH_MASK = XT_ECN_OP_MATCH_MASK,
+};
+
+#endif /* IPT_ECN_H */
diff --git a/kernel-2021/include/uapi/linux/netfilter_ipv4/ipt_ttl.h b/kernel-2021/include/uapi/linux/netfilter_ipv4/ipt_ttl.h
new file mode 100644
index 0000000..37bee44
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter_ipv4/ipt_ttl.h
@@ -0,0 +1,23 @@
+/* IP tables module for matching the value of the TTL
+ * (C) 2000 by Harald Welte <laforge@gnumonks.org> */
+
+#ifndef _IPT_TTL_H
+#define _IPT_TTL_H
+
+#include <linux/types.h>
+
+enum {
+ IPT_TTL_EQ = 0, /* equals */
+ IPT_TTL_NE, /* not equals */
+ IPT_TTL_LT, /* less than */
+ IPT_TTL_GT, /* greater than */
+};
+
+
+struct ipt_ttl_info {
+ __u8 mode;
+ __u8 ttl;
+};
+
+
+#endif
diff --git a/kernel-2018/include/uapi/linux/netfilter_ipv6/ip6t_HL.h b/kernel-2018/include/uapi/linux/netfilter_ipv6/ip6t_HL.h
deleted file mode 100644
index ebd8ead..0000000
--- a/kernel-2018/include/uapi/linux/netfilter_ipv6/ip6t_HL.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Hop Limit modification module for ip6tables
- * Maciej Soltysiak <solt@dns.toxicfilms.tv>
- * Based on HW's TTL module */
-
-#ifndef _IP6T_HL_H
-#define _IP6T_HL_H
-
-#include <linux/types.h>
-
-enum {
- IP6T_HL_SET = 0,
- IP6T_HL_INC,
- IP6T_HL_DEC
-};
-
-#define IP6T_HL_MAXMODE IP6T_HL_DEC
-
-struct ip6t_HL_info {
- __u8 mode;
- __u8 hop_limit;
-};
-
-
-#endif
diff --git a/kernel-2021/include/uapi/linux/netfilter_ipv6/ip6t_hl.h b/kernel-2021/include/uapi/linux/netfilter_ipv6/ip6t_hl.h
new file mode 100644
index 0000000..6e76dbc
--- /dev/null
+++ b/kernel-2021/include/uapi/linux/netfilter_ipv6/ip6t_hl.h
@@ -0,0 +1,24 @@
+/* ip6tables module for matching the Hop Limit value
+ * Maciej Soltysiak <solt@dns.toxicfilms.tv>
+ * Based on HW's ttl module */
+
+#ifndef _IP6T_HL_H
+#define _IP6T_HL_H
+
+#include <linux/types.h>
+
+enum {
+ IP6T_HL_EQ = 0, /* equals */
+ IP6T_HL_NE, /* not equals */
+ IP6T_HL_LT, /* less than */
+ IP6T_HL_GT, /* greater than */
+};
+
+
+struct ip6t_hl_info {
+ __u8 mode;
+ __u8 hop_limit;
+};
+
+
+#endif
diff --git a/kernel-2018/net/netfilter/xt_DSCP.c b/kernel-2018/net/netfilter/xt_DSCP.c
deleted file mode 100644
index 3f83d38..0000000
--- a/kernel-2018/net/netfilter/xt_DSCP.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/* x_tables module for setting the IPv4/IPv6 DSCP field, Version 1.8
- *
- * (C) 2002 by Harald Welte <laforge@netfilter.org>
- * based on ipt_FTOS.c (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * See RFC2474 for a description of the DSCP field within the IP Header.
-*/
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/module.h>
-#include <linux/skbuff.h>
-#include <linux/ip.h>
-#include <linux/ipv6.h>
-#include <net/dsfield.h>
-
-#include <linux/netfilter/x_tables.h>
-#include <linux/netfilter/xt_DSCP.h>
-
-MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
-MODULE_DESCRIPTION("Xtables: DSCP/TOS field modification");
-MODULE_LICENSE("GPL");
-MODULE_ALIAS("ipt_DSCP");
-MODULE_ALIAS("ip6t_DSCP");
-MODULE_ALIAS("ipt_TOS");
-MODULE_ALIAS("ip6t_TOS");
-
-static unsigned int
-dscp_tg(struct sk_buff *skb, const struct xt_action_param *par)
-{
- const struct xt_DSCP_info *dinfo = par->targinfo;
- u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
-
- if (dscp != dinfo->dscp) {
- if (!skb_make_writable(skb, sizeof(struct iphdr)))
- return NF_DROP;
-
- ipv4_change_dsfield(ip_hdr(skb),
- (__force __u8)(~XT_DSCP_MASK),
- dinfo->dscp << XT_DSCP_SHIFT);
-
- }
- return XT_CONTINUE;
-}
-
-static unsigned int
-dscp_tg6(struct sk_buff *skb, const struct xt_action_param *par)
-{
- const struct xt_DSCP_info *dinfo = par->targinfo;
- u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
-
- if (dscp != dinfo->dscp) {
- if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
- return NF_DROP;
-
- ipv6_change_dsfield(ipv6_hdr(skb),
- (__force __u8)(~XT_DSCP_MASK),
- dinfo->dscp << XT_DSCP_SHIFT);
- }
- return XT_CONTINUE;
-}
-
-static int dscp_tg_check(const struct xt_tgchk_param *par)
-{
- const struct xt_DSCP_info *info = par->targinfo;
-
- if (info->dscp > XT_DSCP_MAX) {
- pr_info("dscp %x out of range\n", info->dscp);
- return -EDOM;
- }
- return 0;
-}
-
-static unsigned int
-tos_tg(struct sk_buff *skb, const struct xt_action_param *par)
-{
- const struct xt_tos_target_info *info = par->targinfo;
- struct iphdr *iph = ip_hdr(skb);
- u_int8_t orig, nv;
-
- orig = ipv4_get_dsfield(iph);
- nv = (orig & ~info->tos_mask) ^ info->tos_value;
-
- if (orig != nv) {
- if (!skb_make_writable(skb, sizeof(struct iphdr)))
- return NF_DROP;
- iph = ip_hdr(skb);
- ipv4_change_dsfield(iph, 0, nv);
- }
-
- return XT_CONTINUE;
-}
-
-static unsigned int
-tos_tg6(struct sk_buff *skb, const struct xt_action_param *par)
-{
- const struct xt_tos_target_info *info = par->targinfo;
- struct ipv6hdr *iph = ipv6_hdr(skb);
- u_int8_t orig, nv;
-
- orig = ipv6_get_dsfield(iph);
- nv = (orig & ~info->tos_mask) ^ info->tos_value;
-
- if (orig != nv) {
- if (!skb_make_writable(skb, sizeof(struct iphdr)))
- return NF_DROP;
- iph = ipv6_hdr(skb);
- ipv6_change_dsfield(iph, 0, nv);
- }
-
- return XT_CONTINUE;
-}
-
-static struct xt_target dscp_tg_reg[] __read_mostly = {
- {
- .name = "DSCP",
- .family = NFPROTO_IPV4,
- .checkentry = dscp_tg_check,
- .target = dscp_tg,
- .targetsize = sizeof(struct xt_DSCP_info),
- .table = "mangle",
- .me = THIS_MODULE,
- },
- {
- .name = "DSCP",
- .family = NFPROTO_IPV6,
- .checkentry = dscp_tg_check,
- .target = dscp_tg6,
- .targetsize = sizeof(struct xt_DSCP_info),
- .table = "mangle",
- .me = THIS_MODULE,
- },
- {
- .name = "TOS",
- .revision = 1,
- .family = NFPROTO_IPV4,
- .table = "mangle",
- .target = tos_tg,
- .targetsize = sizeof(struct xt_tos_target_info),
- .me = THIS_MODULE,
- },
- {
- .name = "TOS",
- .revision = 1,
- .family = NFPROTO_IPV6,
- .table = "mangle",
- .target = tos_tg6,
- .targetsize = sizeof(struct xt_tos_target_info),
- .me = THIS_MODULE,
- },
-};
-
-static int __init dscp_tg_init(void)
-{
- return xt_register_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
-}
-
-static void __exit dscp_tg_exit(void)
-{
- xt_unregister_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
-}
-
-module_init(dscp_tg_init);
-module_exit(dscp_tg_exit);
diff --git a/kernel-2018/net/netfilter/xt_HL.c b/kernel-2018/net/netfilter/xt_HL.c
deleted file mode 100644
index 1535e87..0000000
--- a/kernel-2018/net/netfilter/xt_HL.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * TTL modification target for IP tables
- * (C) 2000,2005 by Harald Welte <laforge@netfilter.org>
- *
- * Hop Limit modification target for ip6tables
- * Maciej Soltysiak <solt@dns.toxicfilms.tv>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/module.h>
-#include <linux/skbuff.h>
-#include <linux/ip.h>
-#include <linux/ipv6.h>
-#include <net/checksum.h>
-
-#include <linux/netfilter/x_tables.h>
-#include <linux/netfilter_ipv4/ipt_TTL.h>
-#include <linux/netfilter_ipv6/ip6t_HL.h>
-
-MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
-MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
-MODULE_DESCRIPTION("Xtables: Hoplimit/TTL Limit field modification target");
-MODULE_LICENSE("GPL");
-
-static unsigned int
-ttl_tg(struct sk_buff *skb, const struct xt_action_param *par)
-{
- struct iphdr *iph;
- const struct ipt_TTL_info *info = par->targinfo;
- int new_ttl;
-
- if (!skb_make_writable(skb, skb->len))
- return NF_DROP;
-
- iph = ip_hdr(skb);
-
- switch (info->mode) {
- case IPT_TTL_SET:
- new_ttl = info->ttl;
- break;
- case IPT_TTL_INC:
- new_ttl = iph->ttl + info->ttl;
- if (new_ttl > 255)
- new_ttl = 255;
- break;
- case IPT_TTL_DEC:
- new_ttl = iph->ttl - info->ttl;
- if (new_ttl < 0)
- new_ttl = 0;
- break;
- default:
- new_ttl = iph->ttl;
- break;
- }
-
- if (new_ttl != iph->ttl) {
- csum_replace2(&iph->check, htons(iph->ttl << 8),
- htons(new_ttl << 8));
- iph->ttl = new_ttl;
- }
-
- return XT_CONTINUE;
-}
-
-static unsigned int
-hl_tg6(struct sk_buff *skb, const struct xt_action_param *par)
-{
- struct ipv6hdr *ip6h;
- const struct ip6t_HL_info *info = par->targinfo;
- int new_hl;
-
- if (!skb_make_writable(skb, skb->len))
- return NF_DROP;
-
- ip6h = ipv6_hdr(skb);
-
- switch (info->mode) {
- case IP6T_HL_SET:
- new_hl = info->hop_limit;
- break;
- case IP6T_HL_INC:
- new_hl = ip6h->hop_limit + info->hop_limit;
- if (new_hl > 255)
- new_hl = 255;
- break;
- case IP6T_HL_DEC:
- new_hl = ip6h->hop_limit - info->hop_limit;
- if (new_hl < 0)
- new_hl = 0;
- break;
- default:
- new_hl = ip6h->hop_limit;
- break;
- }
-
- ip6h->hop_limit = new_hl;
-
- return XT_CONTINUE;
-}
-
-static int ttl_tg_check(const struct xt_tgchk_param *par)
-{
- const struct ipt_TTL_info *info = par->targinfo;
-
- if (info->mode > IPT_TTL_MAXMODE) {
- pr_info("TTL: invalid or unknown mode %u\n", info->mode);
- return -EINVAL;
- }
- if (info->mode != IPT_TTL_SET && info->ttl == 0)
- return -EINVAL;
- return 0;
-}
-
-static int hl_tg6_check(const struct xt_tgchk_param *par)
-{
- const struct ip6t_HL_info *info = par->targinfo;
-
- if (info->mode > IP6T_HL_MAXMODE) {
- pr_info("invalid or unknown mode %u\n", info->mode);
- return -EINVAL;
- }
- if (info->mode != IP6T_HL_SET && info->hop_limit == 0) {
- pr_info("increment/decrement does not "
- "make sense with value 0\n");
- return -EINVAL;
- }
- return 0;
-}
-
-static struct xt_target hl_tg_reg[] __read_mostly = {
- {
- .name = "TTL",
- .revision = 0,
- .family = NFPROTO_IPV4,
- .target = ttl_tg,
- .targetsize = sizeof(struct ipt_TTL_info),
- .table = "mangle",
- .checkentry = ttl_tg_check,
- .me = THIS_MODULE,
- },
- {
- .name = "HL",
- .revision = 0,
- .family = NFPROTO_IPV6,
- .target = hl_tg6,
- .targetsize = sizeof(struct ip6t_HL_info),
- .table = "mangle",
- .checkentry = hl_tg6_check,
- .me = THIS_MODULE,
- },
-};
-
-static int __init hl_tg_init(void)
-{
- return xt_register_targets(hl_tg_reg, ARRAY_SIZE(hl_tg_reg));
-}
-
-static void __exit hl_tg_exit(void)
-{
- xt_unregister_targets(hl_tg_reg, ARRAY_SIZE(hl_tg_reg));
-}
-
-module_init(hl_tg_init);
-module_exit(hl_tg_exit);
-MODULE_ALIAS("ipt_TTL");
-MODULE_ALIAS("ip6t_HL");
diff --git a/kernel-2018/net/netfilter/xt_RATEEST.c b/kernel-2018/net/netfilter/xt_RATEEST.c
deleted file mode 100644
index 604df6f..0000000
--- a/kernel-2018/net/netfilter/xt_RATEEST.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * (C) 2007 Patrick McHardy <kaber@trash.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#include <linux/module.h>
-#include <linux/skbuff.h>
-#include <linux/gen_stats.h>
-#include <linux/jhash.h>
-#include <linux/rtnetlink.h>
-#include <linux/random.h>
-#include <linux/slab.h>
-#include <net/gen_stats.h>
-#include <net/netlink.h>
-
-#include <linux/netfilter/x_tables.h>
-#include <linux/netfilter/xt_RATEEST.h>
-#include <net/netfilter/xt_rateest.h>
-
-static DEFINE_MUTEX(xt_rateest_mutex);
-
-#define RATEEST_HSIZE 16
-static struct hlist_head rateest_hash[RATEEST_HSIZE] __read_mostly;
-static unsigned int jhash_rnd __read_mostly;
-static bool rnd_inited __read_mostly;
-
-static unsigned int xt_rateest_hash(const char *name)
-{
- return jhash(name, FIELD_SIZEOF(struct xt_rateest, name), jhash_rnd) &
- (RATEEST_HSIZE - 1);
-}
-
-static void xt_rateest_hash_insert(struct xt_rateest *est)
-{
- unsigned int h;
-
- h = xt_rateest_hash(est->name);
- hlist_add_head(&est->list, &rateest_hash[h]);
-}
-
-struct xt_rateest *xt_rateest_lookup(const char *name)
-{
- struct xt_rateest *est;
- unsigned int h;
-
- h = xt_rateest_hash(name);
- mutex_lock(&xt_rateest_mutex);
- hlist_for_each_entry(est, &rateest_hash[h], list) {
- if (strcmp(est->name, name) == 0) {
- est->refcnt++;
- mutex_unlock(&xt_rateest_mutex);
- return est;
- }
- }
- mutex_unlock(&xt_rateest_mutex);
- return NULL;
-}
-EXPORT_SYMBOL_GPL(xt_rateest_lookup);
-
-void xt_rateest_put(struct xt_rateest *est)
-{
- mutex_lock(&xt_rateest_mutex);
- if (--est->refcnt == 0) {
- hlist_del(&est->list);
- gen_kill_estimator(&est->bstats, &est->rstats);
- /*
- * gen_estimator est_timer() might access est->lock or bstats,
- * wait a RCU grace period before freeing 'est'
- */
- kfree_rcu(est, rcu);
- }
- mutex_unlock(&xt_rateest_mutex);
-}
-EXPORT_SYMBOL_GPL(xt_rateest_put);
-
-static unsigned int
-xt_rateest_tg(struct sk_buff *skb, const struct xt_action_param *par)
-{
- const struct xt_rateest_target_info *info = par->targinfo;
- struct gnet_stats_basic_packed *stats = &info->est->bstats;
-
- spin_lock_bh(&info->est->lock);
- stats->bytes += skb->len;
- stats->packets++;
- spin_unlock_bh(&info->est->lock);
-
- return XT_CONTINUE;
-}
-
-static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
-{
- struct xt_rateest_target_info *info = par->targinfo;
- struct xt_rateest *est;
- struct {
- struct nlattr opt;
- struct gnet_estimator est;
- } cfg;
- int ret;
-
- if (unlikely(!rnd_inited)) {
- get_random_bytes(&jhash_rnd, sizeof(jhash_rnd));
- rnd_inited = true;
- }
-
- est = xt_rateest_lookup(info->name);
- if (est) {
- /*
- * If estimator parameters are specified, they must match the
- * existing estimator.
- */
- if ((!info->interval && !info->ewma_log) ||
- (info->interval != est->params.interval ||
- info->ewma_log != est->params.ewma_log)) {
- xt_rateest_put(est);
- return -EINVAL;
- }
- info->est = est;
- return 0;
- }
-
- ret = -ENOMEM;
- est = kzalloc(sizeof(*est), GFP_KERNEL);
- if (!est)
- goto err1;
-
- strlcpy(est->name, info->name, sizeof(est->name));
- spin_lock_init(&est->lock);
- est->refcnt = 1;
- est->params.interval = info->interval;
- est->params.ewma_log = info->ewma_log;
-
- cfg.opt.nla_len = nla_attr_size(sizeof(cfg.est));
- cfg.opt.nla_type = TCA_STATS_RATE_EST;
- cfg.est.interval = info->interval;
- cfg.est.ewma_log = info->ewma_log;
-
- ret = gen_new_estimator(&est->bstats, NULL, &est->rstats,
- &est->lock, &cfg.opt);
- if (ret < 0)
- goto err2;
-
- info->est = est;
- xt_rateest_hash_insert(est);
- return 0;
-
-err2:
- kfree(est);
-err1:
- return ret;
-}
-
-static void xt_rateest_tg_destroy(const struct xt_tgdtor_param *par)
-{
- struct xt_rateest_target_info *info = par->targinfo;
-
- xt_rateest_put(info->est);
-}
-
-static struct xt_target xt_rateest_tg_reg __read_mostly = {
- .name = "RATEEST",
- .revision = 0,
- .family = NFPROTO_UNSPEC,
- .target = xt_rateest_tg,
- .checkentry = xt_rateest_tg_checkentry,
- .destroy = xt_rateest_tg_destroy,
- .targetsize = sizeof(struct xt_rateest_target_info),
- .me = THIS_MODULE,
-};
-
-static int __init xt_rateest_tg_init(void)
-{
- unsigned int i;
-
- for (i = 0; i < ARRAY_SIZE(rateest_hash); i++)
- INIT_HLIST_HEAD(&rateest_hash[i]);
-
- return xt_register_target(&xt_rateest_tg_reg);
-}
-
-static void __exit xt_rateest_tg_fini(void)
-{
- xt_unregister_target(&xt_rateest_tg_reg);
-}
-
-
-MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
-MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Xtables: packet rate estimator");
-MODULE_ALIAS("ipt_RATEEST");
-MODULE_ALIAS("ip6t_RATEEST");
-module_init(xt_rateest_tg_init);
-module_exit(xt_rateest_tg_fini);
diff --git a/kernel-2018/net/netfilter/xt_TCPMSS.c b/kernel-2018/net/netfilter/xt_TCPMSS.c
deleted file mode 100644
index e762de5..0000000
--- a/kernel-2018/net/netfilter/xt_TCPMSS.c
+++ /dev/null
@@ -1,344 +0,0 @@
-/*
- * This is a module which is used for setting the MSS option in TCP packets.
- *
- * Copyright (C) 2000 Marc Boucher <marc@mbsi.ca>
- * Copyright (C) 2007 Patrick McHardy <kaber@trash.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-#include <linux/module.h>
-#include <linux/skbuff.h>
-#include <linux/ip.h>
-#include <linux/gfp.h>
-#include <linux/ipv6.h>
-#include <linux/tcp.h>
-#include <net/dst.h>
-#include <net/flow.h>
-#include <net/ipv6.h>
-#include <net/route.h>
-#include <net/tcp.h>
-
-#include <linux/netfilter_ipv4/ip_tables.h>
-#include <linux/netfilter_ipv6/ip6_tables.h>
-#include <linux/netfilter/x_tables.h>
-#include <linux/netfilter/xt_tcpudp.h>
-#include <linux/netfilter/xt_TCPMSS.h>
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
-MODULE_DESCRIPTION("Xtables: TCP Maximum Segment Size (MSS) adjustment");
-MODULE_ALIAS("ipt_TCPMSS");
-MODULE_ALIAS("ip6t_TCPMSS");
-
-static inline unsigned int
-optlen(const u_int8_t *opt, unsigned int offset)
-{
- /* Beware zero-length options: make finite progress */
- if (opt[offset] <= TCPOPT_NOP || opt[offset+1] == 0)
- return 1;
- else
- return opt[offset+1];
-}
-
-static u_int32_t tcpmss_reverse_mtu(struct net *net,
- const struct sk_buff *skb,
- unsigned int family)
-{
- struct flowi fl;
- const struct nf_afinfo *ai;
- struct rtable *rt = NULL;
- u_int32_t mtu = ~0U;
-
- if (family == PF_INET) {
- struct flowi4 *fl4 = &fl.u.ip4;
- memset(fl4, 0, sizeof(*fl4));
- fl4->daddr = ip_hdr(skb)->saddr;
- } else {
- struct flowi6 *fl6 = &fl.u.ip6;
-
- memset(fl6, 0, sizeof(*fl6));
- fl6->daddr = ipv6_hdr(skb)->saddr;
- }
- rcu_read_lock();
- ai = nf_get_afinfo(family);
- if (ai != NULL)
- ai->route(net, (struct dst_entry **)&rt, &fl, false);
- rcu_read_unlock();
-
- if (rt != NULL) {
- mtu = dst_mtu(&rt->dst);
- dst_release(&rt->dst);
- }
- return mtu;
-}
-
-static int
-tcpmss_mangle_packet(struct sk_buff *skb,
- const struct xt_action_param *par,
- unsigned int family,
- unsigned int tcphoff,
- unsigned int minlen)
-{
- const struct xt_tcpmss_info *info = par->targinfo;
- struct tcphdr *tcph;
- int len, tcp_hdrlen;
- unsigned int i;
- __be16 oldval;
- u16 newmss;
- u8 *opt;
-
- /* This is a fragment, no TCP header is available */
- if (par->fragoff != 0)
- return 0;
-
- if (!skb_make_writable(skb, skb->len))
- return -1;
-
- len = skb->len - tcphoff;
- if (len < (int)sizeof(struct tcphdr))
- return -1;
-
- tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
- tcp_hdrlen = tcph->doff * 4;
-
- if (len < tcp_hdrlen)
- return -1;
-
- if (info->mss == XT_TCPMSS_CLAMP_PMTU) {
- struct net *net = dev_net(par->in ? par->in : par->out);
- unsigned int in_mtu = tcpmss_reverse_mtu(net, skb, family);
-
- if (dst_mtu(skb_dst(skb)) <= minlen) {
- net_err_ratelimited("unknown or invalid path-MTU (%u)\n",
- dst_mtu(skb_dst(skb)));
- return -1;
- }
- if (in_mtu <= minlen) {
- net_err_ratelimited("unknown or invalid path-MTU (%u)\n",
- in_mtu);
- return -1;
- }
- newmss = min(dst_mtu(skb_dst(skb)), in_mtu) - minlen;
- } else
- newmss = info->mss;
-
- opt = (u_int8_t *)tcph;
- for (i = sizeof(struct tcphdr); i <= tcp_hdrlen - TCPOLEN_MSS; i += optlen(opt, i)) {
- if (opt[i] == TCPOPT_MSS && opt[i+1] == TCPOLEN_MSS) {
- u_int16_t oldmss;
-
- oldmss = (opt[i+2] << 8) | opt[i+3];
-
- /* Never increase MSS, even when setting it, as
- * doing so results in problems for hosts that rely
- * on MSS being set correctly.
- */
- if (oldmss <= newmss)
- return 0;
-
- opt[i+2] = (newmss & 0xff00) >> 8;
- opt[i+3] = newmss & 0x00ff;
-
- inet_proto_csum_replace2(&tcph->check, skb,
- htons(oldmss), htons(newmss),
- 0);
- return 0;
- }
- }
-
- /* There is data after the header so the option can't be added
- * without moving it, and doing so may make the SYN packet
- * itself too large. Accept the packet unmodified instead.
- */
- if (len > tcp_hdrlen)
- return 0;
-
- /*
- * MSS Option not found ?! add it..
- */
- if (skb_tailroom(skb) < TCPOLEN_MSS) {
- if (pskb_expand_head(skb, 0,
- TCPOLEN_MSS - skb_tailroom(skb),
- GFP_ATOMIC))
- return -1;
- tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
- }
-
- skb_put(skb, TCPOLEN_MSS);
-
- /*
- * IPv4: RFC 1122 states "If an MSS option is not received at
- * connection setup, TCP MUST assume a default send MSS of 536".
- * IPv6: RFC 2460 states IPv6 has a minimum MTU of 1280 and a minimum
- * length IPv6 header of 60, ergo the default MSS value is 1220
- * Since no MSS was provided, we must use the default values
- */
- if (par->family == NFPROTO_IPV4)
- newmss = min(newmss, (u16)536);
- else
- newmss = min(newmss, (u16)1220);
-
- opt = (u_int8_t *)tcph + sizeof(struct tcphdr);
- memmove(opt + TCPOLEN_MSS, opt, len - sizeof(struct tcphdr));
-
- inet_proto_csum_replace2(&tcph->check, skb,
- htons(len), htons(len + TCPOLEN_MSS), 1);
- opt[0] = TCPOPT_MSS;
- opt[1] = TCPOLEN_MSS;
- opt[2] = (newmss & 0xff00) >> 8;
- opt[3] = newmss & 0x00ff;
-
- inet_proto_csum_replace4(&tcph->check, skb, 0, *((__be32 *)opt), 0);
-
- oldval = ((__be16 *)tcph)[6];
- tcph->doff += TCPOLEN_MSS/4;
- inet_proto_csum_replace2(&tcph->check, skb,
- oldval, ((__be16 *)tcph)[6], 0);
- return TCPOLEN_MSS;
-}
-
-static unsigned int
-tcpmss_tg4(struct sk_buff *skb, const struct xt_action_param *par)
-{
- struct iphdr *iph = ip_hdr(skb);
- __be16 newlen;
- int ret;
-
- ret = tcpmss_mangle_packet(skb, par,
- PF_INET,
- iph->ihl * 4,
- sizeof(*iph) + sizeof(struct tcphdr));
- if (ret < 0)
- return NF_DROP;
- if (ret > 0) {
- iph = ip_hdr(skb);
- newlen = htons(ntohs(iph->tot_len) + ret);
- csum_replace2(&iph->check, iph->tot_len, newlen);
- iph->tot_len = newlen;
- }
- return XT_CONTINUE;
-}
-
-#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
-static unsigned int
-tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par)
-{
- struct ipv6hdr *ipv6h = ipv6_hdr(skb);
- u8 nexthdr;
- __be16 frag_off;
- int tcphoff;
- int ret;
-
- nexthdr = ipv6h->nexthdr;
- tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr, &frag_off);
- if (tcphoff < 0)
- return NF_DROP;
- ret = tcpmss_mangle_packet(skb, par,
- PF_INET6,
- tcphoff,
- sizeof(*ipv6h) + sizeof(struct tcphdr));
- if (ret < 0)
- return NF_DROP;
- if (ret > 0) {
- ipv6h = ipv6_hdr(skb);
- ipv6h->payload_len = htons(ntohs(ipv6h->payload_len) + ret);
- }
- return XT_CONTINUE;
-}
-#endif
-
-/* Must specify -p tcp --syn */
-static inline bool find_syn_match(const struct xt_entry_match *m)
-{
- const struct xt_tcp *tcpinfo = (const struct xt_tcp *)m->data;
-
- if (strcmp(m->u.kernel.match->name, "tcp") == 0 &&
- tcpinfo->flg_cmp & TCPHDR_SYN &&
- !(tcpinfo->invflags & XT_TCP_INV_FLAGS))
- return true;
-
- return false;
-}
-
-static int tcpmss_tg4_check(const struct xt_tgchk_param *par)
-{
- const struct xt_tcpmss_info *info = par->targinfo;
- const struct ipt_entry *e = par->entryinfo;
- const struct xt_entry_match *ematch;
-
- if (info->mss == XT_TCPMSS_CLAMP_PMTU &&
- (par->hook_mask & ~((1 << NF_INET_FORWARD) |
- (1 << NF_INET_LOCAL_OUT) |
- (1 << NF_INET_POST_ROUTING))) != 0) {
- pr_info("path-MTU clamping only supported in "
- "FORWARD, OUTPUT and POSTROUTING hooks\n");
- return -EINVAL;
- }
- xt_ematch_foreach(ematch, e)
- if (find_syn_match(ematch))
- return 0;
- pr_info("Only works on TCP SYN packets\n");
- return -EINVAL;
-}
-
-#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
-static int tcpmss_tg6_check(const struct xt_tgchk_param *par)
-{
- const struct xt_tcpmss_info *info = par->targinfo;
- const struct ip6t_entry *e = par->entryinfo;
- const struct xt_entry_match *ematch;
-
- if (info->mss == XT_TCPMSS_CLAMP_PMTU &&
- (par->hook_mask & ~((1 << NF_INET_FORWARD) |
- (1 << NF_INET_LOCAL_OUT) |
- (1 << NF_INET_POST_ROUTING))) != 0) {
- pr_info("path-MTU clamping only supported in "
- "FORWARD, OUTPUT and POSTROUTING hooks\n");
- return -EINVAL;
- }
- xt_ematch_foreach(ematch, e)
- if (find_syn_match(ematch))
- return 0;
- pr_info("Only works on TCP SYN packets\n");
- return -EINVAL;
-}
-#endif
-
-static struct xt_target tcpmss_tg_reg[] __read_mostly = {
- {
- .family = NFPROTO_IPV4,
- .name = "TCPMSS",
- .checkentry = tcpmss_tg4_check,
- .target = tcpmss_tg4,
- .targetsize = sizeof(struct xt_tcpmss_info),
- .proto = IPPROTO_TCP,
- .me = THIS_MODULE,
- },
-#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
- {
- .family = NFPROTO_IPV6,
- .name = "TCPMSS",
- .checkentry = tcpmss_tg6_check,
- .target = tcpmss_tg6,
- .targetsize = sizeof(struct xt_tcpmss_info),
- .proto = IPPROTO_TCP,
- .me = THIS_MODULE,
- },
-#endif
-};
-
-static int __init tcpmss_tg_init(void)
-{
- return xt_register_targets(tcpmss_tg_reg, ARRAY_SIZE(tcpmss_tg_reg));
-}
-
-static void __exit tcpmss_tg_exit(void)
-{
- xt_unregister_targets(tcpmss_tg_reg, ARRAY_SIZE(tcpmss_tg_reg));
-}
-
-module_init(tcpmss_tg_init);
-module_exit(tcpmss_tg_exit);
diff --git a/kernel-2021/net/netfilter/xt_dscp.c b/kernel-2021/net/netfilter/xt_dscp.c
new file mode 100644
index 0000000..64670fc
--- /dev/null
+++ b/kernel-2021/net/netfilter/xt_dscp.c
@@ -0,0 +1,115 @@
+/* IP tables module for matching the value of the IPv4/IPv6 DSCP field
+ *
+ * (C) 2002 by Harald Welte <laforge@netfilter.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <net/dsfield.h>
+
+#include <linux/netfilter/x_tables.h>
+#include <linux/netfilter/xt_dscp.h>
+
+MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
+MODULE_DESCRIPTION("Xtables: DSCP/TOS field match");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("ipt_dscp");
+MODULE_ALIAS("ip6t_dscp");
+MODULE_ALIAS("ipt_tos");
+MODULE_ALIAS("ip6t_tos");
+
+static bool
+dscp_mt(const struct sk_buff *skb, struct xt_action_param *par)
+{
+ const struct xt_dscp_info *info = par->matchinfo;
+ u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
+
+ return (dscp == info->dscp) ^ !!info->invert;
+}
+
+static bool
+dscp_mt6(const struct sk_buff *skb, struct xt_action_param *par)
+{
+ const struct xt_dscp_info *info = par->matchinfo;
+ u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
+
+ return (dscp == info->dscp) ^ !!info->invert;
+}
+
+static int dscp_mt_check(const struct xt_mtchk_param *par)
+{
+ const struct xt_dscp_info *info = par->matchinfo;
+
+ if (info->dscp > XT_DSCP_MAX) {
+ pr_info("dscp %x out of range\n", info->dscp);
+ return -EDOM;
+ }
+
+ return 0;
+}
+
+static bool tos_mt(const struct sk_buff *skb, struct xt_action_param *par)
+{
+ const struct xt_tos_match_info *info = par->matchinfo;
+
+ if (par->family == NFPROTO_IPV4)
+ return ((ip_hdr(skb)->tos & info->tos_mask) ==
+ info->tos_value) ^ !!info->invert;
+ else
+ return ((ipv6_get_dsfield(ipv6_hdr(skb)) & info->tos_mask) ==
+ info->tos_value) ^ !!info->invert;
+}
+
+static struct xt_match dscp_mt_reg[] __read_mostly = {
+ {
+ .name = "dscp",
+ .family = NFPROTO_IPV4,
+ .checkentry = dscp_mt_check,
+ .match = dscp_mt,
+ .matchsize = sizeof(struct xt_dscp_info),
+ .me = THIS_MODULE,
+ },
+ {
+ .name = "dscp",
+ .family = NFPROTO_IPV6,
+ .checkentry = dscp_mt_check,
+ .match = dscp_mt6,
+ .matchsize = sizeof(struct xt_dscp_info),
+ .me = THIS_MODULE,
+ },
+ {
+ .name = "tos",
+ .revision = 1,
+ .family = NFPROTO_IPV4,
+ .match = tos_mt,
+ .matchsize = sizeof(struct xt_tos_match_info),
+ .me = THIS_MODULE,
+ },
+ {
+ .name = "tos",
+ .revision = 1,
+ .family = NFPROTO_IPV6,
+ .match = tos_mt,
+ .matchsize = sizeof(struct xt_tos_match_info),
+ .me = THIS_MODULE,
+ },
+};
+
+static int __init dscp_mt_init(void)
+{
+ return xt_register_matches(dscp_mt_reg, ARRAY_SIZE(dscp_mt_reg));
+}
+
+static void __exit dscp_mt_exit(void)
+{
+ xt_unregister_matches(dscp_mt_reg, ARRAY_SIZE(dscp_mt_reg));
+}
+
+module_init(dscp_mt_init);
+module_exit(dscp_mt_exit);
diff --git a/kernel-2021/net/netfilter/xt_hl.c b/kernel-2021/net/netfilter/xt_hl.c
new file mode 100644
index 0000000..0039511
--- /dev/null
+++ b/kernel-2021/net/netfilter/xt_hl.c
@@ -0,0 +1,96 @@
+/*
+ * IP tables module for matching the value of the TTL
+ * (C) 2000,2001 by Harald Welte <laforge@netfilter.org>
+ *
+ * Hop Limit matching module
+ * (C) 2001-2002 Maciej Soltysiak <solt@dns.toxicfilms.tv>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/module.h>
+#include <linux/skbuff.h>
+
+#include <linux/netfilter/x_tables.h>
+#include <linux/netfilter_ipv4/ipt_ttl.h>
+#include <linux/netfilter_ipv6/ip6t_hl.h>
+
+MODULE_AUTHOR("Maciej Soltysiak <solt@dns.toxicfilms.tv>");
+MODULE_DESCRIPTION("Xtables: Hoplimit/TTL field match");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("ipt_ttl");
+MODULE_ALIAS("ip6t_hl");
+
+static bool ttl_mt(const struct sk_buff *skb, struct xt_action_param *par)
+{
+ const struct ipt_ttl_info *info = par->matchinfo;
+ const u8 ttl = ip_hdr(skb)->ttl;
+
+ switch (info->mode) {
+ case IPT_TTL_EQ:
+ return ttl == info->ttl;
+ case IPT_TTL_NE:
+ return ttl != info->ttl;
+ case IPT_TTL_LT:
+ return ttl < info->ttl;
+ case IPT_TTL_GT:
+ return ttl > info->ttl;
+ }
+
+ return false;
+}
+
+static bool hl_mt6(const struct sk_buff *skb, struct xt_action_param *par)
+{
+ const struct ip6t_hl_info *info = par->matchinfo;
+ const struct ipv6hdr *ip6h = ipv6_hdr(skb);
+
+ switch (info->mode) {
+ case IP6T_HL_EQ:
+ return ip6h->hop_limit == info->hop_limit;
+ case IP6T_HL_NE:
+ return ip6h->hop_limit != info->hop_limit;
+ case IP6T_HL_LT:
+ return ip6h->hop_limit < info->hop_limit;
+ case IP6T_HL_GT:
+ return ip6h->hop_limit > info->hop_limit;
+ }
+
+ return false;
+}
+
+static struct xt_match hl_mt_reg[] __read_mostly = {
+ {
+ .name = "ttl",
+ .revision = 0,
+ .family = NFPROTO_IPV4,
+ .match = ttl_mt,
+ .matchsize = sizeof(struct ipt_ttl_info),
+ .me = THIS_MODULE,
+ },
+ {
+ .name = "hl",
+ .revision = 0,
+ .family = NFPROTO_IPV6,
+ .match = hl_mt6,
+ .matchsize = sizeof(struct ip6t_hl_info),
+ .me = THIS_MODULE,
+ },
+};
+
+static int __init hl_mt_init(void)
+{
+ return xt_register_matches(hl_mt_reg, ARRAY_SIZE(hl_mt_reg));
+}
+
+static void __exit hl_mt_exit(void)
+{
+ xt_unregister_matches(hl_mt_reg, ARRAY_SIZE(hl_mt_reg));
+}
+
+module_init(hl_mt_init);
+module_exit(hl_mt_exit);
diff --git a/kernel-2021/net/netfilter/xt_rateest.c b/kernel-2021/net/netfilter/xt_rateest.c
new file mode 100644
index 0000000..7720b03
--- /dev/null
+++ b/kernel-2021/net/netfilter/xt_rateest.c
@@ -0,0 +1,157 @@
+/*
+ * (C) 2007 Patrick McHardy <kaber@trash.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <linux/gen_stats.h>
+
+#include <linux/netfilter/x_tables.h>
+#include <linux/netfilter/xt_rateest.h>
+#include <net/netfilter/xt_rateest.h>
+
+
+static bool
+xt_rateest_mt(const struct sk_buff *skb, struct xt_action_param *par)
+{
+ const struct xt_rateest_match_info *info = par->matchinfo;
+ struct gnet_stats_rate_est64 *r;
+ u_int32_t bps1, bps2, pps1, pps2;
+ bool ret = true;
+
+ spin_lock_bh(&info->est1->lock);
+ r = &info->est1->rstats;
+ if (info->flags & XT_RATEEST_MATCH_DELTA) {
+ bps1 = info->bps1 >= r->bps ? info->bps1 - r->bps : 0;
+ pps1 = info->pps1 >= r->pps ? info->pps1 - r->pps : 0;
+ } else {
+ bps1 = r->bps;
+ pps1 = r->pps;
+ }
+ spin_unlock_bh(&info->est1->lock);
+
+ if (info->flags & XT_RATEEST_MATCH_ABS) {
+ bps2 = info->bps2;
+ pps2 = info->pps2;
+ } else {
+ spin_lock_bh(&info->est2->lock);
+ r = &info->est2->rstats;
+ if (info->flags & XT_RATEEST_MATCH_DELTA) {
+ bps2 = info->bps2 >= r->bps ? info->bps2 - r->bps : 0;
+ pps2 = info->pps2 >= r->pps ? info->pps2 - r->pps : 0;
+ } else {
+ bps2 = r->bps;
+ pps2 = r->pps;
+ }
+ spin_unlock_bh(&info->est2->lock);
+ }
+
+ switch (info->mode) {
+ case XT_RATEEST_MATCH_LT:
+ if (info->flags & XT_RATEEST_MATCH_BPS)
+ ret &= bps1 < bps2;
+ if (info->flags & XT_RATEEST_MATCH_PPS)
+ ret &= pps1 < pps2;
+ break;
+ case XT_RATEEST_MATCH_GT:
+ if (info->flags & XT_RATEEST_MATCH_BPS)
+ ret &= bps1 > bps2;
+ if (info->flags & XT_RATEEST_MATCH_PPS)
+ ret &= pps1 > pps2;
+ break;
+ case XT_RATEEST_MATCH_EQ:
+ if (info->flags & XT_RATEEST_MATCH_BPS)
+ ret &= bps1 == bps2;
+ if (info->flags & XT_RATEEST_MATCH_PPS)
+ ret &= pps1 == pps2;
+ break;
+ }
+
+ ret ^= info->flags & XT_RATEEST_MATCH_INVERT ? true : false;
+ return ret;
+}
+
+static int xt_rateest_mt_checkentry(const struct xt_mtchk_param *par)
+{
+ struct xt_rateest_match_info *info = par->matchinfo;
+ struct xt_rateest *est1, *est2;
+ int ret = -EINVAL;
+
+ if (hweight32(info->flags & (XT_RATEEST_MATCH_ABS |
+ XT_RATEEST_MATCH_REL)) != 1)
+ goto err1;
+
+ if (!(info->flags & (XT_RATEEST_MATCH_BPS | XT_RATEEST_MATCH_PPS)))
+ goto err1;
+
+ switch (info->mode) {
+ case XT_RATEEST_MATCH_EQ:
+ case XT_RATEEST_MATCH_LT:
+ case XT_RATEEST_MATCH_GT:
+ break;
+ default:
+ goto err1;
+ }
+
+ ret = -ENOENT;
+ est1 = xt_rateest_lookup(info->name1);
+ if (!est1)
+ goto err1;
+
+ est2 = NULL;
+ if (info->flags & XT_RATEEST_MATCH_REL) {
+ est2 = xt_rateest_lookup(info->name2);
+ if (!est2)
+ goto err2;
+ }
+
+ info->est1 = est1;
+ info->est2 = est2;
+ return 0;
+
+err2:
+ xt_rateest_put(est1);
+err1:
+ return ret;
+}
+
+static void xt_rateest_mt_destroy(const struct xt_mtdtor_param *par)
+{
+ struct xt_rateest_match_info *info = par->matchinfo;
+
+ xt_rateest_put(info->est1);
+ if (info->est2)
+ xt_rateest_put(info->est2);
+}
+
+static struct xt_match xt_rateest_mt_reg __read_mostly = {
+ .name = "rateest",
+ .revision = 0,
+ .family = NFPROTO_UNSPEC,
+ .match = xt_rateest_mt,
+ .checkentry = xt_rateest_mt_checkentry,
+ .destroy = xt_rateest_mt_destroy,
+ .matchsize = sizeof(struct xt_rateest_match_info),
+ .me = THIS_MODULE,
+};
+
+static int __init xt_rateest_mt_init(void)
+{
+ return xt_register_match(&xt_rateest_mt_reg);
+}
+
+static void __exit xt_rateest_mt_fini(void)
+{
+ xt_unregister_match(&xt_rateest_mt_reg);
+}
+
+MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("xtables rate estimator match");
+MODULE_ALIAS("ipt_rateest");
+MODULE_ALIAS("ip6t_rateest");
+module_init(xt_rateest_mt_init);
+module_exit(xt_rateest_mt_fini);
diff --git a/kernel-2021/net/netfilter/xt_tcpmss.c b/kernel-2021/net/netfilter/xt_tcpmss.c
new file mode 100644
index 0000000..c53d4d1
--- /dev/null
+++ b/kernel-2021/net/netfilter/xt_tcpmss.c
@@ -0,0 +1,110 @@
+/* Kernel module to match TCP MSS values. */
+
+/* Copyright (C) 2000 Marc Boucher <marc@mbsi.ca>
+ * Portions (C) 2005 by Harald Welte <laforge@netfilter.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/skbuff.h>
+#include <net/tcp.h>
+
+#include <linux/netfilter/xt_tcpmss.h>
+#include <linux/netfilter/x_tables.h>
+
+#include <linux/netfilter_ipv4/ip_tables.h>
+#include <linux/netfilter_ipv6/ip6_tables.h>
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
+MODULE_DESCRIPTION("Xtables: TCP MSS match");
+MODULE_ALIAS("ipt_tcpmss");
+MODULE_ALIAS("ip6t_tcpmss");
+
+static bool
+tcpmss_mt(const struct sk_buff *skb, struct xt_action_param *par)
+{
+ const struct xt_tcpmss_match_info *info = par->matchinfo;
+ const struct tcphdr *th;
+ struct tcphdr _tcph;
+ /* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
+ const u_int8_t *op;
+ u8 _opt[15 * 4 - sizeof(_tcph)];
+ unsigned int i, optlen;
+
+ /* If we don't have the whole header, drop packet. */
+ th = skb_header_pointer(skb, par->thoff, sizeof(_tcph), &_tcph);
+ if (th == NULL)
+ goto dropit;
+
+ /* Malformed. */
+ if (th->doff*4 < sizeof(*th))
+ goto dropit;
+
+ optlen = th->doff*4 - sizeof(*th);
+ if (!optlen)
+ goto out;
+
+ /* Truncated options. */
+ op = skb_header_pointer(skb, par->thoff + sizeof(*th), optlen, _opt);
+ if (op == NULL)
+ goto dropit;
+
+ for (i = 0; i < optlen; ) {
+ if (op[i] == TCPOPT_MSS
+ && (optlen - i) >= TCPOLEN_MSS
+ && op[i+1] == TCPOLEN_MSS) {
+ u_int16_t mssval;
+
+ mssval = (op[i+2] << 8) | op[i+3];
+
+ return (mssval >= info->mss_min &&
+ mssval <= info->mss_max) ^ info->invert;
+ }
+ if (op[i] < 2)
+ i++;
+ else
+ i += op[i+1] ? : 1;
+ }
+out:
+ return info->invert;
+
+dropit:
+ par->hotdrop = true;
+ return false;
+}
+
+static struct xt_match tcpmss_mt_reg[] __read_mostly = {
+ {
+ .name = "tcpmss",
+ .family = NFPROTO_IPV4,
+ .match = tcpmss_mt,
+ .matchsize = sizeof(struct xt_tcpmss_match_info),
+ .proto = IPPROTO_TCP,
+ .me = THIS_MODULE,
+ },
+ {
+ .name = "tcpmss",
+ .family = NFPROTO_IPV6,
+ .match = tcpmss_mt,
+ .matchsize = sizeof(struct xt_tcpmss_match_info),
+ .proto = IPPROTO_TCP,
+ .me = THIS_MODULE,
+ },
+};
+
+static int __init tcpmss_mt_init(void)
+{
+ return xt_register_matches(tcpmss_mt_reg, ARRAY_SIZE(tcpmss_mt_reg));
+}
+
+static void __exit tcpmss_mt_exit(void)
+{
+ xt_unregister_matches(tcpmss_mt_reg, ARRAY_SIZE(tcpmss_mt_reg));
+}
+
+module_init(tcpmss_mt_init);
+module_exit(tcpmss_mt_exit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment