From 09f9c897d33c41618ada06fbbcf1a9b3812dee53 Mon Sep 17 00:00:00 2001 From: jamie Date: Tue, 19 Oct 2010 21:32:13 +0000 Subject: A new jail(8) with a configuration file, to replace the work currently done by /etc/rc.d/jail. --- usr.sbin/IPXrouted/IPXrouted.8 | 224 - usr.sbin/IPXrouted/Makefile | 11 - usr.sbin/IPXrouted/af.c | 294 - usr.sbin/IPXrouted/af.h | 77 - usr.sbin/IPXrouted/defs.h | 108 - usr.sbin/IPXrouted/if.c | 151 - usr.sbin/IPXrouted/input.c | 304 - usr.sbin/IPXrouted/interface.h | 95 - usr.sbin/IPXrouted/main.c | 401 -- usr.sbin/IPXrouted/output.c | 231 - usr.sbin/IPXrouted/protocol.h | 92 - usr.sbin/IPXrouted/sap.h | 108 - usr.sbin/IPXrouted/sap_input.c | 215 - usr.sbin/IPXrouted/sap_output.c | 198 - usr.sbin/IPXrouted/sap_tables.c | 321 - usr.sbin/IPXrouted/startup.c | 278 - usr.sbin/IPXrouted/table.h | 115 - usr.sbin/IPXrouted/tables.c | 423 -- usr.sbin/IPXrouted/timer.c | 239 - usr.sbin/IPXrouted/trace.c | 520 -- usr.sbin/IPXrouted/trace.h | 138 - usr.sbin/Makefile | 309 - usr.sbin/Makefile.amd64 | 30 - usr.sbin/Makefile.arm | 5 - usr.sbin/Makefile.i386 | 42 - usr.sbin/Makefile.ia64 | 9 - usr.sbin/Makefile.inc | 6 - usr.sbin/Makefile.mips | 6 - usr.sbin/Makefile.powerpc | 5 - usr.sbin/Makefile.sparc64 | 8 - usr.sbin/ac/Makefile | 23 - usr.sbin/ac/ac.8 | 155 - usr.sbin/ac/ac.c | 636 -- usr.sbin/accton/Makefile | 7 - usr.sbin/accton/accton.8 | 42 - usr.sbin/accton/accton.c | 87 - usr.sbin/acpi/Makefile | 7 - usr.sbin/acpi/Makefile.inc | 24 - usr.sbin/acpi/acpiconf/Makefile | 7 - usr.sbin/acpi/acpiconf/acpiconf.8 | 92 - usr.sbin/acpi/acpiconf/acpiconf.c | 233 - usr.sbin/acpi/acpidb/Makefile | 68 - usr.sbin/acpi/acpidb/acpidb.8 | 167 - usr.sbin/acpi/acpidb/acpidb.c | 503 -- usr.sbin/acpi/acpidump/Makefile | 7 - usr.sbin/acpi/acpidump/acpi.c | 1300 ----- usr.sbin/acpi/acpidump/acpi_user.c | 222 - usr.sbin/acpi/acpidump/acpidump.8 | 199 - usr.sbin/acpi/acpidump/acpidump.c | 144 - usr.sbin/acpi/acpidump/acpidump.h | 158 - usr.sbin/acpi/iasl/Makefile | 79 - usr.sbin/acpi/iasl/iasl.8 | 179 - usr.sbin/adduser/Makefile | 6 - usr.sbin/adduser/adduser.8 | 480 -- usr.sbin/adduser/adduser.conf.5 | 221 - usr.sbin/adduser/adduser.sh | 1050 ---- usr.sbin/adduser/rmuser.8 | 210 - usr.sbin/adduser/rmuser.sh | 361 -- usr.sbin/amd/Makefile | 11 - usr.sbin/amd/Makefile.inc | 47 - usr.sbin/amd/NOTES | 3 - usr.sbin/amd/amd/Makefile | 53 - usr.sbin/amd/amq/Makefile | 20 - usr.sbin/amd/doc/Makefile | 14 - usr.sbin/amd/fixmount/Makefile | 21 - usr.sbin/amd/fsinfo/Makefile | 25 - usr.sbin/amd/hlfsd/Makefile | 19 - usr.sbin/amd/include/Makefile | 29 - usr.sbin/amd/include/amu_autofs_prot.h | 8 - usr.sbin/amd/include/amu_nfs_prot.h | 1 - usr.sbin/amd/include/aux_conf.h | 72 - usr.sbin/amd/include/build_version.h | 8 - usr.sbin/amd/include/config.h | 2205 ------- usr.sbin/amd/include/newvers.sh | 43 - usr.sbin/amd/libamu/Makefile | 36 - usr.sbin/amd/mk-amd-map/Makefile | 16 - usr.sbin/amd/pawd/Makefile | 20 - usr.sbin/amd/scripts/Makefile | 7 - usr.sbin/amd/wire-test/Makefile | 16 - usr.sbin/ancontrol/Makefile | 12 - usr.sbin/ancontrol/ancontrol.8 | 553 -- usr.sbin/ancontrol/ancontrol.c | 1781 ------ usr.sbin/apm/Makefile | 8 - usr.sbin/apm/apm.8 | 153 - usr.sbin/apm/apm.c | 490 -- usr.sbin/apmd/Makefile | 18 - usr.sbin/apmd/README | 213 - usr.sbin/apmd/apmd.8 | 322 -- usr.sbin/apmd/apmd.c | 705 --- usr.sbin/apmd/apmd.h | 133 - usr.sbin/apmd/apmdlex.l | 115 - usr.sbin/apmd/apmdparse.y | 205 - usr.sbin/apmd/contrib/pccardq.c | 286 - usr.sbin/arp/Makefile | 9 - usr.sbin/arp/arp.4 | 191 - usr.sbin/arp/arp.8 | 202 - usr.sbin/arp/arp.c | 868 --- usr.sbin/asf/Makefile | 10 - usr.sbin/asf/asf.8 | 179 - usr.sbin/asf/asf.c | 427 -- usr.sbin/asf/asf.h | 40 - usr.sbin/asf/asf_kld.c | 59 - usr.sbin/asf/asf_kvm.c | 128 - usr.sbin/asf/asf_prog.c | 73 - usr.sbin/audit/Makefile | 18 - usr.sbin/auditd/Makefile | 19 - usr.sbin/auditreduce/Makefile | 18 - usr.sbin/authpf/Makefile | 24 - usr.sbin/bluetooth/Makefile | 20 - usr.sbin/bluetooth/Makefile.inc | 4 - usr.sbin/bluetooth/bcmfw/BCM-LEGAL.txt | 8 - usr.sbin/bluetooth/bcmfw/Makefile | 8 - usr.sbin/bluetooth/bcmfw/README | 22 - usr.sbin/bluetooth/bcmfw/bcmfw.8 | 105 - usr.sbin/bluetooth/bcmfw/bcmfw.c | 308 - usr.sbin/bluetooth/bt3cfw/Makefile | 11 - usr.sbin/bluetooth/bt3cfw/bt3cfw.8 | 73 - usr.sbin/bluetooth/bt3cfw/bt3cfw.c | 227 - usr.sbin/bluetooth/bthidcontrol/Makefile | 15 - usr.sbin/bluetooth/bthidcontrol/bthidcontrol.8 | 102 - usr.sbin/bluetooth/bthidcontrol/bthidcontrol.c | 215 - usr.sbin/bluetooth/bthidcontrol/bthidcontrol.h | 50 - usr.sbin/bluetooth/bthidcontrol/hid.c | 214 - usr.sbin/bluetooth/bthidcontrol/sdp.c | 434 -- usr.sbin/bluetooth/bthidd/Makefile | 16 - usr.sbin/bluetooth/bthidd/bthid_config.h | 70 - usr.sbin/bluetooth/bthidd/bthidd.8 | 127 - usr.sbin/bluetooth/bthidd/bthidd.c | 266 - usr.sbin/bluetooth/bthidd/bthidd.conf.sample | 72 - usr.sbin/bluetooth/bthidd/bthidd.h | 93 - usr.sbin/bluetooth/bthidd/client.c | 256 - usr.sbin/bluetooth/bthidd/hid.c | 397 -- usr.sbin/bluetooth/bthidd/kbd.c | 580 -- usr.sbin/bluetooth/bthidd/kbd.h | 41 - usr.sbin/bluetooth/bthidd/lexer.l | 104 - usr.sbin/bluetooth/bthidd/parser.y | 475 -- usr.sbin/bluetooth/bthidd/server.c | 349 -- usr.sbin/bluetooth/bthidd/session.c | 184 - usr.sbin/bluetooth/btpand/Makefile | 13 - usr.sbin/bluetooth/btpand/bnep.c | 755 --- usr.sbin/bluetooth/btpand/bnep.h | 72 - usr.sbin/bluetooth/btpand/btpand.8 | 241 - usr.sbin/bluetooth/btpand/btpand.c | 293 - usr.sbin/bluetooth/btpand/btpand.h | 212 - usr.sbin/bluetooth/btpand/channel.c | 335 -- usr.sbin/bluetooth/btpand/client.c | 192 - usr.sbin/bluetooth/btpand/event.c | 309 - usr.sbin/bluetooth/btpand/event.h | 147 - usr.sbin/bluetooth/btpand/packet.c | 110 - usr.sbin/bluetooth/btpand/sdp.c | 209 - usr.sbin/bluetooth/btpand/sdp.h | 38 - usr.sbin/bluetooth/btpand/server.c | 277 - usr.sbin/bluetooth/btpand/tap.c | 167 - usr.sbin/bluetooth/hccontrol/Makefile | 14 - usr.sbin/bluetooth/hccontrol/hccontrol.8 | 184 - usr.sbin/bluetooth/hccontrol/hccontrol.c | 322 -- usr.sbin/bluetooth/hccontrol/hccontrol.h | 79 - .../bluetooth/hccontrol/host_controller_baseband.c | 1877 ------ usr.sbin/bluetooth/hccontrol/info.c | 216 - usr.sbin/bluetooth/hccontrol/link_control.c | 960 --- usr.sbin/bluetooth/hccontrol/link_policy.c | 305 - usr.sbin/bluetooth/hccontrol/node.c | 607 -- usr.sbin/bluetooth/hccontrol/send_recv.c | 184 - usr.sbin/bluetooth/hccontrol/status.c | 245 - usr.sbin/bluetooth/hccontrol/util.c | 410 -- usr.sbin/bluetooth/hcsecd/Makefile | 13 - usr.sbin/bluetooth/hcsecd/hcsecd.8 | 128 - usr.sbin/bluetooth/hcsecd/hcsecd.c | 446 -- usr.sbin/bluetooth/hcsecd/hcsecd.conf | 64 - usr.sbin/bluetooth/hcsecd/hcsecd.conf.5 | 131 - usr.sbin/bluetooth/hcsecd/hcsecd.h | 65 - usr.sbin/bluetooth/hcsecd/lexer.l | 95 - usr.sbin/bluetooth/hcsecd/parser.y | 433 -- usr.sbin/bluetooth/hcseriald/Makefile | 11 - usr.sbin/bluetooth/hcseriald/hcseriald.8 | 86 - usr.sbin/bluetooth/hcseriald/hcseriald.c | 268 - usr.sbin/bluetooth/l2control/Makefile | 12 - usr.sbin/bluetooth/l2control/l2cap.c | 313 - usr.sbin/bluetooth/l2control/l2control.8 | 95 - usr.sbin/bluetooth/l2control/l2control.c | 213 - usr.sbin/bluetooth/l2control/l2control.h | 49 - usr.sbin/bluetooth/l2ping/Makefile | 11 - usr.sbin/bluetooth/l2ping/l2ping.8 | 115 - usr.sbin/bluetooth/l2ping/l2ping.c | 290 - usr.sbin/bluetooth/rfcomm_pppd/Makefile | 14 - usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 | 354 -- usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c | 471 -- usr.sbin/bluetooth/sdpcontrol/Makefile | 12 - usr.sbin/bluetooth/sdpcontrol/sdpcontrol.8 | 118 - usr.sbin/bluetooth/sdpcontrol/sdpcontrol.c | 219 - usr.sbin/bluetooth/sdpcontrol/sdpcontrol.h | 49 - usr.sbin/bluetooth/sdpcontrol/search.c | 713 --- usr.sbin/bluetooth/sdpd/Makefile | 13 - usr.sbin/bluetooth/sdpd/bgd.c | 102 - usr.sbin/bluetooth/sdpd/dun.c | 136 - usr.sbin/bluetooth/sdpd/ftrn.c | 117 - usr.sbin/bluetooth/sdpd/gn.c | 172 - usr.sbin/bluetooth/sdpd/irmc.c | 133 - usr.sbin/bluetooth/sdpd/irmc_command.c | 117 - usr.sbin/bluetooth/sdpd/lan.c | 172 - usr.sbin/bluetooth/sdpd/log.c | 127 - usr.sbin/bluetooth/sdpd/log.h | 47 - usr.sbin/bluetooth/sdpd/main.c | 235 - usr.sbin/bluetooth/sdpd/nap.c | 209 - usr.sbin/bluetooth/sdpd/opush.c | 133 - usr.sbin/bluetooth/sdpd/panu.c | 172 - usr.sbin/bluetooth/sdpd/profile.c | 497 -- usr.sbin/bluetooth/sdpd/profile.h | 96 - usr.sbin/bluetooth/sdpd/provider.c | 196 - usr.sbin/bluetooth/sdpd/provider.h | 75 - usr.sbin/bluetooth/sdpd/sar.c | 317 - usr.sbin/bluetooth/sdpd/scr.c | 92 - usr.sbin/bluetooth/sdpd/sd.c | 228 - usr.sbin/bluetooth/sdpd/sdpd.8 | 140 - usr.sbin/bluetooth/sdpd/server.c | 589 -- usr.sbin/bluetooth/sdpd/server.h | 102 - usr.sbin/bluetooth/sdpd/sp.c | 117 - usr.sbin/bluetooth/sdpd/srr.c | 139 - usr.sbin/bluetooth/sdpd/ssar.c | 252 - usr.sbin/bluetooth/sdpd/ssr.c | 282 - usr.sbin/bluetooth/sdpd/sur.c | 83 - usr.sbin/bluetooth/sdpd/uuid-private.h | 39 - usr.sbin/bluetooth/sdpd/uuid.c | 56 - usr.sbin/boot0cfg/Makefile | 9 - usr.sbin/boot0cfg/boot0cfg.8 | 214 - usr.sbin/boot0cfg/boot0cfg.c | 571 -- usr.sbin/boot98cfg/Makefile | 11 - usr.sbin/boot98cfg/boot98cfg.8 | 104 - usr.sbin/boot98cfg/boot98cfg.c | 319 - usr.sbin/bootparamd/Makefile | 5 - usr.sbin/bootparamd/Makefile.inc | 6 - usr.sbin/bootparamd/bootparamd/Makefile | 29 - usr.sbin/bootparamd/bootparamd/README | 75 - usr.sbin/bootparamd/bootparamd/bootparamd.8 | 76 - usr.sbin/bootparamd/bootparamd/bootparamd.c | 358 -- usr.sbin/bootparamd/bootparamd/bootparams.5 | 86 - usr.sbin/bootparamd/bootparamd/main.c | 118 - usr.sbin/bootparamd/callbootd/Makefile | 24 - usr.sbin/bootparamd/callbootd/callbootd.c | 205 - usr.sbin/bsnmpd/Makefile | 7 - usr.sbin/bsnmpd/Makefile.inc | 3 - usr.sbin/bsnmpd/bsnmpd/Makefile | 45 - usr.sbin/bsnmpd/gensnmptree/Makefile | 15 - usr.sbin/bsnmpd/modules/Makefile | 25 - usr.sbin/bsnmpd/modules/Makefile.inc | 9 - .../modules/snmp_atm/BEGEMOT-ATM-FREEBSD-MIB.txt | 99 - usr.sbin/bsnmpd/modules/snmp_atm/Makefile | 21 - usr.sbin/bsnmpd/modules/snmp_atm/atm_freebsd.def | 56 - usr.sbin/bsnmpd/modules/snmp_atm/atm_sys.c | 301 - .../modules/snmp_bridge/BEGEMOT-BRIDGE-MIB.txt | 1166 ---- usr.sbin/bsnmpd/modules/snmp_bridge/BRIDGE-MIB.txt | 1483 ----- usr.sbin/bsnmpd/modules/snmp_bridge/Makefile | 19 - usr.sbin/bsnmpd/modules/snmp_bridge/RSTP-MIB.txt | 325 -- usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c | 589 -- usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c | 1479 ----- usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c | 116 - usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c | 1513 ----- usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c | 338 -- usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h | 357 -- usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c | 1503 ----- .../bsnmpd/modules/snmp_bridge/bridge_tree.def | 283 - usr.sbin/bsnmpd/modules/snmp_bridge/snmp_bridge.3 | 119 - .../modules/snmp_hostres/BEGEMOT-HOSTRES-MIB.txt | 125 - usr.sbin/bsnmpd/modules/snmp_hostres/Makefile | 82 - .../bsnmpd/modules/snmp_hostres/hostres_begemot.c | 171 - .../modules/snmp_hostres/hostres_device_tbl.c | 690 --- .../modules/snmp_hostres/hostres_diskstorage_tbl.c | 646 --- .../bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c | 473 -- .../modules/snmp_hostres/hostres_network_tbl.c | 302 - .../modules/snmp_hostres/hostres_partition_tbl.c | 630 -- .../modules/snmp_hostres/hostres_printer_tbl.c | 398 -- .../modules/snmp_hostres/hostres_processor_tbl.c | 507 -- .../bsnmpd/modules/snmp_hostres/hostres_scalars.c | 492 -- .../bsnmpd/modules/snmp_hostres/hostres_snmp.c | 208 - .../bsnmpd/modules/snmp_hostres/hostres_snmp.h | 324 -- .../modules/snmp_hostres/hostres_storage_tbl.c | 668 --- .../modules/snmp_hostres/hostres_swinstalled_tbl.c | 555 -- .../modules/snmp_hostres/hostres_swrun_tbl.c | 792 --- .../bsnmpd/modules/snmp_hostres/hostres_tree.def | 292 - .../bsnmpd/modules/snmp_hostres/snmp_hostres.3 | 88 - usr.sbin/bsnmpd/modules/snmp_mibII/Makefile | 27 - .../modules/snmp_netgraph/BEGEMOT-NETGRAPH.txt | 398 -- usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile | 17 - .../bsnmpd/modules/snmp_netgraph/netgraph_tree.def | 78 - .../bsnmpd/modules/snmp_netgraph/snmp_netgraph.3 | 436 -- .../bsnmpd/modules/snmp_netgraph/snmp_netgraph.c | 1690 ------ .../bsnmpd/modules/snmp_netgraph/snmp_netgraph.h | 91 - usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt | 1347 ----- usr.sbin/bsnmpd/modules/snmp_pf/Makefile | 13 - usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c | 1799 ------ usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def | 210 - .../modules/snmp_wlan/BEGEMOT-WIRELESS-MIB.txt | 3898 ------------- usr.sbin/bsnmpd/modules/snmp_wlan/Makefile | 17 - usr.sbin/bsnmpd/modules/snmp_wlan/snmp_wlan.3 | 160 - usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c | 4513 --------------- usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.h | 286 - usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c | 3145 ---------- usr.sbin/bsnmpd/modules/snmp_wlan/wlan_tree.def | 675 --- usr.sbin/btxld/Makefile | 7 - usr.sbin/btxld/btx.h | 68 - usr.sbin/btxld/btxld.8 | 98 - usr.sbin/btxld/btxld.c | 575 -- usr.sbin/btxld/elfh.c | 125 - usr.sbin/btxld/elfh.h | 38 - usr.sbin/burncd/Makefile | 6 - usr.sbin/burncd/burncd.8 | 222 - usr.sbin/burncd/burncd.c | 741 --- usr.sbin/cdcontrol/Makefile | 8 - usr.sbin/cdcontrol/cdcontrol.1 | 222 - usr.sbin/cdcontrol/cdcontrol.c | 1289 ----- usr.sbin/chkgrp/Makefile | 6 - usr.sbin/chkgrp/chkgrp.8 | 86 - usr.sbin/chkgrp/chkgrp.c | 169 - usr.sbin/chown/Makefile | 8 - usr.sbin/chown/chgrp.1 | 145 - usr.sbin/chown/chown.8 | 170 - usr.sbin/chown/chown.c | 315 - usr.sbin/chroot/Makefile | 7 - usr.sbin/chroot/chroot.8 | 94 - usr.sbin/chroot/chroot.c | 185 - usr.sbin/ckdist/Makefile | 11 - usr.sbin/ckdist/ckdist.1 | 132 - usr.sbin/ckdist/ckdist.c | 445 -- usr.sbin/clear_locks/Makefile | 8 - usr.sbin/clear_locks/clear_locks.8 | 51 - usr.sbin/clear_locks/clear_locks.c | 70 - usr.sbin/config/Makefile | 21 - usr.sbin/config/SMM.doc/0.t | 88 - usr.sbin/config/SMM.doc/1.t | 61 - usr.sbin/config/SMM.doc/2.t | 188 - usr.sbin/config/SMM.doc/3.t | 299 - usr.sbin/config/SMM.doc/4.t | 442 -- usr.sbin/config/SMM.doc/5.t | 271 - usr.sbin/config/SMM.doc/6.t | 239 - usr.sbin/config/SMM.doc/a.t | 162 - usr.sbin/config/SMM.doc/b.t | 137 - usr.sbin/config/SMM.doc/c.t | 109 - usr.sbin/config/SMM.doc/d.t | 272 - usr.sbin/config/SMM.doc/e.t | 114 - usr.sbin/config/SMM.doc/spell.ok | 306 - usr.sbin/config/config.5 | 407 -- usr.sbin/config/config.8 | 263 - usr.sbin/config/config.h | 204 - usr.sbin/config/config.y | 463 -- usr.sbin/config/configvers.h | 53 - usr.sbin/config/kernconf.tmpl | 17 - usr.sbin/config/lang.l | 309 - usr.sbin/config/main.c | 778 --- usr.sbin/config/mkheaders.c | 66 - usr.sbin/config/mkmakefile.c | 788 --- usr.sbin/config/mkoptions.c | 435 -- usr.sbin/cpucontrol/Makefile | 7 - usr.sbin/cpucontrol/amd.c | 181 - usr.sbin/cpucontrol/amd.h | 49 - usr.sbin/cpucontrol/cpucontrol.8 | 173 - usr.sbin/cpucontrol/cpucontrol.c | 423 -- usr.sbin/cpucontrol/cpucontrol.h | 56 - usr.sbin/cpucontrol/intel.c | 284 - usr.sbin/cpucontrol/intel.h | 70 - usr.sbin/crashinfo/Makefile | 6 - usr.sbin/crashinfo/crashinfo.8 | 109 - usr.sbin/crashinfo/crashinfo.sh | 315 - usr.sbin/cron/Makefile | 5 - usr.sbin/cron/Makefile.inc | 5 - usr.sbin/cron/cron/Makefile | 14 - usr.sbin/cron/cron/compat.h | 140 - usr.sbin/cron/cron/config.h | 87 - usr.sbin/cron/cron/cron.8 | 221 - usr.sbin/cron/cron/cron.c | 482 -- usr.sbin/cron/cron/cron.h | 301 - usr.sbin/cron/cron/database.c | 263 - usr.sbin/cron/cron/do_command.c | 617 -- usr.sbin/cron/cron/externs.h | 147 - usr.sbin/cron/cron/job.c | 76 - usr.sbin/cron/cron/pathnames.h | 81 - usr.sbin/cron/cron/popen.c | 247 - usr.sbin/cron/cron/user.c | 128 - usr.sbin/cron/crontab/Makefile | 18 - usr.sbin/cron/crontab/crontab.1 | 145 - usr.sbin/cron/crontab/crontab.5 | 310 - usr.sbin/cron/crontab/crontab.c | 626 -- usr.sbin/cron/doc/CHANGES | 155 - usr.sbin/cron/doc/CONVERSION | 85 - usr.sbin/cron/doc/FEATURES | 84 - usr.sbin/cron/doc/INSTALL | 87 - usr.sbin/cron/doc/MAIL | 475 -- usr.sbin/cron/doc/Makefile.vixie | 128 - usr.sbin/cron/doc/README | 72 - usr.sbin/cron/doc/README.1ST | 4 - usr.sbin/cron/doc/THANKS | 29 - usr.sbin/cron/lib/Makefile | 12 - usr.sbin/cron/lib/compat.c | 237 - usr.sbin/cron/lib/entry.c | 644 --- usr.sbin/cron/lib/env.c | 269 - usr.sbin/cron/lib/misc.c | 598 -- usr.sbin/crunch/COPYRIGHT | 25 - usr.sbin/crunch/Makefile | 5 - usr.sbin/crunch/Makefile.inc | 6 - usr.sbin/crunch/README | 88 - usr.sbin/crunch/crunchgen/Makefile | 10 - usr.sbin/crunch/crunchgen/crunched_main.c | 125 - usr.sbin/crunch/crunchgen/crunchgen.1 | 475 -- usr.sbin/crunch/crunchgen/crunchgen.c | 1196 ---- usr.sbin/crunch/crunchgen/mkskel.sh | 15 - usr.sbin/crunch/crunchide/Makefile | 23 - usr.sbin/crunch/crunchide/crunchide.1 | 92 - usr.sbin/crunch/crunchide/crunchide.c | 268 - usr.sbin/crunch/crunchide/exec_aout.c | 198 - usr.sbin/crunch/crunchide/exec_elf32.c | 396 -- usr.sbin/crunch/crunchide/exec_elf64.c | 40 - usr.sbin/crunch/crunchide/extern.h | 51 - usr.sbin/crunch/examples/Makefile | 33 - usr.sbin/crunch/examples/filesystem.conf | 31 - usr.sbin/crunch/examples/fixit.conf | 45 - usr.sbin/crunch/examples/kcopy.conf | 21 - usr.sbin/crunch/examples/really-big.conf | 158 - usr.sbin/ctm/Makefile | 5 - usr.sbin/ctm/Makefile.inc | 5 - usr.sbin/ctm/README | 85 - usr.sbin/ctm/ctm/Makefile | 25 - usr.sbin/ctm/ctm/ctm.1 | 325 -- usr.sbin/ctm/ctm/ctm.5 | 183 - usr.sbin/ctm/ctm/ctm.c | 331 -- usr.sbin/ctm/ctm/ctm.h | 163 - usr.sbin/ctm/ctm/ctm_ed.c | 114 - usr.sbin/ctm/ctm/ctm_input.c | 134 - usr.sbin/ctm/ctm/ctm_pass1.c | 250 - usr.sbin/ctm/ctm/ctm_pass2.c | 301 - usr.sbin/ctm/ctm/ctm_pass3.c | 295 - usr.sbin/ctm/ctm/ctm_passb.c | 142 - usr.sbin/ctm/ctm/ctm_syntax.c | 67 - usr.sbin/ctm/ctm_dequeue/Makefile | 13 - usr.sbin/ctm/ctm_dequeue/ctm_dequeue.c | 209 - usr.sbin/ctm/ctm_rmail/Makefile | 10 - usr.sbin/ctm/ctm_rmail/ctm_rmail.1 | 510 -- usr.sbin/ctm/ctm_rmail/ctm_rmail.c | 672 --- usr.sbin/ctm/ctm_rmail/error.c | 102 - usr.sbin/ctm/ctm_rmail/error.h | 5 - usr.sbin/ctm/ctm_rmail/options.h | 139 - usr.sbin/ctm/ctm_smail/Makefile | 13 - usr.sbin/ctm/ctm_smail/ctm_smail.c | 497 -- usr.sbin/ctm/mkCTM/Makefile | 26 - usr.sbin/ctm/mkCTM/ctm_conf.cvs-cur | 9 - usr.sbin/ctm/mkCTM/ctm_conf.gnats | 8 - usr.sbin/ctm/mkCTM/ctm_conf.ports-cur | 7 - usr.sbin/ctm/mkCTM/ctm_conf.smp-cur | 7 - usr.sbin/ctm/mkCTM/ctm_conf.src-cur | 9 - usr.sbin/ctm/mkCTM/ctm_conf.src-special | 9 - usr.sbin/ctm/mkCTM/dequeue | 6 - usr.sbin/ctm/mkCTM/mkCTM | 188 - usr.sbin/ctm/mkCTM/mkctm.c | 597 -- usr.sbin/cxgbtool/Makefile | 11 - usr.sbin/cxgbtool/cxgbtool.c | 1768 ------ usr.sbin/cxgbtool/reg_defs.c | 837 --- usr.sbin/cxgbtool/reg_defs_t3.c | 2676 --------- usr.sbin/cxgbtool/reg_defs_t3b.c | 2832 --------- usr.sbin/cxgbtool/reg_defs_t3c.c | 3119 ---------- usr.sbin/cxgbtool/version.h | 32 - usr.sbin/daemon/Makefile | 9 - usr.sbin/daemon/daemon.8 | 96 - usr.sbin/daemon/daemon.c | 141 - usr.sbin/dconschat/Makefile | 13 - usr.sbin/dconschat/dconschat.8 | 329 -- usr.sbin/dconschat/dconschat.c | 1154 ---- usr.sbin/devinfo/Makefile | 9 - usr.sbin/devinfo/devinfo.8 | 76 - usr.sbin/devinfo/devinfo.c | 233 - usr.sbin/digictl/Makefile | 6 - usr.sbin/digictl/digictl.8 | 118 - usr.sbin/digictl/digictl.c | 171 - usr.sbin/diskinfo/Makefile | 14 - usr.sbin/diskinfo/diskinfo.8 | 74 - usr.sbin/diskinfo/diskinfo.c | 364 -- usr.sbin/dnssec-dsfromkey/Makefile | 24 - usr.sbin/dnssec-keyfromlabel/Makefile | 24 - usr.sbin/dnssec-keygen/Makefile | 24 - usr.sbin/dnssec-signzone/Makefile | 24 - usr.sbin/dumpcis/Makefile | 9 - usr.sbin/dumpcis/cardinfo.h | 205 - usr.sbin/dumpcis/cis.h | 279 - usr.sbin/dumpcis/dumpcis.8 | 49 - usr.sbin/dumpcis/main.c | 58 - usr.sbin/dumpcis/printcis.c | 1105 ---- usr.sbin/dumpcis/readcis.c | 377 -- usr.sbin/dumpcis/readcis.h | 61 - usr.sbin/editmap/Makefile | 39 - usr.sbin/edquota/Makefile | 13 - usr.sbin/edquota/edquota.8 | 264 - usr.sbin/edquota/edquota.c | 959 --- usr.sbin/edquota/pathnames.h | 36 - usr.sbin/eeprom/Makefile | 11 - usr.sbin/eeprom/eeprom.8 | 700 --- usr.sbin/eeprom/eeprom.c | 146 - usr.sbin/eeprom/ofw_options.c | 310 - usr.sbin/eeprom/ofw_options.h | 34 - usr.sbin/extattr/Makefile | 14 - usr.sbin/extattr/rmextattr.8 | 135 - usr.sbin/extattr/rmextattr.c | 289 - usr.sbin/extattrctl/Makefile | 6 - usr.sbin/extattrctl/extattrctl.8 | 181 - usr.sbin/extattrctl/extattrctl.c | 259 - usr.sbin/faithd/Makefile | 25 - usr.sbin/faithd/README | 148 - usr.sbin/faithd/faithd.8 | 404 -- usr.sbin/faithd/faithd.c | 908 --- usr.sbin/faithd/faithd.h | 70 - usr.sbin/faithd/ftp.c | 1085 ---- usr.sbin/faithd/prefix.c | 349 -- usr.sbin/faithd/prefix.h | 52 - usr.sbin/faithd/tcp.c | 324 -- usr.sbin/faithd/test/faithd.rb | 312 - usr.sbin/fdcontrol/Makefile | 14 - usr.sbin/fdcontrol/fdcontrol.8 | 334 -- usr.sbin/fdcontrol/fdcontrol.c | 209 - usr.sbin/fdformat/Makefile | 14 - usr.sbin/fdformat/fdformat.1 | 180 - usr.sbin/fdformat/fdformat.c | 361 -- usr.sbin/fdread/Makefile | 10 - usr.sbin/fdread/fdread.1 | 233 - usr.sbin/fdread/fdread.c | 330 -- usr.sbin/fdread/fdutil.c | 523 -- usr.sbin/fdread/fdutil.h | 37 - usr.sbin/fdwrite/Makefile | 12 - usr.sbin/fdwrite/fdwrite.1 | 129 - usr.sbin/fdwrite/fdwrite.c | 196 - usr.sbin/fifolog/Makefile | 5 - usr.sbin/fifolog/Makefile.inc | 8 - usr.sbin/fifolog/fifolog_create/Makefile | 22 - usr.sbin/fifolog/fifolog_create/fifolog.1 | 218 - usr.sbin/fifolog/fifolog_create/fifolog_create.c | 115 - usr.sbin/fifolog/fifolog_reader/Makefile | 20 - usr.sbin/fifolog/fifolog_reader/fifolog_reader.c | 171 - usr.sbin/fifolog/fifolog_writer/Makefile | 16 - usr.sbin/fifolog/fifolog_writer/fifolog_writer.c | 114 - usr.sbin/fifolog/flint.lnt | 49 - usr.sbin/fifolog/lib/Makefile | 11 - usr.sbin/fifolog/lib/fifolog.h | 138 - usr.sbin/fifolog/lib/fifolog_create.c | 122 - usr.sbin/fifolog/lib/fifolog_int.c | 275 - usr.sbin/fifolog/lib/fifolog_reader.c | 322 -- usr.sbin/fifolog/lib/fifolog_write.h | 65 - usr.sbin/fifolog/lib/fifolog_write_poll.c | 417 -- usr.sbin/fifolog/lib/getdate.y | 889 --- usr.sbin/fifolog/lib/libfifolog.h | 62 - usr.sbin/fifolog/lib/libfifolog_int.h | 45 - usr.sbin/fifolog/lib/miniobj.h | 66 - usr.sbin/flowctl/Makefile | 12 - usr.sbin/flowctl/flowctl.8 | 83 - usr.sbin/flowctl/flowctl.c | 281 - usr.sbin/freebsd-update/Makefile | 6 - usr.sbin/freebsd-update/freebsd-update.8 | 177 - usr.sbin/freebsd-update/freebsd-update.sh | 3211 ---------- usr.sbin/ftp-proxy/Makefile | 5 - usr.sbin/ftp-proxy/Makefile.inc | 5 - usr.sbin/ftp-proxy/ftp-proxy/Makefile | 18 - usr.sbin/ftp-proxy/libevent/Makefile | 27 - usr.sbin/fwcontrol/Makefile | 13 - usr.sbin/fwcontrol/fwcontrol.8 | 220 - usr.sbin/fwcontrol/fwcontrol.c | 1089 ---- usr.sbin/fwcontrol/fwdv.c | 418 -- usr.sbin/fwcontrol/fwmethods.h | 10 - usr.sbin/fwcontrol/fwmpegts.c | 274 - usr.sbin/getfmac/Makefile | 6 - usr.sbin/getfmac/getfmac.8 | 57 - usr.sbin/getfmac/getfmac.c | 116 - usr.sbin/getpmac/Makefile | 6 - usr.sbin/getpmac/getpmac.8 | 59 - usr.sbin/getpmac/getpmac.c | 127 - usr.sbin/gpioctl/Makefile | 6 - usr.sbin/gpioctl/gpioctl.8 | 123 - usr.sbin/gpioctl/gpioctl.c | 323 -- usr.sbin/gssd/Makefile | 29 - usr.sbin/gssd/gssd.8 | 68 - usr.sbin/gssd/gssd.c | 610 -- usr.sbin/gstat/Makefile | 8 - usr.sbin/gstat/gstat.8 | 96 - usr.sbin/gstat/gstat.c | 431 -- usr.sbin/i2c/Makefile | 8 - usr.sbin/i2c/i2c.8 | 166 - usr.sbin/i2c/i2c.c | 633 -- usr.sbin/ifmcstat/Makefile | 24 - usr.sbin/ifmcstat/ifmcstat.8 | 131 - usr.sbin/ifmcstat/ifmcstat.c | 1241 ---- usr.sbin/ifmcstat/printb.c | 64 - usr.sbin/inetd/Makefile | 29 - usr.sbin/inetd/builtins.c | 820 --- usr.sbin/inetd/inetd.8 | 955 --- usr.sbin/inetd/inetd.c | 2584 --------- usr.sbin/inetd/inetd.h | 145 - usr.sbin/inetd/pathnames.h | 36 - usr.sbin/iostat/Makefile | 12 - usr.sbin/iostat/iostat.8 | 479 -- usr.sbin/iostat/iostat.c | 956 --- usr.sbin/ip6addrctl/Makefile | 8 - usr.sbin/ip6addrctl/ip6addrctl.8 | 126 - usr.sbin/ip6addrctl/ip6addrctl.c | 467 -- usr.sbin/ip6addrctl/ip6addrctl.conf.sample | 12 - usr.sbin/ipfwpcap/Makefile | 19 - usr.sbin/ipfwpcap/ipfwpcap.8 | 132 - usr.sbin/ipfwpcap/ipfwpcap.c | 303 - usr.sbin/jexec/Makefile | 8 - usr.sbin/jexec/jexec.8 | 76 - usr.sbin/jexec/jexec.c | 140 - usr.sbin/jls/Makefile | 8 - usr.sbin/jls/jls.8 | 111 - usr.sbin/jls/jls.c | 462 -- usr.sbin/kbdcontrol/Makefile | 14 - usr.sbin/kbdcontrol/kbdcontrol.1 | 276 - usr.sbin/kbdcontrol/kbdcontrol.c | 1212 ---- usr.sbin/kbdcontrol/kbdmap.5 | 326 -- usr.sbin/kbdcontrol/lex.h | 72 - usr.sbin/kbdcontrol/lex.l | 149 - usr.sbin/kbdcontrol/path.h | 4 - usr.sbin/kbdmap/Languages.phrases | 37 - usr.sbin/kbdmap/Makefile | 7 - usr.sbin/kbdmap/TODO | 6 - usr.sbin/kbdmap/kbdmap.1 | 153 - usr.sbin/kbdmap/kbdmap.c | 842 --- usr.sbin/kbdmap/kbdmap.h | 34 - usr.sbin/kernbb/Makefile | 12 - usr.sbin/kernbb/kernbb.8 | 82 - usr.sbin/kernbb/kernbb.c | 145 - usr.sbin/keyserv/Makefile | 26 - usr.sbin/keyserv/crypt_server.c | 276 - usr.sbin/keyserv/keyserv.8 | 80 - usr.sbin/keyserv/keyserv.c | 821 --- usr.sbin/keyserv/keyserv.h | 17 - usr.sbin/keyserv/setkey.c | 550 -- usr.sbin/kgmon/Makefile | 17 - usr.sbin/kgmon/kgmon.8 | 129 - usr.sbin/kgmon/kgmon.c | 534 -- usr.sbin/kgzip/Makefile | 9 - usr.sbin/kgzip/aouthdr.c | 79 - usr.sbin/kgzip/aouthdr.h | 59 - usr.sbin/kgzip/elfhdr.c | 164 - usr.sbin/kgzip/elfhdr.h | 84 - usr.sbin/kgzip/kgz.h | 57 - usr.sbin/kgzip/kgzcmp.c | 237 - usr.sbin/kgzip/kgzip.8 | 143 - usr.sbin/kgzip/kgzip.c | 176 - usr.sbin/kgzip/kgzip.h | 51 - usr.sbin/kgzip/kgzld.c | 101 - usr.sbin/kgzip/xio.c | 121 - usr.sbin/kldxref/Makefile | 16 - usr.sbin/kldxref/ef.c | 648 --- usr.sbin/kldxref/ef.h | 69 - usr.sbin/kldxref/ef_amd64.c | 117 - usr.sbin/kldxref/ef_i386.c | 97 - usr.sbin/kldxref/ef_nop.c | 40 - usr.sbin/kldxref/ef_obj.c | 608 -- usr.sbin/kldxref/ef_powerpc.c | 74 - usr.sbin/kldxref/ef_sparc64.c | 69 - usr.sbin/kldxref/fileformat | 45 - usr.sbin/kldxref/kldxref.8 | 95 - usr.sbin/kldxref/kldxref.c | 360 -- usr.sbin/lastlogin/Makefile | 6 - usr.sbin/lastlogin/lastlogin.8 | 80 - usr.sbin/lastlogin/lastlogin.c | 124 - usr.sbin/lmcconfig/Makefile | 11 - usr.sbin/lmcconfig/lmcconfig.8 | 723 --- usr.sbin/lmcconfig/lmcconfig.c | 2485 -------- usr.sbin/lpr/Makefile | 9 - usr.sbin/lpr/Makefile.inc | 11 - usr.sbin/lpr/SMM.doc/0.t | 68 - usr.sbin/lpr/SMM.doc/1.t | 77 - usr.sbin/lpr/SMM.doc/2.t | 141 - usr.sbin/lpr/SMM.doc/3.t | 73 - usr.sbin/lpr/SMM.doc/4.t | 206 - usr.sbin/lpr/SMM.doc/5.t | 116 - usr.sbin/lpr/SMM.doc/6.t | 94 - usr.sbin/lpr/SMM.doc/7.t | 226 - usr.sbin/lpr/SMM.doc/Makefile | 12 - usr.sbin/lpr/SMM.doc/spell.ok | 70 - usr.sbin/lpr/chkprintcap/Makefile | 14 - usr.sbin/lpr/chkprintcap/chkprintcap.8 | 99 - usr.sbin/lpr/chkprintcap/chkprintcap.c | 318 - usr.sbin/lpr/chkprintcap/skimprintcap.c | 260 - usr.sbin/lpr/chkprintcap/skimprintcap.h | 44 - usr.sbin/lpr/common_source/Makefile | 15 - usr.sbin/lpr/common_source/common.c | 771 --- usr.sbin/lpr/common_source/ctlinfo.c | 914 --- usr.sbin/lpr/common_source/ctlinfo.h | 73 - usr.sbin/lpr/common_source/displayq.c | 641 -- usr.sbin/lpr/common_source/lp.cdefs.h | 107 - usr.sbin/lpr/common_source/lp.h | 307 - usr.sbin/lpr/common_source/lp.local.h | 82 - usr.sbin/lpr/common_source/matchjobs.c | 568 -- usr.sbin/lpr/common_source/matchjobs.h | 102 - usr.sbin/lpr/common_source/net.c | 299 - usr.sbin/lpr/common_source/pathnames.h | 51 - usr.sbin/lpr/common_source/printcap.c | 451 -- usr.sbin/lpr/common_source/request.c | 81 - usr.sbin/lpr/common_source/rmjob.c | 397 -- usr.sbin/lpr/common_source/startdaemon.c | 111 - usr.sbin/lpr/filters.ru/Makefile | 8 - usr.sbin/lpr/filters.ru/Makefile.inc | 5 - usr.sbin/lpr/filters.ru/bjc-240.sh.sample | 64 - usr.sbin/lpr/filters.ru/koi2855/Makefile | 8 - usr.sbin/lpr/filters.ru/koi2855/koi2855.c | 104 - usr.sbin/lpr/filters.ru/koi2alt/Makefile | 8 - usr.sbin/lpr/filters.ru/koi2alt/koi2alt.c | 105 - usr.sbin/lpr/filters/Makefile | 11 - usr.sbin/lpr/filters/lpf.c | 221 - usr.sbin/lpr/lp/Makefile | 8 - usr.sbin/lpr/lp/lp.1 | 125 - usr.sbin/lpr/lp/lp.sh | 81 - usr.sbin/lpr/lpc/Makefile | 19 - usr.sbin/lpr/lpc/cmds.c | 1307 ----- usr.sbin/lpr/lpc/cmdtab.c | 94 - usr.sbin/lpr/lpc/extern.h | 81 - usr.sbin/lpr/lpc/lpc.8 | 313 - usr.sbin/lpr/lpc/lpc.c | 423 -- usr.sbin/lpr/lpc/lpc.h | 55 - usr.sbin/lpr/lpc/movejobs.c | 270 - usr.sbin/lpr/lpd/Makefile | 15 - usr.sbin/lpr/lpd/extern.h | 50 - usr.sbin/lpr/lpd/lpd.8 | 345 -- usr.sbin/lpr/lpd/lpd.c | 946 --- usr.sbin/lpr/lpd/lpdchar.c | 1072 ---- usr.sbin/lpr/lpd/modes.c | 235 - usr.sbin/lpr/lpd/printjob.c | 2021 ------- usr.sbin/lpr/lpd/recvjob.c | 409 -- usr.sbin/lpr/lpq/Makefile | 16 - usr.sbin/lpr/lpq/lpq.1 | 142 - usr.sbin/lpr/lpq/lpq.c | 199 - usr.sbin/lpr/lpr/Makefile | 21 - usr.sbin/lpr/lpr/lpr.1 | 325 -- usr.sbin/lpr/lpr/lpr.c | 891 --- usr.sbin/lpr/lpr/printcap.5 | 437 -- usr.sbin/lpr/lprm/Makefile | 18 - usr.sbin/lpr/lprm/lprm.1 | 151 - usr.sbin/lpr/lprm/lprm.c | 165 - usr.sbin/lpr/lptest/Makefile | 8 - usr.sbin/lpr/lptest/lptest.1 | 77 - usr.sbin/lpr/lptest/lptest.c | 89 - usr.sbin/lpr/pac/Makefile | 14 - usr.sbin/lpr/pac/pac.8 | 109 - usr.sbin/lpr/pac/pac.c | 454 -- usr.sbin/lptcontrol/Makefile | 6 - usr.sbin/lptcontrol/lptcontrol.8 | 90 - usr.sbin/lptcontrol/lptcontrol.c | 106 - usr.sbin/mailstats/Makefile | 37 - usr.sbin/mailwrapper/Makefile | 37 - usr.sbin/mailwrapper/mailwrapper.8 | 163 - usr.sbin/mailwrapper/mailwrapper.c | 162 - usr.sbin/mailwrapper/pathnames.h | 35 - usr.sbin/makefs/Makefile | 28 - usr.sbin/makefs/compat/pwcache.c | 616 -- usr.sbin/makefs/compat/pwcache.h | 73 - usr.sbin/makefs/compat/strsuftoll.c | 222 - usr.sbin/makefs/ffs.c | 1093 ---- usr.sbin/makefs/ffs/buf.c | 222 - usr.sbin/makefs/ffs/buf.h | 67 - usr.sbin/makefs/ffs/ffs_alloc.c | 683 --- usr.sbin/makefs/ffs/ffs_balloc.c | 578 -- usr.sbin/makefs/ffs/ffs_bswap.c | 268 - usr.sbin/makefs/ffs/ffs_extern.h | 77 - usr.sbin/makefs/ffs/ffs_subr.c | 202 - usr.sbin/makefs/ffs/mkfs.c | 832 --- usr.sbin/makefs/ffs/newfs_extern.h | 41 - usr.sbin/makefs/ffs/ufs_bmap.c | 142 - usr.sbin/makefs/ffs/ufs_bswap.h | 88 - usr.sbin/makefs/ffs/ufs_inode.h | 97 - usr.sbin/makefs/getid.c | 429 -- usr.sbin/makefs/makefs.8 | 288 - usr.sbin/makefs/makefs.c | 314 - usr.sbin/makefs/makefs.h | 305 - usr.sbin/makefs/walk.c | 568 -- usr.sbin/makemap/Makefile | 40 - usr.sbin/manctl/Makefile | 6 - usr.sbin/manctl/manctl.8 | 58 - usr.sbin/manctl/manctl.sh | 380 -- usr.sbin/memcontrol/Makefile | 6 - usr.sbin/memcontrol/memcontrol.8 | 111 - usr.sbin/memcontrol/memcontrol.c | 344 -- usr.sbin/mergemaster/Makefile | 7 - usr.sbin/mergemaster/mergemaster.8 | 472 -- usr.sbin/mergemaster/mergemaster.sh | 1370 ----- usr.sbin/mfiutil/Makefile | 19 - usr.sbin/mfiutil/mfi_cmd.c | 351 -- usr.sbin/mfiutil/mfi_config.c | 1164 ---- usr.sbin/mfiutil/mfi_drive.c | 625 -- usr.sbin/mfiutil/mfi_evt.c | 667 --- usr.sbin/mfiutil/mfi_flash.c | 199 - usr.sbin/mfiutil/mfi_patrol.c | 305 - usr.sbin/mfiutil/mfi_show.c | 560 -- usr.sbin/mfiutil/mfi_volume.c | 412 -- usr.sbin/mfiutil/mfiutil.8 | 566 -- usr.sbin/mfiutil/mfiutil.c | 136 - usr.sbin/mfiutil/mfiutil.h | 147 - usr.sbin/mixer/Makefile | 6 - usr.sbin/mixer/mixer.8 | 180 - usr.sbin/mixer/mixer.c | 331 -- usr.sbin/mld6query/Makefile | 25 - usr.sbin/mld6query/mld6.c | 351 -- usr.sbin/mld6query/mld6query.8 | 91 - usr.sbin/mlxcontrol/Makefile | 11 - usr.sbin/mlxcontrol/command.c | 712 --- usr.sbin/mlxcontrol/config.c | 157 - usr.sbin/mlxcontrol/interface.c | 289 - usr.sbin/mlxcontrol/mlxcontrol.8 | 147 - usr.sbin/mlxcontrol/mlxcontrol.h | 89 - usr.sbin/mlxcontrol/util.c | 172 - usr.sbin/mount_nwfs/Makefile | 15 - usr.sbin/mount_nwfs/mount_nwfs.8 | 230 - usr.sbin/mount_nwfs/mount_nwfs.c | 369 -- usr.sbin/mount_portalfs/Makefile | 15 - usr.sbin/mount_portalfs/activate.c | 195 - usr.sbin/mount_portalfs/conf.c | 318 - usr.sbin/mount_portalfs/cred.c | 75 - usr.sbin/mount_portalfs/mount_portalfs.8 | 216 - usr.sbin/mount_portalfs/mount_portalfs.c | 280 - usr.sbin/mount_portalfs/pathnames.h | 40 - usr.sbin/mount_portalfs/portal.conf | 7 - usr.sbin/mount_portalfs/portald.h | 86 - usr.sbin/mount_portalfs/pt_conf.c | 50 - usr.sbin/mount_portalfs/pt_exec.c | 50 - usr.sbin/mount_portalfs/pt_file.c | 91 - usr.sbin/mount_portalfs/pt_pipe.c | 229 - usr.sbin/mount_portalfs/pt_tcp.c | 157 - usr.sbin/mount_portalfs/pt_tcplisten.c | 201 - usr.sbin/mount_smbfs/Makefile | 22 - usr.sbin/mountd/Makefile | 17 - usr.sbin/mountd/exports.5 | 489 -- usr.sbin/mountd/mountd.8 | 195 - usr.sbin/mountd/mountd.c | 3055 ---------- usr.sbin/mountd/netgroup.5 | 190 - usr.sbin/mountd/pathnames.h | 36 - usr.sbin/moused/Makefile | 12 - usr.sbin/moused/moused.8 | 854 --- usr.sbin/moused/moused.c | 3440 ----------- usr.sbin/mptable/Makefile | 5 - usr.sbin/mptable/mptable.1 | 69 - usr.sbin/mptable/mptable.c | 1110 ---- usr.sbin/mptutil/Makefile | 19 - usr.sbin/mptutil/mpt_cam.c | 565 -- usr.sbin/mptutil/mpt_cmd.c | 639 -- usr.sbin/mptutil/mpt_config.c | 1160 ---- usr.sbin/mptutil/mpt_drive.c | 395 -- usr.sbin/mptutil/mpt_evt.c | 155 - usr.sbin/mptutil/mpt_show.c | 565 -- usr.sbin/mptutil/mpt_volume.c | 248 - usr.sbin/mptutil/mptutil.8 | 398 -- usr.sbin/mptutil/mptutil.c | 125 - usr.sbin/mptutil/mptutil.h | 178 - usr.sbin/mtest/Makefile | 18 - usr.sbin/mtest/mtest.8 | 175 - usr.sbin/mtest/mtest.c | 831 --- usr.sbin/mtree/Makefile | 15 - usr.sbin/mtree/compare.c | 388 -- usr.sbin/mtree/create.c | 428 -- usr.sbin/mtree/excludes.c | 111 - usr.sbin/mtree/extern.h | 59 - usr.sbin/mtree/misc.c | 124 - usr.sbin/mtree/mtree.5 | 272 - usr.sbin/mtree/mtree.8 | 401 -- usr.sbin/mtree/mtree.c | 190 - usr.sbin/mtree/mtree.h | 98 - usr.sbin/mtree/spec.c | 323 -- usr.sbin/mtree/specspec.c | 256 - usr.sbin/mtree/test/test00.sh | 67 - usr.sbin/mtree/test/test01.sh | 40 - usr.sbin/mtree/test/test02.sh | 36 - usr.sbin/mtree/test/test03.sh | 60 - usr.sbin/mtree/test/test04.sh | 51 - usr.sbin/mtree/test/test05.sh | 25 - usr.sbin/mtree/verify.c | 259 - usr.sbin/named-checkconf/Makefile | 26 - usr.sbin/named-checkzone/Makefile | 28 - usr.sbin/named.reload/Makefile | 9 - usr.sbin/named.reload/named.reload.8 | 68 - usr.sbin/named.reload/named.reload.sh | 42 - usr.sbin/named/Makefile | 65 - usr.sbin/ndiscvt/Makefile | 30 - usr.sbin/ndiscvt/inf-parse.y | 111 - usr.sbin/ndiscvt/inf-token.l | 129 - usr.sbin/ndiscvt/inf.c | 910 --- usr.sbin/ndiscvt/inf.h | 61 - usr.sbin/ndiscvt/ndiscvt.8 | 283 - usr.sbin/ndiscvt/ndiscvt.c | 430 -- usr.sbin/ndiscvt/ndisgen.8 | 86 - usr.sbin/ndiscvt/ndisgen.sh | 559 -- usr.sbin/ndiscvt/windrv_stub.c | 266 - usr.sbin/ndp/Makefile | 27 - usr.sbin/ndp/ndp.8 | 266 - usr.sbin/ndp/ndp.c | 1639 ------ usr.sbin/newsyslog/Makefile | 7 - usr.sbin/newsyslog/extern.h | 68 - usr.sbin/newsyslog/newsyslog.8 | 299 - usr.sbin/newsyslog/newsyslog.c | 2462 -------- usr.sbin/newsyslog/newsyslog.conf.5 | 355 -- usr.sbin/newsyslog/pathnames.h | 28 - usr.sbin/newsyslog/ptimes.c | 618 -- usr.sbin/nfscbd/Makefile | 6 - usr.sbin/nfscbd/nfscbd.8 | 88 - usr.sbin/nfscbd/nfscbd.c | 373 -- usr.sbin/nfsd/Makefile | 7 - usr.sbin/nfsd/nfsd.8 | 220 - usr.sbin/nfsd/nfsd.c | 972 ---- usr.sbin/nfsd/nfsv4.4 | 331 -- usr.sbin/nfsd/stablerestart.5 | 93 - usr.sbin/nfsdumpstate/Makefile | 6 - usr.sbin/nfsdumpstate/nfsdumpstate.8 | 74 - usr.sbin/nfsdumpstate/nfsdumpstate.c | 280 - usr.sbin/nfsrevoke/Makefile | 6 - usr.sbin/nfsrevoke/nfsrevoke.8 | 64 - usr.sbin/nfsrevoke/nfsrevoke.c | 123 - usr.sbin/nfsuserd/Makefile | 7 - usr.sbin/nfsuserd/nfsuserd.8 | 114 - usr.sbin/nfsuserd/nfsuserd.c | 662 --- usr.sbin/ngctl/Makefile | 29 - usr.sbin/ngctl/config.c | 111 - usr.sbin/ngctl/connect.c | 90 - usr.sbin/ngctl/debug.c | 84 - usr.sbin/ngctl/dot.c | 200 - usr.sbin/ngctl/list.c | 146 - usr.sbin/ngctl/main.c | 661 --- usr.sbin/ngctl/mkpeer.c | 90 - usr.sbin/ngctl/msg.c | 163 - usr.sbin/ngctl/name.c | 81 - usr.sbin/ngctl/ngctl.8 | 141 - usr.sbin/ngctl/ngctl.h | 82 - usr.sbin/ngctl/rmhook.c | 86 - usr.sbin/ngctl/show.c | 139 - usr.sbin/ngctl/shutdown.c | 79 - usr.sbin/ngctl/status.c | 101 - usr.sbin/ngctl/types.c | 101 - usr.sbin/ngctl/write.c | 121 - usr.sbin/nghook/Makefile | 11 - usr.sbin/nghook/main.c | 309 - usr.sbin/nghook/nghook.8 | 145 - usr.sbin/nologin/Makefile | 16 - usr.sbin/nologin/nologin.5 | 96 - usr.sbin/nologin/nologin.8 | 57 - usr.sbin/nologin/nologin.c | 51 - usr.sbin/nscd/Makefile | 16 - usr.sbin/nscd/agent.c | 127 - usr.sbin/nscd/agent.h | 71 - usr.sbin/nscd/agents/Makefile.inc | 3 - usr.sbin/nscd/agents/group.c | 260 - usr.sbin/nscd/agents/group.h | 32 - usr.sbin/nscd/agents/passwd.c | 268 - usr.sbin/nscd/agents/passwd.h | 32 - usr.sbin/nscd/agents/services.c | 281 - usr.sbin/nscd/agents/services.h | 32 - usr.sbin/nscd/cachelib.c | 1218 ---- usr.sbin/nscd/cachelib.h | 261 - usr.sbin/nscd/cacheplcs.c | 590 -- usr.sbin/nscd/cacheplcs.h | 129 - usr.sbin/nscd/config.c | 586 -- usr.sbin/nscd/config.h | 148 - usr.sbin/nscd/debug.c | 150 - usr.sbin/nscd/debug.h | 67 - usr.sbin/nscd/hashtable.h | 221 - usr.sbin/nscd/log.c | 79 - usr.sbin/nscd/log.h | 43 - usr.sbin/nscd/mp_rs_query.c | 537 -- usr.sbin/nscd/mp_rs_query.h | 34 - usr.sbin/nscd/mp_ws_query.c | 546 -- usr.sbin/nscd/mp_ws_query.h | 35 - usr.sbin/nscd/nscd.8 | 165 - usr.sbin/nscd/nscd.c | 870 --- usr.sbin/nscd/nscd.conf.5 | 148 - usr.sbin/nscd/nscdcli.c | 287 - usr.sbin/nscd/nscdcli.h | 55 - usr.sbin/nscd/parser.c | 478 -- usr.sbin/nscd/parser.h | 35 - usr.sbin/nscd/protocol.c | 551 -- usr.sbin/nscd/protocol.h | 249 - usr.sbin/nscd/query.c | 1277 ---- usr.sbin/nscd/query.h | 104 - usr.sbin/nscd/singletons.c | 38 - usr.sbin/nscd/singletons.h | 47 - usr.sbin/ntp/Makefile | 8 - usr.sbin/ntp/Makefile.inc | 23 - usr.sbin/ntp/config.h | 1362 ----- usr.sbin/ntp/doc/Makefile | 33 - usr.sbin/ntp/doc/ntp-keygen.8 | 602 -- usr.sbin/ntp/doc/ntp.conf.5 | 2715 --------- usr.sbin/ntp/doc/ntp.keys.5 | 120 - usr.sbin/ntp/doc/ntpd.8 | 612 -- usr.sbin/ntp/doc/ntpdate.8 | 280 - usr.sbin/ntp/doc/ntpdc.8 | 715 --- usr.sbin/ntp/doc/ntpq.8 | 851 --- usr.sbin/ntp/doc/ntptime.8 | 69 - usr.sbin/ntp/doc/ntptrace.8 | 76 - usr.sbin/ntp/libntp/Makefile | 37 - usr.sbin/ntp/libopts/Makefile | 13 - usr.sbin/ntp/libparse/Makefile | 16 - usr.sbin/ntp/ntp-keygen/Makefile | 24 - usr.sbin/ntp/ntpd/Makefile | 48 - usr.sbin/ntp/ntpdate/Makefile | 19 - usr.sbin/ntp/ntpdc/Makefile | 33 - usr.sbin/ntp/ntpq/Makefile | 32 - usr.sbin/ntp/ntptime/Makefile | 13 - usr.sbin/ntp/scripts/mkver | 44 - usr.sbin/ntp/scripts/ntptrace | 62 - usr.sbin/ntp/scripts/ntpver | 8 - usr.sbin/ntp/sntp/Makefile | 16 - usr.sbin/nvram/Makefile | 7 - usr.sbin/nvram/nvram.8 | 118 - usr.sbin/nvram/nvram.c | 222 - usr.sbin/ofwdump/Makefile | 7 - usr.sbin/ofwdump/ofw_util.c | 230 - usr.sbin/ofwdump/ofw_util.h | 50 - usr.sbin/ofwdump/ofwdump.8 | 107 - usr.sbin/ofwdump/ofwdump.c | 240 - usr.sbin/ofwdump/pathnames.h | 30 - usr.sbin/pc-sysinstall/Makefile | 5 - usr.sbin/pc-sysinstall/Makefile.inc | 3 - .../pc-sysinstall/backend-partmanager/Makefile | 8 - .../backend-partmanager/create-part.sh | 92 - .../backend-partmanager/delete-part.sh | 89 - usr.sbin/pc-sysinstall/backend-query/Makefile | 13 - .../backend-query/detect-emulation.sh | 41 - .../pc-sysinstall/backend-query/detect-laptop.sh | 32 - .../pc-sysinstall/backend-query/detect-nics.sh | 36 - usr.sbin/pc-sysinstall/backend-query/disk-info.sh | 69 - usr.sbin/pc-sysinstall/backend-query/disk-list.sh | 103 - usr.sbin/pc-sysinstall/backend-query/disk-part.sh | 117 - usr.sbin/pc-sysinstall/backend-query/enable-net.sh | 65 - .../pc-sysinstall/backend-query/get-packages.sh | 52 - .../pc-sysinstall/backend-query/list-components.sh | 54 - .../pc-sysinstall/backend-query/list-config.sh | 30 - .../pc-sysinstall/backend-query/list-mirrors.sh | 37 - .../pc-sysinstall/backend-query/list-packages.sh | 86 - .../backend-query/list-rsync-backups.sh | 70 - .../pc-sysinstall/backend-query/list-tzones.sh | 34 - .../pc-sysinstall/backend-query/query-langs.sh | 32 - usr.sbin/pc-sysinstall/backend-query/send-logs.sh | 83 - usr.sbin/pc-sysinstall/backend-query/set-mirror.sh | 40 - .../pc-sysinstall/backend-query/setup-ssh-keys.sh | 64 - usr.sbin/pc-sysinstall/backend-query/sys-mem.sh | 28 - usr.sbin/pc-sysinstall/backend-query/test-live.sh | 40 - usr.sbin/pc-sysinstall/backend-query/test-netup.sh | 50 - .../backend-query/update-part-list.sh | 110 - .../backend-query/xkeyboard-layouts.sh | 56 - .../backend-query/xkeyboard-models.sh | 58 - .../backend-query/xkeyboard-variants.sh | 56 - usr.sbin/pc-sysinstall/backend/Makefile | 15 - .../pc-sysinstall/backend/functions-bsdlabel.sh | 811 --- .../pc-sysinstall/backend/functions-cleanup.sh | 418 -- usr.sbin/pc-sysinstall/backend/functions-disk.sh | 835 --- .../backend/functions-extractimage.sh | 441 -- usr.sbin/pc-sysinstall/backend/functions-ftp.sh | 417 -- .../backend/functions-installcomponents.sh | 167 - .../backend/functions-installpackages.sh | 125 - .../pc-sysinstall/backend/functions-localize.sh | 511 -- .../pc-sysinstall/backend/functions-mountdisk.sh | 191 - .../backend/functions-mountoptical.sh | 153 - .../pc-sysinstall/backend/functions-networking.sh | 357 -- usr.sbin/pc-sysinstall/backend/functions-newfs.sh | 217 - .../pc-sysinstall/backend/functions-packages.sh | 376 -- usr.sbin/pc-sysinstall/backend/functions-parse.sh | 232 - .../pc-sysinstall/backend/functions-runcommands.sh | 110 - .../pc-sysinstall/backend/functions-unmount.sh | 209 - .../pc-sysinstall/backend/functions-upgrade.sh | 247 - usr.sbin/pc-sysinstall/backend/functions-users.sh | 175 - usr.sbin/pc-sysinstall/backend/functions.sh | 513 -- usr.sbin/pc-sysinstall/backend/installimage.sh | 34 - usr.sbin/pc-sysinstall/backend/parseconfig.sh | 120 - usr.sbin/pc-sysinstall/backend/startautoinstall.sh | 136 - usr.sbin/pc-sysinstall/conf/Makefile | 11 - usr.sbin/pc-sysinstall/conf/avail-langs | 20 - usr.sbin/pc-sysinstall/conf/exclude-from-upgrade | 15 - usr.sbin/pc-sysinstall/conf/licenses/bsd-en.txt | 24 - usr.sbin/pc-sysinstall/conf/licenses/intel-en.txt | 207 - usr.sbin/pc-sysinstall/conf/licenses/nvidia-en.txt | 53 - usr.sbin/pc-sysinstall/conf/pc-sysinstall.conf | 86 - usr.sbin/pc-sysinstall/doc/Makefile | 8 - usr.sbin/pc-sysinstall/doc/help-disk-list | 1 - usr.sbin/pc-sysinstall/doc/help-disk-size | 1 - usr.sbin/pc-sysinstall/doc/help-index | 100 - usr.sbin/pc-sysinstall/doc/help-start-autoinstall | 39 - usr.sbin/pc-sysinstall/examples/Makefile | 11 - usr.sbin/pc-sysinstall/examples/README | 369 -- .../pc-sysinstall/examples/pc-autoinstall.conf | 52 - .../examples/pcinstall.cfg.fbsd-netinstall | 71 - usr.sbin/pc-sysinstall/examples/pcinstall.cfg.geli | 50 - .../pc-sysinstall/examples/pcinstall.cfg.gmirror | 45 - .../examples/pcinstall.cfg.netinstall | 68 - .../pc-sysinstall/examples/pcinstall.cfg.restore | 57 - .../pc-sysinstall/examples/pcinstall.cfg.rsync | 45 - .../pc-sysinstall/examples/pcinstall.cfg.upgrade | 24 - usr.sbin/pc-sysinstall/examples/pcinstall.cfg.zfs | 59 - usr.sbin/pc-sysinstall/pc-sysinstall/Makefile | 6 - .../pc-sysinstall/pc-sysinstall/pc-sysinstall.8 | 120 - .../pc-sysinstall/pc-sysinstall/pc-sysinstall.sh | 240 - usr.sbin/pciconf/Makefile | 12 - usr.sbin/pciconf/cap.c | 632 -- usr.sbin/pciconf/pathnames.h | 3 - usr.sbin/pciconf/pciconf.8 | 283 - usr.sbin/pciconf/pciconf.c | 664 --- usr.sbin/pciconf/pciconf.h | 39 - usr.sbin/periodic/Makefile | 6 - usr.sbin/periodic/periodic.8 | 258 - usr.sbin/periodic/periodic.sh | 109 - usr.sbin/pkg_install/Makefile | 20 - usr.sbin/pkg_install/Makefile.inc | 12 - usr.sbin/pkg_install/README | 8 - usr.sbin/pkg_install/add/Makefile | 11 - usr.sbin/pkg_install/add/add.h | 48 - usr.sbin/pkg_install/add/extract.c | 287 - usr.sbin/pkg_install/add/futil.c | 97 - usr.sbin/pkg_install/add/main.c | 359 -- usr.sbin/pkg_install/add/perform.c | 700 --- usr.sbin/pkg_install/add/pkg_add.1 | 603 -- usr.sbin/pkg_install/create/Makefile | 12 - usr.sbin/pkg_install/create/create.h | 58 - usr.sbin/pkg_install/create/main.c | 269 - usr.sbin/pkg_install/create/perform.c | 597 -- usr.sbin/pkg_install/create/pkg_create.1 | 666 --- usr.sbin/pkg_install/create/pl.c | 280 - usr.sbin/pkg_install/delete/Makefile | 8 - usr.sbin/pkg_install/delete/delete.h | 35 - usr.sbin/pkg_install/delete/main.c | 181 - usr.sbin/pkg_install/delete/perform.c | 425 -- usr.sbin/pkg_install/delete/pkg_delete.1 | 293 - usr.sbin/pkg_install/info/Makefile | 11 - usr.sbin/pkg_install/info/info.h | 85 - usr.sbin/pkg_install/info/main.c | 304 - usr.sbin/pkg_install/info/perform.c | 476 -- usr.sbin/pkg_install/info/pkg_info.1 | 294 - usr.sbin/pkg_install/info/show.c | 381 -- usr.sbin/pkg_install/tkpkg | 177 - usr.sbin/pkg_install/updating/Makefile | 8 - usr.sbin/pkg_install/updating/main.c | 285 - usr.sbin/pkg_install/updating/pathnames.h | 17 - usr.sbin/pkg_install/updating/pkg_updating.1 | 90 - usr.sbin/pkg_install/version/Makefile | 11 - usr.sbin/pkg_install/version/main.c | 139 - usr.sbin/pkg_install/version/perform.c | 421 -- usr.sbin/pkg_install/version/pkg_version.1 | 256 - usr.sbin/pkg_install/version/test-pkg_version.sh | 94 - usr.sbin/pkg_install/version/version.h | 43 - usr.sbin/pmcannotate/Makefile | 10 - usr.sbin/pmcannotate/pmcannotate.8 | 109 - usr.sbin/pmcannotate/pmcannotate.c | 804 --- usr.sbin/pmccontrol/Makefile | 13 - usr.sbin/pmccontrol/pmccontrol.8 | 127 - usr.sbin/pmccontrol/pmccontrol.c | 501 -- usr.sbin/pmcstat/Makefile | 14 - usr.sbin/pmcstat/pmcpl_annotate.c | 111 - usr.sbin/pmcstat/pmcpl_annotate.h | 41 - usr.sbin/pmcstat/pmcpl_callgraph.c | 687 --- usr.sbin/pmcstat/pmcpl_callgraph.h | 67 - usr.sbin/pmcstat/pmcpl_calltree.c | 1045 ---- usr.sbin/pmcstat/pmcpl_calltree.h | 42 - usr.sbin/pmcstat/pmcpl_gprof.c | 535 -- usr.sbin/pmcstat/pmcpl_gprof.h | 47 - usr.sbin/pmcstat/pmcstat.8 | 456 -- usr.sbin/pmcstat/pmcstat.c | 1449 ----- usr.sbin/pmcstat/pmcstat.h | 184 - usr.sbin/pmcstat/pmcstat_log.c | 2177 ------- usr.sbin/pmcstat/pmcstat_log.h | 199 - usr.sbin/pmcstat/pmcstat_top.h | 75 - usr.sbin/pnpinfo/Makefile | 16 - usr.sbin/portsnap/Makefile | 5 - usr.sbin/portsnap/Makefile.inc | 5 - usr.sbin/portsnap/make_index/Makefile | 8 - usr.sbin/portsnap/make_index/make_index.c | 513 -- usr.sbin/portsnap/phttpget/Makefile | 8 - usr.sbin/portsnap/phttpget/phttpget.c | 730 --- usr.sbin/portsnap/portsnap/Makefile | 6 - usr.sbin/portsnap/portsnap/portsnap.8 | 244 - usr.sbin/portsnap/portsnap/portsnap.sh | 1070 ---- usr.sbin/powerd/Makefile | 9 - usr.sbin/powerd/powerd.8 | 147 - usr.sbin/powerd/powerd.c | 792 --- usr.sbin/ppp/Makefile | 122 - usr.sbin/ppp/README.changes | 140 - usr.sbin/ppp/README.nat | 378 -- usr.sbin/ppp/acf.c | 116 - usr.sbin/ppp/acf.h | 33 - usr.sbin/ppp/arp.c | 317 - usr.sbin/ppp/arp.h | 36 - usr.sbin/ppp/async.c | 220 - usr.sbin/ppp/async.h | 53 - usr.sbin/ppp/atm.c | 237 - usr.sbin/ppp/atm.h | 35 - usr.sbin/ppp/auth.c | 479 -- usr.sbin/ppp/auth.h | 68 - usr.sbin/ppp/bundle.c | 2019 ------- usr.sbin/ppp/bundle.h | 216 - usr.sbin/ppp/cbcp.c | 763 --- usr.sbin/ppp/cbcp.h | 65 - usr.sbin/ppp/ccp.c | 826 --- usr.sbin/ppp/ccp.h | 165 - usr.sbin/ppp/chap.c | 972 ---- usr.sbin/ppp/chap.h | 75 - usr.sbin/ppp/chap_ms.c | 415 -- usr.sbin/ppp/chap_ms.h | 52 - usr.sbin/ppp/chat.c | 797 --- usr.sbin/ppp/chat.h | 82 - usr.sbin/ppp/command.c | 3312 ----------- usr.sbin/ppp/command.h | 75 - usr.sbin/ppp/datalink.c | 1478 ----- usr.sbin/ppp/datalink.h | 156 - usr.sbin/ppp/deflate.c | 601 -- usr.sbin/ppp/deflate.h | 30 - usr.sbin/ppp/defs.c | 450 -- usr.sbin/ppp/defs.h | 142 - usr.sbin/ppp/descriptor.h | 53 - usr.sbin/ppp/ether.c | 737 --- usr.sbin/ppp/ether.h | 37 - usr.sbin/ppp/exec.c | 410 -- usr.sbin/ppp/exec.h | 35 - usr.sbin/ppp/filter.c | 604 -- usr.sbin/ppp/filter.h | 101 - usr.sbin/ppp/fsm.c | 1213 ---- usr.sbin/ppp/fsm.h | 201 - usr.sbin/ppp/hdlc.c | 438 -- usr.sbin/ppp/hdlc.h | 116 - usr.sbin/ppp/i4b.h | 37 - usr.sbin/ppp/id.c | 292 - usr.sbin/ppp/id.h | 81 - usr.sbin/ppp/iface.c | 730 --- usr.sbin/ppp/iface.h | 65 - usr.sbin/ppp/ip.c | 993 ---- usr.sbin/ppp/ip.h | 44 - usr.sbin/ppp/ipcp.c | 1482 ----- usr.sbin/ppp/ipcp.h | 132 - usr.sbin/ppp/iplist.c | 225 - usr.sbin/ppp/iplist.h | 51 - usr.sbin/ppp/ipv6cp.c | 786 --- usr.sbin/ppp/ipv6cp.h | 83 - usr.sbin/ppp/layer.h | 52 - usr.sbin/ppp/lcp.c | 1305 ----- usr.sbin/ppp/lcp.h | 143 - usr.sbin/ppp/link.c | 412 -- usr.sbin/ppp/link.h | 81 - usr.sbin/ppp/log.c | 521 -- usr.sbin/ppp/log.h | 105 - usr.sbin/ppp/lqr.c | 532 -- usr.sbin/ppp/lqr.h | 82 - usr.sbin/ppp/main.c | 679 --- usr.sbin/ppp/main.h | 32 - usr.sbin/ppp/mbuf.c | 440 -- usr.sbin/ppp/mbuf.h | 119 - usr.sbin/ppp/mp.c | 1209 ---- usr.sbin/ppp/mp.h | 146 - usr.sbin/ppp/mppe.c | 817 --- usr.sbin/ppp/mppe.h | 33 - usr.sbin/ppp/nat_cmd.c | 602 -- usr.sbin/ppp/nat_cmd.h | 42 - usr.sbin/ppp/ncp.c | 547 -- usr.sbin/ppp/ncp.h | 101 - usr.sbin/ppp/ncpaddr.c | 1010 ---- usr.sbin/ppp/ncpaddr.h | 109 - usr.sbin/ppp/netgraph.c | 743 --- usr.sbin/ppp/netgraph.h | 37 - usr.sbin/ppp/pap.c | 303 - usr.sbin/ppp/pap.h | 40 - usr.sbin/ppp/physical.c | 1141 ---- usr.sbin/ppp/physical.h | 176 - usr.sbin/ppp/ppp.8.m4 | 6117 -------------------- usr.sbin/ppp/pred.c | 345 -- usr.sbin/ppp/pred.h | 31 - usr.sbin/ppp/probe.c | 78 - usr.sbin/ppp/probe.h | 38 - usr.sbin/ppp/prompt.c | 574 -- usr.sbin/ppp/prompt.h | 96 - usr.sbin/ppp/proto.c | 115 - usr.sbin/ppp/proto.h | 64 - usr.sbin/ppp/radius.c | 1361 ----- usr.sbin/ppp/radius.h | 133 - usr.sbin/ppp/route.c | 949 --- usr.sbin/ppp/route.h | 74 - usr.sbin/ppp/server.c | 422 -- usr.sbin/ppp/server.h | 61 - usr.sbin/ppp/sig.c | 119 - usr.sbin/ppp/sig.h | 35 - usr.sbin/ppp/slcompress.c | 605 -- usr.sbin/ppp/slcompress.h | 161 - usr.sbin/ppp/sync.c | 84 - usr.sbin/ppp/sync.h | 29 - usr.sbin/ppp/systems.c | 483 -- usr.sbin/ppp/systems.h | 43 - usr.sbin/ppp/tcp.c | 212 - usr.sbin/ppp/tcp.h | 34 - usr.sbin/ppp/tcpmss.c | 185 - usr.sbin/ppp/tcpmss.h | 29 - usr.sbin/ppp/throughput.c | 302 - usr.sbin/ppp/throughput.h | 70 - usr.sbin/ppp/timer.c | 302 - usr.sbin/ppp/timer.h | 55 - usr.sbin/ppp/tty.c | 770 --- usr.sbin/ppp/tty.h | 37 - usr.sbin/ppp/tun.c | 119 - usr.sbin/ppp/tun.h | 39 - usr.sbin/ppp/ua.h | 74 - usr.sbin/ppp/udp.c | 335 -- usr.sbin/ppp/udp.h | 35 - usr.sbin/ppp/vjcomp.c | 200 - usr.sbin/ppp/vjcomp.h | 36 - usr.sbin/pppctl/Makefile | 11 - usr.sbin/pppctl/pppctl.8 | 232 - usr.sbin/pppctl/pppctl.c | 680 --- usr.sbin/praliases/Makefile | 40 - usr.sbin/praudit/Makefile | 16 - usr.sbin/procctl/Makefile | 6 - usr.sbin/procctl/procctl.8 | 34 - usr.sbin/procctl/procctl.c | 79 - usr.sbin/pstat/Makefile | 12 - usr.sbin/pstat/pstat.8 | 251 - usr.sbin/pstat/pstat.c | 597 -- usr.sbin/pw/Makefile | 14 - usr.sbin/pw/README | 22 - usr.sbin/pw/bitmap.c | 132 - usr.sbin/pw/bitmap.h | 50 - usr.sbin/pw/cpdir.c | 130 - usr.sbin/pw/edgroup.c | 229 - usr.sbin/pw/fileupd.c | 203 - usr.sbin/pw/grupd.c | 171 - usr.sbin/pw/psdate.c | 295 - usr.sbin/pw/psdate.h | 40 - usr.sbin/pw/pw.8 | 997 ---- usr.sbin/pw/pw.c | 456 -- usr.sbin/pw/pw.conf.5 | 318 - usr.sbin/pw/pw.h | 132 - usr.sbin/pw/pw_conf.c | 516 -- usr.sbin/pw/pw_group.c | 423 -- usr.sbin/pw/pw_log.c | 68 - usr.sbin/pw/pw_nis.c | 72 - usr.sbin/pw/pw_user.c | 1274 ---- usr.sbin/pw/pw_vpw.c | 316 - usr.sbin/pw/pwupd.c | 213 - usr.sbin/pw/pwupd.h | 160 - usr.sbin/pw/rm_r.c | 75 - usr.sbin/pwd_mkdb/Makefile | 12 - usr.sbin/pwd_mkdb/pwd_mkdb.8 | 183 - usr.sbin/pwd_mkdb/pwd_mkdb.c | 762 --- usr.sbin/quot/Makefile | 8 - usr.sbin/quot/quot.8 | 110 - usr.sbin/quot/quot.c | 644 --- usr.sbin/quotaon/Makefile | 12 - usr.sbin/quotaon/quotaon.8 | 137 - usr.sbin/quotaon/quotaon.c | 195 - usr.sbin/rarpd/Makefile | 11 - usr.sbin/rarpd/rarpd.8 | 148 - usr.sbin/rarpd/rarpd.c | 951 --- usr.sbin/repquota/Makefile | 9 - usr.sbin/repquota/repquota.8 | 111 - usr.sbin/repquota/repquota.c | 372 -- usr.sbin/rip6query/Makefile | 9 - usr.sbin/rip6query/rip6query.8 | 64 - usr.sbin/rip6query/rip6query.c | 200 - usr.sbin/rmt/Makefile | 12 - usr.sbin/rmt/rmt.8 | 221 - usr.sbin/rmt/rmt.c | 250 - usr.sbin/rndc-confgen/Makefile | 31 - usr.sbin/rndc/Makefile | 30 - usr.sbin/route6d/Makefile | 11 - usr.sbin/route6d/misc/chkrt | 64 - usr.sbin/route6d/misc/cksum.c | 52 - usr.sbin/route6d/route6d.8 | 255 - usr.sbin/route6d/route6d.c | 3631 ------------ usr.sbin/route6d/route6d.h | 81 - usr.sbin/rpc.lockd/Makefile | 29 - usr.sbin/rpc.lockd/kern.c | 605 -- usr.sbin/rpc.lockd/lock_proc.c | 1415 ----- usr.sbin/rpc.lockd/lockd.c | 839 --- usr.sbin/rpc.lockd/lockd.h | 41 - usr.sbin/rpc.lockd/lockd_lock.c | 2303 -------- usr.sbin/rpc.lockd/lockd_lock.h | 25 - usr.sbin/rpc.lockd/rpc.lockd.8 | 150 - usr.sbin/rpc.lockd/test.c | 365 -- usr.sbin/rpc.statd/Makefile | 27 - usr.sbin/rpc.statd/file.c | 361 -- usr.sbin/rpc.statd/procs.c | 436 -- usr.sbin/rpc.statd/rpc.statd.8 | 141 - usr.sbin/rpc.statd/statd.c | 471 -- usr.sbin/rpc.statd/statd.h | 111 - usr.sbin/rpc.statd/test.c | 144 - usr.sbin/rpc.umntall/Makefile | 10 - usr.sbin/rpc.umntall/mounttab.c | 230 - usr.sbin/rpc.umntall/mounttab.h | 46 - usr.sbin/rpc.umntall/rpc.umntall.8 | 126 - usr.sbin/rpc.umntall/rpc.umntall.c | 266 - usr.sbin/rpc.yppasswdd/Makefile | 62 - usr.sbin/rpc.yppasswdd/rpc.yppasswdd.8 | 359 -- usr.sbin/rpc.yppasswdd/yppasswd_private.x | 70 - usr.sbin/rpc.yppasswdd/yppasswdd_extern.h | 69 - usr.sbin/rpc.yppasswdd/yppasswdd_main.c | 353 -- usr.sbin/rpc.yppasswdd/yppasswdd_server.c | 918 --- usr.sbin/rpc.yppasswdd/yppwupdate | 34 - usr.sbin/rpc.ypupdated/Makefile | 34 - usr.sbin/rpc.ypupdated/update.c | 330 -- usr.sbin/rpc.ypupdated/yp_dbdelete.c | 68 - usr.sbin/rpc.ypupdated/yp_dbupdate.c | 146 - usr.sbin/rpc.ypupdated/ypupdate | 33 - usr.sbin/rpc.ypupdated/ypupdated_extern.h | 33 - usr.sbin/rpc.ypupdated/ypupdated_main.c | 286 - usr.sbin/rpc.ypupdated/ypupdated_server.c | 228 - usr.sbin/rpc.ypxfrd/Makefile | 37 - usr.sbin/rpc.ypxfrd/rpc.ypxfrd.8 | 153 - usr.sbin/rpc.ypxfrd/ypxfrd_extern.h | 50 - usr.sbin/rpc.ypxfrd/ypxfrd_main.c | 302 - usr.sbin/rpc.ypxfrd/ypxfrd_server.c | 145 - usr.sbin/rpcbind/Makefile | 22 - usr.sbin/rpcbind/check_bound.c | 231 - usr.sbin/rpcbind/pmap_svc.c | 368 -- usr.sbin/rpcbind/rpcb_stat.c | 206 - usr.sbin/rpcbind/rpcb_svc.c | 233 - usr.sbin/rpcbind/rpcb_svc_4.c | 455 -- usr.sbin/rpcbind/rpcb_svc_com.c | 1468 ----- usr.sbin/rpcbind/rpcbind.8 | 148 - usr.sbin/rpcbind/rpcbind.c | 855 --- usr.sbin/rpcbind/rpcbind.h | 153 - usr.sbin/rpcbind/security.c | 288 - usr.sbin/rpcbind/util.c | 376 -- usr.sbin/rpcbind/warmstart.c | 179 - usr.sbin/rrenumd/Makefile | 38 - usr.sbin/rrenumd/lexer.l | 273 - usr.sbin/rrenumd/parser.y | 676 --- usr.sbin/rrenumd/rrenumd.8 | 103 - usr.sbin/rrenumd/rrenumd.c | 663 --- usr.sbin/rrenumd/rrenumd.conf.5 | 369 -- usr.sbin/rrenumd/rrenumd.h | 60 - usr.sbin/rtadvd/Makefile | 25 - usr.sbin/rtadvd/advcap.c | 451 -- usr.sbin/rtadvd/advcap.h | 46 - usr.sbin/rtadvd/config.c | 1080 ---- usr.sbin/rtadvd/config.h | 47 - usr.sbin/rtadvd/dump.c | 252 - usr.sbin/rtadvd/dump.h | 33 - usr.sbin/rtadvd/if.c | 580 -- usr.sbin/rtadvd/if.h | 58 - usr.sbin/rtadvd/pathnames.h | 4 - usr.sbin/rtadvd/rrenum.c | 486 -- usr.sbin/rtadvd/rrenum.h | 34 - usr.sbin/rtadvd/rtadvd.8 | 195 - usr.sbin/rtadvd/rtadvd.c | 1689 ------ usr.sbin/rtadvd/rtadvd.conf | 21 - usr.sbin/rtadvd/rtadvd.conf.5 | 427 -- usr.sbin/rtadvd/rtadvd.h | 161 - usr.sbin/rtadvd/timer.c | 209 - usr.sbin/rtadvd/timer.h | 65 - usr.sbin/rtprio/Makefile | 10 - usr.sbin/rtprio/rtprio.1 | 192 - usr.sbin/rtprio/rtprio.c | 140 - usr.sbin/rtsold/Makefile | 27 - usr.sbin/rtsold/dump.c | 149 - usr.sbin/rtsold/if.c | 438 -- usr.sbin/rtsold/probe.c | 184 - usr.sbin/rtsold/rtsock.c | 175 - usr.sbin/rtsold/rtsol.c | 473 -- usr.sbin/rtsold/rtsold.8 | 272 - usr.sbin/rtsold/rtsold.c | 887 --- usr.sbin/rtsold/rtsold.h | 104 - usr.sbin/rwhod/Makefile | 9 - usr.sbin/rwhod/rwhod.8 | 239 - usr.sbin/rwhod/rwhod.c | 701 --- usr.sbin/sa/Makefile | 9 - usr.sbin/sa/db.c | 207 - usr.sbin/sa/extern.h | 110 - usr.sbin/sa/main.c | 533 -- usr.sbin/sa/pathnames.h | 35 - usr.sbin/sa/pdb.c | 374 -- usr.sbin/sa/sa.8 | 262 - usr.sbin/sa/usrdb.c | 239 - usr.sbin/sade/Makefile | 27 - usr.sbin/sade/command.c | 179 - usr.sbin/sade/config.c | 333 -- usr.sbin/sade/devices.c | 345 -- usr.sbin/sade/disks.c | 1037 ---- usr.sbin/sade/dispatch.c | 161 - usr.sbin/sade/dmenu.c | 295 - usr.sbin/sade/globals.c | 84 - usr.sbin/sade/help/partition.hlp | 169 - usr.sbin/sade/help/slice.hlp | 57 - usr.sbin/sade/install.c | 257 - usr.sbin/sade/label.c | 1703 ------ usr.sbin/sade/list.h | 55 - usr.sbin/sade/main.c | 122 - usr.sbin/sade/menus.c | 116 - usr.sbin/sade/misc.c | 491 -- usr.sbin/sade/msg.c | 350 -- usr.sbin/sade/sade.8 | 73 - usr.sbin/sade/sade.h | 487 -- usr.sbin/sade/system.c | 307 - usr.sbin/sade/termcap.c | 104 - usr.sbin/sade/variable.c | 324 -- usr.sbin/sade/wizard.c | 200 - usr.sbin/sendmail/Makefile | 79 - usr.sbin/service/Makefile | 7 - usr.sbin/service/service.8 | 131 - usr.sbin/service/service.sh | 120 - usr.sbin/services_mkdb/Makefile | 10 - usr.sbin/services_mkdb/services_mkdb.8 | 99 - usr.sbin/services_mkdb/services_mkdb.c | 429 -- usr.sbin/services_mkdb/uniq.c | 159 - usr.sbin/setfib/Makefile | 6 - usr.sbin/setfib/setfib.1 | 97 - usr.sbin/setfib/setfib.c | 105 - usr.sbin/setfmac/Makefile | 7 - usr.sbin/setfmac/setfmac.8 | 66 - usr.sbin/setfmac/setfmac.c | 498 -- usr.sbin/setfmac/setfsmac.8 | 129 - usr.sbin/setpmac/Makefile | 6 - usr.sbin/setpmac/setpmac.8 | 65 - usr.sbin/setpmac/setpmac.c | 92 - usr.sbin/sicontrol/Makefile | 9 - usr.sbin/sicontrol/sicontrol.8 | 109 - usr.sbin/sicontrol/sicontrol.c | 726 --- usr.sbin/smbmsg/Makefile | 7 - usr.sbin/smbmsg/pathnames.h | 29 - usr.sbin/smbmsg/smbmsg.8 | 286 - usr.sbin/smbmsg/smbmsg.c | 344 -- usr.sbin/snapinfo/Makefile | 10 - usr.sbin/snapinfo/snapinfo.8 | 66 - usr.sbin/snapinfo/snapinfo.c | 179 - usr.sbin/spkrtest/Makefile | 6 - usr.sbin/spkrtest/spkrtest.8 | 48 - usr.sbin/spkrtest/spkrtest.sh | 113 - usr.sbin/spray/Makefile | 9 - usr.sbin/spray/spray.8 | 76 - usr.sbin/spray/spray.c | 220 - usr.sbin/sysinstall/Makefile | 126 - usr.sbin/sysinstall/anonFTP.c | 328 -- usr.sbin/sysinstall/cdrom.c | 244 - usr.sbin/sysinstall/command.c | 184 - usr.sbin/sysinstall/config.c | 1074 ---- usr.sbin/sysinstall/devices.c | 587 -- usr.sbin/sysinstall/dhcp.c | 158 - usr.sbin/sysinstall/disks.c | 1055 ---- usr.sbin/sysinstall/dispatch.c | 639 -- usr.sbin/sysinstall/dist.c | 919 --- usr.sbin/sysinstall/dist.h | 92 - usr.sbin/sysinstall/dmenu.c | 393 -- usr.sbin/sysinstall/doc.c | 123 - usr.sbin/sysinstall/dos.c | 94 - usr.sbin/sysinstall/floppy.c | 158 - usr.sbin/sysinstall/ftp.c | 282 - usr.sbin/sysinstall/globals.c | 93 - usr.sbin/sysinstall/help/anonftp.hlp | 21 - usr.sbin/sysinstall/help/configure.hlp | 10 - usr.sbin/sysinstall/help/distributions.hlp | 34 - usr.sbin/sysinstall/help/drives.hlp | 92 - usr.sbin/sysinstall/help/fixit.hlp | 3 - usr.sbin/sysinstall/help/html.hlp | 20 - usr.sbin/sysinstall/help/media.hlp | 54 - usr.sbin/sysinstall/help/network_device.hlp | 58 - usr.sbin/sysinstall/help/options.hlp | 181 - usr.sbin/sysinstall/help/partition.hlp | 169 - usr.sbin/sysinstall/help/securelevel.hlp | 40 - usr.sbin/sysinstall/help/shortcuts.hlp | 117 - usr.sbin/sysinstall/help/slice.hlp | 57 - usr.sbin/sysinstall/help/tcp.hlp | 42 - usr.sbin/sysinstall/help/usage.hlp | 65 - usr.sbin/sysinstall/help/usermgmt.hlp | 89 - usr.sbin/sysinstall/http.c | 279 - usr.sbin/sysinstall/index.c | 893 --- usr.sbin/sysinstall/install.c | 1346 ----- usr.sbin/sysinstall/install.cfg | 101 - usr.sbin/sysinstall/installUpgrade.c | 526 -- usr.sbin/sysinstall/keymap.c | 172 - usr.sbin/sysinstall/label.c | 1692 ------ usr.sbin/sysinstall/list.h | 60 - usr.sbin/sysinstall/main.c | 224 - usr.sbin/sysinstall/media.c | 881 --- usr.sbin/sysinstall/menus.c | 2169 ------- usr.sbin/sysinstall/misc.c | 553 -- usr.sbin/sysinstall/modules.c | 224 - usr.sbin/sysinstall/mouse.c | 103 - usr.sbin/sysinstall/msg.c | 428 -- usr.sbin/sysinstall/network.c | 149 - usr.sbin/sysinstall/nfs.c | 101 - usr.sbin/sysinstall/options.c | 336 -- usr.sbin/sysinstall/package.c | 270 - usr.sbin/sysinstall/rtermcap.c | 15 - usr.sbin/sysinstall/sysinstall.8 | 900 --- usr.sbin/sysinstall/sysinstall.h | 895 --- usr.sbin/sysinstall/system.c | 555 -- usr.sbin/sysinstall/tcpip.c | 775 --- usr.sbin/sysinstall/termcap.c | 150 - usr.sbin/sysinstall/ttys.c | 162 - usr.sbin/sysinstall/ufs.c | 85 - usr.sbin/sysinstall/usb.c | 88 - usr.sbin/sysinstall/user.c | 751 --- usr.sbin/sysinstall/variable.c | 329 -- usr.sbin/sysinstall/wizard.c | 201 - usr.sbin/syslogd/Makefile | 23 - usr.sbin/syslogd/pathnames.h | 37 - usr.sbin/syslogd/syslog.conf.5 | 517 -- usr.sbin/syslogd/syslogd.8 | 407 -- usr.sbin/syslogd/syslogd.c | 2721 --------- usr.sbin/tcpdchk/Makefile | 23 - usr.sbin/tcpdmatch/Makefile | 22 - usr.sbin/tcpdrop/Makefile | 7 - usr.sbin/tcpdrop/tcpdrop.8 | 96 - usr.sbin/tcpdrop/tcpdrop.c | 322 -- usr.sbin/tcpdump/Makefile | 6 - usr.sbin/tcpdump/Makefile.inc | 6 - usr.sbin/tcpdump/tcpdump/Makefile | 72 - usr.sbin/tcpdump/tcpdump/config.h | 359 -- usr.sbin/timed/Makefile | 6 - usr.sbin/timed/SMM.doc/timed/Makefile | 12 - usr.sbin/timed/SMM.doc/timed/date | 53 - usr.sbin/timed/SMM.doc/timed/loop | 54 - usr.sbin/timed/SMM.doc/timed/spell.ok | 34 - usr.sbin/timed/SMM.doc/timed/time | 53 - usr.sbin/timed/SMM.doc/timed/timed.ms | 462 -- usr.sbin/timed/SMM.doc/timed/unused | 53 - usr.sbin/timed/SMM.doc/timedop/Makefile | 8 - usr.sbin/timed/SMM.doc/timedop/timed.ms | 279 - usr.sbin/timed/timed/CHANGES | 145 - usr.sbin/timed/timed/Makefile | 17 - usr.sbin/timed/timed/acksend.c | 132 - usr.sbin/timed/timed/byteorder.c | 86 - usr.sbin/timed/timed/candidate.c | 167 - usr.sbin/timed/timed/cksum.c | 87 - usr.sbin/timed/timed/correct.c | 198 - usr.sbin/timed/timed/extern.h | 91 - usr.sbin/timed/timed/globals.h | 172 - usr.sbin/timed/timed/master.c | 856 --- usr.sbin/timed/timed/measure.c | 346 -- usr.sbin/timed/timed/networkdelta.c | 264 - usr.sbin/timed/timed/pathnames.h | 41 - usr.sbin/timed/timed/readmsg.c | 513 -- usr.sbin/timed/timed/slave.c | 697 --- usr.sbin/timed/timed/timed.8 | 292 - usr.sbin/timed/timed/timed.c | 851 --- usr.sbin/timed/timedc/Makefile | 15 - usr.sbin/timed/timedc/cmds.c | 556 -- usr.sbin/timed/timedc/cmdtab.c | 61 - usr.sbin/timed/timedc/extern.h | 54 - usr.sbin/timed/timedc/timedc.8 | 145 - usr.sbin/timed/timedc/timedc.c | 261 - usr.sbin/timed/timedc/timedc.h | 63 - usr.sbin/traceroute/Makefile | 42 - usr.sbin/traceroute/findsaddr-udp.c | 94 - usr.sbin/traceroute6/Makefile | 33 - usr.sbin/traceroute6/traceroute6.8 | 185 - usr.sbin/traceroute6/traceroute6.c | 1459 ----- usr.sbin/trpt/Makefile | 17 - usr.sbin/trpt/trpt.8 | 149 - usr.sbin/trpt/trpt.c | 463 -- usr.sbin/tzsetup/Makefile | 13 - usr.sbin/tzsetup/tzsetup.8 | 162 - usr.sbin/tzsetup/tzsetup.c | 860 --- usr.sbin/uathload/Makefile | 16 - usr.sbin/uathload/uathload.8 | 69 - usr.sbin/uathload/uathload.c | 233 - usr.sbin/ugidfw/Makefile | 9 - usr.sbin/ugidfw/ugidfw.8 | 360 -- usr.sbin/ugidfw/ugidfw.c | 214 - usr.sbin/uhsoctl/Makefile | 10 - usr.sbin/uhsoctl/uhsoctl.1 | 102 - usr.sbin/uhsoctl/uhsoctl.c | 1561 ----- usr.sbin/usbconfig/Makefile | 10 - usr.sbin/usbconfig/dump.c | 404 -- usr.sbin/usbconfig/dump.h | 40 - usr.sbin/usbconfig/usbconfig.8 | 96 - usr.sbin/usbconfig/usbconfig.c | 822 --- usr.sbin/usbdevs/Makefile | 7 - usr.sbin/usbdevs/usbdevs.8 | 70 - usr.sbin/usbdevs/usbdevs.c | 233 - usr.sbin/vidcontrol/Makefile | 6 - usr.sbin/vidcontrol/decode.c | 99 - usr.sbin/vidcontrol/decode.h | 3 - usr.sbin/vidcontrol/path.h | 4 - usr.sbin/vidcontrol/vidcontrol.1 | 542 -- usr.sbin/vidcontrol/vidcontrol.c | 1331 ----- usr.sbin/vipw/Makefile | 10 - usr.sbin/vipw/vipw.8 | 119 - usr.sbin/vipw/vipw.c | 137 - usr.sbin/wake/Makefile | 8 - usr.sbin/wake/wake.8 | 68 - usr.sbin/wake/wake.c | 213 - usr.sbin/watch/Makefile | 11 - usr.sbin/watch/watch.8 | 120 - usr.sbin/watch/watch.c | 442 -- usr.sbin/watchdogd/Makefile | 13 - usr.sbin/watchdogd/watchdog.8 | 73 - usr.sbin/watchdogd/watchdogd.8 | 127 - usr.sbin/watchdogd/watchdogd.c | 296 - usr.sbin/wlandebug/Makefile | 8 - usr.sbin/wlandebug/wlandebug.8 | 177 - usr.sbin/wlandebug/wlandebug.c | 243 - usr.sbin/wlconfig/Makefile | 9 - usr.sbin/wlconfig/wlconfig.8 | 143 - usr.sbin/wlconfig/wlconfig.c | 417 -- usr.sbin/wpa/Makefile | 7 - usr.sbin/wpa/Makefile.inc | 27 - usr.sbin/wpa/hostapd/Makefile | 114 - usr.sbin/wpa/hostapd/driver_freebsd.c | 909 --- usr.sbin/wpa/hostapd/hostapd.8 | 134 - usr.sbin/wpa/hostapd/hostapd.conf.5 | 210 - usr.sbin/wpa/hostapd_cli/Makefile | 15 - usr.sbin/wpa/hostapd_cli/hostapd_cli.8 | 112 - usr.sbin/wpa/ndis_events/Makefile | 8 - usr.sbin/wpa/ndis_events/ndis_events.8 | 135 - usr.sbin/wpa/ndis_events/ndis_events.c | 354 -- usr.sbin/wpa/wpa_cli/Makefile | 21 - usr.sbin/wpa/wpa_cli/wpa_cli.8 | 222 - usr.sbin/wpa/wpa_passphrase/Makefile | 15 - usr.sbin/wpa/wpa_passphrase/wpa_passphrase.8 | 66 - usr.sbin/wpa/wpa_supplicant/Makefile | 150 - usr.sbin/wpa/wpa_supplicant/Packet32.c | 415 -- usr.sbin/wpa/wpa_supplicant/Packet32.h | 67 - usr.sbin/wpa/wpa_supplicant/driver_freebsd.c | 954 --- usr.sbin/wpa/wpa_supplicant/ntddndis.h | 31 - usr.sbin/wpa/wpa_supplicant/wpa_supplicant.8 | 155 - usr.sbin/wpa/wpa_supplicant/wpa_supplicant.conf.5 | 565 -- usr.sbin/yp_mkdb/Makefile | 14 - usr.sbin/yp_mkdb/yp_mkdb.8 | 209 - usr.sbin/yp_mkdb/yp_mkdb.c | 342 -- usr.sbin/ypbind/Makefile | 12 - usr.sbin/ypbind/yp_ping.c | 310 - usr.sbin/ypbind/yp_ping.h | 5 - usr.sbin/ypbind/ypbind.8 | 202 - usr.sbin/ypbind/ypbind.c | 1001 ---- usr.sbin/yppoll/Makefile | 9 - usr.sbin/yppoll/yppoll.8 | 77 - usr.sbin/yppoll/yppoll.c | 97 - usr.sbin/yppush/Makefile | 30 - usr.sbin/yppush/yppush.8 | 180 - usr.sbin/yppush/yppush_extern.h | 44 - usr.sbin/yppush/yppush_main.c | 620 -- usr.sbin/ypserv/Makefile | 44 - usr.sbin/ypserv/Makefile.yp | 657 --- usr.sbin/ypserv/yp_access.c | 330 -- usr.sbin/ypserv/yp_dblookup.c | 733 --- usr.sbin/ypserv/yp_dnslookup.c | 551 -- usr.sbin/ypserv/yp_error.c | 73 - usr.sbin/ypserv/yp_extern.h | 115 - usr.sbin/ypserv/yp_main.c | 577 -- usr.sbin/ypserv/yp_server.c | 985 ---- usr.sbin/ypserv/yp_svc_udp.c | 71 - usr.sbin/ypserv/ypinit.8 | 198 - usr.sbin/ypserv/ypinit.sh | 386 -- usr.sbin/ypserv/ypserv.8 | 465 -- usr.sbin/ypset/Makefile | 9 - usr.sbin/ypset/ypset.8 | 88 - usr.sbin/ypset/ypset.c | 150 - usr.sbin/zic/Makefile | 7 - usr.sbin/zic/Makefile.inc | 3 - usr.sbin/zic/README | 88 - usr.sbin/zic/zdump/Makefile | 15 - usr.sbin/zic/zic/Makefile | 16 - usr.sbin/zzz/Makefile | 6 - usr.sbin/zzz/zzz.8 | 65 - usr.sbin/zzz/zzz.sh | 43 - 1744 files changed, 466922 deletions(-) delete mode 100644 usr.sbin/IPXrouted/IPXrouted.8 delete mode 100644 usr.sbin/IPXrouted/Makefile delete mode 100644 usr.sbin/IPXrouted/af.c delete mode 100644 usr.sbin/IPXrouted/af.h delete mode 100644 usr.sbin/IPXrouted/defs.h delete mode 100644 usr.sbin/IPXrouted/if.c delete mode 100644 usr.sbin/IPXrouted/input.c delete mode 100644 usr.sbin/IPXrouted/interface.h delete mode 100644 usr.sbin/IPXrouted/main.c delete mode 100644 usr.sbin/IPXrouted/output.c delete mode 100644 usr.sbin/IPXrouted/protocol.h delete mode 100644 usr.sbin/IPXrouted/sap.h delete mode 100644 usr.sbin/IPXrouted/sap_input.c delete mode 100644 usr.sbin/IPXrouted/sap_output.c delete mode 100644 usr.sbin/IPXrouted/sap_tables.c delete mode 100644 usr.sbin/IPXrouted/startup.c delete mode 100644 usr.sbin/IPXrouted/table.h delete mode 100644 usr.sbin/IPXrouted/tables.c delete mode 100644 usr.sbin/IPXrouted/timer.c delete mode 100644 usr.sbin/IPXrouted/trace.c delete mode 100644 usr.sbin/IPXrouted/trace.h delete mode 100644 usr.sbin/Makefile delete mode 100644 usr.sbin/Makefile.amd64 delete mode 100644 usr.sbin/Makefile.arm delete mode 100644 usr.sbin/Makefile.i386 delete mode 100644 usr.sbin/Makefile.ia64 delete mode 100644 usr.sbin/Makefile.inc delete mode 100644 usr.sbin/Makefile.mips delete mode 100644 usr.sbin/Makefile.powerpc delete mode 100644 usr.sbin/Makefile.sparc64 delete mode 100644 usr.sbin/ac/Makefile delete mode 100644 usr.sbin/ac/ac.8 delete mode 100644 usr.sbin/ac/ac.c delete mode 100644 usr.sbin/accton/Makefile delete mode 100644 usr.sbin/accton/accton.8 delete mode 100644 usr.sbin/accton/accton.c delete mode 100644 usr.sbin/acpi/Makefile delete mode 100644 usr.sbin/acpi/Makefile.inc delete mode 100644 usr.sbin/acpi/acpiconf/Makefile delete mode 100644 usr.sbin/acpi/acpiconf/acpiconf.8 delete mode 100644 usr.sbin/acpi/acpiconf/acpiconf.c delete mode 100644 usr.sbin/acpi/acpidb/Makefile delete mode 100644 usr.sbin/acpi/acpidb/acpidb.8 delete mode 100644 usr.sbin/acpi/acpidb/acpidb.c delete mode 100644 usr.sbin/acpi/acpidump/Makefile delete mode 100644 usr.sbin/acpi/acpidump/acpi.c delete mode 100644 usr.sbin/acpi/acpidump/acpi_user.c delete mode 100644 usr.sbin/acpi/acpidump/acpidump.8 delete mode 100644 usr.sbin/acpi/acpidump/acpidump.c delete mode 100644 usr.sbin/acpi/acpidump/acpidump.h delete mode 100644 usr.sbin/acpi/iasl/Makefile delete mode 100644 usr.sbin/acpi/iasl/iasl.8 delete mode 100644 usr.sbin/adduser/Makefile delete mode 100644 usr.sbin/adduser/adduser.8 delete mode 100644 usr.sbin/adduser/adduser.conf.5 delete mode 100644 usr.sbin/adduser/adduser.sh delete mode 100644 usr.sbin/adduser/rmuser.8 delete mode 100644 usr.sbin/adduser/rmuser.sh delete mode 100644 usr.sbin/amd/Makefile delete mode 100644 usr.sbin/amd/Makefile.inc delete mode 100644 usr.sbin/amd/NOTES delete mode 100644 usr.sbin/amd/amd/Makefile delete mode 100644 usr.sbin/amd/amq/Makefile delete mode 100644 usr.sbin/amd/doc/Makefile delete mode 100644 usr.sbin/amd/fixmount/Makefile delete mode 100644 usr.sbin/amd/fsinfo/Makefile delete mode 100644 usr.sbin/amd/hlfsd/Makefile delete mode 100644 usr.sbin/amd/include/Makefile delete mode 100644 usr.sbin/amd/include/amu_autofs_prot.h delete mode 100644 usr.sbin/amd/include/amu_nfs_prot.h delete mode 100644 usr.sbin/amd/include/aux_conf.h delete mode 100644 usr.sbin/amd/include/build_version.h delete mode 100644 usr.sbin/amd/include/config.h delete mode 100644 usr.sbin/amd/include/newvers.sh delete mode 100644 usr.sbin/amd/libamu/Makefile delete mode 100644 usr.sbin/amd/mk-amd-map/Makefile delete mode 100644 usr.sbin/amd/pawd/Makefile delete mode 100644 usr.sbin/amd/scripts/Makefile delete mode 100644 usr.sbin/amd/wire-test/Makefile delete mode 100644 usr.sbin/ancontrol/Makefile delete mode 100644 usr.sbin/ancontrol/ancontrol.8 delete mode 100644 usr.sbin/ancontrol/ancontrol.c delete mode 100644 usr.sbin/apm/Makefile delete mode 100644 usr.sbin/apm/apm.8 delete mode 100644 usr.sbin/apm/apm.c delete mode 100644 usr.sbin/apmd/Makefile delete mode 100644 usr.sbin/apmd/README delete mode 100644 usr.sbin/apmd/apmd.8 delete mode 100644 usr.sbin/apmd/apmd.c delete mode 100644 usr.sbin/apmd/apmd.h delete mode 100644 usr.sbin/apmd/apmdlex.l delete mode 100644 usr.sbin/apmd/apmdparse.y delete mode 100644 usr.sbin/apmd/contrib/pccardq.c delete mode 100644 usr.sbin/arp/Makefile delete mode 100644 usr.sbin/arp/arp.4 delete mode 100644 usr.sbin/arp/arp.8 delete mode 100644 usr.sbin/arp/arp.c delete mode 100644 usr.sbin/asf/Makefile delete mode 100644 usr.sbin/asf/asf.8 delete mode 100644 usr.sbin/asf/asf.c delete mode 100644 usr.sbin/asf/asf.h delete mode 100644 usr.sbin/asf/asf_kld.c delete mode 100644 usr.sbin/asf/asf_kvm.c delete mode 100644 usr.sbin/asf/asf_prog.c delete mode 100644 usr.sbin/audit/Makefile delete mode 100644 usr.sbin/auditd/Makefile delete mode 100644 usr.sbin/auditreduce/Makefile delete mode 100644 usr.sbin/authpf/Makefile delete mode 100644 usr.sbin/bluetooth/Makefile delete mode 100644 usr.sbin/bluetooth/Makefile.inc delete mode 100644 usr.sbin/bluetooth/bcmfw/BCM-LEGAL.txt delete mode 100644 usr.sbin/bluetooth/bcmfw/Makefile delete mode 100644 usr.sbin/bluetooth/bcmfw/README delete mode 100644 usr.sbin/bluetooth/bcmfw/bcmfw.8 delete mode 100644 usr.sbin/bluetooth/bcmfw/bcmfw.c delete mode 100644 usr.sbin/bluetooth/bt3cfw/Makefile delete mode 100644 usr.sbin/bluetooth/bt3cfw/bt3cfw.8 delete mode 100644 usr.sbin/bluetooth/bt3cfw/bt3cfw.c delete mode 100644 usr.sbin/bluetooth/bthidcontrol/Makefile delete mode 100644 usr.sbin/bluetooth/bthidcontrol/bthidcontrol.8 delete mode 100644 usr.sbin/bluetooth/bthidcontrol/bthidcontrol.c delete mode 100644 usr.sbin/bluetooth/bthidcontrol/bthidcontrol.h delete mode 100644 usr.sbin/bluetooth/bthidcontrol/hid.c delete mode 100644 usr.sbin/bluetooth/bthidcontrol/sdp.c delete mode 100644 usr.sbin/bluetooth/bthidd/Makefile delete mode 100644 usr.sbin/bluetooth/bthidd/bthid_config.h delete mode 100644 usr.sbin/bluetooth/bthidd/bthidd.8 delete mode 100644 usr.sbin/bluetooth/bthidd/bthidd.c delete mode 100644 usr.sbin/bluetooth/bthidd/bthidd.conf.sample delete mode 100644 usr.sbin/bluetooth/bthidd/bthidd.h delete mode 100644 usr.sbin/bluetooth/bthidd/client.c delete mode 100644 usr.sbin/bluetooth/bthidd/hid.c delete mode 100644 usr.sbin/bluetooth/bthidd/kbd.c delete mode 100644 usr.sbin/bluetooth/bthidd/kbd.h delete mode 100644 usr.sbin/bluetooth/bthidd/lexer.l delete mode 100644 usr.sbin/bluetooth/bthidd/parser.y delete mode 100644 usr.sbin/bluetooth/bthidd/server.c delete mode 100644 usr.sbin/bluetooth/bthidd/session.c delete mode 100644 usr.sbin/bluetooth/btpand/Makefile delete mode 100644 usr.sbin/bluetooth/btpand/bnep.c delete mode 100644 usr.sbin/bluetooth/btpand/bnep.h delete mode 100644 usr.sbin/bluetooth/btpand/btpand.8 delete mode 100644 usr.sbin/bluetooth/btpand/btpand.c delete mode 100644 usr.sbin/bluetooth/btpand/btpand.h delete mode 100644 usr.sbin/bluetooth/btpand/channel.c delete mode 100644 usr.sbin/bluetooth/btpand/client.c delete mode 100644 usr.sbin/bluetooth/btpand/event.c delete mode 100644 usr.sbin/bluetooth/btpand/event.h delete mode 100644 usr.sbin/bluetooth/btpand/packet.c delete mode 100644 usr.sbin/bluetooth/btpand/sdp.c delete mode 100644 usr.sbin/bluetooth/btpand/sdp.h delete mode 100644 usr.sbin/bluetooth/btpand/server.c delete mode 100644 usr.sbin/bluetooth/btpand/tap.c delete mode 100644 usr.sbin/bluetooth/hccontrol/Makefile delete mode 100644 usr.sbin/bluetooth/hccontrol/hccontrol.8 delete mode 100644 usr.sbin/bluetooth/hccontrol/hccontrol.c delete mode 100644 usr.sbin/bluetooth/hccontrol/hccontrol.h delete mode 100644 usr.sbin/bluetooth/hccontrol/host_controller_baseband.c delete mode 100644 usr.sbin/bluetooth/hccontrol/info.c delete mode 100644 usr.sbin/bluetooth/hccontrol/link_control.c delete mode 100644 usr.sbin/bluetooth/hccontrol/link_policy.c delete mode 100644 usr.sbin/bluetooth/hccontrol/node.c delete mode 100644 usr.sbin/bluetooth/hccontrol/send_recv.c delete mode 100644 usr.sbin/bluetooth/hccontrol/status.c delete mode 100644 usr.sbin/bluetooth/hccontrol/util.c delete mode 100644 usr.sbin/bluetooth/hcsecd/Makefile delete mode 100644 usr.sbin/bluetooth/hcsecd/hcsecd.8 delete mode 100644 usr.sbin/bluetooth/hcsecd/hcsecd.c delete mode 100644 usr.sbin/bluetooth/hcsecd/hcsecd.conf delete mode 100644 usr.sbin/bluetooth/hcsecd/hcsecd.conf.5 delete mode 100644 usr.sbin/bluetooth/hcsecd/hcsecd.h delete mode 100644 usr.sbin/bluetooth/hcsecd/lexer.l delete mode 100644 usr.sbin/bluetooth/hcsecd/parser.y delete mode 100644 usr.sbin/bluetooth/hcseriald/Makefile delete mode 100644 usr.sbin/bluetooth/hcseriald/hcseriald.8 delete mode 100644 usr.sbin/bluetooth/hcseriald/hcseriald.c delete mode 100644 usr.sbin/bluetooth/l2control/Makefile delete mode 100644 usr.sbin/bluetooth/l2control/l2cap.c delete mode 100644 usr.sbin/bluetooth/l2control/l2control.8 delete mode 100644 usr.sbin/bluetooth/l2control/l2control.c delete mode 100644 usr.sbin/bluetooth/l2control/l2control.h delete mode 100644 usr.sbin/bluetooth/l2ping/Makefile delete mode 100644 usr.sbin/bluetooth/l2ping/l2ping.8 delete mode 100644 usr.sbin/bluetooth/l2ping/l2ping.c delete mode 100644 usr.sbin/bluetooth/rfcomm_pppd/Makefile delete mode 100644 usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 delete mode 100644 usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c delete mode 100644 usr.sbin/bluetooth/sdpcontrol/Makefile delete mode 100644 usr.sbin/bluetooth/sdpcontrol/sdpcontrol.8 delete mode 100644 usr.sbin/bluetooth/sdpcontrol/sdpcontrol.c delete mode 100644 usr.sbin/bluetooth/sdpcontrol/sdpcontrol.h delete mode 100644 usr.sbin/bluetooth/sdpcontrol/search.c delete mode 100644 usr.sbin/bluetooth/sdpd/Makefile delete mode 100644 usr.sbin/bluetooth/sdpd/bgd.c delete mode 100644 usr.sbin/bluetooth/sdpd/dun.c delete mode 100644 usr.sbin/bluetooth/sdpd/ftrn.c delete mode 100644 usr.sbin/bluetooth/sdpd/gn.c delete mode 100644 usr.sbin/bluetooth/sdpd/irmc.c delete mode 100644 usr.sbin/bluetooth/sdpd/irmc_command.c delete mode 100644 usr.sbin/bluetooth/sdpd/lan.c delete mode 100644 usr.sbin/bluetooth/sdpd/log.c delete mode 100644 usr.sbin/bluetooth/sdpd/log.h delete mode 100644 usr.sbin/bluetooth/sdpd/main.c delete mode 100644 usr.sbin/bluetooth/sdpd/nap.c delete mode 100644 usr.sbin/bluetooth/sdpd/opush.c delete mode 100644 usr.sbin/bluetooth/sdpd/panu.c delete mode 100644 usr.sbin/bluetooth/sdpd/profile.c delete mode 100644 usr.sbin/bluetooth/sdpd/profile.h delete mode 100644 usr.sbin/bluetooth/sdpd/provider.c delete mode 100644 usr.sbin/bluetooth/sdpd/provider.h delete mode 100644 usr.sbin/bluetooth/sdpd/sar.c delete mode 100644 usr.sbin/bluetooth/sdpd/scr.c delete mode 100644 usr.sbin/bluetooth/sdpd/sd.c delete mode 100644 usr.sbin/bluetooth/sdpd/sdpd.8 delete mode 100644 usr.sbin/bluetooth/sdpd/server.c delete mode 100644 usr.sbin/bluetooth/sdpd/server.h delete mode 100644 usr.sbin/bluetooth/sdpd/sp.c delete mode 100644 usr.sbin/bluetooth/sdpd/srr.c delete mode 100644 usr.sbin/bluetooth/sdpd/ssar.c delete mode 100644 usr.sbin/bluetooth/sdpd/ssr.c delete mode 100644 usr.sbin/bluetooth/sdpd/sur.c delete mode 100644 usr.sbin/bluetooth/sdpd/uuid-private.h delete mode 100644 usr.sbin/bluetooth/sdpd/uuid.c delete mode 100644 usr.sbin/boot0cfg/Makefile delete mode 100644 usr.sbin/boot0cfg/boot0cfg.8 delete mode 100644 usr.sbin/boot0cfg/boot0cfg.c delete mode 100644 usr.sbin/boot98cfg/Makefile delete mode 100644 usr.sbin/boot98cfg/boot98cfg.8 delete mode 100644 usr.sbin/boot98cfg/boot98cfg.c delete mode 100644 usr.sbin/bootparamd/Makefile delete mode 100644 usr.sbin/bootparamd/Makefile.inc delete mode 100644 usr.sbin/bootparamd/bootparamd/Makefile delete mode 100644 usr.sbin/bootparamd/bootparamd/README delete mode 100644 usr.sbin/bootparamd/bootparamd/bootparamd.8 delete mode 100644 usr.sbin/bootparamd/bootparamd/bootparamd.c delete mode 100644 usr.sbin/bootparamd/bootparamd/bootparams.5 delete mode 100644 usr.sbin/bootparamd/bootparamd/main.c delete mode 100644 usr.sbin/bootparamd/callbootd/Makefile delete mode 100644 usr.sbin/bootparamd/callbootd/callbootd.c delete mode 100644 usr.sbin/bsnmpd/Makefile delete mode 100644 usr.sbin/bsnmpd/Makefile.inc delete mode 100644 usr.sbin/bsnmpd/bsnmpd/Makefile delete mode 100644 usr.sbin/bsnmpd/gensnmptree/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/Makefile.inc delete mode 100644 usr.sbin/bsnmpd/modules/snmp_atm/BEGEMOT-ATM-FREEBSD-MIB.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_atm/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/snmp_atm/atm_freebsd.def delete mode 100644 usr.sbin/bsnmpd/modules/snmp_atm/atm_sys.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/BEGEMOT-BRIDGE-MIB.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/BRIDGE-MIB.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/RSTP-MIB.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/bridge_tree.def delete mode 100644 usr.sbin/bsnmpd/modules/snmp_bridge/snmp_bridge.3 delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/BEGEMOT-HOSTRES-MIB.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_begemot.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_printer_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/hostres_tree.def delete mode 100644 usr.sbin/bsnmpd/modules/snmp_hostres/snmp_hostres.3 delete mode 100644 usr.sbin/bsnmpd/modules/snmp_mibII/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/snmp_netgraph/BEGEMOT-NETGRAPH.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/snmp_netgraph/netgraph_tree.def delete mode 100644 usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.3 delete mode 100644 usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.h delete mode 100644 usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_pf/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def delete mode 100644 usr.sbin/bsnmpd/modules/snmp_wlan/BEGEMOT-WIRELESS-MIB.txt delete mode 100644 usr.sbin/bsnmpd/modules/snmp_wlan/Makefile delete mode 100644 usr.sbin/bsnmpd/modules/snmp_wlan/snmp_wlan.3 delete mode 100644 usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.h delete mode 100644 usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c delete mode 100644 usr.sbin/bsnmpd/modules/snmp_wlan/wlan_tree.def delete mode 100644 usr.sbin/btxld/Makefile delete mode 100644 usr.sbin/btxld/btx.h delete mode 100644 usr.sbin/btxld/btxld.8 delete mode 100644 usr.sbin/btxld/btxld.c delete mode 100644 usr.sbin/btxld/elfh.c delete mode 100644 usr.sbin/btxld/elfh.h delete mode 100644 usr.sbin/burncd/Makefile delete mode 100644 usr.sbin/burncd/burncd.8 delete mode 100644 usr.sbin/burncd/burncd.c delete mode 100644 usr.sbin/cdcontrol/Makefile delete mode 100644 usr.sbin/cdcontrol/cdcontrol.1 delete mode 100644 usr.sbin/cdcontrol/cdcontrol.c delete mode 100644 usr.sbin/chkgrp/Makefile delete mode 100644 usr.sbin/chkgrp/chkgrp.8 delete mode 100644 usr.sbin/chkgrp/chkgrp.c delete mode 100644 usr.sbin/chown/Makefile delete mode 100644 usr.sbin/chown/chgrp.1 delete mode 100644 usr.sbin/chown/chown.8 delete mode 100644 usr.sbin/chown/chown.c delete mode 100644 usr.sbin/chroot/Makefile delete mode 100644 usr.sbin/chroot/chroot.8 delete mode 100644 usr.sbin/chroot/chroot.c delete mode 100644 usr.sbin/ckdist/Makefile delete mode 100644 usr.sbin/ckdist/ckdist.1 delete mode 100644 usr.sbin/ckdist/ckdist.c delete mode 100644 usr.sbin/clear_locks/Makefile delete mode 100644 usr.sbin/clear_locks/clear_locks.8 delete mode 100644 usr.sbin/clear_locks/clear_locks.c delete mode 100644 usr.sbin/config/Makefile delete mode 100644 usr.sbin/config/SMM.doc/0.t delete mode 100644 usr.sbin/config/SMM.doc/1.t delete mode 100644 usr.sbin/config/SMM.doc/2.t delete mode 100644 usr.sbin/config/SMM.doc/3.t delete mode 100644 usr.sbin/config/SMM.doc/4.t delete mode 100644 usr.sbin/config/SMM.doc/5.t delete mode 100644 usr.sbin/config/SMM.doc/6.t delete mode 100644 usr.sbin/config/SMM.doc/a.t delete mode 100644 usr.sbin/config/SMM.doc/b.t delete mode 100644 usr.sbin/config/SMM.doc/c.t delete mode 100644 usr.sbin/config/SMM.doc/d.t delete mode 100644 usr.sbin/config/SMM.doc/e.t delete mode 100644 usr.sbin/config/SMM.doc/spell.ok delete mode 100644 usr.sbin/config/config.5 delete mode 100644 usr.sbin/config/config.8 delete mode 100644 usr.sbin/config/config.h delete mode 100644 usr.sbin/config/config.y delete mode 100644 usr.sbin/config/configvers.h delete mode 100644 usr.sbin/config/kernconf.tmpl delete mode 100644 usr.sbin/config/lang.l delete mode 100644 usr.sbin/config/main.c delete mode 100644 usr.sbin/config/mkheaders.c delete mode 100644 usr.sbin/config/mkmakefile.c delete mode 100644 usr.sbin/config/mkoptions.c delete mode 100644 usr.sbin/cpucontrol/Makefile delete mode 100644 usr.sbin/cpucontrol/amd.c delete mode 100644 usr.sbin/cpucontrol/amd.h delete mode 100644 usr.sbin/cpucontrol/cpucontrol.8 delete mode 100644 usr.sbin/cpucontrol/cpucontrol.c delete mode 100644 usr.sbin/cpucontrol/cpucontrol.h delete mode 100644 usr.sbin/cpucontrol/intel.c delete mode 100644 usr.sbin/cpucontrol/intel.h delete mode 100644 usr.sbin/crashinfo/Makefile delete mode 100644 usr.sbin/crashinfo/crashinfo.8 delete mode 100755 usr.sbin/crashinfo/crashinfo.sh delete mode 100644 usr.sbin/cron/Makefile delete mode 100644 usr.sbin/cron/Makefile.inc delete mode 100644 usr.sbin/cron/cron/Makefile delete mode 100644 usr.sbin/cron/cron/compat.h delete mode 100644 usr.sbin/cron/cron/config.h delete mode 100644 usr.sbin/cron/cron/cron.8 delete mode 100644 usr.sbin/cron/cron/cron.c delete mode 100644 usr.sbin/cron/cron/cron.h delete mode 100644 usr.sbin/cron/cron/database.c delete mode 100644 usr.sbin/cron/cron/do_command.c delete mode 100644 usr.sbin/cron/cron/externs.h delete mode 100644 usr.sbin/cron/cron/job.c delete mode 100644 usr.sbin/cron/cron/pathnames.h delete mode 100644 usr.sbin/cron/cron/popen.c delete mode 100644 usr.sbin/cron/cron/user.c delete mode 100644 usr.sbin/cron/crontab/Makefile delete mode 100644 usr.sbin/cron/crontab/crontab.1 delete mode 100644 usr.sbin/cron/crontab/crontab.5 delete mode 100644 usr.sbin/cron/crontab/crontab.c delete mode 100644 usr.sbin/cron/doc/CHANGES delete mode 100644 usr.sbin/cron/doc/CONVERSION delete mode 100644 usr.sbin/cron/doc/FEATURES delete mode 100644 usr.sbin/cron/doc/INSTALL delete mode 100644 usr.sbin/cron/doc/MAIL delete mode 100644 usr.sbin/cron/doc/Makefile.vixie delete mode 100644 usr.sbin/cron/doc/README delete mode 100644 usr.sbin/cron/doc/README.1ST delete mode 100644 usr.sbin/cron/doc/THANKS delete mode 100644 usr.sbin/cron/lib/Makefile delete mode 100644 usr.sbin/cron/lib/compat.c delete mode 100644 usr.sbin/cron/lib/entry.c delete mode 100644 usr.sbin/cron/lib/env.c delete mode 100644 usr.sbin/cron/lib/misc.c delete mode 100644 usr.sbin/crunch/COPYRIGHT delete mode 100644 usr.sbin/crunch/Makefile delete mode 100644 usr.sbin/crunch/Makefile.inc delete mode 100644 usr.sbin/crunch/README delete mode 100644 usr.sbin/crunch/crunchgen/Makefile delete mode 100644 usr.sbin/crunch/crunchgen/crunched_main.c delete mode 100644 usr.sbin/crunch/crunchgen/crunchgen.1 delete mode 100644 usr.sbin/crunch/crunchgen/crunchgen.c delete mode 100644 usr.sbin/crunch/crunchgen/mkskel.sh delete mode 100644 usr.sbin/crunch/crunchide/Makefile delete mode 100644 usr.sbin/crunch/crunchide/crunchide.1 delete mode 100644 usr.sbin/crunch/crunchide/crunchide.c delete mode 100644 usr.sbin/crunch/crunchide/exec_aout.c delete mode 100644 usr.sbin/crunch/crunchide/exec_elf32.c delete mode 100644 usr.sbin/crunch/crunchide/exec_elf64.c delete mode 100644 usr.sbin/crunch/crunchide/extern.h delete mode 100644 usr.sbin/crunch/examples/Makefile delete mode 100644 usr.sbin/crunch/examples/filesystem.conf delete mode 100644 usr.sbin/crunch/examples/fixit.conf delete mode 100644 usr.sbin/crunch/examples/kcopy.conf delete mode 100644 usr.sbin/crunch/examples/really-big.conf delete mode 100644 usr.sbin/ctm/Makefile delete mode 100644 usr.sbin/ctm/Makefile.inc delete mode 100644 usr.sbin/ctm/README delete mode 100644 usr.sbin/ctm/ctm/Makefile delete mode 100644 usr.sbin/ctm/ctm/ctm.1 delete mode 100644 usr.sbin/ctm/ctm/ctm.5 delete mode 100644 usr.sbin/ctm/ctm/ctm.c delete mode 100644 usr.sbin/ctm/ctm/ctm.h delete mode 100644 usr.sbin/ctm/ctm/ctm_ed.c delete mode 100644 usr.sbin/ctm/ctm/ctm_input.c delete mode 100644 usr.sbin/ctm/ctm/ctm_pass1.c delete mode 100644 usr.sbin/ctm/ctm/ctm_pass2.c delete mode 100644 usr.sbin/ctm/ctm/ctm_pass3.c delete mode 100644 usr.sbin/ctm/ctm/ctm_passb.c delete mode 100644 usr.sbin/ctm/ctm/ctm_syntax.c delete mode 100644 usr.sbin/ctm/ctm_dequeue/Makefile delete mode 100644 usr.sbin/ctm/ctm_dequeue/ctm_dequeue.c delete mode 100644 usr.sbin/ctm/ctm_rmail/Makefile delete mode 100644 usr.sbin/ctm/ctm_rmail/ctm_rmail.1 delete mode 100644 usr.sbin/ctm/ctm_rmail/ctm_rmail.c delete mode 100644 usr.sbin/ctm/ctm_rmail/error.c delete mode 100644 usr.sbin/ctm/ctm_rmail/error.h delete mode 100644 usr.sbin/ctm/ctm_rmail/options.h delete mode 100644 usr.sbin/ctm/ctm_smail/Makefile delete mode 100644 usr.sbin/ctm/ctm_smail/ctm_smail.c delete mode 100644 usr.sbin/ctm/mkCTM/Makefile delete mode 100644 usr.sbin/ctm/mkCTM/ctm_conf.cvs-cur delete mode 100644 usr.sbin/ctm/mkCTM/ctm_conf.gnats delete mode 100644 usr.sbin/ctm/mkCTM/ctm_conf.ports-cur delete mode 100644 usr.sbin/ctm/mkCTM/ctm_conf.smp-cur delete mode 100644 usr.sbin/ctm/mkCTM/ctm_conf.src-cur delete mode 100644 usr.sbin/ctm/mkCTM/ctm_conf.src-special delete mode 100755 usr.sbin/ctm/mkCTM/dequeue delete mode 100644 usr.sbin/ctm/mkCTM/mkCTM delete mode 100644 usr.sbin/ctm/mkCTM/mkctm.c delete mode 100644 usr.sbin/cxgbtool/Makefile delete mode 100644 usr.sbin/cxgbtool/cxgbtool.c delete mode 100644 usr.sbin/cxgbtool/reg_defs.c delete mode 100644 usr.sbin/cxgbtool/reg_defs_t3.c delete mode 100644 usr.sbin/cxgbtool/reg_defs_t3b.c delete mode 100644 usr.sbin/cxgbtool/reg_defs_t3c.c delete mode 100644 usr.sbin/cxgbtool/version.h delete mode 100644 usr.sbin/daemon/Makefile delete mode 100644 usr.sbin/daemon/daemon.8 delete mode 100644 usr.sbin/daemon/daemon.c delete mode 100644 usr.sbin/dconschat/Makefile delete mode 100644 usr.sbin/dconschat/dconschat.8 delete mode 100644 usr.sbin/dconschat/dconschat.c delete mode 100644 usr.sbin/devinfo/Makefile delete mode 100644 usr.sbin/devinfo/devinfo.8 delete mode 100644 usr.sbin/devinfo/devinfo.c delete mode 100644 usr.sbin/digictl/Makefile delete mode 100644 usr.sbin/digictl/digictl.8 delete mode 100644 usr.sbin/digictl/digictl.c delete mode 100644 usr.sbin/diskinfo/Makefile delete mode 100644 usr.sbin/diskinfo/diskinfo.8 delete mode 100644 usr.sbin/diskinfo/diskinfo.c delete mode 100644 usr.sbin/dnssec-dsfromkey/Makefile delete mode 100644 usr.sbin/dnssec-keyfromlabel/Makefile delete mode 100644 usr.sbin/dnssec-keygen/Makefile delete mode 100644 usr.sbin/dnssec-signzone/Makefile delete mode 100644 usr.sbin/dumpcis/Makefile delete mode 100644 usr.sbin/dumpcis/cardinfo.h delete mode 100644 usr.sbin/dumpcis/cis.h delete mode 100644 usr.sbin/dumpcis/dumpcis.8 delete mode 100644 usr.sbin/dumpcis/main.c delete mode 100644 usr.sbin/dumpcis/printcis.c delete mode 100644 usr.sbin/dumpcis/readcis.c delete mode 100644 usr.sbin/dumpcis/readcis.h delete mode 100644 usr.sbin/editmap/Makefile delete mode 100644 usr.sbin/edquota/Makefile delete mode 100644 usr.sbin/edquota/edquota.8 delete mode 100644 usr.sbin/edquota/edquota.c delete mode 100644 usr.sbin/edquota/pathnames.h delete mode 100644 usr.sbin/eeprom/Makefile delete mode 100644 usr.sbin/eeprom/eeprom.8 delete mode 100644 usr.sbin/eeprom/eeprom.c delete mode 100644 usr.sbin/eeprom/ofw_options.c delete mode 100644 usr.sbin/eeprom/ofw_options.h delete mode 100644 usr.sbin/extattr/Makefile delete mode 100644 usr.sbin/extattr/rmextattr.8 delete mode 100644 usr.sbin/extattr/rmextattr.c delete mode 100644 usr.sbin/extattrctl/Makefile delete mode 100644 usr.sbin/extattrctl/extattrctl.8 delete mode 100644 usr.sbin/extattrctl/extattrctl.c delete mode 100644 usr.sbin/faithd/Makefile delete mode 100644 usr.sbin/faithd/README delete mode 100644 usr.sbin/faithd/faithd.8 delete mode 100644 usr.sbin/faithd/faithd.c delete mode 100644 usr.sbin/faithd/faithd.h delete mode 100644 usr.sbin/faithd/ftp.c delete mode 100644 usr.sbin/faithd/prefix.c delete mode 100644 usr.sbin/faithd/prefix.h delete mode 100644 usr.sbin/faithd/tcp.c delete mode 100644 usr.sbin/faithd/test/faithd.rb delete mode 100644 usr.sbin/fdcontrol/Makefile delete mode 100644 usr.sbin/fdcontrol/fdcontrol.8 delete mode 100644 usr.sbin/fdcontrol/fdcontrol.c delete mode 100644 usr.sbin/fdformat/Makefile delete mode 100644 usr.sbin/fdformat/fdformat.1 delete mode 100644 usr.sbin/fdformat/fdformat.c delete mode 100644 usr.sbin/fdread/Makefile delete mode 100644 usr.sbin/fdread/fdread.1 delete mode 100644 usr.sbin/fdread/fdread.c delete mode 100644 usr.sbin/fdread/fdutil.c delete mode 100644 usr.sbin/fdread/fdutil.h delete mode 100644 usr.sbin/fdwrite/Makefile delete mode 100644 usr.sbin/fdwrite/fdwrite.1 delete mode 100644 usr.sbin/fdwrite/fdwrite.c delete mode 100644 usr.sbin/fifolog/Makefile delete mode 100644 usr.sbin/fifolog/Makefile.inc delete mode 100644 usr.sbin/fifolog/fifolog_create/Makefile delete mode 100644 usr.sbin/fifolog/fifolog_create/fifolog.1 delete mode 100644 usr.sbin/fifolog/fifolog_create/fifolog_create.c delete mode 100644 usr.sbin/fifolog/fifolog_reader/Makefile delete mode 100644 usr.sbin/fifolog/fifolog_reader/fifolog_reader.c delete mode 100644 usr.sbin/fifolog/fifolog_writer/Makefile delete mode 100644 usr.sbin/fifolog/fifolog_writer/fifolog_writer.c delete mode 100644 usr.sbin/fifolog/flint.lnt delete mode 100644 usr.sbin/fifolog/lib/Makefile delete mode 100644 usr.sbin/fifolog/lib/fifolog.h delete mode 100644 usr.sbin/fifolog/lib/fifolog_create.c delete mode 100644 usr.sbin/fifolog/lib/fifolog_int.c delete mode 100644 usr.sbin/fifolog/lib/fifolog_reader.c delete mode 100644 usr.sbin/fifolog/lib/fifolog_write.h delete mode 100644 usr.sbin/fifolog/lib/fifolog_write_poll.c delete mode 100644 usr.sbin/fifolog/lib/getdate.y delete mode 100644 usr.sbin/fifolog/lib/libfifolog.h delete mode 100644 usr.sbin/fifolog/lib/libfifolog_int.h delete mode 100644 usr.sbin/fifolog/lib/miniobj.h delete mode 100644 usr.sbin/flowctl/Makefile delete mode 100644 usr.sbin/flowctl/flowctl.8 delete mode 100644 usr.sbin/flowctl/flowctl.c delete mode 100644 usr.sbin/freebsd-update/Makefile delete mode 100644 usr.sbin/freebsd-update/freebsd-update.8 delete mode 100644 usr.sbin/freebsd-update/freebsd-update.sh delete mode 100644 usr.sbin/ftp-proxy/Makefile delete mode 100644 usr.sbin/ftp-proxy/Makefile.inc delete mode 100644 usr.sbin/ftp-proxy/ftp-proxy/Makefile delete mode 100644 usr.sbin/ftp-proxy/libevent/Makefile delete mode 100644 usr.sbin/fwcontrol/Makefile delete mode 100644 usr.sbin/fwcontrol/fwcontrol.8 delete mode 100644 usr.sbin/fwcontrol/fwcontrol.c delete mode 100644 usr.sbin/fwcontrol/fwdv.c delete mode 100644 usr.sbin/fwcontrol/fwmethods.h delete mode 100644 usr.sbin/fwcontrol/fwmpegts.c delete mode 100644 usr.sbin/getfmac/Makefile delete mode 100644 usr.sbin/getfmac/getfmac.8 delete mode 100644 usr.sbin/getfmac/getfmac.c delete mode 100644 usr.sbin/getpmac/Makefile delete mode 100644 usr.sbin/getpmac/getpmac.8 delete mode 100644 usr.sbin/getpmac/getpmac.c delete mode 100644 usr.sbin/gpioctl/Makefile delete mode 100644 usr.sbin/gpioctl/gpioctl.8 delete mode 100644 usr.sbin/gpioctl/gpioctl.c delete mode 100644 usr.sbin/gssd/Makefile delete mode 100644 usr.sbin/gssd/gssd.8 delete mode 100644 usr.sbin/gssd/gssd.c delete mode 100644 usr.sbin/gstat/Makefile delete mode 100644 usr.sbin/gstat/gstat.8 delete mode 100644 usr.sbin/gstat/gstat.c delete mode 100644 usr.sbin/i2c/Makefile delete mode 100644 usr.sbin/i2c/i2c.8 delete mode 100644 usr.sbin/i2c/i2c.c delete mode 100644 usr.sbin/ifmcstat/Makefile delete mode 100644 usr.sbin/ifmcstat/ifmcstat.8 delete mode 100644 usr.sbin/ifmcstat/ifmcstat.c delete mode 100644 usr.sbin/ifmcstat/printb.c delete mode 100644 usr.sbin/inetd/Makefile delete mode 100644 usr.sbin/inetd/builtins.c delete mode 100644 usr.sbin/inetd/inetd.8 delete mode 100644 usr.sbin/inetd/inetd.c delete mode 100644 usr.sbin/inetd/inetd.h delete mode 100644 usr.sbin/inetd/pathnames.h delete mode 100644 usr.sbin/iostat/Makefile delete mode 100644 usr.sbin/iostat/iostat.8 delete mode 100644 usr.sbin/iostat/iostat.c delete mode 100644 usr.sbin/ip6addrctl/Makefile delete mode 100644 usr.sbin/ip6addrctl/ip6addrctl.8 delete mode 100644 usr.sbin/ip6addrctl/ip6addrctl.c delete mode 100644 usr.sbin/ip6addrctl/ip6addrctl.conf.sample delete mode 100644 usr.sbin/ipfwpcap/Makefile delete mode 100644 usr.sbin/ipfwpcap/ipfwpcap.8 delete mode 100644 usr.sbin/ipfwpcap/ipfwpcap.c delete mode 100644 usr.sbin/jexec/Makefile delete mode 100644 usr.sbin/jexec/jexec.8 delete mode 100644 usr.sbin/jexec/jexec.c delete mode 100644 usr.sbin/jls/Makefile delete mode 100644 usr.sbin/jls/jls.8 delete mode 100644 usr.sbin/jls/jls.c delete mode 100644 usr.sbin/kbdcontrol/Makefile delete mode 100644 usr.sbin/kbdcontrol/kbdcontrol.1 delete mode 100644 usr.sbin/kbdcontrol/kbdcontrol.c delete mode 100644 usr.sbin/kbdcontrol/kbdmap.5 delete mode 100644 usr.sbin/kbdcontrol/lex.h delete mode 100644 usr.sbin/kbdcontrol/lex.l delete mode 100644 usr.sbin/kbdcontrol/path.h delete mode 100644 usr.sbin/kbdmap/Languages.phrases delete mode 100644 usr.sbin/kbdmap/Makefile delete mode 100644 usr.sbin/kbdmap/TODO delete mode 100644 usr.sbin/kbdmap/kbdmap.1 delete mode 100644 usr.sbin/kbdmap/kbdmap.c delete mode 100644 usr.sbin/kbdmap/kbdmap.h delete mode 100644 usr.sbin/kernbb/Makefile delete mode 100644 usr.sbin/kernbb/kernbb.8 delete mode 100644 usr.sbin/kernbb/kernbb.c delete mode 100644 usr.sbin/keyserv/Makefile delete mode 100644 usr.sbin/keyserv/crypt_server.c delete mode 100644 usr.sbin/keyserv/keyserv.8 delete mode 100644 usr.sbin/keyserv/keyserv.c delete mode 100644 usr.sbin/keyserv/keyserv.h delete mode 100644 usr.sbin/keyserv/setkey.c delete mode 100644 usr.sbin/kgmon/Makefile delete mode 100644 usr.sbin/kgmon/kgmon.8 delete mode 100644 usr.sbin/kgmon/kgmon.c delete mode 100644 usr.sbin/kgzip/Makefile delete mode 100644 usr.sbin/kgzip/aouthdr.c delete mode 100644 usr.sbin/kgzip/aouthdr.h delete mode 100644 usr.sbin/kgzip/elfhdr.c delete mode 100644 usr.sbin/kgzip/elfhdr.h delete mode 100644 usr.sbin/kgzip/kgz.h delete mode 100644 usr.sbin/kgzip/kgzcmp.c delete mode 100644 usr.sbin/kgzip/kgzip.8 delete mode 100644 usr.sbin/kgzip/kgzip.c delete mode 100644 usr.sbin/kgzip/kgzip.h delete mode 100644 usr.sbin/kgzip/kgzld.c delete mode 100644 usr.sbin/kgzip/xio.c delete mode 100644 usr.sbin/kldxref/Makefile delete mode 100644 usr.sbin/kldxref/ef.c delete mode 100644 usr.sbin/kldxref/ef.h delete mode 100644 usr.sbin/kldxref/ef_amd64.c delete mode 100644 usr.sbin/kldxref/ef_i386.c delete mode 100644 usr.sbin/kldxref/ef_nop.c delete mode 100644 usr.sbin/kldxref/ef_obj.c delete mode 100644 usr.sbin/kldxref/ef_powerpc.c delete mode 100644 usr.sbin/kldxref/ef_sparc64.c delete mode 100644 usr.sbin/kldxref/fileformat delete mode 100644 usr.sbin/kldxref/kldxref.8 delete mode 100644 usr.sbin/kldxref/kldxref.c delete mode 100644 usr.sbin/lastlogin/Makefile delete mode 100644 usr.sbin/lastlogin/lastlogin.8 delete mode 100644 usr.sbin/lastlogin/lastlogin.c delete mode 100644 usr.sbin/lmcconfig/Makefile delete mode 100644 usr.sbin/lmcconfig/lmcconfig.8 delete mode 100644 usr.sbin/lmcconfig/lmcconfig.c delete mode 100644 usr.sbin/lpr/Makefile delete mode 100644 usr.sbin/lpr/Makefile.inc delete mode 100644 usr.sbin/lpr/SMM.doc/0.t delete mode 100644 usr.sbin/lpr/SMM.doc/1.t delete mode 100644 usr.sbin/lpr/SMM.doc/2.t delete mode 100644 usr.sbin/lpr/SMM.doc/3.t delete mode 100644 usr.sbin/lpr/SMM.doc/4.t delete mode 100644 usr.sbin/lpr/SMM.doc/5.t delete mode 100644 usr.sbin/lpr/SMM.doc/6.t delete mode 100644 usr.sbin/lpr/SMM.doc/7.t delete mode 100644 usr.sbin/lpr/SMM.doc/Makefile delete mode 100644 usr.sbin/lpr/SMM.doc/spell.ok delete mode 100644 usr.sbin/lpr/chkprintcap/Makefile delete mode 100644 usr.sbin/lpr/chkprintcap/chkprintcap.8 delete mode 100644 usr.sbin/lpr/chkprintcap/chkprintcap.c delete mode 100644 usr.sbin/lpr/chkprintcap/skimprintcap.c delete mode 100644 usr.sbin/lpr/chkprintcap/skimprintcap.h delete mode 100644 usr.sbin/lpr/common_source/Makefile delete mode 100644 usr.sbin/lpr/common_source/common.c delete mode 100644 usr.sbin/lpr/common_source/ctlinfo.c delete mode 100644 usr.sbin/lpr/common_source/ctlinfo.h delete mode 100644 usr.sbin/lpr/common_source/displayq.c delete mode 100644 usr.sbin/lpr/common_source/lp.cdefs.h delete mode 100644 usr.sbin/lpr/common_source/lp.h delete mode 100644 usr.sbin/lpr/common_source/lp.local.h delete mode 100644 usr.sbin/lpr/common_source/matchjobs.c delete mode 100644 usr.sbin/lpr/common_source/matchjobs.h delete mode 100644 usr.sbin/lpr/common_source/net.c delete mode 100644 usr.sbin/lpr/common_source/pathnames.h delete mode 100644 usr.sbin/lpr/common_source/printcap.c delete mode 100644 usr.sbin/lpr/common_source/request.c delete mode 100644 usr.sbin/lpr/common_source/rmjob.c delete mode 100644 usr.sbin/lpr/common_source/startdaemon.c delete mode 100644 usr.sbin/lpr/filters.ru/Makefile delete mode 100644 usr.sbin/lpr/filters.ru/Makefile.inc delete mode 100644 usr.sbin/lpr/filters.ru/bjc-240.sh.sample delete mode 100644 usr.sbin/lpr/filters.ru/koi2855/Makefile delete mode 100644 usr.sbin/lpr/filters.ru/koi2855/koi2855.c delete mode 100644 usr.sbin/lpr/filters.ru/koi2alt/Makefile delete mode 100644 usr.sbin/lpr/filters.ru/koi2alt/koi2alt.c delete mode 100644 usr.sbin/lpr/filters/Makefile delete mode 100644 usr.sbin/lpr/filters/lpf.c delete mode 100644 usr.sbin/lpr/lp/Makefile delete mode 100644 usr.sbin/lpr/lp/lp.1 delete mode 100644 usr.sbin/lpr/lp/lp.sh delete mode 100644 usr.sbin/lpr/lpc/Makefile delete mode 100644 usr.sbin/lpr/lpc/cmds.c delete mode 100644 usr.sbin/lpr/lpc/cmdtab.c delete mode 100644 usr.sbin/lpr/lpc/extern.h delete mode 100644 usr.sbin/lpr/lpc/lpc.8 delete mode 100644 usr.sbin/lpr/lpc/lpc.c delete mode 100644 usr.sbin/lpr/lpc/lpc.h delete mode 100644 usr.sbin/lpr/lpc/movejobs.c delete mode 100644 usr.sbin/lpr/lpd/Makefile delete mode 100644 usr.sbin/lpr/lpd/extern.h delete mode 100644 usr.sbin/lpr/lpd/lpd.8 delete mode 100644 usr.sbin/lpr/lpd/lpd.c delete mode 100644 usr.sbin/lpr/lpd/lpdchar.c delete mode 100644 usr.sbin/lpr/lpd/modes.c delete mode 100644 usr.sbin/lpr/lpd/printjob.c delete mode 100644 usr.sbin/lpr/lpd/recvjob.c delete mode 100644 usr.sbin/lpr/lpq/Makefile delete mode 100644 usr.sbin/lpr/lpq/lpq.1 delete mode 100644 usr.sbin/lpr/lpq/lpq.c delete mode 100644 usr.sbin/lpr/lpr/Makefile delete mode 100644 usr.sbin/lpr/lpr/lpr.1 delete mode 100644 usr.sbin/lpr/lpr/lpr.c delete mode 100644 usr.sbin/lpr/lpr/printcap.5 delete mode 100644 usr.sbin/lpr/lprm/Makefile delete mode 100644 usr.sbin/lpr/lprm/lprm.1 delete mode 100644 usr.sbin/lpr/lprm/lprm.c delete mode 100644 usr.sbin/lpr/lptest/Makefile delete mode 100644 usr.sbin/lpr/lptest/lptest.1 delete mode 100644 usr.sbin/lpr/lptest/lptest.c delete mode 100644 usr.sbin/lpr/pac/Makefile delete mode 100644 usr.sbin/lpr/pac/pac.8 delete mode 100644 usr.sbin/lpr/pac/pac.c delete mode 100644 usr.sbin/lptcontrol/Makefile delete mode 100644 usr.sbin/lptcontrol/lptcontrol.8 delete mode 100644 usr.sbin/lptcontrol/lptcontrol.c delete mode 100644 usr.sbin/mailstats/Makefile delete mode 100644 usr.sbin/mailwrapper/Makefile delete mode 100644 usr.sbin/mailwrapper/mailwrapper.8 delete mode 100644 usr.sbin/mailwrapper/mailwrapper.c delete mode 100644 usr.sbin/mailwrapper/pathnames.h delete mode 100644 usr.sbin/makefs/Makefile delete mode 100644 usr.sbin/makefs/compat/pwcache.c delete mode 100644 usr.sbin/makefs/compat/pwcache.h delete mode 100644 usr.sbin/makefs/compat/strsuftoll.c delete mode 100644 usr.sbin/makefs/ffs.c delete mode 100644 usr.sbin/makefs/ffs/buf.c delete mode 100644 usr.sbin/makefs/ffs/buf.h delete mode 100644 usr.sbin/makefs/ffs/ffs_alloc.c delete mode 100644 usr.sbin/makefs/ffs/ffs_balloc.c delete mode 100644 usr.sbin/makefs/ffs/ffs_bswap.c delete mode 100644 usr.sbin/makefs/ffs/ffs_extern.h delete mode 100644 usr.sbin/makefs/ffs/ffs_subr.c delete mode 100644 usr.sbin/makefs/ffs/mkfs.c delete mode 100644 usr.sbin/makefs/ffs/newfs_extern.h delete mode 100644 usr.sbin/makefs/ffs/ufs_bmap.c delete mode 100644 usr.sbin/makefs/ffs/ufs_bswap.h delete mode 100644 usr.sbin/makefs/ffs/ufs_inode.h delete mode 100644 usr.sbin/makefs/getid.c delete mode 100644 usr.sbin/makefs/makefs.8 delete mode 100644 usr.sbin/makefs/makefs.c delete mode 100644 usr.sbin/makefs/makefs.h delete mode 100644 usr.sbin/makefs/walk.c delete mode 100644 usr.sbin/makemap/Makefile delete mode 100644 usr.sbin/manctl/Makefile delete mode 100644 usr.sbin/manctl/manctl.8 delete mode 100644 usr.sbin/manctl/manctl.sh delete mode 100644 usr.sbin/memcontrol/Makefile delete mode 100644 usr.sbin/memcontrol/memcontrol.8 delete mode 100644 usr.sbin/memcontrol/memcontrol.c delete mode 100644 usr.sbin/mergemaster/Makefile delete mode 100644 usr.sbin/mergemaster/mergemaster.8 delete mode 100755 usr.sbin/mergemaster/mergemaster.sh delete mode 100644 usr.sbin/mfiutil/Makefile delete mode 100644 usr.sbin/mfiutil/mfi_cmd.c delete mode 100644 usr.sbin/mfiutil/mfi_config.c delete mode 100644 usr.sbin/mfiutil/mfi_drive.c delete mode 100644 usr.sbin/mfiutil/mfi_evt.c delete mode 100644 usr.sbin/mfiutil/mfi_flash.c delete mode 100644 usr.sbin/mfiutil/mfi_patrol.c delete mode 100644 usr.sbin/mfiutil/mfi_show.c delete mode 100644 usr.sbin/mfiutil/mfi_volume.c delete mode 100644 usr.sbin/mfiutil/mfiutil.8 delete mode 100644 usr.sbin/mfiutil/mfiutil.c delete mode 100644 usr.sbin/mfiutil/mfiutil.h delete mode 100644 usr.sbin/mixer/Makefile delete mode 100644 usr.sbin/mixer/mixer.8 delete mode 100644 usr.sbin/mixer/mixer.c delete mode 100644 usr.sbin/mld6query/Makefile delete mode 100644 usr.sbin/mld6query/mld6.c delete mode 100644 usr.sbin/mld6query/mld6query.8 delete mode 100644 usr.sbin/mlxcontrol/Makefile delete mode 100644 usr.sbin/mlxcontrol/command.c delete mode 100644 usr.sbin/mlxcontrol/config.c delete mode 100644 usr.sbin/mlxcontrol/interface.c delete mode 100644 usr.sbin/mlxcontrol/mlxcontrol.8 delete mode 100644 usr.sbin/mlxcontrol/mlxcontrol.h delete mode 100644 usr.sbin/mlxcontrol/util.c delete mode 100644 usr.sbin/mount_nwfs/Makefile delete mode 100644 usr.sbin/mount_nwfs/mount_nwfs.8 delete mode 100644 usr.sbin/mount_nwfs/mount_nwfs.c delete mode 100644 usr.sbin/mount_portalfs/Makefile delete mode 100644 usr.sbin/mount_portalfs/activate.c delete mode 100644 usr.sbin/mount_portalfs/conf.c delete mode 100644 usr.sbin/mount_portalfs/cred.c delete mode 100644 usr.sbin/mount_portalfs/mount_portalfs.8 delete mode 100644 usr.sbin/mount_portalfs/mount_portalfs.c delete mode 100644 usr.sbin/mount_portalfs/pathnames.h delete mode 100644 usr.sbin/mount_portalfs/portal.conf delete mode 100644 usr.sbin/mount_portalfs/portald.h delete mode 100644 usr.sbin/mount_portalfs/pt_conf.c delete mode 100644 usr.sbin/mount_portalfs/pt_exec.c delete mode 100644 usr.sbin/mount_portalfs/pt_file.c delete mode 100644 usr.sbin/mount_portalfs/pt_pipe.c delete mode 100644 usr.sbin/mount_portalfs/pt_tcp.c delete mode 100644 usr.sbin/mount_portalfs/pt_tcplisten.c delete mode 100644 usr.sbin/mount_smbfs/Makefile delete mode 100644 usr.sbin/mountd/Makefile delete mode 100644 usr.sbin/mountd/exports.5 delete mode 100644 usr.sbin/mountd/mountd.8 delete mode 100644 usr.sbin/mountd/mountd.c delete mode 100644 usr.sbin/mountd/netgroup.5 delete mode 100644 usr.sbin/mountd/pathnames.h delete mode 100644 usr.sbin/moused/Makefile delete mode 100644 usr.sbin/moused/moused.8 delete mode 100644 usr.sbin/moused/moused.c delete mode 100644 usr.sbin/mptable/Makefile delete mode 100644 usr.sbin/mptable/mptable.1 delete mode 100644 usr.sbin/mptable/mptable.c delete mode 100644 usr.sbin/mptutil/Makefile delete mode 100644 usr.sbin/mptutil/mpt_cam.c delete mode 100644 usr.sbin/mptutil/mpt_cmd.c delete mode 100644 usr.sbin/mptutil/mpt_config.c delete mode 100644 usr.sbin/mptutil/mpt_drive.c delete mode 100644 usr.sbin/mptutil/mpt_evt.c delete mode 100644 usr.sbin/mptutil/mpt_show.c delete mode 100644 usr.sbin/mptutil/mpt_volume.c delete mode 100644 usr.sbin/mptutil/mptutil.8 delete mode 100644 usr.sbin/mptutil/mptutil.c delete mode 100644 usr.sbin/mptutil/mptutil.h delete mode 100644 usr.sbin/mtest/Makefile delete mode 100644 usr.sbin/mtest/mtest.8 delete mode 100644 usr.sbin/mtest/mtest.c delete mode 100644 usr.sbin/mtree/Makefile delete mode 100644 usr.sbin/mtree/compare.c delete mode 100644 usr.sbin/mtree/create.c delete mode 100644 usr.sbin/mtree/excludes.c delete mode 100644 usr.sbin/mtree/extern.h delete mode 100644 usr.sbin/mtree/misc.c delete mode 100644 usr.sbin/mtree/mtree.5 delete mode 100644 usr.sbin/mtree/mtree.8 delete mode 100644 usr.sbin/mtree/mtree.c delete mode 100644 usr.sbin/mtree/mtree.h delete mode 100644 usr.sbin/mtree/spec.c delete mode 100644 usr.sbin/mtree/specspec.c delete mode 100644 usr.sbin/mtree/test/test00.sh delete mode 100644 usr.sbin/mtree/test/test01.sh delete mode 100644 usr.sbin/mtree/test/test02.sh delete mode 100644 usr.sbin/mtree/test/test03.sh delete mode 100644 usr.sbin/mtree/test/test04.sh delete mode 100644 usr.sbin/mtree/test/test05.sh delete mode 100644 usr.sbin/mtree/verify.c delete mode 100644 usr.sbin/named-checkconf/Makefile delete mode 100644 usr.sbin/named-checkzone/Makefile delete mode 100644 usr.sbin/named.reload/Makefile delete mode 100644 usr.sbin/named.reload/named.reload.8 delete mode 100644 usr.sbin/named.reload/named.reload.sh delete mode 100644 usr.sbin/named/Makefile delete mode 100644 usr.sbin/ndiscvt/Makefile delete mode 100644 usr.sbin/ndiscvt/inf-parse.y delete mode 100644 usr.sbin/ndiscvt/inf-token.l delete mode 100644 usr.sbin/ndiscvt/inf.c delete mode 100644 usr.sbin/ndiscvt/inf.h delete mode 100644 usr.sbin/ndiscvt/ndiscvt.8 delete mode 100644 usr.sbin/ndiscvt/ndiscvt.c delete mode 100644 usr.sbin/ndiscvt/ndisgen.8 delete mode 100644 usr.sbin/ndiscvt/ndisgen.sh delete mode 100644 usr.sbin/ndiscvt/windrv_stub.c delete mode 100644 usr.sbin/ndp/Makefile delete mode 100644 usr.sbin/ndp/ndp.8 delete mode 100644 usr.sbin/ndp/ndp.c delete mode 100644 usr.sbin/newsyslog/Makefile delete mode 100644 usr.sbin/newsyslog/extern.h delete mode 100644 usr.sbin/newsyslog/newsyslog.8 delete mode 100644 usr.sbin/newsyslog/newsyslog.c delete mode 100644 usr.sbin/newsyslog/newsyslog.conf.5 delete mode 100644 usr.sbin/newsyslog/pathnames.h delete mode 100644 usr.sbin/newsyslog/ptimes.c delete mode 100644 usr.sbin/nfscbd/Makefile delete mode 100644 usr.sbin/nfscbd/nfscbd.8 delete mode 100644 usr.sbin/nfscbd/nfscbd.c delete mode 100644 usr.sbin/nfsd/Makefile delete mode 100644 usr.sbin/nfsd/nfsd.8 delete mode 100644 usr.sbin/nfsd/nfsd.c delete mode 100644 usr.sbin/nfsd/nfsv4.4 delete mode 100644 usr.sbin/nfsd/stablerestart.5 delete mode 100644 usr.sbin/nfsdumpstate/Makefile delete mode 100644 usr.sbin/nfsdumpstate/nfsdumpstate.8 delete mode 100644 usr.sbin/nfsdumpstate/nfsdumpstate.c delete mode 100644 usr.sbin/nfsrevoke/Makefile delete mode 100644 usr.sbin/nfsrevoke/nfsrevoke.8 delete mode 100644 usr.sbin/nfsrevoke/nfsrevoke.c delete mode 100644 usr.sbin/nfsuserd/Makefile delete mode 100644 usr.sbin/nfsuserd/nfsuserd.8 delete mode 100644 usr.sbin/nfsuserd/nfsuserd.c delete mode 100644 usr.sbin/ngctl/Makefile delete mode 100644 usr.sbin/ngctl/config.c delete mode 100644 usr.sbin/ngctl/connect.c delete mode 100644 usr.sbin/ngctl/debug.c delete mode 100644 usr.sbin/ngctl/dot.c delete mode 100644 usr.sbin/ngctl/list.c delete mode 100644 usr.sbin/ngctl/main.c delete mode 100644 usr.sbin/ngctl/mkpeer.c delete mode 100644 usr.sbin/ngctl/msg.c delete mode 100644 usr.sbin/ngctl/name.c delete mode 100644 usr.sbin/ngctl/ngctl.8 delete mode 100644 usr.sbin/ngctl/ngctl.h delete mode 100644 usr.sbin/ngctl/rmhook.c delete mode 100644 usr.sbin/ngctl/show.c delete mode 100644 usr.sbin/ngctl/shutdown.c delete mode 100644 usr.sbin/ngctl/status.c delete mode 100644 usr.sbin/ngctl/types.c delete mode 100644 usr.sbin/ngctl/write.c delete mode 100644 usr.sbin/nghook/Makefile delete mode 100644 usr.sbin/nghook/main.c delete mode 100644 usr.sbin/nghook/nghook.8 delete mode 100644 usr.sbin/nologin/Makefile delete mode 100644 usr.sbin/nologin/nologin.5 delete mode 100644 usr.sbin/nologin/nologin.8 delete mode 100644 usr.sbin/nologin/nologin.c delete mode 100644 usr.sbin/nscd/Makefile delete mode 100644 usr.sbin/nscd/agent.c delete mode 100644 usr.sbin/nscd/agent.h delete mode 100644 usr.sbin/nscd/agents/Makefile.inc delete mode 100644 usr.sbin/nscd/agents/group.c delete mode 100644 usr.sbin/nscd/agents/group.h delete mode 100644 usr.sbin/nscd/agents/passwd.c delete mode 100644 usr.sbin/nscd/agents/passwd.h delete mode 100644 usr.sbin/nscd/agents/services.c delete mode 100644 usr.sbin/nscd/agents/services.h delete mode 100644 usr.sbin/nscd/cachelib.c delete mode 100644 usr.sbin/nscd/cachelib.h delete mode 100644 usr.sbin/nscd/cacheplcs.c delete mode 100644 usr.sbin/nscd/cacheplcs.h delete mode 100644 usr.sbin/nscd/config.c delete mode 100644 usr.sbin/nscd/config.h delete mode 100644 usr.sbin/nscd/debug.c delete mode 100644 usr.sbin/nscd/debug.h delete mode 100644 usr.sbin/nscd/hashtable.h delete mode 100644 usr.sbin/nscd/log.c delete mode 100644 usr.sbin/nscd/log.h delete mode 100644 usr.sbin/nscd/mp_rs_query.c delete mode 100644 usr.sbin/nscd/mp_rs_query.h delete mode 100644 usr.sbin/nscd/mp_ws_query.c delete mode 100644 usr.sbin/nscd/mp_ws_query.h delete mode 100644 usr.sbin/nscd/nscd.8 delete mode 100644 usr.sbin/nscd/nscd.c delete mode 100644 usr.sbin/nscd/nscd.conf.5 delete mode 100644 usr.sbin/nscd/nscdcli.c delete mode 100644 usr.sbin/nscd/nscdcli.h delete mode 100644 usr.sbin/nscd/parser.c delete mode 100644 usr.sbin/nscd/parser.h delete mode 100644 usr.sbin/nscd/protocol.c delete mode 100644 usr.sbin/nscd/protocol.h delete mode 100644 usr.sbin/nscd/query.c delete mode 100644 usr.sbin/nscd/query.h delete mode 100644 usr.sbin/nscd/singletons.c delete mode 100644 usr.sbin/nscd/singletons.h delete mode 100644 usr.sbin/ntp/Makefile delete mode 100644 usr.sbin/ntp/Makefile.inc delete mode 100644 usr.sbin/ntp/config.h delete mode 100644 usr.sbin/ntp/doc/Makefile delete mode 100644 usr.sbin/ntp/doc/ntp-keygen.8 delete mode 100644 usr.sbin/ntp/doc/ntp.conf.5 delete mode 100644 usr.sbin/ntp/doc/ntp.keys.5 delete mode 100644 usr.sbin/ntp/doc/ntpd.8 delete mode 100644 usr.sbin/ntp/doc/ntpdate.8 delete mode 100644 usr.sbin/ntp/doc/ntpdc.8 delete mode 100644 usr.sbin/ntp/doc/ntpq.8 delete mode 100644 usr.sbin/ntp/doc/ntptime.8 delete mode 100644 usr.sbin/ntp/doc/ntptrace.8 delete mode 100644 usr.sbin/ntp/libntp/Makefile delete mode 100644 usr.sbin/ntp/libopts/Makefile delete mode 100644 usr.sbin/ntp/libparse/Makefile delete mode 100644 usr.sbin/ntp/ntp-keygen/Makefile delete mode 100644 usr.sbin/ntp/ntpd/Makefile delete mode 100644 usr.sbin/ntp/ntpdate/Makefile delete mode 100644 usr.sbin/ntp/ntpdc/Makefile delete mode 100644 usr.sbin/ntp/ntpq/Makefile delete mode 100644 usr.sbin/ntp/ntptime/Makefile delete mode 100755 usr.sbin/ntp/scripts/mkver delete mode 100644 usr.sbin/ntp/scripts/ntptrace delete mode 100755 usr.sbin/ntp/scripts/ntpver delete mode 100644 usr.sbin/ntp/sntp/Makefile delete mode 100644 usr.sbin/nvram/Makefile delete mode 100644 usr.sbin/nvram/nvram.8 delete mode 100644 usr.sbin/nvram/nvram.c delete mode 100644 usr.sbin/ofwdump/Makefile delete mode 100644 usr.sbin/ofwdump/ofw_util.c delete mode 100644 usr.sbin/ofwdump/ofw_util.h delete mode 100644 usr.sbin/ofwdump/ofwdump.8 delete mode 100644 usr.sbin/ofwdump/ofwdump.c delete mode 100644 usr.sbin/ofwdump/pathnames.h delete mode 100644 usr.sbin/pc-sysinstall/Makefile delete mode 100644 usr.sbin/pc-sysinstall/Makefile.inc delete mode 100644 usr.sbin/pc-sysinstall/backend-partmanager/Makefile delete mode 100755 usr.sbin/pc-sysinstall/backend-partmanager/create-part.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-partmanager/delete-part.sh delete mode 100644 usr.sbin/pc-sysinstall/backend-query/Makefile delete mode 100755 usr.sbin/pc-sysinstall/backend-query/detect-emulation.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/detect-laptop.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/detect-nics.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/disk-info.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/disk-list.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/disk-part.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/enable-net.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/get-packages.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/list-components.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/list-config.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/list-mirrors.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/list-packages.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/list-rsync-backups.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/list-tzones.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/query-langs.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/send-logs.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/set-mirror.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/setup-ssh-keys.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/sys-mem.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/test-live.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/test-netup.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/update-part-list.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/xkeyboard-layouts.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/xkeyboard-models.sh delete mode 100755 usr.sbin/pc-sysinstall/backend-query/xkeyboard-variants.sh delete mode 100644 usr.sbin/pc-sysinstall/backend/Makefile delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-bsdlabel.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-cleanup.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-disk.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-extractimage.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-ftp.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-installcomponents.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-installpackages.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-localize.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-mountdisk.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-mountoptical.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-networking.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-newfs.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-packages.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-parse.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-runcommands.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-unmount.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-upgrade.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions-users.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/functions.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/installimage.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/parseconfig.sh delete mode 100755 usr.sbin/pc-sysinstall/backend/startautoinstall.sh delete mode 100644 usr.sbin/pc-sysinstall/conf/Makefile delete mode 100644 usr.sbin/pc-sysinstall/conf/avail-langs delete mode 100644 usr.sbin/pc-sysinstall/conf/exclude-from-upgrade delete mode 100644 usr.sbin/pc-sysinstall/conf/licenses/bsd-en.txt delete mode 100644 usr.sbin/pc-sysinstall/conf/licenses/intel-en.txt delete mode 100644 usr.sbin/pc-sysinstall/conf/licenses/nvidia-en.txt delete mode 100644 usr.sbin/pc-sysinstall/conf/pc-sysinstall.conf delete mode 100644 usr.sbin/pc-sysinstall/doc/Makefile delete mode 100644 usr.sbin/pc-sysinstall/doc/help-disk-list delete mode 100644 usr.sbin/pc-sysinstall/doc/help-disk-size delete mode 100644 usr.sbin/pc-sysinstall/doc/help-index delete mode 100644 usr.sbin/pc-sysinstall/doc/help-start-autoinstall delete mode 100644 usr.sbin/pc-sysinstall/examples/Makefile delete mode 100644 usr.sbin/pc-sysinstall/examples/README delete mode 100644 usr.sbin/pc-sysinstall/examples/pc-autoinstall.conf delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.fbsd-netinstall delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.geli delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.gmirror delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.netinstall delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.restore delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.rsync delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.upgrade delete mode 100644 usr.sbin/pc-sysinstall/examples/pcinstall.cfg.zfs delete mode 100644 usr.sbin/pc-sysinstall/pc-sysinstall/Makefile delete mode 100644 usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.8 delete mode 100755 usr.sbin/pc-sysinstall/pc-sysinstall/pc-sysinstall.sh delete mode 100644 usr.sbin/pciconf/Makefile delete mode 100644 usr.sbin/pciconf/cap.c delete mode 100644 usr.sbin/pciconf/pathnames.h delete mode 100644 usr.sbin/pciconf/pciconf.8 delete mode 100644 usr.sbin/pciconf/pciconf.c delete mode 100644 usr.sbin/pciconf/pciconf.h delete mode 100644 usr.sbin/periodic/Makefile delete mode 100644 usr.sbin/periodic/periodic.8 delete mode 100644 usr.sbin/periodic/periodic.sh delete mode 100644 usr.sbin/pkg_install/Makefile delete mode 100644 usr.sbin/pkg_install/Makefile.inc delete mode 100644 usr.sbin/pkg_install/README delete mode 100644 usr.sbin/pkg_install/add/Makefile delete mode 100644 usr.sbin/pkg_install/add/add.h delete mode 100644 usr.sbin/pkg_install/add/extract.c delete mode 100644 usr.sbin/pkg_install/add/futil.c delete mode 100644 usr.sbin/pkg_install/add/main.c delete mode 100644 usr.sbin/pkg_install/add/perform.c delete mode 100644 usr.sbin/pkg_install/add/pkg_add.1 delete mode 100644 usr.sbin/pkg_install/create/Makefile delete mode 100644 usr.sbin/pkg_install/create/create.h delete mode 100644 usr.sbin/pkg_install/create/main.c delete mode 100644 usr.sbin/pkg_install/create/perform.c delete mode 100644 usr.sbin/pkg_install/create/pkg_create.1 delete mode 100644 usr.sbin/pkg_install/create/pl.c delete mode 100644 usr.sbin/pkg_install/delete/Makefile delete mode 100644 usr.sbin/pkg_install/delete/delete.h delete mode 100644 usr.sbin/pkg_install/delete/main.c delete mode 100644 usr.sbin/pkg_install/delete/perform.c delete mode 100644 usr.sbin/pkg_install/delete/pkg_delete.1 delete mode 100644 usr.sbin/pkg_install/info/Makefile delete mode 100644 usr.sbin/pkg_install/info/info.h delete mode 100644 usr.sbin/pkg_install/info/main.c delete mode 100644 usr.sbin/pkg_install/info/perform.c delete mode 100644 usr.sbin/pkg_install/info/pkg_info.1 delete mode 100644 usr.sbin/pkg_install/info/show.c delete mode 100755 usr.sbin/pkg_install/tkpkg delete mode 100644 usr.sbin/pkg_install/updating/Makefile delete mode 100644 usr.sbin/pkg_install/updating/main.c delete mode 100644 usr.sbin/pkg_install/updating/pathnames.h delete mode 100644 usr.sbin/pkg_install/updating/pkg_updating.1 delete mode 100644 usr.sbin/pkg_install/version/Makefile delete mode 100644 usr.sbin/pkg_install/version/main.c delete mode 100644 usr.sbin/pkg_install/version/perform.c delete mode 100644 usr.sbin/pkg_install/version/pkg_version.1 delete mode 100755 usr.sbin/pkg_install/version/test-pkg_version.sh delete mode 100644 usr.sbin/pkg_install/version/version.h delete mode 100644 usr.sbin/pmcannotate/Makefile delete mode 100644 usr.sbin/pmcannotate/pmcannotate.8 delete mode 100644 usr.sbin/pmcannotate/pmcannotate.c delete mode 100644 usr.sbin/pmccontrol/Makefile delete mode 100644 usr.sbin/pmccontrol/pmccontrol.8 delete mode 100644 usr.sbin/pmccontrol/pmccontrol.c delete mode 100644 usr.sbin/pmcstat/Makefile delete mode 100644 usr.sbin/pmcstat/pmcpl_annotate.c delete mode 100644 usr.sbin/pmcstat/pmcpl_annotate.h delete mode 100644 usr.sbin/pmcstat/pmcpl_callgraph.c delete mode 100644 usr.sbin/pmcstat/pmcpl_callgraph.h delete mode 100644 usr.sbin/pmcstat/pmcpl_calltree.c delete mode 100644 usr.sbin/pmcstat/pmcpl_calltree.h delete mode 100644 usr.sbin/pmcstat/pmcpl_gprof.c delete mode 100644 usr.sbin/pmcstat/pmcpl_gprof.h delete mode 100644 usr.sbin/pmcstat/pmcstat.8 delete mode 100644 usr.sbin/pmcstat/pmcstat.c delete mode 100644 usr.sbin/pmcstat/pmcstat.h delete mode 100644 usr.sbin/pmcstat/pmcstat_log.c delete mode 100644 usr.sbin/pmcstat/pmcstat_log.h delete mode 100644 usr.sbin/pmcstat/pmcstat_top.h delete mode 100644 usr.sbin/pnpinfo/Makefile delete mode 100644 usr.sbin/portsnap/Makefile delete mode 100644 usr.sbin/portsnap/Makefile.inc delete mode 100644 usr.sbin/portsnap/make_index/Makefile delete mode 100644 usr.sbin/portsnap/make_index/make_index.c delete mode 100644 usr.sbin/portsnap/phttpget/Makefile delete mode 100644 usr.sbin/portsnap/phttpget/phttpget.c delete mode 100644 usr.sbin/portsnap/portsnap/Makefile delete mode 100644 usr.sbin/portsnap/portsnap/portsnap.8 delete mode 100644 usr.sbin/portsnap/portsnap/portsnap.sh delete mode 100644 usr.sbin/powerd/Makefile delete mode 100644 usr.sbin/powerd/powerd.8 delete mode 100644 usr.sbin/powerd/powerd.c delete mode 100644 usr.sbin/ppp/Makefile delete mode 100644 usr.sbin/ppp/README.changes delete mode 100644 usr.sbin/ppp/README.nat delete mode 100644 usr.sbin/ppp/acf.c delete mode 100644 usr.sbin/ppp/acf.h delete mode 100644 usr.sbin/ppp/arp.c delete mode 100644 usr.sbin/ppp/arp.h delete mode 100644 usr.sbin/ppp/async.c delete mode 100644 usr.sbin/ppp/async.h delete mode 100644 usr.sbin/ppp/atm.c delete mode 100644 usr.sbin/ppp/atm.h delete mode 100644 usr.sbin/ppp/auth.c delete mode 100644 usr.sbin/ppp/auth.h delete mode 100644 usr.sbin/ppp/bundle.c delete mode 100644 usr.sbin/ppp/bundle.h delete mode 100644 usr.sbin/ppp/cbcp.c delete mode 100644 usr.sbin/ppp/cbcp.h delete mode 100644 usr.sbin/ppp/ccp.c delete mode 100644 usr.sbin/ppp/ccp.h delete mode 100644 usr.sbin/ppp/chap.c delete mode 100644 usr.sbin/ppp/chap.h delete mode 100644 usr.sbin/ppp/chap_ms.c delete mode 100644 usr.sbin/ppp/chap_ms.h delete mode 100644 usr.sbin/ppp/chat.c delete mode 100644 usr.sbin/ppp/chat.h delete mode 100644 usr.sbin/ppp/command.c delete mode 100644 usr.sbin/ppp/command.h delete mode 100644 usr.sbin/ppp/datalink.c delete mode 100644 usr.sbin/ppp/datalink.h delete mode 100644 usr.sbin/ppp/deflate.c delete mode 100644 usr.sbin/ppp/deflate.h delete mode 100644 usr.sbin/ppp/defs.c delete mode 100644 usr.sbin/ppp/defs.h delete mode 100644 usr.sbin/ppp/descriptor.h delete mode 100644 usr.sbin/ppp/ether.c delete mode 100644 usr.sbin/ppp/ether.h delete mode 100644 usr.sbin/ppp/exec.c delete mode 100644 usr.sbin/ppp/exec.h delete mode 100644 usr.sbin/ppp/filter.c delete mode 100644 usr.sbin/ppp/filter.h delete mode 100644 usr.sbin/ppp/fsm.c delete mode 100644 usr.sbin/ppp/fsm.h delete mode 100644 usr.sbin/ppp/hdlc.c delete mode 100644 usr.sbin/ppp/hdlc.h delete mode 100644 usr.sbin/ppp/i4b.h delete mode 100644 usr.sbin/ppp/id.c delete mode 100644 usr.sbin/ppp/id.h delete mode 100644 usr.sbin/ppp/iface.c delete mode 100644 usr.sbin/ppp/iface.h delete mode 100644 usr.sbin/ppp/ip.c delete mode 100644 usr.sbin/ppp/ip.h delete mode 100644 usr.sbin/ppp/ipcp.c delete mode 100644 usr.sbin/ppp/ipcp.h delete mode 100644 usr.sbin/ppp/iplist.c delete mode 100644 usr.sbin/ppp/iplist.h delete mode 100644 usr.sbin/ppp/ipv6cp.c delete mode 100644 usr.sbin/ppp/ipv6cp.h delete mode 100644 usr.sbin/ppp/layer.h delete mode 100644 usr.sbin/ppp/lcp.c delete mode 100644 usr.sbin/ppp/lcp.h delete mode 100644 usr.sbin/ppp/link.c delete mode 100644 usr.sbin/ppp/link.h delete mode 100644 usr.sbin/ppp/log.c delete mode 100644 usr.sbin/ppp/log.h delete mode 100644 usr.sbin/ppp/lqr.c delete mode 100644 usr.sbin/ppp/lqr.h delete mode 100644 usr.sbin/ppp/main.c delete mode 100644 usr.sbin/ppp/main.h delete mode 100644 usr.sbin/ppp/mbuf.c delete mode 100644 usr.sbin/ppp/mbuf.h delete mode 100644 usr.sbin/ppp/mp.c delete mode 100644 usr.sbin/ppp/mp.h delete mode 100644 usr.sbin/ppp/mppe.c delete mode 100644 usr.sbin/ppp/mppe.h delete mode 100644 usr.sbin/ppp/nat_cmd.c delete mode 100644 usr.sbin/ppp/nat_cmd.h delete mode 100644 usr.sbin/ppp/ncp.c delete mode 100644 usr.sbin/ppp/ncp.h delete mode 100644 usr.sbin/ppp/ncpaddr.c delete mode 100644 usr.sbin/ppp/ncpaddr.h delete mode 100644 usr.sbin/ppp/netgraph.c delete mode 100644 usr.sbin/ppp/netgraph.h delete mode 100644 usr.sbin/ppp/pap.c delete mode 100644 usr.sbin/ppp/pap.h delete mode 100644 usr.sbin/ppp/physical.c delete mode 100644 usr.sbin/ppp/physical.h delete mode 100644 usr.sbin/ppp/ppp.8.m4 delete mode 100644 usr.sbin/ppp/pred.c delete mode 100644 usr.sbin/ppp/pred.h delete mode 100644 usr.sbin/ppp/probe.c delete mode 100644 usr.sbin/ppp/probe.h delete mode 100644 usr.sbin/ppp/prompt.c delete mode 100644 usr.sbin/ppp/prompt.h delete mode 100644 usr.sbin/ppp/proto.c delete mode 100644 usr.sbin/ppp/proto.h delete mode 100644 usr.sbin/ppp/radius.c delete mode 100644 usr.sbin/ppp/radius.h delete mode 100644 usr.sbin/ppp/route.c delete mode 100644 usr.sbin/ppp/route.h delete mode 100644 usr.sbin/ppp/server.c delete mode 100644 usr.sbin/ppp/server.h delete mode 100644 usr.sbin/ppp/sig.c delete mode 100644 usr.sbin/ppp/sig.h delete mode 100644 usr.sbin/ppp/slcompress.c delete mode 100644 usr.sbin/ppp/slcompress.h delete mode 100644 usr.sbin/ppp/sync.c delete mode 100644 usr.sbin/ppp/sync.h delete mode 100644 usr.sbin/ppp/systems.c delete mode 100644 usr.sbin/ppp/systems.h delete mode 100644 usr.sbin/ppp/tcp.c delete mode 100644 usr.sbin/ppp/tcp.h delete mode 100644 usr.sbin/ppp/tcpmss.c delete mode 100644 usr.sbin/ppp/tcpmss.h delete mode 100644 usr.sbin/ppp/throughput.c delete mode 100644 usr.sbin/ppp/throughput.h delete mode 100644 usr.sbin/ppp/timer.c delete mode 100644 usr.sbin/ppp/timer.h delete mode 100644 usr.sbin/ppp/tty.c delete mode 100644 usr.sbin/ppp/tty.h delete mode 100644 usr.sbin/ppp/tun.c delete mode 100644 usr.sbin/ppp/tun.h delete mode 100644 usr.sbin/ppp/ua.h delete mode 100644 usr.sbin/ppp/udp.c delete mode 100644 usr.sbin/ppp/udp.h delete mode 100644 usr.sbin/ppp/vjcomp.c delete mode 100644 usr.sbin/ppp/vjcomp.h delete mode 100644 usr.sbin/pppctl/Makefile delete mode 100644 usr.sbin/pppctl/pppctl.8 delete mode 100644 usr.sbin/pppctl/pppctl.c delete mode 100644 usr.sbin/praliases/Makefile delete mode 100644 usr.sbin/praudit/Makefile delete mode 100644 usr.sbin/procctl/Makefile delete mode 100644 usr.sbin/procctl/procctl.8 delete mode 100644 usr.sbin/procctl/procctl.c delete mode 100644 usr.sbin/pstat/Makefile delete mode 100644 usr.sbin/pstat/pstat.8 delete mode 100644 usr.sbin/pstat/pstat.c delete mode 100644 usr.sbin/pw/Makefile delete mode 100644 usr.sbin/pw/README delete mode 100644 usr.sbin/pw/bitmap.c delete mode 100644 usr.sbin/pw/bitmap.h delete mode 100644 usr.sbin/pw/cpdir.c delete mode 100644 usr.sbin/pw/edgroup.c delete mode 100644 usr.sbin/pw/fileupd.c delete mode 100644 usr.sbin/pw/grupd.c delete mode 100644 usr.sbin/pw/psdate.c delete mode 100644 usr.sbin/pw/psdate.h delete mode 100644 usr.sbin/pw/pw.8 delete mode 100644 usr.sbin/pw/pw.c delete mode 100644 usr.sbin/pw/pw.conf.5 delete mode 100644 usr.sbin/pw/pw.h delete mode 100644 usr.sbin/pw/pw_conf.c delete mode 100644 usr.sbin/pw/pw_group.c delete mode 100644 usr.sbin/pw/pw_log.c delete mode 100644 usr.sbin/pw/pw_nis.c delete mode 100644 usr.sbin/pw/pw_user.c delete mode 100644 usr.sbin/pw/pw_vpw.c delete mode 100644 usr.sbin/pw/pwupd.c delete mode 100644 usr.sbin/pw/pwupd.h delete mode 100644 usr.sbin/pw/rm_r.c delete mode 100644 usr.sbin/pwd_mkdb/Makefile delete mode 100644 usr.sbin/pwd_mkdb/pwd_mkdb.8 delete mode 100644 usr.sbin/pwd_mkdb/pwd_mkdb.c delete mode 100644 usr.sbin/quot/Makefile delete mode 100644 usr.sbin/quot/quot.8 delete mode 100644 usr.sbin/quot/quot.c delete mode 100644 usr.sbin/quotaon/Makefile delete mode 100644 usr.sbin/quotaon/quotaon.8 delete mode 100644 usr.sbin/quotaon/quotaon.c delete mode 100644 usr.sbin/rarpd/Makefile delete mode 100644 usr.sbin/rarpd/rarpd.8 delete mode 100644 usr.sbin/rarpd/rarpd.c delete mode 100644 usr.sbin/repquota/Makefile delete mode 100644 usr.sbin/repquota/repquota.8 delete mode 100644 usr.sbin/repquota/repquota.c delete mode 100644 usr.sbin/rip6query/Makefile delete mode 100644 usr.sbin/rip6query/rip6query.8 delete mode 100644 usr.sbin/rip6query/rip6query.c delete mode 100644 usr.sbin/rmt/Makefile delete mode 100644 usr.sbin/rmt/rmt.8 delete mode 100644 usr.sbin/rmt/rmt.c delete mode 100644 usr.sbin/rndc-confgen/Makefile delete mode 100644 usr.sbin/rndc/Makefile delete mode 100644 usr.sbin/route6d/Makefile delete mode 100755 usr.sbin/route6d/misc/chkrt delete mode 100644 usr.sbin/route6d/misc/cksum.c delete mode 100644 usr.sbin/route6d/route6d.8 delete mode 100644 usr.sbin/route6d/route6d.c delete mode 100644 usr.sbin/route6d/route6d.h delete mode 100644 usr.sbin/rpc.lockd/Makefile delete mode 100644 usr.sbin/rpc.lockd/kern.c delete mode 100644 usr.sbin/rpc.lockd/lock_proc.c delete mode 100644 usr.sbin/rpc.lockd/lockd.c delete mode 100644 usr.sbin/rpc.lockd/lockd.h delete mode 100644 usr.sbin/rpc.lockd/lockd_lock.c delete mode 100644 usr.sbin/rpc.lockd/lockd_lock.h delete mode 100644 usr.sbin/rpc.lockd/rpc.lockd.8 delete mode 100644 usr.sbin/rpc.lockd/test.c delete mode 100644 usr.sbin/rpc.statd/Makefile delete mode 100644 usr.sbin/rpc.statd/file.c delete mode 100644 usr.sbin/rpc.statd/procs.c delete mode 100644 usr.sbin/rpc.statd/rpc.statd.8 delete mode 100644 usr.sbin/rpc.statd/statd.c delete mode 100644 usr.sbin/rpc.statd/statd.h delete mode 100644 usr.sbin/rpc.statd/test.c delete mode 100644 usr.sbin/rpc.umntall/Makefile delete mode 100644 usr.sbin/rpc.umntall/mounttab.c delete mode 100644 usr.sbin/rpc.umntall/mounttab.h delete mode 100644 usr.sbin/rpc.umntall/rpc.umntall.8 delete mode 100644 usr.sbin/rpc.umntall/rpc.umntall.c delete mode 100644 usr.sbin/rpc.yppasswdd/Makefile delete mode 100644 usr.sbin/rpc.yppasswdd/rpc.yppasswdd.8 delete mode 100644 usr.sbin/rpc.yppasswdd/yppasswd_private.x delete mode 100644 usr.sbin/rpc.yppasswdd/yppasswdd_extern.h delete mode 100644 usr.sbin/rpc.yppasswdd/yppasswdd_main.c delete mode 100644 usr.sbin/rpc.yppasswdd/yppasswdd_server.c delete mode 100644 usr.sbin/rpc.yppasswdd/yppwupdate delete mode 100644 usr.sbin/rpc.ypupdated/Makefile delete mode 100644 usr.sbin/rpc.ypupdated/update.c delete mode 100644 usr.sbin/rpc.ypupdated/yp_dbdelete.c delete mode 100644 usr.sbin/rpc.ypupdated/yp_dbupdate.c delete mode 100755 usr.sbin/rpc.ypupdated/ypupdate delete mode 100644 usr.sbin/rpc.ypupdated/ypupdated_extern.h delete mode 100644 usr.sbin/rpc.ypupdated/ypupdated_main.c delete mode 100644 usr.sbin/rpc.ypupdated/ypupdated_server.c delete mode 100644 usr.sbin/rpc.ypxfrd/Makefile delete mode 100644 usr.sbin/rpc.ypxfrd/rpc.ypxfrd.8 delete mode 100644 usr.sbin/rpc.ypxfrd/ypxfrd_extern.h delete mode 100644 usr.sbin/rpc.ypxfrd/ypxfrd_main.c delete mode 100644 usr.sbin/rpc.ypxfrd/ypxfrd_server.c delete mode 100644 usr.sbin/rpcbind/Makefile delete mode 100644 usr.sbin/rpcbind/check_bound.c delete mode 100644 usr.sbin/rpcbind/pmap_svc.c delete mode 100644 usr.sbin/rpcbind/rpcb_stat.c delete mode 100644 usr.sbin/rpcbind/rpcb_svc.c delete mode 100644 usr.sbin/rpcbind/rpcb_svc_4.c delete mode 100644 usr.sbin/rpcbind/rpcb_svc_com.c delete mode 100644 usr.sbin/rpcbind/rpcbind.8 delete mode 100644 usr.sbin/rpcbind/rpcbind.c delete mode 100644 usr.sbin/rpcbind/rpcbind.h delete mode 100644 usr.sbin/rpcbind/security.c delete mode 100644 usr.sbin/rpcbind/util.c delete mode 100644 usr.sbin/rpcbind/warmstart.c delete mode 100644 usr.sbin/rrenumd/Makefile delete mode 100644 usr.sbin/rrenumd/lexer.l delete mode 100644 usr.sbin/rrenumd/parser.y delete mode 100644 usr.sbin/rrenumd/rrenumd.8 delete mode 100644 usr.sbin/rrenumd/rrenumd.c delete mode 100644 usr.sbin/rrenumd/rrenumd.conf.5 delete mode 100644 usr.sbin/rrenumd/rrenumd.h delete mode 100644 usr.sbin/rtadvd/Makefile delete mode 100644 usr.sbin/rtadvd/advcap.c delete mode 100644 usr.sbin/rtadvd/advcap.h delete mode 100644 usr.sbin/rtadvd/config.c delete mode 100644 usr.sbin/rtadvd/config.h delete mode 100644 usr.sbin/rtadvd/dump.c delete mode 100644 usr.sbin/rtadvd/dump.h delete mode 100644 usr.sbin/rtadvd/if.c delete mode 100644 usr.sbin/rtadvd/if.h delete mode 100644 usr.sbin/rtadvd/pathnames.h delete mode 100644 usr.sbin/rtadvd/rrenum.c delete mode 100644 usr.sbin/rtadvd/rrenum.h delete mode 100644 usr.sbin/rtadvd/rtadvd.8 delete mode 100644 usr.sbin/rtadvd/rtadvd.c delete mode 100644 usr.sbin/rtadvd/rtadvd.conf delete mode 100644 usr.sbin/rtadvd/rtadvd.conf.5 delete mode 100644 usr.sbin/rtadvd/rtadvd.h delete mode 100644 usr.sbin/rtadvd/timer.c delete mode 100644 usr.sbin/rtadvd/timer.h delete mode 100644 usr.sbin/rtprio/Makefile delete mode 100644 usr.sbin/rtprio/rtprio.1 delete mode 100644 usr.sbin/rtprio/rtprio.c delete mode 100644 usr.sbin/rtsold/Makefile delete mode 100644 usr.sbin/rtsold/dump.c delete mode 100644 usr.sbin/rtsold/if.c delete mode 100644 usr.sbin/rtsold/probe.c delete mode 100644 usr.sbin/rtsold/rtsock.c delete mode 100644 usr.sbin/rtsold/rtsol.c delete mode 100644 usr.sbin/rtsold/rtsold.8 delete mode 100644 usr.sbin/rtsold/rtsold.c delete mode 100644 usr.sbin/rtsold/rtsold.h delete mode 100644 usr.sbin/rwhod/Makefile delete mode 100644 usr.sbin/rwhod/rwhod.8 delete mode 100644 usr.sbin/rwhod/rwhod.c delete mode 100644 usr.sbin/sa/Makefile delete mode 100644 usr.sbin/sa/db.c delete mode 100644 usr.sbin/sa/extern.h delete mode 100644 usr.sbin/sa/main.c delete mode 100644 usr.sbin/sa/pathnames.h delete mode 100644 usr.sbin/sa/pdb.c delete mode 100644 usr.sbin/sa/sa.8 delete mode 100644 usr.sbin/sa/usrdb.c delete mode 100644 usr.sbin/sade/Makefile delete mode 100644 usr.sbin/sade/command.c delete mode 100644 usr.sbin/sade/config.c delete mode 100644 usr.sbin/sade/devices.c delete mode 100644 usr.sbin/sade/disks.c delete mode 100644 usr.sbin/sade/dispatch.c delete mode 100644 usr.sbin/sade/dmenu.c delete mode 100644 usr.sbin/sade/globals.c delete mode 100644 usr.sbin/sade/help/partition.hlp delete mode 100644 usr.sbin/sade/help/slice.hlp delete mode 100644 usr.sbin/sade/install.c delete mode 100644 usr.sbin/sade/label.c delete mode 100644 usr.sbin/sade/list.h delete mode 100644 usr.sbin/sade/main.c delete mode 100644 usr.sbin/sade/menus.c delete mode 100644 usr.sbin/sade/misc.c delete mode 100644 usr.sbin/sade/msg.c delete mode 100644 usr.sbin/sade/sade.8 delete mode 100644 usr.sbin/sade/sade.h delete mode 100644 usr.sbin/sade/system.c delete mode 100644 usr.sbin/sade/termcap.c delete mode 100644 usr.sbin/sade/variable.c delete mode 100644 usr.sbin/sade/wizard.c delete mode 100644 usr.sbin/sendmail/Makefile delete mode 100644 usr.sbin/service/Makefile delete mode 100644 usr.sbin/service/service.8 delete mode 100755 usr.sbin/service/service.sh delete mode 100644 usr.sbin/services_mkdb/Makefile delete mode 100644 usr.sbin/services_mkdb/services_mkdb.8 delete mode 100644 usr.sbin/services_mkdb/services_mkdb.c delete mode 100644 usr.sbin/services_mkdb/uniq.c delete mode 100644 usr.sbin/setfib/Makefile delete mode 100644 usr.sbin/setfib/setfib.1 delete mode 100644 usr.sbin/setfib/setfib.c delete mode 100644 usr.sbin/setfmac/Makefile delete mode 100644 usr.sbin/setfmac/setfmac.8 delete mode 100644 usr.sbin/setfmac/setfmac.c delete mode 100644 usr.sbin/setfmac/setfsmac.8 delete mode 100644 usr.sbin/setpmac/Makefile delete mode 100644 usr.sbin/setpmac/setpmac.8 delete mode 100644 usr.sbin/setpmac/setpmac.c delete mode 100644 usr.sbin/sicontrol/Makefile delete mode 100644 usr.sbin/sicontrol/sicontrol.8 delete mode 100644 usr.sbin/sicontrol/sicontrol.c delete mode 100644 usr.sbin/smbmsg/Makefile delete mode 100644 usr.sbin/smbmsg/pathnames.h delete mode 100644 usr.sbin/smbmsg/smbmsg.8 delete mode 100644 usr.sbin/smbmsg/smbmsg.c delete mode 100644 usr.sbin/snapinfo/Makefile delete mode 100644 usr.sbin/snapinfo/snapinfo.8 delete mode 100644 usr.sbin/snapinfo/snapinfo.c delete mode 100644 usr.sbin/spkrtest/Makefile delete mode 100644 usr.sbin/spkrtest/spkrtest.8 delete mode 100644 usr.sbin/spkrtest/spkrtest.sh delete mode 100644 usr.sbin/spray/Makefile delete mode 100644 usr.sbin/spray/spray.8 delete mode 100644 usr.sbin/spray/spray.c delete mode 100644 usr.sbin/sysinstall/Makefile delete mode 100644 usr.sbin/sysinstall/anonFTP.c delete mode 100644 usr.sbin/sysinstall/cdrom.c delete mode 100644 usr.sbin/sysinstall/command.c delete mode 100644 usr.sbin/sysinstall/config.c delete mode 100644 usr.sbin/sysinstall/devices.c delete mode 100644 usr.sbin/sysinstall/dhcp.c delete mode 100644 usr.sbin/sysinstall/disks.c delete mode 100644 usr.sbin/sysinstall/dispatch.c delete mode 100644 usr.sbin/sysinstall/dist.c delete mode 100644 usr.sbin/sysinstall/dist.h delete mode 100644 usr.sbin/sysinstall/dmenu.c delete mode 100644 usr.sbin/sysinstall/doc.c delete mode 100644 usr.sbin/sysinstall/dos.c delete mode 100644 usr.sbin/sysinstall/floppy.c delete mode 100644 usr.sbin/sysinstall/ftp.c delete mode 100644 usr.sbin/sysinstall/globals.c delete mode 100644 usr.sbin/sysinstall/help/anonftp.hlp delete mode 100644 usr.sbin/sysinstall/help/configure.hlp delete mode 100644 usr.sbin/sysinstall/help/distributions.hlp delete mode 100644 usr.sbin/sysinstall/help/drives.hlp delete mode 100644 usr.sbin/sysinstall/help/fixit.hlp delete mode 100644 usr.sbin/sysinstall/help/html.hlp delete mode 100644 usr.sbin/sysinstall/help/media.hlp delete mode 100644 usr.sbin/sysinstall/help/network_device.hlp delete mode 100644 usr.sbin/sysinstall/help/options.hlp delete mode 100644 usr.sbin/sysinstall/help/partition.hlp delete mode 100644 usr.sbin/sysinstall/help/securelevel.hlp delete mode 100644 usr.sbin/sysinstall/help/shortcuts.hlp delete mode 100644 usr.sbin/sysinstall/help/slice.hlp delete mode 100644 usr.sbin/sysinstall/help/tcp.hlp delete mode 100644 usr.sbin/sysinstall/help/usage.hlp delete mode 100644 usr.sbin/sysinstall/help/usermgmt.hlp delete mode 100644 usr.sbin/sysinstall/http.c delete mode 100644 usr.sbin/sysinstall/index.c delete mode 100644 usr.sbin/sysinstall/install.c delete mode 100644 usr.sbin/sysinstall/install.cfg delete mode 100644 usr.sbin/sysinstall/installUpgrade.c delete mode 100644 usr.sbin/sysinstall/keymap.c delete mode 100644 usr.sbin/sysinstall/label.c delete mode 100644 usr.sbin/sysinstall/list.h delete mode 100644 usr.sbin/sysinstall/main.c delete mode 100644 usr.sbin/sysinstall/media.c delete mode 100644 usr.sbin/sysinstall/menus.c delete mode 100644 usr.sbin/sysinstall/misc.c delete mode 100644 usr.sbin/sysinstall/modules.c delete mode 100644 usr.sbin/sysinstall/mouse.c delete mode 100644 usr.sbin/sysinstall/msg.c delete mode 100644 usr.sbin/sysinstall/network.c delete mode 100644 usr.sbin/sysinstall/nfs.c delete mode 100644 usr.sbin/sysinstall/options.c delete mode 100644 usr.sbin/sysinstall/package.c delete mode 100644 usr.sbin/sysinstall/rtermcap.c delete mode 100644 usr.sbin/sysinstall/sysinstall.8 delete mode 100644 usr.sbin/sysinstall/sysinstall.h delete mode 100644 usr.sbin/sysinstall/system.c delete mode 100644 usr.sbin/sysinstall/tcpip.c delete mode 100644 usr.sbin/sysinstall/termcap.c delete mode 100644 usr.sbin/sysinstall/ttys.c delete mode 100644 usr.sbin/sysinstall/ufs.c delete mode 100644 usr.sbin/sysinstall/usb.c delete mode 100644 usr.sbin/sysinstall/user.c delete mode 100644 usr.sbin/sysinstall/variable.c delete mode 100644 usr.sbin/sysinstall/wizard.c delete mode 100644 usr.sbin/syslogd/Makefile delete mode 100644 usr.sbin/syslogd/pathnames.h delete mode 100644 usr.sbin/syslogd/syslog.conf.5 delete mode 100644 usr.sbin/syslogd/syslogd.8 delete mode 100644 usr.sbin/syslogd/syslogd.c delete mode 100644 usr.sbin/tcpdchk/Makefile delete mode 100644 usr.sbin/tcpdmatch/Makefile delete mode 100644 usr.sbin/tcpdrop/Makefile delete mode 100644 usr.sbin/tcpdrop/tcpdrop.8 delete mode 100644 usr.sbin/tcpdrop/tcpdrop.c delete mode 100644 usr.sbin/tcpdump/Makefile delete mode 100644 usr.sbin/tcpdump/Makefile.inc delete mode 100644 usr.sbin/tcpdump/tcpdump/Makefile delete mode 100644 usr.sbin/tcpdump/tcpdump/config.h delete mode 100644 usr.sbin/timed/Makefile delete mode 100644 usr.sbin/timed/SMM.doc/timed/Makefile delete mode 100644 usr.sbin/timed/SMM.doc/timed/date delete mode 100644 usr.sbin/timed/SMM.doc/timed/loop delete mode 100644 usr.sbin/timed/SMM.doc/timed/spell.ok delete mode 100644 usr.sbin/timed/SMM.doc/timed/time delete mode 100644 usr.sbin/timed/SMM.doc/timed/timed.ms delete mode 100644 usr.sbin/timed/SMM.doc/timed/unused delete mode 100644 usr.sbin/timed/SMM.doc/timedop/Makefile delete mode 100644 usr.sbin/timed/SMM.doc/timedop/timed.ms delete mode 100644 usr.sbin/timed/timed/CHANGES delete mode 100644 usr.sbin/timed/timed/Makefile delete mode 100644 usr.sbin/timed/timed/acksend.c delete mode 100644 usr.sbin/timed/timed/byteorder.c delete mode 100644 usr.sbin/timed/timed/candidate.c delete mode 100644 usr.sbin/timed/timed/cksum.c delete mode 100644 usr.sbin/timed/timed/correct.c delete mode 100644 usr.sbin/timed/timed/extern.h delete mode 100644 usr.sbin/timed/timed/globals.h delete mode 100644 usr.sbin/timed/timed/master.c delete mode 100644 usr.sbin/timed/timed/measure.c delete mode 100644 usr.sbin/timed/timed/networkdelta.c delete mode 100644 usr.sbin/timed/timed/pathnames.h delete mode 100644 usr.sbin/timed/timed/readmsg.c delete mode 100644 usr.sbin/timed/timed/slave.c delete mode 100644 usr.sbin/timed/timed/timed.8 delete mode 100644 usr.sbin/timed/timed/timed.c delete mode 100644 usr.sbin/timed/timedc/Makefile delete mode 100644 usr.sbin/timed/timedc/cmds.c delete mode 100644 usr.sbin/timed/timedc/cmdtab.c delete mode 100644 usr.sbin/timed/timedc/extern.h delete mode 100644 usr.sbin/timed/timedc/timedc.8 delete mode 100644 usr.sbin/timed/timedc/timedc.c delete mode 100644 usr.sbin/timed/timedc/timedc.h delete mode 100644 usr.sbin/traceroute/Makefile delete mode 100644 usr.sbin/traceroute/findsaddr-udp.c delete mode 100644 usr.sbin/traceroute6/Makefile delete mode 100644 usr.sbin/traceroute6/traceroute6.8 delete mode 100644 usr.sbin/traceroute6/traceroute6.c delete mode 100644 usr.sbin/trpt/Makefile delete mode 100644 usr.sbin/trpt/trpt.8 delete mode 100644 usr.sbin/trpt/trpt.c delete mode 100644 usr.sbin/tzsetup/Makefile delete mode 100644 usr.sbin/tzsetup/tzsetup.8 delete mode 100644 usr.sbin/tzsetup/tzsetup.c delete mode 100644 usr.sbin/uathload/Makefile delete mode 100644 usr.sbin/uathload/uathload.8 delete mode 100644 usr.sbin/uathload/uathload.c delete mode 100644 usr.sbin/ugidfw/Makefile delete mode 100644 usr.sbin/ugidfw/ugidfw.8 delete mode 100644 usr.sbin/ugidfw/ugidfw.c delete mode 100644 usr.sbin/uhsoctl/Makefile delete mode 100644 usr.sbin/uhsoctl/uhsoctl.1 delete mode 100644 usr.sbin/uhsoctl/uhsoctl.c delete mode 100644 usr.sbin/usbconfig/Makefile delete mode 100644 usr.sbin/usbconfig/dump.c delete mode 100644 usr.sbin/usbconfig/dump.h delete mode 100644 usr.sbin/usbconfig/usbconfig.8 delete mode 100644 usr.sbin/usbconfig/usbconfig.c delete mode 100644 usr.sbin/usbdevs/Makefile delete mode 100644 usr.sbin/usbdevs/usbdevs.8 delete mode 100644 usr.sbin/usbdevs/usbdevs.c delete mode 100644 usr.sbin/vidcontrol/Makefile delete mode 100644 usr.sbin/vidcontrol/decode.c delete mode 100644 usr.sbin/vidcontrol/decode.h delete mode 100644 usr.sbin/vidcontrol/path.h delete mode 100644 usr.sbin/vidcontrol/vidcontrol.1 delete mode 100644 usr.sbin/vidcontrol/vidcontrol.c delete mode 100644 usr.sbin/vipw/Makefile delete mode 100644 usr.sbin/vipw/vipw.8 delete mode 100644 usr.sbin/vipw/vipw.c delete mode 100644 usr.sbin/wake/Makefile delete mode 100644 usr.sbin/wake/wake.8 delete mode 100644 usr.sbin/wake/wake.c delete mode 100644 usr.sbin/watch/Makefile delete mode 100644 usr.sbin/watch/watch.8 delete mode 100644 usr.sbin/watch/watch.c delete mode 100644 usr.sbin/watchdogd/Makefile delete mode 100644 usr.sbin/watchdogd/watchdog.8 delete mode 100644 usr.sbin/watchdogd/watchdogd.8 delete mode 100644 usr.sbin/watchdogd/watchdogd.c delete mode 100644 usr.sbin/wlandebug/Makefile delete mode 100644 usr.sbin/wlandebug/wlandebug.8 delete mode 100644 usr.sbin/wlandebug/wlandebug.c delete mode 100644 usr.sbin/wlconfig/Makefile delete mode 100644 usr.sbin/wlconfig/wlconfig.8 delete mode 100644 usr.sbin/wlconfig/wlconfig.c delete mode 100644 usr.sbin/wpa/Makefile delete mode 100644 usr.sbin/wpa/Makefile.inc delete mode 100644 usr.sbin/wpa/hostapd/Makefile delete mode 100644 usr.sbin/wpa/hostapd/driver_freebsd.c delete mode 100644 usr.sbin/wpa/hostapd/hostapd.8 delete mode 100644 usr.sbin/wpa/hostapd/hostapd.conf.5 delete mode 100644 usr.sbin/wpa/hostapd_cli/Makefile delete mode 100644 usr.sbin/wpa/hostapd_cli/hostapd_cli.8 delete mode 100644 usr.sbin/wpa/ndis_events/Makefile delete mode 100644 usr.sbin/wpa/ndis_events/ndis_events.8 delete mode 100644 usr.sbin/wpa/ndis_events/ndis_events.c delete mode 100644 usr.sbin/wpa/wpa_cli/Makefile delete mode 100644 usr.sbin/wpa/wpa_cli/wpa_cli.8 delete mode 100644 usr.sbin/wpa/wpa_passphrase/Makefile delete mode 100644 usr.sbin/wpa/wpa_passphrase/wpa_passphrase.8 delete mode 100644 usr.sbin/wpa/wpa_supplicant/Makefile delete mode 100644 usr.sbin/wpa/wpa_supplicant/Packet32.c delete mode 100644 usr.sbin/wpa/wpa_supplicant/Packet32.h delete mode 100644 usr.sbin/wpa/wpa_supplicant/driver_freebsd.c delete mode 100644 usr.sbin/wpa/wpa_supplicant/ntddndis.h delete mode 100644 usr.sbin/wpa/wpa_supplicant/wpa_supplicant.8 delete mode 100644 usr.sbin/wpa/wpa_supplicant/wpa_supplicant.conf.5 delete mode 100644 usr.sbin/yp_mkdb/Makefile delete mode 100644 usr.sbin/yp_mkdb/yp_mkdb.8 delete mode 100644 usr.sbin/yp_mkdb/yp_mkdb.c delete mode 100644 usr.sbin/ypbind/Makefile delete mode 100644 usr.sbin/ypbind/yp_ping.c delete mode 100644 usr.sbin/ypbind/yp_ping.h delete mode 100644 usr.sbin/ypbind/ypbind.8 delete mode 100644 usr.sbin/ypbind/ypbind.c delete mode 100644 usr.sbin/yppoll/Makefile delete mode 100644 usr.sbin/yppoll/yppoll.8 delete mode 100644 usr.sbin/yppoll/yppoll.c delete mode 100644 usr.sbin/yppush/Makefile delete mode 100644 usr.sbin/yppush/yppush.8 delete mode 100644 usr.sbin/yppush/yppush_extern.h delete mode 100644 usr.sbin/yppush/yppush_main.c delete mode 100644 usr.sbin/ypserv/Makefile delete mode 100644 usr.sbin/ypserv/Makefile.yp delete mode 100644 usr.sbin/ypserv/yp_access.c delete mode 100644 usr.sbin/ypserv/yp_dblookup.c delete mode 100644 usr.sbin/ypserv/yp_dnslookup.c delete mode 100644 usr.sbin/ypserv/yp_error.c delete mode 100644 usr.sbin/ypserv/yp_extern.h delete mode 100644 usr.sbin/ypserv/yp_main.c delete mode 100644 usr.sbin/ypserv/yp_server.c delete mode 100644 usr.sbin/ypserv/yp_svc_udp.c delete mode 100644 usr.sbin/ypserv/ypinit.8 delete mode 100644 usr.sbin/ypserv/ypinit.sh delete mode 100644 usr.sbin/ypserv/ypserv.8 delete mode 100644 usr.sbin/ypset/Makefile delete mode 100644 usr.sbin/ypset/ypset.8 delete mode 100644 usr.sbin/ypset/ypset.c delete mode 100644 usr.sbin/zic/Makefile delete mode 100644 usr.sbin/zic/Makefile.inc delete mode 100644 usr.sbin/zic/README delete mode 100644 usr.sbin/zic/zdump/Makefile delete mode 100644 usr.sbin/zic/zic/Makefile delete mode 100644 usr.sbin/zzz/Makefile delete mode 100644 usr.sbin/zzz/zzz.8 delete mode 100644 usr.sbin/zzz/zzz.sh (limited to 'usr.sbin') diff --git a/usr.sbin/IPXrouted/IPXrouted.8 b/usr.sbin/IPXrouted/IPXrouted.8 deleted file mode 100644 index f5d0e13..0000000 --- a/usr.sbin/IPXrouted/IPXrouted.8 +++ /dev/null @@ -1,224 +0,0 @@ -.\" Copyright (c) 1986, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Copyright (c) 1995 John Hay. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd October 11, 1995 -.Dt IPXROUTED 8 -.Os -.Sh NAME -.Nm IPXrouted -.Nd IPX Routing Information Protocol daemon -.Sh SYNOPSIS -.Nm -.Op Fl N -.Op Fl q -.Op Fl s -.Op Fl S -.Op Fl t -.Op Ar logfile -.Sh DESCRIPTION -The -.Nm -utility is invoked at boot time to manage the -.Tn IPX -routing tables. -The -.Tn IPX -routing daemon uses the Novell -.Tn IPX -Routing Information Protocol in maintaining up to date kernel routing -table entries. -.Pp -Available options: -.Bl -tag -width logfile -.It Fl N -Do not reply on GetNearestServer -.Tn SAP -request. -.It Fl q -Do not supply routing information (opposite of -.Fl s -option below). -.It Fl s -Forces -.Nm -to supply routing information whether it is acting as an internetwork -router or not. -.It Fl S -Do not supply Service Advertising Protocol -.Pq Tn SAP -information. -The default is to supply -.Tn SAP -information. -.It Fl t -All packets sent or received are -printed on the standard output. -In addition, -.Nm -will not divorce itself from the controlling terminal -so that interrupts from the keyboard will kill the process. -.It Ar logfile -Name of file in which -.Nm Ns 's -actions should be logged. -This log contains information -about any changes to the routing tables and a history of -recent messages sent and received which are related to -the changed route. -.El -.Pp -In normal operation -.Nm -listens -for routing information packets. -If the host is connected to -multiple -.Tn IPX -networks, it periodically supplies copies -of its routing tables to any directly connected hosts -and networks. -.Pp -When -.Nm -is started, it uses the -.Dv SIOCGIFCONF -.Xr ioctl 2 -to find those -directly connected interfaces configured into the -system and marked -.Dq up -(the software loopback interface is ignored). -If multiple interfaces -are present, it is assumed the host will forward packets -between networks. -The -.Nm -utility then transmits a -.Em request -packet on each interface (using a broadcast packet if -the interface supports it) and enters a loop, listening -for -.Em request -and -.Em response -packets from other hosts. -.Pp -When a -.Em request -packet is received, -.Nm -formulates a reply based on the information maintained in its -internal tables. -The -.Em response -packet generated contains a list of known routes, each marked -with a -.Dq hop count -metric (a count of 16, or greater, is -considered -.Dq infinite ) . -The metric associated with each -route returned provides a metric -.Em relative to the sender . -.Pp -.Em Response -packets received by -.Nm -are used to update the routing tables if one of the following -conditions is satisfied: -.Bl -bullet -.It -No routing table entry exists for the destination network -or host, and the metric indicates the destination is -.Dq reachable -(i.e., the hop count is not infinite). -.It -The source host of the packet is the same as the router in the -existing routing table entry. -That is, updated information is -being received from the very internetwork router through which -packets for the destination are being routed. -.It -The existing entry in the routing table has not been updated for -some time (defined to be 90 seconds) and the route is at least -as cost effective as the current route. -.It -The new route describes a shorter route to the destination than -the one currently stored in the routing tables; the metric of -the new route is compared against the one stored in the table -to decide this. -.El -.Pp -When an update is applied, -.Nm -records the change in its internal tables and generates a -.Em response -packet to all directly connected hosts and networks. -The -.Xr routed 8 -utility waits a short period -of time (no more than 30 seconds) before modifying the kernel's -routing tables to allow possible unstable situations to settle. -.Pp -In addition to processing incoming packets, -.Nm -also periodically checks the routing table entries. -If an entry has not been updated for 3 minutes, the entry's metric -is set to infinity and marked for deletion. -Deletions are delayed -an additional 60 seconds to ensure the invalidation is propagated -to other routers. -.Pp -Hosts acting as internetwork routers gratuitously supply their -routing tables every 30 seconds to all directly connected hosts -and networks. -.Pp -If -.Nm -receives a -.Dv SIGINFO -signal the current contents of the -.Tn RIP -and -.Tn SAP -tables are appended to the file -.Pa /var/log/ipxrouted.dmp . -.Sh SEE ALSO -.Xr ipx 3 -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 2.2 . diff --git a/usr.sbin/IPXrouted/Makefile b/usr.sbin/IPXrouted/Makefile deleted file mode 100644 index 44605ac..0000000 --- a/usr.sbin/IPXrouted/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/5/93 -# $FreeBSD$ - -PROG= IPXrouted -MAN= IPXrouted.8 -SRCS= af.c if.c input.c main.c output.c startup.c tables.c timer.c trace.c -SRCS+= sap_input.c sap_tables.c sap_output.c - -WARNS?= 2 - -.include diff --git a/usr.sbin/IPXrouted/af.c b/usr.sbin/IPXrouted/af.c deleted file mode 100644 index ea61762..0000000 --- a/usr.sbin/IPXrouted/af.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef lint -static const char sccsid[] = "@(#)af.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -#include "defs.h" - -/* - * Address family support routines - */ -af_hash_t null_hash; -af_netmatch_t null_netmatch; -af_output_t null_output; -af_portmatch_t null_portmatch; -af_portcheck_t null_portcheck; -af_checkhost_t null_checkhost; -af_ishost_t null_ishost; -af_canon_t null_canon; - -void ipxnet_hash(struct sockaddr_ipx *, struct afhash *); -int ipxnet_netmatch(struct sockaddr_ipx *, struct sockaddr_ipx *); -void ipxnet_output(int, int, struct sockaddr_ipx *, int); -int ipxnet_portmatch(struct sockaddr_ipx *); -int ipxnet_checkhost(struct sockaddr_ipx *); -int ipxnet_ishost(struct sockaddr_ipx *); -void ipxnet_canon(struct sockaddr_ipx *); - -#define NIL \ - { null_hash, null_netmatch, null_output, \ - null_portmatch, null_portcheck, null_checkhost, \ - null_ishost, null_canon } -#define IPXNET \ - { (af_hash_t *)ipxnet_hash, \ - (af_netmatch_t *)ipxnet_netmatch, \ - (af_output_t *)ipxnet_output, \ - (af_portmatch_t *)ipxnet_portmatch, \ - (af_portcheck_t *)ipxnet_portmatch, \ - (af_checkhost_t *)ipxnet_checkhost, \ - (af_ishost_t *)ipxnet_ishost, \ - (af_canon_t *)ipxnet_canon } - -struct afswitch afswitch[AF_MAX] = - { NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, - NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, - NIL, NIL, NIL, IPXNET, NIL, NIL }; - -struct sockaddr_ipx ipxnet_default = { sizeof(struct sockaddr_ipx), AF_IPX }; - -union ipx_net ipx_anynet; -union ipx_net ipx_zeronet; - -void -ipxnet_hash(sipx, hp) - register struct sockaddr_ipx *sipx; - struct afhash *hp; -{ - long hash; -#if 0 - u_short *s = sipx->sipx_addr.x_host.s_host; -#endif - u_char *c; - - c = sipx->sipx_addr.x_net.c_net; - -#define IMVAL 33 - hash = 0; - hash = hash * IMVAL + *c++; - hash = hash * IMVAL + *c++; - hash = hash * IMVAL + *c++; - hash = hash * IMVAL + *c++; -#undef IMVAL - - hp->afh_nethash = hash; - hp->afh_nethash ^= (hash >> 8); - hp->afh_nethash ^= (hash >> 16); - hp->afh_nethash ^= (hash >> 24); - -#if 0 - hash = 0; - hash = *s++; hash <<= 8; hash += *s++; hash <<= 8; hash += *s; - hp->afh_hosthash = hash; -#endif -} - -int -ipxnet_netmatch(sxn1, sxn2) - struct sockaddr_ipx *sxn1, *sxn2; -{ - return (ipx_neteq(sxn1->sipx_addr, sxn2->sipx_addr)); -} - -/* - * Verify the message is from the right port. - */ -int -ipxnet_portmatch(sipx) - register struct sockaddr_ipx *sipx; -{ - - return (ntohs(sipx->sipx_addr.x_port) == IPXPORT_RIP ); -} - - -/* - * ipx output routine. - */ -#ifdef DEBUG -int do_output = 0; -#endif -void -ipxnet_output(s, flags, sipx, size) - int s; - int flags; - struct sockaddr_ipx *sipx; - int size; -{ - struct sockaddr_ipx dst; - - dst = *sipx; - sipx = &dst; - if (sipx->sipx_addr.x_port == 0) - sipx->sipx_addr.x_port = htons(IPXPORT_RIP); -#ifdef DEBUG - if(do_output || ntohs(msg->rip_cmd) == RIPCMD_REQUEST) -#endif - /* - * Kludge to allow us to get routes out to machines that - * don't know their addresses yet; send to that address on - * ALL connected nets - */ - if (ipx_neteqnn(sipx->sipx_addr.x_net, ipx_zeronet)) { - extern struct interface *ifnet; - register struct interface *ifp; - - for (ifp = ifnet; ifp; ifp = ifp->int_next) { - sipx->sipx_addr.x_net = - satoipx_addr(ifp->int_addr).x_net; - (void) sendto(s, msg, size, flags, - (struct sockaddr *)sipx, sizeof (*sipx)); - } - return; - } - - (void) sendto(s, msg, size, flags, - (struct sockaddr *)sipx, sizeof (*sipx)); -} - -/* - * Return 1 if we want this route. - * We use this to disallow route net G entries for one for multiple - * point to point links. - */ -int -ipxnet_checkhost(sipx) - struct sockaddr_ipx *sipx; -{ - register struct interface *ifp = if_ifwithnet((struct sockaddr *)sipx); - /* - * We want this route if there is no more than one - * point to point interface with this network. - */ - if (ifp == 0 || (ifp->int_flags & IFF_POINTOPOINT)==0) return (1); - return (ifp->int_sq.n == ifp->int_sq.p); -} - -/* - * Return 1 if the address is - * for a host, 0 for a network. - */ -int -ipxnet_ishost(sipx) -struct sockaddr_ipx *sipx; -{ - register u_short *s = sipx->sipx_addr.x_host.s_host; - - if ((s[0]==0x0000) && (s[1]==0x0000) && (s[2]==0x0000)) - return (0); - if ((s[0]==0xffff) && (s[1]==0xffff) && (s[2]==0xffff)) - return (0); - - return (1); -} - -void -ipxnet_canon(sipx) - struct sockaddr_ipx *sipx; -{ - - sipx->sipx_addr.x_port = 0; -} - -void -null_hash(addr, hp) - struct sockaddr *addr; - struct afhash *hp; -{ - - hp->afh_nethash = hp->afh_hosthash = 0; -} - -int -null_netmatch(a1, a2) - struct sockaddr *a1, *a2; -{ - - return (0); -} - -void -null_output(s, f, a1, n) - int s; - int f; - struct sockaddr *a1; - int n; -{ - - ; -} - -int -null_portmatch(a1) - struct sockaddr *a1; -{ - - return (0); -} - -int -null_portcheck(a1) - struct sockaddr *a1; -{ - - return (0); -} - -int -null_ishost(a1) - struct sockaddr *a1; -{ - - return (0); -} - -int -null_checkhost(a1) - struct sockaddr *a1; -{ - - return (0); -} - -void -null_canon(a1) - struct sockaddr *a1; -{ - - ; -} - diff --git a/usr.sbin/IPXrouted/af.h b/usr.sbin/IPXrouted/af.h deleted file mode 100644 index 576a6c7..0000000 --- a/usr.sbin/IPXrouted/af.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)af.h 5.1 (Berkeley) 6/4/85 (routed/af.h) - * - * @(#)af.h 8.1 (Berkeley) 6/5/93 - * - * $FreeBSD$ - */ - -/* - * Routing table management daemon. - */ - -/* - * Structure returned by af_hash routines. - */ -struct afhash { - u_int afh_hosthash; /* host based hash */ - u_int afh_nethash; /* network based hash */ -}; - -/* - * Per address family routines. - */ -typedef void af_hash_t(struct sockaddr *, struct afhash *); -typedef int af_netmatch_t(struct sockaddr *, struct sockaddr *); -typedef void af_output_t(int, int, struct sockaddr *, int); -typedef int af_portmatch_t(struct sockaddr *); -typedef int af_portcheck_t(struct sockaddr *); -typedef int af_checkhost_t(struct sockaddr *); -typedef int af_ishost_t(struct sockaddr *); -typedef void af_canon_t(struct sockaddr *); - -struct afswitch { - af_hash_t *af_hash; /* returns keys based on address */ - af_netmatch_t *af_netmatch; /* verifies net # matching */ - af_output_t *af_output; /* interprets address for sending */ - af_portmatch_t *af_portmatch; /* packet from some other router? */ - af_portcheck_t *af_portcheck; /* packet from privileged peer? */ - af_checkhost_t *af_checkhost; /* tells if address for host or net */ - af_ishost_t *af_ishost; /* tells if address is valid */ - af_canon_t *af_canon; /* canonicalize address for compares */ -}; - -struct afswitch afswitch[AF_MAX]; /* table proper */ diff --git a/usr.sbin/IPXrouted/defs.h b/usr.sbin/IPXrouted/defs.h deleted file mode 100644 index c2b28a7..0000000 --- a/usr.sbin/IPXrouted/defs.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)defs.h 8.1 (Berkeley) 6/5/93 - * - * $FreeBSD$ - */ - -#include -#include - -#include -#include -#include -#if defined(vax) || defined(pdp11) -#define xnnet(x) ((u_long) (x)->rip_dst[1] << 16 | (u_long) (x)->rip_dst[0] ) -#else -#define xnnet(x) ((u_long) (x)->rip_dst[0] << 16 | (u_long) (x)->rip_dst[1] ) -#endif - -#include -#include -#include - -#include "protocol.h" -#include "sap.h" -#include "table.h" -#include "trace.h" -#include "interface.h" -#include "af.h" - - -/* - * When we find any interfaces marked down we rescan the - * kernel every CHECK_INTERVAL seconds to see if they've - * come up. - */ -#define CHECK_INTERVAL (5*60) - -#define equal(a1, a2) \ - (bcmp((caddr_t)(a1), (caddr_t)(a2), sizeof (struct sockaddr)) == 0) -#define min(a,b) ((a)>(b)?(b):(a)) -#define max(a,b) ((a)<(b)?(b):(a)) - -extern int ripsock; /* Socket to listen on */ -extern int sapsock; /* Socket to listen on */ -extern int kmem; -extern int supplier; /* process should supply updates */ -extern int dosap; /* SAP is enabled */ -extern int dognreply; /* enable GET_NEAREST response */ -extern int install; /* if 1 call kernel */ -extern int lookforinterfaces; /* if 1 probe kernel for new up ifs */ -extern int performnlist; /* if 1 check if /kernel has changed */ -extern int externalinterfaces; /* # of remote and local interfaces */ -extern int timeval; /* local idea of time */ -extern int noteremoterequests; /* squawk on requests from non-local nets */ -extern int r; /* Routing socket to install updates with */ -extern int gateway; -extern struct sockaddr_ipx ipx_netmask; /* Used in installing routes */ - -extern char packet[MAXRXPACKETSIZE+1]; -extern struct rip *msg; - -extern char **argv0; - -#define ADD 1 -#define DELETE 2 -#define CHANGE 3 - -void sndmsg(struct sockaddr *, int, struct interface *, int); -void supply(struct sockaddr *, int, struct interface *, int); -void addrouteforif(struct interface *); -void ifinit(void); -void toall(void (*f)(struct sockaddr *, int, struct interface *, int), - struct rt_entry *, int); -void rip_input(struct sockaddr *, int); - diff --git a/usr.sbin/IPXrouted/if.c b/usr.sbin/IPXrouted/if.c deleted file mode 100644 index 2c6e664..0000000 --- a/usr.sbin/IPXrouted/if.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * static char sccsid[] = "@(#)if.c 5.1 (Berkeley) 6/4/85"; (routed/if.c) - * - * $FreeBSD$ - */ - -#ifndef lint -static const char sccsid[] = "@(#)if.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -/* - * Routing Table Management Daemon - */ -#include "defs.h" - -extern struct interface *ifnet; - -/* - * Find the interface with address addr. - */ -struct interface * -if_ifwithaddr(addr) - struct sockaddr *addr; -{ - register struct interface *ifp; - -#define same(a1, a2) \ - (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 10) == 0) - for (ifp = ifnet; ifp; ifp = ifp->int_next) { - if (ifp->int_flags & IFF_REMOTE) - continue; - if (ifp->int_addr.sa_family != addr->sa_family) - continue; - if (same(&ifp->int_addr, addr)) - break; - if ((ifp->int_flags & IFF_BROADCAST) && - same(&ifp->int_broadaddr, addr)) - break; - } - return (ifp); -} - -/* - * Find the point-to-point interface with destination address addr. - */ -struct interface * -if_ifwithdstaddr(addr) - struct sockaddr *addr; -{ - register struct interface *ifp; - - for (ifp = ifnet; ifp; ifp = ifp->int_next) { - if ((ifp->int_flags & IFF_POINTOPOINT) == 0) - continue; - if (same(&ifp->int_dstaddr, addr)) - break; - } - return (ifp); -} - -/* - * Find the interface on the network - * of the specified address. - */ -struct interface * -if_ifwithnet(addr) - register struct sockaddr *addr; -{ - register struct interface *ifp; - register int af = addr->sa_family; - register int (*netmatch)(); - - if (af >= AF_MAX) - return (0); - netmatch = afswitch[af].af_netmatch; - for (ifp = ifnet; ifp; ifp = ifp->int_next) { - if (ifp->int_flags & IFF_REMOTE) - continue; - if (af != ifp->int_addr.sa_family) - continue; - if ((*netmatch)(addr, &ifp->int_addr)) - break; - } - return (ifp); -} - -/* - * Find an interface from which the specified address - * should have come from. Used for figuring out which - * interface a packet came in on -- for tracing. - */ -struct interface * -if_iflookup(addr) - struct sockaddr *addr; -{ - register struct interface *ifp, *maybe; - register int af = addr->sa_family; - register int (*netmatch)(); - - if (af >= AF_MAX) - return (0); - maybe = 0; - netmatch = afswitch[af].af_netmatch; - for (ifp = ifnet; ifp; ifp = ifp->int_next) { - if (ifp->int_addr.sa_family != af) - continue; - if (same(&ifp->int_addr, addr)) - break; - if ((ifp->int_flags & IFF_BROADCAST) && - same(&ifp->int_broadaddr, addr)) - break; - if (maybe == 0 && (*netmatch)(addr, &ifp->int_addr)) - maybe = ifp; - } - if (ifp == 0) - ifp = maybe; - return (ifp); -} diff --git a/usr.sbin/IPXrouted/input.c b/usr.sbin/IPXrouted/input.c deleted file mode 100644 index 651a8ae..0000000 --- a/usr.sbin/IPXrouted/input.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef lint -static const char sccsid[] = "@(#)input.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -/* - * IPX Routing Table Management Daemon - */ -#include "defs.h" - -struct sockaddr * -ipx_nettosa(net) -union ipx_net net; -{ - static struct sockaddr_ipx sxn; - - bzero(&sxn, sizeof (struct sockaddr_ipx)); - sxn.sipx_family = AF_IPX; - sxn.sipx_len = sizeof (sxn); - sxn.sipx_addr.x_net = net; - return( (struct sockaddr *)&sxn); - -} - -/* - * Process a newly received packet. - */ -void -rip_input(from, size) - struct sockaddr *from; - int size; -{ - int newsize; - int rtchanged = 0; - struct rt_entry *rt; - struct netinfo *n; - struct interface *ifp = 0; - struct afswitch *afp; - struct sockaddr_ipx *ipxp; - - ifp = if_ifwithnet(from); - ipxp = (struct sockaddr_ipx *)from; - if (ifp == 0) { - if(ftrace) { - fprintf(ftrace, "Received bogus packet from %s\n", - ipxdp_ntoa(&ipxp->sipx_addr)); - } - return; - } - - TRACE_INPUT(ifp, from, size); - if (from->sa_family >= AF_MAX) - return; - afp = &afswitch[from->sa_family]; - - size -= sizeof (u_short) /* command */; - n = msg->rip_nets; - - switch (ntohs(msg->rip_cmd)) { - - case RIPCMD_REQUEST: - if (ipx_hosteq(satoipx_addr(ifp->int_addr), ipxp->sipx_addr)) - return; - newsize = 0; - while (size > 0) { - if (size < sizeof (struct netinfo)) - break; - size -= sizeof (struct netinfo); - - /* - * A single entry with rip_dst == DSTNETS_ALL and - * metric ``infinity'' means ``all routes''. - * - * XXX According to the IPX RIP spec the metric - * and tick fields can be anything. So maybe we - * should not check the metric??? - */ - if (ipx_neteqnn(n->rip_dst, ipx_anynet) && - ntohs(n->rip_metric) == HOPCNT_INFINITY && - size == 0) { - supply(from, 0, ifp, 0); - return; - } - /* - * request for specific nets - */ - rt = rtlookup(ipx_nettosa(n->rip_dst)); - if (ftrace) { - fprintf(ftrace, - "specific request for %s", - ipxdp_nettoa(n->rip_dst)); - fprintf(ftrace, - " yields route %lx\n", - (u_long)rt); - } - /* - * XXX We break out on the first net that isn't - * found. The specs is a bit vague here. I'm not - * sure what we should do. - */ - if (rt == 0) - return; - /* XXX - * According to the spec we should not include - * information about networks for which the number - * of hops is 16. - */ - if (rt->rt_metric == (HOPCNT_INFINITY-1)) - return; - n->rip_metric = htons( rt == 0 ? HOPCNT_INFINITY : - min(rt->rt_metric+1, HOPCNT_INFINITY)); - n->rip_ticks = htons(rt->rt_ticks+1); - - /* - * We use split horizon with a twist. If the requested - * net is the directly connected net we supply an - * answer. This is so that the host can learn about - * the routers on its net. - */ - { - register struct rt_entry *trt = rt; - - while (trt) { - if ((trt->rt_ifp == ifp) && - !ipx_neteqnn(n->rip_dst, - satoipx_addr(ifp->int_addr).x_net)) - return; - trt = trt->rt_clone; - } - n++; - newsize += sizeof (struct netinfo); - } - } - if (newsize > 0) { - msg->rip_cmd = htons(RIPCMD_RESPONSE); - newsize += sizeof (u_short); - /* should check for if with dstaddr(from) first */ - (*afp->af_output)(ripsock, 0, from, newsize); - TRACE_OUTPUT(ifp, from, newsize); - if (ftrace) { - /* XXX This should not happen anymore. */ - if(ifp == 0) - fprintf(ftrace, "--- ifp = 0\n"); - else - fprintf(ftrace, - "request arrived on interface %s\n", - ifp->int_name); - } - } - return; - - case RIPCMD_RESPONSE: - /* verify message came from a router */ - if ((*afp->af_portmatch)(from) == 0) - return; - (*afp->af_canon)(from); - /* are we talking to ourselves? */ - if ((ifp = if_ifwithaddr(from)) != 0) { - rt = rtfind(from); - if (rt == 0 || (rt->rt_state & RTS_INTERFACE) == 0) { - addrouteforif(ifp); - rtchanged = 1; - } else - rt->rt_timer = 0; - return; - } - /* Update timer for interface on which the packet arrived. - * If from other end of a point-to-point link that isn't - * in the routing tables, (re-)add the route. - */ - if ((rt = rtfind(from)) && (rt->rt_state & RTS_INTERFACE)) { - if(ftrace) fprintf(ftrace, "Got route\n"); - rt->rt_timer = 0; - } else if ((ifp = if_ifwithdstaddr(from)) != 0) { - if(ftrace) fprintf(ftrace, "Got partner\n"); - addrouteforif(ifp); - rtchanged = 1; - } - for (; size > 0; size -= sizeof (struct netinfo), n++) { - struct sockaddr *sa; - if (size < sizeof (struct netinfo)) - break; - if ((unsigned) ntohs(n->rip_metric) > HOPCNT_INFINITY) - continue; - rt = rtfind(sa = ipx_nettosa(n->rip_dst)); - if (rt == 0) { - if (ntohs(n->rip_metric) == HOPCNT_INFINITY) - continue; - rtadd(sa, from, ntohs(n->rip_metric), - ntohs(n->rip_ticks), 0); - rtchanged = 1; - continue; - } - - /* - * A clone is a different route to the same net - * with exactly the same cost (ticks and metric). - * They must all be recorded because those interfaces - * must be handled in the same way as the first route - * to that net. ie When using the split horizon - * algorithm we must look at these interfaces also. - * - * Update if from gateway and different, - * from anywhere and less ticks or - * if same ticks and shorter, - * or getting stale and equivalent. - */ - if (!equal(from, &rt->rt_router) && - ntohs(n->rip_ticks) == rt->rt_ticks && - ntohs(n->rip_metric) == rt->rt_metric && - ntohs(n->rip_metric) != HOPCNT_INFINITY) { - register struct rt_entry *trt = rt->rt_clone; - - while (trt) { - if (equal(from, &trt->rt_router)) { - trt->rt_timer = 0; - break; - } - trt = trt->rt_clone; - } - if (trt == NULL) { - rtadd_clone(rt, sa, from, - ntohs(n->rip_metric), - ntohs(n->rip_ticks), 0); - } - continue; - } - if ((equal(from, &rt->rt_router) && - ((ntohs(n->rip_ticks) != rt->rt_ticks) || - (ntohs(n->rip_metric) != rt->rt_metric))) || - (ntohs(n->rip_ticks) < rt->rt_ticks) || - ((ntohs(n->rip_ticks) == rt->rt_ticks) && - (ntohs(n->rip_metric) < rt->rt_metric)) || - (rt->rt_timer > (EXPIRE_TIME*2/3) && - rt->rt_metric == ntohs(n->rip_metric) && - ntohs(n->rip_metric) != HOPCNT_INFINITY)) { - rtchange(rt, from, ntohs(n->rip_metric), - ntohs(n->rip_ticks)); - if (ntohs(n->rip_metric) == HOPCNT_INFINITY) - rt->rt_timer = EXPIRE_TIME; - else - rt->rt_timer = 0; - rtchanged = 1; - } else if (equal(from, &rt->rt_router) && - (ntohs(n->rip_ticks) == rt->rt_ticks) && - (ntohs(n->rip_metric) == rt->rt_metric) && - (ntohs(n->rip_metric) != HOPCNT_INFINITY)) { - rt->rt_timer = 0; - } - } - if (rtchanged) { - register struct rthash *rh; - register struct rt_entry *rt; - - toall(supply, NULL, 1); - for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++) - for (rt = rh->rt_forw; - rt != (struct rt_entry *)rh; - rt = rt->rt_forw) - rt->rt_state &= ~RTS_CHANGED; - } - - return; - } -} diff --git a/usr.sbin/IPXrouted/interface.h b/usr.sbin/IPXrouted/interface.h deleted file mode 100644 index ed7b988..0000000 --- a/usr.sbin/IPXrouted/interface.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)interface.h 8.1 (Berkeley) 6/5/93 - * - * $FreeBSD$ - */ - -/* - * Routing table management daemon. - */ - -/* - * An ``interface'' is similar to an ifnet structure, - * except it doesn't contain q'ing info, and it also - * handles ``logical'' interfaces (remote gateways - * that we want to keep polling even if they go down). - * The list of interfaces which we maintain is used - * in supplying the gratuitous routing table updates. - * We list only one address for each interface, the AF_IPX one. - */ -struct interface { - struct interface *int_next; - struct sockaddr int_addr; /* address on this host */ - union { - struct sockaddr intu_broadaddr; - struct sockaddr intu_dstaddr; - } int_intu; -#define int_broadaddr int_intu.intu_broadaddr /* broadcast address */ -#define int_dstaddr int_intu.intu_dstaddr /* other end of p-to-p link */ - int int_metric; /* init's routing entry */ - int int_flags; /* see below */ - struct ifdebug int_input, int_output; /* packet tracing stuff */ - int int_ipackets; /* input packets received */ - int int_opackets; /* output packets sent */ - char *int_name; /* from kernel if structure */ - u_short int_transitions; /* times gone up-down */ - - /* XXX IPX Specific entry */ - struct sameq { - struct sameq *n; /* q of other pt-to-pt links */ - struct sameq *p; /* with same net # */ - } int_sq; -}; - -/* - * 0x1 to 0x10 are reused from the kernel's ifnet definitions, - * the others agree with the RTS_ flags defined elsewhere. - */ -#define IFF_UP 0x1 /* interface is up */ -#define IFF_BROADCAST 0x2 /* broadcast address valid */ -#define IFF_DEBUG 0x4 /* turn on debugging */ -#define IFF_ROUTE 0x8 /* routing entry installed */ -#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */ - -#define IFF_PASSIVE 0x200000 /* can't tell if up/down */ -#define IFF_INTERFACE 0x400000 /* hardware interface */ -#define IFF_REMOTE 0x800000 /* interface isn't on this machine */ - -struct interface *if_ifwithaddr(struct sockaddr *); -struct interface *if_ifwithdstaddr(struct sockaddr *); -struct interface *if_ifwithnet(struct sockaddr *); -struct interface *if_iflookup(struct sockaddr *); - diff --git a/usr.sbin/IPXrouted/main.c b/usr.sbin/IPXrouted/main.c deleted file mode 100644 index 773410a..0000000 --- a/usr.sbin/IPXrouted/main.c +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1985, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static const char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -/* - * IPX Routing Information Protocol Daemon - */ -#include "defs.h" -#include - -#include - -#include -#include -#include -#include -#include -#include - -#define SAP_PKT 0 -#define RIP_PKT 1 - -struct sockaddr_ipx addr; /* Daemon's Address */ -int ripsock; /* RIP Socket to listen on */ -int sapsock; /* SAP Socket to listen on */ -int kmem; -int install; /* if 1 call kernel */ -int lookforinterfaces; /* if 1 probe kernel for new up interfaces */ -int performnlist; /* if 1 check if /kernel has changed */ -int externalinterfaces; /* # of remote and local interfaces */ -int timeval; /* local idea of time */ -int noteremoterequests; /* squawk on requests from non-local nets */ -int r; /* Routing socket to install updates with */ -struct sockaddr_ipx ipx_netmask; /* Used in installing routes */ - -char packet[MAXRXPACKETSIZE+1]; - -char **argv0; - -int supplier = -1; /* process should supply updates */ -int dosap = 1; /* By default do SAP services. */ -int dobcast = 1; /* A RIP/SAP broadcast is needed. */ -time_t lastbcast; /* Time of last RIP/SAP broadcast */ - -struct rip *msg = (struct rip *) &packet[sizeof (struct ipx)]; -struct sap_packet *sap_msg = - (struct sap_packet *) &packet[sizeof (struct ipx)]; -void hup(), fkexit(), timer(); -void process(int fd, int pkt_type); -int getsocket(int type, int proto, struct sockaddr_ipx *sipx); -void getinfo(); -void catchtimer(); - -int -main(argc, argv) - int argc; - char *argv[]; -{ - int nfds; - fd_set fdvar; - time_t ttime; - struct itimerval tval; - - argv0 = argv; - argv++, argc--; - while (argc > 0 && **argv == '-') { - if (strcmp(*argv, "-s") == 0) { - supplier = 1; - argv++, argc--; - continue; - } - if (strcmp(*argv, "-q") == 0) { - supplier = 0; - argv++, argc--; - continue; - } - if (strcmp(*argv, "-R") == 0) { - noteremoterequests++; - argv++, argc--; - continue; - } - if (strcmp(*argv, "-S") == 0) { - dosap = 0; - argv++, argc--; - continue; - } - if (strcmp(*argv, "-t") == 0) { - tracepackets++; - argv++, argc--; - ftrace = stderr; - tracing = 1; - continue; - } - if (strcmp(*argv, "-g") == 0) { - gateway = 1; - argv++, argc--; - continue; - } - if (strcmp(*argv, "-l") == 0) { - gateway = -1; - argv++, argc--; - continue; - } - if (strcmp(*argv, "-N") == 0) { - dognreply = 0; - argv++, argc--; - continue; - } - fprintf(stderr, - "usage: ipxrouted [ -s ] [ -q ] [ -t ] [ -g ] [ -l ] [ -N ]\n"); - exit(1); - } - - -#ifndef DEBUG - if (!tracepackets) - daemon(0, 0); -#endif - openlog("IPXrouted", LOG_PID, LOG_DAEMON); - - addr.sipx_family = AF_IPX; - addr.sipx_len = sizeof(addr); - addr.sipx_port = htons(IPXPORT_RIP); - ipx_anynet.s_net[0] = ipx_anynet.s_net[1] = -1; - ipx_netmask.sipx_addr.x_net = ipx_anynet; - ipx_netmask.sipx_len = 6; - ipx_netmask.sipx_family = AF_IPX; - r = socket(AF_ROUTE, SOCK_RAW, 0); - /* later, get smart about lookingforinterfaces */ - if (r) - shutdown(r, SHUT_RD); /* for now, don't want reponses */ - else { - fprintf(stderr, "IPXrouted: no routing socket\n"); - exit(1); - } - ripsock = getsocket(SOCK_DGRAM, 0, &addr); - if (ripsock < 0) - exit(1); - - if (dosap) { - addr.sipx_port = htons(IPXPORT_SAP); - sapsock = getsocket(SOCK_DGRAM, 0, &addr); - if (sapsock < 0) - exit(1); - } else - sapsock = -1; - - /* - * Any extra argument is considered - * a tracing log file. - */ - if (argc > 0) - traceon(*argv); - /* - * Collect an initial view of the world by - * snooping in the kernel. Then, send a request packet on all - * directly connected networks to find out what - * everyone else thinks. - */ - rtinit(); - sapinit(); - ifinit(); - if (supplier < 0) - supplier = 0; - /* request the state of the world */ - msg->rip_cmd = htons(RIPCMD_REQUEST); - msg->rip_nets[0].rip_dst = ipx_anynet; - msg->rip_nets[0].rip_metric = htons(HOPCNT_INFINITY); - msg->rip_nets[0].rip_ticks = htons(-1); - toall(sndmsg, NULL, 0); - - if (dosap) { - sap_msg->sap_cmd = htons(SAP_REQ); - sap_msg->sap[0].ServType = htons(SAP_WILDCARD); - toall(sapsndmsg, NULL, 0); - } - - signal(SIGALRM, catchtimer); - signal(SIGHUP, hup); - signal(SIGINT, hup); - signal(SIGEMT, fkexit); - signal(SIGINFO, getinfo); - - tval.it_interval.tv_sec = TIMER_RATE; - tval.it_interval.tv_usec = 0; - tval.it_value.tv_sec = TIMER_RATE; - tval.it_value.tv_usec = 0; - setitimer(ITIMER_REAL, &tval, NULL); - - nfds = 1 + max(sapsock, ripsock); - - for (;;) { - if (dobcast) { - dobcast = 0; - lastbcast = time(NULL); - timer(); - } - - FD_ZERO(&fdvar); - if (dosap) { - FD_SET(sapsock, &fdvar); - } - FD_SET(ripsock, &fdvar); - - if(select(nfds, &fdvar, (fd_set *)NULL, (fd_set *)NULL, - (struct timeval *)NULL) < 0) { - if(errno == EINTR) - continue; - perror("during select"); - exit(1); - } - - if(FD_ISSET(ripsock, &fdvar)) - process(ripsock, RIP_PKT); - - if(dosap && FD_ISSET(sapsock, &fdvar)) - process(sapsock, SAP_PKT); - - ttime = time(NULL); - if (ttime > (lastbcast + TIMER_RATE + (TIMER_RATE * 2 / 3))) { - dobcast = 1; - syslog(LOG_ERR, "Missed alarm"); - } - } -} - -void -process(fd, pkt_type) - int fd; - int pkt_type; -{ - struct sockaddr from; - int cc, omask; - socklen_t fromlen = sizeof (from); - struct ipx *ipxdp = (struct ipx *)packet; - - cc = recvfrom(fd, packet, sizeof (packet), 0, &from, &fromlen); - if (cc <= 0) { - if (cc < 0 && errno != EINTR) - syslog(LOG_ERR, "recvfrom: %m"); - return; - } - if (tracepackets > 1 && ftrace) { - fprintf(ftrace,"rcv %d bytes on %s ", - cc, ipxdp_ntoa(&ipxdp->ipx_dna)); - fprintf(ftrace," from %s\n", ipxdp_ntoa(&ipxdp->ipx_sna)); - } - - if (noteremoterequests && - !ipx_neteqnn(ipxdp->ipx_sna.x_net, ipx_zeronet) && - !ipx_neteq(ipxdp->ipx_sna, ipxdp->ipx_dna)) - { - syslog(LOG_ERR, - "net of interface (%s) != net on ether (%s)!\n", - ipxdp_nettoa(ipxdp->ipx_dna.x_net), - ipxdp_nettoa(ipxdp->ipx_sna.x_net)); - } - - /* We get the IPX header in front of the RIF packet*/ - cc -= sizeof (struct ipx); -#define mask(s) (1<<((s)-1)) - omask = sigblock(mask(SIGALRM)); - switch(pkt_type) { - case SAP_PKT: sap_input(&from, cc); - break; - case RIP_PKT: rip_input(&from, cc); - break; - } - sigsetmask(omask); -} - -int -getsocket(type, proto, sipx) - int type, proto; - struct sockaddr_ipx *sipx; -{ - int domain = sipx->sipx_family; - int retry, s, on = 1; - - retry = 1; - while ((s = socket(domain, type, proto)) < 0 && retry) { - syslog(LOG_ERR, "socket: %m"); - sleep(5 * retry); - retry <<= 1; - } - if (retry == 0) - return (-1); - while (bind(s, (struct sockaddr *)sipx, sizeof (*sipx)) < 0 && retry) { - syslog(LOG_ERR, "bind: %m"); - sleep(5 * retry); - retry <<= 1; - } - if (retry == 0) - return (-1); - if (domain==AF_IPX) { - struct ipx ipxdp; - if (setsockopt(s, 0, SO_HEADERS_ON_INPUT, &on, sizeof(on))) { - syslog(LOG_ERR, "setsockopt SEE HEADERS: %m"); - exit(1); - } - if (ntohs(sipx->sipx_addr.x_port) == IPXPORT_RIP) - ipxdp.ipx_pt = IPXPROTO_RI; - else if (ntohs(sipx->sipx_addr.x_port) == IPXPORT_SAP) -#ifdef IPXPROTO_SAP - ipxdp.ipx_pt = IPXPROTO_SAP; -#else - ipxdp.ipx_pt = IPXPROTO_PXP; -#endif - else { - syslog(LOG_ERR, "port should be either RIP or SAP"); - exit(1); - } - if (setsockopt(s, 0, SO_DEFAULT_HEADERS, &ipxdp, sizeof(ipxdp))) { - syslog(LOG_ERR, "setsockopt SET HEADER: %m"); - exit(1); - } - } - if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) { - syslog(LOG_ERR, "setsockopt SO_BROADCAST: %m"); - exit(1); - } - return (s); -} - -/* - * Fork and exit on EMT-- for profiling. - */ -void -fkexit() -{ - if (fork() == 0) - exit(0); -} - -void -catchtimer() -{ - dobcast = 1; -} - -void -getinfo() -{ - FILE *fh; - - fh = fopen("/var/log/ipxrouted.dmp", "a"); - if(fh == NULL) - return; - - dumpriptable(fh); - dumpsaptable(fh, sap_head); - - fclose(fh); -} - diff --git a/usr.sbin/IPXrouted/output.c b/usr.sbin/IPXrouted/output.c deleted file mode 100644 index 78922c9..0000000 --- a/usr.sbin/IPXrouted/output.c +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef lint -static const char sccsid[] = "@(#)output.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -/* - * Routing Table Management Daemon - */ -#include -#include "defs.h" - -/* - * Apply the function "f" to all non-passive - * interfaces. If the interface supports the - * use of broadcasting use it, otherwise address - * the output to the known router. - */ -void -toall(f, except, changesonly) - void (*f)(struct sockaddr *, int, struct interface *, int); - struct rt_entry *except; - int changesonly; -{ - register struct interface *ifp; - register struct sockaddr *dst; - register int flags; - register struct rt_entry *trt; - int onlist; - extern struct interface *ifnet; - - for (ifp = ifnet; ifp; ifp = ifp->int_next) { - if (ifp->int_flags & IFF_PASSIVE) - continue; - - /* - * Don't send it on interfaces in the except list. - */ - onlist = 0; - trt = except; - while(trt) { - if (ifp == trt->rt_ifp) { - onlist = 1; - break; - } - trt = trt->rt_clone; - } - if (onlist) - continue; - - dst = ifp->int_flags & IFF_BROADCAST ? &ifp->int_broadaddr : - ifp->int_flags & IFF_POINTOPOINT ? &ifp->int_dstaddr : - &ifp->int_addr; - flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0; - (*f)(dst, flags, ifp, changesonly); - } -} - -/* - * Output a preformed packet. - */ -void -sndmsg(dst, flags, ifp, changesonly) - struct sockaddr *dst; - int flags; - struct interface *ifp; - int changesonly; -{ - - (*afswitch[dst->sa_family].af_output) - (ripsock, flags, dst, sizeof (struct rip)); - TRACE_OUTPUT(ifp, dst, sizeof (struct rip)); -} - -/* - * Supply dst with the contents of the routing tables. - * If this won't fit in one packet, chop it up into several. - * - * This must be done using the split horizon algorithm. - * 1. Don't send routing info to the interface from where it was received. - * 2. Don't publish an interface to itself. - * 3. If a route is received from more than one interface and the cost is - * the same, don't publish it on either interface. I am calling this - * clones. - */ -void -supply(dst, flags, ifp, changesonly) - struct sockaddr *dst; - int flags; - struct interface *ifp; - int changesonly; -{ - register struct rt_entry *rt; - register struct rt_entry *crt; /* Clone route */ - register struct rthash *rh; - register struct netinfo *nn; - register struct netinfo *n = msg->rip_nets; - struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) dst; - af_output_t *output = afswitch[dst->sa_family].af_output; - int size, metric, ticks; - union ipx_net net; - int delay = 0; - - if (sipx->sipx_port == 0) - sipx->sipx_port = htons(IPXPORT_RIP); - - msg->rip_cmd = ntohs(RIPCMD_RESPONSE); - for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++) - for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { - size = (char *)n - (char *)msg; - if (size >= ((MAXRIPNETS * sizeof (struct netinfo)) + - sizeof (msg->rip_cmd))) { - (*output)(ripsock, flags, dst, size); - TRACE_OUTPUT(ifp, dst, size); - n = msg->rip_nets; - delay++; - if(delay == 2) { - usleep(50000); - delay = 0; - } - } - - if (changesonly && !(rt->rt_state & RTS_CHANGED)) - continue; - - /* - * This should do rule one and two of the split horizon - * algorithm. - */ - if (rt->rt_ifp == ifp) - continue; - - /* - * Rule 3. - * Look if we have clones (different routes to the same - * place with exactly the same cost). - * - * We should not publish on any of the clone interfaces. - */ - crt = rt->rt_clone; - while (crt) { - if (crt->rt_ifp == ifp) - goto next; - crt = crt->rt_clone; - } - - sipx = (struct sockaddr_ipx *)&rt->rt_dst; - if ((rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST) - sipx = (struct sockaddr_ipx *)&rt->rt_router; - if (rt->rt_metric == HOPCNT_INFINITY) - metric = HOPCNT_INFINITY; - else { - metric = rt->rt_metric + 1; - /* - * We don't advertize routes with more than 15 hops. - */ - if (metric >= HOPCNT_INFINITY) - continue; - } - /* XXX One day we should cater for slow interfaces also. */ - ticks = rt->rt_ticks + 1; - net = sipx->sipx_addr.x_net; - - /* - * Make sure that we don't put out a two net entries - * for a pt to pt link (one for the G route, one for the if) - * This is a kludge, and won't work if there are lots of nets. - */ - for (nn = msg->rip_nets; nn < n; nn++) { - if (ipx_neteqnn(net, nn->rip_dst)) { - if (ticks < ntohs(nn->rip_ticks)) { - nn->rip_metric = htons(metric); - nn->rip_ticks = htons(ticks); - } else if ((ticks == ntohs(nn->rip_ticks)) && - (metric < ntohs(nn->rip_metric))) { - nn->rip_metric = htons(metric); - nn->rip_ticks = htons(ticks); - } - goto next; - } - } - n->rip_dst = net; - n->rip_metric = htons(metric); - n->rip_ticks = htons(ticks); - n++; - next:; - } - if (n != msg->rip_nets) { - size = (char *)n - (char *)msg; - (*output)(ripsock, flags, dst, size); - TRACE_OUTPUT(ifp, dst, size); - } -} diff --git a/usr.sbin/IPXrouted/protocol.h b/usr.sbin/IPXrouted/protocol.h deleted file mode 100644 index 7fae536..0000000 --- a/usr.sbin/IPXrouted/protocol.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)protocol.h 8.1 (Berkeley) 6/5/93 - * - * $FreeBSD$ - */ - -/* - * IPX Routing Information Protocol - * - */ - -struct netinfo { - union ipx_net rip_dst; /* destination net */ - u_short rip_metric; /* cost of route */ - u_short rip_ticks; /* cost of route */ -}; - -struct rip { - u_short rip_cmd; /* request/response */ - struct netinfo rip_nets[1]; /* variable length */ -}; - -/* - * Packet types. - */ -#define RIPCMD_REQUEST 1 /* want info */ -#define RIPCMD_RESPONSE 2 /* responding to request */ - -#define RIPCMD_MAX 3 -#ifdef RIPCMDS -char *ripcmds[RIPCMD_MAX] = - { "#0", "REQUEST", "RESPONSE" }; -#endif - -#define HOPCNT_INFINITY 16 /* per IPX */ -#define DSTNETS_ALL 0xffffffff /* per IPX */ -#define MAXRXPACKETSIZE 1500 /* max rx broadcast size */ -#define MAXRIPNETS 50 /* max nets in tx packet */ - -extern union ipx_net ipx_anynet; -extern union ipx_net ipx_zeronet; - -/* - * Timer values used in managing the routing table. - * Every update forces an entry's timer to be reset. After - * EXPIRE_TIME without updates, the entry is marked invalid, - * but held onto until GARBAGE_TIME so that others may - * see it "be deleted". - */ -#define TIMER_RATE 30 /* alarm clocks every 30 seconds */ - -#define SUPPLY_INTERVAL 30 /* time to supply tables */ -#define RIP_INTERVAL 60 /* time to supply rip tables */ - -#define EXPIRE_TIME 180 /* time to mark entry invalid */ -#define GARBAGE_TIME 240 /* time to garbage collect */ diff --git a/usr.sbin/IPXrouted/sap.h b/usr.sbin/IPXrouted/sap.h deleted file mode 100644 index b4e9dcb..0000000 --- a/usr.sbin/IPXrouted/sap.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Hay. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY John Hay AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL John Hay OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#ifndef _SAP_H_ -#define _SAP_H_ - -#define SAP_REQ 1 -#define SAP_RESP 2 -#define SAP_REQ_NEAR 3 -#define SAP_RESP_NEAR 4 - -#define SAPCMD_MAX 5 -#ifdef SAPCMDS -char *sapcmds[SAPCMD_MAX] = - { "#0", "REQUEST", "RESPONSE", "REQ NEAREST", "RESP NEAREST"}; -#endif - -#define MAXSAPENTRIES 7 -#define SAP_WILDCARD 0xFFFF -#define SERVNAMELEN 48 -typedef struct sap_info { - u_short ServType; - char ServName[SERVNAMELEN]; - struct ipx_addr ipx; - u_short hops; - }sap_info; - -typedef struct sap_packet { - u_short sap_cmd; - sap_info sap[0]; /* Variable length. */ - }sap_packet; - -typedef struct sap_entry { - struct sap_entry *forw; - struct sap_entry *back; - struct sap_entry *clone; - struct interface *ifp; - struct sap_info sap; - struct sockaddr source; - int hash; - int state; - int timer; - }sap_entry; - -#define SAPHASHSIZ 256 /* Should be a power of 2 */ -#define SAPHASHMASK (SAPHASHSIZ-1) -typedef struct sap_hash { - struct sap_entry *forw; - struct sap_entry *back; - }sap_hash; - -extern sap_hash sap_head[SAPHASHSIZ]; - -extern struct sap_packet *sap_msg; - -void sapinit(void); -void sap_input(struct sockaddr *from, int size); -void sapsndmsg(struct sockaddr *dst, int flags, struct interface *ifp, - int changesonly); -void sap_supply_toall(int changesonly); -void sap_supply(struct sockaddr *dst, - int flags, - struct interface *ifp, - int ServType, - int changesonly); - -struct sap_entry *sap_lookup(u_short ServType, char *ServName); -struct sap_entry *sap_nearestserver(ushort ServType, struct interface *ifp); -void sap_add(struct sap_info *si, struct sockaddr *from); -void sap_change(struct sap_entry *sap, - struct sap_info *si, - struct sockaddr *from); -void sap_add_clone(struct sap_entry *sap, - struct sap_info *clone, - struct sockaddr *from); -void sap_delete(struct sap_entry *sap); - -#endif /*_SAP_H_*/ - diff --git a/usr.sbin/IPXrouted/sap_input.c b/usr.sbin/IPXrouted/sap_input.c deleted file mode 100644 index 59281b2..0000000 --- a/usr.sbin/IPXrouted/sap_input.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Hay. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY John Hay AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL John Hay OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * IPX Routing Table Management Daemon - */ -#include "defs.h" - -int dognreply = 1; - -/* - * Process a newly received packet. - */ -void -sap_input(from, size) - struct sockaddr *from; - int size; -{ - int newsize; - int sapchanged = 0; - struct sap_entry *sap; - struct sap_info *n; - struct interface *ifp = 0; - struct afswitch *afp; - struct sockaddr_ipx *ipxp; - - ifp = if_ifwithnet(from); - ipxp = (struct sockaddr_ipx *)from; - if (ifp == 0) { - if(ftrace) { - fprintf(ftrace, "Received bogus packet from %s\n", - ipxdp_ntoa(&ipxp->sipx_addr)); - } - return; - } - - if (ftrace) - dumpsappacket(ftrace, "received", from, (char *)sap_msg , size); - - if (from->sa_family >= AF_MAX) - return; - afp = &afswitch[from->sa_family]; - - size -= sizeof (u_short) /* command */; - n = sap_msg->sap; - - switch (ntohs(sap_msg->sap_cmd)) { - - case SAP_REQ_NEAR: - if (ftrace) - fprintf(ftrace, "Received a sap REQ_NEAR packet.\n"); - if (!dognreply) - return; - sap = sap_nearestserver(n->ServType, ifp); - if (sap == NULL) - return; - sap_msg->sap_cmd = htons(SAP_RESP_NEAR); - *n = sap->sap; - n->hops = htons(ntohs(n->hops) + 1); - if (ntohs(n->hops) >= HOPCNT_INFINITY) - return; - - newsize = sizeof(struct sap_info) + sizeof(struct sap_packet); - (*afp->af_output)(sapsock, 0, from, newsize); - if (ftrace) { - fprintf(ftrace, "sap_nearestserver %X %s returned:\n", - ntohs(n->ServType), - ifp->int_name); - fprintf(ftrace, " service %04X %-20.20s " - "addr %s.%04X metric %d\n", - ntohs(sap->sap.ServType), - sap->sap.ServName, - ipxdp_ntoa(&sap->sap.ipx), - ntohs(sap->sap.ipx.x_port), - ntohs(sap->sap.hops)); - } - return; - - case SAP_REQ: - if (ftrace) - fprintf(ftrace, "Received a sap REQ packet.\n"); - - sap_supply(from, 0, ifp, n->ServType, 0); - return; - - case SAP_RESP_NEAR: - /* XXX We do nothing here, for the moment. - * Maybe we should check if the service is in our table? - * - */ - if (ftrace) - fprintf(ftrace, "Received a sap RESP_NEAR packet.\n"); - - return; - - case SAP_RESP: - if (ftrace) - fprintf(ftrace, "Received a sap RESP packet.\n"); - - (*afp->af_canon)(from); - - for (; size > 0; size -= sizeof (struct sap_info), n++) { - if (size < sizeof (struct netinfo)) - break; - /* - * The idea here is that if the hop count is more - * than INFINITY it is bogus and should be discarded. - * If it is equal to INFINITY it is a message to say - * that a service went down. If we don't allready - * have it in our tables discard it. Otherwise - * update our table and set the timer to EXPIRE_TIME - * so that it is removed next time we go through the - * tables. - */ - if (ntohs(n->hops) > HOPCNT_INFINITY) - continue; - sap = sap_lookup(n->ServType, n->ServName); - if (sap == 0) { - if (ntohs(n->hops) == HOPCNT_INFINITY) - continue; - sap_add(n, from); - sapchanged = 1; - continue; - } - - /* - * A clone is a different route to the same service - * with exactly the same cost (metric). - * They must all be recorded because those interfaces - * must be handled in the same way as the first route - * to that service. ie When using the split horizon - * algorithm we must look at these interfaces also. - * - * Update if from gateway and different, - * from anywhere and less hops or - * getting stale and equivalent. - */ - if (((ifp != sap->ifp) || - !equal(&sap->source, from)) && - (n->hops == sap->sap.hops) && - (ntohs(n->hops) != HOPCNT_INFINITY)) { - register struct sap_entry *tsap = sap->clone; - - while (tsap) { - if ((ifp == tsap->ifp) && - equal(&tsap->source, from)) { - tsap->timer = 0; - break; - } - tsap = tsap->clone; - } - if (tsap == NULL) { - sap_add_clone(sap, n, from); - } - continue; - } - if ((ifp == sap->ifp) && - equal(&sap->source, from) && - (ntohs(n->hops) == ntohs(sap->sap.hops))) - sap->timer = 0; - else if (((ifp == sap->ifp) && - equal(&sap->source, from) && - (n->hops != sap->sap.hops)) || - (ntohs(n->hops) < ntohs(sap->sap.hops)) || - (sap->timer > (EXPIRE_TIME*2/3) && - ntohs(sap->sap.hops) == ntohs(n->hops) && - ntohs(n->hops) != HOPCNT_INFINITY)) { - sap_change(sap, n, from); - sapchanged = 1; - } - } - if (sapchanged) { - register struct sap_entry *sap; - register struct sap_hash *sh; - sap_supply_toall(1); - - for (sh = sap_head; sh < &sap_head[SAPHASHSIZ]; sh++) - for (sap = sh->forw; - sap != (struct sap_entry *)sh; - sap = sap->forw) - sap->state &= ~RTS_CHANGED; - } - return; - } -} diff --git a/usr.sbin/IPXrouted/sap_output.c b/usr.sbin/IPXrouted/sap_output.c deleted file mode 100644 index d1f1a28..0000000 --- a/usr.sbin/IPXrouted/sap_output.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Hay. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY John Hay AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL John Hay OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Routing Table Management Daemon - */ -#include -#include "defs.h" - -/* - * Apply the function "f" to all non-passive - * interfaces. If the interface supports the - * use of broadcasting use it, otherwise address - * the output to the known router. - */ -void -sap_supply_toall(changesonly) - int changesonly; -{ - register struct interface *ifp; - struct sockaddr dst; - register struct sockaddr_ipx *ipx_dst; - register int flags; - extern struct interface *ifnet; - - ipx_dst = (struct sockaddr_ipx *)&dst; - - for (ifp = ifnet; ifp; ifp = ifp->int_next) { - if (ifp->int_flags & IFF_PASSIVE) - continue; - - dst = ifp->int_flags & IFF_BROADCAST ? ifp->int_broadaddr : - ifp->int_flags & IFF_POINTOPOINT ? ifp->int_dstaddr : - ifp->int_addr; - - ipx_dst->sipx_addr.x_port = htons(IPXPORT_SAP); - - flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0; - sap_supply(&dst, flags, ifp, SAP_WILDCARD, changesonly); - } -} - -void -sapsndmsg(dst, flags, ifp, changesonly) - struct sockaddr *dst; - int flags; - struct interface *ifp; - int changesonly; -{ - struct sockaddr t_dst; - struct sockaddr_ipx *ipx_dst; - - t_dst = *dst; - ipx_dst = (struct sockaddr_ipx *)&t_dst; - - if (ipx_dst->sipx_addr.x_port == 0) - ipx_dst->sipx_addr.x_port = htons(IPXPORT_SAP); - - (*afswitch[dst->sa_family].af_output) - (sapsock, flags, &t_dst, - sizeof (struct sap_packet) + sizeof(u_short)); - TRACE_SAP_OUTPUT(ifp, &t_dst, - sizeof (struct sap_packet) + sizeof(u_short)); -} - -/* - * Supply dst with the contents of the SAP tables. If the ServType == - * SAP_WILDCARD (0xFFFF) supply the whole table, otherwise only the - * services that are of ServType. If this won't fit in one packet, chop - * it up into several. - * - * This must be done using the split horizon algorithm. - * 1. Don't send SAP info to the interface from where it was received. - * 2. If a service is received from more than one interface and the cost is - * the same, don't publish it on either interface. I am calling this - * clones. - */ -void -sap_supply(dst, flags, ifp, ServType, changesonly) - struct sockaddr *dst; - int flags; - struct interface *ifp; - int ServType; - int changesonly; -{ - register struct sap_entry *sap; - register struct sap_entry *csap; /* Clone route */ - register struct sap_hash *sh; - register struct sap_info *n = sap_msg->sap; - struct sap_hash *base = sap_head; - struct sockaddr_ipx *sipx = (struct sockaddr_ipx *) dst; - af_output_t *output = afswitch[dst->sa_family].af_output; - int size, metric; - int delay = 0; - - if (sipx->sipx_port == 0) - sipx->sipx_port = htons(IPXPORT_SAP); - - sap_msg->sap_cmd = ntohs(SAP_RESP); - - for (sh = base; sh < &base[SAPHASHSIZ]; sh++) - for (sap = sh->forw; sap != (struct sap_entry *)sh; sap = sap->forw) { - size = (char *)n - (char *)sap_msg; - if (size >= ((MAXSAPENTRIES * sizeof (struct sap_info)) + - sizeof (sap_msg->sap_cmd))) { - (*output)(sapsock, flags, dst, size); - TRACE_SAP_OUTPUT(ifp, dst, size); - n = sap_msg->sap; - delay++; - if(delay == 2) { - usleep(50000); - delay = 0; - } - } - - if (changesonly && !(sap->state & RTS_CHANGED)) - continue; - - /* - * Check for the servicetype except if the ServType is - * a wildcard (0xFFFF). - */ - if ((ServType != SAP_WILDCARD) && - (ServType != sap->sap.ServType)) - continue; - - /* - * This should do rule one and two of the split horizon - * algorithm. - */ - if (sap->ifp == ifp) - continue; - - /* - * Rule 2. - * Look if we have clones (different routes to the same - * place with exactly the same cost). - * - * We should not publish on any of the clone interfaces. - */ - csap = sap->clone; - while (csap) { - if (csap->ifp == ifp) - goto next; - csap = csap->clone; - } - - /* - * Don't advertise services with more than 15 hops. It - * will be confused with a service that has gone down. - */ - if (ntohs(sap->sap.hops) == (HOPCNT_INFINITY - 1)) - continue; - metric = min(ntohs(sap->sap.hops) + 1, HOPCNT_INFINITY); - - *n = sap->sap; - n->hops = htons(metric); - n++; -next: - ; - } - if (n != sap_msg->sap) { - size = (char *)n - (char *)sap_msg; - (*output)(sapsock, flags, dst, size); - TRACE_SAP_OUTPUT(ifp, dst, size); - } -} - diff --git a/usr.sbin/IPXrouted/sap_tables.c b/usr.sbin/IPXrouted/sap_tables.c deleted file mode 100644 index e1572d1..0000000 --- a/usr.sbin/IPXrouted/sap_tables.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by John Hay. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY John Hay AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL John Hay OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include "defs.h" -#include -#include -#include - -#define FIXLEN(s) { if ((s)->sa_len == 0) (s)->sa_len = sizeof (*(s));} - -sap_hash sap_head[SAPHASHSIZ]; - -void -sapinit(void) -{ - int i; - - for (i=0; i> 8); - - for (i=0;i<14;i++) { - hsh = hsh * SMVAL + *ServName++; - ServName++; - } - -#undef SMVAL - - return hsh; -} - -/* - * Look for an exact match on ServType and ServName. It is - * mostly used by the function that process SAP RESPONSE packets. - * - * A hash is created and used to index into the hash table. Then - * that list is walk through searching for a match. - * - * If no match is found NULL is returned. - */ -struct sap_entry * -sap_lookup(u_short ServType, char *ServName) -{ - register struct sap_entry *sap; - register struct sap_hash *sh; - int hsh; - - hsh = saphash(ServType, ServName); - sh = &sap_head[hsh & SAPHASHMASK]; - - for(sap = sh->forw; sap != (sap_entry *)sh; sap = sap->forw) { - if ((hsh == sap->hash) && - (ServType == sap->sap.ServType) && - (strncmp(ServName, sap->sap.ServName, SERVNAMELEN) == 0)) { - return sap; - } - } - return NULL; -} - -/* - * This returns the nearest service of the specified type. If no - * suitable service is found or if that service is on the interface - * where the request came from, NULL is returned. - * - * When checking interfaces clones must be considered also. - * - * XXX TODO: - * Maybe we can use RIP tables to get the fastest service (ticks). - */ -struct sap_entry * -sap_nearestserver(ushort ServType, struct interface *ifp) -{ - register struct sap_entry *sap; - struct sap_hash *sh; - register struct sap_entry *best = NULL; - register int besthops = HOPCNT_INFINITY; - - sh = sap_head; - - for (; sh < &sap_head[SAPHASHSIZ]; sh++) - for(sap = sh->forw; sap != (sap_entry *)sh; sap = sap->forw) { - if (ServType != sap->sap.ServType) - continue; - - if (ntohs(sap->sap.hops) < besthops) { - best = sap; - besthops = ntohs(best->sap.hops); - } - } - return best; -} - -/* - * Add an entry to the SAP table. - * - * If the malloc fail, the entry will silently be thrown away. - */ -void -sap_add(struct sap_info *si, struct sockaddr *from) -{ - register struct sap_entry *nsap; - register struct sap_hash *sh; - - if (ntohs(si->hops) == HOPCNT_INFINITY) - return; - - FIXLEN(from); - nsap = malloc(sizeof(struct sap_entry)); - if (nsap == NULL) - return; - - nsap->sap = *si; - nsap->source = *from; - nsap->clone = NULL; - nsap->ifp = if_ifwithnet(from); - nsap->state = RTS_CHANGED; - nsap->timer = 0; - nsap->hash = saphash(si->ServType, si->ServName); - - sh = &sap_head[nsap->hash & SAPHASHMASK]; - - insque(nsap, sh); - TRACE_SAP_ACTION("ADD", nsap); -} - -/* - * Change an existing SAP entry. If a clone exist for the old one, - * check if it is cheaper. If it is change tothe clone, otherwise - * delete all the clones. - */ -void -sap_change(struct sap_entry *sap, - struct sap_info *si, - struct sockaddr *from) -{ - struct sap_entry *osap = NULL; - - FIXLEN(from); - TRACE_SAP_ACTION("CHANGE FROM", sap); - /* - * If the hopcount (metric) is HOPCNT_INFINITY (16) it means that - * a service has gone down. We should keep it like that for 30 - * seconds, so that it will get broadcast and then change to a - * clone if one exist. - */ - if (sap->clone && (ntohs(si->hops) != HOPCNT_INFINITY)) { - /* - * There are three possibilities: - * 1. The new path is cheaper than the old one. - * Free all the clones. - * - * 2. The new path is the same cost as the old ones. - * If it is on the list of clones remove it - * from the clone list and free it. - * - * 3. The new path is more expensive than the old one. - * Use the values of the first clone and take it - * out of the list, to be freed at the end. - */ - osap = sap->clone; - if (ntohs(osap->sap.hops) > ntohs(si->hops)) { - struct sap_entry *nsap; - - while (osap) { - nsap = osap->clone; - TRACE_SAP_ACTION("DELETE", osap); - free(osap); - osap = nsap; - } - sap->clone = NULL; - } else if (ntohs(osap->sap.hops) == ntohs(si->hops)) { - struct sap_entry *psap; - - psap = sap; - while (osap) { - if (equal(&osap->source, from)) { - psap->clone = osap->clone; - TRACE_SAP_ACTION("DELETE", osap); - free(osap); - osap = psap->clone; - } else { - psap = osap; - osap = osap->clone; - } - } - } else { - from = &osap->source; - si = &osap->sap; - sap->clone = osap->clone; - } - } - sap->sap = *si; - sap->source = *from; - sap->ifp = if_ifwithnet(from); - sap->state = RTS_CHANGED; - if (ntohs(si->hops) == HOPCNT_INFINITY) - sap->timer = EXPIRE_TIME; - else - sap->timer = 0; - - if (osap) { - TRACE_SAP_ACTION("DELETE", osap); - free(osap); - } - TRACE_SAP_ACTION("CHANGE TO", sap); -} - -/* - * Add a clone to the specified SAP entry. A clone is a different - * route to the same service. We must know about them when we use - * the split horizon algorithm. - * - * If the malloc fail, the entry will silently be thrown away. - */ -void -sap_add_clone(struct sap_entry *sap, - struct sap_info *clone, - struct sockaddr *from) -{ - register struct sap_entry *nsap; - register struct sap_entry *csap; - - if (ntohs(clone->hops) == HOPCNT_INFINITY) - return; - - FIXLEN(from); - nsap = malloc(sizeof(struct sap_entry)); - if (nsap == NULL) - return; - - if (ftrace) - fprintf(ftrace, "CLONE ADD %4.4X %s.\n", - ntohs(clone->ServType), - clone->ServName); - - nsap->sap = *clone; - nsap->source = *from; - nsap->clone = NULL; - nsap->ifp = if_ifwithnet(from); - nsap->state = RTS_CHANGED; - nsap->timer = 0; - nsap->hash = saphash(clone->ServType, clone->ServName); - - csap = sap; - while (csap->clone) - csap = csap->clone; - csap->clone = nsap; - TRACE_SAP_ACTION("ADD CLONE", nsap); -} - -/* - * Remove a SAP entry from the table and free the memory - * used by it. - * - * If the service have clone, do a sap_change to it and free - * the clone. - */ -void -sap_delete(struct sap_entry *sap) -{ - if (sap->clone) { - sap_change(sap, &sap->clone->sap, &sap->clone->source); - return; - } - remque(sap); - TRACE_SAP_ACTION("DELETE", sap); - free(sap); -} diff --git a/usr.sbin/IPXrouted/startup.c b/usr.sbin/IPXrouted/startup.c deleted file mode 100644 index 2b9ccfa..0000000 --- a/usr.sbin/IPXrouted/startup.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef lint -static const char sccsid[] = "@(#)startup.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -/* - * Routing Table Management Daemon - */ -#include "defs.h" - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -struct interface *ifnet; -int lookforinterfaces = 1; -int performnlist = 1; -int gateway = 0; -int externalinterfaces = 0; /* # of remote and local interfaces */ - -void -quit(s) - char *s; -{ - int sverrno = errno; - - (void) fprintf(stderr, "IPXroute: "); - if (s) - (void) fprintf(stderr, "%s: ", s); - (void) fprintf(stderr, "%s\n", strerror(sverrno)); - exit(1); - /* NOTREACHED */ -} - -struct rt_addrinfo info; -/* XXX Sleazy use of local variables throughout file, warning!!!! */ -#define netmask info.rti_info[RTAX_NETMASK] -#define ifaaddr info.rti_info[RTAX_IFA] -#define brdaddr info.rti_info[RTAX_BRD] - -void -rt_xaddrs(cp, cplim, rtinfo) - register caddr_t cp, cplim; - register struct rt_addrinfo *rtinfo; -{ - register struct sockaddr *sa; - register int i; - - bzero(rtinfo->rti_info, sizeof(rtinfo->rti_info)); - for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) { - if ((rtinfo->rti_addrs & (1 << i)) == 0) - continue; - rtinfo->rti_info[i] = sa = (struct sockaddr *)cp; - cp += SA_SIZE(sa); - } -} - -/* - * Find the network interfaces which have configured themselves. - * If the interface is present but not yet up (for example an - * ARPANET IMP), set the lookforinterfaces flag so we'll - * come back later and look again. - */ -void -ifinit(void) -{ - struct interface ifs, *ifp; - size_t needed; - int mib[6], no_ipxaddr = 0, flags = 0; - char *buf, *cplim, *cp; - register struct if_msghdr *ifm; - register struct ifa_msghdr *ifam; - struct sockaddr_dl *sdl = 0; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; - mib[3] = AF_IPX; - mib[4] = NET_RT_IFLIST; - mib[5] = 0; - if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) - quit("route-sysctl-estimate"); - if ((buf = malloc(needed)) == NULL) - quit("malloc"); - if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) - lookforinterfaces = 0; - cplim = buf + needed; - for (cp = buf; cp < cplim; cp += ifm->ifm_msglen) { - ifm = (struct if_msghdr *)cp; - if (ifm->ifm_type == RTM_IFINFO) { - bzero(&ifs, sizeof(ifs)); - ifs.int_flags = flags = ifm->ifm_flags | IFF_INTERFACE; - if ((flags & IFF_UP) == 0 || no_ipxaddr) - lookforinterfaces = 1; - sdl = (struct sockaddr_dl *) (ifm + 1); - sdl->sdl_data[sdl->sdl_nlen] = 0; - no_ipxaddr = 1; - continue; - } - if (ifm->ifm_type != RTM_NEWADDR) - quit("ifinit: out of sync"); - if ((flags & IFF_UP) == 0) - continue; - ifam = (struct ifa_msghdr *)ifm; - info.rti_addrs = ifam->ifam_addrs; - rt_xaddrs((char *)(ifam + 1), cp + ifam->ifam_msglen, &info); - if (ifaaddr == 0) { - syslog(LOG_ERR, "%s: (get addr)", sdl->sdl_data); - continue; - } - ifs.int_addr = *ifaaddr; - if (ifs.int_addr.sa_family != AF_IPX) - continue; - no_ipxaddr = 0; - if (ifs.int_flags & IFF_POINTOPOINT) { - if (brdaddr == 0) { - syslog(LOG_ERR, "%s: (get dstaddr)", - sdl->sdl_data); - continue; - } - if (brdaddr->sa_family == AF_UNSPEC) { - lookforinterfaces = 1; - continue; - } - ifs.int_dstaddr = *brdaddr; - } - if (ifs.int_flags & IFF_BROADCAST) { - if (brdaddr == 0) { - syslog(LOG_ERR, "%s: (get broadaddr)", - sdl->sdl_data); - continue; - } - ifs.int_dstaddr = *brdaddr; - } - if (ifs.int_flags & IFF_LOOPBACK) { - ifs.int_dstaddr = ifs.int_addr; - } - /* - * already known to us? - * what makes a POINTOPOINT if unique is its dst addr, - * NOT its source address - */ - if ( ((ifs.int_flags & IFF_POINTOPOINT) && - if_ifwithdstaddr(&ifs.int_dstaddr)) || - ( ((ifs.int_flags & IFF_POINTOPOINT) == 0) && - if_ifwithaddr(&ifs.int_addr))) - continue; - ifp = (struct interface *) - malloc(sdl->sdl_nlen + 1 + sizeof(ifs)); - if (ifp == 0) { - syslog(LOG_ERR, "IPXrouted: out of memory\n"); - lookforinterfaces = 1; - break; - } - *ifp = ifs; - /* - * Count the # of directly connected networks - * and point to point links which aren't looped - * back to ourself. This is used below to - * decide if we should be a routing ``supplier''. - */ - if ((ifs.int_flags & IFF_POINTOPOINT) == 0 || - if_ifwithaddr(&ifs.int_dstaddr) == 0) - externalinterfaces++; - /* - * If we have a point-to-point link, we want to act - * as a supplier even if it's our only interface, - * as that's the only way our peer on the other end - * can tell that the link is up. - */ - if ((ifs.int_flags & IFF_POINTOPOINT) && supplier < 0) - supplier = 1; - ifp->int_name = (char *)(ifp + 1); - strcpy(ifp->int_name, sdl->sdl_data); - - ifp->int_metric = ifam->ifam_metric; - ifp->int_next = ifnet; - ifnet = ifp; - traceinit(ifp); - addrouteforif(ifp); - } - if (externalinterfaces > 1 && supplier < 0) - supplier = 1; - free(buf); -} - -void -addrouteforif(ifp) - struct interface *ifp; -{ - struct sockaddr_ipx net; - struct sockaddr *dst; - struct rt_entry *rt; - - if (ifp->int_flags & IFF_POINTOPOINT) { - int (*match)(); - register struct interface *ifp2 = ifnet; - - dst = &ifp->int_dstaddr; - - /* Search for interfaces with the same net */ - ifp->int_sq.n = ifp->int_sq.p = &(ifp->int_sq); - match = afswitch[dst->sa_family].af_netmatch; - if (match) - for (ifp2 = ifnet; ifp2; ifp2 =ifp2->int_next) { - if ((ifp->int_flags & IFF_POINTOPOINT) == 0) - continue; - if ((*match)(&ifp2->int_dstaddr,&ifp->int_dstaddr)) { - insque(&ifp2->int_sq,&ifp->int_sq); - break; - } - } - } else { - bzero(&net, sizeof(net)); - net.sipx_family = AF_IPX; - net.sipx_len = sizeof (net); - net.sipx_addr.x_net = satoipx_addr(ifp->int_broadaddr).x_net; - dst = (struct sockaddr *)&net; - } - rt = rtlookup(dst); - if (rt) - rtdelete(rt); - if (tracing) - fprintf(stderr, "Adding route to interface %s\n", ifp->int_name); - if (ifp->int_transitions++ > 0) - syslog(LOG_ERR, "re-installing interface %s", ifp->int_name); - rtadd(dst, &ifp->int_addr, ifp->int_metric, 0, - ifp->int_flags & (IFF_INTERFACE|IFF_PASSIVE|IFF_REMOTE)); -} - diff --git a/usr.sbin/IPXrouted/table.h b/usr.sbin/IPXrouted/table.h deleted file mode 100644 index 3f9693f..0000000 --- a/usr.sbin/IPXrouted/table.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)table.h 5.1 (Berkeley) 6/4/85 (routed/table.h) - * - * @(#)table.h 8.1 (Berkeley) 6/5/93 - * - * $FreeBSD$ - */ - -/* - * Routing table management daemon. - */ - -/* - * Routing table structure; differs a bit from kernel tables. - * - * Note: the union below must agree in the first 4 members - * so the ioctl's will work. - */ -struct rthash { - struct rt_entry *rt_forw; - struct rt_entry *rt_back; -}; - -#ifdef RTM_ADD -#define rtentry ortentry -#endif - -struct rt_entry { - struct rt_entry *rt_forw; - struct rt_entry *rt_back; - union { - struct rtentry rtu_rt; - struct rtuentry { - u_long rtu_hash; - struct sockaddr rtu_dst; - struct sockaddr rtu_router; - short rtu_rtflags; /* used by old rtioctl */ - short rtu_wasted; /* XXX routed does it this way. */ - int rtu_flags; - int rtu_state; - int rtu_timer; - int rtu_metric; - int rtu_ticks; - struct interface *rtu_ifp; - } rtu_entry; - } rt_rtu; - struct rt_entry *rt_clone; -}; - -#define rt_rt rt_rtu.rtu_entry /* pass to ioctl */ -#define rt_hash rt_rtu.rtu_entry.rtu_hash /* for net or host */ -#define rt_dst rt_rtu.rtu_entry.rtu_dst /* match value */ -#define rt_router rt_rtu.rtu_entry.rtu_router /* who to forward to */ -#define rt_flags rt_rtu.rtu_entry.rtu_flags /* kernel flags */ -#define rt_timer rt_rtu.rtu_entry.rtu_timer /* for invalidation */ -#define rt_state rt_rtu.rtu_entry.rtu_state /* see below */ -#define rt_metric rt_rtu.rtu_entry.rtu_metric /* cost of route */ -#define rt_ticks rt_rtu.rtu_entry.rtu_ticks /* time of route */ -#define rt_ifp rt_rtu.rtu_entry.rtu_ifp /* interface to take */ - -#define ROUTEHASHSIZ 128 /* must be a power of 2 */ -#define ROUTEHASHMASK (ROUTEHASHSIZ - 1) - -/* - * "State" of routing table entry. - */ -#define RTS_CHANGED 0x1 /* route has been altered recently */ -#define RTS_PASSIVE IFF_PASSIVE /* don't time out route */ -#define RTS_INTERFACE IFF_INTERFACE /* route is for network interface */ -#define RTS_REMOTE IFF_REMOTE /* route is for ``remote'' entity */ - -extern struct rthash nethash[ROUTEHASHSIZ]; -struct rt_entry *rtlookup(struct sockaddr *); -struct rt_entry *rtfind(struct sockaddr *); -void rtadd(struct sockaddr *, struct sockaddr *, short, short, int); -void rtadd_clone(struct rt_entry *, struct sockaddr *, struct sockaddr *, - short, short, int); -void rtchange(struct rt_entry *, struct sockaddr *, short, short); -void rtdelete(struct rt_entry *); -int rtioctl(int, struct rtuentry *); -void rtinit(void); - diff --git a/usr.sbin/IPXrouted/tables.c b/usr.sbin/IPXrouted/tables.c deleted file mode 100644 index fe816b2..0000000 --- a/usr.sbin/IPXrouted/tables.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef lint -static const char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -/* - * Routing Table Management Daemon - */ -#include "defs.h" -#include -#include -#include -#include -#include - -#ifndef DEBUG -#define DEBUG 0 -#endif - -#define FIXLEN(s) { if ((s)->sa_len == 0) (s)->sa_len = sizeof (*(s));} - -int install = !DEBUG; /* if 1 call kernel */ -int delete = 1; - -struct rthash nethash[ROUTEHASHSIZ]; - -/* - * Lookup dst in the tables for an exact match. - */ -struct rt_entry * -rtlookup(struct sockaddr *dst) -{ - register struct rt_entry *rt; - register struct rthash *rh; - register u_int hash; - struct afhash h; - - if (dst->sa_family >= AF_MAX) - return (0); - (*afswitch[dst->sa_family].af_hash)(dst, &h); - hash = h.afh_nethash; - rh = &nethash[hash & ROUTEHASHMASK]; - for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { - if (rt->rt_hash != hash) - continue; - if (equal(&rt->rt_dst, dst)) - return (rt); - } - return (0); -} - -/* - * Find a route to dst as the kernel would. - */ -struct rt_entry * -rtfind(struct sockaddr *dst) -{ - register struct rt_entry *rt; - register struct rthash *rh; - register u_int hash; - struct afhash h; - int af = dst->sa_family; - int (*match)() = 0; - - if (af >= AF_MAX) - return (0); - (*afswitch[af].af_hash)(dst, &h); - - hash = h.afh_nethash; - rh = &nethash[hash & ROUTEHASHMASK]; - match = afswitch[af].af_netmatch; - for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { - if (rt->rt_hash != hash) - continue; - if (rt->rt_dst.sa_family == af && - (*match)(&rt->rt_dst, dst)) - return (rt); - } - return (0); -} - -void -rtadd(struct sockaddr *dst, struct sockaddr *gate, short metric, - short ticks, int state) -{ - struct afhash h; - register struct rt_entry *rt; - struct rthash *rh; - int af = dst->sa_family, flags; - u_int hash; - - FIXLEN(dst); - FIXLEN(gate); - if (af >= AF_MAX) - return; - (*afswitch[af].af_hash)(dst, &h); - flags = (*afswitch[af].af_ishost)(dst) ? RTF_HOST : 0; - hash = h.afh_nethash; - rh = &nethash[hash & ROUTEHASHMASK]; - rt = (struct rt_entry *)malloc(sizeof (*rt)); - if (rt == 0) - return; - rt->rt_hash = hash; - rt->rt_dst = *dst; - rt->rt_router = *gate; - rt->rt_metric = metric; - rt->rt_ticks = ticks; - rt->rt_timer = 0; - rt->rt_flags = RTF_UP | flags; - rt->rt_state = state | RTS_CHANGED; - rt->rt_ifp = if_ifwithnet(&rt->rt_router); - rt->rt_clone = NULL; - if (metric) - rt->rt_flags |= RTF_GATEWAY; - insque(rt, rh); - TRACE_ACTION("ADD", rt); - /* - * If the ioctl fails because the gateway is unreachable - * from this host, discard the entry. This should only - * occur because of an incorrect entry in /etc/gateways. - */ - if (install && rtioctl(ADD, &rt->rt_rt) < 0) { - if (errno != EEXIST) - perror("SIOCADDRT"); - if (errno == ENETUNREACH) { - TRACE_ACTION("DELETE", rt); - remque(rt); - free((char *)rt); - } - } -} - -void -rtadd_clone(struct rt_entry *ort, struct sockaddr *dst, - struct sockaddr *gate, short metric, short ticks, int state) -{ - struct afhash h; - register struct rt_entry *rt; - struct rthash *rh; - int af = dst->sa_family, flags; - u_int hash; - - FIXLEN(dst); - FIXLEN(gate); - if (af >= AF_MAX) - return; - (*afswitch[af].af_hash)(dst, &h); - flags = (*afswitch[af].af_ishost)(dst) ? RTF_HOST : 0; - hash = h.afh_nethash; - rh = &nethash[hash & ROUTEHASHMASK]; - rt = (struct rt_entry *)malloc(sizeof (*rt)); - if (rt == 0) - return; - rt->rt_hash = hash; - rt->rt_dst = *dst; - rt->rt_router = *gate; - rt->rt_metric = metric; - rt->rt_ticks = ticks; - rt->rt_timer = 0; - rt->rt_flags = RTF_UP | flags; - rt->rt_state = state | RTS_CHANGED; - rt->rt_ifp = if_ifwithnet(&rt->rt_router); - rt->rt_clone = NULL; - rt->rt_forw = NULL; - rt->rt_back = NULL; - if (metric) - rt->rt_flags |= RTF_GATEWAY; - - while(ort->rt_clone != NULL) - ort = ort->rt_clone; - ort->rt_clone = rt; - TRACE_ACTION("ADD_CLONE", rt); -} - -void -rtchange(struct rt_entry *rt, struct sockaddr *gate, short metric, - short ticks) -{ - int doioctl = 0, metricchanged = 0; - struct rtuentry oldroute; - - FIXLEN(gate); - /* - * Handling of clones. - * When the route changed and it had clones, handle it special. - * 1. If the new route is cheaper than the clone(s), free the clones. - * 2. If the new route is the same cost, it may be one of the clones, - * search for it and free it. - * 3. If the new route is more expensive than the clone(s), use the - * values of the clone(s). - */ - if (rt->rt_clone) { - if ((ticks < rt->rt_clone->rt_ticks) || - ((ticks == rt->rt_clone->rt_ticks) && - (metric < rt->rt_clone->rt_metric))) { - /* - * Free all clones. - */ - struct rt_entry *trt, *nrt; - - trt = rt->rt_clone; - rt->rt_clone = NULL; - while(trt) { - nrt = trt->rt_clone; - free((char *)trt); - trt = nrt; - } - } else if ((ticks == rt->rt_clone->rt_ticks) && - (metric == rt->rt_clone->rt_metric)) { - struct rt_entry *prt, *trt; - - prt = rt; - trt = rt->rt_clone; - - while(trt) { - if (equal(&trt->rt_router, gate)) { - prt->rt_clone = trt->rt_clone; - free(trt); - trt = prt->rt_clone; - } else { - prt = trt; - trt = trt->rt_clone; - } - } - } else { - /* - * Use the values of the first clone. - * Delete the corresponding clone. - */ - struct rt_entry *trt; - - trt = rt->rt_clone; - rt->rt_clone = rt->rt_clone->rt_clone; - metric = trt->rt_metric; - ticks = trt->rt_ticks; - *gate = trt->rt_router; - free((char *)trt); - } - } - - if (!equal(&rt->rt_router, gate)) - doioctl++; - if ((metric != rt->rt_metric) || (ticks != rt->rt_ticks)) - metricchanged++; - if (doioctl || metricchanged) { - TRACE_ACTION("CHANGE FROM", rt); - if (doioctl) { - oldroute = rt->rt_rt; - rt->rt_router = *gate; - } - rt->rt_metric = metric; - rt->rt_ticks = ticks; - if ((rt->rt_state & RTS_INTERFACE) && metric) { - rt->rt_state &= ~RTS_INTERFACE; - if(rt->rt_ifp) - syslog(LOG_ERR, - "changing route from interface %s (timed out)", - rt->rt_ifp->int_name); - else - syslog(LOG_ERR, - "changing route from interface ??? (timed out)"); - } - if (metric) - rt->rt_flags |= RTF_GATEWAY; - else - rt->rt_flags &= ~RTF_GATEWAY; - rt->rt_ifp = if_ifwithnet(&rt->rt_router); - rt->rt_state |= RTS_CHANGED; - TRACE_ACTION("CHANGE TO", rt); - } - if (doioctl && install) { -#ifndef RTM_ADD - if (rtioctl(ADD, &rt->rt_rt) < 0) - syslog(LOG_ERR, "rtioctl ADD dst %s, gw %s: %m", - ipx_ntoa(&((struct sockaddr_ipx *)&rt->rt_dst)->sipx_addr), - ipx_ntoa(&((struct sockaddr_ipx *)&rt->rt_router)->sipx_addr)); - if (delete && rtioctl(DELETE, &oldroute) < 0) - perror("rtioctl DELETE"); -#else - if (delete == 0) { - if (rtioctl(ADD, &rt->rt_rt) >= 0) - return; - } else { - if (rtioctl(CHANGE, &rt->rt_rt) >= 0) - return; - } - syslog(LOG_ERR, "rtioctl ADD dst %s, gw %s: %m", - ipxdp_ntoa(&((struct sockaddr_ipx *)&rt->rt_dst)->sipx_addr), - ipxdp_ntoa(&((struct sockaddr_ipx *)&rt->rt_router)->sipx_addr)); -#endif - } -} - -void -rtdelete(struct rt_entry *rt) -{ - - struct sockaddr *sa = &(rt->rt_router); - FIXLEN(sa); - sa = &(rt->rt_dst); - FIXLEN(sa); - if (rt->rt_clone) { - /* - * If there is a clone we just do a rt_change to it. - */ - struct rt_entry *trt = rt->rt_clone; - rtchange(rt, &trt->rt_router, trt->rt_metric, trt->rt_ticks); - return; - } - if (rt->rt_state & RTS_INTERFACE) { - if (rt->rt_ifp) - syslog(LOG_ERR, - "deleting route to interface %s (timed out)", - rt->rt_ifp->int_name); - else - syslog(LOG_ERR, - "deleting route to interface ??? (timed out)"); - } - TRACE_ACTION("DELETE", rt); - if (install && rtioctl(DELETE, &rt->rt_rt) < 0) - perror("rtioctl DELETE"); - remque(rt); - free((char *)rt); -} - -void -rtinit(void) -{ - register struct rthash *rh; - - for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++) - rh->rt_forw = rh->rt_back = (struct rt_entry *)rh; -} -int seqno; - -int -rtioctl(int action, struct rtuentry *ort) -{ -#ifndef RTM_ADD - if (install == 0) - return (errno = 0); - - ort->rtu_rtflags = ort->rtu_flags; - - switch (action) { - - case ADD: - return (ioctl(s, SIOCADDRT, (char *)ort)); - - case DELETE: - return (ioctl(s, SIOCDELRT, (char *)ort)); - - default: - return (-1); - } -#else /* RTM_ADD */ - struct { - struct rt_msghdr w_rtm; - struct sockaddr w_dst; - struct sockaddr w_gate; - struct sockaddr_ipx w_netmask; - } w; -#define rtm w.w_rtm - - bzero((char *)&w, sizeof(w)); - rtm.rtm_msglen = sizeof(w); - rtm.rtm_version = RTM_VERSION; - rtm.rtm_type = (action == ADD ? RTM_ADD : - (action == DELETE ? RTM_DELETE : RTM_CHANGE)); - rtm.rtm_flags = ort->rtu_flags; - rtm.rtm_seq = ++seqno; - rtm.rtm_addrs = RTA_DST|RTA_GATEWAY; - bcopy((char *)&ort->rtu_dst, (char *)&w.w_dst, sizeof(w.w_dst)); - bcopy((char *)&ort->rtu_router, (char *)&w.w_gate, sizeof(w.w_gate)); - w.w_gate.sa_family = w.w_dst.sa_family = AF_IPX; - w.w_gate.sa_len = w.w_dst.sa_len = sizeof(w.w_dst); - if (rtm.rtm_flags & RTF_HOST) { - rtm.rtm_msglen -= sizeof(w.w_netmask); - } else { - rtm.rtm_addrs |= RTA_NETMASK; - w.w_netmask = ipx_netmask; - rtm.rtm_msglen -= sizeof(w.w_netmask) - ipx_netmask.sipx_len; - } - errno = 0; - return write(r, (char *)&w, rtm.rtm_msglen); -#endif /* RTM_ADD */ -} diff --git a/usr.sbin/IPXrouted/timer.c b/usr.sbin/IPXrouted/timer.c deleted file mode 100644 index 2159730..0000000 --- a/usr.sbin/IPXrouted/timer.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef lint -static const char sccsid[] = "@(#)timer.c 8.1 (Berkeley) 6/5/93"; -#endif /* not lint */ - -/* - * Routing Table Management Daemon - */ -#include "defs.h" -#include -#include - -int timeval = -TIMER_RATE; - -/* - * Timer routine. Performs routing information supply - * duties and manages timers on routing and SAP table entries. - */ -void -timer() -{ - register struct rthash *rh; - register struct rt_entry *rt; - register struct sap_hash *sh; - register struct sap_entry *sap; - struct sap_hash *sap_base = sap_head; - int timetobroadcast, ripbroadcast, sapbroadcast; - - timeval += TIMER_RATE; - if (lookforinterfaces && (timeval % CHECK_INTERVAL) == 0) - ifinit(); - timetobroadcast = supplier && (timeval % SUPPLY_INTERVAL) == 0; - ripbroadcast = supplier && timetobroadcast && - (timeval % RIP_INTERVAL) == 0; - sapbroadcast = timetobroadcast && dosap && !ripbroadcast; - - for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++) { - rt = rh->rt_forw; - for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { - if (rt->rt_clone) { - struct rt_entry *trt, *prt; - /* - * If a clone expire free it and mark the - * main route RTS_CHANGED. - */ - prt = rt; - trt = rt->rt_clone; - while (trt) { - trt->rt_timer += TIMER_RATE; - if (trt->rt_timer >= EXPIRE_TIME) { - prt->rt_clone = trt->rt_clone; - free((char *)trt); - trt = prt->rt_clone; - rt->rt_state |= RTS_CHANGED; - } else { - prt = trt; - trt = prt->rt_clone; - } - } - } - /* - * We don't advance time on a routing entry for - * a passive gateway or that for our only interface. - * The latter is excused because we don't act as - * a routing information supplier and hence would - * time it out. This is fair as if it's down - * we're cut off from the world anyway and it's - * not likely we'll grow any new hardware in - * the mean time. - */ - if (!(rt->rt_state & RTS_PASSIVE) && - !(rt->rt_state & RTS_INTERFACE)) - rt->rt_timer += TIMER_RATE; - if (rt->rt_timer >= EXPIRE_TIME) { - rt->rt_metric = HOPCNT_INFINITY; - rt->rt_state |= RTS_CHANGED; - } - if (rt->rt_timer >= GARBAGE_TIME) { - rt = rt->rt_back; - /* Perhaps we should send a REQUEST for this route? */ - rtdelete(rt->rt_forw); - continue; - } - if (rt->rt_state & RTS_CHANGED) { - rt->rt_state &= ~RTS_CHANGED; - /* don't send extraneous packets */ - if (!supplier || ripbroadcast) - continue; - if ((rt->rt_metric + 1) == HOPCNT_INFINITY) - continue; - msg->rip_cmd = htons(RIPCMD_RESPONSE); - msg->rip_nets[0].rip_dst = - (satoipx_addr(rt->rt_dst)).x_net; - msg->rip_nets[0].rip_metric = - htons(min(rt->rt_metric+1, HOPCNT_INFINITY)); - msg->rip_nets[0].rip_ticks = - htons(rt->rt_ticks + 1); - toall(sndmsg, rt, 0); - } - } - } - if (ripbroadcast) - toall(supply, NULL, 0); - - /* - * Now do the SAP stuff. - */ - for (sh = sap_base; sh < &sap_base[SAPHASHSIZ]; sh++) { - sap = sh->forw; - for (; sap != (struct sap_entry *)sh; sap = sap->forw) { - if (sap->clone) { - struct sap_entry *tsap, *psap; - /* - * If a clone expire free it and mark the - * main sap entry RTS_CHANGED. - */ - psap = sap; - tsap = sap->clone; - while (tsap) { - tsap->timer += TIMER_RATE; - if (tsap->timer >= EXPIRE_TIME) { - psap->clone = tsap->clone; - free((char *)tsap); - tsap = psap->clone; - sap->state |= RTS_CHANGED; - } else { - psap = tsap; - tsap = psap->clone; - } - } - } - sap->timer += TIMER_RATE; - if (sap->timer >= EXPIRE_TIME) { - sap->sap.hops = htons(HOPCNT_INFINITY); - sap->state |= RTS_CHANGED; - } - if (sap->timer >= GARBAGE_TIME) { - sap = sap->back; - /* Perhaps we should send a REQUEST for this route? */ - sap_delete(sap->forw); - continue; - } - /* - * XXX sap_sndmsg on RTS_CHANGED - */ - if (sap->state & RTS_CHANGED) { - sap->state &= ~RTS_CHANGED; -#ifdef notyet - /* don't send extraneous packets */ - if (!supplier || sapbroadcast) - continue; - if ((ntohs(sap->sap.hops) + 1) == HOPCNT_INFINITY) - continue; - sap_msg->sap_cmd = htons(SAP_RESP); - sap_msg->sap[0] = sap->sap; - sap_msg->sap[0].hops = - htons(min(sap->sap.hops+1, HOPCNT_INFINITY)); - toall(sapsndmsg, rt, 0); -#endif - } - } - } - if (sapbroadcast) - sap_supply_toall(0); - if (ftrace && sapbroadcast) - dumpsaptable(ftrace, sap_head); -} - -/* - * On hangup, let everyone know we're going away. - */ -void -hup() -{ - register struct rthash *rh; - register struct rt_entry *rt; - register struct sap_hash *sh; - register struct sap_entry *sap; - - if (supplier) { - for (rh = nethash; rh < &nethash[ROUTEHASHSIZ]; rh++) { - rt = rh->rt_forw; - for (; rt != (struct rt_entry *)rh; rt = rt->rt_forw) - rt->rt_metric = HOPCNT_INFINITY; - } - toall(supply, NULL, 0); - - /* - * Now for SAP. - */ - for (sh = sap_head; sh < &sap_head[SAPHASHSIZ]; sh++) { - sap = sh->forw; - for (; sap != (struct sap_entry *)sh; sap = sap->forw) - sap->sap.hops = htons(HOPCNT_INFINITY); - } - if (dosap) - sap_supply_toall(0); - } - exit(1); -} diff --git a/usr.sbin/IPXrouted/trace.c b/usr.sbin/IPXrouted/trace.c deleted file mode 100644 index d9e74b8..0000000 --- a/usr.sbin/IPXrouted/trace.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - * Copyright (c) 1985, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)trace.c 8.1 (Berkeley) 6/5/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Routing Table Management Daemon - */ -#define RIPCMDS -#define SAPCMDS -#include -#include -#include -#include -#include "defs.h" - -#define NRECORDS 50 /* size of circular trace buffer */ -#ifdef DEBUG -FILE *ftrace = stdout; -int tracing = 1; -#else /* DEBUG */ -FILE *ftrace = NULL; -int tracing = 0; -#endif - -void dumpif(FILE *fd, struct interface *ifp); -void dumptrace(FILE *fd, char *dir, struct ifdebug *ifd); -static int iftraceinit(struct interface *ifp, struct ifdebug *ifd); - -void -traceinit(ifp) - register struct interface *ifp; -{ - if (iftraceinit(ifp, &ifp->int_input) && - iftraceinit(ifp, &ifp->int_output)) - return; - tracing = 0; - syslog(LOG_ERR, "traceinit: can't init %s\n", ifp->int_name); -} - -static int -iftraceinit(ifp, ifd) - struct interface *ifp; - register struct ifdebug *ifd; -{ - register struct iftrace *t; - - ifd->ifd_records = - (struct iftrace *)malloc(NRECORDS * sizeof (struct iftrace)); - if (ifd->ifd_records == 0) - return (0); - ifd->ifd_front = ifd->ifd_records; - ifd->ifd_count = 0; - for (t = ifd->ifd_records; t < ifd->ifd_records + NRECORDS; t++) { - t->ift_size = 0; - t->ift_packet = 0; - } - ifd->ifd_if = ifp; - return (1); -} - -void -traceon(file) - char *file; -{ - - if (ftrace != NULL) - return; - ftrace = fopen(file, "a"); - if (ftrace == NULL) - return; - dup2(fileno(ftrace), 1); - dup2(fileno(ftrace), 2); - tracing = 1; -} - -void -traceoff(void) -{ - if (!tracing) - return; - if (ftrace != NULL) - fclose(ftrace); - ftrace = NULL; - tracing = 0; -} - -void -trace(ifd, who, p, len, m) - register struct ifdebug *ifd; - struct sockaddr *who; - char *p; - int len, m; -{ - register struct iftrace *t; - - if (ifd->ifd_records == 0) - return; - t = ifd->ifd_front++; - if (ifd->ifd_front >= ifd->ifd_records + NRECORDS) - ifd->ifd_front = ifd->ifd_records; - if (ifd->ifd_count < NRECORDS) - ifd->ifd_count++; - if (t->ift_size > 0 && t->ift_packet) - free(t->ift_packet); - t->ift_packet = 0; - t->ift_stamp = time(0); - t->ift_who = *who; - if (len > 0) { - t->ift_packet = malloc(len); - if (t->ift_packet) - bcopy(p, t->ift_packet, len); - else - len = 0; - } - t->ift_size = len; - t->ift_metric = m; -} - -void -traceaction(fd, action, rt) - FILE *fd; - char *action; - struct rt_entry *rt; -{ - struct sockaddr_ipx *dst, *gate; - static struct bits { - int t_bits; - char *t_name; - } flagbits[] = { - { RTF_UP, "UP" }, - { RTF_GATEWAY, "GATEWAY" }, - { RTF_HOST, "HOST" }, - { 0 } - }, statebits[] = { - { RTS_PASSIVE, "PASSIVE" }, - { RTS_REMOTE, "REMOTE" }, - { RTS_INTERFACE,"INTERFACE" }, - { RTS_CHANGED, "CHANGED" }, - { 0 } - }; - register struct bits *p; - register int first; - char *cp; - - if (fd == NULL) - return; - fprintf(fd, "%s ", action); - dst = (struct sockaddr_ipx *)&rt->rt_dst; - gate = (struct sockaddr_ipx *)&rt->rt_router; - fprintf(fd, "dst %s, ", ipxdp_ntoa(&dst->sipx_addr)); - fprintf(fd, "router %s, metric %d, ticks %d, flags", - ipxdp_ntoa(&gate->sipx_addr), rt->rt_metric, rt->rt_ticks); - cp = " %s"; - for (first = 1, p = flagbits; p->t_bits > 0; p++) { - if ((rt->rt_flags & p->t_bits) == 0) - continue; - fprintf(fd, cp, p->t_name); - if (first) { - cp = "|%s"; - first = 0; - } - } - fprintf(fd, " state"); - cp = " %s"; - for (first = 1, p = statebits; p->t_bits > 0; p++) { - if ((rt->rt_state & p->t_bits) == 0) - continue; - fprintf(fd, cp, p->t_name); - if (first) { - cp = "|%s"; - first = 0; - } - } - putc('\n', fd); - if (!tracepackets && (rt->rt_state & RTS_PASSIVE) == 0 && rt->rt_ifp) - dumpif(fd, rt->rt_ifp); - fflush(fd); -} - -void -traceactionlog(action, rt) - char *action; - struct rt_entry *rt; -{ - struct sockaddr_ipx *dst, *gate; - static struct bits { - int t_bits; - char *t_name; - } flagbits[] = { - { RTF_UP, "UP" }, - { RTF_GATEWAY, "GATEWAY" }, - { RTF_HOST, "HOST" }, - { 0 } - }, statebits[] = { - { RTS_PASSIVE, "PASSIVE" }, - { RTS_REMOTE, "REMOTE" }, - { RTS_INTERFACE,"INTERFACE" }, - { RTS_CHANGED, "CHANGED" }, - { 0 } - }; - register struct bits *p; - register int first; - char *cp; - char *lstr, *olstr; - - dst = (struct sockaddr_ipx *)&rt->rt_dst; - gate = (struct sockaddr_ipx *)&rt->rt_router; - asprintf(&lstr, "%s dst %s,", action, ipxdp_ntoa(&dst->sipx_addr)); - olstr = lstr; - asprintf(&lstr, "%s router %s, metric %d, ticks %d, flags", - olstr, ipxdp_ntoa(&gate->sipx_addr), rt->rt_metric, rt->rt_ticks); - free(olstr); - olstr = lstr; - cp = "%s %s"; - for (first = 1, p = flagbits; p->t_bits > 0; p++) { - if ((rt->rt_flags & p->t_bits) == 0) - continue; - asprintf(&lstr, cp, olstr, p->t_name); - free(olstr); - olstr = lstr; - if (first) { - cp = "%s|%s"; - first = 0; - } - } - asprintf(&lstr, "%s state", olstr); - free(olstr); - olstr = lstr; - cp = "%s %s"; - for (first = 1, p = statebits; p->t_bits > 0; p++) { - if ((rt->rt_state & p->t_bits) == 0) - continue; - asprintf(&lstr, cp, olstr, p->t_name); - free(olstr); - olstr = lstr; - if (first) { - cp = "%s|%s"; - first = 0; - } - } - syslog(LOG_DEBUG, "%s", lstr); - free(lstr); -} - -void -tracesapactionlog(action, sap) - char *action; - struct sap_entry *sap; -{ - syslog(LOG_DEBUG, "%-12.12s service %04X %-20.20s " - "addr %s.%04X %c metric %d\n", - action, - ntohs(sap->sap.ServType), - sap->sap.ServName, - ipxdp_ntoa(&sap->sap.ipx), - ntohs(sap->sap.ipx.x_port), - (sap->clone ? 'C' : ' '), - ntohs(sap->sap.hops)); -} - -void -dumpif(fd, ifp) - register struct interface *ifp; - FILE *fd; -{ - if (ifp->int_input.ifd_count || ifp->int_output.ifd_count) { - fprintf(fd, "*** Packet history for interface %s ***\n", - ifp->int_name); - dumptrace(fd, "to", &ifp->int_output); - dumptrace(fd, "from", &ifp->int_input); - fprintf(fd, "*** end packet history ***\n"); - } -} - -void -dumptrace(fd, dir, ifd) - FILE *fd; - char *dir; - register struct ifdebug *ifd; -{ - register struct iftrace *t; - char *cp = !strcmp(dir, "to") ? "Output" : "Input"; - - if (ifd->ifd_front == ifd->ifd_records && - ifd->ifd_front->ift_size == 0) { - fprintf(fd, "%s: no packets.\n", cp); - return; - } - fprintf(fd, "%s trace:\n", cp); - t = ifd->ifd_front - ifd->ifd_count; - if (t < ifd->ifd_records) - t += NRECORDS; - for ( ; ifd->ifd_count; ifd->ifd_count--, t++) { - if (t >= ifd->ifd_records + NRECORDS) - t = ifd->ifd_records; - if (t->ift_size == 0) - continue; - fprintf(fd, "%.24s: metric=%d\n", ctime(&t->ift_stamp), - t->ift_metric); - dumppacket(fd, dir, &t->ift_who, t->ift_packet, t->ift_size); - } -} - -void -dumppacket(fd, dir, source, cp, size) - FILE *fd; - char *dir; - struct sockaddr *source; - char *cp; - register int size; -{ - register struct rip *msg = (struct rip *)cp; - register struct netinfo *n; - struct sockaddr_ipx *who = (struct sockaddr_ipx *)source; - - if (msg->rip_cmd && ntohs(msg->rip_cmd) < RIPCMD_MAX) - fprintf(fd, "%s %s %s#%x", ripcmds[ntohs(msg->rip_cmd)], - dir, ipxdp_ntoa(&who->sipx_addr), - ntohs(who->sipx_addr.x_port)); - else { - fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->rip_cmd), - dir, ipxdp_ntoa(&who->sipx_addr), - ntohs(who->sipx_addr.x_port)); - fprintf(fd, "size=%d cp=%p packet=%p\n", size, - cp, packet); - return; - } - switch (ntohs(msg->rip_cmd)) { - - case RIPCMD_REQUEST: - case RIPCMD_RESPONSE: - fprintf(fd, ":\n"); - size -= sizeof (u_short); - n = msg->rip_nets; - for (; size > 0; n++, size -= sizeof (struct netinfo)) { - if (size < sizeof (struct netinfo)) - break; - fprintf(fd, "\tnet %s metric %d ticks %d\n", - ipxdp_nettoa(n->rip_dst), - ntohs(n->rip_metric), - ntohs(n->rip_ticks)); - } - break; - - } -} - -void -dumpsappacket(fd, dir, source, cp, size) - FILE *fd; - char *dir; - struct sockaddr *source; - char *cp; - register int size; -{ - register struct sap_packet *msg = (struct sap_packet *)cp; - register struct sap_info *n; - struct sockaddr_ipx *who = (struct sockaddr_ipx *)source; - - if (msg->sap_cmd && ntohs(msg->sap_cmd) < SAPCMD_MAX) - fprintf(fd, "%s %s %s#%x", sapcmds[ntohs(msg->sap_cmd)], - dir, ipxdp_ntoa(&who->sipx_addr), - ntohs(who->sipx_addr.x_port)); - else { - fprintf(fd, "Bad cmd 0x%x %s %s#%x\n", ntohs(msg->sap_cmd), - dir, ipxdp_ntoa(&who->sipx_addr), - ntohs(who->sipx_addr.x_port)); - fprintf(fd, "size=%d cp=%p packet=%p\n", size, - cp, packet); - return; - } - switch (ntohs(msg->sap_cmd)) { - - case SAP_REQ: - case SAP_RESP: - case SAP_REQ_NEAR: - case SAP_RESP_NEAR: - fprintf(fd, ":\n"); - size -= sizeof (u_short); - n = msg->sap; - for (; size > 0; n++, size -= sizeof (struct sap_info)) { - if (size < sizeof (struct sap_info)) - break; - fprintf(fd, " service %04X %-20.20s " - "addr %s.%04X metric %d\n", - ntohs(n->ServType), - n->ServName, - ipxdp_ntoa(&n->ipx), - ntohs(n->ipx.x_port), - ntohs(n->hops)); - } - break; - - } -} - -void -dumpsaptable(fd, sh) - FILE *fd; - struct sap_hash *sh; -{ - register struct sap_entry *sap; - struct sap_hash *hash; - int x = 0; - - fprintf(fd, "------- SAP table dump. -------\n"); - for (hash = sh; hash < &sh[SAPHASHSIZ]; hash++, x++) { - fprintf(fd, "HASH %d\n", x); - sap = hash->forw; - for (; sap != (struct sap_entry *)hash; sap = sap->forw) { - fprintf(fd, " service %04X %-20.20s " - "addr %s.%04X %c metric %d\n", - ntohs(sap->sap.ServType), - sap->sap.ServName, - ipxdp_ntoa(&sap->sap.ipx), - ntohs(sap->sap.ipx.x_port), - (sap->clone ? 'C' : ' '), - ntohs(sap->sap.hops)); - } - } - fprintf(fd, "\n"); -} - -void -dumpriptable(fd) - FILE *fd; -{ - register struct rt_entry *rip; - struct rthash *hash; - int x; - struct rthash *rh = nethash; - - fprintf(fd, "------- RIP table dump. -------\n"); - x = 0; - fprintf(fd, "Network table.\n"); - - for (hash = rh; hash < &rh[ROUTEHASHSIZ]; hash++, x++) { - fprintf(fd, "HASH %d\n", x); - rip = hash->rt_forw; - for (; rip != (struct rt_entry *)hash; rip = rip->rt_forw) { - fprintf(fd, " dest %s\t", - ipxdp_ntoa(&satoipx_addr(rip->rt_dst))); - fprintf(fd, "%s metric %d, ticks %d\n", - ipxdp_ntoa(&satoipx_addr(rip->rt_router)), - rip->rt_metric, - rip->rt_ticks); - } - } - fprintf(fd, "\n"); -} - -union ipx_net_u net; - -char * -ipxdp_nettoa(val) -union ipx_net val; -{ - static char buf[100]; - net.net_e = val; - (void)sprintf(buf, "%u", ntohl(net.long_e)); - return (buf); -} - - -char * -ipxdp_ntoa(addr) -struct ipx_addr *addr; -{ - static char buf[100]; - - (void)sprintf(buf, "%s#%x:%x:%x:%x:%x:%x", - ipxdp_nettoa(addr->x_net), - addr->x_host.c_host[0], addr->x_host.c_host[1], - addr->x_host.c_host[2], addr->x_host.c_host[3], - addr->x_host.c_host[4], addr->x_host.c_host[5]); - - return(buf); -} diff --git a/usr.sbin/IPXrouted/trace.h b/usr.sbin/IPXrouted/trace.h deleted file mode 100644 index c83a9d1..0000000 --- a/usr.sbin/IPXrouted/trace.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Copyright (c) 1995 John Hay. All rights reserved. - * - * This file includes significant work done at Cornell University by - * Bill Nesheim. That work included by permission. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)trace.h 8.1 (Berkeley) 6/5/93 - * - * $FreeBSD$ - */ - -/* - * IPX Routing Information Protocol. - */ - -/* - * Trace record format. - */ -struct iftrace { - time_t ift_stamp; /* time stamp */ - struct sockaddr ift_who; /* from/to */ - char *ift_packet; /* pointer to packet */ - short ift_size; /* size of packet */ - short ift_metric; /* metric */ -}; - -/* - * Per interface packet tracing buffers. An incoming and - * outgoing circular buffer of packets is maintained, per - * interface, for debugging. Buffers are dumped whenever - * an interface is marked down. - */ -struct ifdebug { - struct iftrace *ifd_records; /* array of trace records */ - struct iftrace *ifd_front; /* next empty trace record */ - int ifd_count; /* number of unprinted records */ - struct interface *ifd_if; /* for locating stuff */ -}; - -/* - * Packet tracing stuff. - */ -int tracepackets; /* watch packets as they go by */ -int tracing; /* on/off */ -FILE *ftrace; /* output trace file */ - -#define TRACE_ACTION(action, route) { \ - if (tracing) \ - traceaction(ftrace, "action", route); \ - traceactionlog(action, route); \ - } -#define TRACE_SAP_ACTION(action, service) { \ - tracesapactionlog(action, service); \ - } -#define TRACE_INPUT(ifp, src, size) { \ - if (tracing) { \ - ifp = if_iflookup(src); \ - if (ifp) \ - trace(&ifp->int_input, src, \ - &packet[sizeof(struct ipx)], size, \ - ntohl(ifp->int_metric)); \ - } \ - if (tracepackets && ftrace) \ - dumppacket(ftrace, "from", src, \ - &packet[sizeof(struct ipx)], size); \ - } -#define TRACE_OUTPUT(ifp, dst, size) { \ - if (tracing) { \ - ifp = if_iflookup(dst); \ - if (ifp) \ - trace(&ifp->int_output, dst, \ - &packet[sizeof(struct ipx)], \ - size, ifp->int_metric); \ - } \ - if (tracepackets && ftrace) \ - dumppacket(ftrace, "to", dst, \ - &packet[sizeof(struct ipx)], size); \ - } - -#define TRACE_SAP_OUTPUT(ifp, dst, size) { \ - if (tracing) { \ - ifp = if_iflookup(dst); \ - if (ifp) \ - trace(&ifp->int_output, dst, \ - &packet[sizeof(struct ipx)], \ - size, ifp->int_metric); \ - } \ - if (tracepackets && ftrace) \ - dumpsappacket(ftrace, "to", dst, \ - &packet[sizeof(struct ipx)], size); \ - } - -void traceinit(struct interface *); -void traceon(char *file); -void traceoff(void); -void traceaction(FILE *, char *, struct rt_entry *); -void traceactionlog(char *, struct rt_entry *); -void tracesapactionlog(char *action, struct sap_entry *sap); -void trace(struct ifdebug *, struct sockaddr *, char *, int, int); -void dumppacket(FILE *, char *, struct sockaddr *, char *, int); -void dumpsappacket(FILE *, char *, struct sockaddr *, char *, int); -void dumpsaptable(FILE *fd, struct sap_hash *sh); -void dumpriptable(FILE *fd); - -char *ipxdp_nettoa(union ipx_net); -char *ipxdp_ntoa(struct ipx_addr *); - diff --git a/usr.sbin/Makefile b/usr.sbin/Makefile deleted file mode 100644 index a3863d0..0000000 --- a/usr.sbin/Makefile +++ /dev/null @@ -1,309 +0,0 @@ -# From: @(#)Makefile 5.20 (Berkeley) 6/12/93 -# $FreeBSD$ - -.include - -SUBDIR= adduser \ - arp \ - bootparamd \ - burncd \ - cdcontrol \ - chkgrp \ - chown \ - chroot \ - ckdist \ - clear_locks \ - crashinfo \ - cron \ - daemon \ - dconschat \ - devinfo \ - digictl \ - diskinfo \ - dumpcis \ - extattr \ - extattrctl \ - fifolog \ - fwcontrol \ - getfmac \ - getpmac \ - gstat \ - i2c \ - ifmcstat \ - inetd \ - iostat \ - kldxref \ - lastlogin \ - mailwrapper \ - makefs \ - manctl \ - memcontrol \ - mergemaster \ - mfiutil \ - mixer \ - mlxcontrol \ - mountd \ - mount_portalfs \ - mptutil \ - mtest \ - mtree \ - newsyslog \ - nfscbd \ - nfsd \ - nfsdumpstate \ - nfsrevoke \ - nfsuserd \ - nologin \ - pc-sysinstall \ - pciconf \ - periodic \ - powerd \ - procctl \ - pstat \ - pw \ - pwd_mkdb \ - quot \ - rarpd \ - rmt \ - rpcbind \ - rpc.lockd \ - rpc.statd \ - rpc.umntall \ - rtprio \ - service \ - services_mkdb \ - setfib \ - setfmac \ - setpmac \ - smbmsg \ - snapinfo \ - spray \ - syslogd \ - tcpdchk \ - tcpdmatch \ - tcpdrop \ - tcpdump \ - timed \ - traceroute \ - trpt \ - tzsetup \ - ugidfw \ - vipw \ - wake \ - watch \ - watchdogd \ - zic - -# NB: keep these sorted by MK_* knobs - -.if ${MK_ACCT} != "no" -SUBDIR+= ac -SUBDIR+= accton -SUBDIR+= sa -.endif - -.if ${MK_AMD} != "no" -SUBDIR+= amd -.endif - -.if ${MK_AUDIT} != "no" -SUBDIR+= audit -SUBDIR+= auditd -SUBDIR+= auditreduce -SUBDIR+= praudit -.endif - -.if ${MK_AUTHPF} != "no" -SUBDIR+= authpf -.endif - -.if ${MK_BIND_DNSSEC} != "no" && ${MK_OPENSSL} != "no" -SUBDIR+= dnssec-dsfromkey -SUBDIR+= dnssec-keyfromlabel -SUBDIR+= dnssec-keygen -SUBDIR+= dnssec-signzone -.endif -.if ${MK_BIND_NAMED} != "no" -SUBDIR+= named -SUBDIR+= named-checkconf -SUBDIR+= named-checkzone -SUBDIR+= named.reload -SUBDIR+= rndc -SUBDIR+= rndc-confgen -.endif - -.if ${MK_BLUETOOTH} != "no" -SUBDIR+= bluetooth -.endif - -.if ${MK_BSNMP} != "no" -SUBDIR+= bsnmpd -.endif - -.if ${MK_CTM} != "no" -SUBDIR+= ctm -.endif - -.if ${MK_FLOPPY} != "no" -SUBDIR+= fdcontrol -SUBDIR+= fdformat -SUBDIR+= fdread -SUBDIR+= fdwrite -.endif - -.if ${MK_FREEBSD_UPDATE} != "no" -SUBDIR+= freebsd-update -.endif - -.if ${MK_GSSAPI} != no -SUBDIR+= gssd -.endif - -.if ${MK_GPIO} != "no" -SUBDIR+= gpioctl -.endif - -.if ${MK_INET6} != "no" -SUBDIR+= faithd -SUBDIR+= ip6addrctl -SUBDIR+= mld6query -SUBDIR+= ndp -SUBDIR+= rip6query -SUBDIR+= route6d -SUBDIR+= rrenumd -SUBDIR+= rtadvd -SUBDIR+= rtsold -SUBDIR+= traceroute6 -.endif - -.if ${MK_IPFW} != "no" -SUBDIR+= ipfwpcap -.endif - -.if ${MK_IPX} != "no" -SUBDIR+= IPXrouted -.endif - -.if ${MK_JAIL} != "no" -SUBDIR+= jail -SUBDIR+= jexec -SUBDIR+= jls -.endif - -# XXX MK_SYSCONS -.if ${MK_LEGACY_CONSOLE} != "no" -SUBDIR+= kbdcontrol -SUBDIR+= kbdmap -SUBDIR+= moused -SUBDIR+= vidcontrol -.endif - -.if ${MK_LIBTHR} != "no" || ${MK_LIBPTHREAD} != "no" -.if ${MK_PPP} != "no" -SUBDIR+= pppctl -.endif -.if ${MK_NS_CACHING} != "no" -SUBDIR+= nscd -.endif -.endif - -.if ${MK_LPR} != "no" -SUBDIR+= lpr -.endif - -.if ${MK_MAN_UTILS} != "no" -SUBDIR+= manctl -.endif - -.if ${MK_NETGRAPH} != "no" -SUBDIR+= flowctl -SUBDIR+= lmcconfig -SUBDIR+= ngctl -SUBDIR+= nghook -.endif - -.if ${MK_NIS} != "no" -SUBDIR+= rpc.yppasswdd -SUBDIR+= rpc.ypupdated -SUBDIR+= rpc.ypxfrd -SUBDIR+= ypbind -SUBDIR+= yp_mkdb -SUBDIR+= yppoll -SUBDIR+= yppush -SUBDIR+= ypserv -SUBDIR+= ypset -.endif - -.if ${MK_NTP} != "no" -SUBDIR+= ntp -.endif - -.if ${MK_OPENSSL} != "no" -SUBDIR+= keyserv -.endif - -.if ${MK_PF} != "no" -SUBDIR+= ftp-proxy -.endif - -.if ${MK_PKGTOOLS} != "no" -SUBDIR+= pkg_install -.endif - -# XXX MK_TOOLCHAIN? -.if ${MK_PMC} != "no" -SUBDIR+= pmcannotate -SUBDIR+= pmccontrol -SUBDIR+= pmcstat -.endif - -.if ${MK_PORTSNAP} != "no" -SUBDIR+= portsnap -.endif - -.if ${MK_PPP} != "no" -SUBDIR+= ppp -.endif - -.if ${MK_QUOTAS} != "no" -SUBDIR+= edquota -SUBDIR+= quotaon -SUBDIR+= repquota -.endif - -.if ${MK_RCMDS} != "no" -SUBDIR+= rwhod -.endif - -.if ${MK_SENDMAIL} != "no" -SUBDIR+= editmap -SUBDIR+= mailstats -SUBDIR+= makemap -SUBDIR+= praliases -SUBDIR+= sendmail -.endif - -SUBDIR+= sysinstall - -.if ${MK_TOOLCHAIN} != "no" -SUBDIR+= config -SUBDIR+= crunch -.endif - -.if ${MK_USB} != "no" -SUBDIR+= uathload -SUBDIR+= uhsoctl -SUBDIR+= usbconfig -.endif - -.if ${MK_WIRELESS} != "no" -SUBDIR+= ancontrol -SUBDIR+= wlandebug -SUBDIR+= wpa -.endif - -.include - -SUBDIR:= ${SUBDIR:O} - -.include diff --git a/usr.sbin/Makefile.amd64 b/usr.sbin/Makefile.amd64 deleted file mode 100644 index 61f94c4..0000000 --- a/usr.sbin/Makefile.amd64 +++ /dev/null @@ -1,30 +0,0 @@ -# $FreeBSD$ - -# kgzip: builds, but missing support files -# mptable: broken (not 64 bit clean) -# pnpinfo: crashes (not really useful anyway) -.if ${MK_ACPI} != "no" -SUBDIR+= acpi -.endif -.if ${MK_APM} != "no" -SUBDIR+= apm -.endif -SUBDIR+= asf -SUBDIR+= boot0cfg -.if ${MK_TOOLCHAIN} != "no" -SUBDIR+= btxld -.endif -SUBDIR+= cpucontrol -SUBDIR+= kgmon -SUBDIR+= lptcontrol -.if ${MK_NCP} != "no" -SUBDIR+= mount_nwfs -.endif -SUBDIR+= mount_smbfs -SUBDIR+= mptable -.if ${MK_NDIS} != "no" -SUBDIR+= ndiscvt -.endif -SUBDIR+= sicontrol -SUBDIR+= spkrtest -SUBDIR+= zzz diff --git a/usr.sbin/Makefile.arm b/usr.sbin/Makefile.arm deleted file mode 100644 index f19c717..0000000 --- a/usr.sbin/Makefile.arm +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -SUBDIR+= ofwdump -SUBDIR+= kgmon -SUBDIR:= ${SUBDIR:Nsysinstall} diff --git a/usr.sbin/Makefile.i386 b/usr.sbin/Makefile.i386 deleted file mode 100644 index f7870dc..0000000 --- a/usr.sbin/Makefile.i386 +++ /dev/null @@ -1,42 +0,0 @@ -# $FreeBSD$ - -.if ${MK_APM} != "no" -SUBDIR+= apm -SUBDIR+= apmd -.endif -SUBDIR+= asf -.if ${MK_TOOLCHAIN} != "no" -SUBDIR+= btxld -.endif -SUBDIR+= cpucontrol -SUBDIR+= kgmon -SUBDIR+= kgzip -SUBDIR+= lptcontrol -.if ${MK_NCP} != "no" -SUBDIR+= mount_nwfs -.endif -SUBDIR+= mount_smbfs -SUBDIR+= mptable -.if ${MK_NDIS} != "no" -SUBDIR+= ndiscvt -.endif -SUBDIR+= pnpinfo -.if ${MK_SYSINSTALL} != "no" -SUBDIR+= sade -.endif -SUBDIR+= sicontrol -SUBDIR+= spkrtest -SUBDIR+= zzz - -# Differentiate between FreeBSD/i386 and FreeBSD/pc98 -.if ${MACHINE} == "i386" -.if ${MK_ACPI} != "no" -SUBDIR+= acpi -.endif -SUBDIR+= boot0cfg -.if ${MK_WIRELESS} != "no" -SUBDIR+= wlconfig -.endif -.elif ${MACHINE} == "pc98" -SUBDIR+= boot98cfg -.endif diff --git a/usr.sbin/Makefile.ia64 b/usr.sbin/Makefile.ia64 deleted file mode 100644 index 0a897b4..0000000 --- a/usr.sbin/Makefile.ia64 +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD$ - -.if ${MK_ACPI} != "no" -SUBDIR+= acpi -.endif -SUBDIR+= kgmon -SUBDIR+= mount_smbfs -SUBDIR:= ${SUBDIR:Nuathload} -SUBDIR+= zzz diff --git a/usr.sbin/Makefile.inc b/usr.sbin/Makefile.inc deleted file mode 100644 index bd13613..0000000 --- a/usr.sbin/Makefile.inc +++ /dev/null @@ -1,6 +0,0 @@ -# @(#)Makefile.inc 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -BINDIR?= /usr/sbin - -WARNS?= 6 diff --git a/usr.sbin/Makefile.mips b/usr.sbin/Makefile.mips deleted file mode 100644 index 4d30e12..0000000 --- a/usr.sbin/Makefile.mips +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -SUBDIR:= ${SUBDIR:Nsysinstall} -.if defined(TARGET_ABI) && ${TARGET_ABI} == "n64" -SUBDIR:= ${SUBDIR:Nuathload} -.endif diff --git a/usr.sbin/Makefile.powerpc b/usr.sbin/Makefile.powerpc deleted file mode 100644 index 8833a27..0000000 --- a/usr.sbin/Makefile.powerpc +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -SUBDIR+= mount_smbfs -SUBDIR+= nvram -SUBDIR+= ofwdump diff --git a/usr.sbin/Makefile.sparc64 b/usr.sbin/Makefile.sparc64 deleted file mode 100644 index 320226d..0000000 --- a/usr.sbin/Makefile.sparc64 +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -SUBDIR+= eeprom -SUBDIR+= mount_smbfs -SUBDIR+= ofwdump -.if ${MK_SYSINSTALL} != "no" -SUBDIR+= sade -.endif diff --git a/usr.sbin/ac/Makefile b/usr.sbin/ac/Makefile deleted file mode 100644 index 576dbb3..0000000 --- a/usr.sbin/ac/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# $FreeBSD$ - -PROG= ac -MAN= ac.8 - -# Temporary, while tracking down problem wrt 64-bit time_t's on sparc64 -.if ${MACHINE_CPUARCH} == "sparc64" -CFLAGS+=-DDEBUG -.endif - -# If "CONSOLE_TTY" is not defined, this program is compatible with the -# traditional implementation (using SunOS 4.x as the sample traditional -# implementation). This is the default. -# -# If "CONSOLE_TTY" is defined, it must be defined to the appropriate -# console name, e.g. "vga". Additionally, the various commented-out -# sections of the man page should be uncommented. This is not the -# default because of the inability to detect the proper console name -# easily, especially on m68k systems, which can share binaries. -# -#CFLAGS+=-DCONSOLE_TTY=\"vga\" - -.include diff --git a/usr.sbin/ac/ac.8 b/usr.sbin/ac/ac.8 deleted file mode 100644 index 34484ab..0000000 --- a/usr.sbin/ac/ac.8 +++ /dev/null @@ -1,155 +0,0 @@ -.\" -.\" Copyright (c) 1994 Simon J. Gerraty -.\" Copyright (c) 1994 Christopher G. Demetriou -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Christopher G. Demetriou. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd March 15, 1994 -.Dt AC 8 -.Os -.Sh NAME -.Nm ac -.Nd connect time accounting -.Sh SYNOPSIS -.Nm -.Op Fl dp -.\".Op Fl c Ar console -.Op Fl t Ar tty -.Op Fl w Ar wtmp -.Op Ar users ... -.Sh DESCRIPTION -If the file -.Pa /var/log/utx.log -exists, a record of individual login and logout -times are written to it by -.Xr login 1 -and -.Xr init 8 , -respectively. -The -.Nm -utility -examines these records and writes the accumulated connect time (in hours) -for all logins to the standard output. -.Pp -The options are as follows: -.Bl -tag -width indentXXX -.It Fl d -Display the connect times in 24 hour chunks. -.\" .It Fl c Ar console -.\" Use -.\" .Ar console -.\" as the name of the device that local X sessions (ut_host of ":0.0") -.\" originate from. If any login has been recorded on -.\" .Ar console -.\" then these X sessions are ignored unless COMPAT_SUNOS was defined at -.\" compile time. -.It Fl p -Print individual users' totals. -.It Fl t Ar tty -Only do accounting logins on certain ttys. -The -.Ar tty -specification can start with '!' to indicate not this -.Ar tty -and end with '*' to indicate all similarly named ttys. -Multiple -.Fl t -flags may be specified. -.It Fl w Ar wtmp -Read connect time data from -.Ar wtmp -instead of the default file, -.Pa /var/log/utx.log . -.It Ar users ... -Display totals for the given individuals only. -.El -.Pp -If no arguments are given, -.Nm -displays the total connect time for all -accounts with login sessions recorded in -.Pa utx.log . -.Pp -The default -.Pa utx.log -file will increase without bound unless it is truncated. -It is normally truncated by the daily scripts run -by -.Xr cron 8 , -which rename and rotate the -.Pa utx.log -files, keeping a week's worth of data on -hand. -No login or connect time accounting is performed if -.Pa /var/log/utx.log -does not exist. -.Pp -For example, -.Bd -literal -offset -ac -p -t "ttyd*" > modems -ac -p -t "!ttyd*" > other -.Ed -.Pp -allows times recorded in -.Pa modems -to be charged out at a different rate than -.Pa other . -.Sh FILES -.Bl -tag -width /var/log/utx.log -compact -.It Pa /var/log/utx.log -connect time accounting file -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr login 1 , -.Xr getutxent 3 , -.Xr init 8 , -.Xr sa 8 -.\" .Sh NOTES -.\" If COMPAT_SUNOS is defined -.\" .Nm ac -.\" ignores the fact that entries with ut_host of ":0.0" are not real -.\" login sessions. Normally such entries are ignored except in the case -.\" of a user being logged in when the -.\" .Pa wtmp -.\" file was rotated, in which case a login with ut_host of ":0.0" may -.\" appear without any preceding console logins. -.\" If no one is logged in on the console, the user is deemed to have -.\" logged in on at the earliest time stamp found in -.\" .Pa wtmp . -.\" Use of -.\" .Pa console -.\" allows -.\" .Nm ac -.\" to identify and correctly process a logout for the user. The default -.\" value for -.\" .Pa console -.\" is usually correct at compile time. diff --git a/usr.sbin/ac/ac.c b/usr.sbin/ac/ac.c deleted file mode 100644 index c584cd4..0000000 --- a/usr.sbin/ac/ac.c +++ /dev/null @@ -1,636 +0,0 @@ -/* - * Copyright (c) 1994 Christopher G. Demetriou. - * @(#)Copyright (c) 1994, Simon J. Gerraty. - * - * This is free software. It comes with NO WARRANTY. - * Permission to use, modify and distribute this source code - * is granted subject to the following conditions. - * 1/ that the above copyright notice and this notice - * are preserved in all copies and that due credit be given - * to the author. - * 2/ that any changes to this code are clearly commented - * as such so that the author does not get blamed for bugs - * other than his own. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * this is for our list of currently logged in sessions - */ -struct utmp_list { - struct utmp_list *next; - struct utmpx usr; -}; - -/* - * this is for our list of users that are accumulating time. - */ -struct user_list { - struct user_list *next; - char name[sizeof(((struct utmpx *)0)->ut_user)]; - time_t secs; -}; - -/* - * this is for chosing whether to ignore a login - */ -struct tty_list { - struct tty_list *next; - char name[sizeof(((struct utmpx *)0)->ut_host) + 2]; - size_t len; - int ret; -}; - -/* - * globals - yes yuk - */ -#ifdef CONSOLE_TTY -static char *Console = CONSOLE_TTY; -#endif -static time_t Total = 0; -static time_t FirstTime = 0; -static int Flags = 0; -static struct user_list *Users = NULL; -static struct tty_list *Ttys = NULL; - -#define NEW(type) (type *)malloc(sizeof (type)) - -#define AC_W 1 /* not _PATH_WTMP */ -#define AC_D 2 /* daily totals (ignore -p) */ -#define AC_P 4 /* per-user totals */ -#define AC_U 8 /* specified users only */ -#define AC_T 16 /* specified ttys only */ - -#ifdef DEBUG -static int Debug = 0; -#endif - -int main(int, char **); -int ac(const char *); -struct tty_list *add_tty(char *); -#ifdef DEBUG -const char *debug_pfx(const struct utmpx *, const struct utmpx *); -#endif -int do_tty(char *); -struct utmp_list *log_in(struct utmp_list *, struct utmpx *); -struct utmp_list *log_out(struct utmp_list *, struct utmpx *); -int on_console(struct utmp_list *); -void show(const char *, time_t); -void show_today(struct user_list *, struct utmp_list *, - time_t); -void show_users(struct user_list *); -struct user_list *update_user(struct user_list *, char *, time_t); -void usage(void); - -struct tty_list * -add_tty(char *name) -{ - struct tty_list *tp; - char *rcp; - - Flags |= AC_T; - - if ((tp = NEW(struct tty_list)) == NULL) - errx(1, "malloc failed"); - tp->len = 0; /* full match */ - tp->ret = 1; /* do if match */ - if (*name == '!') { /* don't do if match */ - tp->ret = 0; - name++; - } - strlcpy(tp->name, name, sizeof (tp->name)); - if ((rcp = strchr(tp->name, '*')) != NULL) { /* wild card */ - *rcp = '\0'; - tp->len = strlen(tp->name); /* match len bytes only */ - } - tp->next = Ttys; - Ttys = tp; - return Ttys; -} - -/* - * should we process the named tty? - */ -int -do_tty(char *name) -{ - struct tty_list *tp; - int def_ret = 0; - - for (tp = Ttys; tp != NULL; tp = tp->next) { - if (tp->ret == 0) /* specific don't */ - def_ret = 1; /* default do */ - if (tp->len != 0) { - if (strncmp(name, tp->name, tp->len) == 0) - return tp->ret; - } else { - if (strncmp(name, tp->name, sizeof (tp->name)) == 0) - return tp->ret; - } - } - return def_ret; -} - -#ifdef CONSOLE_TTY -/* - * is someone logged in on Console? - */ -int -on_console(struct utmp_list *head) -{ - struct utmp_list *up; - - for (up = head; up; up = up->next) { - if (strcmp(up->usr.ut_line, Console) == 0) - return 1; - } - return 0; -} -#endif - -/* - * update user's login time - */ -struct user_list * -update_user(struct user_list *head, char *name, time_t secs) -{ - struct user_list *up; - - for (up = head; up != NULL; up = up->next) { - if (strcmp(up->name, name) == 0) { - up->secs += secs; - Total += secs; - return head; - } - } - /* - * not found so add new user unless specified users only - */ - if (Flags & AC_U) - return head; - - if ((up = NEW(struct user_list)) == NULL) - errx(1, "malloc failed"); - up->next = head; - strlcpy(up->name, name, sizeof (up->name)); - up->secs = secs; - Total += secs; - return up; -} - -#ifdef DEBUG -/* - * Create a string which is the standard prefix for a debug line. It - * includes a timestamp (perhaps with year), device-name, and user-name. - */ -const char * -debug_pfx(const struct utmpx *event_up, const struct utmpx *userinf_up) -{ - static char str_result[40 + sizeof(userinf_up->ut_line) + - sizeof(userinf_up->ut_user)]; - static char thisyear[5]; - size_t maxcopy; - time_t ut_timecopy; - - if (thisyear[0] == '\0') { - /* Figure out what "this year" is. */ - time(&ut_timecopy); - strlcpy(str_result, ctime(&ut_timecopy), sizeof(str_result)); - strlcpy(thisyear, &str_result[20], sizeof(thisyear)); - } - - if (event_up->ut_tv.tv_sec == 0) - strlcpy(str_result, "*ZeroTime* --:--:-- ", sizeof(str_result)); - else { - ut_timecopy = event_up->ut_tv.tv_sec; - strlcpy(str_result, ctime(&ut_timecopy), sizeof(str_result)); - /* - * Include the year, if it is not the same year as "now". - */ - if (strncmp(&str_result[20], thisyear, 4) == 0) - str_result[20] = '\0'; - else { - str_result[24] = ' '; /* Replace a '\n' */ - str_result[25] = '\0'; - } - } - - if (userinf_up->ut_line[0] == '\0') - strlcat(str_result, "NoDev", sizeof(str_result)); - else { - maxcopy = strlen(str_result) + sizeof(userinf_up->ut_line); - if (maxcopy > sizeof(str_result)) - maxcopy = sizeof(str_result); - strlcat(str_result, userinf_up->ut_line, maxcopy); - } - strlcat(str_result, ": ", sizeof(str_result)); - - if (userinf_up->ut_user[0] == '\0') - strlcat(str_result, "LogOff", sizeof(str_result)); - else { - maxcopy = strlen(str_result) + sizeof(userinf_up->ut_user); - if (maxcopy > sizeof(str_result)) - maxcopy = sizeof(str_result); - strlcat(str_result, userinf_up->ut_user, maxcopy); - } - - return (str_result); -} -#endif - -int -main(int argc, char *argv[]) -{ - const char *wtmpf = NULL; - int c; - - (void) setlocale(LC_TIME, ""); - - while ((c = getopt(argc, argv, "Dc:dpt:w:")) != -1) { - switch (c) { -#ifdef DEBUG - case 'D': - Debug++; - break; -#endif - case 'c': -#ifdef CONSOLE_TTY - Console = optarg; -#else - usage(); /* XXX */ -#endif - break; - case 'd': - Flags |= AC_D; - break; - case 'p': - Flags |= AC_P; - break; - case 't': /* only do specified ttys */ - add_tty(optarg); - break; - case 'w': - Flags |= AC_W; - wtmpf = optarg; - break; - case '?': - default: - usage(); - break; - } - } - if (optind < argc) { - /* - * initialize user list - */ - for (; optind < argc; optind++) { - Users = update_user(Users, argv[optind], (time_t)0); - } - Flags |= AC_U; /* freeze user list */ - } - if (Flags & AC_D) - Flags &= ~AC_P; - ac(wtmpf); - - return 0; -} - -/* - * print login time in decimal hours - */ -void -show(const char *name, time_t secs) -{ - (void)printf("\t%-*s %8.2f\n", - (int)sizeof(((struct utmpx *)0)->ut_user), name, - ((double)secs / 3600)); -} - -void -show_users(struct user_list *list) -{ - struct user_list *lp; - - for (lp = list; lp; lp = lp->next) - show(lp->name, lp->secs); -} - -/* - * print total login time for 24hr period in decimal hours - */ -void -show_today(struct user_list *users, struct utmp_list *logins, time_t secs) -{ - struct user_list *up; - struct utmp_list *lp; - char date[64]; - time_t yesterday = secs - 1; - static int d_first = -1; - - if (d_first < 0) - d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); - (void)strftime(date, sizeof (date), - d_first ? "%e %b total" : "%b %e total", - localtime(&yesterday)); - - /* restore the missing second */ - yesterday++; - - for (lp = logins; lp != NULL; lp = lp->next) { - secs = yesterday - lp->usr.ut_tv.tv_sec; - Users = update_user(Users, lp->usr.ut_user, secs); - lp->usr.ut_tv.tv_sec = yesterday; /* as if they just logged in */ - } - secs = 0; - for (up = users; up != NULL; up = up->next) { - secs += up->secs; - up->secs = 0; /* for next day */ - } - if (secs) - (void)printf("%s %11.2f\n", date, ((double)secs / 3600)); -} - -/* - * log a user out and update their times. - * if ut_line is "~", we log all users out as the system has - * been shut down. - */ -struct utmp_list * -log_out(struct utmp_list *head, struct utmpx *up) -{ - struct utmp_list *lp, *lp2, *tlp; - time_t secs; - - for (lp = head, lp2 = NULL; lp != NULL; ) - if (up->ut_type == BOOT_TIME || up->ut_type == SHUTDOWN_TIME || - (up->ut_type == DEAD_PROCESS && - memcmp(lp->usr.ut_id, up->ut_id, sizeof up->ut_id) == 0)) { - secs = up->ut_tv.tv_sec - lp->usr.ut_tv.tv_sec; - Users = update_user(Users, lp->usr.ut_user, secs); -#ifdef DEBUG - if (Debug) - printf("%s logged out (%2d:%02d:%02d)\n", - debug_pfx(up, &lp->usr), (int)(secs / 3600), - (int)((secs % 3600) / 60), - (int)(secs % 60)); -#endif - /* - * now lose it - */ - tlp = lp; - lp = lp->next; - if (tlp == head) - head = lp; - else if (lp2 != NULL) - lp2->next = lp; - free(tlp); - } else { - lp2 = lp; - lp = lp->next; - } - return head; -} - - -/* - * if do_tty says ok, login a user - */ -struct utmp_list * -log_in(struct utmp_list *head, struct utmpx *up) -{ - struct utmp_list *lp; - - /* - * this could be a login. if we're not dealing with - * the console name, say it is. - * - * If we are, and if ut_host==":0.0" we know that it - * isn't a real login. _But_ if we have not yet recorded - * someone being logged in on Console - due to the wtmp - * file starting after they logged in, we'll pretend they - * logged in, at the start of the wtmp file. - */ - -#ifdef CONSOLE_TTY - if (up->ut_host[0] == ':') { - /* - * SunOS 4.0.2 does not treat ":0.0" as special but we - * do. - */ - if (on_console(head)) - return head; - /* - * ok, no recorded login, so they were here when wtmp - * started! Adjust ut_time! - */ - up->ut_time = FirstTime; - /* - * this allows us to pick the right logout - */ - strlcpy(up->ut_line, Console, sizeof (up->ut_line)); - } -#endif - /* - * If we are doing specified ttys only, we ignore - * anything else. - */ - if (Flags & AC_T) - if (!do_tty(up->ut_line)) - return head; - - /* - * go ahead and log them in - */ - if ((lp = NEW(struct utmp_list)) == NULL) - errx(1, "malloc failed"); - lp->next = head; - head = lp; - memmove(&lp->usr, up, sizeof *up); -#ifdef DEBUG - if (Debug) { - printf("%s logged in", debug_pfx(&lp->usr, up)); - if (*up->ut_host) - printf(" (%-.*s)", (int)sizeof(up->ut_host), - up->ut_host); - putchar('\n'); - } -#endif - return head; -} - -int -ac(const char *file) -{ - struct utmp_list *lp, *head = NULL; - struct utmpx *usr, usht; - struct tm *ltm; - time_t prev_secs, secs, ut_timecopy; - int day, rfound, tchanged, tskipped; - - day = -1; - prev_secs = 1; /* Minimum acceptable date == 1970 */ - rfound = tchanged = tskipped = 0; - secs = 0; - if (setutxdb(UTXDB_LOG, file) != 0) - err(1, "%s", file); - while ((usr = getutxent()) != NULL) { - rfound++; - ut_timecopy = usr->ut_tv.tv_sec; - /* - * With sparc64 using 64-bit time_t's, there is some system - * routine which sets ut_time==0 (the high-order word of a - * 64-bit time) instead of a 32-bit time value. For those - * wtmp files, it is "more-accurate" to substitute the most- - * recent time found, instead of throwing away the entire - * record. While it is still just a guess, it is a better - * guess than throwing away a log-off record and therefore - * counting a session as if it continued to the end of the - * month, or the next system-reboot. - */ - if (ut_timecopy == 0 && prev_secs > 1) { -#ifdef DEBUG - if (Debug) - printf("%s - date changed to: %s", - debug_pfx(usr, usr), ctime(&prev_secs)); -#endif - tchanged++; - usr->ut_tv.tv_sec = ut_timecopy = prev_secs; - } - /* - * Skip records where the time goes backwards. - */ - if (ut_timecopy < prev_secs) { -#ifdef DEBUG - if (Debug) - printf("%s - bad date, record skipped\n", - debug_pfx(usr, usr)); -#endif - tskipped++; - continue; /* Skip this invalid record. */ - } - prev_secs = ut_timecopy; - - if (!FirstTime) - FirstTime = ut_timecopy; - if (Flags & AC_D) { - ltm = localtime(&ut_timecopy); - if (day >= 0 && day != ltm->tm_yday) { - day = ltm->tm_yday; - /* - * print yesterday's total - */ - secs = ut_timecopy; - secs -= ltm->tm_sec; - secs -= 60 * ltm->tm_min; - secs -= 3600 * ltm->tm_hour; - show_today(Users, head, secs); - } else - day = ltm->tm_yday; - } - switch(usr->ut_type) { - case OLD_TIME: - secs = ut_timecopy; - break; - case NEW_TIME: - secs -= ut_timecopy; - /* - * adjust time for those logged in - */ - for (lp = head; lp != NULL; lp = lp->next) - lp->usr.ut_tv.tv_sec -= secs; - break; - case BOOT_TIME: - case SHUTDOWN_TIME: - head = log_out(head, usr); - FirstTime = ut_timecopy; /* shouldn't be needed */ - break; - case USER_PROCESS: - /* - * if they came in on tty[p-sP-S]*, then it is only - * a login session if the ut_host field is non-empty - */ - if (strncmp(usr->ut_line, "tty", 3) != 0 || - strchr("pqrsPQRS", usr->ut_line[3]) == NULL || - *usr->ut_host != '\0') - head = log_in(head, usr); -#ifdef DEBUG - else if (Debug > 1) - /* Things such as 'screen' sessions. */ - printf("%s - record ignored\n", - debug_pfx(usr, usr)); -#endif - break; - case DEAD_PROCESS: - head = log_out(head, usr); - break; - } - } - endutxent(); - if (!(Flags & AC_W)) - usht.ut_tv.tv_sec = time(NULL); - else - usht.ut_tv.tv_sec = ut_timecopy;; - usht.ut_type = SHUTDOWN_TIME; - - if (Flags & AC_D) { - ltm = localtime(&ut_timecopy); - if (day >= 0 && day != ltm->tm_yday) { - /* - * print yesterday's total - */ - secs = ut_timecopy; - secs -= ltm->tm_sec; - secs -= 60 * ltm->tm_min; - secs -= 3600 * ltm->tm_hour; - show_today(Users, head, secs); - } - } - /* - * anyone still logged in gets time up to now - */ - head = log_out(head, &usht); - - if (Flags & AC_D) - show_today(Users, head, time((time_t *)0)); - else { - if (Flags & AC_P) - show_users(Users); - show("total", Total); - } - - if (tskipped > 0) - printf("(Skipped %d of %d records due to invalid time values)\n", - tskipped, rfound); - if (tchanged > 0) - printf("(Changed %d of %d records to have a more likely time value)\n", - tchanged, rfound); - - return 0; -} - -void -usage(void) -{ - (void)fprintf(stderr, -#ifdef CONSOLE_TTY - "ac [-dp] [-c console] [-t tty] [-w wtmp] [users ...]\n"); -#else - "ac [-dp] [-t tty] [-w wtmp] [users ...]\n"); -#endif - exit(1); -} diff --git a/usr.sbin/accton/Makefile b/usr.sbin/accton/Makefile deleted file mode 100644 index ea9b4f4..0000000 --- a/usr.sbin/accton/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -PROG= accton -MAN= accton.8 - -.include diff --git a/usr.sbin/accton/accton.8 b/usr.sbin/accton/accton.8 deleted file mode 100644 index 73c7d29..0000000 --- a/usr.sbin/accton/accton.8 +++ /dev/null @@ -1,42 +0,0 @@ -.\" $FreeBSD$ -.\" -.Dd May 21, 1993 -.Dt ACCTON 8 -.Os -.Sh NAME -.Nm accton -.Nd enable/disable system accounting -.Sh SYNOPSIS -.Nm -.Op Ar acctfile -.Sh DESCRIPTION -The -.Nm -utility is used -for switching system accounting on or off. -If called with the argument -.Ar acctfile , -system accounting is enabled. -The -.Ar acctfile -specified must exist prior to starting system accounting, or -.Nm -will return an error. -A record of every process that is started by the -.Xr execve 2 -system call and then later exits the system is stored in -.Ar acctfile . -The -.Xr sa 8 -command may be used to examine the accounting records. -If no arguments are given, system accounting is disabled. -.Sh FILES -.Bl -tag -width /var/account/acct -.It Pa /var/account/acct -default accounting file -.El -.Sh SEE ALSO -.Xr lastcomm 1 , -.Xr acct 2 , -.Xr acct 5 , -.Xr sa 8 diff --git a/usr.sbin/accton/accton.c b/usr.sbin/accton/accton.c deleted file mode 100644 index 33e6604..0000000 --- a/usr.sbin/accton/accton.c +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1988, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)accton.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ -#endif -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -static void usage(void); - -int -main(int argc, char *argv[]) -{ - int ch; - - while ((ch = getopt(argc, argv, "")) != -1) - switch(ch) { - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - switch(argc) { - case 0: - if (acct(NULL)) - err(1, NULL); - break; - case 1: - if (acct(*argv)) - err(1, "%s", *argv); - break; - default: - usage(); - } - exit(0); -} - -static void -usage(void) -{ - (void)fprintf(stderr, "usage: accton [file]\n"); - exit(1); -} diff --git a/usr.sbin/acpi/Makefile b/usr.sbin/acpi/Makefile deleted file mode 100644 index 8190bc7..0000000 --- a/usr.sbin/acpi/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# Makefile for acpi tools -# $Id: Makefile,v 1.1 2000/07/14 18:16:22 iwasaki Exp $ -# $FreeBSD$ - -SUBDIR= acpiconf acpidb acpidump iasl - -.include diff --git a/usr.sbin/acpi/Makefile.inc b/usr.sbin/acpi/Makefile.inc deleted file mode 100644 index 9d387bc..0000000 --- a/usr.sbin/acpi/Makefile.inc +++ /dev/null @@ -1,24 +0,0 @@ -# $Id: Makefile.inc,v 1.1 2000/07/14 18:16:22 iwasaki Exp $ -# $FreeBSD$ - -ACPICA_DIR= ${.CURDIR}/../../../sys/contrib/dev/acpica -CFLAGS+= -I${.CURDIR}/../../../sys - -.if exists(${.CURDIR}/../../Makefile.inc) -.include "${.CURDIR}/../../Makefile.inc" -.endif - -.PATH: ${ACPICA_DIR} \ - ${ACPICA_DIR}/common \ - ${ACPICA_DIR}/compiler \ - ${ACPICA_DIR}/debugger \ - ${ACPICA_DIR}/disassembler \ - ${ACPICA_DIR}/dispatcher \ - ${ACPICA_DIR}/events \ - ${ACPICA_DIR}/executer \ - ${ACPICA_DIR}/hardware \ - ${ACPICA_DIR}/namespace \ - ${ACPICA_DIR}/parser \ - ${ACPICA_DIR}/resources \ - ${ACPICA_DIR}/tables \ - ${ACPICA_DIR}/utilities diff --git a/usr.sbin/acpi/acpiconf/Makefile b/usr.sbin/acpi/acpiconf/Makefile deleted file mode 100644 index 5f862a2..0000000 --- a/usr.sbin/acpi/acpiconf/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $Id: Makefile,v 1.2 2000/07/14 18:16:25 iwasaki Exp $ -# $FreeBSD$ - -PROG= acpiconf -MAN= acpiconf.8 - -.include diff --git a/usr.sbin/acpi/acpiconf/acpiconf.8 b/usr.sbin/acpi/acpiconf/acpiconf.8 deleted file mode 100644 index 05d3a5d..0000000 --- a/usr.sbin/acpi/acpiconf/acpiconf.8 +++ /dev/null @@ -1,92 +0,0 @@ -.\"- -.\" Copyright (c) 2000 Dag-Erling Coïdan Smørgrav -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer -.\" in this position and unchanged. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd August 16, 2004 -.Dt ACPICONF 8 -.Os -.Sh NAME -.Nm acpiconf -.Nd control ACPI power management -.Sh SYNOPSIS -.Nm -.Op Fl h -.Op Fl i Ar batt -.Op Fl s Ar type -.Sh DESCRIPTION -The -.Nm -utility allows the user control of the ACPI power management -functions. -The following command-line options are recognized: -.Bl -tag -width ".Fl s Ar type" -.It Fl h -Displays a summary of available options. -.It Fl i Ar batt -Get design information about the specified battery. -.It Fl s Ar type -Enters the specified sleep mode. -Recognized types are -.Cm 1 -(only the CPU clock is stopped), -.Cm 2 -(not implemented on most systems but similar to S1), -.Cm 3 -(the CPU context is lost and memory context is preserved), -.Cm 4 -(the CPU context is lost and memory context is stored to disk) -and -.Cm 5 -(soft off). -Sleep states may also be given as S1, S2, etc. -The supported states depend on BIOS implementation, including ACPI -byte code (AML). -If the -.Pa /etc/rc.suspend -and -.Pa /etc/rc.resume -scripts are executable, they will be run before and after entering -the given sleep state. -.El -.Sh SEE ALSO -.Xr acpi 4 , -.Xr acpidump 8 , -.Xr apm 8 -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 5.0 . -.Sh AUTHORS -.An -nosplit -The -.Nm -utility was written by -.An Mitsuru Iwasaki Aq iwasaki@FreeBSD.org . -This manual page was written by -.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org . diff --git a/usr.sbin/acpi/acpiconf/acpiconf.c b/usr.sbin/acpi/acpiconf/acpiconf.c deleted file mode 100644 index 5ca2f98..0000000 --- a/usr.sbin/acpi/acpiconf/acpiconf.c +++ /dev/null @@ -1,233 +0,0 @@ -/*- - * Copyright (c) 1999 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: acpiconf.c,v 1.5 2000/08/08 14:12:19 iwasaki Exp $ - * $FreeBSD$ - */ - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include - -#define ACPIDEV "/dev/acpi" - -static int acpifd; - -static void -acpi_init(void) -{ - acpifd = open(ACPIDEV, O_RDWR); - if (acpifd == -1) - acpifd = open(ACPIDEV, O_RDONLY); - if (acpifd == -1) - err(EX_OSFILE, ACPIDEV); -} - -/* Prepare to sleep and then wait for the signal that sleeping can occur. */ -static void -acpi_sleep(int sleep_type) -{ - int ret; - - /* Notify OS that we want to sleep. devd(8) gets this notify. */ - ret = ioctl(acpifd, ACPIIO_REQSLPSTATE, &sleep_type); - if (ret != 0) - err(EX_IOERR, "request sleep type (%d) failed", sleep_type); -} - -/* Ack or abort a pending suspend request. */ -static void -acpi_sleep_ack(int err_val) -{ - int ret; - - ret = ioctl(acpifd, ACPIIO_ACKSLPSTATE, &err_val); - if (ret != 0) - err(EX_IOERR, "ack sleep type failed"); -} - -/* should be a acpi define, but doesn't appear to be */ -#define UNKNOWN_CAP 0xffffffff -#define UNKNOWN_VOLTAGE 0xffffffff - -static int -acpi_battinfo(int num) -{ - union acpi_battery_ioctl_arg battio; - const char *pwr_units; - int hours, min, amp; - uint32_t volt; - - if (num < 0 || num > 64) - err(EX_USAGE, "invalid battery %d", num); - - /* Print battery design information. */ - battio.unit = num; - if (ioctl(acpifd, ACPIIO_BATT_GET_BIF, &battio) == -1) - err(EX_IOERR, "get battery info (%d) failed", num); - amp = battio.bif.units; - pwr_units = amp ? "mA" : "mW"; - if (battio.bif.dcap == UNKNOWN_CAP) - printf("Design capacity:\tunknown\n"); - else - printf("Design capacity:\t%d %sh\n", battio.bif.dcap, - pwr_units); - if (battio.bif.lfcap == UNKNOWN_CAP) - printf("Last full capacity:\tunknown\n"); - else - printf("Last full capacity:\t%d %sh\n", battio.bif.lfcap, - pwr_units); - printf("Technology:\t\t%s\n", battio.bif.btech == 0 ? - "primary (non-rechargeable)" : "secondary (rechargeable)"); - if (battio.bif.dvol == UNKNOWN_CAP) - printf("Design voltage:\t\tunknown\n"); - else - printf("Design voltage:\t\t%d mV\n", battio.bif.dvol); - printf("Capacity (warn):\t%d %sh\n", battio.bif.wcap, pwr_units); - printf("Capacity (low):\t\t%d %sh\n", battio.bif.lcap, pwr_units); - printf("Low/warn granularity:\t%d %sh\n", battio.bif.gra1, pwr_units); - printf("Warn/full granularity:\t%d %sh\n", battio.bif.gra2, pwr_units); - printf("Model number:\t\t%s\n", battio.bif.model); - printf("Serial number:\t\t%s\n", battio.bif.serial); - printf("Type:\t\t\t%s\n", battio.bif.type); - printf("OEM info:\t\t%s\n", battio.bif.oeminfo); - - /* Fetch battery voltage information. */ - volt = UNKNOWN_VOLTAGE; - battio.unit = num; - if (ioctl(acpifd, ACPIIO_BATT_GET_BST, &battio) == -1) - err(EX_IOERR, "get battery status (%d) failed", num); - if (battio.bst.state != ACPI_BATT_STAT_NOT_PRESENT) - volt = battio.bst.volt; - - /* Print current battery state information. */ - battio.unit = num; - if (ioctl(acpifd, ACPIIO_BATT_GET_BATTINFO, &battio) == -1) - err(EX_IOERR, "get battery user info (%d) failed", num); - if (battio.battinfo.state != ACPI_BATT_STAT_NOT_PRESENT) { - printf("State:\t\t\t"); - if (battio.battinfo.state == 0) - printf("high "); - if (battio.battinfo.state & ACPI_BATT_STAT_CRITICAL) - printf("critical "); - if (battio.battinfo.state & ACPI_BATT_STAT_DISCHARG) - printf("discharging "); - if (battio.battinfo.state & ACPI_BATT_STAT_CHARGING) - printf("charging "); - printf("\n"); - if (battio.battinfo.cap == -1) - printf("Remaining capacity:\tunknown\n"); - else - printf("Remaining capacity:\t%d%%\n", - battio.battinfo.cap); - if (battio.battinfo.min == -1) - printf("Remaining time:\t\tunknown\n"); - else { - hours = battio.battinfo.min / 60; - min = battio.battinfo.min % 60; - printf("Remaining time:\t\t%d:%02d\n", hours, min); - } - if (battio.battinfo.rate == -1) - printf("Present rate:\t\tunknown\n"); - else if (amp && volt != UNKNOWN_VOLTAGE) { - printf("Present rate:\t\t%d mA (%d mW)\n", - battio.battinfo.rate, - battio.battinfo.rate * volt / 1000); - } else - printf("Present rate:\t\t%d %s\n", - battio.battinfo.rate, pwr_units); - } else - printf("State:\t\t\tnot present\n"); - - /* Print battery voltage information. */ - if (volt == UNKNOWN_VOLTAGE) - printf("Present voltage:\tunknown\n"); - else - printf("Present voltage:\t%d mV\n", volt); - - return (0); -} - -static void -usage(const char* prog) -{ - printf("usage: %s [-h] [-i batt] [-k ack] [-s 1-4]\n", prog); - exit(0); -} - -int -main(int argc, char *argv[]) -{ - char c, *prog; - int sleep_type; - - prog = argv[0]; - if (argc < 2) - usage(prog); - /* NOTREACHED */ - - sleep_type = -1; - acpi_init(); - while ((c = getopt(argc, argv, "hi:k:s:")) != -1) { - switch (c) { - case 'i': - acpi_battinfo(atoi(optarg)); - break; - case 'k': - acpi_sleep_ack(atoi(optarg)); - break; - case 's': - if (optarg[0] == 'S') - sleep_type = optarg[1] - '0'; - else - sleep_type = optarg[0] - '0'; - if (sleep_type < 1 || sleep_type > 4) - errx(EX_USAGE, "invalid sleep type (%d)", - sleep_type); - break; - case 'h': - default: - usage(prog); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - - if (sleep_type != -1) - acpi_sleep(sleep_type); - - close(acpifd); - exit (0); -} diff --git a/usr.sbin/acpi/acpidb/Makefile b/usr.sbin/acpi/acpidb/Makefile deleted file mode 100644 index 3ff837f..0000000 --- a/usr.sbin/acpi/acpidb/Makefile +++ /dev/null @@ -1,68 +0,0 @@ -# $FreeBSD$ - -PROG= acpidb -SRCS= acpidb.c -SRCS+= osunixxf.c - -# debugger -SRCS+= dbcmds.c dbdisply.c dbexec.c dbfileio.c dbhistry.c \ - dbinput.c dbstats.c dbutils.c dbxface.c - -# disassembler -SRCS+= dmbuffer.c dmnames.c dmobject.c dmopcode.c dmresrc.c \ - dmresrcl.c dmresrcs.c dmutils.c dmwalk.c - -# events -SRCS+= evevent.c evgpe.c evgpeblk.c evgpeinit.c evgpeutil.c \ - evmisc.c evregion.c evrgnini.c evsci.c evxface.c \ - evxfevnt.c evxfregn.c - -# hardware -SRCS+= hwacpi.c hwgpe.c hwpci.c hwregs.c hwsleep.c hwvalid.c \ - hwxface.c - -# interpreter/dispatcher -SRCS+= dsfield.c dsinit.c dsmethod.c dsmthdat.c dsobject.c \ - dsopcode.c dsutils.c dswexec.c dswload.c dswscope.c \ - dswstate.c - -# interpreter/executer -SRCS+= exconfig.c exconvrt.c excreate.c exdebug.c exdump.c \ - exfield.c exfldio.c exmisc.c exmutex.c exnames.c \ - exoparg1.c exoparg2.c exoparg3.c exoparg6.c exprep.c \ - exregion.c exresnte.c exresolv.c exresop.c exstore.c \ - exstoren.c exstorob.c exsystem.c exutils.c - -# interpreter/parser -SRCS+= psargs.c psloop.c psopcode.c psparse.c psscope.c \ - pstree.c psutils.c pswalk.c psxface.c - -# namespace -SRCS+= nsaccess.c nsalloc.c nsdump.c nseval.c nsinit.c \ - nsload.c nsnames.c nsobject.c nsparse.c nspredef.c \ - nsrepair.c nsrepair2.c nssearch.c nsutils.c nswalk.c \ - nsxfeval.c nsxfname.c nsxfobj.c - -# resources -SRCS+= rsaddr.c rscalc.c rscreate.c rsdump.c rsinfo.c \ - rsio.c rsirq.c rslist.c rsmemory.c rsmisc.c \ - rsutils.c rsxface.c - -# tables -SRCS+= tbfadt.c tbfind.c tbinstal.c tbutils.c tbxface.c \ - tbxfroot.c - -# utilities -SRCS+= utalloc.c utcache.c utcopy.c utdebug.c utdelete.c \ - uteval.c utglobal.c utids.c utinit.c utlock.c utmath.c \ - utmisc.c utmutex.c utobject.c utosi.c utresrc.c \ - utstate.c uttrack.c utxface.c utxferror.c - -MAN= acpidb.8 -WARNS?= 2 - -CFLAGS+= -DACPI_EXEC_APP -fno-strict-aliasing -DPADD= ${LIBPTHREAD} -LDADD= -lpthread - -.include diff --git a/usr.sbin/acpi/acpidb/acpidb.8 b/usr.sbin/acpi/acpidb/acpidb.8 deleted file mode 100644 index 4ed97a6..0000000 --- a/usr.sbin/acpi/acpidb/acpidb.8 +++ /dev/null @@ -1,167 +0,0 @@ -.\"- -.\" Copyright (c) 2003 Nate Lawson -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer -.\" in this position and unchanged. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd August 7, 2003 -.Dt ACPIDB 8 -.Os -.Sh NAME -.Nm acpidb -.Nd ACPI DSDT debugger -.Sh SYNOPSIS -.Nm -.Ar input-file -.Sh DESCRIPTION -The -.Nm -utility is a debugger for the ACPI DSDT. -It can parse and execute various -AML methods and display the result. -.Sh COMMANDS -.Ss General-Purpose Commands -.Bl -tag -width indent -.It Ic Allocations -Display list of current memory allocations -.It Ic Dump Ar Address | Namepath Op Cm Byte | Word | Dword | Qword -Display ACPI objects or memory -.It Ic EnableAcpi -Enable ACPI (hardware) mode -.It Ic Help -Show various help screens -.It Ic History -Display command history buffer -.It Ic Level Ar DebugLevel Op Cm console -Get/Set debug level for file or console -.It Ic Locks -Current status of internal mutexes -.It Ic Quit No or Ic Exit -Exit the debugger -.It Ic Stats Op Cm Allocations | Memory | Misc | Objects | Tables -Display namespace and memory statistics -.It Ic Tables -Display info about loaded ACPI tables -.It Ic Unload Ar TableSig Op Ar Instance -Unload an ACPI table -.It Ic !\& Ar CommandNumber -Execute command from history buffer -.It Ic !! -Execute last command again -.El -.Ss Namespace Access Commands -.Bl -tag -width indent -.It Ic Event Cm F | G Ar Value -Generate AcpiEvent (Fixed/GPE) -.It Ic Find Ar Name -Find ACPI name(s) with wildcards -.Ql ( ?\& -is wildcard) -.It Ic Method -Display list of loaded control methods -.It Ic Namespace Oo Ar Addr | Path Oc Op Ar Depth -Display loaded namespace tree/subtree -.It Ic Notify Ar NamePath Value -Send a notification -.It Ic Objects Ar ObjectType -Display all objects of the given type -.It Ic Owner Ar OwnerId Op Ar Depth -Display loaded namespace by object owner -.It Ic Prefix Op Ar NamePath -Set or Get current execution prefix -.It Ic References Ar Addr -Find all references to object at addr -.It Ic Resources -Get and display resources -.It Ic Terminate -Delete namespace and all internal objects -.It Ic Thread Ar Threads Loops NamePath -Spawn threads to execute method(s) -.El -.Ss Control Method Execution Commands -.Bl -tag -width indent -.It Ic Arguments -.Pq Ic Args -Display method arguments -.It Ic Breakpoint Ar AmlOffset -Set an AML execution breakpoint -.It Ic Call -Run to next control method invocation -.It Ic Debug Ar Namepath Op Ar Arguments -Single Step a control method -.It Ic Execute Ar Namepath Op Arguments -Execute control method -.It Ic Go -Allow method to run to completion -.It Ic Information -Display info about the current method -.It Ic Into -Step into (not over) a method call -.It Ic List Op OpcodeCount -Display method ASL statements -.It Ic Locals -Display method local variables -.It Ic Results -Display method result stack -.It Ic Set Cm A | L Ar # Value -Set method data (Arguments/Locals) -.It Ic Stop -Terminate control method -.It Ic Tree -Display control method calling tree -.It Ic -Single step next AML opcode (over calls) -.El -.Ss File I/O Commands -.Bl -tag -width indent -.It Ic Close -Close debug output file -.It Ic Open Ar Filename -Open a file for debug output -.It Ic Load Ar Filename -Load ACPI table from a file -.El -.Sh SEE ALSO -.Xr acpi 4 , -.Xr acpidump 8 , -.Xr iasl 8 -.Sh HISTORY -The -.Nm -utility first appeared in the -.Nm acpicatools -port. -It was imported for -.Fx 5.2 . -.Sh AUTHORS -.An -nosplit -The -.Nm -utility was written by -.An Mitsuru Iwasaki Aq iwasaki@FreeBSD.org -and uses Intel ACPI-CA for the backend. -This manual page was written by -.An Nate Lawson . diff --git a/usr.sbin/acpi/acpidb/acpidb.c b/usr.sbin/acpi/acpidb/acpidb.c deleted file mode 100644 index 325dfae..0000000 --- a/usr.sbin/acpi/acpidb/acpidb.c +++ /dev/null @@ -1,503 +0,0 @@ -/*- - * Copyright (c) 2000-2002 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/* - * Dummy DSDT Table Header - */ - -ACPI_TABLE_HEADER dummy_dsdt_table = { - "DSDT", 123, 1, 123, "OEMID", "OEMTBLID", 1, "CRID", 1 -}; - -/* - * Region space I/O routines on virtual machine - */ - -int aml_debug_prompt = 1; - -struct ACPIRegionContent { - TAILQ_ENTRY(ACPIRegionContent) links; - int regtype; - ACPI_PHYSICAL_ADDRESS addr; - UINT8 value; -}; - -TAILQ_HEAD(ACPIRegionContentList, ACPIRegionContent); -struct ACPIRegionContentList RegionContentList; - -static int aml_simulation_initialized = 0; - -static void aml_simulation_init(void); -static int aml_simulate_regcontent_add(int regtype, - ACPI_PHYSICAL_ADDRESS addr, - UINT8 value); -static int aml_simulate_regcontent_read(int regtype, - ACPI_PHYSICAL_ADDRESS addr, - UINT8 *valuep); -static int aml_simulate_regcontent_write(int regtype, - ACPI_PHYSICAL_ADDRESS addr, - UINT8 *valuep); -static UINT64 aml_simulate_prompt(char *msg, UINT64 def_val); -static void aml_simulation_regload(const char *dumpfile); -static void aml_simulation_regdump(const char *dumpfile); - -/* Stubs to simplify linkage to the ACPI CA core subsystem. */ -ACPI_STATUS -AeLocalGetRootPointer(void) -{ - - return (AE_ERROR); -} - -void -AeTableOverride(ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable) -{ -} - -static void -aml_simulation_init(void) -{ - - aml_simulation_initialized = 1; - TAILQ_INIT(&RegionContentList); - aml_simulation_regload("region.ini"); -} - -static int -aml_simulate_regcontent_add(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 value) -{ - struct ACPIRegionContent *rc; - - rc = malloc(sizeof(struct ACPIRegionContent)); - if (rc == NULL) { - return (-1); /* malloc fail */ - } - rc->regtype = regtype; - rc->addr = addr; - rc->value = value; - - TAILQ_INSERT_TAIL(&RegionContentList, rc, links); - return (0); -} - -static int -aml_simulate_regcontent_read(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep) -{ - struct ACPIRegionContent *rc; - - if (!aml_simulation_initialized) { - aml_simulation_init(); - } - TAILQ_FOREACH(rc, &RegionContentList, links) { - if (rc->regtype == regtype && rc->addr == addr) { - *valuep = rc->value; - return (1); /* found */ - } - } - - *valuep = 0; - return (aml_simulate_regcontent_add(regtype, addr, *valuep)); -} - -static int -aml_simulate_regcontent_write(int regtype, ACPI_PHYSICAL_ADDRESS addr, UINT8 *valuep) -{ - struct ACPIRegionContent *rc; - - if (!aml_simulation_initialized) { - aml_simulation_init(); - } - TAILQ_FOREACH(rc, &RegionContentList, links) { - if (rc->regtype == regtype && rc->addr == addr) { - rc->value = *valuep; - return (1); /* exists */ - } - } - - return (aml_simulate_regcontent_add(regtype, addr, *valuep)); -} - -static UINT64 -aml_simulate_prompt(char *msg, UINT64 def_val) -{ - char buf[16], *ep; - UINT64 val; - - val = def_val; - printf("DEBUG"); - if (msg != NULL) { - printf("%s", msg); - } - printf("(default: 0x%jx ", val); - printf(" / %ju) >>", val); - fflush(stdout); - - bzero(buf, sizeof buf); - while (1) { - if (read(0, buf, sizeof buf) == 0) { - continue; - } - if (buf[0] == '\n') { - break; /* use default value */ - } - if (buf[0] == '0' && buf[1] == 'x') { - val = strtoq(buf, &ep, 16); - } else { - val = strtoq(buf, &ep, 10); - } - break; - } - return (val); -} - -static void -aml_simulation_regload(const char *dumpfile) -{ - char buf[256], *np, *ep; - struct ACPIRegionContent rc; - FILE *fp; - - if (!aml_simulation_initialized) { - return; - } - - if ((fp = fopen(dumpfile, "r")) == NULL) { - return; - } - - while (fgets(buf, sizeof buf, fp) != NULL) { - np = buf; - /* reading region type */ - rc.regtype = strtoq(np, &ep, 10); - if (np == ep) { - continue; - } - np = ep; - - /* reading address */ - rc.addr = strtoq(np, &ep, 16); - if (np == ep) { - continue; - } - np = ep; - - /* reading value */ - rc.value = strtoq(np, &ep, 16); - if (np == ep) { - continue; - } - aml_simulate_regcontent_write(rc.regtype, rc.addr, &rc.value); - } - - fclose(fp); -} - -static void -aml_simulation_regdump(const char *dumpfile) -{ - struct ACPIRegionContent *rc; - FILE *fp; - - if (!aml_simulation_initialized) { - return; - } - if ((fp = fopen(dumpfile, "w")) == NULL) { - warn("%s", dumpfile); - return; - } - while (!TAILQ_EMPTY(&RegionContentList)) { - rc = TAILQ_FIRST(&RegionContentList); - fprintf(fp, "%d 0x%jx 0x%x\n", - rc->regtype, (uintmax_t)rc->addr, rc->value); - TAILQ_REMOVE(&RegionContentList, rc, links); - free(rc); - } - - fclose(fp); - TAILQ_INIT(&RegionContentList); -} - -/* - * Space handlers on virtual machine - */ - -static ACPI_STATUS -aml_vm_space_handler( - UINT32 SpaceID, - UINT32 Function, - ACPI_PHYSICAL_ADDRESS Address, - UINT32 BitWidth, - UINT64 *Value, - int Prompt) -{ - int state; - UINT8 val; - UINT64 value, i; - char msg[256]; - static const char *space_names[] = { - "SYSTEM_MEMORY", "SYSTEM_IO", "PCI_CONFIG", - "EC", "SMBUS", "CMOS", "PCI_BAR_TARGET"}; - - switch (Function) { - case ACPI_READ: - value = 0; - for (i = 0; (i * 8) < BitWidth; i++) { - state = aml_simulate_regcontent_read(SpaceID, - Address + i, &val); - if (state == -1) { - return (AE_NO_MEMORY); - } - value |= val << (i * 8); - } - *Value = value; - if (Prompt) { - sprintf(msg, "[read (%s, %2d, 0x%jx)]", - space_names[SpaceID], BitWidth, - (uintmax_t)Address); - *Value = aml_simulate_prompt(msg, value); - if (*Value != value) { - return(aml_vm_space_handler(SpaceID, - ACPI_WRITE, - Address, BitWidth, Value, 0)); - } - } - break; - - case ACPI_WRITE: - value = *Value; - if (Prompt) { - sprintf(msg, "[write(%s, %2d, 0x%jx)]", - space_names[SpaceID], BitWidth, - (uintmax_t)Address); - value = aml_simulate_prompt(msg, *Value); - } - *Value = value; - for (i = 0; (i * 8) < BitWidth; i++) { - val = value & 0xff; - state = aml_simulate_regcontent_write(SpaceID, - Address + i, &val); - if (state == -1) { - return (AE_NO_MEMORY); - } - value = value >> 8; - } - } - - return (AE_OK); -} - -#define DECLARE_VM_SPACE_HANDLER(name, id); \ -static ACPI_STATUS \ -aml_vm_space_handler_##name ( \ - UINT32 Function, \ - ACPI_PHYSICAL_ADDRESS Address, \ - UINT32 BitWidth, \ - UINT64 *Value) \ -{ \ - return (aml_vm_space_handler(id, Function, Address, \ - BitWidth, Value, aml_debug_prompt)); \ -} - -DECLARE_VM_SPACE_HANDLER(system_memory, ACPI_ADR_SPACE_SYSTEM_MEMORY); -DECLARE_VM_SPACE_HANDLER(system_io, ACPI_ADR_SPACE_SYSTEM_IO); -DECLARE_VM_SPACE_HANDLER(pci_config, ACPI_ADR_SPACE_PCI_CONFIG); -DECLARE_VM_SPACE_HANDLER(ec, ACPI_ADR_SPACE_EC); -DECLARE_VM_SPACE_HANDLER(smbus, ACPI_ADR_SPACE_SMBUS); -DECLARE_VM_SPACE_HANDLER(cmos, ACPI_ADR_SPACE_CMOS); -DECLARE_VM_SPACE_HANDLER(pci_bar_target,ACPI_ADR_SPACE_PCI_BAR_TARGET); - -/* - * Load DSDT data file and invoke debugger - */ - -static int -load_dsdt(const char *dsdtfile) -{ - char filetmp[PATH_MAX]; - u_int8_t *code; - struct stat sb; - int fd, fd2; - int error; - - fd = open(dsdtfile, O_RDONLY, 0); - if (fd == -1) { - perror("open"); - return (-1); - } - if (fstat(fd, &sb) == -1) { - perror("fstat"); - return (-1); - } - code = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0); - if (code == NULL) { - perror("mmap"); - return (-1); - } - if ((error = AcpiInitializeSubsystem()) != AE_OK) { - return (-1); - } - - /* - * make sure DSDT data contains table header or not. - */ - if (strncmp((char *)code, "DSDT", 4) == 0) { - strncpy(filetmp, dsdtfile, sizeof(filetmp)); - } else { - mode_t mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - dummy_dsdt_table.Length = sizeof(ACPI_TABLE_HEADER) + sb.st_size; - snprintf(filetmp, sizeof(filetmp), "%s.tmp", dsdtfile); - fd2 = open(filetmp, O_WRONLY | O_CREAT | O_TRUNC, mode); - if (fd2 == -1) { - perror("open"); - return (-1); - } - write(fd2, &dummy_dsdt_table, sizeof(ACPI_TABLE_HEADER)); - - write(fd2, code, sb.st_size); - close(fd2); - } - - /* - * Install the virtual machine version of address space handlers. - */ - if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, - ACPI_ADR_SPACE_SYSTEM_MEMORY, - (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_memory, - NULL, NULL)) != AE_OK) { - fprintf(stderr, "could not initialise SystemMemory handler: %d\n", error); - return (-1); - } - if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, - ACPI_ADR_SPACE_SYSTEM_IO, - (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_system_io, - NULL, NULL)) != AE_OK) { - fprintf(stderr, "could not initialise SystemIO handler: %d\n", error); - return (-1); - } - if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, - ACPI_ADR_SPACE_PCI_CONFIG, - (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_config, - NULL, NULL)) != AE_OK) { - fprintf(stderr, "could not initialise PciConfig handler: %d\n", error); - return (-1); - } - if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, - ACPI_ADR_SPACE_EC, - (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_ec, - NULL, NULL)) != AE_OK) { - fprintf(stderr, "could not initialise EC handler: %d\n", error); - return (-1); - } - if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, - ACPI_ADR_SPACE_SMBUS, - (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_smbus, - NULL, NULL)) != AE_OK) { - fprintf(stderr, "could not initialise SMBUS handler: %d\n", error); - return (-1); - } - if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, - ACPI_ADR_SPACE_CMOS, - (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_cmos, - NULL, NULL)) != AE_OK) { - fprintf(stderr, "could not initialise CMOS handler: %d\n", error); - return (-1); - } - if ((error = AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT, - ACPI_ADR_SPACE_PCI_BAR_TARGET, - (ACPI_ADR_SPACE_HANDLER)aml_vm_space_handler_pci_bar_target, - NULL, NULL)) != AE_OK) { - fprintf(stderr, "could not initialise PCI BAR TARGET handler: %d\n", error); - return (-1); - } - - AcpiDbGetTableFromFile(filetmp, NULL); - - AcpiDbInitialize(); - AcpiGbl_DebuggerConfiguration = 0; - AcpiDbUserCommands(':', NULL); - - if (strcmp(dsdtfile, filetmp) != 0) { - unlink(filetmp); - } - - return (0); -} - -static void -usage(const char *progname) -{ - - printf("usage: %s dsdt_file\n", progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - char *progname; - - progname = argv[0]; - - if (argc == 1) { - usage(progname); - } - - AcpiDbgLevel = ACPI_DEBUG_DEFAULT; - - /* - * Match kernel options for the interpreter. Global variable names - * can be found in acglobal.h. - */ - AcpiGbl_EnableInterpreterSlack = TRUE; - - aml_simulation_regload("region.ini"); - if (load_dsdt(argv[1]) == 0) { - aml_simulation_regdump("region.dmp"); - } - - return (0); -} diff --git a/usr.sbin/acpi/acpidump/Makefile b/usr.sbin/acpi/acpidump/Makefile deleted file mode 100644 index e004500..0000000 --- a/usr.sbin/acpi/acpidump/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -PROG= acpidump -MAN= acpidump.8 -SRCS= acpi.c acpi_user.c acpidump.c - -.include diff --git a/usr.sbin/acpi/acpidump/acpi.c b/usr.sbin/acpi/acpidump/acpi.c deleted file mode 100644 index c273e26..0000000 --- a/usr.sbin/acpi/acpidump/acpi.c +++ /dev/null @@ -1,1300 +0,0 @@ -/*- - * Copyright (c) 1998 Doug Rabson - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "acpidump.h" - -#define BEGIN_COMMENT "/*\n" -#define END_COMMENT " */\n" - -static void acpi_print_string(char *s, size_t length); -static void acpi_print_gas(ACPI_GENERIC_ADDRESS *gas); -static int acpi_get_fadt_revision(ACPI_TABLE_FADT *fadt); -static void acpi_handle_fadt(ACPI_TABLE_HEADER *fadt); -static void acpi_print_cpu(u_char cpu_id); -static void acpi_print_cpu_uid(uint32_t uid, char *uid_string); -static void acpi_print_local_apic(uint32_t apic_id, uint32_t flags); -static void acpi_print_io_apic(uint32_t apic_id, uint32_t int_base, - uint64_t apic_addr); -static void acpi_print_mps_flags(uint16_t flags); -static void acpi_print_intr(uint32_t intr, uint16_t mps_flags); -static void acpi_print_local_nmi(u_int lint, uint16_t mps_flags); -static void acpi_print_madt(ACPI_SUBTABLE_HEADER *mp); -static void acpi_handle_madt(ACPI_TABLE_HEADER *sdp); -static void acpi_handle_ecdt(ACPI_TABLE_HEADER *sdp); -static void acpi_handle_hpet(ACPI_TABLE_HEADER *sdp); -static void acpi_handle_mcfg(ACPI_TABLE_HEADER *sdp); -static void acpi_print_srat_cpu(uint32_t apic_id, uint32_t proximity_domain, - uint32_t flags); -static void acpi_print_srat_memory(ACPI_SRAT_MEM_AFFINITY *mp); -static void acpi_print_srat(ACPI_SUBTABLE_HEADER *srat); -static void acpi_handle_srat(ACPI_TABLE_HEADER *sdp); -static void acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp); -static void acpi_print_sdt(ACPI_TABLE_HEADER *sdp); -static void acpi_print_fadt(ACPI_TABLE_HEADER *sdp); -static void acpi_print_facs(ACPI_TABLE_FACS *facs); -static void acpi_print_dsdt(ACPI_TABLE_HEADER *dsdp); -static ACPI_TABLE_HEADER *acpi_map_sdt(vm_offset_t pa); -static void acpi_print_rsd_ptr(ACPI_TABLE_RSDP *rp); -static void acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp); -static void acpi_walk_subtables(ACPI_TABLE_HEADER *table, void *first, - void (*action)(ACPI_SUBTABLE_HEADER *)); - -/* Size of an address. 32-bit for ACPI 1.0, 64-bit for ACPI 2.0 and up. */ -static int addr_size; - -/* Strings used in the TCPA table */ -static const char *tcpa_event_type_strings[] = { - "PREBOOT Certificate", - "POST Code", - "Unused", - "No Action", - "Separator", - "Action", - "Event Tag", - "S-CRTM Contents", - "S-CRTM Version", - "CPU Microcode", - "Platform Config Flags", - "Table of Devices", - "Compact Hash", - "IPL", - "IPL Partition Data", - "Non-Host Code", - "Non-Host Config", - "Non-Host Info" -}; - -static const char *TCPA_pcclient_strings[] = { - "", - "SMBIOS", - "BIS Certificate", - "POST BIOS ROM Strings", - "ESCD", - "CMOS", - "NVRAM", - "Option ROM Execute", - "Option ROM Configurateion", - "", - "Option ROM Microcode Update ", - "S-CRTM Version String", - "S-CRTM Contents", - "POST Contents", - "Table of Devices", -}; - -static void -acpi_print_string(char *s, size_t length) -{ - int c; - - /* Trim trailing spaces and NULLs */ - while (length > 0 && (s[length - 1] == ' ' || s[length - 1] == '\0')) - length--; - - while (length--) { - c = *s++; - putchar(c); - } -} - -static void -acpi_print_gas(ACPI_GENERIC_ADDRESS *gas) -{ - switch(gas->SpaceId) { - case ACPI_GAS_MEMORY: - printf("0x%08lx:%u[%u] (Memory)", (u_long)gas->Address, - gas->BitOffset, gas->BitWidth); - break; - case ACPI_GAS_IO: - printf("0x%02lx:%u[%u] (IO)", (u_long)gas->Address, - gas->BitOffset, gas->BitWidth); - break; - case ACPI_GAS_PCI: - printf("%x:%x+0x%x (PCI)", (uint16_t)(gas->Address >> 32), - (uint16_t)((gas->Address >> 16) & 0xffff), - (uint16_t)gas->Address); - break; - /* XXX How to handle these below? */ - case ACPI_GAS_EMBEDDED: - printf("0x%x:%u[%u] (EC)", (uint16_t)gas->Address, - gas->BitOffset, gas->BitWidth); - break; - case ACPI_GAS_SMBUS: - printf("0x%x:%u[%u] (SMBus)", (uint16_t)gas->Address, - gas->BitOffset, gas->BitWidth); - break; - case ACPI_GAS_CMOS: - case ACPI_GAS_PCIBAR: - case ACPI_GAS_DATATABLE: - case ACPI_GAS_FIXED: - default: - printf("0x%08lx (?)", (u_long)gas->Address); - break; - } -} - -/* The FADT revision indicates whether we use the DSDT or X_DSDT addresses. */ -static int -acpi_get_fadt_revision(ACPI_TABLE_FADT *fadt) -{ - int fadt_revision; - - /* Set the FADT revision separately from the RSDP version. */ - if (addr_size == 8) { - fadt_revision = 2; - - /* - * A few systems (e.g., IBM T23) have an RSDP that claims - * revision 2 but the 64 bit addresses are invalid. If - * revision 2 and the 32 bit address is non-zero but the - * 32 and 64 bit versions don't match, prefer the 32 bit - * version for all subsequent tables. - */ - if (fadt->Facs != 0 && - (fadt->XFacs & 0xffffffff) != fadt->Facs) - fadt_revision = 1; - } else - fadt_revision = 1; - return (fadt_revision); -} - -static void -acpi_handle_fadt(ACPI_TABLE_HEADER *sdp) -{ - ACPI_TABLE_HEADER *dsdp; - ACPI_TABLE_FACS *facs; - ACPI_TABLE_FADT *fadt; - int fadt_revision; - - fadt = (ACPI_TABLE_FADT *)sdp; - acpi_print_fadt(sdp); - - fadt_revision = acpi_get_fadt_revision(fadt); - if (fadt_revision == 1) - facs = (ACPI_TABLE_FACS *)acpi_map_sdt(fadt->Facs); - else - facs = (ACPI_TABLE_FACS *)acpi_map_sdt(fadt->XFacs); - if (memcmp(facs->Signature, ACPI_SIG_FACS, 4) != 0 || facs->Length < 64) - errx(1, "FACS is corrupt"); - acpi_print_facs(facs); - - if (fadt_revision == 1) - dsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->Dsdt); - else - dsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->XDsdt); - if (acpi_checksum(dsdp, dsdp->Length)) - errx(1, "DSDT is corrupt"); - acpi_print_dsdt(dsdp); -} - -static void -acpi_walk_subtables(ACPI_TABLE_HEADER *table, void *first, - void (*action)(ACPI_SUBTABLE_HEADER *)) -{ - ACPI_SUBTABLE_HEADER *subtable; - char *end; - - subtable = first; - end = (char *)table + table->Length; - while ((char *)subtable < end) { - printf("\n"); - action(subtable); - subtable = (ACPI_SUBTABLE_HEADER *)((char *)subtable + - subtable->Length); - } -} - -static void -acpi_print_cpu(u_char cpu_id) -{ - - printf("\tACPI CPU="); - if (cpu_id == 0xff) - printf("ALL\n"); - else - printf("%d\n", (u_int)cpu_id); -} - -static void -acpi_print_cpu_uid(uint32_t uid, char *uid_string) -{ - - printf("\tUID=%d", uid); - if (uid_string != NULL) - printf(" (%s)", uid_string); - printf("\n"); -} - -static void -acpi_print_local_apic(uint32_t apic_id, uint32_t flags) -{ - - printf("\tFlags={"); - if (flags & ACPI_MADT_ENABLED) - printf("ENABLED"); - else - printf("DISABLED"); - printf("}\n"); - printf("\tAPIC ID=%d\n", apic_id); -} - -static void -acpi_print_io_apic(uint32_t apic_id, uint32_t int_base, uint64_t apic_addr) -{ - - printf("\tAPIC ID=%d\n", apic_id); - printf("\tINT BASE=%d\n", int_base); - printf("\tADDR=0x%016jx\n", (uintmax_t)apic_addr); -} - -static void -acpi_print_mps_flags(uint16_t flags) -{ - - printf("\tFlags={Polarity="); - switch (flags & ACPI_MADT_POLARITY_MASK) { - case ACPI_MADT_POLARITY_CONFORMS: - printf("conforming"); - break; - case ACPI_MADT_POLARITY_ACTIVE_HIGH: - printf("active-hi"); - break; - case ACPI_MADT_POLARITY_ACTIVE_LOW: - printf("active-lo"); - break; - default: - printf("0x%x", flags & ACPI_MADT_POLARITY_MASK); - break; - } - printf(", Trigger="); - switch (flags & ACPI_MADT_TRIGGER_MASK) { - case ACPI_MADT_TRIGGER_CONFORMS: - printf("conforming"); - break; - case ACPI_MADT_TRIGGER_EDGE: - printf("edge"); - break; - case ACPI_MADT_TRIGGER_LEVEL: - printf("level"); - break; - default: - printf("0x%x", (flags & ACPI_MADT_TRIGGER_MASK) >> 2); - } - printf("}\n"); -} - -static void -acpi_print_intr(uint32_t intr, uint16_t mps_flags) -{ - - printf("\tINTR=%d\n", intr); - acpi_print_mps_flags(mps_flags); -} - -static void -acpi_print_local_nmi(u_int lint, uint16_t mps_flags) -{ - - printf("\tLINT Pin=%d\n", lint); - acpi_print_mps_flags(mps_flags); -} - -const char *apic_types[] = { "Local APIC", "IO APIC", "INT Override", "NMI", - "Local APIC NMI", "Local APIC Override", - "IO SAPIC", "Local SAPIC", "Platform Interrupt", - "Local X2APIC", "Local X2APIC NMI" }; -const char *platform_int_types[] = { "0 (unknown)", "PMI", "INIT", - "Corrected Platform Error" }; - -static void -acpi_print_madt(ACPI_SUBTABLE_HEADER *mp) -{ - ACPI_MADT_LOCAL_APIC *lapic; - ACPI_MADT_IO_APIC *ioapic; - ACPI_MADT_INTERRUPT_OVERRIDE *over; - ACPI_MADT_NMI_SOURCE *nmi; - ACPI_MADT_LOCAL_APIC_NMI *lapic_nmi; - ACPI_MADT_LOCAL_APIC_OVERRIDE *lapic_over; - ACPI_MADT_IO_SAPIC *iosapic; - ACPI_MADT_LOCAL_SAPIC *lsapic; - ACPI_MADT_INTERRUPT_SOURCE *isrc; - ACPI_MADT_LOCAL_X2APIC *x2apic; - ACPI_MADT_LOCAL_X2APIC_NMI *x2apic_nmi; - - if (mp->Type < sizeof(apic_types) / sizeof(apic_types[0])) - printf("\tType=%s\n", apic_types[mp->Type]); - else - printf("\tType=%d (unknown)\n", mp->Type); - switch (mp->Type) { - case ACPI_MADT_TYPE_LOCAL_APIC: - lapic = (ACPI_MADT_LOCAL_APIC *)mp; - acpi_print_cpu(lapic->ProcessorId); - acpi_print_local_apic(lapic->Id, lapic->LapicFlags); - break; - case ACPI_MADT_TYPE_IO_APIC: - ioapic = (ACPI_MADT_IO_APIC *)mp; - acpi_print_io_apic(ioapic->Id, ioapic->GlobalIrqBase, - ioapic->Address); - break; - case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE: - over = (ACPI_MADT_INTERRUPT_OVERRIDE *)mp; - printf("\tBUS=%d\n", (u_int)over->Bus); - printf("\tIRQ=%d\n", (u_int)over->SourceIrq); - acpi_print_intr(over->GlobalIrq, over->IntiFlags); - break; - case ACPI_MADT_TYPE_NMI_SOURCE: - nmi = (ACPI_MADT_NMI_SOURCE *)mp; - acpi_print_intr(nmi->GlobalIrq, nmi->IntiFlags); - break; - case ACPI_MADT_TYPE_LOCAL_APIC_NMI: - lapic_nmi = (ACPI_MADT_LOCAL_APIC_NMI *)mp; - acpi_print_cpu(lapic_nmi->ProcessorId); - acpi_print_local_nmi(lapic_nmi->Lint, lapic_nmi->IntiFlags); - break; - case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE: - lapic_over = (ACPI_MADT_LOCAL_APIC_OVERRIDE *)mp; - printf("\tLocal APIC ADDR=0x%016jx\n", - (uintmax_t)lapic_over->Address); - break; - case ACPI_MADT_TYPE_IO_SAPIC: - iosapic = (ACPI_MADT_IO_SAPIC *)mp; - acpi_print_io_apic(iosapic->Id, iosapic->GlobalIrqBase, - iosapic->Address); - break; - case ACPI_MADT_TYPE_LOCAL_SAPIC: - lsapic = (ACPI_MADT_LOCAL_SAPIC *)mp; - acpi_print_cpu(lsapic->ProcessorId); - acpi_print_local_apic(lsapic->Id, lsapic->LapicFlags); - printf("\tAPIC EID=%d\n", (u_int)lsapic->Eid); - if (mp->Length > __offsetof(ACPI_MADT_LOCAL_SAPIC, Uid)) - acpi_print_cpu_uid(lsapic->Uid, lsapic->UidString); - break; - case ACPI_MADT_TYPE_INTERRUPT_SOURCE: - isrc = (ACPI_MADT_INTERRUPT_SOURCE *)mp; - if (isrc->Type < sizeof(platform_int_types) / - sizeof(platform_int_types[0])) - printf("\tType=%s\n", platform_int_types[isrc->Type]); - else - printf("\tType=%d (unknown)\n", isrc->Type); - printf("\tAPIC ID=%d\n", (u_int)isrc->Id); - printf("\tAPIC EID=%d\n", (u_int)isrc->Eid); - printf("\tSAPIC Vector=%d\n", (u_int)isrc->IoSapicVector); - acpi_print_intr(isrc->GlobalIrq, isrc->IntiFlags); - break; - case ACPI_MADT_TYPE_LOCAL_X2APIC: - x2apic = (ACPI_MADT_LOCAL_X2APIC *)mp; - acpi_print_cpu_uid(x2apic->Uid, NULL); - acpi_print_local_apic(x2apic->LocalApicId, x2apic->LapicFlags); - break; - case ACPI_MADT_TYPE_LOCAL_X2APIC_NMI: - x2apic_nmi = (ACPI_MADT_LOCAL_X2APIC_NMI *)mp; - acpi_print_cpu_uid(x2apic_nmi->Uid, NULL); - acpi_print_local_nmi(x2apic_nmi->Lint, x2apic_nmi->IntiFlags); - break; - } -} - -static void -acpi_handle_madt(ACPI_TABLE_HEADER *sdp) -{ - ACPI_TABLE_MADT *madt; - - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - madt = (ACPI_TABLE_MADT *)sdp; - printf("\tLocal APIC ADDR=0x%08x\n", madt->Address); - printf("\tFlags={"); - if (madt->Flags & ACPI_MADT_PCAT_COMPAT) - printf("PC-AT"); - printf("}\n"); - acpi_walk_subtables(sdp, (madt + 1), acpi_print_madt); - printf(END_COMMENT); -} - -static void -acpi_handle_hpet(ACPI_TABLE_HEADER *sdp) -{ - ACPI_TABLE_HPET *hpet; - - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - hpet = (ACPI_TABLE_HPET *)sdp; - printf("\tHPET Number=%d\n", hpet->Sequence); - printf("\tADDR="); - acpi_print_gas(&hpet->Address); - printf("\tHW Rev=0x%x\n", hpet->Id & ACPI_HPET_ID_HARDWARE_REV_ID); - printf("\tComparators=%d\n", (hpet->Id & ACPI_HPET_ID_COMPARATORS) >> - 8); - printf("\tCounter Size=%d\n", hpet->Id & ACPI_HPET_ID_COUNT_SIZE_CAP ? - 1 : 0); - printf("\tLegacy IRQ routing capable={"); - if (hpet->Id & ACPI_HPET_ID_LEGACY_CAPABLE) - printf("TRUE}\n"); - else - printf("FALSE}\n"); - printf("\tPCI Vendor ID=0x%04x\n", hpet->Id >> 16); - printf("\tMinimal Tick=%d\n", hpet->MinimumTick); - printf(END_COMMENT); -} - -static void -acpi_handle_ecdt(ACPI_TABLE_HEADER *sdp) -{ - ACPI_TABLE_ECDT *ecdt; - - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - ecdt = (ACPI_TABLE_ECDT *)sdp; - printf("\tEC_CONTROL="); - acpi_print_gas(&ecdt->Control); - printf("\n\tEC_DATA="); - acpi_print_gas(&ecdt->Data); - printf("\n\tUID=%#x, ", ecdt->Uid); - printf("GPE_BIT=%#x\n", ecdt->Gpe); - printf("\tEC_ID=%s\n", ecdt->Id); - printf(END_COMMENT); -} - -static void -acpi_handle_mcfg(ACPI_TABLE_HEADER *sdp) -{ - ACPI_TABLE_MCFG *mcfg; - ACPI_MCFG_ALLOCATION *alloc; - u_int i, entries; - - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - mcfg = (ACPI_TABLE_MCFG *)sdp; - entries = (sdp->Length - sizeof(ACPI_TABLE_MCFG)) / - sizeof(ACPI_MCFG_ALLOCATION); - alloc = (ACPI_MCFG_ALLOCATION *)(mcfg + 1); - for (i = 0; i < entries; i++, alloc++) { - printf("\n"); - printf("\tBase Address=0x%016jx\n", alloc->Address); - printf("\tSegment Group=0x%04x\n", alloc->PciSegment); - printf("\tStart Bus=%d\n", alloc->StartBusNumber); - printf("\tEnd Bus=%d\n", alloc->EndBusNumber); - } - printf(END_COMMENT); -} - -static void -acpi_print_srat_cpu(uint32_t apic_id, uint32_t proximity_domain, - uint32_t flags) -{ - - printf("\tFlags={"); - if (flags & ACPI_SRAT_CPU_ENABLED) - printf("ENABLED"); - else - printf("DISABLED"); - printf("}\n"); - printf("\tAPIC ID=%d\n", apic_id); - printf("\tProximity Domain=%d\n", proximity_domain); -} - -static char * -acpi_tcpa_evname(struct TCPAevent *event) -{ - struct TCPApc_event *pc_event; - char *eventname = NULL; - - pc_event = (struct TCPApc_event *)(event + 1); - - switch(event->event_type) { - case PREBOOT: - case POST_CODE: - case UNUSED: - case NO_ACTION: - case SEPARATOR: - case SCRTM_CONTENTS: - case SCRTM_VERSION: - case CPU_MICROCODE: - case PLATFORM_CONFIG_FLAGS: - case TABLE_OF_DEVICES: - case COMPACT_HASH: - case IPL: - case IPL_PARTITION_DATA: - case NONHOST_CODE: - case NONHOST_CONFIG: - case NONHOST_INFO: - asprintf(&eventname, "%s", - tcpa_event_type_strings[event->event_type]); - break; - - case ACTION: - eventname = calloc(event->event_size + 1, sizeof(char)); - memcpy(eventname, pc_event, event->event_size); - break; - - case EVENT_TAG: - switch (pc_event->event_id) { - case SMBIOS: - case BIS_CERT: - case CMOS: - case NVRAM: - case OPTION_ROM_EXEC: - case OPTION_ROM_CONFIG: - case S_CRTM_VERSION: - case POST_BIOS_ROM: - case ESCD: - case OPTION_ROM_MICROCODE: - case S_CRTM_CONTENTS: - case POST_CONTENTS: - asprintf(&eventname, "%s", - TCPA_pcclient_strings[pc_event->event_id]); - break; - - default: - asprintf(&eventname, "", - pc_event->event_id); - break; - } - break; - - default: - asprintf(&eventname, "", event->event_type); - break; - } - - return eventname; -} - -static void -acpi_print_tcpa(struct TCPAevent *event) -{ - int i; - char *eventname; - - eventname = acpi_tcpa_evname(event); - - printf("\t%d", event->pcr_index); - printf(" 0x"); - for (i = 0; i < 20; i++) - printf("%02x", event->pcr_value[i]); - printf(" [%s]\n", eventname ? eventname : ""); - - free(eventname); -} - -static void -acpi_handle_tcpa(ACPI_TABLE_HEADER *sdp) -{ - struct TCPAbody *tcpa; - struct TCPAevent *event; - uintmax_t len, paddr; - unsigned char *vaddr = NULL; - unsigned char *vend = NULL; - - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - tcpa = (struct TCPAbody *) sdp; - - switch (tcpa->platform_class) { - case ACPI_TCPA_BIOS_CLIENT: - len = tcpa->client.log_max_len; - paddr = tcpa->client.log_start_addr; - break; - - case ACPI_TCPA_BIOS_SERVER: - len = tcpa->server.log_max_len; - paddr = tcpa->server.log_start_addr; - break; - - default: - printf("XXX"); - printf(END_COMMENT); - return; - } - printf("\tClass %u Base Address 0x%jx Length %ju\n\n", - tcpa->platform_class, paddr, len); - - if (len == 0) { - printf("\tEmpty TCPA table\n"); - printf(END_COMMENT); - return; - } - - vaddr = (unsigned char *)acpi_map_physical(paddr, len); - vend = vaddr + len; - - while (vaddr != NULL) { - if (vaddr + sizeof(struct TCPAevent) >= vend) - break; - event = (struct TCPAevent *)(void *)vaddr; - if (vaddr + event->event_size >= vend) - break; - if (event->event_type == 0 && event->event_size == 0) - break; -#if 0 - { - unsigned int i, j, k; - - printf("\n\tsize %d\n\t\t%p ", event->event_size, vaddr); - for (j = 0, i = 0; i < - sizeof(struct TCPAevent) + event->event_size; i++) { - printf("%02x ", vaddr[i]); - if ((i+1) % 8 == 0) { - for (k = 0; k < 8; k++) - printf("%c", isprint(vaddr[j+k]) ? - vaddr[j+k] : '.'); - printf("\n\t\t%p ", &vaddr[i + 1]); - j = i + 1; - } - } - printf("\n"); } -#endif - acpi_print_tcpa(event); - - vaddr += sizeof(struct TCPAevent) + event->event_size; - } - - printf(END_COMMENT); -} - -static void -acpi_print_srat_memory(ACPI_SRAT_MEM_AFFINITY *mp) -{ - - printf("\tFlags={"); - if (mp->Flags & ACPI_SRAT_MEM_ENABLED) - printf("ENABLED"); - else - printf("DISABLED"); - if (mp->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) - printf(",HOT_PLUGGABLE"); - if (mp->Flags & ACPI_SRAT_MEM_NON_VOLATILE) - printf(",NON_VOLATILE"); - printf("}\n"); - printf("\tBase Address=0x%016jx\n", (uintmax_t)mp->BaseAddress); - printf("\tLength=0x%016jx\n", (uintmax_t)mp->Length); - printf("\tProximity Domain=%d\n", mp->ProximityDomain); -} - -const char *srat_types[] = { "CPU", "Memory", "X2APIC" }; - -static void -acpi_print_srat(ACPI_SUBTABLE_HEADER *srat) -{ - ACPI_SRAT_CPU_AFFINITY *cpu; - ACPI_SRAT_X2APIC_CPU_AFFINITY *x2apic; - - if (srat->Type < sizeof(srat_types) / sizeof(srat_types[0])) - printf("\tType=%s\n", srat_types[srat->Type]); - else - printf("\tType=%d (unknown)\n", srat->Type); - switch (srat->Type) { - case ACPI_SRAT_TYPE_CPU_AFFINITY: - cpu = (ACPI_SRAT_CPU_AFFINITY *)srat; - acpi_print_srat_cpu(cpu->ApicId, - cpu->ProximityDomainHi[2] << 24 | - cpu->ProximityDomainHi[1] << 16 | - cpu->ProximityDomainHi[0] << 0 | - cpu->ProximityDomainLo, cpu->Flags); - break; - case ACPI_SRAT_TYPE_MEMORY_AFFINITY: - acpi_print_srat_memory((ACPI_SRAT_MEM_AFFINITY *)srat); - break; - case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: - x2apic = (ACPI_SRAT_X2APIC_CPU_AFFINITY *)srat; - acpi_print_srat_cpu(x2apic->ApicId, x2apic->ProximityDomain, - x2apic->Flags); - break; - } -} - -static void -acpi_handle_srat(ACPI_TABLE_HEADER *sdp) -{ - ACPI_TABLE_SRAT *srat; - - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - srat = (ACPI_TABLE_SRAT *)sdp; - printf("\tTable Revision=%d\n", srat->TableRevision); - acpi_walk_subtables(sdp, (srat + 1), acpi_print_srat); - printf(END_COMMENT); -} - -static void -acpi_print_sdt(ACPI_TABLE_HEADER *sdp) -{ - printf(" "); - acpi_print_string(sdp->Signature, ACPI_NAME_SIZE); - printf(": Length=%d, Revision=%d, Checksum=%d,\n", - sdp->Length, sdp->Revision, sdp->Checksum); - printf("\tOEMID="); - acpi_print_string(sdp->OemId, ACPI_OEM_ID_SIZE); - printf(", OEM Table ID="); - acpi_print_string(sdp->OemTableId, ACPI_OEM_TABLE_ID_SIZE); - printf(", OEM Revision=0x%x,\n", sdp->OemRevision); - printf("\tCreator ID="); - acpi_print_string(sdp->AslCompilerId, ACPI_NAME_SIZE); - printf(", Creator Revision=0x%x\n", sdp->AslCompilerRevision); -} - -static void -acpi_print_rsdt(ACPI_TABLE_HEADER *rsdp) -{ - ACPI_TABLE_RSDT *rsdt; - ACPI_TABLE_XSDT *xsdt; - int i, entries; - u_long addr; - - rsdt = (ACPI_TABLE_RSDT *)rsdp; - xsdt = (ACPI_TABLE_XSDT *)rsdp; - printf(BEGIN_COMMENT); - acpi_print_sdt(rsdp); - entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; - printf("\tEntries={ "); - for (i = 0; i < entries; i++) { - if (i > 0) - printf(", "); - switch (addr_size) { - case 4: - addr = le32toh(rsdt->TableOffsetEntry[i]); - break; - case 8: - addr = le64toh(xsdt->TableOffsetEntry[i]); - break; - default: - addr = 0; - } - assert(addr != 0); - printf("0x%08lx", addr); - } - printf(" }\n"); - printf(END_COMMENT); -} - -static const char *acpi_pm_profiles[] = { - "Unspecified", "Desktop", "Mobile", "Workstation", - "Enterprise Server", "SOHO Server", "Appliance PC" -}; - -static void -acpi_print_fadt(ACPI_TABLE_HEADER *sdp) -{ - ACPI_TABLE_FADT *fadt; - const char *pm; - char sep; - - fadt = (ACPI_TABLE_FADT *)sdp; - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - printf(" \tFACS=0x%x, DSDT=0x%x\n", fadt->Facs, - fadt->Dsdt); - printf("\tINT_MODEL=%s\n", fadt->Model ? "APIC" : "PIC"); - if (fadt->PreferredProfile >= sizeof(acpi_pm_profiles) / sizeof(char *)) - pm = "Reserved"; - else - pm = acpi_pm_profiles[fadt->PreferredProfile]; - printf("\tPreferred_PM_Profile=%s (%d)\n", pm, fadt->PreferredProfile); - printf("\tSCI_INT=%d\n", fadt->SciInterrupt); - printf("\tSMI_CMD=0x%x, ", fadt->SmiCommand); - printf("ACPI_ENABLE=0x%x, ", fadt->AcpiEnable); - printf("ACPI_DISABLE=0x%x, ", fadt->AcpiDisable); - printf("S4BIOS_REQ=0x%x\n", fadt->S4BiosRequest); - printf("\tPSTATE_CNT=0x%x\n", fadt->PstateControl); - printf("\tPM1a_EVT_BLK=0x%x-0x%x\n", - fadt->Pm1aEventBlock, - fadt->Pm1aEventBlock + fadt->Pm1EventLength - 1); - if (fadt->Pm1bEventBlock != 0) - printf("\tPM1b_EVT_BLK=0x%x-0x%x\n", - fadt->Pm1bEventBlock, - fadt->Pm1bEventBlock + fadt->Pm1EventLength - 1); - printf("\tPM1a_CNT_BLK=0x%x-0x%x\n", - fadt->Pm1aControlBlock, - fadt->Pm1aControlBlock + fadt->Pm1ControlLength - 1); - if (fadt->Pm1bControlBlock != 0) - printf("\tPM1b_CNT_BLK=0x%x-0x%x\n", - fadt->Pm1bControlBlock, - fadt->Pm1bControlBlock + fadt->Pm1ControlLength - 1); - if (fadt->Pm2ControlBlock != 0) - printf("\tPM2_CNT_BLK=0x%x-0x%x\n", - fadt->Pm2ControlBlock, - fadt->Pm2ControlBlock + fadt->Pm2ControlLength - 1); - printf("\tPM_TMR_BLK=0x%x-0x%x\n", - fadt->PmTimerBlock, - fadt->PmTimerBlock + fadt->PmTimerLength - 1); - if (fadt->Gpe0Block != 0) - printf("\tGPE0_BLK=0x%x-0x%x\n", - fadt->Gpe0Block, - fadt->Gpe0Block + fadt->Gpe0BlockLength - 1); - if (fadt->Gpe1Block != 0) - printf("\tGPE1_BLK=0x%x-0x%x, GPE1_BASE=%d\n", - fadt->Gpe1Block, - fadt->Gpe1Block + fadt->Gpe1BlockLength - 1, - fadt->Gpe1Base); - if (fadt->CstControl != 0) - printf("\tCST_CNT=0x%x\n", fadt->CstControl); - printf("\tP_LVL2_LAT=%d us, P_LVL3_LAT=%d us\n", - fadt->C2Latency, fadt->C3Latency); - printf("\tFLUSH_SIZE=%d, FLUSH_STRIDE=%d\n", - fadt->FlushSize, fadt->FlushStride); - printf("\tDUTY_OFFSET=%d, DUTY_WIDTH=%d\n", - fadt->DutyOffset, fadt->DutyWidth); - printf("\tDAY_ALRM=%d, MON_ALRM=%d, CENTURY=%d\n", - fadt->DayAlarm, fadt->MonthAlarm, fadt->Century); - -#define PRINTFLAG(var, flag) do { \ - if ((var) & ACPI_FADT_## flag) { \ - printf("%c%s", sep, #flag); sep = ','; \ - } \ -} while (0) - - printf("\tIAPC_BOOT_ARCH="); - sep = '{'; - PRINTFLAG(fadt->BootFlags, LEGACY_DEVICES); - PRINTFLAG(fadt->BootFlags, 8042); - PRINTFLAG(fadt->BootFlags, NO_VGA); - PRINTFLAG(fadt->BootFlags, NO_MSI); - PRINTFLAG(fadt->BootFlags, NO_ASPM); - if (fadt->BootFlags != 0) - printf("}"); - printf("\n"); - - printf("\tFlags="); - sep = '{'; - PRINTFLAG(fadt->Flags, WBINVD); - PRINTFLAG(fadt->Flags, WBINVD_FLUSH); - PRINTFLAG(fadt->Flags, C1_SUPPORTED); - PRINTFLAG(fadt->Flags, C2_MP_SUPPORTED); - PRINTFLAG(fadt->Flags, POWER_BUTTON); - PRINTFLAG(fadt->Flags, SLEEP_BUTTON); - PRINTFLAG(fadt->Flags, FIXED_RTC); - PRINTFLAG(fadt->Flags, S4_RTC_WAKE); - PRINTFLAG(fadt->Flags, 32BIT_TIMER); - PRINTFLAG(fadt->Flags, DOCKING_SUPPORTED); - PRINTFLAG(fadt->Flags, RESET_REGISTER); - PRINTFLAG(fadt->Flags, SEALED_CASE); - PRINTFLAG(fadt->Flags, HEADLESS); - PRINTFLAG(fadt->Flags, SLEEP_TYPE); - PRINTFLAG(fadt->Flags, PCI_EXPRESS_WAKE); - PRINTFLAG(fadt->Flags, PLATFORM_CLOCK); - PRINTFLAG(fadt->Flags, S4_RTC_VALID); - PRINTFLAG(fadt->Flags, REMOTE_POWER_ON); - PRINTFLAG(fadt->Flags, APIC_CLUSTER); - PRINTFLAG(fadt->Flags, APIC_PHYSICAL); - if (fadt->Flags != 0) - printf("}\n"); - -#undef PRINTFLAG - - if (fadt->Flags & ACPI_FADT_RESET_REGISTER) { - printf("\tRESET_REG="); - acpi_print_gas(&fadt->ResetRegister); - printf(", RESET_VALUE=%#x\n", fadt->ResetValue); - } - if (acpi_get_fadt_revision(fadt) > 1) { - printf("\tX_FACS=0x%08lx, ", (u_long)fadt->XFacs); - printf("X_DSDT=0x%08lx\n", (u_long)fadt->XDsdt); - printf("\tX_PM1a_EVT_BLK="); - acpi_print_gas(&fadt->XPm1aEventBlock); - if (fadt->XPm1bEventBlock.Address != 0) { - printf("\n\tX_PM1b_EVT_BLK="); - acpi_print_gas(&fadt->XPm1bEventBlock); - } - printf("\n\tX_PM1a_CNT_BLK="); - acpi_print_gas(&fadt->XPm1aControlBlock); - if (fadt->XPm1bControlBlock.Address != 0) { - printf("\n\tX_PM1b_CNT_BLK="); - acpi_print_gas(&fadt->XPm1bControlBlock); - } - if (fadt->XPm2ControlBlock.Address != 0) { - printf("\n\tX_PM2_CNT_BLK="); - acpi_print_gas(&fadt->XPm2ControlBlock); - } - printf("\n\tX_PM_TMR_BLK="); - acpi_print_gas(&fadt->XPmTimerBlock); - if (fadt->XGpe0Block.Address != 0) { - printf("\n\tX_GPE0_BLK="); - acpi_print_gas(&fadt->XGpe0Block); - } - if (fadt->XGpe1Block.Address != 0) { - printf("\n\tX_GPE1_BLK="); - acpi_print_gas(&fadt->XGpe1Block); - } - printf("\n"); - } - - printf(END_COMMENT); -} - -static void -acpi_print_facs(ACPI_TABLE_FACS *facs) -{ - printf(BEGIN_COMMENT); - printf(" FACS:\tLength=%u, ", facs->Length); - printf("HwSig=0x%08x, ", facs->HardwareSignature); - printf("Firm_Wake_Vec=0x%08x\n", facs->FirmwareWakingVector); - - printf("\tGlobal_Lock="); - if (facs->GlobalLock != 0) { - if (facs->GlobalLock & ACPI_GLOCK_PENDING) - printf("PENDING,"); - if (facs->GlobalLock & ACPI_GLOCK_OWNED) - printf("OWNED"); - } - printf("\n"); - - printf("\tFlags="); - if (facs->Flags & ACPI_FACS_S4_BIOS_PRESENT) - printf("S4BIOS"); - printf("\n"); - - if (facs->XFirmwareWakingVector != 0) { - printf("\tX_Firm_Wake_Vec=%08lx\n", - (u_long)facs->XFirmwareWakingVector); - } - printf("\tVersion=%u\n", facs->Version); - - printf(END_COMMENT); -} - -static void -acpi_print_dsdt(ACPI_TABLE_HEADER *dsdp) -{ - printf(BEGIN_COMMENT); - acpi_print_sdt(dsdp); - printf(END_COMMENT); -} - -int -acpi_checksum(void *p, size_t length) -{ - uint8_t *bp; - uint8_t sum; - - bp = p; - sum = 0; - while (length--) - sum += *bp++; - - return (sum); -} - -static ACPI_TABLE_HEADER * -acpi_map_sdt(vm_offset_t pa) -{ - ACPI_TABLE_HEADER *sp; - - sp = acpi_map_physical(pa, sizeof(ACPI_TABLE_HEADER)); - sp = acpi_map_physical(pa, sp->Length); - return (sp); -} - -static void -acpi_print_rsd_ptr(ACPI_TABLE_RSDP *rp) -{ - printf(BEGIN_COMMENT); - printf(" RSD PTR: OEM="); - acpi_print_string(rp->OemId, ACPI_OEM_ID_SIZE); - printf(", ACPI_Rev=%s (%d)\n", rp->Revision < 2 ? "1.0x" : "2.0x", - rp->Revision); - if (rp->Revision < 2) { - printf("\tRSDT=0x%08x, cksum=%u\n", rp->RsdtPhysicalAddress, - rp->Checksum); - } else { - printf("\tXSDT=0x%08lx, length=%u, cksum=%u\n", - (u_long)rp->XsdtPhysicalAddress, rp->Length, - rp->ExtendedChecksum); - } - printf(END_COMMENT); -} - -static void -acpi_handle_rsdt(ACPI_TABLE_HEADER *rsdp) -{ - ACPI_TABLE_HEADER *sdp; - ACPI_TABLE_RSDT *rsdt; - ACPI_TABLE_XSDT *xsdt; - vm_offset_t addr; - int entries, i; - - acpi_print_rsdt(rsdp); - rsdt = (ACPI_TABLE_RSDT *)rsdp; - xsdt = (ACPI_TABLE_XSDT *)rsdp; - entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; - for (i = 0; i < entries; i++) { - switch (addr_size) { - case 4: - addr = le32toh(rsdt->TableOffsetEntry[i]); - break; - case 8: - addr = le64toh(xsdt->TableOffsetEntry[i]); - break; - default: - assert((addr = 0)); - } - - sdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(addr); - if (acpi_checksum(sdp, sdp->Length)) { - warnx("RSDT entry %d (sig %.4s) is corrupt", i, - sdp->Signature); - continue; - } - if (!memcmp(sdp->Signature, ACPI_SIG_FADT, 4)) - acpi_handle_fadt(sdp); - else if (!memcmp(sdp->Signature, ACPI_SIG_MADT, 4)) - acpi_handle_madt(sdp); - else if (!memcmp(sdp->Signature, ACPI_SIG_HPET, 4)) - acpi_handle_hpet(sdp); - else if (!memcmp(sdp->Signature, ACPI_SIG_ECDT, 4)) - acpi_handle_ecdt(sdp); - else if (!memcmp(sdp->Signature, ACPI_SIG_MCFG, 4)) - acpi_handle_mcfg(sdp); - else if (!memcmp(sdp->Signature, ACPI_SIG_SRAT, 4)) - acpi_handle_srat(sdp); - else if (!memcmp(sdp->Signature, ACPI_SIG_TCPA, 4)) - acpi_handle_tcpa(sdp); - else { - printf(BEGIN_COMMENT); - acpi_print_sdt(sdp); - printf(END_COMMENT); - } - } -} - -ACPI_TABLE_HEADER * -sdt_load_devmem(void) -{ - ACPI_TABLE_RSDP *rp; - ACPI_TABLE_HEADER *rsdp; - - rp = acpi_find_rsd_ptr(); - if (!rp) - errx(1, "Can't find ACPI information"); - - if (tflag) - acpi_print_rsd_ptr(rp); - if (rp->Revision < 2) { - rsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(rp->RsdtPhysicalAddress); - if (memcmp(rsdp->Signature, "RSDT", 4) != 0 || - acpi_checksum(rsdp, rsdp->Length) != 0) - errx(1, "RSDT is corrupted"); - addr_size = sizeof(uint32_t); - } else { - rsdp = (ACPI_TABLE_HEADER *)acpi_map_sdt(rp->XsdtPhysicalAddress); - if (memcmp(rsdp->Signature, "XSDT", 4) != 0 || - acpi_checksum(rsdp, rsdp->Length) != 0) - errx(1, "XSDT is corrupted"); - addr_size = sizeof(uint64_t); - } - return (rsdp); -} - -/* Write the DSDT to a file, concatenating any SSDTs (if present). */ -static int -write_dsdt(int fd, ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdt) -{ - ACPI_TABLE_HEADER sdt; - ACPI_TABLE_HEADER *ssdt; - uint8_t sum; - - /* Create a new checksum to account for the DSDT and any SSDTs. */ - sdt = *dsdt; - if (rsdt != NULL) { - sdt.Checksum = 0; - sum = acpi_checksum(dsdt + 1, dsdt->Length - - sizeof(ACPI_TABLE_HEADER)); - ssdt = sdt_from_rsdt(rsdt, ACPI_SIG_SSDT, NULL); - while (ssdt != NULL) { - sdt.Length += ssdt->Length - sizeof(ACPI_TABLE_HEADER); - sum += acpi_checksum(ssdt + 1, - ssdt->Length - sizeof(ACPI_TABLE_HEADER)); - ssdt = sdt_from_rsdt(rsdt, ACPI_SIG_SSDT, ssdt); - } - sum += acpi_checksum(&sdt, sizeof(ACPI_TABLE_HEADER)); - sdt.Checksum -= sum; - } - - /* Write out the DSDT header and body. */ - write(fd, &sdt, sizeof(ACPI_TABLE_HEADER)); - write(fd, dsdt + 1, dsdt->Length - sizeof(ACPI_TABLE_HEADER)); - - /* Write out any SSDTs (if present.) */ - if (rsdt != NULL) { - ssdt = sdt_from_rsdt(rsdt, "SSDT", NULL); - while (ssdt != NULL) { - write(fd, ssdt + 1, ssdt->Length - - sizeof(ACPI_TABLE_HEADER)); - ssdt = sdt_from_rsdt(rsdt, "SSDT", ssdt); - } - } - return (0); -} - -void -dsdt_save_file(char *outfile, ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) -{ - int fd; - mode_t mode; - - assert(outfile != NULL); - mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; - fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, mode); - if (fd == -1) { - perror("dsdt_save_file"); - return; - } - write_dsdt(fd, rsdt, dsdp); - close(fd); -} - -void -aml_disassemble(ACPI_TABLE_HEADER *rsdt, ACPI_TABLE_HEADER *dsdp) -{ - char buf[PATH_MAX], tmpstr[PATH_MAX]; - const char *tmpdir; - char *tmpext; - FILE *fp; - size_t len; - int fd; - - tmpdir = getenv("TMPDIR"); - if (tmpdir == NULL) - tmpdir = _PATH_TMP; - strncpy(tmpstr, tmpdir, sizeof(tmpstr)); - strncat(tmpstr, "/acpidump.", sizeof(tmpstr) - strlen(tmpdir)); - if (realpath(tmpstr, buf) == NULL) { - perror("realpath tmp file"); - return; - } - strncpy(tmpstr, buf, sizeof(tmpstr)); - len = strlen(buf); - tmpext = tmpstr + len; - strncpy(tmpext, "XXXXXX", sizeof(tmpstr) - len); - fd = mkstemp(tmpstr); - if (fd < 0) { - perror("iasl tmp file"); - return; - } - write_dsdt(fd, rsdt, dsdp); - close(fd); - - /* Run iasl -d on the temp file */ - if (fork() == 0) { - close(STDOUT_FILENO); - if (vflag == 0) - close(STDERR_FILENO); - execl("/usr/sbin/iasl", "iasl", "-d", tmpstr, NULL); - err(1, "exec"); - } - - wait(NULL); - unlink(tmpstr); - - /* Dump iasl's output to stdout */ - strncpy(tmpext, "dsl", sizeof(tmpstr) - len); - fp = fopen(tmpstr, "r"); - unlink(tmpstr); - if (fp == NULL) { - perror("iasl tmp file (read)"); - return; - } - while ((len = fread(buf, 1, sizeof(buf), fp)) > 0) - fwrite(buf, 1, len, stdout); - fclose(fp); -} - -void -sdt_print_all(ACPI_TABLE_HEADER *rsdp) -{ - acpi_handle_rsdt(rsdp); -} - -/* Fetch a table matching the given signature via the RSDT. */ -ACPI_TABLE_HEADER * -sdt_from_rsdt(ACPI_TABLE_HEADER *rsdp, const char *sig, ACPI_TABLE_HEADER *last) -{ - ACPI_TABLE_HEADER *sdt; - ACPI_TABLE_RSDT *rsdt; - ACPI_TABLE_XSDT *xsdt; - vm_offset_t addr; - int entries, i; - - rsdt = (ACPI_TABLE_RSDT *)rsdp; - xsdt = (ACPI_TABLE_XSDT *)rsdp; - entries = (rsdp->Length - sizeof(ACPI_TABLE_HEADER)) / addr_size; - for (i = 0; i < entries; i++) { - switch (addr_size) { - case 4: - addr = le32toh(rsdt->TableOffsetEntry[i]); - break; - case 8: - addr = le64toh(xsdt->TableOffsetEntry[i]); - break; - default: - assert((addr = 0)); - } - sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(addr); - if (last != NULL) { - if (sdt == last) - last = NULL; - continue; - } - if (memcmp(sdt->Signature, sig, strlen(sig))) - continue; - if (acpi_checksum(sdt, sdt->Length)) - errx(1, "RSDT entry %d is corrupt", i); - return (sdt); - } - - return (NULL); -} - -ACPI_TABLE_HEADER * -dsdt_from_fadt(ACPI_TABLE_FADT *fadt) -{ - ACPI_TABLE_HEADER *sdt; - - /* Use the DSDT address if it is version 1, otherwise use XDSDT. */ - if (acpi_get_fadt_revision(fadt) == 1) - sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->Dsdt); - else - sdt = (ACPI_TABLE_HEADER *)acpi_map_sdt(fadt->XDsdt); - if (acpi_checksum(sdt, sdt->Length)) - errx(1, "DSDT is corrupt\n"); - return (sdt); -} diff --git a/usr.sbin/acpi/acpidump/acpi_user.c b/usr.sbin/acpi/acpidump/acpi_user.c deleted file mode 100644 index 86e581f..0000000 --- a/usr.sbin/acpi/acpidump/acpi_user.c +++ /dev/null @@ -1,222 +0,0 @@ -/*- - * Copyright (c) 1999 Doug Rabson - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "acpidump.h" - -static char hint_acpi_0_rsdp[] = "hint.acpi.0.rsdp"; -static char machdep_acpi_root[] = "machdep.acpi_root"; -static int acpi_mem_fd = -1; - -struct acpi_user_mapping { - LIST_ENTRY(acpi_user_mapping) link; - vm_offset_t pa; - caddr_t va; - size_t size; -}; - -LIST_HEAD(acpi_user_mapping_list, acpi_user_mapping) maplist; - -static void -acpi_user_init(void) -{ - - if (acpi_mem_fd == -1) { - acpi_mem_fd = open("/dev/mem", O_RDONLY); - if (acpi_mem_fd == -1) - err(1, "opening /dev/mem"); - LIST_INIT(&maplist); - } -} - -static struct acpi_user_mapping * -acpi_user_find_mapping(vm_offset_t pa, size_t size) -{ - struct acpi_user_mapping *map; - - /* First search for an existing mapping */ - for (map = LIST_FIRST(&maplist); map; map = LIST_NEXT(map, link)) { - if (map->pa <= pa && map->size >= pa + size - map->pa) - return (map); - } - - /* Then create a new one */ - size = round_page(pa + size) - trunc_page(pa); - pa = trunc_page(pa); - map = malloc(sizeof(struct acpi_user_mapping)); - if (!map) - errx(1, "out of memory"); - map->pa = pa; - map->va = mmap(0, size, PROT_READ, MAP_SHARED, acpi_mem_fd, pa); - map->size = size; - if ((intptr_t) map->va == -1) - err(1, "can't map address"); - LIST_INSERT_HEAD(&maplist, map, link); - - return (map); -} - -static ACPI_TABLE_RSDP * -acpi_get_rsdp(u_long addr) -{ - ACPI_TABLE_RSDP rsdp; - size_t len; - - /* Read in the table signature and check it. */ - pread(acpi_mem_fd, &rsdp, 8, addr); - if (memcmp(rsdp.Signature, "RSD PTR ", 8)) - return (NULL); - - /* Read the entire table. */ - pread(acpi_mem_fd, &rsdp, sizeof(rsdp), addr); - - /* Check the standard checksum. */ - if (acpi_checksum(&rsdp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) - return (NULL); - - /* Check extended checksum if table version >= 2. */ - if (rsdp.Revision >= 2 && - acpi_checksum(&rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0) - return (NULL); - - /* If the revision is 0, assume a version 1 length. */ - if (rsdp.Revision == 0) - len = sizeof(ACPI_RSDP_COMMON); - else - len = rsdp.Length; - - return (acpi_map_physical(addr, len)); -} - -static ACPI_TABLE_RSDP * -acpi_scan_rsd_ptr(void) -{ -#if defined(__amd64__) || defined(__i386__) - ACPI_TABLE_RSDP *rsdp; - u_long addr, end; - - /* - * On ia32, scan physical memory for the RSD PTR if above failed. - * According to section 5.2.2 of the ACPI spec, we only consider - * two regions for the base address: - * 1. EBDA (1 KB area addressed by the 16 bit pointer at 0x40E - * 2. High memory (0xE0000 - 0xFFFFF) - */ - addr = ACPI_EBDA_PTR_LOCATION; - pread(acpi_mem_fd, &addr, sizeof(uint16_t), addr); - addr <<= 4; - end = addr + ACPI_EBDA_WINDOW_SIZE; - for (; addr < end; addr += 16) - if ((rsdp = acpi_get_rsdp(addr)) != NULL) - return (rsdp); - addr = ACPI_HI_RSDP_WINDOW_BASE; - end = addr + ACPI_HI_RSDP_WINDOW_SIZE; - for (; addr < end; addr += 16) - if ((rsdp = acpi_get_rsdp(addr)) != NULL) - return (rsdp); -#endif /* __amd64__ || __i386__ */ - return (NULL); -} - -/* - * Public interfaces - */ -ACPI_TABLE_RSDP * -acpi_find_rsd_ptr(void) -{ - ACPI_TABLE_RSDP *rsdp; - char buf[20]; - u_long addr; - size_t len; - - acpi_user_init(); - - addr = 0; - - /* Attempt to use kenv or sysctl to find RSD PTR record. */ - if (kenv(KENV_GET, hint_acpi_0_rsdp, buf, 20) == 0) - addr = strtoul(buf, NULL, 0); - if (addr == 0) { - len = sizeof(addr); - if (sysctlbyname(machdep_acpi_root, &addr, &len, NULL, 0) != 0) - addr = 0; - } - if (addr != 0 && (rsdp = acpi_get_rsdp(addr)) != NULL) - return (rsdp); - - return (acpi_scan_rsd_ptr()); -} - -void * -acpi_map_physical(vm_offset_t pa, size_t size) -{ - struct acpi_user_mapping *map; - - map = acpi_user_find_mapping(pa, size); - return (map->va + (pa - map->pa)); -} - -ACPI_TABLE_HEADER * -dsdt_load_file(char *infile) -{ - ACPI_TABLE_HEADER *sdt; - uint8_t *dp; - struct stat sb; - - if ((acpi_mem_fd = open(infile, O_RDONLY)) == -1) - errx(1, "opening %s", infile); - - LIST_INIT(&maplist); - - if (fstat(acpi_mem_fd, &sb) == -1) - errx(1, "fstat %s", infile); - - dp = mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, acpi_mem_fd, 0); - if (dp == NULL) - errx(1, "mmap %s", infile); - - sdt = (ACPI_TABLE_HEADER *)dp; - if (strncmp(dp, ACPI_SIG_DSDT, 4) != 0 || - acpi_checksum(sdt, sdt->Length) != 0) - return (NULL); - - return (sdt); -} diff --git a/usr.sbin/acpi/acpidump/acpidump.8 b/usr.sbin/acpi/acpidump/acpidump.8 deleted file mode 100644 index 1401e38..0000000 --- a/usr.sbin/acpi/acpidump/acpidump.8 +++ /dev/null @@ -1,199 +0,0 @@ -.\" ACPI (ACPI Package) -.\" -.\" Copyright (c) 1999 Doug Rabson -.\" Copyright (c) 2000 Mitsuru IWASAKI -.\" Copyright (c) 2000 Yasuo YOKOYAMA -.\" Copyright (c) 2000 Hiroki Sato -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd February 14, 2005 -.Dt ACPIDUMP 8 -.Os -.Sh NAME -.Nm acpidump -.Nd dump ACPI tables and ASL -.Sh SYNOPSIS -.Nm -.Op Fl d -.Op Fl t -.Op Fl h -.Op Fl v -.Op Fl f Ar dsdt_input -.Op Fl o Ar dsdt_output -.Sh DESCRIPTION -The -.Nm -utility analyzes ACPI tables in physical memory and can dump them to a file. -In addition, -.Nm -can call -.Xr iasl 8 -to disassemble AML -(ACPI Machine Language) -found in these tables and dump them as ASL -(ACPI Source Language) -to stdout. -.Pp -ACPI tables have an essential data block (the DSDT, -Differentiated System Description Table) -that includes information used on the kernel side such as -detailed information about PnP hardware, procedures for controlling -power management support, and so on. -The -.Nm -utility can extract the DSDT data block from physical memory and store it into -an output file and optionally also disassemble it. -If any Secondary System Description Table -(SSDT) -entries exist, they will also be included in the output file and disassembly. -.Pp -When -.Nm -is invoked without the -.Fl f -option, it will read ACPI tables from physical memory via -.Pa /dev/mem . -First it searches for the RSDP -(Root System Description Pointer), -which has the signature -.Qq RSD PTR\ \& , -and then gets the RSDT -(Root System Description Table), -which includes a list of pointers to physical memory addresses -for other tables. -The RSDT itself and all other tables linked from RSDT are generically -called SDTs -(System Description Tables) -and their header has a common format which consists of items -such as Signature, Length, Revision, Checksum, OEMID, OEM Table ID, -OEM Revision, Creator ID and Creator Revision. -When invoked with the -.Fl t -flag, the -.Nm -utility dumps contents of the following tables: -.Pp -.Bl -tag -offset indent -width 12345 -compact -.It DSDT -.It ECDT -.It FACS -.It FADT -.It HPET -.It MADT -.It MCFG -.It RSD PTR -.It RSDT -.El -.Pp -The RSDT contains a pointer to the physical memory address of the FACP -(Fixed ACPI Description Table). -The FACP defines static system information about power management support -(ACPI Hardware Register Implementation) -such as interrupt mode (INT_MODEL), -SCI interrupt number, SMI command port (SMI_CMD) -and the location of ACPI registers. -The FACP also has a pointer to a physical memory address for the DSDT. -While the other tables are fixed format, -the DSDT consists of free-formatted AML data. -.Sh OPTIONS -The following options are supported by -.Nm : -.Bl -tag -width indent -.It Fl d -Disassemble the DSDT into ASL using -.Xr iasl 8 -and print the results to stdout. -.It Fl t -Dump the contents of the various fixed tables listed above. -.It Fl h -Displays usage and exit. -.It Fl v -Enable verbose messages. -.It Fl f Ar dsdt_input -Load the DSDT from the specified file instead of physical memory. -Since only the DSDT is stored in the file, the -.Fl t -flag may not be used with this option. -.It Fl o Ar dsdt_output -Store the DSDT data block from physical memory into the specified file. -.El -.Sh FILES -.Bl -tag -width /dev/mem -.It Pa /dev/mem -.El -.Sh EXAMPLES -If a developer requests a copy of your ASL, please use the following -command to dump all tables and compress the result. -.Bd -literal -offset indent -# acpidump -dt | gzip -c9 > my_computer.asl.gz -.Ed -.Pp -This example dumps the DSDT from physical memory to foo.dsdt. -It also prints the contents of various system tables and disassembles -the AML contained in the DSDT to stdout, redirecting the output -to foo.asl. -.Bd -literal -offset indent -# acpidump -t -d -o foo.dsdt > foo.asl -.Ed -.Pp -This example reads a DSDT file and disassembles it to stdout. -Verbose messages are enabled. -.Bd -literal -offset indent -# acpidump -v -d -f foo.dsdt -.Ed -.Sh SEE ALSO -.Xr acpi 4 , -.Xr mem 4 , -.Xr acpiconf 8 , -.Xr acpidb 8 , -.Xr iasl 8 -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 5.0 -and was rewritten to use -.Xr iasl 8 -for -.Fx 5.2 . -.Sh AUTHORS -.An Doug Rabson Aq dfr@FreeBSD.org -.An Mitsuru IWASAKI Aq iwasaki@FreeBSD.org -.An Yasuo YOKOYAMA Aq yokoyama@jp.FreeBSD.org -.An Nate Lawson Aq njl@FreeBSD.org -.Pp -.An -nosplit -Some contributions made by -.An Chitoshi Ohsawa Aq ohsawa@catv1.ccn-net.ne.jp , -.An Takayasu IWANASHI Aq takayasu@wendy.a.perfect-liberty.or.jp , -.An Yoshihiko SARUMARU Aq mistral@imasy.or.jp , -.An Hiroki Sato Aq hrs@FreeBSD.org , -.An Michael Lucas Aq mwlucas@blackhelicopters.org -and -.An Michael Smith Aq msmith@FreeBSD.org . -.Sh BUGS -The current implementation does not dump the BOOT structure or -other miscellaneous tables. diff --git a/usr.sbin/acpi/acpidump/acpidump.c b/usr.sbin/acpi/acpidump/acpidump.c deleted file mode 100644 index 38844b6..0000000 --- a/usr.sbin/acpi/acpidump/acpidump.c +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "acpidump.h" - -int dflag; /* Disassemble AML using iasl(8) */ -int tflag; /* Dump contents of SDT tables */ -int vflag; /* Use verbose messages */ - -static void -usage(const char *progname) -{ - - fprintf(stderr, "usage: %s [-d] [-t] [-h] [-v] [-f dsdt_input] " - "[-o dsdt_output]\n", progname); - fprintf(stderr, "To send ASL:\n\t%s -dt | gzip -c9 > foo.asl.gz\n", - progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - ACPI_TABLE_HEADER *rsdt, *sdt; - char c, *progname; - char *dsdt_input_file, *dsdt_output_file; - - dsdt_input_file = dsdt_output_file = NULL; - progname = argv[0]; - - if (argc < 2) - usage(progname); - - while ((c = getopt(argc, argv, "dhtvf:o:")) != -1) { - switch (c) { - case 'd': - dflag = 1; - break; - case 't': - tflag = 1; - break; - case 'v': - vflag = 1; - break; - case 'f': - dsdt_input_file = optarg; - break; - case 'o': - dsdt_output_file = optarg; - break; - case 'h': - default: - usage(progname); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - - /* Get input either from file or /dev/mem */ - if (dsdt_input_file != NULL) { - if (dflag == 0 && tflag == 0) { - warnx("Need to specify -d or -t with DSDT input file"); - usage(progname); - } else if (tflag != 0) { - warnx("Can't use -t with DSDT input file"); - usage(progname); - } - if (vflag) - warnx("loading DSDT file: %s", dsdt_input_file); - rsdt = dsdt_load_file(dsdt_input_file); - } else { - if (vflag) - warnx("loading RSD PTR from /dev/mem"); - rsdt = sdt_load_devmem(); - } - - /* Display misc. SDT tables (only available when using /dev/mem) */ - if (tflag) { - if (vflag) - warnx("printing various SDT tables"); - sdt_print_all(rsdt); - } - - /* Translate RSDT to DSDT pointer */ - if (dsdt_input_file == NULL) { - sdt = sdt_from_rsdt(rsdt, ACPI_SIG_FADT, NULL); - sdt = dsdt_from_fadt((ACPI_TABLE_FADT *)sdt); - } else { - sdt = rsdt; - rsdt = NULL; - } - - /* Dump the DSDT and SSDTs to a file */ - if (dsdt_output_file != NULL) { - if (vflag) - warnx("saving DSDT file: %s", dsdt_output_file); - dsdt_save_file(dsdt_output_file, rsdt, sdt); - } - - /* Disassemble the DSDT into ASL */ - if (dflag) { - if (vflag) - warnx("disassembling DSDT, iasl messages follow"); - aml_disassemble(rsdt, sdt); - if (vflag) - warnx("iasl processing complete"); - } - - exit(0); -} diff --git a/usr.sbin/acpi/acpidump/acpidump.h b/usr.sbin/acpi/acpidump/acpidump.h deleted file mode 100644 index 3421519..0000000 --- a/usr.sbin/acpi/acpidump/acpidump.h +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * Copyright (c) 1999 Doug Rabson - * Copyright (c) 2000 Mitsuru IWASAKI - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _ACPIDUMP_H_ -#define _ACPIDUMP_H_ - -#include -#include -#include - -/* GAS address space ID constants. */ -#define ACPI_GAS_MEMORY 0 -#define ACPI_GAS_IO 1 -#define ACPI_GAS_PCI 2 -#define ACPI_GAS_EMBEDDED 3 -#define ACPI_GAS_SMBUS 4 -#define ACPI_GAS_CMOS 5 -#define ACPI_GAS_PCIBAR 6 -#define ACPI_GAS_DATATABLE 7 -#define ACPI_GAS_FIXED 0x7f - -/* Subfields in the HPET Id member. */ -#define ACPI_HPET_ID_HARDWARE_REV_ID 0x000000ff -#define ACPI_HPET_ID_COMPARATORS 0x00001f00 -#define ACPI_HPET_ID_COUNT_SIZE_CAP 0x00002000 -#define ACPI_HPET_ID_LEGACY_CAPABLE 0x00008000 -#define ACPI_HPET_ID_PCI_VENDOR_ID 0xffff0000 - -/* Find and map the RSD PTR structure and return it for parsing */ -ACPI_TABLE_HEADER *sdt_load_devmem(void); - -/* TCPA */ -struct TCPAbody { - ACPI_TABLE_HEADER header; - uint16_t platform_class; -#define ACPI_TCPA_BIOS_CLIENT 0x00 -#define ACPI_TCPA_BIOS_SERVER 0x01 - union { - struct client_hdr { - uint32_t log_max_len __packed; - uint64_t log_start_addr __packed; - } client; - struct server_hdr { - uint16_t reserved; - uint64_t log_max_len __packed; - uint64_t log_start_addr __packed; - } server; - }; -} __packed; - -struct TCPAevent { - u_int32_t pcr_index; - u_int32_t event_type; - u_int8_t pcr_value[20]; - u_int32_t event_size; - u_int8_t event_data[0]; -}; - -struct TCPApc_event { - u_int32_t event_id; - u_int32_t event_size; - u_int8_t event_data[0]; -}; - -enum TCPAevent_types { - PREBOOT = 0, - POST_CODE, - UNUSED, - NO_ACTION, - SEPARATOR, - ACTION, - EVENT_TAG, - SCRTM_CONTENTS, - SCRTM_VERSION, - CPU_MICROCODE, - PLATFORM_CONFIG_FLAGS, - TABLE_OF_DEVICES, - COMPACT_HASH, - IPL, - IPL_PARTITION_DATA, - NONHOST_CODE, - NONHOST_CONFIG, - NONHOST_INFO, - EVENT_TYPE_MAX, -}; - -enum TCPApcclient_ids { - SMBIOS = 1, - BIS_CERT, - POST_BIOS_ROM, - ESCD, - CMOS, - NVRAM, - OPTION_ROM_EXEC, - OPTION_ROM_CONFIG, - OPTION_ROM_MICROCODE = 10, - S_CRTM_VERSION, - S_CRTM_CONTENTS, - POST_CONTENTS, - HOST_TABLE_OF_DEVICES, - PCCLIENT_ID_MAX, -}; - -/* - * Load the DSDT from a previous save file. Note that other tables are - * not saved (i.e. FADT) - */ -ACPI_TABLE_HEADER *dsdt_load_file(char *); - -/* Save the DSDT to a file */ -void dsdt_save_file(char *, ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER *); - -/* Print out as many fixed tables as possible, given the RSD PTR */ -void sdt_print_all(ACPI_TABLE_HEADER *); - -/* Disassemble the AML in the DSDT */ -void aml_disassemble(ACPI_TABLE_HEADER *, ACPI_TABLE_HEADER *); - -/* Routines for accessing tables in physical memory */ -ACPI_TABLE_RSDP *acpi_find_rsd_ptr(void); -void *acpi_map_physical(vm_offset_t, size_t); -ACPI_TABLE_HEADER *sdt_from_rsdt(ACPI_TABLE_HEADER *, const char *, - ACPI_TABLE_HEADER *); -ACPI_TABLE_HEADER *dsdt_from_fadt(ACPI_TABLE_FADT *); -int acpi_checksum(void *, size_t); - -/* Command line flags */ -extern int dflag; -extern int tflag; -extern int vflag; - -#endif /* !_ACPIDUMP_H_ */ diff --git a/usr.sbin/acpi/iasl/Makefile b/usr.sbin/acpi/iasl/Makefile deleted file mode 100644 index 76999fa..0000000 --- a/usr.sbin/acpi/iasl/Makefile +++ /dev/null @@ -1,79 +0,0 @@ -# $FreeBSD$ - -PROG= iasl -SRCS= adfile.c adisasm.c adwalk.c -SRCS+= osunixxf.c - -# common -SRCS+= dmextern.c dmrestag.c dmtable.c dmtbdump.c dmtbinfo.c \ - getopt.c - -# compiler -SRCS+= aslanalyze.c aslcodegen.c aslcompile.c aslcompiler.y.h \ - aslcompilerlex.l aslcompilerparse.y aslerror.c \ - aslfiles.c aslfold.c asllength.c asllisting.c \ - aslload.c asllookup.c aslmain.c aslmap.c aslopcodes.c \ - asloperands.c aslopt.c aslpredef.c aslresource.c \ - aslrestype1.c aslrestype1i.c aslrestype2.c \ - aslrestype2d.c aslrestype2e.c aslrestype2q.c \ - aslrestype2w.c aslstartup.c aslstubs.c asltransform.c \ - asltree.c aslutils.c dtcompile.c dtfield.c dtio.c \ - dtsubtable.c dttable.c dttemplate.c dtutils.c - -# debugger -SRCS+= dbfileio.c - -# disassembler -SRCS+= dmbuffer.c dmnames.c dmobject.c dmopcode.c dmresrc.c \ - dmresrcl.c dmresrcs.c dmutils.c dmwalk.c - -# interpreter/dispatcher -SRCS+= dsfield.c dsobject.c dsopcode.c dsutils.c dswexec.c \ - dswload.c dswscope.c dswstate.c - -# interpreter/executer -SRCS+= exconvrt.c excreate.c exdump.c exmisc.c exmutex.c \ - exnames.c exoparg1.c exoparg2.c exoparg3.c exoparg6.c \ - exprep.c exregion.c exresnte.c exresolv.c exresop.c \ - exstore.c exstoren.c exstorob.c exsystem.c exutils.c - -# interpreter/parser -SRCS+= psargs.c psloop.c psopcode.c psparse.c psscope.c \ - pstree.c psutils.c pswalk.c - -# namespace -SRCS+= nsaccess.c nsalloc.c nsdump.c nsnames.c nsobject.c \ - nsparse.c nssearch.c nsutils.c nswalk.c nsxfobj.c - -# tables -SRCS+= tbfadt.c tbinstal.c tbutils.c tbxface.c - -# utilities -SRCS+= utalloc.c utcache.c utcopy.c utdebug.c utdelete.c \ - utglobal.c utinit.c utlock.c utmath.c utmisc.c \ - utmutex.c utobject.c utosi.c utresrc.c utstate.c \ - utxface.c utxferror.c - -WARNS?= 2 - -MAN= iasl.8 - -CFLAGS+= -DACPI_ASL_COMPILER -I. -CFLAGS+= -D_USE_BERKELEY_YACC -LFLAGS= -i -PAslCompiler -YFLAGS= -d -pAslCompiler -DPADD= ${LIBPTHREAD} -LDADD= -lpthread - -CLEANFILES= aslcompiler.y.h aslcompilerlex.l aslcompilerparse.y - -aslcompiler.y.h: aslcompilerparse.h - cat ${.ALLSRC} > ${.TARGET} - -aslcompilerlex.l: aslcompiler.l - cat ${.ALLSRC} > ${.TARGET} - -aslcompilerparse.y: aslcompiler.y - cat ${.ALLSRC} > ${.TARGET} - -.include diff --git a/usr.sbin/acpi/iasl/iasl.8 b/usr.sbin/acpi/iasl/iasl.8 deleted file mode 100644 index bf16c8c..0000000 --- a/usr.sbin/acpi/iasl/iasl.8 +++ /dev/null @@ -1,179 +0,0 @@ -.\"- -.\" Copyright (c) 2003 Nate Lawson -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer -.\" in this position and unchanged. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd May 20, 2008 -.Dt IASL 8 -.Os -.Sh NAME -.Nm iasl -.Nd Intel ACPI compiler/decompiler -.Sh SYNOPSIS -.Nm -.Op Fl 2cefghl -.Op Fl b Ar type -.Op Fl d Ar file -.Op Fl dc Ar file -.Op Fl hc -.Op Fl hr -.Op Fl i Ar type -.Op Fl ln -.Op Fl ls -.Op Fl oa -.Op Fl of -.Op Fl oi -.Op Fl on -.Op Fl ot -.Op Fl p Ar prefix -.Op Fl s Ar type -.Op Fl t Ar type -.Op Fl vi -.Op Fl vo -.Op Fl vr -.Op Fl vs -.Op Fl x Ar level -.Op Fl w Ar level -.Ar input-file -.Sh DESCRIPTION -The -.Nm -utility is a compiler/decompiler for ACPI Source Language (ASL) -and ACPI Machine Language (AML). -Major features of -.Nm -include: -.Bl -bullet -offset indent -.It -Full support for the ACPI 3.0b Specification including ASL grammar -elements and operators. -.It -Extensive compiler syntax and semantic error checking, especially in -the area of control methods. -This reduces the number of errors that are -not discovered until the AML code is actually interpreted (i.e., the -compile-time error checking reduces the number of run-time errors). -.It -Multiple types of output files, including formatted listing files with -intermixed source, several types of AML files, and error messages. -.El -.Sh OPTIONS -.Bl -tag -width indent -.It Fl 2 -Emit ACPI 2.0 compatible ASL code. -.It Fl b Sm Cm p | t | b Sm -Create compiler debug/trace file -.Pq Pa *.txt . -Types: Parse/Tree/Both. -.It Fl c -Parse only, no output generation. -.It Fl d Ar file -Disassemble AML to ASL source code file -.Pq Pa *.dsl . -.It Fl dc Ar file -Disassemble AML and immediately compile it. -(Obtain DSDT from current system if no input file.) -.It Fl e -Generate -.Fn External -statements for unresolved symbols. -.It Fl f -Ignore errors, force creation of AML output file(s). -.It Fl g -Get ACPI tables and write to files -.Pq Pa *.dat . -.It Fl h -Additional help and compiler debug options. -.It Fl hc -Display operators allowed in constant expressions. -.It Fl hr -Display ACPI reserved method names. -.It Fl i Sm Cm a | c Sm -Create assembler or C include file -.Pa ( *.inc -or -.Pa *.h ) . -.It Fl l -Create mixed listing file (ASL source and AML) -.Pq Pa *.lst . -.It Fl ln -Create namespace file -.Pq Pa *.nsp . -.It Fl ls -Create combined source file (expanded includes) -.Pq Pa *.src . -.It Fl oa -Disable all optimizations (compatibility mode). -.It Fl of -Disable constant folding. -.It Fl oi -Disable integer optimization to Zero/One/Ones. -.It Fl on -Disable named reference string optimization. -.It Fl ot -Display compile times. -.It Fl p Ar prefix -Specify filename prefix for all output files (including -.Pa .aml ) . -.It Fl s Sm Cm a | c Sm -Create AML in assembler or C source file -.Pa ( *.asm -or -.Pa *.c ) . -.It Fl t Ar a|c -Create AML in assembler or C hex table -.Pq Pa *.hex . -.It Fl vi -Less verbose errors and warnings for use with IDEs. -.It Fl vo -Enable optimization comments. -.It Fl vr -Disable remarks. -.It Fl vs -Disable signon. -.It Fl x Ar level -Set debug level for trace output. -.It Fl w Ar level -Set warning level. -.El -.Sh SEE ALSO -.Xr acpi 4 , -.Xr acpidump 8 -.Sh HISTORY -The -.Nm -utility is provided with Intel ACPI-CA. -It first appeared in -.Fx 5.2 . -.Sh AUTHORS -.An -nosplit -The -.Nm -utility was written by -.An Intel . -This manual page was written by -.An Nate Lawson . diff --git a/usr.sbin/adduser/Makefile b/usr.sbin/adduser/Makefile deleted file mode 100644 index 0ca2dae..0000000 --- a/usr.sbin/adduser/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -SCRIPTS=adduser.sh rmuser.sh -MAN= adduser.conf.5 adduser.8 rmuser.8 - -.include diff --git a/usr.sbin/adduser/adduser.8 b/usr.sbin/adduser/adduser.8 deleted file mode 100644 index 03f7e34..0000000 --- a/usr.sbin/adduser/adduser.8 +++ /dev/null @@ -1,480 +0,0 @@ -.\" Copyright (c) 1995-1996 Wolfram Schneider . Berlin. -.\" All rights reserved. -.\" Copyright (c) 2002-2004 Michael Telahun Makonnen -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd March 16, 2008 -.Dt ADDUSER 8 -.Os -.Sh NAME -.Nm adduser -.Nd command for adding new users -.Sh SYNOPSIS -.Nm -.Op Fl CDENShq -.Op Fl G Ar groups -.Op Fl L Ar login_class -.Op Fl M Ar mode -.Op Fl d Ar partition -.Op Fl f Ar file -.Op Fl g Ar login_group -.Op Fl k Ar dotdir -.Op Fl m Ar message_file -.Op Fl s Ar shell -.Op Fl u Ar uid_start -.Op Fl w Ar type -.Sh DESCRIPTION -The -.Nm -utility is a shell script, implemented around the -.Xr pw 8 -command, for adding new users. -It creates passwd/group entries, a home directory, -copies dotfiles and sends the new user a welcome message. -It supports two modes of operation. -It may be used interactively -at the command line to add one user at a time, or it may be directed -to get the list of new users from a file and operate in batch mode -without requiring any user interaction. -.Sh RESTRICTIONS -.Bl -tag -width indent -.It username -Login name. -The user name is restricted to whatever -.Xr pw 8 -will accept. -Generally this means it -may contain only lowercase characters or digits but cannot begin with the -.Ql - -character. -Maximum length -is 16 characters. -The reasons for this limit are historical. -Given that people have traditionally wanted to break this -limit for aesthetic reasons, it has never been of great importance to break -such a basic fundamental parameter in -.Ux . -You can change -.Dv UT_NAMESIZE -in -.In utmp.h -and recompile the -world; people have done this and it works, but you will have problems -with any precompiled programs, or source that assumes the 8-character -name limit, such as NIS. -The NIS protocol mandates an 8-character username. -If you need a longer login name for e-mail addresses, -you can define an alias in -.Pa /etc/mail/aliases . -.It "full name" -This is typically known as the gecos field and usually contains -the user's full name. -Additionally, it may contain a comma separated -list of values such as office number and work and home phones. -If the -name contains an ampersand it will be replaced by the capitalized -login name when displayed by other programs. -The -.Ql \&: -character is not allowed. -.It shell -Unless the -.Fl S -argument is supplied only valid shells from the shell database -.Pq Pa /etc/shells -are allowed. -In addition, -either the base name or the full path of the shell may be supplied. -.It UID -Automatically generated or your choice. -It must be less than 32000. -.It "GID/login group" -Automatically generated or your choice. -It must be less than 32000. -.It password -You may choose an empty password, disable the password, use a -randomly generated password or specify your own plaintext password, -which will be encrypted before being stored in the user database. -.El -.Sh UNIQUE GROUPS -Perhaps you are missing what -.Em can -be done with this scheme that falls apart -with most other schemes. -With each user in their own group, -they can safely run with a umask of 002 instead of the usual 022 -and create files in their home directory -without worrying about others being able to change them. -.Pp -For a shared area you create a separate UID/GID (like cvs or ncvs on freefall), -you place each person that should be able to access this area into that new -group. -.Pp -This model of UID/GID administration allows far greater flexibility than lumping -users into groups and having to muck with the umask when working in a shared -area. -.Pp -I have been using this model for almost 10 years and found that it works -for most situations, and has never gotten in the way. -(Rod Grimes) -.Sh CONFIGURATION -The -.Nm -utility reads its configuration information from -.Pa /etc/adduser.conf . -If this file does not exist, it will use predefined defaults. -While this file may be edited by hand, -the safer option is to use the -.Fl C -command line argument. -With this argument, -.Nm -will start interactive input, save the answers to its prompts in -.Pa /etc/adduser.conf , -and promptly exit without modifying the user -database. -Options specified on the command line will take precedence over -any values saved in this file. -.Sh OPTIONS -.Bl -tag -width indent -.It Fl C -Create new configuration file and exit. -This option is mutually exclusive with the -.Fl f -option. -.It Fl d Ar partition -Home partition. -Default partition, under which all user directories -will be located. -The -.Pa /nonexistent -partition is considered special. -The -.Nm -script will not create and populate a home directory by that name. -Otherwise, -by default it attempts to create a home directory. -.It Fl D -Do not attempt to create the home directory. -.It Fl E -Disable the account. -This option will lock the account by prepending the string -.Dq Li *LOCKED* -to the password field. -The account may be unlocked -by the super-user with the -.Xr pw 8 -command: -.Pp -.D1 Nm pw Cm unlock Op Ar name | uid -.It Fl f Ar file -Get the list of accounts to create from -.Ar file . -If -.Ar file -is -.Dq Fl , -then get the list from standard input. -If this option is specified, -.Nm -will operate in batch mode and will not seek any user input. -If an error is encountered while processing an account, it will write a -message to standard error and move to the next account. -The format -of the input file is described below. -.It Fl g Ar login_group -Normally, -if no login group is specified, -it is assumed to be the same as the username. -This option makes -.Ar login_group -the default. -.It Fl G Ar groups -Space-separated list of additional groups. -This option allows the user to specify additional groups to add users to. -The user is a member of these groups in addition to their login group. -.It Fl h -Print a summary of options and exit. -.It Fl k Ar directory -Copy files from -.Ar directory -into the home -directory of new users; -.Pa dot.foo -will be renamed to -.Pa .foo . -.It Fl L Ar login_class -Set default login class. -.It Fl m Ar file -Send new users a welcome message from -.Ar file . -Specifying a value of -.Cm no -for -.Ar file -causes no message to be sent to new users. -Please note that the message -file can reference the internal variables of the -.Nm -script. -.It Fl M Ar mode -Create the home directory with permissions set to -.Ar mode . -.It Fl N -Do not read the default configuration file. -.It Fl q -Minimal user feedback. -In particular, the random password will not be echoed to -standard output. -.It Fl s Ar shell -Default shell for new users. -The -.Ar shell -argument may be the base name of the shell or the full path. -Unless the -.Fl S -argument is supplied the shell must exist in -.Pa /etc/shells -or be the special shell -.Em nologin -to be considered a valid shell. -.It Fl S -The existence or validity of the specified shell will not be checked. -.It Fl u Ar uid -Use UIDs from -.Ar uid -on up. -.It Fl w Ar type -Password type. -The -.Nm -utility allows the user to specify what type of password to create. -The -.Ar type -argument may have one of the following values: -.Bl -tag -width ".Cm random" -.It Cm no -Disable the password. -Instead of an encrypted string, the password field will contain a single -.Ql * -character. -The user may not log in until the super-user -manually enables the password. -.It Cm none -Use an empty string as the password. -.It Cm yes -Use a user-supplied string as the password. -In interactive mode, -the user will be prompted for the password. -In batch mode, the -last (10th) field in the line is assumed to be the password. -.It Cm random -Generate a random string and use it as a password. -The password will be echoed to standard output. -In addition, it will be available for inclusion in the message file in the -.Va randompass -variable. -.El -.El -.Sh FORMAT -When the -.Fl f -option is used, the account information must be stored in a specific -format. -All empty lines or lines beginning with a -.Ql # -will be ignored. -All other lines must contain ten colon -.Pq Ql \&: -separated fields as described below. -Command line options do not take precedence -over values in the fields. -Only the password field may contain a -.Ql \&: -character as part of the string. -.Pp -.Sm off -.D1 Ar name : uid : gid : class : change : expire : gecos : home_dir : shell : password -.Sm on -.Bl -tag -width ".Ar password" -.It Ar name -Login name. -This field may not be empty. -.It Ar uid -Numeric login user ID. -If this field is left empty, it will be automatically generated. -.It Ar gid -Numeric primary group ID. -If this field is left empty, a group with the -same name as the user name will be created and its GID will be used -instead. -.It Ar class -Login class. -This field may be left empty. -.It Ar change -Password ageing. -This field denotes the password change date for the account. -The format of this field is the same as the format of the -.Fl p -argument to -.Xr pw 8 . -It may be -.Ar dd Ns - Ns Ar mmm Ns - Ns Ar yy Ns Op Ar yy , -where -.Ar dd -is for the day, -.Ar mmm -is for the month in numeric or alphabetical format: -.Dq Li 10 -or -.Dq Li Oct , -and -.Ar yy Ns Op Ar yy -is the four or two digit year. -To denote a time relative to the current date the format is: -.No + Ns Ar n Ns Op Ar mhdwoy , -where -.Ar n -denotes a number, followed by the minutes, hours, days, weeks, -months or years after which the password must be changed. -This field may be left empty to turn it off. -.It Ar expire -Account expiration. -This field denotes the expiry date of the account. -The account may not be used after the specified date. -The format of this field is the same as that for password ageing. -This field may be left empty to turn it off. -.It Ar gecos -Full name and other extra information about the user. -.It Ar home_dir -Home directory. -If this field is left empty, it will be automatically -created by appending the username to the home partition. -The -.Pa /nonexistent -home directory is considered special and -is understood to mean that no home directory is to be -created for the user. -.It Ar shell -Login shell. -This field should contain either the base name or -the full path to a valid login shell. -.It Ar password -User password. -This field should contain a plaintext string, which will -be encrypted before being placed in the user database. -If the password type is -.Cm yes -and this field is empty, it is assumed the account will have an empty password. -If the password type is -.Cm random -and this field is -.Em not -empty, its contents will be used -as a password. -This field will be ignored if the -.Fl w -option is used with a -.Cm no -or -.Cm none -argument. -Be careful not to terminate this field with a closing -.Ql \&: -because it will be treated as part of the password. -.El -.Sh FILES -.Bl -tag -width ".Pa /etc/adduser.message" -compact -.It Pa /etc/master.passwd -user database -.It Pa /etc/group -group database -.It Pa /etc/shells -shell database -.It Pa /etc/login.conf -login classes database -.It Pa /etc/adduser.conf -configuration file for -.Nm -.It Pa /etc/adduser.message -message file for -.Nm -.It Pa /usr/share/skel -skeletal login directory -.It Pa /var/log/adduser -logfile for -.Nm -.El -.Sh SEE ALSO -.Xr chpass 1 , -.Xr passwd 1 , -.Xr adduser.conf 5 , -.Xr aliases 5 , -.Xr group 5 , -.Xr login.conf 5 , -.Xr passwd 5 , -.Xr shells 5 , -.Xr adding_user 8 , -.Xr pw 8 , -.Xr pwd_mkdb 8 , -.Xr rmuser 8 , -.Xr vipw 8 , -.Xr yp 8 -.Sh HISTORY -The -.Nm -command appeared in -.Fx 2.1 . -.Sh AUTHORS -.An -nosplit -This manual page and the original script, in Perl, was written by -.An Wolfram Schneider Aq wosch@FreeBSD.org . -The replacement script, written as a Bourne -shell script with some enhancements, and the man page modification that -came with it were done by -.An Mike Makonnen Aq mtm@identd.net . -.Sh BUGS -In order for -.Nm -to correctly expand variables such as -.Va $username -and -.Va $randompass -in the message sent to new users, it must let the shell evaluate -each line of the message file. -This means that shell commands can also be embedded in the message file. -The -.Nm -utility attempts to mitigate the possibility of an attacker using this -feature by refusing to evaluate the file if it is not owned and writable -only by the root user. -In addition, shell special characters and operators will have to be -escaped when used in the message file. -.Pp -Also, password ageing and account expiry times are currently settable -only in batch mode or when specified in -.Pa /etc/adduser.conf . -The user should be able to set them in interactive mode as well. diff --git a/usr.sbin/adduser/adduser.conf.5 b/usr.sbin/adduser/adduser.conf.5 deleted file mode 100644 index d5fcf77..0000000 --- a/usr.sbin/adduser/adduser.conf.5 +++ /dev/null @@ -1,221 +0,0 @@ -.\" -.\" Copyright (c) 2004 Tom Rhodes -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd April 12, 2007 -.Dt ADDUSER.CONF 5 -.Os -.Sh NAME -.Nm adduser.conf -.Nd -.Xr adduser 8 -configuration file -.Sh DESCRIPTION -The -.Pa /etc/adduser.conf -file is automatically generated by the -.Xr adduser 8 -utility when invoked with the -.Fl C -command-line option. -It is not meant to be edited by hand. -.Pp -The -.Pa /etc/adduser.conf -file is used to pre-set certain configuration options for -the -.Xr adduser 8 -utility. -When -.Xr adduser 8 -is invoked, it will check to see if this file exists, and -if so, the configuration will be used or offered as the -default settings. -The -.Nm -file offers three types of configuration: -.Bl -bullet -.It -Default settings offered by -.Xr adduser 8 . -These options are specified in the configuration file and offered -as the default during every invocation of the -.Xr adduser 8 -utility. -.It -Configuration options which can be set in -.Nm , -but overridden by passing a flag to -.Xr adduser 8 . -.It -Configuration supported by -.Xr adduser 8 -but not offered by a flag or during initial invocation. -.El -.Pp -In the first case, these options can be set in -.Nm -but will still be offered when -.Xr adduser 8 -is invoked. -In the second case, -.Xr adduser 8 -will read the configuration data unless a flag -has been passed to override it. -For example, the -.Va defaultshell -option. -In the third case, the configuration will be utilized, but the -user will never be prompted to modify the default setting by -either a flag or an -.Xr adduser 8 -prompt. -For example, the -.Va upwexpire -setting. -.Pp -The following configuration options can be set in -.Nm : -.Bl -tag -width ".Va defaultgroups" -offset indent -.It Va defaultLgroup -The default group new users will be added to. -.It Va defaultclass -The default class to place users in as described in -.Xr login.conf 5 . -.It Va defaultgroups -This option is used to specify what other groups the new account -should be added to. -.It Va passwdtype -May be one of -.Cm no , none , random , -or -.Cm yes , -as described in -.Xr adduser 8 . -As such, the text is not duplicated here and may be -read in -.Xr adduser 8 . -.It Va homeprefix -The default home directory prefix, usually -.Pa /home . -.It Va defaultshell -The user's default shell which may be any of the shells listed in -.Xr shells 5 . -.It Va udotdir -Defines the location of the default shell and environment -configuration files. -.It Va msgfile -Location of the default new user message file. -This message will be sent to all new users if specified -here or at the -.Xr adduser 8 -prompt. -.It Va disableflag -The default message enclosed in brackets for the -lock account prompt. -.It Va upwexpire -The default password expiration time. -Format of the date is either a -.Ux -time in decimal, or a date in -.Sm off -.Ar dd No - Ar mmm No - Ar yy Op Ar yy -.Sm on -format, where -.Ar dd -is the day, -.Ar mmm -is the month in either numeric or -alphabetic format, and -.Ar yy Ns Op Ar yy -is either a two or four digit year. -This option also accepts a relative date in the form of -.Sm off -.Ar n Op Ar m h d w o y -.Sm on -where -.Ar n -is a decimal, octal (leading 0) or hexadecimal (leading 0x) digit -followed by the number of Minutes, Hours, Days, Weeks, Months or -Years from the current date at -which the expiration time is to be set. -.It Va uexpire -The default account expire time. -The format is similar to the -.Va upwexpire -option. -.It Va ugecos -The default information to be held in the GECOS field of -.Pa /etc/master.passwd . -.It Va uidstart -The default user ID setting. -This must be a number above 1000 and fewer than 65534. -.El -.Sh EXAMPLES -The following is an example -.Nm -file created with the -.Fl C -.Xr adduser 8 -flag and modified. -.Bd -literal -offset indent -# Configuration file for adduser(8). -# NOTE: only *some* variables are saved. -# Last Modified on Fri Mar 30 14:04:05 EST 2004. - -defaultLgroup= -defaultclass= -defaultgroups= -passwdtype=yes -homeprefix=/home -defaultshell=/bin/csh -udotdir=/usr/share/skel -msgfile=/etc/adduser.msg -disableflag= -upwexpire=91d # Expire passwords 91 days after creation. -.Ed -.Sh SEE ALSO -.Xr group 5 , -.Xr passwd 5 , -.Xr adduser 8 , -.Xr pw 8 , -.Xr rmuser 8 -.Sh HISTORY -The -.Nm -manual page first appeared in -.Fx 5.3 . -.Sh AUTHORS -This manual page was written by -.An Tom Rhodes Aq trhodes@FreeBSD.org . -.Sh BUGS -The internal variables documented here may change without notice. -Do not rely on them. -To modify this file invoke -.Xr adduser 8 -with the -.Fl C -option instead. diff --git a/usr.sbin/adduser/adduser.sh b/usr.sbin/adduser/adduser.sh deleted file mode 100644 index 8e05f33..0000000 --- a/usr.sbin/adduser/adduser.sh +++ /dev/null @@ -1,1050 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2002-2004 Michael Telahun Makonnen. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# Email: Mike Makonnen -# -# $FreeBSD$ -# - -# err msg -# Display $msg on stderr, unless we're being quiet. -# -err() { - if [ -z "$quietflag" ]; then - echo 1>&2 ${THISCMD}: ERROR: $* - fi -} - -# info msg -# Display $msg on stdout, unless we're being quiet. -# -info() { - if [ -z "$quietflag" ]; then - echo ${THISCMD}: INFO: $* - fi -} - -# get_nextuid -# Output the value of $_uid if it is available for use. If it -# is not, output the value of the next higher uid that is available. -# If a uid is not specified, output the first available uid, as indicated -# by pw(8). -# -get_nextuid () { - _uid=$1 - _nextuid= - - if [ -z "$_uid" ]; then - _nextuid="`${PWCMD} usernext | cut -f1 -d:`" - else - while : ; do - ${PWCMD} usershow $_uid > /dev/null 2>&1 - if [ ! "$?" -eq 0 ]; then - _nextuid=$_uid - break - fi - _uid=$(($_uid + 1)) - done - fi - echo $_nextuid -} - -# show_usage -# Display usage information for this utility. -# -show_usage() { - echo "usage: ${THISCMD} [options]" - echo " options may include:" - echo " -C save to the configuration file only" - echo " -D do not attempt to create the home directory" - echo " -E disable this account after creation" - echo " -G additional groups to add accounts to" - echo " -L login class of the user" - echo " -M file permission for home directory" - echo " -N do not read configuration file" - echo " -S a nonexistent shell is not an error" - echo " -d home directory" - echo " -f file from which input will be received" - echo " -g default login group" - echo " -h display this usage message" - echo " -k path to skeleton home directory" - echo " -m user welcome message file" - echo " -q absolute minimal user feedback" - echo " -s shell" - echo " -u uid to start at" - echo " -w password type: no, none, yes or random" -} - -# valid_shells -# Outputs a list of valid shells from /etc/shells. Only the -# basename of the shell is output. -# -valid_shells() { - _prefix= - cat ${ETCSHELLS} | - while read _path _junk ; do - case $_path in - \#*|'') - ;; - *) - echo -n "${_prefix}`basename $_path`" - _prefix=' ' - ;; - esac - done - - # /usr/sbin/nologin is a special case - [ -x "${NOLOGIN_PATH}" ] && echo -n " ${NOLOGIN}" -} - -# fullpath_from_shell shell -# Given $shell, which is either the full path to a shell or -# the basename component of a valid shell, get the -# full path to the shell from the /etc/shells file. -# -fullpath_from_shell() { - _shell=$1 - [ -z "$_shell" ] && return 1 - - # /usr/sbin/nologin is a special case; it needs to be handled - # before the cat | while loop, since a 'return' from within - # a subshell will not terminate the function's execution, and - # the path to the nologin shell might be printed out twice. - # - if [ "$_shell" = "${NOLOGIN}" -o \ - "$_shell" = "${NOLOGIN_PATH}" ]; then - echo ${NOLOGIN_PATH} - return 0; - fi - - cat ${ETCSHELLS} | - while read _path _junk ; do - case "$_path" in - \#*|'') - ;; - *) - if [ "$_path" = "$_shell" -o \ - "`basename $_path`" = "$_shell" ]; then - echo $_path - return 0 - fi - ;; - esac - done - - return 1 -} - -# shell_exists shell -# If the given shell is listed in ${ETCSHELLS} or it is -# the nologin shell this function will return 0. -# Otherwise, it will return 1. If shell is valid but -# the path is invalid or it is not executable it -# will emit an informational message saying so. -# -shell_exists() { - _sh="$1" - _shellchk="${GREPCMD} '^$_sh$' ${ETCSHELLS} > /dev/null 2>&1" - - if ! eval $_shellchk; then - # The nologin shell is not listed in /etc/shells. - if [ "$_sh" != "${NOLOGIN_PATH}" ]; then - err "Invalid shell ($_sh) for user $username." - return 1 - fi - fi - ! [ -x "$_sh" ] && - info "The shell ($_sh) does not exist or is not executable." - - return 0 -} - -# save_config -# Save some variables to a configuration file. -# Note: not all script variables are saved, only those that -# it makes sense to save. -# -save_config() { - echo "# Configuration file for adduser(8)." > ${ADDUSERCONF} - echo "# NOTE: only *some* variables are saved." >> ${ADDUSERCONF} - echo "# Last Modified on `${DATECMD}`." >> ${ADDUSERCONF} - echo '' >> ${ADDUSERCONF} - echo "defaultHomePerm=$uhomeperm" >> ${ADDUSERCONF} - echo "defaultLgroup=$ulogingroup" >> ${ADDUSERCONF} - echo "defaultclass=$uclass" >> ${ADDUSERCONF} - echo "defaultgroups=$ugroups" >> ${ADDUSERCONF} - echo "passwdtype=$passwdtype" >> ${ADDUSERCONF} - echo "homeprefix=$homeprefix" >> ${ADDUSERCONF} - echo "defaultshell=$ushell" >> ${ADDUSERCONF} - echo "udotdir=$udotdir" >> ${ADDUSERCONF} - echo "msgfile=$msgfile" >> ${ADDUSERCONF} - echo "disableflag=$disableflag" >> ${ADDUSERCONF} - echo "uidstart=$uidstart" >> ${ADDUSERCONF} -} - -# add_user -# Add a user to the user database. If the user chose to send a welcome -# message or lock the account, do so. -# -add_user() { - - # Is this a configuration run? If so, don't modify user database. - # - if [ -n "$configflag" ]; then - save_config - return - fi - - _uid= - _name= - _comment= - _gecos= - _home= - _group= - _grouplist= - _shell= - _class= - _dotdir= - _expire= - _pwexpire= - _passwd= - _upasswd= - _passwdmethod= - - _name="-n '$username'" - [ -n "$uuid" ] && _uid='-u "$uuid"' - [ -n "$ulogingroup" ] && _group='-g "$ulogingroup"' - [ -n "$ugroups" ] && _grouplist='-G "$ugroups"' - [ -n "$ushell" ] && _shell='-s "$ushell"' - [ -n "$uclass" ] && _class='-L "$uclass"' - [ -n "$ugecos" ] && _comment='-c "$ugecos"' - [ -n "$udotdir" ] && _dotdir='-k "$udotdir"' - [ -n "$uexpire" ] && _expire='-e "$uexpire"' - [ -n "$upwexpire" ] && _pwexpire='-p "$upwexpire"' - if [ -z "$Dflag" -a -n "$uhome" ]; then - # The /nonexistent home directory is special. It - # means the user has no home directory. - if [ "$uhome" = "$NOHOME" ]; then - _home='-d "$uhome"' - else - # Use home directory permissions if specified - if [ -n "$uhomeperm" ]; then - _home='-m -d "$uhome" -M "$uhomeperm"' - else - _home='-m -d "$uhome"' - fi - fi - elif [ -n "$Dflag" -a -n "$uhome" ]; then - _home='-d "$uhome"' - fi - case $passwdtype in - no) - _passwdmethod="-w no" - _passwd="-h -" - ;; - yes) - # Note on processing the password: The outer double quotes - # make literal everything except ` and \ and $. - # The outer single quotes make literal ` and $. - # We can ensure the \ isn't treated specially by specifying - # the -r switch to the read command used to obtain the input. - # - _passwdmethod="-w yes" - _passwd="-h 0" - _upasswd='echo "$upass" |' - ;; - none) - _passwdmethod="-w none" - ;; - random) - _passwdmethod="-w random" - ;; - esac - - _pwcmd="$_upasswd ${PWCMD} useradd $_uid $_name $_group $_grouplist $_comment" - _pwcmd="$_pwcmd $_shell $_class $_home $_dotdir $_passwdmethod $_passwd" - _pwcmd="$_pwcmd $_expire $_pwexpire" - - if ! _output=`eval $_pwcmd` ; then - err "There was an error adding user ($username)." - return 1 - else - info "Successfully added ($username) to the user database." - if [ "random" = "$passwdtype" ]; then - randompass="$_output" - info "Password for ($username) is: $randompass" - fi - fi - - if [ -n "$disableflag" ]; then - if ${PWCMD} lock $username ; then - info "Account ($username) is locked." - else - info "Account ($username) could NOT be locked." - fi - fi - - _line= - _owner= - _perms= - if [ -n "$msgflag" ]; then - [ -r "$msgfile" ] && { - # We're evaluating the contents of an external file. - # Let's not open ourselves up for attack. _perms will - # be empty if it's writeable only by the owner. _owner - # will *NOT* be empty if the file is owned by root. - # - _dir="`dirname $msgfile`" - _file="`basename $msgfile`" - _perms=`/usr/bin/find $_dir -name $_file -perm +07022 -prune` - _owner=`/usr/bin/find $_dir -name $_file -user 0 -prune` - if [ -z "$_owner" -o -n "$_perms" ]; then - err "The message file ($msgfile) may be writeable only by root." - return 1 - fi - cat "$msgfile" | - while read _line ; do - eval echo "$_line" - done | ${MAILCMD} -s"Welcome" ${username} - info "Sent welcome message to ($username)." - } - fi -} - -# get_user -# Reads username of the account from standard input or from a global -# variable containing an account line from a file. The username is -# required. If this is an interactive session it will prompt in -# a loop until a username is entered. If it is batch processing from -# a file it will output an error message and return to the caller. -# -get_user() { - _input= - - # No need to take down user names if this is a configuration saving run. - [ -n "$configflag" ] && return - - while : ; do - if [ -z "$fflag" ]; then - echo -n "Username: " - read _input - else - _input="`echo "$fileline" | cut -f1 -d:`" - fi - - # There *must* be a username, and it must not exist. If - # this is an interactive session give the user an - # opportunity to retry. - # - if [ -z "$_input" ]; then - err "You must enter a username!" - [ -z "$fflag" ] && continue - fi - ${PWCMD} usershow $_input > /dev/null 2>&1 - if [ "$?" -eq 0 ]; then - err "User exists!" - [ -z "$fflag" ] && continue - fi - break - done - username="$_input" -} - -# get_gecos -# Reads extra information about the user. Can be used both in interactive -# and batch (from file) mode. -# -get_gecos() { - _input= - - # No need to take down additional user information for a configuration run. - [ -n "$configflag" ] && return - - if [ -z "$fflag" ]; then - echo -n "Full name: " - read _input - else - _input="`echo "$fileline" | cut -f7 -d:`" - fi - ugecos="$_input" -} - -# get_shell -# Get the account's shell. Works in interactive and batch mode. It -# accepts either the base name of the shell or the full path. -# If an invalid shell is entered it will simply use the default shell. -# -get_shell() { - _input= - _fullpath= - ushell="$defaultshell" - - # Make sure the current value of the shell is a valid one - if [ -z "$Sflag" ]; then - if ! shell_exists $ushell ; then - info "Using default shell ${defaultshell}." - ushell="$defaultshell" - fi - fi - - if [ -z "$fflag" ]; then - echo -n "Shell ($shells) [`basename $ushell`]: " - read _input - else - _input="`echo "$fileline" | cut -f9 -d:`" - fi - if [ -n "$_input" ]; then - if [ -n "$Sflag" ]; then - ushell="$_input" - else - _fullpath=`fullpath_from_shell $_input` - if [ -n "$_fullpath" ]; then - ushell="$_fullpath" - else - err "Invalid shell ($_input) for user $username." - info "Using default shell ${defaultshell}." - ushell="$defaultshell" - fi - fi - fi -} - -# get_homedir -# Reads the account's home directory. Used both with interactive input -# and batch input. -# -get_homedir() { - _input= - if [ -z "$fflag" ]; then - echo -n "Home directory [${homeprefix}/${username}]: " - read _input - else - _input="`echo "$fileline" | cut -f8 -d:`" - fi - - if [ -n "$_input" ]; then - uhome="$_input" - # if this is a configuration run, then user input is the home - # directory prefix. Otherwise it is understood to - # be $prefix/$user - # - [ -z "$configflag" ] && homeprefix="`dirname $uhome`" || homeprefix="$uhome" - else - uhome="${homeprefix}/${username}" - fi -} - -# get_homeperm -# Reads the account's home directory permissions. -# -get_homeperm() { - uhomeperm=$defaultHomePerm - _input= - _prompt= - - if [ -n "$uhomeperm" ]; then - _prompt="Home directory permissions [${uhomeperm}]: " - else - _prompt="Home directory permissions (Leave empty for default): " - fi - if [ -z "$fflag" ]; then - echo -n "$_prompt" - read _input - fi - - if [ -n "$_input" ]; then - uhomeperm="$_input" - fi -} - -# get_uid -# Reads a numeric userid in an interactive or batch session. Automatically -# allocates one if it is not specified. -# -get_uid() { - uuid=${uidstart} - _input= - _prompt= - - if [ -n "$uuid" ]; then - _prompt="Uid [$uuid]: " - else - _prompt="Uid (Leave empty for default): " - fi - if [ -z "$fflag" ]; then - echo -n "$_prompt" - read _input - else - _input="`echo "$fileline" | cut -f2 -d:`" - fi - - [ -n "$_input" ] && uuid=$_input - uuid=`get_nextuid $uuid` - uidstart=$uuid -} - -# get_class -# Reads login class of account. Can be used in interactive or batch mode. -# -get_class() { - uclass="$defaultclass" - _input= - _class=${uclass:-"default"} - - if [ -z "$fflag" ]; then - echo -n "Login class [$_class]: " - read _input - else - _input="`echo "$fileline" | cut -f4 -d:`" - fi - - [ -n "$_input" ] && uclass="$_input" -} - -# get_logingroup -# Reads user's login group. Can be used in both interactive and batch -# modes. The specified value can be a group name or its numeric id. -# This routine leaves the field blank if nothing is provided and -# a default login group has not been set. The pw(8) command -# will then provide a login group with the same name as the username. -# -get_logingroup() { - ulogingroup="$defaultLgroup" - _input= - - if [ -z "$fflag" ]; then - echo -n "Login group [${ulogingroup:-$username}]: " - read _input - else - _input="`echo "$fileline" | cut -f3 -d:`" - fi - - # Pw(8) will use the username as login group if it's left empty - [ -n "$_input" ] && ulogingroup="$_input" -} - -# get_groups -# Read additional groups for the user. It can be used in both interactive -# and batch modes. -# -get_groups() { - ugroups="$defaultgroups" - _input= - _group=${ulogingroup:-"${username}"} - - if [ -z "$configflag" ]; then - [ -z "$fflag" ] && echo -n "Login group is $_group. Invite $username" - [ -z "$fflag" ] && echo -n " into other groups? [$ugroups]: " - else - [ -z "$fflag" ] && echo -n "Enter additional groups [$ugroups]: " - fi - read _input - - [ -n "$_input" ] && ugroups="$_input" -} - -# get_expire_dates -# Read expiry information for the account and also for the password. This -# routine is used only from batch processing mode. -# -get_expire_dates() { - upwexpire="`echo "$fileline" | cut -f5 -d:`" - uexpire="`echo "$fileline" | cut -f6 -d:`" -} - -# get_password -# Read the password in batch processing mode. The password field matters -# only when the password type is "yes" or "random". If the field is empty and the -# password type is "yes", then it assumes the account has an empty passsword -# and changes the password type accordingly. If the password type is "random" -# and the password field is NOT empty, then it assumes the account will NOT -# have a random password and set passwdtype to "yes." -# -get_password() { - # We may temporarily change a password type. Make sure it's changed - # back to whatever it was before we process the next account. - # - [ -n "$savedpwtype" ] && { - passwdtype=$savedpwtype - savedpwtype= - } - - # There may be a ':' in the password - upass=${fileline#*:*:*:*:*:*:*:*:*:} - - if [ -z "$upass" ]; then - case $passwdtype in - yes) - # if it's empty, assume an empty password - passwdtype=none - savedpwtype=yes - ;; - esac - else - case $passwdtype in - random) - passwdtype=yes - savedpwtype=random - ;; - esac - fi -} - -# input_from_file -# Reads a line of account information from standard input and -# adds it to the user database. -# -input_from_file() { - _field= - - while read -r fileline ; do - case "$fileline" in - \#*|'') - ;; - *) - get_user || continue - get_gecos - get_uid - get_logingroup - get_class - get_shell - get_homedir - get_homeperm - get_password - get_expire_dates - ugroups="$defaultgroups" - - add_user - ;; - esac - done -} - -# input_interactive -# Prompts for user information interactively, and commits to -# the user database. -# -input_interactive() { - _disable= - _pass= - _passconfirm= - _random="no" - _emptypass="no" - _usepass="yes" - _logingroup_ok="no" - _groups_ok="no" - case $passwdtype in - none) - _emptypass="yes" - _usepass="yes" - ;; - no) - _usepass="no" - ;; - random) - _random="yes" - ;; - esac - - get_user - get_gecos - get_uid - - # The case where group = user is handled elsewhere, so - # validate any other groups the user is invited to. - until [ "$_logingroup_ok" = yes ]; do - get_logingroup - _logingroup_ok=yes - if [ -n "$ulogingroup" -a "$username" != "$ulogingroup" ]; then - if ! ${PWCMD} show group $ulogingroup > /dev/null 2>&1; then - echo "Group $ulogingroup does not exist!" - _logingroup_ok=no - fi - fi - done - until [ "$_groups_ok" = yes ]; do - get_groups - _groups_ok=yes - for i in $ugroups; do - if [ "$username" != "$i" ]; then - if ! ${PWCMD} show group $i > /dev/null 2>&1; then - echo "Group $i does not exist!" - _groups_ok=no - fi - fi - done - done - - get_class - get_shell - get_homedir - get_homeperm - - while : ; do - echo -n "Use password-based authentication? [$_usepass]: " - read _input - [ -z "$_input" ] && _input=$_usepass - case $_input in - [Nn][Oo]|[Nn]) - passwdtype="no" - ;; - [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - while : ; do - echo -n "Use an empty password? (yes/no) [$_emptypass]: " - read _input - [ -n "$_input" ] && _emptypass=$_input - case $_emptypass in - [Nn][Oo]|[Nn]) - echo -n "Use a random password? (yes/no) [$_random]: " - read _input - [ -n "$_input" ] && _random="$_input" - case $_random in - [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - passwdtype="random" - break - ;; - esac - passwdtype="yes" - [ -n "$configflag" ] && break - trap 'stty echo; exit' 0 1 2 3 15 - stty -echo - echo -n "Enter password: " - read -r upass - echo'' - echo -n "Enter password again: " - read -r _passconfirm - echo '' - stty echo - # if user entered a blank password - # explicitly ask again. - [ -z "$upass" -a -z "$_passconfirm" ] \ - && continue - ;; - [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - passwdtype="none" - break; - ;; - *) - # invalid answer; repeat the loop - continue - ;; - esac - if [ "$upass" != "$_passconfirm" ]; then - echo "Passwords did not match!" - continue - fi - break - done - ;; - *) - # invalid answer; repeat loop - continue - ;; - esac - break; - done - _disable=${disableflag:-"no"} - while : ; do - echo -n "Lock out the account after creation? [$_disable]: " - read _input - [ -z "$_input" ] && _input=$_disable - case $_input in - [Nn][Oo]|[Nn]) - disableflag= - ;; - [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - disableflag=yes - ;; - *) - # invalid answer; repeat loop - continue - ;; - esac - break - done - - # Display the information we have so far and prompt to - # commit it. - # - _disable=${disableflag:-"no"} - [ -z "$configflag" ] && printf "%-10s : %s\n" Username $username - case $passwdtype in - yes) - _pass='*****' - ;; - no) - _pass='' - ;; - none) - _pass='' - ;; - random) - _pass='' - ;; - esac - [ -z "$configflag" ] && printf "%-10s : %s\n" "Password" "$_pass" - [ -n "$configflag" ] && printf "%-10s : %s\n" "Pass Type" "$passwdtype" - [ -z "$configflag" ] && printf "%-10s : %s\n" "Full Name" "$ugecos" - [ -z "$configflag" ] && printf "%-10s : %s\n" "Uid" "$uuid" - printf "%-10s : %s\n" "Class" "$uclass" - printf "%-10s : %s %s\n" "Groups" "${ulogingroup:-$username}" "$ugroups" - printf "%-10s : %s\n" "Home" "$uhome" - printf "%-10s : %s\n" "Home Mode" "$uhomeperm" - printf "%-10s : %s\n" "Shell" "$ushell" - printf "%-10s : %s\n" "Locked" "$_disable" - while : ; do - echo -n "OK? (yes/no): " - read _input - case $_input in - [Nn][Oo]|[Nn]) - return 1 - ;; - [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - add_user - ;; - *) - continue - ;; - esac - break - done - return 0 -} - -#### END SUBROUTINE DEFINITION #### - -THISCMD=`/usr/bin/basename $0` -DEFAULTSHELL=/bin/sh -ADDUSERCONF="${ADDUSERCONF:-/etc/adduser.conf}" -PWCMD="${PWCMD:-/usr/sbin/pw}" -MAILCMD="${MAILCMD:-mail}" -ETCSHELLS="${ETCSHELLS:-/etc/shells}" -NOHOME="/nonexistent" -NOLOGIN="nologin" -NOLOGIN_PATH="/usr/sbin/nologin" -GREPCMD="/usr/bin/grep" -DATECMD="/bin/date" - -# Set default values -# -username= -uuid= -uidstart= -ugecos= -ulogingroup= -uclass= -uhome= -uhomeperm= -upass= -ushell= -udotdir=/usr/share/skel -ugroups= -uexpire= -upwexpire= -shells="`valid_shells`" -passwdtype="yes" -msgfile=/etc/adduser.msg -msgflag= -quietflag= -configflag= -fflag= -infile= -disableflag= -Dflag= -Sflag= -readconfig="yes" -homeprefix="/home" -randompass= -fileline= -savedpwtype= -defaultclass= -defaultLgroup= -defaultgroups= -defaultshell="${DEFAULTSHELL}" -defaultHomePerm= - -# Make sure the user running this program is root. This isn't a security -# measure as much as it is a useful method of reminding the user to -# 'su -' before he/she wastes time entering data that won't be saved. -# -procowner=${procowner:-`/usr/bin/id -u`} -if [ "$procowner" != "0" ]; then - err 'you must be the super-user (uid 0) to use this utility.' - exit 1 -fi - -# Overide from our conf file -# Quickly go through the commandline line to see if we should read -# from our configuration file. The actual parsing of the commandline -# arguments happens after we read in our configuration file (commandline -# should override configuration file). -# -for _i in $* ; do - if [ "$_i" = "-N" ]; then - readconfig= - break; - fi -done -if [ -n "$readconfig" ]; then - # On a long-lived system, the first time this script is run it - # will barf upon reading the configuration file for its perl predecessor. - if ( . ${ADDUSERCONF} > /dev/null 2>&1 ); then - [ -r ${ADDUSERCONF} ] && . ${ADDUSERCONF} > /dev/null 2>&1 - fi -fi - -# Proccess command-line options -# -for _switch ; do - case $_switch in - -L) - defaultclass="$2" - shift; shift - ;; - -C) - configflag=yes - shift - ;; - -D) - Dflag=yes - shift - ;; - -E) - disableflag=yes - shift - ;; - -k) - udotdir="$2" - shift; shift - ;; - -f) - [ "$2" != "-" ] && infile="$2" - fflag=yes - shift; shift - ;; - -g) - defaultLgroup="$2" - shift; shift - ;; - -G) - defaultgroups="$2" - shift; shift - ;; - -h) - show_usage - exit 0 - ;; - -d) - homeprefix="$2" - shift; shift - ;; - -m) - case "$2" in - [Nn][Oo]) - msgflag= - ;; - *) - msgflag=yes - msgfile="$2" - ;; - esac - shift; shift - ;; - -M) - defaultHomePerm=$2 - shift; shift - ;; - -N) - readconfig= - shift - ;; - -w) - case "$2" in - no|none|random|yes) - passwdtype=$2 - ;; - *) - show_usage - exit 1 - ;; - esac - shift; shift - ;; - -q) - quietflag=yes - shift - ;; - -s) - defaultshell="`fullpath_from_shell $2`" - shift; shift - ;; - -S) - Sflag=yes - shift - ;; - -u) - uidstart=$2 - shift; shift - ;; - esac -done - -# If the -f switch was used, get input from a file. Otherwise, -# this is an interactive session. -# -if [ -n "$fflag" ]; then - if [ -z "$infile" ]; then - input_from_file - elif [ -n "$infile" ]; then - if [ -r "$infile" ]; then - input_from_file < $infile - else - err "File ($infile) is unreadable or does not exist." - fi - fi -else - input_interactive - while : ; do - if [ -z "$configflag" ]; then - echo -n "Add another user? (yes/no): " - else - echo -n "Re-edit the default configuration? (yes/no): " - fi - read _input - case $_input in - [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - uidstart=`get_nextuid $uidstart` - input_interactive - continue - ;; - [Nn][Oo]|[Nn]) - echo "Goodbye!" - ;; - *) - continue - ;; - esac - break - done -fi diff --git a/usr.sbin/adduser/rmuser.8 b/usr.sbin/adduser/rmuser.8 deleted file mode 100644 index 68a99b5..0000000 --- a/usr.sbin/adduser/rmuser.8 +++ /dev/null @@ -1,210 +0,0 @@ -.\" Copyright 1995, 1996, 1997 -.\" Guy Helmer, Ames, Iowa 50014. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer as -.\" the first lines of this file unmodified. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY GUY HELMER ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL GUY HELMER BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd May 10, 2002 -.Dt RMUSER 8 -.Os -.Sh NAME -.Nm rmuser -.Nd remove users from the system -.Sh SYNOPSIS -.Nm -.Op Fl yv -.Op Fl f Ar file -.Op Ar username ... -.Sh DESCRIPTION -The -.Nm -utility removes one or more users submitted on the command line -or from a file. -In removing a user from the system, this utility: -.Bl -enum -.It -Removes the user's -.Xr crontab 1 -entry (if any). -.It -Removes any -.Xr at 1 -jobs belonging to the user. -.It -Sends a -.Dv SIGKILL -signal to all processes owned by the user. -.It -Removes the user from the system's local password file. -.It -Removes the user's home directory (if it is owned by the user), -including handling of symbolic links in the path to the actual home -directory. -.It -Removes the incoming mail and POP daemon mail files belonging to the -user from -.Pa /var/mail . -.It -Removes all files owned by the user from -.Pa /tmp , /var/tmp , -and -.Pa /var/tmp/vi.recover . -.It -Removes the username from all groups to which it belongs in -.Pa /etc/group . -(If a group becomes empty and the group name is the same as the username, -the group is removed; this complements -.Xr adduser 8 Ns 's -per-user unique groups.) -.It -Removes all message queues, shared memory segments and -semaphores owned by the user. -.El -.Pp -The -.Nm -utility refuses to remove users whose UID is 0 (typically root), since -certain actions (namely, killing all the user's processes, and perhaps -removing the user's home directory) would cause damage to a running system. -If it is necessary to remove a user whose UID is 0, see -.Xr vipw 8 -for information on directly editing the password file. -.Pp -If -.Nm -was not invoked with the -.Fl y -option, it will -show the selected user's password file entry and ask for confirmation -that the user be removed. -It will then ask for confirmation to delete -the user's home directory. -If the answer is in the affirmative, the home -directory and any files and subdirectories under it will be deleted only if -they are owned by the user. -See -.Xr pw 8 -for more details. -.Pp -As -.Nm -operates, it informs the user regarding the current activity. -If any -errors occur, they are posted to standard error and, if it is possible for -.Nm -to continue, it will. -.Pp -The options are as follows: -.Bl -tag -width ".Ar username" -.It Fl f Ar file -The -.Nm -utility will get a list of users to be removed from -.Ar file , -which will contain one user per line. -Anything following a hash mark -.Pq Ql # , -including the hash mark itself, is considered a comment and will not -be processed. -If the file is owned by anyone other than a user with -UID 0, or is writable by anyone other than the owner, -.Nm -will refuse to continue. -.It Fl y -Implicitly answer -.Dq Li yes -to any and all prompts. -Currently, this includes -prompts on whether to remove the specified user and whether to remove -the home directory. -This option requires that either the -.Fl f -option be used, or one or more user names be given as command line -arguments. -.It Fl v -Enable verbose mode. -Normally, -the output includes one line per removed user; -however, -with this option -.Nm -will be much more chatty about the steps taken. -.It Ar username -Identifies one or more users to be removed; if not present, -.Nm -interactively asks for one or more users to be removed. -.El -.Sh FILES -.Bl -tag -compact -.It Pa /etc/master.passwd -.It Pa /etc/passwd -.It Pa /etc/group -.It Pa /etc/spwd.db -.It Pa /etc/pwd.db -.El -.Sh SEE ALSO -.Xr at 1 , -.Xr chpass 1 , -.Xr crontab 1 , -.Xr finger 1 , -.Xr passwd 1 , -.Xr group 5 , -.Xr passwd 5 , -.Xr adduser 8 , -.Xr pw 8 , -.Xr pwd_mkdb 8 , -.Xr vipw 8 -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 2.2 . -.Sh BUGS -The -.Nm -utility does not comprehensively search the file system for all files -owned by the removed user and remove them; to do so on a system -of any size is prohibitively slow and I/O intensive. -It is also unable to remove symbolic links that were created by the -user in -.Pa /tmp -or -.Pa /var/tmp , -as symbolic links on -.Bx 4.4 -file systems do not contain information -as to who created them. -Also, there may be other files created in -.Pa /var/mail -other than -.Pa /var/mail/ Ns Ar username -and -.Pa /var/mail/.pop. Ns Ar username -that are not owned by the removed user but should be removed. -.Pp -The -.Nm -utility has no knowledge of YP/NIS, and it operates only on the -local password file. diff --git a/usr.sbin/adduser/rmuser.sh b/usr.sbin/adduser/rmuser.sh deleted file mode 100644 index 6b09225..0000000 --- a/usr.sbin/adduser/rmuser.sh +++ /dev/null @@ -1,361 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2002, 2003 Michael Telahun Makonnen. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# Email: Mike Makonnen -# -# $FreeBSD$ -# - -ATJOBDIR="/var/at/jobs" -CRONJOBDIR="/var/cron/tabs" -MAILSPOOL="/var/mail" -SIGKILL="-KILL" -TEMPDIRS="/tmp /var/tmp" -THISCMD=`/usr/bin/basename $0` -PWCMD="${PWCMD:-/usr/sbin/pw}" - -# err msg -# Display $msg on stderr. -# -err() { - echo 1>&2 ${THISCMD}: $* -} - -# verbose -# Returns 0 if verbose mode is set, 1 if it is not. -# -verbose() { - [ -n "$vflag" ] && return 0 || return 1 -} - -# rm_files login -# Removes files or empty directories belonging to $login from various -# temporary directories. -# -rm_files() { - # The argument is required - [ -n $1 ] && login=$1 || return - - totalcount=0 - for _dir in ${TEMPDIRS} ; do - filecount=0 - if [ ! -d $_dir ]; then - err "$_dir is not a valid directory." - continue - fi - verbose && echo -n "Removing files owned by ($login) in $_dir:" - filecount=`find 2>/dev/null "$_dir" -user "$login" -delete -print | - wc -l | sed 's/ *//'` - verbose && echo " $filecount removed." - totalcount=$(($totalcount + $filecount)) - done - ! verbose && [ $totalcount -ne 0 ] && echo -n " files($totalcount)" -} - -# rm_mail login -# Removes unix mail and pop daemon files belonging to the user -# specified in the $login argument. -# -rm_mail() { - # The argument is required - [ -n $1 ] && login=$1 || return - - verbose && echo -n "Removing mail spool(s) for ($login):" - if [ -f ${MAILSPOOL}/$login ]; then - verbose && echo -n " ${MAILSPOOL}/$login" || - echo -n " mailspool" - rm ${MAILSPOOL}/$login - fi - if [ -f ${MAILSPOOL}/.${login}.pop ]; then - verbose && echo -n " ${MAILSPOOL}/.${login}.pop" || - echo -n " pop3" - rm ${MAILSPOOL}/.${login}.pop - fi - verbose && echo '.' -} - -# kill_procs login -# Send a SIGKILL to all processes owned by $login. -# -kill_procs() { - # The argument is required - [ -n $1 ] && login=$1 || return - - verbose && echo -n "Terminating all processes owned by ($login):" - killcount=0 - proclist=`ps 2>/dev/null -U $login | grep -v '^\ *PID' | awk '{print $1}'` - for _pid in $proclist ; do - kill 2>/dev/null ${SIGKILL} $_pid - killcount=$(($killcount + 1)) - done - verbose && echo " ${SIGKILL} signal sent to $killcount processes." - ! verbose && [ $killcount -ne 0 ] && echo -n " processes(${killcount})" -} - -# rm_at_jobs login -# Remove at (1) jobs belonging to $login. -# -rm_at_jobs() { - # The argument is required - [ -n $1 ] && login=$1 || return - - atjoblist=`find 2>/dev/null ${ATJOBDIR} -maxdepth 1 -user $login -print` - jobcount=0 - verbose && echo -n "Removing at(1) jobs owned by ($login):" - for _atjob in $atjoblist ; do - rm -f $_atjob - jobcount=$(($jobcount + 1)) - done - verbose && echo " $jobcount removed." - ! verbose && [ $jobcount -ne 0 ] && echo -n " at($jobcount)" -} - -# rm_crontab login -# Removes crontab file belonging to user $login. -# -rm_crontab() { - # The argument is required - [ -n $1 ] && login=$1 || return - - verbose && echo -n "Removing crontab for ($login):" - if [ -f ${CRONJOBDIR}/$login ]; then - verbose && echo -n " ${CRONJOBDIR}/$login" || echo -n " crontab" - rm -f ${CRONJOBDIR}/$login - fi - verbose && echo '.' -} - -# rm_ipc login -# Remove all IPC mechanisms which are owned by $login. -# -rm_ipc() { - verbose && echo -n "Removing IPC mechanisms" - for i in s m q; do - ipcs -$i | - awk -v i=$i -v login=$1 '$1 == i && $5 == login { print $2 }' | - xargs -n 1 ipcrm -$i - done - verbose && echo '.' -} - -# rm_user login -# Remove user $login from the system. This subroutine makes use -# of the pw(8) command to remove a user from the system. The pw(8) -# command will remove the specified user from the user database -# and group file and remove any crontabs. His home -# directory will be removed if it is owned by him and contains no -# files or subdirectories owned by other users. Mail spool files will -# also be removed. -# -rm_user() { - # The argument is required - [ -n $1 ] && login=$1 || return - - verbose && echo -n "Removing user ($login)" - [ -n "$pw_rswitch" ] && { - verbose && echo -n " (including home directory)" - ! verbose && echo -n " home" - } - ! verbose && echo -n " passwd" - verbose && echo -n " from the system:" - ${PWCMD} userdel -n $login $pw_rswitch - verbose && echo ' Done.' -} - -# prompt_yesno msg -# Prompts the user with a $msg. The answer is expected to be -# yes, no, or some variation thereof. This subroutine returns 0 -# if the answer was yes, 1 if it was not. -# -prompt_yesno() { - # The argument is required - [ -n "$1" ] && msg="$1" || return - - while : ; do - echo -n "$msg" - read _ans - case $_ans in - [Nn][Oo]|[Nn]) - return 1 - ;; - [Yy][Ee][Ss]|[Yy][Ee]|[Yy]) - return 0 - ;; - *) - ;; - esac - done -} - -# show_usage -# (no arguments) -# Display usage message. -# -show_usage() { - echo "usage: ${THISCMD} [-yv] [-f file] [user ...]" - echo " if the -y switch is used, either the -f switch or" - echo " one or more user names must be given" -} - -#### END SUBROUTINE DEFENITION #### - -ffile= -fflag= -procowner= -pw_rswitch= -userlist= -yflag= -vflag= - -procowner=`/usr/bin/id -u` -if [ "$procowner" != "0" ]; then - err 'you must be root (0) to use this utility.' - exit 1 -fi - -args=`getopt 2>/dev/null yvf: $*` -if [ "$?" != "0" ]; then - show_usage - exit 1 -fi -set -- $args -for _switch ; do - case $_switch in - -y) - yflag=1 - shift - ;; - -v) - vflag=1 - shift - ;; - -f) - fflag=1 - ffile="$2" - shift; shift - ;; - --) - shift - break - ;; - esac -done - -# Get user names from a file if the -f switch was used. Otherwise, -# get them from the commandline arguments. If we're getting it -# from a file, the file must be owned by and writable only by root. -# -if [ $fflag ]; then - _insecure=`find $ffile ! -user 0 -or -perm +0022` - if [ -n "$_insecure" ]; then - err "file ($ffile) must be owned by and writeable only by root." - exit 1 - fi - if [ -r "$ffile" ]; then - userlist=`cat $ffile | while read _user _junk ; do - case $_user in - \#*|'') - ;; - *) - echo -n "$userlist $_user" - ;; - esac - done` - fi -else - while [ $1 ] ; do - userlist="$userlist $1" - shift - done -fi - -# If the -y or -f switch has been used and the list of users to remove -# is empty it is a fatal error. Otherwise, prompt the user for a list -# of one or more user names. -# -if [ ! "$userlist" ]; then - if [ $fflag ]; then - err "($ffile) does not exist or does not contain any user names." - exit 1 - elif [ $yflag ]; then - show_usage - exit 1 - else - echo -n "Please enter one or more usernames: " - read userlist - fi -fi - -_user= -_uid= -for _user in $userlist ; do - # Make sure the name exists in the passwd database and that it - # does not have a uid of 0 - # - userrec=`pw 2>/dev/null usershow -n $_user` - if [ "$?" != "0" ]; then - err "user ($_user) does not exist in the password database." - continue - fi - _uid=`echo $userrec | awk -F: '{print $3}'` - if [ "$_uid" = "0" ]; then - err "user ($_user) has uid 0. You may not remove this user." - continue - fi - - # If the -y switch was not used ask for confirmation to remove the - # user and home directory. - # - if [ -z "$yflag" ]; then - echo "Matching password entry:" - echo - echo $userrec - echo - if ! prompt_yesno "Is this the entry you wish to remove? " ; then - continue - fi - _homedir=`echo $userrec | awk -F: '{print $9}'` - if prompt_yesno "Remove user's home directory ($_homedir)? "; then - pw_rswitch="-r" - fi - else - pw_rswitch="-r" - fi - - # Disable any further attempts to log into this account - ${PWCMD} 2>/dev/null lock $_user - - # Remove crontab, mail spool, etc. Then obliterate the user from - # the passwd and group database. - # - ! verbose && echo -n "Removing user ($_user):" - rm_crontab $_user - rm_at_jobs $_user - rm_ipc $_user - kill_procs $_user - rm_files $_user - rm_mail $_user - rm_user $_user - ! verbose && echo "." -done diff --git a/usr.sbin/amd/Makefile b/usr.sbin/amd/Makefile deleted file mode 100644 index 37e4200..0000000 --- a/usr.sbin/amd/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -SUBDIR= include libamu amd amq doc fixmount fsinfo hlfsd mk-amd-map pawd \ - scripts wire-test - -.include diff --git a/usr.sbin/amd/Makefile.inc b/usr.sbin/amd/Makefile.inc deleted file mode 100644 index 1965ff9..0000000 --- a/usr.sbin/amd/Makefile.inc +++ /dev/null @@ -1,47 +0,0 @@ -# ex:ts=8 -# -# $FreeBSD$ -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998. -# Portions derived from -# $NetBSD: Makefile.inc,v 1.10 1998/08/08 22:33:27 christos Exp $ -# Portions derived from amd/libamu/Makefile -# $NetBSD: Makefile,v 1.8 1998/08/08 22:33:37 christos Exp $ - -.include - -CFLAGS+= -I. -I${.CURDIR} -CFLAGS+= -I${.CURDIR}/../include -.if exists(${.OBJDIR}/../include) -CFLAGS+= -I${.OBJDIR}/../include -.endif -CFLAGS+= -I${.CURDIR}/../../../contrib/amd/include -CFLAGS+= -I${.CURDIR}/../../../contrib/amd -CFLAGS+= -DHAVE_CONFIG_H -.if ${MK_NIS} == "no" -CFLAGS+= -DHAVE_LOCALCONFIG_H -.endif - -.if ${MK_HESIOD} != "no" -CFLAGS+= -DYES_HESIOD -.endif - -CFLAGS+= -DHOST_CPU=\"${MACHINE_CPUARCH}\" -DHOST_ARCH=\"${MACHINE_ARCH}\" - -.if exists(${.OBJDIR}/../libamu) -LIBAMUDIR= ${.OBJDIR}/../libamu -.else -LIBAMUDIR= ${.CURDIR}/../libamu -.endif -LIBAMU= ${LIBAMUDIR}/libamu.a - -RPCCOM= rpcgen -MOUNT_X= ${DESTDIR}/usr/include/rpcsvc/mount.x -NFS_PROT_X= ${DESTDIR}/usr/include/rpcsvc/nfs_prot.x - -WARNS?= 1 - -.if exists(${.CURDIR}/../../Makefile.inc) -.include "${.CURDIR}/../../Makefile.inc" -.endif diff --git a/usr.sbin/amd/NOTES b/usr.sbin/amd/NOTES deleted file mode 100644 index b04244b..0000000 --- a/usr.sbin/amd/NOTES +++ /dev/null @@ -1,3 +0,0 @@ -amd/amd supports HESIOD, LDAP, and NIS+ which we don't presently. -If they are added to FreeBSD, add info_hesiod.c, info_ldap.c, info_nisplus.c -to amd/amd's Makefile. diff --git a/usr.sbin/amd/amd/Makefile b/usr.sbin/amd/amd/Makefile deleted file mode 100644 index c720003..0000000 --- a/usr.sbin/amd/amd/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ -# - -.include - -.PATH: ${.CURDIR}/../../../contrib/amd/amd - -PROG= amd -MAN= amd.8 -SRCS= conf_parse.y conf_tok.l -SRCS+= am_ops.c amd.c amfs_auto.c amfs_direct.c amfs_error.c amfs_generic.c -SRCS+= amfs_host.c amfs_link.c amfs_linkx.c amfs_nfsl.c -SRCS+= amfs_nfsx.c amfs_program.c amfs_root.c amfs_toplvl.c -SRCS+= amfs_union.c amq_subr.c amq_svc.c autil.c clock.c conf.c -SRCS+= get_args.c info_exec.c info_file.c info_ndbm.c info_passwd.c -SRCS+= info_union.c map.c mapc.c mntfs.c nfs_prot_svc.c nfs_start.c -SRCS+= nfs_subr.c ops_cdfs.c ops_mfs.c ops_nfs.c ops_nfs3.c -SRCS+= ops_nullfs.c ops_pcfs.c ops_tfs.c ops_ufs.c ops_umapfs.c -SRCS+= ops_unionfs.c opts.c readdir.c restart.c rpc_fwd.c sched.c -SRCS+= srvr_amfs_auto.c srvr_nfs.c - -CFLAGS+= -I${.CURDIR}/../../../contrib/amd/amd \ - -I${DESTDIR}/usr/include/rpcsvc - -DPADD= ${LIBAMU} ${LIBWRAP} -LDADD= ${LIBAMU} -lwrap - -CLEANFILES+= conf_parse.c conf_parse.h conf_tok.c - -conf_tok.o: conf_parse.h - -# These are generated at compile time -SRCS+= mount_xdr.c -CLEANFILES+= mount_xdr.c - -mount_xdr.c: ${MOUNT_X} - ${RPCCOM} -c -DWANT_NFS3 ${MOUNT_X} -o ${.TARGET} - -.if ${MK_HESIOD} != "no" -SRCS+= info_hesiod.c -CFLAGS+= -DHAVE_MAP_HESIOD -.endif - -.if ${MK_NIS} != "no" -SRCS+= info_nis.c -.endif - -.include diff --git a/usr.sbin/amd/amq/Makefile b/usr.sbin/amd/amq/Makefile deleted file mode 100644 index 74fc749..0000000 --- a/usr.sbin/amd/amq/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ -# - -.PATH: ${.CURDIR}/../../../contrib/amd/amq - -PROG= amq -MAN= amq.8 -SRCS= amq.c amq_clnt.c amq_xdr.c - -CFLAGS+= -I${.CURDIR}/../../../contrib/amd/amq - -DPADD= ${LIBAMU} -LDADD= ${LIBAMU} - -.include diff --git a/usr.sbin/amd/doc/Makefile b/usr.sbin/amd/doc/Makefile deleted file mode 100644 index e9c7707..0000000 --- a/usr.sbin/amd/doc/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# This file is under a "BSD" copyright (c) by David O'Brien 1998. - -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/doc - -INFO= am-utils - -INFOSECTION= "AMD Documentation" -INFOENTRY= "* Am-utils: (am-utils). The Amd automounter suite of utilities" - -MAKEINFOFLAGS+= -I ${.CURDIR}/../../../contrib/amd/doc - -.include diff --git a/usr.sbin/amd/fixmount/Makefile b/usr.sbin/amd/fixmount/Makefile deleted file mode 100644 index 7f96a45..0000000 --- a/usr.sbin/amd/fixmount/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/fixmount \ - ${.CURDIR}/../../../contrib/amd/conf/checkmount - -PROG= fixmount -MAN= fixmount.8 -SRCS= fixmount.c - -# These would be links created by the GNU-style configure -SRCS+= checkmount_bsd44.c - -DPADD= ${LIBAMU} ${LIBRPCSVC} -LDADD= ${LIBAMU} -lrpcsvc - -.include diff --git a/usr.sbin/amd/fsinfo/Makefile b/usr.sbin/amd/fsinfo/Makefile deleted file mode 100644 index 1695a46..0000000 --- a/usr.sbin/amd/fsinfo/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/fsinfo - -PROG= fsinfo -MAN= fsinfo.8 -SRCS= fsi_gram.y fsi_lex.l -SRCS+= fsi_analyze.c fsi_dict.c fsi_util.c fsinfo.c wr_atab.c -SRCS+= wr_bparam.c wr_dumpset.c wr_exportfs.c wr_fstab.c - -CFLAGS+= -I${.CURDIR}/../../../contrib/amd/fsinfo - -DPADD= ${LIBAMU} -LDADD= ${LIBAMU} - -CLEANFILES+= fsi_gram.c fsi_gram.h fsi_lex.c - -fsi_lex.o: fsi_gram.h - -.include diff --git a/usr.sbin/amd/hlfsd/Makefile b/usr.sbin/amd/hlfsd/Makefile deleted file mode 100644 index 5b863dd..0000000 --- a/usr.sbin/amd/hlfsd/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/hlfsd - -PROG= hlfsd -MAN= hlfsd.8 -SRCS= hlfsd.c homedir.c nfs_prot_svc.c stubs.c - -CFLAGS+= -I${.CURDIR}/../../../contrib/amd/hlfsd - -DPADD= ${LIBAMU} -LDADD= ${LIBAMU} - -.include diff --git a/usr.sbin/amd/include/Makefile b/usr.sbin/amd/include/Makefile deleted file mode 100644 index df770d1..0000000 --- a/usr.sbin/amd/include/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# ex:ts=8 -# -# $FreeBSD$ -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998. -# Portions derived from amd/libamu/Makefile -# $NetBSD: Makefile,v 1.8 1998/08/08 22:33:37 christos Exp $ - -.include - -SRCS= config_local.h -.if ${MK_NIS} == "no" -SRCS+= localconfig.h -.endif -CLEANFILES= ${SRCS} - -all depend: ${SRCS} - -config_local.h: newvers.sh - @rm -f ${.TARGET} - sh ${.ALLSRC} ${.CURDIR}/../../../sys/conf/newvers.sh > ${.TARGET} - -localconfig.h: - @rm -f ${.TARGET} - @echo "/* NIS disabled by WITHOUT_NIS src.conf option */" >> ${.TARGET} - @echo "#undef HAVE_MAP_NIS" >> ${.TARGET} - -.include diff --git a/usr.sbin/amd/include/amu_autofs_prot.h b/usr.sbin/amd/include/amu_autofs_prot.h deleted file mode 100644 index 12f5b95..0000000 --- a/usr.sbin/amd/include/amu_autofs_prot.h +++ /dev/null @@ -1,8 +0,0 @@ -// $FreeBSD$ - -/* Adjust once we have some form of Autofs support. */ - -#if 0 -#include "conf/autofs/autofs_default.h" -#endif - diff --git a/usr.sbin/amd/include/amu_nfs_prot.h b/usr.sbin/amd/include/amu_nfs_prot.h deleted file mode 100644 index 8e8856f..0000000 --- a/usr.sbin/amd/include/amu_nfs_prot.h +++ /dev/null @@ -1 +0,0 @@ -#include "conf/nfs_prot/nfs_prot_freebsd3.h" diff --git a/usr.sbin/amd/include/aux_conf.h b/usr.sbin/amd/include/aux_conf.h deleted file mode 100644 index 1529ba3..0000000 --- a/usr.sbin/amd/include/aux_conf.h +++ /dev/null @@ -1,72 +0,0 @@ -/* $FreeBSD$ */ - -/* - * aux_conf.h: - * This file gets "filled in" for each architecture. - * aux_conf.h. Generated from aux_conf.h.in by configure. - */ - -#ifndef _AUX_CONF_H -#define _AUX_CONF_H - -/* - * The next line is a literal inclusion of a file which includes a - * definition for the MOUNT_TRAP macro for a particular architecture. - * If it defines the wrong entry, check the AC_CHECK_MOUNT_TRAP m4 macro - * in $srcdir/m4/macros. - */ - -/* $srcdir/conf/trap/trap_default.h */ -#define MOUNT_TRAP(type, mnt, flags, mnt_data) mount(type, mnt->mnt_dir, flags, mnt_data) -/* End of included MOUNT_TRAP macro definition file */ - -/* - * The next line is a literal replacement of a variable which defines the - * the UNMOUNT_TRAP macro for a particular architecture. - * If it defines the wrong entry, check the AC_CHECK_UNMOUNT_CALL m4 macro - * in $srcdir/aclocal.m4. If the arguments are being defined wrong, check - * the macro AC_CHECK_UNMOUNT_ARGS in $srcdir/m4/macros. - */ -#define UNMOUNT_TRAP(mnt) unmount(mnt->mnt_dir) -/* End of replaced UNMOUNT_TRAP macro definition */ -/* umount(8) executable path, for type:=program */ -#define UNMOUNT_PROGRAM "/sbin/umount" - -/* - * The next line is a literal inclusion of a file which includes a - * definition for the NFS_FH_DREF macro for a particular architecture. - * If it defines the wrong entry, check the AC_CHECK_NFS_FH_DREF m4 macro - * in $srcdir/m4/macros. - */ - -/* $srcdir/conf/fh_dref/fh_dref_freebsd22.h */ -#define NFS_FH_DREF(dst, src) (dst) = (u_char *) (src) -/* End of included NFS_FH_DREF macro definition file */ - -/* - * The next line is a literal inclusion of a file which includes a - * definition for the NFS_SA_DREF macro for a particular architecture. - * If it defines the wrong entry, check the AC_CHECK_NFS_SA_DREF m4 macro - * in $srcdir/m4/macros. - */ - -/* $srcdir/conf/sa_dref/sa_dref_bsd44.h */ -#define NFS_SA_DREF(dst, src) { \ - (dst)->addr = (struct sockaddr *) (src); \ - (dst)->addrlen = sizeof(*src); \ - } -#define NFS_ARGS_T_ADDR_IS_POINTER 1 -/* End of included NFS_SA_DREF macro definition file */ - -/* - * The next line is a literal inclusion of a file which includes a - * definition for the NFS_HN_DREF macro for a particular architecture. - * If it defines the wrong entry, check the AC_CHECK_NFS_HN_DREF m4 macro - * in $srcdir/m4/macros. - */ - -/* $srcdir/conf/hn_dref/hn_dref_default.h */ -#define NFS_HN_DREF(dst, src) (dst) = (src) -/* End of included NFS_HN_DREF macro definition file */ - -#endif /* not _AUX_CONF_H */ diff --git a/usr.sbin/amd/include/build_version.h b/usr.sbin/amd/include/build_version.h deleted file mode 100644 index 09eb1fc..0000000 --- a/usr.sbin/amd/include/build_version.h +++ /dev/null @@ -1,8 +0,0 @@ -/* $FreeBSD$ */ - -#include -/*#define AMU_BUILD_VERSION 1 */ -#define AMU_BUILD_VERSION __FreeBSD_version -#define USER_NAME "David O'Brien " -#define CONFIG_DATE "4-December-2007 PST" diff --git a/usr.sbin/amd/include/config.h b/usr.sbin/amd/include/config.h deleted file mode 100644 index 5817a46..0000000 --- a/usr.sbin/amd/include/config.h +++ /dev/null @@ -1,2205 +0,0 @@ -/* - * $FreeBSD$ - * - * portions derived from - * $NetBSD: config.h,v 1.11 1998/08/08 22:33:37 christos Exp $ - */ - -#ifndef _CONFIG_H -#define _CONFIG_H - -/* We [FREEBSD-NATIVE] pick some parameters from our local config file */ -#include "config_local.h" - -/* define name of am-utils' NFS protocol header */ -#define AMU_NFS_PROTOCOL_HEADER "./conf/nfs_prot/nfs_prot_freebsd3.h" - -/* Type of the 5rd argument to authunix_create() */ -#define AUTH_CREATE_GIDLIST_TYPE gid_t - -/* Define configuration date */ -/* #define CONFIG_DATE "Tue Dec 4 21:39:00 PST 2007" */ - -/* Turn off general debugging by default */ -/* #undef DEBUG */ - -/* Turn off memory debugging by default */ -/* #undef DEBUG_MEM */ - -/* Define name of host OS's distribution name (eg. debian, redhat, suse, etc.) - */ -#define DISTRO_NAME "The FreeBSD Project" - -/* Define to the type of elements in the array set by `getgroups'. Usually - this is either `int' or `gid_t'. */ -#define GETGROUPS_T gid_t - -/* Define to 1 if the `getpgrp' function requires zero arguments. */ -#define GETPGRP_VOID 1 - -/* Define if have automount filesystem */ -#define HAVE_AMU_FS_AUTO 1 - -/* Define if have direct automount filesystem */ -#define HAVE_AMU_FS_DIRECT 1 - -/* Define if have error filesystem */ -#define HAVE_AMU_FS_ERROR 1 - -/* Define if have NFS host-tree filesystem */ -#define HAVE_AMU_FS_HOST 1 - -/* Define if have symbolic-link filesystem */ -#define HAVE_AMU_FS_LINK 1 - -/* Define if have symlink with existence check filesystem */ -#define HAVE_AMU_FS_LINKX 1 - -/* Define if have nfsl (NFS with local link check) filesystem */ -#define HAVE_AMU_FS_NFSL 1 - -/* Define if have multi-NFS filesystem */ -#define HAVE_AMU_FS_NFSX 1 - -/* Define if have program filesystem */ -#define HAVE_AMU_FS_PROGRAM 1 - -/* Define if have "top-level" filesystem */ -#define HAVE_AMU_FS_TOPLVL 1 - -/* Define if have union filesystem */ -#define HAVE_AMU_FS_UNION 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_ARPA_INET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_ARPA_NAMESER_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_ASSERT_H 1 - -/* Define to 1 if `addr' is member of `autofs_args_t'. */ -/* #undef HAVE_AUTOFS_ARGS_T_ADDR */ - -/* define if have a bad version of hasmntopt() */ -/* #undef HAVE_BAD_HASMNTOPT */ - -/* define if have a bad version of memcmp() */ -/* #undef HAVE_BAD_MEMCMP */ - -/* define if have a bad version of yp_all() */ -/* #undef HAVE_BAD_YP_ALL */ - -/* Define to 1 if you have the `bcmp' function. */ -#define HAVE_BCMP 1 - -/* Define to 1 if you have the `bcopy' function. */ -#define HAVE_BCOPY 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_BSD_RPC_RPC_H */ - -/* Define to 1 if you have the `bzero' function. */ -#define HAVE_BZERO 1 - -/* System supports C99-style variable-length argument macros */ -#define HAVE_C99_VARARGS_MACROS 1 - -/* Define to 1 if `flags' is member of `cdfs_args_t'. */ -#define HAVE_CDFS_ARGS_T_FLAGS 1 - -/* Define to 1 if `fspec' is member of `cdfs_args_t'. */ -#define HAVE_CDFS_ARGS_T_FSPEC 1 - -/* Define to 1 if `iso_flags' is member of `cdfs_args_t'. */ -/* #undef HAVE_CDFS_ARGS_T_ISO_FLAGS */ - -/* Define to 1 if `iso_pgthresh' is member of `cdfs_args_t'. */ -/* #undef HAVE_CDFS_ARGS_T_ISO_PGTHRESH */ - -/* Define to 1 if `norrip' is member of `cdfs_args_t'. */ -/* #undef HAVE_CDFS_ARGS_T_NORRIP */ - -/* Define to 1 if `ssector' is member of `cdfs_args_t'. */ -#define HAVE_CDFS_ARGS_T_SSECTOR 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_CDFS_CDFSMOUNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_CDFS_CDFS_MOUNT_H */ - -/* Define to 1 if you have the `clnt_create' function. */ -#define HAVE_CLNT_CREATE 1 - -/* Define to 1 if you have the `clnt_create_vers' function. */ -#define HAVE_CLNT_CREATE_VERS 1 - -/* Define to 1 if you have the `clnt_create_vers_timed' function. */ -#define HAVE_CLNT_CREATE_VERS_TIMED 1 - -/* Define to 1 if you have the `clnt_spcreateerror' function. */ -#define HAVE_CLNT_SPCREATEERROR 1 - -/* Define to 1 if you have the `clnt_sperrno' function. */ -#define HAVE_CLNT_SPERRNO 1 - -/* Define to 1 if you have the `clock_gettime' function. */ -#define HAVE_CLOCK_GETTIME 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_CLUSTER_H */ - -/* Define to 1 if you have the `cnodeid' function. */ -/* #undef HAVE_CNODEID */ - -/* Define to 1 if you have the header file. */ -#define HAVE_CTYPE_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_DB1_NDBM_H */ - -/* Define to 1 if you have the `dbm_open' function. */ -#define HAVE_DBM_OPEN 1 - -/* Define to 1 if you have the `dg_mount' function. */ -/* #undef HAVE_DG_MOUNT */ - -/* Define to 1 if you have the header file, and it defines `DIR'. - */ -#define HAVE_DIRENT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Define to 1 if `flags' is member of `efs_args_t'. */ -/* #undef HAVE_EFS_ARGS_T_FLAGS */ - -/* Define to 1 if `fspec' is member of `efs_args_t'. */ -/* #undef HAVE_EFS_ARGS_T_FSPEC */ - -/* Define to 1 if you have the header file. */ -#define HAVE_ERRNO_H 1 - -/* does extern definition for clnt_spcreateerror() exist? */ -#define HAVE_EXTERN_CLNT_SPCREATEERROR 1 - -/* does extern definition for clnt_sperrno() exist? */ -#define HAVE_EXTERN_CLNT_SPERRNO 1 - -/* does extern definition for free() exist? */ -#define HAVE_EXTERN_FREE 1 - -/* does extern definition for getccent() (hpux) exist? */ -/* #undef HAVE_EXTERN_GETCCENT */ - -/* does extern definition for getdomainname() exist? */ -#define HAVE_EXTERN_GETDOMAINNAME 1 - -/* does extern definition for getdtablesize() exist? */ -#define HAVE_EXTERN_GETDTABLESIZE 1 - -/* does extern definition for gethostname() exist? */ -#define HAVE_EXTERN_GETHOSTNAME 1 - -/* does extern definition for getlogin() exist? */ -#define HAVE_EXTERN_GETLOGIN 1 - -/* does extern definition for getpagesize() exist? */ -#define HAVE_EXTERN_GETPAGESIZE 1 - -/* does extern definition for gettablesize() exist? */ -/* #undef HAVE_EXTERN_GETTABLESIZE */ - -/* does extern definition for getwd() exist? */ -#define HAVE_EXTERN_GETWD 1 - -/* does extern definition for get_myaddress() exist? */ -#define HAVE_EXTERN_GET_MYADDRESS 1 - -/* does extern definition for hosts_ctl() exist? */ -/* #undef HAVE_EXTERN_HOSTS_CTL */ - -/* does extern definition for innetgr() exist? */ -#define HAVE_EXTERN_INNETGR 1 - -/* does extern definition for ldap_enable_cache() exist? */ -/* #undef HAVE_EXTERN_LDAP_ENABLE_CACHE */ - -/* does extern definition for mkstemp() exist? */ -#define HAVE_EXTERN_MKSTEMP 1 - -/* does extern definition for mntctl() exist? */ -/* #undef HAVE_EXTERN_MNTCTL */ - -/* does extern definition for optarg exist? */ -#define HAVE_EXTERN_OPTARG 1 - -/* does extern definition for sbrk() exist? */ -#define HAVE_EXTERN_SBRK 1 - -/* does extern definition for seteuid() exist? */ -#define HAVE_EXTERN_SETEUID 1 - -/* does extern definition for setitimer() exist? */ -#define HAVE_EXTERN_SETITIMER 1 - -/* does extern definition for sleep() exist? */ -#define HAVE_EXTERN_SLEEP 1 - -/* does extern definition for strcasecmp() exist? */ -#define HAVE_EXTERN_STRCASECMP 1 - -/* does extern definition for strdup() exist? */ -#define HAVE_EXTERN_STRDUP 1 - -/* does extern definition for strlcat() exist? */ -#define HAVE_EXTERN_STRLCAT 1 - -/* does extern definition for strlcpy() exist? */ -#define HAVE_EXTERN_STRLCPY 1 - -/* does extern definition for strstr() exist? */ -#define HAVE_EXTERN_STRSTR 1 - -/* does extern definition for sys_errlist[] exist? */ -#define HAVE_EXTERN_SYS_ERRLIST 1 - -/* does extern definition for ualarm() exist? */ -#define HAVE_EXTERN_UALARM 1 - -/* does extern definition for usleep() exist? */ -#define HAVE_EXTERN_USLEEP 1 - -/* does extern definition for vsnprintf() exist? */ -#define HAVE_EXTERN_VSNPRINTF 1 - -/* does extern definition for wait3() exist? */ -#define HAVE_EXTERN_WAIT3 1 - -/* does extern definition for xdr_callmsg() exist? */ -#define HAVE_EXTERN_XDR_CALLMSG 1 - -/* does extern definition for xdr_opaque_auth() exist? */ -#define HAVE_EXTERN_XDR_OPAQUE_AUTH 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_FCNTL_H 1 - -/* Define to 1 if `fds_bits' is member of `fd_set'. */ -#define HAVE_FD_SET_FDS_BITS 1 - -/* Define to 1 if you have the `fgets' function. */ -#define HAVE_FGETS 1 - -/* Define if plain fhandle type exists */ -#define HAVE_FHANDLE 1 - -/* Define to 1 if you have the `flock' function. */ -#define HAVE_FLOCK 1 - -/* Define to 1 if you have the `fork' function. */ -#define HAVE_FORK 1 - -/* Define to 1 if you have the `fsmount' function. */ -/* #undef HAVE_FSMOUNT */ - -/* Define if have AUTOFS filesystem */ -/* #undef HAVE_FS_AUTOFS */ - -/* Define if have CACHEFS filesystem */ -/* #undef HAVE_FS_CACHEFS */ - -/* Define if have CDFS filesystem */ -#define HAVE_FS_CDFS 1 - -/* Define if have CFS (crypto) filesystem */ -/* #undef HAVE_FS_CFS */ - -/* Define if have EFS filesystem (irix) */ -/* #undef HAVE_FS_EFS */ - -/* Define if have FFS filesystem */ -/* #undef HAVE_FS_FFS */ - -/* Define if have HSFS filesystem */ -/* #undef HAVE_FS_HSFS */ - -/* Define if have LOFS filesystem */ -/* #undef HAVE_FS_LOFS */ - -/* Define if have MFS filesystem */ -/* #undef HAVE_FS_MFS */ - -/* Define if have NFS filesystem */ -#define HAVE_FS_NFS 1 - -/* Define if have NFS3 filesystem */ -#define HAVE_FS_NFS3 1 - -/* Define if have NULLFS (loopback on bsd44) filesystem */ -#define HAVE_FS_NULLFS 1 - -/* Define if have PCFS filesystem */ -#define HAVE_FS_PCFS 1 - -/* Define if have TFS filesystem */ -/* #undef HAVE_FS_TFS */ - -/* Define if have TMPFS filesystem */ -/* #undef HAVE_FS_TMPFS */ - -/* Define if have UFS filesystem */ -#define HAVE_FS_UFS 1 - -/* Define if have UMAPFS (uid/gid mapping) filesystem */ -/* #undef HAVE_FS_UMAPFS */ - -/* Define if have UNIONFS filesystem */ -#define HAVE_FS_UNIONFS 1 - -/* Define if have XFS filesystem (irix) */ -/* #undef HAVE_FS_XFS */ - -/* System supports GCC-style variable-length argument macros */ -/* #undef HAVE_GCC_VARARGS_MACROS */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_GDBM_NDBM_H */ - -/* Define to 1 if you have the `getccent' function. */ -/* #undef HAVE_GETCCENT */ - -/* Define to 1 if you have the `getcwd' function. */ -#define HAVE_GETCWD 1 - -/* Define to 1 if you have the `getdomainname' function. */ -#define HAVE_GETDOMAINNAME 1 - -/* Define to 1 if you have the `getdtablesize' function. */ -#define HAVE_GETDTABLESIZE 1 - -/* Define to 1 if you have the `gethostname' function. */ -#define HAVE_GETHOSTNAME 1 - -/* Define to 1 if you have the `getifaddrs' function. */ -#define HAVE_GETIFADDRS 1 - -/* Define to 1 if you have the `getmntinfo' function. */ -#define HAVE_GETMNTINFO 1 - -/* Define to 1 if you have the `getmountent' function. */ -/* #undef HAVE_GETMOUNTENT */ - -/* Define to 1 if you have the `getpagesize' function. */ -#define HAVE_GETPAGESIZE 1 - -/* Define to 1 if you have the `getpwnam' function. */ -#define HAVE_GETPWNAM 1 - -/* Define to 1 if you have the `gettimeofday' function. */ -#define HAVE_GETTIMEOFDAY 1 - -/* Define to 1 if you have the `get_myaddress' function. */ -#define HAVE_GET_MYADDRESS 1 - -/* define if your system's getopt() is GNU getopt() (are you using glibc) */ -/* #undef HAVE_GNU_GETOPT */ - -/* Define to 1 if you have the header file. */ -#define HAVE_GRP_H 1 - -/* Define to 1 if you have the `hasmntopt' function. */ -/* #undef HAVE_HASMNTOPT */ - -#ifdef YES_HESIOD -/* Define to 1 if you have the header file. */ -#define HAVE_HESIOD_H 1 - -/* Define to 1 if you have the `hesiod_init' function. */ -#define HAVE_HESIOD_INIT 1 - -/* Define to 1 if you have the `hesiod_reload' function. */ -/* #undef HAVE_HESIOD_RELOAD */ - -/* Define to 1 if you have the `hesiod_to_bind' function. */ -#define HAVE_HESIOD_TO_BIND 1 - -/* Define to 1 if you have the `hes_init' function. */ -#define HAVE_HES_INIT 1 -#else -#undef HAVE_HESIOD_H -#undef HAVE_HESIOD_INIT -#undef HAVE_HESIOD_RELOAD -#undef HAVE_HESIOD_TO_BIND -#undef HAVE_HES_INIT -#endif - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_HSFS_HSFS_H */ - -/* Define to 1 if you have the `hstrerror' function. */ -#define HAVE_HSTRERROR 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_IFADDRS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_IRS_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_ISOFS_CD9660_CD9660_MOUNT_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LBER_H */ - -/* Define to 1 if you have the `ldap_enable_cache' function. */ -/* #undef HAVE_LDAP_ENABLE_CACHE */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LDAP_H */ - -/* Define to 1 if you have the `ldap_open' function. */ -/* #undef HAVE_LDAP_OPEN */ - -/* Define to 1 if you have the header file. */ -#define HAVE_LIBGEN_H 1 - -/* Define to 1 if you have the `malloc' library (-lmalloc). */ -/* #undef HAVE_LIBMALLOC */ - -/* Define to 1 if you have the `mapmalloc' library (-lmapmalloc). */ -/* #undef HAVE_LIBMAPMALLOC */ - -/* Define to 1 if you have the `nsl' library (-lnsl). */ -/* #undef HAVE_LIBNSL */ - -/* Define to 1 if you have the `posix4' library (-lposix4). */ -/* #undef HAVE_LIBPOSIX4 */ - -/* Define to 1 if you have the `resolv' library (-lresolv). */ -/* #undef HAVE_LIBRESOLV */ - -/* Define to 1 if you have the `rpc' library (-lrpc). */ -/* #undef HAVE_LIBRPC */ - -/* Define to 1 if you have the `rpcsvc' library (-lrpcsvc). */ -#define HAVE_LIBRPCSVC 1 - -/* Define to 1 if you have the `rt' library (-lrt). */ -/* #undef HAVE_LIBRT */ - -/* does libwrap exist? */ -#define HAVE_LIBWRAP 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_AUTO_FS4_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_AUTO_FS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_FS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_KDEV_T_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_LIST_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_LOOP_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_NFS2_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_NFS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_NFS_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_POSIX_TYPES_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_LINUX_SOCKET_H */ - -/* Define to 1 if you support file names longer than 14 characters. */ -#define HAVE_LONG_FILE_NAMES 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MACHINE_ENDIAN_H 1 - -/* Define to 1 if you have the `madvise' function. */ -#define HAVE_MADVISE 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MALLOC_H */ - -/* Define if have DBM maps */ -/* #undef HAVE_MAP_DBM */ - -/* Define if have executable maps */ -#define HAVE_MAP_EXEC 1 - -/* Define if have file maps (everyone should have it!) */ -#define HAVE_MAP_FILE 1 - -#ifdef YES_HESIOD -/* Define if have HESIOD maps */ -#define HAVE_MAP_HESIOD 1 -#else -#undef HAVE_MAP_HESIOD -#endif - -/* Define if have LDAP maps */ -/* #undef HAVE_MAP_LDAP */ - -/* Define if have NDBM maps */ -#define HAVE_MAP_NDBM 1 - -/* Define if have NIS maps */ -#define HAVE_MAP_NIS 1 - -/* Define if have NIS+ maps */ -/* #undef HAVE_MAP_NISPLUS */ - -/* Define if have PASSWD maps */ -#define HAVE_MAP_PASSWD 1 - -/* Define if have UNION maps */ -#define HAVE_MAP_UNION 1 - -/* Define to 1 if you have the `memcmp' function. */ -#define HAVE_MEMCMP 1 - -/* Define to 1 if you have the `memcpy' function. */ -#define HAVE_MEMCPY 1 - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the `memset' function. */ -#define HAVE_MEMSET 1 - -/* Define to 1 if you have the `mkdir' function. */ -#define HAVE_MKDIR 1 - -/* Define to 1 if you have the `mkstemp' function. */ -#define HAVE_MKSTEMP 1 - -/* Define to 1 if you have the `mlockall' function. */ -#define HAVE_MLOCKALL 1 - -/* Define to 1 if you have the `mntctl' function. */ -/* #undef HAVE_MNTCTL */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MNTENT_H */ - -/* Define to 1 if `mnt_cnode' is member of `mntent_t'. */ -/* #undef HAVE_MNTENT_T_MNT_CNODE */ - -/* Define to 1 if `mnt_ro' is member of `mntent_t'. */ -/* #undef HAVE_MNTENT_T_MNT_RO */ - -/* Define to 1 if `mnt_time' is member of `mntent_t'. */ -/* #undef HAVE_MNTENT_T_MNT_TIME */ - -/* does mntent_t have mnt_time field and is of type "char *" ? */ -/* #undef HAVE_MNTENT_T_MNT_TIME_STRING */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MNTTAB_H */ - -/* Define to 1 if you have the `mount' function. */ -#define HAVE_MOUNT 1 - -/* Define to 1 if `optptr' is member of `mounta'. */ -/* #undef HAVE_MOUNTA_OPTPTR */ - -/* Define to 1 if you have the `mountsyscall' function. */ -/* #undef HAVE_MOUNTSYSCALL */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_MSDOSFS_MSDOSFSMOUNT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_FS_MSDOSFS_MSDOSFSMOUNT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NDBM_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NDIR_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_NETCONFIG_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETDB_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NETDIR_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_NETINET_IF_ETHER_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NETINET_IN_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NET_ERRNO_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_NET_IF_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NET_IF_VAR_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NET_ROUTE_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_NFSCLIENT_NFSARGS_H 1 - -/* Define to 1 if `acdirmax' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_ACDIRMAX 1 - -/* Define to 1 if `acdirmin' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_ACDIRMIN 1 - -/* Define to 1 if `acregmax' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_ACREGMAX 1 - -/* Define to 1 if `acregmin' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_ACREGMIN 1 - -/* Define to 1 if `addrlen' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_ADDRLEN 1 - -/* Define to 1 if `bsize' is member of `nfs_args_t'. */ -/* #undef HAVE_NFS_ARGS_T_BSIZE */ - -/* Define to 1 if `fhsize' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_FHSIZE 1 - -/* Define to 1 if `fh_len' is member of `nfs_args_t'. */ -/* #undef HAVE_NFS_ARGS_T_FH_LEN */ - -/* Define to 1 if `gfs_flags' is member of `nfs_args_t'. */ -/* #undef HAVE_NFS_ARGS_T_GFS_FLAGS */ - -/* Define to 1 if `namlen' is member of `nfs_args_t'. */ -/* #undef HAVE_NFS_ARGS_T_NAMLEN */ - -/* Define to 1 if `optstr' is member of `nfs_args_t'. */ -/* #undef HAVE_NFS_ARGS_T_OPTSTR */ - -/* Define to 1 if `proto' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_PROTO 1 - -/* Define to 1 if `sotype' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_SOTYPE 1 - -/* Define to 1 if `version' is member of `nfs_args_t'. */ -#define HAVE_NFS_ARGS_T_VERSION 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_EXPORT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_NFSMOUNT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_NFS_NFSPROTO_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_NFSV2_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_NFS_CLNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_NFS_GFS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_NFS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_NFS_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_NFS_PATHCONF_H */ - -/* define if the host has NFS protocol headers in system headers */ -/* #undef HAVE_NFS_PROT_HEADERS */ - -/* Define to 1 if you have the header file. */ -/* #define HAVE_NFS_RPCV2_H 1 */ - -/* Define to 1 if you have the `nis_domain_of' function. */ -/* #undef HAVE_NIS_DOMAIN_OF */ - -/* Define to 1 if you have the header file. */ -#define HAVE_NSSWITCH_H 1 - -/* Define to 1 if you have the `opendir' function. */ -#define HAVE_OPENDIR 1 -/* Define to 1 if `dsttime' is member of `pcfs_args_t'. */ -/* #undef HAVE_PCFS_ARGS_T_DSTTIME */ - -/* Define to 1 if `fspec' is member of `pcfs_args_t'. */ -#define HAVE_PCFS_ARGS_T_FSPEC 1 - -/* Define to 1 if `gid' is member of `pcfs_args_t'. */ -#define HAVE_PCFS_ARGS_T_GID 1 - -/* Define to 1 if `mask' is member of `pcfs_args_t'. */ -#define HAVE_PCFS_ARGS_T_MASK 1 - -/* Define to 1 if `dirmask' is member of `pcfs_args_t'. */ -#define HAVE_PCFS_ARGS_T_DIRMASK 1 - -/* Define to 1 if `secondswest' is member of `pcfs_args_t'. */ -/* #undef HAVE_PCFS_ARGS_T_SECONDSWEST */ - -/* Define to 1 if `uid' is member of `pcfs_args_t'. */ -#define HAVE_PCFS_ARGS_T_UID 1 - -/* Define to 1 if you have the `plock' function. */ -/* #undef HAVE_PLOCK */ - -/* Define to 1 if you have the header file. */ -#define HAVE_PWD_H 1 - -/* Define to 1 if you have the `regcomp' function. */ -#define HAVE_REGCOMP 1 - -/* Define to 1 if you have the `regexec' function. */ -#define HAVE_REGEXEC 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_REGEX_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RESOLV_H 1 - -/* Define to 1 if system calls automatically restart after interruption by a - signal. */ -#define HAVE_RESTARTABLE_SYSCALLS 1 - -/* Define to 1 if you have the `rmdir' function. */ -#define HAVE_RMDIR 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_RPCSVC_AUTOFS_PROT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_RPCSVC_MOUNTV3_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_RPCSVC_MOUNT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPCSVC_NFS_PROT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPCSVC_NIS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPCSVC_YPCLNT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPCSVC_YP_PROT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPC_AUTH_DES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPC_PMAP_CLNT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPC_PMAP_PROT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPC_RPC_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPC_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_RPC_XDR_H 1 - -/* Define to 1 if you have the `select' function. */ -#define HAVE_SELECT 1 - -/* Define to 1 if you have the `seteuid' function. */ -#define HAVE_SETEUID 1 - -/* Define to 1 if you have the `setitimer' function. */ -#define HAVE_SETITIMER 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SETJMP_H 1 - -/* Define to 1 if you have the `setresuid' function. */ -#define HAVE_SETRESUID 1 - -/* Define to 1 if you have the `setsid' function. */ -#define HAVE_SETSID 1 - -/* Define to 1 if you have the `sigaction' function. */ -#define HAVE_SIGACTION 1 - -/* Define to 1 if you have the `signal' function. */ -#define HAVE_SIGNAL 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SIGNAL_H 1 - -/* Define to 1 if you have the `sigsuspend' function. */ -#define HAVE_SIGSUSPEND 1 - -/* Define to 1 if you have the `socket' function. */ -#define HAVE_SOCKET 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SOCKETBITS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_STATBUF_H */ - -/* Define to 1 if you have the `statfs' function. */ -#define HAVE_STATFS 1 - -/* Define to 1 if you have the `statvfs' function. */ -#define HAVE_STATVFS 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDARG_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDIO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the `strcasecmp' function. */ -#define HAVE_STRCASECMP 1 - -/* Define to 1 if you have the `strchr' function. */ -#define HAVE_STRCHR 1 - -/* Define to 1 if you have the `strcspn' function. */ -#define HAVE_STRCSPN 1 - -/* Define to 1 if you have the `strdup' function. */ -#define HAVE_STRDUP 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the `strlcat' function. */ -#define HAVE_STRLCAT 1 - -/* Define to 1 if you have the `strlcpy' function. */ -#define HAVE_STRLCPY 1 - -/* Define to 1 if you have the `strspn' function. */ -#define HAVE_STRSPN 1 - -/* Define to 1 if you have the `strstr' function. */ -#define HAVE_STRSTR 1 - -/* Define to 1 if `fhs_fh' is member of `struct fhstatus'. */ -/* #undef HAVE_STRUCT_FHSTATUS_FHS_FH */ - -/* Define to 1 if `ifa_next' is member of `struct ifaddrs'. */ -#define HAVE_STRUCT_IFADDRS_IFA_NEXT 1 - -/* Define to 1 if `ifr_addr' is member of `struct ifreq'. */ -#define HAVE_STRUCT_IFREQ_IFR_ADDR 1 - -/* Define if have struct mntent in one of the standard headers */ -/* #undef HAVE_STRUCT_MNTENT */ - -/* Define if have struct mnttab in one of the standard headers */ -/* #undef HAVE_STRUCT_MNTTAB */ - -/* Define if have struct nfs_args in one of the standard nfs headers */ -#define HAVE_STRUCT_NFS_ARGS 1 - -/* Define if have struct nfs_gfs_mount in one of the standard nfs headers */ -/* #undef HAVE_STRUCT_NFS_GFS_MOUNT */ - -/* Define to 1 if `sa_len' is member of `struct sockaddr'. */ -#define HAVE_STRUCT_SOCKADDR_SA_LEN 1 - -/* Define to 1 if `f_fstypename' is member of `struct statfs'. */ -#define HAVE_STRUCT_STATFS_F_FSTYPENAME 1 - -/* Define to 1 if `devid' is member of `struct umntrequest'. */ -/* #undef HAVE_STRUCT_UMNTREQUEST_DEVID */ - -/* Define to 1 if you have the `svc_getreq' function. */ -#define HAVE_SVC_GETREQ 1 - -/* Define to 1 if you have the `svc_getreqset' function. */ -#define HAVE_SVC_GETREQSET 1 - -/* Define to 1 if you have the `sysfs' function. */ -/* #undef HAVE_SYSFS */ - -/* Define to 1 if you have the `syslog' function. */ -#define HAVE_SYSLOG 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYSLOG_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_CONFIG_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_DG_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_DIR_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_ERRNO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_FILE_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FSID_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FSTYP_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_AUTOFS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_AUTOFS_PROT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_CACHEFS_FS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_EFS_CLNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_NFS_CLNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_NFS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_NFS_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_NFS_NFS_CLNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_PC_FS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_TMP_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_TYPES_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_UFS_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_FS_XFS_CLNT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_IMMU_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_IOCTL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_LOCK_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_MACHINE_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_MBUF_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_MMAN_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_MNTCTL_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_MNTENT_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_MNTTAB_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_MOUNT_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_NDIR_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_NETCONFIG_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_PARAM_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_PATHCONF_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_PROC_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_RESOURCE_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SEMA_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SIGNAL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKET_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SOCKIO_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_STATFS_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STATVFS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SYSCALL_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SYSLIMITS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_SYSLOG_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_TIUSER_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_UCRED_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_UIO_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_UTSNAME_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_VFS_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_VMOUNT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_VNODE_H 1 - -/* Define to 1 if you have that is POSIX.1 compatible. */ -#define HAVE_SYS_WAIT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_TCPD_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_TIME_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_TIUSER_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_TMPFS_TMP_H */ - -/* what type of network transport type is in use? TLI or sockets? */ -/* #undef HAVE_TRANSPORT_TYPE_TLI */ - -/* Define to 1 if you have the `ualarm' function. */ -#define HAVE_UALARM 1 - -/* Define to 1 if `flags' is member of `ufs_args_t'. */ -/* #undef HAVE_UFS_ARGS_T_FLAGS */ - -/* Define to 1 if `fspec' is member of `ufs_args_t'. */ -#define HAVE_UFS_ARGS_T_FSPEC 1 - -/* Define to 1 if `ufs_flags' is member of `ufs_args_t'. */ -/* #undef HAVE_UFS_ARGS_T_UFS_FLAGS */ - -/* Define to 1 if `ufs_pgthresh' is member of `ufs_args_t'. */ -/* #undef HAVE_UFS_ARGS_T_UFS_PGTHRESH */ - -/* Define to 1 if you have the header file. */ -#define HAVE_UFS_UFS_EXTATTR_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_UFS_UFS_MOUNT_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_UFS_UFS_UFSMOUNT_H 1 - -/* Define to 1 if you have the `umount' function. */ -/* #undef HAVE_UMOUNT */ - -/* Define to 1 if you have the `umount2' function. */ -/* #undef HAVE_UMOUNT2 */ - -/* Define to 1 if you have the `uname' function. */ -#define HAVE_UNAME 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the `unmount' function. */ -#define HAVE_UNMOUNT 1 - -/* Define to 1 if you have the `uvmount' function. */ -/* #undef HAVE_UVMOUNT */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_VARARGS_H */ - -/* Define to 1 if you have the `vfork' function. */ -#define HAVE_VFORK 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_VFORK_H */ - -/* Define to 1 if you have the `vfsmount' function. */ -/* #undef HAVE_VFSMOUNT */ - -/* Define to 1 if you have the `vmount' function. */ -/* #undef HAVE_VMOUNT */ - -/* Define to 1 if you have the `vsnprintf' function. */ -#define HAVE_VSNPRINTF 1 - -/* Define to 1 if you have the `wait3' function. */ -#define HAVE_WAIT3 1 - -/* Define to 1 if you have the `waitpid' function. */ -#define HAVE_WAITPID 1 - -/* Define to 1 if `fork' works. */ -#define HAVE_WORKING_FORK 1 - -/* Define to 1 if `vfork' works. */ -#define HAVE_WORKING_VFORK 1 - -/* Define to 1 if you have the `xdr_attrstat' function. */ -#define HAVE_XDR_ATTRSTAT 1 - -/* Define to 1 if you have the `xdr_createargs' function. */ -#define HAVE_XDR_CREATEARGS 1 - -/* Define to 1 if you have the `xdr_dirlist' function. */ -#define HAVE_XDR_DIRLIST 1 - -/* Define to 1 if you have the `xdr_diropargs' function. */ -#define HAVE_XDR_DIROPARGS 1 - -/* Define to 1 if you have the `xdr_diropokres' function. */ -#define HAVE_XDR_DIROPOKRES 1 - -/* Define to 1 if you have the `xdr_diropres' function. */ -#define HAVE_XDR_DIROPRES 1 - -/* Define to 1 if you have the `xdr_dirpath' function. */ -#define HAVE_XDR_DIRPATH 1 - -/* Define to 1 if you have the `xdr_entry' function. */ -#define HAVE_XDR_ENTRY 1 - -/* Define to 1 if you have the `xdr_exportnode' function. */ -#define HAVE_XDR_EXPORTNODE 1 - -/* Define to 1 if you have the `xdr_exports' function. */ -#define HAVE_XDR_EXPORTS 1 - -/* Define to 1 if you have the `xdr_fattr' function. */ -#define HAVE_XDR_FATTR 1 - -/* Define to 1 if you have the `xdr_fhandle' function. */ -#define HAVE_XDR_FHANDLE 1 - -/* Define to 1 if you have the `xdr_fhstatus' function. */ -#define HAVE_XDR_FHSTATUS 1 - -/* Define to 1 if you have the `xdr_filename' function. */ -#define HAVE_XDR_FILENAME 1 - -/* Define to 1 if you have the `xdr_ftype' function. */ -#define HAVE_XDR_FTYPE 1 - -/* Define to 1 if you have the `xdr_groupnode' function. */ -#define HAVE_XDR_GROUPNODE 1 - -/* Define to 1 if you have the `xdr_groups' function. */ -#define HAVE_XDR_GROUPS 1 - -/* Define to 1 if you have the `xdr_linkargs' function. */ -#define HAVE_XDR_LINKARGS 1 - -/* Define to 1 if you have the `xdr_mountbody' function. */ -#define HAVE_XDR_MOUNTBODY 1 - -/* Define to 1 if you have the `xdr_mountlist' function. */ -#define HAVE_XDR_MOUNTLIST 1 - -/* Define to 1 if you have the `xdr_name' function. */ -#define HAVE_XDR_NAME 1 - -/* Define to 1 if you have the `xdr_nfscookie' function. */ -#define HAVE_XDR_NFSCOOKIE 1 - -/* Define to 1 if you have the `xdr_nfspath' function. */ -#define HAVE_XDR_NFSPATH 1 - -/* Define to 1 if you have the `xdr_nfsstat' function. */ -#define HAVE_XDR_NFSSTAT 1 - -/* Define to 1 if you have the `xdr_nfstime' function. */ -#define HAVE_XDR_NFSTIME 1 - -/* Define to 1 if you have the `xdr_nfs_fh' function. */ -#define HAVE_XDR_NFS_FH 1 - -/* Define to 1 if you have the `xdr_pointer' function. */ -#define HAVE_XDR_POINTER 1 - -/* Define to 1 if you have the `xdr_readargs' function. */ -#define HAVE_XDR_READARGS 1 - -/* Define to 1 if you have the `xdr_readdirargs' function. */ -#define HAVE_XDR_READDIRARGS 1 - -/* Define to 1 if you have the `xdr_readdirres' function. */ -#define HAVE_XDR_READDIRRES 1 - -/* Define to 1 if you have the `xdr_readlinkres' function. */ -#define HAVE_XDR_READLINKRES 1 - -/* Define to 1 if you have the `xdr_readokres' function. */ -#define HAVE_XDR_READOKRES 1 - -/* Define to 1 if you have the `xdr_readres' function. */ -#define HAVE_XDR_READRES 1 - -/* Define to 1 if you have the `xdr_renameargs' function. */ -#define HAVE_XDR_RENAMEARGS 1 - -/* Define to 1 if you have the `xdr_sattr' function. */ -#define HAVE_XDR_SATTR 1 - -/* Define to 1 if you have the `xdr_sattrargs' function. */ -#define HAVE_XDR_SATTRARGS 1 - -/* Define to 1 if you have the `xdr_statfsokres' function. */ -#define HAVE_XDR_STATFSOKRES 1 - -/* Define to 1 if you have the `xdr_statfsres' function. */ -#define HAVE_XDR_STATFSRES 1 - -/* Define to 1 if you have the `xdr_symlinkargs' function. */ -#define HAVE_XDR_SYMLINKARGS 1 - -/* Define to 1 if you have the `xdr_writeargs' function. */ -#define HAVE_XDR_WRITEARGS 1 - -/* Define to 1 if `flags' is member of `xfs_args_t'. */ -/* #undef HAVE_XFS_ARGS_T_FLAGS */ - -/* Define to 1 if `fspec' is member of `xfs_args_t'. */ -/* #undef HAVE_XFS_ARGS_T_FSPEC */ - -/* Define to 1 if you have the `yp_all' function. */ -/* #undef HAVE_YP_ALL */ - -/* Define to 1 if you have the `yp_get_default_domain' function. */ -#define HAVE_YP_GET_DEFAULT_DOMAIN 1 - -/* Define to 1 if you have the `_seterr_reply' function. */ -#define HAVE__SETERR_REPLY 1 - -/* Define to 1 if you have the `__rpc_get_local_uid' function. */ -#define HAVE___RPC_GET_LOCAL_UID 1 - -/* Define to 1 if you have the `__seterr_reply' function. */ -/* #undef HAVE___SETERR_REPLY */ - -/* Name of mount type to hide amd mount from df(1) */ -#define HIDE_MOUNT_TYPE "nfs" - -/* Define name of host machine's architecture (eg. sun4) */ -/* #define HOST_ARCH "i386" */ - -/* Define name of host machine's cpu (eg. sparc) */ -/* #define HOST_CPU "i386" */ - -/* Define the header version of (linux) hosts (eg. 2.2.10) */ -// #undef define HOST_HEADER_VERSION */ - -/* Define name of host */ -/* #define HOST_NAME "trang.nuxi.org" */ - -/* Define name and version of host machine (eg. solaris2.5.1) */ -/* #define HOST_OS "freebsd8.0" */ - -/* Define only name of host machine OS (eg. solaris2) */ -/* #define HOST_OS_NAME "freebsd8" */ - -/* Define only version of host machine (eg. 2.5.1) */ -/* #define HOST_OS_VERSION "8.0" */ - -/* Define name of host machine's vendor (eg. sun) */ -#define HOST_VENDOR "undermydesk" - -/* Ignore permission bits */ -/* #undef MNT2_CDFS_OPT_DEFPERM */ - -/* Use on-disk permission bits */ -/* #undef MNT2_CDFS_OPT_NODEFPERM */ - -/* Strip off extension from version string */ -/* #undef MNT2_CDFS_OPT_NOVERSION */ - -/* Use Rock Ridge Interchange Protocol (RRIP) extensions */ -/* #undef MNT2_CDFS_OPT_RRIP */ - -/* asynchronous filesystem access */ -#define MNT2_GEN_OPT_ASYNC 0x40 - -/* automounter filesystem (ignore) flag, used in bsdi-4.1 */ -/* #undef MNT2_GEN_OPT_AUTOMNTFS */ - -/* automounter filesystem flag, used in Mac OS X / Darwin */ -/* #undef MNT2_GEN_OPT_AUTOMOUNTED */ - -/* directory hardlink */ -/* #undef MNT2_GEN_OPT_BIND */ - -/* cache (what?) */ -/* #undef MNT2_GEN_OPT_CACHE */ - -/* 6-argument mount */ -/* #undef MNT2_GEN_OPT_DATA */ - -/* Use a lazy unmount (detach) */ -/* #undef MNT2_GEN_OPT_DETACH */ - -/* Use a forced unmount */ -#define MNT2_GEN_OPT_FORCE 0x80000 - -/* old (4-argument) mount (compatibility) */ -/* #undef MNT2_GEN_OPT_FSS */ - -/* old BSD group-id on create */ -/* #undef MNT2_GEN_OPT_GRPID */ - -/* ignore mount entry in df output */ -#define MNT2_GEN_OPT_IGNORE 0x800000 - -/* journaling filesystem (AIX's UFS/FFS) */ -/* #undef MNT2_GEN_OPT_JFS */ - -/* do multi-component lookup on files */ -/* #undef MNT2_GEN_OPT_MULTI */ - -/* use type string instead of int */ -/* #undef MNT2_GEN_OPT_NEWTYPE */ - -/* NFS mount */ -/* #undef MNT2_GEN_OPT_NFS */ - -/* nocache (what?) */ -/* #undef MNT2_GEN_OPT_NOCACHE */ - -/* do not interpret special device files */ -#define MNT2_GEN_OPT_NODEV 0x0 - -/* no exec calls allowed */ -#define MNT2_GEN_OPT_NOEXEC 0x4 - -/* do not interpret special device files */ -/* #undef MNT2_GEN_OPT_NONDEV */ - -/* Disallow mounts beneath this mount */ -/* #undef MNT2_GEN_OPT_NOSUB */ - -/* Setuid programs disallowed */ -#define MNT2_GEN_OPT_NOSUID 0x8 - -/* Return ENAMETOOLONG for long filenames */ -/* #undef MNT2_GEN_OPT_NOTRUNC */ - -/* Pass mount option string to kernel */ -/* #undef MNT2_GEN_OPT_OPTIONSTR */ - -/* allow overlay mounts */ -/* #undef MNT2_GEN_OPT_OVERLAY */ - -/* check quotas */ -#define MNT2_GEN_OPT_QUOTA 0x2000 - -/* Read-only */ -#define MNT2_GEN_OPT_RDONLY 0x1 - -/* change options on an existing mount */ -/* #undef MNT2_GEN_OPT_REMOUNT */ - -/* read only */ -/* #undef MNT2_GEN_OPT_RONLY */ - -/* synchronize data immediately to filesystem */ -/* #undef MNT2_GEN_OPT_SYNC */ - -/* synchronous filesystem access (same as SYNC) */ -#define MNT2_GEN_OPT_SYNCHRONOUS 0x2 - -/* Mount with Sys 5-specific semantics */ -/* #undef MNT2_GEN_OPT_SYS5 */ - -/* Union mount */ -/* #undef MNT2_GEN_OPT_UNION */ - -/* set max secs for dir attr cache */ -#define MNT2_NFS_OPT_ACDIRMAX 0x200000 - -/* set min secs for dir attr cache */ -#define MNT2_NFS_OPT_ACDIRMIN 0x100000 - -/* set max secs for file attr cache */ -#define MNT2_NFS_OPT_ACREGMAX 0x80000 - -/* set min secs for file attr cache */ -#define MNT2_NFS_OPT_ACREGMIN 0x40000 - -/* Authentication error */ -/* #undef MNT2_NFS_OPT_AUTHERR */ - -/* hide mount type from df(1) */ -/* #undef MNT2_NFS_OPT_AUTO */ - -/* set dead server retry thresh */ -#define MNT2_NFS_OPT_DEADTHRESH 0x4000 - -/* Dismount in progress */ -/* #undef MNT2_NFS_OPT_DISMINPROG */ - -/* Dismounted */ -/* #undef MNT2_NFS_OPT_DISMNT */ - -/* Don't estimate rtt dynamically */ -#define MNT2_NFS_OPT_DUMBTIMR 0x800 - -/* provide name of server's fs to system */ -/* #undef MNT2_NFS_OPT_FSNAME */ - -/* System V-style gid inheritance */ -/* #undef MNT2_NFS_OPT_GRPID */ - -/* Has authenticator */ -/* #undef MNT2_NFS_OPT_HASAUTH */ - -/* set hostname for error printf */ -/* #undef MNT2_NFS_OPT_HOSTNAME */ - -/* ignore mount point */ -/* #undef MNT2_NFS_OPT_IGNORE */ - -/* allow interrupts on hard mount */ -#define MNT2_NFS_OPT_INT 0x40 - -/* Bits set internally */ -/* #undef MNT2_NFS_OPT_INTERNAL */ - -/* allow interrupts on hard mount */ -/* #undef MNT2_NFS_OPT_INTR */ - -/* Use Kerberos authentication */ -/* #undef MNT2_NFS_OPT_KERB */ - -/* use kerberos credentials */ -/* #undef MNT2_NFS_OPT_KERBEROS */ - -/* transport's knetconfig structure */ -/* #undef MNT2_NFS_OPT_KNCONF */ - -/* set lease term (nqnfs) */ -/* #undef MNT2_NFS_OPT_LEASETERM */ - -/* Local locking (no lock manager) */ -/* #undef MNT2_NFS_OPT_LLOCK */ - -/* set maximum grouplist size */ -#define MNT2_NFS_OPT_MAXGRPS 0x20 - -/* Mnt server for mnt point */ -/* #undef MNT2_NFS_OPT_MNTD */ - -/* Assume writes were mine */ -/* #undef MNT2_NFS_OPT_MYWRITE */ - -/* mount NFS Version 3 */ -#define MNT2_NFS_OPT_NFSV3 0x200 - -/* don't cache attributes */ -/* #undef MNT2_NFS_OPT_NOAC */ - -/* Don't Connect the socket */ -#define MNT2_NFS_OPT_NOCONN 0x80 - -/* no close-to-open consistency */ -/* #undef MNT2_NFS_OPT_NOCTO */ - -/* disallow interrupts on hard mounts */ -/* #undef MNT2_NFS_OPT_NOINT */ - -/* Don't use locking */ -/* #undef MNT2_NFS_OPT_NONLM */ - -/* Get lease for lookup */ -/* #undef MNT2_NFS_OPT_NQLOOKLEASE */ - -/* Use Nqnfs protocol */ -/* #undef MNT2_NFS_OPT_NQNFS */ - -/* paging threshold */ -/* #undef MNT2_NFS_OPT_PGTHRESH */ - -/* static pathconf kludge info */ -/* #undef MNT2_NFS_OPT_POSIX */ - -/* Use local locking */ -/* #undef MNT2_NFS_OPT_PRIVATE */ - -/* allow property list operations (ACLs over NFS) */ -/* #undef MNT2_NFS_OPT_PROPLIST */ - -/* Rcv socket lock */ -/* #undef MNT2_NFS_OPT_RCVLOCK */ - -/* Do lookup with readdir (nqnfs) */ -/* #undef MNT2_NFS_OPT_RDIRALOOK */ - -/* Use Readdirplus for NFSv3 */ -#define MNT2_NFS_OPT_RDIRPLUS 0x10000 - -/* set read ahead */ -#define MNT2_NFS_OPT_READAHEAD 0x2000 - -/* Set readdir size */ -#define MNT2_NFS_OPT_READDIRSIZE 0x20000 - -/* Allocate a reserved port */ -#define MNT2_NFS_OPT_RESVPORT 0x8000 - -/* set number of request retries */ -#define MNT2_NFS_OPT_RETRANS 0x10 - -/* read only */ -/* #undef MNT2_NFS_OPT_RONLY */ - -/* use RPC to do secure NFS time sync */ -/* #undef MNT2_NFS_OPT_RPCTIMESYNC */ - -/* set read size */ -#define MNT2_NFS_OPT_RSIZE 0x4 - -/* secure mount */ -/* #undef MNT2_NFS_OPT_SECURE */ - -/* Send socket lock */ -/* #undef MNT2_NFS_OPT_SNDLOCK */ - -/* soft mount (hard is default) */ -#define MNT2_NFS_OPT_SOFT 0x1 - -/* spongy mount */ -/* #undef MNT2_NFS_OPT_SPONGY */ - -/* set symlink cache time-to-live */ -/* #undef MNT2_NFS_OPT_SYMTTL */ - -/* use TCP for mounts */ -/* #undef MNT2_NFS_OPT_TCP */ - -/* set initial timeout */ -#define MNT2_NFS_OPT_TIMEO 0x8 - -/* linux NFSv3 */ -/* #undef MNT2_NFS_OPT_VER3 */ - -/* Wait for authentication */ -/* #undef MNT2_NFS_OPT_WAITAUTH */ - -/* Wants an authenticator */ -/* #undef MNT2_NFS_OPT_WANTAUTH */ - -/* Want receive socket lock */ -/* #undef MNT2_NFS_OPT_WANTRCV */ - -/* Want send socket lock */ -/* #undef MNT2_NFS_OPT_WANTSND */ - -/* set write size */ -#define MNT2_NFS_OPT_WSIZE 0x2 - -/* 32<->64 dir cookie translation */ -/* #undef MNT2_NFS_OPT_XLATECOOKIE */ - -/* Force Win95 long names */ -#define MNT2_PCFS_OPT_LONGNAME 0x2 - -/* Completely ignore Win95 entries */ -#define MNT2_PCFS_OPT_NOWIN95 0x4 - -/* Force old DOS short names only */ -#define MNT2_PCFS_OPT_SHORTNAME 0x1 - -/* Name of mount table file name */ -/* #undef MNTTAB_FILE_NAME */ - -/* Mount Table option string: Max attr cache timeout (dirs) */ -/* #undef MNTTAB_OPT_ACDIRMAX */ - -/* Mount Table option string: Min attr cache timeout (dirs) */ -/* #undef MNTTAB_OPT_ACDIRMIN */ - -/* Mount Table option string: Max attr cache timeout (files) */ -/* #undef MNTTAB_OPT_ACREGMAX */ - -/* Mount Table option string: Min attr cache timeout (files) */ -/* #undef MNTTAB_OPT_ACREGMIN */ - -/* Mount Table option string: Attr cache timeout (sec) */ -/* #undef MNTTAB_OPT_ACTIMEO */ - -/* Mount Table option string: Do mount retries in background */ -/* #undef MNTTAB_OPT_BG */ - -/* Mount Table option string: compress */ -/* #undef MNTTAB_OPT_COMPRESS */ - -/* Mount Table option string: Device id of mounted fs */ -/* #undef MNTTAB_OPT_DEV */ - -/* Mount Table option string: Automount direct map mount */ -/* #undef MNTTAB_OPT_DIRECT */ - -/* Mount Table option string: Do mount retries in foreground */ -/* #undef MNTTAB_OPT_FG */ - -/* Mount Table option string: Filesystem id of mounted fs */ -/* #undef MNTTAB_OPT_FSID */ - -/* Mount Table option string: SysV-compatible gid on create */ -/* #undef MNTTAB_OPT_GRPID */ - -/* Mount Table option string: Hard mount */ -/* #undef MNTTAB_OPT_HARD */ - -/* Mount Table option string: Ignore this entry */ -/* #undef MNTTAB_OPT_IGNORE */ - -/* Mount Table option string: Automount indirect map mount */ -/* #undef MNTTAB_OPT_INDIRECT */ - -/* Mount Table option string: Allow NFS ops to be interrupted */ -/* #undef MNTTAB_OPT_INTR */ - -/* Mount Table option string: Secure (AUTH_Kerb) mounting */ -/* #undef MNTTAB_OPT_KERB */ - -/* Mount Table option string: Local locking (no lock manager) */ -/* #undef MNTTAB_OPT_LLOCK */ - -/* Force Win95 long names */ -/* #undef MNTTAB_OPT_LONGNAME */ - -/* Mount Table option string: Automount map */ -/* #undef MNTTAB_OPT_MAP */ - -/* Mount Table option string: max groups */ -/* #undef MNTTAB_OPT_MAXGROUPS */ - -/* Mount Table option string: Do multi-component lookup */ -/* #undef MNTTAB_OPT_MULTI */ - -/* Mount Table option string: Don't cache attributes at all */ -/* #undef MNTTAB_OPT_NOAC */ - -/* Mount Table option string: No auto (what?) */ -/* #undef MNTTAB_OPT_NOAUTO */ - -/* Mount Table option string: No connection */ -/* #undef MNTTAB_OPT_NOCONN */ - -/* Mount Table option string: No close-to-open consistency */ -/* #undef MNTTAB_OPT_NOCTO */ - -/* Mount Table option string: Don't allow interrupted ops */ -/* #undef MNTTAB_OPT_NOINTR */ - -/* Mount Table option string: Don't check quotas */ -/* #undef MNTTAB_OPT_NOQUOTA */ - -/* Mount Table option string: Do no allow setting sec attrs */ -/* #undef MNTTAB_OPT_NOSETSEC */ - -/* Mount Table option string: Disallow mounts on subdirs */ -/* #undef MNTTAB_OPT_NOSUB */ - -/* Mount Table option string: Set uid not allowed */ -/* #undef MNTTAB_OPT_NOSUID */ - -/* Completely ignore Win95 entries */ -/* #undef MNTTAB_OPT_NOWIN95 */ - -/* Mount Table option string: action to taken on error */ -/* #undef MNTTAB_OPT_ONERROR */ - -/* Mount Table option string: paging threshold */ -/* #undef MNTTAB_OPT_PGTHRESH */ - -/* Mount Table option string: NFS server IP port number */ -/* #undef MNTTAB_OPT_PORT */ - -/* Mount Table option string: Get static pathconf for mount */ -/* #undef MNTTAB_OPT_POSIX */ - -/* Mount Table option string: Use local locking */ -/* #undef MNTTAB_OPT_PRIVATE */ - -/* Mount Table option string: support property lists (ACLs) */ -/* #undef MNTTAB_OPT_PROPLIST */ - -/* Mount Table option string: protocol network_id indicator */ -/* #undef MNTTAB_OPT_PROTO */ - -/* Mount Table option string: Check quotas */ -/* #undef MNTTAB_OPT_QUOTA */ - -/* Mount Table option string: Change mount options */ -/* #undef MNTTAB_OPT_REMOUNT */ - -/* Mount Table option string: Max retransmissions (soft mnts) */ -/* #undef MNTTAB_OPT_RETRANS */ - -/* Mount Table option string: Number of mount retries */ -/* #undef MNTTAB_OPT_RETRY */ - -/* Mount Table option string: Read only */ -/* #undef MNTTAB_OPT_RO */ - -/* Mount Table option string: Read/write with quotas */ -/* #undef MNTTAB_OPT_RQ */ - -/* Mount Table option string: Max NFS read size (bytes) */ -/* #undef MNTTAB_OPT_RSIZE */ - -/* Mount Table option string: Read/write */ -/* #undef MNTTAB_OPT_RW */ - -/* Mount Table option string: Secure (AUTH_DES) mounting */ -/* #undef MNTTAB_OPT_SECURE */ - -/* Force old DOS short names only */ -/* #undef MNTTAB_OPT_SHORTNAME */ - -/* Mount Table option string: Soft mount */ -/* #undef MNTTAB_OPT_SOFT */ - -/* Mount Table option string: spongy mount */ -/* #undef MNTTAB_OPT_SPONGY */ - -/* Mount Table option string: Set uid allowed */ -/* #undef MNTTAB_OPT_SUID */ - -/* Mount Table option string: set symlink cache time-to-live */ -/* #undef MNTTAB_OPT_SYMTTL */ - -/* Mount Table option string: Synchronous local directory ops */ -/* #undef MNTTAB_OPT_SYNCDIR */ - -/* Mount Table option string: NFS timeout (1/10 sec) */ -/* #undef MNTTAB_OPT_TIMEO */ - -/* Mount Table option string: min. time between inconsistencies */ -/* #undef MNTTAB_OPT_TOOSOON */ - -/* Mount Table option string: protocol version number indicator */ -/* #undef MNTTAB_OPT_VERS */ - -/* Mount Table option string: Max NFS write size (bytes) */ -/* #undef MNTTAB_OPT_WSIZE */ - -/* Mount-table entry name for AUTOFS filesystem */ -/* #undef MNTTAB_TYPE_AUTOFS */ - -/* Mount-table entry name for CACHEFS filesystem */ -/* #undef MNTTAB_TYPE_CACHEFS */ - -/* Mount-table entry name for CDFS filesystem */ -#define MNTTAB_TYPE_CDFS "cd9660" - -/* Mount-table entry name for CFS (crypto) filesystem */ -/* #undef MNTTAB_TYPE_CFS */ - -/* Mount-table entry name for EFS filesystem (irix) */ -/* #undef MNTTAB_TYPE_EFS */ - -/* Mount-table entry name for FFS filesystem */ -/* #undef MNTTAB_TYPE_FFS */ - -/* Mount-table entry name for LOFS filesystem */ -/* #undef MNTTAB_TYPE_LOFS */ - -/* Mount-table entry name for MFS filesystem */ -/* #undef MNTTAB_TYPE_MFS */ - -/* Mount-table entry name for NFS filesystem */ -#define MNTTAB_TYPE_NFS "nfs" - -/* Mount-table entry name for NFS3 filesystem */ -#define MNTTAB_TYPE_NFS3 "nfs3" - -/* Mount-table entry name for NULLFS (loopback on bsd44) filesystem */ -#define MNTTAB_TYPE_NULLFS "nullfs" - -/* Mount-table entry name for PCFS filesystem */ -#define MNTTAB_TYPE_PCFS "msdosfs" - -/* Mount-table entry name for TFS filesystem */ -/* #undef MNTTAB_TYPE_TFS */ - -/* Mount-table entry name for TMPFS filesystem */ -/* #undef MNTTAB_TYPE_TMPFS */ - -/* Mount-table entry name for UFS filesystem */ -#define MNTTAB_TYPE_UFS "ufs" - -/* Mount-table entry name for UMAPFS (uid/gid mapping) filesystem */ -/* #undef MNTTAB_TYPE_UMAPFS */ - -/* Mount-table entry name for UNIONFS filesystem */ -#define MNTTAB_TYPE_UNIONFS "unionfs" - -/* Mount-table entry name for XFS filesystem (irix) */ -/* #undef MNTTAB_TYPE_XFS */ - -/* Define if mount table is on file, undefine if in kernel */ -/* #undef MOUNT_TABLE_ON_FILE */ - -/* Mount(2) type/name for AUTOFS filesystem */ -/* #undef MOUNT_TYPE_AUTOFS */ - -/* Mount(2) type/name for CACHEFS filesystem */ -/* #undef MOUNT_TYPE_CACHEFS */ - -/* Mount(2) type/name for CDFS filesystem */ -#define MOUNT_TYPE_CDFS "cd9660" - -/* Mount(2) type/name for CFS (crypto) filesystem */ -/* #undef MOUNT_TYPE_CFS */ - -/* Mount(2) type/name for EFS filesystem (irix) */ -/* #undef MOUNT_TYPE_EFS */ - -/* Mount(2) type/name for FFS filesystem */ -/* #undef MOUNT_TYPE_FFS */ - -/* Mount(2) type/name for IGNORE filesystem (not real just ignore for df) */ -#define MOUNT_TYPE_IGNORE MNT_IGNORE - -/* Mount(2) type/name for LOFS filesystem */ -/* #undef MOUNT_TYPE_LOFS */ - -/* Mount(2) type/name for MFS filesystem */ -/* #undef MOUNT_TYPE_MFS */ - -/* Mount(2) type/name for NFS filesystem */ -#define MOUNT_TYPE_NFS "nfs" - -/* Mount(2) type/name for NFS3 filesystem */ -#define MOUNT_TYPE_NFS3 MOUNT_NFS3 - -/* Mount(2) type/name for NULLFS (loopback on bsd44) filesystem */ -#define MOUNT_TYPE_NULLFS "nullfs" - -/* Mount(2) type/name for PCFS filesystem. XXX: conf/trap/trap_hpux.h may - override this definition for HPUX 9.0 */ -#define MOUNT_TYPE_PCFS "msdosfs" - -/* Mount(2) type/name for TFS filesystem */ -/* #undef MOUNT_TYPE_TFS */ - -/* Mount(2) type/name for TMPFS filesystem */ -/* #undef MOUNT_TYPE_TMPFS */ - -/* Mount(2) type/name for UFS filesystem */ -#define MOUNT_TYPE_UFS "ufs" - -/* Mount(2) type/name for UMAPFS (uid/gid mapping) filesystem */ -/* #undef MOUNT_TYPE_UMAPFS */ - -/* Mount(2) type/name for UNIONFS filesystem */ -#define MOUNT_TYPE_UNIONFS MNT_UNION - -/* Mount(2) type/name for XFS filesystem (irix) */ -/* #undef MOUNT_TYPE_XFS */ - -/* The string used in printf to print the mount-type field of mount(2) */ -#define MTYPE_PRINTF_TYPE "%s" - -/* Type of the mount-type field in the mount() system call */ -#define MTYPE_TYPE char * - -/* does libwrap expect caller to define the variables allow_severity and - deny_severity */ -/* #undef NEED_LIBWRAP_SEVERITY_VARIABLES */ - -/* Defined to the header file containing ndbm-compatible definitions */ -#define NEW_DBM_H - -/* Define the field name for the filehandle within nfs_args_t */ -#define NFS_FH_FIELD fh - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -/* #undef NO_MINUS_C_MINUS_O */ - -/* Name of package */ -#define PACKAGE "am-utils" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "https://bugzilla.am-utils.org/ or am-utils@am-utils.org" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "am-utils" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "am-utils 6.1.5" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "am-utils" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "6.1.5" - -/* Type of the 6th argument to recvfrom() */ -#define RECVFROM_FROMLEN_TYPE int - -/* should signal handlers be reinstalled? */ -/* #undef REINSTALL_SIGNAL_HANDLER */ - -/* Define as the return type of signal handlers (`int' or `void'). */ -#define RETSIGTYPE void - -/* Define to 1 if the `setpgrp' function takes no argument. */ -/* #undef SETPGRP_VOID */ - -/* Define to 1 if the `S_IS*' macros in do not work properly. */ -/* #undef STAT_MACROS_BROKEN */ - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define the type of the 3rd argument ('in') to svc_getargs() */ -#define SVC_IN_ARG_TYPE caddr_t - -/* Define to 1 if you can safely include both and . */ -#define TIME_WITH_SYS_TIME 1 - -/* Define to 1 if your declares `struct tm'. */ -/* #undef TM_IN_SYS_TIME */ - -/* Define user name */ -/* #define USER_NAME "obrien" */ - -/* define if must NOT use NFS "noconn" option */ -#define USE_CONNECTED_NFS_SOCKETS 1 - -/* define if must use NFS "noconn" option */ -/* #undef USE_UNCONNECTED_NFS_SOCKETS */ - -/* Version number of package */ -#define VERSION "6.1.5" - -/* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ -/* #undef WORDS_BIGENDIAN */ - -/* Define to the type of xdr procedure type */ -#define XDRPROC_T_TYPE xdrproc_t - -/* Type of the 3rd argument to yp_order() */ -#define YP_ORDER_OUTORDER_TYPE int - -/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a - `char[]'. */ -#define YYTEXT_POINTER 1 - -/* Define to 1 if on AIX 3. - System headers sometimes define this. - We just want to avoid a redefinition error message. */ -#ifndef _ALL_SOURCE -/* # undef _ALL_SOURCE */ -#endif - -/* Define a type/structure for an NFS V2 filehandle */ -#define am_nfs_fh nfs_fh - -/* Define a type/structure for an NFS V3 filehandle */ -#define am_nfs_fh3 nfs_fh3_freebsd3 - -/* Define a type for the autofs_args structure */ -/* #undef autofs_args_t */ - -/* Define a type for the cachefs_args structure */ -/* #undef cachefs_args_t */ - -/* Define a type for the cdfs_args structure */ -#define cdfs_args_t struct iso_args - -/* Define to empty if `const' does not conform to ANSI C. */ -/* #undef const */ - -/* Define a type for the efs_args structure */ -/* #undef efs_args_t */ - -/* Define to `int' if doesn't define. */ -/* #undef gid_t */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -/* #undef inline */ -#endif - -/* Define a type for the lofs_args structure */ -/* #undef lofs_args_t */ - -/* Define a type for the mfs_args structure */ -/* #undef mfs_args_t */ - -/* Define to `int' if does not define. */ -/* #undef mode_t */ - -/* Define a type for the nfs_args structure */ -#define nfs_args_t struct nfs_args - -/* Define a type for the pcfs_args structure */ -#define pcfs_args_t struct msdosfs_args - -/* Define to `int' if does not define. */ -/* #undef pid_t */ - -/* Check if pte_t is defined in */ -/* #undef pte_t */ - -/* Define a type for the rfs_args structure */ -/* #undef rfs_args_t */ - -/* Check if rpcvers_t is defined in */ -/* #undef rpcvers_t */ - -/* Define to `unsigned' if does not define. */ -/* #undef size_t */ - -/* Define to `long' if does not define. */ -/* #undef time_t */ - -/* Define a type for the tmpfs_args structure */ -/* #undef tmpfs_args_t */ - -/* Define a type for the ufs_args structure */ -#define ufs_args_t struct ufs_args - -/* Define to `int' if doesn't define. */ -/* #undef uid_t */ - -/* Define as `fork' if `vfork' does not work. */ -/* #undef vfork */ - -/* Define to "void *" if compiler can handle, otherwise "char *" */ -#define voidp void * - -/* Define to empty if the keyword `volatile' does not work. Warning: valid - code using `volatile' can become incorrect without. Disable with care. */ -/* #undef volatile */ - -/* Define a type for the xfs_args structure */ -/* #undef xfs_args_t */ - - -/****************************************************************************/ -/*** INCLUDE localconfig.h if it exists, to allow users to make some ***/ -/*** compile time configuration changes. ***/ -/****************************************************************************/ -/* does a local configuration file exist? */ -/* #undef HAVE_LOCALCONFIG_H */ -#ifdef HAVE_LOCALCONFIG_H -# include -#endif /* HAVE_LOCALCONFIG_H */ - -#endif /* not _CONFIG_H */ - -/* - * Local Variables: - * mode: c - * End: - */ - -/* End of am-utils-6.x config.h file */ diff --git a/usr.sbin/amd/include/newvers.sh b/usr.sbin/amd/include/newvers.sh deleted file mode 100644 index e192ee9..0000000 --- a/usr.sbin/amd/include/newvers.sh +++ /dev/null @@ -1,43 +0,0 @@ -# $NetBSD: mkconf,v 1.1.1.1 1997/07/24 21:20:12 christos Exp $ -# $FreeBSD$ -# mkconf -# Generate local configuration parameters for amd -# - -if [ -e $1 ]; then - eval `LC_ALL=C egrep '^[A-Z]+=' $1 | grep -v COPYRIGHT` - OS=`echo ${TYPE} | LC_ALL=C tr 'A-Z' 'a-z'` - echo '/* Define name and version of host machine (eg. solaris2.5.1) */' - echo "#define HOST_OS \"${OS}${REVISION}\"" - echo '/* Define only name of host machine OS (eg. solaris2) */' - echo "#define HOST_OS_NAME \"${OS}${REVISION}\"" \ - | sed -e 's/\.[-._0-9]*//' - echo '/* Define only version of host machine (eg. 2.5.1) */' - echo "#define HOST_OS_VERSION \"${REVISION}\"" -else -cat << __NO_newvers_sh - -/* Define name and version of host machine (eg. solaris2.5.1) */ -#define HOST_OS "`uname -s | LC_ALL=C tr 'A-Z' 'a-z'``uname -r`" - -/* Define only name of host machine OS (eg. solaris2) */ -#define HOST_OS_NAME "`uname -s | LC_ALL=C tr 'A-Z' 'a-z'``uname -r | sed -e 's/\..*$//'`" - -/* Define only version of host machine (eg. 2.5.1) */ -#define HOST_OS_VERSION "`uname -r | sed -e 's/[-([:alpha:]].*//'`" - -__NO_newvers_sh -fi - -cat << __EOF - -/* Define name of host */ -#define BUILD_HOST "`hostname`" - -/* Define user name */ -#define BUILD_USER "`whoami`" - -/* Define configuration date */ -#define BUILD_DATE "`LC_ALL=C date`" - -__EOF diff --git a/usr.sbin/amd/libamu/Makefile b/usr.sbin/amd/libamu/Makefile deleted file mode 100644 index fa8e3ab..0000000 --- a/usr.sbin/amd/libamu/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/libamu \ - ${.CURDIR}/../../../contrib/amd/conf/transp \ - ${.CURDIR}/../../../contrib/amd/conf/mtab \ - ${.CURDIR}/../../../contrib/amd/conf/umount - -LIB= amu -INTERNALLIB= -SRCS= hasmntopt.c misc_rpc.c mount_fs.c mtab.c nfs_prot_xdr.c \ - strutil.c wire.c xutil.c - -# These would be links created by the GNU-style configure -SRCS+= transp_sockets.c mtab_bsd.c umount_bsd44.c - -# Generated at compile time (replaces supplied xdr_func.c) -SRCS+= nfs_prot_x.c xdr_func_%undef.c -CLEANFILES+= nfs_prot_x.c xdr_func_%undef.c - -CFLAGS+= -I${.CURDIR}/../../../contrib/amd/libamu \ - -I${DESTDIR}/usr/include/rpcsvc - -nfs_prot_x.c: ${NFS_PROT_X} - ${RPCCOM} -c -C -DWANT_NFS3 ${NFS_PROT_X} -o ${.TARGET} - -XDRDEFS!= grep 'ifndef.*HAVE_XDR' ${.CURDIR}/../../../contrib/amd/libamu/xdr_func.c | awk '{print "-D"$$2}' - -xdr_func_%undef.c: xdr_func.c - -unifdef ${XDRDEFS} < ${.ALLSRC} > ${.TARGET} - -.include diff --git a/usr.sbin/amd/mk-amd-map/Makefile b/usr.sbin/amd/mk-amd-map/Makefile deleted file mode 100644 index 57fd6a5..0000000 --- a/usr.sbin/amd/mk-amd-map/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/mk-amd-map - -PROG= mk-amd-map -MAN= mk-amd-map.8 - -DPADD= ${LIBAMU} -LDADD= ${LIBAMU} - -.include diff --git a/usr.sbin/amd/pawd/Makefile b/usr.sbin/amd/pawd/Makefile deleted file mode 100644 index c6bb1cc..0000000 --- a/usr.sbin/amd/pawd/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/amq - -BINDIR= /usr/bin - -PROG= pawd -SRCS= pawd.c amq_clnt.c amq_xdr.c - -CFLAGS+= -I${.CURDIR}/../../../contrib/amd/amq - -DPADD= ${LIBAMU} -LDADD= ${LIBAMU} - -.include diff --git a/usr.sbin/amd/scripts/Makefile b/usr.sbin/amd/scripts/Makefile deleted file mode 100644 index 822b951..0000000 --- a/usr.sbin/amd/scripts/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/scripts - -MAN= amd.conf.5 - -.include diff --git a/usr.sbin/amd/wire-test/Makefile b/usr.sbin/amd/wire-test/Makefile deleted file mode 100644 index a07e690..0000000 --- a/usr.sbin/amd/wire-test/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# ex:ts=8 -# -# Makefile for amd -# This file is under a "BSD" copyright (c) by David O'Brien 1998 -# -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/amd/wire-test - -PROG= wire-test -MAN= wire-test.8 - -DPADD= ${LIBAMU} -LDADD= ${LIBAMU} - -.include diff --git a/usr.sbin/ancontrol/Makefile b/usr.sbin/ancontrol/Makefile deleted file mode 100644 index b0f66cd..0000000 --- a/usr.sbin/ancontrol/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $FreeBSD$ - -PROG= ancontrol -MAN= ancontrol.8 - -WARNS?= 3 -CFLAGS+= -DANCACHE -I${.CURDIR}/../../sys - -DPADD= ${LIBMD} -LDADD= -lmd - -.include diff --git a/usr.sbin/ancontrol/ancontrol.8 b/usr.sbin/ancontrol/ancontrol.8 deleted file mode 100644 index 13da6ab..0000000 --- a/usr.sbin/ancontrol/ancontrol.8 +++ /dev/null @@ -1,553 +0,0 @@ -.\" Copyright (c) 1997, 1998, 1999 -.\" Bill Paul All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Bill Paul. -.\" 4. Neither the name of the author nor the names of any co-contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -.\" THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd September 10, 1999 -.Dt ANCONTROL 8 -.Os -.Sh NAME -.Nm ancontrol -.Nd configure Aironet 4500/4800 devices -.Sh SYNOPSIS -.Nm -.Fl i Ar iface Fl A -.Nm -.Fl i Ar iface Fl N -.Nm -.Fl i Ar iface Fl S -.Nm -.Fl i Ar iface Fl I -.Nm -.Fl i Ar iface Fl T -.Nm -.Fl i Ar iface Fl C -.Nm -.Fl i Ar iface Fl Q -.Nm -.Fl i Ar iface Fl Z -.Nm -.Fl i Ar iface Fl R -.Nm -.Fl i Ar iface Fl t Cm 0 Ns - Ns Cm 4 -.Nm -.Fl i Ar iface Fl s Cm 0 Ns - Ns Cm 3 -.Nm -.Fl i Ar iface -.Op Fl v Cm 1 Ns - Ns Cm 4 -.Fl a Ar AP -.Nm -.Fl i Ar iface Fl b Ar beacon_period -.Nm -.Fl i Ar iface -.Op Fl v Cm 0 | 1 -.Fl d Cm 0 Ns - Ns Cm 3 -.Nm -.Fl i Ar iface Fl e Cm 0 Ns - Ns Cm 4 -.Nm -.Fl i Ar iface -.Op Fl v Cm 0 Ns - Ns Cm 8 -.Fl k Ar key -.Nm -.Fl i Ar iface -.Fl K Cm 0 Ns - Ns Cm 2 -.Nm -.Fl i Ar iface -.Fl W Cm 0 Ns - Ns Cm 2 -.Nm -.Fl i Ar iface -.Fl L Ar user_name -.Nm -.Fl i Ar iface Fl j Ar netjoin_timeout -.Nm -.Fl i Ar iface Fl l Ar station_name -.Nm -.Fl i Ar iface Fl m Ar mac_address -.Nm -.Fl i Ar iface -.Op Fl v Cm 1 Ns - Ns Cm 3 -.Fl n Ar SSID -.Nm -.Fl i Ar iface Fl o Cm 0 | 1 -.Nm -.Fl i Ar iface Fl p Ar tx_power -.Nm -.Fl i Ar iface Fl c Ar frequency -.Nm -.Fl i Ar iface Fl f Ar fragmentation_threshold -.Nm -.Fl i Ar iface Fl r Ar RTS_threshold -.Nm -.Fl i Ar iface Fl M Cm 0 Ns - Ns Cm 15 -.Nm -.Fl h -.Sh DESCRIPTION -The -.Nm -utility controls the operation of Aironet wireless networking -devices via the -.Xr an 4 -driver. -Most of the parameters that can be changed relate to the -IEEE 802.11 protocol which the Aironet cards implement. -This includes such things as -the station name, whether the station is operating in ad-hoc (point -to point) or infrastructure mode, and the network name of a service -set to join. -The -.Nm -utility can also be used to view the current NIC status, configuration -and to dump out the values of the card's statistics counters. -.Pp -The -.Ar iface -argument given to -.Nm -should be the logical interface name associated with the Aironet -device -.Li ( an0 , an1 , -etc.). -If one is not specified the device -.Dq Li an0 -will be assumed. -.Pp -The -.Nm -utility is not designed to support the combination of arguments from different -.Sx SYNOPSIS -lines in a single -.Nm -invocation, and such combinations are not recommended. -.Sh OPTIONS -The options are as follows: -.Bl -tag -width indent -.It Fl i Ar iface Fl A -Display the preferred access point list. -The AP list can be used by -stations to specify the MAC address of access points with which it -wishes to associate. -If no AP list is specified (the default) then -the station will associate with the first access point that it finds -which serves the SSID(s) specified in the SSID list. -The AP list can -be modified with the -.Fl a -option. -.It Fl i Ar iface Fl N -Display the SSID list. -This is a list of service set IDs (i.e., network names) -with which the station wishes to associate. -There may be up to three SSIDs -in the list: the station will go through the list in ascending order and -associate with the first matching SSID that it finds. -.It Fl i Ar iface Fl S -Display NIC status information. -This includes the current operating -status, current BSSID, SSID, channel, beacon period and currently -associated access point. -The operating mode indicates the state of -the NIC, MAC status and receiver status. -When the -.Qq Li synced -keyword -appears, it means the NIC has successfully associated with an access -point, associated with an ad-hoc -.Dq master -station, or become a -.Dq master -itself. -The beacon period can be anything between 20 and 976 milliseconds. -The default is 100. -.It Fl i Ar iface Fl I -Display NIC capability information. -This shows the device type, -frequency, speed and power level capabilities and firmware revision levels. -.It Fl i Ar iface Fl T -Display the NIC's internal statistics counters. -.It Fl i Ar iface Fl C -Display current NIC configuration. -This shows the current operation mode, -receive mode, MAC address, power save settings, various timing settings, -channel selection, diversity, transmit power and transmit speed. -.It Fl i Ar iface Fl Q -Display the cached signal strength information maintained by the -.Xr an 4 -driver. -The driver retains information about signal strength and -noise level for packets received from different hosts. -The signal strength and noise level values are displayed in units of dBms by -default. -The -.Va hw.an.an_cache_mode -.Xr sysctl 8 -variable can be set to -.Cm raw , dbm -or -.Cm per . -.It Fl i Ar iface Fl Z -Clear the signal strength cache maintained internally by the -.Xr an 4 -driver. -.It Fl i Ar iface Fl R -Display RSSI map that converts from the RSSI index to percent and dBm. -.It Fl i Ar iface Fl t Cm 0 Ns - Ns Cm 4 -Select transmit speed. -The available settings are as follows: -.Bl -column ".Em TX rate" -offset indent -.Em "TX rate NIC speed" -.It Cm 0 Ta "Auto -- NIC selects optimal speed" -.It Cm 1 Ta "1Mbps fixed" -.It Cm 2 Ta "2Mbps fixed" -.It Cm 3 Ta "5.5Mbps fixed" -.It Cm 4 Ta "11Mbps fixed" -.El -.Pp -Note that the 5.5 and 11Mbps settings are only supported on the 4800 -series adapters: the 4500 series adapters have a maximum speed of 2Mbps. -.It Fl i Ar iface Fl s Cm 0 Ns - Ns Cm 3 -Set power save mode. -Valid selections are as follows: -.Bl -column ".Em Selection" -offset indent -.Em "Selection Power save mode" -.It Cm 0 Ta "None - power save disabled" -.It Cm 1 Ta "Constantly awake mode (CAM)" -.It Cm 2 Ta "Power Save Polling (PSP)" -.It Cm 3 Ta "Fast Power Save Polling (PSP-CAM)" -.El -.Pp -Note that for IBSS (ad-hoc) mode, only PSP mode is supported, and only -if the ATIM window is non-zero. -.It Fl i Ar iface Oo Fl v Cm 1 Ns - Ns Cm 4 Oc Fl a Ar AP -Set preferred access point. -The -.Ar AP -is specified as a MAC address consisting of 6 hexadecimal values -separated by colons. -By default, the -.Fl a -option only sets the first entry in the AP list. -The -.Fl v -modifier can be used to specify exactly which AP list entry is to be -modified. -If the -.Fl v -flag is not used, the first AP list entry will be changed. -.It Fl i Ar iface Fl b Ar beacon_period -Set the ad-hoc mode beacon period. -The -.Ar beacon_period -is specified in milliseconds. -The default is 100ms. -.It Fl i Ar iface Oo Fl v Cm 0 | 1 Oc Fl d Cm 0 Ns - Ns Cm 3 -Select the antenna diversity. -Aironet devices can be configured with up -to two antennas, and transmit and receive diversity can be configured -accordingly. -Valid selections are as follows: -.Bl -column ".Em Selection" -offset indent -.Em "Selection Diversity" -.It Cm 0 Ta "Select factory default diversity" -.It Cm 1 Ta "Antenna 1 only" -.It Cm 2 Ta "Antenna 2 only" -.It Cm 3 Ta "Antenna 1 and 2" -.El -.Pp -The receive and transmit diversity can be set independently. -The user -must specify which diversity setting is to be modified by using the -.Fl v -option: selection -.Cm 0 -sets the receive diversity and -.Cm 1 -sets the transmit diversity. -.It Fl i Ar iface Fl e Cm 0 Ns - Ns Cm 4 -Set the transmit WEP key to use. -Note that until this command is issued, the device will use the -last key programmed. -The transmit key is stored in NVRAM. -Currently -set transmit key can be checked via -.Fl C -option. -Selection -.Cm 4 -sets the card in -.Dq "Home Network Mode" -and uses the home key. -.It Fl i Ar iface Oo Fl v Cm 0 Ns - Ns Cm 8 Oc Fl k Ar key -Set a WEP key. -For 40 bit prefix 10 hex character with 0x. -For 128 bit prefix 26 hex character with 0x. -Use -.Qq \& -as the key to erase the key. -Supports 4 keys; even numbers are for permanent keys -and odd number are for temporary keys. -For example, -.Fl v Cm 1 -sets the first temporary key. -(A -.Dq permanent -key is stored in NVRAM; a -.Dq temporary -key is not.) -Note that the device will use the most recently-programmed key by default. -Currently set keys can be checked via -.Fl C -option, only the sizes of the -keys are returned. -The value of -.Cm 8 -is for the home key. -Note that the value for the home key can be read back from firmware. -.It Fl i Ar iface Fl K Cm 0 Ns - Ns Cm 2 -Set authorization type. -Use -.Cm 0 -for none, -.Cm 1 -for -.Dq Open , -.Cm 2 -for -.Dq "Shared Key" . -.It Fl i Ar iface Fl W Cm 0 Ns - Ns Cm 2 -Enable WEP. -Use -.Cm 0 -for no WEP, -.Cm 1 -to enable full WEP, -.Cm 2 -for mixed cell. -.It Fl i Ar iface Fl L Ar user_name -Enable LEAP and query for password. -It will check to see if it has authenticated for up to 60s. -To disable LEAP, set WEP mode. -.It Fl i Ar iface Fl j Ar netjoin_timeout -Set the ad-hoc network join timeout. -When a station is first activated -in ad-hoc mode, it will search out a -.Dq master -station with the desired -SSID and associate with it. -If the station is unable to locate another -station with the same SSID after a suitable timeout, it sets itself up -as the -.Dq master -so that other stations may associate with it. -This -timeout defaults to 10000 milliseconds (10 seconds) but may be changed -with this option. -The timeout should be specified in milliseconds. -.It Fl i Ar iface Fl l Ar station_name -Set the station name used internally by the NIC. -The -.Ar station_name -can be any text string up to 16 characters in length. -The default name -is set by the driver to -.Dq Li FreeBSD . -.It Fl i Ar iface Fl m Ar mac_address -Set the station address for the specified interface. -The -.Ar mac_address -is specified as a series of six hexadecimal values separated by colons, -e.g.: -.Li 00:60:1d:12:34:56 . -This programs the new address into the card -and updates the interface as well. -.It Fl i Ar iface Oo Fl v Cm 1 Ns - Ns Cm 3 Oc Fl n Ar SSID -Set the desired SSID (network name). -There are three SSIDs which allows -the NIC to work with access points at several locations without needing -to be reconfigured. -The NIC checks each SSID in sequence when searching -for a match. -The SSID to be changed can be specified with the -.Fl v -modifier option. -If the -.Fl v -flag is not used, the first SSID in the list is set. -.It Fl i Ar iface Fl o Cm 0 | 1 -Set the operating mode of the Aironet interface. -Valid selections are -.Cm 0 -for ad-hoc mode and -.Cm 1 -for infrastructure mode. -The default driver setting is for infrastructure -mode. -.It Fl i Ar iface Fl p Ar tx_power -Set the transmit power level in milliwatts. -Valid power settings -vary depending on the actual NIC and can be viewed by dumping the -device capabilities with the -.Fl I -flag. -Typical values are 1, 5, 20, 50 and 100mW. -Selecting 0 sets -the factory default. -.It Fl i Ar iface Fl c Ar frequency -Set the radio frequency of a given interface. -The -.Ar frequency -should be specified as a channel ID as shown in the table below. -The -list of available frequencies is dependent on radio regulations specified -by regional authorities. -Recognized regulatory authorities include -the FCC (United States), ETSI (Europe), France and Japan. -Frequencies -in the table are specified in MHz. -.Bl -column ".Em Channel ID" ".Em FCC" ".Em ETSI" ".Em France" ".Em Japan" -offset indent -.Em "Channel ID FCC ETSI France Japan" -.It Cm 1 Ta 2412 Ta 2412 Ta - Ta - -.It Cm 2 Ta 2417 Ta 2417 Ta - Ta - -.It Cm 3 Ta 2422 Ta 2422 Ta - Ta - -.It Cm 4 Ta 2427 Ta 2427 Ta - Ta - -.It Cm 5 Ta 2432 Ta 2432 Ta - Ta - -.It Cm 6 Ta 2437 Ta 2437 Ta - Ta - -.It Cm 7 Ta 2442 Ta 2442 Ta - Ta - -.It Cm 8 Ta 2447 Ta 2447 Ta - Ta - -.It Cm 9 Ta 2452 Ta 2452 Ta - Ta - -.It Cm 10 Ta 2457 Ta 2457 Ta 2457 Ta - -.It Cm 11 Ta 2462 Ta 2462 Ta 2462 Ta - -.It Cm 12 Ta - Ta 2467 Ta 2467 Ta - -.It Cm 13 Ta - Ta 2472 Ta 2472 Ta - -.It Cm 14 Ta - Ta - Ta - Ta 2484 -.El -.Pp -If an illegal channel is specified, the -NIC will revert to its default channel. -For NICs sold in the United States -and Europe, the default channel is 3. -For NICs sold in France, the default -channel is 11. -For NICs sold in Japan, the only available channel is 14. -Note that two stations must be set to the same channel in order to -communicate. -.It Fl i Ar iface Fl f Ar fragmentation_threshold -Set the fragmentation threshold in bytes. -This threshold controls the -point at which outgoing packets will be split into multiple fragments. -If a single fragment is not sent successfully, only that fragment will -need to be retransmitted instead of the whole packet. -The fragmentation -threshold can be anything from 64 to 2312 bytes. -The default is 2312. -.It Fl i Ar iface Fl r Ar RTS_threshold -Set the RTS/CTS threshold for a given interface. -This controls the -number of bytes used for the RTS/CTS handshake boundary. -The -.Ar RTS_threshold -can be any value between 0 and 2312. -The default is 2312. -.It Fl i Ar iface Fl M Cm 0 Ns - Ns Cm 15 -Set monitor mode via bit mask, meaning: -.Pp -.Bl -tag -width indent -offset indent -compact -.It Em Bit -.Em Meaning -.It 0 -to not dump 802.11 packet. -.It 1 -to enable 802.11 monitor. -.It 2 -to monitor any SSID. -.It 4 -to not skip beacons, monitor beacons produces a high system load. -.It 8 -to enable full Aironet header returned via BPF. -Note it appears that a SSID must be set. -.El -.It Fl h -Print a list of available options and sample usage. -.El -.Sh SECURITY NOTES -WEP -.Pq Dq "wired equivalent privacy" -is based on the RC4 algorithm, -using a 24 bit initialization vector. -.Pp -RC4 is supposedly vulnerable to certain known plaintext attacks, -especially with 40 bit keys. -So the security of WEP in part depends on how much known plaintext -is transmitted. -.Pp -Because of this, although counter-intuitive, using -.Dq "shared key" -authentication (which involves sending known plaintext) is less -secure than using -.Dq open -authentication when WEP is enabled. -.Pp -Devices may alternate among all of the configured WEP keys when -transmitting packets. -Therefore, all configured keys (up to four) must agree. -.Sh EXAMPLES -.Bd -literal -offset indent -ancontrol -i an0 -v 0 -k 0x12345678901234567890123456 -ancontrol -i an0 -K 2 -ancontrol -i an0 -W 1 -ancontrol -i an0 -e 0 -.Ed -.Pp -Sets a WEP key 0, enables -.Dq "Shared Key" -authentication, enables full WEP -and uses transmit key 0. -.Sh SEE ALSO -.Xr an 4 , -.Xr ifconfig 8 -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 4.0 . -.Sh AUTHORS -The -.Nm -utility was written by -.An Bill Paul Aq wpaul@ee.columbia.edu . -.Sh BUGS -The statistics counters do not seem to show the amount of transmit -and received frames as increasing. -This is likely due to the fact that -the -.Xr an 4 -driver uses unmodified packet mode instead of letting the NIC perform -802.11/ethernet encapsulation itself. -.Pp -Setting the channel does not seem to have any effect. diff --git a/usr.sbin/ancontrol/ancontrol.c b/usr.sbin/ancontrol/ancontrol.c deleted file mode 100644 index 008970d..0000000 --- a/usr.sbin/ancontrol/ancontrol.c +++ /dev/null @@ -1,1781 +0,0 @@ -/* - * Copyright 1997, 1998, 1999 - * Bill Paul . All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Bill Paul. - * 4. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#if 0 -#ifndef lint -static const char copyright[] = "@(#) Copyright (c) 1997, 1998, 1999\ - Bill Paul. All rights reserved."; -#endif -#endif -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static int an_getval(const char *, struct an_req *); -static void an_setval(const char *, struct an_req *); -static void an_printwords(const u_int16_t *, int); -static void an_printspeeds(const u_int8_t *, int); -static void an_printbool(int); -static void an_printhex(const char *, int); -static void an_printstr(char *, int); -static void an_dumpstatus(const char *); -static void an_dumpstats(const char *); -static void an_dumpconfig(const char *); -static void an_dumpcaps(const char *); -static void an_dumpssid(const char *); -static void an_dumpap(const char *); -static void an_setconfig(const char *, int, void *); -static void an_setssid(const char *, int, void *); -static void an_setap(const char *, int, void *); -static void an_setspeed(const char *, int, void *); -static void an_readkeyinfo(const char *); -#ifdef ANCACHE -static void an_zerocache(const char *); -static void an_readcache(const char *); -#endif -static int an_hex2int(char); -static void an_str2key(const char *, struct an_ltv_key *); -static void an_setkeys(const char *, const char *, int); -static void an_enable_tx_key(const char *, const char *); -static void an_enable_leap_mode(const char *, const char *); -static void an_dumprssimap(const char *); -static void usage(const char *); - -#define ACT_DUMPSTATS 1 -#define ACT_DUMPCONFIG 2 -#define ACT_DUMPSTATUS 3 -#define ACT_DUMPCAPS 4 -#define ACT_DUMPSSID 5 -#define ACT_DUMPAP 6 - -#define ACT_SET_OPMODE 7 -#define ACT_SET_SSID 8 -#define ACT_SET_FREQ 11 -#define ACT_SET_AP1 12 -#define ACT_SET_AP2 13 -#define ACT_SET_AP3 14 -#define ACT_SET_AP4 15 -#define ACT_SET_DRIVERNAME 16 -#define ACT_SET_SCANMODE 17 -#define ACT_SET_TXRATE 18 -#define ACT_SET_RTS_THRESH 19 -#define ACT_SET_PWRSAVE 20 -#define ACT_SET_DIVERSITY_RX 21 -#define ACT_SET_DIVERSITY_TX 22 -#define ACT_SET_RTS_RETRYLIM 23 -#define ACT_SET_WAKE_DURATION 24 -#define ACT_SET_BEACON_PERIOD 25 -#define ACT_SET_TXPWR 26 -#define ACT_SET_FRAG_THRESH 27 -#define ACT_SET_NETJOIN 28 -#define ACT_SET_MYNAME 29 -#define ACT_SET_MAC 30 - -#define ACT_DUMPCACHE 31 -#define ACT_ZEROCACHE 32 - -#define ACT_ENABLE_WEP 33 -#define ACT_SET_KEY_TYPE 34 -#define ACT_SET_KEYS 35 -#define ACT_ENABLE_TX_KEY 36 -#define ACT_SET_MONITOR_MODE 37 -#define ACT_SET_LEAP_MODE 38 - -#define ACT_DUMPRSSIMAP 39 - -static int -an_getval(const char *iface, struct an_req *areq) -{ - struct ifreq ifr; - int s, okay = 1; - - bzero(&ifr, sizeof(ifr)); - - strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - ifr.ifr_data = (caddr_t)areq; - - s = socket(AF_INET, SOCK_DGRAM, 0); - - if (s == -1) - err(1, "socket"); - - if (ioctl(s, SIOCGAIRONET, &ifr) == -1) { - okay = 0; - err(1, "SIOCGAIRONET"); - } - - close(s); - - return (okay); -} - -static void -an_setval(const char *iface, struct an_req *areq) -{ - struct ifreq ifr; - int s; - - bzero(&ifr, sizeof(ifr)); - - strlcpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - ifr.ifr_data = (caddr_t)areq; - - s = socket(AF_INET, SOCK_DGRAM, 0); - - if (s == -1) - err(1, "socket"); - - if (ioctl(s, SIOCSAIRONET, &ifr) == -1) - err(1, "SIOCSAIRONET"); - - close(s); - - return; -} - -static void -an_printstr(char *str, int len) -{ - int i; - - for (i = 0; i < len - 1; i++) { - if (str[i] == '\0') - str[i] = ' '; - } - - printf("[ %.*s ]", len, str); -} - -static void -an_printwords(const u_int16_t *w, int len) -{ - int i; - - printf("[ "); - for (i = 0; i < len; i++) - printf("%u ", w[i]); - printf("]"); -} - -static void -an_printspeeds(const u_int8_t *w, int len) -{ - int i; - - printf("[ "); - for (i = 0; i < len && w[i]; i++) - printf("%2.1fMbps ", w[i] * 0.500); - printf("]"); -} - -static void -an_printbool(int val) -{ - if (val) - printf("[ On ]"); - else - printf("[ Off ]"); -} - -static void -an_printhex(const char *ptr, int len) -{ - int i; - - printf("[ "); - for (i = 0; i < len; i++) { - printf("%02x", ptr[i] & 0xFF); - if (i < (len - 1)) - printf(":"); - } - - printf(" ]"); -} - - - -static void -an_dumpstatus(const char *iface) -{ - struct an_ltv_status *sts; - struct an_req areq; - struct an_ltv_rssi_map an_rssimap; - int rssimap_valid = 0; - - /* - * Try to get RSSI to percent and dBM table - */ - - an_rssimap.an_len = sizeof(an_rssimap); - an_rssimap.an_type = AN_RID_RSSI_MAP; - rssimap_valid = an_getval(iface, (struct an_req*)&an_rssimap); - - if (rssimap_valid) - printf("RSSI table:\t\t[ present ]\n"); - else - printf("RSSI table:\t\t[ not available ]\n"); - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_STATUS; - - an_getval(iface, &areq); - - sts = (struct an_ltv_status *)&areq; - - printf("MAC address:\t\t"); - an_printhex((char *)&sts->an_macaddr, ETHER_ADDR_LEN); - printf("\nOperating mode:\t\t[ "); - if (sts->an_opmode & AN_STATUS_OPMODE_CONFIGURED) - printf("configured "); - if (sts->an_opmode & AN_STATUS_OPMODE_MAC_ENABLED) - printf("MAC ON "); - if (sts->an_opmode & AN_STATUS_OPMODE_RX_ENABLED) - printf("RX ON "); - if (sts->an_opmode & AN_STATUS_OPMODE_IN_SYNC) - printf("synced "); - if (sts->an_opmode & AN_STATUS_OPMODE_ASSOCIATED) - printf("associated "); - if (sts->an_opmode & AN_STATUS_OPMODE_LEAP) - printf("LEAP "); - if (sts->an_opmode & AN_STATUS_OPMODE_ERROR) - printf("error "); - printf("]\n"); - printf("Error code:\t\t"); - an_printhex((char *)&sts->an_errcode, 1); - if (rssimap_valid) - printf("\nSignal strength:\t[ %u%% ]", - an_rssimap.an_entries[ - sts->an_normalized_strength].an_rss_pct); - else - printf("\nSignal strength:\t[ %u%% ]", - sts->an_normalized_strength); - printf("\nAverage Noise:\t\t[ %u%% ]", sts->an_avg_noise_prev_min_pc); - if (rssimap_valid) - printf("\nSignal quality:\t\t[ %u%% ]", - an_rssimap.an_entries[ - sts->an_cur_signal_quality].an_rss_pct); - else - printf("\nSignal quality:\t\t[ %u ]", - sts->an_cur_signal_quality); - printf("\nMax Noise:\t\t[ %u%% ]", sts->an_max_noise_prev_min_pc); - /* - * XXX: This uses the old definition of the rate field (units of - * 500kbps). Technically the new definition is that this field - * contains arbitrary values, but no devices which need this - * support exist and the IEEE seems to intend to use the old - * definition until they get something big so we'll keep using - * it as well because this will work with new cards with - * rate <= 63.5Mbps. - */ - printf("\nCurrent TX rate:\t[ %u%s ]", sts->an_current_tx_rate / 2, - (sts->an_current_tx_rate % 2) ? ".5" : ""); - printf("\nCurrent SSID:\t\t"); - an_printstr((char *)&sts->an_ssid, sts->an_ssidlen); - printf("\nCurrent AP name:\t"); - an_printstr((char *)&sts->an_ap_name, 16); - printf("\nCurrent BSSID:\t\t"); - an_printhex((char *)&sts->an_cur_bssid, ETHER_ADDR_LEN); - printf("\nBeacon period:\t\t"); - an_printwords(&sts->an_beacon_period, 1); - printf("\nDTIM period:\t\t"); - an_printwords(&sts->an_dtim_period, 1); - printf("\nATIM duration:\t\t"); - an_printwords(&sts->an_atim_duration, 1); - printf("\nHOP period:\t\t"); - an_printwords(&sts->an_hop_period, 1); - printf("\nChannel set:\t\t"); - an_printwords(&sts->an_channel_set, 1); - printf("\nCurrent channel:\t"); - an_printwords(&sts->an_cur_channel, 1); - printf("\nHops to backbone:\t"); - an_printwords(&sts->an_hops_to_backbone, 1); - printf("\nTotal AP load:\t\t"); - an_printwords(&sts->an_ap_total_load, 1); - printf("\nOur generated load:\t"); - an_printwords(&sts->an_our_generated_load, 1); - printf("\nAccumulated ARL:\t"); - an_printwords(&sts->an_accumulated_arl, 1); - printf("\n"); - return; -} - -static void -an_dumpcaps(const char *iface) -{ - struct an_ltv_caps *caps; - struct an_req areq; - u_int16_t tmp; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_CAPABILITIES; - - an_getval(iface, &areq); - - caps = (struct an_ltv_caps *)&areq; - - printf("OUI:\t\t\t"); - an_printhex((char *)&caps->an_oui, 3); - printf("\nProduct number:\t\t"); - an_printwords(&caps->an_prodnum, 1); - printf("\nManufacturer name:\t"); - an_printstr((char *)&caps->an_manufname, 32); - printf("\nProduce name:\t\t"); - an_printstr((char *)&caps->an_prodname, 16); - printf("\nFirmware version:\t"); - an_printstr((char *)&caps->an_prodvers, 1); - printf("\nOEM MAC address:\t"); - an_printhex((char *)&caps->an_oemaddr, ETHER_ADDR_LEN); - printf("\nAironet MAC address:\t"); - an_printhex((char *)&caps->an_aironetaddr, ETHER_ADDR_LEN); - printf("\nRadio type:\t\t[ "); - if (caps->an_radiotype & AN_RADIOTYPE_80211_FH) - printf("802.11 FH"); - else if (caps->an_radiotype & AN_RADIOTYPE_80211_DS) - printf("802.11 DS"); - else if (caps->an_radiotype & AN_RADIOTYPE_LM2000_DS) - printf("LM2000 DS"); - else - printf("unknown (%x)", caps->an_radiotype); - printf(" ]"); - printf("\nRegulatory domain:\t"); - an_printwords(&caps->an_regdomain, 1); - printf("\nAssigned CallID:\t"); - an_printhex((char *)&caps->an_callid, 6); - printf("\nSupported speeds:\t"); - an_printspeeds(caps->an_rates, 8); - printf("\nRX Diversity:\t\t[ "); - if (caps->an_rx_diversity == AN_DIVERSITY_FACTORY_DEFAULT) - printf("factory default"); - else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY) - printf("antenna 1 only"); - else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY) - printf("antenna 2 only"); - else if (caps->an_rx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2) - printf("antenna 1 and 2"); - printf(" ]"); - printf("\nTX Diversity:\t\t[ "); - if (caps->an_tx_diversity == AN_DIVERSITY_FACTORY_DEFAULT) - printf("factory default"); - else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_ONLY) - printf("antenna 1 only"); - else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_2_ONLY) - printf("antenna 2 only"); - else if (caps->an_tx_diversity == AN_DIVERSITY_ANTENNA_1_AND_2) - printf("antenna 1 and 2"); - printf(" ]"); - printf("\nSupported power levels:\t"); - an_printwords(caps->an_tx_powerlevels, 8); - printf("\nHardware revision:\t"); - tmp = ntohs(caps->an_hwrev); - an_printhex((char *)&tmp, 2); - printf("\nSoftware revision:\t"); - tmp = ntohs(caps->an_fwrev); - an_printhex((char *)&tmp, 2); - printf("\nSoftware subrevision:\t"); - tmp = ntohs(caps->an_fwsubrev); - an_printhex((char *)&tmp, 2); - printf("\nInterface revision:\t"); - tmp = ntohs(caps->an_ifacerev); - an_printhex((char *)&tmp, 2); - printf("\nBootblock revision:\t"); - tmp = ntohs(caps->an_bootblockrev); - an_printhex((char *)&tmp, 2); - printf("\n"); - return; -} - -static void -an_dumpstats(const char *iface) -{ - struct an_ltv_stats *stats; - struct an_req areq; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_32BITS_CUM; - - an_getval(iface, &areq); - - stats = (struct an_ltv_stats *)((uint16_t *)&areq - 1); - - printf("RX overruns:\t\t\t\t\t[ %u ]\n", stats->an_rx_overruns); - printf("RX PLCP CSUM errors:\t\t\t\t[ %u ]\n", - stats->an_rx_plcp_csum_errs); - printf("RX PLCP format errors:\t\t\t\t[ %u ]\n", - stats->an_rx_plcp_format_errs); - printf("RX PLCP length errors:\t\t\t\t[ %u ]\n", - stats->an_rx_plcp_len_errs); - printf("RX MAC CRC errors:\t\t\t\t[ %u ]\n", - stats->an_rx_mac_crc_errs); - printf("RX MAC CRC OK:\t\t\t\t\t[ %u ]\n", - stats->an_rx_mac_crc_ok); - printf("RX WEP errors:\t\t\t\t\t[ %u ]\n", - stats->an_rx_wep_errs); - printf("RX WEP OK:\t\t\t\t\t[ %u ]\n", - stats->an_rx_wep_ok); - printf("Long retries:\t\t\t\t\t[ %u ]\n", - stats->an_retry_long); - printf("Short retries:\t\t\t\t\t[ %u ]\n", - stats->an_retry_short); - printf("Retries exhausted:\t\t\t\t[ %u ]\n", - stats->an_retry_max); - printf("Bad ACK:\t\t\t\t\t[ %u ]\n", - stats->an_no_ack); - printf("Bad CTS:\t\t\t\t\t[ %u ]\n", - stats->an_no_cts); - printf("RX good ACKs:\t\t\t\t\t[ %u ]\n", - stats->an_rx_ack_ok); - printf("RX good CTSs:\t\t\t\t\t[ %u ]\n", - stats->an_rx_cts_ok); - printf("TX good ACKs:\t\t\t\t\t[ %u ]\n", - stats->an_tx_ack_ok); - printf("TX good RTSs:\t\t\t\t\t[ %u ]\n", - stats->an_tx_rts_ok); - printf("TX good CTSs:\t\t\t\t\t[ %u ]\n", - stats->an_tx_cts_ok); - printf("LMAC multicasts transmitted:\t\t\t[ %u ]\n", - stats->an_tx_lmac_mcasts); - printf("LMAC broadcasts transmitted:\t\t\t[ %u ]\n", - stats->an_tx_lmac_bcasts); - printf("LMAC unicast frags transmitted:\t\t\t[ %u ]\n", - stats->an_tx_lmac_ucast_frags); - printf("LMAC unicasts transmitted:\t\t\t[ %u ]\n", - stats->an_tx_lmac_ucasts); - printf("Beacons transmitted:\t\t\t\t[ %u ]\n", - stats->an_tx_beacons); - printf("Beacons received:\t\t\t\t[ %u ]\n", - stats->an_rx_beacons); - printf("Single transmit collisions:\t\t\t[ %u ]\n", - stats->an_tx_single_cols); - printf("Multiple transmit collisions:\t\t\t[ %u ]\n", - stats->an_tx_multi_cols); - printf("Transmits without deferrals:\t\t\t[ %u ]\n", - stats->an_tx_defers_no); - printf("Transmits deferred due to protocol:\t\t[ %u ]\n", - stats->an_tx_defers_prot); - printf("Transmits deferred due to energy detect:\t\t[ %u ]\n", - stats->an_tx_defers_energy); - printf("RX duplicate frames/frags:\t\t\t[ %u ]\n", - stats->an_rx_dups); - printf("RX partial frames:\t\t\t\t[ %u ]\n", - stats->an_rx_partial); - printf("TX max lifetime exceeded:\t\t\t[ %u ]\n", - stats->an_tx_too_old); - printf("RX max lifetime exceeded:\t\t\t[ %u ]\n", - stats->an_tx_too_old); - printf("Sync lost due to too many missed beacons:\t[ %u ]\n", - stats->an_lostsync_missed_beacons); - printf("Sync lost due to ARL exceeded:\t\t\t[ %u ]\n", - stats->an_lostsync_arl_exceeded); - printf("Sync lost due to deauthentication:\t\t[ %u ]\n", - stats->an_lostsync_deauthed); - printf("Sync lost due to disassociation:\t\t[ %u ]\n", - stats->an_lostsync_disassociated); - printf("Sync lost due to excess change in TSF timing:\t[ %u ]\n", - stats->an_lostsync_tsf_timing); - printf("Host transmitted multicasts:\t\t\t[ %u ]\n", - stats->an_tx_host_mcasts); - printf("Host transmitted broadcasts:\t\t\t[ %u ]\n", - stats->an_tx_host_bcasts); - printf("Host transmitted unicasts:\t\t\t[ %u ]\n", - stats->an_tx_host_ucasts); - printf("Host transmission failures:\t\t\t[ %u ]\n", - stats->an_tx_host_failed); - printf("Host received multicasts:\t\t\t[ %u ]\n", - stats->an_rx_host_mcasts); - printf("Host received broadcasts:\t\t\t[ %u ]\n", - stats->an_rx_host_bcasts); - printf("Host received unicasts:\t\t\t\t[ %u ]\n", - stats->an_rx_host_ucasts); - printf("Host receive discards:\t\t\t\t[ %u ]\n", - stats->an_rx_host_discarded); - printf("HMAC transmitted multicasts:\t\t\t[ %u ]\n", - stats->an_tx_hmac_mcasts); - printf("HMAC transmitted broadcasts:\t\t\t[ %u ]\n", - stats->an_tx_hmac_bcasts); - printf("HMAC transmitted unicasts:\t\t\t[ %u ]\n", - stats->an_tx_hmac_ucasts); - printf("HMAC transmissions failed:\t\t\t[ %u ]\n", - stats->an_tx_hmac_failed); - printf("HMAC received multicasts:\t\t\t[ %u ]\n", - stats->an_rx_hmac_mcasts); - printf("HMAC received broadcasts:\t\t\t[ %u ]\n", - stats->an_rx_hmac_bcasts); - printf("HMAC received unicasts:\t\t\t\t[ %u ]\n", - stats->an_rx_hmac_ucasts); - printf("HMAC receive discards:\t\t\t\t[ %u ]\n", - stats->an_rx_hmac_discarded); - printf("HMAC transmits accepted:\t\t\t[ %u ]\n", - stats->an_tx_hmac_accepted); - printf("SSID mismatches:\t\t\t\t[ %u ]\n", - stats->an_ssid_mismatches); - printf("Access point mismatches:\t\t\t[ %u ]\n", - stats->an_ap_mismatches); - printf("Speed mismatches:\t\t\t\t[ %u ]\n", - stats->an_rates_mismatches); - printf("Authentication rejects:\t\t\t\t[ %u ]\n", - stats->an_auth_rejects); - printf("Authentication timeouts:\t\t\t[ %u ]\n", - stats->an_auth_timeouts); - printf("Association rejects:\t\t\t\t[ %u ]\n", - stats->an_assoc_rejects); - printf("Association timeouts:\t\t\t\t[ %u ]\n", - stats->an_assoc_timeouts); - printf("Management frames received:\t\t\t[ %u ]\n", - stats->an_rx_mgmt_pkts); - printf("Management frames transmitted:\t\t\t[ %u ]\n", - stats->an_tx_mgmt_pkts); - printf("Refresh frames received:\t\t\t[ %u ]\n", - stats->an_rx_refresh_pkts), - printf("Refresh frames transmitted:\t\t\t[ %u ]\n", - stats->an_tx_refresh_pkts), - printf("Poll frames received:\t\t\t\t[ %u ]\n", - stats->an_rx_poll_pkts); - printf("Poll frames transmitted:\t\t\t[ %u ]\n", - stats->an_tx_poll_pkts); - printf("Host requested sync losses:\t\t\t[ %u ]\n", - stats->an_lostsync_hostreq); - printf("Host transmitted bytes:\t\t\t\t[ %u ]\n", - stats->an_host_tx_bytes); - printf("Host received bytes:\t\t\t\t[ %u ]\n", - stats->an_host_rx_bytes); - printf("Uptime in microseconds:\t\t\t\t[ %u ]\n", - stats->an_uptime_usecs); - printf("Uptime in seconds:\t\t\t\t[ %u ]\n", - stats->an_uptime_secs); - printf("Sync lost due to better AP:\t\t\t[ %u ]\n", - stats->an_lostsync_better_ap); -} - -static void -an_dumpap(const char *iface) -{ - struct an_ltv_aplist *ap; - struct an_req areq; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_APLIST; - - an_getval(iface, &areq); - - ap = (struct an_ltv_aplist *)&areq; - printf("Access point 1:\t\t\t"); - an_printhex((char *)&ap->an_ap1, ETHER_ADDR_LEN); - printf("\nAccess point 2:\t\t\t"); - an_printhex((char *)&ap->an_ap2, ETHER_ADDR_LEN); - printf("\nAccess point 3:\t\t\t"); - an_printhex((char *)&ap->an_ap3, ETHER_ADDR_LEN); - printf("\nAccess point 4:\t\t\t"); - an_printhex((char *)&ap->an_ap4, ETHER_ADDR_LEN); - printf("\n"); - - return; -} - -static void -an_dumpssid(const char *iface) -{ - struct an_ltv_ssidlist_new *ssid; - struct an_req areq; - int i, max; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_SSIDLIST; - - an_getval(iface, &areq); - - max = (areq.an_len - 4) / sizeof(struct an_ltv_ssid_entry); - if ( max > MAX_SSIDS ) { - printf("Too many SSIDs only printing %d of %d\n", - MAX_SSIDS, max); - max = MAX_SSIDS; - } - ssid = (struct an_ltv_ssidlist_new *)&areq; - for (i = 0; i < max; i++) - printf("SSID %2d:\t\t\t[ %.*s ]\n", i + 1, - ssid->an_entry[i].an_len, - ssid->an_entry[i].an_ssid); - - return; -} - -static void -an_dumpconfig(const char *iface) -{ - struct an_ltv_genconfig *cfg; - struct an_req areq; - unsigned char diversity; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_ACTUALCFG; - - an_getval(iface, &areq); - - cfg = (struct an_ltv_genconfig *)&areq; - - printf("Operating mode:\t\t\t\t[ "); - if ((cfg->an_opmode & 0x7) == AN_OPMODE_IBSS_ADHOC) - printf("ad-hoc"); - if ((cfg->an_opmode & 0x7) == AN_OPMODE_INFRASTRUCTURE_STATION) - printf("infrastructure"); - if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP) - printf("access point"); - if ((cfg->an_opmode & 0x7) == AN_OPMODE_AP_REPEATER) - printf("access point repeater"); - printf(" ]"); - printf("\nReceive mode:\t\t\t\t[ "); - if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_MC_ADDR) - printf("broadcast/multicast/unicast"); - if ((cfg->an_rxmode & 0x7) == AN_RXMODE_BC_ADDR) - printf("broadcast/unicast"); - if ((cfg->an_rxmode & 0x7) == AN_RXMODE_ADDR) - printf("unicast"); - if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_CURBSS) - printf("802.11 monitor, current BSSID"); - if ((cfg->an_rxmode & 0x7) == AN_RXMODE_80211_MONITOR_ANYBSS) - printf("802.11 monitor, any BSSID"); - if ((cfg->an_rxmode & 0x7) == AN_RXMODE_LAN_MONITOR_CURBSS) - printf("LAN monitor, current BSSID"); - printf(" ]"); - printf("\nFragment threshold:\t\t\t"); - an_printwords(&cfg->an_fragthresh, 1); - printf("\nRTS threshold:\t\t\t\t"); - an_printwords(&cfg->an_rtsthresh, 1); - printf("\nMAC address:\t\t\t\t"); - an_printhex((char *)&cfg->an_macaddr, ETHER_ADDR_LEN); - printf("\nSupported rates:\t\t\t"); - an_printspeeds(cfg->an_rates, 8); - printf("\nShort retry limit:\t\t\t"); - an_printwords(&cfg->an_shortretry_limit, 1); - printf("\nLong retry limit:\t\t\t"); - an_printwords(&cfg->an_longretry_limit, 1); - printf("\nTX MSDU lifetime:\t\t\t"); - an_printwords(&cfg->an_tx_msdu_lifetime, 1); - printf("\nRX MSDU lifetime:\t\t\t"); - an_printwords(&cfg->an_rx_msdu_lifetime, 1); - printf("\nStationary:\t\t\t\t"); - an_printbool(cfg->an_stationary); - printf("\nOrdering:\t\t\t\t"); - an_printbool(cfg->an_ordering); - printf("\nDevice type:\t\t\t\t[ "); - if (cfg->an_devtype == AN_DEVTYPE_PC4500) - printf("PC4500"); - else if (cfg->an_devtype == AN_DEVTYPE_PC4800) - printf("PC4800"); - else - printf("unknown (%x)", cfg->an_devtype); - printf(" ]"); - printf("\nScanning mode:\t\t\t\t[ "); - if (cfg->an_scanmode == AN_SCANMODE_ACTIVE) - printf("active"); - if (cfg->an_scanmode == AN_SCANMODE_PASSIVE) - printf("passive"); - if (cfg->an_scanmode == AN_SCANMODE_AIRONET_ACTIVE) - printf("Aironet active"); - printf(" ]"); - printf("\nProbe delay:\t\t\t\t"); - an_printwords(&cfg->an_probedelay, 1); - printf("\nProbe energy timeout:\t\t\t"); - an_printwords(&cfg->an_probe_energy_timeout, 1); - printf("\nProbe response timeout:\t\t\t"); - an_printwords(&cfg->an_probe_response_timeout, 1); - printf("\nBeacon listen timeout:\t\t\t"); - an_printwords(&cfg->an_beacon_listen_timeout, 1); - printf("\nIBSS join network timeout:\t\t"); - an_printwords(&cfg->an_ibss_join_net_timeout, 1); - printf("\nAuthentication timeout:\t\t\t"); - an_printwords(&cfg->an_auth_timeout, 1); - printf("\nWEP enabled:\t\t\t\t[ "); - if (cfg->an_authtype & AN_AUTHTYPE_PRIVACY_IN_USE) - { - if (cfg->an_authtype & AN_AUTHTYPE_LEAP) - printf("LEAP"); - else if (cfg->an_authtype & AN_AUTHTYPE_ALLOW_UNENCRYPTED) - printf("mixed cell"); - else - printf("full"); - } - else - printf("no"); - printf(" ]"); - printf("\nAuthentication type:\t\t\t[ "); - if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_NONE) - printf("none"); - if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_OPEN) - printf("open"); - if ((cfg->an_authtype & AN_AUTHTYPE_MASK) == AN_AUTHTYPE_SHAREDKEY) - printf("shared key"); - printf(" ]"); - printf("\nAssociation timeout:\t\t\t"); - an_printwords(&cfg->an_assoc_timeout, 1); - printf("\nSpecified AP association timeout:\t"); - an_printwords(&cfg->an_specified_ap_timeout, 1); - printf("\nOffline scan interval:\t\t\t"); - an_printwords(&cfg->an_offline_scan_interval, 1); - printf("\nOffline scan duration:\t\t\t"); - an_printwords(&cfg->an_offline_scan_duration, 1); - printf("\nLink loss delay:\t\t\t"); - an_printwords(&cfg->an_link_loss_delay, 1); - printf("\nMax beacon loss time:\t\t\t"); - an_printwords(&cfg->an_max_beacon_lost_time, 1); - printf("\nRefresh interval:\t\t\t"); - an_printwords(&cfg->an_refresh_interval, 1); - printf("\nPower save mode:\t\t\t[ "); - if (cfg->an_psave_mode == AN_PSAVE_NONE) - printf("none"); - if (cfg->an_psave_mode == AN_PSAVE_CAM) - printf("constantly awake mode"); - if (cfg->an_psave_mode == AN_PSAVE_PSP) - printf("PSP"); - if (cfg->an_psave_mode == AN_PSAVE_PSP_CAM) - printf("PSP-CAM (fast PSP)"); - printf(" ]"); - printf("\nSleep through DTIMs:\t\t\t"); - an_printbool(cfg->an_sleep_for_dtims); - printf("\nPower save listen interval:\t\t"); - an_printwords(&cfg->an_listen_interval, 1); - printf("\nPower save fast listen interval:\t"); - an_printwords(&cfg->an_fast_listen_interval, 1); - printf("\nPower save listen decay:\t\t"); - an_printwords(&cfg->an_listen_decay, 1); - printf("\nPower save fast listen decay:\t\t"); - an_printwords(&cfg->an_fast_listen_decay, 1); - printf("\nAP/ad-hoc Beacon period:\t\t"); - an_printwords(&cfg->an_beacon_period, 1); - printf("\nAP/ad-hoc ATIM duration:\t\t"); - an_printwords(&cfg->an_atim_duration, 1); - printf("\nAP/ad-hoc current channel:\t\t"); - an_printwords(&cfg->an_ds_channel, 1); - printf("\nAP/ad-hoc DTIM period:\t\t\t"); - an_printwords(&cfg->an_dtim_period, 1); - printf("\nRadio type:\t\t\t\t[ "); - if (cfg->an_radiotype & AN_RADIOTYPE_80211_FH) - printf("802.11 FH"); - else if (cfg->an_radiotype & AN_RADIOTYPE_80211_DS) - printf("802.11 DS"); - else if (cfg->an_radiotype & AN_RADIOTYPE_LM2000_DS) - printf("LM2000 DS"); - else - printf("unknown (%x)", cfg->an_radiotype); - printf(" ]"); - printf("\nRX Diversity:\t\t\t\t[ "); - diversity = cfg->an_diversity & 0xFF; - if (diversity == AN_DIVERSITY_FACTORY_DEFAULT) - printf("factory default"); - else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY) - printf("antenna 1 only"); - else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY) - printf("antenna 2 only"); - else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2) - printf("antenna 1 and 2"); - printf(" ]"); - printf("\nTX Diversity:\t\t\t\t[ "); - diversity = (cfg->an_diversity >> 8) & 0xFF; - if (diversity == AN_DIVERSITY_FACTORY_DEFAULT) - printf("factory default"); - else if (diversity == AN_DIVERSITY_ANTENNA_1_ONLY) - printf("antenna 1 only"); - else if (diversity == AN_DIVERSITY_ANTENNA_2_ONLY) - printf("antenna 2 only"); - else if (diversity == AN_DIVERSITY_ANTENNA_1_AND_2) - printf("antenna 1 and 2"); - printf(" ]"); - printf("\nTransmit power level:\t\t\t"); - an_printwords(&cfg->an_tx_power, 1); - printf("\nRSS threshold:\t\t\t\t"); - an_printwords(&cfg->an_rss_thresh, 1); - printf("\nNode name:\t\t\t\t"); - an_printstr((char *)&cfg->an_nodename, 16); - printf("\nARL threshold:\t\t\t\t"); - an_printwords(&cfg->an_arl_thresh, 1); - printf("\nARL decay:\t\t\t\t"); - an_printwords(&cfg->an_arl_decay, 1); - printf("\nARL delay:\t\t\t\t"); - an_printwords(&cfg->an_arl_delay, 1); - printf("\nConfiguration:\t\t\t\t[ "); - if (cfg->an_home_product & AN_HOME_NETWORK) - printf("Home Configuration"); - else - printf("Enterprise Configuration"); - printf(" ]"); - - printf("\n"); - printf("\n"); - an_readkeyinfo(iface); -} - -static void -an_dumprssimap(const char *iface) -{ - struct an_ltv_rssi_map *rssi; - struct an_req areq; - int i; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_RSSI_MAP; - - an_getval(iface, &areq); - - rssi = (struct an_ltv_rssi_map *)&areq; - - printf("idx\tpct\t dBm\n"); - - for (i = 0; i < 0xFF; i++) { - /* - * negate the dBm value: it's the only way the power - * level makes sense - */ - printf("%3d\t%3d\t%4d\n", i, - rssi->an_entries[i].an_rss_pct, - - rssi->an_entries[i].an_rss_dbm); - } -} - -static void -usage(const char *p) -{ - fprintf(stderr, "usage: %s -i iface -A (show specified APs)\n", p); - fprintf(stderr, "\t%s -i iface -N (show specified SSIDss)\n", p); - fprintf(stderr, "\t%s -i iface -S (show NIC status)\n", p); - fprintf(stderr, "\t%s -i iface -I (show NIC capabilities)\n", p); - fprintf(stderr, "\t%s -i iface -T (show stats counters)\n", p); - fprintf(stderr, "\t%s -i iface -C (show current config)\n", p); - fprintf(stderr, "\t%s -i iface -R (show RSSI map)\n", p); - fprintf(stderr, "\t%s -i iface -t 0-4 (set TX speed)\n", p); - fprintf(stderr, "\t%s -i iface -s 0-3 (set power save mode)\n", p); - fprintf(stderr, "\t%s -i iface [-v 1-4] -a AP (specify AP)\n", p); - fprintf(stderr, "\t%s -i iface -b val (set beacon period)\n", p); - fprintf(stderr, "\t%s -i iface [-v 0|1] -d val (set diversity)\n", p); - fprintf(stderr, "\t%s -i iface -j val (set netjoin timeout)\n", p); - fprintf(stderr, "\t%s -i iface -e 0-4 (enable transmit key)\n", p); - fprintf(stderr, "\t%s -i iface [-v 0-8] -k key (set key)\n", p); - fprintf(stderr, "\t%s -i iface -K 0-2 (no auth/open/shared secret)\n", p); - fprintf(stderr, "\t%s -i iface -W 0-2 (no WEP/full WEP/mixed cell)\n", p); - fprintf(stderr, "\t%s -i iface -l val (set station name)\n", p); - fprintf(stderr, "\t%s -i iface -m val (set MAC address)\n", p); - fprintf(stderr, "\t%s -i iface [-v 1-3] -n SSID " - "(specify SSID)\n", p); - fprintf(stderr, "\t%s -i iface -o 0|1 (set operating mode)\n", p); - fprintf(stderr, "\t%s -i iface -c val (set ad-hoc channel)\n", p); - fprintf(stderr, "\t%s -i iface -f val (set frag threshold)\n", p); - fprintf(stderr, "\t%s -i iface -r val (set RTS threshold)\n", p); - fprintf(stderr, "\t%s -i iface -M 0-15 (set monitor mode)\n", p); - fprintf(stderr, "\t%s -i iface -L user (enter LEAP authentication mode)\n", p); -#ifdef ANCACHE - fprintf(stderr, "\t%s -i iface -Q print signal quality cache\n", p); - fprintf(stderr, "\t%s -i iface -Z zero out signal cache\n", p); -#endif - - fprintf(stderr, "\t%s -h (display this message)\n", p); - - exit(1); -} - -static void -an_setconfig(const char *iface, int act, void *arg) -{ - struct an_ltv_genconfig *cfg; - struct an_ltv_caps *caps; - struct an_req areq; - struct an_req areq_caps; - u_int16_t diversity = 0; - struct ether_addr *addr; - int i; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_GENCONFIG; - an_getval(iface, &areq); - cfg = (struct an_ltv_genconfig *)&areq; - - areq_caps.an_len = sizeof(areq); - areq_caps.an_type = AN_RID_CAPABILITIES; - an_getval(iface, &areq_caps); - caps = (struct an_ltv_caps *)&areq_caps; - - switch(act) { - case ACT_SET_OPMODE: - cfg->an_opmode = atoi(arg); - break; - case ACT_SET_FREQ: - cfg->an_ds_channel = atoi(arg); - break; - case ACT_SET_PWRSAVE: - cfg->an_psave_mode = atoi(arg); - break; - case ACT_SET_SCANMODE: - cfg->an_scanmode = atoi(arg); - break; - case ACT_SET_DIVERSITY_RX: - case ACT_SET_DIVERSITY_TX: - switch(atoi(arg)) { - case 0: - diversity = AN_DIVERSITY_FACTORY_DEFAULT; - break; - case 1: - diversity = AN_DIVERSITY_ANTENNA_1_ONLY; - break; - case 2: - diversity = AN_DIVERSITY_ANTENNA_2_ONLY; - break; - case 3: - diversity = AN_DIVERSITY_ANTENNA_1_AND_2; - break; - default: - errx(1, "bad diversity setting: %u", diversity); - break; - } - if (act == ACT_SET_DIVERSITY_RX) { - cfg->an_diversity &= 0xFF00; - cfg->an_diversity |= diversity; - } else { - cfg->an_diversity &= 0x00FF; - cfg->an_diversity |= (diversity << 8); - } - break; - case ACT_SET_TXPWR: - for (i = 0; i < 8; i++) { - if (caps->an_tx_powerlevels[i] == atoi(arg)) - break; - } - if (i == 8) - errx(1, "unsupported power level: %dmW", atoi(arg)); - - cfg->an_tx_power = atoi(arg); - break; - case ACT_SET_RTS_THRESH: - cfg->an_rtsthresh = atoi(arg); - break; - case ACT_SET_RTS_RETRYLIM: - cfg->an_shortretry_limit = - cfg->an_longretry_limit = atoi(arg); - break; - case ACT_SET_BEACON_PERIOD: - cfg->an_beacon_period = atoi(arg); - break; - case ACT_SET_WAKE_DURATION: - cfg->an_atim_duration = atoi(arg); - break; - case ACT_SET_FRAG_THRESH: - cfg->an_fragthresh = atoi(arg); - break; - case ACT_SET_NETJOIN: - cfg->an_ibss_join_net_timeout = atoi(arg); - break; - case ACT_SET_MYNAME: - bzero(cfg->an_nodename, 16); - strncpy((char *)&cfg->an_nodename, optarg, 16); - break; - case ACT_SET_MAC: - addr = ether_aton((char *)arg); - - if (addr == NULL) - errx(1, "badly formatted address"); - bzero(cfg->an_macaddr, ETHER_ADDR_LEN); - bcopy(addr, &cfg->an_macaddr, ETHER_ADDR_LEN); - break; - case ACT_ENABLE_WEP: - switch (atoi (arg)) { - case 0: - /* no WEP */ - cfg->an_authtype &= ~(AN_AUTHTYPE_PRIVACY_IN_USE - | AN_AUTHTYPE_ALLOW_UNENCRYPTED - | AN_AUTHTYPE_LEAP); - break; - case 1: - /* full WEP */ - cfg->an_authtype |= AN_AUTHTYPE_PRIVACY_IN_USE; - cfg->an_authtype &= ~AN_AUTHTYPE_ALLOW_UNENCRYPTED; - cfg->an_authtype &= ~AN_AUTHTYPE_LEAP; - break; - case 2: - /* mixed cell */ - cfg->an_authtype = AN_AUTHTYPE_PRIVACY_IN_USE - | AN_AUTHTYPE_ALLOW_UNENCRYPTED; - break; - } - break; - case ACT_SET_KEY_TYPE: - cfg->an_authtype = (cfg->an_authtype & ~AN_AUTHTYPE_MASK) - | atoi(arg); - break; - case ACT_SET_MONITOR_MODE: - areq.an_type = AN_RID_MONITOR_MODE; - cfg->an_len = atoi(arg); /* mode is put in length */ - break; - default: - errx(1, "unknown action"); - break; - } - - an_setval(iface, &areq); - exit(0); -} - -static void -an_setspeed(const char *iface, int act __unused, void *arg) -{ - struct an_req areq; - struct an_ltv_caps *caps; - u_int16_t speed; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_CAPABILITIES; - - an_getval(iface, &areq); - caps = (struct an_ltv_caps *)&areq; - - switch(atoi(arg)) { - case 0: - speed = 0; - break; - case 1: - speed = AN_RATE_1MBPS; - break; - case 2: - speed = AN_RATE_2MBPS; - break; - case 3: - if (caps->an_rates[2] != AN_RATE_5_5MBPS) - errx(1, "5.5Mbps not supported on this card"); - speed = AN_RATE_5_5MBPS; - break; - case 4: - if (caps->an_rates[3] != AN_RATE_11MBPS) - errx(1, "11Mbps not supported on this card"); - speed = AN_RATE_11MBPS; - break; - default: - errx(1, "unsupported speed"); - break; - } - - areq.an_len = 6; - areq.an_type = AN_RID_TX_SPEED; - areq.an_val[0] = speed; - - an_setval(iface, &areq); - exit(0); -} - -static void -an_setap(const char *iface, int act, void *arg) -{ - struct an_ltv_aplist *ap; - struct an_req areq; - struct ether_addr *addr; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_APLIST; - - an_getval(iface, &areq); - ap = (struct an_ltv_aplist *)&areq; - - addr = ether_aton((char *)arg); - - if (addr == NULL) - errx(1, "badly formatted address"); - - switch(act) { - case ACT_SET_AP1: - bzero(ap->an_ap1, ETHER_ADDR_LEN); - bcopy(addr, &ap->an_ap1, ETHER_ADDR_LEN); - break; - case ACT_SET_AP2: - bzero(ap->an_ap2, ETHER_ADDR_LEN); - bcopy(addr, &ap->an_ap2, ETHER_ADDR_LEN); - break; - case ACT_SET_AP3: - bzero(ap->an_ap3, ETHER_ADDR_LEN); - bcopy(addr, &ap->an_ap3, ETHER_ADDR_LEN); - break; - case ACT_SET_AP4: - bzero(ap->an_ap4, ETHER_ADDR_LEN); - bcopy(addr, &ap->an_ap4, ETHER_ADDR_LEN); - break; - default: - errx(1, "unknown action"); - break; - } - - an_setval(iface, &areq); - exit(0); -} - -static void -an_setssid(const char *iface, int act, void *arg) -{ - struct an_ltv_ssidlist_new *ssid; - struct an_req areq; - int max; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_SSIDLIST; - - an_getval(iface, &areq); - ssid = (struct an_ltv_ssidlist_new *)&areq; - - max = (areq.an_len - 4) / sizeof(struct an_ltv_ssid_entry); - if ( max > MAX_SSIDS ) { - printf("Too many SSIDs only printing %d of %d\n", - MAX_SSIDS, max); - max = MAX_SSIDS; - } - - if ( act > max ) { - errx(1, "bad modifier %d: there " - "are only %d SSID settings", act, max); - exit(1); - } - - bzero(ssid->an_entry[act-1].an_ssid, - sizeof(ssid->an_entry[act-1].an_ssid)); - strlcpy(ssid->an_entry[act-1].an_ssid, (char *)arg, - sizeof(ssid->an_entry[act-1].an_ssid)); - ssid->an_entry[act-1].an_len - = strlen(ssid->an_entry[act-1].an_ssid); - - an_setval(iface, &areq); - - exit(0); -} - -#ifdef ANCACHE -static void -an_zerocache(const char *iface) -{ - struct an_req areq; - - bzero(&areq, sizeof(areq)); - areq.an_len = 0; - areq.an_type = AN_RID_ZERO_CACHE; - - an_getval(iface, &areq); -} - -static void -an_readcache(const char *iface) -{ - struct an_req areq; - uint16_t *an_sigitems; - struct an_sigcache *sc; - int i; - - if (iface == NULL) - errx(1, "must specify interface name"); - - bzero(&areq, sizeof(areq)); - areq.an_len = AN_MAX_DATALEN; - areq.an_type = AN_RID_READ_CACHE; - - an_getval(iface, &areq); - - an_sigitems = areq.an_val; - sc = (struct an_sigcache *)((int32_t *)areq.an_val + 1); - - for (i = 0; i < *an_sigitems; i++) { - printf("[%d/%d]:", i+1, *an_sigitems); - printf(" %02x:%02x:%02x:%02x:%02x:%02x,", - sc->macsrc[0]&0xff, - sc->macsrc[1]&0xff, - sc->macsrc[2]&0xff, - sc->macsrc[3]&0xff, - sc->macsrc[4]&0xff, - sc->macsrc[5]&0xff); - printf(" %d.%d.%d.%d,",((sc->ipsrc >> 0) & 0xff), - ((sc->ipsrc >> 8) & 0xff), - ((sc->ipsrc >> 16) & 0xff), - ((sc->ipsrc >> 24) & 0xff)); - printf(" sig: %d, noise: %d, qual: %d\n", - sc->signal, - sc->noise, - sc->quality); - sc++; - } -} -#endif - -static int -an_hex2int(char c) -{ - if (c >= '0' && c <= '9') - return (c - '0'); - if (c >= 'A' && c <= 'F') - return (c - 'A' + 10); - if (c >= 'a' && c <= 'f') - return (c - 'a' + 10); - - return (0); -} - -static void -an_str2key(const char *s, struct an_ltv_key *k) -{ - int n, i; - char *p; - - /* Is this a hex string? */ - if (s[0] == '0' && (s[1] == 'x' || s[1] == 'X')) { - /* Yes, convert to int. */ - n = 0; - p = (char *)&k->key[0]; - for (i = 2; s[i] != '\0' && s[i + 1] != '\0'; i+= 2) { - *p++ = (an_hex2int(s[i]) << 4) + an_hex2int(s[i + 1]); - n++; - } - if (s[i] != '\0') - errx(1, "hex strings must be of even length"); - k->klen = n; - } else { - /* No, just copy it in. */ - bcopy(s, k->key, strlen(s)); - k->klen = strlen(s); - } - - return; -} - -static void -an_setkeys(const char *iface, const char *key, int keytype) -{ - struct an_req areq; - struct an_ltv_key *k; - - bzero(&areq, sizeof(areq)); - k = (struct an_ltv_key *)&areq; - - if (strlen(key) > 28) { - err(1, "encryption key must be no " - "more than 18 characters long"); - } - - an_str2key(key, k); - - k->kindex=keytype/2; - - if (!(k->klen==0 || k->klen==5 || k->klen==13)) { - err(1, "encryption key must be 0, 5 or 13 bytes long"); - } - - /* default mac and only valid one (from manual) 1.0.0.0.0.0 */ - k->mac[0]=1; - k->mac[1]=0; - k->mac[2]=0; - k->mac[3]=0; - k->mac[4]=0; - k->mac[5]=0; - - switch(keytype & 1) { - case 0: - areq.an_len = sizeof(struct an_ltv_key); - areq.an_type = AN_RID_WEP_PERM; - an_setval(iface, &areq); - break; - case 1: - areq.an_len = sizeof(struct an_ltv_key); - areq.an_type = AN_RID_WEP_TEMP; - an_setval(iface, &areq); - break; - } -} - -static void -an_readkeyinfo(const char *iface) -{ - struct an_req areq; - struct an_ltv_genconfig *cfg; - struct an_ltv_key *k; - int i; - int home; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_ACTUALCFG; - an_getval(iface, &areq); - cfg = (struct an_ltv_genconfig *)&areq; - if (cfg->an_home_product & AN_HOME_NETWORK) - home = 1; - else - home = 0; - - bzero(&areq, sizeof(areq)); - k = (struct an_ltv_key *)&areq; - - printf("WEP Key status:\n"); - areq.an_type = AN_RID_WEP_TEMP; /* read first key */ - for(i=0; i<5; i++) { - areq.an_len = sizeof(struct an_ltv_key); - an_getval(iface, &areq); - if (k->kindex == 0xffff) - break; - switch (k->klen) { - case 0: - printf("\tKey %u is unset\n", k->kindex); - break; - case 5: - printf("\tKey %u is set 40 bits\n", k->kindex); - break; - case 13: - printf("\tKey %u is set 128 bits\n", k->kindex); - break; - default: - printf("\tWEP Key %d has an unknown size %u\n", - i, k->klen); - } - - areq.an_type = AN_RID_WEP_PERM; /* read next key */ - } - k->kindex = 0xffff; - areq.an_len = sizeof(struct an_ltv_key); - an_getval(iface, &areq); - printf("\tThe active transmit key is %d\n", 4 * home + k->mac[0]); - - return; -} - -static void -an_enable_tx_key(const char *iface, const char *arg) -{ - struct an_req areq; - struct an_ltv_key *k; - struct an_ltv_genconfig *config; - - bzero(&areq, sizeof(areq)); - - /* set home or not home mode */ - areq.an_len = sizeof(struct an_ltv_genconfig); - areq.an_type = AN_RID_GENCONFIG; - an_getval(iface, &areq); - config = (struct an_ltv_genconfig *)&areq; - if (atoi(arg) == 4) { - config->an_home_product |= AN_HOME_NETWORK; - }else{ - config->an_home_product &= ~AN_HOME_NETWORK; - } - an_setval(iface, &areq); - - bzero(&areq, sizeof(areq)); - - k = (struct an_ltv_key *)&areq; - - /* From a Cisco engineer write the transmit key to use in the - first MAC, index is FFFF*/ - k->kindex=0xffff; - k->klen=0; - - k->mac[0]=atoi(arg); - k->mac[1]=0; - k->mac[2]=0; - k->mac[3]=0; - k->mac[4]=0; - k->mac[5]=0; - - areq.an_len = sizeof(struct an_ltv_key); - areq.an_type = AN_RID_WEP_PERM; - an_setval(iface, &areq); -} - -static void -an_enable_leap_mode(const char *iface, const char *username) -{ - struct an_req areq; - struct an_ltv_status *sts; - struct an_ltv_genconfig *cfg; - struct an_ltv_caps *caps; - struct an_ltv_leap_username an_username; - struct an_ltv_leap_password an_password; - char *password; - MD4_CTX context; - int len; - int i; - char unicode_password[LEAP_PASSWORD_MAX * 2]; - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_CAPABILITIES; - - an_getval(iface, &areq); - - caps = (struct an_ltv_caps *)&areq; - - if (!caps->an_softcaps & AN_AUTHTYPE_LEAP) { - fprintf(stderr, "Firmware does not support LEAP\n"); - exit(1); - } - - bzero(&an_username, sizeof(an_username)); - bzero(&an_password, sizeof(an_password)); - - len = strlen(username); - if (len > LEAP_USERNAME_MAX) { - printf("Username too long (max %d)\n", LEAP_USERNAME_MAX); - exit(1); - } - strncpy(an_username.an_username, username, len); - an_username.an_username_len = len; - an_username.an_len = sizeof(an_username); - an_username.an_type = AN_RID_LEAPUSERNAME; - - password = getpass("Enter LEAP password:"); - - len = strlen(password); - if (len > LEAP_PASSWORD_MAX) { - printf("Password too long (max %d)\n", LEAP_PASSWORD_MAX); - exit(1); - } - - bzero(&unicode_password, sizeof(unicode_password)); - for(i = 0; i < len; i++) { - unicode_password[i * 2] = *password++; - } - - /* First half */ - MD4Init(&context); - MD4Update(&context, unicode_password, len * 2); - MD4Final(&an_password.an_password[0], &context); - - /* Second half */ - MD4Init (&context); - MD4Update (&context, &an_password.an_password[0], 16); - MD4Final (&an_password.an_password[16], &context); - - an_password.an_password_len = 32; - an_password.an_len = sizeof(an_password); - an_password.an_type = AN_RID_LEAPPASSWORD; - - an_setval(iface, (struct an_req *)&an_username); - an_setval(iface, (struct an_req *)&an_password); - - areq.an_len = sizeof(areq); - areq.an_type = AN_RID_GENCONFIG; - an_getval(iface, &areq); - cfg = (struct an_ltv_genconfig *)&areq; - cfg->an_authtype = (AN_AUTHTYPE_PRIVACY_IN_USE | AN_AUTHTYPE_LEAP); - an_setval(iface, &areq); - - sts = (struct an_ltv_status *)&areq; - areq.an_type = AN_RID_STATUS; - - for (i = 60; i > 0; i--) { - an_getval(iface, &areq); - if (sts->an_opmode & AN_STATUS_OPMODE_LEAP) { - printf("Authenticated\n"); - break; - } - sleep(1); - } - - if (i == 0) { - fprintf(stderr, "Failed LEAP authentication\n"); - exit(1); - } -} - -int -main(int argc, char *argv[]) -{ - int ch; - int act = 0; - const char *iface = NULL; - int modifier = 0; - char *key = NULL; - void *arg = NULL; - char *p = argv[0]; - - /* Get the interface name */ - opterr = 0; - ch = getopt(argc, argv, "i:"); - if (ch == 'i') { - iface = optarg; - } else { - if (argc > 1 && *argv[1] != '-') { - iface = argv[1]; - optind = 2; - } else { - iface = "an0"; - optind = 1; - } - optreset = 1; - } - opterr = 1; - - while ((ch = getopt(argc, argv, - "ANISCTRht:a:e:o:s:n:v:d:j:b:c:f:r:p:w:m:l:k:K:W:QZM:L:")) != -1) { - switch(ch) { - case 'Z': -#ifdef ANCACHE - act = ACT_ZEROCACHE; -#else - errx(1, "ANCACHE not available"); -#endif - break; - case 'Q': -#ifdef ANCACHE - act = ACT_DUMPCACHE; -#else - errx(1, "ANCACHE not available"); -#endif - break; - case 'A': - act = ACT_DUMPAP; - break; - case 'N': - act = ACT_DUMPSSID; - break; - case 'S': - act = ACT_DUMPSTATUS; - break; - case 'I': - act = ACT_DUMPCAPS; - break; - case 'T': - act = ACT_DUMPSTATS; - break; - case 'C': - act = ACT_DUMPCONFIG; - break; - case 'R': - act = ACT_DUMPRSSIMAP; - break; - case 't': - act = ACT_SET_TXRATE; - arg = optarg; - break; - case 's': - act = ACT_SET_PWRSAVE; - arg = optarg; - break; - case 'p': - act = ACT_SET_TXPWR; - arg = optarg; - break; - case 'v': - modifier = atoi(optarg); - break; - case 'a': - switch(modifier) { - case 0: - case 1: - act = ACT_SET_AP1; - break; - case 2: - act = ACT_SET_AP2; - break; - case 3: - act = ACT_SET_AP3; - break; - case 4: - act = ACT_SET_AP4; - break; - default: - errx(1, "bad modifier %d: there " - "are only 4 access point settings", - modifier); - usage(p); - break; - } - arg = optarg; - break; - case 'b': - act = ACT_SET_BEACON_PERIOD; - arg = optarg; - break; - case 'd': - switch(modifier) { - case 0: - act = ACT_SET_DIVERSITY_RX; - break; - case 1: - act = ACT_SET_DIVERSITY_TX; - break; - default: - errx(1, "must specify RX or TX diversity"); - break; - } - if (!isdigit(*optarg)) { - errx(1, "%s is not numeric", optarg); - exit(1); - } - arg = optarg; - break; - case 'j': - act = ACT_SET_NETJOIN; - arg = optarg; - break; - case 'l': - act = ACT_SET_MYNAME; - arg = optarg; - break; - case 'm': - act = ACT_SET_MAC; - arg = optarg; - break; - case 'n': - if (modifier == 0) - modifier = 1; - act = ACT_SET_SSID; - arg = optarg; - break; - case 'o': - act = ACT_SET_OPMODE; - arg = optarg; - break; - case 'c': - act = ACT_SET_FREQ; - arg = optarg; - break; - case 'f': - act = ACT_SET_FRAG_THRESH; - arg = optarg; - break; - case 'W': - act = ACT_ENABLE_WEP; - arg = optarg; - break; - case 'K': - act = ACT_SET_KEY_TYPE; - arg = optarg; - break; - case 'k': - act = ACT_SET_KEYS; - key = optarg; - break; - case 'e': - act = ACT_ENABLE_TX_KEY; - arg = optarg; - break; - case 'q': - act = ACT_SET_RTS_RETRYLIM; - arg = optarg; - break; - case 'r': - act = ACT_SET_RTS_THRESH; - arg = optarg; - break; - case 'w': - act = ACT_SET_WAKE_DURATION; - arg = optarg; - break; - case 'M': - act = ACT_SET_MONITOR_MODE; - arg = optarg; - break; - case 'L': - act = ACT_SET_LEAP_MODE; - arg = optarg; - break; - case 'h': - default: - usage(p); - } - } - - if (iface == NULL || (!act && !key)) - usage(p); - - switch(act) { - case ACT_DUMPSTATUS: - an_dumpstatus(iface); - break; - case ACT_DUMPCAPS: - an_dumpcaps(iface); - break; - case ACT_DUMPSTATS: - an_dumpstats(iface); - break; - case ACT_DUMPCONFIG: - an_dumpconfig(iface); - break; - case ACT_DUMPSSID: - an_dumpssid(iface); - break; - case ACT_DUMPAP: - an_dumpap(iface); - break; - case ACT_DUMPRSSIMAP: - an_dumprssimap(iface); - break; - case ACT_SET_SSID: - an_setssid(iface, modifier, arg); - break; - case ACT_SET_AP1: - case ACT_SET_AP2: - case ACT_SET_AP3: - case ACT_SET_AP4: - an_setap(iface, act, arg); - break; - case ACT_SET_TXRATE: - an_setspeed(iface, act, arg); - break; -#ifdef ANCACHE - case ACT_ZEROCACHE: - an_zerocache(iface); - break; - case ACT_DUMPCACHE: - an_readcache(iface); - break; - -#endif - case ACT_SET_KEYS: - an_setkeys(iface, key, modifier); - break; - case ACT_ENABLE_TX_KEY: - an_enable_tx_key(iface, arg); - break; - case ACT_SET_LEAP_MODE: - an_enable_leap_mode(iface, arg); - break; - default: - an_setconfig(iface, act, arg); - break; - } - - exit(0); -} - diff --git a/usr.sbin/apm/Makefile b/usr.sbin/apm/Makefile deleted file mode 100644 index 3cc6f50..0000000 --- a/usr.sbin/apm/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= apm -MAN= apm.8 -MLINKS= apm.8 apmconf.8 -MANSUBDIR= /${MACHINE_CPUARCH} - -.include diff --git a/usr.sbin/apm/apm.8 b/usr.sbin/apm/apm.8 deleted file mode 100644 index 3e039b0..0000000 --- a/usr.sbin/apm/apm.8 +++ /dev/null @@ -1,153 +0,0 @@ -.\" LP (Laptop Package) -.\" -.\" Copyright (c) 1994 by Tatsumi Hosokawa -.\" -.\" This software may be used, modified, copied, and distributed, in -.\" both source and binary form provided that the above copyright and -.\" these terms are retained. Under no circumstances is the author -.\" responsible for the proper functioning of this software, nor does -.\" the author assume any responsibility for damages incurred with its -.\" use. -.\" -.\" $FreeBSD$ -.\" -.Dd December 22, 2009 -.Dt APM 8 i386 -.Os -.Sh NAME -.Nm apm -.Nd control the APM BIOS and display its information -.Sh SYNOPSIS -.Nm -.Op Fl ablstzZ -.Op Fl d Ar enable -.Op Fl e Ar enable -.Op Fl h Ar enable -.Op Fl r Ar delta -.Sh DESCRIPTION -The -.Nm -utility -controls the Intel / Microsoft APM (Advanced Power Management) BIOS and -displays the current status of APM on laptop PCs. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a -Display the current AC-line status as an integer value. -The values -0, 1 and 2 correspond to the -.Dq off-line -state, -.Dq on-line -state or -.Dq backup power -state, respectively. -.It Fl b -Display an integer value reflecting the current battery status. -The values 0, 1, 2, 3, correspond to the -.Dq high -status, -.Dq low -status, -.Dq critical -status, -.Dq charging -status respectively. -.It Fl d Ar enable -Disable/enable suspending of the display separately from a normal suspend -using the boolean value for -.Ar enable . -This feature seems to not work on many different laptops, -including the Libretto 30CT and 50CT. -.It Fl e Ar enable -Enable or disable APM functions of the computer, -depending on the boolean -.Ar enable -argument. -.It Fl h Ar enable -Depending on the boolean value of -.Ar enable , -enable or disable the HLT instruction in the kernel context switch routine. -These options are not necessary for almost all APM implementations, -but for some implementations whose -.Dq Pa Idle CPU -call executes both CPU clock slowdown and HLT instruction, -.Fl h Cm false -is necessary to prevent the system from reducing its peak performance. -See -.Xr apm 4 -for details. -.It Fl l -Display the remaining battery percentage. -If your laptop does not -support this function, 255 is displayed. -.It Fl r Ar delta -Enable the resume wakeup timer, if the laptop supports it. -This -does not actually suspend the laptop, but if the laptop is suspended, -and it supports resume from suspend, then it will be resumed after -.Ar delta -seconds (from when you run this command, not from when you suspend). -.It Fl s -Display the status of the APM support as an integer value. -The values -0 and 1 correspond to the -.Dq disabled -state or -.Dq enabled -state respectively. -.It Fl t -Display the estimated remaining battery lifetime in seconds. -If -it is unknown, -1 is displayed. -.It Fl Z -Transition the system into standby mode. -This mode uses less power than -full power mode, but more than suspend mode. -Some laptops support -resuming from this state on timer or Ring Indicator events. -The -output of -.Nm -tells what your laptop claims to support. -.It Fl z -Suspend the system. -It is used by -.Xr zzz 8 . -.El -.Pp -If no options are specified, -.Nm -displays information and current status of APM in verbose mode. -If multiple display options are given, the values are displayed one -per line in the order given here. -.Sh NOTES -.Xr apmconf 8 -has been merged in -.Nm -and thus -.Nm -replaces all of its functionality. -.Sh SEE ALSO -.Xr apm 4 , -.Xr zzz 8 -.Sh AUTHORS -.An Tatsumi Hosokawa Aq hosokawa@jp.FreeBSD.org -.Sh BUGS -Some APM implementations do not support parameters needed by -.Nm . -On such systems, -.Nm -displays them as unknown. -.Pp -Some APM implementations cannot handle events such as pushing the -power button or closing the cover. -On such implementations, the system -.Ar must -be suspended -.Ar only -by using -.Nm -or -.Nm zzz . diff --git a/usr.sbin/apm/apm.c b/usr.sbin/apm/apm.c deleted file mode 100644 index b4c34ab..0000000 --- a/usr.sbin/apm/apm.c +++ /dev/null @@ -1,490 +0,0 @@ -/* - * APM BIOS utility for FreeBSD - * - * Copyright (C) 1994-1996 by Tatsumi Hosokawa - * - * This software may be used, modified, copied, distributed, and sold, - * in both source and binary form provided that the above copyright and - * these terms are retained. Under no circumstances is the author - * responsible for the proper functioning of this software, nor does - * the author assume any responsibility for damages incurred with its - * use. - * - * Sep., 1994 Implemented on FreeBSD 1.1.5.1R (Toshiba AVS001WD) - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#define APMDEV "/dev/apm" - -#define APM_UNKNOWN 255 - -#define xh(a) (((a) & 0xff00) >> 8) -#define xl(a) ((a) & 0xff) -#define APMERR(a) xh(a) - -int cmos_wall = 0; /* True when wall time is in cmos clock, else UTC */ - -static void -usage(void) -{ - fprintf(stderr, - "usage: apm [-ablstzZ] [-d enable ] [ -e enable ] " - "[ -h enable ] [-r delta]\n"); - exit(1); -} - -/* - * Return 1 for boolean true, and 0 for false, according to the - * interpretation of the string argument given. - */ -static int -is_true(const char *boolean) -{ - char *endp; - long val; - - val = strtoul(boolean, &endp, 0); - if (*endp == '\0') - return (val != 0 ? 1 : 0); - if (strcasecmp(boolean, "true") == 0 || - strcasecmp(boolean, "yes") == 0 || - strcasecmp(boolean, "enable") == 0) - return (1); - if (strcasecmp(boolean, "false") == 0 || - strcasecmp(boolean, "no") == 0 || - strcasecmp(boolean, "disable") == 0) - return (0); - /* Well, I have no idea what the user wants, so... */ - warnx("invalid boolean argument \"%s\"", boolean); - usage(); - /* NOTREACHED */ - - return (0); -} - -static int -int2bcd(int i) -{ - int retval = 0; - int base = 0; - - if (i >= 10000) - return -1; - - while (i) { - retval |= (i % 10) << base; - i /= 10; - base += 4; - } - return retval; -} - -static int -bcd2int(int bcd) -{ - int retval = 0; - int place = 1; - - if (bcd > 0x9999) - return -1; - - while (bcd) { - retval += (bcd & 0xf) * place; - bcd >>= 4; - place *= 10; - } - return retval; -} - -static void -apm_suspend(int fd) -{ - if (ioctl(fd, APMIO_SUSPEND, NULL) == -1) - err(1, "ioctl(APMIO_SUSPEND)"); -} - -static void -apm_standby(int fd) -{ - if (ioctl(fd, APMIO_STANDBY, NULL) == -1) - err(1, "ioctl(APMIO_STANDBY)"); -} - -static void -apm_getinfo(int fd, apm_info_t aip) -{ - if (ioctl(fd, APMIO_GETINFO, aip) == -1) - err(1, "ioctl(APMIO_GETINFO)"); -} - -static void -apm_enable(int fd, int enable) -{ - if (enable) { - if (ioctl(fd, APMIO_ENABLE) == -1) - err(1, "ioctl(APMIO_ENABLE)"); - } else { - if (ioctl(fd, APMIO_DISABLE) == -1) - err(1, "ioctl(APMIO_DISABLE)"); - } -} - -static void -print_batt_time(int batt_time) -{ - printf("Remaining battery time: "); - if (batt_time == -1) - printf("unknown\n"); - else { - int h, m, s; - - h = batt_time; - s = h % 60; - h /= 60; - m = h % 60; - h /= 60; - printf("%2d:%02d:%02d\n", h, m, s); - } -} - -static void -print_batt_life(u_int batt_life) -{ - printf("Remaining battery life: "); - if (batt_life == APM_UNKNOWN) - printf("unknown\n"); - else if (batt_life <= 100) - printf("%d%%\n", batt_life); - else - printf("invalid value (0x%x)\n", batt_life); -} - -static void -print_batt_stat(u_int batt_stat) -{ - const char *batt_msg[] = { "high", "low", "critical", "charging" }; - - printf("Battery Status: "); - if (batt_stat == APM_UNKNOWN) - printf("unknown\n"); - else if (batt_stat > 3) - printf("invalid value (0x%x)\n", batt_stat); - else - printf("%s\n", batt_msg[batt_stat]); -} - -static void -print_all_info(int fd, apm_info_t aip, int bioscall_available) -{ - struct apm_bios_arg args; - int apmerr; - const char *line_msg[] = { "off-line", "on-line" , "backup power"}; - - printf("APM version: %d.%d\n", aip->ai_major, aip->ai_minor); - printf("APM Management: %s\n", aip->ai_status ? "Enabled" : "Disabled"); - printf("AC Line status: "); - if (aip->ai_acline == APM_UNKNOWN) - printf("unknown\n"); - else if (aip->ai_acline > 2) - printf("invalid value (0x%x)\n", aip->ai_acline); - else - printf("%s\n", line_msg[aip->ai_acline]); - - print_batt_stat(aip->ai_batt_stat); - print_batt_life(aip->ai_batt_life); - print_batt_time(aip->ai_batt_time); - - if (aip->ai_infoversion >= 1) { - printf("Number of batteries: "); - if (aip->ai_batteries == ~0U) - printf("unknown\n"); - else { - u_int i; - struct apm_pwstatus aps; - - printf("%d\n", aip->ai_batteries); - for (i = 0; i < aip->ai_batteries; ++i) { - bzero(&aps, sizeof(aps)); - aps.ap_device = PMDV_BATT0 + i; - if (ioctl(fd, APMIO_GETPWSTATUS, &aps) == -1) - continue; - printf("Battery %d:\n", i); - if (aps.ap_batt_flag & APM_BATT_NOT_PRESENT) { - printf("not present\n"); - continue; - } - printf("\t"); - print_batt_stat(aps.ap_batt_stat); - printf("\t"); - print_batt_life(aps.ap_batt_life); - printf("\t"); - print_batt_time(aps.ap_batt_time); - } - } - } - - if (bioscall_available) { - /* - * try to get the suspend timer - */ - bzero(&args, sizeof(args)); - args.eax = (APM_BIOS) << 8 | APM_RESUMETIMER; - args.ebx = PMDV_APMBIOS; - args.ecx = 0x0001; - if (ioctl(fd, APMIO_BIOS, &args)) { - printf("Resume timer: unknown\n"); - } else { - apmerr = APMERR(args.eax); - if (apmerr == 0x0d || apmerr == 0x86) - printf("Resume timer: disabled\n"); - else if (apmerr) - warnx( - "failed to get the resume timer: APM error0x%x", apmerr); - else { - /* - * OK. We have the time (all bcd). - * CH - seconds - * DH - hours - * DL - minutes - * xh(SI) - month (1-12) - * xl(SI) - day of month (1-31) - * DI - year - */ - struct tm tm; - char buf[1024]; - time_t t; - - tm.tm_sec = bcd2int(xh(args.ecx)); - tm.tm_min = bcd2int(xl(args.edx)); - tm.tm_hour = bcd2int(xh(args.edx)); - tm.tm_mday = bcd2int(xl(args.esi)); - tm.tm_mon = bcd2int(xh(args.esi)) - 1; - tm.tm_year = bcd2int(args.edi) - 1900; - if (cmos_wall) - t = mktime(&tm); - else - t = timegm(&tm); - if (t != -1) { - tm = *localtime(&t); - strftime(buf, sizeof(buf), "%c", &tm); - printf("Resume timer: %s\n", buf); - } else - printf("Resume timer: unknown\n"); - } - } - - /* - * Get the ring indicator resume state - */ - bzero(&args, sizeof(args)); - args.eax = (APM_BIOS) << 8 | APM_RESUMEONRING; - args.ebx = PMDV_APMBIOS; - args.ecx = 0x0002; - if (ioctl(fd, APMIO_BIOS, &args) == 0) { - printf("Resume on ring indicator: %sabled\n", - args.ecx ? "en" : "dis"); - } - } - - if (aip->ai_infoversion >= 1) { - if (aip->ai_capabilities == 0xff00) - return; - printf("APM Capabilities:\n"); - if (aip->ai_capabilities & 0x01) - printf("\tglobal standby state\n"); - if (aip->ai_capabilities & 0x02) - printf("\tglobal suspend state\n"); - if (aip->ai_capabilities & 0x04) - printf("\tresume timer from standby\n"); - if (aip->ai_capabilities & 0x08) - printf("\tresume timer from suspend\n"); - if (aip->ai_capabilities & 0x10) - printf("\tRI resume from standby\n"); - if (aip->ai_capabilities & 0x20) - printf("\tRI resume from suspend\n"); - if (aip->ai_capabilities & 0x40) - printf("\tPCMCIA RI resume from standby\n"); - if (aip->ai_capabilities & 0x80) - printf("\tPCMCIA RI resume from suspend\n"); - } - -} - -/* - * currently, it can turn off the display, but the display never comes - * back until the machine suspend/resumes :-). - */ -static void -apm_display(int fd, int newstate) -{ - if (ioctl(fd, APMIO_DISPLAY, &newstate) == -1) - err(1, "ioctl(APMIO_DISPLAY)"); -} - -static void -apm_haltcpu(int fd, int enable) -{ - if (enable) { - if (ioctl(fd, APMIO_HALTCPU, NULL) == -1) - err(1, "ioctl(APMIO_HALTCPU)"); - } else { - if (ioctl(fd, APMIO_NOTHALTCPU, NULL) == -1) - err(1, "ioctl(APMIO_NOTHALTCPU)"); - } -} - -static void -apm_set_timer(int fd, int delta) -{ - time_t tmr; - struct tm *tm; - struct apm_bios_arg args; - - tmr = time(NULL) + delta; - if (cmos_wall) - tm = localtime(&tmr); - else - tm = gmtime(&tmr); - bzero(&args, sizeof(args)); - args.eax = (APM_BIOS) << 8 | APM_RESUMETIMER; - args.ebx = PMDV_APMBIOS; - if (delta > 0) { - args.ecx = (int2bcd(tm->tm_sec) << 8) | 0x02; - args.edx = (int2bcd(tm->tm_hour) << 8) | int2bcd(tm->tm_min); - args.esi = (int2bcd(tm->tm_mon + 1) << 8) | int2bcd(tm->tm_mday); - args.edi = int2bcd(tm->tm_year + 1900); - } else { - args.ecx = 0x0000; - } - if (ioctl(fd, APMIO_BIOS, &args)) { - err(1,"set resume timer"); - } -} - -int -main(int argc, char *argv[]) -{ - int c, fd; - int dosleep = 0, all_info = 1, apm_status = 0, batt_status = 0; - int display = -1, batt_life = 0, ac_status = 0, standby = 0; - int batt_time = 0, delta = 0, enable = -1, haltcpu = -1; - int bioscall_available = 0; - size_t cmos_wall_len = sizeof(cmos_wall); - - if (sysctlbyname("machdep.wall_cmos_clock", &cmos_wall, &cmos_wall_len, - NULL, 0) == -1) - err(1, "sysctlbyname(machdep.wall_cmos_clock)"); - - while ((c = getopt(argc, argv, "abe:h:lRr:stzd:Z")) != -1) { - switch (c) { - case 'a': - ac_status = 1; - all_info = 0; - break; - case 'b': - batt_status = 1; - all_info = 0; - break; - case 'd': - display = is_true(optarg); - all_info = 0; - break; - case 'l': - batt_life = 1; - all_info = 0; - break; - case 'R': - delta = -1; - break; - case 'r': - delta = atoi(optarg); - break; - case 's': - apm_status = 1; - all_info = 0; - break; - case 'e': - enable = is_true(optarg); - all_info = 0; - break; - case 'h': - haltcpu = is_true(optarg); - all_info = 0; - break; - case 't': - batt_time = 1; - all_info = 0; - break; - case 'z': - dosleep = 1; - all_info = 0; - break; - case 'Z': - standby = 1; - all_info = 0; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - } - if (haltcpu != -1 || enable != -1 || display != -1 || delta || dosleep - || standby) { - fd = open(APMDEV, O_RDWR); - bioscall_available = 1; - } else if ((fd = open(APMDEV, O_RDWR)) >= 0) - bioscall_available = 1; - else - fd = open(APMDEV, O_RDONLY); - if (fd == -1) - err(1, "can't open %s", APMDEV); - if (enable != -1) - apm_enable(fd, enable); - if (haltcpu != -1) - apm_haltcpu(fd, haltcpu); - if (delta) - apm_set_timer(fd, delta); - if (dosleep) - apm_suspend(fd); - else if (standby) - apm_standby(fd); - else if (delta == 0) { - struct apm_info info; - - apm_getinfo(fd, &info); - if (all_info) - print_all_info(fd, &info, bioscall_available); - if (ac_status) - printf("%d\n", info.ai_acline); - if (batt_status) - printf("%d\n", info.ai_batt_stat); - if (batt_life) - printf("%d\n", info.ai_batt_life); - if (apm_status) - printf("%d\n", info.ai_status); - if (batt_time) - printf("%d\n", info.ai_batt_time); - if (display != -1) - apm_display(fd, display); - } - close(fd); - exit(0); -} diff --git a/usr.sbin/apmd/Makefile b/usr.sbin/apmd/Makefile deleted file mode 100644 index 9a0dc0d..0000000 --- a/usr.sbin/apmd/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# $FreeBSD$ - -PROG= apmd -MAN= apmd.8 -MANSUBDIR= /i386 -SRCS= apmd.c apmdlex.l apmdparse.y y.tab.h - -WARNS?= 3 - -DPADD= ${LIBL} -LDADD= -ll - -CFLAGS+= -I${.CURDIR} - -test: - ./apmd -d -f etc/apmd.conf -n - -.include diff --git a/usr.sbin/apmd/README b/usr.sbin/apmd/README deleted file mode 100644 index dd0a03a..0000000 --- a/usr.sbin/apmd/README +++ /dev/null @@ -1,213 +0,0 @@ -FreeBSD apmd Package Release Notes (19990711 version) - -1. What is "apmd"? -================== - -The apmd package provides a means of handling various APM events from -userland code. Using apmd.conf, the apmd(8) configuration file, you -can select the APM events to be handled from userland and specify the -commands for a given event, allowing APM behaviour to be configured -flexibly. - - -2. How to install the apmd package -================================== - -2.1 Making the apmd control device file ---------------------------------------- - -apmd(8) uses the new special device file /dev/apmctl. This should be -created as follows: - -# cd /dev -# mknod apmctl c 39 8 - -2.2 Applying the kernel patch and building a new kernel -------------------------------------------------------- - -The next step is to apply the patch against the sys source tree. -Go to the source directory (eg. /usr/src/ or /usr/PAO3/src/) and run -the patch command as follows: - -# gzip -cd [somewhere]/apmd-sys-R320.diff | patch - -For PAO3 users, the patch file name would be apmd-sys-PAO3.diff -instead of apmd-sys-R320.diff. After this step has completed -successfully, build and install a new kernel and reboot your system. - -2.3 Making the apmd program ---------------------------- - -Go to src/usr.sbin/ and extract the apmd tarball as follows: - -# tar xzpvf [somewhere]/apmd-usr.sbin.tar.gz - -Before doing a make all, you need to copy apm_bios.h in the sys source -tree to /usr/include/machine/ first: - -# cp /sys/i386/include/apm_bios.h /usr/include/machine/ - -Then do the build and install steps in the apmd directory: - -# cd src/usr.sbin/apmd -# make depend all install - -2.4 Setting up the configuration file and userland script ---------------------------------------------------------- - -In src/usr.sbin/apm/etc/ there are example configuration and userland -script files which are invoked automatically when the APM BIOS informs -apmd of an event, such as suspend request. Copy these files to -/etc/ as follows: - -# cp src/usr.sbin/apm/etc/* /etc/ - - -3. Running the apmd daemon program -================================== - -To run apmd(8) in background mode, simply type ``apmd''. - -# apmd - -To make a running apmd reload /etc/apmd.conf, send a SIGHUP signal to -the apmd(8) process. - -# kill -HUP [apmd pid] -or -# killall -HUP apmd - -apmd has some command line options. For the details, please -refer to the manpage of apmd. - -4. Configuration file -===================== - -The structure of the apmd configuration file is quite simple. For -example: - -apm_event SUSPENDREQ { - exec "sync && sync && sync"; - exec "sleep 1"; - exec "zzz"; -} - -Will cause apmd to receive the APM event SUSPENDREQ (which may be -posted by an LCD close), run the sync command 3 times and wait for a -while, then execute zzz (apm -z) to put the system in the suspend -state. - -4.1 The apm_event keyword -------------------------- -`apm_event' is the keyword which indicates the start of configuration for -each events. - -4.2 APM events --------------- - -If you wish to execute the same commands for different events, the -event names should be delimited by a comma. The following are valid -event names: - -o Events ignored by the kernel if apmd is running: - -STANDBYREQ -SUSPENDREQ -USERSUSPENDREQ -BATTERYLOW - -o Events passed to apmd after kernel handling: - -NORMRESUME -CRITRESUME -STANDBYRESUME -POWERSTATECHANGE -UPDATETIME - - -Other events will not be sent to apmd. - -4.3 command line syntax ------------------------ - -In the example above, the three lines beginning with `exec' are commands -for the event. Each line should be terminated with a semicolon. The -command list for the event should be enclosed by `{' and `}'. apmd(8) -uses /bin/sh for double-quotation enclosed command execution, just as -with system(3). Each command is executed in order until the end of -the list is reached or a command finishes with a non-zero status code. -apmd(8) will report any failed command's status code via syslog(3) -and will then reject the request event posted by APM BIOS. - -4.4 Built-in functions ----------------------- - -You can also specify apmd built-in functions instead of command lines. -A built-in function name should be terminated with a semicolon, just as -with a command line. -The following built-in functions are currently supported: - -o reject; - - Reject last request posted by the APM BIOS. This can be used to reject a - SUSPEND request when the LCD is closed and put the system in a STANDBY - state instead. - - - -5. EXAMPLES -=========== - -Sample configuration commands include: - -apm_event SUSPENDREQ { - exec "/etc/rc.suspend"; -} - -apm_event USERSUSPENDREQ { - exec "sync && sync && sync"; - exec "sleep 1"; - exec "apm -z"; -} - -apm_event NORMRESUME, STANDBYRESUME { - exec "/etc/rc.resume"; -} - -# resume event configuration for serial mouse users by -# reinitializing a moused(8) connected to a serial port. -# -#apm_event NORMRESUME { -# exec "kill -HUP `cat /var/run/moused.pid`"; -#} - -# suspend request event configuration for ATA HDD users: -# execute standby instead of suspend. -# -#apm_event SUSPENDREQ { -# reject; -# exec "sync && sync && sync"; -# exec "sleep 1"; -# exec "apm -Z"; -#} - - -6. Call for developers -====================== - -The initial version of apmd(8) was implemented primarily to test the -kernel support code and was ALPHA quality. Based on that code, the -current version was developed by KOIE Hidetaka . -However, we're still looking around for interesting new features and -ideas, so if you have any thoughts, please let us know. -Documentation is also sparse, and the manpage have just written. -If you wish to collaborate on this work, please e-mail me: -iwasaki@freebsd.org. - - -June 1, 1999 -Created by: iwasaki@FreeBSD.org -Edited by: jkh@FreeBSD.org - nick@foobar.org - -$FreeBSD$ diff --git a/usr.sbin/apmd/apmd.8 b/usr.sbin/apmd/apmd.8 deleted file mode 100644 index 4ca8aae..0000000 --- a/usr.sbin/apmd/apmd.8 +++ /dev/null @@ -1,322 +0,0 @@ -.\" Copyright (c) 1999 Mitsuru IWASAKI -.\" Copyright (c) 1999 KOIE Hidetaka -.\" Copyright (c) 1999 Yoshihiko SARUMARU Aq -.\" Copyright (c) 1999 Norihiro Kumagai -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)apmd.8 1.1 (FreeBSD) 6/28/99 -.\" $FreeBSD$ -.\" -.Dd June 28, 1999 -.Dt APMD 8 i386 -.Os -.Sh NAME -.Nm apmd -.Nd Advanced Power Management monitor daemon -.Sh SYNOPSIS -.Nm -.Op Fl d -.Op Fl f file -.Op Fl s -.Op Fl v -.Sh DESCRIPTION -The -.Nm -utility -monitors the occurrence of the specified Advanced Power Management -.Pq Tn APM -events and, if one of the events occurs, it executes the sequence of -commands corresponding to the event. -Only the events specified in the -configuration file are notified to -.Nm ; -all other events are ignored. -For each event posted by the APM BIOS, -.Nm -invokes the sequence of commands specified in the configuration file. -When -.Nm -is running with monitoring suspend/standby requests, -the kernel will not process those requests. -Therefore, if you wish action to be taken when these events -occur, you need to explicitly configure the appropriate commands or -built-in functions in the configuration file. -.Pp -The -.Nm -utility recognizes the following runtime options: -.Bl -tag -width -f_file -.It Fl d -Starts in debug mode. -This causes -.Nm -to execute in the foreground instead of in daemon mode. -.It Fl f Ar file -Specifies a different configuration file -.Ar file -to be used in place of the default -.Pa /etc/apmd.conf . -.It Fl s -Causes -.Nm -to simulate a POWERSTATECHANGE event when a power state change is detected -(AC_POWER_STATE) but the bios of the laptop does not report it. -This enables you to do things like dimming the LCD backlight when you unplug -the power cord. -.It Fl v -Verbose mode. -.El -.Pp -When -.Nm -starts, it reads the configuration file -.Pa ( /etc/apmd.conf -as default) -and notifies the set of events to be monitored to the APM device driver. -When it terminates, the APM device driver automatically cancels -monitored events. -.Pp -If the -.Nm -process receives a -.Dv SIGHUP , -it will reread its configuration file and -notify the APM device driver of any changes to its configuration. -.Pp -The -.Nm -utility uses the device -.Pa /dev/apmctl -to issue -.Xr ioctl 2 -requests for monitoring events and for controlling the APM system. -This device file is opened exclusively, so only a single -.Nm -process can be running at any time. -.Pp -When -.Nm -receives an APM event, it forks a child process to execute the -commands specified in the configuration file and then continues -listening for more events. -The child process executes the commands -specified, one at a time and in the order that they are listed. -.Pp -While -.Nm -is processing the command list for SUSPEND/STANDBY requests, the APM kernel -device driver issues notifications to APM BIOS once per second so that the -BIOS knows that there are still some commands pending, and that it should not -complete the request just yet. -.Pp -The -.Nm -utility creates the file -.Pa /var/run/apmd.pid , -and stores its process -id there. -This can be used to kill or reconfigure -.Nm . -.Sh CONFIGURATION FILE -The structure of the -.Nm -configuration file is quite simple. -For example: -.Bd -literal -apm_event SUSPENDREQ { - exec "sync && sync && sync"; - exec "sleep 1"; - exec "zzz"; -} -.Ed -.Pp -will cause -.Nm -to receive the APM event -.Ql SUSPENDREQ -(which may be posted by an LCD close), run the -.Ql sync -command 3 times and wait for a while, then execute -.Nm zzz ( Ns Nm apm Fl z ) -to put the system in the suspend state. -.Bl -bullet -.It -The apm_event keyword -.Bd -ragged -offset indent -.Ql apm_event -is the keyword which indicates the start of configuration for -each event. -.Ed -.It -APM events -.Bd -ragged -offset indent -If you wish to execute the same commands for different events, the -event names should be delimited by a comma. -The following are -valid event names: -.Bl -item -.It -- Events ignored by the kernel if -.Nm -is running: -.Pp -.Bl -tag -width USERSUSPENDREQ -compact -offset indent -.It STANDBYREQ -.It USERSTANDBYREQ -.It SUSPENDREQ -should include sync in the command list, -.It USERSUSPENDREQ -should include sync in the command list, -.It BATTERYLOW -only zzz should be specified in the command list. -.El -.It -- Events passed to -.Nm -after kernel handling: -.Pp -.Bl -tag -width USERSUSPENDREQ -compact -offset indent -.It NORMRESUME -.It CRITRESUME -.It STANDBYRESUME -.It POWERSTATECHANGE -.It UPDATETIME -.It CAPABILITIESCHANGE -.El -.Pp -Other events will not be sent to -.Nm . -.El -.Ed -.It -command line syntax -.Bd -ragged -offset indent -In the example above, the three lines beginning with -.Ql exec -are commands for the event. -Each line should be terminated with a semicolon. -The command list for the event should be enclosed by -.Ql { -and -.Ql } . -The -.Nm -utility uses -.Pa /bin/sh -for double-quotation enclosed command execution, just as with -.Xr system 3 . -Each command is executed in order until the end of -the list is reached or a command finishes with a non-zero status code. -The -.Nm -utility will report any failed command's status code via -.Xr syslog 3 -and will then reject the request event posted by the APM BIOS. -.Ed -.It -Built-in functions -.Bd -ragged -offset indent -You can also specify -.Nm -built-in functions instead of command lines. -A built-in function name should be terminated with a semicolon, -just as with a command line. -The following built-in functions are currently supported: -.Bl -item -.It -- reject: -.Bd -ragged -offset indent -Reject last request posted by APM BIOS. -This can be used to reject -a SUSPEND request when the LCD is closed and put the system in a -STANDBY state instead. -.Ed -.El -.Ed -.El -.Sh FILES -.Bl -tag -width /etc/apmd.conf -compact -.It Pa /etc/apmd.conf -.It Pa /dev/apmctl -.It Pa /var/run/apmd.pid -.El -.Sh EXAMPLES -Sample configuration commands include: -.Bd -literal -apm_event SUSPENDREQ { - exec "/etc/rc.suspend apm suspend"; -} - -apm_event USERSUSPENDREQ { - exec "sync && sync && sync"; - exec "sleep 1"; - exec "apm -z"; -} - -apm_event NORMRESUME { - exec "/etc/rc.resume apm suspend"; -} - -apm_event STANDBYRESUME { - exec "/etc/rc.resume apm standby"; -} - -# resume event configuration for serial mouse users by -# reinitializing a moused(8) connected to a serial port. -# -#apm_event NORMRESUME { -# exec "kill -HUP `cat /var/run/moused.pid`"; -#} -# -# suspend request event configuration for ATA HDD users: -# execute standby instead of suspend. -# -#apm_event SUSPENDREQ { -# reject; -# exec "sync && sync && sync"; -# exec "sleep 1"; -# exec "apm -Z"; -#} -.Ed -.Sh SEE ALSO -.Xr apm 4 , -.Xr apm 8 -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 3.3 . -.Sh AUTHORS -.An Mitsuru IWASAKI Aq iwasaki@FreeBSD.org -.An KOIE Hidetaka Aq koie@suri.co.jp -.Pp -.An -nosplit -Some contributions made by -.An Warner Losh Aq imp@FreeBSD.org , -.An Hiroshi Yamashita Aq bluemoon@msj.biglobe.ne.jp , -.An Yoshihiko SARUMARU Aq mistral@imasy.or.jp , -.An Norihiro Kumagai Aq kuma@nk.rim.or.jp , -.An NAKAGAWA Yoshihisa Aq nakagawa@jp.FreeBSD.org , -and -.An Nick Hilliard Aq nick@foobar.org . diff --git a/usr.sbin/apmd/apmd.c b/usr.sbin/apmd/apmd.c deleted file mode 100644 index 585383c..0000000 --- a/usr.sbin/apmd/apmd.c +++ /dev/null @@ -1,705 +0,0 @@ -/*- - * APM (Advanced Power Management) Event Dispatcher - * - * Copyright (c) 1999 Mitsuru IWASAKI - * Copyright (c) 1999 KOIE Hidetaka - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "apmd.h" - -int debug_level = 0; -int verbose = 0; -int soft_power_state_change = 0; -const char *apmd_configfile = APMD_CONFIGFILE; -const char *apmd_pidfile = APMD_PIDFILE; -int apmctl_fd = -1, apmnorm_fd = -1; - -/* - * table of event handlers - */ -#define EVENT_CONFIG_INITIALIZER(EV,R) { #EV, NULL, R }, -struct event_config events[EVENT_MAX] = { - EVENT_CONFIG_INITIALIZER(NOEVENT, 0) - EVENT_CONFIG_INITIALIZER(STANDBYREQ, 1) - EVENT_CONFIG_INITIALIZER(SUSPENDREQ, 1) - EVENT_CONFIG_INITIALIZER(NORMRESUME, 0) - EVENT_CONFIG_INITIALIZER(CRITRESUME, 0) - EVENT_CONFIG_INITIALIZER(BATTERYLOW, 0) - EVENT_CONFIG_INITIALIZER(POWERSTATECHANGE, 0) - EVENT_CONFIG_INITIALIZER(UPDATETIME, 0) - EVENT_CONFIG_INITIALIZER(CRITSUSPEND, 1) - EVENT_CONFIG_INITIALIZER(USERSTANDBYREQ, 1) - EVENT_CONFIG_INITIALIZER(USERSUSPENDREQ, 1) - EVENT_CONFIG_INITIALIZER(STANDBYRESUME, 0) - EVENT_CONFIG_INITIALIZER(CAPABILITIESCHANGE, 0) -}; - -/* - * List of battery events - */ -struct battery_watch_event *battery_watch_list = NULL; - -#define BATT_CHK_INTV 10 /* how many seconds between battery state checks? */ - -/* - * default procedure - */ -struct event_cmd * -event_cmd_default_clone(void *this) -{ - struct event_cmd * oldone = this; - struct event_cmd * newone = malloc(oldone->len); - - newone->next = NULL; - newone->len = oldone->len; - newone->name = oldone->name; - newone->op = oldone->op; - return newone; -} - -/* - * exec command - */ -int -event_cmd_exec_act(void *this) -{ - struct event_cmd_exec * p = this; - int status = -1; - pid_t pid; - - switch ((pid = fork())) { - case -1: - warn("cannot fork"); - break; - case 0: - /* child process */ - signal(SIGHUP, SIG_DFL); - signal(SIGCHLD, SIG_DFL); - signal(SIGTERM, SIG_DFL); - execl(_PATH_BSHELL, "sh", "-c", p->line, (char *)NULL); - _exit(127); - default: - /* parent process */ - do { - pid = waitpid(pid, &status, 0); - } while (pid == -1 && errno == EINTR); - break; - } - return status; -} -void -event_cmd_exec_dump(void *this, FILE *fp) -{ - fprintf(fp, " \"%s\"", ((struct event_cmd_exec *)this)->line); -} -struct event_cmd * -event_cmd_exec_clone(void *this) -{ - struct event_cmd_exec * newone = (struct event_cmd_exec *) event_cmd_default_clone(this); - struct event_cmd_exec * oldone = this; - - newone->evcmd.next = NULL; - newone->evcmd.len = oldone->evcmd.len; - newone->evcmd.name = oldone->evcmd.name; - newone->evcmd.op = oldone->evcmd.op; - if ((newone->line = strdup(oldone->line)) == NULL) - err(1, "out of memory"); - return (struct event_cmd *) newone; -} -void -event_cmd_exec_free(void *this) -{ - free(((struct event_cmd_exec *)this)->line); -} -struct event_cmd_op event_cmd_exec_ops = { - event_cmd_exec_act, - event_cmd_exec_dump, - event_cmd_exec_clone, - event_cmd_exec_free -}; - -/* - * reject command - */ -int -event_cmd_reject_act(void *this __unused) -{ - int rc = 0; - - if (ioctl(apmctl_fd, APMIO_REJECTLASTREQ, NULL)) { - syslog(LOG_NOTICE, "fail to reject\n"); - rc = -1; - } - return rc; -} -struct event_cmd_op event_cmd_reject_ops = { - event_cmd_reject_act, - NULL, - event_cmd_default_clone, - NULL -}; - -/* - * manipulate event_config - */ -struct event_cmd * -clone_event_cmd_list(struct event_cmd *p) -{ - struct event_cmd dummy; - struct event_cmd *q = &dummy; - for ( ;p; p = p->next) { - assert(p->op->clone); - if ((q->next = p->op->clone(p)) == NULL) - err(1, "out of memory"); - q = q->next; - } - q->next = NULL; - return dummy.next; -} -void -free_event_cmd_list(struct event_cmd *p) -{ - struct event_cmd * q; - for ( ; p ; p = q) { - q = p->next; - if (p->op->free) - p->op->free(p); - free(p); - } -} -int -register_battery_handlers( - int level, int direction, - struct event_cmd *cmdlist) -{ - /* - * level is negative if it's in "minutes", non-negative if - * percentage. - * - * direction =1 means we care about this level when charging, - * direction =-1 means we care about it when discharging. - */ - if (level>100) /* percentage > 100 */ - return -1; - if (abs(direction) != 1) /* nonsense direction value */ - return -1; - - if (cmdlist) { - struct battery_watch_event *we; - - if ((we = malloc(sizeof(struct battery_watch_event))) == NULL) - err(1, "out of memory"); - - we->next = battery_watch_list; /* starts at NULL */ - battery_watch_list = we; - we->level = abs(level); - we->type = (level<0)?BATTERY_MINUTES:BATTERY_PERCENT; - we->direction = (direction<0)?BATTERY_DISCHARGING: - BATTERY_CHARGING; - we->done = 0; - we->cmdlist = clone_event_cmd_list(cmdlist); - } - return 0; -} -int -register_apm_event_handlers( - bitstr_t bit_decl(evlist, EVENT_MAX), - struct event_cmd *cmdlist) -{ - if (cmdlist) { - bitstr_t bit_decl(tmp, EVENT_MAX); - memcpy(&tmp, evlist, bitstr_size(EVENT_MAX)); - - for (;;) { - int n; - struct event_cmd *p; - struct event_cmd *q; - bit_ffs(tmp, EVENT_MAX, &n); - if (n < 0) - break; - p = events[n].cmdlist; - if ((q = clone_event_cmd_list(cmdlist)) == NULL) - err(1, "out of memory"); - if (p) { - while (p->next != NULL) - p = p->next; - p->next = q; - } else { - events[n].cmdlist = q; - } - bit_clear(tmp, n); - } - } - return 0; -} - -/* - * execute command - */ -int -exec_run_cmd(struct event_cmd *p) -{ - int status = 0; - - for (; p; p = p->next) { - assert(p->op->act); - if (verbose) - syslog(LOG_INFO, "action: %s", p->name); - status = p->op->act(p); - if (status) { - syslog(LOG_NOTICE, "command finished with %d\n", status); - break; - } - } - return status; -} - -/* - * execute command -- the event version - */ -int -exec_event_cmd(struct event_config *ev) -{ - int status = 0; - - status = exec_run_cmd(ev->cmdlist); - if (status && ev->rejectable) { - syslog(LOG_ERR, "canceled"); - event_cmd_reject_act(NULL); - } - return status; -} - -/* - * read config file - */ -extern FILE * yyin; -extern int yydebug; - -void -read_config(void) -{ - int i; - - if ((yyin = fopen(apmd_configfile, "r")) == NULL) { - err(1, "cannot open config file"); - } - -#ifdef DEBUG - yydebug = debug_level; -#endif - - if (yyparse() != 0) - err(1, "cannot parse config file"); - - fclose(yyin); - - /* enable events */ - for (i = 0; i < EVENT_MAX; i++) { - if (events[i].cmdlist) { - u_int event_type = i; - if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) { - err(1, "cannot enable event 0x%x", event_type); - } - } - } -} - -void -dump_config(void) -{ - int i; - struct battery_watch_event *q; - - for (i = 0; i < EVENT_MAX; i++) { - struct event_cmd * p; - if ((p = events[i].cmdlist)) { - fprintf(stderr, "apm_event %s {\n", events[i].name); - for ( ; p ; p = p->next) { - fprintf(stderr, "\t%s", p->name); - if (p->op->dump) - p->op->dump(p, stderr); - fprintf(stderr, ";\n"); - } - fprintf(stderr, "}\n"); - } - } - for (q = battery_watch_list ; q != NULL ; q = q -> next) { - struct event_cmd * p; - fprintf(stderr, "apm_battery %d%s %s {\n", - q -> level, - (q -> type == BATTERY_PERCENT)?"%":"m", - (q -> direction == BATTERY_CHARGING)?"charging": - "discharging"); - for ( p = q -> cmdlist; p ; p = p->next) { - fprintf(stderr, "\t%s", p->name); - if (p->op->dump) - p->op->dump(p, stderr); - fprintf(stderr, ";\n"); - } - fprintf(stderr, "}\n"); - } -} - -void -destroy_config(void) -{ - int i; - struct battery_watch_event *q; - - /* disable events */ - for (i = 0; i < EVENT_MAX; i++) { - if (events[i].cmdlist) { - u_int event_type = i; - if (write(apmctl_fd, &event_type, sizeof(u_int)) == -1) { - err(1, "cannot disable event 0x%x", event_type); - } - } - } - - for (i = 0; i < EVENT_MAX; i++) { - struct event_cmd * p; - if ((p = events[i].cmdlist)) - free_event_cmd_list(p); - events[i].cmdlist = NULL; - } - - for( ; battery_watch_list; battery_watch_list = battery_watch_list -> next) { - free_event_cmd_list(battery_watch_list->cmdlist); - q = battery_watch_list->next; - free(battery_watch_list); - battery_watch_list = q; - } -} - -void -restart(void) -{ - destroy_config(); - read_config(); - if (verbose) - dump_config(); -} - -/* - * write pid file - */ -static void -write_pid(void) -{ - FILE *fp = fopen(apmd_pidfile, "w"); - - if (fp) { - fprintf(fp, "%ld\n", (long)getpid()); - fclose(fp); - } -} - -/* - * handle signals - */ -static int signal_fd[2]; - -void -enque_signal(int sig) -{ - if (write(signal_fd[1], &sig, sizeof sig) != sizeof sig) - err(1, "cannot process signal."); -} - -void -wait_child(void) -{ - int status; - while (waitpid(-1, &status, WNOHANG) > 0) - ; -} - -int -proc_signal(int fd) -{ - int rc = 0; - int sig; - - while (read(fd, &sig, sizeof sig) == sizeof sig) { - syslog(LOG_INFO, "caught signal: %d", sig); - switch (sig) { - case SIGHUP: - syslog(LOG_NOTICE, "restart by SIG"); - restart(); - break; - case SIGTERM: - syslog(LOG_NOTICE, "going down on signal %d", sig); - rc = -1; - return rc; - case SIGCHLD: - wait_child(); - break; - default: - warn("unexpected signal(%d) received.", sig); - break; - } - } - return rc; -} -void -proc_apmevent(int fd) -{ - struct apm_event_info apmevent; - - while (ioctl(fd, APMIO_NEXTEVENT, &apmevent) == 0) { - int status; - syslog(LOG_NOTICE, "apmevent %04x index %d\n", - apmevent.type, apmevent.index); - syslog(LOG_INFO, "apm event: %s", events[apmevent.type].name); - if (fork() == 0) { - status = exec_event_cmd(&events[apmevent.type]); - exit(status); - } - } -} - -#define AC_POWER_STATE ((pw_info.ai_acline == 1) ? BATTERY_CHARGING :\ - BATTERY_DISCHARGING) - -void -check_battery(void) -{ - - static int first_time=1, last_state; - int status; - - struct apm_info pw_info; - struct battery_watch_event *p; - - /* If we don't care, don't bother */ - if (battery_watch_list == NULL) - return; - - if (first_time) { - if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0) - err(1, "cannot check battery state."); -/* - * This next statement isn't entirely true. The spec does not tie AC - * line state to battery charging or not, but this is a bit lazier to do. - */ - last_state = AC_POWER_STATE; - first_time = 0; - return; /* We can't process events, we have no baseline */ - } - - /* - * XXX - should we do this a bunch of times and perform some sort - * of smoothing or correction? - */ - if ( ioctl(apmnorm_fd, APMIO_GETINFO, &pw_info) < 0) - err(1, "cannot check battery state."); - - /* - * If we're not in the state now that we were in last time, - * then it's a transition, which means we must clean out - * the event-caught state. - */ - if (last_state != AC_POWER_STATE) { - if (soft_power_state_change && fork() == 0) { - status = exec_event_cmd(&events[PMEV_POWERSTATECHANGE]); - exit(status); - } - last_state = AC_POWER_STATE; - for (p = battery_watch_list ; p!=NULL ; p = p -> next) - p->done = 0; - } - for (p = battery_watch_list ; p != NULL ; p = p -> next) - if (p -> direction == AC_POWER_STATE && - !(p -> done) && - ((p -> type == BATTERY_PERCENT && - p -> level == (int)pw_info.ai_batt_life) || - (p -> type == BATTERY_MINUTES && - p -> level == (pw_info.ai_batt_time / 60)))) { - p -> done++; - if (verbose) - syslog(LOG_NOTICE, "Caught battery event: %s, %d%s", - (p -> direction == BATTERY_CHARGING)?"charging":"discharging", - p -> level, - (p -> type == BATTERY_PERCENT)?"%":" minutes"); - if (fork() == 0) { - status = exec_run_cmd(p -> cmdlist); - exit(status); - } - } -} -void -event_loop(void) -{ - int fdmax = 0; - struct sigaction nsa; - fd_set master_rfds; - sigset_t sigmask, osigmask; - - FD_ZERO(&master_rfds); - FD_SET(apmctl_fd, &master_rfds); - fdmax = apmctl_fd > fdmax ? apmctl_fd : fdmax; - - FD_SET(signal_fd[0], &master_rfds); - fdmax = signal_fd[0] > fdmax ? signal_fd[0] : fdmax; - - memset(&nsa, 0, sizeof nsa); - nsa.sa_handler = enque_signal; - sigfillset(&nsa.sa_mask); - nsa.sa_flags = SA_RESTART; - sigaction(SIGHUP, &nsa, NULL); - sigaction(SIGCHLD, &nsa, NULL); - sigaction(SIGTERM, &nsa, NULL); - - sigemptyset(&sigmask); - sigaddset(&sigmask, SIGHUP); - sigaddset(&sigmask, SIGCHLD); - sigaddset(&sigmask, SIGTERM); - sigprocmask(SIG_SETMASK, &sigmask, &osigmask); - - while (1) { - fd_set rfds; - int res; - struct timeval to; - - to.tv_sec = BATT_CHK_INTV; - to.tv_usec = 0; - - memcpy(&rfds, &master_rfds, sizeof rfds); - sigprocmask(SIG_SETMASK, &osigmask, NULL); - if ((res=select(fdmax + 1, &rfds, 0, 0, &to)) < 0) { - if (errno != EINTR) - err(1, "select"); - } - sigprocmask(SIG_SETMASK, &sigmask, NULL); - - if (res == 0) { /* time to check the battery */ - check_battery(); - continue; - } - - if (FD_ISSET(signal_fd[0], &rfds)) { - if (proc_signal(signal_fd[0]) < 0) - return; - } - - if (FD_ISSET(apmctl_fd, &rfds)) - proc_apmevent(apmctl_fd); - } -} - -int -main(int ac, char* av[]) -{ - int ch; - int daemonize = 1; - char *prog; - int logopt = LOG_NDELAY | LOG_PID; - - while ((ch = getopt(ac, av, "df:sv")) != -1) { - switch (ch) { - case 'd': - daemonize = 0; - debug_level++; - break; - case 'f': - apmd_configfile = optarg; - break; - case 's': - soft_power_state_change = 1; - break; - case 'v': - verbose = 1; - break; - default: - err(1, "unknown option `%c'", ch); - } - } - - if (daemonize) - daemon(0, 0); - -#ifdef NICE_INCR - nice(NICE_INCR); -#endif - - if (!daemonize) - logopt |= LOG_PERROR; - - prog = strrchr(av[0], '/'); - openlog(prog ? prog+1 : av[0], logopt, LOG_DAEMON); - - syslog(LOG_NOTICE, "start"); - - if (pipe(signal_fd) < 0) - err(1, "pipe"); - if (fcntl(signal_fd[0], F_SETFL, O_NONBLOCK) < 0) - err(1, "fcntl"); - - if ((apmnorm_fd = open(APM_NORM_DEVICEFILE, O_RDWR)) == -1) { - err(1, "cannot open device file `%s'", APM_NORM_DEVICEFILE); - } - - if (fcntl(apmnorm_fd, F_SETFD, 1) == -1) { - err(1, "cannot set close-on-exec flag for device file '%s'", APM_NORM_DEVICEFILE); - } - - if ((apmctl_fd = open(APM_CTL_DEVICEFILE, O_RDWR)) == -1) { - err(1, "cannot open device file `%s'", APM_CTL_DEVICEFILE); - } - - if (fcntl(apmctl_fd, F_SETFD, 1) == -1) { - err(1, "cannot set close-on-exec flag for device file '%s'", APM_CTL_DEVICEFILE); - } - - restart(); - write_pid(); - event_loop(); - exit(EXIT_SUCCESS); -} - diff --git a/usr.sbin/apmd/apmd.h b/usr.sbin/apmd/apmd.h deleted file mode 100644 index d379feb..0000000 --- a/usr.sbin/apmd/apmd.h +++ /dev/null @@ -1,133 +0,0 @@ -/*- - * APM (Advanced Power Management) Event Dispatcher - * - * Copyright (c) 1999 Mitsuru IWASAKI - * Copyright (c) 1999 KOIE Hidetaka - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#define APMD_CONFIGFILE "/etc/apmd.conf" -#define APM_CTL_DEVICEFILE "/dev/apmctl" -#define APM_NORM_DEVICEFILE "/dev/apm" -#define APMD_PIDFILE "/var/run/apmd.pid" -#define NICE_INCR -20 - -enum { - EVENT_NOEVENT, - EVENT_STANDBYREQ, - EVENT_SUSPENDREQ, - EVENT_NORMRESUME, - EVENT_CRITRESUME, - EVENT_BATTERYLOW, - EVENT_POWERSTATECHANGE, - EVENT_UPDATETIME, - EVENT_CRITSUSPEND, - EVENT_USERSTANDBYREQ, - EVENT_USERSUSPENDREQ, - EVENT_STANDBYRESUME, - EVENT_CAPABILITIESCHANGE, - EVENT_MAX -}; - -struct event_cmd_op { - int (* act)(void *this); - void (* dump)(void *this, FILE * fp); - struct event_cmd * (* clone)(void *this); - void (* free)(void *this); -}; -struct event_cmd { - struct event_cmd * next; - size_t len; - char * name; - struct event_cmd_op * op; -}; -struct event_cmd_exec { - struct event_cmd evcmd; - char * line; /* Command line */ -}; -struct event_cmd_reject { - struct event_cmd evcmd; -}; - -struct event_config { - const char *name; - struct event_cmd * cmdlist; - int rejectable; -}; - -struct battery_watch_event { - struct battery_watch_event *next; - int level; - enum { - BATTERY_CHARGING, - BATTERY_DISCHARGING - } direction; - enum { - BATTERY_MINUTES, - BATTERY_PERCENT - } type; - int done; - struct event_cmd *cmdlist; -}; - - -extern struct event_cmd_op event_cmd_exec_ops; -extern struct event_cmd_op event_cmd_reject_ops; -extern struct event_config events[EVENT_MAX]; -extern struct battery_watch_event *battery_watch_list; - -extern int register_battery_handlers( - int level, int direction, - struct event_cmd *cmdlist); -extern int register_apm_event_handlers( - bitstr_t bit_decl(evlist, EVENT_MAX), - struct event_cmd *cmdlist); -extern void free_event_cmd_list(struct event_cmd *p); - -extern int yyparse(void); - -void yyerror(const char *); -int yylex(void); - -struct event_cmd *event_cmd_default_clone(void *); -int event_cmd_exec_act(void *); -void event_cmd_exec_dump(void *, FILE *); -struct event_cmd *event_cmd_exec_clone(void *); -void event_cmd_exec_free(void *); -int event_cmd_reject_act(void *); -struct event_cmd *clone_event_cmd_list(struct event_cmd *); -int exec_run_cmd(struct event_cmd *); -int exec_event_cmd(struct event_config *); -void read_config(void); -void dump_config(void); -void destroy_config(void); -void restart(void); -void enque_signal(int); -void wait_child(void); -int proc_signal(int); -void proc_apmevent(int); -void check_battery(void); -void event_loop(void); diff --git a/usr.sbin/apmd/apmdlex.l b/usr.sbin/apmd/apmdlex.l deleted file mode 100644 index 0f95574..0000000 --- a/usr.sbin/apmd/apmdlex.l +++ /dev/null @@ -1,115 +0,0 @@ -%{ -/*- - * APM (Advanced Power Management) Event Dispatcher - * - * Copyright (c) 1999 Mitsuru IWASAKI - * Copyright (c) 1999 KOIE Hidetaka - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include "apmd.h" -#include "y.tab.h" - -/* We don't need it, avoid the warning. */ -#define YY_NO_UNPUT - -int lineno; -int first_time; -%} - -%s TOP - -%% - -%{ - if (first_time) { - BEGIN TOP; - lineno = 1; - first_time = 0; - } -%} - -[ \t]+ ; -\n lineno++; -, { return COMMA; } -; { return SEMICOLON; } -#.*$ ; - -apm_event { return APMEVENT; } - -NOEVENT { yylval.ev = EVENT_NOEVENT; return EVENT; } -STANDBYREQ { yylval.ev = EVENT_STANDBYREQ; return EVENT; } -SUSPENDREQ { yylval.ev = EVENT_SUSPENDREQ; return EVENT; } -NORMRESUME { yylval.ev = EVENT_NORMRESUME; return EVENT; } -CRITRESUME { yylval.ev = EVENT_CRITRESUME; return EVENT; } -BATTERYLOW { yylval.ev = EVENT_BATTERYLOW; return EVENT; } -POWERSTATECHANGE { yylval.ev = EVENT_POWERSTATECHANGE; return EVENT; } -UPDATETIME { yylval.ev = EVENT_UPDATETIME; return EVENT; } -CRITSUSPEND { yylval.ev = EVENT_CRITSUSPEND; return EVENT; } -USERSTANDBYREQ { yylval.ev = EVENT_USERSTANDBYREQ; return EVENT; } -USERSUSPENDREQ { yylval.ev = EVENT_USERSUSPENDREQ; return EVENT; } -STANDBYRESUME { yylval.ev = EVENT_STANDBYRESUME; return EVENT; } -CAPABILITIESCHANGE { yylval.ev = EVENT_CAPABILITIESCHANGE; return EVENT; } - -apm_battery { return APMBATT; } - -charging { return BATTCHARGE; } -discharging { return BATTDISCHARGE; } -[0-9]+% { - yylval.i = atoi(yytext); - return BATTPERCENT; - } -[0-9]+[Mm] { - yylval.i = -atoi(yytext); - return BATTTIME; - } - -exec { return EXECCMD; } -reject { return REJECTCMD; } - -\{ { return BEGINBLOCK; } -\} { return ENDBLOCK; } -\"[^"]+\" { - int len = strlen(yytext) - 2; - if ((yylval.str = (char *) malloc(len + 1)) == NULL) - goto out; - memcpy(yylval.str, yytext + 1, len); - yylval.str[len] = '\0'; - out: - return STRING; - } - -[^"{},;#\n\t ]+ { yylval.str = strdup(yytext); return UNKNOWN; } -%% - -void -yyerror(const char *s) -{ - syslog(LOG_ERR, "line %d: %s%s %s.\n", lineno, yytext, yytext?":":"", s); -} diff --git a/usr.sbin/apmd/apmdparse.y b/usr.sbin/apmd/apmdparse.y deleted file mode 100644 index 597982b..0000000 --- a/usr.sbin/apmd/apmdparse.y +++ /dev/null @@ -1,205 +0,0 @@ -%{ -/*- - * APM (Advanced Power Management) Event Dispatcher - * - * Copyright (c) 1999 Mitsuru IWASAKI - * Copyright (c) 1999 KOIE Hidetaka - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "apmd.h" - -#ifdef DEBUG -#define YYDEBUG 1 -#endif - -extern int first_time; - -%} - -%union { - char *str; - bitstr_t bit_decl(evlist, EVENT_MAX); - int ev; - struct event_cmd * evcmd; - int i; -} - -%token BEGINBLOCK ENDBLOCK -%token COMMA SEMICOLON -%token APMEVENT -%token APMBATT -%token BATTCHARGE BATTDISCHARGE -%token BATTTIME BATTPERCENT -%token EXECCMD REJECTCMD -%token EVENT -%token STRING UNKNOWN - -%type apm_battery_level -%type apm_battery_direction -%type string -%type unknown -%type event_list -%type cmd_list -%type cmd -%type exec_cmd reject_cmd - -%% - -config_file - : { first_time = 1; } config_list - ; - -config_list - : config - | config_list config - ; - -config - : apm_event_statement - | apm_battery_statement - ; - -apm_event_statement - : APMEVENT event_list BEGINBLOCK cmd_list ENDBLOCK - { - if (register_apm_event_handlers($2, $4) < 0) - abort(); /* XXX */ - free_event_cmd_list($4); - } - ; - -apm_battery_level - : BATTPERCENT - { - $$ = $1; - } - | BATTTIME - { - $$ = $1; - } - ; - -apm_battery_direction - : BATTCHARGE - { - $$ = 1; - } - | BATTDISCHARGE - { - $$ = -1; - } - ; -apm_battery_statement - : APMBATT apm_battery_level apm_battery_direction - BEGINBLOCK cmd_list ENDBLOCK - { - if (register_battery_handlers($2, $3, $5) < 0) - abort(); /* XXX */ - free_event_cmd_list($5); - } - ; - -event_list - : EVENT - { - bit_nclear($$, 0, EVENT_MAX - 1); - bit_set($$, $1); - } - | event_list COMMA EVENT - { - memcpy(&($$), &($1), bitstr_size(EVENT_MAX)); - bit_set($$, $3); - } - ; - -cmd_list - : /* empty */ - { - $$ = NULL; - } - | cmd_list cmd - { - struct event_cmd * p = $1; - if (p) { - while (p->next != NULL) - p = p->next; - p->next = $2; - $$ = $1; - } else { - $$ = $2; - } - } - ; - -cmd - : exec_cmd SEMICOLON { $$ = $1; } - | reject_cmd SEMICOLON { $$ = $1; } - ; - -exec_cmd - : EXECCMD string - { - size_t len = sizeof (struct event_cmd_exec); - struct event_cmd_exec *cmd = malloc(len); - cmd->evcmd.next = NULL; - cmd->evcmd.len = len; - cmd->evcmd.name = "exec"; - cmd->evcmd.op = &event_cmd_exec_ops; - cmd->line = $2; - $$ = (struct event_cmd *) cmd; - } - ; - -reject_cmd - : REJECTCMD - { - size_t len = sizeof (struct event_cmd_reject); - struct event_cmd_reject *cmd = malloc(len); - cmd->evcmd.next = NULL; - cmd->evcmd.len = len; - cmd->evcmd.name = "reject"; - cmd->evcmd.op = &event_cmd_reject_ops; - $$ = (struct event_cmd *) cmd; - } - ; - -string - : STRING { $$ = $1; } - ; - -unknown - : UNKNOWN - { - $$ = $1; - } - ; -%% - diff --git a/usr.sbin/apmd/contrib/pccardq.c b/usr.sbin/apmd/contrib/pccardq.c deleted file mode 100644 index aebd1d5..0000000 --- a/usr.sbin/apmd/contrib/pccardq.c +++ /dev/null @@ -1,286 +0,0 @@ -/* $FreeBSD$ */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const char *const pccardd_file = "/var/tmp/.pccardd"; -const char *prog = "pccardq"; -const char *tmp_dir = "/tmp"; -unsigned slot_map = ~0; - -void -usage(void) -{ - fprintf(stderr, "usage: %s [-a] [-n] [-s slot]\n", prog); -} - -int -proc_arg(int ac, char **av) -{ - int rc = -1; - int ch; - - char *p = strrchr(av[0], '/'); - prog = p ? p + 1 : av[0]; - - tmp_dir = getenv("TMPDIR") ? getenv("TMPDIR") : tmp_dir; - - while ((ch = getopt(ac, av, "ans:")) != -1) { - switch (ch) { - case 'a': - slot_map = ~0; - break; - case 'n': - slot_map = 0; - break; - case 's': - { - int n = atoi(optarg); - if (n < 0 || n >= CHAR_BIT * sizeof slot_map) { - warnc(0, "Invalid slot number."); - usage(); - goto out; - } - if (slot_map == ~0) - slot_map = 0; - slot_map |= 1 << n; - } - break; - default: - usage(); - goto out; - } - } - - rc = 0; - out: - return rc; -} - -int -connect_to_pccardd(char **path) -{ - int so = -1; - int pccardd_len; - struct sockaddr_un pccardq; - struct sockaddr_un pccardd; - - if ((so = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) { - warn("socket"); - goto err; - } - - snprintf(pccardq.sun_path, sizeof pccardq.sun_path, - "%s/%s%ld%ld", tmp_dir, prog, (long) getpid(), (long) time(0)); - pccardq.sun_family = AF_UNIX; - pccardq.sun_len = offsetof(struct sockaddr_un, sun_path) + strlen(pccardq.sun_path); - if (bind(so, (struct sockaddr *) &pccardq, pccardq.sun_len) < 0) { - warn("bind: %s", pccardq.sun_path); - goto err; - } - if ((*path = strdup(pccardq.sun_path)) == NULL) { - warn("strdup"); - goto err; - } - - pccardd_len = strlen(pccardd_file) + 1; - if (pccardd_len > sizeof pccardd.sun_path) { - warnc(0, "%s: too long", pccardd_file); - goto err; - } - pccardd.sun_len = offsetof(struct sockaddr_un, sun_path) + pccardd_len; - pccardd.sun_family = AF_UNIX; - strcpy(pccardd.sun_path, pccardd_file); - if (connect(so, (struct sockaddr *) &pccardd, pccardd.sun_len) < 0) { - warn("connect: %s", pccardd_file); - goto err; - } - return so; - err: - if (so >= 0) - close(so); - return -1; -} - -int -get_slot_number(int so) -{ - char buf[8]; - int rv; - int nslot; - - if ((rv = write(so, "S", 1)) < 1) { - warn("write"); - goto err; - } else if (rv != 1) { - warnc(0, "write: fail."); - goto err; - } - - if ((rv = read(so, buf, sizeof buf)) < 0) { - warn("read"); - goto err; - } - buf[sizeof buf - 1] = 0; - if (sscanf(buf, "%d", &nslot) != 1) { - warnc(0, "Invalid response."); - goto err; - } - return nslot; - err: - return -1; -} - -enum { - SLOT_EMPTY = 0, - SLOT_FILLED = 1, - SLOT_INACTIVE = 2, - SLOT_UNDEFINED = 9 -}; - -int -get_slot_info(int so, int slot, char **manuf, char **version, char - **device, int *state) -{ - int rc = -1; - int rv; - static char buf[1024]; - int slen; - char *s; - char *sl; - - char *_manuf; - char *_version; - char *_device; - - if ((slen = snprintf(buf, sizeof buf, "N%d", slot)) < 0) { - warnc(0, "write"); - goto err; - } - - if ((rv = write(so, buf, slen)) < 0) { - warn("write"); - goto err; - } else if (rv != slen) { - warnc(0, "write"); - goto err; - } - - if ((rv = read(so, buf, sizeof buf)) < 0) { - warn("read"); - goto err; - } - - s = buf; - if ((sl = strsep(&s, "~")) == NULL) - goto parse_err; - if (atoi(sl) != slot) - goto parse_err; - if ((_manuf = strsep(&s, "~")) == NULL) - goto parse_err; - if ((_version = strsep(&s, "~")) == NULL) - goto parse_err; - if ((_device = strsep(&s, "~")) == NULL) - goto parse_err; - if (sscanf(s, "%1d", state) != 1) - goto parse_err; - if (s != NULL && strchr(s, '~') != NULL) - goto parse_err; - - if ((*manuf = strdup(_manuf)) == NULL) { - warn("strdup"); - goto err; - } - if ((*version = strdup(_version)) == NULL) { - warn("strdup"); - goto err; - } - if ((*device = strdup(_device)) == NULL) { - warn("strdup"); - goto err; - } - if (*manuf == NULL || *version == NULL || *device == NULL) { - warn("strdup"); - goto err; - } - - rc = 0; - err: - return rc; - parse_err: - warnc(0, "Invalid response: %*s", rv, buf); - return rc; -} - -const char * -strstate(int state) -{ - switch (state) { - case 0: - return "empty"; - case 1: - return "filled"; - case 2: - return "inactive"; - default: - return "unknown"; - } -} - -int -main(int ac, char **av) -{ - char *path = NULL; - int so = -1; - int nslot; - int i; - - if (proc_arg(ac, av) < 0) - goto out; - if ((so = connect_to_pccardd(&path)) < 0) - goto out; - if ((nslot = get_slot_number(so)) < 0) - goto out; - if (slot_map == 0) { - printf("%d\n", nslot); - } else { - for (i = 0; i < nslot; i++) { - if ((slot_map & (1 << i))) { - char *manuf; - char *version; - char *device; - int state; - - if (get_slot_info(so, i, &manuf, &version, &device, - &state) < 0) - goto out; - if (manuf == NULL || version == NULL || device == NULL) - goto out; - printf("%d~%s~%s~%s~%s\n", - i, manuf, version, device, strstate(state)); - free(manuf); - free(version); - free(device); - } - } - } - out: - if (path) { - unlink(path); - free(path); - } - if (so >= 0) - close(so); - exit(0); -} diff --git a/usr.sbin/arp/Makefile b/usr.sbin/arp/Makefile deleted file mode 100644 index 6ca9dd2..0000000 --- a/usr.sbin/arp/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# @(#)Makefile 8.2 (Berkeley) 4/18/94 -# $FreeBSD$ - -PROG= arp -MAN= arp.4 arp.8 - -WARNS?= 3 - -.include diff --git a/usr.sbin/arp/arp.4 b/usr.sbin/arp/arp.4 deleted file mode 100644 index 335a521..0000000 --- a/usr.sbin/arp/arp.4 +++ /dev/null @@ -1,191 +0,0 @@ -.\" Copyright (c) 1985, 1986, 1988, 1994 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)arp4.4 6.5 (Berkeley) 4/18/94 -.\" $FreeBSD$ -.\" -.Dd March 28, 2007 -.Dt ARP 4 -.Os -.Sh NAME -.Nm arp -.Nd Address Resolution Protocol -.Sh SYNOPSIS -.Cd "device ether" -.Sh DESCRIPTION -The Address Resolution Protocol (ARP) is used to dynamically -map between Protocol Addresses (such as IP addresses) and -Local Network Addresses (such as Ethernet addresses). -This implementation maps IP addresses to Ethernet, -ARCnet, -or Token Ring addresses. -It is used by all the Ethernet interface drivers. -.Pp -ARP caches Internet-Ethernet address mappings. -When an interface requests a mapping for an address not in the cache, -ARP queues the message which requires the mapping and broadcasts -a message on the associated network requesting the address mapping. -If a response is provided, the new mapping is cached and any pending -message is transmitted. -ARP will queue at most one packet while waiting for a response to a -mapping request; -only the most recently ``transmitted'' packet is kept. -If the target host does not respond after several requests, -the host is considered to be down allowing an error to be returned to -transmission attempts. -Further demand for this mapping causes ARP request retransmissions, that -are ratelimited to one packet per second. -The error is -.Er EHOSTDOWN -for a non-responding destination host, and -.Er EHOSTUNREACH -for a non-responding router. -.Pp -The ARP cache is stored in the system routing table as -dynamically-created host routes. -The route to a directly-attached Ethernet network is installed as a -.Dq cloning -route (one with the -.Li RTF_CLONING -flag set), -causing routes to individual hosts on that network to be created on -demand. -These routes time out periodically (normally 20 minutes after validated; -entries are not validated when not in use). -.Pp -ARP entries may be added, deleted or changed with the -.Xr arp 8 -utility. -Manually-added entries may be temporary or permanent, -and may be -.Dq published , -in which case the system will respond to ARP requests for that host -as if it were the target of the request. -.Pp -In the past, -ARP was used to negotiate the use of a trailer encapsulation. -This is no longer supported. -.Pp -ARP watches passively for hosts impersonating the local host (i.e., a host -which responds to an ARP mapping request for the local host's address). -.Pp -Proxy ARP is a feature whereby the local host will respond to requests -for addresses other than itself, with its own address. -Normally, proxy ARP in -.Fx -is set up on a host-by-host basis using the -.Xr arp 8 -utility, by adding an entry for each host inside a given subnet for -which proxying of ARP requests is desired. -However, the -.Dq "proxy all" -feature causes the local host to act as a proxy for -.Em all -hosts reachable through some other network interface, -different from the one the request came in from. -It may be enabled by setting the -.Xr sysctl 8 -MIB variable -.Va net.link.ether.inet.proxyall -to 1. -.Sh MIB Variables -The ARP protocol implements a number of configrable variables in -.Va net.link.ether.inet -branch -of the -.Xr sysctl 3 -MIB. -.Bl -tag -.It Va max_age -How long an ARP entry is held in the cache until it needs to be refreshed. -.It Va maxtries -Number of retransmits before host is considered down and error is returned. -.It Va useloopback -If an ARP entry is added for local address, force the traffic to go through -the loopback interface. -.It Va proxyall -Enables ARP proxying for all hosts on net. -.El -.Sh DIAGNOSTICS -.Bl -diag -.It "arp: %x:%x:%x:%x:%x:%x is using my IP address %d.%d.%d.%d!" -ARP has discovered another host on the local network which responds to -mapping requests for its own Internet address with a different Ethernet -address, generally indicating that two hosts are attempting to use the -same Internet address. -.It "arp: link address is broadcast for IP address %d.%d.%d.%d!" -ARP requested information for a host, and received an answer indicating -that the host's ethernet address is the ethernet broadcast address. -This indicates a misconfigured or broken device. -.It "arp: %d.%d.%d.%d moved from %x:%x:%x:%x:%x:%x to %x:%x:%x:%x:%x:%x on %s" -ARP had a cached value for the ethernet address of the referenced host, -but received a reply indicating that the host is at a new address. -This can happen normally when host hardware addresses change, -or when a mobile node arrives or leaves the local subnet. -It can also indicate a problem with proxy ARP. -This message can only be issued if the sysctl -.Va net.link.ether.inet.log_arp_movements -is set to 1, which is the system's default behaviour. -.It "arpresolve: can't allocate llinfo for %d.%d.%d.%d" -The route for the referenced host points to a device upon which ARP is -required, but ARP was unable to allocate a routing table entry in which -to store the host's MAC address. -This usually points to a misconfigured routing table. -It can also occur if the kernel cannot allocate memory. -.It "arp: %d.%d.%d.%d is on if0 but got reply from %x:%x:%x:%x:%x:%x on if1" -Physical connections exist to the same logical IP network on both if0 and if1. -It can also occur if an entry already exists in the ARP cache for the IP -address above, and the cable has been disconnected from if0, then reconnected -to if1. -This message can only be issued if the sysctl -.Va net.link.ether.inet.log_arp_wrong_iface -is set to 1, which is the system's default behaviour. -.It "arp: %x:%x:%x:%x:%x:%x attempts to modify permanent entry for %d.%d.%d.%d on %s" -ARP has received an ARP reply that attempts to overwrite a permanent -entry in the local ARP table. -This error will only be logged if the sysctl -.Va net.link.ether.inet.log_arp_permanent_modify -is set to 1, which is the system's default behaviour. -.El -.Sh SEE ALSO -.Xr inet 4 , -.Xr route 4 , -.Xr arp 8 , -.Xr ifconfig 8 , -.Xr route 8 , -.Xr sysctl 8 -.Rs -.%A Plummer, D. -.%B "An Ethernet Address Resolution Protocol" -.%T RFC826 -.Re -.Rs -.%A Leffler, S.J. -.%A Karels, M.J. -.%B "Trailer Encapsulations -.%T RFC893 -.Re diff --git a/usr.sbin/arp/arp.8 b/usr.sbin/arp/arp.8 deleted file mode 100644 index d7306d3..0000000 --- a/usr.sbin/arp/arp.8 +++ /dev/null @@ -1,202 +0,0 @@ -.\" Copyright (c) 1985, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)arp.8 8.1 (Berkeley) 6/6/93 -.\" $FreeBSD$ -.\" -.Dd December 25, 2008 -.Dt ARP 8 -.Os -.Sh NAME -.Nm arp -.Nd address resolution display and control -.Sh SYNOPSIS -.Nm -.Op Fl n -.Op Fl i Ar interface -.Ar hostname -.Nm -.Op Fl n -.Op Fl i Ar interface -.Fl a -.Nm -.Fl d Ar hostname -.Op Cm pub -.Nm -.Fl d -.Op Fl i Ar interface -.Fl a -.Nm -.Fl s Ar hostname ether_addr -.Op Cm temp -.Op Cm blackhole No \&| Cm reject -.Op Cm pub Op Cm only -.Nm -.Fl S Ar hostname ether_addr -.Op Cm temp -.Op Cm blackhole No \&| Cm reject -.Op Cm pub Op Cm only -.Nm -.Fl f Ar filename -.Sh DESCRIPTION -The -.Nm -utility displays and modifies the Internet-to-Ethernet address translation -tables used by the address resolution protocol -.Pq Xr arp 4 . -With no flags, the program displays the current -.Tn ARP -entry for -.Ar hostname . -The host may be specified by name or by number, -using Internet dot notation. -.Pp -Available options: -.Bl -tag -width indent -.It Fl a -The program displays or deletes all of the current -.Tn ARP -entries. -.It Fl d -A super-user may delete an entry for the host called -.Ar hostname -with the -.Fl d -flag. -If the -.Cm pub -keyword is specified, only the -.Dq published -.Tn ARP -entry -for this host will be deleted. -.Pp -Alternatively, the -.Fl d -flag may be combined with the -.Fl a -flag to delete all entries. -.It Fl i Ar interface -Limit the operation scope to the -.Tn ARP -entries on -.Ar interface . -Applicable only to the following operations: -display one, display all, delete all. -.It Fl n -Show network addresses as numbers (normally -.Nm -attempts to display addresses symbolically). -.It Fl s Ar hostname ether_addr -Create an -.Tn ARP -entry for the host called -.Ar hostname -with the Ethernet address -.Ar ether_addr . -The Ethernet address is given as six hex bytes separated by colons. -The entry will be permanent unless the word -.Cm temp -is given in the command. -If the word -.Cm pub -is given, the entry will be -.Dq published ; -i.e., this system will -act as an -.Tn ARP -server, -responding to requests for -.Ar hostname -even though the host address is not its own. -In this case the -.Ar ether_addr -can be given as -.Cm auto -in which case the interfaces on this host will be examined, -and if one of them is found to occupy the same subnet, its -Ethernet address will be used. -If the -.Cm only -keyword is also specified, this will create a -.Dq "published (proxy only)" -entry. -This type of entry is created automatically if -.Nm -detects that a routing table entry for -.Ar hostname -already exists. -.Pp -If the -.Cm reject -keyword is specified the entry will be marked so that traffic to -the host will be discarded and the sender will be notified the -host is unreachable. -The -.Cm blackhole -keyword is similar in that traffic is discarded but the sender is -not notified. -These can be used to block external traffic to a host without -using a firewall. -.It Fl S Ar hostname ether_addr -Is just like -.Fl s -except any existing -.Tn ARP -entry for this host will be deleted first. -.It Fl f Ar filename -Cause the file -.Ar filename -to be read and multiple entries to be set in the -.Tn ARP -tables. -Entries -in the file should be of the form -.Pp -.Bd -ragged -offset indent -compact -.Ar hostname ether_addr -.Op Cm temp -.Op Cm blackhole No \&| Cm reject -.Op Cm pub Op Cm only -.Ed -.Pp -with argument meanings as given above. -Leading whitespace and empty lines are ignored. -A -.Ql # -character will mark the rest of the line as a comment. -.El -.Sh SEE ALSO -.Xr inet 3 , -.Xr arp 4 , -.Xr ifconfig 8 , -.Xr ndp 8 -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 4.3 . diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c deleted file mode 100644 index 2ee9d67..0000000 --- a/usr.sbin/arp/arp.c +++ /dev/null @@ -1,868 +0,0 @@ -/* - * Copyright (c) 1984, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Sun Microsystems, Inc. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -#ifndef lint -static char const copyright[] = -"@(#) Copyright (c) 1984, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char const sccsid[] = "@(#)from: arp.c 8.2 (Berkeley) 1/2/94"; -#endif /* not lint */ -#endif -#include -__FBSDID("$FreeBSD$"); - -/* - * arp - display, set, and delete arp table entries - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -typedef void (action_fn)(struct sockaddr_dl *sdl, - struct sockaddr_inarp *s_in, struct rt_msghdr *rtm); - -static int search(u_long addr, action_fn *action); -static action_fn print_entry; -static action_fn nuke_entry; - -static int delete(char *host, int do_proxy); -static void usage(void); -static int set(int argc, char **argv); -static int get(char *host); -static int file(char *name); -static struct rt_msghdr *rtmsg(int cmd, - struct sockaddr_inarp *dst, struct sockaddr_dl *sdl); -static int get_ether_addr(in_addr_t ipaddr, struct ether_addr *hwaddr); -static struct sockaddr_inarp *getaddr(char *host); -static int valid_type(int type); - -static int nflag; /* no reverse dns lookups */ -static char *rifname; - -static time_t expire_time; -static int flags, doing_proxy, proxy_only; - -/* which function we're supposed to do */ -#define F_GET 1 -#define F_SET 2 -#define F_FILESET 3 -#define F_REPLACE 4 -#define F_DELETE 5 - -#define SETFUNC(f) { if (func) usage(); func = (f); } - -int -main(int argc, char *argv[]) -{ - int ch, func = 0; - int rtn = 0; - int aflag = 0; /* do it for all entries */ - - while ((ch = getopt(argc, argv, "andfsSi:")) != -1) - switch(ch) { - case 'a': - aflag = 1; - break; - case 'd': - SETFUNC(F_DELETE); - break; - case 'n': - nflag = 1; - break; - case 'S': - SETFUNC(F_REPLACE); - break; - case 's': - SETFUNC(F_SET); - break; - case 'f' : - SETFUNC(F_FILESET); - break; - case 'i': - rifname = optarg; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (!func) - func = F_GET; - if (rifname) { - if (func != F_GET && !(func == F_DELETE && aflag)) - errx(1, "-i not applicable to this operation"); - if (if_nametoindex(rifname) == 0) { - if (errno == ENXIO) - errx(1, "interface %s does not exist", rifname); - else - err(1, "if_nametoindex(%s)", rifname); - } - } - switch (func) { - case F_GET: - if (aflag) { - if (argc != 0) - usage(); - search(0, print_entry); - } else { - if (argc != 1) - usage(); - rtn = get(argv[0]); - } - break; - case F_SET: - case F_REPLACE: - if (argc < 2 || argc > 6) - usage(); - if (func == F_REPLACE) - (void)delete(argv[0], 0); - rtn = set(argc, argv) ? 1 : 0; - break; - case F_DELETE: - if (aflag) { - if (argc != 0) - usage(); - search(0, nuke_entry); - } else { - if (argc == 2 && strncmp(argv[1], "pub", 3) == 0) - ch = SIN_PROXY; - else if (argc == 1) - ch = 0; - else - usage(); - rtn = delete(argv[0], ch); - } - break; - case F_FILESET: - if (argc != 1) - usage(); - rtn = file(argv[0]); - break; - } - - return (rtn); -} - -/* - * Process a file to set standard arp entries - */ -static int -file(char *name) -{ - FILE *fp; - int i, retval; - char line[100], arg[5][50], *args[5], *p; - - if ((fp = fopen(name, "r")) == NULL) - err(1, "cannot open %s", name); - args[0] = &arg[0][0]; - args[1] = &arg[1][0]; - args[2] = &arg[2][0]; - args[3] = &arg[3][0]; - args[4] = &arg[4][0]; - retval = 0; - while(fgets(line, sizeof(line), fp) != NULL) { - if ((p = strchr(line, '#')) != NULL) - *p = '\0'; - for (p = line; isblank(*p); p++); - if (*p == '\n' || *p == '\0') - continue; - i = sscanf(p, "%49s %49s %49s %49s %49s", arg[0], arg[1], - arg[2], arg[3], arg[4]); - if (i < 2) { - warnx("bad line: %s", line); - retval = 1; - continue; - } - if (set(i, args)) - retval = 1; - } - fclose(fp); - return (retval); -} - -/* - * Given a hostname, fills up a (static) struct sockaddr_inarp with - * the address of the host and returns a pointer to the - * structure. - */ -static struct sockaddr_inarp * -getaddr(char *host) -{ - struct hostent *hp; - static struct sockaddr_inarp reply; - - bzero(&reply, sizeof(reply)); - reply.sin_len = sizeof(reply); - reply.sin_family = AF_INET; - reply.sin_addr.s_addr = inet_addr(host); - if (reply.sin_addr.s_addr == INADDR_NONE) { - if (!(hp = gethostbyname(host))) { - warnx("%s: %s", host, hstrerror(h_errno)); - return (NULL); - } - bcopy((char *)hp->h_addr, (char *)&reply.sin_addr, - sizeof reply.sin_addr); - } - return (&reply); -} - -/* - * Returns true if the type is a valid one for ARP. - */ -static int -valid_type(int type) -{ - - switch (type) { - case IFT_ETHER: - case IFT_FDDI: - case IFT_ISO88023: - case IFT_ISO88024: - case IFT_ISO88025: - case IFT_L2VLAN: - case IFT_BRIDGE: - return (1); - default: - return (0); - } -} - -/* - * Set an individual arp entry - */ -static int -set(int argc, char **argv) -{ - struct sockaddr_inarp *addr; - struct sockaddr_inarp *dst; /* what are we looking for */ - struct sockaddr_dl *sdl; - struct rt_msghdr *rtm; - struct ether_addr *ea; - char *host = argv[0], *eaddr = argv[1]; - struct sockaddr_dl sdl_m; - - argc -= 2; - argv += 2; - - bzero(&sdl_m, sizeof(sdl_m)); - sdl_m.sdl_len = sizeof(sdl_m); - sdl_m.sdl_family = AF_LINK; - - dst = getaddr(host); - if (dst == NULL) - return (1); - doing_proxy = flags = proxy_only = expire_time = 0; - while (argc-- > 0) { - if (strncmp(argv[0], "temp", 4) == 0) { - struct timeval tv; - gettimeofday(&tv, 0); - expire_time = tv.tv_sec + 20 * 60; - } else if (strncmp(argv[0], "pub", 3) == 0) { - flags |= RTF_ANNOUNCE; - doing_proxy = 1; - if (argc && strncmp(argv[1], "only", 3) == 0) { - proxy_only = 1; - argc--; argv++; - } - } else if (strncmp(argv[0], "blackhole", 9) == 0) { - if (flags & RTF_REJECT) { - printf("Choose one of blackhole or reject, not both.\n"); - } - flags |= RTF_BLACKHOLE; - } else if (strncmp(argv[0], "reject", 6) == 0) { - if (flags & RTF_BLACKHOLE) { - printf("Choose one of blackhole or reject, not both.\n"); - } - flags |= RTF_REJECT; - } else if (strncmp(argv[0], "trail", 5) == 0) { - /* XXX deprecated and undocumented feature */ - printf("%s: Sending trailers is no longer supported\n", - host); - } - argv++; - } - ea = (struct ether_addr *)LLADDR(&sdl_m); - if (doing_proxy && !strcmp(eaddr, "auto")) { - if (!get_ether_addr(dst->sin_addr.s_addr, ea)) { - printf("no interface found for %s\n", - inet_ntoa(dst->sin_addr)); - return (1); - } - sdl_m.sdl_alen = ETHER_ADDR_LEN; - } else { - struct ether_addr *ea1 = ether_aton(eaddr); - - if (ea1 == NULL) { - warnx("invalid Ethernet address '%s'", eaddr); - return (1); - } else { - *ea = *ea1; - sdl_m.sdl_alen = ETHER_ADDR_LEN; - } - } - - /* - * In the case a proxy-arp entry is being added for - * a remote end point, the RTF_ANNOUNCE flag in the - * RTM_GET command is an indication to the kernel - * routing code that the interface associated with - * the prefix route covering the local end of the - * PPP link should be returned, on which ARP applies. - */ - rtm = rtmsg(RTM_GET, dst, &sdl_m); - if (rtm == NULL) { - warn("%s", host); - return (1); - } - addr = (struct sockaddr_inarp *)(rtm + 1); - sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr); - if (addr->sin_addr.s_addr == dst->sin_addr.s_addr) { - printf("set: proxy entry exists for non 802 device\n"); - return (1); - } - - if ((sdl->sdl_family != AF_LINK) || - (rtm->rtm_flags & RTF_GATEWAY) || - !valid_type(sdl->sdl_type)) { - printf("cannot intuit interface index and type for %s\n", host); - return (1); - } - sdl_m.sdl_type = sdl->sdl_type; - sdl_m.sdl_index = sdl->sdl_index; - return (rtmsg(RTM_ADD, dst, &sdl_m) == NULL); -} - -/* - * Display an individual arp entry - */ -static int -get(char *host) -{ - struct sockaddr_inarp *addr; - - addr = getaddr(host); - if (addr == NULL) - return (1); - if (0 == search(addr->sin_addr.s_addr, print_entry)) { - printf("%s (%s) -- no entry", - host, inet_ntoa(addr->sin_addr)); - if (rifname) - printf(" on %s", rifname); - printf("\n"); - return (1); - } - return (0); -} - -/* - * Delete an arp entry - */ -static int -delete(char *host, int do_proxy) -{ - struct sockaddr_inarp *addr, *dst; - struct rt_msghdr *rtm; - struct sockaddr_dl *sdl; - struct sockaddr_dl sdl_m; - - dst = getaddr(host); - if (dst == NULL) - return (1); - - /* - * Perform a regular entry delete first. - */ - flags &= ~RTF_ANNOUNCE; - - /* - * setup the data structure to notify the kernel - * it is the ARP entry the RTM_GET is interested - * in - */ - bzero(&sdl_m, sizeof(sdl_m)); - sdl_m.sdl_len = sizeof(sdl_m); - sdl_m.sdl_family = AF_LINK; - - for (;;) { /* try twice */ - rtm = rtmsg(RTM_GET, dst, &sdl_m); - if (rtm == NULL) { - warn("%s", host); - return (1); - } - addr = (struct sockaddr_inarp *)(rtm + 1); - sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr); - - /* - * With the new L2/L3 restructure, the route - * returned is a prefix route. The important - * piece of information from the previous - * RTM_GET is the interface index. In the - * case of ECMP, the kernel will traverse - * the route group for the given entry. - */ - if (sdl->sdl_family == AF_LINK && - !(rtm->rtm_flags & RTF_GATEWAY) && - valid_type(sdl->sdl_type) ) { - addr->sin_addr.s_addr = dst->sin_addr.s_addr; - break; - } - - /* - * Regualar entry delete failed, now check if there - * is a proxy-arp entry to remove. - */ - if (flags & RTF_ANNOUNCE) { - fprintf(stderr, "delete: cannot locate %s\n",host); - return (1); - } - - flags |= RTF_ANNOUNCE; - } - rtm->rtm_flags |= RTF_LLDATA; - if (rtmsg(RTM_DELETE, dst, NULL) != NULL) { - printf("%s (%s) deleted\n", host, inet_ntoa(addr->sin_addr)); - return (0); - } - return (1); -} - - -/* - * Search the arp table and do some action on matching entries - */ -static int -search(u_long addr, action_fn *action) -{ - int mib[6]; - size_t needed; - char *lim, *buf, *next; - struct rt_msghdr *rtm; - struct sockaddr_inarp *sin2; - struct sockaddr_dl *sdl; - char ifname[IF_NAMESIZE]; - int st, found_entry = 0; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; - mib[3] = AF_INET; - mib[4] = NET_RT_FLAGS; -#ifdef RTF_LLINFO - mib[5] = RTF_LLINFO; -#else - mib[5] = 0; -#endif - if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) - err(1, "route-sysctl-estimate"); - if (needed == 0) /* empty table */ - return 0; - buf = NULL; - for (;;) { - buf = reallocf(buf, needed); - if (buf == NULL) - errx(1, "could not reallocate memory"); - st = sysctl(mib, 6, buf, &needed, NULL, 0); - if (st == 0 || errno != ENOMEM) - break; - needed += needed / 8; - } - if (st == -1) - err(1, "actual retrieval of routing table"); - lim = buf + needed; - for (next = buf; next < lim; next += rtm->rtm_msglen) { - rtm = (struct rt_msghdr *)next; - sin2 = (struct sockaddr_inarp *)(rtm + 1); - sdl = (struct sockaddr_dl *)((char *)sin2 + SA_SIZE(sin2)); - if (rifname && if_indextoname(sdl->sdl_index, ifname) && - strcmp(ifname, rifname)) - continue; - if (addr) { - if (addr != sin2->sin_addr.s_addr) - continue; - found_entry = 1; - } - (*action)(sdl, sin2, rtm); - } - free(buf); - return (found_entry); -} - -/* - * Display an arp entry - */ -static char lifname[IF_NAMESIZE]; -static int64_t lifindex = -1; - -static void -print_entry(struct sockaddr_dl *sdl, - struct sockaddr_inarp *addr, struct rt_msghdr *rtm) -{ - const char *host; - struct hostent *hp; - struct iso88025_sockaddr_dl_data *trld; - int seg; - - if (nflag == 0) - hp = gethostbyaddr((caddr_t)&(addr->sin_addr), - sizeof addr->sin_addr, AF_INET); - else - hp = 0; - if (hp) - host = hp->h_name; - else { - host = "?"; - if (h_errno == TRY_AGAIN) - nflag = 1; - } - printf("%s (%s) at ", host, inet_ntoa(addr->sin_addr)); - if (sdl->sdl_alen) { - if ((sdl->sdl_type == IFT_ETHER || - sdl->sdl_type == IFT_L2VLAN || - sdl->sdl_type == IFT_BRIDGE) && - sdl->sdl_alen == ETHER_ADDR_LEN) - printf("%s", ether_ntoa((struct ether_addr *)LLADDR(sdl))); - else { - int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0; - - printf("%s", link_ntoa(sdl) + n); - } - } else - printf("(incomplete)"); - if (sdl->sdl_index != lifindex && - if_indextoname(sdl->sdl_index, lifname) != NULL) { - lifindex = sdl->sdl_index; - printf(" on %s", lifname); - } else if (sdl->sdl_index == lifindex) - printf(" on %s", lifname); - if (rtm->rtm_rmx.rmx_expire == 0) - printf(" permanent"); - else { - static struct timeval tv; - if (tv.tv_sec == 0) - gettimeofday(&tv, 0); - if ((expire_time = rtm->rtm_rmx.rmx_expire - tv.tv_sec) > 0) - printf(" expires in %d seconds", (int)expire_time); - else - printf(" expired"); - } - if (addr->sin_other & SIN_PROXY) - printf(" published (proxy only)"); - if (rtm->rtm_flags & RTF_ANNOUNCE) - printf(" published"); - switch(sdl->sdl_type) { - case IFT_ETHER: - printf(" [ethernet]"); - break; - case IFT_ISO88025: - printf(" [token-ring]"); - trld = SDL_ISO88025(sdl); - if (trld->trld_rcf != 0) { - printf(" rt=%x", ntohs(trld->trld_rcf)); - for (seg = 0; - seg < ((TR_RCF_RIFLEN(trld->trld_rcf) - 2 ) / 2); - seg++) - printf(":%x", ntohs(*(trld->trld_route[seg]))); - } - break; - case IFT_FDDI: - printf(" [fddi]"); - break; - case IFT_ATM: - printf(" [atm]"); - break; - case IFT_L2VLAN: - printf(" [vlan]"); - break; - case IFT_IEEE1394: - printf(" [firewire]"); - break; - case IFT_BRIDGE: - printf(" [bridge]"); - break; - default: - break; - } - - printf("\n"); - -} - -/* - * Nuke an arp entry - */ -static void -nuke_entry(struct sockaddr_dl *sdl __unused, - struct sockaddr_inarp *addr, struct rt_msghdr *rtm __unused) -{ - char ip[20]; - - snprintf(ip, sizeof(ip), "%s", inet_ntoa(addr->sin_addr)); - (void)delete(ip, 0); -} - -static void -usage(void) -{ - fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: arp [-n] [-i interface] hostname", - " arp [-n] [-i interface] -a", - " arp -d hostname [pub]", - " arp -d [-i interface] -a", - " arp -s hostname ether_addr [temp] [reject | blackhole] [pub [only]]", - " arp -S hostname ether_addr [temp] [reject | blackhole] [pub [only]]", - " arp -f filename"); - exit(1); -} - -static struct rt_msghdr * -rtmsg(int cmd, struct sockaddr_inarp *dst, struct sockaddr_dl *sdl) -{ - static int seq; - int rlen; - int l; - struct sockaddr_in so_mask, *som = &so_mask; - static int s = -1; - static pid_t pid; - - static struct { - struct rt_msghdr m_rtm; - char m_space[512]; - } m_rtmsg; - - struct rt_msghdr *rtm = &m_rtmsg.m_rtm; - char *cp = m_rtmsg.m_space; - - if (s < 0) { /* first time: open socket, get pid */ - s = socket(PF_ROUTE, SOCK_RAW, 0); - if (s < 0) - err(1, "socket"); - pid = getpid(); - } - bzero(&so_mask, sizeof(so_mask)); - so_mask.sin_len = 8; - so_mask.sin_addr.s_addr = 0xffffffff; - - errno = 0; - /* - * XXX RTM_DELETE relies on a previous RTM_GET to fill the buffer - * appropriately. - */ - if (cmd == RTM_DELETE) - goto doit; - bzero((char *)&m_rtmsg, sizeof(m_rtmsg)); - rtm->rtm_flags = flags; - rtm->rtm_version = RTM_VERSION; - - switch (cmd) { - default: - errx(1, "internal wrong cmd"); - case RTM_ADD: - rtm->rtm_addrs |= RTA_GATEWAY; - rtm->rtm_rmx.rmx_expire = expire_time; - rtm->rtm_inits = RTV_EXPIRE; - rtm->rtm_flags |= (RTF_HOST | RTF_STATIC | RTF_LLDATA); - dst->sin_other = 0; - if (doing_proxy) { - if (proxy_only) - dst->sin_other = SIN_PROXY; - else { - rtm->rtm_addrs |= RTA_NETMASK; - rtm->rtm_flags &= ~RTF_HOST; - } - } - /* FALLTHROUGH */ - case RTM_GET: - rtm->rtm_addrs |= RTA_DST; - } -#define NEXTADDR(w, s) \ - do { \ - if ((s) != NULL && rtm->rtm_addrs & (w)) { \ - bcopy((s), cp, sizeof(*(s))); \ - cp += SA_SIZE(s); \ - } \ - } while (0) - - NEXTADDR(RTA_DST, dst); - NEXTADDR(RTA_GATEWAY, sdl); - NEXTADDR(RTA_NETMASK, som); - - rtm->rtm_msglen = cp - (char *)&m_rtmsg; -doit: - l = rtm->rtm_msglen; - rtm->rtm_seq = ++seq; - rtm->rtm_type = cmd; - if ((rlen = write(s, (char *)&m_rtmsg, l)) < 0) { - if (errno != ESRCH || cmd != RTM_DELETE) { - warn("writing to routing socket"); - return (NULL); - } - } - do { - l = read(s, (char *)&m_rtmsg, sizeof(m_rtmsg)); - } while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid)); - if (l < 0) - warn("read from routing socket"); - return (rtm); -} - -/* - * get_ether_addr - get the hardware address of an interface on the - * the same subnet as ipaddr. - */ -#define MAX_IFS 32 - -static int -get_ether_addr(in_addr_t ipaddr, struct ether_addr *hwaddr) -{ - struct ifreq *ifr, *ifend, *ifp; - in_addr_t ina, mask; - struct sockaddr_dl *dla; - struct ifreq ifreq; - struct ifconf ifc; - struct ifreq ifs[MAX_IFS]; - int sock; - int retval = 0; - - sock = socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) - err(1, "socket"); - - ifc.ifc_len = sizeof(ifs); - ifc.ifc_req = ifs; - if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) { - warnx("ioctl(SIOCGIFCONF)"); - goto done; - } - -#define NEXTIFR(i) \ - ((struct ifreq *)((char *)&(i)->ifr_addr \ - + MAX((i)->ifr_addr.sa_len, sizeof((i)->ifr_addr))) ) - - /* - * Scan through looking for an interface with an Internet - * address on the same subnet as `ipaddr'. - */ - ifend = (struct ifreq *)(ifc.ifc_buf + ifc.ifc_len); - for (ifr = ifc.ifc_req; ifr < ifend; ifr = NEXTIFR(ifr) ) { - if (ifr->ifr_addr.sa_family != AF_INET) - continue; - strncpy(ifreq.ifr_name, ifr->ifr_name, - sizeof(ifreq.ifr_name)); - ifreq.ifr_addr = ifr->ifr_addr; - /* - * Check that the interface is up, - * and not point-to-point or loopback. - */ - if (ioctl(sock, SIOCGIFFLAGS, &ifreq) < 0) - continue; - if ((ifreq.ifr_flags & - (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT| - IFF_LOOPBACK|IFF_NOARP)) - != (IFF_UP|IFF_BROADCAST)) - continue; - /* - * Get its netmask and check that it's on - * the right subnet. - */ - if (ioctl(sock, SIOCGIFNETMASK, &ifreq) < 0) - continue; - mask = ((struct sockaddr_in *) - &ifreq.ifr_addr)->sin_addr.s_addr; - ina = ((struct sockaddr_in *) - &ifr->ifr_addr)->sin_addr.s_addr; - if ((ipaddr & mask) == (ina & mask)) - break; /* ok, we got it! */ - } - - if (ifr >= ifend) - goto done; - - /* - * Now scan through again looking for a link-level address - * for this interface. - */ - ifp = ifr; - for (ifr = ifc.ifc_req; ifr < ifend; ifr = NEXTIFR(ifr)) - if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0 && - ifr->ifr_addr.sa_family == AF_LINK) - break; - if (ifr >= ifend) - goto done; - /* - * Found the link-level address - copy it out - */ - dla = (struct sockaddr_dl *) &ifr->ifr_addr; - memcpy(hwaddr, LLADDR(dla), dla->sdl_alen); - printf("using interface %s for proxy with address ", - ifp->ifr_name); - printf("%s\n", ether_ntoa(hwaddr)); - retval = dla->sdl_alen; -done: - close(sock); - return (retval); -} diff --git a/usr.sbin/asf/Makefile b/usr.sbin/asf/Makefile deleted file mode 100644 index 0db69e8..0000000 --- a/usr.sbin/asf/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $FreeBSD$ - -PROG= asf -SRCS= asf.c asf_kld.c asf_kvm.c asf_prog.c -MAN= asf.8 - -DPADD= ${LIBKVM} -LDADD= -lkvm - -.include diff --git a/usr.sbin/asf/asf.8 b/usr.sbin/asf/asf.8 deleted file mode 100644 index 92edb4b..0000000 --- a/usr.sbin/asf/asf.8 +++ /dev/null @@ -1,179 +0,0 @@ -.\" Copyright (c) 2003 Greg Lehey. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" This software is provided by Greg Lehey ``as is'' and -.\" any express or implied warranties, including, but not limited to, the -.\" implied warranties of merchantability and fitness for a particular purpose -.\" are disclaimed. in no event shall Greg Lehey be liable -.\" for any direct, indirect, incidental, special, exemplary, or consequential -.\" damages (including, but not limited to, procurement of substitute goods -.\" or services; loss of use, data, or profits; or business interruption) -.\" however caused and on any theory of liability, whether in contract, strict -.\" liability, or tort (including negligence or otherwise) arising in any way -.\" out of the use of this software, even if advised of the possibility of -.\" such damage. -.\" -.\" $FreeBSD$ -.\" -.Dd December 20, 2006 -.Dt ASF 8 -.Os -.Sh NAME -.Nm asf -.Nd add symbol files -.Sh SYNOPSIS -.Nm -.Op Fl afKksVx -.Op Fl M Ar core -.Op Fl N Ar system -.Op Fl o Ar outfile -.Op Fl X Ar suffix -.Op Ar modules-path Op Ar outfile -.Sh DESCRIPTION -By default, -.Nm -reads -.Xr kldstat 8 -output from standard input and writes to the -.Pa .asf -file a list of -.Xr gdb 1 -commands to add symbol files from KLDs in subdirectories of the subdirectory -.Pa modules -of the current directory, which is intended to be a kernel build directory. -This allows -.Xr gdb 1 -to load the symbols into the debugging environment. -.Pp -An optional -.Ar modules-path -argument can specify a semicolon-separated list of directory pathnames -similar to the -.Va kern.module_path -sysctl. -Each directory in the list will be searched in turn for modules. -The default list consists of just one element, -.Pa modules , -which is suitable if the current directory is a kernel build directory. -.Pp -If -.Ar outfile -is specified, -.Nm -writes to it instead of -.Pa .asf . -If -.Ar outfile -is a single dash -.Pq Sq Fl , -standard output is used. -.Sh OPTIONS -The following options modify the function of -.Nm : -.Bl -tag -width indent -.It Fl a -When writing to an explicit -.Ar outfile , -append to the file rather than overwriting it. -.It Fl f -Instead of trying to simplistically guess the path for each module, perform -a traversal in the same way that -.Xr find 1 -does to locate an exact path for each module, no matter where in -.Ar modules-path -it is located. -.It Fl K -Instead of reading from standard input, use the conventional -system interface to get the list of modules currently loaded. -.It Fl k -Instead of reading from standard input, start a -.Xr kldstat 8 -and read the information from it. -.It Fl M -Specify the core file for -.Xr kvm 3 . -Implies -.Fl V . -.It Fl N -Specify the system file for -.Xr kvm 3 . -Implies -.Fl V . -.It Fl o -Specify the file for -.Nm -to write or append its output to. -If -.Ar outfile -is a single dash -.Pq Sq Fl , -standard output is used. -.It Fl s -Do not prepend a (guessed) subdirectory of the module path. -.It Fl V -Instead of reading from standard input, use the -.Xr kvm 3 -interface to get the list of modules. -This interface allows for inspecting system crash dumps, -as well as the live system. -The -.Fl M -and -.Fl N -options will be of use if inspecting a crash dump. -Elevated privileges, e.g., those of a superuser, -may be needed to use this option. -.It Fl X -Add -.Ar suffix -to the list of suffixes -.Nm -tries to append to KLD file names. -The default list consists of -.Pa .debug , -.Pa .symbols , -and the null suffix. -The null suffix always stays at the list tail, after the suffix added. -Should it be needed in the middle of the list, -a blank suffix can be specified to -.Fl X -instead. -.It Fl x -Clear the list of suffixes -.Nm -tries to append to KLD file names. -Only the null suffix is left in the list. -.El -.Sh EXAMPLES -To add symbol files from the system search path specified by the -.Va kern.module_path -sysctl, the following command can be used: -.Pp -.Dl asf -s `sysctl -n kern.module_path` -.Sh SEE ALSO -.Xr gdb 1 , -.Xr kvm 3 , -.Xr kld 4 , -.Xr kldstat 8 , -.Xr sysctl 8 -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 5.2 . -.Sh AUTHORS -.An Greg Lehey Aq grog@FreeBSD.org -.Sh BUGS -Module paths are guessed in a rather naive way by default. -It is likely to lag behind the changes to the build tree layout. -Using -.Fl f -is recommended. diff --git a/usr.sbin/asf/asf.c b/usr.sbin/asf/asf.c deleted file mode 100644 index c913e3d..0000000 --- a/usr.sbin/asf/asf.c +++ /dev/null @@ -1,427 +0,0 @@ -/*- - * Copyright (c) 2002, 2003 Greg Lehey - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * This software is provided by the author ``as is'' and any express - * or implied warranties, including, but not limited to, the implied - * warranties of merchantability and fitness for a particular purpose - * are disclaimed. In no event shall the author be liable for any - * direct, indirect, incidental, special, exemplary, or consequential - * damages (including, but not limited to, procurement of substitute - * goods or services; loss of use, data, or profits; or business - * interruption) however caused and on any theory of liability, - * whether in contract, strict liability, or tort (including - * negligence or otherwise) arising in any way out of the use of this - * software, even if advised of the possibility of such damage. - */ -/* $Id: asf.c,v 1.4 2003/05/04 02:55:20 grog Exp grog $ */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "asf.h" - -struct kfile { - char *name; - caddr_t addr; - int seen; - STAILQ_ENTRY(kfile) link; -}; - -static STAILQ_HEAD(,kfile) kfile_head = STAILQ_HEAD_INITIALIZER(kfile_head); - -void -kfile_add(const char *name, caddr_t addr) -{ - struct kfile *kfp; - - if ((kfp = malloc(sizeof(*kfp))) == NULL || - (kfp->name = strdup(name)) == NULL) - errx(2, "out of memory"); - kfp->addr = addr; - kfp->seen = 0; - STAILQ_INSERT_TAIL(&kfile_head, kfp, link); -} - -static struct kfile * -kfile_find(const char *name) -{ - struct kfile *kfp; - - STAILQ_FOREACH(kfp, &kfile_head, link) - if (strcmp(kfp->name, name) == 0) - return (kfp); /* found */ - - return (NULL); /* not found */ -} - -static int -kfile_allseen(void) -{ - struct kfile *kfp; - - STAILQ_FOREACH(kfp, &kfile_head, link) - if (!kfp->seen) - return (0); /* at least one unseen */ - - return (1); /* all seen */ -} - -static int -kfile_empty(void) -{ - return (STAILQ_EMPTY(&kfile_head)); -} - -/* - * Take a blank separated list of tokens and turn it into a list of - * individual nul-delimited strings. Build a list of pointers at - * token, which must have enough space for the tokens. Return the - * number of tokens, or -1 on error (typically a missing string - * delimiter). - */ -int -tokenize(char *cptr, char *token[], int maxtoken) -{ - char delim; /* delimiter to search for */ - int tokennr; /* index of this token */ - - for (tokennr = 0; tokennr < maxtoken;) { - while (isspace(*cptr)) - cptr++; /* skip initial white space */ - if ((*cptr == '\0') || (*cptr == '\n') - || (*cptr == '#')) /* end of line */ - return tokennr; /* return number of tokens found */ - delim = *cptr; - token[tokennr] = cptr; /* point to it */ - tokennr++; /* one more */ - if (tokennr == maxtoken) /* run off the end? */ - return tokennr; - if ((delim == '\'') || (delim == '"')) { /* delimitered */ - for (;;) { - cptr++; - if ((*cptr == delim) - && (cptr[-1] != '\\')) { /* found the partner */ - cptr++; /* move on past */ - if (!isspace(*cptr)) /* no space after closing quote */ - return -1; - *cptr++ = '\0'; /* delimit */ - } else if ((*cptr == '\0') - || (*cptr == '\n')) /* end of line */ - return -1; - } - } else { /* not quoted */ - while ((*cptr != '\0') && (!isspace(*cptr)) && (*cptr != '\n')) - cptr++; - if (*cptr != '\0') /* not end of the line, */ - *cptr++ = '\0'; /* delimit and move to the next */ - } - } - return maxtoken; /* can't get here */ -} - -static void -doobj(const char *path, caddr_t addr, FILE *out) -{ - uintmax_t base = (uintptr_t)addr; - uintmax_t textaddr = 0; - uintmax_t dataaddr = 0; - uintmax_t bssaddr = 0; - uintmax_t *up; - int octokens; - char *octoken[MAXTOKEN]; - char ocbuf[LINE_MAX + PATH_MAX]; - FILE *objcopy; - - snprintf(ocbuf, sizeof(ocbuf), - "/usr/bin/objdump --section-headers %s", path); - if ((objcopy = popen(ocbuf, "r")) == NULL) - err(2, "can't start %s", ocbuf); - while (fgets(ocbuf, sizeof(ocbuf), objcopy)) { - octokens = tokenize(ocbuf, octoken, MAXTOKEN); - if (octokens <= 1) - continue; - up = NULL; - if (strcmp(octoken[1], ".text") == 0) - up = &textaddr; - else if (strcmp(octoken[1], ".data") == 0) - up = &dataaddr; - else if (strcmp(octoken[1], ".bss") == 0) - up = &bssaddr; - if (up == NULL) - continue; - *up = strtoumax(octoken[3], NULL, 16) + base; - } - if (textaddr) { /* we must have a text address */ - fprintf(out, "add-symbol-file %s 0x%jx", path, textaddr); - if (dataaddr) - fprintf(out, " -s .data 0x%jx", dataaddr); - if (bssaddr) - fprintf(out, " -s .bss 0x%jx", bssaddr); - fprintf(out, "\n"); - } -} - -static void -findmodules(char *path_argv[], const char *sfx[], FILE *out) -{ - char *p; - FTS *fts; - FTSENT *ftsent; - struct kfile *kfp; - int i; - int sl; - - /* Have to fts once per suffix to find preferred suffixes first */ - do { - sl = *sfx ? strlen(*sfx) : 0; /* current suffix length */ - fts = fts_open(path_argv, FTS_PHYSICAL | FTS_NOCHDIR, NULL); - if (fts == NULL) - err(2, "can't begin traversing module path"); - while ((ftsent = fts_read(fts)) != NULL) { - if (ftsent->fts_info == FTS_DNR || - ftsent->fts_info == FTS_ERR || - ftsent->fts_info == FTS_NS) { - errno = ftsent->fts_errno; - err(2, "error while traversing path %s", ftsent->fts_path); - } - if (ftsent->fts_info != FTS_F) - continue; /* not a plain file */ - - if (sl > 0) { - /* non-blank suffix; see if file name has it */ - i = ftsent->fts_namelen - sl; - if (i <= 0 || strcmp(ftsent->fts_name + i, *sfx) != 0) - continue; /* no such suffix */ - if ((p = strdup(ftsent->fts_name)) == NULL) - errx(2, "out of memory"); - p[i] = '\0'; /* remove suffix in the copy */ - kfp = kfile_find(p); - free(p); - } else - kfp = kfile_find(ftsent->fts_name); - - if (kfp && !kfp->seen) { - doobj(ftsent->fts_path, kfp->addr, out); - kfp->seen = 1; - /* Optimization: stop fts as soon as seen all loaded modules */ - if (kfile_allseen()) { - fts_close(fts); - return; - } - } - } - if (ftsent == NULL && errno != 0) - err(2, "couldn't complete traversing module path"); - fts_close(fts); - } while (*sfx++); -} - -static void -usage(const char *myname) -{ - fprintf(stderr, - "Usage:\n" - "%s [-afKksVx] [-M core] [-N system] [-o outfile] [-X suffix]\n" - "%*s [modules-path [outfile]]\n\n" - "\t-a\tappend to outfile\n" - "\t-f\tfind the module in any subdirectory of modules-path\n" - "\t-K\tuse kld(2) to get the list of modules\n" - "\t-k\ttake input from kldstat(8)\n" - "\t-M\tspecify core name for kvm(3)\n" - "\t-N\tspecify system name for kvm(3)\n" - "\t-o\tuse outfile instead of \".asf\"\n" - "\t-s\tdon't prepend subdir for module path\n" - "\t-V\tuse kvm(3) to get the list of modules\n" - "\t-X\tappend suffix to list of possible module file name suffixes\n" - "\t-x\tclear list of possible module file name suffixes\n", - myname, (int)strlen(myname), ""); - exit(2); -} - -#define MAXPATHS 15 -#define MAXSUFFIXES 15 - -/* KLD file names end in this */ -static int nsuffixes = 2; -static const char *suffixes[MAXSUFFIXES + 1] = { - ".debug", - ".symbols", - NULL -}; - -int -main(int argc, char *argv[]) -{ - char basename[PATH_MAX]; - char path[PATH_MAX]; - char *modules_argv[MAXPATHS + 1]; - char *copy, *p; - char **ap; - const char *filemode = "w"; /* mode for outfile */ - const char *modules_path = "modules"; /* path to kernel build directory */ - const char *outfile = ".asf"; /* and where to write the output */ - const char *corefile = NULL; /* for kvm(3) */ - const char *sysfile = NULL; /* for kvm(3) */ - const char **sfx; - struct kfile *kfp; - struct stat st; - FILE *out; /* output file */ - int dofind = 0; - int dokld = 0; - int dokvm = 0; - int nosubdir = 0; - int runprog = 0; - int i; - const int sl = strlen(KLDSUFFIX); - - while ((i = getopt(argc, argv, "afKkM:N:o:sVX:x")) != -1) - switch (i) { - case 'a': - filemode = "a"; /* append to outfile */ - break; - case 'f': - dofind = 1; /* find .ko (recursively) */ - break; - case 'K': - dokld = 1; /* use kld(2) interface */ - break; - case 'k': - runprog = 1; /* get input from kldstat(8) */ - break; - case 'M': - corefile = optarg; /* core file for kvm(3) */ - break; - case 'N': - sysfile = optarg; /* system file (kernel) for kvm(3) */ - break; - case 'o': - outfile = optarg; /* output file name */ - break; - case 's': - nosubdir = 1; /* don't descend into subdirs */ - break; - case 'V': - dokvm = 1; /* use kvm(3) interface */ - break; - case 'X': - if (nsuffixes >= MAXSUFFIXES) - errx(2, "only %d suffixes can be specified", MAXSUFFIXES); - suffixes[nsuffixes++] = optarg; - suffixes[nsuffixes] = NULL; - break; - case 'x': - nsuffixes = 0; - suffixes[0] = NULL; - break; - default: - usage(argv[0]); - } - - argc -= optind; - argv += optind; - - if (argc > 0) { - modules_path = argv[0]; - argc--, argv++; - } - if (argc > 0) { - outfile = argv[0]; - argc--, argv++; - } - if (argc > 0) - usage(argv[0]); - - if (strcmp(outfile, "-") == 0) - out = stdout; - else - if ((out = fopen(outfile, filemode)) == NULL) - err(2, "can't open output file %s", outfile); - - if (dokvm || corefile || sysfile) { - if (dokld || runprog) - warnx("using kvm(3) instead"); - asf_kvm(sysfile, corefile); - } else if (dokld) { - if (runprog) - warnx("using kld(2) instead"); - asf_kld(); - } else - asf_prog(runprog); - - /* Avoid long operations like module tree traversal when nothing to do */ - if (kfile_empty()) { - warnx("no kernel modules loaded"); - return (0); - } - - if ((copy = strdup(modules_path)) == NULL) - errx(2, "out of memory"); - for ( - ap = modules_argv, p = copy; - (*ap = strsep(&p, ";")) != NULL && ap < &modules_argv[MAXPATHS]; - ap++ - ); - if (*ap) - errx(2, "only %d module path elements can be specified", MAXPATHS); - - if (!dofind) - STAILQ_FOREACH(kfp, &kfile_head, link) { - for (ap = modules_argv; *ap; ap++) { - if (!nosubdir) { - /* prepare basename of KLD, w/o suffix */ - strlcpy(basename, kfp->name, sizeof(basename) - 1); - i = strlen(basename); - if (i > sl && strcmp(basename + i - sl, KLDSUFFIX) == 0) - i -= sl; - basename[i] = '/'; - basename[i + 1] = '\0'; - } - for (sfx = suffixes;; sfx++) { - snprintf(path, sizeof(path), - "%s/%s%s%s", - *ap, - nosubdir ? "" : basename, - kfp->name, - *sfx ? *sfx : ""); - if (stat(path, &st) == 0) { - doobj(path, kfp->addr, out); - goto found; - } - if (*sfx == NULL) - break; - } - } - warnx("module %s not found in search path", kfp->name); -found: - ; - } - else - findmodules(modules_argv, suffixes, out); - - free(copy); - return (0); -} diff --git a/usr.sbin/asf/asf.h b/usr.sbin/asf/asf.h deleted file mode 100644 index d034936..0000000 --- a/usr.sbin/asf/asf.h +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * Copyright (c) 2006 The FreeBSD Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#define KERNFILE "kernel" -#define KLDSUFFIX ".ko" - -#define MAXTOKEN 10 - -int tokenize(char *cptr, char *token[], int maxtoken); - -void kfile_add(const char *name, caddr_t addr); - -void asf_kld(void); -void asf_kvm(const char *kernfile, const char *corefile); -void asf_prog(int run); diff --git a/usr.sbin/asf/asf_kld.c b/usr.sbin/asf/asf_kld.c deleted file mode 100644 index f0bd699..0000000 --- a/usr.sbin/asf/asf_kld.c +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * Copyright (c) 2006 The FreeBSD Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include "asf.h" - -/* - * Get the linker file list using the kld interface. - * Works with a live kernel only. - */ -void -asf_kld(void) -{ - struct kld_file_stat kfs; - int fid = 0; /* indicates the beginning of the linker file list */ - - while ((fid = kldnext(fid)) != 0) { - if (fid == -1) - err(2, "kldnext"); - kfs.version = sizeof(kfs); /* must be set for kldstat(2) */ - /* Get info on this linker file */ - if (kldstat(fid, &kfs) == -1) - err(2, "kldstat"); - if (strcmp(kfs.name, KERNFILE) == 0) - continue; - /* Add to our list of linker files */ - kfile_add(kfs.name, kfs.address); - } -} diff --git a/usr.sbin/asf/asf_kvm.c b/usr.sbin/asf/asf_kvm.c deleted file mode 100644 index aa4effe..0000000 --- a/usr.sbin/asf/asf_kvm.c +++ /dev/null @@ -1,128 +0,0 @@ -/*- - * Copyright (c) 2006 The FreeBSD Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include /* for with _KERNEL defined */ -#include -#include -#include -#include -#include -#include -#include - -#define _KERNEL -#include -#undef _KERNEL - -#include "asf.h" - -/* Name of the head of the linker file list in /sys/kern/kern_linker.c */ -#define LINKER_HEAD "linker_files" - -/* - * Get the list of linker files using kvm(3). - * Can work with a live kernel as well as with a crash dump. - */ -void -asf_kvm(const char *kernfile, const char *corefile) -{ - char errbuf[LINE_MAX]; - char name[PATH_MAX]; - kvm_t *kd; - struct nlist nl[2]; - struct linker_file lf; - linker_file_list_t linker_files; - ssize_t n; - void *kp; - - kd = kvm_openfiles(kernfile, corefile, NULL, O_RDONLY, errbuf); - if (kd == NULL) - errx(2, "open kernel memory: %s", errbuf); - - /* - * Locate the head of the linker file list using kernel symbols. - */ - strcpy(name, LINKER_HEAD); - nl[0].n_name = name; /* can't use LINKER_HEAD here because it's const */ - nl[1].n_name = NULL; /* terminate the array for kvm_nlist() */ - switch (kvm_nlist(kd, nl)) { - case 0: - break; - case -1: - warnx("%s: %s", LINKER_HEAD, kvm_geterr(kd)); - kvm_close(kd); - exit(2); - default: - kvm_close(kd); - errx(2, "%s: symbol not found", LINKER_HEAD); - } - - /* - * Read the head of the linker file list from kernel memory. - */ - n = kvm_read(kd, nl[0].n_value, &linker_files, sizeof(linker_files)); - if (n == -1) - goto read_err; - if (n != sizeof(linker_files)) { - kvm_close(kd); - errx(2, "%s: short read", LINKER_HEAD); - } - - /* - * Traverse the linker file list starting at its head. - */ - for (kp = linker_files.tqh_first; kp; kp = lf.link.tqe_next) { - /* Read a linker file structure */ - n = kvm_read(kd, (u_long)kp, &lf, sizeof(lf)); - if (n == -1) - goto read_err; - if (n != sizeof(lf)) { - kvm_close(kd); - errx(2, "kvm: short read"); - } - /* Read the name of the file stored separately */ - bzero(name, sizeof(name)); - n = kvm_read(kd, (u_long)lf.filename, name, sizeof(name) - 1); - if (n == -1) - goto read_err; - if (strcmp(name, KERNFILE) == 0) - continue; - /* Add this file to our list of linker files */ - kfile_add(name, lf.address); - } - kvm_close(kd); - return; - -read_err: /* A common error case */ - warnx("read kernel memory: %s", kvm_geterr(kd)); - kvm_close(kd); - exit(2); -} diff --git a/usr.sbin/asf/asf_prog.c b/usr.sbin/asf/asf_prog.c deleted file mode 100644 index 9a13cd6..0000000 --- a/usr.sbin/asf/asf_prog.c +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * Copyright (c) 2002, 2003 Greg Lehey - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * This software is provided by the author ``as is'' and any express - * or implied warranties, including, but not limited to, the implied - * warranties of merchantability and fitness for a particular purpose - * are disclaimed. In no event shall the author be liable for any - * direct, indirect, incidental, special, exemplary, or consequential - * damages (including, but not limited to, procurement of substitute - * goods or services; loss of use, data, or profits; or business - * interruption) however caused and on any theory of liability, - * whether in contract, strict liability, or tort (including - * negligence or otherwise) arising in any way out of the use of this - * software, even if advised of the possibility of such damage. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -#include "asf.h" - -/* - * Get the linker file list from kldstat(8) output. - * The "run" flag tells if kldstat(8) should run now. - * Of course, kldstat(1) can run in a live system only, but its output - * can be saved beforehand and fed to this function later via stdin. - */ -void -asf_prog(int run) -{ - char buf[LINE_MAX]; - char *token[MAXTOKEN]; - char *endp; - FILE *kldstat; - caddr_t base; - int tokens; - - if (run) { - if ((kldstat = popen("kldstat", "r")) == NULL) - err(2, "can't start kldstat"); - } else - kldstat = stdin; - - while (fgets(buf, sizeof(buf), kldstat)) { - /* Skip header line and main kernel file */ - if (buf[0] == 'I' || strstr(buf, KERNFILE)) - continue; - tokens = tokenize(buf, token, MAXTOKEN); - if (tokens < 4) - continue; - base = (caddr_t)(uintptr_t)strtoumax(token[2], &endp, 16); - if (endp == NULL || *endp != '\0') - continue; - kfile_add(token[4], base); - } -} diff --git a/usr.sbin/audit/Makefile b/usr.sbin/audit/Makefile deleted file mode 100644 index a3f7fbf..0000000 --- a/usr.sbin/audit/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# -# $FreeBSD$ -# - -OPENBSMDIR=${.CURDIR}/../../contrib/openbsm -.PATH: ${OPENBSMDIR}/bin/audit - -CFLAGS+= -I${OPENBSMDIR} - -PROG= audit -MAN= audit.8 - -DPADD= ${LIBBSM} -LDADD= -lbsm - -WARNS?= 5 - -.include diff --git a/usr.sbin/auditd/Makefile b/usr.sbin/auditd/Makefile deleted file mode 100644 index 47ffd0b..0000000 --- a/usr.sbin/auditd/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# -# $FreeBSD$ -# - -OPENBSMDIR=${.CURDIR}/../../contrib/openbsm -.PATH: ${OPENBSMDIR}/bin/auditd - -CFLAGS+= -I${OPENBSMDIR} - -PROG= auditd -SRCS= auditd.c audit_warn.c auditd_fbsd.c -MAN= auditd.8 - -DPADD= ${LIBAUDITD} ${LIBBSM} -LDADD= -lauditd -lbsm - -WARNS?= 3 - -.include diff --git a/usr.sbin/auditreduce/Makefile b/usr.sbin/auditreduce/Makefile deleted file mode 100644 index 7dc9553..0000000 --- a/usr.sbin/auditreduce/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# -# $FreeBSD$ -# - -OPENBSMDIR=${.CURDIR}/../../contrib/openbsm -.PATH: ${OPENBSMDIR}/bin/auditreduce - -CFLAGS+= -I${OPENBSMDIR} - -PROG= auditreduce -MAN= auditreduce.1 - -DPADD= ${LIBBSM} -LDADD= -lbsm - -WARNS?= 3 - -.include diff --git a/usr.sbin/authpf/Makefile b/usr.sbin/authpf/Makefile deleted file mode 100644 index 0a24b8e..0000000 --- a/usr.sbin/authpf/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../contrib/pf/authpf -.PATH: ${.CURDIR}/../../contrib/pf/pfctl - -PROG= authpf -MAN= authpf.8 -BINOWN= root -BINGRP= authpf -BINMODE= 6555 - -SRCS= authpf.c - -CFLAGS+= -I${.CURDIR}/../../contrib/pf/pfctl - -# XXX ALTQ: -CFLAGS+= -DENABLE_ALTQ - -LDADD+= -lm -lmd -lutil -DPADD+= ${LIBM} ${LIBMD} ${LIBUTIL} - -WARNS?= 3 - -.include diff --git a/usr.sbin/bluetooth/Makefile b/usr.sbin/bluetooth/Makefile deleted file mode 100644 index ad193d0..0000000 --- a/usr.sbin/bluetooth/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# $Id: Makefile,v 1.5 2003/09/08 02:28:35 max Exp $ -# $FreeBSD$ - -SUBDIR= \ - bcmfw \ - bt3cfw \ - bthidcontrol \ - bthidd \ - btpand \ - hccontrol \ - hcsecd \ - hcseriald \ - l2control \ - l2ping \ - rfcomm_pppd \ - sdpcontrol \ - sdpd - -.include - diff --git a/usr.sbin/bluetooth/Makefile.inc b/usr.sbin/bluetooth/Makefile.inc deleted file mode 100644 index c0e05cf..0000000 --- a/usr.sbin/bluetooth/Makefile.inc +++ /dev/null @@ -1,4 +0,0 @@ -# $FreeBSD$ - -.include "${.CURDIR}/../../Makefile.inc" - diff --git a/usr.sbin/bluetooth/bcmfw/BCM-LEGAL.txt b/usr.sbin/bluetooth/bcmfw/BCM-LEGAL.txt deleted file mode 100644 index e3a235e..0000000 --- a/usr.sbin/bluetooth/bcmfw/BCM-LEGAL.txt +++ /dev/null @@ -1,8 +0,0 @@ -$FreeBSD$ - -BCM firmware version 2.15 -Copyright (c) 2000-2002 Broadcom Corporation - -Permission to distribute from.. -Contact info: - bluetooth_help@broadcom.com diff --git a/usr.sbin/bluetooth/bcmfw/Makefile b/usr.sbin/bluetooth/bcmfw/Makefile deleted file mode 100644 index 2427cf4..0000000 --- a/usr.sbin/bluetooth/bcmfw/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $Id: Makefile,v 1.6 2003/08/14 20:05:58 max Exp $ -# $FreeBSD$ - -PROG= bcmfw -MAN= bcmfw.8 -WARNS?= 2 - -.include diff --git a/usr.sbin/bluetooth/bcmfw/README b/usr.sbin/bluetooth/bcmfw/README deleted file mode 100644 index 0d769d8..0000000 --- a/usr.sbin/bluetooth/bcmfw/README +++ /dev/null @@ -1,22 +0,0 @@ -$FreeBSD$ - -This directory will eventually also contain copies of the broadcom firmware. - -It WILL look like: -total 190 -drwxr-xr-x 3 julian wheel 512 May 10 00:40 . -drwxr-xr-x 11 julian wheel 512 May 10 14:48 .. --rw-r--r-- 1 julian wheel 154 May 10 00:41 BCM-LEGAL.txt --rw-r--r-- 1 julian wheel 56 May 10 00:14 BCM2033-FW.bin.md5 --rw-r--r-- 1 julian wheel 158049 May 10 00:14 BCM2033-FW.bin.uue --rw-r--r-- 1 julian wheel 56 May 10 00:14 BCM2033-MD.hex.md5 --rw-r--r-- 1 julian wheel 4505 May 10 00:14 BCM2033-MD.hex.uue -drwxr-xr-x 2 julian wheel 512 May 10 00:52 CVS --rw-r--r-- 1 julian wheel 516 May 10 00:14 Makefile --rw-r--r-- 1 julian wheel 3013 May 10 00:14 bcmfw.8 --rw-r--r-- 1 julian wheel 6806 May 10 00:14 bcmfw.c - -Until then, the firmware files can be fetched as part of - http://bluez.sourceforge.net/download/bluez-bluefw-0.9.tar.gz - - diff --git a/usr.sbin/bluetooth/bcmfw/bcmfw.8 b/usr.sbin/bluetooth/bcmfw/bcmfw.8 deleted file mode 100644 index e799350..0000000 --- a/usr.sbin/bluetooth/bcmfw/bcmfw.8 +++ /dev/null @@ -1,105 +0,0 @@ -.\" Copyright (c) 2003 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: bcmfw.8,v 1.7 2003/05/21 00:33:40 max Exp $ -.\" $FreeBSD$ -.\" -.Dd March 31, 2003 -.Dt BCMFW 8 -.Os -.Sh NAME -.Nm bcmfw -.Nd firmware download utility for Broadcom BCM2033 chip based Bluetooth USB devices -.Sh SYNOPSIS -.Nm -.Op Fl h -.Fl f Ar firmware_file_name -.Fl m Ar mini-driver_file_name -.Fl n Ar device_name -.Sh DESCRIPTION -The -.Nm -utility downloads the specified mini-driver and firmware files to the specified -device. -.Pp -This utility will -.Em only -work with Broadcom BCM2033 chip based Bluetooth USB devices. -The identification is currently based on USB vendor ID/product ID pair. -The vendor ID should be 0x0a5c -.Pq Dv USB_VENDOR_BROADCOM -and the product ID should be 0x2033. -.Pp -Due to copyright issues I will no longer provide mini-driver and firmware -files for the device. -These files can be obtained from the Linux BlueZ bluez-firmware package. -.Pp -Visit -.Pa http://www.bluez.org/download.html -for details. -.Pp -I am using the following files from the bluez-firmware-1.0 package: -.Pp -.Dl "MD5 (BCM2033-MD.hex) = 5580317158d07fc4ace90af04f8e1c73" -.Dl "MD5 (BCM2033-FW.bin) = b4e142b3272cfe5a84b32fda6b4b032f" -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl f Ar firmware_file_name -Specify firmware file name for download. -.It Fl h -Display usage message and exit. -.It Fl m Ar mini-driver_file_name -Specify mini-driver file name for download. -.It Fl n Ar device_name -Specify device name. -.El -.Sh FILES -.Bl -tag -width ".Pa /dev/ubtbcmfw Ns Ar N Ns Pa \&. Ns Ar EE" -compact -.It Pa BCM2033-MD.hex -Mini-driver image. -.It Pa BCM2033-FW.bin -Firmware image. -.It Pa /dev/ubtbcmfw Ns Ar N Ns Pa \&. Ns Ar EE -Endpoint -.Ar EE -of device -.Ar N . -.El -.Sh EXIT STATUS -.Ex -std -.Sh EXAMPLES -To download the firmware into the -.Pa /dev/ubtbcmfw0 -device: -.Pp -.Dl "bcmfw -n ubtbcmfw0 -m BCM2033-MD.hex -f BCM2033-FW.bin" -.Sh SEE ALSO -.Xr ubtbcmfw 4 , -.Xr ugen 4 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh BUGS -Most likely. -Please report if found. diff --git a/usr.sbin/bluetooth/bcmfw/bcmfw.c b/usr.sbin/bluetooth/bcmfw/bcmfw.c deleted file mode 100644 index 29d9996c..0000000 --- a/usr.sbin/bluetooth/bcmfw/bcmfw.c +++ /dev/null @@ -1,308 +0,0 @@ -/* - * bcmfw.c - * - * Copyright (c) 2003 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bcmfw.c,v 1.4 2003/04/27 19:28:09 max Exp $ - * $FreeBSD$ - * - * Based on Linux BlueZ BlueFW-0.9 package - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BCMFW "bcmfw" -#define BCMFW_INTR_EP 1 -#define BCMFW_BULK_EP 2 -#define BCMFW_BSIZE 4096 - -#define USB_VENDOR_BROADCOM 0x0a5c -#define USB_PRODUCT_BROADCOM_BCM2033 0x2033 - -static int bcmfw_check_device - (char const *name); -static int bcmfw_load_firmware - (char const *name, char const *md, char const *fw); -static void bcmfw_usage - (void); - -/* - * Main - */ - -int -main(int argc, char *argv[]) -{ - char *name = NULL, *md = NULL, *fw = NULL; - int x; - - while ((x = getopt(argc, argv, "f:hn:m:")) != -1) { - switch (x) { - case 'f': /* firmware file */ - fw = optarg; - break; - - case 'n': /* name */ - name = optarg; - break; - - case 'm': /* Mini-driver */ - md = optarg; - break; - - case 'h': - default: - bcmfw_usage(); - /* NOT REACHED */ - } - } - - if (name == NULL || md == NULL || fw == NULL) - bcmfw_usage(); - /* NOT REACHED */ - - openlog(BCMFW, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_USER); - - if (bcmfw_check_device(name) < 0) - exit(1); - - if (bcmfw_load_firmware(name, md, fw) < 0) - exit(1); - - closelog(); - - return (0); -} /* main */ - -/* - * Check device VendorID/ProductID - */ - -static int -bcmfw_check_device(char const *name) -{ - usb_device_descriptor_t desc; - char path[BCMFW_BSIZE]; - int fd = -1, error = -1; - - snprintf(path, sizeof(path), "/dev/%s", name); - - if ((fd = open(path, O_WRONLY)) < 0) { - syslog(LOG_ERR, "Could not open(%s). %s (%d)", - path, strerror(errno), errno); - goto out; - } - - if (ioctl(fd, USB_GET_DEVICE_DESC, &desc) < 0) { - syslog(LOG_ERR, "Could not ioctl(%d, %ld, %p). %s (%d)", - fd, USB_GET_DEVICE_DESC, &desc, - strerror(errno), errno); - goto out; - } - - if (UGETW(desc.idVendor) != USB_VENDOR_BROADCOM || - UGETW(desc.idProduct) != USB_PRODUCT_BROADCOM_BCM2033) { - syslog(LOG_ERR, "Unsupported device, VendorID=%#x, " \ - "ProductID=%#x", UGETW(desc.idVendor), - UGETW(desc.idProduct)); - error = -1; - } else - error = 0; -out: - if (fd != -1) - close(fd); - - return (error); -} /* bcmfw_check_device */ - -/* - * Download minidriver and firmware - */ - -static int -bcmfw_load_firmware(char const *name, char const *md, char const *fw) -{ - char buf[BCMFW_BSIZE]; - int intr = -1, bulk = -1, fd = -1, error = -1, len; - - /* Open interrupt endpoint device */ - snprintf(buf, sizeof(buf), "/dev/%s.%d", name, BCMFW_INTR_EP); - if ((intr = open(buf, O_RDONLY)) < 0) { - syslog(LOG_ERR, "Could not open(%s). %s (%d)", - buf, strerror(errno), errno); - goto out; - } - - /* Open bulk endpoint device */ - snprintf(buf, sizeof(buf), "/dev/%s.%d", name, BCMFW_BULK_EP); - if ((bulk = open(buf, O_WRONLY)) < 0) { - syslog(LOG_ERR, "Could not open(%s). %s (%d)", - buf, strerror(errno), errno); - goto out; - } - - /* - * Load mini-driver - */ - - if ((fd = open(md, O_RDONLY)) < 0) { - syslog(LOG_ERR, "Could not open(%s). %s (%d)", - md, strerror(errno), errno); - goto out; - } - - for (;;) { - len = read(fd, buf, sizeof(buf)); - if (len < 0) { - syslog(LOG_ERR, "Could not read(%s). %s (%d)", - md, strerror(errno), errno); - goto out; - } - if (len == 0) - break; - - len = write(bulk, buf, len); - if (len < 0) { - syslog(LOG_ERR, "Could not write(/dev/%s.%d). %s (%d)", - name, BCMFW_BULK_EP, strerror(errno), - errno); - goto out; - } - } - - close(fd); - fd = -1; - - usleep(10); - - /* - * Memory select - */ - - if (write(bulk, "#", 1) < 0) { - syslog(LOG_ERR, "Could not write(/dev/%s.%d). %s (%d)", - name, BCMFW_BULK_EP, strerror(errno), errno); - goto out; - } - - if (read(intr, buf, sizeof(buf)) < 0) { - syslog(LOG_ERR, "Could not read(/dev/%s.%d). %s (%d)", - name, BCMFW_INTR_EP, strerror(errno), errno); - goto out; - } - - if (buf[0] != '#') { - syslog(LOG_ERR, "%s: Memory select failed (%c)", name, buf[0]); - goto out; - } - - /* - * Load firmware - */ - - if ((fd = open(fw, O_RDONLY)) < 0) { - syslog(LOG_ERR, "Could not open(%s). %s (%d)", - fw, strerror(errno), errno); - goto out; - } - - for (;;) { - len = read(fd, buf, sizeof(buf)); - if (len < 0) { - syslog(LOG_ERR, "Could not read(%s). %s (%d)", - fw, strerror(errno), errno); - goto out; - } - if (len == 0) - break; - - len = write(bulk, buf, len); - if (len < 0) { - syslog(LOG_ERR, "Could not write(/dev/%s.%d). %s (%d)", - name, BCMFW_BULK_EP, strerror(errno), - errno); - goto out; - } - } - - close(fd); - fd = -1; - - if (read(intr, buf, sizeof(buf)) < 0) { - syslog(LOG_ERR, "Could not read(/dev/%s.%d). %s (%d)", - name, BCMFW_INTR_EP, strerror(errno), errno); - goto out; - } - - if (buf[0] != '.') { - syslog(LOG_ERR, "%s: Could not load firmware (%c)", - name, buf[0]); - goto out; - } - - usleep(500000); - error = 0; -out: - if (fd != -1) - close(fd); - if (bulk != -1) - close(bulk); - if (intr != -1) - close(intr); - - return (error); -} /* bcmfw_load_firmware */ - -/* - * Display usage message and quit - */ - -static void -bcmfw_usage(void) -{ - fprintf(stdout, -"Usage: %s -n name -m md_file -f fw_file\n" -"Where:\n" \ -"\t-n name device name\n" \ -"\t-m mini-driver image mini-driver image file name for download\n" \ -"\t-f firmware image firmware image file name for download\n" \ -"\t-h display this message\n", BCMFW); - - exit(255); -} /* bcmfw_usage */ - diff --git a/usr.sbin/bluetooth/bt3cfw/Makefile b/usr.sbin/bluetooth/bt3cfw/Makefile deleted file mode 100644 index 90bf751..0000000 --- a/usr.sbin/bluetooth/bt3cfw/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $Id: Makefile,v 1.5 2003/08/14 20:06:00 max Exp $ -# $FreeBSD$ - -PROG= bt3cfw -MAN= bt3cfw.8 -WARNS?= 2 - -DPADD= ${LIBNETGRAPH} -LDADD= -lnetgraph - -.include diff --git a/usr.sbin/bluetooth/bt3cfw/bt3cfw.8 b/usr.sbin/bluetooth/bt3cfw/bt3cfw.8 deleted file mode 100644 index 54df178..0000000 --- a/usr.sbin/bluetooth/bt3cfw/bt3cfw.8 +++ /dev/null @@ -1,73 +0,0 @@ -.\" Copyright (c) 2001-2002 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: bt3cfw.8,v 1.4 2003/05/21 00:34:51 max Exp $ -.\" $FreeBSD$ -.\" -.Dd November 11, 2002 -.Dt BT3CFW 8 -.Os -.Sh NAME -.Nm bt3cfw -.Nd firmware download utility for 3Com Bluetooth PC card driver -.Sh SYNOPSIS -.Nm -.Op Fl h -.Fl f Ar Firmware_file_name -.Fl n Ar Netgraph_node_name -.Sh DESCRIPTION -The -.Nm -utility connects to the specified Netgraph driver node of type -.Dv BTCCC -and downloads the specified firmware file. -.Pp -Due to copyright issues, I will no longer provide firmware with the card -driver. -The firmware can be obtained from the Windows driver package that -can be downloaded from the 3COM web site at no charge. -The firmware name is -.Pa BT3CPCC.BIN . -I am using the original firmware that came with the card on CD-ROM. -.Pp -.Dl "MD5 (BT3CPCC.BIN) = 36170fda56ea9fdbf1702c966f8a97f1" -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl f Ar Firmware_file_name -Specify firmware file name for download. -.It Fl h -Display usage message and exit. -.It Fl n Ar Netgraph_node_name -Connect to the specified Netgraph driver node of type -.Dv BTCCC . -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr ng_bt3c 4 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh BUGS -Please report if found. diff --git a/usr.sbin/bluetooth/bt3cfw/bt3cfw.c b/usr.sbin/bluetooth/bt3cfw/bt3cfw.c deleted file mode 100644 index aadb6b6..0000000 --- a/usr.sbin/bluetooth/bt3cfw/bt3cfw.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * bt3cfw.c - * - * Copyright (c) 2001 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bt3cfw.c,v 1.2 2003/05/21 22:40:29 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BT3CFW_IDENT "bt3cfw" -#define BT3CFW_MAX_FIRMWARE_SIZE 0xffff - -/* Convert hex ASCII to int4 */ -static int -hexa2int4(const char *a) -{ - if ('0' <= *a && *a <= '9') - return (*a - '0'); - - if ('A' <= *a && *a <= 'F') - return (*a - 'A' + 0xa); - - if ('a' <= *a && *a <= 'f') - return (*a - 'a' + 0xa); - - syslog(LOG_ERR, "Invalid hex character: '%c' (%#x)", *a, *a); - exit(255); -} - -/* Convert hex ASCII to int8 */ -static int -hexa2int8(const char *a) -{ - return ((hexa2int4(a) << 4) | hexa2int4(a + 1)); -} - -/* Convert hex ASCII to int16 */ -static int -hexa2int16(const char *a) -{ - return ((hexa2int8(a) << 8) | hexa2int8(a + 2)); -} - -/* Convert hex ASCII to int32 */ -static int -hexa2int32(const char *a) -{ - return ((hexa2int16(a) << 16) | hexa2int16(a + 4)); -} - -/* Display usage() and exit */ -static void -usage(void) -{ - syslog(LOG_ERR, "Usage: %s -f FirmwareFile -n NodeName", BT3CFW_IDENT); - exit(255); -} - -/* Main */ -int -main(int argc, char *argv[]) -{ - FILE *firmware_file = NULL; - char buffer[80], path[NG_PATHSIZ], - *firmware_filename = NULL; - uint8_t *firmware = NULL; - int firmware_size, opt, cs, ds; - - memset(path, 0, sizeof(path)); - openlog(BT3CFW_IDENT, LOG_NDELAY|LOG_PID|LOG_PERROR, LOG_USER); - - while ((opt = getopt(argc, argv, "f:hn:")) != -1) { - switch (opt) { - case 'f': - firmware_filename = optarg; - break; - - case 'n': - snprintf(path, sizeof(path), "%s:", optarg); - break; - - case 'h': - default: - usage(); - /* NOT REACHED */ - } - } - - if (firmware_filename == NULL || path[0] == 0) - usage(); - /* NOT REACHED */ - - firmware = (uint8_t *) calloc(BT3CFW_MAX_FIRMWARE_SIZE, - sizeof(uint8_t)); - if (firmware == NULL) { - syslog(LOG_ERR, "Could not allocate firmware buffer"); - exit(255); - } - - if ((firmware_file = fopen(firmware_filename, "r")) == NULL) { - syslog(LOG_ERR, "Could not open BT3C firmware file %s. %s (%d)", - firmware_filename, strerror(errno), errno); - exit(255); - } - - firmware_size = 0; - - while (fgets(buffer, sizeof(buffer), firmware_file)) { - int i, size, address, cs, fcs; - - size = hexa2int8(buffer + 2); - address = hexa2int32(buffer + 4); - fcs = hexa2int8(buffer + 2 + size * 2); - - if (buffer[1] == '3') { - ng_bt3c_firmware_block_ep *block = NULL; - uint16_t *data = NULL; - - block = (ng_bt3c_firmware_block_ep *) - (firmware + firmware_size); - - firmware_size += sizeof(*block); - if (firmware_size >= BT3CFW_MAX_FIRMWARE_SIZE) { - syslog(LOG_ERR, "Could not add new firmware " \ - "block. Firmware file %s is " \ - "too big, firmware_size=%d", - firmware_filename, - firmware_size); - exit(255); - } - - block->block_address = address; - block->block_size = (size - 4) / 2; - block->block_alignment = (block->block_size * 2) % 3; - if (block->block_alignment != 0) - block->block_alignment = 3 - block->block_alignment; - - firmware_size += (block->block_size * 2); - firmware_size += block->block_alignment; - if (firmware_size >= BT3CFW_MAX_FIRMWARE_SIZE) { - syslog(LOG_ERR, "Could not add new firmware " \ - "data. Firmware file %s is " \ - "too big, firmware_size=%d", - firmware_filename, - firmware_size); - exit(255); - } - - /* First part of the cheksum: size and address */ - cs = 0; - for (i = 0; i < 5; i++) - cs += hexa2int8(buffer + 2 + i * 2); - - /* Data + second part of the cheksum: data */ - data = (uint16_t *)(block + 1); - for (i = 0; i < block->block_size; i++) { - data[i] = hexa2int16(buffer + (i * 4) + 12); - cs += (((data[i] & 0xff00) >> 8) & 0xff); - cs += (data[i] & 0x00ff); - } - } else - for (cs = 0, i = 0; i < size; i++) - cs += hexa2int8(buffer + 2 + i * 2); - - if (((cs + fcs) & 0xff) != 0xff) { - syslog(LOG_ERR, "Invalid firmware file %s. Checksum " \ - "error, cs=%#x, fcs=%#x, checksum=%#x", - firmware_filename, (cs & 0xff), fcs, - ((cs + fcs) & 0xff)); - exit(255); - } - } - - /* Send firmware to the card */ - if (NgMkSockNode(NULL, &cs, &ds) < 0) { - syslog(LOG_ERR, "Could not create Netgraph socket. %s (%d)", - strerror(errno), errno); - exit(255); - } - - if (NgSendMsg(cs, path, NGM_BT3C_COOKIE, - NGM_BT3C_NODE_DOWNLOAD_FIRMWARE, - (void const *) firmware, firmware_size) < 0) { - syslog(LOG_ERR, "Could not send Netgraph message. %s (%d)", - strerror(errno), errno); - exit(255); - } - - free(firmware); - firmware = NULL; - - return (0); -} - diff --git a/usr.sbin/bluetooth/bthidcontrol/Makefile b/usr.sbin/bluetooth/bthidcontrol/Makefile deleted file mode 100644 index 6c9eafb..0000000 --- a/usr.sbin/bluetooth/bthidcontrol/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# $Id: Makefile,v 1.2 2004/02/13 21:44:41 max Exp $ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../bthidd - -PROG= bthidcontrol -MAN= bthidcontrol.8 -SRCS= bthidcontrol.c hid.c lexer.l parser.y sdp.c -WARNS?= 1 -CFLAGS+= -DBTHIDCONTROL=1 -I${.CURDIR}/../bthidd - -DPADD= ${LIBBLUETOOTH} ${LIBSDP} ${LIBUSBHID} -LDADD= -lbluetooth -lsdp -lusbhid - -.include diff --git a/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.8 b/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.8 deleted file mode 100644 index 7625b39..0000000 --- a/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.8 +++ /dev/null @@ -1,102 +0,0 @@ -.\" Copyright (c) 2004 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: bthidcontrol.8,v 1.1 2004/02/13 21:44:41 max Exp $ -.\" $FreeBSD$ -.\" -.Dd October 30, 2006 -.Dt BTHIDCONTROL 8 -.Os -.Sh NAME -.Nm bthidcontrol -.Nd Bluetooth HID control utility -.Sh SYNOPSIS -.Nm -.Fl h -.Nm -.Op Fl a Ar BD_ADDR -.Op Fl c Ar file -.Op Fl H Ar file -.Op Fl v -.Ar command -.Sh DESCRIPTION -The -.Nm -utility can be used to query remote Bluetooth HID devices, dump HID descriptors -in human readable form and perform simple manipulations on the Bluetooth HID -daemon configuration files. -.Pp -The -.Nm -utility will print results to the standard output and error messages to the -standard error. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a Ar BD_ADDR -Specify BD_ADDR for the HID device. -Example: -.Fl a Li 00:01:02:03:04:05 . -.It Fl c Ar file -Specify path to the Bluetooth HID daemon configuration file. -The default path is -.Pa /etc/bluetooth/bthidd.conf . -.It Fl H Ar file -Specify path to the Bluetooth HID daemon known HIDs file. -The default path is -.Pa /var/db/bthidd.hids . -.It Fl h -Display usage message and exit. -.It Fl v -Be verbose and show items that are being used for padding. -.It Ar command -One of the supported commands (see below). -Special command -.Cm help -can be used to obtain the list of all supported commands. -To get more information about specific command use -.Cm help Ar command . -.El -.Sh COMMANDS -The currently supported node commands in -.Nm -are: -.Pp -.Bl -tag -offset indent -compact -.It Cm Query -.It Cm Dump -.It Cm Known -.It Cm Forget -.El -.Sh FILES -.Bl -tag -width ".Pa /etc/bluetooth/bthidd.conf" -compact -.It Pa /etc/bluetooth/bthidd.conf -.It Pa /var/db/bthidd.hids -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr bthidd 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com diff --git a/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.c b/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.c deleted file mode 100644 index 900bda5..0000000 --- a/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * bthidcontrol.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bthidcontrol.c,v 1.2 2004/02/13 21:44:41 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidcontrol.h" - -static int do_bthid_command(bdaddr_p bdaddr, int argc, char **argv); -static struct bthid_command * find_bthid_command(char const *command, struct bthid_command *category); -static void print_bthid_command(struct bthid_command *category); -static void usage(void); - -int32_t hid_sdp_query(bdaddr_t const *local, bdaddr_t const *remote, int32_t *error); - -uint32_t verbose = 0; - -/* - * bthidcontrol - */ - -int -main(int argc, char *argv[]) -{ - bdaddr_t bdaddr; - int opt; - - hid_init(NULL); - memcpy(&bdaddr, NG_HCI_BDADDR_ANY, sizeof(bdaddr)); - - while ((opt = getopt(argc, argv, "a:c:H:hv")) != -1) { - switch (opt) { - case 'a': /* bdaddr */ - if (!bt_aton(optarg, &bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(1, "%s: %s", optarg, hstrerror(h_errno)); - - memcpy(&bdaddr, he->h_addr, sizeof(bdaddr)); - } - break; - - case 'c': /* config file */ - config_file = optarg; - break; - - case 'H': /* HIDs file */ - hids_file = optarg; - break; - - case 'v': /* verbose */ - verbose++; - break; - - case 'h': - default: - usage(); - /* NOT REACHED */ - } - } - - argc -= optind; - argv += optind; - - if (*argv == NULL) - usage(); - - return (do_bthid_command(&bdaddr, argc, argv)); -} /* main */ - -/* Execute commands */ -static int -do_bthid_command(bdaddr_p bdaddr, int argc, char **argv) -{ - char *cmd = argv[0]; - struct bthid_command *c = NULL; - int e, help; - - help = 0; - if (strcasecmp(cmd, "help") == 0) { - argc --; - argv ++; - - if (argc <= 0) { - fprintf(stdout, "Supported commands:\n"); - print_bthid_command(sdp_commands); - print_bthid_command(hid_commands); - fprintf(stdout, "\nFor more information use " \ - "'help command'\n"); - - return (OK); - } - - help = 1; - cmd = argv[0]; - } - - c = find_bthid_command(cmd, sdp_commands); - if (c == NULL) - c = find_bthid_command(cmd, hid_commands); - - if (c == NULL) { - fprintf(stdout, "Unknown command: \"%s\"\n", cmd); - return (ERROR); - } - - if (!help) - e = (c->handler)(bdaddr, -- argc, ++ argv); - else - e = USAGE; - - switch (e) { - case OK: - case FAILED: - break; - - case ERROR: - fprintf(stdout, "Could not execute command \"%s\". %s\n", - cmd, strerror(errno)); - break; - - case USAGE: - fprintf(stdout, "Usage: %s\n%s\n", c->command, c->description); - break; - - default: assert(0); break; - } - - return (e); -} /* do_bthid_command */ - -/* Try to find command in specified category */ -static struct bthid_command * -find_bthid_command(char const *command, struct bthid_command *category) -{ - struct bthid_command *c = NULL; - - for (c = category; c->command != NULL; c++) { - char *c_end = strchr(c->command, ' '); - - if (c_end != NULL) { - int len = c_end - c->command; - - if (strncasecmp(command, c->command, len) == 0) - return (c); - } else if (strcasecmp(command, c->command) == 0) - return (c); - } - - return (NULL); -} /* find_bthid_command */ - -/* Print commands in specified category */ -static void -print_bthid_command(struct bthid_command *category) -{ - struct bthid_command *c = NULL; - - for (c = category; c->command != NULL; c++) - fprintf(stdout, "\t%s\n", c->command); -} /* print_bthid_command */ - -/* Usage */ -static void -usage(void) -{ - fprintf(stderr, -"Usage: bthidcontrol options command\n" \ -"Where options are:\n" -" -a bdaddr specify bdaddr\n" \ -" -c file specify path to the bthidd config file\n" \ -" -H file specify path to the bthidd HIDs file\n" \ -" -h display usage and quit\n" \ -" -v be verbose\n" \ -" command one of the supported commands\n"); - exit(255); -} /* usage */ - diff --git a/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.h b/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.h deleted file mode 100644 index 50ed2fa..0000000 --- a/usr.sbin/bluetooth/bthidcontrol/bthidcontrol.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * bthidcontrol.h - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bthidcontrol.h,v 1.1 2004/02/12 23:25:51 max Exp $ - * $FreeBSD$ - */ - -#ifndef __BTHIDCONTROL_H__ -#define __BTHIDCONTROL_H__ - -#define OK 0 /* everything was OK */ -#define ERROR 1 /* could not execute command */ -#define FAILED 2 /* error was reported */ -#define USAGE 3 /* invalid parameters */ - -struct bthid_command { - char const *command; - char const *description; - int (*handler)(bdaddr_t *, int, char **); -}; - -extern struct bthid_command hid_commands[]; -extern struct bthid_command sdp_commands[]; - -#endif /* __BTHIDCONTROL_H__ */ - diff --git a/usr.sbin/bluetooth/bthidcontrol/hid.c b/usr.sbin/bluetooth/bthidcontrol/hid.c deleted file mode 100644 index 9fb6220..0000000 --- a/usr.sbin/bluetooth/bthidcontrol/hid.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * hid.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: hid.c,v 1.3 2004/02/17 22:14:57 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidcontrol.h" - -extern uint32_t verbose; - -static void hid_dump_descriptor (report_desc_t r); -static void hid_dump_item (char const *label, struct hid_item *h); - -static int -hid_dump(bdaddr_t *bdaddr, int argc, char **argv) -{ - struct hid_device *hd = NULL; - int e = FAILED; - - if (read_config_file() == 0) { - if ((hd = get_hid_device(bdaddr)) != NULL) { - hid_dump_descriptor(hd->desc); - e = OK; - } - - clean_config(); - } - - return (e); -} - -static int -hid_forget(bdaddr_t *bdaddr, int argc, char **argv) -{ - struct hid_device *hd = NULL; - int e = FAILED; - - if (read_config_file() == 0) { - if (read_hids_file() == 0) { - if ((hd = get_hid_device(bdaddr)) != NULL) { - hd->new_device = 1; - if (write_hids_file() == 0) - e = OK; - } - } - - clean_config(); - } - - return (e); -} - -static int -hid_known(bdaddr_t *bdaddr, int argc, char **argv) -{ - struct hid_device *hd = NULL; - struct hostent *he = NULL; - int e = FAILED; - - if (read_config_file() == 0) { - if (read_hids_file() == 0) { - e = OK; - - for (hd = get_next_hid_device(hd); - hd != NULL; - hd = get_next_hid_device(hd)) { - if (hd->new_device) - continue; - - he = bt_gethostbyaddr((char *) &hd->bdaddr, - sizeof(hd->bdaddr), - AF_BLUETOOTH); - - fprintf(stdout, -"%s %s\n", bt_ntoa(&hd->bdaddr, NULL), - (he != NULL && he->h_name != NULL)? - he->h_name : ""); - } - } - - clean_config(); - } - - return (e); -} - -static void -hid_dump_descriptor(report_desc_t r) -{ - struct hid_data *d = NULL; - struct hid_item h; - - for (d = hid_start_parse(r, ~0, -1); hid_get_item(d, &h); ) { - switch (h.kind) { - case hid_collection: - fprintf(stdout, -"Collection page=%s usage=%s\n", hid_usage_page(HID_PAGE(h.usage)), - hid_usage_in_page(h.usage)); - break; - - case hid_endcollection: - fprintf(stdout, "End collection\n"); - break; - - case hid_input: - hid_dump_item("Input ", &h); - break; - - case hid_output: - hid_dump_item("Output ", &h); - break; - - case hid_feature: - hid_dump_item("Feature", &h); - break; - } - } - - hid_end_parse(d); -} - -static void -hid_dump_item(char const *label, struct hid_item *h) -{ - if ((h->flags & HIO_CONST) && !verbose) - return; - - fprintf(stdout, -"%s id=%u size=%u count=%u page=%s usage=%s%s%s%s%s%s%s%s%s%s", - label, (uint8_t) h->report_ID, h->report_size, h->report_count, - hid_usage_page(HID_PAGE(h->usage)), - hid_usage_in_page(h->usage), - h->flags & HIO_CONST ? " Const" : "", - h->flags & HIO_VARIABLE ? " Variable" : "", - h->flags & HIO_RELATIVE ? " Relative" : "", - h->flags & HIO_WRAP ? " Wrap" : "", - h->flags & HIO_NONLINEAR ? " NonLinear" : "", - h->flags & HIO_NOPREF ? " NoPref" : "", - h->flags & HIO_NULLSTATE ? " NullState" : "", - h->flags & HIO_VOLATILE ? " Volatile" : "", - h->flags & HIO_BUFBYTES ? " BufBytes" : ""); - - fprintf(stdout, -", logical range %d..%d", - h->logical_minimum, h->logical_maximum); - - if (h->physical_minimum != h->physical_maximum) - fprintf(stdout, -", physical range %d..%d", - h->physical_minimum, h->physical_maximum); - - if (h->unit) - fprintf(stdout, -", unit=0x%02x exp=%d", h->unit, h->unit_exponent); - - fprintf(stdout, "\n"); -} - -struct bthid_command hid_commands[] = { -{ -"Dump", -"Dump HID descriptor for the specified device in human readable form. The\n" \ -"device must have an entry in the Bluetooth HID daemon configuration file.\n", -hid_dump -}, -{ -"Known", -"List all known to the Bluetooth HID daemon devices.\n", -hid_known -}, -{ -"Forget", -"Forget (mark as new) specified HID device. This command is useful when it\n" \ -"is required to remove device from the known HIDs file. This should be done\n" \ -"when reset button was pressed on the device or the battery was changed. The\n"\ -"Bluetooth HID daemon should be restarted.\n", -hid_forget -}, -{ NULL, NULL, NULL } -}; - diff --git a/usr.sbin/bluetooth/bthidcontrol/sdp.c b/usr.sbin/bluetooth/bthidcontrol/sdp.c deleted file mode 100644 index a0b4534..0000000 --- a/usr.sbin/bluetooth/bthidcontrol/sdp.c +++ /dev/null @@ -1,434 +0,0 @@ -/* - * sdp.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: sdp.c,v 1.3 2004/02/17 22:14:57 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidcontrol.h" - -static int32_t hid_sdp_query (bdaddr_t const *local, struct hid_device *hd, int32_t *error); -static int32_t hid_sdp_parse_protocol_descriptor_list (sdp_attr_p a); -static int32_t hid_sdp_parse_hid_descriptor (sdp_attr_p a); -static int32_t hid_sdp_parse_boolean (sdp_attr_p a); - -static uint16_t service = SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE; - -static uint32_t attrs[] = { -SDP_ATTR_RANGE( SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST), -SDP_ATTR_RANGE (SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS, - SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS), -SDP_ATTR_RANGE( 0x0205, /* HIDReconnectInitiate */ - 0x0205), -SDP_ATTR_RANGE( 0x0206, /* HIDDescriptorList */ - 0x0206), -SDP_ATTR_RANGE( 0x0209, /* HIDBatteryPower */ - 0x0209), -SDP_ATTR_RANGE( 0x020d, /* HIDNormallyConnectable */ - 0x020d) - }; -#define nattrs (sizeof(attrs)/sizeof(attrs[0])) - -static sdp_attr_t values[8]; -#define nvalues (sizeof(values)/sizeof(values[0])) - -static uint8_t buffer[nvalues][512]; - -/* - * Query remote device - */ - -#undef hid_sdp_query_exit -#define hid_sdp_query_exit(e) { \ - if (error != NULL) \ - *error = (e); \ - if (ss != NULL) { \ - sdp_close(ss); \ - ss = NULL; \ - } \ - return (((e) == 0)? 0 : -1); \ -} - -static int32_t -hid_sdp_query(bdaddr_t const *local, struct hid_device *hd, int32_t *error) -{ - void *ss = NULL; - uint8_t *hid_descriptor = NULL; - int32_t i, control_psm = -1, interrupt_psm = -1, - reconnect_initiate = -1, - normally_connectable = 0, battery_power = 0, - hid_descriptor_length = -1; - - if (local == NULL) - local = NG_HCI_BDADDR_ANY; - if (hd == NULL) - hid_sdp_query_exit(EINVAL); - - for (i = 0; i < nvalues; i ++) { - values[i].flags = SDP_ATTR_INVALID; - values[i].attr = 0; - values[i].vlen = sizeof(buffer[i]); - values[i].value = buffer[i]; - } - - if ((ss = sdp_open(local, &hd->bdaddr)) == NULL) - hid_sdp_query_exit(ENOMEM); - if (sdp_error(ss) != 0) - hid_sdp_query_exit(sdp_error(ss)); - if (sdp_search(ss, 1, &service, nattrs, attrs, nvalues, values) != 0) - hid_sdp_query_exit(sdp_error(ss)); - - sdp_close(ss); - ss = NULL; - - for (i = 0; i < nvalues; i ++) { - if (values[i].flags != SDP_ATTR_OK) - continue; - - switch (values[i].attr) { - case SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST: - control_psm = hid_sdp_parse_protocol_descriptor_list(&values[i]); - break; - - case SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS: - interrupt_psm = hid_sdp_parse_protocol_descriptor_list(&values[i]); - break; - - case 0x0205: /* HIDReconnectInitiate */ - reconnect_initiate = hid_sdp_parse_boolean(&values[i]); - break; - - case 0x0206: /* HIDDescriptorList */ - if (hid_sdp_parse_hid_descriptor(&values[i]) == 0) { - hid_descriptor = values[i].value; - hid_descriptor_length = values[i].vlen; - } - break; - - case 0x0209: /* HIDBatteryPower */ - battery_power = hid_sdp_parse_boolean(&values[i]); - break; - - case 0x020d: /* HIDNormallyConnectable */ - normally_connectable = hid_sdp_parse_boolean(&values[i]); - break; - } - } - - if (control_psm == -1 || interrupt_psm == -1 || - reconnect_initiate == -1 || - hid_descriptor == NULL || hid_descriptor_length == -1) - hid_sdp_query_exit(ENOATTR); - - hd->control_psm = control_psm; - hd->interrupt_psm = interrupt_psm; - hd->reconnect_initiate = reconnect_initiate? 1 : 0; - hd->battery_power = battery_power? 1 : 0; - hd->normally_connectable = normally_connectable? 1 : 0; - hd->desc = hid_use_report_desc(hid_descriptor, hid_descriptor_length); - if (hd->desc == NULL) - hid_sdp_query_exit(ENOMEM); - - return (0); -} - -/* - * seq len 2 - * seq len 2 - * uuid value 3 - * uint16 value 3 - * seq len 2 - * uuid value 3 - */ - -static int32_t -hid_sdp_parse_protocol_descriptor_list(sdp_attr_p a) -{ - uint8_t *ptr = a->value; - uint8_t *end = a->value + a->vlen; - int32_t type, len, uuid, psm; - - if (end - ptr < 15) - return (-1); - - if (a->attr == SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS) { - SDP_GET8(type, ptr); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, ptr); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, ptr); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, ptr); - break; - - default: - return (-1); - } - if (ptr + len > end) - return (-1); - } - - SDP_GET8(type, ptr); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, ptr); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, ptr); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, ptr); - break; - - default: - return (-1); - } - if (ptr + len > end) - return (-1); - - /* Protocol */ - SDP_GET8(type, ptr); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, ptr); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, ptr); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, ptr); - break; - - default: - return (-1); - } - if (ptr + len > end) - return (-1); - - /* UUID */ - if (ptr + 3 > end) - return (-1); - SDP_GET8(type, ptr); - switch (type) { - case SDP_DATA_UUID16: - SDP_GET16(uuid, ptr); - if (uuid != SDP_UUID_PROTOCOL_L2CAP) - return (-1); - break; - - case SDP_DATA_UUID32: /* XXX FIXME can we have 32-bit UUID */ - case SDP_DATA_UUID128: /* XXX FIXME can we have 128-bit UUID */ - default: - return (-1); - } - - /* PSM */ - if (ptr + 3 > end) - return (-1); - SDP_GET8(type, ptr); - if (type != SDP_DATA_UINT16) - return (-1); - SDP_GET16(psm, ptr); - - return (psm); -} - -/* - * seq len 2 - * seq len 2 - * uint8 value8 2 - * str value 3 - */ - -static int32_t -hid_sdp_parse_hid_descriptor(sdp_attr_p a) -{ - uint8_t *ptr = a->value; - uint8_t *end = a->value + a->vlen; - int32_t type, len, descriptor_type; - - if (end - ptr < 9) - return (-1); - - SDP_GET8(type, ptr); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, ptr); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, ptr); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, ptr); - break; - - default: - return (-1); - } - if (ptr + len > end) - return (-1); - - while (ptr < end) { - /* Descriptor */ - SDP_GET8(type, ptr); - switch (type) { - case SDP_DATA_SEQ8: - if (ptr + 1 > end) - return (-1); - SDP_GET8(len, ptr); - break; - - case SDP_DATA_SEQ16: - if (ptr + 2 > end) - return (-1); - SDP_GET16(len, ptr); - break; - - case SDP_DATA_SEQ32: - if (ptr + 4 > end) - return (-1); - SDP_GET32(len, ptr); - break; - - default: - return (-1); - } - - /* Descripor type */ - if (ptr + 1 > end) - return (-1); - SDP_GET8(type, ptr); - if (type != SDP_DATA_UINT8 || ptr + 1 > end) - return (-1); - SDP_GET8(descriptor_type, ptr); - - /* Descriptor value */ - if (ptr + 1 > end) - return (-1); - SDP_GET8(type, ptr); - switch (type) { - case SDP_DATA_STR8: - if (ptr + 1 > end) - return (-1); - SDP_GET8(len, ptr); - break; - - case SDP_DATA_STR16: - if (ptr + 2 > end) - return (-1); - SDP_GET16(len, ptr); - break; - - case SDP_DATA_STR32: - if (ptr + 4 > end) - return (-1); - SDP_GET32(len, ptr); - break; - - default: - return (-1); - } - if (ptr + len > end) - return (-1); - - if (descriptor_type == UDESC_REPORT && len > 0) { - a->value = ptr; - a->vlen = len; - - return (0); - } - - ptr += len; - } - - return (-1); -} - -/* bool8 int8 */ -static int32_t -hid_sdp_parse_boolean(sdp_attr_p a) -{ - if (a->vlen != 2 || a->value[0] != SDP_DATA_BOOL) - return (-1); - - return (a->value[1]); -} - -/* Perform SDP query */ -static int32_t -hid_query(bdaddr_t *bdaddr, int argc, char **argv) -{ - struct hid_device hd; - int e; - - memcpy(&hd.bdaddr, bdaddr, sizeof(hd.bdaddr)); - if (hid_sdp_query(NULL, &hd, &e) < 0) { - fprintf(stderr, "Could not perform SDP query on the " \ - "device %s. %s (%d)\n", bt_ntoa(bdaddr, NULL), - strerror(e), e); - return (FAILED); - } - - print_hid_device(&hd, stdout); - - return (OK); -} - -struct bthid_command sdp_commands[] = -{ -{ -"Query", -"Perform SDP query to the specified device and print HID configuration entry\n"\ -"for the device. The configuration entry should be appended to the Bluetooth\n"\ -"HID daemon configuration file and the daemon should be restarted.\n", -hid_query -}, -{ NULL, NULL, NULL } -}; - diff --git a/usr.sbin/bluetooth/bthidd/Makefile b/usr.sbin/bluetooth/bthidd/Makefile deleted file mode 100644 index dd0754d..0000000 --- a/usr.sbin/bluetooth/bthidd/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# $Id: Makefile,v 1.6 2006/09/07 21:36:55 max Exp $ -# $FreeBSD$ - -PROG= bthidd -MAN= bthidd.8 -# bthidd.conf.5 -SRCS= bthidd.c client.c hid.c kbd.c lexer.l parser.y server.c \ - session.c - -CFLAGS+= -I${.CURDIR} -DEBUG_FLAGS= -g - -DPADD= ${LIBBLUETOOTH} ${LIBUSBHID} -LDADD= -lbluetooth -lusbhid - -.include diff --git a/usr.sbin/bluetooth/bthidd/bthid_config.h b/usr.sbin/bluetooth/bthidd/bthid_config.h deleted file mode 100644 index 71cb425..0000000 --- a/usr.sbin/bluetooth/bthidd/bthid_config.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * bthid_config.h - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bthid_config.h,v 1.4 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#ifndef _BTHID_CONFIG_H_ -#define _BTHID_CONFIG_H_ 1 - -#define BTHIDD_CONFFILE "/etc/bluetooth/bthidd.conf" -#define BTHIDD_HIDSFILE "/var/db/bthidd.hids" - -struct hid_device -{ - bdaddr_t bdaddr; /* HID device BDADDR */ - uint16_t control_psm; /* control PSM */ - uint16_t interrupt_psm; /* interrupt PSM */ - unsigned new_device : 1; - unsigned reconnect_initiate : 1; - unsigned battery_power : 1; - unsigned normally_connectable : 1; - unsigned keyboard : 1; - unsigned reserved : 11; - report_desc_t desc; /* HID report descriptor */ - LIST_ENTRY(hid_device) next; /* link to the next */ -}; -typedef struct hid_device hid_device_t; -typedef struct hid_device * hid_device_p; - -extern char const *config_file; -extern char const *hids_file; - -int32_t read_config_file (void); -void clean_config (void); -hid_device_p get_hid_device (bdaddr_p bdaddr); -hid_device_p get_next_hid_device (hid_device_p d); -void print_hid_device (hid_device_p hid_device, FILE *f); - -int32_t read_hids_file (void); -int32_t write_hids_file (void); - -#endif /* ndef _BTHID_CONFIG_H_ */ - diff --git a/usr.sbin/bluetooth/bthidd/bthidd.8 b/usr.sbin/bluetooth/bthidd/bthidd.8 deleted file mode 100644 index 8dd052e..0000000 --- a/usr.sbin/bluetooth/bthidd/bthidd.8 +++ /dev/null @@ -1,127 +0,0 @@ -.\" Copyright (c) 2006 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: bthidd.8,v 1.1 2006/09/07 21:36:55 max Exp $ -.\" $FreeBSD$ -.\" -.Dd September 7, 2006 -.Dt BTHIDD 8 -.Os -.Sh NAME -.Nm bthidd -.Nd Bluetooth HID daemon -.Sh SYNOPSIS -.Nm -.Fl h -.Nm -.Op Fl a Ar BD_ADDR -.Op Fl c Ar file -.Op Fl H Ar file -.Op Fl p Ar file -.Op Fl t Ar val -.Sh DESCRIPTION -The -.Nm -daemon handles remote Bluetooth HID devices. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a Ar BD_ADDR -Specify the local address to listen on. -By default, the server will listen on -.Dv ANY -address. -The address can be specified as BD_ADDR or name. -If a name was specified, the -.Nm -daemon will attempt to resolve the name via -.Xr bt_gethostbyname 3 . -.It Fl c Ar file -Specify path to the configuration file. -The default path is -.Pa /etc/bluetooth/bthidd.conf . -.It Fl d -Do not detach from the controlling terminal, i.e., run in foreground. -.It Fl H Ar file -Specify path to the known HIDs file. -The default path is -.Pa /var/db/bthidd.hids . -.It Fl h -Display usage message and exit. -.It Fl p Ar file -Specify path to the PID file. -The default path is -.Pa /var/run/bthidd.pid . -.It Fl t Ar val -Specify client rescan interval in seconds. -The -.Nm -daemon will periodically scan for newly configured Bluetooth HID devices or -disconnected -.Dq passive -Bluetooth HID devices and will attempt to establish an outgoing connection. -The default rescan interval is 10 seconds. -.El -.Sh KNOWN LIMITATIONS -The -.Nm -daemon currently does not handle key auto repeat and double click mouse events. -Those events work under -.Xr X 7 -just fine, -but not in text console. -.Pp -This manual page needs more work. -A manual page documenting the format of the -.Pa /etc/bluetooth/bthidd.conf -configuration file is needed as well. -.Sh FILES -.Bl -tag -width ".Pa /etc/bluetooth/bthidd.conf" -compact -.It Pa /etc/bluetooth/bthidd.conf -.It Pa /var/db/bthidd.hids -.It Pa /var/run/bthidd.pid -.El -.Sh SEE ALSO -.Xr kbdmux 4 , -.Xr vkbd 4 , -.Xr bthidcontrol 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh CAVEATS -Any Bluetooth HID device that has -.Dv HUP_KEYBOARD -or -.Dv HUP_CONSUMER -entries in its descriptor is considered as -.Dq keyboard . -For each -.Dq keyboard -Bluetooth HID device, -the -.Nm -daemon will use a separate instance of the virtual keyboard interface -.Xr vkbd 4 . -Therefore the -.Xr kbdmux 4 -driver must be used to properly multiplex input from multiple keyboards. diff --git a/usr.sbin/bluetooth/bthidd/bthidd.c b/usr.sbin/bluetooth/bthidd/bthidd.c deleted file mode 100644 index b93fd3d..0000000 --- a/usr.sbin/bluetooth/bthidd/bthidd.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - * bthidd.c - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bthidd.c,v 1.8 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidd.h" - -static int32_t write_pid_file (char const *file); -static int32_t remove_pid_file (char const *file); -static int32_t elapsed (int32_t tval); -static void sighandler (int32_t s); -static void usage (void); - -/* - * bthidd - */ - -static int32_t done = 0; /* are we done? */ - -int32_t -main(int32_t argc, char *argv[]) -{ - struct bthid_server srv; - struct sigaction sa; - char const *pid_file = BTHIDD_PIDFILE; - char *ep; - int32_t opt, detach, tval; - - memset(&srv, 0, sizeof(srv)); - memset(&srv.bdaddr, 0, sizeof(srv.bdaddr)); - detach = 1; - tval = 10; /* sec */ - - while ((opt = getopt(argc, argv, "a:c:dH:hp:t:")) != -1) { - switch (opt) { - case 'a': /* BDADDR */ - if (!bt_aton(optarg, &srv.bdaddr)) { - struct hostent *he; - - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(1, "%s: %s", optarg, hstrerror(h_errno)); - - memcpy(&srv.bdaddr, he->h_addr, sizeof(srv.bdaddr)); - } - break; - - case 'c': /* config file */ - config_file = optarg; - break; - - case 'd': /* do not detach */ - detach = 0; - break; - - case 'H': /* hids file */ - hids_file = optarg; - break; - - case 'p': /* pid file */ - pid_file = optarg; - break; - - case 't': /* rescan interval */ - tval = strtol(optarg, (char **) &ep, 10); - if (*ep != '\0' || tval <= 0) - usage(); - break; - - case 'h': - default: - usage(); - /* NOT REACHED */ - } - } - - openlog(BTHIDD_IDENT, LOG_PID|LOG_PERROR|LOG_NDELAY, LOG_USER); - - /* Become daemon if required */ - if (detach && daemon(0, 0) < 0) { - syslog(LOG_CRIT, "Could not become daemon. %s (%d)", - strerror(errno), errno); - exit(1); - } - - /* Install signal handler */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sighandler; - - if (sigaction(SIGTERM, &sa, NULL) < 0 || - sigaction(SIGHUP, &sa, NULL) < 0 || - sigaction(SIGINT, &sa, NULL) < 0) { - syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", - strerror(errno), errno); - exit(1); - } - - sa.sa_handler = SIG_IGN; - if (sigaction(SIGPIPE, &sa, NULL) < 0) { - syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", - strerror(errno), errno); - exit(1); - } - - sa.sa_handler = SIG_IGN; - sa.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT; - if (sigaction(SIGCHLD, &sa, NULL) < 0) { - syslog(LOG_CRIT, "Could not install signal handlers. %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (read_config_file() < 0 || read_hids_file() < 0 || - server_init(&srv) < 0 || write_pid_file(pid_file) < 0) - exit(1); - - for (done = 0; !done; ) { - if (elapsed(tval)) - client_rescan(&srv); - - if (server_do(&srv) < 0) - break; - } - - server_shutdown(&srv); - remove_pid_file(pid_file); - clean_config(); - closelog(); - - return (0); -} - -/* - * Write pid file - */ - -static int32_t -write_pid_file(char const *file) -{ - FILE *pid; - - assert(file != NULL); - - if ((pid = fopen(file, "w")) == NULL) { - syslog(LOG_ERR, "Could not open file %s. %s (%d)", - file, strerror(errno), errno); - return (-1); - } - - fprintf(pid, "%d", getpid()); - fclose(pid); - - return (0); -} - -/* - * Remote pid file - */ - -static int32_t -remove_pid_file(char const *file) -{ - assert(file != NULL); - - if (unlink(file) < 0) { - syslog(LOG_ERR, "Could not unlink file %s. %s (%d)", - file, strerror(errno), errno); - return (-1); - } - - return (0); -} - -/* - * Returns true if desired time interval has elapsed - */ - -static int32_t -elapsed(int32_t tval) -{ - static struct timeval last = { 0, 0 }; - struct timeval now; - - gettimeofday(&now, NULL); - - if (now.tv_sec - last.tv_sec >= tval) { - last = now; - return (1); - } - - return (0); -} - -/* - * Signal handler - */ - -static void -sighandler(int32_t s) -{ - syslog(LOG_NOTICE, "Got signal %d, total number of signals %d", - s, ++ done); -} - -/* - * Display usage and exit - */ - -static void -usage(void) -{ - fprintf(stderr, -"Usage: %s [options]\n" \ -"Where options are:\n" \ -" -a address specify address to listen on (default ANY)\n" \ -" -c file specify config file name\n" \ -" -d run in foreground\n" \ -" -H file specify known HIDs file name\n" \ -" -h display this message\n" \ -" -p file specify PID file name\n" \ -" -t tval specify client rescan interval (sec)\n" \ -"", BTHIDD_IDENT); - exit(255); -} - diff --git a/usr.sbin/bluetooth/bthidd/bthidd.conf.sample b/usr.sbin/bluetooth/bthidd/bthidd.conf.sample deleted file mode 100644 index e23dc12..0000000 --- a/usr.sbin/bluetooth/bthidd/bthidd.conf.sample +++ /dev/null @@ -1,72 +0,0 @@ -# $FreeBSD$ - -device { - bdaddr 00:50:f2:e5:68:84; - control_psm 0x11; - interrupt_psm 0x13; - reconnect_initiate true; - normally_connectable false; - hid_descriptor { - 0x05 0x01 0x09 0x02 0xa1 0x01 0x85 0x02 - 0x09 0x01 0xa1 0x00 0x05 0x09 0x19 0x01 - 0x29 0x05 0x15 0x00 0x25 0x01 0x75 0x01 - 0x95 0x05 0x81 0x02 0x75 0x03 0x95 0x01 - 0x81 0x01 0x05 0x01 0x09 0x30 0x09 0x31 - 0x09 0x38 0x15 0x81 0x25 0x7f 0x75 0x08 - 0x95 0x03 0x81 0x06 0xc0 0xc0 0x05 0x0c - 0x09 0x01 0xa1 0x01 0x85 0x03 0x05 0x01 - 0x09 0x02 0xa1 0x02 0x06 0x00 0xff 0x15 - 0x00 0x25 0x03 0x95 0x01 0x75 0x02 0x0a - 0x01 0xfe 0x81 0x02 0x75 0x06 0x81 0x01 - 0xc0 0xc0 - }; -} - -device { - bdaddr 00:50:f2:e3:fb:e1; - control_psm 0x11; - interrupt_psm 0x13; - reconnect_initiate true; - normally_connectable false; - hid_descriptor { - 0x05 0x01 0x09 0x06 0xa1 0x01 0x85 0x01 - 0x05 0x08 0x19 0x01 0x29 0x03 0x15 0x00 - 0x25 0x01 0x75 0x01 0x95 0x03 0x91 0x02 - 0x09 0x4b 0x95 0x01 0x91 0x02 0x95 0x04 - 0x91 0x01 0x05 0x07 0x19 0xe0 0x29 0xe7 - 0x95 0x08 0x81 0x02 0x75 0x08 0x95 0x01 - 0x81 0x01 0x19 0x00 0x29 0x91 0x26 0xff - 0x00 0x95 0x06 0x81 0x00 0xc0 0x05 0x0c - 0x09 0x01 0xa1 0x01 0x85 0x02 0x05 0x0c - 0x15 0x00 0x25 0x01 0x75 0x01 0x95 0x1c - 0x09 0xe2 0x09 0xb7 0x09 0xcd 0x09 0xea - 0x09 0xe9 0x09 0xb6 0x09 0xb5 0x0a 0x83 - 0x01 0x0a 0x1a 0x02 0x0a 0x79 0x02 0x0a - 0xab 0x01 0x0a 0x08 0x02 0x0a 0x02 0x02 - 0x0a 0x03 0x02 0x0a 0x07 0x02 0x0a 0x01 - 0x02 0x0a 0x92 0x01 0x0a 0x9c 0x01 0x09 - 0x95 0x0a 0x23 0x02 0x0a 0x89 0x02 0x0a - 0x8b 0x02 0x0a 0x8c 0x02 0x0a 0x8a 0x01 - 0x0a 0x99 0x01 0x0a 0xa7 0x01 0x0a 0xb6 - 0x01 0x0a 0xb7 0x01 0x81 0x02 0x75 0x01 - 0x95 0x04 0x81 0x01 0x06 0x00 0xff 0x0a - 0x02 0xff 0x26 0xff 0x00 0x95 0x01 0x75 - 0x08 0x81 0x02 0xc0 0x05 0x01 0x09 0x80 - 0xa1 0x01 0x85 0x03 0x19 0x81 0x29 0x83 - 0x25 0x01 0x95 0x03 0x75 0x01 0x81 0x02 - 0x95 0x05 0x81 0x01 0xc0 0x05 0x0c 0x09 - 0x01 0xa1 0x01 0x85 0x04 0x05 0x01 0x09 - 0x06 0xa1 0x02 0x06 0x00 0xff 0x15 0x00 - 0x25 0x03 0x95 0x01 0x75 0x02 0x0a 0x01 - 0xfe 0x81 0x02 0x75 0x06 0x81 0x01 0xc0 - 0xc0 0x05 0x0c 0x09 0x01 0xa1 0x01 0x85 - 0x05 0x05 0x01 0x09 0x06 0xa1 0x02 0x06 - 0x00 0xff 0x25 0x01 0x75 0x01 0x95 0x02 - 0x0a 0x03 0xfe 0x0a 0x04 0xfe 0x81 0x02 - 0x95 0x06 0x81 0x01 0xc0 0xc0 0x05 0x0c - 0x09 0x01 0xa1 0x01 0x85 0xff 0x05 0x06 - 0x95 0x01 0x75 0x02 0x19 0x24 0x29 0x26 - 0x81 0x02 0x75 0x06 0x81 0x01 0xc0 - }; -} - diff --git a/usr.sbin/bluetooth/bthidd/bthidd.h b/usr.sbin/bluetooth/bthidd/bthidd.h deleted file mode 100644 index 3485fc3..0000000 --- a/usr.sbin/bluetooth/bthidd/bthidd.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * bthidd.h - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bthidd.h,v 1.7 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#ifndef _BTHIDD_H_ -#define _BTHIDD_H_ 1 - -#define BTHIDD_IDENT "bthidd" -#define BTHIDD_PIDFILE "/var/run/" BTHIDD_IDENT ".pid" - -struct bthid_session; - -struct bthid_server -{ - bdaddr_t bdaddr; /* local bdaddr */ - int32_t cons; /* /dev/consolectl */ - int32_t ctrl; /* control channel (listen) */ - int32_t intr; /* intr. channel (listen) */ - int32_t maxfd; /* max fd in sets */ - fd_set rfdset; /* read descriptor set */ - fd_set wfdset; /* write descriptor set */ - LIST_HEAD(, bthid_session) sessions; -}; - -typedef struct bthid_server bthid_server_t; -typedef struct bthid_server * bthid_server_p; - -struct bthid_session -{ - bthid_server_p srv; /* pointer back to server */ - int32_t ctrl; /* control channel */ - int32_t intr; /* interrupt channel */ - int32_t vkbd; /* virual keyboard */ - bdaddr_t bdaddr;/* remote bdaddr */ - uint16_t state; /* session state */ -#define CLOSED 0 -#define W4CTRL 1 -#define W4INTR 2 -#define OPEN 3 - bitstr_t *keys1; /* keys map (new) */ - bitstr_t *keys2; /* keys map (old) */ - LIST_ENTRY(bthid_session) next; /* link to next */ -}; - -typedef struct bthid_session bthid_session_t; -typedef struct bthid_session * bthid_session_p; - -int32_t server_init (bthid_server_p srv); -void server_shutdown (bthid_server_p srv); -int32_t server_do (bthid_server_p srv); - -int32_t client_rescan (bthid_server_p srv); -int32_t client_connect (bthid_server_p srv, int fd); - -bthid_session_p session_open (bthid_server_p srv, hid_device_p const d); -bthid_session_p session_by_bdaddr(bthid_server_p srv, bdaddr_p bdaddr); -bthid_session_p session_by_fd (bthid_server_p srv, int32_t fd); -void session_close (bthid_session_p s); - -int32_t hid_control (bthid_session_p s, uint8_t *data, int32_t len); -int32_t hid_interrupt (bthid_session_p s, uint8_t *data, int32_t len); - -#endif /* ndef _BTHIDD_H_ */ - diff --git a/usr.sbin/bluetooth/bthidd/client.c b/usr.sbin/bluetooth/bthidd/client.c deleted file mode 100644 index 59f0d19..0000000 --- a/usr.sbin/bluetooth/bthidd/client.c +++ /dev/null @@ -1,256 +0,0 @@ -/* - * client.c - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: client.c,v 1.7 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidd.h" - -static int32_t client_socket(bdaddr_p bdaddr, uint16_t psm); - -/* - * Get next config entry and create outbound connection (if required) - * - * XXX Do only one device at a time. At least one of my devices (3COM - * Bluetooth PCCARD) rejects Create_Connection command if another - * Create_Connection command is still pending. Weird... - */ - -static int32_t connect_in_progress = 0; - -int32_t -client_rescan(bthid_server_p srv) -{ - static hid_device_p d; - bthid_session_p s; - - assert(srv != NULL); - - if (connect_in_progress) - return (0); /* another connect is still pending */ - - d = get_next_hid_device(d); - if (d == NULL) - return (0); /* XXX should not happen? empty config? */ - - if ((s = session_by_bdaddr(srv, &d->bdaddr)) != NULL) - return (0); /* session already active */ - - if (!d->new_device) { - if (d->reconnect_initiate) - return (0); /* device will initiate reconnect */ - } - - syslog(LOG_NOTICE, "Opening outbound session for %s " \ - "(new_device=%d, reconnect_initiate=%d)", - bt_ntoa(&d->bdaddr, NULL), d->new_device, d->reconnect_initiate); - - if ((s = session_open(srv, d)) == NULL) { - syslog(LOG_CRIT, "Could not create outbound session for %s", - bt_ntoa(&d->bdaddr, NULL)); - return (-1); - } - - /* Open control channel */ - s->ctrl = client_socket(&s->bdaddr, d->control_psm); - if (s->ctrl < 0) { - syslog(LOG_ERR, "Could not open control channel to %s. %s (%d)", - bt_ntoa(&s->bdaddr, NULL), strerror(errno), errno); - session_close(s); - return (-1); - } - - s->state = W4CTRL; - - FD_SET(s->ctrl, &srv->wfdset); - if (s->ctrl > srv->maxfd) - srv->maxfd = s->ctrl; - - connect_in_progress = 1; - - return (0); -} - -/* - * Process connect on the socket - */ - -int32_t -client_connect(bthid_server_p srv, int32_t fd) -{ - bthid_session_p s; - hid_device_p d; - int32_t error; - socklen_t len; - - assert(srv != NULL); - assert(fd >= 0); - - s = session_by_fd(srv, fd); - assert(s != NULL); - - d = get_hid_device(&s->bdaddr); - assert(d != NULL); - - error = 0; - len = sizeof(error); - if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { - syslog(LOG_ERR, "Could not get socket error for %s. %s (%d)", - bt_ntoa(&s->bdaddr, NULL), strerror(errno), errno); - session_close(s); - connect_in_progress = 0; - - return (-1); - } - - if (error != 0) { - syslog(LOG_ERR, "Could not connect to %s. %s (%d)", - bt_ntoa(&s->bdaddr, NULL), strerror(error), error); - session_close(s); - connect_in_progress = 0; - - return (0); - } - - switch (s->state) { - case W4CTRL: /* Control channel is open */ - assert(s->ctrl == fd); - assert(s->intr == -1); - - /* Open interrupt channel */ - s->intr = client_socket(&s->bdaddr, d->interrupt_psm); - if (s->intr < 0) { - syslog(LOG_ERR, "Could not open interrupt channel " \ - "to %s. %s (%d)", bt_ntoa(&s->bdaddr, NULL), - strerror(errno), errno); - session_close(s); - connect_in_progress = 0; - - return (-1); - } - - s->state = W4INTR; - - FD_SET(s->intr, &srv->wfdset); - if (s->intr > srv->maxfd) - srv->maxfd = s->intr; - - d->new_device = 0; /* reset new device flag */ - write_hids_file(); - break; - - case W4INTR: /* Interrupt channel is open */ - assert(s->ctrl != -1); - assert(s->intr == fd); - - s->state = OPEN; - connect_in_progress = 0; - - /* Register session's vkbd descriptor (if any) for read */ - if (s->state == OPEN && d->keyboard) { - assert(s->vkbd != -1); - - FD_SET(s->vkbd, &srv->rfdset); - if (s->vkbd > srv->maxfd) - srv->maxfd = s->vkbd; - } - break; - - default: - assert(0); - break; - } - - /* Move fd to from the write fd set into read fd set */ - FD_CLR(fd, &srv->wfdset); - FD_SET(fd, &srv->rfdset); - - return (0); -} - -/* - * Create bound non-blocking socket and initiate connect - */ - -static int -client_socket(bdaddr_p bdaddr, uint16_t psm) -{ - struct sockaddr_l2cap l2addr; - int32_t s, m; - - s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP); - if (s < 0) - return (-1); - - m = fcntl(s, F_GETFL); - if (m < 0) { - close(s); - return (-1); - } - - if (fcntl(s, F_SETFL, (m|O_NONBLOCK)) < 0) { - close(s); - return (-1); - } - - l2addr.l2cap_len = sizeof(l2addr); - l2addr.l2cap_family = AF_BLUETOOTH; - memset(&l2addr.l2cap_bdaddr, 0, sizeof(l2addr.l2cap_bdaddr)); - l2addr.l2cap_psm = 0; - - if (bind(s, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0) { - close(s); - return (-1); - } - - memcpy(&l2addr.l2cap_bdaddr, bdaddr, sizeof(l2addr.l2cap_bdaddr)); - l2addr.l2cap_psm = htole16(psm); - - if (connect(s, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0 && - errno != EINPROGRESS) { - close(s); - return (-1); - } - - return (s); -} - diff --git a/usr.sbin/bluetooth/bthidd/hid.c b/usr.sbin/bluetooth/bthidd/hid.c deleted file mode 100644 index 8c0db6c..0000000 --- a/usr.sbin/bluetooth/bthidd/hid.c +++ /dev/null @@ -1,397 +0,0 @@ -/* - * hid.c - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: hid.c,v 1.5 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidd.h" -#include "kbd.h" - -#undef min -#define min(x, y) (((x) < (y))? (x) : (y)) - -#undef ASIZE -#define ASIZE(a) (sizeof(a)/sizeof(a[0])) - -/* - * Process data from control channel - */ - -int32_t -hid_control(bthid_session_p s, uint8_t *data, int32_t len) -{ - assert(s != NULL); - assert(data != NULL); - assert(len > 0); - - switch (data[0] >> 4) { - case 0: /* Handshake (response to command) */ - if (data[0] & 0xf) - syslog(LOG_ERR, "Got handshake message with error " \ - "response 0x%x from %s", - data[0], bt_ntoa(&s->bdaddr, NULL)); - break; - - case 1: /* HID Control */ - switch (data[0] & 0xf) { - case 0: /* NOP */ - break; - - case 1: /* Hard reset */ - case 2: /* Soft reset */ - syslog(LOG_WARNING, "Device %s requested %s reset", - bt_ntoa(&s->bdaddr, NULL), - ((data[0] & 0xf) == 1)? "hard" : "soft"); - break; - - case 3: /* Suspend */ - syslog(LOG_NOTICE, "Device %s requested Suspend", - bt_ntoa(&s->bdaddr, NULL)); - break; - - case 4: /* Exit suspend */ - syslog(LOG_NOTICE, "Device %s requested Exit Suspend", - bt_ntoa(&s->bdaddr, NULL)); - break; - - case 5: /* Virtual cable unplug */ - syslog(LOG_NOTICE, "Device %s unplugged virtual cable", - bt_ntoa(&s->bdaddr, NULL)); - session_close(s); - break; - - default: - syslog(LOG_WARNING, "Device %s sent unknown " \ - "HID_Control message 0x%x", - bt_ntoa(&s->bdaddr, NULL), data[0]); - break; - } - break; - - default: - syslog(LOG_WARNING, "Got unexpected message 0x%x on Control " \ - "channel from %s", data[0], bt_ntoa(&s->bdaddr, NULL)); - break; - } - - return (0); -} - -/* - * Process data from the interrupt channel - */ - -int32_t -hid_interrupt(bthid_session_p s, uint8_t *data, int32_t len) -{ - hid_device_p hid_device; - hid_data_t d; - hid_item_t h; - int32_t report_id, usage, page, val, - mouse_x, mouse_y, mouse_z, mouse_butt, - mevents, kevents, i; - - assert(s != NULL); - assert(s->srv != NULL); - assert(data != NULL); - - if (len < 3) { - syslog(LOG_ERR, "Got short message (%d bytes) on Interrupt " \ - "channel from %s", len, bt_ntoa(&s->bdaddr, NULL)); - return (-1); - } - - if (data[0] != 0xa1) { - syslog(LOG_ERR, "Got unexpected message 0x%x on " \ - "Interrupt channel from %s", - data[0], bt_ntoa(&s->bdaddr, NULL)); - return (-1); - } - - report_id = data[1]; - data ++; - len --; - - hid_device = get_hid_device(&s->bdaddr); - assert(hid_device != NULL); - - mouse_x = mouse_y = mouse_z = mouse_butt = mevents = kevents = 0; - - for (d = hid_start_parse(hid_device->desc, 1 << hid_input, -1); - hid_get_item(d, &h) > 0; ) { - if ((h.flags & HIO_CONST) || (h.report_ID != report_id) || - (h.kind != hid_input)) - continue; - - page = HID_PAGE(h.usage); - usage = HID_USAGE(h.usage); - val = hid_get_data(data, &h); - - switch (page) { - case HUP_GENERIC_DESKTOP: - switch (usage) { - case HUG_X: - mouse_x = val; - mevents ++; - break; - - case HUG_Y: - mouse_y = val; - mevents ++; - break; - - case HUG_WHEEL: - mouse_z = -val; - mevents ++; - break; - - case HUG_SYSTEM_SLEEP: - if (val) - syslog(LOG_NOTICE, "Sleep button pressed"); - break; - } - break; - - case HUP_KEYBOARD: - kevents ++; - - if (h.flags & HIO_VARIABLE) { - if (val && usage < kbd_maxkey()) - bit_set(s->keys1, usage); - } else { - if (val && val < kbd_maxkey()) - bit_set(s->keys1, val); - - for (i = 1; i < h.report_count; i++) { - h.pos += h.report_size; - val = hid_get_data(data, &h); - if (val && val < kbd_maxkey()) - bit_set(s->keys1, val); - } - } - break; - - case HUP_BUTTON: - if (usage != 0) { - if (usage == 2) - usage = 3; - else if (usage == 3) - usage = 2; - - mouse_butt |= (val << (usage - 1)); - mevents ++; - } - break; - - case HUP_CONSUMER: - if (!val) - break; - - switch (usage) { - case 0xb5: /* Scan Next Track */ - val = 0x19; - break; - - case 0xb6: /* Scan Previous Track */ - val = 0x10; - break; - - case 0xb7: /* Stop */ - val = 0x24; - break; - - case 0xcd: /* Play/Pause */ - val = 0x22; - break; - - case 0xe2: /* Mute */ - val = 0x20; - break; - - case 0xe9: /* Volume Up */ - val = 0x30; - break; - - case 0xea: /* Volume Down */ - val = 0x2E; - break; - - case 0x183: /* Media Select */ - val = 0x6D; - break; - - case 0x018a: /* Mail */ - val = 0x6C; - break; - - case 0x192: /* Calculator */ - val = 0x21; - break; - - case 0x194: /* My Computer */ - val = 0x6B; - break; - - case 0x221: /* WWW Search */ - val = 0x65; - break; - - case 0x223: /* WWW Home */ - val = 0x32; - break; - - case 0x224: /* WWW Back */ - val = 0x6A; - break; - - case 0x225: /* WWW Forward */ - val = 0x69; - break; - - case 0x226: /* WWW Stop */ - val = 0x68; - break; - - case 0x227: /* WWW Refresh */ - val = 0x67; - break; - - case 0x22a: /* WWW Favorites */ - val = 0x66; - break; - - default: - val = 0; - break; - } - - /* XXX FIXME - UGLY HACK */ - if (val != 0) { - if (hid_device->keyboard) { - int32_t buf[4] = { 0xe0, val, - 0xe0, val|0x80 }; - - assert(s->vkbd != -1); - write(s->vkbd, buf, sizeof(buf)); - } else - syslog(LOG_ERR, "Keyboard events " \ - "received from non-keyboard " \ - "device %s. Please report", - bt_ntoa(&s->bdaddr, NULL)); - } - break; - - case HUP_MICROSOFT: - switch (usage) { - case 0xfe01: - if (!hid_device->battery_power) - break; - - switch (val) { - case 1: - syslog(LOG_INFO, "Battery is OK on %s", - bt_ntoa(&s->bdaddr, NULL)); - break; - - case 2: - syslog(LOG_NOTICE, "Low battery on %s", - bt_ntoa(&s->bdaddr, NULL)); - break; - - case 3: - syslog(LOG_WARNING, "Very low battery "\ - "on %s", - bt_ntoa(&s->bdaddr, NULL)); - break; - } - break; - } - break; - } - } - hid_end_parse(d); - - /* - * XXX FIXME Feed keyboard events into kernel. - * The code below works, bit host also needs to track - * and handle repeat. - * - * Key repeat currently works in X, but not in console. - */ - - if (kevents > 0) { - if (hid_device->keyboard) { - assert(s->vkbd != -1); - kbd_process_keys(s); - } else - syslog(LOG_ERR, "Keyboard events received from " \ - "non-keyboard device %s. Please report", - bt_ntoa(&s->bdaddr, NULL)); - } - - /* - * XXX FIXME Feed mouse events into kernel. - * The code block below works, but it is not good enough. - * Need to track double-clicks etc. - * - * Double click currently works in X, but not in console. - */ - - if (mevents > 0) { - struct mouse_info mi; - - mi.operation = MOUSE_ACTION; - mi.u.data.x = mouse_x; - mi.u.data.y = mouse_y; - mi.u.data.z = mouse_z; - mi.u.data.buttons = mouse_butt; - - if (ioctl(s->srv->cons, CONS_MOUSECTL, &mi) < 0) - syslog(LOG_ERR, "Could not process mouse events from " \ - "%s. %s (%d)", bt_ntoa(&s->bdaddr, NULL), - strerror(errno), errno); - } - - return (0); -} diff --git a/usr.sbin/bluetooth/bthidd/kbd.c b/usr.sbin/bluetooth/bthidd/kbd.c deleted file mode 100644 index e1ab870..0000000 --- a/usr.sbin/bluetooth/bthidd/kbd.c +++ /dev/null @@ -1,580 +0,0 @@ -/* - * kbd.c - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: kbd.c,v 1.4 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidd.h" -#include "kbd.h" - -static void kbd_write(bitstr_t *m, int32_t fb, int32_t make, int32_t fd); -static int32_t kbd_xlate(int32_t code, int32_t make, int32_t *b, int32_t const *eob); - -/* - * HID code to PS/2 set 1 code translation table. - * - * http://www.microsoft.com/whdc/device/input/Scancode.mspx - * - * The table only contains "make" (key pressed) codes. - * The "break" (key released) code is generated as "make" | 0x80 - */ - -#define E0PREFIX (1 << 31) -#define NOBREAK (1 << 30) -#define CODEMASK (~(E0PREFIX|NOBREAK)) - -static int32_t const x[] = -{ -/*==================================================*/ -/* Name HID code Make Break*/ -/*==================================================*/ -/* No Event 00 */ -1, /* None */ -/* Overrun Error 01 */ NOBREAK|0xFF, /* None */ -/* POST Fail 02 */ NOBREAK|0xFC, /* None */ -/* ErrorUndefined 03 */ -1, /* Unassigned */ -/* a A 04 */ 0x1E, /* 9E */ -/* b B 05 */ 0x30, /* B0 */ -/* c C 06 */ 0x2E, /* AE */ -/* d D 07 */ 0x20, /* A0 */ -/* e E 08 */ 0x12, /* 92 */ -/* f F 09 */ 0x21, /* A1 */ -/* g G 0A */ 0x22, /* A2 */ -/* h H 0B */ 0x23, /* A3 */ -/* i I 0C */ 0x17, /* 97 */ -/* j J 0D */ 0x24, /* A4 */ -/* k K 0E */ 0x25, /* A5 */ -/* l L 0F */ 0x26, /* A6 */ -/* m M 10 */ 0x32, /* B2 */ -/* n N 11 */ 0x31, /* B1 */ -/* o O 12 */ 0x18, /* 98 */ -/* p P 13 */ 0x19, /* 99 */ -/* q Q 14 */ 0x10, /* 90 */ -/* r R 15 */ 0x13, /* 93 */ -/* s S 16 */ 0x1F, /* 9F */ -/* t T 17 */ 0x14, /* 94 */ -/* u U 18 */ 0x16, /* 96 */ -/* v V 19 */ 0x2F, /* AF */ -/* w W 1A */ 0x11, /* 91 */ -/* x X 1B */ 0x2D, /* AD */ -/* y Y 1C */ 0x15, /* 95 */ -/* z Z 1D */ 0x2C, /* AC */ -/* 1 ! 1E */ 0x02, /* 82 */ -/* 2 @ 1F */ 0x03, /* 83 */ -/* 3 # 20 */ 0x04, /* 84 */ -/* 4 $ 21 */ 0x05, /* 85 */ -/* 5 % 22 */ 0x06, /* 86 */ -/* 6 ^ 23 */ 0x07, /* 87 */ -/* 7 & 24 */ 0x08, /* 88 */ -/* 8 * 25 */ 0x09, /* 89 */ -/* 9 ( 26 */ 0x0A, /* 8A */ -/* 0 ) 27 */ 0x0B, /* 8B */ -/* Return 28 */ 0x1C, /* 9C */ -/* Escape 29 */ 0x01, /* 81 */ -/* Backspace 2A */ 0x0E, /* 8E */ -/* Tab 2B */ 0x0F, /* 8F */ -/* Space 2C */ 0x39, /* B9 */ -/* - _ 2D */ 0x0C, /* 8C */ -/* = + 2E */ 0x0D, /* 8D */ -/* [ { 2F */ 0x1A, /* 9A */ -/* ] } 30 */ 0x1B, /* 9B */ -/* \ | 31 */ 0x2B, /* AB */ -/* Europe 1 32 */ 0x2B, /* AB */ -/* ; : 33 */ 0x27, /* A7 */ -/* " ' 34 */ 0x28, /* A8 */ -/* ` ~ 35 */ 0x29, /* A9 */ -/* comma < 36 */ 0x33, /* B3 */ -/* . > 37 */ 0x34, /* B4 */ -/* / ? 38 */ 0x35, /* B5 */ -/* Caps Lock 39 */ 0x3A, /* BA */ -/* F1 3A */ 0x3B, /* BB */ -/* F2 3B */ 0x3C, /* BC */ -/* F3 3C */ 0x3D, /* BD */ -/* F4 3D */ 0x3E, /* BE */ -/* F5 3E */ 0x3F, /* BF */ -/* F6 3F */ 0x40, /* C0 */ -/* F7 40 */ 0x41, /* C1 */ -/* F8 41 */ 0x42, /* C2 */ -/* F9 42 */ 0x43, /* C3 */ -/* F10 43 */ 0x44, /* C4 */ -/* F11 44 */ 0x57, /* D7 */ -/* F12 45 */ 0x58, /* D8 */ -/* Print Screen 46 */ E0PREFIX|0x37, /* E0 B7 */ -/* Scroll Lock 47 */ 0x46, /* C6 */ -#if 0 -/* Break (Ctrl-Pause) 48 */ E0 46 E0 C6, /* None */ -/* Pause 48 */ E1 1D 45 E1 9D C5, /* None */ -#else -/* Break (Ctrl-Pause)/Pause 48 */ NOBREAK /* Special case */, /* None */ -#endif -/* Insert 49 */ E0PREFIX|0x52, /* E0 D2 */ -/* Home 4A */ E0PREFIX|0x47, /* E0 C7 */ -/* Page Up 4B */ E0PREFIX|0x49, /* E0 C9 */ -/* Delete 4C */ E0PREFIX|0x53, /* E0 D3 */ -/* End 4D */ E0PREFIX|0x4F, /* E0 CF */ -/* Page Down 4E */ E0PREFIX|0x51, /* E0 D1 */ -/* Right Arrow 4F */ E0PREFIX|0x4D, /* E0 CD */ -/* Left Arrow 50 */ E0PREFIX|0x4B, /* E0 CB */ -/* Down Arrow 51 */ E0PREFIX|0x50, /* E0 D0 */ -/* Up Arrow 52 */ E0PREFIX|0x48, /* E0 C8 */ -/* Num Lock 53 */ 0x45, /* C5 */ -/* Keypad / 54 */ E0PREFIX|0x35, /* E0 B5 */ -/* Keypad * 55 */ 0x37, /* B7 */ -/* Keypad - 56 */ 0x4A, /* CA */ -/* Keypad + 57 */ 0x4E, /* CE */ -/* Keypad Enter 58 */ E0PREFIX|0x1C, /* E0 9C */ -/* Keypad 1 End 59 */ 0x4F, /* CF */ -/* Keypad 2 Down 5A */ 0x50, /* D0 */ -/* Keypad 3 PageDn 5B */ 0x51, /* D1 */ -/* Keypad 4 Left 5C */ 0x4B, /* CB */ -/* Keypad 5 5D */ 0x4C, /* CC */ -/* Keypad 6 Right 5E */ 0x4D, /* CD */ -/* Keypad 7 Home 5F */ 0x47, /* C7 */ -/* Keypad 8 Up 60 */ 0x48, /* C8 */ -/* Keypad 9 PageUp 61 */ 0x49, /* C9 */ -/* Keypad 0 Insert 62 */ 0x52, /* D2 */ -/* Keypad . Delete 63 */ 0x53, /* D3 */ -/* Europe 2 64 */ 0x56, /* D6 */ -/* App 65 */ E0PREFIX|0x5D, /* E0 DD */ -/* Keyboard Power 66 */ E0PREFIX|0x5E, /* E0 DE */ -/* Keypad = 67 */ 0x59, /* D9 */ -/* F13 68 */ 0x64, /* E4 */ -/* F14 69 */ 0x65, /* E5 */ -/* F15 6A */ 0x66, /* E6 */ -/* F16 6B */ 0x67, /* E7 */ -/* F17 6C */ 0x68, /* E8 */ -/* F18 6D */ 0x69, /* E9 */ -/* F19 6E */ 0x6A, /* EA */ -/* F20 6F */ 0x6B, /* EB */ -/* F21 70 */ 0x6C, /* EC */ -/* F22 71 */ 0x6D, /* ED */ -/* F23 72 */ 0x6E, /* EE */ -/* F24 73 */ 0x76, /* F6 */ -/* Keyboard Execute 74 */ -1, /* Unassigned */ -/* Keyboard Help 75 */ -1, /* Unassigned */ -/* Keyboard Menu 76 */ -1, /* Unassigned */ -/* Keyboard Select 77 */ -1, /* Unassigned */ -/* Keyboard Stop 78 */ -1, /* Unassigned */ -/* Keyboard Again 79 */ -1, /* Unassigned */ -/* Keyboard Undo 7A */ -1, /* Unassigned */ -/* Keyboard Cut 7B */ -1, /* Unassigned */ -/* Keyboard Copy 7C */ -1, /* Unassigned */ -/* Keyboard Paste 7D */ -1, /* Unassigned */ -/* Keyboard Find 7E */ -1, /* Unassigned */ -/* Keyboard Mute 7F */ -1, /* Unassigned */ -/* Keyboard Volume Up 80 */ -1, /* Unassigned */ -/* Keyboard Volume Dn 81 */ -1, /* Unassigned */ -/* Keyboard Locking Caps Lock 82 */ -1, /* Unassigned */ -/* Keyboard Locking Num Lock 83 */ -1, /* Unassigned */ -/* Keyboard Locking Scroll Lock 84 */ -1, /* Unassigned */ -/* Keypad comma 85 */ 0x7E, /* FE */ -/* Keyboard Equal Sign 86 */ -1, /* Unassigned */ -/* Keyboard Int'l 1 87 */ 0x73, /* F3 */ -/* Keyboard Int'l 2 88 */ 0x70, /* F0 */ -/* Keyboard Int'l 2 89 */ 0x7D, /* FD */ -/* Keyboard Int'l 4 8A */ 0x79, /* F9 */ -/* Keyboard Int'l 5 8B */ 0x7B, /* FB */ -/* Keyboard Int'l 6 8C */ 0x5C, /* DC */ -/* Keyboard Int'l 7 8D */ -1, /* Unassigned */ -/* Keyboard Int'l 8 8E */ -1, /* Unassigned */ -/* Keyboard Int'l 9 8F */ -1, /* Unassigned */ -/* Keyboard Lang 1 90 */ NOBREAK|0xF2, /* None */ -/* Keyboard Lang 2 91 */ NOBREAK|0xF1, /* None */ -/* Keyboard Lang 3 92 */ 0x78, /* F8 */ -/* Keyboard Lang 4 93 */ 0x77, /* F7 */ -/* Keyboard Lang 5 94 */ 0x76, /* F6 */ -/* Keyboard Lang 6 95 */ -1, /* Unassigned */ -/* Keyboard Lang 7 96 */ -1, /* Unassigned */ -/* Keyboard Lang 8 97 */ -1, /* Unassigned */ -/* Keyboard Lang 9 98 */ -1, /* Unassigned */ -/* Keyboard Alternate Erase 99 */ -1, /* Unassigned */ -/* Keyboard SysReq/Attention 9A */ -1, /* Unassigned */ -/* Keyboard Cancel 9B */ -1, /* Unassigned */ -/* Keyboard Clear 9C */ -1, /* Unassigned */ -/* Keyboard Prior 9D */ -1, /* Unassigned */ -/* Keyboard Return 9E */ -1, /* Unassigned */ -/* Keyboard Separator 9F */ -1, /* Unassigned */ -/* Keyboard Out A0 */ -1, /* Unassigned */ -/* Keyboard Oper A1 */ -1, /* Unassigned */ -/* Keyboard Clear/Again A2 */ -1, /* Unassigned */ -/* Keyboard CrSel/Props A3 */ -1, /* Unassigned */ -/* Keyboard ExSel A4 */ -1, /* Unassigned */ -/* Reserved A5 */ -1, /* Reserved */ -/* Reserved A6 */ -1, /* Reserved */ -/* Reserved A7 */ -1, /* Reserved */ -/* Reserved A8 */ -1, /* Reserved */ -/* Reserved A9 */ -1, /* Reserved */ -/* Reserved AA */ -1, /* Reserved */ -/* Reserved AB */ -1, /* Reserved */ -/* Reserved AC */ -1, /* Reserved */ -/* Reserved AD */ -1, /* Reserved */ -/* Reserved AE */ -1, /* Reserved */ -/* Reserved AF */ -1, /* Reserved */ -/* Reserved B0 */ -1, /* Reserved */ -/* Reserved B1 */ -1, /* Reserved */ -/* Reserved B2 */ -1, /* Reserved */ -/* Reserved B3 */ -1, /* Reserved */ -/* Reserved B4 */ -1, /* Reserved */ -/* Reserved B5 */ -1, /* Reserved */ -/* Reserved B6 */ -1, /* Reserved */ -/* Reserved B7 */ -1, /* Reserved */ -/* Reserved B8 */ -1, /* Reserved */ -/* Reserved B9 */ -1, /* Reserved */ -/* Reserved BA */ -1, /* Reserved */ -/* Reserved BB */ -1, /* Reserved */ -/* Reserved BC */ -1, /* Reserved */ -/* Reserved BD */ -1, /* Reserved */ -/* Reserved BE */ -1, /* Reserved */ -/* Reserved BF */ -1, /* Reserved */ -/* Reserved C0 */ -1, /* Reserved */ -/* Reserved C1 */ -1, /* Reserved */ -/* Reserved C2 */ -1, /* Reserved */ -/* Reserved C3 */ -1, /* Reserved */ -/* Reserved C4 */ -1, /* Reserved */ -/* Reserved C5 */ -1, /* Reserved */ -/* Reserved C6 */ -1, /* Reserved */ -/* Reserved C7 */ -1, /* Reserved */ -/* Reserved C8 */ -1, /* Reserved */ -/* Reserved C9 */ -1, /* Reserved */ -/* Reserved CA */ -1, /* Reserved */ -/* Reserved CB */ -1, /* Reserved */ -/* Reserved CC */ -1, /* Reserved */ -/* Reserved CD */ -1, /* Reserved */ -/* Reserved CE */ -1, /* Reserved */ -/* Reserved CF */ -1, /* Reserved */ -/* Reserved D0 */ -1, /* Reserved */ -/* Reserved D1 */ -1, /* Reserved */ -/* Reserved D2 */ -1, /* Reserved */ -/* Reserved D3 */ -1, /* Reserved */ -/* Reserved D4 */ -1, /* Reserved */ -/* Reserved D5 */ -1, /* Reserved */ -/* Reserved D6 */ -1, /* Reserved */ -/* Reserved D7 */ -1, /* Reserved */ -/* Reserved D8 */ -1, /* Reserved */ -/* Reserved D9 */ -1, /* Reserved */ -/* Reserved DA */ -1, /* Reserved */ -/* Reserved DB */ -1, /* Reserved */ -/* Reserved DC */ -1, /* Reserved */ -/* Reserved DD */ -1, /* Reserved */ -/* Reserved DE */ -1, /* Reserved */ -/* Reserved DF */ -1, /* Reserved */ -/* Left Control E0 */ 0x1D, /* 9D */ -/* Left Shift E1 */ 0x2A, /* AA */ -/* Left Alt E2 */ 0x38, /* B8 */ -/* Left GUI E3 */ E0PREFIX|0x5B, /* E0 DB */ -/* Right Control E4 */ E0PREFIX|0x1D, /* E0 9D */ -/* Right Shift E5 */ 0x36, /* B6 */ -/* Right Alt E6 */ E0PREFIX|0x38, /* E0 B8 */ -/* Right GUI E7 */ E0PREFIX|0x5C /* E0 DC */ -}; - -#define xsize ((int32_t)(sizeof(x)/sizeof(x[0]))) - -/* - * Get a max HID keycode (aligned) - */ - -int32_t -kbd_maxkey(void) -{ - return (xsize); -} - -/* - * Process keys - */ - -int32_t -kbd_process_keys(bthid_session_p s) -{ - bitstr_t diff[bitstr_size(xsize)]; - int32_t f1, f2, i; - - assert(s != NULL); - assert(s->srv != NULL); - - /* Check if the new keys have been pressed */ - bit_ffs(s->keys1, xsize, &f1); - - /* Check if old keys still pressed */ - bit_ffs(s->keys2, xsize, &f2); - - if (f1 == -1) { - /* no new key pressed */ - if (f2 != -1) { - /* release old keys */ - kbd_write(s->keys2, f2, 0, s->vkbd); - memset(s->keys2, 0, bitstr_size(xsize)); - } - - return (0); - } - - if (f2 == -1) { - /* no old keys, but new keys pressed */ - assert(f1 != -1); - - memcpy(s->keys2, s->keys1, bitstr_size(xsize)); - kbd_write(s->keys1, f1, 1, s->vkbd); - memset(s->keys1, 0, bitstr_size(xsize)); - - return (0); - } - - /* new keys got pressed, old keys got released */ - memset(diff, 0, bitstr_size(xsize)); - - for (i = f2; i < xsize; i ++) { - if (bit_test(s->keys2, i)) { - if (!bit_test(s->keys1, i)) { - bit_clear(s->keys2, i); - bit_set(diff, i); - } - } - } - - for (i = f1; i < xsize; i++) { - if (bit_test(s->keys1, i)) { - if (!bit_test(s->keys2, i)) - bit_set(s->keys2, i); - else - bit_clear(s->keys1, i); - } - } - - bit_ffs(diff, xsize, &f2); - if (f2 > 0) - kbd_write(diff, f2, 0, s->vkbd); - - bit_ffs(s->keys1, xsize, &f1); - if (f1 > 0) { - kbd_write(s->keys1, f1, 1, s->vkbd); - memset(s->keys1, 0, bitstr_size(xsize)); - } - - return (0); -} - -/* - * Translate given keymap and write keyscodes - */ - -static void -kbd_write(bitstr_t *m, int32_t fb, int32_t make, int32_t fd) -{ - int32_t i, *b, *eob, n, buf[64]; - - b = buf; - eob = b + sizeof(buf)/sizeof(buf[0]); - i = fb; - - while (i < xsize) { - if (bit_test(m, i)) { - n = kbd_xlate(i, make, b, eob); - if (n == -1) { - write(fd, buf, (b - buf) * sizeof(buf[0])); - b = buf; - continue; - } - - b += n; - } - - i ++; - } - - if (b != buf) - write(fd, buf, (b - buf) * sizeof(buf[0])); -} - -/* - * Translate HID code into PS/2 code and put codes into buffer b. - * Returns the number of codes put in b. Return -1 if buffer has not - * enough space. - */ - -#undef PUT -#define PUT(c, n, b, eob) \ -do { \ - if ((b) >= (eob)) \ - return (-1); \ - *(b) = (c); \ - (b) ++; \ - (n) ++; \ -} while (0) - -static int32_t -kbd_xlate(int32_t code, int32_t make, int32_t *b, int32_t const *eob) -{ - int32_t c, n; - - n = 0; - - if (code >= xsize) - return (0); /* HID code is not in the table */ - - /* Handle special case - Pause/Break */ - if (code == 0x48) { - if (!make) - return (0); /* No break code */ - -#if 0 -XXX FIXME - if (ctrl_is_pressed) { - /* Break (Ctrl-Pause) */ - PUT(0xe0, n, b, eob); - PUT(0x46, n, b, eob); - PUT(0xe0, n, b, eob); - PUT(0xc6, n, b, eob); - } else { - /* Pause */ - PUT(0xe1, n, b, eob); - PUT(0x1d, n, b, eob); - PUT(0x45, n, b, eob); - PUT(0xe1, n, b, eob); - PUT(0x9d, n, b, eob); - PUT(0xc5, n, b, eob); - } -#endif - - return (n); - } - - if ((c = x[code]) == -1) - return (0); /* HID code translation is not defined */ - - if (make) { - if (c & E0PREFIX) - PUT(0xe0, n, b, eob); - - PUT((c & CODEMASK), n, b, eob); - } else if (!(c & NOBREAK)) { - if (c & E0PREFIX) - PUT(0xe0, n, b, eob); - - PUT((0x80|(c & CODEMASK)), n, b, eob); - } - - return (n); -} - -/* - * Process status change from vkbd(4) - */ - -int32_t -kbd_status_changed(bthid_session_p s, uint8_t *data, int32_t len) -{ - vkbd_status_t st; - uint8_t leds, report_id; - hid_device_p hid_device; - hid_data_t d; - hid_item_t h; - - assert(s != NULL); - assert(len == sizeof(vkbd_status_t)); - - memcpy(&st, data, sizeof(st)); - leds = 0; - report_id = NO_REPORT_ID; - - hid_device = get_hid_device(&s->bdaddr); - assert(hid_device != NULL); - - for (d = hid_start_parse(hid_device->desc, 1 << hid_output, -1); - hid_get_item(d, &h) > 0; ) { - if (HID_PAGE(h.usage) == HUP_LEDS) { - if (report_id == NO_REPORT_ID) - report_id = h.report_ID; - else if (h.report_ID != report_id) - syslog(LOG_WARNING, "Output HID report IDs " \ - "for %s do not match: %d vs. %d. " \ - "Please report", - bt_ntoa(&s->bdaddr, NULL), - h.report_ID, report_id); - - switch(HID_USAGE(h.usage)) { - case 0x01: /* Num Lock LED */ - if (st.leds & LED_NUM) - hid_set_data(&leds, &h, 1); - break; - - case 0x02: /* Caps Lock LED */ - if (st.leds & LED_CAP) - hid_set_data(&leds, &h, 1); - break; - - case 0x03: /* Scroll Lock LED */ - if (st.leds & LED_SCR) - hid_set_data(&leds, &h, 1); - break; - - /* XXX add other LEDs ? */ - } - } - } - hid_end_parse(d); - - data[0] = 0xa2; /* DATA output (HID output report) */ - - if (report_id != NO_REPORT_ID) { - data[1] = report_id; - data[2] = leds; - len = 3; - } else { - data[1] = leds; - len = 2; - } - - write(s->intr, data, len); - - return (0); -} - diff --git a/usr.sbin/bluetooth/bthidd/kbd.h b/usr.sbin/bluetooth/bthidd/kbd.h deleted file mode 100644 index 552f310..0000000 --- a/usr.sbin/bluetooth/bthidd/kbd.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * kbd.h - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: kbd.h,v 1.3 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#ifndef _KBD_H_ -#define _KBD_H_ - -int32_t kbd_maxkey (void); -int32_t kbd_process_keys (bthid_session_p s); -int32_t kbd_status_changed(bthid_session_p s, uint8_t *data, int32_t len); - -#endif /* ndef _KBD_H_ */ diff --git a/usr.sbin/bluetooth/bthidd/lexer.l b/usr.sbin/bluetooth/bthidd/lexer.l deleted file mode 100644 index a25ae92..0000000 --- a/usr.sbin/bluetooth/bthidd/lexer.l +++ /dev/null @@ -1,104 +0,0 @@ -%{ -/* - * lexer.l - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: lexer.l,v 1.3 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include "parser.h" - - int yylex (void); -%} - -%option yylineno noyywrap nounput - -delim [ \t\n] -ws {delim}+ -empty {delim}* -comment \#.* - -hexdigit [0-9a-fA-F] -hexbyte {hexdigit}{hexdigit}? - -device_word device -bdaddr_word bdaddr -control_psm_word control_psm -interrupt_psm_word interrupt_psm -reconnect_initiate_word reconnect_initiate -battery_power_word battery_power -normally_connectable_word normally_connectable -hid_descriptor_word hid_descriptor -true_word true -false_word false - -bdaddrstring {hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte} -hexbytestring 0x{hexbyte} - -%% - -\; return (';'); -\: return (':'); -\{ return ('{'); -\} return ('}'); - -{ws} ; -{empty} ; -{comment} ; - -{device_word} return (T_DEVICE); -{bdaddr_word} return (T_BDADDR); -{control_psm_word} return (T_CONTROL_PSM); -{interrupt_psm_word} return (T_INTERRUPT_PSM); -{reconnect_initiate_word} return (T_RECONNECT_INITIATE); -{battery_power_word} return (T_BATTERY_POWER); -{normally_connectable_word} return (T_NORMALLY_CONNECTABLE); -{hid_descriptor_word} return (T_HID_DESCRIPTOR); -{true_word} return (T_TRUE); -{false_word} return (T_FALSE); - -{bdaddrstring} { - return (bt_aton(yytext, &yylval.bdaddr)? - T_BDADDRSTRING : T_ERROR); - } - -{hexbytestring} { - char *ep; - - yylval.num = strtoul(yytext, &ep, 16); - - return (*ep == '\0'? T_HEXBYTE : T_ERROR); - } - -. return (T_ERROR); - -%% - diff --git a/usr.sbin/bluetooth/bthidd/parser.y b/usr.sbin/bluetooth/bthidd/parser.y deleted file mode 100644 index ca49059..0000000 --- a/usr.sbin/bluetooth/bthidd/parser.y +++ /dev/null @@ -1,475 +0,0 @@ -%{ -/* - * parser.y - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: parser.y,v 1.7 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef BTHIDCONTROL -#include -#include -#define SYSLOG syslog -#define LOGCRIT LOG_CRIT -#define LOGERR LOG_ERR -#define LOGWARNING LOG_WARNING -#define EOL -#else -#define SYSLOG fprintf -#define LOGCRIT stderr -#define LOGERR stderr -#define LOGWARNING stderr -#define EOL "\n" -#endif /* ndef BTHIDCONTROL */ - -#include "bthid_config.h" - - int yyparse (void); - int yylex (void); - void yyerror (char const *); -static int32_t check_hid_device(hid_device_p hid_device); -static void free_hid_device (hid_device_p hid_device); - -extern FILE *yyin; -extern int yylineno; - char const *config_file = BTHIDD_CONFFILE; - char const *hids_file = BTHIDD_HIDSFILE; - -static char buffer[1024]; -static int32_t hid_descriptor_size; -static hid_device_t *hid_device = NULL; -static LIST_HEAD(, hid_device) hid_devices; - -%} - -%union { - bdaddr_t bdaddr; - int32_t num; -} - -%token T_BDADDRSTRING -%token T_HEXBYTE -%token T_DEVICE T_BDADDR T_CONTROL_PSM T_INTERRUPT_PSM T_RECONNECT_INITIATE -%token T_BATTERY_POWER T_NORMALLY_CONNECTABLE T_HID_DESCRIPTOR -%token T_TRUE T_FALSE T_ERROR - -%% - -config: line - | config line - ; - -line: T_DEVICE - { - hid_device = (hid_device_t *) calloc(1, sizeof(*hid_device)); - if (hid_device == NULL) { - SYSLOG(LOGCRIT, "Could not allocate new " \ - "config entry" EOL); - YYABORT; - } - - hid_device->new_device = 1; - } - '{' options '}' - { - if (check_hid_device(hid_device)) - LIST_INSERT_HEAD(&hid_devices,hid_device,next); - else - free_hid_device(hid_device); - - hid_device = NULL; - } - ; - -options: option ';' - | options option ';' - ; - -option: bdaddr - | control_psm - | interrupt_psm - | reconnect_initiate - | battery_power - | normally_connectable - | hid_descriptor - | parser_error - ; - -bdaddr: T_BDADDR T_BDADDRSTRING - { - memcpy(&hid_device->bdaddr, &$2, sizeof(hid_device->bdaddr)); - } - ; - -control_psm: T_CONTROL_PSM T_HEXBYTE - { - hid_device->control_psm = $2; - } - ; - -interrupt_psm: T_INTERRUPT_PSM T_HEXBYTE - { - hid_device->interrupt_psm = $2; - } - ; - -reconnect_initiate: T_RECONNECT_INITIATE T_TRUE - { - hid_device->reconnect_initiate = 1; - } - | T_RECONNECT_INITIATE T_FALSE - { - hid_device->reconnect_initiate = 0; - } - ; - -battery_power: T_BATTERY_POWER T_TRUE - { - hid_device->battery_power = 1; - } - | T_BATTERY_POWER T_FALSE - { - hid_device->battery_power = 0; - } - ; - -normally_connectable: T_NORMALLY_CONNECTABLE T_TRUE - { - hid_device->normally_connectable = 1; - } - | T_NORMALLY_CONNECTABLE T_FALSE - { - hid_device->normally_connectable = 0; - } - ; - -hid_descriptor: T_HID_DESCRIPTOR - { - hid_descriptor_size = 0; - } - '{' hid_descriptor_bytes '}' - { - if (hid_device->desc != NULL) - hid_dispose_report_desc(hid_device->desc); - - hid_device->desc = hid_use_report_desc((unsigned char *) buffer, hid_descriptor_size); - if (hid_device->desc == NULL) { - SYSLOG(LOGCRIT, "Could not use HID descriptor" EOL); - YYABORT; - } - } - ; - -hid_descriptor_bytes: hid_descriptor_byte - | hid_descriptor_bytes hid_descriptor_byte - ; - -hid_descriptor_byte: T_HEXBYTE - { - if (hid_descriptor_size >= (int32_t) sizeof(buffer)) { - SYSLOG(LOGCRIT, "HID descriptor is too big" EOL); - YYABORT; - } - - buffer[hid_descriptor_size ++] = $1; - } - ; - -parser_error: T_ERROR - { - YYABORT; - } - -%% - -/* Display parser error message */ -void -yyerror(char const *message) -{ - SYSLOG(LOGERR, "%s in line %d" EOL, message, yylineno); -} - -/* Re-read config file */ -int32_t -read_config_file(void) -{ - int32_t e; - - if (config_file == NULL) { - SYSLOG(LOGERR, "Unknown config file name!" EOL); - return (-1); - } - - if ((yyin = fopen(config_file, "r")) == NULL) { - SYSLOG(LOGERR, "Could not open config file '%s'. %s (%d)" EOL, - config_file, strerror(errno), errno); - return (-1); - } - - clean_config(); - if (yyparse() < 0) { - SYSLOG(LOGERR, "Could not parse config file '%s'" EOL, - config_file); - e = -1; - } else - e = 0; - - fclose(yyin); - yyin = NULL; - - return (e); -} - -/* Clean config */ -void -clean_config(void) -{ - while (!LIST_EMPTY(&hid_devices)) { - hid_device_p d = LIST_FIRST(&hid_devices); - - LIST_REMOVE(d, next); - free_hid_device(d); - } -} - -/* Lookup config entry */ -hid_device_p -get_hid_device(bdaddr_p bdaddr) -{ - hid_device_p d; - - LIST_FOREACH(d, &hid_devices, next) - if (memcmp(&d->bdaddr, bdaddr, sizeof(bdaddr_t)) == 0) - break; - - return (d); -} - -/* Get next config entry */ -hid_device_p -get_next_hid_device(hid_device_p d) -{ - return ((d == NULL)? LIST_FIRST(&hid_devices) : LIST_NEXT(d, next)); -} - -/* Print config entry */ -void -print_hid_device(hid_device_p d, FILE *f) -{ - /* XXX FIXME hack! */ - struct report_desc { - unsigned int size; - unsigned char data[1]; - }; - /* XXX FIXME hack! */ - - struct report_desc *desc = (struct report_desc *) d->desc; - uint32_t i; - - fprintf(f, -"device {\n" \ -" bdaddr %s;\n" \ -" control_psm 0x%x;\n" \ -" interrupt_psm 0x%x;\n" \ -" reconnect_initiate %s;\n" \ -" battery_power %s;\n" \ -" normally_connectable %s;\n" \ -" hid_descriptor {", - bt_ntoa(&d->bdaddr, NULL), - d->control_psm, d->interrupt_psm, - d->reconnect_initiate? "true" : "false", - d->battery_power? "true" : "false", - d->normally_connectable? "true" : "false"); - - for (i = 0; i < desc->size; i ++) { - if ((i % 8) == 0) - fprintf(f, "\n "); - - fprintf(f, "0x%2.2x ", desc->data[i]); - } - - fprintf(f, -"\n" \ -" };\n" \ -"}\n"); -} - -/* Check config entry */ -static int32_t -check_hid_device(hid_device_p d) -{ - hid_data_t hd; - hid_item_t hi; - int32_t page; - - if (get_hid_device(&d->bdaddr) != NULL) { - SYSLOG(LOGERR, "Ignoring duplicated entry for bdaddr %s" EOL, - bt_ntoa(&d->bdaddr, NULL)); - return (0); - } - - if (d->control_psm == 0) { - SYSLOG(LOGERR, "Ignoring entry with invalid control PSM" EOL); - return (0); - } - - if (d->interrupt_psm == 0) { - SYSLOG(LOGERR, "Ignoring entry with invalid interrupt PSM" EOL); - return (0); - } - - if (d->desc == NULL) { - SYSLOG(LOGERR, "Ignoring entry without HID descriptor" EOL); - return (0); - } - - /* XXX somehow need to make sure descriptor is valid */ - for (hd = hid_start_parse(d->desc, ~0, -1); hid_get_item(hd, &hi) > 0; ) { - switch (hi.kind) { - case hid_collection: - case hid_endcollection: - case hid_output: - case hid_feature: - break; - - case hid_input: - /* Check if the device may send keystrokes */ - page = HID_PAGE(hi.usage); - if (page == HUP_KEYBOARD) - d->keyboard = 1; - break; - } - } - hid_end_parse(hd); - - return (1); -} - -/* Free config entry */ -static void -free_hid_device(hid_device_p d) -{ - if (d->desc != NULL) - hid_dispose_report_desc(d->desc); - - memset(d, 0, sizeof(*d)); - free(d); -} - -/* Re-read hids file */ -int32_t -read_hids_file(void) -{ - FILE *f; - hid_device_t *d; - char *line; - bdaddr_t bdaddr; - int32_t lineno; - - if (hids_file == NULL) { - SYSLOG(LOGERR, "Unknown HIDs file name!" EOL); - return (-1); - } - - if ((f = fopen(hids_file, "r")) == NULL) { - if (errno == ENOENT) - return (0); - - SYSLOG(LOGERR, "Could not open HIDs file '%s'. %s (%d)" EOL, - hids_file, strerror(errno), errno); - return (-1); - } - - for (lineno = 1; fgets(buffer, sizeof(buffer), f) != NULL; lineno ++) { - if ((line = strtok(buffer, "\r\n\t ")) == NULL) - continue; /* ignore empty lines */ - - if (!bt_aton(line, &bdaddr)) { - SYSLOG(LOGWARNING, "Ignoring unparseable BD_ADDR in " \ - "%s:%d" EOL, hids_file, lineno); - continue; - } - - if ((d = get_hid_device(&bdaddr)) != NULL) - d->new_device = 0; - } - - fclose(f); - - return (0); -} - -/* Write hids file */ -int32_t -write_hids_file(void) -{ - char path[PATH_MAX]; - FILE *f; - hid_device_t *d; - - if (hids_file == NULL) { - SYSLOG(LOGERR, "Unknown HIDs file name!" EOL); - return (-1); - } - - snprintf(path, sizeof(path), "%s.new", hids_file); - - if ((f = fopen(path, "w")) == NULL) { - SYSLOG(LOGERR, "Could not open HIDs file '%s'. %s (%d)" EOL, - path, strerror(errno), errno); - return (-1); - } - - LIST_FOREACH(d, &hid_devices, next) - if (!d->new_device) - fprintf(f, "%s\n", bt_ntoa(&d->bdaddr, NULL)); - - fclose(f); - - if (rename(path, hids_file) < 0) { - SYSLOG(LOGERR, "Could not rename new HIDs file '%s' to '%s'. " \ - "%s (%d)" EOL, path, hids_file, strerror(errno), errno); - unlink(path); - return (-1); - } - - return (0); -} - diff --git a/usr.sbin/bluetooth/bthidd/server.c b/usr.sbin/bluetooth/bthidd/server.c deleted file mode 100644 index d76bd62..0000000 --- a/usr.sbin/bluetooth/bthidd/server.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * server.c - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: server.c,v 1.9 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidd.h" -#include "kbd.h" - -#undef max -#define max(x, y) (((x) > (y))? (x) : (y)) - -static int32_t server_accept (bthid_server_p srv, int32_t fd); -static int32_t server_process(bthid_server_p srv, int32_t fd); - -/* - * Initialize server - */ - -int32_t -server_init(bthid_server_p srv) -{ - struct sockaddr_l2cap l2addr; - - assert(srv != NULL); - - srv->ctrl = srv->intr = -1; - FD_ZERO(&srv->rfdset); - FD_ZERO(&srv->wfdset); - LIST_INIT(&srv->sessions); - - /* Open /dev/consolectl */ - srv->cons = open("/dev/consolectl", O_RDWR); - if (srv->cons < 0) { - syslog(LOG_ERR, "Could not open /dev/consolectl. %s (%d)", - strerror(errno), errno); - return (-1); - } - - /* Create control socket */ - srv->ctrl = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP); - if (srv->ctrl < 0) { - syslog(LOG_ERR, "Could not create control L2CAP socket. " \ - "%s (%d)", strerror(errno), errno); - close(srv->cons); - return (-1); - } - - l2addr.l2cap_len = sizeof(l2addr); - l2addr.l2cap_family = AF_BLUETOOTH; - memcpy(&l2addr.l2cap_bdaddr, &srv->bdaddr, sizeof(l2addr.l2cap_bdaddr)); - l2addr.l2cap_psm = htole16(0x11); - - if (bind(srv->ctrl, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0) { - syslog(LOG_ERR, "Could not bind control L2CAP socket. " \ - "%s (%d)", strerror(errno), errno); - close(srv->ctrl); - close(srv->cons); - return (-1); - } - - if (listen(srv->ctrl, 10) < 0) { - syslog(LOG_ERR, "Could not listen on control L2CAP socket. " \ - "%s (%d)", strerror(errno), errno); - close(srv->ctrl); - close(srv->cons); - return (-1); - } - - /* Create intrrupt socket */ - srv->intr = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP); - if (srv->intr < 0) { - syslog(LOG_ERR, "Could not create interrupt L2CAP socket. " \ - "%s (%d)", strerror(errno), errno); - close(srv->ctrl); - close(srv->cons); - return (-1); - } - - l2addr.l2cap_psm = htole16(0x13); - - if (bind(srv->intr, (struct sockaddr *) &l2addr, sizeof(l2addr)) < 0) { - syslog(LOG_ERR, "Could not bind interrupt L2CAP socket. " \ - "%s (%d)", strerror(errno), errno); - close(srv->intr); - close(srv->ctrl); - close(srv->cons); - return (-1); - } - - if (listen(srv->intr, 10) < 0) { - syslog(LOG_ERR, "Could not listen on interrupt L2CAP socket. "\ - "%s (%d)", strerror(errno), errno); - close(srv->intr); - close(srv->ctrl); - close(srv->cons); - return (-1); - } - - FD_SET(srv->ctrl, &srv->rfdset); - FD_SET(srv->intr, &srv->rfdset); - srv->maxfd = max(srv->ctrl, srv->intr); - - return (0); -} - -/* - * Shutdown server - */ - -void -server_shutdown(bthid_server_p srv) -{ - assert(srv != NULL); - - close(srv->cons); - close(srv->ctrl); - close(srv->intr); - - while (!LIST_EMPTY(&srv->sessions)) - session_close(LIST_FIRST(&srv->sessions)); - - memset(srv, 0, sizeof(*srv)); -} - -/* - * Do one server iteration - */ - -int32_t -server_do(bthid_server_p srv) -{ - struct timeval tv; - fd_set rfdset, wfdset; - int32_t n, fd; - - assert(srv != NULL); - - tv.tv_sec = 1; - tv.tv_usec = 0; - - /* Copy cached version of the fd sets and call select */ - memcpy(&rfdset, &srv->rfdset, sizeof(rfdset)); - memcpy(&wfdset, &srv->wfdset, sizeof(wfdset)); - - n = select(srv->maxfd + 1, &rfdset, &wfdset, NULL, &tv); - if (n < 0) { - if (errno == EINTR) - return (0); - - syslog(LOG_ERR, "Could not select(%d, %p, %p). %s (%d)", - srv->maxfd + 1, &rfdset, &wfdset, strerror(errno), errno); - - return (-1); - } - - /* Process descriptors (if any) */ - for (fd = 0; fd < srv->maxfd + 1 && n > 0; fd ++) { - if (FD_ISSET(fd, &rfdset)) { - n --; - - if (fd == srv->ctrl || fd == srv->intr) - server_accept(srv, fd); - else - server_process(srv, fd); - } else if (FD_ISSET(fd, &wfdset)) { - n --; - - client_connect(srv, fd); - } - } - - return (0); -} - -/* - * Accept new connection - */ - -static int32_t -server_accept(bthid_server_p srv, int32_t fd) -{ - bthid_session_p s; - hid_device_p d; - struct sockaddr_l2cap l2addr; - int32_t new_fd; - socklen_t len; - - len = sizeof(l2addr); - if ((new_fd = accept(fd, (struct sockaddr *) &l2addr, &len)) < 0) { - syslog(LOG_ERR, "Could not accept %s connection. %s (%d)", - (fd == srv->ctrl)? "control" : "interrupt", - strerror(errno), errno); - return (-1); - } - - /* Is device configured? */ - if ((d = get_hid_device(&l2addr.l2cap_bdaddr)) == NULL) { - syslog(LOG_ERR, "Rejecting %s connection from %s. " \ - "Device not configured", - (fd == srv->ctrl)? "control" : "interrupt", - bt_ntoa(&l2addr.l2cap_bdaddr, NULL)); - close(new_fd); - return (-1); - } - - /* Check if we have session for the device */ - if ((s = session_by_bdaddr(srv, &l2addr.l2cap_bdaddr)) == NULL) { - d->new_device = 0; /* reset new device flag */ - write_hids_file(); - - /* Create new inbound session */ - if ((s = session_open(srv, d)) == NULL) { - syslog(LOG_CRIT, "Could not open inbound session " - "for %s", bt_ntoa(&l2addr.l2cap_bdaddr, NULL)); - close(new_fd); - return (-1); - } - } - - /* Update descriptors */ - if (fd == srv->ctrl) { - assert(s->ctrl == -1); - s->ctrl = new_fd; - s->state = (s->intr == -1)? W4INTR : OPEN; - } else { - assert(s->intr == -1); - s->intr = new_fd; - s->state = (s->ctrl == -1)? W4CTRL : OPEN; - } - - FD_SET(new_fd, &srv->rfdset); - if (new_fd > srv->maxfd) - srv->maxfd = new_fd; - - syslog(LOG_NOTICE, "Accepted %s connection from %s", - (fd == srv->ctrl)? "control" : "interrupt", - bt_ntoa(&l2addr.l2cap_bdaddr, NULL)); - - /* Register session's vkbd descriptor (if needed) for read */ - if (s->state == OPEN && d->keyboard) { - assert(s->vkbd != -1); - - FD_SET(s->vkbd, &srv->rfdset); - if (s->vkbd > srv->maxfd) - srv->maxfd = s->vkbd; - } - - return (0); -} - -/* - * Process data on the connection - */ - -static int32_t -server_process(bthid_server_p srv, int32_t fd) -{ - bthid_session_p s = session_by_fd(srv, fd); - int32_t len, to_read; - int32_t (*cb)(bthid_session_p, uint8_t *, int32_t); - union { - uint8_t b[1024]; - vkbd_status_t s; - } data; - - if (s == NULL) - return (0); /* can happen on device disconnect */ - - - if (fd == s->ctrl) { - cb = hid_control; - to_read = sizeof(data.b); - } else if (fd == s->intr) { - cb = hid_interrupt; - to_read = sizeof(data.b); - } else { - assert(fd == s->vkbd); - - cb = kbd_status_changed; - to_read = sizeof(data.s); - } - - do { - len = read(fd, &data, to_read); - } while (len < 0 && errno == EINTR); - - if (len < 0) { - syslog(LOG_ERR, "Could not read data from %s (%s). %s (%d)", - bt_ntoa(&s->bdaddr, NULL), - (fd == s->ctrl)? "control" : "interrupt", - strerror(errno), errno); - session_close(s); - return (0); - } - - if (len == 0) { - syslog(LOG_NOTICE, "Remote device %s has closed %s connection", - bt_ntoa(&s->bdaddr, NULL), - (fd == s->ctrl)? "control" : "interrupt"); - session_close(s); - return (0); - } - - (*cb)(s, (uint8_t *) &data, len); - - return (0); -} - diff --git a/usr.sbin/bluetooth/bthidd/session.c b/usr.sbin/bluetooth/bthidd/session.c deleted file mode 100644 index b9f331b..0000000 --- a/usr.sbin/bluetooth/bthidd/session.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * session.c - */ - -/*- - * Copyright (c) 2006 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: session.c,v 1.3 2006/09/07 21:06:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bthid_config.h" -#include "bthidd.h" -#include "kbd.h" - -/* - * Create new session - */ - -bthid_session_p -session_open(bthid_server_p srv, hid_device_p const d) -{ - bthid_session_p s; - - assert(srv != NULL); - assert(d != NULL); - - if ((s = (bthid_session_p) malloc(sizeof(*s))) == NULL) - return (NULL); - - s->srv = srv; - memcpy(&s->bdaddr, &d->bdaddr, sizeof(s->bdaddr)); - s->ctrl = -1; - s->intr = -1; - - if (d->keyboard) { - /* Open /dev/vkbdctl */ - s->vkbd = open("/dev/vkbdctl", O_RDWR); - if (s->vkbd < 0) { - syslog(LOG_ERR, "Could not open /dev/vkbdctl " \ - "for %s. %s (%d)", bt_ntoa(&s->bdaddr, NULL), - strerror(errno), errno); - free(s); - return (NULL); - } - } else - s->vkbd = -1; - - s->state = CLOSED; - - s->keys1 = bit_alloc(kbd_maxkey()); - if (s->keys1 == NULL) { - free(s); - return (NULL); - } - - s->keys2 = bit_alloc(kbd_maxkey()); - if (s->keys2 == NULL) { - free(s->keys1); - free(s); - return (NULL); - } - - LIST_INSERT_HEAD(&srv->sessions, s, next); - - return (s); -} - -/* - * Lookup session by bdaddr - */ - -bthid_session_p -session_by_bdaddr(bthid_server_p srv, bdaddr_p bdaddr) -{ - bthid_session_p s; - - assert(srv != NULL); - assert(bdaddr != NULL); - - LIST_FOREACH(s, &srv->sessions, next) - if (memcmp(&s->bdaddr, bdaddr, sizeof(s->bdaddr)) == 0) - break; - - return (s); -} - -/* - * Lookup session by fd - */ - -bthid_session_p -session_by_fd(bthid_server_p srv, int32_t fd) -{ - bthid_session_p s; - - assert(srv != NULL); - assert(fd >= 0); - - LIST_FOREACH(s, &srv->sessions, next) - if (s->ctrl == fd || s->intr == fd || s->vkbd == fd) - break; - - return (s); -} - -/* - * Close session - */ - -void -session_close(bthid_session_p s) -{ - assert(s != NULL); - assert(s->srv != NULL); - - LIST_REMOVE(s, next); - - if (s->intr != -1) { - FD_CLR(s->intr, &s->srv->rfdset); - FD_CLR(s->intr, &s->srv->wfdset); - close(s->intr); - - if (s->srv->maxfd == s->intr) - s->srv->maxfd --; - } - - if (s->ctrl != -1) { - FD_CLR(s->ctrl, &s->srv->rfdset); - FD_CLR(s->ctrl, &s->srv->wfdset); - close(s->ctrl); - - if (s->srv->maxfd == s->ctrl) - s->srv->maxfd --; - } - - if (s->vkbd != -1) { - FD_CLR(s->vkbd, &s->srv->rfdset); - close(s->vkbd); - - if (s->srv->maxfd == s->vkbd) - s->srv->maxfd --; - } - - free(s->keys1); - free(s->keys2); - - memset(s, 0, sizeof(*s)); - free(s); -} - diff --git a/usr.sbin/bluetooth/btpand/Makefile b/usr.sbin/bluetooth/btpand/Makefile deleted file mode 100644 index 5e4bb0b..0000000 --- a/usr.sbin/bluetooth/btpand/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $NetBSD: Makefile,v 1.2 2008/08/18 08:25:32 plunky Exp $ -# $FreeBSD$ - -PROG= btpand -MAN= btpand.8 -SRCS= btpand.c bnep.c channel.c client.c event.c packet.c server.c sdp.c tap.c - -WARNS?= 3 - -DPADD+= ${LIBBLUETOOTH} ${LIBSDP} ${LIBUTIL} -LDADD+= -lbluetooth -lsdp -lutil - -.include diff --git a/usr.sbin/bluetooth/btpand/bnep.c b/usr.sbin/bluetooth/btpand/bnep.c deleted file mode 100644 index 200a723..0000000 --- a/usr.sbin/bluetooth/btpand/bnep.c +++ /dev/null @@ -1,755 +0,0 @@ -/* $NetBSD: bnep.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__RCSID("$NetBSD: bnep.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); - -#include -#include -#include -#include -#include -#include - -#include "btpand.h" -#include "bnep.h" - -static bool bnep_recv_extension(packet_t *); -static size_t bnep_recv_control(channel_t *, uint8_t *, size_t, bool); -static size_t bnep_recv_control_command_not_understood(channel_t *, uint8_t *, size_t); -static size_t bnep_recv_setup_connection_req(channel_t *, uint8_t *, size_t); -static size_t bnep_recv_setup_connection_rsp(channel_t *, uint8_t *, size_t); -static size_t bnep_recv_filter_net_type_set(channel_t *, uint8_t *, size_t); -static size_t bnep_recv_filter_net_type_rsp(channel_t *, uint8_t *, size_t); -static size_t bnep_recv_filter_multi_addr_set(channel_t *, uint8_t *, size_t); -static size_t bnep_recv_filter_multi_addr_rsp(channel_t *, uint8_t *, size_t); - -static bool bnep_pfilter(channel_t *, packet_t *); -static bool bnep_mfilter(channel_t *, packet_t *); - -static uint8_t NAP_UUID[] = { - 0x00, 0x00, 0x11, 0x16, - 0x00, 0x00, - 0x10, 0x00, - 0x80, 0x00, - 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb -}; - -static uint8_t GN_UUID[] = { - 0x00, 0x00, 0x11, 0x17, - 0x00, 0x00, - 0x10, 0x00, - 0x80, 0x00, - 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb, -}; - -static uint8_t PANU_UUID[] = { - 0x00, 0x00, 0x11, 0x15, - 0x00, 0x00, - 0x10, 0x00, - 0x80, 0x00, - 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb -}; - -/* - * receive BNEP packet - * return true if packet is to be forwarded - */ -bool -bnep_recv(packet_t *pkt) -{ - size_t len; - uint8_t type; - - if (pkt->len < 1) - return false; - - type = pkt->ptr[0]; - packet_adj(pkt, 1); - - switch (BNEP_TYPE(type)) { - case BNEP_GENERAL_ETHERNET: - if (pkt->len < (ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN) { - log_debug("dropped short packet (type 0x%2.2x)", type); - return false; - } - - pkt->dst = pkt->ptr; - packet_adj(pkt, ETHER_ADDR_LEN); - pkt->src = pkt->ptr; - packet_adj(pkt, ETHER_ADDR_LEN); - pkt->type = pkt->ptr; - packet_adj(pkt, ETHER_TYPE_LEN); - break; - - case BNEP_CONTROL: - len = bnep_recv_control(pkt->chan, pkt->ptr, pkt->len, false); - if (len == 0) - return false; - - packet_adj(pkt, len); - break; - - case BNEP_COMPRESSED_ETHERNET: - if (pkt->len < ETHER_TYPE_LEN) { - log_debug("dropped short packet (type 0x%2.2x)", type); - return false; - } - - pkt->dst = pkt->chan->laddr; - pkt->src = pkt->chan->raddr; - pkt->type = pkt->ptr; - packet_adj(pkt, ETHER_TYPE_LEN); - break; - - case BNEP_COMPRESSED_ETHERNET_SRC_ONLY: - if (pkt->len < ETHER_ADDR_LEN + ETHER_TYPE_LEN) { - log_debug("dropped short packet (type 0x%2.2x)", type); - return false; - } - - pkt->dst = pkt->chan->laddr; - pkt->src = pkt->ptr; - packet_adj(pkt, ETHER_ADDR_LEN); - pkt->type = pkt->ptr; - packet_adj(pkt, ETHER_TYPE_LEN); - break; - - case BNEP_COMPRESSED_ETHERNET_DST_ONLY: - if (pkt->len < ETHER_ADDR_LEN + ETHER_TYPE_LEN) { - log_debug("dropped short packet (type 0x%2.2x)", type); - return false; - } - - pkt->dst = pkt->ptr; - packet_adj(pkt, ETHER_ADDR_LEN); - pkt->src = pkt->chan->raddr; - pkt->type = pkt->ptr; - packet_adj(pkt, ETHER_TYPE_LEN); - break; - - default: - /* - * Any packet containing a reserved BNEP - * header packet type SHALL be dropped. - */ - - log_debug("dropped packet with reserved type 0x%2.2x", type); - return false; - } - - if (BNEP_TYPE_EXT(type) - && !bnep_recv_extension(pkt)) - return false; /* invalid extensions */ - - if (BNEP_TYPE(type) == BNEP_CONTROL - || pkt->chan->state != CHANNEL_OPEN) - return false; /* no forwarding */ - - return true; -} - -static bool -bnep_recv_extension(packet_t *pkt) -{ - exthdr_t *eh; - size_t len, size; - uint8_t type; - - do { - if (pkt->len < 2) - return false; - - type = pkt->ptr[0]; - size = pkt->ptr[1]; - - if (pkt->len < size + 2) - return false; - - switch (type) { - case BNEP_EXTENSION_CONTROL: - len = bnep_recv_control(pkt->chan, pkt->ptr + 2, size, true); - if (len != size) - log_err("ignored spurious data in exthdr"); - - break; - - default: - /* Unknown extension headers in data packets */ - /* SHALL be forwarded irrespective of any */ - /* network protocol or multicast filter settings */ - /* and any local filtering policy. */ - - eh = malloc(sizeof(exthdr_t)); - if (eh == NULL) { - log_err("exthdr malloc() failed: %m"); - break; - } - - eh->ptr = pkt->ptr; - eh->len = size; - STAILQ_INSERT_TAIL(&pkt->extlist, eh, next); - break; - } - - packet_adj(pkt, size + 2); - } while (BNEP_TYPE_EXT(type)); - - return true; -} - -static size_t -bnep_recv_control(channel_t *chan, uint8_t *ptr, size_t size, bool isext) -{ - uint8_t type; - size_t len; - - if (size-- < 1) - return 0; - - type = *ptr++; - - switch (type) { - case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD: - len = bnep_recv_control_command_not_understood(chan, ptr, size); - break; - - case BNEP_SETUP_CONNECTION_REQUEST: - if (isext) - return 0; /* not allowed in extension headers */ - - len = bnep_recv_setup_connection_req(chan, ptr, size); - break; - - case BNEP_SETUP_CONNECTION_RESPONSE: - if (isext) - return 0; /* not allowed in extension headers */ - - len = bnep_recv_setup_connection_rsp(chan, ptr, size); - break; - - case BNEP_FILTER_NET_TYPE_SET: - len = bnep_recv_filter_net_type_set(chan, ptr, size); - break; - - case BNEP_FILTER_NET_TYPE_RESPONSE: - len = bnep_recv_filter_net_type_rsp(chan, ptr, size); - break; - - case BNEP_FILTER_MULTI_ADDR_SET: - len = bnep_recv_filter_multi_addr_set(chan, ptr, size); - break; - - case BNEP_FILTER_MULTI_ADDR_RESPONSE: - len = bnep_recv_filter_multi_addr_rsp(chan, ptr, size); - break; - - default: - len = 0; - break; - } - - if (len == 0) - bnep_send_control(chan, BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD, type); - - return len; -} - -static size_t -bnep_recv_control_command_not_understood(channel_t *chan, uint8_t *ptr, size_t size) -{ - uint8_t type; - - if (size < 1) - return 0; - - type = *ptr++; - log_err("received Control Command Not Understood (0x%2.2x)", type); - - /* we didn't send any reserved commands, just cut them off */ - channel_close(chan); - - return 1; -} - -static size_t -bnep_recv_setup_connection_req(channel_t *chan, uint8_t *ptr, size_t size) -{ - uint8_t off; - int src, dst, rsp; - size_t len; - - if (size < 1) - return 0; - - len = *ptr++; - if (size < (len * 2 + 1)) - return 0; - - if (chan->state != CHANNEL_WAIT_CONNECT_REQ - && chan->state != CHANNEL_OPEN) { - log_debug("ignored"); - return (len * 2 + 1); - } - - if (len == 2) - off = 2; - else if (len == 4) - off = 0; - else if (len == 16) - off = 0; - else { - rsp = BNEP_SETUP_INVALID_UUID_SIZE; - goto done; - } - - if (memcmp(ptr, NAP_UUID + off, len) == 0) - dst = SDP_SERVICE_CLASS_NAP; - else if (memcmp(ptr, GN_UUID + off, len) == 0) - dst = SDP_SERVICE_CLASS_GN; - else if (memcmp(ptr, PANU_UUID + off, len) == 0) - dst = SDP_SERVICE_CLASS_PANU; - else - dst = 0; - - if (dst != service_class) { - rsp = BNEP_SETUP_INVALID_DST_UUID; - goto done; - } - - ptr += len; - - if (memcmp(ptr, NAP_UUID + off, len) == 0) - src = SDP_SERVICE_CLASS_NAP; - else if (memcmp(ptr, GN_UUID + off, len) == 0) - src = SDP_SERVICE_CLASS_GN; - else if (memcmp(ptr, PANU_UUID + off, len) == 0) - src = SDP_SERVICE_CLASS_PANU; - else - src = 0; - - if ((dst != SDP_SERVICE_CLASS_PANU && src != SDP_SERVICE_CLASS_PANU) - || src == 0) { - rsp = BNEP_SETUP_INVALID_SRC_UUID; - goto done; - } - - rsp = BNEP_SETUP_SUCCESS; - chan->state = CHANNEL_OPEN; - channel_timeout(chan, 0); - -done: - log_debug("addr %s response 0x%2.2x", - ether_ntoa((struct ether_addr *)chan->raddr), rsp); - - bnep_send_control(chan, BNEP_SETUP_CONNECTION_RESPONSE, rsp); - return (len * 2 + 1); -} - -static size_t -bnep_recv_setup_connection_rsp(channel_t *chan, uint8_t *ptr, size_t size) -{ - int rsp; - - if (size < 2) - return 0; - - rsp = be16dec(ptr); - - if (chan->state != CHANNEL_WAIT_CONNECT_RSP) { - log_debug("ignored"); - return 2; - } - - log_debug("addr %s response 0x%2.2x", - ether_ntoa((struct ether_addr *)chan->raddr), rsp); - - if (rsp == BNEP_SETUP_SUCCESS) { - chan->state = CHANNEL_OPEN; - channel_timeout(chan, 0); - } else { - channel_close(chan); - } - - return 2; -} - -static size_t -bnep_recv_filter_net_type_set(channel_t *chan, uint8_t *ptr, size_t size) -{ - pfilter_t *pf; - int i, nf, rsp; - size_t len; - - if (size < 2) - return 0; - - len = be16dec(ptr); - ptr += 2; - - if (size < (len + 2)) - return 0; - - if (chan->state != CHANNEL_OPEN) { - log_debug("ignored"); - return (len + 2); - } - - nf = len / 4; - pf = malloc(nf * sizeof(pfilter_t)); - if (pf == NULL) { - rsp = BNEP_FILTER_TOO_MANY_FILTERS; - goto done; - } - - log_debug("nf = %d", nf); - - for (i = 0; i < nf; i++) { - pf[i].start = be16dec(ptr); - ptr += 2; - pf[i].end = be16dec(ptr); - ptr += 2; - - if (pf[i].start > pf[i].end) { - free(pf); - rsp = BNEP_FILTER_INVALID_RANGE; - goto done; - } - - log_debug("pf[%d] = %#4.4x, %#4.4x", i, pf[i].start, pf[i].end); - } - - if (chan->pfilter) - free(chan->pfilter); - - chan->pfilter = pf; - chan->npfilter = nf; - - rsp = BNEP_FILTER_SUCCESS; - -done: - log_debug("addr %s response 0x%2.2x", - ether_ntoa((struct ether_addr *)chan->raddr), rsp); - - bnep_send_control(chan, BNEP_FILTER_NET_TYPE_RESPONSE, rsp); - return (len + 2); -} - -static size_t -bnep_recv_filter_net_type_rsp(channel_t *chan, uint8_t *ptr, size_t size) -{ - int rsp; - - if (size < 2) - return 0; - - if (chan->state != CHANNEL_OPEN) { - log_debug("ignored"); - return 2; - } - - rsp = be16dec(ptr); - - log_debug("addr %s response 0x%2.2x", - ether_ntoa((struct ether_addr *)chan->raddr), rsp); - - /* we did not send any filter_net_type_set message */ - return 2; -} - -static size_t -bnep_recv_filter_multi_addr_set(channel_t *chan, uint8_t *ptr, size_t size) -{ - mfilter_t *mf; - int i, nf, rsp; - size_t len; - - if (size < 2) - return 0; - - len = be16dec(ptr); - ptr += 2; - - if (size < (len + 2)) - return 0; - - if (chan->state != CHANNEL_OPEN) { - log_debug("ignored"); - return (len + 2); - } - - nf = len / (ETHER_ADDR_LEN * 2); - mf = malloc(nf * sizeof(mfilter_t)); - if (mf == NULL) { - rsp = BNEP_FILTER_TOO_MANY_FILTERS; - goto done; - } - - log_debug("nf = %d", nf); - - for (i = 0; i < nf; i++) { - memcpy(mf[i].start, ptr, ETHER_ADDR_LEN); - ptr += ETHER_ADDR_LEN; - - memcpy(mf[i].end, ptr, ETHER_ADDR_LEN); - ptr += ETHER_ADDR_LEN; - - if (memcmp(mf[i].start, mf[i].end, ETHER_ADDR_LEN) > 0) { - free(mf); - rsp = BNEP_FILTER_INVALID_RANGE; - goto done; - } - - log_debug("pf[%d] = " - "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, " - "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x", i, - mf[i].start[0], mf[i].start[1], mf[i].start[2], - mf[i].start[3], mf[i].start[4], mf[i].start[5], - mf[i].end[0], mf[i].end[1], mf[i].end[2], - mf[i].end[3], mf[i].end[4], mf[i].end[5]); - } - - if (chan->mfilter) - free(chan->mfilter); - - chan->mfilter = mf; - chan->nmfilter = nf; - - rsp = BNEP_FILTER_SUCCESS; - -done: - log_debug("addr %s response 0x%2.2x", - ether_ntoa((struct ether_addr *)chan->raddr), rsp); - - bnep_send_control(chan, BNEP_FILTER_MULTI_ADDR_RESPONSE, rsp); - return (len + 2); -} - -static size_t -bnep_recv_filter_multi_addr_rsp(channel_t *chan, uint8_t *ptr, size_t size) -{ - int rsp; - - if (size < 2) - return false; - - if (chan->state != CHANNEL_OPEN) { - log_debug("ignored"); - return 2; - } - - rsp = be16dec(ptr); - log_debug("addr %s response 0x%2.2x", - ether_ntoa((struct ether_addr *)chan->raddr), rsp); - - /* we did not send any filter_multi_addr_set message */ - return 2; -} - -void -bnep_send_control(channel_t *chan, uint8_t type, ...) -{ - packet_t *pkt; - uint8_t *p; - va_list ap; - - assert(chan->state != CHANNEL_CLOSED); - - pkt = packet_alloc(chan); - if (pkt == NULL) - return; - - p = pkt->ptr; - va_start(ap, type); - - *p++ = BNEP_CONTROL; - *p++ = type; - - switch(type) { - case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD: - *p++ = va_arg(ap, int); - break; - - case BNEP_SETUP_CONNECTION_REQUEST: - *p++ = va_arg(ap, int); - be16enc(p, va_arg(ap, int)); - p += 2; - be16enc(p, va_arg(ap, int)); - p += 2; - break; - - case BNEP_SETUP_CONNECTION_RESPONSE: - case BNEP_FILTER_NET_TYPE_RESPONSE: - case BNEP_FILTER_MULTI_ADDR_RESPONSE: - be16enc(p, va_arg(ap, int)); - p += 2; - break; - - case BNEP_FILTER_NET_TYPE_SET: /* TODO */ - case BNEP_FILTER_MULTI_ADDR_SET: /* TODO */ - default: - log_err("Can't send control type 0x%2.2x", type); - break; - } - - va_end(ap); - pkt->len = p - pkt->ptr; - - channel_put(chan, pkt); - packet_free(pkt); -} - -/* - * BNEP send packet routine - * return true if packet can be removed from queue - */ -bool -bnep_send(channel_t *chan, packet_t *pkt) -{ - struct iovec iov[2]; - uint8_t *p, *type, *proto; - exthdr_t *eh; - bool src, dst; - size_t nw; - - if (pkt->type == NULL) { - iov[0].iov_base = pkt->ptr; - iov[0].iov_len = pkt->len; - iov[1].iov_base = NULL; - iov[1].iov_len = 0; - } else { - p = chan->sendbuf; - - dst = (memcmp(pkt->dst, chan->raddr, ETHER_ADDR_LEN) != 0); - src = (memcmp(pkt->src, chan->laddr, ETHER_ADDR_LEN) != 0); - - type = p; - p += 1; - - if (dst && src) - *type = BNEP_GENERAL_ETHERNET; - else if (dst && !src) - *type = BNEP_COMPRESSED_ETHERNET_DST_ONLY; - else if (!dst && src) - *type = BNEP_COMPRESSED_ETHERNET_SRC_ONLY; - else /* (!dst && !src) */ - *type = BNEP_COMPRESSED_ETHERNET; - - if (dst) { - memcpy(p, pkt->dst, ETHER_ADDR_LEN); - p += ETHER_ADDR_LEN; - } - - if (src) { - memcpy(p, pkt->src, ETHER_ADDR_LEN); - p += ETHER_ADDR_LEN; - } - - proto = p; - memcpy(p, pkt->type, ETHER_TYPE_LEN); - p += ETHER_TYPE_LEN; - - STAILQ_FOREACH(eh, &pkt->extlist, next) { - if (p + eh->len > chan->sendbuf + chan->mtu) - break; - - *type |= BNEP_EXT; - type = p; - - memcpy(p, eh->ptr, eh->len); - p += eh->len; - } - - *type &= ~BNEP_EXT; - - iov[0].iov_base = chan->sendbuf; - iov[0].iov_len = (p - chan->sendbuf); - - if ((chan->npfilter == 0 || bnep_pfilter(chan, pkt)) - && (chan->nmfilter == 0 || bnep_mfilter(chan, pkt))) { - iov[1].iov_base = pkt->ptr; - iov[1].iov_len = pkt->len; - } else if (be16dec(proto) == ETHERTYPE_VLAN - && pkt->len >= ETHER_VLAN_ENCAP_LEN) { - iov[1].iov_base = pkt->ptr; - iov[1].iov_len = ETHER_VLAN_ENCAP_LEN; - } else { - iov[1].iov_base = NULL; - iov[1].iov_len = 0; - memset(proto, 0, ETHER_TYPE_LEN); - } - } - - if (iov[0].iov_len + iov[1].iov_len > chan->mtu) { - log_err("packet exceeded MTU (dropped)"); - return false; - } - - nw = writev(chan->fd, iov, __arraycount(iov)); - return (nw > 0); -} - -static bool -bnep_pfilter(channel_t *chan, packet_t *pkt) -{ - int proto, i; - - proto = be16dec(pkt->type); - if (proto == ETHERTYPE_VLAN) { /* IEEE 802.1Q tag header */ - if (pkt->len < 4) - return false; - - proto = be16dec(pkt->ptr + 2); - } - - for (i = 0; i < chan->npfilter; i++) { - if (chan->pfilter[i].start <= proto - && chan->pfilter[i].end >=proto) - return true; - } - - return false; -} - -static bool -bnep_mfilter(channel_t *chan, packet_t *pkt) -{ - int i; - - if (!ETHER_IS_MULTICAST(pkt->dst)) - return true; - - for (i = 0; i < chan->nmfilter; i++) { - if (memcmp(pkt->dst, chan->mfilter[i].start, ETHER_ADDR_LEN) >= 0 - && memcmp(pkt->dst, chan->mfilter[i].end, ETHER_ADDR_LEN) <= 0) - return true; - } - - return false; -} diff --git a/usr.sbin/bluetooth/btpand/bnep.h b/usr.sbin/bluetooth/btpand/bnep.h deleted file mode 100644 index 2fc6a77..0000000 --- a/usr.sbin/bluetooth/btpand/bnep.h +++ /dev/null @@ -1,72 +0,0 @@ -/* $NetBSD: bnep.h,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -/* - * Constants defined in the Bluetooth Network Encapsulation - * Protocol (BNEP) specification v1.0 - */ - -#define BNEP_MTU_MIN 1691 - -#define BNEP_EXT 0x80 -#define BNEP_TYPE(x) ((x) & 0x7f) -#define BNEP_TYPE_EXT(x) (((x) & BNEP_EXT) == BNEP_EXT) - -/* BNEP packet types */ -#define BNEP_GENERAL_ETHERNET 0x00 -#define BNEP_CONTROL 0x01 -#define BNEP_COMPRESSED_ETHERNET 0x02 -#define BNEP_COMPRESSED_ETHERNET_SRC_ONLY 0x03 -#define BNEP_COMPRESSED_ETHERNET_DST_ONLY 0x04 - -/* BNEP extension header types */ -#define BNEP_EXTENSION_CONTROL 0x00 - -/* BNEP control types */ -#define BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD 0x00 -#define BNEP_SETUP_CONNECTION_REQUEST 0x01 -#define BNEP_SETUP_CONNECTION_RESPONSE 0x02 -#define BNEP_FILTER_NET_TYPE_SET 0x03 -#define BNEP_FILTER_NET_TYPE_RESPONSE 0x04 -#define BNEP_FILTER_MULTI_ADDR_SET 0x05 -#define BNEP_FILTER_MULTI_ADDR_RESPONSE 0x06 - -/* BNEP setup response codes */ -#define BNEP_SETUP_SUCCESS 0x0000 -#define BNEP_SETUP_INVALID_SRC_UUID 0x0001 -#define BNEP_SETUP_INVALID_DST_UUID 0x0002 -#define BNEP_SETUP_INVALID_UUID_SIZE 0x0003 -#define BNEP_SETUP_NOT_ALLOWED 0x0004 - -/* BNEP filter return codes */ -#define BNEP_FILTER_SUCCESS 0x0000 -#define BNEP_FILTER_UNSUPPORTED_REQUEST 0x0001 -#define BNEP_FILTER_INVALID_RANGE 0x0002 -#define BNEP_FILTER_TOO_MANY_FILTERS 0x0003 -#define BNEP_FILTER_SECURITY_FAILURE 0x0004 diff --git a/usr.sbin/bluetooth/btpand/btpand.8 b/usr.sbin/bluetooth/btpand/btpand.8 deleted file mode 100644 index b9726bf..0000000 --- a/usr.sbin/bluetooth/btpand/btpand.8 +++ /dev/null @@ -1,241 +0,0 @@ -.\" $NetBSD: btpand.8,v 1.3 2008/08/17 14:43:07 plunky Exp $ -.\" $FreeBSD$ -.\" -.\" Copyright (c) 2008 Iain Hibbert -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd August 17, 2008 -.Dt BTPAND 8 -.Os -.Sh NAME -.Nm btpand -.Nd Bluetooth PAN daemon -.Sh SYNOPSIS -.Nm -.Op Fl i Ar ifname -.Op Fl m Ar mode -.Fl a Ar addr -.Fl d Ar device -.Brq Fl s Ar service | Fl S Ar service Op Fl p Ar psm -.Nm -.Op Fl c Ar path -.Op Fl i Ar ifname -.Op Fl l Ar limit -.Op Fl m Ar mode -.Op Fl p Ar psm -.Fl d Ar device -.Brq Fl s Ar service | Fl S Ar service -.Sh DESCRIPTION -The -.Nm -daemon handles Bluetooth Personal Area Networking services -in the system. -It can operate in client mode as a Personal Area Networking User -.Pq PANU -or in server mode as Network Access Point -.Pq NAP , -Group ad-hoc Network -.Pq GN -or PANU host. -.Nm -connects to the system via a -.Xr tap 4 -virtual Ethernet device and forwards Ethernet packets to -remote Bluetooth devices using the Bluetooth Network Encapsulation -Protocol -.Pq BNEP . -.Pp -The PANU client is the device that uses either the NAP or GN -service, or can talk directly to a PANU host in a crossover -cable fashion. -.Pp -A GN host forwards Ethernet packets to each of the connected PAN -users as needed but does not provide access to any additional networks. -.Pp -The NAP service provides some of the features of an Ethernet bridge, -with the NAP host forwarding Ethernet packets between each of the -connected PAN users, and a different network -media. -.Pp -Note, the only differences between NAP and GN services as implemented by -.Nm -are in the SDP service record. -The bridging of packets by the NAP must be configured separately. -.Pp -The options are as follows: -.Bl -tag -width ".Fl a Ar address" -.It Fl a Ar address -In client mode, address of remote server. -May be given as BDADDR or name, in which case -.Nm -will attempt to resolve the address via the -.Xr bt_gethostbyname 3 -call. -.It Fl c Ar path -In server mode, specify -.Ar path -to the -.Xr sdpd 8 -control socket. -The default path is -.Pa /var/run/sdp . -.It Fl d Ar device -Restrict connections to the local -.Ar device . -May be given as BDADDR or name, in which case -.Nm -will attempt to resolve the address via the -.Xr bt_devaddr 3 -call. -.Nm -will set the -.Xr tap 4 -interface physical address to the BDADDR -of the Bluetooth radio. -.It Fl i Ar ifname -.Nm -uses the -.Xr tap 4 -driver to create a new network interface for use. -Use this option to select a specific -.Xr tap 4 -device interface which must already be created. -.It Fl l Ar limit -In server mode, limit the number of simultaneous connections. -The default limit is 7 for NAP and GN servers, -and 1 for a PANU server. -.It Fl m Ar mode -Set L2CAP connection link mode. -Supported modes are: -.Pp -.Bl -tag -compact -.It auth -require devices to be paired. -.It encrypt -auth, plus enable encryption. -.It secure -encryption, plus change of link key. -.El -.Pp -NOT YET SUPPORTED. -Use global device settings to set authentication and encryption. -.It Fl p Ar psm -Use an alternative L2CAP Protocol/Service Multiplexer -.Pq PSM -for server mode or client mode -.Pq when not using Service Discovery . -The default PSM for BNEP is 15 -.Pq 0x000f . -.It Fl s Ar service -Name of -.Ar service -to provide or connect to, the following services are recognised: -.Pp -.Bl -tag -compact -.It GN -Group ad-hoc Network. -.It NAP -Network Access Point. -.It PANU -Personal Area Networking User. -.El -.Pp -.It Fl S Ar service -As per -.Fl s -except that -.Nm -will not use SDP services for connection setup. -.El -.Pp -When providing networking services, the Bluetooth PAN profile says that the -.Sq Class of Device -property of the bluetooth controller SHALL include Networking capability -.Pq set bit 0x020000 . -See -.Xr hccontrol 8 -for details. -.Pp -After -.Nm -has set up the client or server connection and opened the -.Xr tap 4 -interface, it will create a pid file and detach. -.Sh FILES -.Bl -tag -compact -.It Pa /dev/tap -.It Pa /etc/bluetooth/hosts -.It Pa /var/run/sdp -.It Pa /var/run/tap Ns Em N Ns No .pid -.El -.Sh EXIT STATUS -.Ex -std -.Sh EXAMPLES -.Dl ifconfig tap1 create -.Dl btpand -a host -d mydevice -s NAP -i tap1 -.Dl dhclient tap1 -.Pp -Will create a connection to the NAP on -.Ar host , -and link that to the -.Ar tap1 -interface. -.Pp -.Dl btpand -d mydevice -s GN -.Pp -Will create a Group Network and register the GN service with the local -SDP server. -.Sh SEE ALSO -.Xr bluetooth 3 , -.Xr tap 4 , -.Xr bridge 4 , -.Xr hccontrol 8 , -.Xr dhclient 8 , -.Xr ifconfig 8 , -.Xr sdpd 8 -.Pp -The -.Qq Personal Area Networking Profile -and -.Qq Bluetooth Network Encapsulation Protocol -specifications are available at -.Dl http://www.bluetooth.com/ -.Sh AUTHORS -.An Iain Hibbert -.Sh BUGS -There is no way to supply alternative values for the SDP record. -.Pp -There is no way to set net type or multicast address filters. -.Pp -.Nm -does not do any address routing except to directly connected -unicast addresses. -All other packets are multicast. -.Pp -As -.Nm -uses the BDADDR of the Bluetooth radio as the physical address -of the tap, only one instance can be run per radio. -.Pp -.Nm -can only provide a single service. diff --git a/usr.sbin/bluetooth/btpand/btpand.c b/usr.sbin/bluetooth/btpand/btpand.c deleted file mode 100644 index 9387444..0000000 --- a/usr.sbin/bluetooth/btpand/btpand.c +++ /dev/null @@ -1,293 +0,0 @@ -/* $NetBSD: btpand.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__COPYRIGHT("@(#) Copyright (c) 2008 Iain Hibbert. All rights reserved."); -__RCSID("$NetBSD: btpand.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "btpand.h" - -/* global variables */ -const char * control_path; /* -c */ -const char * interface_name; /* -i */ -const char * service_name; /* -s */ -uint16_t service_class; - -bdaddr_t local_bdaddr; /* -d */ -bdaddr_t remote_bdaddr; /* -a */ -uint16_t l2cap_psm; /* -p */ -int l2cap_mode; /* -m */ - -int server_limit; /* -n */ - -static const struct { - const char * name; - uint16_t class; - const char * desc; -} services[] = { - { "PANU", SDP_SERVICE_CLASS_PANU, "Personal Area Networking User" }, - { "NAP", SDP_SERVICE_CLASS_NAP, "Network Acess Point" }, - { "GN", SDP_SERVICE_CLASS_GN, "Group Network" }, -}; - -static void main_exit(int); -static void main_detach(void); -static void usage(void); - -int -main(int argc, char *argv[]) -{ - unsigned long ul; - char * ep; - int ch, status; - - while ((ch = getopt(argc, argv, "a:c:d:i:l:m:p:S:s:")) != -1) { - switch (ch) { - case 'a': /* remote address */ - if (!bt_aton(optarg, &remote_bdaddr)) { - struct hostent *he; - - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(EXIT_FAILURE, "%s: %s", - optarg, hstrerror(h_errno)); - - bdaddr_copy(&remote_bdaddr, - (bdaddr_t *)he->h_addr); - } - - break; - - case 'c': /* control socket path */ - control_path = optarg; - break; - - case 'd': /* local address */ - if (!bt_devaddr(optarg, &local_bdaddr)) { - struct hostent *he; - - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(EXIT_FAILURE, "%s: %s", - optarg, hstrerror(h_errno)); - - bdaddr_copy(&local_bdaddr, - (bdaddr_t *)he->h_addr); - } - break; - - case 'i': /* tap interface name */ - if (strchr(optarg, '/') == NULL) { - asprintf(&ep, "/dev/%s", optarg); - interface_name = ep; - } else - interface_name = optarg; - break; - - case 'l': /* limit server sessions */ - ul = strtoul(optarg, &ep, 10); - if (*optarg == '\0' || *ep != '\0' || ul == 0) - errx(EXIT_FAILURE, "%s: invalid session limit", - optarg); - - server_limit = ul; - break; - - case 'm': /* link mode */ - warnx("Setting link mode is not yet supported"); - break; - - case 'p': /* protocol/service multiplexer */ - ul = strtoul(optarg, &ep, 0); - if (*optarg == '\0' || *ep != '\0' - || ul > 0xffff || L2CAP_PSM_INVALID(ul)) - errx(EXIT_FAILURE, "%s: invalid PSM", optarg); - - l2cap_psm = ul; - break; - - case 's': /* service */ - case 'S': /* service (no SDP) */ - for (ul = 0; strcasecmp(optarg, services[ul].name); ul++) { - if (ul == __arraycount(services)) - errx(EXIT_FAILURE, "%s: unknown service", optarg); - } - - if (ch == 's') - service_name = services[ul].name; - - service_class = services[ul].class; - break; - - default: - usage(); - /* NOTREACHED */ - } - } - - argc -= optind; - argv += optind; - - /* validate options */ - if (bdaddr_any(&local_bdaddr) || service_class == 0) - usage(); - - if (!bdaddr_any(&remote_bdaddr) && (server_limit != 0 || - control_path != 0 || (service_name != NULL && l2cap_psm != 0))) - usage(); - - /* default options */ - if (interface_name == NULL) - interface_name = "/dev/tap"; - - if (l2cap_psm == 0) - l2cap_psm = L2CAP_PSM_BNEP; - - if (bdaddr_any(&remote_bdaddr) && server_limit == 0) { - if (service_class == SDP_SERVICE_CLASS_PANU) - server_limit = 1; - else - server_limit = 7; - } - -#ifdef L2CAP_LM_MASTER - if (server_limit > 1 && service_class != SDP_SERVICE_CLASS_PANU) - l2cap_mode |= L2CAP_LM_MASTER; -#endif - - /* - * fork() now so that the setup can be done in the child process - * (as kqueue is not inherited) but block in the parent until the - * setup is finished so we can return an error if necessary. - */ - switch(fork()) { - case -1: /* bad */ - err(EXIT_FAILURE, "fork() failed"); - - case 0: /* child */ - signal(SIGPIPE, SIG_IGN); - - openlog(getprogname(), LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_DAEMON); - - channel_init(); - server_init(); - event_init(); - client_init(); - tap_init(); - - main_detach(); - - event_dispatch(); - break; - - default: /* parent */ - signal(SIGUSR1, main_exit); - wait(&status); - - if (WIFEXITED(status)) - exit(WEXITSTATUS(status)); - - break; - } - - err(EXIT_FAILURE, "exiting"); -} - -static void -main_exit(int s) -{ - - /* child is all grown up */ - _exit(EXIT_SUCCESS); -} - -static void -main_detach(void) -{ - int fd; - - if (kill(getppid(), SIGUSR1) == -1) - log_err("Could not signal main process: %m"); - - if (setsid() == -1) - log_err("setsid() failed"); - - fd = open(_PATH_DEVNULL, O_RDWR, 0); - if (fd == -1) { - log_err("Could not open %s", _PATH_DEVNULL); - } else { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); - close(fd); - } -} - -static void -usage(void) -{ - const char *p = getprogname(); - int n = strlen(p); - - fprintf(stderr, - "usage: %s [-i ifname] [-m mode] -a address -d device\n" - " %*s {-s service | -S service [-p psm]}\n" - " %s [-c path] [-i ifname] [-l limit] [-m mode] [-p psm] -d device\n" - " %*s {-s service | -S service}\n" - "\n" - "Where:\n" - "\t-a address remote bluetooth device\n" - "\t-c path SDP server socket\n" - "\t-d device local bluetooth device\n" - "\t-i ifname tap interface\n" - "\t-l limit limit server sessions\n" - "\t-m mode L2CAP link mode (NOT YET SUPPORTED)\n" - "\t-p psm L2CAP PSM\n" - "\t-S service service name (no SDP)\n" - "\t-s service service name\n" - "\n" - "Known services:\n" - "", p, n, "", p, n, ""); - - for (n = 0; n < __arraycount(services); n++) - fprintf(stderr, "\t%s\t%s\n", services[n].name, services[n].desc); - - exit(EXIT_FAILURE); -} diff --git a/usr.sbin/bluetooth/btpand/btpand.h b/usr.sbin/bluetooth/btpand/btpand.h deleted file mode 100644 index c5f7204..0000000 --- a/usr.sbin/bluetooth/btpand/btpand.h +++ /dev/null @@ -1,212 +0,0 @@ -/* $NetBSD: btpand.h,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "event.h" - -#ifndef __arraycount -#define __arraycount(__x) (int)(sizeof((__x)) / sizeof((__x)[0])) -#endif - -#ifndef L2CAP_PSM_INVALID -#define L2CAP_PSM_INVALID(psm) (((psm) & 0x0101) != 0x0001) -#endif - -#ifndef L2CAP_PSM_BNEP -#define L2CAP_PSM_BNEP 15 -#endif - -typedef struct channel channel_t; -typedef struct pfilter pfilter_t; -typedef struct mfilter mfilter_t; -typedef struct packet packet_t; -typedef struct pkthdr pkthdr_t; -typedef struct pktlist pktlist_t; -typedef struct exthdr exthdr_t; -typedef struct extlist extlist_t; - -LIST_HEAD(chlist, channel); -STAILQ_HEAD(extlist, exthdr); -STAILQ_HEAD(pktlist, pkthdr); - -enum channel_state { - CHANNEL_CLOSED, - CHANNEL_WAIT_CONNECT_REQ, - CHANNEL_WAIT_CONNECT_RSP, - CHANNEL_OPEN, -}; - -#define CHANNEL_MAXQLEN 128 - -/* BNEP or tap channel */ -struct channel { - enum channel_state state; - bool oactive; - - uint8_t laddr[ETHER_ADDR_LEN]; - uint8_t raddr[ETHER_ADDR_LEN]; - size_t mru; - size_t mtu; - - int npfilter; - pfilter_t * pfilter; - - int nmfilter; - mfilter_t * mfilter; - - pktlist_t pktlist; - int qlen; - - int fd; - struct event rd_ev; - struct event wr_ev; - uint8_t * sendbuf; - - bool (*send)(channel_t *, packet_t *); - bool (*recv)(packet_t *); - - int tick; - - struct pidfh *pfh; - - int refcnt; - LIST_ENTRY(channel) next; -}; - -/* network protocol type filter */ -struct pfilter { - uint16_t start; - uint16_t end; -}; - -/* multicast address filter */ -struct mfilter { - uint8_t start[ETHER_ADDR_LEN]; - uint8_t end[ETHER_ADDR_LEN]; -}; - -/* packet data buffer */ -struct packet { - channel_t * chan; /* source channel */ - uint8_t * dst; /* dest address */ - uint8_t * src; /* source address */ - uint8_t * type; /* protocol type */ - uint8_t * ptr; /* data pointer */ - size_t len; /* data length */ - int refcnt; /* reference count */ - extlist_t extlist;/* extension headers */ - uint8_t buf[0]; /* data starts here */ -}; - -/* extension header */ -struct exthdr { - STAILQ_ENTRY(exthdr) next; - uint8_t * ptr; - uint8_t len; -}; - -/* packet header */ -struct pkthdr { - STAILQ_ENTRY(pkthdr) next; - packet_t * data; -}; - -/* global variables */ -extern const char * control_path; -extern const char * service_name; -extern const char * interface_name; -extern bdaddr_t local_bdaddr; -extern bdaddr_t remote_bdaddr; -extern uint16_t l2cap_psm; -extern int l2cap_mode; -extern uint16_t service_class; -extern int server_limit; - -/* - * Bluetooth addresses are stored the other way around than - * Ethernet addresses even though they are of the same family - */ -static inline void -b2eaddr(void *dst, bdaddr_t *src) -{ - uint8_t *d = dst; - int i; - - for (i = 0; i < ETHER_ADDR_LEN; i++) - d[i] = src->b[ETHER_ADDR_LEN - i - 1]; -} - -#define log_err(fmt, args...) syslog(LOG_ERR, fmt , ##args) -#define log_info(fmt, args...) syslog(LOG_INFO, fmt , ##args) -#define log_notice(fmt, args...) syslog(LOG_NOTICE, fmt , ##args) -#define log_debug(fmt, args...) syslog(LOG_DEBUG, "%s: " fmt, __func__ , ##args) - -/* bnep.c */ -bool bnep_send(channel_t *, packet_t *); -bool bnep_recv(packet_t *); -void bnep_send_control(channel_t *, uint8_t, ...); - -/* channel.c */ -void channel_init(void); -channel_t * channel_alloc(void); -bool channel_open(channel_t *, int); -void channel_close(channel_t *); -void channel_free(channel_t *); -void channel_timeout(channel_t *, int); -void channel_put(channel_t *, packet_t *); - -/* client.c */ -void client_init(void); - -/* packet.c */ -packet_t * packet_alloc(channel_t *); -void packet_free(packet_t *); -void packet_adj(packet_t *, size_t); -pkthdr_t * pkthdr_alloc(packet_t *); -void pkthdr_free(pkthdr_t *); - -/* server.c */ -void server_init(void); -void server_update(int); - -/* tap.c */ -void tap_init(void); diff --git a/usr.sbin/bluetooth/btpand/channel.c b/usr.sbin/bluetooth/btpand/channel.c deleted file mode 100644 index b4eb4ab..0000000 --- a/usr.sbin/bluetooth/btpand/channel.c +++ /dev/null @@ -1,335 +0,0 @@ -/* $NetBSD: channel.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__RCSID("$NetBSD: channel.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); - -#include -#include - -#include -#include - -#include "btpand.h" - -static struct chlist channel_list; -static int channel_count; -static int channel_tick; - -static void channel_start(int, short, void *); -static void channel_read(int, short, void *); -static void channel_dispatch(packet_t *); -static void channel_watchdog(int, short, void *); - -void -channel_init(void) -{ - - LIST_INIT(&channel_list); -} - -channel_t * -channel_alloc(void) -{ - channel_t *chan; - - chan = malloc(sizeof(channel_t)); - if (chan == NULL) { - log_err("%s() failed: %m", __func__); - return NULL; - } - - memset(chan, 0, sizeof(channel_t)); - STAILQ_INIT(&chan->pktlist); - chan->state = CHANNEL_CLOSED; - LIST_INSERT_HEAD(&channel_list, chan, next); - - server_update(++channel_count); - - return chan; -} - -bool -channel_open(channel_t *chan, int fd) -{ - int n; - - assert(chan->refcnt == 0); - assert(chan->state != CHANNEL_CLOSED); - - if (chan->mtu > 0) { - chan->sendbuf = malloc(chan->mtu); - if (chan->sendbuf == NULL) { - log_err("Could not malloc channel sendbuf: %m"); - return false; - } - } - - n = 1; - if (ioctl(fd, FIONBIO, &n) == -1) { - log_err("Could not set non-blocking IO: %m"); - return false; - } - - event_set(&chan->rd_ev, fd, EV_READ | EV_PERSIST, channel_read, chan); - if (event_add(&chan->rd_ev, NULL) == -1) { - log_err("Could not add channel read event: %m"); - return false; - } - - event_set(&chan->wr_ev, fd, EV_WRITE, channel_start, chan); - - chan->refcnt++; - chan->fd = fd; - - log_debug("(fd#%d)", chan->fd); - - return true; -} - -void -channel_close(channel_t *chan) -{ - pkthdr_t *ph; - - assert(chan->state != CHANNEL_CLOSED); - - log_debug("(fd#%d)", chan->fd); - - chan->state = CHANNEL_CLOSED; - event_del(&chan->rd_ev); - event_del(&chan->wr_ev); - close(chan->fd); - chan->refcnt--; - chan->tick = 0; - - while ((ph = STAILQ_FIRST(&chan->pktlist)) != NULL) { - STAILQ_REMOVE_HEAD(&chan->pktlist, next); - pkthdr_free(ph); - chan->qlen--; - } - - if (chan->pfh != NULL) { - pidfile_remove(chan->pfh); - chan->pfh = NULL; - } - - if (chan->refcnt == 0) - channel_free(chan); -} - -void -channel_free(channel_t *chan) -{ - - assert(chan->refcnt == 0); - assert(chan->state == CHANNEL_CLOSED); - assert(chan->qlen == 0); - assert(STAILQ_EMPTY(&chan->pktlist)); - - LIST_REMOVE(chan, next); - free(chan->pfilter); - free(chan->mfilter); - free(chan->sendbuf); - free(chan); - - server_update(--channel_count); - - if (server_limit == 0) { - log_info("connection closed, exiting"); - exit(EXIT_SUCCESS); - } -} - -static void -channel_start(int fd, short ev, void *arg) -{ - channel_t *chan = arg; - pkthdr_t *ph; - - chan->oactive = true; - - while (chan->qlen > 0) { - ph = STAILQ_FIRST(&chan->pktlist); - - channel_timeout(chan, 10); - if (chan->send(chan, ph->data) == false) { - if (event_add(&chan->wr_ev, NULL) == -1) { - log_err("Could not add channel write event: %m"); - channel_close(chan); - } - return; - } - - STAILQ_REMOVE_HEAD(&chan->pktlist, next); - pkthdr_free(ph); - chan->qlen--; - } - - channel_timeout(chan, 0); - chan->oactive = false; -} - -static void -channel_read(int fd, short ev, void *arg) -{ - channel_t *chan = arg; - packet_t *pkt; - ssize_t nr; - - pkt = packet_alloc(chan); - if (pkt == NULL) { - channel_close(chan); - return; - } - - nr = read(fd, pkt->buf, chan->mru); - if (nr == -1) { - log_err("channel read error: %m"); - packet_free(pkt); - channel_close(chan); - return; - } - if (nr == 0) { /* EOF */ - log_debug("(fd#%d) EOF", fd); - packet_free(pkt); - channel_close(chan); - return; - } - pkt->len = nr; - - if (chan->recv(pkt) == true) - channel_dispatch(pkt); - - packet_free(pkt); -} - -static void -channel_dispatch(packet_t *pkt) -{ - channel_t *chan; - - /* - * This is simple routing. I'm not sure if its allowed by - * the PAN or BNEP specifications, but it seems logical - * to send unicast packets to connected destinations where - * possible. - */ - if (!ETHER_IS_MULTICAST(pkt->dst)) { - LIST_FOREACH(chan, &channel_list, next) { - if (chan == pkt->chan - || chan->state != CHANNEL_OPEN) - continue; - - if (memcmp(pkt->dst, chan->raddr, ETHER_ADDR_LEN) == 0) { - if (chan->qlen > CHANNEL_MAXQLEN) - log_notice("Queue overflow"); - else - channel_put(chan, pkt); - - return; - } - } - } - - LIST_FOREACH(chan, &channel_list, next) { - if (chan == pkt->chan - || chan->state != CHANNEL_OPEN) - continue; - - if (chan->qlen > CHANNEL_MAXQLEN) { - log_notice("Queue overflow"); - continue; - } - - channel_put(chan, pkt); - } -} - -void -channel_put(channel_t *chan, packet_t *pkt) -{ - pkthdr_t *ph; - - ph = pkthdr_alloc(pkt); - if (ph == NULL) - return; - - chan->qlen++; - STAILQ_INSERT_TAIL(&chan->pktlist, ph, next); - - if (!chan->oactive) - channel_start(chan->fd, EV_WRITE, chan); -} - -/* - * Simple watchdog timer, only ticks when it is required and - * closes the channel down if it times out. - */ -void -channel_timeout(channel_t *chan, int to) -{ - static struct event ev; - - if (to == 0) - chan->tick = 0; - else - chan->tick = (channel_tick + to) % 60; - - if (channel_tick == 0) { - evtimer_set(&ev, channel_watchdog, &ev); - channel_watchdog(0, 0, &ev); - } -} - -static void -channel_watchdog(int fd, short ev, void *arg) -{ - static struct timeval tv = { .tv_sec = 1 }; - channel_t *chan, *next; - int tick; - - tick = (channel_tick % 60) + 1; - channel_tick = 0; - - next = LIST_FIRST(&channel_list); - while ((chan = next) != NULL) { - next = LIST_NEXT(chan, next); - - if (chan->tick == tick) - channel_close(chan); - else if (chan->tick != 0) - channel_tick = tick; - } - - if (channel_tick != 0 && evtimer_add(arg, &tv) < 0) { - log_err("Could not add watchdog event: %m"); - exit(EXIT_FAILURE); - } -} diff --git a/usr.sbin/bluetooth/btpand/client.c b/usr.sbin/bluetooth/btpand/client.c deleted file mode 100644 index 97064db..0000000 --- a/usr.sbin/bluetooth/btpand/client.c +++ /dev/null @@ -1,192 +0,0 @@ -/* $NetBSD: client.c,v 1.2 2008/12/06 20:01:14 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__RCSID("$NetBSD: client.c,v 1.2 2008/12/06 20:01:14 plunky Exp $"); - -#include -#include -#include -#include - -#include "btpand.h" -#include "bnep.h" -#include "sdp.h" - -static void client_query(void); - -void -client_init(void) -{ - struct sockaddr_l2cap sa; - channel_t *chan; - socklen_t len; - int fd; - uint16_t mru, mtu; - - if (bdaddr_any(&remote_bdaddr)) - return; - - if (service_name) - client_query(); - - fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP); - if (fd == -1) { - log_err("Could not open L2CAP socket: %m"); - exit(EXIT_FAILURE); - } - - memset(&sa, 0, sizeof(sa)); - sa.l2cap_family = AF_BLUETOOTH; - sa.l2cap_len = sizeof(sa); - bdaddr_copy(&sa.l2cap_bdaddr, &local_bdaddr); - if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { - log_err("Could not bind client socket: %m"); - exit(EXIT_FAILURE); - } - - mru = BNEP_MTU_MIN; - if (setsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, sizeof(mru)) == -1) { - log_err("Could not set L2CAP IMTU (%d): %m", mru); - exit(EXIT_FAILURE); - } - - log_info("Opening connection to service 0x%4.4x at %s", - service_class, bt_ntoa(&remote_bdaddr, NULL)); - - sa.l2cap_psm = htole16(l2cap_psm); - bdaddr_copy(&sa.l2cap_bdaddr, &remote_bdaddr); - if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { - log_err("Could not connect: %m"); - exit(EXIT_FAILURE); - } - - len = sizeof(mru); - if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, &len) == -1) { - log_err("Could not get IMTU: %m"); - exit(EXIT_FAILURE); - } - if (mru < BNEP_MTU_MIN) { - log_err("L2CAP IMTU too small (%d)", mru); - exit(EXIT_FAILURE); - } - - len = sizeof(mtu); - if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) { - log_err("Could not get L2CAP OMTU: %m"); - exit(EXIT_FAILURE); - } - if (mtu < BNEP_MTU_MIN) { - log_err("L2CAP OMTU too small (%d)", mtu); - exit(EXIT_FAILURE); - } - - chan = channel_alloc(); - if (chan == NULL) - exit(EXIT_FAILURE); - - chan->send = bnep_send; - chan->recv = bnep_recv; - chan->mru = mru; - chan->mtu = mtu; - b2eaddr(chan->raddr, &remote_bdaddr); - b2eaddr(chan->laddr, &local_bdaddr); - chan->state = CHANNEL_WAIT_CONNECT_RSP; - channel_timeout(chan, 10); - if (!channel_open(chan, fd)) - exit(EXIT_FAILURE); - - bnep_send_control(chan, BNEP_SETUP_CONNECTION_REQUEST, - 2, service_class, SDP_SERVICE_CLASS_PANU); -} - -static void -client_query(void) -{ - uint8_t buffer[512]; - sdp_attr_t attr; - uint32_t range; - void *ss; - int rv; - uint8_t *seq0, *seq1; - - attr.flags = SDP_ATTR_INVALID; - attr.attr = 0; - attr.vlen = sizeof(buffer); - attr.value = buffer; - - range = SDP_ATTR_RANGE(SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST); - - ss = sdp_open(&local_bdaddr, &remote_bdaddr); - if (ss == NULL || (errno = sdp_error(ss)) != 0) { - log_err("%s: %m", service_name); - exit(EXIT_FAILURE); - } - - log_info("Searching for %s service at %s", - service_name, bt_ntoa(&remote_bdaddr, NULL)); - - rv = sdp_search(ss, 1, &service_class, 1, &range, 1, &attr); - if (rv != 0) { - log_err("%s: %s", service_name, strerror(sdp_error(ss))); - exit(EXIT_FAILURE); - } - - sdp_close(ss); - - if (attr.flags != SDP_ATTR_OK - || attr.attr != SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST) { - log_err("%s service not found", service_name); - exit(EXIT_FAILURE); - } - - /* - * we expect the following protocol descriptor list - * - * seq len - * seq len - * uuid value == L2CAP - * uint16 value16 => PSM - * seq len - * uuid value == BNEP - */ - if (_sdp_get_seq(&attr.value, attr.value + attr.vlen, &seq0) - && _sdp_get_seq(&seq0, attr.value, &seq1) - && _sdp_match_uuid16(&seq1, seq0, SDP_UUID_PROTOCOL_L2CAP) - && _sdp_get_uint16(&seq1, seq0, &l2cap_psm) - && _sdp_get_seq(&seq0, attr.value, &seq1) - && _sdp_match_uuid16(&seq1, seq0, SDP_UUID_PROTOCOL_BNEP)) { - log_info("Found PSM %d for service %s", l2cap_psm, service_name); - return; - } - - log_err("%s query failed", service_name); - exit(EXIT_FAILURE); -} diff --git a/usr.sbin/bluetooth/btpand/event.c b/usr.sbin/bluetooth/btpand/event.c deleted file mode 100644 index 159f90c..0000000 --- a/usr.sbin/bluetooth/btpand/event.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - * event.h - */ - -/*- - * Copyright (c) 2009 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -/* - * Hack to provide libevent (see devel/libevent port) like API. - * Should be removed if FreeBSD ever decides to import libevent into base. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "event.h" -#include "btpand.h" - -#define __event_link(ev) \ -do { \ - TAILQ_INSERT_TAIL(&pending, ev, next); \ - ev->flags |= EV_PENDING; \ -} while (0) - -static void tv_add(struct timeval *, struct timeval const *); -static void tv_sub(struct timeval *, struct timeval const *); -static int tv_cmp(struct timeval const *, struct timeval const *); -static int __event_dispatch(void); -static void __event_add_current(struct event *); -static void __event_del_current(struct event *); - - -static TAILQ_HEAD(, event) pending; -static TAILQ_HEAD(, event) current; - -void -event_init(void) -{ - TAILQ_INIT(&pending); -} - -int -event_dispatch(void) -{ - while (__event_dispatch() == 0) - ; - - return (-1); -} - -static int -__event_dispatch(void) -{ - fd_set r, w; - int nfd; - struct event *ev; - struct timeval now, timeout, t; - - FD_ZERO(&r); - FD_ZERO(&w); - - nfd = 0; - - gettimeofday(&now, NULL); - - timeout.tv_sec = 10; /* arbitrary */ - timeout.tv_usec = 0; - - TAILQ_INIT(¤t); - - /* - * Build fd_set's - */ - - event_log_debug("%s: building fd set...", __func__); - - while (!TAILQ_EMPTY(&pending)) { - ev = TAILQ_FIRST(&pending); - event_del(ev); - - if (ev->flags & EV_HAS_TIMEOUT) { - if (tv_cmp(&now, &ev->expire) >= 0) - t.tv_sec = t.tv_usec = 0; - else { - t = ev->expire; - tv_sub(&t, &now); - } - - if (tv_cmp(&t, &timeout) < 0) - timeout = t; - } - - if (ev->fd >= 0) { - if (ev->flags & EV_READ) { - FD_SET(ev->fd, &r); - nfd = (nfd > ev->fd) ? nfd : ev->fd; - } - - if (ev->flags & EV_WRITE) { - FD_SET(ev->fd, &w); - nfd = (nfd > ev->fd) ? nfd : ev->fd; - } - } - - __event_add_current(ev); - } - - event_log_debug("%s: waiting for events...", __func__); - - nfd = select(nfd + 1, &r, &w, NULL, &timeout); - if (nfd < 0) - return (-1); - - /* - * Process current pending - */ - - event_log_debug("%s: processing events...", __func__); - - gettimeofday(&now, NULL); - - while (!TAILQ_EMPTY(¤t)) { - ev = TAILQ_FIRST(¤t); - __event_del_current(ev); - - /* check if fd is ready for reading/writing */ - if (nfd > 0 && ev->fd >= 0) { - if (FD_ISSET(ev->fd, &r) || FD_ISSET(ev->fd, &w)) { - if (ev->flags & EV_PERSIST) { - if (ev->flags & EV_HAS_TIMEOUT) - event_add(ev, &ev->timeout); - else - event_add(ev, NULL); - } - - nfd --; - - event_log_debug("%s: calling %p(%d, %p), " \ - "ev=%p", __func__, ev->cb, ev->fd, - ev->cbarg, ev); - - (ev->cb)(ev->fd, - (ev->flags & (EV_READ|EV_WRITE)), - ev->cbarg); - - continue; - } - } - - /* if event has no timeout - just requeue */ - if ((ev->flags & EV_HAS_TIMEOUT) == 0) { - event_add(ev, NULL); - continue; - } - - /* check if event has expired */ - if (tv_cmp(&now, &ev->expire) >= 0) { - if (ev->flags & EV_PERSIST) - event_add(ev, &ev->timeout); - - event_log_debug("%s: calling %p(%d, %p), ev=%p", - __func__, ev->cb, ev->fd, ev->cbarg, ev); - - (ev->cb)(ev->fd, - (ev->flags & (EV_READ|EV_WRITE)), - ev->cbarg); - - continue; - } - - assert((ev->flags & (EV_PENDING|EV_CURRENT)) == 0); - __event_link(ev); - } - - return (0); -} - -void -__event_set(struct event *ev, int fd, short flags, - void (*cb)(int, short, void *), void *cbarg) -{ - ev->fd = fd; - ev->flags = flags; - ev->cb = cb; - ev->cbarg = cbarg; -} - -int -__event_add(struct event *ev, const struct timeval *timeout) -{ - assert((ev->flags & (EV_PENDING|EV_CURRENT)) == 0); - - if (timeout != NULL) { - gettimeofday(&ev->expire, NULL); - tv_add(&ev->expire, timeout); - ev->timeout = *timeout; - ev->flags |= EV_HAS_TIMEOUT; - } else - ev->flags &= ~EV_HAS_TIMEOUT; - - __event_link(ev); - - return (0); -} - -int -__event_del(struct event *ev) -{ - assert((ev->flags & EV_CURRENT) == 0); - - if ((ev->flags & EV_PENDING) != 0) { - TAILQ_REMOVE(&pending, ev, next); - ev->flags &= ~EV_PENDING; - } - - return (0); -} - -static void -__event_add_current(struct event *ev) -{ - assert((ev->flags & (EV_PENDING|EV_CURRENT)) == 0); - - TAILQ_INSERT_TAIL(¤t, ev, next); - ev->flags |= EV_CURRENT; -} - -static void -__event_del_current(struct event *ev) -{ - assert((ev->flags & (EV_CURRENT|EV_PENDING)) == EV_CURRENT); - - TAILQ_REMOVE(¤t, ev, next); - ev->flags &= ~EV_CURRENT; -} - -static void -tv_add(struct timeval *a, struct timeval const *b) -{ - a->tv_sec += b->tv_sec; - a->tv_usec += b->tv_usec; - - if(a->tv_usec >= 1000000) { - a->tv_usec -= 1000000; - a->tv_sec += 1; - } -} - -static void -tv_sub(struct timeval *a, struct timeval const *b) -{ - if (a->tv_usec < b->tv_usec) { - a->tv_usec += 1000000; - a->tv_sec -= 1; - } - - a->tv_usec -= b->tv_usec; - a->tv_sec -= b->tv_sec; -} - -static int -tv_cmp(struct timeval const *a, struct timeval const *b) -{ - if (a->tv_sec > b->tv_sec) - return (1); - - if (a->tv_sec < b->tv_sec) - return (-1); - - if (a->tv_usec > b->tv_usec) - return (1); - - if (a->tv_usec < b->tv_usec) - return (-1); - - return (0); -} - diff --git a/usr.sbin/bluetooth/btpand/event.h b/usr.sbin/bluetooth/btpand/event.h deleted file mode 100644 index 75515e3..0000000 --- a/usr.sbin/bluetooth/btpand/event.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * event.h - */ - -/*- - * Copyright (c) 2009 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -/* - * Hack to provide libevent (see devel/libevent port) like API. - * Should be removed if FreeBSD ever decides to import libevent into base. - */ - -#ifndef _EVENT_H_ -#define _EVENT_H_ 1 - -#define EV_READ 0x02 -#define EV_WRITE 0x04 -#define EV_PERSIST 0x10 /* Persistant event */ -#define EV_PENDING (1 << 13) /* internal use only! */ -#define EV_HAS_TIMEOUT (1 << 14) /* internal use only! */ -#define EV_CURRENT (1 << 15) /* internal use only! */ - -struct event -{ - int fd; - short flags; - void (*cb)(int, short, void *); - void *cbarg; - struct timeval timeout; - struct timeval expire; - -#ifdef EVENT_DEBUG - char const *files[3]; - int lines[3]; -#endif - - TAILQ_ENTRY(event) next; -}; - -void event_init (void); -int event_dispatch (void); - -void __event_set (struct event *, int, short, - void (*)(int, short, void *), void *); -int __event_add (struct event *, struct timeval const *); -int __event_del (struct event *); - -#ifdef EVENT_DEBUG -#define event_log_err(fmt, args...) syslog(LOG_ERR, fmt, ##args) -#define event_log_info(fmt, args...) syslog(LOG_INFO, fmt, ##args) -#define event_log_notice(fmt, args...) syslog(LOG_NOTICE, fmt, ##args) -#define event_log_debug(fmt, args...) syslog(LOG_DEBUG, fmt, ##args) - -#define event_set(ev, fd, flags, cb, cbarg) \ - _event_set(__FILE__, __LINE__, ev, fd, flags, cb, cbarg) -#define event_add(ev, timeout) \ - _event_add(__FILE__, __LINE__, ev, timeout) -#define event_del(ev) \ - _event_del(__FILE__, __LINE__, ev) - -#define evtimer_set(ev, cb, cbarg) \ - _event_set(__FILE__, __LINE__, ev, -1, 0, cb, cbarg) -#define evtimer_add(ev, timeout) \ - _event_add(__FILE__, __LINE__, ev, timeout) - -static inline void -_event_set(char const *file, int line, struct event *ev, int fd, short flags, - void (*cb)(int, short, void *), void *cbarg) -{ - event_log_debug("set %s:%d ev=%p, fd=%d, flags=%#x, cb=%p, cbarg=%p", - file, line, ev, fd, flags, cb, cbarg); - - ev->files[0] = file; - ev->lines[0] = line; - - __event_set(ev, fd, flags, cb, cbarg); -} - -static inline int -_event_add(char const *file, int line, struct event *ev, - struct timeval const *timeout) { - event_log_debug("add %s:%d ev=%p, fd=%d, flags=%#x, cb=%p, cbarg=%p, " \ - "timeout=%p", file, line, ev, ev->fd, ev->flags, ev->cb, - ev->cbarg, timeout); - - ev->files[1] = file; - ev->lines[1] = line; - - return (__event_add(ev, timeout)); -} - -static inline int -_event_del(char const *file, int line, struct event *ev) -{ - event_log_debug("del %s:%d ev=%p, fd=%d, flags=%#x, cb=%p, cbarg=%p", - file, line, ev, ev->fd, ev->flags, ev->cb, ev->cbarg); - - ev->files[2] = file; - ev->lines[2] = line; - - return (__event_del(ev)); -} -#else -#define event_log_err(fmt, args...) -#define event_log_info(fmt, args...) -#define event_log_notice(fmt, args...) -#define event_log_debug(fmt, args...) - -#define event_set(ev, fd, flags, cb, cbarg) \ - __event_set(ev, fd, flags, cb, cbarg) -#define event_add(ev, timeout) \ - __event_add(ev, timeout) -#define event_del(ev) \ - __event_del(ev) - -#define evtimer_set(ev, cb, cbarg) \ - __event_set(ev, -1, 0, cb, cbarg) -#define evtimer_add(ev, timeout) \ - __event_add(ev, timeout) -#endif /* EVENT_DEBUG */ - -#endif /* ndef _EVENT_H_ */ diff --git a/usr.sbin/bluetooth/btpand/packet.c b/usr.sbin/bluetooth/btpand/packet.c deleted file mode 100644 index e42e5c5..0000000 --- a/usr.sbin/bluetooth/btpand/packet.c +++ /dev/null @@ -1,110 +0,0 @@ -/* $NetBSD: packet.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__RCSID("$NetBSD: packet.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); - -#include "btpand.h" - -packet_t * -packet_alloc(channel_t *chan) -{ - packet_t *pkt; - - pkt = malloc(sizeof(packet_t) + chan->mru); - if (pkt == NULL) { - log_err("%s() failed: %m", __func__); - return NULL; - } - - memset(pkt, 0, sizeof(packet_t)); - STAILQ_INIT(&pkt->extlist); - pkt->ptr = pkt->buf; - - pkt->chan = chan; - chan->refcnt++; - - return pkt; -} - -void -packet_free(packet_t *pkt) -{ - exthdr_t *eh; - - if (pkt->refcnt-- > 0) - return; - - while ((eh = STAILQ_FIRST(&pkt->extlist)) != NULL) { - STAILQ_REMOVE_HEAD(&pkt->extlist, next); - free(eh); - } - - pkt->chan->refcnt--; - if (pkt->chan->refcnt == 0) - channel_free(pkt->chan); - - free(pkt); -} - -void -packet_adj(packet_t *pkt, size_t size) -{ - - assert(pkt->refcnt == 0); - assert(pkt->len >= size); - - pkt->ptr += size; - pkt->len -= size; -} - -pkthdr_t * -pkthdr_alloc(packet_t *pkt) -{ - pkthdr_t *ph; - - ph = malloc(sizeof(pkthdr_t)); - if (ph == NULL) { - log_err("%s() failed: %m", __func__); - return NULL; - } - - ph->data = pkt; - pkt->refcnt++; - - return ph; -} - -void -pkthdr_free(pkthdr_t *ph) -{ - - packet_free(ph->data); - free(ph); -} diff --git a/usr.sbin/bluetooth/btpand/sdp.c b/usr.sbin/bluetooth/btpand/sdp.c deleted file mode 100644 index e5aec1c..0000000 --- a/usr.sbin/bluetooth/btpand/sdp.c +++ /dev/null @@ -1,209 +0,0 @@ -/* $NetBSD: sdp.c,v 1.2 2008/12/06 20:01:14 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__RCSID("$NetBSD: sdp.c,v 1.2 2008/12/06 20:01:14 plunky Exp $"); - -#include - -#include "sdp.h" - -/* - * SDP data stream manipulation routines - */ - -/* Bluetooth Base UUID */ -static const uuid_t BASE_UUID = { - 0x00000000, - 0x0000, - 0x1000, - 0x80, - 0x00, - { 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb } -}; - -/* - * _sdp_match_uuid16(ptr, limit, uuid) - * - * examine SDP data stream at ptr for a UUID, and return - * true if it matches the supplied short alias bluetooth UUID. - * limit is the first address past the end of valid data. - */ -bool -_sdp_match_uuid16(uint8_t **ptr, uint8_t *limit, uint16_t uuid) -{ - uint8_t *p = *ptr; - uuid_t u1, u2; - - memcpy(&u1, &BASE_UUID, sizeof(uuid_t)); - u1.time_low = uuid; - - if (!_sdp_get_uuid(&p, limit, &u2) - || !uuid_equal(&u1, &u2, NULL)) - return false; - - *ptr = p; - return true; -} - -/* - * _sdp_get_uuid(ptr, limit, uuid) - * - * examine SDP data stream at ptr for a UUID, and extract - * to given storage, advancing ptr. - * limit is the first address past the end of valid data. - */ -bool -_sdp_get_uuid(uint8_t **ptr, uint8_t *limit, uuid_t *uuid) -{ - uint8_t *p = *ptr; - - if (p + 1 > limit) - return false; - - switch (*p++) { - case SDP_DATA_UUID16: - if (p + 2 > limit) - return false; - - memcpy(uuid, &BASE_UUID, sizeof(uuid_t)); - uuid->time_low = be16dec(p); - p += 2; - break; - - case SDP_DATA_UUID32: - if (p + 4 > limit) - return false; - - memcpy(uuid, &BASE_UUID, sizeof(uuid_t)); - uuid->time_low = be32dec(p); - p += 4; - break; - - case SDP_DATA_UUID128: - if (p + 16 > limit) - return false; - - uuid_dec_be(p, uuid); - p += 16; - break; - - default: - return false; - } - - *ptr = p; - return true; -} - -/* - * _sdp_get_seq(ptr, limit, seq) - * - * examine SDP data stream at ptr for a sequence. return - * seq pointer if found and advance ptr to next object. - * limit is the first address past the end of valid data. - */ -bool -_sdp_get_seq(uint8_t **ptr, uint8_t *limit, uint8_t **seq) -{ - uint8_t *p = *ptr; - int32_t l; - - if (p + 1 > limit) - return false; - - switch (*p++) { - case SDP_DATA_SEQ8: - if (p + 1 > limit) - return false; - - l = *p; - p += 1; - break; - - case SDP_DATA_SEQ16: - if (p + 2 > limit) - return false; - - l = be16dec(p); - p += 2; - break; - - case SDP_DATA_SEQ32: - if (p + 4 > limit) - return false; - - l = be32dec(p); - p += 4; - break; - - default: - return false; - } - if (p + l > limit) - return false; - - *seq = p; - *ptr = p + l; - return true; -} - -/* - * _sdp_get_uint16(ptr, limit, value) - * - * examine SDP data stream at ptr for a uint16_t, and - * extract to given storage, advancing ptr. - * limit is the first address past the end of valid data. - */ -bool -_sdp_get_uint16(uint8_t **ptr, uint8_t *limit, uint16_t *value) -{ - uint8_t *p = *ptr; - uint16_t v; - - if (p + 1 > limit) - return false; - - switch (*p++) { - case SDP_DATA_UINT16: - if (p + 2 > limit) - return false; - - v = be16dec(p); - p += 2; - break; - - default: - return false; - } - - *value = v; - *ptr = p; - return true; -} diff --git a/usr.sbin/bluetooth/btpand/sdp.h b/usr.sbin/bluetooth/btpand/sdp.h deleted file mode 100644 index 32dd95d..0000000 --- a/usr.sbin/bluetooth/btpand/sdp.h +++ /dev/null @@ -1,38 +0,0 @@ -/* $NetBSD: sdp.h,v 1.2 2008/12/06 20:01:15 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -#include -#include -#include - -bool _sdp_match_uuid16(uint8_t **, uint8_t *, uint16_t); -bool _sdp_get_uuid(uint8_t **, uint8_t *, uuid_t *); -bool _sdp_get_seq(uint8_t **, uint8_t *, uint8_t **); -bool _sdp_get_uint16(uint8_t **, uint8_t *, uint16_t *); diff --git a/usr.sbin/bluetooth/btpand/server.c b/usr.sbin/bluetooth/btpand/server.c deleted file mode 100644 index 0843d0c..0000000 --- a/usr.sbin/bluetooth/btpand/server.c +++ /dev/null @@ -1,277 +0,0 @@ -/* $NetBSD: server.c,v 1.2 2009/01/24 17:29:28 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__RCSID("$NetBSD: server.c,v 1.2 2009/01/24 17:29:28 plunky Exp $"); - -#include - -#include -#include -#include -#include -#include - -#include "btpand.h" -#include "bnep.h" - -static struct event server_ev; -static int server_fd; -static int server_avail; - -static void * server_ss; -static uint32_t server_handle; - -static void server_open(void); -static void server_close(void); -static void server_read(int, short, void *); -static void server_register(void); - -void -server_init(void) -{ - - server_fd = -1; -} - -/* - * The server_update() function is called whenever the channel count is - * changed. We maintain the SDP record and open or close the server socket - * as required. - */ -void -server_update(int count) -{ - - if (server_limit == 0) - return; - - log_debug("count %d", count); - - server_avail = UINT8_MAX - (count - 1) * UINT8_MAX / server_limit; - log_info("Service Availability: %d/%d", server_avail, UINT8_MAX); - - if (server_avail == 0 && server_fd != -1) - server_close(); - - if (server_avail > 0 && server_fd == -1) - server_open(); - - if (service_name) - server_register(); -} - -static void -server_open(void) -{ - struct sockaddr_l2cap sa; - uint16_t mru; - - server_fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP); - if (server_fd == -1) { - log_err("Could not open L2CAP socket: %m"); - exit(EXIT_FAILURE); - } - - memset(&sa, 0, sizeof(sa)); - sa.l2cap_family = AF_BLUETOOTH; - sa.l2cap_len = sizeof(sa); - sa.l2cap_psm = htole16(l2cap_psm); - bdaddr_copy(&sa.l2cap_bdaddr, &local_bdaddr); - if (bind(server_fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) { - log_err("Could not bind server socket: %m"); - exit(EXIT_FAILURE); - } - - mru = BNEP_MTU_MIN; - if (setsockopt(server_fd, SOL_L2CAP, - SO_L2CAP_IMTU, &mru, sizeof(mru)) == -1) { - log_err("Could not set L2CAP IMTU (%d): %m", mru); - exit(EXIT_FAILURE); - } - - if (listen(server_fd, 0) == -1) { - log_err("Could not listen on server socket: %m"); - exit(EXIT_FAILURE); - } - - event_set(&server_ev, server_fd, EV_READ | EV_PERSIST, server_read, NULL); - if (event_add(&server_ev, NULL) == -1) { - log_err("Could not add server event: %m"); - exit(EXIT_FAILURE); - } - - log_info("server socket open"); -} - -static void -server_close(void) -{ - - event_del(&server_ev); - close(server_fd); - server_fd = -1; - - log_info("server socket closed"); -} - -/* - * handle connection request - */ -static void -server_read(int s, short ev, void *arg) -{ - struct sockaddr_l2cap ra, la; - channel_t *chan; - socklen_t len; - int fd, n; - uint16_t mru, mtu; - - len = sizeof(ra); - fd = accept(s, (struct sockaddr *)&ra, &len); - if (fd == -1) - return; - - n = 1; - if (ioctl(fd, FIONBIO, &n) == -1) { - log_err("Could not set NonBlocking IO: %m"); - close(fd); - return; - } - - len = sizeof(mru); - if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_IMTU, &mru, &len) == -1) { - log_err("Could not get L2CAP IMTU: %m"); - close(fd); - return; - } - if(mru < BNEP_MTU_MIN) { - log_err("L2CAP IMTU too small (%d)", mru); - close(fd); - return; - } - - len = sizeof(mtu); - if (getsockopt(fd, SOL_L2CAP, SO_L2CAP_OMTU, &mtu, &len) == -1) { - log_err("Could not get L2CAP OMTU: %m"); - close(fd); - return; - } - if (mtu < BNEP_MTU_MIN) { - log_err("L2CAP OMTU too small (%d)", mtu); - close(fd); - return; - } - - len = sizeof(n); - if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, &len) == -1) { - log_err("Could not get socket send buffer size: %m"); - close(fd); - return; - } - - if (n < (mtu * 2)) { - n = mtu * 2; - if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &n, sizeof(n)) == -1) { - log_err("Could not set socket send buffer size (%d): %m", n); - close(fd); - return; - } - } - - n = mtu; - if (setsockopt(fd, SOL_SOCKET, SO_SNDLOWAT, &n, sizeof(n)) == -1) { - log_err("Could not set socket low water mark (%d): %m", n); - close(fd); - return; - } - - len = sizeof(la); - if (getsockname(fd, (struct sockaddr *)&la, &len) == -1) { - log_err("Could not get socket address: %m"); - close(fd); - return; - } - - log_info("Accepted connection from %s", bt_ntoa(&ra.l2cap_bdaddr, NULL)); - - chan = channel_alloc(); - if (chan == NULL) { - close(fd); - return; - } - - chan->send = bnep_send; - chan->recv = bnep_recv; - chan->mru = mru; - chan->mtu = mtu; - b2eaddr(chan->raddr, &ra.l2cap_bdaddr); - b2eaddr(chan->laddr, &la.l2cap_bdaddr); - chan->state = CHANNEL_WAIT_CONNECT_REQ; - channel_timeout(chan, 10); - if (!channel_open(chan, fd)) { - chan->state = CHANNEL_CLOSED; - channel_free(chan); - close(fd); - return; - } -} - -static void -server_register(void) -{ - sdp_nap_profile_t p; - int rv; - - if (server_ss == NULL) { - server_ss = sdp_open_local(control_path); - if (server_ss == NULL || sdp_error(server_ss) != 0) { - log_err("failed to contact SDP server"); - return; - } - } - - memset(&p, 0, sizeof(p)); - p.psm = l2cap_psm; - p.load_factor = server_avail; - p.security_description = (l2cap_mode == 0 ? 0x0000 : 0x0001); - - if (server_handle) - rv = sdp_change_service(server_ss, server_handle, - (uint8_t *)&p, sizeof(p)); - else - rv = sdp_register_service(server_ss, service_class, - &local_bdaddr, (uint8_t *)&p, sizeof(p), &server_handle); - - if (rv != 0) { - errno = sdp_error(server_ss); - log_err("%s: %m", service_name); - exit(EXIT_FAILURE); - } -} diff --git a/usr.sbin/bluetooth/btpand/tap.c b/usr.sbin/bluetooth/btpand/tap.c deleted file mode 100644 index c965633..0000000 --- a/usr.sbin/bluetooth/btpand/tap.c +++ /dev/null @@ -1,167 +0,0 @@ -/* $NetBSD: tap.c,v 1.1 2008/08/17 13:20:57 plunky Exp $ */ - -/*- - * Copyright (c) 2008 Iain Hibbert - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#include -__RCSID("$NetBSD: tap.c,v 1.1 2008/08/17 13:20:57 plunky Exp $"); - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include "btpand.h" - -static bool tap_send(channel_t *, packet_t *); -static bool tap_recv(packet_t *); - -void -tap_init(void) -{ - channel_t *chan; - struct ifreq ifr; - int fd, s; - char pidfile[PATH_MAX]; - - fd = open(interface_name, O_RDWR); - if (fd == -1) { - log_err("Could not open \"%s\": %m", interface_name); - exit(EXIT_FAILURE); - } - - memset(&ifr, 0, sizeof(ifr)); - if (ioctl(fd, TAPGIFNAME, &ifr) == -1) { - log_err("Could not get interface name: %m"); - exit(EXIT_FAILURE); - } - - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s == -1) { - log_err("Could not open PF_LINK socket: %m"); - exit(EXIT_FAILURE); - } - - ifr.ifr_addr.sa_family = AF_LINK; - ifr.ifr_addr.sa_len = ETHER_ADDR_LEN; - b2eaddr(ifr.ifr_addr.sa_data, &local_bdaddr); - - if (ioctl(s, SIOCSIFLLADDR, &ifr) == -1) { - log_err("Could not set %s physical address: %m", ifr.ifr_name); - exit(EXIT_FAILURE); - } - - if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) { - log_err("Could not get interface flags: %m"); - exit(EXIT_FAILURE); - } - - if ((ifr.ifr_flags & IFF_UP) == 0) { - ifr.ifr_flags |= IFF_UP; - - if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) { - log_err("Could not set IFF_UP: %m"); - exit(EXIT_FAILURE); - } - } - - close(s); - - log_info("Using interface %s with addr %s", ifr.ifr_name, - ether_ntoa((struct ether_addr *)&ifr.ifr_addr.sa_data)); - - chan = channel_alloc(); - if (chan == NULL) - exit(EXIT_FAILURE); - - chan->send = tap_send; - chan->recv = tap_recv; - chan->mru = ETHER_HDR_LEN + ETHER_MAX_LEN; - memcpy(chan->raddr, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); - memcpy(chan->laddr, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); - chan->state = CHANNEL_OPEN; - if (!channel_open(chan, fd)) - exit(EXIT_FAILURE); - - snprintf(pidfile, sizeof(pidfile), "%s/%s.pid", - _PATH_VARRUN, ifr.ifr_name); - chan->pfh = pidfile_open(pidfile, 0600, NULL); - if (chan->pfh == NULL) - log_err("can't create pidfile"); - else if (pidfile_write(chan->pfh) < 0) { - log_err("can't write pidfile"); - pidfile_remove(chan->pfh); - chan->pfh = NULL; - } -} - -static bool -tap_send(channel_t *chan, packet_t *pkt) -{ - struct iovec iov[4]; - ssize_t nw; - - iov[0].iov_base = pkt->dst; - iov[0].iov_len = ETHER_ADDR_LEN; - iov[1].iov_base = pkt->src; - iov[1].iov_len = ETHER_ADDR_LEN; - iov[2].iov_base = pkt->type; - iov[2].iov_len = ETHER_TYPE_LEN; - iov[3].iov_base = pkt->ptr; - iov[3].iov_len = pkt->len; - - /* tap device write never fails */ - nw = writev(chan->fd, iov, __arraycount(iov)); - assert(nw > 0); - - return true; -} - -static bool -tap_recv(packet_t *pkt) -{ - - if (pkt->len < ETHER_HDR_LEN) - return false; - - pkt->dst = pkt->ptr; - packet_adj(pkt, ETHER_ADDR_LEN); - pkt->src = pkt->ptr; - packet_adj(pkt, ETHER_ADDR_LEN); - pkt->type = pkt->ptr; - packet_adj(pkt, ETHER_TYPE_LEN); - - return true; -} diff --git a/usr.sbin/bluetooth/hccontrol/Makefile b/usr.sbin/bluetooth/hccontrol/Makefile deleted file mode 100644 index 592247e..0000000 --- a/usr.sbin/bluetooth/hccontrol/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $Id: Makefile,v 1.7 2003/08/14 20:06:17 max Exp $ -# $FreeBSD$ - -PROG= hccontrol -MAN= hccontrol.8 -SRCS= send_recv.c link_policy.c link_control.c \ - host_controller_baseband.c info.c status.c node.c hccontrol.c \ - util.c -WARNS?= 2 - -DPADD= ${LIBBLUETOOTH} -LDADD= -lbluetooth - -.include diff --git a/usr.sbin/bluetooth/hccontrol/hccontrol.8 b/usr.sbin/bluetooth/hccontrol/hccontrol.8 deleted file mode 100644 index b98a0fc..0000000 --- a/usr.sbin/bluetooth/hccontrol/hccontrol.8 +++ /dev/null @@ -1,184 +0,0 @@ -.\" Copyright (c) 2001-2002 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: hccontrol.8,v 1.6 2003/08/06 21:26:38 max Exp $ -.\" $FreeBSD$ -.\" -.Dd June 14, 2002 -.Dt HCCONTROL 8 -.Os -.Sh NAME -.Nm hccontrol -.Nd HCI configuration utility -.Sh SYNOPSIS -.Nm -.Op Fl hN -.Op Fl n Ar HCI_node_name -.Ar command -.Op Ar parameters ... -.Sh DESCRIPTION -The -.Nm -utility connects to the specified Netgraph node of type -.Dv HCI -or the first one found if none is specified and attempts to send the specified -command to the HCI Netgraph node or to the associated Bluetooth device. -The -.Nm -utility will print results to the standard output and error messages to -the standard error. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl h -Display usage message and exit. -.It Fl N -Show Bluetooth addresses as numbers. -Normally -.Nm -attempts to resolve Bluetooth addresses, and display them symbolically. -.It Fl n Ar HCI_node_name -Connect to the specified HCI Netgraph node. -.It Ar command -One of the supported commands (see below). -The special command -.Cm help -can be used to obtain the list of all supported commands. -To get more information about a specific command use -.Cm help Ar command . -.It Ar parameters -One or more optional space separated command parameters. -Many commands require a remote device address as one of the parameters. -The remote device address can be specified as BD_ADDR or a name. -If a name was specified then the -.Nm -utility will attempt to resolve the name via -.Xr bt_gethostbyname 3 . -.El -.Sh COMMANDS -The currently supported HCI commands in -.Nm -are: -.Pp -.Bl -tag -offset indent -compact -.It Cm Inquiry -.It Cm Create_Connection -.It Cm Disconnect -.It Cm Add_SCO_Connection -.It Cm Change_Connection_Packet_Type -.It Cm Remote_Name_Request -.It Cm Read_Remote_Supported_Features -.It Cm Read_Remote_Version_Information -.It Cm Read_Clock_Offset -.It Cm Role_Discovery -.It Cm Switch_Role -.It Cm Read_Link_Policy_Settings -.It Cm Write_Link_Policy_Settings -.It Cm Reset -.It Cm Read_Pin_Type -.It Cm Write_Pin_Type -.It Cm Read_Stored_Link_Key -.It Cm Write_Stored_Link_Key -.It Cm Delete_Stored_Link_Key -.It Cm Change_Local_Name -.It Cm Read_Local_Name -.It Cm Read_Connection_Accept_Timeout -.It Cm Write_Connection_Accept_Timeout -.It Cm Read_Page_Timeout -.It Cm Write_Page_Timeout -.It Cm Read_Scan_Enable -.It Cm Write_Scan_Enable -.It Cm Read_Page_Scan_Activity -.It Cm Write_Page_Scan_Activity -.It Cm Read_Inquiry_Scan_Activity -.It Cm Write_Inquiry_Scan_Activity -.It Cm Read_Authentication_Enable -.It Cm Write_Authentication_Enable -.It Cm Read_Encryption_Mode -.It Cm Write_Encryption_Mode -.It Cm Read_Class_Of_Device -.It Cm Write_Class_Of_Device -.It Cm Read_Voice_Settings -.It Cm Write_Voice_Settings -.It Cm Read_Number_Broadcast_Retransmissions -.It Cm Write_Number_Broadcast_Retransmissions -.It Cm Read_Hold_Mode_Activity -.It Cm Write_Hold_Mode_Activity -.It Cm Read_SCO_Flow_Control_Enable -.It Cm Write_SCO_Flow_Control_Enable -.It Cm Read_Link_Supervision_Timeout -.It Cm Write_Link_Supervision_Timeout -.It Cm Read_Page_Scan_Period_Mode -.It Cm Write_Page_Scan_Period_Mode -.It Cm Read_Page_Scan_Mode -.It Cm Write_Page_Scan_Mode -.It Cm Read_Local_Version_Information -.It Cm Read_Local_Supported_Features -.It Cm Read_Buffer_Size -.It Cm Read_Country_Code -.It Cm Read_BD_ADDR -.It Cm Read_Failed_Contact_Counter -.It Cm Reset_Failed_Contact_Counter -.It Cm Get_Link_Quality -.It Cm Read_RSSI -.El -.Pp -The currently supported node commands in -.Nm -are: -.Pp -.Bl -tag -offset indent -compact -.It Cm Read_Node_State -.It Cm Initialize -.It Cm Read_Debug_Level -.It Cm Write_Debug_Level -.It Cm Read_Node_Buffer_Size -.It Cm Read_Node_BD_ADDR -.It Cm Read_Node_Features -.It Cm Read_Node_Stat -.It Cm Reset_Node_Stat -.It Cm Flush_Neighbor_Cache -.It Cm Read_Neighbor_Cache -.It Cm Read_Connection_List -.It Cm Read_Node_Link_Policy_Settings_Mask -.It Cm Write_Node_Link_Policy_Settings_Mask -.It Cm Read_Node_Packet_Mask -.It Cm Write_Node_Packet_Mask -.It Cm Read_Node_Role_Switch -.It Cm Write_Node_Role_Switch -.It Cm Read_Node_List -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr bluetooth 3 , -.Xr netgraph 3 , -.Xr netgraph 4 , -.Xr ng_hci 4 , -.Xr hcseriald 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh BUGS -Most likely. -Please report if found. diff --git a/usr.sbin/bluetooth/hccontrol/hccontrol.c b/usr.sbin/bluetooth/hccontrol/hccontrol.c deleted file mode 100644 index 089869b..0000000 --- a/usr.sbin/bluetooth/hccontrol/hccontrol.c +++ /dev/null @@ -1,322 +0,0 @@ -/* - * hccontrol.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: hccontrol.c,v 1.5 2003/09/05 00:38:24 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "hccontrol.h" - -/* Prototypes */ -static int do_hci_command (char const *, int, char **); -static struct hci_command * find_hci_command (char const *, struct hci_command *); -static int find_hci_nodes (struct nodeinfo **); -static void print_hci_command (struct hci_command *); -static void usage (void); - -/* Globals */ -int verbose = 0; -int timeout; -int numeric_bdaddr = 0; - -/* Main */ -int -main(int argc, char *argv[]) -{ - char *node = NULL; - int n; - - /* Process command line arguments */ - while ((n = getopt(argc, argv, "n:Nvh")) != -1) { - switch (n) { - case 'n': - node = optarg; - break; - - case 'N': - numeric_bdaddr = 1; - break; - - case 'v': - verbose = 1; - break; - - case 'h': - default: - usage(); - } - } - - argc -= optind; - argv += optind; - - if (*argv == NULL) - usage(); - - n = do_hci_command(node, argc, argv); - - return (n); -} /* main */ - -/* Create socket and bind it */ -static int -socket_open(char const *node) -{ - struct sockaddr_hci addr; - struct ng_btsocket_hci_raw_filter filter; - int s, mib[4], num; - size_t size; - struct nodeinfo *nodes; - - num = find_hci_nodes(&nodes); - if (num == 0) - errx(7, "Could not find HCI nodes"); - - if (node == NULL) { - node = strdup(nodes[0].name); - if (num > 1) - fprintf(stdout, "Using HCI node: %s\n", node); - } - - free(nodes); - - s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI); - if (s < 0) - err(1, "Could not create socket"); - - memset(&addr, 0, sizeof(addr)); - addr.hci_len = sizeof(addr); - addr.hci_family = AF_BLUETOOTH; - strncpy(addr.hci_node, node, sizeof(addr.hci_node)); - if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) - err(2, "Could not bind socket, node=%s", node); - - if (connect(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) - err(3, "Could not connect socket, node=%s", node); - - memset(&filter, 0, sizeof(filter)); - bit_set(filter.event_mask, NG_HCI_EVENT_COMMAND_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_COMMAND_STATUS - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_INQUIRY_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_INQUIRY_RESULT - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_CON_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_DISCON_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_READ_REMOTE_FEATURES_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_READ_REMOTE_VER_INFO_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_RETURN_LINK_KEYS - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_READ_CLOCK_OFFSET_COMPL - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_CON_PKT_TYPE_CHANGED - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_ROLE_CHANGE - 1); - - if (setsockopt(s, SOL_HCI_RAW, SO_HCI_RAW_FILTER, - (void * const) &filter, sizeof(filter)) < 0) - err(4, "Could not setsockopt()"); - - size = (sizeof(mib)/sizeof(mib[0])); - if (sysctlnametomib("net.bluetooth.hci.command_timeout",mib,&size) < 0) - err(5, "Could not sysctlnametomib()"); - - if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), - (void *) &timeout, &size, NULL, 0) < 0) - err(6, "Could not sysctl()"); - - timeout ++; - - return (s); -} /* socket_open */ - -/* Execute commands */ -static int -do_hci_command(char const *node, int argc, char **argv) -{ - char *cmd = argv[0]; - struct hci_command *c = NULL; - int s, e, help; - - help = 0; - if (strcasecmp(cmd, "help") == 0) { - argc --; - argv ++; - - if (argc <= 0) { - fprintf(stdout, "Supported commands:\n"); - print_hci_command(link_control_commands); - print_hci_command(link_policy_commands); - print_hci_command(host_controller_baseband_commands); - print_hci_command(info_commands); - print_hci_command(status_commands); - print_hci_command(node_commands); - fprintf(stdout, "\nFor more information use " \ - "'help command'\n"); - - return (OK); - } - - help = 1; - cmd = argv[0]; - } - - c = find_hci_command(cmd, link_control_commands); - if (c != NULL) - goto execute; - - c = find_hci_command(cmd, link_policy_commands); - if (c != NULL) - goto execute; - - c = find_hci_command(cmd, host_controller_baseband_commands); - if (c != NULL) - goto execute; - - c = find_hci_command(cmd, info_commands); - if (c != NULL) - goto execute; - - c = find_hci_command(cmd, status_commands); - if (c != NULL) - goto execute; - - c = find_hci_command(cmd, node_commands); - if (c == NULL) { - fprintf(stdout, "Unknown command: \"%s\"\n", cmd); - return (ERROR); - } -execute: - if (!help) { - s = socket_open(node); - e = (c->handler)(s, -- argc, ++ argv); - close(s); - } else - e = USAGE; - - switch (e) { - case OK: - case FAILED: - break; - - case ERROR: - fprintf(stdout, "Could not execute command \"%s\". %s\n", - cmd, strerror(errno)); - break; - - case USAGE: - fprintf(stdout, "Usage: %s\n%s\n", c->command, c->description); - break; - - default: assert(0); break; - } - - - return (e); -} /* do_hci_command */ - -/* Try to find command in specified category */ -static struct hci_command * -find_hci_command(char const *command, struct hci_command *category) -{ - struct hci_command *c = NULL; - - for (c = category; c->command != NULL; c++) { - char *c_end = strchr(c->command, ' '); - - if (c_end != NULL) { - int len = c_end - c->command; - - if (strncasecmp(command, c->command, len) == 0) - return (c); - } else if (strcasecmp(command, c->command) == 0) - return (c); - } - - return (NULL); -} /* find_hci_command */ - -/* Find all HCI nodes */ -static int -find_hci_nodes(struct nodeinfo** nodes) -{ - struct ng_btsocket_hci_raw_node_list_names r; - struct sockaddr_hci addr; - int s; - const char * node = "ubt0hci"; - - r.num_names = MAX_NODE_NUM; - r.names = (struct nodeinfo*)calloc(MAX_NODE_NUM, sizeof(struct nodeinfo)); - if (r.names == NULL) - err(8, "Could not allocate memory"); - - s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI); - if (s < 0) - err(9, "Could not create socket"); - - memset(&addr, 0, sizeof(addr)); - addr.hci_len = sizeof(addr); - addr.hci_family = AF_BLUETOOTH; - strncpy(addr.hci_node, node, sizeof(addr.hci_node)); - if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) - err(10, "Could not bind socket"); - - if (ioctl(s, SIOC_HCI_RAW_NODE_LIST_NAMES, &r, sizeof(r)) < 0) - err(11, "Could not get list of HCI nodes"); - - close(s); - - *nodes = r.names; - - return (r.num_names); -} /* find_hci_nodes */ - -/* Print commands in specified category */ -static void -print_hci_command(struct hci_command *category) -{ - struct hci_command *c = NULL; - - for (c = category; c->command != NULL; c++) - fprintf(stdout, "\t%s\n", c->command); -} /* print_hci_command */ - -/* Usage */ -static void -usage(void) -{ - fprintf(stdout, "Usage: hccontrol [-hN] [-n HCI_node_name] cmd [p1] [..]\n"); - exit(255); -} /* usage */ - diff --git a/usr.sbin/bluetooth/hccontrol/hccontrol.h b/usr.sbin/bluetooth/hccontrol/hccontrol.h deleted file mode 100644 index cd56ebf..0000000 --- a/usr.sbin/bluetooth/hccontrol/hccontrol.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * hccontrol.h - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: hccontrol.h,v 1.2 2003/05/19 17:29:29 max Exp $ - * $FreeBSD$ - */ - -#ifndef _HCCONTROL_H_ -#define _HCCONTROL_H_ - -#define OK 0 /* everything was OK */ -#define ERROR 1 /* could not execute command */ -#define FAILED 2 /* error was reported */ -#define USAGE 3 /* invalid parameters */ - -#define MAX_NODE_NUM 16 /* max number of nodes */ - -struct hci_command { - char const *command; - char const *description; - int (*handler)(int, int, char **); -}; - -extern int timeout; -extern int verbose; -extern struct hci_command link_control_commands[]; -extern struct hci_command link_policy_commands[]; -extern struct hci_command host_controller_baseband_commands[]; -extern struct hci_command info_commands[]; -extern struct hci_command status_commands[]; -extern struct hci_command node_commands[]; - -int hci_request (int, int, char const *, int, char *, int *); -int hci_simple_request (int, int, char *, int *); -int hci_send (int, char const *, int); -int hci_recv (int, char *, int *); - -char const * hci_link2str (int); -char const * hci_pin2str (int); -char const * hci_scan2str (int); -char const * hci_encrypt2str (int, int); -char const * hci_coding2str (int); -char const * hci_vdata2str (int); -char const * hci_hmode2str (int, char *, int); -char const * hci_ver2str (int); -char const * hci_lmpver2str (int); -char const * hci_manufacturer2str(int); -char const * hci_features2str (uint8_t *, char *, int); -char const * hci_cc2str (int); -char const * hci_con_state2str (int); -char const * hci_status2str (int); -char const * hci_bdaddr2str (bdaddr_t const *); - -#endif /* _HCCONTROL_H_ */ - diff --git a/usr.sbin/bluetooth/hccontrol/host_controller_baseband.c b/usr.sbin/bluetooth/hccontrol/host_controller_baseband.c deleted file mode 100644 index 38f77eb..0000000 --- a/usr.sbin/bluetooth/hccontrol/host_controller_baseband.c +++ /dev/null @@ -1,1877 +0,0 @@ -/* - * host_controller_baseband.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: host_controller_baseband.c,v 1.4 2003/08/18 19:19:53 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "hccontrol.h" - -/* Convert hex ASCII to int4 */ -static int -hci_hexa2int4(const char *a) -{ - if ('0' <= *a && *a <= '9') - return (*a - '0'); - - if ('A' <= *a && *a <= 'F') - return (*a - 'A' + 0xa); - - if ('a' <= *a && *a <= 'f') - return (*a - 'a' + 0xa); - - return (-1); -} - -/* Convert hex ASCII to int8 */ -static int -hci_hexa2int8(const char *a) -{ - int hi = hci_hexa2int4(a); - int lo = hci_hexa2int4(a + 1); - - if (hi < 0 || lo < 0) - return (-1); - - return ((hi << 4) | lo); -} - -/* Convert ascii hex string to the uint8_t[] */ -static int -hci_hexstring2array(char const *s, uint8_t *a, int asize) -{ - int i, l, b; - - l = strlen(s) / 2; - if (l > asize) - l = asize; - - for (i = 0; i < l; i++) { - b = hci_hexa2int8(s + i * 2); - if (b < 0) - return (-1); - - a[i] = (b & 0xff); - } - - return (0); -} - -/* Send RESET to the unit */ -static int -hci_reset(int s, int argc, char **argv) -{ - ng_hci_status_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_RESET), (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_reset */ - -/* Send Read_PIN_Type command to the unit */ -static int -hci_read_pin_type(int s, int argc, char **argv) -{ - ng_hci_read_pin_type_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_PIN_TYPE), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "PIN type: %s [%#02x]\n", - hci_pin2str(rp.pin_type), rp.pin_type); - - return (OK); -} /* hci_read_pin_type */ - -/* Send Write_PIN_Type command to the unit */ -static int -hci_write_pin_type(int s, int argc, char **argv) -{ - ng_hci_write_pin_type_cp cp; - ng_hci_write_pin_type_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) - return (USAGE); - - cp.pin_type = (uint8_t) n; - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_PIN_TYPE), - (char const *) &cp, sizeof(cp), - (char *) &rp , &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_pin_type */ - -/* Send Read_Stored_Link_Key command to the unit */ -static int -hci_read_stored_link_key(int s, int argc, char **argv) -{ - struct { - ng_hci_cmd_pkt_t hdr; - ng_hci_read_stored_link_key_cp cp; - } __attribute__ ((packed)) cmd; - - struct { - ng_hci_event_pkt_t hdr; - union { - ng_hci_command_compl_ep cc; - ng_hci_return_link_keys_ep key; - uint8_t b[NG_HCI_EVENT_PKT_SIZE]; - } ep; - } __attribute__ ((packed)) event; - - int n, n1; - - /* Send command */ - memset(&cmd, 0, sizeof(cmd)); - cmd.hdr.type = NG_HCI_CMD_PKT; - cmd.hdr.opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_STORED_LINK_KEY)); - cmd.hdr.length = sizeof(cmd.cp); - - switch (argc) { - case 1: - /* parse BD_ADDR */ - if (!bt_aton(argv[0], &cmd.cp.bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(argv[0])) == NULL) - return (USAGE); - - memcpy(&cmd.cp.bdaddr, he->h_addr, sizeof(cmd.cp.bdaddr)); - } - break; - - default: - cmd.cp.read_all = 1; - break; - } - - if (hci_send(s, (char const *) &cmd, sizeof(cmd)) != OK) - return (ERROR); - - /* Receive events */ -again: - memset(&event, 0, sizeof(event)); - n = sizeof(event); - if (hci_recv(s, (char *) &event, &n) != OK) - return (ERROR); - - if (n <= sizeof(event.hdr)) { - errno = EMSGSIZE; - return (ERROR); - } - - if (event.hdr.type != NG_HCI_EVENT_PKT) { - errno = EIO; - return (ERROR); - } - - /* Parse event */ - switch (event.hdr.event) { - case NG_HCI_EVENT_COMMAND_COMPL: { - ng_hci_read_stored_link_key_rp *rp = NULL; - - if (event.ep.cc.opcode == 0x0000 || - event.ep.cc.opcode != cmd.hdr.opcode) - goto again; - - rp = (ng_hci_read_stored_link_key_rp *)(event.ep.b + - sizeof(event.ep.cc)); - - fprintf(stdout, "Complete: Status: %s [%#x]\n", - hci_status2str(rp->status), rp->status); - fprintf(stdout, "Maximum Number of keys: %d\n", - le16toh(rp->max_num_keys)); - fprintf(stdout, "Number of keys read: %d\n", - le16toh(rp->num_keys_read)); - } break; - - case NG_HCI_EVENT_RETURN_LINK_KEYS: { - struct _key { - bdaddr_t bdaddr; - uint8_t key[NG_HCI_KEY_SIZE]; - } __attribute__ ((packed)) *k = NULL; - - fprintf(stdout, "Event: Number of keys: %d\n", - event.ep.key.num_keys); - - k = (struct _key *)(event.ep.b + sizeof(event.ep.key)); - for (n = 0; n < event.ep.key.num_keys; n++) { - fprintf(stdout, "\t%d: %s ", - n + 1, hci_bdaddr2str(&k->bdaddr)); - - for (n1 = 0; n1 < sizeof(k->key); n1++) - fprintf(stdout, "%02x", k->key[n1]); - fprintf(stdout, "\n"); - - k ++; - } - - goto again; - - } break; - - default: - goto again; - } - - return (OK); -} /* hci_read_store_link_key */ - -/* Send Write_Stored_Link_Key command to the unit */ -static int -hci_write_stored_link_key(int s, int argc, char **argv) -{ - struct { - ng_hci_write_stored_link_key_cp p; - bdaddr_t bdaddr; - uint8_t key[NG_HCI_KEY_SIZE]; - } cp; - ng_hci_write_stored_link_key_rp rp; - int32_t n; - - memset(&cp, 0, sizeof(cp)); - - switch (argc) { - case 2: - cp.p.num_keys_write = 1; - - /* parse BD_ADDR */ - if (!bt_aton(argv[0], &cp.bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(argv[0])) == NULL) - return (USAGE); - - memcpy(&cp.bdaddr, he->h_addr, sizeof(cp.bdaddr)); - } - - /* parse key */ - if (hci_hexstring2array(argv[1], cp.key, sizeof(cp.key)) < 0) - return (USAGE); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_STORED_LINK_KEY), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Number of keys written: %d\n", rp.num_keys_written); - - return (OK); -} /* hci_write_stored_link_key */ - - -/* Send Delete_Stored_Link_Key command to the unit */ -static int -hci_delete_stored_link_key(int s, int argc, char **argv) -{ - ng_hci_delete_stored_link_key_cp cp; - ng_hci_delete_stored_link_key_rp rp; - int32_t n; - - memset(&cp, 0, sizeof(cp)); - - switch (argc) { - case 1: - /* parse BD_ADDR */ - if (!bt_aton(argv[0], &cp.bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(argv[0])) == NULL) - return (USAGE); - - memcpy(&cp.bdaddr, he->h_addr, sizeof(cp.bdaddr)); - } - break; - - default: - cp.delete_all = 1; - break; - } - - /* send command */ - n = sizeof(cp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_DELETE_STORED_LINK_KEY), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Number of keys deleted: %d\n", rp.num_keys_deleted); - - return (OK); -} /* hci_delete_stored_link_key */ - -/* Send Change_Local_Name command to the unit */ -static int -hci_change_local_name(int s, int argc, char **argv) -{ - ng_hci_change_local_name_cp cp; - ng_hci_change_local_name_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - snprintf(cp.name, sizeof(cp.name), "%s", argv[0]); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_CHANGE_LOCAL_NAME), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_change_local_name */ - -/* Send Read_Local_Name command to the unit */ -static int -hci_read_local_name(int s, int argc, char **argv) -{ - ng_hci_read_local_name_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_LOCAL_NAME), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Local name: %s\n", rp.name); - - return (OK); -} /* hci_read_local_name */ - -/* Send Read_Connection_Accept_Timeout to the unit */ -static int -hci_read_connection_accept_timeout(int s, int argc, char **argv) -{ - ng_hci_read_con_accept_timo_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_CON_ACCEPT_TIMO), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - rp.timeout = le16toh(rp.timeout); - fprintf(stdout, "Connection accept timeout: %.2f msec [%d slots]\n", - rp.timeout * 0.625, rp.timeout); - - return (OK); -} /* hci_read_connection_accept_timeout */ - -/* Send Write_Connection_Accept_Timeout to the unit */ -static int -hci_write_connection_accept_timeout(int s, int argc, char **argv) -{ - ng_hci_write_con_accept_timo_cp cp; - ng_hci_write_con_accept_timo_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 1 || n > 0xb540) - return (USAGE); - - cp.timeout = (uint16_t) n; - cp.timeout = htole16(cp.timeout); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_CON_ACCEPT_TIMO), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_connection_accept_timeout */ - -/* Send Read_Page_Timeout command to the unit */ -static int -hci_read_page_timeout(int s, int argc, char **argv) -{ - ng_hci_read_page_timo_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_PAGE_TIMO), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - rp.timeout = le16toh(rp.timeout); - fprintf(stdout, "Page timeout: %.2f msec [%d slots]\n", - rp.timeout * 0.625, rp.timeout); - - return (OK); -} /* hci_read_page_timeoout */ - -/* Send Write_Page_Timeout command to the unit */ -static int -hci_write_page_timeout(int s, int argc, char **argv) -{ - ng_hci_write_page_timo_cp cp; - ng_hci_write_page_timo_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 1 || n > 0xffff) - return (USAGE); - - cp.timeout = (uint16_t) n; - cp.timeout = htole16(cp.timeout); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_PAGE_TIMO), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_page_timeout */ - -/* Send Read_Scan_Enable command to the unit */ -static int -hci_read_scan_enable(int s, int argc, char **argv) -{ - ng_hci_read_scan_enable_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_SCAN_ENABLE), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Scan enable: %s [%#02x]\n", - hci_scan2str(rp.scan_enable), rp.scan_enable); - - return (OK); -} /* hci_read_scan_enable */ - -/* Send Write_Scan_Enable command to the unit */ -static int -hci_write_scan_enable(int s, int argc, char **argv) -{ - ng_hci_write_scan_enable_cp cp; - ng_hci_write_scan_enable_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 3) - return (USAGE); - - cp.scan_enable = (uint8_t) n; - break; - - default: - return (USAGE); - } - - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_SCAN_ENABLE), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_scan_enable */ - -/* Send Read_Page_Scan_Activity command to the unit */ -static int -hci_read_page_scan_activity(int s, int argc, char **argv) -{ - ng_hci_read_page_scan_activity_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_PAGE_SCAN_ACTIVITY), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - rp.page_scan_interval = le16toh(rp.page_scan_interval); - rp.page_scan_window = le16toh(rp.page_scan_window); - - fprintf(stdout, "Page Scan Interval: %.2f msec [%d slots]\n", - rp.page_scan_interval * 0.625, rp.page_scan_interval); - fprintf(stdout, "Page Scan Window: %.2f msec [%d slots]\n", - rp.page_scan_window * 0.625, rp.page_scan_window); - - return (OK); -} /* hci_read_page_scan_activity */ - -/* Send Write_Page_Scan_Activity command to the unit */ -static int -hci_write_page_scan_activity(int s, int argc, char **argv) -{ - ng_hci_write_page_scan_activity_cp cp; - ng_hci_write_page_scan_activity_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 2: - /* page scan interval */ - if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) - return (USAGE); - - cp.page_scan_interval = (uint16_t) n; - - /* page scan window */ - if (sscanf(argv[1], "%d", &n) != 1 || n < 0x12 || n > 0x1000) - return (USAGE); - - cp.page_scan_window = (uint16_t) n; - - if (cp.page_scan_window > cp.page_scan_interval) - return (USAGE); - - cp.page_scan_interval = htole16(cp.page_scan_interval); - cp.page_scan_window = htole16(cp.page_scan_window); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_PAGE_SCAN_ACTIVITY), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_page_scan_activity */ - -/* Send Read_Inquiry_Scan_Activity command to the unit */ -static int -hci_read_inquiry_scan_activity(int s, int argc, char **argv) -{ - ng_hci_read_inquiry_scan_activity_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_INQUIRY_SCAN_ACTIVITY), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - rp.inquiry_scan_interval = le16toh(rp.inquiry_scan_interval); - rp.inquiry_scan_window = le16toh(rp.inquiry_scan_window); - - fprintf(stdout, "Inquiry Scan Interval: %.2f msec [%d slots]\n", - rp.inquiry_scan_interval * 0.625, rp.inquiry_scan_interval); - fprintf(stdout, "Inquiry Scan Window: %.2f msec [%d slots]\n", - rp.inquiry_scan_window * 0.625, rp.inquiry_scan_interval); - - return (OK); -} /* hci_read_inquiry_scan_activity */ - -/* Send Write_Inquiry_Scan_Activity command to the unit */ -static int -hci_write_inquiry_scan_activity(int s, int argc, char **argv) -{ - ng_hci_write_inquiry_scan_activity_cp cp; - ng_hci_write_inquiry_scan_activity_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 2: - /* inquiry scan interval */ - if (sscanf(argv[0], "%d", &n) != 1 || n < 0x12 || n > 0x1000) - return (USAGE); - - cp.inquiry_scan_interval = (uint16_t) n; - - /* inquiry scan window */ - if (sscanf(argv[1], "%d", &n) != 1 || n < 0x12 || n > 0x1000) - return (USAGE); - - cp.inquiry_scan_window = (uint16_t) n; - - if (cp.inquiry_scan_window > cp.inquiry_scan_interval) - return (USAGE); - - cp.inquiry_scan_interval = - htole16(cp.inquiry_scan_interval); - cp.inquiry_scan_window = htole16(cp.inquiry_scan_window); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_INQUIRY_SCAN_ACTIVITY), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_inquiry_scan_activity */ - -/* Send Read_Authentication_Enable command to the unit */ -static int -hci_read_authentication_enable(int s, int argc, char **argv) -{ - ng_hci_read_auth_enable_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_AUTH_ENABLE), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Authentication Enable: %s [%d]\n", - rp.auth_enable? "Enabled" : "Disabled", rp.auth_enable); - - return (OK); -} /* hci_read_authentication_enable */ - -/* Send Write_Authentication_Enable command to the unit */ -static int -hci_write_authentication_enable(int s, int argc, char **argv) -{ - ng_hci_write_auth_enable_cp cp; - ng_hci_write_auth_enable_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) - return (USAGE); - - cp.auth_enable = (uint8_t) n; - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_AUTH_ENABLE), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_authentication_enable */ - -/* Send Read_Encryption_Mode command to the unit */ -static int -hci_read_encryption_mode(int s, int argc, char **argv) -{ - ng_hci_read_encryption_mode_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_ENCRYPTION_MODE), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Encryption mode: %s [%#02x]\n", - hci_encrypt2str(rp.encryption_mode, 0), rp.encryption_mode); - - return (OK); -} /* hci_read_encryption_mode */ - -/* Send Write_Encryption_Mode command to the unit */ -static int -hci_write_encryption_mode(int s, int argc, char **argv) -{ - ng_hci_write_encryption_mode_cp cp; - ng_hci_write_encryption_mode_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 2) - return (USAGE); - - cp.encryption_mode = (uint8_t) n; - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_ENCRYPTION_MODE), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_encryption_mode */ - -/* Send Read_Class_Of_Device command to the unit */ -static int -hci_read_class_of_device(int s, int argc, char **argv) -{ - ng_hci_read_unit_class_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_UNIT_CLASS), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Class: %02x:%02x:%02x\n", - rp.uclass[2], rp.uclass[1], rp.uclass[0]); - - return (0); -} /* hci_read_class_of_device */ - -/* Send Write_Class_Of_Device command to the unit */ -static int -hci_write_class_of_device(int s, int argc, char **argv) -{ - ng_hci_write_unit_class_cp cp; - ng_hci_write_unit_class_rp rp; - int n0, n1, n2; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%x:%x:%x", &n2, &n1, &n0) != 3) - return (USAGE); - - cp.uclass[0] = (n0 & 0xff); - cp.uclass[1] = (n1 & 0xff); - cp.uclass[2] = (n2 & 0xff); - break; - - default: - return (USAGE); - } - - /* send command */ - n0 = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_UNIT_CLASS), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n0) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_class_of_device */ - -/* Send Read_Voice_Settings command to the unit */ -static int -hci_read_voice_settings(int s, int argc, char **argv) -{ - ng_hci_read_voice_settings_rp rp; - int n, - input_coding, - input_data_format, - input_sample_size; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_VOICE_SETTINGS), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - rp.settings = le16toh(rp.settings); - - input_coding = (rp.settings & 0x0300) >> 8; - input_data_format = (rp.settings & 0x00c0) >> 6; - input_sample_size = (rp.settings & 0x0020) >> 5; - - fprintf(stdout, "Voice settings: %#04x\n", rp.settings); - fprintf(stdout, "Input coding: %s [%d]\n", - hci_coding2str(input_coding), input_coding); - fprintf(stdout, "Input data format: %s [%d]\n", - hci_vdata2str(input_data_format), input_data_format); - - if (input_coding == 0x00) /* Only for Linear PCM */ - fprintf(stdout, "Input sample size: %d bit [%d]\n", - input_sample_size? 16 : 8, input_sample_size); - - return (OK); -} /* hci_read_voice_settings */ - -/* Send Write_Voice_Settings command to the unit */ -static int -hci_write_voice_settings(int s, int argc, char **argv) -{ - ng_hci_write_voice_settings_cp cp; - ng_hci_write_voice_settings_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%x", &n) != 1) - return (USAGE); - - cp.settings = (uint16_t) n; - cp.settings = htole16(cp.settings); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_VOICE_SETTINGS), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_voice_settings */ - -/* Send Read_Number_Broadcast_Restransmissions */ -static int -hci_read_number_broadcast_retransmissions(int s, int argc, char **argv) -{ - ng_hci_read_num_broadcast_retrans_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_NUM_BROADCAST_RETRANS), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Number of broadcast retransmissions: %d\n", - rp.counter); - - return (OK); -} /* hci_read_number_broadcast_retransmissions */ - -/* Send Write_Number_Broadcast_Restransmissions */ -static int -hci_write_number_broadcast_retransmissions(int s, int argc, char **argv) -{ - ng_hci_write_num_broadcast_retrans_cp cp; - ng_hci_write_num_broadcast_retrans_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 0xff) - return (USAGE); - - cp.counter = (uint8_t) n; - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_NUM_BROADCAST_RETRANS), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_number_broadcast_retransmissions */ - -/* Send Read_Hold_Mode_Activity command to the unit */ -static int -hci_read_hold_mode_activity(int s, int argc, char **argv) -{ - ng_hci_read_hold_mode_activity_rp rp; - int n; - char buffer[1024]; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_HOLD_MODE_ACTIVITY), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Hold Mode Activities: %#02x\n", rp.hold_mode_activity); - if (rp.hold_mode_activity == 0) - fprintf(stdout, "Maintain current Power State"); - else - fprintf(stdout, "%s", hci_hmode2str(rp.hold_mode_activity, - buffer, sizeof(buffer))); - - fprintf(stdout, "\n"); - - return (OK); -} /* hci_read_hold_mode_activity */ - -/* Send Write_Hold_Mode_Activity command to the unit */ -static int -hci_write_hold_mode_activity(int s, int argc, char **argv) -{ - ng_hci_write_hold_mode_activity_cp cp; - ng_hci_write_hold_mode_activity_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 4) - return (USAGE); - - cp.hold_mode_activity = (uint8_t) n; - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_HOLD_MODE_ACTIVITY), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_hold_mode_activity */ - -/* Send Read_SCO_Flow_Control_Enable command to the unit */ -static int -hci_read_sco_flow_control_enable(int s, int argc, char **argv) -{ - ng_hci_read_sco_flow_control_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_SCO_FLOW_CONTROL), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "SCO flow control %s [%d]\n", - rp.flow_control? "enabled" : "disabled", rp.flow_control); - - return (OK); -} /* hci_read_sco_flow_control_enable */ - -/* Send Write_SCO_Flow_Control_Enable command to the unit */ -static int -hci_write_sco_flow_control_enable(int s, int argc, char **argv) -{ - ng_hci_write_sco_flow_control_cp cp; - ng_hci_write_sco_flow_control_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 1) - return (USAGE); - - cp.flow_control = (uint8_t) n; - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_SCO_FLOW_CONTROL), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_sco_flow_control_enable */ - -/* Send Read_Link_Supervision_Timeout command to the unit */ -static int -hci_read_link_supervision_timeout(int s, int argc, char **argv) -{ - ng_hci_read_link_supervision_timo_cp cp; - ng_hci_read_link_supervision_timo_rp rp; - int n; - - switch (argc) { - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_LINK_SUPERVISION_TIMO), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - rp.timeout = le16toh(rp.timeout); - - fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle)); - fprintf(stdout, "Link supervision timeout: %.2f msec [%d slots]\n", - rp.timeout * 0.625, rp.timeout); - - return (OK); -} /* hci_read_link_supervision_timeout */ - -/* Send Write_Link_Supervision_Timeout command to the unit */ -static int -hci_write_link_supervision_timeout(int s, int argc, char **argv) -{ - ng_hci_write_link_supervision_timo_cp cp; - ng_hci_write_link_supervision_timo_rp rp; - int n; - - switch (argc) { - case 2: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - - /* link supervision timeout */ - if (sscanf(argv[1], "%d", &n) != 1 || n < 0 || n > 0xffff) - return (USAGE); - - cp.timeout = (uint16_t) (n & 0x0fff); - cp.timeout = htole16(cp.timeout); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_LINK_SUPERVISION_TIMO), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_link_supervision_timeout */ - -/* Send Read_Page_Scan_Period_Mode command to the unit */ -static int -hci_read_page_scan_period_mode(int s, int argc, char **argv) -{ - ng_hci_read_page_scan_period_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_PAGE_SCAN_PERIOD), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Page scan period mode: %#02x\n", - rp.page_scan_period_mode); - - return (OK); -} /* hci_read_page_scan_period_mode */ - -/* Send Write_Page_Scan_Period_Mode command to the unit */ -static int -hci_write_page_scan_period_mode(int s, int argc, char **argv) -{ - ng_hci_write_page_scan_period_cp cp; - ng_hci_write_page_scan_period_rp rp; - int n; - - /* parse command arguments */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 2) - return (USAGE); - - cp.page_scan_period_mode = (n & 0xff); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_PAGE_SCAN_PERIOD), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_page_scan_period_mode */ - -/* Send Read_Page_Scan_Mode command to the unit */ -static int -hci_read_page_scan_mode(int s, int argc, char **argv) -{ - ng_hci_read_page_scan_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_READ_PAGE_SCAN), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Page scan mode: %#02x\n", rp.page_scan_mode); - - return (OK); -} /* hci_read_page_scan_mode */ - -/* Send Write_Page_Scan_Mode command to the unit */ -static int -hci_write_page_scan_mode(int s, int argc, char **argv) -{ - ng_hci_write_page_scan_cp cp; - ng_hci_write_page_scan_rp rp; - int n; - - /* parse command arguments */ - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 3) - return (USAGE); - - cp.page_scan_mode = (n & 0xff); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_HC_BASEBAND, - NG_HCI_OCF_WRITE_PAGE_SCAN), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_page_scan_mode */ - -struct hci_command host_controller_baseband_commands[] = { -{ -"reset", -"\nThe Reset command will reset the Host Controller and the Link Manager.\n" \ -"After the reset is completed, the current operational state will be lost,\n" \ -"the Bluetooth unit will enter standby mode and the Host Controller will\n" \ -"automatically revert to the default values for the parameters for which\n" \ -"default values are defined in the specification.", -&hci_reset -}, -{ -"read_pin_type", -"\nThe Read_PIN_Type command is used for the Host to read whether the Link\n" \ -"Manager assumes that the Host supports variable PIN codes only a fixed PIN\n" \ -"code.", -&hci_read_pin_type -}, -{ -"write_pin_type ", -"\nThe Write_PIN_Type command is used for the Host to write to the Host\n" \ -"Controller whether the Host supports variable PIN codes or only a fixed PIN\n"\ -"code.\n\n" \ -"\t - dd; 0 - Variable; 1 - Fixed", -&hci_write_pin_type -}, -{ -"read_stored_link_key []", -"\nThe Read_Stored_Link_Key command provides the ability to read one or\n" \ -"more link keys stored in the Bluetooth Host Controller. The Bluetooth Host\n" \ -"Controller can store a limited number of link keys for other Bluetooth\n" \ -"devices.\n\n" \ -"\t - xx:xx:xx:xx:xx:xx BD_ADDR or name", -&hci_read_stored_link_key -}, -{ -"write_stored_link_key ", -"\nThe Write_Stored_Link_Key command provides the ability to write one\n" \ -"or more link keys to be stored in the Bluetooth Host Controller. The\n" \ -"Bluetooth Host Controller can store a limited number of link keys for other\n"\ -"Bluetooth devices. If no additional space is available in the Bluetooth\n"\ -"Host Controller then no additional link keys will be stored.\n\n" \ -"\t - xx:xx:xx:xx:xx:xx BD_ADDR or name\n" \ -"\t - xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx up to 16 bytes link key", -&hci_write_stored_link_key -}, -{ -"delete_stored_link_key []", -"\nThe Delete_Stored_Link_Key command provides the ability to remove one\n" \ -"or more of the link keys stored in the Bluetooth Host Controller. The\n" \ -"Bluetooth Host Controller can store a limited number of link keys for other\n"\ -"Bluetooth devices.\n\n" \ -"\t - xx:xx:xx:xx:xx:xx BD_ADDR or name", -&hci_delete_stored_link_key -}, -{ -"change_local_name ", -"\nThe Change_Local_Name command provides the ability to modify the user\n" \ -"friendly name for the Bluetooth unit.\n\n" \ -"\t - string", -&hci_change_local_name -}, -{ -"read_local_name", -"\nThe Read_Local_Name command provides the ability to read the\n" \ -"stored user-friendly name for the Bluetooth unit.", -&hci_read_local_name -}, -{ -"read_connection_accept_timeout", -"\nThis command will read the value for the Connection_Accept_Timeout\n" \ -"configuration parameter. The Connection_Accept_Timeout configuration\n" \ -"parameter allows the Bluetooth hardware to automatically deny a\n" \ -"connection request after a specified time period has occurred and\n" \ -"the new connection is not accepted. Connection Accept Timeout\n" \ -"measured in Number of Baseband slots.", -&hci_read_connection_accept_timeout -}, -{ -"write_connection_accept_timeout ", -"\nThis command will write the value for the Connection_Accept_Timeout\n" \ -"configuration parameter.\n\n" \ -"\t - dddd; measured in number of baseband slots.", -&hci_write_connection_accept_timeout -}, -{ -"read_page_timeout", -"\nThis command will read the value for the Page_Timeout configuration\n" \ -"parameter. The Page_Timeout configuration parameter defines the\n" \ -"maximum time the local Link Manager will wait for a baseband page\n" \ -"response from the remote unit at a locally initiated connection\n" \ -"attempt. Page Timeout measured in Number of Baseband slots.", -&hci_read_page_timeout -}, -{ -"write_page_timeout ", -"\nThis command will write the value for the Page_Timeout configuration\n" \ -"parameter.\n\n" \ -"\t - dddd; measured in number of baseband slots.", -&hci_write_page_timeout -}, -{ -"read_scan_enable", -"\nThis command will read the value for the Scan_Enable parameter. The\n" \ -"Scan_Enable parameter controls whether or not the Bluetooth uint\n" \ -"will periodically scan for page attempts and/or inquiry requests\n" \ -"from other Bluetooth unit.\n\n" \ -"\t0x00 - No Scans enabled.\n" \ -"\t0x01 - Inquiry Scan enabled. Page Scan disabled.\n" \ -"\t0x02 - Inquiry Scan disabled. Page Scan enabled.\n" \ -"\t0x03 - Inquiry Scan enabled. Page Scan enabled.", -&hci_read_scan_enable -}, -{ -"write_scan_enable ", -"\nThis command will write the value for the Scan_Enable parameter.\n" \ -"The Scan_Enable parameter controls whether or not the Bluetooth\n" \ -"unit will periodically scan for page attempts and/or inquiry\n" \ -"requests from other Bluetooth unit.\n\n" \ -"\t - dd;\n" \ -"\t0 - No Scans enabled.\n" \ -"\t1 - Inquiry Scan enabled. Page Scan disabled.\n" \ -"\t2 - Inquiry Scan disabled. Page Scan enabled.\n" \ -"\t3 - Inquiry Scan enabled. Page Scan enabled.", -&hci_write_scan_enable -}, -{ -"read_page_scan_activity", -"\nThis command will read the value for Page_Scan_Activity configuration\n" \ -"parameters. The Page_Scan_Interval configuration parameter defines the\n" \ -"amount of time between consecutive page scans. This time interval is \n" \ -"defined from when the Host Controller started its last page scan until\n" \ -"it begins the next page scan. The Page_Scan_Window configuration parameter\n" \ -"defines the amount of time for the duration of the page scan. The\n" \ -"Page_Scan_Window can only be less than or equal to the Page_Scan_Interval.", -&hci_read_page_scan_activity -}, -{ -"write_page_scan_activity interval(dddd) window(dddd)", -"\nThis command will write the value for Page_Scan_Activity configuration\n" \ -"parameter. The Page_Scan_Interval configuration parameter defines the\n" \ -"amount of time between consecutive page scans. This is defined as the time\n" \ -"interval from when the Host Controller started its last page scan until it\n" \ -"begins the next page scan. The Page_Scan_Window configuration parameter\n" \ -"defines the amount of time for the duration of the page scan. \n" \ -"The Page_Scan_Window can only be less than or equal to the Page_Scan_Interval.\n\n" \ -"\t - Range: 0x0012 -– 0x100, Time = N * 0.625 msec\n" \ -"\t - Range: 0x0012 -– 0x100, Time = N * 0.625 msen", -&hci_write_page_scan_activity -}, -{ -"read_inquiry_scan_activity", -"\nThis command will read the value for Inquiry_Scan_Activity configuration\n" \ -"parameter. The Inquiry_Scan_Interval configuration parameter defines the\n" \ -"amount of time between consecutive inquiry scans. This is defined as the\n" \ -"time interval from when the Host Controller started its last inquiry scan\n" \ -"until it begins the next inquiry scan.", -&hci_read_inquiry_scan_activity -}, -{ -"write_inquiry_scan_activity interval(dddd) window(dddd)", -"\nThis command will write the value for Inquiry_Scan_Activity configuration\n"\ -"parameter. The Inquiry_Scan_Interval configuration parameter defines the\n" \ -"amount of time between consecutive inquiry scans. This is defined as the\n" \ -"time interval from when the Host Controller started its last inquiry scan\n" \ -"until it begins the next inquiry scan. The Inquiry_Scan_Window configuration\n" \ -"parameter defines the amount of time for the duration of the inquiry scan.\n" \ -"The Inquiry_Scan_Window can only be less than or equal to the Inquiry_Scan_Interval.\n\n" \ -"\t - Range: 0x0012 -– 0x100, Time = N * 0.625 msec\n" \ -"\t - Range: 0x0012 -– 0x100, Time = N * 0.625 msen", -&hci_write_inquiry_scan_activity -}, -{ -"read_authentication_enable", -"\nThis command will read the value for the Authentication_Enable parameter.\n"\ -"The Authentication_Enable parameter controls if the local unit requires\n"\ -"to authenticate the remote unit at connection setup (between the\n" \ -"Create_Connection command or acceptance of an incoming ACL connection\n"\ -"and the corresponding Connection Complete event). At connection setup, only\n"\ -"the unit(s) with the Authentication_Enable parameter enabled will try to\n"\ -"authenticate the other unit.", -&hci_read_authentication_enable -}, -{ -"write_authentication_enable enable(0|1)", -"\nThis command will write the value for the Authentication_Enable parameter.\n"\ -"The Authentication_Enable parameter controls if the local unit requires to\n"\ -"authenticate the remote unit at connection setup (between the\n" \ -"Create_Connection command or acceptance of an incoming ACL connection\n" \ -"and the corresponding Connection Complete event). At connection setup, only\n"\ -"the unit(s) with the Authentication_Enable parameter enabled will try to\n"\ -"authenticate the other unit.", -&hci_write_authentication_enable -}, -{ -"read_encryption_mode", -"\nThis command will read the value for the Encryption_Mode parameter. The\n" \ -"Encryption_Mode parameter controls if the local unit requires encryption\n" \ -"to the remote unit at connection setup (between the Create_Connection\n" \ -"command or acceptance of an incoming ACL connection and the corresponding\n" \ -"Connection Complete event). At connection setup, only the unit(s) with\n" \ -"the Authentication_Enable parameter enabled and Encryption_Mode parameter\n" \ -"enabled will try to encrypt the connection to the other unit.\n\n" \ -"\t:\n" \ -"\t0x00 - Encryption disabled.\n" \ -"\t0x01 - Encryption only for point-to-point packets.\n" \ -"\t0x02 - Encryption for both point-to-point and broadcast packets.", -&hci_read_encryption_mode -}, -{ -"write_encryption_mode mode(0|1|2)", -"\tThis command will write the value for the Encryption_Mode parameter.\n" \ -"The Encryption_Mode parameter controls if the local unit requires\n" \ -"encryption to the remote unit at connection setup (between the\n" \ -"Create_Connection command or acceptance of an incoming ACL connection\n" \ -"and the corresponding Connection Complete event). At connection setup,\n" \ -"only the unit(s) with the Authentication_Enable parameter enabled and\n" \ -"Encryption_Mode parameter enabled will try to encrypt the connection to\n" \ -"the other unit.\n\n" \ -"\t (dd)\n" \ -"\t0 - Encryption disabled.\n" \ -"\t1 - Encryption only for point-to-point packets.\n" \ -"\t2 - Encryption for both point-to-point and broadcast packets.", -&hci_write_encryption_mode -}, -{ -"read_class_of_device", -"\nThis command will read the value for the Class_of_Device parameter.\n" \ -"The Class_of_Device parameter is used to indicate the capabilities of\n" \ -"the local unit to other units.", -&hci_read_class_of_device -}, -{ -"write_class_of_device class(xx:xx:xx)", -"\nThis command will write the value for the Class_of_Device parameter.\n" \ -"The Class_of_Device parameter is used to indicate the capabilities of \n" \ -"the local unit to other units.\n\n" \ -"\t (xx:xx:xx) - class of device", -&hci_write_class_of_device -}, -{ -"read_voice_settings", -"\nThis command will read the values for the Voice_Setting parameter.\n" \ -"The Voice_Setting parameter controls all the various settings for voice\n" \ -"connections. These settings apply to all voice connections, and cannot be\n" \ -"set for individual voice connections. The Voice_Setting parameter controls\n" \ -"the configuration for voice connections: Input Coding, Air coding format,\n" \ -"input data format, Input sample size, and linear PCM parameter.", -&hci_read_voice_settings -}, -{ -"write_voice_settings settings(xxxx)", -"\nThis command will write the values for the Voice_Setting parameter.\n" \ -"The Voice_Setting parameter controls all the various settings for voice\n" \ -"connections. These settings apply to all voice connections, and cannot be\n" \ -"set for individual voice connections. The Voice_Setting parameter controls\n" \ -"the configuration for voice connections: Input Coding, Air coding format,\n" \ -"input data format, Input sample size, and linear PCM parameter.\n\n" \ -"\t (xxxx) - voice settings", -&hci_write_voice_settings -}, -{ -"read_number_broadcast_retransmissions", -"\nThis command will read the unit's parameter value for the Number of\n" \ -"Broadcast Retransmissions. Broadcast packets are not acknowledged and are\n" \ -"unreliable.", -&hci_read_number_broadcast_retransmissions -}, -{ -"write_number_broadcast_retransmissions count(dd)", -"\nThis command will write the unit's parameter value for the Number of\n" \ -"Broadcast Retransmissions. Broadcast packets are not acknowledged and are\n" \ -"unreliable.\n\n" \ -"\t (dd) - number of broadcast retransimissions", -&hci_write_number_broadcast_retransmissions -}, -{ -"read_hold_mode_activity", -"\nThis command will read the value for the Hold_Mode_Activity parameter.\n" \ -"The Hold_Mode_Activity value is used to determine what activities should\n" \ -"be suspended when the unit is in hold mode.", -&hci_read_hold_mode_activity -}, -{ -"write_hold_mode_activity settings(0|1|2|4)", -"\nThis command will write the value for the Hold_Mode_Activity parameter.\n" \ -"The Hold_Mode_Activity value is used to determine what activities should\n" \ -"be suspended when the unit is in hold mode.\n\n" \ -"\t (dd) - bit mask:\n" \ -"\t0 - Maintain current Power State. Default\n" \ -"\t1 - Suspend Page Scan.\n" \ -"\t2 - Suspend Inquiry Scan.\n" \ -"\t4 - Suspend Periodic Inquiries.", -&hci_write_hold_mode_activity -}, -{ -"read_sco_flow_control_enable", -"\nThe Read_SCO_Flow_Control_Enable command provides the ability to read\n" \ -"the SCO_Flow_Control_Enable setting. By using this setting, the Host can\n" \ -"decide if the Host Controller will send Number Of Completed Packets events\n" \ -"for SCO Connection Handles. This setting allows the Host to enable and\n" \ -"disable SCO flow control.", -&hci_read_sco_flow_control_enable -}, -{ -"write_sco_flow_control_enable enable(0|1)", -"\nThe Write_SCO_Flow_Control_Enable command provides the ability to write\n" \ -"the SCO_Flow_Control_Enable setting. By using this setting, the Host can\n" \ -"decide if the Host Controller will send Number Of Completed Packets events\n" \ -"for SCO Connection Handles. This setting allows the Host to enable and\n" \ -"disable SCO flow control. The SCO_Flow_Control_Enable setting can only be\n" \ -"changed if no connections exist.", -&hci_write_sco_flow_control_enable -}, -{ -"read_link_supervision_timeout ", -"\nThis command will read the value for the Link_Supervision_Timeout\n" \ -"parameter for the device. The Link_Supervision_Timeout parameter is used\n" \ -"by the master or slave Bluetooth device to monitor link loss. If, for any\n" \ -"reason, no Baseband packets are received from that Connection Handle for a\n" \ -"duration longer than the Link_Supervision_Timeout, the connection is\n" -"disconnected.\n\n" \ -"\t - dddd; connection handle\n", -&hci_read_link_supervision_timeout -}, -{ -"write_link_supervision_timeout ", -"\nThis command will write the value for the Link_Supervision_Timeout\n" \ -"parameter for the device. The Link_Supervision_Timeout parameter is used\n" \ -"by the master or slave Bluetooth device to monitor link loss. If, for any\n" \ -"reason, no Baseband packets are received from that connection handle for a\n" \ -"duration longer than the Link_Supervision_Timeout, the connection is\n" \ -"disconnected.\n\n" \ -"\t - dddd; connection handle\n" \ -"\t - dddd; timeout measured in number of baseband slots\n", -&hci_write_link_supervision_timeout -}, -{ -"read_page_scan_period_mode", -"\nThis command is used to read the mandatory Page_Scan_Period_Mode of the\n" \ -"local Bluetooth device. Every time an inquiry response message is sent, the\n"\ -"Bluetooth device will start a timer (T_mandatory_pscan), the value of which\n"\ -"is dependent on the Page_Scan_Period_Mode. As long as this timer has not\n" \ -"expired, the Bluetooth device will use the Page_Scan_Period_Mode for all\n" \ -"following page scans.", -&hci_read_page_scan_period_mode -}, -{ -"write_page_scan_period_mode ", -"\nThis command is used to write the mandatory Page_Scan_Period_Mode of the\n" \ -"local Bluetooth device. Every time an inquiry response message is sent, the\n"\ -"Bluetooth device will start a timer (T_mandatory_pscan), the value of which\n"\ -"is dependent on the Page_Scan_Period_Mode. As long as this timer has not\n" \ -"expired, the Bluetooth device will use the Page_Scan_Period_Mode for all\n" \ -"following page scans.\n\n" \ -"\t - dd; page scan period mode:\n" \ -"\t0x00 - P0 (Default)\n" \ -"\t0x01 - P1\n" \ -"\t0x02 - P2", -&hci_write_page_scan_period_mode -}, -{ -"read_page_scan_mode", -"\nThis command is used to read the default page scan mode of the local\n" \ -"Bluetooth device. The Page_Scan_Mode parameter indicates the page scan mode\n"\ -"that is used for the default page scan. Currently one mandatory page scan\n"\ -"mode and three optional page scan modes are defined. Following an inquiry\n" \ -"response, if the Baseband timer T_mandatory_pscan has not expired, the\n" \ -"mandatory page scan mode must be applied.", -&hci_read_page_scan_mode -}, -{ -"write_page_scan_mode ", -"\nThis command is used to write the default page scan mode of the local\n" \ -"Bluetooth device. The Page_Scan_Mode parameter indicates the page scan mode\n"\ -"that is used for the default page scan. Currently, one mandatory page scan\n"\ -"mode and three optional page scan modes are defined. Following an inquiry\n"\ -"response, if the Baseband timer T_mandatory_pscan has not expired, the\n" \ -"mandatory page scan mode must be applied.\n\n" \ -"\t - dd; page scan mode:\n" \ -"\t0x00 - Mandatory Page Scan Mode (Default)\n" \ -"\t0x01 - Optional Page Scan Mode I\n" \ -"\t0x02 - Optional Page Scan Mode II\n" \ -"\t0x03 - Optional Page Scan Mode III", -&hci_write_page_scan_mode -}, -{ NULL, } -}; - diff --git a/usr.sbin/bluetooth/hccontrol/info.c b/usr.sbin/bluetooth/hccontrol/info.c deleted file mode 100644 index d7bad36..0000000 --- a/usr.sbin/bluetooth/hccontrol/info.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * info.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: info.c,v 1.3 2003/08/18 19:19:54 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "hccontrol.h" - -/* Send Read_Local_Version_Information command to the unit */ -static int -hci_read_local_version_information(int s, int argc, char **argv) -{ - ng_hci_read_local_ver_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO, - NG_HCI_OCF_READ_LOCAL_VER), (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - rp.manufacturer = le16toh(rp.manufacturer); - - fprintf(stdout, "HCI version: %s [%#02x]\n", - hci_ver2str(rp.hci_version), rp.hci_version); - fprintf(stdout, "HCI revision: %#04x\n", - le16toh(rp.hci_revision)); - fprintf(stdout, "LMP version: %s [%#02x]\n", - hci_lmpver2str(rp.lmp_version), rp.lmp_version); - fprintf(stdout, "LMP sub-version: %#04x\n", - le16toh(rp.lmp_subversion)); - fprintf(stdout, "Manufacturer: %s [%#04x]\n", - hci_manufacturer2str(rp.manufacturer), rp.manufacturer); - - return (OK); -} /* hci_read_local_version_information */ - -/* Send Read_Local_Supported_Features command to the unit */ -static int -hci_read_local_supported_features(int s, int argc, char **argv) -{ - ng_hci_read_local_features_rp rp; - int n; - char buffer[1024]; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO, - NG_HCI_OCF_READ_LOCAL_FEATURES), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Features: "); - for (n = 0; n < sizeof(rp.features); n++) - fprintf(stdout, "%#02x ", rp.features[n]); - fprintf(stdout, "\n%s\n", hci_features2str(rp.features, - buffer, sizeof(buffer))); - - return (OK); -} /* hci_read_local_supported_features */ - -/* Sent Read_Buffer_Size command to the unit */ -static int -hci_read_buffer_size(int s, int argc, char **argv) -{ - ng_hci_read_buffer_size_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO, - NG_HCI_OCF_READ_BUFFER_SIZE), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Max. ACL packet size: %d bytes\n", - le16toh(rp.max_acl_size)); - fprintf(stdout, "Number of ACL packets: %d\n", - le16toh(rp.num_acl_pkt)); - fprintf(stdout, "Max. SCO packet size: %d bytes\n", - rp.max_sco_size); - fprintf(stdout, "Number of SCO packets: %d\n", - le16toh(rp.num_sco_pkt)); - - return (OK); -} /* hci_read_buffer_size */ - -/* Send Read_Country_Code command to the unit */ -static int -hci_read_country_code(int s, int argc, char **argv) -{ - ng_hci_read_country_code_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO, - NG_HCI_OCF_READ_COUNTRY_CODE), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Country code: %s [%#02x]\n", - hci_cc2str(rp.country_code), rp.country_code); - - return (OK); -} /* hci_read_country_code */ - -/* Send Read_BD_ADDR command to the unit */ -static int -hci_read_bd_addr(int s, int argc, char **argv) -{ - ng_hci_read_bdaddr_rp rp; - int n; - - n = sizeof(rp); - if (hci_simple_request(s, NG_HCI_OPCODE(NG_HCI_OGF_INFO, - NG_HCI_OCF_READ_BDADDR), (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "BD_ADDR: %s\n", bt_ntoa(&rp.bdaddr, NULL)); - - return (OK); -} /* hci_read_bd_addr */ - -struct hci_command info_commands[] = { -{ -"read_local_version_information", -"\nThis command will read the values for the version information for the\n" \ -"local Bluetooth unit.", -&hci_read_local_version_information -}, -{ -"read_local_supported_features", -"\nThis command requests a list of the supported features for the local\n" \ -"unit. This command will return a list of the LMP features.", -&hci_read_local_supported_features -}, -{ -"read_buffer_size", -"\nThe Read_Buffer_Size command is used to read the maximum size of the\n" \ -"data portion of HCI ACL and SCO Data Packets sent from the Host to the\n" \ -"Host Controller.", -&hci_read_buffer_size -}, -{ -"read_country_code", -"\nThis command will read the value for the Country_Code return parameter.\n" \ -"The Country_Code defines which range of frequency band of the ISM 2.4 GHz\n" \ -"band will be used by the unit.", -&hci_read_country_code -}, -{ -"read_bd_addr", -"\nThis command will read the value for the BD_ADDR parameter. The BD_ADDR\n" \ -"is a 48-bit unique identifier for a Bluetooth unit.", -&hci_read_bd_addr -}, -{ -NULL, -}}; - diff --git a/usr.sbin/bluetooth/hccontrol/link_control.c b/usr.sbin/bluetooth/hccontrol/link_control.c deleted file mode 100644 index ea880cd..0000000 --- a/usr.sbin/bluetooth/hccontrol/link_control.c +++ /dev/null @@ -1,960 +0,0 @@ -/* - * link_control.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: link_control.c,v 1.4 2003/08/18 19:19:54 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "hccontrol.h" - -static void hci_inquiry_response (int n, uint8_t **b); - -/* Send Inquiry command to the unit */ -static int -hci_inquiry(int s, int argc, char **argv) -{ - int n0, n1, n2, timo; - char b[512]; - ng_hci_inquiry_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - /* set defaults */ - cp.lap[2] = 0x9e; - cp.lap[1] = 0x8b; - cp.lap[0] = 0x33; - cp.inquiry_length = 5; - cp.num_responses = 8; - - /* parse command parameters */ - switch (argc) { - case 3: - /* number of responses, range 0x00 - 0xff */ - if (sscanf(argv[2], "%d", &n0) != 1 || n0 < 0 || n0 > 0xff) - return (USAGE); - - cp.num_responses = (n0 & 0xff); - - case 2: - /* inquiry length (N * 1.28) sec, range 0x01 - 0x30 */ - if (sscanf(argv[1], "%d", &n0) != 1 || n0 < 0x1 || n0 > 0x30) - return (USAGE); - - cp.inquiry_length = (n0 & 0xff); - - case 1: - /* LAP */ - if (sscanf(argv[0], "%x:%x:%x", &n2, &n1, &n0) != 3) - return (USAGE); - - cp.lap[0] = (n0 & 0xff); - cp.lap[1] = (n1 & 0xff); - cp.lap[2] = (n2 & 0xff); - - case 0: - /* use defaults */ - break; - - default: - return (USAGE); - } - - /* send request and expect status back */ - n0 = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_INQUIRY), (char const *) &cp, sizeof(cp), - b, &n0) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - timo = timeout; - timeout = cp.inquiry_length * 1.28 + 1; - -wait_for_more: - /* wait for inquiry events */ - n0 = sizeof(b); - if (hci_recv(s, b, &n0) == ERROR) { - timeout = timo; - return (ERROR); - } - - if (n0 < sizeof(*e)) { - timeout = timo; - errno = EIO; - return (ERROR); - } - - switch (e->event) { - case NG_HCI_EVENT_INQUIRY_RESULT: { - ng_hci_inquiry_result_ep *ir = - (ng_hci_inquiry_result_ep *)(e + 1); - uint8_t *r = (uint8_t *)(ir + 1); - - fprintf(stdout, "Inquiry result, num_responses=%d\n", - ir->num_responses); - - for (n0 = 0; n0 < ir->num_responses; n0++) - hci_inquiry_response(n0, &r); - - goto wait_for_more; - } - - case NG_HCI_EVENT_INQUIRY_COMPL: - fprintf(stdout, "Inquiry complete. Status: %s [%#02x]\n", - hci_status2str(*(b + sizeof(*e))), *(b + sizeof(*e))); - break; - - default: - goto wait_for_more; - } - - timeout = timo; - - return (OK); -} /* hci_inquiry */ - -/* Print Inquiry_Result event */ -static void -hci_inquiry_response(int n, uint8_t **b) -{ - ng_hci_inquiry_response *ir = (ng_hci_inquiry_response *)(*b); - - fprintf(stdout, "Inquiry result #%d\n", n); - fprintf(stdout, "\tBD_ADDR: %s\n", hci_bdaddr2str(&ir->bdaddr)); - fprintf(stdout, "\tPage Scan Rep. Mode: %#02x\n", - ir->page_scan_rep_mode); - fprintf(stdout, "\tPage Scan Period Mode: %#02x\n", - ir->page_scan_period_mode); - fprintf(stdout, "\tPage Scan Mode: %#02x\n", - ir->page_scan_mode); - fprintf(stdout, "\tClass: %02x:%02x:%02x\n", - ir->uclass[2], ir->uclass[1], ir->uclass[0]); - fprintf(stdout, "\tClock offset: %#04x\n", - le16toh(ir->clock_offset)); - - *b += sizeof(*ir); -} /* hci_inquiry_response */ - -/* Send Create_Connection command to the unit */ -static int -hci_create_connection(int s, int argc, char **argv) -{ - int n0; - char b[512]; - ng_hci_create_con_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - /* Set defaults */ - memset(&cp, 0, sizeof(cp)); - cp.pkt_type = htole16( NG_HCI_PKT_DM1 | NG_HCI_PKT_DH1 | - NG_HCI_PKT_DM3 | NG_HCI_PKT_DH3 | - NG_HCI_PKT_DM5); - cp.page_scan_rep_mode = NG_HCI_SCAN_REP_MODE0; - cp.page_scan_mode = NG_HCI_MANDATORY_PAGE_SCAN_MODE; - cp.clock_offset = 0; - cp.accept_role_switch = 1; - - /* parse command parameters */ - switch (argc) { - case 6: - /* accept role switch */ - if (sscanf(argv[5], "%d", &n0) != 1) - return (USAGE); - - cp.accept_role_switch = n0 ? 1 : 0; - - case 5: - /* clock offset */ - if (sscanf(argv[4], "%d", &n0) != 1) - return (USAGE); - - cp.clock_offset = (n0 & 0xffff); - cp.clock_offset = htole16(cp.clock_offset); - - case 4: - /* page scan mode */ - if (sscanf(argv[3], "%d", &n0) != 1 || n0 < 0 || n0 > 3) - return (USAGE); - - cp.page_scan_mode = (n0 & 0xff); - - case 3: - /* page scan rep mode */ - if (sscanf(argv[2], "%d", &n0) != 1 || n0 < 0 || n0 > 2) - return (USAGE); - - cp.page_scan_rep_mode = (n0 & 0xff); - - case 2: - /* packet type */ - if (sscanf(argv[1], "%x", &n0) != 1) - return (USAGE); - - n0 &= ( NG_HCI_PKT_DM1 | NG_HCI_PKT_DH1 | - NG_HCI_PKT_DM3 | NG_HCI_PKT_DH3 | - NG_HCI_PKT_DM5); - if (n0 == 0) - return (USAGE); - - cp.pkt_type = (n0 & 0xffff); - cp.pkt_type = htole16(cp.pkt_type); - - case 1: - /* BD_ADDR */ - if (!bt_aton(argv[0], &cp.bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(argv[0])) == NULL) - return (USAGE); - - memcpy(&cp.bdaddr, he->h_addr, sizeof(cp.bdaddr)); - } - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n0 = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_CREATE_CON), - (char const *) &cp, sizeof(cp), b, &n0) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n0 = sizeof(b); - if (hci_recv(s, b, &n0) == ERROR) - return (ERROR); - if (n0 < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_CON_COMPL) { - ng_hci_con_compl_ep *ep = (ng_hci_con_compl_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "BD_ADDR: %s\n", hci_bdaddr2str(&ep->bdaddr)); - fprintf(stdout, "Connection handle: %d\n", - le16toh(ep->con_handle)); - fprintf(stdout, "Encryption mode: %s [%d]\n", - hci_encrypt2str(ep->encryption_mode, 0), - ep->encryption_mode); - } else - goto again; - - return (OK); -} /* hci_create_connection */ - -/* Send Disconnect command to the unit */ -static int -hci_disconnect(int s, int argc, char **argv) -{ - int n; - char b[512]; - ng_hci_discon_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - /* Set defaults */ - memset(&cp, 0, sizeof(cp)); - cp.reason = 0x13; - - /* parse command parameters */ - switch (argc) { - case 2: - /* reason */ - if (sscanf(argv[1], "%d", &n) != 1 || n <= 0x00 || n > 0xff) - return (USAGE); - - cp.reason = (uint8_t) (n & 0xff); - - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_DISCON), - (char const *) &cp, sizeof(cp), b, &n) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n = sizeof(b); - if (hci_recv(s, b, &n) == ERROR) - return (ERROR); - if (n < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_DISCON_COMPL) { - ng_hci_discon_compl_ep *ep = (ng_hci_discon_compl_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", - le16toh(ep->con_handle)); - fprintf(stdout, "Reason: %s [%#02x]\n", - hci_status2str(ep->reason), ep->reason); - } else - goto again; - - return (OK); -} /* hci_diconnect */ - -/* Send Add_SCO_Connection command to the unit */ -static int -hci_add_sco_connection(int s, int argc, char **argv) -{ - int n; - char b[512]; - ng_hci_add_sco_con_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - /* Set defaults */ - memset(&cp, 0, sizeof(cp)); - cp.pkt_type = htole16(NG_HCI_PKT_HV1 | NG_HCI_PKT_HV2 | NG_HCI_PKT_HV3); - - /* parse command parameters */ - switch (argc) { - case 2: - /* packet type */ - if (sscanf(argv[1], "%x", &n) != 1) - return (USAGE); - - n &= (NG_HCI_PKT_HV1 | NG_HCI_PKT_HV2 | NG_HCI_PKT_HV3); - if (n == 0) - return (USAGE); - - cp.pkt_type = (uint16_t) (n & 0x0fff); - cp.pkt_type = htole16(cp.pkt_type); - - case 1: - /* acl connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_ADD_SCO_CON), - (char const *) &cp, sizeof(cp), b, &n) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n = sizeof(b); - if (hci_recv(s, b, &n) == ERROR) - return (ERROR); - if (n < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_CON_COMPL) { - ng_hci_con_compl_ep *ep = (ng_hci_con_compl_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "BD_ADDR: %s\n", hci_bdaddr2str(&ep->bdaddr)); - fprintf(stdout, "Connection handle: %d\n", - le16toh(ep->con_handle)); - fprintf(stdout, "Encryption mode: %s [%d]\n", - hci_encrypt2str(ep->encryption_mode, 0), - ep->encryption_mode); - } else - goto again; - - return (OK); -} /* Add_SCO_Connection */ - -/* Send Change_Connection_Packet_Type command to the unit */ -static int -hci_change_connection_packet_type(int s, int argc, char **argv) -{ - int n; - char b[512]; - ng_hci_change_con_pkt_type_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - switch (argc) { - case 2: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - - /* packet type */ - if (sscanf(argv[1], "%x", &n) != 1) - return (USAGE); - - cp.pkt_type = (uint16_t) (n & 0xffff); - cp.pkt_type = htole16(cp.pkt_type); - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_CHANGE_CON_PKT_TYPE), - (char const *) &cp, sizeof(cp), b, &n) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n = sizeof(b); - if (hci_recv(s, b, &n) == ERROR) - return (ERROR); - if (n < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_CON_PKT_TYPE_CHANGED) { - ng_hci_con_pkt_type_changed_ep *ep = - (ng_hci_con_pkt_type_changed_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", - le16toh(ep->con_handle)); - fprintf(stdout, "Packet type: %#04x\n", - le16toh(ep->pkt_type)); - } else - goto again; - - return (OK); -} /* hci_change_connection_packet_type */ - -/* Send Remote_Name_Request command to the unit */ -static int -hci_remote_name_request(int s, int argc, char **argv) -{ - int n0; - char b[512]; - ng_hci_remote_name_req_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - memset(&cp, 0, sizeof(cp)); - cp.page_scan_rep_mode = NG_HCI_SCAN_REP_MODE0; - cp.page_scan_mode = NG_HCI_MANDATORY_PAGE_SCAN_MODE; - - /* parse command parameters */ - switch (argc) { - case 4: - /* clock_offset */ - if (sscanf(argv[3], "%x", &n0) != 1) - return (USAGE); - - cp.clock_offset = (n0 & 0xffff); - cp.clock_offset = htole16(cp.clock_offset); - - case 3: - /* page_scan_mode */ - if (sscanf(argv[2], "%d", &n0) != 1 || n0 < 0x00 || n0 > 0x03) - return (USAGE); - - cp.page_scan_mode = (n0 & 0xff); - - case 2: - /* page_scan_rep_mode */ - if (sscanf(argv[1], "%d", &n0) != 1 || n0 < 0x00 || n0 > 0x02) - return (USAGE); - - cp.page_scan_rep_mode = (n0 & 0xff); - - case 1: - /* BD_ADDR */ - if (!bt_aton(argv[0], &cp.bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(argv[0])) == NULL) - return (USAGE); - - memcpy(&cp.bdaddr, he->h_addr, sizeof(cp.bdaddr)); - } - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n0 = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_REMOTE_NAME_REQ), - (char const *) &cp, sizeof(cp), b, &n0) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n0 = sizeof(b); - if (hci_recv(s, b, &n0) == ERROR) - return (ERROR); - if (n0 < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL) { - ng_hci_remote_name_req_compl_ep *ep = - (ng_hci_remote_name_req_compl_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "BD_ADDR: %s\n", hci_bdaddr2str(&ep->bdaddr)); - fprintf(stdout, "Name: %s\n", ep->name); - } else - goto again; - - return (OK); -} /* hci_remote_name_request */ - -/* Send Read_Remote_Supported_Features command to the unit */ -static int -hci_read_remote_supported_features(int s, int argc, char **argv) -{ - int n; - char b[512]; - ng_hci_read_remote_features_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - char buffer[1024]; - - /* parse command parameters */ - switch (argc) { - case 1: - /* connecton handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_READ_REMOTE_FEATURES), - (char const *) &cp, sizeof(cp), b, &n) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n = sizeof(b); - if (hci_recv(s, b, &n) == ERROR) - return (ERROR); - - if (n < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_READ_REMOTE_FEATURES_COMPL) { - ng_hci_read_remote_features_compl_ep *ep = - (ng_hci_read_remote_features_compl_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", - le16toh(ep->con_handle)); - fprintf(stdout, "Features: "); - for (n = 0; n < sizeof(ep->features); n++) - fprintf(stdout, "%#02x ", ep->features[n]); - fprintf(stdout, "\n%s\n", hci_features2str(ep->features, - buffer, sizeof(buffer))); - } else - goto again; - - return (OK); -} /* hci_read_remote_supported_features */ - -/* Send Read_Remote_Version_Information command to the unit */ -static int -hci_read_remote_version_information(int s, int argc, char **argv) -{ - int n; - char b[512]; - ng_hci_read_remote_ver_info_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - /* parse command parameters */ - switch (argc) { - case 1: - /* connecton handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_READ_REMOTE_VER_INFO), - (char const *) &cp, sizeof(cp), b, &n) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n = sizeof(b); - if (hci_recv(s, b, &n) == ERROR) - return (ERROR); - - if (n < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_READ_REMOTE_VER_INFO_COMPL) { - ng_hci_read_remote_ver_info_compl_ep *ep = - (ng_hci_read_remote_ver_info_compl_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - ep->manufacturer = le16toh(ep->manufacturer); - - fprintf(stdout, "Connection handle: %d\n", - le16toh(ep->con_handle)); - fprintf(stdout, "LMP version: %s [%#02x]\n", - hci_lmpver2str(ep->lmp_version), ep->lmp_version); - fprintf(stdout, "LMP sub-version: %#04x\n", - le16toh(ep->lmp_subversion)); - fprintf(stdout, "Manufacturer: %s [%#04x]\n", - hci_manufacturer2str(ep->manufacturer), - ep->manufacturer); - } else - goto again; - - return (OK); -} /* hci_read_remote_version_information */ - -/* Send Read_Clock_Offset command to the unit */ -static int -hci_read_clock_offset(int s, int argc, char **argv) -{ - int n; - char b[512]; - ng_hci_read_clock_offset_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - /* parse command parameters */ - switch (argc) { - case 1: - /* connecton handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n < 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_READ_CLOCK_OFFSET), - (char const *) &cp, sizeof(cp), b, &n) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n = sizeof(b); - if (hci_recv(s, b, &n) == ERROR) - return (ERROR); - - if (n < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_READ_CLOCK_OFFSET_COMPL) { - ng_hci_read_clock_offset_compl_ep *ep = - (ng_hci_read_clock_offset_compl_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", - le16toh(ep->con_handle)); - fprintf(stdout, "Clock offset: %#04x\n", - le16toh(ep->clock_offset)); - } else - goto again; - - return (OK); -} /* hci_read_clock_offset */ - -struct hci_command link_control_commands[] = { -{ -"inquiry ", -"\nThis command will cause the Bluetooth unit to enter Inquiry Mode.\n" \ -"Inquiry Mode is used to discover other nearby Bluetooth units. The LAP\n" \ -"input parameter contains the LAP from which the inquiry access code shall\n" \ -"be derived when the inquiry procedure is made. The Inquiry_Length parameter\n"\ -"specifies the total duration of the Inquiry Mode and, when this time\n" \ -"expires, Inquiry will be halted. The Num_Responses parameter specifies the\n" \ -"number of responses that can be received before the Inquiry is halted.\n\n" \ -"\t - xx:xx:xx; 9e:8b:33 (GIAC), 93:8b:00 (LDIAC)\n" \ -"\t - dd; total length == dd * 1.28 sec\n" \ -"\t - dd", -&hci_inquiry -}, -{ -"create_connection ", -"" \ -"\t - xx:xx:xx:xx:xx:xx BD_ADDR or name\n\n" \ -"\t - xxxx; packet type\n" \ -"" \ -"\t\tACL packets\n" \ -"\t\t-----------\n" \ -"\t\t0x0008 DM1\n" \ -"\t\t0x0010 DH1\n" \ -"\t\t0x0400 DM3\n" \ -"\t\t0x0800 DH3\n" \ -"\t\t0x4000 DM5\n" \ -"\t\t0x8000 DH5\n\n" \ -"" \ -"\trep_mode - d; page scan repetition mode\n" \ -"" \ -"\t\tPage scan repetition modes\n" \ -"\t\t--------------------------\n" \ -"\t\t0 Page scan repetition mode 0\n" \ -"\t\t1 Page scan repetition mode 1\n" \ -"\t\t2 Page scan repetition mode 2\n" \ -"\n" \ -"\tps_mode - d; Page scan mode\n" \ -"" \ -"\t\tPage scan modes\n" \ -"\t\t---------------\n" \ -"\t\t0 Mandatory page scan mode\n" \ -"\t\t1 Optional page scan mode1\n" \ -"\t\t2 Optional page scan mode2\n" \ -"\t\t3 Optional page scan mode3\n" \ -"\n" \ -"\tclck_off - dddd; clock offset. Use 0 if unknown\n\n" \ -"\trole_sw - d; allow (1) or deny role switch\n", -&hci_create_connection -}, -{ -"disconnect ", -"\nThe Disconnection command is used to terminate an existing connection.\n" \ -"The connection handle command parameter indicates which connection is to\n" \ -"be disconnected. The Reason command parameter indicates the reason for\n" \ -"ending the connection.\n\n" \ -"\t - dddd; connection handle\n" \ -"\t - dd; reason; usually 19 (0x13) - user ended;\n" \ -"\t also 0x05, 0x13-0x15, 0x1A, 0x29", -&hci_disconnect -}, -{ -"add_sco_connection ", -"This command will cause the link manager to create a SCO connection using\n" \ -"the ACL connection specified by the connection handle command parameter.\n" \ -"The Link Manager will determine how the new connection is established. This\n"\ -"connection is determined by the current state of the device, its piconet,\n" \ -"and the state of the device to be connected. The packet type command parameter\n" \ -"specifies which packet types the Link Manager should use for the connection.\n"\ -"The Link Manager must only use the packet type(s) specified by the packet\n" \ -"type command parameter for sending HCI SCO data packets. Multiple packet\n" \ -"types may be specified for the packet type command parameter by performing\n" \ -"a bitwise OR operation of the different packet types. Note: An SCO connection\n" \ -"can only be created when an ACL connection already exists and when it is\n" \ -"not put in park mode.\n\n" \ -"\t - dddd; ACL connection handle\n" \ -"\t - xxxx; packet type\n" \ -"" \ -"\t\tSCO packets\n" \ -"\t\t-----------\n" \ -"\t\t0x0020 HV1\n" \ -"\t\t0x0040 HV2\n" \ -"\t\t0x0080 HV3\n", -&hci_add_sco_connection -}, -{ -"change_connection_packet_type ", -"The Change_Connection_Packet_Type command is used to change which packet\n" \ -"types can be used for a connection that is currently established. This\n" \ -"allows current connections to be dynamically modified to support different\n" \ -"types of user data. The Packet_Type command parameter specifies which\n" \ -"packet types the Link Manager can use for the connection. Multiple packet\n" \ -"types may be specified for the Packet_Type command parameter by bitwise OR\n" \ -"operation of the different packet types.\n\n" \ -"\t - dddd; connection handle\n" \ -"\t - xxxx; packet type mask\n" \ -"" \ -"\t\tACL packets\n" \ -"\t\t-----------\n" \ -"\t\t0x0008 DM1\n" \ -"\t\t0x0010 DH1\n" \ -"\t\t0x0400 DM3\n" \ -"\t\t0x0800 DH3\n" \ -"\t\t0x4000 DM5\n" \ -"\t\t0x8000 DH5\n\n" \ -"" \ -"\t\tSCO packets\n" \ -"\t\t-----------\n" \ -"\t\t0x0020 HV1\n" \ -"\t\t0x0040 HV2\n" \ -"\t\t0x0080 HV3\n" \ -"", -&hci_change_connection_packet_type -}, -{ -"remote_name_request ", -"\nThe Remote_Name_Request command is used to obtain the user-friendly\n" \ -"name of another Bluetooth unit.\n\n" \ -"\t - xx:xx:xx:xx:xx:xx BD_ADDR or name\n" \ -"\t - dd; page scan repetition mode [0-2]\n" \ -"\t - dd; page scan mode [0-3]\n" \ -"\t - xxxx; clock offset [0 - 0xffff]", -&hci_remote_name_request -}, -{ -"read_remote_supported_features ", -"\nThis command requests a list of the supported features for the remote\n" \ -"unit identified by the connection handle parameter. The connection handle\n" \ -"must be a connection handle for an ACL connection.\n\n" \ -"\t - dddd; connection handle", -&hci_read_remote_supported_features -}, -{ -"read_remote_version_information ", -"\nThis command will obtain the values for the version information for the\n" \ -"remote Bluetooth unit identified by the connection handle parameter. The\n" \ -"connection handle must be a connection handle for an ACL connection.\n\n" \ -"\t - dddd; connection handle", -&hci_read_remote_version_information -}, -{ -"read_clock_offset ", -"\nThis command allows the Host to read the clock offset from the remote unit.\n" \ -"\t - dddd; connection handle", -&hci_read_clock_offset -}, -{ -NULL, -}}; - diff --git a/usr.sbin/bluetooth/hccontrol/link_policy.c b/usr.sbin/bluetooth/hccontrol/link_policy.c deleted file mode 100644 index 67b32d5..0000000 --- a/usr.sbin/bluetooth/hccontrol/link_policy.c +++ /dev/null @@ -1,305 +0,0 @@ -/* - * link_policy.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: link_policy.c,v 1.3 2003/08/18 19:19:54 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "hccontrol.h" - -/* Send Role Discovery to the unit */ -static int -hci_role_discovery(int s, int argc, char **argv) -{ - ng_hci_role_discovery_cp cp; - ng_hci_role_discovery_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send request */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_POLICY, - NG_HCI_OCF_ROLE_DISCOVERY), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle)); - fprintf(stdout, "Role: %s [%#x]\n", - (rp.role == NG_HCI_ROLE_MASTER)? "Master" : "Slave", rp.role); - - return (OK); -} /* hci_role_discovery */ - -/* Send Swith Role to the unit */ -static int -hci_switch_role(int s, int argc, char **argv) -{ - int n0; - char b[512]; - ng_hci_switch_role_cp cp; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) b; - - /* parse command parameters */ - switch (argc) { - case 2: - /* bdaddr */ - if (!bt_aton(argv[0], &cp.bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(argv[0])) == NULL) - return (USAGE); - - memcpy(&cp.bdaddr, he->h_addr, sizeof(cp.bdaddr)); - } - - /* role */ - if (sscanf(argv[1], "%d", &n0) != 1) - return (USAGE); - - cp.role = n0? NG_HCI_ROLE_SLAVE : NG_HCI_ROLE_MASTER; - break; - - default: - return (USAGE); - } - - /* send request and expect status response */ - n0 = sizeof(b); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_POLICY, - NG_HCI_OCF_SWITCH_ROLE), - (char const *) &cp, sizeof(cp), b, &n0) == ERROR) - return (ERROR); - - if (*b != 0x00) - return (FAILED); - - /* wait for event */ -again: - n0 = sizeof(b); - if (hci_recv(s, b, &n0) == ERROR) - return (ERROR); - if (n0 < sizeof(*e)) { - errno = EIO; - return (ERROR); - } - - if (e->event == NG_HCI_EVENT_ROLE_CHANGE) { - ng_hci_role_change_ep *ep = (ng_hci_role_change_ep *)(e + 1); - - if (ep->status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(ep->status), ep->status); - return (FAILED); - } - - fprintf(stdout, "BD_ADDR: %s\n", hci_bdaddr2str(&ep->bdaddr)); - fprintf(stdout, "Role: %s [%#x]\n", - (ep->role == NG_HCI_ROLE_MASTER)? "Master" : "Slave", - ep->role); - } else - goto again; - - return (OK); -} /* hci_switch_role */ - -/* Send Read_Link_Policy_Settings command to the unit */ -static int -hci_read_link_policy_settings(int s, int argc, char **argv) -{ - ng_hci_read_link_policy_settings_cp cp; - ng_hci_read_link_policy_settings_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send request */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_POLICY, - NG_HCI_OCF_READ_LINK_POLICY_SETTINGS), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle)); - fprintf(stdout, "Link policy settings: %#x\n", le16toh(rp.settings)); - - return (OK); -} /* hci_read_link_policy_settings */ - -/* Send Write_Link_Policy_Settings command to the unit */ -static int -hci_write_link_policy_settings(int s, int argc, char **argv) -{ - ng_hci_write_link_policy_settings_cp cp; - ng_hci_write_link_policy_settings_rp rp; - int n; - - /* parse command parameters */ - switch (argc) { - case 2: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - - /* link policy settings */ - if (sscanf(argv[1], "%x", &n) != 1) - return (USAGE); - - cp.settings = (uint16_t) (n & 0x0ffff); - cp.settings = htole16(cp.settings); - break; - - default: - return (USAGE); - } - - /* send request */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_LINK_POLICY, - NG_HCI_OCF_WRITE_LINK_POLICY_SETTINGS), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_write_link_policy_settings */ - -struct hci_command link_policy_commands[] = { -{ -"role_discovery ", -"\nThe Role_Discovery command is used for a Bluetooth device to determine\n" \ -"which role the device is performing for a particular Connection Handle.\n" \ -"The connection handle must be a connection handle for an ACL connection.\n\n" \ -"\t - dddd; connection handle", -&hci_role_discovery -}, -{ -"switch_role ", -"\nThe Switch_Role command is used for a Bluetooth device to switch the\n" \ -"current role the device is performing for a particular connection with\n" \ -"another specified Bluetooth device. The BD_ADDR command parameter indicates\n"\ -"for which connection the role switch is to be performed. The Role indicates\n"\ -"the requested new role that the local device performs. Note: the BD_ADDR\n" \ -"command parameter must specify a Bluetooth device for which a connection\n" -"already exists.\n\n" \ -"\t - xx:xx:xx:xx:xx:xx BD_ADDR or name\n" \ -"\t - dd; role; 0 - Master, 1 - Slave", -&hci_switch_role -}, -{ -"read_link_policy_settings ", -"\nThis command will read the Link Policy setting for the specified connection\n"\ -"handle. The link policy settings parameter determines the behavior of the\n" \ -"local Link Manager when it receives a request from a remote device or it\n" \ -"determines itself to change the master-slave role or to enter the hold,\n" \ -"sniff, or park mode. The local Link Manager will automatically accept or\n" \ -"reject such a request from the remote device, and may even autonomously\n" \ -"request itself, depending on the value of the link policy settings parameter\n"\ -"for the corresponding connection handle. The connection handle must be a\n" \ -"connection handle for an ACL connection.\n\n" \ -"\t - dddd; connection handle", -&hci_read_link_policy_settings -}, -{ -"write_link_policy_settings ", -"\nThis command will write the Link Policy setting for the specified connection\n"\ -"handle. The link policy settings parameter determines the behavior of the\n" \ -"local Link Manager when it receives a request from a remote device or it\n" \ -"determines itself to change the master-slave role or to enter the hold,\n" \ -"sniff, or park mode. The local Link Manager will automatically accept or\n" \ -"reject such a request from the remote device, and may even autonomously\n" \ -"request itself, depending on the value of the link policy settings parameter\n"\ -"for the corresponding connection handle. The connection handle must be a\n" \ -"connection handle for an ACL connection. Multiple Link Manager policies may\n"\ -"be specified for the link policy settings parameter by performing a bitwise\n"\ -"OR operation of the different activity types.\n\n" \ -"\t - dddd; connection handle\n" \ -"\t - xxxx; settings\n" \ -"\t\t0x0000 - Disable All LM Modes (Default)\n" \ -"\t\t0x0001 - Enable Master Slave Switch\n" \ -"\t\t0x0002 - Enable Hold Mode\n" \ -"\t\t0x0004 - Enable Sniff Mode\n" \ -"\t\t0x0008 - Enable Park Mode\n", -&hci_write_link_policy_settings -}, -{ -NULL, -}}; - diff --git a/usr.sbin/bluetooth/hccontrol/node.c b/usr.sbin/bluetooth/hccontrol/node.c deleted file mode 100644 index ede2153..0000000 --- a/usr.sbin/bluetooth/hccontrol/node.c +++ /dev/null @@ -1,607 +0,0 @@ -/* - * node.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: node.c,v 1.6 2003/07/22 21:14:02 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "hccontrol.h" - -/* Send Read_Node_State command to the node */ -static int -hci_read_node_state(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_state r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_STATE, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "State: %#x\n", r.state); - - return (OK); -} /* hci_read_node_state */ - -/* Send Intitialize command to the node */ -static int -hci_node_initialize(int s, int argc, char **argv) -{ - if (ioctl(s, SIOC_HCI_RAW_NODE_INIT) < 0) - return (ERROR); - - return (OK); -} /* hci_node_initialize */ - -/* Send Read_Debug_Level command to the node */ -static int -hci_read_debug_level(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_debug r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_DEBUG, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Debug level: %d\n", r.debug); - - return (OK); -} /* hci_read_debug_level */ - -/* Send Write_Debug_Level command to the node */ -static int -hci_write_debug_level(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_debug r; - - memset(&r, 0, sizeof(r)); - switch (argc) { - case 1: - r.debug = atoi(argv[0]); - break; - - default: - return (USAGE); - } - - if (ioctl(s, SIOC_HCI_RAW_NODE_SET_DEBUG, &r, sizeof(r)) < 0) - return (ERROR); - - return (OK); -} /* hci_write_debug_level */ - -/* Send Read_Node_Buffer_Size command to the node */ -static int -hci_read_node_buffer_size(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_buffer r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_BUFFER, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Number of free command buffers: %d\n", - r.buffer.cmd_free); - fprintf(stdout, "Max. ACL packet size: %d\n", - r.buffer.acl_size); - fprintf(stdout, "Numbef of free ACL buffers: %d\n", - r.buffer.acl_free); - fprintf(stdout, "Total number of ACL buffers: %d\n", - r.buffer.acl_pkts); - fprintf(stdout, "Max. SCO packet size: %d\n", - r.buffer.sco_size); - fprintf(stdout, "Numbef of free SCO buffers: %d\n", - r.buffer.sco_free); - fprintf(stdout, "Total number of SCO buffers: %d\n", - r.buffer.sco_pkts); - - return (OK); -} /* hci_read_node_buffer_size */ - -/* Send Read_Node_BD_ADDR command to the node */ -static int -hci_read_node_bd_addr(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_bdaddr r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_BDADDR, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "BD_ADDR: %s\n", bt_ntoa(&r.bdaddr, NULL)); - - return (OK); -} /* hci_read_node_bd_addr */ - -/* Send Read_Node_Features command to the node */ -static int -hci_read_node_features(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_features r; - int n; - char buffer[1024]; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_FEATURES, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Features: "); - for (n = 0; n < sizeof(r.features)/sizeof(r.features[0]); n++) - fprintf(stdout, "%#02x ", r.features[n]); - fprintf(stdout, "\n%s\n", hci_features2str(r.features, - buffer, sizeof(buffer))); - - return (OK); -} /* hci_read_node_features */ - -/* Send Read_Node_Stat command to the node */ -static int -hci_read_node_stat(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_stat r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_STAT, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Commands sent: %d\n", r.stat.cmd_sent); - fprintf(stdout, "Events received: %d\n", r.stat.evnt_recv); - fprintf(stdout, "ACL packets received: %d\n", r.stat.acl_recv); - fprintf(stdout, "ACL packets sent: %d\n", r.stat.acl_sent); - fprintf(stdout, "SCO packets received: %d\n", r.stat.sco_recv); - fprintf(stdout, "SCO packets sent: %d\n", r.stat.sco_sent); - fprintf(stdout, "Bytes received: %d\n", r.stat.bytes_recv); - fprintf(stdout, "Bytes sent: %d\n", r.stat.bytes_sent); - - return (OK); -} /* hci_read_node_stat */ - -/* Send Reset_Node_Stat command to the node */ -static int -hci_reset_node_stat(int s, int argc, char **argv) -{ - if (ioctl(s, SIOC_HCI_RAW_NODE_RESET_STAT) < 0) - return (ERROR); - - return (OK); -} /* hci_reset_node_stat */ - -/* Send Flush_Neighbor_Cache command to the node */ -static int -hci_flush_neighbor_cache(int s, int argc, char **argv) -{ - if (ioctl(s, SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE) < 0) - return (ERROR); - - return (OK); -} /* hci_flush_neighbor_cache */ - -/* Send Read_Neighbor_Cache command to the node */ -static int -hci_read_neighbor_cache(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_neighbor_cache r; - int n, error = OK; - - memset(&r, 0, sizeof(r)); - r.num_entries = NG_HCI_MAX_NEIGHBOR_NUM; - r.entries = calloc(NG_HCI_MAX_NEIGHBOR_NUM, - sizeof(ng_hci_node_neighbor_cache_entry_ep)); - if (r.entries == NULL) { - errno = ENOMEM; - return (ERROR); - } - - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE, &r, - sizeof(r)) < 0) { - error = ERROR; - goto out; - } - - fprintf(stdout, -"BD_ADDR " \ -"Features " \ -"Clock offset " \ -"Page scan " \ -"Rep. scan\n"); - - for (n = 0; n < r.num_entries; n++) { - fprintf(stdout, -"%-17.17s " \ -"%02x %02x %02x %02x %02x %02x %02x %02x " \ -"%#12x " \ -"%#9x " \ -"%#9x\n", - hci_bdaddr2str(&r.entries[n].bdaddr), - r.entries[n].features[0], r.entries[n].features[1], - r.entries[n].features[2], r.entries[n].features[3], - r.entries[n].features[4], r.entries[n].features[5], - r.entries[n].features[6], r.entries[n].features[7], - r.entries[n].clock_offset, r.entries[n].page_scan_mode, - r.entries[n].page_scan_rep_mode); - } -out: - free(r.entries); - - return (error); -} /* hci_read_neightbor_cache */ - -/* Send Read_Connection_List command to the node */ -static int -hci_read_connection_list(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_con_list r; - int n, error = OK; - - memset(&r, 0, sizeof(r)); - r.num_connections = NG_HCI_MAX_CON_NUM; - r.connections = calloc(NG_HCI_MAX_CON_NUM, sizeof(ng_hci_node_con_ep)); - if (r.connections == NULL) { - errno = ENOMEM; - return (ERROR); - } - - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_CON_LIST, &r, sizeof(r)) < 0) { - error = ERROR; - goto out; - } - - fprintf(stdout, -"Remote BD_ADDR " \ -"Handle " \ -"Type " \ -"Mode " \ -"Role " \ -"Encrypt " \ -"Pending " \ -"Queue " \ -"State\n"); - - for (n = 0; n < r.num_connections; n++) { - fprintf(stdout, -"%-17.17s " \ -"%6d " \ -"%4.4s " \ -"%4d " \ -"%4.4s " \ -"%7.7s " \ -"%7d " \ -"%5d " \ -"%s\n", - hci_bdaddr2str(&r.connections[n].bdaddr), - r.connections[n].con_handle, - (r.connections[n].link_type == NG_HCI_LINK_ACL)? - "ACL" : "SCO", - r.connections[n].mode, - (r.connections[n].role == NG_HCI_ROLE_MASTER)? - "MAST" : "SLAV", - hci_encrypt2str(r.connections[n].encryption_mode, 1), - r.connections[n].pending, - r.connections[n].queue_len, - hci_con_state2str(r.connections[n].state)); - } -out: - free(r.connections); - - return (error); -} /* hci_read_connection_list */ - -/* Send Read_Node_Link_Policy_Settings_Mask command to the node */ -int -hci_read_node_link_policy_settings_mask(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_link_policy_mask r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Link Policy Settings mask: %#04x\n", r.policy_mask); - - return (OK); -} /* hci_read_node_link_policy_settings_mask */ - -/* Send Write_Node_Link_Policy_Settings_Mask command to the node */ -int -hci_write_node_link_policy_settings_mask(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_link_policy_mask r; - int m; - - memset(&r, 0, sizeof(r)); - - switch (argc) { - case 1: - if (sscanf(argv[0], "%x", &m) != 1) - return (USAGE); - - r.policy_mask = (m & 0xffff); - break; - - default: - return (USAGE); - } - - if (ioctl(s, SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK, &r, sizeof(r)) < 0) - return (ERROR); - - return (OK); -} /* hci_write_node_link_policy_settings_mask */ - -/* Send Read_Node_Packet_Mask command to the node */ -int -hci_read_node_packet_mask(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_packet_mask r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_PACKET_MASK, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Packet mask: %#04x\n", r.packet_mask); - - return (OK); -} /* hci_read_node_packet_mask */ - -/* Send Write_Node_Packet_Mask command to the node */ -int -hci_write_node_packet_mask(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_packet_mask r; - int m; - - memset(&r, 0, sizeof(r)); - - switch (argc) { - case 1: - if (sscanf(argv[0], "%x", &m) != 1) - return (USAGE); - - r.packet_mask = (m & 0xffff); - break; - - default: - return (USAGE); - } - - if (ioctl(s, SIOC_HCI_RAW_NODE_SET_PACKET_MASK, &r, sizeof(r)) < 0) - return (ERROR); - - return (OK); -} /* hci_write_node_packet_mask */ - -/* Send Read_Node_Role_Switch command to the node */ -int -hci_read_node_role_switch(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_role_switch r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_HCI_RAW_NODE_GET_ROLE_SWITCH, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Role switch: %d\n", r.role_switch); - - return (OK); -} /* hci_read_node_role_switch */ - -/* Send Write_Node_Role_Switch command to the node */ -int -hci_write_node_role_switch(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_role_switch r; - int m; - - memset(&r, 0, sizeof(r)); - - switch (argc) { - case 1: - if (sscanf(argv[0], "%d", &m) != 1) - return (USAGE); - - r.role_switch = m? 1 : 0; - break; - - default: - return (USAGE); - } - - if (ioctl(s, SIOC_HCI_RAW_NODE_SET_ROLE_SWITCH, &r, sizeof(r)) < 0) - return (ERROR); - - return (OK); -} /* hci_write_node_role_switch */ - -/* Send Read_Node_List command to the node */ -int -hci_read_node_list(int s, int argc, char **argv) -{ - struct ng_btsocket_hci_raw_node_list_names r; - int i; - - r.num_names = MAX_NODE_NUM; - r.names = (struct nodeinfo*)calloc(MAX_NODE_NUM, sizeof(struct nodeinfo)); - if (r.names == NULL) - return (ERROR); - - if (ioctl(s, SIOC_HCI_RAW_NODE_LIST_NAMES, &r, sizeof(r)) < 0) { - free(r.names); - return (ERROR); - } - - fprintf(stdout, "Name ID Num hooks\n"); - for (i = 0; i < r.num_names; ++i) - fprintf(stdout, "%-15s %08x %9d\n", - r.names[i].name, r.names[i].id, r.names[i].hooks); - - free(r.names); - - return (OK); -} /* hci_read_node_list */ - -struct hci_command node_commands[] = { -{ -"read_node_state", -"Get the HCI node state", -&hci_read_node_state -}, -{ -"initialize", -"Initialize the HCI node", -&hci_node_initialize -}, -{ -"read_debug_level", -"Read the HCI node debug level", -&hci_read_debug_level -}, -{ -"write_debug_level ", -"Write the HCI node debug level", -&hci_write_debug_level -}, -{ -"read_node_buffer_size", -"Read the HCI node buffer information. This will return current state of the\n"\ -"HCI buffer for the HCI node", -&hci_read_node_buffer_size -}, -{ -"read_node_bd_addr", -"Read the HCI node BD_ADDR. Returns device BD_ADDR as cached by the HCI node", -&hci_read_node_bd_addr -}, -{ -"read_node_features", -"Read the HCI node features. This will return list of supported features as\n" \ -"cached by the HCI node", -&hci_read_node_features -}, -{ -"read_node_stat", -"Read packets and bytes counters for the HCI node", -&hci_read_node_stat -}, -{ -"reset_node_stat", -"Reset packets and bytes counters for the HCI node", -&hci_reset_node_stat -}, -{ -"flush_neighbor_cache", -"Flush content of the HCI node neighbor cache", -&hci_flush_neighbor_cache -}, -{ -"read_neighbor_cache", -"Read content of the HCI node neighbor cache", -&hci_read_neighbor_cache -}, -{ -"read_connection_list", -"Read the baseband connection descriptors list for the HCI node", -&hci_read_connection_list -}, -{ -"read_node_link_policy_settings_mask", -"Read the value of the Link Policy Settinngs mask for the HCI node", -&hci_read_node_link_policy_settings_mask -}, -{ -"write_node_link_policy_settings_mask ", -"Write the value of the Link Policy Settings mask for the HCI node. By default\n" \ -"all supported Link Policy modes (as reported by the local device features) are\n"\ -"enabled. The particular Link Policy mode is enabled if local device supports\n"\ -"it and correspinding bit in the mask was set\n\n" \ -"\t - xxxx; Link Policy mask\n" \ -"\t\t0x0000 - Disable All LM Modes\n" \ -"\t\t0x0001 - Enable Master Slave Switch\n" \ -"\t\t0x0002 - Enable Hold Mode\n" \ -"\t\t0x0004 - Enable Sniff Mode\n" \ -"\t\t0x0008 - Enable Park Mode\n", -&hci_write_node_link_policy_settings_mask -}, -{ -"read_node_packet_mask", -"Read the value of the Packet mask for the HCI node", -&hci_read_node_packet_mask -}, -{ -"write_node_packet_mask ", -"Write the value of the Packet mask for the HCI node. By default all supported\n" \ -"packet types (as reported by the local device features) are enabled. The\n" \ -"particular packet type is enabled if local device supports it and corresponding\n" \ -"bit in the mask was set\n\n" \ -"\t - xxxx; packet type mask\n" \ -"" \ -"\t\tACL packets\n" \ -"\t\t-----------\n" \ -"\t\t0x0008 DM1\n" \ -"\t\t0x0010 DH1\n" \ -"\t\t0x0400 DM3\n" \ -"\t\t0x0800 DH3\n" \ -"\t\t0x4000 DM5\n" \ -"\t\t0x8000 DH5\n" \ -"\n" \ -"\t\tSCO packets\n" \ -"\t\t-----------\n" \ -"\t\t0x0020 HV1\n" \ -"\t\t0x0040 HV2\n" \ -"\t\t0x0080 HV3\n", -&hci_write_node_packet_mask -}, -{ -"read_node_role_switch", -"Read the value of the Role Switch parameter for the HCI node", -&hci_read_node_role_switch -}, -{ -"write_node_role_switch {0|1}", -"Write the value of the Role Switch parameter for the HCI node. By default,\n" \ -"if Role Switch is supported, local device will try to perform Role Switch\n" \ -"and become Master on incoming connection. Some devices do not support Role\n" \ -"Switch and thus incomming connections from such devices will fail. Setting\n" \ -"this parameter to zero will prevent Role Switch and thus accepting device\n" \ -"will remain Slave", -&hci_write_node_role_switch -}, -{ -"read_node_list", -"Get a list of HCI nodes, their Netgraph IDs and connected hooks.", -&hci_read_node_list -}, -{ -NULL, -}}; - diff --git a/usr.sbin/bluetooth/hccontrol/send_recv.c b/usr.sbin/bluetooth/hccontrol/send_recv.c deleted file mode 100644 index 5c2aea9..0000000 --- a/usr.sbin/bluetooth/hccontrol/send_recv.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * send_recv.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: send_recv.c,v 1.2 2003/05/21 22:40:30 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "hccontrol.h" - -/* Send HCI request to the unit */ -int -hci_request(int s, int opcode, char const *cp, int cp_size, char *rp, int *rp_size) -{ - char buffer[512]; - int n; - ng_hci_cmd_pkt_t *c = (ng_hci_cmd_pkt_t *) buffer; - ng_hci_event_pkt_t *e = (ng_hci_event_pkt_t *) buffer; - - assert(rp != NULL); - assert(rp_size != NULL); - assert(*rp_size > 0); - - c->type = NG_HCI_CMD_PKT; - c->opcode = (uint16_t) opcode; - c->opcode = htole16(c->opcode); - - if (cp != NULL) { - assert(0 < cp_size && cp_size <= NG_HCI_CMD_PKT_SIZE); - - c->length = (uint8_t) cp_size; - memcpy(buffer + sizeof(*c), cp, cp_size); - } else - c->length = 0; - - if (hci_send(s, buffer, sizeof(*c) + cp_size) == ERROR) - return (ERROR); - -again: - n = sizeof(buffer); - if (hci_recv(s, buffer, &n) == ERROR) - return (ERROR); - - if (n < sizeof(*e)) { - errno = EMSGSIZE; - return (ERROR); - } - - if (e->type != NG_HCI_EVENT_PKT) { - errno = EIO; - return (ERROR); - } - - switch (e->event) { - case NG_HCI_EVENT_COMMAND_COMPL: { - ng_hci_command_compl_ep *cc = - (ng_hci_command_compl_ep *)(e + 1); - - cc->opcode = le16toh(cc->opcode); - - if (cc->opcode == 0x0000 || cc->opcode != opcode) - goto again; - - n -= (sizeof(*e) + sizeof(*cc)); - if (n < *rp_size) - *rp_size = n; - - memcpy(rp, buffer + sizeof(*e) + sizeof(*cc), *rp_size); - } break; - - case NG_HCI_EVENT_COMMAND_STATUS: { - ng_hci_command_status_ep *cs = - (ng_hci_command_status_ep *)(e + 1); - - cs->opcode = le16toh(cs->opcode); - - if (cs->opcode == 0x0000 || cs->opcode != opcode) - goto again; - - *rp_size = 1; - *rp = cs->status; - } break; - - default: - goto again; - } - - return (OK); -} /* hci_request */ - -/* Send simple HCI request - Just HCI command packet (no parameters) */ -int -hci_simple_request(int s, int opcode, char *rp, int *rp_size) -{ - return (hci_request(s, opcode, NULL, 0, rp, rp_size)); -} /* hci_simple_request */ - -/* Send HCI data to the unit */ -int -hci_send(int s, char const *buffer, int size) -{ - assert(buffer != NULL); - assert(size >= sizeof(ng_hci_cmd_pkt_t)); - assert(size <= sizeof(ng_hci_cmd_pkt_t) + NG_HCI_CMD_PKT_SIZE); - - if (send(s, buffer, size, 0) < 0) - return (ERROR); - - return (OK); -} /* hci_send */ - -/* Receive HCI data from the unit */ -int -hci_recv(int s, char *buffer, int *size) -{ - struct timeval tv; - fd_set rfd; - int n; - - assert(buffer != NULL); - assert(size != NULL); - assert(*size > sizeof(ng_hci_event_pkt_t)); - -again: - FD_ZERO(&rfd); - FD_SET(s, &rfd); - - tv.tv_sec = timeout; - tv.tv_usec = 0; - - n = select(s + 1, &rfd, NULL, NULL, &tv); - if (n <= 0) { - if (n < 0) { - if (errno == EINTR) - goto again; - } else - errno = ETIMEDOUT; - - return (ERROR); - } - - assert(FD_ISSET(s, &rfd)); - - n = recv(s, buffer, *size, 0); - if (n < 0) - return (ERROR); - - *size = n; - - return (OK); -} /* hci_recv */ - diff --git a/usr.sbin/bluetooth/hccontrol/status.c b/usr.sbin/bluetooth/hccontrol/status.c deleted file mode 100644 index 3364576..0000000 --- a/usr.sbin/bluetooth/hccontrol/status.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * status.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: status.c,v 1.2 2003/05/21 22:40:30 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include "hccontrol.h" - -/* Send Read_Failed_Contact_Counter command to the unit */ -static int -hci_read_failed_contact_counter(int s, int argc, char **argv) -{ - ng_hci_read_failed_contact_cntr_cp cp; - ng_hci_read_failed_contact_cntr_rp rp; - int n; - - switch (argc) { - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS, - NG_HCI_OCF_READ_FAILED_CONTACT_CNTR), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle)); - fprintf(stdout, "Failed contact counter: %d\n", le16toh(rp.counter)); - - return (OK); -} /* hci_read_failed_contact_counter */ - -/* Send Reset_Failed_Contact_Counter command to the unit */ -static int -hci_reset_failed_contact_counter(int s, int argc, char **argv) -{ - ng_hci_reset_failed_contact_cntr_cp cp; - ng_hci_reset_failed_contact_cntr_rp rp; - int n; - - switch (argc) { - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS, - NG_HCI_OCF_RESET_FAILED_CONTACT_CNTR), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - return (OK); -} /* hci_reset_failed_contact_counter */ - -/* Sent Get_Link_Quality command to the unit */ -static int -hci_get_link_quality(int s, int argc, char **argv) -{ - ng_hci_get_link_quality_cp cp; - ng_hci_get_link_quality_rp rp; - int n; - - switch (argc) { - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS, - NG_HCI_OCF_GET_LINK_QUALITY), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle)); - fprintf(stdout, "Link quality: %d\n", le16toh(rp.quality)); - - return (OK); -} /* hci_get_link_quality */ - -/* Send Read_RSSI command to the unit */ -static int -hci_read_rssi(int s, int argc, char **argv) -{ - ng_hci_read_rssi_cp cp; - ng_hci_read_rssi_rp rp; - int n; - - switch (argc) { - case 1: - /* connection handle */ - if (sscanf(argv[0], "%d", &n) != 1 || n <= 0 || n > 0x0eff) - return (USAGE); - - cp.con_handle = (uint16_t) (n & 0x0fff); - cp.con_handle = htole16(cp.con_handle); - break; - - default: - return (USAGE); - } - - /* send command */ - n = sizeof(rp); - if (hci_request(s, NG_HCI_OPCODE(NG_HCI_OGF_STATUS, - NG_HCI_OCF_READ_RSSI), - (char const *) &cp, sizeof(cp), - (char *) &rp, &n) == ERROR) - return (ERROR); - - if (rp.status != 0x00) { - fprintf(stdout, "Status: %s [%#02x]\n", - hci_status2str(rp.status), rp.status); - return (FAILED); - } - - fprintf(stdout, "Connection handle: %d\n", le16toh(rp.con_handle)); - fprintf(stdout, "RSSI: %d dB\n", (int) rp.rssi); - - return (OK); -} /* hci_read_rssi */ - -struct hci_command status_commands[] = { -{ -"read_failed_contact_counter ", -"\nThis command will read the value for the Failed_Contact_Counter\n" \ -"parameter for a particular ACL connection to another device.\n\n" \ -"\t - dddd; ACL connection handle\n", -&hci_read_failed_contact_counter -}, -{ -"reset_failed_contact_counter ", -"\nThis command will reset the value for the Failed_Contact_Counter\n" \ -"parameter for a particular ACL connection to another device.\n\n" \ -"\t - dddd; ACL connection handle\n", -&hci_reset_failed_contact_counter -}, -{ -"get_link_quality ", -"\nThis command will return the value for the Link_Quality for the\n" \ -"specified ACL connection handle. This command will return a Link_Quality\n" \ -"value from 0-255, which represents the quality of the link between two\n" \ -"Bluetooth devices. The higher the value, the better the link quality is.\n" \ -"Each Bluetooth module vendor will determine how to measure the link quality." \ -"\n\n" \ -"\t - dddd; ACL connection handle\n", -&hci_get_link_quality -}, -{ -"read_rssi ", -"\nThis command will read the value for the difference between the\n" \ -"measured Received Signal Strength Indication (RSSI) and the limits of\n" \ -"the Golden Receive Power Range for a ACL connection handle to another\n" \ -"Bluetooth device. Any positive RSSI value returned by the Host Controller\n" \ -"indicates how many dB the RSSI is above the upper limit, any negative\n" \ -"value indicates how many dB the RSSI is below the lower limit. The value\n" \ -"zero indicates that the RSSI is inside the Golden Receive Power Range.\n\n" \ -"\t - dddd; ACL connection handle\n", -&hci_read_rssi -}, -{ -NULL, -}}; - diff --git a/usr.sbin/bluetooth/hccontrol/util.c b/usr.sbin/bluetooth/hccontrol/util.c deleted file mode 100644 index 4bb5000..0000000 --- a/usr.sbin/bluetooth/hccontrol/util.c +++ /dev/null @@ -1,410 +0,0 @@ -/* - * util.c - * - * Copyright (c) 2001 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: util.c,v 1.2 2003/05/19 17:29:29 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include - -#define SIZE(x) (sizeof((x))/sizeof((x)[0])) - -char const * -hci_link2str(int link_type) -{ - static char const * const t[] = { - /* NG_HCI_LINK_SCO */ "SCO", - /* NG_HCI_LINK_ACL */ "ACL" - }; - - return (link_type >= SIZE(t)? "?" : t[link_type]); -} /* hci_link2str */ - -char const * -hci_pin2str(int type) -{ - static char const * const t[] = { - /* 0x00 */ "Variable PIN", - /* 0x01 */ "Fixed PIN" - }; - - return (type >= SIZE(t)? "?" : t[type]); -} /* hci_pin2str */ - -char const * -hci_scan2str(int scan) -{ - static char const * const t[] = { - /* 0x00 */ "No Scan enabled", - /* 0x01 */ "Inquiry Scan enabled. Page Scan disabled", - /* 0x02 */ "Inquiry Scan disabled. Page Scan enabled", - /* 0x03 */ "Inquiry Scan enabled. Page Scan enabled" - }; - - return (scan >= SIZE(t)? "?" : t[scan]); -} /* hci_scan2str */ - -char const * -hci_encrypt2str(int encrypt, int brief) -{ - static char const * const t[] = { - /* 0x00 */ "Disabled", - /* 0x01 */ "Only for point-to-point packets", - /* 0x02 */ "Both point-to-point and broadcast packets" - }; - - static char const * const t1[] = { - /* NG_HCI_ENCRYPTION_MODE_NONE */ "NONE", - /* NG_HCI_ENCRYPTION_MODE_P2P */ "P2P", - /* NG_HCI_ENCRYPTION_MODE_ALL */ "ALL", - }; - - if (brief) - return (encrypt >= SIZE(t1)? "?" : t1[encrypt]); - - return (encrypt >= SIZE(t)? "?" : t[encrypt]); -} /* hci_encrypt2str */ - -char const * -hci_coding2str(int coding) -{ - static char const * const t[] = { - /* 0x00 */ "Linear", - /* 0x01 */ "u-law", - /* 0x02 */ "A-law", - /* 0x03 */ "Reserved" - }; - - return (coding >= SIZE(t)? "?" : t[coding]); -} /* hci_coding2str */ - -char const * -hci_vdata2str(int data) -{ - static char const * const t[] = { - /* 0x00 */ "1's complement", - /* 0x01 */ "2's complement", - /* 0x02 */ "Sign-Magnitude", - /* 0x03 */ "Reserved" - }; - - return (data >= SIZE(t)? "?" : t[data]); -} /* hci_vdata2str */ - -char const * -hci_hmode2str(int mode, char *buffer, int size) -{ - static char const * const t[] = { - /* 0x01 */ "Suspend Page Scan ", - /* 0x02 */ "Suspend Inquiry Scan ", - /* 0x04 */ "Suspend Periodic Inquiries " - }; - - if (buffer != NULL && size > 0) { - int n; - - memset(buffer, 0, size); - for (n = 0; n < SIZE(t); n++) { - int len = strlen(buffer); - - if (len >= size) - break; - if (mode & (1 << n)) - strncat(buffer, t[n], size - len); - } - } - - return (buffer); -} /* hci_hmode2str */ - -char const * -hci_ver2str(int ver) -{ - static char const * const t[] = { - /* 0x00 */ "Bluetooth HCI Specification 1.0B", - /* 0x01 */ "Bluetooth HCI Specification 1.1", - /* 0x02 */ "Bluetooth HCI Specification 1.2", - /* 0x03 */ "Bluetooth HCI Specification 2.0" - }; - - return (ver >= SIZE(t)? "?" : t[ver]); -} /* hci_ver2str */ - -char const * -hci_lmpver2str(int ver) -{ - static char const * const t[] = { - /* 0x00 */ "Bluetooth LMP 1.0", - /* 0x01 */ "Bluetooth LMP 1.1", - /* 0x02 */ "Bluetooth LMP 1.2", - /* 0x03 */ "Bluetooth LMP 2.0" - }; - - return (ver >= SIZE(t)? "?" : t[ver]); -} /* hci_lmpver2str */ - -char const * -hci_manufacturer2str(int m) -{ - static char const * const t[] = { - /* 0000 */ "Ericsson Technology Licensing", - /* 0001 */ "Nokia Mobile Phones", - /* 0002 */ "Intel Corp.", - /* 0003 */ "IBM Corp.", - /* 0004 */ "Toshiba Corp.", - /* 0005 */ "3Com", - /* 0006 */ "Microsoft", - /* 0007 */ "Lucent", - /* 0008 */ "Motorola", - /* 0009 */ "Infineon Technologies AG", - /* 0010 */ "Cambridge Silicon Radio", - /* 0011 */ "Silicon Wave", - /* 0012 */ "Digianswer A/S", - /* 0013 */ "Texas Instruments Inc.", - /* 0014 */ "Parthus Technologies Inc.", - /* 0015 */ "Broadcom Corporation", - /* 0016 */ "Mitel Semiconductor", - /* 0017 */ "Widcomm, Inc.", - /* 0018 */ "Zeevo, Inc.", - /* 0019 */ "Atmel Corporation", - /* 0020 */ "Mitsubishi Electric Corporation", - /* 0021 */ "RTX Telecom A/S", - /* 0022 */ "KC Technology Inc.", - /* 0023 */ "Newlogic", - /* 0024 */ "Transilica, Inc.", - /* 0025 */ "Rohde & Schwartz GmbH & Co. KG", - /* 0026 */ "TTPCom Limited", - /* 0027 */ "Signia Technologies, Inc.", - /* 0028 */ "Conexant Systems Inc.", - /* 0029 */ "Qualcomm", - /* 0030 */ "Inventel", - /* 0031 */ "AVM Berlin", - /* 0032 */ "BandSpeed, Inc.", - /* 0033 */ "Mansella Ltd", - /* 0034 */ "NEC Corporation", - /* 0035 */ "WavePlus Technology Co., Ltd.", - /* 0036 */ "Alcatel", - /* 0037 */ "Philips Semiconductors", - /* 0038 */ "C Technologies", - /* 0039 */ "Open Interface", - /* 0040 */ "R F Micro Devices", - /* 0041 */ "Hitachi Ltd", - /* 0042 */ "Symbol Technologies, Inc.", - /* 0043 */ "Tenovis", - /* 0044 */ "Macronix International Co. Ltd.", - /* 0045 */ "GCT Semiconductor", - /* 0046 */ "Norwood Systems", - /* 0047 */ "MewTel Technology Inc.", - /* 0048 */ "ST Microelectronics", - /* 0049 */ "Synopsys", - /* 0050 */ "Red-M (Communications) Ltd", - /* 0051 */ "Commil Ltd", - /* 0052 */ "Computer Access Technology Corporation (CATC)", - /* 0053 */ "Eclipse (HQ Espana) S.L.", - /* 0054 */ "Renesas Technology Corp.", - /* 0055 */ "Mobilian Corporation", - /* 0056 */ "Terax", - /* 0057 */ "Integrated System Solution Corp.", - /* 0058 */ "Matsushita Electric Industrial Co., Ltd.", - /* 0059 */ "Gennum Corporation", - /* 0060 */ "Research In Motion", - /* 0061 */ "IPextreme, Inc.", - /* 0062 */ "Systems and Chips, Inc", - /* 0063 */ "Bluetooth SIG, Inc", - /* 0064 */ "Seiko Epson Corporation" - }; - - return (m >= SIZE(t)? "?" : t[m]); -} /* hci_manufacturer2str */ - -char const * -hci_features2str(uint8_t *features, char *buffer, int size) -{ - static char const * const t[][8] = { - { /* byte 0 */ - /* 0 */ "<3-Slot> ", - /* 1 */ "<5-Slot> ", - /* 2 */ " ", - /* 3 */ " ", - /* 4 */ " ", - /* 5 */ " ", - /* 6 */ " ", - /* 7 */ " " - }, - { /* byte 1 */ - /* 0 */ " ", - /* 1 */ " ", - /* 2 */ " ", - /* 3 */ " ", - /* 4 */ " ", - /* 5 */ " ", - /* 6 */ " ", - /* 7 */ " " - }, - { /* byte 2 */ - /* 0 */ " ", - /* 1 */ " ", - /* 2 */ " ", - /* 3 */ " ", - /* 4 */ " ", - /* 5 */ " ", - /* 6 */ " ", - /* 7 */ " " - }}; - - if (buffer != NULL && size > 0) { - int n, i, len0, len1; - - memset(buffer, 0, size); - len1 = 0; - - for (n = 0; n < SIZE(t); n++) { - for (i = 0; i < SIZE(t[n]); i++) { - len0 = strlen(buffer); - if (len0 >= size) - goto done; - - if (features[n] & (1 << i)) { - if (len1 + strlen(t[n][i]) > 60) { - len1 = 0; - buffer[len0 - 1] = '\n'; - } - - len1 += strlen(t[n][i]); - strncat(buffer, t[n][i], size - len0); - } - } - } - } -done: - return (buffer); -} /* hci_features2str */ - -char const * -hci_cc2str(int cc) -{ - static char const * const t[] = { - /* 0x00 */ "North America, Europe, Japan", - /* 0x01 */ "France" - }; - - return (cc >= SIZE(t)? "?" : t[cc]); -} /* hci_cc2str */ - -char const * -hci_con_state2str(int state) -{ - static char const * const t[] = { - /* NG_HCI_CON_CLOSED */ "CLOSED", - /* NG_HCI_CON_W4_LP_CON_RSP */ "W4_LP_CON_RSP", - /* NG_HCI_CON_W4_CONN_COMPLETE */ "W4_CONN_COMPLETE", - /* NG_HCI_CON_OPEN */ "OPEN" - }; - - return (state >= SIZE(t)? "UNKNOWN" : t[state]); -} /* hci_con_state2str */ - -char const * -hci_status2str(int status) -{ - static char const * const t[] = { - /* 0x00 */ "No error", - /* 0x01 */ "Unknown HCI command", - /* 0x02 */ "No connection", - /* 0x03 */ "Hardware failure", - /* 0x04 */ "Page timeout", - /* 0x05 */ "Authentication failure", - /* 0x06 */ "Key missing", - /* 0x07 */ "Memory full", - /* 0x08 */ "Connection timeout", - /* 0x09 */ "Max number of connections", - /* 0x0a */ "Max number of SCO connections to a unit", - /* 0x0b */ "ACL connection already exists", - /* 0x0c */ "Command disallowed", - /* 0x0d */ "Host rejected due to limited resources", - /* 0x0e */ "Host rejected due to security reasons", - /* 0x0f */ "Host rejected due to remote unit is a personal unit", - /* 0x10 */ "Host timeout", - /* 0x11 */ "Unsupported feature or parameter value", - /* 0x12 */ "Invalid HCI command parameter", - /* 0x13 */ "Other end terminated connection: User ended connection", - /* 0x14 */ "Other end terminated connection: Low resources", - /* 0x15 */ "Other end terminated connection: About to power off", - /* 0x16 */ "Connection terminated by local host", - /* 0x17 */ "Repeated attempts", - /* 0x18 */ "Pairing not allowed", - /* 0x19 */ "Unknown LMP PDU", - /* 0x1a */ "Unsupported remote feature", - /* 0x1b */ "SCO offset rejected", - /* 0x1c */ "SCO interval rejected", - /* 0x1d */ "SCO air mode rejected", - /* 0x1e */ "Invalid LMP parameters", - /* 0x1f */ "Unspecified error", - /* 0x20 */ "Unsupported LMP parameter value", - /* 0x21 */ "Role change not allowed", - /* 0x22 */ "LMP response timeout", - /* 0x23 */ "LMP error transaction collision", - /* 0x24 */ "LMP PSU not allowed", - /* 0x25 */ "Encryption mode not acceptable", - /* 0x26 */ "Unit key used", - /* 0x27 */ "QoS is not supported", - /* 0x28 */ "Instant passed", - /* 0x29 */ "Pairing with unit key not supported" - }; - - return (status >= SIZE(t)? "Unknown error" : t[status]); -} /* hci_status2str */ - -char const * -hci_bdaddr2str(bdaddr_t const *ba) -{ - extern int numeric_bdaddr; - static char buffer[MAXHOSTNAMELEN]; - struct hostent *he = NULL; - - if (memcmp(ba, NG_HCI_BDADDR_ANY, sizeof(*ba)) == 0) { - buffer[0] = '*'; - buffer[1] = 0; - - return (buffer); - } - - if (!numeric_bdaddr && - (he = bt_gethostbyaddr((char *)ba, sizeof(*ba), AF_BLUETOOTH)) != NULL) { - strlcpy(buffer, he->h_name, sizeof(buffer)); - - return (buffer); - } - - bt_ntoa(ba, buffer); - - return (buffer); -} /* hci_bdaddr2str */ - diff --git a/usr.sbin/bluetooth/hcsecd/Makefile b/usr.sbin/bluetooth/hcsecd/Makefile deleted file mode 100644 index e544ed4..0000000 --- a/usr.sbin/bluetooth/hcsecd/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $Id: Makefile,v 1.8 2003/08/14 20:06:20 max Exp $ -# $FreeBSD$ - -PROG= hcsecd -MAN= hcsecd.8 hcsecd.conf.5 -SRCS= hcsecd.c lexer.l parser.y -WARNS?= 2 -CFLAGS+= -I${.CURDIR} - -DPADD= ${LIBBLUETOOTH} -LDADD= -lbluetooth - -.include diff --git a/usr.sbin/bluetooth/hcsecd/hcsecd.8 b/usr.sbin/bluetooth/hcsecd/hcsecd.8 deleted file mode 100644 index 8b7084d..0000000 --- a/usr.sbin/bluetooth/hcsecd/hcsecd.8 +++ /dev/null @@ -1,128 +0,0 @@ -.\" Copyright (c) 2001-2002 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: hcsecd.8,v 1.8 2003/09/08 18:54:20 max Exp $ -.\" $FreeBSD$ -.\" -.Dd November 16, 2002 -.Dt HCSECD 8 -.Os -.Sh NAME -.Nm hcsecd -.Nd control link keys and PIN codes for Bluetooth devices -.Sh SYNOPSIS -.Nm -.Op Fl dh -.Fl f Ar configfile -.Sh DESCRIPTION -The -.Nm -daemon controls link keys and PIN codes for Bluetooth devices. -It opens a raw HCI socket and listens for -.Dv Link_Key_Request , -.Dv PIN_Code_Request -and -.Dv Link_Key_Notification -HCI events. -.Pp -Once a -.Dv Link_Key_Request -or -.Dv PIN_Code_Request -HCI event is received, the daemon scans the configuration file for a -matching entry. -The remote device BD_ADDR is used as a key. -If no matching entry was found, the default entry will be used. -If no default entry was found then it is assumed that no link key and no -PIN code exists. -For any given entry, the link key takes precedence over the PIN code. -If a link key was not specified, the device must generate the link key from -the PIN code. -If an entry was found and the link key (or PIN code) exists, the -.Dv Link_Key_Request_Reply -(or -.Dv PIN_Code_Request_Reply ) -command will be sent back to the device. -Otherwise, the -.Dv Link_Key_Request_Negative_Reply -(or -.Dv PIN_Code_Request_Negative_Reply ) -command will be sent back to the device. -.Pp -The -.Nm -daemon also handles HCI -.Dv Link_Key_Notification -events and caches link keys created from the PIN codes in memory. -To preserve link keys between restarts the -.Nm -daemon dumps link keys for all entries in the -.Pa /var/db/hcsecd.keys -link keys file. -If it exists, the link keys file gets processed by the -.Nm -daemon after it processes its main configuration file. -The link keys file gets written every time the -.Nm -daemon shuts down gracefully. -It is possible to force the -.Nm -daemon to re-read its main configuration file and dump the link keys file by -sending the -.Dv HUP -signal to the -.Nm -process. -The user is expected to not modify the link keys file by hand. -.Pp -The command line options are as follows: -.Bl -tag -width indent -.It Fl d -Do not detach from the controlling terminal. -.It Fl f Ar configfile -Specify the name of the configuration file. -The default is -.Pa /etc/bluetooth/hcsecd.conf . -.It Fl h -Display usage message and exit. -.El -.Sh FILES -.Bl -tag -width ".Pa /etc/bluetooth/hcsecd.conf" -compact -.It Pa /etc/bluetooth/hcsecd.conf -.It Pa /var/db/hcsecd.keys -.It Pa /var/run/hcsecd.pid -.El -.Sh SEE ALSO -.Xr ng_btsocket 4 , -.Xr ng_hci 4 , -.Xr hcsecd.conf 5 , -.Xr hccontrol 8 , -.Xr hcseriald 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh BUGS -Currently there is no way to select the link key or the PIN code based on -which local device received the request. -Everything is based on the remote device BD_ADDR. -An interface for external helpers to obtain link keys and PIN codes is missing. diff --git a/usr.sbin/bluetooth/hcsecd/hcsecd.c b/usr.sbin/bluetooth/hcsecd/hcsecd.c deleted file mode 100644 index 72f9c8c..0000000 --- a/usr.sbin/bluetooth/hcsecd/hcsecd.c +++ /dev/null @@ -1,446 +0,0 @@ -/* - * hcsecd.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: hcsecd.c,v 1.6 2003/08/18 19:19:55 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "hcsecd.h" - -static int done = 0; - -static int process_pin_code_request_event - (int sock, struct sockaddr_hci *addr, bdaddr_p bdaddr); -static int process_link_key_request_event - (int sock, struct sockaddr_hci *addr, bdaddr_p bdaddr); -static int send_pin_code_reply - (int sock, struct sockaddr_hci *addr, bdaddr_p bdaddr, char const *pin); -static int send_link_key_reply - (int sock, struct sockaddr_hci *addr, bdaddr_p bdaddr, uint8_t *key); -static int process_link_key_notification_event - (int sock, struct sockaddr_hci *addr, ng_hci_link_key_notification_ep *ep); -static void sighup - (int s); -static void sigint - (int s); -static void usage - (void); - -/* Main */ -int -main(int argc, char *argv[]) -{ - int n, detach, sock; - socklen_t size; - struct sigaction sa; - struct sockaddr_hci addr; - struct ng_btsocket_hci_raw_filter filter; - char buffer[HCSECD_BUFFER_SIZE]; - ng_hci_event_pkt_t *event = NULL; - - detach = 1; - - while ((n = getopt(argc, argv, "df:h")) != -1) { - switch (n) { - case 'd': - detach = 0; - break; - - case 'f': - config_file = optarg; - break; - - case 'h': - default: - usage(); - /* NOT REACHED */ - } - } - - if (config_file == NULL) - usage(); - /* NOT REACHED */ - - if (getuid() != 0) - errx(1, "** ERROR: You should run %s as privileged user!", - HCSECD_IDENT); - - /* Set signal handlers */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sigint; - sa.sa_flags = SA_NOCLDWAIT; - if (sigaction(SIGINT, &sa, NULL) < 0) - err(1, "Could not sigaction(SIGINT)"); - if (sigaction(SIGTERM, &sa, NULL) < 0) - err(1, "Could not sigaction(SIGINT)"); - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sighup; - if (sigaction(SIGHUP, &sa, NULL) < 0) - err(1, "Could not sigaction(SIGHUP)"); - - /* Open socket and set filter */ - sock = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_HCI); - if (sock < 0) - err(1, "Could not create HCI socket"); - - memset(&filter, 0, sizeof(filter)); - bit_set(filter.event_mask, NG_HCI_EVENT_PIN_CODE_REQ - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_LINK_KEY_REQ - 1); - bit_set(filter.event_mask, NG_HCI_EVENT_LINK_KEY_NOTIFICATION - 1); - - if (setsockopt(sock, SOL_HCI_RAW, SO_HCI_RAW_FILTER, - (void * const) &filter, sizeof(filter)) < 0) - err(1, "Could not set HCI socket filter"); - - if (detach && daemon(0, 0) < 0) - err(1, "Could not daemon()ize"); - - openlog(HCSECD_IDENT, LOG_NDELAY|LOG_PERROR|LOG_PID, LOG_DAEMON); - - read_config_file(); - read_keys_file(); - - if (detach) { - FILE *pid = NULL; - - if ((pid = fopen(HCSECD_PIDFILE, "w")) == NULL) { - syslog(LOG_ERR, "Could not create PID file %s. %s (%d)", - HCSECD_PIDFILE, strerror(errno), errno); - exit(1); - } - - fprintf(pid, "%d", getpid()); - fclose(pid); - } - - event = (ng_hci_event_pkt_t *) buffer; - while (!done) { - size = sizeof(addr); - n = recvfrom(sock, buffer, sizeof(buffer), 0, - (struct sockaddr *) &addr, &size); - if (n < 0) { - if (errno == EINTR) - continue; - - syslog(LOG_ERR, "Could not receive from HCI socket. " \ - "%s (%d)", strerror(errno), errno); - exit(1); - } - - if (event->type != NG_HCI_EVENT_PKT) { - syslog(LOG_ERR, "Received unexpected HCI packet, " \ - "type=%#x", event->type); - continue; - } - - switch (event->event) { - case NG_HCI_EVENT_PIN_CODE_REQ: - process_pin_code_request_event(sock, &addr, - (bdaddr_p)(event + 1)); - break; - - case NG_HCI_EVENT_LINK_KEY_REQ: - process_link_key_request_event(sock, &addr, - (bdaddr_p)(event + 1)); - break; - - case NG_HCI_EVENT_LINK_KEY_NOTIFICATION: - process_link_key_notification_event(sock, &addr, - (ng_hci_link_key_notification_ep *)(event + 1)); - break; - - default: - syslog(LOG_ERR, "Received unexpected HCI event, " \ - "event=%#x", event->event); - break; - } - } - - if (detach) - if (remove(HCSECD_PIDFILE) < 0) - syslog(LOG_ERR, "Could not remove PID file %s. %s (%d)", - HCSECD_PIDFILE, strerror(errno), errno); - - dump_keys_file(); - clean_config(); - closelog(); - close(sock); - - return (0); -} - -/* Process PIN_Code_Request event */ -static int -process_pin_code_request_event(int sock, struct sockaddr_hci *addr, - bdaddr_p bdaddr) -{ - link_key_p key = NULL; - - syslog(LOG_DEBUG, "Got PIN_Code_Request event from '%s', " \ - "remote bdaddr %s", addr->hci_node, - bt_ntoa(bdaddr, NULL)); - - if ((key = get_key(bdaddr, 0)) != NULL) { - syslog(LOG_DEBUG, "Found matching entry, " \ - "remote bdaddr %s, name '%s', PIN code %s", - bt_ntoa(&key->bdaddr, NULL), - (key->name != NULL)? key->name : "No name", - (key->pin != NULL)? "exists" : "doesn't exist"); - - return (send_pin_code_reply(sock, addr, bdaddr, key->pin)); - } - - syslog(LOG_DEBUG, "Could not PIN code for remote bdaddr %s", - bt_ntoa(bdaddr, NULL)); - - return (send_pin_code_reply(sock, addr, bdaddr, NULL)); -} - -/* Process Link_Key_Request event */ -static int -process_link_key_request_event(int sock, struct sockaddr_hci *addr, - bdaddr_p bdaddr) -{ - link_key_p key = NULL; - - syslog(LOG_DEBUG, "Got Link_Key_Request event from '%s', " \ - "remote bdaddr %s", addr->hci_node, - bt_ntoa(bdaddr, NULL)); - - if ((key = get_key(bdaddr, 0)) != NULL) { - syslog(LOG_DEBUG, "Found matching entry, " \ - "remote bdaddr %s, name '%s', link key %s", - bt_ntoa(&key->bdaddr, NULL), - (key->name != NULL)? key->name : "No name", - (key->key != NULL)? "exists" : "doesn't exist"); - - return (send_link_key_reply(sock, addr, bdaddr, key->key)); - } - - syslog(LOG_DEBUG, "Could not find link key for remote bdaddr %s", - bt_ntoa(bdaddr, NULL)); - - return (send_link_key_reply(sock, addr, bdaddr, NULL)); -} - -/* Send PIN_Code_[Negative]_Reply */ -static int -send_pin_code_reply(int sock, struct sockaddr_hci *addr, - bdaddr_p bdaddr, char const *pin) -{ - uint8_t buffer[HCSECD_BUFFER_SIZE]; - ng_hci_cmd_pkt_t *cmd = NULL; - - memset(buffer, 0, sizeof(buffer)); - - cmd = (ng_hci_cmd_pkt_t *) buffer; - cmd->type = NG_HCI_CMD_PKT; - - if (pin != NULL) { - ng_hci_pin_code_rep_cp *cp = NULL; - - cmd->opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_PIN_CODE_REP)); - cmd->length = sizeof(*cp); - - cp = (ng_hci_pin_code_rep_cp *)(cmd + 1); - memcpy(&cp->bdaddr, bdaddr, sizeof(cp->bdaddr)); - strncpy((char *) cp->pin, pin, sizeof(cp->pin)); - cp->pin_size = strlen((char const *) cp->pin); - - syslog(LOG_DEBUG, "Sending PIN_Code_Reply to '%s' " \ - "for remote bdaddr %s", - addr->hci_node, bt_ntoa(bdaddr, NULL)); - } else { - ng_hci_pin_code_neg_rep_cp *cp = NULL; - - cmd->opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_PIN_CODE_NEG_REP)); - cmd->length = sizeof(*cp); - - cp = (ng_hci_pin_code_neg_rep_cp *)(cmd + 1); - memcpy(&cp->bdaddr, bdaddr, sizeof(cp->bdaddr)); - - syslog(LOG_DEBUG, "Sending PIN_Code_Negative_Reply to '%s' " \ - "for remote bdaddr %s", - addr->hci_node, bt_ntoa(bdaddr, NULL)); - } - -again: - if (sendto(sock, buffer, sizeof(*cmd) + cmd->length, 0, - (struct sockaddr *) addr, sizeof(*addr)) < 0) { - if (errno == EINTR) - goto again; - - syslog(LOG_ERR, "Could not send PIN code reply to '%s' " \ - "for remote bdaddr %s. %s (%d)", - addr->hci_node, bt_ntoa(bdaddr, NULL), - strerror(errno), errno); - return (-1); - } - - return (0); -} - -/* Send Link_Key_[Negative]_Reply */ -static int -send_link_key_reply(int sock, struct sockaddr_hci *addr, - bdaddr_p bdaddr, uint8_t *key) -{ - uint8_t buffer[HCSECD_BUFFER_SIZE]; - ng_hci_cmd_pkt_t *cmd = NULL; - - memset(buffer, 0, sizeof(buffer)); - - cmd = (ng_hci_cmd_pkt_t *) buffer; - cmd->type = NG_HCI_CMD_PKT; - - if (key != NULL) { - ng_hci_link_key_rep_cp *cp = NULL; - - cmd->opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_LINK_KEY_REP)); - cmd->length = sizeof(*cp); - - cp = (ng_hci_link_key_rep_cp *)(cmd + 1); - memcpy(&cp->bdaddr, bdaddr, sizeof(cp->bdaddr)); - memcpy(&cp->key, key, sizeof(cp->key)); - - syslog(LOG_DEBUG, "Sending Link_Key_Reply to '%s' " \ - "for remote bdaddr %s", - addr->hci_node, bt_ntoa(bdaddr, NULL)); - } else { - ng_hci_link_key_neg_rep_cp *cp = NULL; - - cmd->opcode = htole16(NG_HCI_OPCODE(NG_HCI_OGF_LINK_CONTROL, - NG_HCI_OCF_LINK_KEY_NEG_REP)); - cmd->length = sizeof(*cp); - - cp = (ng_hci_link_key_neg_rep_cp *)(cmd + 1); - memcpy(&cp->bdaddr, bdaddr, sizeof(cp->bdaddr)); - - syslog(LOG_DEBUG, "Sending Link_Key_Negative_Reply to '%s' " \ - "for remote bdaddr %s", - addr->hci_node, bt_ntoa(bdaddr, NULL)); - } - -again: - if (sendto(sock, buffer, sizeof(*cmd) + cmd->length, 0, - (struct sockaddr *) addr, sizeof(*addr)) < 0) { - if (errno == EINTR) - goto again; - - syslog(LOG_ERR, "Could not send link key reply to '%s' " \ - "for remote bdaddr %s. %s (%d)", - addr->hci_node, bt_ntoa(bdaddr, NULL), - strerror(errno), errno); - return (-1); - } - - return (0); -} - -/* Process Link_Key_Notification event */ -static int -process_link_key_notification_event(int sock, struct sockaddr_hci *addr, - ng_hci_link_key_notification_ep *ep) -{ - link_key_p key = NULL; - - syslog(LOG_DEBUG, "Got Link_Key_Notification event from '%s', " \ - "remote bdaddr %s", addr->hci_node, - bt_ntoa(&ep->bdaddr, NULL)); - - if ((key = get_key(&ep->bdaddr, 1)) == NULL) { - syslog(LOG_ERR, "Could not find entry for remote bdaddr %s", - bt_ntoa(&ep->bdaddr, NULL)); - return (-1); - } - - syslog(LOG_DEBUG, "Updating link key for the entry, " \ - "remote bdaddr %s, name '%s', link key %s", - bt_ntoa(&key->bdaddr, NULL), - (key->name != NULL)? key->name : "No name", - (key->key != NULL)? "exists" : "doesn't exist"); - - if (key->key == NULL) { - key->key = (uint8_t *) malloc(NG_HCI_KEY_SIZE); - if (key->key == NULL) { - syslog(LOG_ERR, "Could not allocate link key"); - exit(1); - } - } - - memcpy(key->key, &ep->key, NG_HCI_KEY_SIZE); - - return (0); -} - -/* Signal handlers */ -static void -sighup(int s) -{ - syslog(LOG_DEBUG, "Got SIGHUP (%d)", s); - - dump_keys_file(); - read_config_file(); - read_keys_file(); -} - -static void -sigint(int s) -{ - syslog(LOG_DEBUG, "Got signal %d, total number of signals %d", - s, ++ done); -} - -/* Display usage and exit */ -static void -usage(void) -{ - fprintf(stderr, -"Usage: %s [-d] -f config_file [-h]\n" \ -"Where:\n" \ -"\t-d do not detach from terminal\n" \ -"\t-f config_file use \n" \ -"\t-h display this message\n", HCSECD_IDENT); - - exit(255); -} - diff --git a/usr.sbin/bluetooth/hcsecd/hcsecd.conf b/usr.sbin/bluetooth/hcsecd/hcsecd.conf deleted file mode 100644 index 127ce04..0000000 --- a/usr.sbin/bluetooth/hcsecd/hcsecd.conf +++ /dev/null @@ -1,64 +0,0 @@ -# -# $Id: hcsecd.conf,v 1.1 2002/11/24 20:22:39 max Exp $ -# $FreeBSD$ -# -# HCI security daemon configuration file -# -# Format: -# -# device { -# option value ; -# } -# -# Possible options and values -# -# Options Values -# ---------------------------------- -# bdaddr xx:xx:xx:xx:xx:xx ; - remote device BD_ADDR -# name "any char" ; - to set user friendly device name -# key 0x11223344 | nokey ; - to set link key for the device -# pin "secret" | nopin ; - to PIN code for the device -# -# Notes: -# -# Currently there is no way to select keys/PIN code based on which -# local device received the request. Everything is based on remote -# device BD_ADDR. -# -# "nokey" means that no link key has been defined and we should -# send Link_Key_Negative_Reply command to the device. -# -# "nopin" means that no PIN code has been defined and we should -# send PIN_Code_Negative_Reply command to the device -# - -# Default entry applied if no better match found -# It MUST have 00:00:00:00:00:00 as bdaddr -device { - bdaddr 00:00:00:00:00:00; - name "Default entry"; - key nokey; - pin nopin; -} - -device { - bdaddr 00:80:37:5e:4d:d4; - name "Ericsson T68 phone"; - key nokey; - pin "0000"; # PIN code (string up to 16 character) -} - -device { - bdaddr 00:01:03:fc:6e:ec; - name "3COM PCCARD"; - key nokey; - pin "0000"; -} - -device { - bdaddr 00:11:22:33:44:55; - name "Dummy"; - key 0x00112233445566778899aabbccddeeff; # 16 bytes key (hex string) - pin nopin; -} - diff --git a/usr.sbin/bluetooth/hcsecd/hcsecd.conf.5 b/usr.sbin/bluetooth/hcsecd/hcsecd.conf.5 deleted file mode 100644 index 189ca66..0000000 --- a/usr.sbin/bluetooth/hcsecd/hcsecd.conf.5 +++ /dev/null @@ -1,131 +0,0 @@ -.\" Copyright (c) 2001-2002 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: hcsecd.conf.5,v 1.1 2003/05/26 22:49:23 max Exp $ -.\" $FreeBSD$ -.\" -.Dd May 26, 2003 -.Dt HCSECD.CONF 5 -.Os -.Sh NAME -.Nm hcsecd.conf -.Nd -.Xr hcsecd 8 -configuration file -.Sh DESCRIPTION -The -.Nm -file is the configuration file for the -.Xr hcsecd 8 -Bluetooth link keys/PIN codes management daemon. -.Pp -The -.Nm -file is a free-form -.Tn ASCII -text file. -It is parsed by the recursive-descent parser built into -.Xr hcsecd 8 . -The file may contain extra tabs and newlines for formatting purposes. -Keywords in the file are case-sensitive. -Comments may be placed anywhere within the file (except within quotes). -Comments begin with the -.Ql # -character and end at the end of the line. -.Sh FILE FORMAT -The -.Nm -file consists of a list of -.Cm device -entries. -Each -.Cm device -entry defines a link key or PIN code for a remote Bluetooth device. -Each remote Bluetooth device is identified by its unique BD_ADDR. -.Pp -The -.Cm device -entry -.Pp -.Cm device -{ -.Cm option Ar argument ; -.Oo -.Cm option Ar argument ; -.Oc -} -.Pp -The following section describes all supported options and arguments. -.Bl -tag -width indent -.It Cm bdaddr Ar BD_ADDR -Specify remote device BD_ADDR for the entry. -.It Cm name Ar device_name -Specify user friendly name for the entry. -Name is a string in straight double quotes. -.It Cm key Ar link_key -Specify link key for the entry. -Link key is hexadecimal string up to 32 characters in length starting with -.Ql 0x . -.It Cm key nokey -Specify no link key for the entry. -.It Cm pin Ar PIN_code -Specify PIN code for the entry. -PIN code is a string up to 16 characters in length in straight double quotes. -.It Cm pin nopin -Specify no PIN code for the entry. -.El -.Sh EXAMPLES -A sample -.Nm -file: -.Bd -literal -# Default entry is applied if no better match found -# It MUST have 00:00:00:00:00:00 as bdaddr -device { - bdaddr 00:00:00:00:00:00; - name "Default entry"; - key nokey; - pin nopin; -} - -# Ericsson T68 phone -device { - bdaddr 00:80:37:5e:4d:d4; - name "Ericsson T68 phone"; - key nokey; - pin "0000"; # PIN code -} - -# Dummy device -device { - bdaddr 00:11:22:33:44:55; - name "Dummy"; - key 0x00112233445566778899aabbccddeeff; # 16 bytes key - pin nopin; -} -.Ed -.Sh SEE ALSO -.Xr hcsecd 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com diff --git a/usr.sbin/bluetooth/hcsecd/hcsecd.h b/usr.sbin/bluetooth/hcsecd/hcsecd.h deleted file mode 100644 index acfc887..0000000 --- a/usr.sbin/bluetooth/hcsecd/hcsecd.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * hcsecd.h - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: hcsecd.h,v 1.3 2003/09/08 18:54:21 max Exp $ - * $FreeBSD$ - */ - -#ifndef _HCSECD_H_ -#define _HCSECD_H_ 1 - -#define HCSECD_BUFFER_SIZE 512 -#define HCSECD_IDENT "hcsecd" -#define HCSECD_PIDFILE "/var/run/" HCSECD_IDENT ".pid" -#define HCSECD_KEYSFILE "/var/db/" HCSECD_IDENT ".keys" - -struct link_key -{ - bdaddr_t bdaddr; /* remote device BDADDR */ - char *name; /* remote device name */ - uint8_t *key; /* link key (or NULL if no key) */ - char *pin; /* pin (or NULL if no pin) */ - LIST_ENTRY(link_key) next; /* link to the next */ -}; -typedef struct link_key link_key_t; -typedef struct link_key * link_key_p; - -extern char *config_file; - -#if __config_debug__ -void dump_config (void); -#endif - -void read_config_file(void); -void clean_config (void); -link_key_p get_key (bdaddr_p bdaddr, int exact_match); - -int read_keys_file (void); -int dump_keys_file (void); - -#endif /* ndef _HCSECD_H_ */ - diff --git a/usr.sbin/bluetooth/hcsecd/lexer.l b/usr.sbin/bluetooth/hcsecd/lexer.l deleted file mode 100644 index 2430d7e..0000000 --- a/usr.sbin/bluetooth/hcsecd/lexer.l +++ /dev/null @@ -1,95 +0,0 @@ -%{ -/* - * lexer.l - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: lexer.l,v 1.1 2002/11/24 20:22:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include "parser.h" -%} - -%option yylineno noyywrap nounput - -delim [ \t\n] -ws {delim}+ -empty {delim}* -comment \#.* - -hexdigit [0-9a-fA-F] -hexbyte {hexdigit}{hexdigit} - -device_word device -bdaddr_word bdaddr -name_word name -key_word key -nokey_word nokey -pin_word pin -nopin_word nopin - -bdaddrstring {hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte}:{hexbyte} -hexstring 0x{hexbyte}+ -string \".+\" - -%% - -\; return (';'); -\: return (':'); -\{ return ('{'); -\} return ('}'); - -{ws} ; -{empty} ; -{comment} ; - -{device_word} return (T_DEVICE); -{bdaddr_word} return (T_BDADDR); -{name_word} return (T_NAME); -{key_word} return (T_KEY); -{nokey_word} return (T_NOKEY); -{pin_word} return (T_PIN); -{nopin_word} return (T_NOPIN); - -{bdaddrstring} { - yylval.string = yytext; - return (T_BDADDRSTRING); - } - -{hexstring} { - yylval.string = &yytext[2]; - return (T_HEXSTRING); - } - -{string} { - yytext[strlen(yytext) - 1] = 0; - yylval.string = &yytext[1]; - return (T_STRING); - } - -%% - diff --git a/usr.sbin/bluetooth/hcsecd/parser.y b/usr.sbin/bluetooth/hcsecd/parser.y deleted file mode 100644 index 385bff2..0000000 --- a/usr.sbin/bluetooth/hcsecd/parser.y +++ /dev/null @@ -1,433 +0,0 @@ -%{ -/* - * parser.y - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: parser.y,v 1.5 2003/06/07 21:22:30 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "hcsecd.h" - - int yyparse (void); - int yylex (void); - -static void free_key (link_key_p key); -static int hexa2int4(char *a); -static int hexa2int8(char *a); - -extern int yylineno; -static LIST_HEAD(, link_key) link_keys; - char *config_file = "/etc/bluetooth/hcsecd.conf"; - -static link_key_p key = NULL; -%} - -%union { - char *string; -} - -%token T_BDADDRSTRING T_HEXSTRING T_STRING -%token T_DEVICE T_BDADDR T_NAME T_KEY T_PIN T_NOKEY T_NOPIN T_JUNK - -%% - -config: line - | config line - ; - -line: T_DEVICE - { - key = (link_key_p) malloc(sizeof(*key)); - if (key == NULL) { - syslog(LOG_ERR, "Could not allocate new " \ - "config entry"); - exit(1); - } - - memset(key, 0, sizeof(*key)); - } - '{' options '}' - { - if (get_key(&key->bdaddr, 1) != NULL) { - syslog(LOG_ERR, "Ignoring duplicated entry " \ - "for bdaddr %s", - bt_ntoa(&key->bdaddr, NULL)); - free_key(key); - } else - LIST_INSERT_HEAD(&link_keys, key, next); - - key = NULL; - } - ; - -options: option ';' - | options option ';' - ; - -option: bdaddr - | name - | key - | pin - ; - -bdaddr: T_BDADDR T_BDADDRSTRING - { - if (!bt_aton($2, &key->bdaddr)) { - syslog(LOG_ERR, "Cound not parse BD_ADDR " \ - "'%s'", $2); - exit(1); - } - } - ; - -name: T_NAME T_STRING - { - if (key->name != NULL) - free(key->name); - - key->name = strdup($2); - if (key->name == NULL) { - syslog(LOG_ERR, "Could not allocate new " \ - "device name"); - exit(1); - } - } - ; - -key: T_KEY T_HEXSTRING - { - int i, len; - - if (key->key != NULL) - free(key->key); - - key->key = (uint8_t *) malloc(NG_HCI_KEY_SIZE); - if (key->key == NULL) { - syslog(LOG_ERR, "Could not allocate new " \ - "link key"); - exit(1); - } - - memset(key->key, 0, NG_HCI_KEY_SIZE); - - len = strlen($2) / 2; - if (len > NG_HCI_KEY_SIZE) - len = NG_HCI_KEY_SIZE; - - for (i = 0; i < len; i ++) - key->key[i] = hexa2int8((char *)($2) + 2*i); - } - | T_KEY T_NOKEY - { - if (key->key != NULL) - free(key->key); - - key->key = NULL; - } - ; - -pin: T_PIN T_STRING - { - if (key->pin != NULL) - free(key->pin); - - key->pin = strdup($2); - if (key->pin == NULL) { - syslog(LOG_ERR, "Could not allocate new " \ - "PIN code"); - exit(1); - } - } - | T_PIN T_NOPIN - { - if (key->pin != NULL) - free(key->pin); - - key->pin = NULL; - } - ; - -%% - -/* Display parser error message */ -void -yyerror(char const *message) -{ - syslog(LOG_ERR, "%s in line %d", message, yylineno); -} - -/* Re-read config file */ -void -read_config_file(void) -{ - extern FILE *yyin; - - if (config_file == NULL) { - syslog(LOG_ERR, "Unknown config file name!"); - exit(1); - } - - if ((yyin = fopen(config_file, "r")) == NULL) { - syslog(LOG_ERR, "Could not open config file '%s'. %s (%d)", - config_file, strerror(errno), errno); - exit(1); - } - - clean_config(); - if (yyparse() < 0) { - syslog(LOG_ERR, "Could not parse config file '%s'",config_file); - exit(1); - } - - fclose(yyin); - yyin = NULL; - -#if __config_debug__ - dump_config(); -#endif -} - -/* Clean config */ -void -clean_config(void) -{ - link_key_p key = NULL; - - while ((key = LIST_FIRST(&link_keys)) != NULL) { - LIST_REMOVE(key, next); - free_key(key); - } -} - -/* Find link key entry in the list. Return exact or default match */ -link_key_p -get_key(bdaddr_p bdaddr, int exact_match) -{ - link_key_p key = NULL, defkey = NULL; - - LIST_FOREACH(key, &link_keys, next) { - if (memcmp(bdaddr, &key->bdaddr, sizeof(key->bdaddr)) == 0) - break; - - if (!exact_match) - if (memcmp(NG_HCI_BDADDR_ANY, &key->bdaddr, - sizeof(key->bdaddr)) == 0) - defkey = key; - } - - return ((key != NULL)? key : defkey); -} - -#if __config_debug__ -/* Dump config */ -void -dump_config(void) -{ - link_key_p key = NULL; - char buffer[64]; - - LIST_FOREACH(key, &link_keys, next) { - if (key->key != NULL) - snprintf(buffer, sizeof(buffer), -"0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - key->key[0], key->key[1], key->key[2], - key->key[3], key->key[4], key->key[5], - key->key[6], key->key[7], key->key[8], - key->key[9], key->key[10], key->key[11], - key->key[12], key->key[13], key->key[14], - key->key[15]); - - syslog(LOG_DEBUG, -"device %s " \ -"bdaddr %s " \ -"pin %s " \ -"key %s", - (key->name != NULL)? key->name : "noname", - bt_ntoa(&key->bdaddr, NULL), - (key->pin != NULL)? key->pin : "nopin", - (key->key != NULL)? buffer : "nokey"); - } -} -#endif - -/* Read keys file */ -int -read_keys_file(void) -{ - FILE *f = NULL; - link_key_t *key = NULL; - char buf[HCSECD_BUFFER_SIZE], *p = NULL, *cp = NULL; - bdaddr_t bdaddr; - int i, len; - - if ((f = fopen(HCSECD_KEYSFILE, "r")) == NULL) { - if (errno == ENOENT) - return (0); - - syslog(LOG_ERR, "Could not open keys file %s. %s (%d)\n", - HCSECD_KEYSFILE, strerror(errno), errno); - - return (-1); - } - - while ((p = fgets(buf, sizeof(buf), f)) != NULL) { - if (*p == '#') - continue; - if ((cp = strpbrk(p, " ")) == NULL) - continue; - - *cp++ = '\0'; - - if (!bt_aton(p, &bdaddr)) - continue; - - if ((key = get_key(&bdaddr, 1)) == NULL) - continue; - - if (key->key == NULL) { - key->key = (uint8_t *) malloc(NG_HCI_KEY_SIZE); - if (key->key == NULL) { - syslog(LOG_ERR, "Could not allocate link key"); - exit(1); - } - } - - memset(key->key, 0, NG_HCI_KEY_SIZE); - - len = strlen(cp) / 2; - if (len > NG_HCI_KEY_SIZE) - len = NG_HCI_KEY_SIZE; - - for (i = 0; i < len; i ++) - key->key[i] = hexa2int8(cp + 2*i); - - syslog(LOG_DEBUG, "Restored link key for the entry, " \ - "remote bdaddr %s, name '%s'", - bt_ntoa(&key->bdaddr, NULL), - (key->name != NULL)? key->name : "No name"); - } - - fclose(f); - - return (0); -} - -/* Dump keys file */ -int -dump_keys_file(void) -{ - link_key_p key = NULL; - char tmp[PATH_MAX], buf[HCSECD_BUFFER_SIZE]; - int f; - - snprintf(tmp, sizeof(tmp), "%s.tmp", HCSECD_KEYSFILE); - if ((f = open(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600)) < 0) { - syslog(LOG_ERR, "Could not create temp keys file %s. %s (%d)\n", - tmp, strerror(errno), errno); - return (-1); - } - - LIST_FOREACH(key, &link_keys, next) { - if (key->key == NULL) - continue; - - snprintf(buf, sizeof(buf), -"%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", - bt_ntoa(&key->bdaddr, NULL), - key->key[0], key->key[1], key->key[2], key->key[3], - key->key[4], key->key[5], key->key[6], key->key[7], - key->key[8], key->key[9], key->key[10], key->key[11], - key->key[12], key->key[13], key->key[14], key->key[15]); - - if (write(f, buf, strlen(buf)) < 0) { - syslog(LOG_ERR, "Could not write temp keys file. " \ - "%s (%d)\n", strerror(errno), errno); - break; - } - } - - close(f); - - if (rename(tmp, HCSECD_KEYSFILE) < 0) { - syslog(LOG_ERR, "Could not rename(%s, %s). %s (%d)\n", - tmp, HCSECD_KEYSFILE, strerror(errno), errno); - unlink(tmp); - return (-1); - } - - return (0); -} - -/* Free key entry */ -static void -free_key(link_key_p key) -{ - if (key->name != NULL) - free(key->name); - if (key->key != NULL) - free(key->key); - if (key->pin != NULL) - free(key->pin); - - memset(key, 0, sizeof(*key)); - free(key); -} - -/* Convert hex ASCII to int4 */ -static int -hexa2int4(char *a) -{ - if ('0' <= *a && *a <= '9') - return (*a - '0'); - - if ('A' <= *a && *a <= 'F') - return (*a - 'A' + 0xa); - - if ('a' <= *a && *a <= 'f') - return (*a - 'a' + 0xa); - - syslog(LOG_ERR, "Invalid hex character: '%c' (%#x)", *a, *a); - exit(1); -} - -/* Convert hex ASCII to int8 */ -static int -hexa2int8(char *a) -{ - return ((hexa2int4(a) << 4) | hexa2int4(a + 1)); -} - diff --git a/usr.sbin/bluetooth/hcseriald/Makefile b/usr.sbin/bluetooth/hcseriald/Makefile deleted file mode 100644 index ed0bf32..0000000 --- a/usr.sbin/bluetooth/hcseriald/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $Id: Makefile,v 1.5 2003/08/14 20:06:21 max Exp $ -# $FreeBSD$ - -PROG= hcseriald -MAN= hcseriald.8 -WARNS?= 2 - -DPADD= ${LIBNETGRAPH} -LDADD= -lnetgraph - -.include diff --git a/usr.sbin/bluetooth/hcseriald/hcseriald.8 b/usr.sbin/bluetooth/hcseriald/hcseriald.8 deleted file mode 100644 index 111b28c..0000000 --- a/usr.sbin/bluetooth/hcseriald/hcseriald.8 +++ /dev/null @@ -1,86 +0,0 @@ -.\" Copyright (c) 2001-2002 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: hcseriald.8,v 1.3 2003/05/21 00:47:26 max Exp $ -.\" $FreeBSD$ -.\" -.Dd June 14, 2002 -.Dt HCSERIALD 8 -.Os -.Sh NAME -.Nm hcseriald -.Nd supervise serial Bluetooth devices -.Sh SYNOPSIS -.Nm -.Op Fl dh -.Fl f Ar device -.Fl n Ar node_name -.Op Fl s Ar speed -.Sh DESCRIPTION -The -.Nm -utility handles serial Bluetooth devices. -It does one simple thing: -it opens the specified serial device, sets the device parameters, and pushes -the -.Dv H4 -line discipline. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl d -Do not disassociate from the controlling terminal, i.e., run in foreground. -.It Fl f Ar device -Callout device name. -Example: -.Fl f Pa /dev/cuad0 . -.It Fl h -Display usage message and exit. -.It Fl n Ar node_name -Set H4 Netgraph node name. -Example: -.Fl n Li sio0 . -.It Fl s Ar speed -Set serial device speed to -.Ar speed . -Example: -.Fl s Li 115200 . -.El -.Sh FILES -.Bl -tag -width ".Pa /var/run/hcserial. Ns Ar * Ns Pa .pid" -compact -.It Pa /var/run/hcserial. Ns Ar * Ns Pa .pid -Process ID of the currently running -.Nm -daemon. -Where -.Ar * -is an H4 Netgraph node name. -.El -.Sh SEE ALSO -.Xr ng_h4 4 , -.Xr ng_hci 4 , -.Xr tty 4 , -.Xr hccontrol 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com diff --git a/usr.sbin/bluetooth/hcseriald/hcseriald.c b/usr.sbin/bluetooth/hcseriald/hcseriald.c deleted file mode 100644 index b811c1d..0000000 --- a/usr.sbin/bluetooth/hcseriald/hcseriald.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * hcseriald.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: hcseriald.c,v 1.3 2003/05/21 22:40:32 max Exp $ - * $FreeBSD$ - */ - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* Prototypes */ -static int open_device (char const *, speed_t, char const *); -static void sighandler (int); -static void usage (); - -static char const * const hcseriald = "hcseriald"; -static int done = 0; - -int -main(int argc, char *argv[]) -{ - char *device = NULL, *name = NULL; - speed_t speed = 115200; - int n, detach = 1; - char p[FILENAME_MAX]; - FILE *f = NULL; - struct sigaction sa; - - /* Process command line arguments */ - while ((n = getopt(argc, argv, "df:n:s:h")) != -1) { - switch (n) { - case 'd': - detach = 0; - break; - - case 'f': - device = optarg; - break; - - case 'n': - name = optarg; - break; - - case 's': - speed = atoi(optarg); - if (speed < 0) - usage(argv[0]); - break; - - case 'h': - default: - usage(argv[0]); - break; - } - } - - if (device == NULL || name == NULL) - usage(argv[0]); - - openlog(hcseriald, LOG_PID | LOG_NDELAY, LOG_USER); - - /* Open device */ - n = open_device(device, speed, name); - - if (detach && daemon(0, 0) < 0) { - syslog(LOG_ERR, "Could not daemon(0, 0). %s (%d)", - strerror(errno), errno); - exit(1); - } - - /* Write PID file */ - snprintf(p, sizeof(p), "/var/run/%s.%s.pid", hcseriald, name); - f = fopen(p, "w"); - if (f == NULL) { - syslog(LOG_ERR, "Could not fopen(%s). %s (%d)", - p, strerror(errno), errno); - exit(1); - } - fprintf(f, "%d", getpid()); - fclose(f); - - /* Install signal handler */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sighandler; - - if (sigaction(SIGTERM, &sa, NULL) < 0) { - syslog(LOG_ERR, "Could not sigaction(SIGTERM). %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (sigaction(SIGHUP, &sa, NULL) < 0) { - syslog(LOG_ERR, "Could not sigaction(SIGHUP). %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (sigaction(SIGINT, &sa, NULL) < 0) { - syslog(LOG_ERR, "Could not sigaction(SIGINT). %s (%d)", - strerror(errno), errno); - exit(1); - } - - /* Keep running */ - while (!done) - select(0, NULL, NULL, NULL, NULL); - - /* Remove PID file and close device */ - unlink(p); - close(n); - closelog(); - - return (0); -} /* main */ - -/* Open terminal, set settings, push H4 line discipline and set node name */ -static int -open_device(char const *device, speed_t speed, char const *name) -{ - int fd, disc, cs, ds; - struct termios t; - struct nodeinfo ni; - struct ngm_name n; - char p[NG_NODESIZ]; - - /* Open terminal device and setup H4 line discipline */ - fd = open(device, O_RDWR|O_NOCTTY); - if (fd < 0) { - syslog(LOG_ERR, "Could not open(%s). %s (%d)", - device, strerror(errno), errno); - exit(1); - } - - tcflush(fd, TCIOFLUSH); - - if (tcgetattr(fd, &t) < 0) { - syslog(LOG_ERR, "Could not tcgetattr(%s). %s (%d)", - device, strerror(errno), errno); - exit(1); - } - - cfmakeraw(&t); - - t.c_cflag |= CLOCAL; /* clocal */ - t.c_cflag &= ~CSIZE; /* cs8 */ - t.c_cflag |= CS8; /* cs8 */ - t.c_cflag &= ~PARENB; /* -parenb */ - t.c_cflag &= ~CSTOPB; /* -cstopb */ - t.c_cflag |= CRTSCTS; /* crtscts */ - - if (tcsetattr(fd, TCSANOW, &t) < 0) { - syslog(LOG_ERR, "Could not tcsetattr(%s). %s (%d)", - device, strerror(errno), errno); - exit(1); - } - - tcflush(fd, TCIOFLUSH); - - if (cfsetspeed(&t, speed) < 0) { - syslog(LOG_ERR, "Could not cfsetspeed(%s). %s (%d)", - device, strerror(errno), errno); - exit(1); - } - - if (tcsetattr(fd, TCSANOW, &t) < 0) { - syslog(LOG_ERR, "Could not tcsetattr(%s). %s (%d)", - device, strerror(errno), errno); - exit(1); - } - - disc = H4DISC; - if (ioctl(fd, TIOCSETD, &disc) < 0) { - syslog(LOG_ERR, "Could not ioctl(%s, TIOCSETD, %d). %s (%d)", - device, disc, strerror(errno), errno); - exit(1); - } - - /* Get default name of the Netgraph node */ - memset(&ni, 0, sizeof(ni)); - if (ioctl(fd, NGIOCGINFO, &ni) < 0) { - syslog(LOG_ERR, "Could not ioctl(%d, NGIOGINFO). %s (%d)", - fd, strerror(errno), errno); - exit(1); - } - - /* Assign new name to the Netgraph node */ - snprintf(p, sizeof(p), "%s:", ni.name); - snprintf(n.name, sizeof(n.name), "%s", name); - - if (NgMkSockNode(NULL, &cs, &ds) < 0) { - syslog(LOG_ERR, "Could not NgMkSockNode(). %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (NgSendMsg(cs, p, NGM_GENERIC_COOKIE, NGM_NAME, &n, sizeof(n)) < 0) { - syslog(LOG_ERR, "Could not NgSendMsg(%d, %s, NGM_NAME, %s). " \ - "%s (%d)", cs, p, n.name, strerror(errno), errno); - exit(1); - } - - close(cs); - close(ds); - - return (fd); -} /* open_device */ - -/* Signal handler */ -static void -sighandler(int s) -{ - done = 1; -} /* sighandler */ - -/* Usage */ -static void -usage(void) -{ - fprintf(stderr, "Usage: %s -f device -n node_name [-s speed -d -h]\n" \ - "Where:\n" \ - "\t-f device tty device name, ex. /dev/cuad1\n" \ - "\t-n node_name set Netgraph node name to node_name\n" \ - "\t-s speed set tty speed, ex. 115200\n" \ - "\t-d run in foreground\n" \ - "\t-h display this message\n", - hcseriald); - exit(255); -} /* usage */ - diff --git a/usr.sbin/bluetooth/l2control/Makefile b/usr.sbin/bluetooth/l2control/Makefile deleted file mode 100644 index 847ff4b..0000000 --- a/usr.sbin/bluetooth/l2control/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $Id: Makefile,v 1.7 2003/08/14 20:06:22 max Exp $ -# $FreeBSD$ - -PROG= l2control -MAN= l2control.8 -SRCS= l2cap.c l2control.c -WARNS?= 2 - -DPADD= ${LIBBLUETOOTH} -LDADD= -lbluetooth - -.include diff --git a/usr.sbin/bluetooth/l2control/l2cap.c b/usr.sbin/bluetooth/l2control/l2cap.c deleted file mode 100644 index c23106c..0000000 --- a/usr.sbin/bluetooth/l2control/l2cap.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * l2cap.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: l2cap.c,v 1.5 2003/05/16 19:52:37 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include "l2control.h" - -#define SIZE(x) (sizeof((x))/sizeof((x)[0])) - -/* Print BDADDR */ -static char * -bdaddrpr(bdaddr_t const *ba) -{ - extern int numeric_bdaddr; - static char str[24]; - struct hostent *he = NULL; - - if (memcmp(ba, NG_HCI_BDADDR_ANY, sizeof(*ba)) == 0) { - str[0] = '*'; - str[1] = 0; - - return (str); - } - - if (!numeric_bdaddr && - (he = bt_gethostbyaddr((char *)ba, sizeof(*ba), AF_BLUETOOTH)) != NULL) { - strlcpy(str, he->h_name, sizeof(str)); - - return (str); - } - - bt_ntoa(ba, str); - - return (str); -} /* bdaddrpr */ - -/* Send read_node_flags command to the node */ -static int -l2cap_read_node_flags(int s, int argc, char **argv) -{ - struct ng_btsocket_l2cap_raw_node_flags r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_L2CAP_NODE_GET_FLAGS, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Connectionless traffic flags:\n"); - fprintf(stdout, "\tSDP: %s\n", - (r.flags & NG_L2CAP_CLT_SDP_DISABLED)? "disabled" : "enabled"); - fprintf(stdout, "\tRFCOMM: %s\n", - (r.flags & NG_L2CAP_CLT_RFCOMM_DISABLED)? "disabled":"enabled"); - fprintf(stdout, "\tTCP: %s\n", - (r.flags & NG_L2CAP_CLT_TCP_DISABLED)? "disabled" : "enabled"); - - return (OK); -} /* l2cap_read_node_flags */ - -/* Send read_debug_level command to the node */ -static int -l2cap_read_debug_level(int s, int argc, char **argv) -{ - struct ng_btsocket_l2cap_raw_node_debug r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_L2CAP_NODE_GET_DEBUG, &r, sizeof(r)) < 0) - return (ERROR); - - fprintf(stdout, "Debug level: %d\n", r.debug); - - return (OK); -} /* l2cap_read_debug_level */ - -/* Send write_debug_level command to the node */ -static int -l2cap_write_debug_level(int s, int argc, char **argv) -{ - struct ng_btsocket_l2cap_raw_node_debug r; - - memset(&r, 0, sizeof(r)); - switch (argc) { - case 1: - r.debug = atoi(argv[0]); - break; - - default: - return (USAGE); - } - - if (ioctl(s, SIOC_L2CAP_NODE_SET_DEBUG, &r, sizeof(r)) < 0) - return (ERROR); - - return (OK); -} /* l2cap_write_debug_level */ - -/* Send read_connection_list command to the node */ -static int -l2cap_read_connection_list(int s, int argc, char **argv) -{ - static char const * const state[] = { - /* NG_L2CAP_CON_CLOSED */ "CLOSED", - /* NG_L2CAP_W4_LP_CON_CFM */ "W4_LP_CON_CFM", - /* NG_L2CAP_CON_OPEN */ "OPEN" - }; -#define con_state2str(x) ((x) >= SIZE(state)? "UNKNOWN" : state[(x)]) - - struct ng_btsocket_l2cap_raw_con_list r; - int n, error = OK; - - memset(&r, 0, sizeof(r)); - r.num_connections = NG_L2CAP_MAX_CON_NUM; - r.connections = calloc(NG_L2CAP_MAX_CON_NUM, - sizeof(ng_l2cap_node_con_ep)); - if (r.connections == NULL) { - errno = ENOMEM; - return (ERROR); - } - - if (ioctl(s, SIOC_L2CAP_NODE_GET_CON_LIST, &r, sizeof(r)) < 0) { - error = ERROR; - goto out; - } - - fprintf(stdout, "L2CAP connections:\n"); - fprintf(stdout, -"Remote BD_ADDR Handle Flags Pending State\n"); - for (n = 0; n < r.num_connections; n++) { - fprintf(stdout, - "%-17.17s " \ - "%6d " \ - "%c%c%c%c%c " \ - "%7d " \ - "%s\n", - bdaddrpr(&r.connections[n].remote), - r.connections[n].con_handle, - ((r.connections[n].flags & NG_L2CAP_CON_OUTGOING)? 'O' : 'I'), - ((r.connections[n].flags & NG_L2CAP_CON_LP_TIMO)? 'L' : ' '), - ((r.connections[n].flags & NG_L2CAP_CON_AUTO_DISCON_TIMO)? 'D' : ' '), - ((r.connections[n].flags & NG_L2CAP_CON_TX)? 'T' : ' '), - ((r.connections[n].flags & NG_L2CAP_CON_RX)? 'R' : ' '), - r.connections[n].pending, - con_state2str(r.connections[n].state)); - } -out: - free(r.connections); - - return (error); -} /* l2cap_read_connection_list */ - -/* Send read_channel_list command to the node */ -static int -l2cap_read_channel_list(int s, int argc, char **argv) -{ - static char const * const state[] = { - /* NG_L2CAP_CLOSED */ "CLOSED", - /* NG_L2CAP_W4_L2CAP_CON_RSP */ "W4_L2CAP_CON_RSP", - /* NG_L2CAP_W4_L2CA_CON_RSP */ "W4_L2CA_CON_RSP", - /* NG_L2CAP_CONFIG */ "CONFIG", - /* NG_L2CAP_OPEN */ "OPEN", - /* NG_L2CAP_W4_L2CAP_DISCON_RSP */ "W4_L2CAP_DISCON_RSP", - /* NG_L2CAP_W4_L2CA_DISCON_RSP */ "W4_L2CA_DISCON_RSP" - }; -#define ch_state2str(x) ((x) >= SIZE(state)? "UNKNOWN" : state[(x)]) - - struct ng_btsocket_l2cap_raw_chan_list r; - int n, error = OK; - - memset(&r, 0, sizeof(r)); - r.num_channels = NG_L2CAP_MAX_CHAN_NUM; - r.channels = calloc(NG_L2CAP_MAX_CHAN_NUM, - sizeof(ng_l2cap_node_chan_ep)); - if (r.channels == NULL) { - errno = ENOMEM; - return (ERROR); - } - - if (ioctl(s, SIOC_L2CAP_NODE_GET_CHAN_LIST, &r, sizeof(r)) < 0) { - error = ERROR; - goto out; - } - - fprintf(stdout, "L2CAP channels:\n"); - fprintf(stdout, -"Remote BD_ADDR SCID/ DCID PSM IMTU/ OMTU State\n"); - for (n = 0; n < r.num_channels; n++) { - fprintf(stdout, - "%-17.17s " \ - "%5d/%5d %5d " \ - "%5d/%5d " \ - "%s\n", - bdaddrpr(&r.channels[n].remote), - r.channels[n].scid, r.channels[n].dcid, - r.channels[n].psm, r.channels[n].imtu, - r.channels[n].omtu, - ch_state2str(r.channels[n].state)); - } -out: - free(r.channels); - - return (error); -} /* l2cap_read_channel_list */ - -/* Send read_auto_disconnect_timeout command to the node */ -static int -l2cap_read_auto_disconnect_timeout(int s, int argc, char **argv) -{ - struct ng_btsocket_l2cap_raw_auto_discon_timo r; - - memset(&r, 0, sizeof(r)); - if (ioctl(s, SIOC_L2CAP_NODE_GET_AUTO_DISCON_TIMO, &r, sizeof(r)) < 0) - return (ERROR); - - if (r.timeout != 0) - fprintf(stdout, "Auto disconnect timeout: %d sec\n", r.timeout); - else - fprintf(stdout, "Auto disconnect disabled\n"); - - return (OK); -} /* l2cap_read_auto_disconnect_timeout */ - -/* Send write_auto_disconnect_timeout command to the node */ -static int -l2cap_write_auto_disconnect_timeout(int s, int argc, char **argv) -{ - struct ng_btsocket_l2cap_raw_auto_discon_timo r; - - memset(&r, 0, sizeof(r)); - switch (argc) { - case 1: - r.timeout = atoi(argv[0]); - break; - - default: - return (USAGE); - } - - if (ioctl(s, SIOC_L2CAP_NODE_SET_AUTO_DISCON_TIMO, &r, sizeof(r)) < 0) - return (ERROR); - - return (OK); -} /* l2cap_write_auto_disconnect_timeout */ - -struct l2cap_command l2cap_commands[] = { -{ -"read_node_flags", -"Get L2CAP node flags", -&l2cap_read_node_flags -}, -{ -"read_debug_level", -"Get L2CAP node debug level", -&l2cap_read_debug_level -}, -{ -"write_debug_level ", -"Set L2CAP node debug level", -&l2cap_write_debug_level -}, -{ -"read_connection_list", -"Read list of the L2CAP connections", -&l2cap_read_connection_list -}, -{ -"read_channel_list", -"Read list of the L2CAP channels", -&l2cap_read_channel_list -}, -{ -"read_auto_disconnect_timeout", -"Get L2CAP node auto disconnect timeout (in sec)", -&l2cap_read_auto_disconnect_timeout -}, -{ -"write_auto_disconnect_timeout ", -"Set L2CAP node auto disconnect timeout (in sec)", -&l2cap_write_auto_disconnect_timeout -}, -{ -NULL, -}}; - diff --git a/usr.sbin/bluetooth/l2control/l2control.8 b/usr.sbin/bluetooth/l2control/l2control.8 deleted file mode 100644 index 794b6a7..0000000 --- a/usr.sbin/bluetooth/l2control/l2control.8 +++ /dev/null @@ -1,95 +0,0 @@ -.\" Copyright (c) 2001-2002 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: l2control.8,v 1.5 2003/05/21 00:53:00 max Exp $ -.\" $FreeBSD$ -.\" -.Dd June 14, 2002 -.Dt L2CONTROL 8 -.Os -.Sh NAME -.Nm l2control -.Nd L2CAP configuration utility -.Sh SYNOPSIS -.Nm -.Op Fl hn -.Fl a Ar BD_ADDR -.Ar command -.Op Ar parameters ... -.Sh DESCRIPTION -The -.Nm -utility connects to the local device with the specified BD_ADDR and attempts -to send the specified command. -The -.Nm -utility will print results to the standard output and error messages to -the standard error. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a Ar BD_ADDR -Connect to the local device with the specified BD_ADDR. -Example: -.Fl a Li 00:01:02:03:04:05 . -.It Fl h -Display usage message and exit. -.It Fl n -Show Bluetooth addresses as numbers. -Normally -.Nm -attempts to resolve Bluetooth addresses, and display them symbolically. -.It Ar command -One of the supported commands (see below). -Special command -.Cm help -can be used to obtain the list of all supported commands. -To get more information about specific command use -.Cm help Ar command . -.It Ar parameters -One or more optional space separated command parameters. -.El -.Sh COMMANDS -The currently supported node commands in -.Nm -are: -.Pp -.Bl -tag -offset indent -compact -.It Cm Read_Node_Flags -.It Cm Read_Debug_Level -.It Cm Write_Debug_Level -.It Cm Read_Connection_List -.It Cm Read_Channel_List -.It Cm Read_Auto_Disconnect_Timeout -.It Cm Write_Auto_Disconnect_Timeout -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr netgraph 3 , -.Xr netgraph 4 , -.Xr ng_l2cap 4 , -.Xr l2ping 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com diff --git a/usr.sbin/bluetooth/l2control/l2control.c b/usr.sbin/bluetooth/l2control/l2control.c deleted file mode 100644 index 585021c..0000000 --- a/usr.sbin/bluetooth/l2control/l2control.c +++ /dev/null @@ -1,213 +0,0 @@ -/* - * l2control.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: l2control.c,v 1.6 2003/09/05 00:38:25 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "l2control.h" - -/* Prototypes */ -static int do_l2cap_command (bdaddr_p, int, char **); -static struct l2cap_command * find_l2cap_command (char const *, - struct l2cap_command *); -static void print_l2cap_command (struct l2cap_command *); -static void usage (void); - -/* Main */ - -int numeric_bdaddr = 0; - -int -main(int argc, char *argv[]) -{ - int n; - bdaddr_t bdaddr; - - memset(&bdaddr, 0, sizeof(bdaddr)); - - /* Process command line arguments */ - while ((n = getopt(argc, argv, "a:nh")) != -1) { - switch (n) { - case 'a': - if (!bt_aton(optarg, &bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(1, "%s: %s", optarg, hstrerror(h_errno)); - - memcpy(&bdaddr, he->h_addr, sizeof(bdaddr)); - } - break; - - case 'n': - numeric_bdaddr = 1; - break; - - case 'h': - default: - usage(); - break; - } - } - - argc -= optind; - argv += optind; - - if (*argv == NULL) - usage(); - - return (do_l2cap_command(&bdaddr, argc, argv)); -} /* main */ - -/* Execute commands */ -static int -do_l2cap_command(bdaddr_p bdaddr, int argc, char **argv) -{ - char *cmd = argv[0]; - struct l2cap_command *c = NULL; - struct sockaddr_l2cap sa; - int s, e, help; - - help = 0; - if (strcasecmp(cmd, "help") == 0) { - argc --; - argv ++; - - if (argc <= 0) { - fprintf(stdout, "Supported commands:\n"); - print_l2cap_command(l2cap_commands); - fprintf(stdout, "\nFor more information use " \ - "'help command'\n"); - - return (OK); - } - - help = 1; - cmd = argv[0]; - } - - c = find_l2cap_command(cmd, l2cap_commands); - if (c == NULL) { - fprintf(stdout, "Unknown command: \"%s\"\n", cmd); - return (ERROR); - } - - if (!help) { - if (memcmp(bdaddr, NG_HCI_BDADDR_ANY, sizeof(*bdaddr)) == 0) - usage(); - - memset(&sa, 0, sizeof(sa)); - sa.l2cap_len = sizeof(sa); - sa.l2cap_family = AF_BLUETOOTH; - memcpy(&sa.l2cap_bdaddr, bdaddr, sizeof(sa.l2cap_bdaddr)); - - s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_L2CAP); - if (s < 0) - err(1, "Could not create socket"); - - if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) - err(2, -"Could not bind socket, bdaddr=%s", bt_ntoa(&sa.l2cap_bdaddr, NULL)); - - e = 0x0ffff; - if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &e, sizeof(e)) < 0) - err(3, "Coult not setsockopt(RCVBUF, %d)", e); - - e = (c->handler)(s, -- argc, ++ argv); - - close(s); - } else - e = USAGE; - - switch (e) { - case OK: - case FAILED: - break; - - case ERROR: - fprintf(stdout, "Could not execute command \"%s\". %s\n", - cmd, strerror(errno)); - break; - - case USAGE: - fprintf(stdout, "Usage: %s\n%s\n", c->command, c->description); - break; - - default: assert(0); break; - } - - return (e); -} /* do_l2cap_command */ - -/* Try to find command in specified category */ -static struct l2cap_command * -find_l2cap_command(char const *command, struct l2cap_command *category) -{ - struct l2cap_command *c = NULL; - - for (c = category; c->command != NULL; c++) { - char *c_end = strchr(c->command, ' '); - - if (c_end != NULL) { - int len = c_end - c->command; - - if (strncasecmp(command, c->command, len) == 0) - return (c); - } else if (strcasecmp(command, c->command) == 0) - return (c); - } - - return (NULL); -} /* find_l2cap_command */ - -/* Print commands in specified category */ -static void -print_l2cap_command(struct l2cap_command *category) -{ - struct l2cap_command *c = NULL; - - for (c = category; c->command != NULL; c++) - fprintf(stdout, "\t%s\n", c->command); -} /* print_l2cap_command */ - -/* Usage */ -static void -usage(void) -{ - fprintf(stdout, "Usage: l2control -a BD_ADDR [-n] [-h] cmd [p1] [..]]\n"); - exit(255); -} /* usage */ - diff --git a/usr.sbin/bluetooth/l2control/l2control.h b/usr.sbin/bluetooth/l2control/l2control.h deleted file mode 100644 index 43d4561..0000000 --- a/usr.sbin/bluetooth/l2control/l2control.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * l2control.h - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: l2control.h,v 1.1 2002/11/24 20:22:41 max Exp $ - * $FreeBSD$ - */ - -#ifndef _L2CONTROL_H_ -#define _L2CONTROL_H_ - -#define OK 0 /* everything was OK */ -#define ERROR 1 /* could not execute command */ -#define FAILED 2 /* error was reported */ -#define USAGE 3 /* invalid parameters */ - -struct l2cap_command { - char const *command; - char const *description; - int (*handler)(int, int, char **); -}; - -extern struct l2cap_command l2cap_commands[]; - -#endif /* _L2CONTROL_H_ */ - diff --git a/usr.sbin/bluetooth/l2ping/Makefile b/usr.sbin/bluetooth/l2ping/Makefile deleted file mode 100644 index bc130e3..0000000 --- a/usr.sbin/bluetooth/l2ping/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $Id: Makefile,v 1.6 2003/08/14 20:06:24 max Exp $ -# $FreeBSD$ - -PROG= l2ping -MAN= l2ping.8 -WARNS?= 2 - -DPADD= ${LIBBLUETOOTH} -LDADD= -lbluetooth - -.include diff --git a/usr.sbin/bluetooth/l2ping/l2ping.8 b/usr.sbin/bluetooth/l2ping/l2ping.8 deleted file mode 100644 index 477f4ec..0000000 --- a/usr.sbin/bluetooth/l2ping/l2ping.8 +++ /dev/null @@ -1,115 +0,0 @@ -.\" Copyright (c) 2001-2002 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: l2ping.8,v 1.3 2003/05/21 01:00:19 max Exp $ -.\" $FreeBSD$ -.\" -.Dd June 14, 2002 -.Dt L2PING 8 -.Os -.Sh NAME -.Nm l2ping -.Nd send L2CAP ECHO_REQUEST to remote devices -.Sh SYNOPSIS -.Nm -.Op Fl fhn -.Fl a Ar remote -.Op Fl c Ar count -.Op Fl i Ar delay -.Op Fl S Ar source -.Op Fl s Ar size -.Sh DESCRIPTION -The -.Nm -utility uses L2CAP -.Dv ECHO_REQUEST -datagram to elicit an L2CAP -.Dv ECHO_RESPONSE -datagram from a remote device. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a Ar remote -Specify the remote device to ping. -The remote device can be specified by either its BD_ADDR or name. -If name was specified then the -.Nm -utility will attempt to resolve the name via -.Xr bt_gethostbyname 3 . -.It Fl c Ar count -Number of packets to send. -If this option is not specified, -.Nm -will operate until interrupted. -.It Fl f -.Dq Flood -ping, i.e., no delay between packets. -.It Fl h -Display usage message and exit. -.It Fl i Ar wait -Wait -.Ar wait -seconds between sending each packet. -The default is to wait for one second between each packet. -This option is ignored if -.Fl f -has been specified. -.It Fl n -Numeric output only. -No attempt will be made to look up symbolic names for host addresses. -.It Fl S Ar source -Specify the local device which should be used to send L2CAP -.Dv ECHO_REQUEST -datagrams. -The local device can be specified by either its BD_ADDR or name. -If name was specified then the -.Nm -utility will attempt to resolve the name via -.Xr bt_gethostbyname 3 . -.It Fl s Ar size -Specify the number of payload bytes to be sent. -The default size is 44 bytes. -It is calculated as minimum L2CAP MTU (48 bytes) minus the size of the L2CAP -signalling command header (4 bytes). -The maximum size is 65531 bytes. -Is is calculated as maximum L2CAP MTU -(65535 bytes) minus four bytes of payload reserved for -.Nm -internal use. -Use this option with caution. -Some implementations may not like large sizes and may hang or even crash. -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr bluetooth 3 , -.Xr netgraph 3 , -.Xr netgraph 4 , -.Xr ng_l2cap 4 , -.Xr l2control 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh BUGS -Could collect more statistic. -Could check for duplicated, corrupted and lost packets. diff --git a/usr.sbin/bluetooth/l2ping/l2ping.c b/usr.sbin/bluetooth/l2ping/l2ping.c deleted file mode 100644 index d7e1b1e..0000000 --- a/usr.sbin/bluetooth/l2ping/l2ping.c +++ /dev/null @@ -1,290 +0,0 @@ -/* - * l2ping.c - * - * Copyright (c) 2001-2002 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: l2ping.c,v 1.5 2003/05/16 19:54:40 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void usage (void); -static void tv_sub (struct timeval *, struct timeval const *); -static double tv2msec (struct timeval const *); - -#undef min -#define min(x, y) (((x) > (y))? (y) : (x)) - -static char const pattern[] = "1234567890-"; -#define PATTERN_SIZE (sizeof(pattern) - 1) - -/* - * Main - */ - -int -main(int argc, char *argv[]) -{ - bdaddr_t src, dst; - struct hostent *he = NULL; - uint8_t *echo_data = NULL; - struct sockaddr_l2cap sa; - int32_t n, s, count, wait, flood, echo_size, numeric; - char *rname = NULL; - - /* Set defaults */ - memcpy(&src, NG_HCI_BDADDR_ANY, sizeof(src)); - memcpy(&dst, NG_HCI_BDADDR_ANY, sizeof(dst)); - - echo_data = (uint8_t *) calloc(NG_L2CAP_MAX_ECHO_SIZE, sizeof(uint8_t)); - if (echo_data == NULL) { - fprintf(stderr, "Failed to allocate echo data buffer"); - exit(1); - } - - /* - * Set default echo size to the NG_L2CAP_MTU_MINIMUM minus - * the size of the L2CAP signalling command header. - */ - - echo_size = NG_L2CAP_MTU_MINIMUM - sizeof(ng_l2cap_cmd_hdr_t); - count = -1; /* unimited */ - wait = 1; /* sec */ - flood = 0; - numeric = 0; - - /* Parse command line arguments */ - while ((n = getopt(argc, argv, "a:c:fi:nS:s:h")) != -1) { - switch (n) { - case 'a': - if (!bt_aton(optarg, &dst)) { - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(1, "%s: %s", optarg, hstrerror(h_errno)); - - memcpy(&dst, he->h_addr, sizeof(dst)); - } - break; - - case 'c': - count = atoi(optarg); - if (count <= 0) - usage(); - break; - - case 'f': - flood = 1; - break; - - case 'i': - wait = atoi(optarg); - if (wait <= 0) - usage(); - break; - - case 'n': - numeric = 1; - break; - - case 'S': - if (!bt_aton(optarg, &src)) { - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(1, "%s: %s", optarg, hstrerror(h_errno)); - - memcpy(&src, he->h_addr, sizeof(src)); - } - break; - - case 's': - echo_size = atoi(optarg); - if (echo_size < sizeof(int32_t) || - echo_size > NG_L2CAP_MAX_ECHO_SIZE) - usage(); - break; - - case 'h': - default: - usage(); - break; - } - } - - if (memcmp(&dst, NG_HCI_BDADDR_ANY, sizeof(dst)) == 0) - usage(); - - he = bt_gethostbyaddr((const char *)&dst, sizeof(dst), AF_BLUETOOTH); - if (he == NULL || he->h_name == NULL || he->h_name[0] == '\0' || numeric) - asprintf(&rname, "%s", bt_ntoa(&dst, NULL)); - else - rname = strdup(he->h_name); - - if (rname == NULL) - errx(1, "Failed to create remote hostname"); - - s = socket(PF_BLUETOOTH, SOCK_RAW, BLUETOOTH_PROTO_L2CAP); - if (s < 0) - err(2, "Could not create socket"); - - memset(&sa, 0, sizeof(sa)); - sa.l2cap_len = sizeof(sa); - sa.l2cap_family = AF_BLUETOOTH; - memcpy(&sa.l2cap_bdaddr, &src, sizeof(sa.l2cap_bdaddr)); - - if (bind(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) - err(3, -"Could not bind socket, src bdaddr=%s", bt_ntoa(&sa.l2cap_bdaddr, NULL)); - - memset(&sa, 0, sizeof(sa)); - sa.l2cap_len = sizeof(sa); - sa.l2cap_family = AF_BLUETOOTH; - memcpy(&sa.l2cap_bdaddr, &dst, sizeof(sa.l2cap_bdaddr)); - - if (connect(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) - err(4, -"Could not connect socket, dst bdaddr=%s", bt_ntoa(&sa.l2cap_bdaddr, NULL)); - - /* Fill pattern */ - for (n = 0; n < echo_size; ) { - int32_t avail = min(echo_size - n, PATTERN_SIZE); - - memcpy(echo_data + n, pattern, avail); - n += avail; - } - - /* Start ping'ing */ - for (n = 0; count == -1 || count > 0; n ++) { - struct ng_btsocket_l2cap_raw_ping r; - struct timeval a, b; - int32_t fail; - - if (gettimeofday(&a, NULL) < 0) - err(5, "Could not gettimeofday(a)"); - - fail = 0; - *((int32_t *) echo_data) = htonl(n); - - r.result = 0; - r.echo_size = echo_size; - r.echo_data = echo_data; - if (ioctl(s, SIOC_L2CAP_L2CA_PING, &r, sizeof(r)) < 0) { - r.result = errno; - fail = 1; -/* - warn("Could not ping, dst bdaddr=%s", - bt_ntoa(&r.echo_dst, NULL)); -*/ - } - - if (gettimeofday(&b, NULL) < 0) - err(7, "Could not gettimeofday(b)"); - - tv_sub(&b, &a); - - fprintf(stdout, -"%d bytes from %s seq_no=%d time=%.3f ms result=%#x %s\n", - r.echo_size, - rname, - ntohl(*((int32_t *)(r.echo_data))), - tv2msec(&b), r.result, - ((fail == 0)? "" : strerror(errno))); - - if (!flood) { - /* Wait */ - a.tv_sec = wait; - a.tv_usec = 0; - select(0, NULL, NULL, NULL, &a); - } - - if (count != -1) - count --; - } - - free(rname); - free(echo_data); - close(s); - - return (0); -} /* main */ - -/* - * a -= b, for timevals - */ - -static void -tv_sub(struct timeval *a, struct timeval const *b) -{ - if (a->tv_usec < b->tv_usec) { - a->tv_usec += 1000000; - a->tv_sec -= 1; - } - - a->tv_usec -= b->tv_usec; - a->tv_sec -= b->tv_sec; -} /* tv_sub */ - -/* - * convert tv to msec - */ - -static double -tv2msec(struct timeval const *tvp) -{ - return(((double)tvp->tv_usec)/1000.0 + ((double)tvp->tv_sec)*1000.0); -} /* tv2msec */ - -/* - * Usage - */ - -static void -usage(void) -{ - fprintf(stderr, "Usage: l2ping -a bd_addr " \ - "[-S bd_addr -c count -i wait -n -s size -h]\n"); - fprintf(stderr, "Where:\n"); - fprintf(stderr, " -a remote Specify remote device to ping\n"); - fprintf(stderr, " -c count Number of packets to send\n"); - fprintf(stderr, " -f No delay (sort of flood)\n"); - fprintf(stderr, " -h Display this message\n"); - fprintf(stderr, " -i wait Delay between packets (sec)\n"); - fprintf(stderr, " -n Numeric output only\n"); - fprintf(stderr, " -S source Specify source device\n"); - fprintf(stderr, " -s size Packet size (bytes), " \ - "between %zd and %zd\n", sizeof(int32_t), NG_L2CAP_MAX_ECHO_SIZE); - - exit(255); -} /* usage */ - diff --git a/usr.sbin/bluetooth/rfcomm_pppd/Makefile b/usr.sbin/bluetooth/rfcomm_pppd/Makefile deleted file mode 100644 index adac64e..0000000 --- a/usr.sbin/bluetooth/rfcomm_pppd/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $Id: Makefile,v 1.7 2003/09/07 18:32:11 max Exp $ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../usr.bin/bluetooth/rfcomm_sppd - -PROG= rfcomm_pppd -MAN= rfcomm_pppd.8 -SRCS= rfcomm_pppd.c rfcomm_sdp.c -WARNS?= 2 - -DPADD= ${LIBBLUETOOTH} ${LIBSDP} -LDADD= -lbluetooth -lsdp - -.include diff --git a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 b/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 deleted file mode 100644 index 0588d0c..0000000 --- a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.8 +++ /dev/null @@ -1,354 +0,0 @@ -.\" Copyright (c) 2001-2003 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: rfcomm_pppd.8,v 1.7 2003/09/07 18:32:11 max Exp $ -.\" $FreeBSD$ -.\" -.Dd February 4, 2003 -.Dt RFCOMM_PPPD 8 -.Os -.Sh NAME -.Nm rfcomm_pppd -.Nd RFCOMM PPP daemon -.Sh SYNOPSIS -.Nm -.Fl c -.Op Fl dh -.Fl a Ar address -.Fl C Ar channel -.Fl l Ar label -.Fl u Ar N -.Nm -.Fl s -.Op Fl dDhS -.Op Fl a Ar address -.Fl C Ar channel -.Fl l Ar label -.Sh DESCRIPTION -The -.Nm -daemon is a simple wrapper daemon that allows the use of -.Xr ppp 8 -via an RFCOMM connection. -It can operate in two modes: client and server. -.Pp -In client mode, -.Nm -opens an RFCOMM connection to the specified server's -.Ar BD_ADRR -and -.Ar channel . -Once the RFCOMM connection is established, -.Nm -executes -.Xr ppp 8 -in -.Fl direct -mode with the specified -.Ar label . -Likewise, -.Xr ppp 8 -operates over the RFCOMM connection just like it would over a standard serial -port, thus allowing a user to -.Dq "dial out" -and connect to the Internet. -.Pp -In server mode, -.Nm -opens an RFCOMM socket and listens for incoming connections from remote clients. -Once the new incoming connection is accepted, -.Nm -forks and executes -.Xr ppp 8 -in -.Fl direct -mode with the specified -.Ar label . -Likewise, -.Xr ppp 8 -operates over the RFCOMM connection just like it would over a standard serial -port, thus providing network connectivity to remote clients. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a Ar address -In client mode, this required option specifies the address of the remote -RFCOMM server. -In server mode, this option can be used to specify the local -address to listen on. -By default, in server mode, the daemon will listen on -.Dv ANY -address. -The address can be specified as BD_ADDR or name. -If a name was specified, the -.Nm -utility will attempt to resolve the name via -.Xr bt_gethostbyname 3 . -.It Fl C Ar channel -In both client and server mode, this required option specifies the RFCOMM -channel to connect to or listen on. -In server mode, the channel should be a number between 1 and 30. -In client mode, the channel could either be a number between 1 and 30 -or a service name. -Supported service names are: -.Cm DUN -(Dial-Up Networking) and -.Cm LAN -(LAN Access Using PPP). -If a service name is used instead of a numeric channel number, then -.Nm -will try to obtain an RFCOMM channel number via SDP -(Service Discovery Protocol). -.It Fl c -Act as an RFCOMM client. -This is the default mode. -.It Fl d -Do not detach from the controlling terminal, i.e., run in foreground. -.It Fl D -In server mode, register the -.Cm DUN -(Dial-Up Networking) service in addition to the -.Cm LAN -(LAN Access Using PPP) service. -AT-command exchange can be faked with -.Xr ppp 8 -chat script. -.It Fl h -Display usage message and exit. -.It Fl l Ar label -In both client and server mode, this required option specifies which -.Xr ppp 8 -label will be used. -.It Fl S -In server mode, register the -.Cm SP -(Serial Port) service in addition to the -.Cm LAN -(LAN Access Using PPP) service. -.Pp -It appears that some cell phones are using the so-called -.Dq "callback mechanism" . -In this scenario, the user is trying to connect his cell phone to the Internet, -while the user's host computer is acting as the gateway server. -It seems that it is not possible to tell the phone to just connect and start -using the -.Cm LAN -service. -Instead, the user's host computer must -.Dq "jump start" -the phone by connecting to the phone's -.Cm SP -service. -What happens next is the phone kills the existing connection and opens another -connection back to the user's host computer. -The phone really wants to use the -.Cm LAN -service, but for whatever reason it looks for the -.Cm SP -service on the user's host computer. -This brain-damaged behavior was reported for the Nokia 6600 and the -Sony/Ericsson P900. -.It Fl s -Act as an RFCOMM server. -.It Fl u Ar N -This option maps directly to the -.Fl unit -.Xr ppp 8 -command-line option and tells -.Nm -to instruct -.Xr ppp 8 -to only attempt to open -.Pa /dev/tun Ns Ar N . -This option only works in client mode. -.El -.Sh PPP CONFIGURATION -.Ss Important Notes on PPP Configuration -Special attention is required when adding new RFCOMM configurations to the -existing PPP configuration. -Please keep in mind that PPP will -.Em always -execute commands in the -.Dq Li default -label of your -.Pa /etc/ppp/ppp.conf -file. -Please make sure that the -.Dq Li default -label -.Em only -contains commands that apply to -.Em every -other label. -If you need to use PPP for both dialing out and accepting incoming -RFCOMM connections, please make sure you have moved all commands related to -dialing out from the -.Dq Li default -section into an appropriate outgoing label. -.Ss RFCOMM Server -One of the typical examples is the LAN access. -In this example, an RFCOMM connection -is used as a null-modem connection between a client and a server. -Both client and server will start talking PPP right after the RFCOMM -connection has been established. -.Bd -literal -offset indent -rfcomm-server: - set timeout 0 - set lqrperiod 10 - set ifaddr 10.0.0.1 10.0.0.2 255.255.255.0 - enable lqr - accept lqr - accept dns - # Do not use PPP authentication. Assume that - # Bluetooth connection was authenticated already - disable pap - deny pap - disable chap - deny chap -.Ed -.Ss RFCOMM Client -The -.Nm -utility supports both -.Cm LAN -(LAN Access Using PPP) and -.Cm DUN -(Dial-Up Networking) access. -The client's configuration for -.Cm LAN -access is very similar to the server's and might look like this: -.Bd -literal -offset indent -rfcomm-client: - enable lqr - accept lqr - set dial - set timeout 0 - disable iface-alias - set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0 - # Do not use PPP authentication. Assume that - # Bluetooth connection was authenticated already - deny pap - disable pap - deny chap - disable chap -.Ed -.Pp -The client's configuration for -.Cm DUN -access is different. -In this scenario, the client gets connected to the virtual serial port on the -server. -To open a PPP session, the client must dial a number. -Note that by default -.Xr ppp 8 -will not execute any configured chat scripts. -The -.Ic force-scripts -option can be used to override this behavior. -An example configuration is shown below: -.Bd -literal -offset indent -rfcomm-dialup: - # This is IMPORTANT option - enable force-scripts - - # You might want to change these - set authname - set authkey - set phone "*99***1#" - - # You might want to adjust dial string as well - set dial "ABORT BUSY ABORT NO\\\\sCARRIER TIMEOUT 5 \\ - \\"\\" AT OK-AT-OK ATE1Q0 OK \\\\dATDT\\\\T TIMEOUT 40 CONNECT" - set login - set timeout 30 - enable dns - resolv rewrite - - set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0 - add default HISADDR -.Ed -.Pp -Note that by adjusting the initialization string, one can make a CSD (Circuit -Switched Data), HSCSD (High Speed Circuit Switched Data) or GPRS (General -Packet Radio Service) connection. -The availability of the particular connection -type depends on the phone model and service plan activated on the phone. -.Sh EXIT STATUS -.Ex -std -.Sh EXAMPLES -.Dl "rfcomm_pppd -s -a 00:01:02:03:04:05 -C 1 -l rfcomm-server" -.Pp -This command will start -.Nm -in the server mode. -The RFCOMM server will listen on local address -.Li 00:01:02:03:04:05 -and channel -.Li 1 . -Once the incoming connection has been accepted, -.Nm -will execute -.Xr ppp 8 -in -.Fl direct -mode with the -.Dq Li rfcomm-server -label. -.Pp -.Dl "rfcomm_pppd -c -a 00:01:02:03:04:05 -C 1 -l rfcomm-client" -.Pp -This command will start -.Nm -in the client mode. -.Nm -will try to connect to the RFCOMM server at -.Li 00:01:02:03:04:05 -address and channel -.Li 1 . -Once connected, -.Nm -will execute -.Xr ppp 8 -in -.Fl direct -mode with the -.Dq Li rfcomm-client -label. -.Sh SEE ALSO -.Xr rfcomm_sppd 1 , -.Xr bluetooth 3 , -.Xr ng_btsocket 4 , -.Xr ppp 8 , -.Xr sdpcontrol 8 , -.Xr sdpd 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh CAVEATS -The -.Nm -utility in server mode will try to register the Bluetooth LAN Access Over PPP -service with the local SPD daemon. -If the local SDP daemon is not running, -.Nm -will exit with an error. diff --git a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c b/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c deleted file mode 100644 index 956dc4d..0000000 --- a/usr.sbin/bluetooth/rfcomm_pppd/rfcomm_pppd.c +++ /dev/null @@ -1,471 +0,0 @@ -/* - * rfcomm_pppd.c - */ - -/*- - * Copyright (c) 2001-2008 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: rfcomm_pppd.c,v 1.5 2003/09/07 18:32:11 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define RFCOMM_PPPD "rfcomm_pppd" - -int rfcomm_channel_lookup (bdaddr_t const *local, - bdaddr_t const *remote, - int service, int *channel, int *error); - -static void exec_ppp (int s, char *unit, char *label); -static void sighandler (int s); -static void usage (void); - -static int done; - -/* Main */ -int -main(int argc, char *argv[]) -{ - struct sockaddr_rfcomm sock_addr; - char *label = NULL, *unit = NULL, *ep = NULL; - bdaddr_t addr; - int s, channel, detach, server, service, - regdun, regsp; - pid_t pid; - - memcpy(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)); - channel = 0; - detach = 1; - server = 0; - service = 0; - regdun = 0; - regsp = 0; - - /* Parse command line arguments */ - while ((s = getopt(argc, argv, "a:cC:dDhl:sSu:")) != -1) { - switch (s) { - case 'a': /* BDADDR */ - if (!bt_aton(optarg, &addr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(1, "%s: %s", optarg, hstrerror(h_errno)); - - memcpy(&addr, he->h_addr, sizeof(addr)); - } - break; - - case 'c': /* client */ - server = 0; - break; - - case 'C': /* RFCOMM channel */ - channel = strtoul(optarg, &ep, 10); - if (*ep != '\0') { - channel = 0; - switch (tolower(optarg[0])) { - case 'd': /* DialUp Networking */ - service = SDP_SERVICE_CLASS_DIALUP_NETWORKING; - break; - - case 'l': /* LAN Access Using PPP */ - service = SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP; - break; - } - } - break; - - case 'd': /* do not detach */ - detach = 0; - break; - - case 'D': /* Register DUN service as well as LAN service */ - regdun = 1; - break; - - case 'l': /* PPP label */ - label = optarg; - break; - - case 's': /* server */ - server = 1; - break; - - case 'S': /* Register SP service as well as LAN service */ - regsp = 1; - break; - - case 'u': /* PPP -unit option */ - strtoul(optarg, &ep, 10); - if (*ep != '\0') - usage(); - /* NOT REACHED */ - - unit = optarg; - break; - - case 'h': - default: - usage(); - /* NOT REACHED */ - } - } - - /* Check if we got everything we wanted */ - if (label == NULL) - errx(1, "Must specify PPP label"); - - if (!server) { - if (memcmp(&addr, NG_HCI_BDADDR_ANY, sizeof(addr)) == 0) - errx(1, "Must specify server BD_ADDR"); - - /* Check channel, if was not set then obtain it via SDP */ - if (channel == 0 && service != 0) - if (rfcomm_channel_lookup(NULL, &addr, service, - &channel, &s) != 0) - errc(1, s, "Could not obtain RFCOMM channel"); - } - - if (channel <= 0 || channel > 30) - errx(1, "Invalid RFCOMM channel number %d", channel); - - openlog(RFCOMM_PPPD, LOG_PID | LOG_PERROR | LOG_NDELAY, LOG_USER); - - if (detach && daemon(0, 0) < 0) { - syslog(LOG_ERR, "Could not daemon(0, 0). %s (%d)", - strerror(errno), errno); - exit(1); - } - - s = socket(PF_BLUETOOTH, SOCK_STREAM, BLUETOOTH_PROTO_RFCOMM); - if (s < 0) { - syslog(LOG_ERR, "Could not create socket. %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (server) { - struct sigaction sa; - void *ss = NULL; - sdp_lan_profile_t lan; - - /* Install signal handler */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sighandler; - - if (sigaction(SIGTERM, &sa, NULL) < 0) { - syslog(LOG_ERR, "Could not sigaction(SIGTERM). %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (sigaction(SIGHUP, &sa, NULL) < 0) { - syslog(LOG_ERR, "Could not sigaction(SIGHUP). %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (sigaction(SIGINT, &sa, NULL) < 0) { - syslog(LOG_ERR, "Could not sigaction(SIGINT). %s (%d)", - strerror(errno), errno); - exit(1); - } - - sa.sa_handler = SIG_IGN; - sa.sa_flags = SA_NOCLDWAIT; - - if (sigaction(SIGCHLD, &sa, NULL) < 0) { - syslog(LOG_ERR, "Could not sigaction(SIGCHLD). %s (%d)", - strerror(errno), errno); - exit(1); - } - - /* bind socket and listen for incoming connections */ - sock_addr.rfcomm_len = sizeof(sock_addr); - sock_addr.rfcomm_family = AF_BLUETOOTH; - memcpy(&sock_addr.rfcomm_bdaddr, &addr, - sizeof(sock_addr.rfcomm_bdaddr)); - sock_addr.rfcomm_channel = channel; - - if (bind(s, (struct sockaddr *) &sock_addr, - sizeof(sock_addr)) < 0) { - syslog(LOG_ERR, "Could not bind socket. %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (listen(s, 10) < 0) { - syslog(LOG_ERR, "Could not listen on socket. %s (%d)", - strerror(errno), errno); - exit(1); - } - - ss = sdp_open_local(NULL); - if (ss == NULL) { - syslog(LOG_ERR, "Unable to create local SDP session"); - exit(1); - } - - if (sdp_error(ss) != 0) { - syslog(LOG_ERR, "Unable to open local SDP session. " \ - "%s (%d)", strerror(sdp_error(ss)), - sdp_error(ss)); - exit(1); - } - - memset(&lan, 0, sizeof(lan)); - lan.server_channel = channel; - - if (sdp_register_service(ss, - SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP, - &addr, (void *) &lan, sizeof(lan), NULL) != 0) { - syslog(LOG_ERR, "Unable to register LAN service with " \ - "local SDP daemon. %s (%d)", - strerror(sdp_error(ss)), sdp_error(ss)); - exit(1); - } - - /* - * Register DUN (Dial-Up Networking) service on the same - * RFCOMM channel if requested. There is really no good reason - * to not to support this. AT-command exchange can be faked - * with chat script in ppp.conf - */ - - if (regdun) { - sdp_dun_profile_t dun; - - memset(&dun, 0, sizeof(dun)); - dun.server_channel = channel; - - if (sdp_register_service(ss, - SDP_SERVICE_CLASS_DIALUP_NETWORKING, - &addr, (void *) &dun, sizeof(dun), - NULL) != 0) { - syslog(LOG_ERR, "Unable to register DUN " \ - "service with local SDP daemon. " \ - "%s (%d)", strerror(sdp_error(ss)), - sdp_error(ss)); - exit(1); - } - } - - /* - * Register SP (Serial Port) service on the same RFCOMM channel - * if requested. It appears that some cell phones are using so - * called "callback mechanism". In this scenario user is trying - * to connect his cell phone to the Internet, and, user's host - * computer is acting as the gateway server. It seems that it - * is not possible to tell the phone to just connect and start - * using the LAN service. Instead the user's host computer must - * "jump start" the phone by connecting to the phone's SP - * service. What happens next is the phone kills the existing - * connection and opens another connection back to the user's - * host computer. The phone really wants to use LAN service, - * but for whatever reason it looks for SP service on the - * user's host computer. This brain damaged behavior was - * reported for Nokia 6600 and Sony/Ericsson P900. Both phones - * are Symbian-based phones. Perhaps this is a Symbian problem? - */ - - if (regsp) { - sdp_sp_profile_t sp; - - memset(&sp, 0, sizeof(sp)); - sp.server_channel = channel; - - if (sdp_register_service(ss, - SDP_SERVICE_CLASS_SERIAL_PORT, - &addr, (void *) &sp, sizeof(sp), - NULL) != 0) { - syslog(LOG_ERR, "Unable to register SP " \ - "service with local SDP daemon. " \ - "%s (%d)", strerror(sdp_error(ss)), - sdp_error(ss)); - exit(1); - } - } - - for (done = 0; !done; ) { - socklen_t len = sizeof(sock_addr); - int s1 = accept(s, (struct sockaddr *) &sock_addr, &len); - - if (s1 < 0) { - syslog(LOG_ERR, "Could not accept connection " \ - "on socket. %s (%d)", strerror(errno), - errno); - exit(1); - } - - pid = fork(); - if (pid == (pid_t) -1) { - syslog(LOG_ERR, "Could not fork(). %s (%d)", - strerror(errno), errno); - exit(1); - } - - if (pid == 0) { - sdp_close(ss); - close(s); - - /* Reset signal handler */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = SIG_DFL; - - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGHUP, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGCHLD, &sa, NULL); - - /* Become daemon */ - daemon(0, 0); - - /* - * XXX Make sure user does not shoot himself - * in the foot. Do not pass unit option to the - * PPP when operating in the server mode. - */ - - exec_ppp(s1, NULL, label); - } else - close(s1); - } - } else { - sock_addr.rfcomm_len = sizeof(sock_addr); - sock_addr.rfcomm_family = AF_BLUETOOTH; - memcpy(&sock_addr.rfcomm_bdaddr, NG_HCI_BDADDR_ANY, - sizeof(sock_addr.rfcomm_bdaddr)); - sock_addr.rfcomm_channel = 0; - - if (bind(s, (struct sockaddr *) &sock_addr, - sizeof(sock_addr)) < 0) { - syslog(LOG_ERR, "Could not bind socket. %s (%d)", - strerror(errno), errno); - exit(1); - } - - memcpy(&sock_addr.rfcomm_bdaddr, &addr, - sizeof(sock_addr.rfcomm_bdaddr)); - sock_addr.rfcomm_channel = channel; - - if (connect(s, (struct sockaddr *) &sock_addr, - sizeof(sock_addr)) < 0) { - syslog(LOG_ERR, "Could not connect socket. %s (%d)", - strerror(errno), errno); - exit(1); - } - - exec_ppp(s, unit, label); - } - - exit(0); -} /* main */ - -/* - * Redirects stdin/stdout to s, stderr to /dev/null and exec - * 'ppp -direct -quiet [-unit N] label'. Never returns. - */ - -static void -exec_ppp(int s, char *unit, char *label) -{ - char ppp[] = "/usr/sbin/ppp"; - char *ppp_args[] = { ppp, "-direct", "-quiet", - NULL, NULL, NULL, NULL }; - - close(0); - if (dup(s) < 0) { - syslog(LOG_ERR, "Could not dup(0). %s (%d)", - strerror(errno), errno); - exit(1); - } - - close(1); - if (dup(s) < 0) { - syslog(LOG_ERR, "Could not dup(1). %s (%d)", - strerror(errno), errno); - exit(1); - } - - close(2); - open("/dev/null", O_RDWR); - - if (unit != NULL) { - ppp_args[3] = "-unit"; - ppp_args[4] = unit; - ppp_args[5] = label; - } else - ppp_args[3] = label; - - if (execv(ppp, ppp_args) < 0) { - syslog(LOG_ERR, "Could not exec(%s -direct -quiet%s%s %s). " \ - "%s (%d)", ppp, (unit != NULL)? " -unit " : "", - (unit != NULL)? unit : "", label, - strerror(errno), errno); - exit(1); - } -} /* run_ppp */ - -/* Signal handler */ -static void -sighandler(int s) -{ - done = 1; -} /* sighandler */ - -/* Display usage and exit */ -static void -usage(void) -{ - fprintf(stdout, -"Usage: %s options\n" \ -"Where options are:\n" \ -"\t-a address Address to listen on or connect to (required for client)\n" \ -"\t-c Act as a clinet (default)\n" \ -"\t-C channel RFCOMM channel to listen on or connect to (required)\n" \ -"\t-d Run in foreground\n" \ -"\t-D Register Dial-Up Networking service (server mode only)\n" \ -"\t-l label Use PPP label (required)\n" \ -"\t-s Act as a server\n" \ -"\t-S Register Serial Port service (server mode only)\n" \ -"\t-u N Tell PPP to operate on /dev/tunN (client mode only)\n" \ -"\t-h Display this message\n", RFCOMM_PPPD); - - exit(255); -} /* usage */ - diff --git a/usr.sbin/bluetooth/sdpcontrol/Makefile b/usr.sbin/bluetooth/sdpcontrol/Makefile deleted file mode 100644 index c0ec8d4..0000000 --- a/usr.sbin/bluetooth/sdpcontrol/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $Id: Makefile,v 1.1 2003/09/08 02:27:27 max Exp $ -# $FreeBSD$ - -PROG= sdpcontrol -MAN= sdpcontrol.8 -SRCS= sdpcontrol.c search.c -WARNS?= 2 - -DPADD= ${LIBBLUETOOTH} ${LIBSDP} -LDADD= -lbluetooth -lsdp - -.include diff --git a/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.8 b/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.8 deleted file mode 100644 index f0d375a..0000000 --- a/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.8 +++ /dev/null @@ -1,118 +0,0 @@ -.\" Copyright (c) 2003 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: sdpcontrol.8,v 1.1 2003/09/08 02:27:27 max Exp $ -.\" $FreeBSD$ -.\" -.Dd September 7, 2003 -.Dt SDPCONTROL 8 -.Os -.Sh NAME -.Nm sdpcontrol -.Nd SDP query utility -.Sh SYNOPSIS -.Nm -.Fl h -.Nm -.Fl a Ar address -.Ar command -.Op Ar parameters ... -.Nm -.Fl l -.Op Fl c Ar path -.Ar command -.Op Ar parameters ... -.Sh DESCRIPTION -The -.Nm -utility attempts to query the specified Service Discovery Protocol (SDP) server. -Remote SDP servers are identified by their address. -Connection to the local SDP server is made via the control socket. -The -.Nm -utility uses Service Search Attribute Requests and prints results to -standard output and error messages to standard error. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a Ar address -Connect to the remote device with the specified address. -The address can be specified as BD_ADDR or a name. -If a name was specified, the -.Nm -utility attempts to resolve the name via -.Xr bt_gethostbyname 3 . -.It Fl c Ar path -Specify path to the control socket. -The default path is -.Pa /var/run/sdp . -.It Fl h -Display usage message and exit. -.It Fl l -Query the local SDP server via the control socket. -.It Ar command -One of the supported commands (see below). -The special command -.Cm help -can be used to obtain a list of all supported commands. -To get more information about a specific command, use -.Cm help Ar command . -.It Ar parameters -One or more optional space separated command parameters. -.El -.Sh COMMANDS -The currently supported node commands in -.Nm -are: -.Pp -.Bl -tag -offset indent -compact -.It Cm Browse -.It Cm Search -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr bluetooth 3 , -.Xr sdp 3 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh CAVEATS -The -.Nm -utility only implements client side functionality. -.Pp -The -.Nm -utility only requests the following attributes from the SDP server: -.Pp -.Bl -enum -offset indent -compact -.It -Service Record Handle -.It -Service Class ID List -.It -Protocol Descriptor List -.It -Bluetooth Profile Descriptor List -.El diff --git a/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.c b/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.c deleted file mode 100644 index fca2015..0000000 --- a/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * sdpcontrol.c - * - * Copyright (c) 2001-2003 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: sdpcontrol.c,v 1.1 2003/09/08 02:27:27 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "sdpcontrol.h" - -/* Prototypes */ -static int do_sdp_command (bdaddr_p, char const *, int, - int, char **); -static struct sdp_command * find_sdp_command (char const *, - struct sdp_command *); -static void print_sdp_command (struct sdp_command *); -static void usage (void); - -/* Main */ -int -main(int argc, char *argv[]) -{ - char const *control = SDP_LOCAL_PATH; - int n, local; - bdaddr_t bdaddr; - - memset(&bdaddr, 0, sizeof(bdaddr)); - local = 0; - - /* Process command line arguments */ - while ((n = getopt(argc, argv, "a:c:lh")) != -1) { - switch (n) { - case 'a': /* bdaddr */ - if (!bt_aton(optarg, &bdaddr)) { - struct hostent *he = NULL; - - if ((he = bt_gethostbyname(optarg)) == NULL) - errx(1, "%s: %s", optarg, hstrerror(h_errno)); - - memcpy(&bdaddr, he->h_addr, sizeof(bdaddr)); - } - break; - - case 'c': /* control socket */ - control = optarg; - break; - - case 'l': /* local sdpd */ - local = 1; - break; - - case 'h': - default: - usage(); - /* NOT REACHED */ - } - } - - argc -= optind; - argv += optind; - - if (*argv == NULL) - usage(); - - return (do_sdp_command(&bdaddr, control, local, argc, argv)); -} - -/* Execute commands */ -static int -do_sdp_command(bdaddr_p bdaddr, char const *control, int local, - int argc, char **argv) -{ - char *cmd = argv[0]; - struct sdp_command *c = NULL; - void *xs = NULL; - int e, help; - - help = 0; - if (strcasecmp(cmd, "help") == 0) { - argc --; - argv ++; - - if (argc <= 0) { - fprintf(stdout, "Supported commands:\n"); - print_sdp_command(sdp_commands); - fprintf(stdout, "\nFor more information use " \ - "'help command'\n"); - - return (OK); - } - - help = 1; - cmd = argv[0]; - } - - c = find_sdp_command(cmd, sdp_commands); - if (c == NULL) { - fprintf(stdout, "Unknown command: \"%s\"\n", cmd); - return (ERROR); - } - - if (!help) { - if (!local) { - if (memcmp(bdaddr, NG_HCI_BDADDR_ANY, sizeof(*bdaddr)) == 0) - usage(); - - xs = sdp_open(NG_HCI_BDADDR_ANY, bdaddr); - } else - xs = sdp_open_local(control); - - if (xs == NULL) - errx(1, "Could not create SDP session object"); - if (sdp_error(xs) == 0) - e = (c->handler)(xs, -- argc, ++ argv); - else - e = ERROR; - } else - e = USAGE; - - switch (e) { - case OK: - case FAILED: - break; - - case ERROR: - fprintf(stdout, "Could not execute command \"%s\". %s\n", - cmd, strerror(sdp_error(xs))); - break; - - case USAGE: - fprintf(stdout, "Usage: %s\n%s\n", c->command, c->description); - break; - - default: assert(0); break; - } - - sdp_close(xs); - - return (e); -} /* do_sdp_command */ - -/* Try to find command in specified category */ -static struct sdp_command * -find_sdp_command(char const *command, struct sdp_command *category) -{ - struct sdp_command *c = NULL; - - for (c = category; c->command != NULL; c++) { - char *c_end = strchr(c->command, ' '); - - if (c_end != NULL) { - int len = c_end - c->command; - - if (strncasecmp(command, c->command, len) == 0) - return (c); - } else if (strcasecmp(command, c->command) == 0) - return (c); - } - - return (NULL); -} /* find_sdp_command */ - -/* Print commands in specified category */ -static void -print_sdp_command(struct sdp_command *category) -{ - struct sdp_command *c = NULL; - - for (c = category; c->command != NULL; c++) - fprintf(stdout, "\t%s\n", c->command); -} /* print_sdp_command */ - -/* Usage */ -static void -usage(void) -{ - fprintf(stderr, -"Usage: sdpcontrol options command\n" \ -"Where options are:\n" -" -a address address to connect to\n" \ -" -c path path to the control socket (default is %s)\n" \ -" -h display usage and quit\n" \ -" -l connect to the local SDP server via control socket\n" \ -" command one of the supported commands\n", SDP_LOCAL_PATH); - exit(255); -} /* usage */ - diff --git a/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.h b/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.h deleted file mode 100644 index 4a1ee76f..0000000 --- a/usr.sbin/bluetooth/sdpcontrol/sdpcontrol.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * sdpcontrol.h - * - * Copyright (c) 2001-2003 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: sdpcontrol.h,v 1.1 2003/09/08 02:27:27 max Exp $ - * $FreeBSD$ - */ - -#ifndef __SDPCONTROL_H__ -#define __SDPCONTROL_H__ - -#define OK 0 /* everything was OK */ -#define ERROR 1 /* could not execute command */ -#define FAILED 2 /* error was reported */ -#define USAGE 3 /* invalid parameters */ - -struct sdp_command { - char const *command; - char const *description; - int (*handler)(void *, int, char **); -}; - -extern struct sdp_command sdp_commands[]; - -#endif /* __SDPCONTROL_H__ */ - diff --git a/usr.sbin/bluetooth/sdpcontrol/search.c b/usr.sbin/bluetooth/sdpcontrol/search.c deleted file mode 100644 index e7d8244..0000000 --- a/usr.sbin/bluetooth/sdpcontrol/search.c +++ /dev/null @@ -1,713 +0,0 @@ -/* - * search.c - * - * Copyright (c) 2001-2003 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: search.c,v 1.2 2003/09/08 17:35:15 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include "sdpcontrol.h" - -/* List of the attributes we are looking for */ -static uint32_t attrs[] = -{ - SDP_ATTR_RANGE( SDP_ATTR_SERVICE_RECORD_HANDLE, - SDP_ATTR_SERVICE_RECORD_HANDLE), - SDP_ATTR_RANGE( SDP_ATTR_SERVICE_CLASS_ID_LIST, - SDP_ATTR_SERVICE_CLASS_ID_LIST), - SDP_ATTR_RANGE( SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST), - SDP_ATTR_RANGE( SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST) -}; -#define attrs_len (sizeof(attrs)/sizeof(attrs[0])) - -/* Buffer for the attributes */ -#define NRECS 25 /* request this much records from the SDP server */ -#define BSIZE 256 /* one attribute buffer size */ -static uint8_t buffer[NRECS * attrs_len][BSIZE]; - -/* SDP attributes */ -static sdp_attr_t values[NRECS * attrs_len]; -#define values_len (sizeof(values)/sizeof(values[0])) - -/* - * Print Service Class ID List - * - * The ServiceClassIDList attribute consists of a data element sequence in - * which each data element is a UUID representing the service classes that - * a given service record conforms to. The UUIDs are listed in order from - * the most specific class to the most general class. The ServiceClassIDList - * must contain at least one service class UUID. - */ - -static void -print_service_class_id_list(uint8_t const *start, uint8_t const *end) -{ - uint32_t type, len, value; - - if (end - start < 2) { - fprintf(stderr, "Invalid Service Class ID List. " \ - "Too short, len=%zd\n", end - start); - return; - } - - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, start); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, start); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, start); - break; - - default: - fprintf(stderr, "Invalid Service Class ID List. " \ - "Not a sequence, type=%#x\n", type); - return; - /* NOT REACHED */ - } - - while (start < end) { - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_UUID16: - SDP_GET16(value, start); - fprintf(stdout, "\t%s (%#4.4x)\n", - sdp_uuid2desc(value), value); - break; - - case SDP_DATA_UUID32: - SDP_GET32(value, start); - fprintf(stdout, "\t%#8.8x\n", value); - break; - - case SDP_DATA_UUID128: { - int128_t uuid; - - SDP_GET_UUID128(&uuid, start); - fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n", - ntohl(*(uint32_t *)&uuid.b[0]), - ntohs(*(uint16_t *)&uuid.b[4]), - ntohs(*(uint16_t *)&uuid.b[6]), - ntohs(*(uint16_t *)&uuid.b[8]), - ntohs(*(uint16_t *)&uuid.b[10]), - ntohl(*(uint32_t *)&uuid.b[12])); - } break; - - default: - fprintf(stderr, "Invalid Service Class ID List. " \ - "Not a UUID, type=%#x\n", type); - return; - /* NOT REACHED */ - } - } -} /* print_service_class_id_list */ - -/* - * Print Protocol Descriptor List - * - * If the ProtocolDescriptorList describes a single stack, it takes the form - * of a data element sequence in which each element of the sequence is a - * protocol descriptor. Each protocol descriptor is, in turn, a data element - * sequence whose first element is a UUID identifying the protocol and whose - * successive elements are protocol-specific parameters. The protocol - * descriptors are listed in order from the lowest layer protocol to the - * highest layer protocol used to gain access to the service. If it is possible - * for more than one kind of protocol stack to be used to gain access to the - * service, the ProtocolDescriptorList takes the form of a data element - * alternative where each member is a data element sequence as described above. - */ - -static void -print_protocol_descriptor(uint8_t const *start, uint8_t const *end) -{ - union { - uint8_t uint8; - uint16_t uint16; - uint32_t uint32; - uint64_t uint64; - int128_t int128; - } value; - uint32_t type, len, param; - - /* Get Protocol UUID */ - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_UUID16: - SDP_GET16(value.uint16, start); - fprintf(stdout, "\t%s (%#4.4x)\n", sdp_uuid2desc(value.uint16), - value.uint16); - break; - - case SDP_DATA_UUID32: - SDP_GET32(value.uint32, start); - fprintf(stdout, "\t%#8.8x\n", value.uint32); - break; - - case SDP_DATA_UUID128: - SDP_GET_UUID128(&value.int128, start); - fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n", - ntohl(*(uint32_t *)&value.int128.b[0]), - ntohs(*(uint16_t *)&value.int128.b[4]), - ntohs(*(uint16_t *)&value.int128.b[6]), - ntohs(*(uint16_t *)&value.int128.b[8]), - ntohs(*(uint16_t *)&value.int128.b[10]), - ntohl(*(uint32_t *)&value.int128.b[12])); - break; - - default: - fprintf(stderr, "Invalid Protocol Descriptor. " \ - "Not a UUID, type=%#x\n", type); - return; - /* NOT REACHED */ - } - - /* Protocol specific parameters */ - for (param = 1; start < end; param ++) { - fprintf(stdout, "\t\tProtocol specific parameter #%d: ", param); - - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_NIL: - fprintf(stdout, "nil\n"); - break; - - case SDP_DATA_UINT8: - case SDP_DATA_INT8: - case SDP_DATA_BOOL: - SDP_GET8(value.uint8, start); - fprintf(stdout, "u/int8/bool %u\n", value.uint8); - break; - - case SDP_DATA_UINT16: - case SDP_DATA_INT16: - case SDP_DATA_UUID16: - SDP_GET16(value.uint16, start); - fprintf(stdout, "u/int/uuid16 %u\n", value.uint16); - break; - - case SDP_DATA_UINT32: - case SDP_DATA_INT32: - case SDP_DATA_UUID32: - SDP_GET32(value.uint32, start); - fprintf(stdout, "u/int/uuid32 %u\n", value.uint32); - break; - - case SDP_DATA_UINT64: - case SDP_DATA_INT64: - SDP_GET64(value.uint64, start); - fprintf(stdout, "u/int64 %ju\n", value.uint64); - break; - - case SDP_DATA_UINT128: - case SDP_DATA_INT128: - SDP_GET128(&value.int128, start); - fprintf(stdout, "u/int128 %#8.8x%8.8x%8.8x%8.8x\n", - *(uint32_t *)&value.int128.b[0], - *(uint32_t *)&value.int128.b[4], - *(uint32_t *)&value.int128.b[8], - *(uint32_t *)&value.int128.b[12]); - break; - - case SDP_DATA_UUID128: - SDP_GET_UUID128(&value.int128, start); - fprintf(stdout, "uuid128 %#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x\n", - ntohl(*(uint32_t *)&value.int128.b[0]), - ntohs(*(uint16_t *)&value.int128.b[4]), - ntohs(*(uint16_t *)&value.int128.b[6]), - ntohs(*(uint16_t *)&value.int128.b[8]), - ntohs(*(uint16_t *)&value.int128.b[10]), - ntohl(*(uint32_t *)&value.int128.b[12])); - break; - - case SDP_DATA_STR8: - case SDP_DATA_URL8: - SDP_GET8(len, start); - fprintf(stdout, "%*.*s\n", len, len, (char *) start); - start += len; - break; - - case SDP_DATA_STR16: - case SDP_DATA_URL16: - SDP_GET16(len, start); - fprintf(stdout, "%*.*s\n", len, len, (char *) start); - start += len; - break; - - case SDP_DATA_STR32: - case SDP_DATA_URL32: - SDP_GET32(len, start); - fprintf(stdout, "%*.*s\n", len, len, (char *) start); - start += len; - break; - - case SDP_DATA_SEQ8: - case SDP_DATA_ALT8: - SDP_GET8(len, start); - for (; len > 0; start ++, len --) - fprintf(stdout, "%#2.2x ", *start); - fprintf(stdout, "\n"); - break; - - case SDP_DATA_SEQ16: - case SDP_DATA_ALT16: - SDP_GET16(len, start); - for (; len > 0; start ++, len --) - fprintf(stdout, "%#2.2x ", *start); - fprintf(stdout, "\n"); - break; - - case SDP_DATA_SEQ32: - case SDP_DATA_ALT32: - SDP_GET32(len, start); - for (; len > 0; start ++, len --) - fprintf(stdout, "%#2.2x ", *start); - fprintf(stdout, "\n"); - break; - - default: - fprintf(stderr, "Invalid Protocol Descriptor. " \ - "Unknown data type: %#02x\n", type); - return; - /* NOT REACHED */ - } - } -} /* print_protocol_descriptor */ - -static void -print_protocol_descriptor_list(uint8_t const *start, uint8_t const *end) -{ - uint32_t type, len; - - if (end - start < 2) { - fprintf(stderr, "Invalid Protocol Descriptor List. " \ - "Too short, len=%zd\n", end - start); - return; - } - - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, start); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, start); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, start); - break; - - default: - fprintf(stderr, "Invalid Protocol Descriptor List. " \ - "Not a sequence, type=%#x\n", type); - return; - /* NOT REACHED */ - } - - while (start < end) { - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, start); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, start); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, start); - break; - - default: - fprintf(stderr, "Invalid Protocol Descriptor List. " \ - "Not a sequence, type=%#x\n", type); - return; - /* NOT REACHED */ - } - - print_protocol_descriptor(start, start + len); - start += len; - } -} /* print_protocol_descriptor_list */ - -/* - * Print Bluetooth Profile Descriptor List - * - * The BluetoothProfileDescriptorList attribute consists of a data element - * sequence in which each element is a profile descriptor that contains - * information about a Bluetooth profile to which the service represented by - * this service record conforms. Each profile descriptor is a data element - * sequence whose first element is the UUID assigned to the profile and whose - * second element is a 16-bit profile version number. Each version of a profile - * is assigned a 16-bit unsigned integer profile version number, which consists - * of two 8-bit fields. The higher-order 8 bits contain the major version - * number field and the lower-order 8 bits contain the minor version number - * field. - */ - -static void -print_bluetooth_profile_descriptor_list(uint8_t const *start, uint8_t const *end) -{ - uint32_t type, len, value; - - if (end - start < 2) { - fprintf(stderr, "Invalid Bluetooth Profile Descriptor List. " \ - "Too short, len=%zd\n", end - start); - return; - } - - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, start); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, start); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, start); - break; - - default: - fprintf(stderr, "Invalid Bluetooth Profile Descriptor List. " \ - "Not a sequence, type=%#x\n", type); - return; - /* NOT REACHED */ - } - - while (start < end) { - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(len, start); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(len, start); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(len, start); - break; - - default: - fprintf(stderr, "Invalid Bluetooth Profile " \ - "Descriptor List. " \ - "Not a sequence, type=%#x\n", type); - return; - /* NOT REACHED */ - } - - /* Get UUID */ - SDP_GET8(type, start); - switch (type) { - case SDP_DATA_UUID16: - SDP_GET16(value, start); - fprintf(stdout, "\t%s (%#4.4x) ", - sdp_uuid2desc(value), value); - break; - - case SDP_DATA_UUID32: - SDP_GET32(value, start); - fprintf(stdout, "\t%#8.8x ", value); - break; - - case SDP_DATA_UUID128: { - int128_t uuid; - - SDP_GET_UUID128(&uuid, start); - fprintf(stdout, "\t%#8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.8x ", - ntohl(*(uint32_t *)&uuid.b[0]), - ntohs(*(uint16_t *)&uuid.b[4]), - ntohs(*(uint16_t *)&uuid.b[6]), - ntohs(*(uint16_t *)&uuid.b[8]), - ntohs(*(uint16_t *)&uuid.b[10]), - ntohl(*(uint32_t *)&uuid.b[12])); - } break; - - default: - fprintf(stderr, "Invalid Bluetooth Profile " \ - "Descriptor List. " \ - "Not a UUID, type=%#x\n", type); - return; - /* NOT REACHED */ - } - - /* Get version */ - SDP_GET8(type, start); - if (type != SDP_DATA_UINT16) { - fprintf(stderr, "Invalid Bluetooth Profile " \ - "Descriptor List. " \ - "Invalid version type=%#x\n", type); - return; - } - - SDP_GET16(value, start); - fprintf(stdout, "ver. %d.%d\n", - (value >> 8) & 0xff, value & 0xff); - } -} /* print_bluetooth_profile_descriptor_list */ - -/* Perform SDP search command */ -static int -do_sdp_search(void *xs, int argc, char **argv) -{ - char *ep = NULL; - int32_t n, type, value; - uint16_t service; - - /* Parse command line arguments */ - switch (argc) { - case 1: - n = strtoul(argv[0], &ep, 16); - if (*ep != 0) { - switch (tolower(argv[0][0])) { - case 'c': /* CIP/CTP */ - switch (tolower(argv[0][1])) { - case 'i': - service = SDP_SERVICE_CLASS_COMMON_ISDN_ACCESS; - break; - - case 't': - service = SDP_SERVICE_CLASS_CORDLESS_TELEPHONY; - break; - - default: - return (USAGE); - /* NOT REACHED */ - } - break; - - case 'd': /* DialUp Networking */ - service = SDP_SERVICE_CLASS_DIALUP_NETWORKING; - break; - - case 'f': /* Fax/OBEX File Transfer */ - switch (tolower(argv[0][1])) { - case 'a': - service = SDP_SERVICE_CLASS_FAX; - break; - - case 't': - service = SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER; - break; - - default: - return (USAGE); - /* NOT REACHED */ - } - break; - - case 'g': /* GN */ - service = SDP_SERVICE_CLASS_GN; - break; - - case 'h': /* Headset/HID */ - switch (tolower(argv[0][1])) { - case 'i': - service = SDP_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE; - break; - - case 's': - service = SDP_SERVICE_CLASS_HEADSET; - break; - - default: - return (USAGE); - /* NOT REACHED */ - } - break; - - case 'l': /* LAN Access Using PPP */ - service = SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP; - break; - - case 'n': /* NAP */ - service = SDP_SERVICE_CLASS_NAP; - break; - - case 'o': /* OBEX Object Push */ - service = SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH; - break; - - case 's': /* Serial Port */ - service = SDP_SERVICE_CLASS_SERIAL_PORT; - break; - - default: - return (USAGE); - /* NOT REACHED */ - } - } else - service = (uint16_t) n; - break; - - default: - return (USAGE); - } - - /* Initialize attribute values array */ - for (n = 0; n < values_len; n ++) { - values[n].flags = SDP_ATTR_INVALID; - values[n].attr = 0; - values[n].vlen = BSIZE; - values[n].value = buffer[n]; - } - - /* Do SDP Service Search Attribute Request */ - n = sdp_search(xs, 1, &service, attrs_len, attrs, values_len, values); - if (n != 0) - return (ERROR); - - /* Print attributes values */ - for (n = 0; n < values_len; n ++) { - if (values[n].flags != SDP_ATTR_OK) - break; - - switch (values[n].attr) { - case SDP_ATTR_SERVICE_RECORD_HANDLE: - fprintf(stdout, "\n"); - if (values[n].vlen == 5) { - SDP_GET8(type, values[n].value); - if (type == SDP_DATA_UINT32) { - SDP_GET32(value, values[n].value); - fprintf(stdout, "Record Handle: " \ - "%#8.8x\n", value); - } else - fprintf(stderr, "Invalid type=%#x " \ - "Record Handle " \ - "attribute!\n", type); - } else - fprintf(stderr, "Invalid size=%d for Record " \ - "Handle attribute\n", - values[n].vlen); - break; - - case SDP_ATTR_SERVICE_CLASS_ID_LIST: - fprintf(stdout, "Service Class ID List:\n"); - print_service_class_id_list(values[n].value, - values[n].value + values[n].vlen); - break; - - case SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST: - fprintf(stdout, "Protocol Descriptor List:\n"); - print_protocol_descriptor_list(values[n].value, - values[n].value + values[n].vlen); - break; - - case SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST: - fprintf(stdout, "Bluetooth Profile Descriptor List:\n"); - print_bluetooth_profile_descriptor_list(values[n].value, - values[n].value + values[n].vlen); - break; - - default: - fprintf(stderr, "Unexpected attribute ID=%#4.4x\n", - values[n].attr); - break; - } - } - - return (OK); -} /* do_sdp_search */ - -/* Perform SDP browse command */ -static int -do_sdp_browse(void *xs, int argc, char **argv) -{ -#undef _STR -#undef STR -#define _STR(x) #x -#define STR(x) _STR(x) - - static char const * const av[] = { - STR(SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP), - NULL - }; - - switch (argc) { - case 0: - argc = 1; - argv = (char **) av; - /* FALL THROUGH */ - case 1: - return (do_sdp_search(xs, argc, argv)); - } - - return (USAGE); -} /* do_sdp_browse */ - -/* List of SDP commands */ -struct sdp_command sdp_commands[] = { -{ -"Browse []", -"Browse for services. The parameter is a 16-bit UUID of the group\n" \ -"to browse. If omitted is set to Public Browse Group.\n\n" \ -"\t - xxxx; 16-bit UUID of the group to browse\n", -do_sdp_browse -}, -{ -"Search ", -"Search for the . The parameter is a 16-bit UUID of the\n" \ -"service to search for. For some services it is possible to use service name\n"\ -"instead of service UUID\n\n" \ -"\t - xxxx; 16-bit UUID of the service to search for\n\n" \ -"\tKnown service names\n" \ -"\t===================\n" \ -"\tCIP - Common ISDN Access\n" \ -"\tCTP - Cordless Telephony\n" \ -"\tDUN - DialUp Networking\n" \ -"\tFAX - Fax\n" \ -"\tFTRN - OBEX File Transfer\n" \ -"\tGN - GN\n" \ -"\tHID - Human Interface Device\n" \ -"\tHSET - Headset\n" \ -"\tLAN - LAN Access Using PPP\n" \ -"\tNAP - Network Access Point\n" \ -"\tOPUSH - OBEX Object Push\n" \ -"\tSP - Serial Port\n", -do_sdp_search -}, -{ NULL, NULL, NULL } -}; - diff --git a/usr.sbin/bluetooth/sdpd/Makefile b/usr.sbin/bluetooth/sdpd/Makefile deleted file mode 100644 index c47441f..0000000 --- a/usr.sbin/bluetooth/sdpd/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $Id: Makefile,v 1.1 2004/01/20 21:27:55 max Exp $ -# $FreeBSD$ - -PROG= sdpd -MAN= sdpd.8 -SRCS= bgd.c dun.c ftrn.c gn.c irmc.c irmc_command.c lan.c log.c \ - main.c nap.c opush.c panu.c profile.c provider.c sar.c scr.c \ - sd.c server.c sp.c srr.c ssar.c ssr.c sur.c uuid.c - -CFLAGS+= -I${.CURDIR} -WARNS?= 2 - -.include diff --git a/usr.sbin/bluetooth/sdpd/bgd.c b/usr.sbin/bluetooth/sdpd/bgd.c deleted file mode 100644 index 70dda89..0000000 --- a/usr.sbin/bluetooth/sdpd/bgd.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * bgd.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: bgd.c,v 1.4 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include "profile.h" - -static int32_t -bgd_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_BROWSE_GROUP_DESCRIPTOR - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -bgd_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "Public Browse Group Root"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -bgd_profile_create_group_id( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (buf + 3 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP, buf); - - return (3); -} - -static attr_t bgd_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - bgd_profile_create_service_class_id_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - bgd_profile_create_service_name }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, - bgd_profile_create_service_name }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_PROVIDER_NAME_OFFSET, - common_profile_create_service_provider_name }, - { SDP_ATTR_GROUP_ID, - bgd_profile_create_group_id }, - { 0, NULL } /* end entry */ -}; - -profile_t bgd_profile_descriptor = { - SDP_SERVICE_CLASS_BROWSE_GROUP_DESCRIPTOR, - 0, - (profile_data_valid_p) NULL, - (attr_t const * const) &bgd_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/dun.c b/usr.sbin/bluetooth/sdpd/dun.c deleted file mode 100644 index e7aeb78..0000000 --- a/usr.sbin/bluetooth/sdpd/dun.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * dun.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: dun.c,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -dun_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_DIALUP_NETWORKING - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -dun_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_DIALUP_NETWORKING, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -dun_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "DialUp networking"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -dun_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_dun_profile_p dun = (sdp_dun_profile_p) provider->data; - - return (rfcomm_profile_create_protocol_descriptor_list( - buf, eob, - (uint8_t const *) &dun->server_channel, 1)); -} - -static int32_t -dun_profile_create_audio_feedback_support( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_dun_profile_p dun = (sdp_dun_profile_p) provider->data; - - if (buf + 2 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_BOOL, buf); - SDP_PUT8(dun->audio_feedback_support, buf); - - return (2); -} - -static attr_t dun_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - dun_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - dun_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - dun_profile_create_service_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - dun_profile_create_protocol_descriptor_list }, - { SDP_ATTR_AUDIO_FEEDBACK_SUPPORT, - dun_profile_create_audio_feedback_support }, - { 0, NULL } /* end entry */ -}; - -profile_t dun_profile_descriptor = { - SDP_SERVICE_CLASS_DIALUP_NETWORKING, - sizeof(sdp_dun_profile_t), - common_profile_server_channel_valid, - (attr_t const * const) &dun_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/ftrn.c b/usr.sbin/bluetooth/sdpd/ftrn.c deleted file mode 100644 index bcebfc7..0000000 --- a/usr.sbin/bluetooth/sdpd/ftrn.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * ftrn.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: ftrn.c,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -ftrn_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -ftrn_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -ftrn_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "OBEX File Transfer"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -ftrn_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_ftrn_profile_p ftrn = (sdp_ftrn_profile_p) provider->data; - - return (obex_profile_create_protocol_descriptor_list( - buf, eob, - (uint8_t const *) &ftrn->server_channel, 1)); -} - -static attr_t ftrn_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - ftrn_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - ftrn_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - ftrn_profile_create_service_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - ftrn_profile_create_protocol_descriptor_list }, - { 0, NULL } /* end entry */ -}; - -profile_t ftrn_profile_descriptor = { - SDP_SERVICE_CLASS_OBEX_FILE_TRANSFER, - sizeof(sdp_ftrn_profile_t), - common_profile_server_channel_valid, - (attr_t const * const) &ftrn_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/gn.c b/usr.sbin/bluetooth/sdpd/gn.c deleted file mode 100644 index d35c0ee..0000000 --- a/usr.sbin/bluetooth/sdpd/gn.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * gn.c - */ - -/*- - * Copyright (c) 2008 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: gn.c,v 1.1 2008/03/11 00:02:42 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -gn_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_GN - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -gn_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_GN, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -gn_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "Group Ad-hoc Network"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -gn_profile_create_service_description( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_descr[] = - "Personal Group Ad-hoc Network Service"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_descr, - strlen(service_descr))); -} - -static int32_t -gn_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; - - return (bnep_profile_create_protocol_descriptor_list( - buf, eob, (uint8_t const *) &gn->psm, - sizeof(gn->psm))); -} - -static int32_t -gn_profile_create_security_description( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; - - return (bnep_profile_create_security_description(buf, eob, - (uint8_t const *) &gn->security_description, - sizeof(gn->security_description))); -} - -static int32_t -gn_profile_create_service_availability( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_gn_profile_p gn = (sdp_gn_profile_p) provider->data; - - return (common_profile_create_service_availability(buf, eob, - &gn->load_factor, 1)); -} - -static int32_t -gn_profile_data_valid(uint8_t const *data, uint32_t datalen) -{ - sdp_gn_profile_p gn = (sdp_gn_profile_p) data; - - return ((gn->psm == 0)? 0 : 1); -} - -static attr_t gn_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - gn_profile_create_service_class_id_list }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - gn_profile_create_protocol_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_SERVICE_AVAILABILITY, - gn_profile_create_service_availability }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - gn_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - gn_profile_create_service_name }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, - gn_profile_create_service_description }, - { SDP_ATTR_SECURITY_DESCRIPTION, - gn_profile_create_security_description }, - { 0, NULL } /* end entry */ -}; - -profile_t gn_profile_descriptor = { - SDP_SERVICE_CLASS_GN, - sizeof(sdp_gn_profile_t), - gn_profile_data_valid, - (attr_t const * const) &gn_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/irmc.c b/usr.sbin/bluetooth/sdpd/irmc.c deleted file mode 100644 index d28a120..0000000 --- a/usr.sbin/bluetooth/sdpd/irmc.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * irmc.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: irmc.c,v 1.6 2004/01/13 19:31:54 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -irmc_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_IR_MC_SYNC - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -irmc_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_IR_MC_SYNC, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -irmc_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "IrMC Synchronization"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -irmc_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_irmc_profile_p irmc = (sdp_irmc_profile_p) provider->data; - - return (obex_profile_create_protocol_descriptor_list( - buf, eob, - (uint8_t const *) &irmc->server_channel, 1)); -} - -static int32_t -irmc_profile_create_supported_formats_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_irmc_profile_p irmc = (sdp_irmc_profile_p) provider->data; - - return (obex_profile_create_supported_formats_list( - buf, eob, - (uint8_t const *) irmc->supported_formats, - irmc->supported_formats_size)); -} - -static attr_t irmc_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - irmc_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - irmc_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - irmc_profile_create_service_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - irmc_profile_create_protocol_descriptor_list }, - { SDP_ATTR_SUPPORTED_FORMATS_LIST, - irmc_profile_create_supported_formats_list }, - { 0, NULL } /* end entry */ -}; - -profile_t irmc_profile_descriptor = { - SDP_SERVICE_CLASS_IR_MC_SYNC, - sizeof(sdp_irmc_profile_t), - obex_profile_data_valid, - (attr_t const * const) &irmc_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/irmc_command.c b/usr.sbin/bluetooth/sdpd/irmc_command.c deleted file mode 100644 index 10dafe0..0000000 --- a/usr.sbin/bluetooth/sdpd/irmc_command.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * irmc_command_command_command.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: irmc_command.c,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -irmc_command_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -irmc_command_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -irmc_command_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "Sync Command Service"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -irmc_command_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_irmc_command_profile_p irmc_command = (sdp_irmc_command_profile_p) provider->data; - - return (obex_profile_create_protocol_descriptor_list( - buf, eob, - (uint8_t const *) &irmc_command->server_channel, 1)); -} - -static attr_t irmc_command_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - irmc_command_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - irmc_command_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - irmc_command_profile_create_service_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - irmc_command_profile_create_protocol_descriptor_list }, - { 0, NULL } /* end entry */ -}; - -profile_t irmc_command_profile_descriptor = { - SDP_SERVICE_CLASS_IR_MC_SYNC_COMMAND, - sizeof(sdp_irmc_command_profile_t), - common_profile_server_channel_valid, - (attr_t const * const) &irmc_command_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/lan.c b/usr.sbin/bluetooth/sdpd/lan.c deleted file mode 100644 index 2425a89..0000000 --- a/usr.sbin/bluetooth/sdpd/lan.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * lan.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: lan.c,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -lan_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -lan_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -lan_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "LAN Access using PPP"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -lan_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_lan_profile_p lan = (sdp_lan_profile_p) provider->data; - - return (rfcomm_profile_create_protocol_descriptor_list( - buf, eob, - (uint8_t const *) &lan->server_channel, 1)); -} - -static int32_t -lan_profile_create_service_availability( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_lan_profile_p lan = (sdp_lan_profile_p) provider->data; - - return (common_profile_create_service_availability(buf, eob, - &lan->load_factor, 1)); -} - -static int32_t -lan_profile_create_ip_subnet( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_lan_profile_p lan = (sdp_lan_profile_p) provider->data; - char net[32]; - int32_t len; - - len = snprintf(net, sizeof(net), "%s/%d", - inet_ntoa(* (struct in_addr *) &lan->ip_subnet), - lan->ip_subnet_radius); - - if (len < 0 || buf + 2 + len > eob) - return (-1); - - SDP_PUT8(SDP_DATA_STR8, buf); - SDP_PUT8(len, buf); - memcpy(buf, net, len); - - return (2 + len); -} - -static int32_t -lan_profile_data_valid(uint8_t const *data, uint32_t datalen) -{ - sdp_lan_profile_p lan = (sdp_lan_profile_p) data; - - if (lan->server_channel < 1 || - lan->server_channel > 30 || - lan->ip_subnet_radius > 32) - return (0); - - return (1); -} - -static attr_t lan_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - lan_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - lan_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - lan_profile_create_service_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - lan_profile_create_protocol_descriptor_list }, - { SDP_ATTR_SERVICE_AVAILABILITY, - lan_profile_create_service_availability }, - { SDP_ATTR_IP_SUBNET, - lan_profile_create_ip_subnet }, - { 0, NULL } /* end entry */ -}; - -profile_t lan_profile_descriptor = { - SDP_SERVICE_CLASS_LAN_ACCESS_USING_PPP, - sizeof(sdp_lan_profile_t), - lan_profile_data_valid, - (attr_t const * const) &lan_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/log.c b/usr.sbin/bluetooth/sdpd/log.c deleted file mode 100644 index b03f7e1..0000000 --- a/usr.sbin/bluetooth/sdpd/log.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * log.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: log.c,v 1.1 2004/01/07 23:15:00 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include - -void -log_open(char const *prog, int32_t log2stderr) -{ - openlog(prog, LOG_PID|LOG_NDELAY|(log2stderr? LOG_PERROR:0), LOG_USER); -} - -void -log_close(void) -{ - closelog(); -} - -void -log_emerg(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_EMERG, message, ap); - va_end(ap); -} - -void -log_alert(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_ALERT, message, ap); - va_end(ap); -} - -void -log_crit(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_CRIT, message, ap); - va_end(ap); -} - -void -log_err(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_ERR, message, ap); - va_end(ap); -} - -void -log_warning(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_WARNING, message, ap); - va_end(ap); -} - -void -log_notice(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_NOTICE, message, ap); - va_end(ap); -} - -void -log_info(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_INFO, message, ap); - va_end(ap); -} - -void -log_debug(char const *message, ...) -{ - va_list ap; - - va_start(ap, message); - vsyslog(LOG_DEBUG, message, ap); - va_end(ap); -} - diff --git a/usr.sbin/bluetooth/sdpd/log.h b/usr.sbin/bluetooth/sdpd/log.h deleted file mode 100644 index 8c9ce77..0000000 --- a/usr.sbin/bluetooth/sdpd/log.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * log.h - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: log.h,v 1.1 2004/01/07 23:15:00 max Exp $ - * $FreeBSD$ - */ - -#ifndef _LOG_H_ -#define _LOG_H_ - -void log_open (char const *prog, int32_t log2stderr); -void log_close (void); -void log_emerg (char const *message, ...); -void log_alert (char const *message, ...); -void log_crit (char const *message, ...); -void log_err (char const *message, ...); -void log_warning (char const *message, ...); -void log_notice (char const *message, ...); -void log_info (char const *message, ...); -void log_debug (char const *message, ...); - -#endif /* ndef _LOG_H_ */ - diff --git a/usr.sbin/bluetooth/sdpd/main.c b/usr.sbin/bluetooth/sdpd/main.c deleted file mode 100644 index 1df3bf0..0000000 --- a/usr.sbin/bluetooth/sdpd/main.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * main.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: main.c,v 1.8 2004/01/13 19:31:54 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "log.h" -#include "server.h" - -#include -#include -#include -#include "profile.h" -#include "provider.h" - -#define SDPD "sdpd" - -static int32_t drop_root (char const *user, char const *group); -static void sighandler (int32_t s); -static void usage (void); - -static int32_t done; - -/* - * Bluetooth Service Discovery Procotol (SDP) daemon - */ - -int -main(int argc, char *argv[]) -{ - server_t server; - char const *control = SDP_LOCAL_PATH; - char const *user = "nobody", *group = "nobody"; - int32_t detach = 1, opt; - struct sigaction sa; - - while ((opt = getopt(argc, argv, "c:dg:hu:")) != -1) { - switch (opt) { - case 'c': /* control */ - control = optarg; - break; - - case 'd': /* do not detach */ - detach = 0; - break; - - case 'g': /* group */ - group = optarg; - break; - - case 'u': /* user */ - user = optarg; - break; - - case 'h': - default: - usage(); - /* NOT REACHED */ - } - } - - log_open(SDPD, !detach); - - /* Become daemon if required */ - if (detach && daemon(0, 0) < 0) { - log_crit("Could not become daemon. %s (%d)", - strerror(errno), errno); - exit(1); - } - - /* Set signal handlers */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sighandler; - - if (sigaction(SIGTERM, &sa, NULL) < 0 || - sigaction(SIGHUP, &sa, NULL) < 0 || - sigaction(SIGINT, &sa, NULL) < 0) { - log_crit("Could not install signal handlers. %s (%d)", - strerror(errno), errno); - exit(1); - } - - sa.sa_handler = SIG_IGN; - if (sigaction(SIGPIPE, &sa, NULL) < 0) { - log_crit("Could not install signal handlers. %s (%d)", - strerror(errno), errno); - exit(1); - } - - /* Initialize server */ - if (server_init(&server, control) < 0) - exit(1); - - if ((user != NULL || group != NULL) && drop_root(user, group) < 0) - exit(1); - - for (done = 0; !done; ) { - if (server_do(&server) != 0) - done ++; - } - - server_shutdown(&server); - log_close(); - - return (0); -} - -/* - * Drop root - */ - -static int32_t -drop_root(char const *user, char const *group) -{ - int uid, gid; - char *ep; - - if ((uid = getuid()) != 0) { - log_notice("Cannot set uid/gid. Not a superuser"); - return (0); /* dont do anything unless root */ - } - - gid = getgid(); - - if (user != NULL) { - uid = strtol(user, &ep, 10); - if (*ep != '\0') { - struct passwd *pwd = getpwnam(user); - - if (pwd == NULL) { - log_err("Could not find passwd entry for " \ - "user %s", user); - return (-1); - } - - uid = pwd->pw_uid; - } - } - - if (group != NULL) { - gid = strtol(group, &ep, 10); - if (*ep != '\0') { - struct group *grp = getgrnam(group); - - if (grp == NULL) { - log_err("Could not find group entry for " \ - "group %s", group); - return (-1); - } - - gid = grp->gr_gid; - } - } - - if (setgid(gid) < 0) { - log_err("Could not setgid(%s). %s (%d)", - group, strerror(errno), errno); - return (-1); - } - - if (setuid(uid) < 0) { - log_err("Could not setuid(%s). %s (%d)", - user, strerror(errno), errno); - return (-1); - } - - return (0); -} - -/* - * Signal handler - */ - -static void -sighandler(int32_t s) -{ - log_notice("Got signal %d. Total number of signals received %d", - s, ++ done); -} - -/* - * Display usage information and quit - */ - -static void -usage(void) -{ - fprintf(stderr, -"Usage: %s [options]\n" \ -"Where options are:\n" \ -" -c specify control socket name (default %s)\n" \ -" -d do not detach (run in foreground)\n" \ -" -g grp specify group\n" \ -" -h display usage and exit\n" \ -" -u usr specify user\n", - SDPD, SDP_LOCAL_PATH); - exit(255); -} - diff --git a/usr.sbin/bluetooth/sdpd/nap.c b/usr.sbin/bluetooth/sdpd/nap.c deleted file mode 100644 index 5a857d8..0000000 --- a/usr.sbin/bluetooth/sdpd/nap.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * nap.c - */ - -/*- - * Copyright (c) 2008 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: nap.c,v 1.1 2008/03/11 00:02:42 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -nap_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_NAP - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -nap_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_NAP, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -nap_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "Network Access Point"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -nap_profile_create_service_description( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_descr[] = "Personal Ad-hoc Network Service"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_descr, - strlen(service_descr))); -} - -static int32_t -nap_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_nap_profile_p nap = (sdp_nap_profile_p) provider->data; - - return (bnep_profile_create_protocol_descriptor_list( - buf, eob, (uint8_t const *) &nap->psm, - sizeof(nap->psm))); -} - -static int32_t -nap_profile_create_security_description( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_nap_profile_p nap = (sdp_nap_profile_p) provider->data; - - return (bnep_profile_create_security_description(buf, eob, - (uint8_t const *) &nap->security_description, - sizeof(nap->security_description))); -} - -static int32_t -nap_profile_create_net_access_type( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_nap_profile_p nap = (sdp_nap_profile_p) provider->data; - - if (buf + 3 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(nap->net_access_type, buf); - - return (3); -} - -static int32_t -nap_profile_create_max_net_access_rate( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_nap_profile_p nap = (sdp_nap_profile_p) provider->data; - - if (buf + 3 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(nap->max_net_access_rate, buf); - - return (3); -} - -static int32_t -nap_profile_create_service_availability( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_nap_profile_p nap = (sdp_nap_profile_p) provider->data; - - return (common_profile_create_service_availability(buf, eob, - &nap->load_factor, 1)); -} - -static int32_t -nap_profile_data_valid(uint8_t const *data, uint32_t datalen) -{ - sdp_nap_profile_p nap = (sdp_nap_profile_p) data; - - return ((nap->psm == 0)? 0 : 1); -} - -static attr_t nap_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - nap_profile_create_service_class_id_list }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - nap_profile_create_protocol_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_SERVICE_AVAILABILITY, - nap_profile_create_service_availability }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - nap_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - nap_profile_create_service_name }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, - nap_profile_create_service_description }, - { SDP_ATTR_SECURITY_DESCRIPTION, - nap_profile_create_security_description }, - { SDP_ATTR_NET_ACCESS_TYPE, - nap_profile_create_net_access_type }, - { SDP_ATTR_MAX_NET_ACCESS_RATE, - nap_profile_create_max_net_access_rate }, - { 0, NULL } /* end entry */ -}; - -profile_t nap_profile_descriptor = { - SDP_SERVICE_CLASS_NAP, - sizeof(sdp_nap_profile_t), - nap_profile_data_valid, - (attr_t const * const) &nap_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/opush.c b/usr.sbin/bluetooth/sdpd/opush.c deleted file mode 100644 index 36359da..0000000 --- a/usr.sbin/bluetooth/sdpd/opush.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * opush.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: opush.c,v 1.6 2004/01/13 19:31:54 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -opush_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -opush_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -opush_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "OBEX Object Push"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -opush_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_opush_profile_p opush = (sdp_opush_profile_p) provider->data; - - return (obex_profile_create_protocol_descriptor_list( - buf, eob, - (uint8_t const *) &opush->server_channel, 1)); -} - -static int32_t -opush_profile_create_supported_formats_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_opush_profile_p opush = (sdp_opush_profile_p) provider->data; - - return (obex_profile_create_supported_formats_list( - buf, eob, - (uint8_t const *) opush->supported_formats, - opush->supported_formats_size)); -} - -static attr_t opush_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - opush_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - opush_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - opush_profile_create_service_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - opush_profile_create_protocol_descriptor_list }, - { SDP_ATTR_SUPPORTED_FORMATS_LIST, - opush_profile_create_supported_formats_list }, - { 0, NULL } /* end entry */ -}; - -profile_t opush_profile_descriptor = { - SDP_SERVICE_CLASS_OBEX_OBJECT_PUSH, - sizeof(sdp_opush_profile_t), - obex_profile_data_valid, - (attr_t const * const) &opush_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/panu.c b/usr.sbin/bluetooth/sdpd/panu.c deleted file mode 100644 index e00f650..0000000 --- a/usr.sbin/bluetooth/sdpd/panu.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * panu.c - */ - -/*- - * Copyright (c) 2008 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: panu.c,v 1.1 2008/03/11 00:02:42 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -panu_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_PANU - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -panu_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_PANU, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -panu_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "Personal Ad-hoc User Service"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -panu_profile_create_service_description( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_descr[] = - "Personal Ad-hoc User Service"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_descr, - strlen(service_descr))); -} - -static int32_t -panu_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_panu_profile_p panu = (sdp_panu_profile_p) provider->data; - - return (bnep_profile_create_protocol_descriptor_list( - buf, eob, (uint8_t const *) &panu->psm, - sizeof(panu->psm))); -} - -static int32_t -panu_profile_data_valid(uint8_t const *data, uint32_t datalen) -{ - sdp_panu_profile_p panu = (sdp_panu_profile_p) data; - - return ((panu->psm == 0)? 0 : 1); -} - -static int32_t -panu_profile_create_service_availability( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_panu_profile_p panu = (sdp_panu_profile_p) provider->data; - - return (common_profile_create_service_availability( buf, eob, - &panu->load_factor, 1)); -} - -static int32_t -panu_profile_create_security_description( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_panu_profile_p panu = (sdp_panu_profile_p) provider->data; - - return (bnep_profile_create_security_description(buf, eob, - (uint8_t const *) &panu->security_description, - sizeof(panu->security_description))); -} - -static attr_t panu_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - panu_profile_create_service_class_id_list }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - panu_profile_create_protocol_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_SERVICE_AVAILABILITY, - panu_profile_create_service_availability }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - panu_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - panu_profile_create_service_name }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, - panu_profile_create_service_description }, - { SDP_ATTR_SECURITY_DESCRIPTION, - panu_profile_create_security_description }, - { 0, NULL } /* end entry */ -}; - -profile_t panu_profile_descriptor = { - SDP_SERVICE_CLASS_PANU, - sizeof(sdp_panu_profile_t), - panu_profile_data_valid, - (attr_t const * const) &panu_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/profile.c b/usr.sbin/bluetooth/sdpd/profile.c deleted file mode 100644 index f3dfaa7..0000000 --- a/usr.sbin/bluetooth/sdpd/profile.c +++ /dev/null @@ -1,497 +0,0 @@ -/* - * profile.c - */ - -/*- - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: profile.c,v 1.6 2004/01/13 19:31:54 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -/* - * Lookup profile descriptor - */ - -profile_p -profile_get_descriptor(uint16_t uuid) -{ - extern profile_t dun_profile_descriptor; - extern profile_t ftrn_profile_descriptor; - extern profile_t irmc_profile_descriptor; - extern profile_t irmc_command_profile_descriptor; - extern profile_t lan_profile_descriptor; - extern profile_t opush_profile_descriptor; - extern profile_t sp_profile_descriptor; - extern profile_t nap_profile_descriptor; - extern profile_t gn_profile_descriptor; - extern profile_t panu_profile_descriptor; - - static const profile_p profiles[] = { - &dun_profile_descriptor, - &ftrn_profile_descriptor, - &irmc_profile_descriptor, - &irmc_command_profile_descriptor, - &lan_profile_descriptor, - &opush_profile_descriptor, - &sp_profile_descriptor, - &nap_profile_descriptor, - &gn_profile_descriptor, - &panu_profile_descriptor - }; - - int32_t i; - - for (i = 0; i < sizeof(profiles)/sizeof(profiles[0]); i++) - if (profiles[i]->uuid == uuid) - return (profiles[i]); - - return (NULL); -} - -/* - * Look attribute in the profile descripror - */ - -profile_attr_create_p -profile_get_attr(const profile_p profile, uint16_t attr) -{ - attr_p ad = (attr_p) profile->attrs; - - for (; ad->create != NULL; ad ++) - if (ad->attr == attr) - return (ad->create); - - return (NULL); -} - -/* - * uint32 value32 - 5 bytes - */ - -int32_t -common_profile_create_service_record_handle( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (buf + 5 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_UINT32, buf); - SDP_PUT32(((provider_p) data)->handle, buf); - - return (5); -} - -/* - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes - * [ uuid16 value ] - */ - -int32_t -common_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - int32_t len = 3 * (datalen >>= 1); - - if (len <= 0 || len > 0xff || buf + 2 + len > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(len, buf); - - for (; datalen > 0; datalen --) { - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(*((uint16_t const *)data), buf); - data += sizeof(uint16_t); - } - - return (2 + len); -} - -/* - * seq8 len8 - 2 bytes - * seq 8 len8 - 2 bytes - * uuid16 value16 - 3 bytes - * uint16 value16 - 3 bytes - * [ seq 8 len8 - * uuid16 value16 - * uint16 value16 ] - */ - -int32_t -common_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - int32_t len = 8 * (datalen >>= 2); - - if (len <= 0 || len > 0xff || buf + 2 + len > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(len, buf); - - for (; datalen > 0; datalen --) { - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(6, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(*((uint16_t const *)data), buf); - data += sizeof(uint16_t); - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(*((uint16_t const *)data), buf); - data += sizeof(uint16_t); - } - - return (2 + len); -} - -/* - * seq8 len8 - 2 bytes - * uint16 value16 - 3 bytes - * uint16 value16 - 3 bytes - * uint16 value16 - 3 bytes - */ - -int32_t -common_profile_create_language_base_attribute_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (buf + 11 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(9, buf); - - /* - * Language code per ISO 639:1988. Use "en". - */ - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(((0x65 << 8) | 0x6e), buf); - - /* - * Encoding. Recommended is UTF-8. ISO639 UTF-8 MIBenum is 106 - * (http://www.iana.org/assignments/character-sets) - */ - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(106, buf); - - /* - * Offset (Primary Language Base is 0x100) - */ - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID, buf); - - return (11); -} - -/* - * Common provider name is "FreeBSD" - */ - -int32_t -common_profile_create_service_provider_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - char provider_name[] = "FreeBSD"; - - return (common_profile_create_string8(buf, eob, - (uint8_t const *) provider_name, - strlen(provider_name))); -} - -/* - * str8 len8 string - */ - -int32_t -common_profile_create_string8( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (datalen == 0 || datalen > 0xff || buf + 2 + datalen > eob) - return (-1); - - SDP_PUT8(SDP_DATA_STR8, buf); - SDP_PUT8(datalen, buf); - memcpy(buf, data, datalen); - - return (2 + datalen); -} - -/* - * Service Availability - */ - -int32_t -common_profile_create_service_availability( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (datalen != 1 || buf + 2 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_UINT8, buf); - SDP_PUT8(data[0], buf); - - return (2); -} - -/* - * seq8 len8 - 2 bytes - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes - * uint8 value8 - 2 bytes - */ - -int32_t -rfcomm_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (datalen != 1 || buf + 14 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(12, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(3, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_L2CAP, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(5, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_RFCOMM, buf); - SDP_PUT8(SDP_DATA_UINT8, buf); - SDP_PUT8(*data, buf); - - return (14); -} - -/* - * seq8 len8 - 2 bytes - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes - * uint8 value8 - 2 bytes - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes - */ - -int32_t -obex_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (datalen != 1 || buf + 19 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(17, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(3, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_L2CAP, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(5, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_RFCOMM, buf); - SDP_PUT8(SDP_DATA_UINT8, buf); - SDP_PUT8(*data, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(3, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_OBEX, buf); - - return (19); -} - -/* - * seq8 len8 - * uint8 value8 - bytes - * [ uint8 value 8 ] - */ - -int32_t -obex_profile_create_supported_formats_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - int32_t len = 2 * datalen; - - if (len <= 0 || len > 0xff || buf + 2 + len > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(len, buf); - - for (; datalen > 0; datalen --) { - SDP_PUT8(SDP_DATA_UINT8, buf); - SDP_PUT8(*data++, buf); - } - - return (2 + len); -} - -/* - * do not check anything - */ - -int32_t -common_profile_always_valid(uint8_t const *data, uint32_t datalen) -{ - return (1); -} - -/* - * verify server channel number (the first byte in the data) - */ - -int32_t -common_profile_server_channel_valid(uint8_t const *data, uint32_t datalen) -{ - if (data[0] < 1 || data[0] > 30) - return (0); - - return (1); -} - -/* - * verify server channel number and supported_formats_size - * sdp_opush_profile and sdp_irmc_profile - */ - -int32_t -obex_profile_data_valid(uint8_t const *data, uint32_t datalen) -{ - sdp_opush_profile_p opush = (sdp_opush_profile_p) data; - - if (opush->server_channel < 1 || - opush->server_channel > 30 || - opush->supported_formats_size == 0 || - opush->supported_formats_size > sizeof(opush->supported_formats)) - return (0); - - return (1); -} - -/* - * BNEP protocol descriptor - */ - -int32_t -bnep_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - /* supported protocol types */ - uint16_t ptype[] = { - 0x0800, /* IPv4 */ - 0x0806, /* ARP */ -#ifdef INET6 - 0x86dd, /* IPv6 */ -#endif - }; - - uint16_t i, psm, version = 0x0100, - nptypes = sizeof(ptype)/sizeof(ptype[0]), - nptypes_size = nptypes * 3; - - if (datalen != 2 || 18 + nptypes_size > 255 || - buf + 20 + nptypes_size > eob) - return (-1); - - memcpy(&psm, data, sizeof(psm)); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(18 + nptypes_size, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(6, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_L2CAP, buf); - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(psm, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(8 + nptypes_size, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_BNEP, buf); - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(version, buf); - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(nptypes_size, buf); - for (i = 0; i < nptypes; i ++) { - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(ptype[i], buf); - } - - return (20 + nptypes_size); -} - -/* - * BNEP security description - */ - -int32_t -bnep_profile_create_security_description( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - uint16_t security_descr; - - if (datalen != 2 || buf + 3 > eob) - return (-1); - - memcpy(&security_descr, data, sizeof(security_descr)); - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(security_descr, buf); - - return (3); -} - diff --git a/usr.sbin/bluetooth/sdpd/profile.h b/usr.sbin/bluetooth/sdpd/profile.h deleted file mode 100644 index 0b0d86d..0000000 --- a/usr.sbin/bluetooth/sdpd/profile.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * profile.h - */ - -/*- - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: profile.h,v 1.6 2004/01/13 19:31:54 max Exp $ - * $FreeBSD$ - */ - -#ifndef _PROFILE_H_ -#define _PROFILE_H_ - -/* - * Attribute descriptor - */ - -typedef int32_t (profile_attr_create_t)( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen); -typedef profile_attr_create_t * profile_attr_create_p; - -typedef int32_t (profile_data_valid_t)( - uint8_t const *data, uint32_t datalen); -typedef profile_data_valid_t * profile_data_valid_p; - -struct attr -{ - uint16_t attr; /* attribute id */ - profile_attr_create_p create; /* create attr value */ -}; - -typedef struct attr attr_t; -typedef struct attr * attr_p; - -/* - * Profile descriptor - */ - - -struct profile -{ - uint16_t uuid; /* profile uuid */ - uint16_t dsize; /* profile data size */ - profile_data_valid_p valid; /* profile data validator */ - attr_t const * const attrs; /* supported attributes */ -}; - -typedef struct profile profile_t; -typedef struct profile *profile_p; - -profile_p profile_get_descriptor(uint16_t uuid); -profile_attr_create_p profile_get_attr(const profile_p profile, uint16_t attr); - -profile_attr_create_t common_profile_create_service_record_handle; -profile_attr_create_t common_profile_create_service_class_id_list; -profile_attr_create_t common_profile_create_bluetooth_profile_descriptor_list; -profile_attr_create_t common_profile_create_language_base_attribute_id_list; -profile_attr_create_t common_profile_create_service_provider_name; -profile_attr_create_t common_profile_create_string8; -profile_attr_create_t common_profile_create_service_availability; -profile_attr_create_t rfcomm_profile_create_protocol_descriptor_list; -profile_attr_create_t obex_profile_create_protocol_descriptor_list; -profile_attr_create_t obex_profile_create_supported_formats_list; -profile_attr_create_t bnep_profile_create_protocol_descriptor_list; -profile_attr_create_t bnep_profile_create_security_description; - -profile_data_valid_t common_profile_always_valid; -profile_data_valid_t common_profile_server_channel_valid; -profile_data_valid_t obex_profile_data_valid; - -#endif /* ndef _PROFILE_H_ */ - diff --git a/usr.sbin/bluetooth/sdpd/provider.c b/usr.sbin/bluetooth/sdpd/provider.c deleted file mode 100644 index b0f5347..0000000 --- a/usr.sbin/bluetooth/sdpd/provider.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * provider.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: provider.c,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static TAILQ_HEAD(, provider) providers = TAILQ_HEAD_INITIALIZER(providers); -static uint32_t change_state = 0; -static uint32_t handle = 0; - -/* - * Register Service Discovery provider. - * Should not be called more the once. - */ - -int32_t -provider_register_sd(int32_t fd) -{ - extern profile_t sd_profile_descriptor; - extern profile_t bgd_profile_descriptor; - - provider_p sd = calloc(1, sizeof(*sd)); - provider_p bgd = calloc(1, sizeof(*bgd)); - - if (sd == NULL || bgd == NULL) { - if (sd != NULL) - free(sd); - - if (bgd != NULL) - free(bgd); - - return (-1); - } - - sd->profile = &sd_profile_descriptor; - bgd->handle = 0; - sd->fd = fd; - TAILQ_INSERT_HEAD(&providers, sd, provider_next); - - bgd->profile = &bgd_profile_descriptor; - bgd->handle = 1; - sd->fd = fd; - TAILQ_INSERT_AFTER(&providers, sd, bgd, provider_next); - - change_state ++; - - return (0); -} - -/* - * Register new provider for a given profile, bdaddr and session. - */ - -provider_p -provider_register(profile_p const profile, bdaddr_p const bdaddr, int32_t fd, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = calloc(1, sizeof(*provider)); - - if (provider != NULL) { - provider->data = malloc(datalen); - if (provider->data != NULL) { - provider->profile = profile; - memcpy(provider->data, data, datalen); - - /* - * Record handles 0x0 and 0x1 are reserved - * for SDP itself - */ - - if (++ handle <= 1) - handle = 2; - - provider->handle = handle; - - memcpy(&provider->bdaddr, bdaddr, - sizeof(provider->bdaddr)); - provider->fd = fd; - - TAILQ_INSERT_TAIL(&providers, provider, provider_next); - change_state ++; - } else { - free(provider); - provider = NULL; - } - } - - return (provider); -} - -/* - * Unregister provider - */ - -void -provider_unregister(provider_p provider) -{ - TAILQ_REMOVE(&providers, provider, provider_next); - if (provider->data != NULL) - free(provider->data); - free(provider); - change_state ++; -} - -/* - * Update provider data - */ - -int32_t -provider_update(provider_p provider, uint8_t const *data, uint32_t datalen) -{ - uint8_t *new_data = (uint8_t *) realloc(provider->data, datalen); - - if (new_data == NULL) - return (-1); - - memcpy(new_data, data, datalen); - provider->data = new_data; - - return (0); -} - -/* - * Get a provider for given record handle - */ - -provider_p -provider_by_handle(uint32_t handle) -{ - provider_p provider = NULL; - - TAILQ_FOREACH(provider, &providers, provider_next) - if (provider->handle == handle) - break; - - return (provider); -} - -/* - * Cursor access - */ - -provider_p -provider_get_first(void) -{ - return (TAILQ_FIRST(&providers)); -} - -provider_p -provider_get_next(provider_p provider) -{ - return (TAILQ_NEXT(provider, provider_next)); -} - -/* - * Return change state - */ - -uint32_t -provider_get_change_state(void) -{ - return (change_state); -} - diff --git a/usr.sbin/bluetooth/sdpd/provider.h b/usr.sbin/bluetooth/sdpd/provider.h deleted file mode 100644 index b48bc8d..0000000 --- a/usr.sbin/bluetooth/sdpd/provider.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * provider.h - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: provider.h,v 1.6 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#ifndef _PROVIDER_H_ -#define _PROVIDER_H_ - -/* - * Provider of service - */ - -struct profile; - -struct provider -{ - struct profile *profile; /* profile */ - void *data; /* profile data */ - uint32_t handle; /* record handle */ - bdaddr_t bdaddr; /* provider's BDADDR */ - int32_t fd; /* session descriptor */ - TAILQ_ENTRY(provider) provider_next; /* all providers */ -}; - -typedef struct provider provider_t; -typedef struct provider * provider_p; - -#define provider_match_bdaddr(p, b) \ - (memcmp(b, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0 || \ - memcmp(&(p)->bdaddr, NG_HCI_BDADDR_ANY, sizeof(bdaddr_t)) == 0 || \ - memcmp(&(p)->bdaddr, b, sizeof(bdaddr_t)) == 0) - -int32_t provider_register_sd (int32_t fd); -provider_p provider_register (profile_p const profile, - bdaddr_p const bdaddr, - int32_t fd, - uint8_t const *data, - uint32_t datalen); - -void provider_unregister (provider_p provider); -int32_t provider_update (provider_p provider, - uint8_t const *data, - uint32_t datalen); -provider_p provider_by_handle (uint32_t handle); -provider_p provider_get_first (void); -provider_p provider_get_next (provider_p provider); -uint32_t provider_get_change_state (void); - -#endif /* ndef _PROVIDER_H_ */ diff --git a/usr.sbin/bluetooth/sdpd/sar.c b/usr.sbin/bluetooth/sdpd/sar.c deleted file mode 100644 index 4fc25d9..0000000 --- a/usr.sbin/bluetooth/sdpd/sar.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * sar.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: sar.c,v 1.2 2004/01/08 23:46:51 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include /* for NULL */ -#include "profile.h" -#include "provider.h" -#include "server.h" - -/* - * Prepare SDP attr/value pair. Check if profile implements the attribute - * and if so call the attribute value function. - * - * uint16 value16 - 3 bytes (attribute) - * value - N bytes (value) - */ - -static int32_t -server_prepare_attr_value_pair( - provider_p const provider, uint16_t attr, - uint8_t *buf, uint8_t const * const eob) -{ - profile_attr_create_p cf = profile_get_attr(provider->profile, attr); - int32_t len; - - if (cf == NULL) - return (0); /* no attribute */ - - if (buf + 3 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(attr, buf); - - len = cf(buf, eob, (uint8_t const *) provider, sizeof(*provider)); - if (len < 0) - return (-1); - - return (3 + len); -} - -/* - * seq16 value16 - 3 bytes - * attr value - 3+ bytes - * [ attr value ] - */ - -int32_t -server_prepare_attr_list(provider_p const provider, - uint8_t const *req, uint8_t const * const req_end, - uint8_t *rsp, uint8_t const * const rsp_end) -{ - uint8_t *ptr = rsp + 3; - int32_t type, hi, lo, len; - - if (ptr > rsp_end) - return (-1); - - while (req < req_end) { - SDP_GET8(type, req); - - switch (type) { - case SDP_DATA_UINT16: - if (req + 2 > req_end) - return (-1); - - SDP_GET16(lo, req); - hi = lo; - break; - - case SDP_DATA_UINT32: - if (req + 4 > req_end) - return (-1); - - SDP_GET16(lo, req); - SDP_GET16(hi, req); - break; - - default: - return (-1); - /* NOT REACHED */ - } - - for (; lo <= hi; lo ++) { - len = server_prepare_attr_value_pair(provider, lo, ptr, rsp_end); - if (len < 0) - return (-1); - - ptr += len; - } - } - - len = ptr - rsp; /* we put this much bytes in rsp */ - - /* Fix SEQ16 header for the rsp */ - SDP_PUT8(SDP_DATA_SEQ16, rsp); - SDP_PUT16(len - 3, rsp); - - return (len); -} - -/* - * Prepare SDP Service Attribute Response - */ - -int32_t -server_prepare_service_attribute_response(server_p srv, int32_t fd) -{ - uint8_t const *req = srv->req + sizeof(sdp_pdu_t); - uint8_t const *req_end = req + ((sdp_pdu_p)(srv->req))->len; - uint8_t *rsp = srv->fdidx[fd].rsp; - uint8_t const *rsp_end = rsp + NG_L2CAP_MTU_MAXIMUM; - - uint8_t *ptr = NULL; - provider_t *provider = NULL; - uint32_t handle; - int32_t type, rsp_limit, aidlen, cslen, cs; - - /* - * Minimal Service Attribute Request request - * - * value32 - 4 bytes ServiceRecordHandle - * value16 - 2 bytes MaximumAttributeByteCount - * seq8 len8 - 2 bytes - * uint16 value16 - 3 bytes AttributeIDList - * value8 - 1 byte ContinuationState - */ - - if (req_end - req < 12) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get ServiceRecordHandle and MaximumAttributeByteCount */ - SDP_GET32(handle, req); - SDP_GET16(rsp_limit, req); - if (rsp_limit <= 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get size of AttributeIDList */ - aidlen = 0; - SDP_GET8(type, req); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(aidlen, req); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(aidlen, req); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(aidlen, req); - break; - } - if (aidlen <= 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - ptr = (uint8_t *) req + aidlen; - - /* Get ContinuationState */ - if (ptr + 1 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET8(cslen, ptr); - if (cslen != 0) { - if (cslen != 2 || req_end - ptr != 2) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET16(cs, ptr); - } else - cs = 0; - - /* Process the request. First, check continuation state */ - if (srv->fdidx[fd].rsp_cs != cs) - return (SDP_ERROR_CODE_INVALID_CONTINUATION_STATE); - if (srv->fdidx[fd].rsp_size > 0) - return (0); - - /* Lookup record handle */ - if ((provider = provider_by_handle(handle)) == NULL) - return (SDP_ERROR_CODE_INVALID_SERVICE_RECORD_HANDLE); - - /* - * Service Attribute Response format - * - * value16 - 2 bytes AttributeListByteCount (not incl.) - * seq8 len16 - 3 bytes - * attr value - 3+ bytes AttributeList - * [ attr value ] - */ - - cs = server_prepare_attr_list(provider, req, req+aidlen, rsp, rsp_end); - if (cs < 0) - return (SDP_ERROR_CODE_INSUFFICIENT_RESOURCES); - - /* Set reply size (not counting PDU header and continuation state) */ - srv->fdidx[fd].rsp_limit = srv->fdidx[fd].omtu - sizeof(sdp_pdu_t) - 2; - if (srv->fdidx[fd].rsp_limit > rsp_limit) - srv->fdidx[fd].rsp_limit = rsp_limit; - - srv->fdidx[fd].rsp_size = cs; - srv->fdidx[fd].rsp_cs = 0; - - return (0); -} - -/* - * Send SDP Service [Search] Attribute Response - */ - -int32_t -server_send_service_attribute_response(server_p srv, int32_t fd) -{ - uint8_t *rsp = srv->fdidx[fd].rsp + srv->fdidx[fd].rsp_cs; - uint8_t *rsp_end = srv->fdidx[fd].rsp + srv->fdidx[fd].rsp_size; - - struct iovec iov[4]; - sdp_pdu_t pdu; - uint16_t bcount; - uint8_t cs[3]; - int32_t size; - - /* First update continuation state (assume we will send all data) */ - size = rsp_end - rsp; - srv->fdidx[fd].rsp_cs += size; - - if (size + 1 > srv->fdidx[fd].rsp_limit) { - /* - * We need to split out response. Add 3 more bytes for the - * continuation state and move rsp_end and rsp_cs backwards. - */ - - while ((rsp_end - rsp) + 3 > srv->fdidx[fd].rsp_limit) { - rsp_end --; - srv->fdidx[fd].rsp_cs --; - } - - cs[0] = 2; - cs[1] = srv->fdidx[fd].rsp_cs >> 8; - cs[2] = srv->fdidx[fd].rsp_cs & 0xff; - } else - cs[0] = 0; - - assert(rsp_end >= rsp); - - bcount = rsp_end - rsp; - - if (((sdp_pdu_p)(srv->req))->pid == SDP_PDU_SERVICE_ATTRIBUTE_REQUEST) - pdu.pid = SDP_PDU_SERVICE_ATTRIBUTE_RESPONSE; - else - pdu.pid = SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_RESPONSE; - - pdu.tid = ((sdp_pdu_p)(srv->req))->tid; - pdu.len = htons(sizeof(bcount) + bcount + 1 + cs[0]); - - bcount = htons(bcount); - - iov[0].iov_base = &pdu; - iov[0].iov_len = sizeof(pdu); - - iov[1].iov_base = &bcount; - iov[1].iov_len = sizeof(bcount); - - iov[2].iov_base = rsp; - iov[2].iov_len = rsp_end - rsp; - - iov[3].iov_base = cs; - iov[3].iov_len = 1 + cs[0]; - - do { - size = writev(fd, (struct iovec const *) &iov, sizeof(iov)/sizeof(iov[0])); - } while (size < 0 && errno == EINTR); - - /* Check if we have sent (or failed to sent) last response chunk */ - if (srv->fdidx[fd].rsp_cs == srv->fdidx[fd].rsp_size) { - srv->fdidx[fd].rsp_cs = 0; - srv->fdidx[fd].rsp_size = 0; - srv->fdidx[fd].rsp_limit = 0; - } - - return ((size < 0)? errno : 0); -} - diff --git a/usr.sbin/bluetooth/sdpd/scr.c b/usr.sbin/bluetooth/sdpd/scr.c deleted file mode 100644 index d0c9ec5..0000000 --- a/usr.sbin/bluetooth/sdpd/scr.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * scr.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: scr.c,v 1.1 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" -#include "server.h" - -/* - * Prepare Service Change response - */ - -int32_t -server_prepare_service_change_response(server_p srv, int32_t fd) -{ - uint8_t const *req = srv->req + sizeof(sdp_pdu_t); - uint8_t const *req_end = req + ((sdp_pdu_p)(srv->req))->len; - uint8_t *rsp = srv->fdidx[fd].rsp; - - provider_t *provider = NULL; - uint32_t handle; - - /* - * Minimal Service Change Request - * - * value32 - handle 4 bytes - */ - - if (!srv->fdidx[fd].control || - !srv->fdidx[fd].priv || req_end - req < 4) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get handle */ - SDP_GET32(handle, req); - - /* Lookup provider */ - provider = provider_by_handle(handle); - if (provider == NULL || provider->fd != fd) - return (SDP_ERROR_CODE_INVALID_SERVICE_RECORD_HANDLE); - - /* Validate user data */ - if (req_end - req < provider->profile->dsize || - provider->profile->valid == NULL || - (provider->profile->valid)(req, req_end - req) == 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Update provider */ - if (provider_update(provider, req, req_end - req) < 0) - return (SDP_ERROR_CODE_INSUFFICIENT_RESOURCES); - - SDP_PUT16(0, rsp); - - /* Set reply size */ - srv->fdidx[fd].rsp_limit = srv->fdidx[fd].omtu - sizeof(sdp_pdu_t); - srv->fdidx[fd].rsp_size = rsp - srv->fdidx[fd].rsp; - srv->fdidx[fd].rsp_cs = 0; - - return (0); -} - diff --git a/usr.sbin/bluetooth/sdpd/sd.c b/usr.sbin/bluetooth/sdpd/sd.c deleted file mode 100644 index 1743ea7..0000000 --- a/usr.sbin/bluetooth/sdpd/sd.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * sd.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: sd.c,v 1.4 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -sd_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -sd_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -sd_profile_create_service_id( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (buf + 3 > eob) - return (-1); - - /* - * The ServiceID is a UUID that universally and uniquely identifies - * the service instance described by the service record. This service - * attribute is particularly useful if the same service is described - * by service records in more than one SDP server - */ - - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_SDP, buf); /* XXX ??? */ - - return (3); -} - -static int32_t -sd_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "Bluetooth service discovery"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -sd_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (buf + 12 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(10, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(3, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_L2CAP, buf); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(3, buf); - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_UUID_PROTOCOL_SDP, buf); - - return (12); -} - -static int32_t -sd_profile_create_browse_group_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (buf + 5 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(3, buf); - - /* - * The top-level browse group ID, called PublicBrowseRoot and - * representing the root of the browsing hierarchy, has the value - * 00001002-0000-1000-8000-00805F9B34FB (UUID16: 0x1002) from the - * Bluetooth Assigned Numbers document - */ - - SDP_PUT8(SDP_DATA_UUID16, buf); - SDP_PUT16(SDP_SERVICE_CLASS_PUBLIC_BROWSE_GROUP, buf); - - return (5); -} - -static int32_t -sd_profile_create_version_number_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - if (buf + 5 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_SEQ8, buf); - SDP_PUT8(3, buf); - - /* - * The VersionNumberList is a data element sequence in which each - * element of the sequence is a version number supported by the SDP - * server. A version number is a 16-bit unsigned integer consisting - * of two fields. The higher-order 8 bits contain the major version - * number field and the low-order 8 bits contain the minor version - * number field. The initial version of SDP has a major version of - * 1 and a minor version of 0 - */ - - SDP_PUT8(SDP_DATA_UINT16, buf); - SDP_PUT16(0x0100, buf); - - return (5); -} - -static int32_t -sd_profile_create_service_database_state( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - uint32_t change_state = provider_get_change_state(); - - if (buf + 5 > eob) - return (-1); - - SDP_PUT8(SDP_DATA_UINT32, buf); - SDP_PUT32(change_state, buf); - - return (5); -} - -static attr_t sd_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - sd_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - sd_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_SERVICE_ID, - sd_profile_create_service_id }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - sd_profile_create_service_name }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_DESCRIPTION_OFFSET, - sd_profile_create_service_name }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_PROVIDER_NAME_OFFSET, - common_profile_create_service_provider_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - sd_profile_create_protocol_descriptor_list }, - { SDP_ATTR_BROWSE_GROUP_LIST, - sd_profile_create_browse_group_list }, - { SDP_ATTR_VERSION_NUMBER_LIST, - sd_profile_create_version_number_list }, - { SDP_ATTR_SERVICE_DATABASE_STATE, - sd_profile_create_service_database_state }, - { 0, NULL } /* end entry */ -}; - -profile_t sd_profile_descriptor = { - SDP_SERVICE_CLASS_SERVICE_DISCOVERY_SERVER, - 0, - (profile_data_valid_p) NULL, - (attr_t const * const) &sd_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/sdpd.8 b/usr.sbin/bluetooth/sdpd/sdpd.8 deleted file mode 100644 index 0844e30..0000000 --- a/usr.sbin/bluetooth/sdpd/sdpd.8 +++ /dev/null @@ -1,140 +0,0 @@ -.\" Copyright (c) 2004 Maksim Yevmenkin -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: sdpd.8,v 1.1 2004/01/13 19:31:54 max Exp $ -.\" $FreeBSD$ -.\" -.Dd January 13, 2004 -.Dt SDPD 8 -.Os -.Sh NAME -.Nm sdpd -.Nd Bluetooth Service Discovery Protocol daemon -.Sh SYNOPSIS -.Nm -.Op Fl dh -.Op Fl c Ar path -.Op Fl g Ar group -.Op Fl u Ar user -.Sh DESCRIPTION -The -.Nm -daemon keeps track of the Bluetooth services registered on the host -and responds to Service Discovery inquiries from the remote Bluetooth devices. -.Pp -In order to use any service remote Bluetooth device need to send Service -Search and Service Attribute or Service Search Attribute request over -Bluetooth L2CAP connection on SDP PSM (0x0001). -The -.Nm -daemon will try to find matching Service Record in its Service Database -and will send appropriate response back. -The remote device then will process the response, extract all required -information and will make a separate connection in order to use the service. -.Pp -Bluetooth applications, running on the host, register services with -the local -.Nm -daemon. -Operation like service registration, service removal and service change are -performed over the control socket. -It is possible to query entire content of the -.Nm -Service Database with -.Xr sdpcontrol 8 -by issuing -.Cm browse -command on the control socket. -.Pp -The command line options are as follows: -.Bl -tag -width indent -.It Fl d -Do not detach from the controlling terminal. -.It Fl c Ar path -Specify path to the control socket. -The default path is -.Pa /var/run/sdp . -.It Fl g Ar group -Specifies the group the -.Nm -should run as after it initializes. -The value specified may be either a group name or a numeric group ID. -This only works if -.Nm -was started as root. -The default group name is -.Dq Li nobody . -.It Fl h -Display usage message and exit. -.It Fl u Ar user -Specifies the user the -.Nm -should run as after it initializes. -The value specified may be either a user name or a numeric user ID. -This only works if -.Nm -was started as root. -The default user name is -.Dq Li nobody . -.El -.Sh CAVEAT -The -.Nm -daemon -will listen for incoming L2CAP connections on a wildcard BD_ADDR. -.Pp -In case of multiple Bluetooth devices connected to the same host it is -possible to specify which services should be -.Dq bound -to which Bluetooth device. -Such assignment should be done at service registration time. -.Pp -Requests to register, remove or change service can only be made via the -control socket. -The -.Nm -daemon will check peer's credentials and will only accept the request if -the application has the same effective user ID as the -.Dq Li root -user ID. -.Pp -The -.Nm -daemon does not check for duplicated Service Records. -It only performs minimal checking on the service data sent in the Service -Register request. -It is assumed that application must obtain all required resources such -as RFCOMM channels etc., before registering the service. -.Sh FILES -.Bl -tag -width ".Pa /var/run/sdp" -compact -.It Pa /var/run/sdp -.El -.Sh SEE ALSO -.Xr sdp 3 , -.Xr sdpcontrol 8 -.Sh AUTHORS -.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com -.Sh BUGS -Most likely. -Please report if found. diff --git a/usr.sbin/bluetooth/sdpd/server.c b/usr.sbin/bluetooth/sdpd/server.c deleted file mode 100644 index 816c6f5..0000000 --- a/usr.sbin/bluetooth/sdpd/server.c +++ /dev/null @@ -1,589 +0,0 @@ -/* - * server.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: server.c,v 1.6 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "log.h" -#include "profile.h" -#include "provider.h" -#include "server.h" - -static void server_accept_client (server_p srv, int32_t fd); -static int32_t server_process_request (server_p srv, int32_t fd); -static int32_t server_send_error_response (server_p srv, int32_t fd, - uint16_t error); -static void server_close_fd (server_p srv, int32_t fd); - -/* - * Initialize server - */ - -int32_t -server_init(server_p srv, char const *control) -{ - struct sockaddr_un un; - struct sockaddr_l2cap l2; - int32_t unsock, l2sock; - socklen_t size; - uint16_t imtu; - - assert(srv != NULL); - assert(control != NULL); - - memset(srv, 0, sizeof(srv)); - - /* Open control socket */ - if (unlink(control) < 0 && errno != ENOENT) { - log_crit("Could not unlink(%s). %s (%d)", - control, strerror(errno), errno); - return (-1); - } - - unsock = socket(PF_LOCAL, SOCK_STREAM, 0); - if (unsock < 0) { - log_crit("Could not create control socket. %s (%d)", - strerror(errno), errno); - return (-1); - } - - memset(&un, 0, sizeof(un)); - un.sun_len = sizeof(un); - un.sun_family = AF_LOCAL; - strlcpy(un.sun_path, control, sizeof(un.sun_path)); - - if (bind(unsock, (struct sockaddr *) &un, sizeof(un)) < 0) { - log_crit("Could not bind control socket. %s (%d)", - strerror(errno), errno); - close(unsock); - return (-1); - } - - if (chmod(control, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) < 0) { - log_crit("Could not change permissions on control socket. " \ - "%s (%d)", strerror(errno), errno); - close(unsock); - return (-1); - } - - if (listen(unsock, 10) < 0) { - log_crit("Could not listen on control socket. %s (%d)", - strerror(errno), errno); - close(unsock); - return (-1); - } - - /* Open L2CAP socket */ - l2sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BLUETOOTH_PROTO_L2CAP); - if (l2sock < 0) { - log_crit("Could not create L2CAP socket. %s (%d)", - strerror(errno), errno); - close(unsock); - return (-1); - } - - size = sizeof(imtu); - if (getsockopt(l2sock, SOL_L2CAP, SO_L2CAP_IMTU, &imtu, &size) < 0) { - log_crit("Could not get L2CAP IMTU. %s (%d)", - strerror(errno), errno); - close(unsock); - close(l2sock); - return (-1); - } - - memset(&l2, 0, sizeof(l2)); - l2.l2cap_len = sizeof(l2); - l2.l2cap_family = AF_BLUETOOTH; - memcpy(&l2.l2cap_bdaddr, NG_HCI_BDADDR_ANY, sizeof(l2.l2cap_bdaddr)); - l2.l2cap_psm = htole16(NG_L2CAP_PSM_SDP); - - if (bind(l2sock, (struct sockaddr *) &l2, sizeof(l2)) < 0) { - log_crit("Could not bind L2CAP socket. %s (%d)", - strerror(errno), errno); - close(unsock); - close(l2sock); - return (-1); - } - - if (listen(l2sock, 10) < 0) { - log_crit("Could not listen on L2CAP socket. %s (%d)", - strerror(errno), errno); - close(unsock); - close(l2sock); - return (-1); - } - - /* Allocate incoming buffer */ - srv->imtu = (imtu > SDP_LOCAL_MTU)? imtu : SDP_LOCAL_MTU; - srv->req = (uint8_t *) calloc(srv->imtu, sizeof(srv->req[0])); - if (srv->req == NULL) { - log_crit("Could not allocate request buffer"); - close(unsock); - close(l2sock); - return (-1); - } - - /* Allocate memory for descriptor index */ - srv->fdidx = (fd_idx_p) calloc(FD_SETSIZE, sizeof(srv->fdidx[0])); - if (srv->fdidx == NULL) { - log_crit("Could not allocate fd index"); - free(srv->req); - close(unsock); - close(l2sock); - return (-1); - } - - /* Register Service Discovery profile (attach it to control socket) */ - if (provider_register_sd(unsock) < 0) { - log_crit("Could not register Service Discovery profile"); - free(srv->fdidx); - free(srv->req); - close(unsock); - close(l2sock); - return (-1); - } - - /* - * If we got here then everything is fine. Add both control sockets - * to the index. - */ - - FD_ZERO(&srv->fdset); - srv->maxfd = (unsock > l2sock)? unsock : l2sock; - - FD_SET(unsock, &srv->fdset); - srv->fdidx[unsock].valid = 1; - srv->fdidx[unsock].server = 1; - srv->fdidx[unsock].control = 1; - srv->fdidx[unsock].priv = 0; - srv->fdidx[unsock].rsp_cs = 0; - srv->fdidx[unsock].rsp_size = 0; - srv->fdidx[unsock].rsp_limit = 0; - srv->fdidx[unsock].omtu = SDP_LOCAL_MTU; - srv->fdidx[unsock].rsp = NULL; - - FD_SET(l2sock, &srv->fdset); - srv->fdidx[l2sock].valid = 1; - srv->fdidx[l2sock].server = 1; - srv->fdidx[l2sock].control = 0; - srv->fdidx[l2sock].priv = 0; - srv->fdidx[l2sock].rsp_cs = 0; - srv->fdidx[l2sock].rsp_size = 0; - srv->fdidx[l2sock].rsp_limit = 0; - srv->fdidx[l2sock].omtu = 0; /* unknown */ - srv->fdidx[l2sock].rsp = NULL; - - return (0); -} - -/* - * Shutdown server - */ - -void -server_shutdown(server_p srv) -{ - int fd; - - assert(srv != NULL); - - for (fd = 0; fd < srv->maxfd + 1; fd ++) - if (srv->fdidx[fd].valid) - server_close_fd(srv, fd); - - free(srv->req); - free(srv->fdidx); - - memset(srv, 0, sizeof(*srv)); -} - -/* - * Do one server iteration - */ - -int32_t -server_do(server_p srv) -{ - fd_set fdset; - int32_t n, fd; - - assert(srv != NULL); - - /* Copy cached version of the fd set and call select */ - memcpy(&fdset, &srv->fdset, sizeof(fdset)); - n = select(srv->maxfd + 1, &fdset, NULL, NULL, NULL); - if (n < 0) { - if (errno == EINTR) - return (0); - - log_err("Could not select(%d, %p). %s (%d)", - srv->maxfd + 1, &fdset, strerror(errno), errno); - - return (-1); - } - - /* Process descriptors */ - for (fd = 0; fd < srv->maxfd + 1 && n > 0; fd ++) { - if (!FD_ISSET(fd, &fdset)) - continue; - - assert(srv->fdidx[fd].valid); - n --; - - if (srv->fdidx[fd].server) - server_accept_client(srv, fd); - else if (server_process_request(srv, fd) != 0) - server_close_fd(srv, fd); - } - - return (0); - -} - -/* - * Accept new client connection and register it with index - */ - -static void -server_accept_client(server_p srv, int32_t fd) -{ - uint8_t *rsp = NULL; - int32_t cfd, priv; - uint16_t omtu; - socklen_t size; - - do { - cfd = accept(fd, NULL, NULL); - } while (cfd < 0 && errno == EINTR); - - if (cfd < 0) { - log_err("Could not accept connection on %s socket. %s (%d)", - srv->fdidx[fd].control? "control" : "L2CAP", - strerror(errno), errno); - return; - } - - assert(!FD_ISSET(cfd, &srv->fdset)); - assert(!srv->fdidx[cfd].valid); - - priv = 0; - - if (!srv->fdidx[fd].control) { - /* Get local BD_ADDR */ - size = sizeof(srv->req_sa); - if (getsockname(cfd,(struct sockaddr*)&srv->req_sa,&size) < 0) { - log_err("Could not get local BD_ADDR. %s (%d)", - strerror(errno), errno); - close(cfd); - return; - } - - /* Get outgoing MTU */ - size = sizeof(omtu); - if (getsockopt(cfd,SOL_L2CAP,SO_L2CAP_OMTU,&omtu,&size) < 0) { - log_err("Could not get L2CAP OMTU. %s (%d)", - strerror(errno), errno); - close(cfd); - return; - } - - /* - * The maximum size of the L2CAP packet is 65536 bytes. - * The minimum L2CAP MTU is 43 bytes. That means we need - * 65536 / 43 = ~1524 chunks to transfer maximum packet - * size with minimum MTU. The "rsp_cs" field in fd_idx_t - * is 11 bit wide that gives us upto 2048 chunks. - */ - - if (omtu < NG_L2CAP_MTU_MINIMUM) { - log_err("L2CAP OMTU is too small (%d bytes)", omtu); - close(cfd); - return; - } - } else { - struct xucred cr; - struct passwd *pw; - - /* Get peer's credentials */ - memset(&cr, 0, sizeof(cr)); - size = sizeof(cr); - - if (getsockopt(cfd, 0, LOCAL_PEERCRED, &cr, &size) < 0) { - log_err("Could not get peer's credentials. %s (%d)", - strerror(errno), errno); - close(cfd); - return; - } - - /* Check credentials */ - pw = getpwuid(cr.cr_uid); - if (pw != NULL) - priv = (strcmp(pw->pw_name, "root") == 0); - else - log_warning("Could not verify credentials for uid %d", - cr.cr_uid); - - memcpy(&srv->req_sa.l2cap_bdaddr, NG_HCI_BDADDR_ANY, - sizeof(srv->req_sa.l2cap_bdaddr)); - - omtu = srv->fdidx[fd].omtu; - } - - /* - * Allocate buffer. This is an overkill, but we can not know how - * big our reply is going to be. - */ - - rsp = (uint8_t *) calloc(NG_L2CAP_MTU_MAXIMUM, sizeof(rsp[0])); - if (rsp == NULL) { - log_crit("Could not allocate response buffer"); - close(cfd); - return; - } - - /* Add client descriptor to the index */ - FD_SET(cfd, &srv->fdset); - if (srv->maxfd < cfd) - srv->maxfd = cfd; - srv->fdidx[cfd].valid = 1; - srv->fdidx[cfd].server = 0; - srv->fdidx[cfd].control = srv->fdidx[fd].control; - srv->fdidx[cfd].priv = priv; - srv->fdidx[cfd].rsp_cs = 0; - srv->fdidx[cfd].rsp_size = 0; - srv->fdidx[cfd].rsp_limit = 0; - srv->fdidx[cfd].omtu = omtu; - srv->fdidx[cfd].rsp = rsp; -} - -/* - * Process request from the client - */ - -static int32_t -server_process_request(server_p srv, int32_t fd) -{ - sdp_pdu_p pdu = (sdp_pdu_p) srv->req; - int32_t len, error; - - assert(srv->imtu > 0); - assert(srv->req != NULL); - assert(FD_ISSET(fd, &srv->fdset)); - assert(srv->fdidx[fd].valid); - assert(!srv->fdidx[fd].server); - assert(srv->fdidx[fd].rsp != NULL); - assert(srv->fdidx[fd].omtu >= NG_L2CAP_MTU_MINIMUM); - - do { - len = read(fd, srv->req, srv->imtu); - } while (len < 0 && errno == EINTR); - - if (len < 0) { - log_err("Could not receive SDP request from %s socket. %s (%d)", - srv->fdidx[fd].control? "control" : "L2CAP", - strerror(errno), errno); - return (-1); - } - if (len == 0) { - log_info("Client on %s socket has disconnected", - srv->fdidx[fd].control? "control" : "L2CAP"); - return (-1); - } - - if (len >= sizeof(*pdu) && - sizeof(*pdu) + (pdu->len = ntohs(pdu->len)) == len) { - switch (pdu->pid) { - case SDP_PDU_SERVICE_SEARCH_REQUEST: - error = server_prepare_service_search_response(srv, fd); - break; - - case SDP_PDU_SERVICE_ATTRIBUTE_REQUEST: - error = server_prepare_service_attribute_response(srv, fd); - break; - - case SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_REQUEST: - error = server_prepare_service_search_attribute_response(srv, fd); - break; - - case SDP_PDU_SERVICE_REGISTER_REQUEST: - error = server_prepare_service_register_response(srv, fd); - break; - - case SDP_PDU_SERVICE_UNREGISTER_REQUEST: - error = server_prepare_service_unregister_response(srv, fd); - break; - - case SDP_PDU_SERVICE_CHANGE_REQUEST: - error = server_prepare_service_change_response(srv, fd); - break; - - default: - error = SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX; - break; - } - } else - error = SDP_ERROR_CODE_INVALID_PDU_SIZE; - - if (error == 0) { - switch (pdu->pid) { - case SDP_PDU_SERVICE_SEARCH_REQUEST: - error = server_send_service_search_response(srv, fd); - break; - - case SDP_PDU_SERVICE_ATTRIBUTE_REQUEST: - error = server_send_service_attribute_response(srv, fd); - break; - - case SDP_PDU_SERVICE_SEARCH_ATTRIBUTE_REQUEST: - error = server_send_service_search_attribute_response(srv, fd); - break; - - case SDP_PDU_SERVICE_REGISTER_REQUEST: - error = server_send_service_register_response(srv, fd); - break; - - case SDP_PDU_SERVICE_UNREGISTER_REQUEST: - error = server_send_service_unregister_response(srv, fd); - break; - - case SDP_PDU_SERVICE_CHANGE_REQUEST: - error = server_send_service_change_response(srv, fd); - break; - - default: - error = SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX; - break; - } - - if (error != 0) - log_err("Could not send SDP response to %s socket, " \ - "pdu->pid=%d, pdu->tid=%d, error=%d", - srv->fdidx[fd].control? "control" : "L2CAP", - pdu->pid, ntohs(pdu->tid), error); - } else { - log_err("Could not process SDP request from %s socket, " \ - "pdu->pid=%d, pdu->tid=%d, pdu->len=%d, len=%d, " \ - "error=%d", - srv->fdidx[fd].control? "control" : "L2CAP", - pdu->pid, ntohs(pdu->tid), pdu->len, len, error); - - error = server_send_error_response(srv, fd, error); - if (error != 0) - log_err("Could not send SDP error response to %s " \ - "socket, pdu->pid=%d, pdu->tid=%d, error=%d", - srv->fdidx[fd].control? "control" : "L2CAP", - pdu->pid, ntohs(pdu->tid), error); - } - - /* On error forget response (if any) */ - if (error != 0) { - srv->fdidx[fd].rsp_cs = 0; - srv->fdidx[fd].rsp_size = 0; - srv->fdidx[fd].rsp_limit = 0; - } - - return (error); -} - -/* - * Send SDP_Error_Response PDU - */ - -static int32_t -server_send_error_response(server_p srv, int32_t fd, uint16_t error) -{ - int32_t size; - - struct { - sdp_pdu_t pdu; - uint16_t error; - } __attribute__ ((packed)) rsp; - - /* Prepare and send SDP error response */ - rsp.pdu.pid = SDP_PDU_ERROR_RESPONSE; - rsp.pdu.tid = ((sdp_pdu_p)(srv->req))->tid; - rsp.pdu.len = htons(sizeof(rsp.error)); - rsp.error = htons(error); - - do { - size = write(fd, &rsp, sizeof(rsp)); - } while (size < 0 && errno == EINTR); - - return ((size < 0)? errno : 0); -} - -/* - * Close descriptor and remove it from index - */ - -static void -server_close_fd(server_p srv, int32_t fd) -{ - provider_p provider = NULL, provider_next = NULL; - - assert(FD_ISSET(fd, &srv->fdset)); - assert(srv->fdidx[fd].valid); - - close(fd); - - FD_CLR(fd, &srv->fdset); - if (fd == srv->maxfd) - srv->maxfd --; - - if (srv->fdidx[fd].rsp != NULL) - free(srv->fdidx[fd].rsp); - - memset(&srv->fdidx[fd], 0, sizeof(srv->fdidx[fd])); - - for (provider = provider_get_first(); - provider != NULL; - provider = provider_next) { - provider_next = provider_get_next(provider); - - if (provider->fd == fd) - provider_unregister(provider); - } -} - diff --git a/usr.sbin/bluetooth/sdpd/server.h b/usr.sbin/bluetooth/sdpd/server.h deleted file mode 100644 index d7ef55e..0000000 --- a/usr.sbin/bluetooth/sdpd/server.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * server.h - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: server.h,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#ifndef _SERVER_H_ -#define _SERVER_H_ - -/* - * File descriptor index entry - */ - -struct fd_idx -{ - unsigned valid : 1; /* descriptor is valid */ - unsigned server : 1; /* descriptor is listening */ - unsigned control : 1; /* descriptor is a control socket */ - unsigned priv : 1; /* descriptor is privileged */ - unsigned reserved : 1; - unsigned rsp_cs : 11; /* response continuation state */ - uint16_t rsp_size; /* response size */ - uint16_t rsp_limit; /* response limit */ - uint16_t omtu; /* outgoing MTU */ - uint8_t *rsp; /* outgoing buffer */ -}; - -typedef struct fd_idx fd_idx_t; -typedef struct fd_idx * fd_idx_p; - -/* - * SDP server - */ - -struct server -{ - uint32_t imtu; /* incoming MTU */ - uint8_t *req; /* incoming buffer */ - int32_t maxfd; /* max. descriptor is the set */ - fd_set fdset; /* current descriptor set */ - fd_idx_p fdidx; /* descriptor index */ - struct sockaddr_l2cap req_sa; /* local address */ -}; - -typedef struct server server_t; -typedef struct server * server_p; - -/* - * External API - */ - -int32_t server_init(server_p srv, const char *control); -void server_shutdown(server_p srv); -int32_t server_do(server_p srv); - -int32_t server_prepare_service_search_response(server_p srv, int32_t fd); -int32_t server_send_service_search_response(server_p srv, int32_t fd); - -int32_t server_prepare_service_attribute_response(server_p srv, int32_t fd); -int32_t server_send_service_attribute_response(server_p srv, int32_t fd); - -int32_t server_prepare_service_search_attribute_response(server_p srv, int32_t fd); -#define server_send_service_search_attribute_response \ - server_send_service_attribute_response - -int32_t server_prepare_service_register_response(server_p srv, int32_t fd); -int32_t server_send_service_register_response(server_p srv, int32_t fd); - -int32_t server_prepare_service_unregister_response(server_p srv, int32_t fd); -#define server_send_service_unregister_response \ - server_send_service_register_response - -int32_t server_prepare_service_change_response(server_p srv, int32_t fd); -#define server_send_service_change_response \ - server_send_service_register_response - -#endif /* ndef _SERVER_H_ */ diff --git a/usr.sbin/bluetooth/sdpd/sp.c b/usr.sbin/bluetooth/sdpd/sp.c deleted file mode 100644 index 31a9585a..0000000 --- a/usr.sbin/bluetooth/sdpd/sp.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * sp.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: sp.c,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" - -static int32_t -sp_profile_create_service_class_id_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t service_classes[] = { - SDP_SERVICE_CLASS_SERIAL_PORT - }; - - return (common_profile_create_service_class_id_list( - buf, eob, - (uint8_t const *) service_classes, - sizeof(service_classes))); -} - -static int32_t -sp_profile_create_bluetooth_profile_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static uint16_t profile_descriptor_list[] = { - SDP_SERVICE_CLASS_SERIAL_PORT, - 0x0100 - }; - - return (common_profile_create_bluetooth_profile_descriptor_list( - buf, eob, - (uint8_t const *) profile_descriptor_list, - sizeof(profile_descriptor_list))); -} - -static int32_t -sp_profile_create_service_name( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - static char service_name[] = "Serial Port"; - - return (common_profile_create_string8( - buf, eob, - (uint8_t const *) service_name, strlen(service_name))); -} - -static int32_t -sp_profile_create_protocol_descriptor_list( - uint8_t *buf, uint8_t const * const eob, - uint8_t const *data, uint32_t datalen) -{ - provider_p provider = (provider_p) data; - sdp_sp_profile_p sp = (sdp_sp_profile_p) provider->data; - - return (rfcomm_profile_create_protocol_descriptor_list( - buf, eob, - (uint8_t const *) &sp->server_channel, 1)); -} - -static attr_t sp_profile_attrs[] = { - { SDP_ATTR_SERVICE_RECORD_HANDLE, - common_profile_create_service_record_handle }, - { SDP_ATTR_SERVICE_CLASS_ID_LIST, - sp_profile_create_service_class_id_list }, - { SDP_ATTR_BLUETOOTH_PROFILE_DESCRIPTOR_LIST, - sp_profile_create_bluetooth_profile_descriptor_list }, - { SDP_ATTR_LANGUAGE_BASE_ATTRIBUTE_ID_LIST, - common_profile_create_language_base_attribute_id_list }, - { SDP_ATTR_PRIMARY_LANGUAGE_BASE_ID + SDP_ATTR_SERVICE_NAME_OFFSET, - sp_profile_create_service_name }, - { SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST, - sp_profile_create_protocol_descriptor_list }, - { 0, NULL } /* end entry */ -}; - -profile_t sp_profile_descriptor = { - SDP_SERVICE_CLASS_SERIAL_PORT, - sizeof(sdp_sp_profile_t), - common_profile_server_channel_valid, - (attr_t const * const) &sp_profile_attrs -}; - diff --git a/usr.sbin/bluetooth/sdpd/srr.c b/usr.sbin/bluetooth/sdpd/srr.c deleted file mode 100644 index fd636d5..0000000 --- a/usr.sbin/bluetooth/sdpd/srr.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * srr.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: srr.c,v 1.1 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" -#include "server.h" - -/* - * Prepare Service Register response - */ - -int32_t -server_prepare_service_register_response(server_p srv, int32_t fd) -{ - uint8_t const *req = srv->req + sizeof(sdp_pdu_t); - uint8_t const *req_end = req + ((sdp_pdu_p)(srv->req))->len; - uint8_t *rsp = srv->fdidx[fd].rsp; - - profile_t *profile = NULL; - provider_t *provider = NULL; - bdaddr_t *bdaddr = NULL; - int32_t uuid; - - /* - * Minimal Service Register Request - * - * value16 - uuid 2 bytes - * bdaddr - BD_ADDR 6 bytes - */ - - if (!srv->fdidx[fd].control || - !srv->fdidx[fd].priv || req_end - req < 8) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get ServiceClass UUID */ - SDP_GET16(uuid, req); - - /* Get BD_ADDR */ - bdaddr = (bdaddr_p) req; - req += sizeof(*bdaddr); - - /* Lookup profile descriptror */ - profile = profile_get_descriptor(uuid); - if (profile == NULL) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Validate user data */ - if (req_end - req < profile->dsize || - profile->valid == NULL || - (profile->valid)(req, req_end - req) == 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Register provider */ - provider = provider_register(profile, bdaddr, fd, req, req_end - req); - if (provider == NULL) - return (SDP_ERROR_CODE_INSUFFICIENT_RESOURCES); - - SDP_PUT16(0, rsp); - SDP_PUT32(provider->handle, rsp); - - /* Set reply size */ - srv->fdidx[fd].rsp_limit = srv->fdidx[fd].omtu - sizeof(sdp_pdu_t); - srv->fdidx[fd].rsp_size = rsp - srv->fdidx[fd].rsp; - srv->fdidx[fd].rsp_cs = 0; - - return (0); -} - -/* - * Send Service Register Response - */ - -int32_t -server_send_service_register_response(server_p srv, int32_t fd) -{ - struct iovec iov[2]; - sdp_pdu_t pdu; - int32_t size; - - assert(srv->fdidx[fd].rsp_size < srv->fdidx[fd].rsp_limit); - - pdu.pid = SDP_PDU_ERROR_RESPONSE; - pdu.tid = ((sdp_pdu_p)(srv->req))->tid; - pdu.len = htons(srv->fdidx[fd].rsp_size); - - iov[0].iov_base = &pdu; - iov[0].iov_len = sizeof(pdu); - - iov[1].iov_base = srv->fdidx[fd].rsp; - iov[1].iov_len = srv->fdidx[fd].rsp_size; - - do { - size = writev(fd, (struct iovec const *) &iov, sizeof(iov)/sizeof(iov[0])); - } while (size < 0 && errno == EINTR); - - srv->fdidx[fd].rsp_cs = 0; - srv->fdidx[fd].rsp_size = 0; - srv->fdidx[fd].rsp_limit = 0; - - return ((size < 0)? errno : 0); -} - diff --git a/usr.sbin/bluetooth/sdpd/ssar.c b/usr.sbin/bluetooth/sdpd/ssar.c deleted file mode 100644 index eac9235..0000000 --- a/usr.sbin/bluetooth/sdpd/ssar.c +++ /dev/null @@ -1,252 +0,0 @@ -/* - * ssar.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: ssar.c,v 1.4 2004/01/12 22:54:31 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" -#include "server.h" -#include "uuid-private.h" - -/* from sar.c */ -int32_t server_prepare_attr_list(provider_p const provider, - uint8_t const *req, uint8_t const * const req_end, - uint8_t *rsp, uint8_t const * const rsp_end); - -/* - * Prepare SDP Service Search Attribute Response - */ - -int32_t -server_prepare_service_search_attribute_response(server_p srv, int32_t fd) -{ - uint8_t const *req = srv->req + sizeof(sdp_pdu_t); - uint8_t const *req_end = req + ((sdp_pdu_p)(srv->req))->len; - uint8_t *rsp = srv->fdidx[fd].rsp; - uint8_t const *rsp_end = rsp + NG_L2CAP_MTU_MAXIMUM; - - uint8_t const *sspptr = NULL, *aidptr = NULL; - uint8_t *ptr = NULL; - - provider_t *provider = NULL; - int32_t type, rsp_limit, ssplen, aidlen, cslen, cs; - uint128_t uuid, puuid; - - /* - * Minimal Service Search Attribute Request request - * - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes ServiceSearchPattern - * value16 - 2 bytes MaximumAttributeByteCount - * seq8 len8 - 2 bytes - * uint16 value16 - 3 bytes AttributeIDList - * value8 - 1 byte ContinuationState - */ - - if (req_end - req < 13) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get size of ServiceSearchPattern */ - ssplen = 0; - SDP_GET8(type, req); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(ssplen, req); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(ssplen, req); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(ssplen, req); - break; - } - if (ssplen <= 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - sspptr = req; - req += ssplen; - - /* Get MaximumAttributeByteCount */ - if (req + 2 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET16(rsp_limit, req); - if (rsp_limit <= 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get size of AttributeIDList */ - if (req + 1 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - aidlen = 0; - SDP_GET8(type, req); - switch (type) { - case SDP_DATA_SEQ8: - if (req + 1 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET8(aidlen, req); - break; - - case SDP_DATA_SEQ16: - if (req + 2 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET16(aidlen, req); - break; - - case SDP_DATA_SEQ32: - if (req + 4 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET32(aidlen, req); - break; - } - if (aidlen <= 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - aidptr = req; - req += aidlen; - - /* Get ContinuationState */ - if (req + 1 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET8(cslen, req); - if (cslen != 0) { - if (cslen != 2 || req_end - req != 2) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET16(cs, req); - } else - cs = 0; - - /* Process the request. First, check continuation state */ - if (srv->fdidx[fd].rsp_cs != cs) - return (SDP_ERROR_CODE_INVALID_CONTINUATION_STATE); - if (srv->fdidx[fd].rsp_size > 0) - return (0); - - /* - * Service Search Attribute Response format - * - * value16 - 2 bytes AttributeListByteCount (not incl.) - * seq8 len16 - 3 bytes - * attr list - 3+ bytes AttributeLists - * [ attr list ] - */ - - ptr = rsp + 3; - - while (ssplen > 0) { - SDP_GET8(type, sspptr); - ssplen --; - - switch (type) { - case SDP_DATA_UUID16: - if (ssplen < 2) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - memcpy(&uuid, &uuid_base, sizeof(uuid)); - uuid.b[2] = *sspptr ++; - uuid.b[3] = *sspptr ++; - ssplen -= 2; - break; - - case SDP_DATA_UUID32: - if (ssplen < 4) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - memcpy(&uuid, &uuid_base, sizeof(uuid)); - uuid.b[0] = *sspptr ++; - uuid.b[1] = *sspptr ++; - uuid.b[2] = *sspptr ++; - uuid.b[3] = *sspptr ++; - ssplen -= 4; - break; - - case SDP_DATA_UUID128: - if (ssplen < 16) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - memcpy(uuid.b, sspptr, 16); - sspptr += 16; - ssplen -= 16; - break; - - default: - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - /* NOT REACHED */ - } - - for (provider = provider_get_first(); - provider != NULL; - provider = provider_get_next(provider)) { - if (!provider_match_bdaddr(provider, &srv->req_sa.l2cap_bdaddr)) - continue; - - memcpy(&puuid, &uuid_base, sizeof(puuid)); - puuid.b[2] = provider->profile->uuid >> 8; - puuid.b[3] = provider->profile->uuid; - - if (memcmp(&uuid, &puuid, sizeof(uuid)) != 0 && - memcmp(&uuid, &uuid_public_browse_group, sizeof(uuid)) != 0) - continue; - - cs = server_prepare_attr_list(provider, - aidptr, aidptr + aidlen, ptr, rsp_end); - if (cs < 0) - return (SDP_ERROR_CODE_INSUFFICIENT_RESOURCES); - - ptr += cs; - } - } - - /* Set reply size (not counting PDU header and continuation state) */ - srv->fdidx[fd].rsp_limit = srv->fdidx[fd].omtu - sizeof(sdp_pdu_t) - 2; - if (srv->fdidx[fd].rsp_limit > rsp_limit) - srv->fdidx[fd].rsp_limit = rsp_limit; - - srv->fdidx[fd].rsp_size = ptr - rsp; - srv->fdidx[fd].rsp_cs = 0; - - /* Fix AttributeLists sequence header */ - ptr = rsp; - SDP_PUT8(SDP_DATA_SEQ16, ptr); - SDP_PUT16(srv->fdidx[fd].rsp_size - 3, ptr); - - return (0); -} - diff --git a/usr.sbin/bluetooth/sdpd/ssr.c b/usr.sbin/bluetooth/sdpd/ssr.c deleted file mode 100644 index ac27548..0000000 --- a/usr.sbin/bluetooth/sdpd/ssr.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * ssr.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: ssr.c,v 1.5 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" -#include "server.h" -#include "uuid-private.h" - -/* - * Prepare SDP Service Search Response - */ - -int32_t -server_prepare_service_search_response(server_p srv, int32_t fd) -{ - uint8_t const *req = srv->req + sizeof(sdp_pdu_t); - uint8_t const *req_end = req + ((sdp_pdu_p)(srv->req))->len; - uint8_t *rsp = srv->fdidx[fd].rsp; - uint8_t const *rsp_end = rsp + NG_L2CAP_MTU_MAXIMUM; - - uint8_t *ptr = NULL; - provider_t *provider = NULL; - int32_t type, ssplen, rsp_limit, rcount, cslen, cs; - uint128_t uuid, puuid; - - /* - * Minimal SDP Service Search Request - * - * seq8 len8 - 2 bytes - * uuid16 value16 - 3 bytes ServiceSearchPattern - * value16 - 2 bytes MaximumServiceRecordCount - * value8 - 1 byte ContinuationState - */ - - if (req_end - req < 8) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get size of ServiceSearchPattern */ - ssplen = 0; - SDP_GET8(type, req); - switch (type) { - case SDP_DATA_SEQ8: - SDP_GET8(ssplen, req); - break; - - case SDP_DATA_SEQ16: - SDP_GET16(ssplen, req); - break; - - case SDP_DATA_SEQ32: - SDP_GET32(ssplen, req); - break; - } - if (ssplen <= 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - ptr = (uint8_t *) req + ssplen; - - /* Get MaximumServiceRecordCount */ - if (ptr + 2 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET16(rsp_limit, ptr); - if (rsp_limit <= 0) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get ContinuationState */ - if (ptr + 1 > req_end) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET8(cslen, ptr); - if (cslen != 0) { - if (cslen != 2 || req_end - ptr != 2) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - SDP_GET16(cs, ptr); - } else - cs = 0; - - /* Process the request. First, check continuation state */ - if (srv->fdidx[fd].rsp_cs != cs) - return (SDP_ERROR_CODE_INVALID_CONTINUATION_STATE); - if (srv->fdidx[fd].rsp_size > 0) - return (0); - - /* - * Service Search Response format - * - * value16 - 2 bytes TotalServiceRecordCount (not incl.) - * value16 - 2 bytes CurrentServiceRecordCount (not incl.) - * value32 - 4 bytes handle - * [ value32 ] - * - * Calculate how many record handles we can fit - * in our reply buffer and adjust rlimit. - */ - - ptr = rsp; - rcount = (rsp_end - ptr) / 4; - if (rcount < rsp_limit) - rsp_limit = rcount; - - /* Look for the record handles */ - for (rcount = 0; ssplen > 0 && rcount < rsp_limit; ) { - SDP_GET8(type, req); - ssplen --; - - switch (type) { - case SDP_DATA_UUID16: - if (ssplen < 2) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - memcpy(&uuid, &uuid_base, sizeof(uuid)); - uuid.b[2] = *req ++; - uuid.b[3] = *req ++; - ssplen -= 2; - break; - - case SDP_DATA_UUID32: - if (ssplen < 4) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - memcpy(&uuid, &uuid_base, sizeof(uuid)); - uuid.b[0] = *req ++; - uuid.b[1] = *req ++; - uuid.b[2] = *req ++; - uuid.b[3] = *req ++; - ssplen -= 4; - break; - - case SDP_DATA_UUID128: - if (ssplen < 16) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - memcpy(uuid.b, req, 16); - req += 16; - ssplen -= 16; - break; - - default: - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - /* NOT REACHED */ - } - - for (provider = provider_get_first(); - provider != NULL && rcount < rsp_limit; - provider = provider_get_next(provider)) { - if (!provider_match_bdaddr(provider, &srv->req_sa.l2cap_bdaddr)) - continue; - - memcpy(&puuid, &uuid_base, sizeof(puuid)); - puuid.b[2] = provider->profile->uuid >> 8; - puuid.b[3] = provider->profile->uuid; - - if (memcmp(&uuid, &puuid, sizeof(uuid)) == 0 || - memcmp(&uuid, &uuid_public_browse_group, sizeof(uuid)) == 0) { - SDP_PUT32(provider->handle, ptr); - rcount ++; - } - } - } - - /* Set reply size (not counting PDU header and continuation state) */ - srv->fdidx[fd].rsp_limit = srv->fdidx[fd].omtu - sizeof(sdp_pdu_t) - 4; - srv->fdidx[fd].rsp_size = ptr - rsp; - srv->fdidx[fd].rsp_cs = 0; - - return (0); -} - -/* - * Send SDP Service Search Response - */ - -int32_t -server_send_service_search_response(server_p srv, int32_t fd) -{ - uint8_t *rsp = srv->fdidx[fd].rsp + srv->fdidx[fd].rsp_cs; - uint8_t *rsp_end = srv->fdidx[fd].rsp + srv->fdidx[fd].rsp_size; - - struct iovec iov[4]; - sdp_pdu_t pdu; - uint16_t rcounts[2]; - uint8_t cs[3]; - int32_t size; - - /* First update continuation state (assume we will send all data) */ - size = rsp_end - rsp; - srv->fdidx[fd].rsp_cs += size; - - if (size + 1 > srv->fdidx[fd].rsp_limit) { - /* - * We need to split out response. Add 3 more bytes for the - * continuation state and move rsp_end and rsp_cs backwards. - */ - - while ((rsp_end - rsp) + 3 > srv->fdidx[fd].rsp_limit) { - rsp_end -= 4; - srv->fdidx[fd].rsp_cs -= 4; - } - - cs[0] = 2; - cs[1] = srv->fdidx[fd].rsp_cs >> 8; - cs[2] = srv->fdidx[fd].rsp_cs & 0xff; - } else - cs[0] = 0; - - assert(rsp_end >= rsp); - - rcounts[0] = srv->fdidx[fd].rsp_size / 4; /* TotalServiceRecordCount */ - rcounts[1] = (rsp_end - rsp) / 4; /* CurrentServiceRecordCount */ - - pdu.pid = SDP_PDU_SERVICE_SEARCH_RESPONSE; - pdu.tid = ((sdp_pdu_p)(srv->req))->tid; - pdu.len = htons(sizeof(rcounts) + rcounts[1] * 4 + 1 + cs[0]); - - rcounts[0] = htons(rcounts[0]); - rcounts[1] = htons(rcounts[1]); - - iov[0].iov_base = &pdu; - iov[0].iov_len = sizeof(pdu); - - iov[1].iov_base = rcounts; - iov[1].iov_len = sizeof(rcounts); - - iov[2].iov_base = rsp; - iov[2].iov_len = rsp_end - rsp; - - iov[3].iov_base = cs; - iov[3].iov_len = 1 + cs[0]; - - do { - size = writev(fd, (struct iovec const *) &iov, sizeof(iov)/sizeof(iov[0])); - } while (size < 0 && errno == EINTR); - - /* Check if we have sent (or failed to sent) last response chunk */ - if (srv->fdidx[fd].rsp_cs == srv->fdidx[fd].rsp_size) { - srv->fdidx[fd].rsp_cs = 0; - srv->fdidx[fd].rsp_size = 0; - srv->fdidx[fd].rsp_limit = 0; - } - - return ((size < 0)? errno : 0); -} - diff --git a/usr.sbin/bluetooth/sdpd/sur.c b/usr.sbin/bluetooth/sdpd/sur.c deleted file mode 100644 index 143eaf3..0000000 --- a/usr.sbin/bluetooth/sdpd/sur.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * sur.c - * - * Copyright (c) 2004 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: sur.c,v 1.1 2004/01/13 01:54:39 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include "profile.h" -#include "provider.h" -#include "server.h" - -/* - * Prepare Service Unregister response - */ - -int32_t -server_prepare_service_unregister_response(server_p srv, int32_t fd) -{ - uint8_t const *req = srv->req + sizeof(sdp_pdu_t); - uint8_t const *req_end = req + ((sdp_pdu_p)(srv->req))->len; - uint8_t *rsp = srv->fdidx[fd].rsp; - - provider_t *provider = NULL; - uint32_t handle; - - /* - * Minimal Service Unregister Request - * - * value32 - uuid 4 bytes - */ - - if (!srv->fdidx[fd].control || - !srv->fdidx[fd].priv || req_end - req < 4) - return (SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX); - - /* Get handle */ - SDP_GET32(handle, req); - - /* Lookup provider */ - provider = provider_by_handle(handle); - if (provider == NULL || provider->fd != fd) - return (SDP_ERROR_CODE_INVALID_SERVICE_RECORD_HANDLE); - - provider_unregister(provider); - SDP_PUT16(0, rsp); - - /* Set reply size */ - srv->fdidx[fd].rsp_limit = srv->fdidx[fd].omtu - sizeof(sdp_pdu_t); - srv->fdidx[fd].rsp_size = rsp - srv->fdidx[fd].rsp; - srv->fdidx[fd].rsp_cs = 0; - - return (0); -} - diff --git a/usr.sbin/bluetooth/sdpd/uuid-private.h b/usr.sbin/bluetooth/sdpd/uuid-private.h deleted file mode 100644 index db8d13b..0000000 --- a/usr.sbin/bluetooth/sdpd/uuid-private.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * uuid-private.h - * - * Copyright (c) 2005 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: uuid-private.h,v 1.1 2004/12/09 18:20:26 max Exp $ - * $FreeBSD$ - */ - -#ifndef _UUID_PRIVATE_H_ -#define _UUID_PRIVATE_H_ - -extern uint128_t uuid_base; -extern uint128_t uuid_public_browse_group; - -#endif /* ndef _UUID_PRIVATE_H_ */ - diff --git a/usr.sbin/bluetooth/sdpd/uuid.c b/usr.sbin/bluetooth/sdpd/uuid.c deleted file mode 100644 index 1989bc5..0000000 --- a/usr.sbin/bluetooth/sdpd/uuid.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * uuid.c - * - * Copyright (c) 2005 Maksim Yevmenkin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: uuid.c,v 1.1 2004/12/09 18:20:26 max Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include "uuid-private.h" - -uint128_t uuid_base = { - .b = { - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, - 0x10, 0x00, - 0x80, 0x00, - 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb - } -}; - -uint128_t uuid_public_browse_group = { - .b = { - 0x00, 0x00, 0x10, 0x02, - 0x00, 0x00, - 0x10, 0x00, - 0x80, 0x00, - 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb - } -}; - diff --git a/usr.sbin/boot0cfg/Makefile b/usr.sbin/boot0cfg/Makefile deleted file mode 100644 index 9b46701..0000000 --- a/usr.sbin/boot0cfg/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD$ - -PROG= boot0cfg -MAN= boot0cfg.8 - -DPADD= ${LIBGEOM} ${LIBBSDXML} ${LIBSBUF} -LDADD= -lgeom -lbsdxml -lsbuf - -.include diff --git a/usr.sbin/boot0cfg/boot0cfg.8 b/usr.sbin/boot0cfg/boot0cfg.8 deleted file mode 100644 index c7e664c..0000000 --- a/usr.sbin/boot0cfg/boot0cfg.8 +++ /dev/null @@ -1,214 +0,0 @@ -.\" Copyright (c) 1999 Robert Nordier -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -.\" OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -.\" OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd January 13, 2009 -.Dt BOOT0CFG 8 -.Os -.Sh NAME -.Nm boot0cfg -.Nd boot manager installation/configuration utility -.Sh SYNOPSIS -.Nm -.Op Fl Bv -.Op Fl b Ar boot0 -.Op Fl d Ar drive -.Op Fl e Ar bell character -.Op Fl f Ar file -.Op Fl i Ar volume-id -.Op Fl m Ar mask -.Op Fl o Ar options -.Op Fl s Ar slice -.Op Fl t Ar ticks -.Ar disk -.Sh DESCRIPTION -The -.Fx -.Sq boot0 -boot manager permits the operator to select from which disk and -slice an i386 machine (PC) is booted. -.Pp -Note that what are referred to here as -.Dq slices -are typically called -.Dq partitions -in -.No non- Ns Bx -documentation relating to the PC. -Typically, only non-removable disks are sliced. -.Pp -The -.Nm -utility optionally installs the -.Sq boot0 -boot manager on the specified -.Ar disk ; -and allows various operational parameters to be configured. -.Pp -On PCs, a boot manager typically occupies sector 0 of a disk, which is -known as the Master Boot Record (MBR). -The MBR contains both code (to which control is passed by the PC BIOS) -and data (an embedded table of defined slices). -.Pp -The options are: -.Bl -tag -width indent -.It Fl B -Install the -.Sq boot0 -boot manager. -This option causes MBR code to be replaced, without -affecting the embedded slice table. -.It Fl b Ar boot0 -Specify which -.Sq boot0 -image to use. -The default is -.Pa /boot/boot0 -which will use the video card as output, alternatively -.Pa /boot/boot0sio -can be used for output to the COM1 port. -(Be aware that nothing will be output to the COM1 port unless the -modem signals DSR and CTS are active.) -.It Fl d Ar drive -Specify the drive number used by the PC BIOS in referencing the drive -which contains the specified -.Ar disk . -Typically this will be 0x80 for the first hard drive, 0x81 for the -second hard drive, and so on; however any integer between 0 and 0xff -is acceptable here. -.It Fl e Ar bell character -Set the character to be printed in case of input error. -.It Fl f Ar file -Specify that a backup copy of the preexisting MBR should be written to -.Ar file . -This file is created if it does not exist, and replaced if it does. -.It Fl i Ar volume-id -Specifies a volume-id (in the form XXXX-XXXX) to be saved at location -0x1b8 in the MBR. This information is sometimes used by NT, XP and Vista -to identify the disk drive. The option is only compatible with version 2.00 -of the 512-byte boot block. -.It Fl m Ar mask -Specify slices to be enabled/disabled, where -.Ar mask -is an integer between 0 (no slices enabled) and 0xf (all four slices -enabled). -.It Fl o Ar options -A comma-separated string of any of the following options may be -specified (with -.Dq no -prepended as necessary): -.Bl -tag -width indent -.It packet -Use the disk packet (BIOS INT 0x13 extensions) interface, -as opposed to the legacy (CHS) interface, when doing disk I/O. -This allows booting above cylinder 1023, but requires specific -BIOS support. -The default is -.Sq packet . -.It setdrv -Forces the drive containing the disk to be referenced using drive -number definable by means of the -d option. -The default is -.Sq nosetdrv . -.It update -Allow the MBR to be updated by the boot manager. -(The MBR may be updated to flag slices as -.Sq active , -and to save slice selection information.) -This is the default; a -.Sq noupdate -option causes the MBR to be treated as read-only. -.El -.It Fl s Ar slice -Set the default boot selection to -.Ar slice . -Values between 1 and 4 refer to slices; a value of 5 refers to the -option of booting from a second disk. -.It Fl t Ar ticks -Set the timeout value to -.Ar ticks . -(There are approximately 18.2 ticks per second.) -.It Fl v -Verbose: display information about the slices defined, etc. -.El -.Sh NOTE -Protection mechanisms in the -.Xr geom 4 -subsystem might prevent -.Nm -from being able to update the MBR on a mounted disk. -Instructions for temporarily disabling these protection mechanisms -can be found in the -.Xr geom 4 -manpage. Specifically, do a -.Pp -.Dl sysctl kern.geom.debugflags=0x10 -.Pp -to allow writing to the MBR, and restore it to 0 afterwards. -.Pp -.Sh FILES -.Bl -tag -width /boot/boot0sio -compact -.It Pa /boot/boot0 -The default -.Sq boot0 -image -.It Pa /boot/boot0sio -Image for serial consoles (COM1,9600,8,N,1,MODEM) -.El -.Sh EXIT STATUS -.Ex -std -.Sh EXAMPLES -To boot slice 2 on the next boot: -.Pp -.Dl "boot0cfg -s 2 ad0" -.Pp -To enable just slices 1 and 2 in the menu: -.Pp -.Dl "boot0cfg -m 0x3 ad0" -.Pp -To go back to non-interactive booting, use -.Xr fdisk 8 -to install the default MBR: -.Pp -.Dl "fdisk -B ad0" -.Pp -.Sh SEE ALSO -.Xr geom 4 , -.Xr boot 8 , -.Xr fdisk 8 -.Sh AUTHORS -.An Robert Nordier Aq rnordier@FreeBSD.org . -.Sh BUGS -Use of the -.Sq packet -option may cause -.Sq boot0 -to fail, depending on the nature of BIOS support. -.Pp -Use of the -.Sq setdrv -option with an incorrect -d operand may cause the boot0 code -to write the MBR to the wrong disk, thus trashing its previous -content. Be careful. diff --git a/usr.sbin/boot0cfg/boot0cfg.c b/usr.sbin/boot0cfg/boot0cfg.c deleted file mode 100644 index fe2c755..0000000 --- a/usr.sbin/boot0cfg/boot0cfg.c +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright (c) 2008 Luigi Rizzo - * Copyright (c) 1999 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MBRSIZE 512 /* master boot record size */ - -#define OFF_VERSION 0x1b0 /* offset: version number, only boot0version */ -#define OFF_SERIAL 0x1b8 /* offset: volume serial number */ -#define OFF_PTBL 0x1be /* offset: partition table */ -#define OFF_MAGIC 0x1fe /* offset: magic number */ -/* - * Offsets to the parameters of the 512-byte boot block. - * For historical reasons they are set as macros - */ -struct opt_offsets { - int opt; - int drive; - int flags; - int ticks; -}; - -struct opt_offsets b0_ofs[] = { - { 0x0, 0x0, 0x0, 0x0 }, /* no boot block */ - { 0x1b9, 0x1ba, 0x1bb, 0x1bc }, /* original block */ - { 0x1b5, 0x1b6, 0x1b7, 0x1bc }, /* NT_SERIAL block */ -}; - -int b0_ver; /* boot block version set by boot0bs */ - -#define OFF_OPT (b0_ofs[b0_ver].opt) /* default boot option */ -#define OFF_DRIVE (b0_ofs[b0_ver].drive) /* setdrv drive */ -#define OFF_FLAGS (b0_ofs[b0_ver].flags) /* option flags */ -#define OFF_TICKS (b0_ofs[b0_ver].ticks) /* clock ticks */ - - -#define cv2(p) ((p)[0] | (p)[1] << 010) - -#define mk2(p, x) \ - (p)[0] = (u_int8_t)(x), \ - (p)[1] = (u_int8_t)((x) >> 010) - -static const struct { - const char *tok; - int def; -} opttbl[] = { - {"packet", 0}, - {"update", 1}, - {"setdrv", 0} -}; -static const int nopt = sizeof(opttbl) / sizeof(opttbl[0]); - -static const char fmt0[] = "# flag start chs type" - " end chs offset size\n"; - -static const char fmt1[] = "%d 0x%02x %4u:%3u:%2u 0x%02x" - " %4u:%3u:%2u %10u %10u\n"; - -static int read_mbr(const char *, u_int8_t **, int); -static void write_mbr(const char *, int, u_int8_t *, int); -static void display_mbr(u_int8_t *); -static int boot0version(const u_int8_t *); -static int boot0bs(const u_int8_t *); -static void stropt(const char *, int *, int *); -static int argtoi(const char *, int, int, int); -static int set_bell(u_int8_t *, int, int); -static void usage(void); - -unsigned vol_id[5]; /* 4 plus 1 for flag */ - -int v_flag; -/* - * Boot manager installation/configuration utility. - */ -int -main(int argc, char *argv[]) -{ - u_int8_t *mbr, *boot0; - int boot0_size, mbr_size; - const char *bpath, *fpath; - char *disk; - int B_flag, o_flag; - int d_arg, m_arg, s_arg, t_arg; - int o_and, o_or, o_e = -1; - int up, c; - - bpath = "/boot/boot0"; - fpath = NULL; - B_flag = v_flag = o_flag = 0; - d_arg = m_arg = s_arg = t_arg = -1; - o_and = 0xff; - o_or = 0; - while ((c = getopt(argc, argv, "Bvb:d:e:f:i:m:o:s:t:")) != -1) - switch (c) { - case 'B': - B_flag = 1; - break; - case 'v': - v_flag = 1; - break; - case 'b': - bpath = optarg; - break; - case 'd': - d_arg = argtoi(optarg, 0, 0xff, 'd'); - break; - case 'e': - if (optarg[0] == '0' && optarg[1] == 'x') - sscanf(optarg, "0x%02x", &o_e); - else - o_e = optarg[0]; - break; - case 'f': - fpath = optarg; - break; - case 'i': - if (sscanf(optarg, "%02x%02x-%02x%02x", - vol_id, vol_id+1, vol_id+2, vol_id+3) == 4) - vol_id[4] = 1; - else - errx(1, "bad argument %s", optarg); - break; - case 'm': - m_arg = argtoi(optarg, 0, 0xf, 'm'); - break; - case 'o': - stropt(optarg, &o_and, &o_or); - o_flag = 1; - break; - case 's': - s_arg = argtoi(optarg, 1, 5, 's'); - break; - case 't': - t_arg = argtoi(optarg, 1, 0xffff, 't'); - break; - default: - usage(); - } - argc -= optind; - argv += optind; - if (argc != 1) - usage(); - disk = g_device_path(*argv); - if (disk == NULL) - errx(1, "Unable to get providername for %s\n", *argv); - up = B_flag || d_arg != -1 || m_arg != -1 || o_flag || s_arg != -1 - || t_arg != -1; - - /* open the disk and read in the existing mbr. Either here or - * when reading the block from disk, we do check for the version - * and abort if a suitable block is not found. - */ - mbr_size = read_mbr(disk, &mbr, !B_flag); - - /* save the existing MBR if we are asked to do so */ - if (fpath) - write_mbr(fpath, O_CREAT | O_TRUNC, mbr, mbr_size); - - /* - * If we are installing the boot loader, read it from disk and copy the - * slice table over from the existing MBR. If not, then point boot0 - * back at the MBR we just read in. After this, boot0 is the data to - * write back to disk if we are going to do a write. - */ - if (B_flag) { - boot0_size = read_mbr(bpath, &boot0, 1); - memcpy(boot0 + OFF_PTBL, mbr + OFF_PTBL, - sizeof(struct dos_partition) * NDOSPART); - if (b0_ver == 2) /* volume serial number support */ - memcpy(boot0 + OFF_SERIAL, mbr + OFF_SERIAL, 4); - } else { - boot0 = mbr; - boot0_size = mbr_size; - } - - /* set the drive */ - if (d_arg != -1) - boot0[OFF_DRIVE] = d_arg; - - /* set various flags */ - if (m_arg != -1) { - boot0[OFF_FLAGS] &= 0xf0; - boot0[OFF_FLAGS] |= m_arg; - } - if (o_flag) { - boot0[OFF_FLAGS] &= o_and; - boot0[OFF_FLAGS] |= o_or; - } - - /* set the default boot selection */ - if (s_arg != -1) - boot0[OFF_OPT] = s_arg - 1; - - /* set the timeout */ - if (t_arg != -1) - mk2(boot0 + OFF_TICKS, t_arg); - - /* set the bell char */ - if (o_e != -1 && set_bell(boot0, o_e, 0) != -1) - up = 1; - - if (vol_id[4]) { - if (b0_ver != 2) - errx(1, "incompatible boot block, cannot set volume ID"); - boot0[OFF_SERIAL] = vol_id[0]; - boot0[OFF_SERIAL+1] = vol_id[1]; - boot0[OFF_SERIAL+2] = vol_id[2]; - boot0[OFF_SERIAL+3] = vol_id[3]; - up = 1; /* force update */ - } - /* write the MBR back to disk */ - if (up) - write_mbr(disk, 0, boot0, boot0_size); - - /* display the MBR */ - if (v_flag) - display_mbr(boot0); - - /* clean up */ - if (mbr != boot0) - free(boot0); - free(mbr); - free(disk); - - return 0; -} - -/* get or set the 'bell' character to be used in case of errors. - * Lookup for a certain code sequence, return -1 if not found. - */ -static int -set_bell(u_int8_t *mbr, int new_bell, int report) -{ - /* lookup sequence: 0x100 means skip, 0x200 means done */ - static unsigned seq[] = - { 0xb0, 0x100, 0xe8, 0x100, 0x100, 0x30, 0xe4, 0x200 }; - int ofs, i, c; - for (ofs = 0x60; ofs < 0x180; ofs++) { /* search range */ - if (mbr[ofs] != seq[0]) /* search initial pattern */ - continue; - for (i=0;; i++) { - if (seq[i] == 0x200) { /* found */ - c = mbr[ofs+1]; - if (!report) - mbr[ofs+1] = c = new_bell; - else - printf(" bell=%c (0x%x)", - (c >= ' ' && c < 0x7f) ? c : ' ', c); - return c; - } - if (seq[i] != 0x100 && seq[i] != mbr[ofs+i]) - break; - } - } - warn("bell not found"); - return -1; -} -/* - * Read in the MBR of the disk. If it is boot0, then use the version to - * read in all of it if necessary. Use pointers to return a malloc'd - * buffer containing the MBR and then return its size. - */ -static int -read_mbr(const char *disk, u_int8_t **mbr, int check_version) -{ - u_int8_t buf[MBRSIZE]; - int mbr_size, fd; - int ver; - ssize_t n; - - if ((fd = open(disk, O_RDONLY)) == -1) - err(1, "open %s", disk); - if ((n = read(fd, buf, MBRSIZE)) == -1) - err(1, "read %s", disk); - if (n != MBRSIZE) - errx(1, "%s: short read", disk); - if (cv2(buf + OFF_MAGIC) != 0xaa55) - errx(1, "%s: bad magic", disk); - - if (! (ver = boot0bs(buf))) { - if (check_version) - errx(1, "%s: unknown or incompatible boot code", disk); - } else if (boot0version(buf) == 0x101) { - mbr_size = 1024; - if ((*mbr = malloc(mbr_size)) == NULL) - errx(1, "%s: unable to allocate read buffer", disk); - if (lseek(fd, 0, SEEK_SET) == -1 || - (n = read(fd, *mbr, mbr_size)) == -1) - err(1, "%s", disk); - if (n != mbr_size) - errx(1, "%s: short read", disk); - return (mbr_size); - } - *mbr = malloc(sizeof(buf)); - memcpy(*mbr, buf, sizeof(buf)); - - return sizeof(buf); -} - -/* - * Write out the mbr to the specified file. - */ -static void -write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size) -{ - int fd; - ssize_t n; - const char *errmsg; - char *pname; - struct gctl_req *grq; - - fd = open(fname, O_WRONLY | flags, 0666); - if (fd != -1) { - n = write(fd, mbr, mbr_size); - close(fd); - if (n != mbr_size) - errx(1, "%s: short write", fname); - return; - } else { - err(1, "write_mbr: %s", fname); - } - - /* - * If we're called to write to a backup file, don't try to - * write through GEOM. It only generates additional errors. - */ - if (flags != 0) - return; - - /* Try open it read only. */ - fd = open(fname, O_RDONLY); - if (fd == -1) { - warn("error opening %s", fname); - return; - } - pname = g_providername(fd); - if (pname == NULL) { - warn("error getting providername for %s", fname); - return; - } - grq = gctl_get_handle(); - gctl_ro_param(grq, "class", -1, "PART"); - gctl_ro_param(grq, "geom", -1, pname); - gctl_ro_param(grq, "verb", -1, "bootcode"); - gctl_ro_param(grq, "bootcode", mbr_size, mbr); - gctl_ro_param(grq, "flags", -1, "C"); - errmsg = gctl_issue(grq); - if (errmsg == NULL) - goto out; - - grq = gctl_get_handle(); - gctl_ro_param(grq, "verb", -1, "write MBR"); - gctl_ro_param(grq, "class", -1, "MBR"); - gctl_ro_param(grq, "geom", -1, pname); - gctl_ro_param(grq, "data", mbr_size, mbr); - errmsg = gctl_issue(grq); - if (errmsg != NULL) - err(1, "write_mbr: %s", fname); - -out: - free(pname); - gctl_free(grq); -} - -/* - * Outputs an informative dump of the data in the MBR to stdout. - */ -static void -display_mbr(u_int8_t *mbr) -{ - struct dos_partition *part; - int i, version; - - part = (struct dos_partition *)(mbr + DOSPARTOFF); - printf(fmt0); - for (i = 0; i < NDOSPART; i++) - if (part[i].dp_typ) - printf(fmt1, 1 + i, part[i].dp_flag, - part[i].dp_scyl + ((part[i].dp_ssect & 0xc0) << 2), - part[i].dp_shd, part[i].dp_ssect & 0x3f, part[i].dp_typ, - part[i].dp_ecyl + ((part[i].dp_esect & 0xc0) << 2), - part[i].dp_ehd, part[i].dp_esect & 0x3f, part[i].dp_start, - part[i].dp_size); - printf("\n"); - version = boot0version(mbr); - printf("version=%d.%d drive=0x%x mask=0x%x ticks=%u", - version >> 8, version & 0xff, mbr[OFF_DRIVE], - mbr[OFF_FLAGS] & 0xf, cv2(mbr + OFF_TICKS)); - set_bell(mbr, 0, 1); - printf("\noptions="); - for (i = 0; i < nopt; i++) { - if (i) - printf(","); - if (!(mbr[OFF_FLAGS] & 1 << (7 - i)) ^ opttbl[i].def) - printf("no"); - printf("%s", opttbl[i].tok); - } - printf("\n"); - if (b0_ver == 2) - printf("volume serial ID %02x%02x-%02x%02x\n", - mbr[OFF_SERIAL], mbr[OFF_SERIAL+1], - mbr[OFF_SERIAL+2], mbr[OFF_SERIAL+3]); - printf("default_selection=F%d (", mbr[OFF_OPT] + 1); - if (mbr[OFF_OPT] < 4) - printf("Slice %d", mbr[OFF_OPT] + 1); - else - printf("Drive 1"); - printf(")\n"); -} - -/* - * Return the boot0 version with the minor revision in the low byte, and - * the major revision in the next higher byte. - */ -static int -boot0version(const u_int8_t *bs) -{ - /* Check for old version, and return 0x100 if found. */ - int v = boot0bs(bs); - if (v != 0) - return v << 8; - - /* We have a newer boot0, so extract the version number and return it. */ - return *(const int *)(bs + OFF_VERSION) & 0xffff; -} - -/* descriptor of a pattern to match. - * Start from the first entry trying to match the chunk of bytes, - * if you hit an entry with len=0 terminate the search and report - * off as the version. Otherwise skip to the next block after len=0 - * An entry with len=0, off=0 is the end marker. - */ -struct byte_pattern { - unsigned off; - unsigned len; - u_int8_t *key; -}; - -/* - * Decide if we have valid boot0 boot code by looking for - * characteristic byte sequences at fixed offsets. - */ -static int -boot0bs(const u_int8_t *bs) -{ - /* the initial code sequence */ - static u_int8_t id0[] = {0xfc, 0x31, 0xc0, 0x8e, 0xc0, 0x8e, 0xd8, - 0x8e, 0xd0, 0xbc, 0x00, 0x7c }; - /* the drive id */ - static u_int8_t id1[] = {'D', 'r', 'i', 'v', 'e', ' '}; - static struct byte_pattern patterns[] = { - {0x0, sizeof(id0), id0}, - {0x1b2, sizeof(id1), id1}, - {1, 0, NULL}, - {0x0, sizeof(id0), id0}, /* version with NT support */ - {0x1ae, sizeof(id1), id1}, - {2, 0, NULL}, - {0, 0, NULL}, - }; - struct byte_pattern *p = patterns; - - for (; p->off || p->len; p++) { - if (p->len == 0) - break; - if (!memcmp(bs + p->off, p->key, p->len)) /* match */ - continue; - while (p->len) /* skip to next block */ - p++; - } - b0_ver = p->off; /* XXX ugly side effect */ - return p->off; -} - -/* - * Adjust "and" and "or" masks for a -o option argument. - */ -static void -stropt(const char *arg, int *xa, int *xo) -{ - const char *q; - char *s, *s1; - int inv, i, x; - - if (!(s = strdup(arg))) - err(1, NULL); - for (s1 = s; (q = strtok(s1, ",")); s1 = NULL) { - if ((inv = !strncmp(q, "no", 2))) - q += 2; - for (i = 0; i < nopt; i++) - if (!strcmp(q, opttbl[i].tok)) - break; - if (i == nopt) - errx(1, "%s: Unknown -o option", q); - if (opttbl[i].def) - inv ^= 1; - x = 1 << (7 - i); - if (inv) - *xa &= ~x; - else - *xo |= x; - } - free(s); -} - -/* - * Convert and check an option argument. - */ -static int -argtoi(const char *arg, int lo, int hi, int opt) -{ - char *s; - long x; - - errno = 0; - x = strtol(arg, &s, 0); - if (errno || !*arg || *s || x < lo || x > hi) - errx(1, "%s: Bad argument to -%c option", arg, opt); - return x; -} - -/* - * Display usage information. - */ -static void -usage(void) -{ - fprintf(stderr, "%s\n%s\n", - "usage: boot0cfg [-Bv] [-b boot0] [-d drive] [-f file] [-m mask]", - " [-o options] [-s slice] [-t ticks] disk"); - exit(1); -} diff --git a/usr.sbin/boot98cfg/Makefile b/usr.sbin/boot98cfg/Makefile deleted file mode 100644 index 9b0e703..0000000 --- a/usr.sbin/boot98cfg/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $FreeBSD$ - -PROG= boot98cfg -MAN= boot98cfg.8 - -WARNS?= 2 - -DPADD= ${LIBGEOM} -LDADD= -lgeom - -.include diff --git a/usr.sbin/boot98cfg/boot98cfg.8 b/usr.sbin/boot98cfg/boot98cfg.8 deleted file mode 100644 index 96ebbcd..0000000 --- a/usr.sbin/boot98cfg/boot98cfg.8 +++ /dev/null @@ -1,104 +0,0 @@ -.\" Copyright (c) KATO Takenori, 2000. -.\" -.\" All rights reserved. Unpublished rights reserved under the copyright -.\" laws of Japan. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer as -.\" the first lines of this file unmodified. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd July 10, 2000 -.Dt BOOT98CFG 8 -.Os -.Sh NAME -.Nm boot98cfg -.Nd HDD boot manager installation utility -.Sh SYNOPSIS -.Nm -.Op Fl B -.Op Fl i Ar boot0 -.Op Fl m Ar boot0.5 -.Op Fl s Ar secsize -.Op Fl v Ar version -.Op Fl f Ar boot0.bak -.Op Fl F Ar boot0.5.bak -.Ar disk -.Sh DESCRIPTION -On NEC PC-98s, -.Sq boot loader -consists of the -.Sq IPL -and -.Sq HDD boot menu . -The IPL occupies sector 0 of a disk and is followed by the partition -table. -The IPL loads the HDD boot menu that starts from 0x400. -.Pp -The -.Nm -utility installs and makes backup copy of the IPL and the HDD boot menu; and -allows changing the version number field in the sector 0. -.Pp -Note that the format command in NEC's OSs replaces the HDD boot menu -with its own HDD boot menu when the version number field is smaller -than that in the format command. -.Pp -The options are: -.Bl -tag -width indent -.It Fl B -Install the IPL and HDD boot menu. -This option causes the IPL and HDD -boot menu code to be replaced. -.It Fl i Ar boot0 -Specify which IPL image to use. -The default is /boot/boot0. -.It Fl m Ar boot0.5 -Specify which HDD boot menu image to use. -The default is -/boot/boot0.5. -.It Fl f Ar boot0.bak -Specify that a backup copy of the preexisting IPL should be written to -.Ar boot0.bak . -This file is created if it does not exist, and truncated if it does. -.It Fl F Ar boot0.5.bak -Specify that a backup copy of the preexisting HDD boot menu should be -written to -.Ar boot0.5.bak . -This file is created if it does not exist, and truncated if it does. -.It Fl v Ar version -Specify the version number. -.It Fl s Ar secsize -Specify the sector size. -The default sector size is 512 -(bytes/sector). -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr boot 8 , -.Xr fdisk 8 -.Sh AUTHORS -.An NOKUBI Hirotaka , -.An KATO Takenori diff --git a/usr.sbin/boot98cfg/boot98cfg.c b/usr.sbin/boot98cfg/boot98cfg.c deleted file mode 100644 index f1ae8329..0000000 --- a/usr.sbin/boot98cfg/boot98cfg.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (c) KATO Takenori, 2000. - * - * All rights reserved. Unpublished rights reserved under the copyright - * laws of Japan. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer as - * the first lines of this file unmodified. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * Copyright (c) 1999 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BOOTSIZE 0x2000 -#define IPLSIZE 512 /* IPL size */ -#define BOOTMENUSIZE 7168 /* Max HDD boot menu size */ -#define BOOTMENUOFF 0x400 - -u_char boot0buf[BOOTSIZE]; -u_char ipl[IPLSIZE]; -u_char menu[BOOTMENUSIZE]; - -static int read_boot(const char *, u_char *); -static int write_boot(const char *, u_char *); -static char *mkrdev(const char *); -static void usage(void); - -/* - * Boot manager installation/configuration utility. - */ -int -main(int argc, char *argv[]) -{ - char *endptr; - const char *iplpath = "/boot/boot0", *menupath = "/boot/boot0.5"; - char *iplbakpath = NULL, *menubakpath = NULL; - char *disk; - int B_flag = 0; - int c; - int fd1; - int n; - int secsize = 512; - int v_flag = 0, version; - - while ((c = getopt(argc, argv, "BF:f:i:m:s:v:")) != -1) { - switch (c) { - case 'B': - B_flag = 1; - break; - case 'F': - menubakpath = optarg; - break; - case 'f': - iplbakpath = optarg; - break; - case 'i': - iplpath = optarg; - break; - case 'm': - menupath = optarg; - break; - case 's': - secsize = strtol(optarg, &endptr, 0); - if (errno || *optarg == '\0' || *endptr) - errx(1, "%s: Bad argument to -s option", - optarg); - switch (secsize) { - case 256: - case 512: - case 1024: - case 2048: - break; - default: - errx(1, "%s: unsupported sector size", optarg); - break; - } - break; - case 'v': - v_flag = 1; - version = strtol(optarg, &endptr, 0); - if (errno || *optarg == '\0' || *endptr || - version < 0 || version > 255) - errx(1, "%s: Bad argument to -v option", - optarg); - break; - default: - usage(); - /* NOTREACHED */ - break; - } - } - argc -= optind; - argv += optind; - if (argc != 1) - usage(); - disk = mkrdev(*argv); - - read_boot(disk, boot0buf); - - if (iplbakpath != NULL) { - fd1 = open(iplbakpath, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd1 < 0) - err(1, "%s", iplbakpath); - n = write(fd1, boot0buf, IPLSIZE); - if (n == -1) - err(1, "%s", iplbakpath); - if (n != IPLSIZE) - errx(1, "%s: short write", iplbakpath); - close(fd1); - } - - if (menubakpath != NULL) { - fd1 = open(menubakpath, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if (fd1 < 0) - err(1, "%s", menubakpath); - n = write(fd1, boot0buf + BOOTMENUOFF, BOOTMENUSIZE); - if (n == -1) - err(1, "%s", menubakpath); - if (n != BOOTMENUSIZE) - errx(1, "%s: short write", menubakpath); - close(fd1); - } - - if (B_flag) { - /* Read IPL (boot0). */ - fd1 = open(iplpath, O_RDONLY); - if (fd1 < 0) - err(1, "%s", disk); - n = read(fd1, ipl, IPLSIZE); - if (n < 0) - err(1, "%s", iplpath); - if (n != IPLSIZE) - errx(1, "%s: invalid file", iplpath); - close(fd1); - - /* Read HDD boot menu (boot0.5). */ - fd1 = open(menupath, O_RDONLY); - if (fd1 < 0) - err(1, "%s", disk); - n = read(fd1, menu, BOOTMENUSIZE); - if (n < 0) - err(1, "%s", menupath); - if (n != BOOTMENUSIZE) - errx(1, "%s: invalid file", menupath); - close(fd1); - - memcpy(boot0buf, ipl, IPLSIZE); - memcpy(boot0buf + BOOTMENUOFF, menu, BOOTMENUSIZE); - } - - /* Set version number field. */ - if (v_flag) - *(boot0buf + secsize - 4) = (u_char)version; - - if (B_flag || v_flag) - write_boot(disk, boot0buf); - - return 0; -} - -static int -read_boot(const char *disk, u_char *boot) -{ - int fd, n; - - /* Read IPL, partition table and HDD boot menu. */ - fd = open(disk, O_RDONLY); - if (fd < 0) - err(1, "%s", disk); - n = read(fd, boot, BOOTSIZE); - if (n != BOOTSIZE) - errx(1, "%s: short read", disk); - close(fd); - - return 0; -} - -static int -write_boot(const char *disk, u_char *boot) -{ - int fd, n, i; - char buf[MAXPATHLEN]; - const char *q; - struct gctl_req *grq; - - fd = open(disk, O_WRONLY, 0666); - if (fd != -1) { - if ((n = write(fd, boot, BOOTSIZE)) < 0) - err(1, "%s", disk); - if (n != BOOTSIZE) - errx(1, "%s: short write", disk); - close(fd); - return 0; - } - - grq = gctl_get_handle(); - gctl_ro_param(grq, "verb", -1, "write PC98"); - gctl_ro_param(grq, "class", -1, "PC98"); - q = strrchr(disk, '/'); - if (q == NULL) - q = disk; - else - q++; - gctl_ro_param(grq, "geom", -1, q); - gctl_ro_param(grq, "data", BOOTSIZE, boot); - q = gctl_issue(grq); - if (q == NULL) - return 0; - - warnx("%s: %s", disk, q); - gctl_free(grq); - - for (i = 0; i < NDOSPART; i++) { - snprintf(buf, sizeof(buf), "%ss%d", disk, i + 1); - fd = open(buf, O_RDONLY); - if (fd < 0) - continue; - n = ioctl(fd, DIOCSPC98, boot); - if (n != 0) - err(1, "%s: ioctl DIOCSPC98", disk); - close(fd); - return 0; - } - - err(1, "%s", disk); -} - -/* - * Produce a device path for a "canonical" name, where appropriate. - */ -static char * -mkrdev(const char *fname) -{ - char buf[MAXPATHLEN]; - char *s; - - if (!strchr(fname, '/')) { - snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname); - s = strdup(buf); - } else - s = strdup(fname); - - if (s == NULL) - errx(1, "No more memory"); - return s; -} - -/* - * Display usage information. - */ -static void -usage(void) -{ - fprintf(stderr, - "boot98cfg [-B][-i boot0][-m boot0.5][-s secsize][-v version]\n" - " [-f ipl.bak][-F menu.bak] disk\n"); - exit(1); -} diff --git a/usr.sbin/bootparamd/Makefile b/usr.sbin/bootparamd/Makefile deleted file mode 100644 index c4e3361..0000000 --- a/usr.sbin/bootparamd/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -SUBDIR= bootparamd callbootd - -.include diff --git a/usr.sbin/bootparamd/Makefile.inc b/usr.sbin/bootparamd/Makefile.inc deleted file mode 100644 index 5c01215..0000000 --- a/usr.sbin/bootparamd/Makefile.inc +++ /dev/null @@ -1,6 +0,0 @@ -# @(#)Makefile.inc 5.1 (Berkeley) 5/11/90 -# $FreeBSD$ - -BINDIR?= /usr/sbin - -WARNS?= 2 diff --git a/usr.sbin/bootparamd/bootparamd/Makefile b/usr.sbin/bootparamd/bootparamd/Makefile deleted file mode 100644 index 5d2047b..0000000 --- a/usr.sbin/bootparamd/bootparamd/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# from: @(#)Makefile 5.8 (Berkeley) 7/28/90 -# $FreeBSD$ - -.include - -PROG= bootparamd -MAN= bootparams.5 bootparamd.8 -SRCS= bootparamd.c main.c ${GENSRCS} -GENSRCS=bootparam_prot.h bootparam_prot_svc.c bootparam_prot_xdr.c - -CFLAGS+= -DTFTP_DIR=\"/tftpboot\" -I. -.if ${MK_NIS} != "no" -CFLAGS+= -DYP -.endif - -CLEANFILES= ${GENSRCS} - -RPCSRC= ${DESTDIR}/usr/include/rpcsvc/bootparam_prot.x - -bootparam_prot_svc.c: ${RPCSRC} - rpcgen -C -m -o ${.TARGET} ${RPCSRC} - -bootparam_prot_xdr.c: ${RPCSRC} - rpcgen -C -c -o ${.TARGET} ${RPCSRC} - -bootparam_prot.h: ${RPCSRC} - rpcgen -C -h -o ${.TARGET} ${RPCSRC} - -.include diff --git a/usr.sbin/bootparamd/bootparamd/README b/usr.sbin/bootparamd/bootparamd/README deleted file mode 100644 index 508ee0f..0000000 --- a/usr.sbin/bootparamd/bootparamd/README +++ /dev/null @@ -1,75 +0,0 @@ -$FreeBSD$ - -This directory contains a version of the rpc.bootparamd, which have been -written using the Sun's RPC protocol for bootparamd. To use it you must -have a copy of the bootparam_prot.x file which on Sun systems you find in - - /usr/include/rpcsvc/bootparam_prot.x - -(( This file was retrieved from the Sun-RPC source package )) - - -This code is not copyright, and is placed in the public domain. Feel free to -use and modify. Please send modifications and/or suggestions + bug fixes to - - Klas Heggemann - - -RPC.BOOTPARAMD - - -The rpc.bootparamd program does NOT use the yellow pages for the bootparams -database. This data should recide in /etc/bootparams on the local host, -or another file given when the server is started. - -The default router is set to the address of the machine running the server. -This may not be a good thing to do, so it can be modified using the -r -option when startning the daemon. - -This program was written with the need to keep short hostnames in the -/etc/bootparams file and long (canonical) names in the hosts database. -It probably also will work in conjunction with a nameserver, since matching -is done by comparing the canonical name of the booting machine with the -canonical name of the hosts found in the bootparams database. - -It is kept simple, e g there is no caching of data, but the bootparameter file -is read at each request. - - -CALLBOOTD - -The debugging tool callbootd is used to check the response you get -to a specific (booting) request. It can be used as - callbootd server inet-address -or - callbootd server hostname file -where "server" is a machine running the rpc.bootparamd program, "inet-address" -is the internet address of a booting machine, "hostname" is the name of a -booting machine and "file" the requested file, typically "root", "swap" or -"dump". - -You may also use "all" instead of a specific server, in which case a RPC -broadcast is performed. The broadcast is performed 4 times and then the -program times out, after printing all responses. - - -TODO - -Cache the date, instead of rereading it. -Maybe match by comparing the inet address instead. (But beware that caching -will prevent the server from detecting that a machine has changed name -or address.) - - - - - - - - - - - - - - diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.8 b/usr.sbin/bootparamd/bootparamd/bootparamd.8 deleted file mode 100644 index 6048a8f..0000000 --- a/usr.sbin/bootparamd/bootparamd/bootparamd.8 +++ /dev/null @@ -1,76 +0,0 @@ -.\" @(#)bootparamd.8 -.\" $FreeBSD$ -.Dd December 14, 2000 -.Dt BOOTPARAMD 8 -.Os -.Sh NAME -.Nm bootparamd -.Nd boot parameter server -.Sh SYNOPSIS -.Nm -.Op Fl ds -.Op Fl r Ar router -.Op Fl f Ar file -.Sh DESCRIPTION -The -.Nm -utility is a server process that provides information to -.Xr diskless 8 -clients necessary for booting. -It consults the -.Pa /etc/bootparams -file. -.Pp -This version will allow the use of aliases on the hostname in the -.Pa /etc/bootparams -file. -The returned hostname to the -.Em whoami -request done by the booting client -will be the name that appears in -.Pa /etc/bootparams -and not the canonical name. -In this way you can keep the answer short enough -so that machines that cannot handle long hostnames will not fail during boot. -.Sh OPTIONS -.Bl -tag -width Fl -.It Fl d -Display the debugging information. -.It Fl s -Log the debugging information with -.Xr syslog 3 . -.It Fl r Ar router -The default router (a machine or an IP-address). -This defaults to the machine running the server. -.It Fl f Ar file -The file to use as boot parameter file instead of -.Pa /etc/bootparams . -.El -.Sh FILES -.Bl -tag -width /etc/bootparams -compact -.It /etc/bootparams -default boot parameter file -.El -.Sh EXAMPLES -When netbooting diskless SunOS/Xkernel SPARCstations the booted SunOS kernel -also broadcasts to the all-0 address. -The SunOS kernel hangs until it receives a reply. -To accommodate this behaviour add an alias address -that responds to an all-0 broadcast. -So, add something like -.Ql "ifconfig xl0 192.168.200.254 netmask 255.255.255.255 broadcast 192.168.200.0 alias -on the relevant network interface on your -.Nm -server. -The alias address must of course be free for use. -.Sh SEE ALSO -.Xr syslog 3 , -.Xr bootparams 5 , -.Xr diskless 8 -.Sh AUTHORS -Written by -.An Klas Heggemann Aq klas@nada.kth.se . -.Sh BUGS -You may find the -.Xr syslog 3 -loggings to be verbose. diff --git a/usr.sbin/bootparamd/bootparamd/bootparamd.c b/usr.sbin/bootparamd/bootparamd/bootparamd.c deleted file mode 100644 index 5c1d264..0000000 --- a/usr.sbin/bootparamd/bootparamd/bootparamd.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - -This code is not copyright, and is placed in the public domain. Feel free to -use and modify. Please send modifications and/or suggestions + bug fixes to - - Klas Heggemann - -*/ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#ifdef YP -#include -#include -#include -#endif -#include "bootparam_prot.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -extern int debug, dolog; -extern in_addr_t route_addr; -extern char *bootpfile; - -#define MAXLEN 800 - -struct hostent *he; -static char buffer[MAXLEN]; -static char hostname[MAX_MACHINE_NAME]; -static char askname[MAX_MACHINE_NAME]; -static char path[MAX_PATH_LEN]; -static char domain_name[MAX_MACHINE_NAME]; - -int getthefile(char *, char *, char *, int); -int checkhost(char *, char *, int); - -bp_whoami_res * -bootparamproc_whoami_1_svc(whoami, req) -bp_whoami_arg *whoami; -struct svc_req *req; -{ - in_addr_t haddr; - static bp_whoami_res res; - if (debug) - fprintf(stderr,"whoami got question for %d.%d.%d.%d\n", - 255 & whoami->client_address.bp_address_u.ip_addr.net, - 255 & whoami->client_address.bp_address_u.ip_addr.host, - 255 & whoami->client_address.bp_address_u.ip_addr.lh, - 255 & whoami->client_address.bp_address_u.ip_addr.impno); - if (dolog) - syslog(LOG_NOTICE, "whoami got question for %d.%d.%d.%d\n", - 255 & whoami->client_address.bp_address_u.ip_addr.net, - 255 & whoami->client_address.bp_address_u.ip_addr.host, - 255 & whoami->client_address.bp_address_u.ip_addr.lh, - 255 & whoami->client_address.bp_address_u.ip_addr.impno); - - bcopy((char *)&whoami->client_address.bp_address_u.ip_addr, (char *)&haddr, - sizeof(haddr)); - he = gethostbyaddr((char *)&haddr,sizeof(haddr),AF_INET); - if ( ! he ) goto failed; - - if (debug) warnx("this is host %s", he->h_name); - if (dolog) syslog(LOG_NOTICE,"This is host %s\n", he->h_name); - - strncpy(askname, he->h_name, sizeof(askname)); - askname[sizeof(askname)-1] = 0; - - if (checkhost(askname, hostname, sizeof hostname) ) { - res.client_name = hostname; - getdomainname(domain_name, MAX_MACHINE_NAME); - res.domain_name = domain_name; - - if ( res.router_address.address_type != IP_ADDR_TYPE ) { - res.router_address.address_type = IP_ADDR_TYPE; - bcopy( &route_addr, &res.router_address.bp_address_u.ip_addr, sizeof(in_addr_t)); - } - if (debug) fprintf(stderr, - "Returning %s %s %d.%d.%d.%d\n", - res.client_name, - res.domain_name, - 255 & res.router_address.bp_address_u.ip_addr.net, - 255 & res.router_address.bp_address_u.ip_addr.host, - 255 & res.router_address.bp_address_u.ip_addr.lh, - 255 & res.router_address.bp_address_u.ip_addr.impno); - if (dolog) syslog(LOG_NOTICE, - "Returning %s %s %d.%d.%d.%d\n", - res.client_name, - res.domain_name, - 255 & res.router_address.bp_address_u.ip_addr.net, - 255 & res.router_address.bp_address_u.ip_addr.host, - 255 & res.router_address.bp_address_u.ip_addr.lh, - 255 & res.router_address.bp_address_u.ip_addr.impno); - - return(&res); - } - failed: - if (debug) warnx("whoami failed"); - if (dolog) syslog(LOG_NOTICE,"whoami failed\n"); - return(NULL); -} - - -bp_getfile_res * - bootparamproc_getfile_1_svc(getfile, req) -bp_getfile_arg *getfile; -struct svc_req *req; -{ - char *where, *index(); - static bp_getfile_res res; - - if (debug) - warnx("getfile got question for \"%s\" and file \"%s\"", - getfile->client_name, getfile->file_id); - - if (dolog) - syslog(LOG_NOTICE,"getfile got question for \"%s\" and file \"%s\"\n", - getfile->client_name, getfile->file_id); - - he = NULL; - he = gethostbyname(getfile->client_name); - if (! he ) goto failed; - - strncpy(askname, he->h_name, sizeof(askname)); - askname[sizeof(askname)-1] = 0; - - if (getthefile(askname, getfile->file_id,buffer,sizeof(buffer))) { - if ( (where = index(buffer,':')) ) { - /* buffer is re-written to contain the name of the info of file */ - strncpy(hostname, buffer, where - buffer); - hostname[where - buffer] = '\0'; - where++; - strcpy(path, where); - he = gethostbyname(hostname); - if ( !he ) goto failed; - bcopy( he->h_addr, &res.server_address.bp_address_u.ip_addr, 4); - res.server_name = hostname; - res.server_path = path; - res.server_address.address_type = IP_ADDR_TYPE; - } - else { /* special for dump, answer with null strings */ - if (!strcmp(getfile->file_id, "dump")) { - res.server_name = ""; - res.server_path = ""; - res.server_address.address_type = IP_ADDR_TYPE; - bzero(&res.server_address.bp_address_u.ip_addr,4); - } else goto failed; - } - if (debug) - fprintf(stderr, "returning server:%s path:%s address: %d.%d.%d.%d\n", - res.server_name, res.server_path, - 255 & res.server_address.bp_address_u.ip_addr.net, - 255 & res.server_address.bp_address_u.ip_addr.host, - 255 & res.server_address.bp_address_u.ip_addr.lh, - 255 & res.server_address.bp_address_u.ip_addr.impno); - if (dolog) - syslog(LOG_NOTICE, "returning server:%s path:%s address: %d.%d.%d.%d\n", - res.server_name, res.server_path, - 255 & res.server_address.bp_address_u.ip_addr.net, - 255 & res.server_address.bp_address_u.ip_addr.host, - 255 & res.server_address.bp_address_u.ip_addr.lh, - 255 & res.server_address.bp_address_u.ip_addr.impno); - return(&res); - } - failed: - if (debug) warnx("getfile failed for %s", getfile->client_name); - if (dolog) syslog(LOG_NOTICE, - "getfile failed for %s\n", getfile->client_name); - return(NULL); -} - -/* getthefile return 1 and fills the buffer with the information - of the file, e g "host:/export/root/client" if it can be found. - If the host is in the database, but the file is not, the buffer - will be empty. (This makes it possible to give the special - empty answer for the file "dump") */ - -int -getthefile(askname,fileid,buffer,blen) -char *askname; -char *fileid, *buffer; -int blen; -{ - FILE *bpf; - char *where; -#ifdef YP - static char *result; - int resultlen; - static char *yp_domain; -#endif - - int ch, pch, fid_len, res = 0; - int match = 0; - char info[MAX_FILEID + MAX_PATH_LEN+MAX_MACHINE_NAME + 3]; - - bpf = fopen(bootpfile, "r"); - if ( ! bpf ) - errx(1, "no %s", bootpfile); - - /* XXX see comment below */ - while ( fscanf(bpf, "%255s", hostname) > 0 && !match ) { - if ( *hostname != '#' ) { /* comment */ - if ( ! strcmp(hostname, askname) ) { - match = 1; - } else { - he = gethostbyname(hostname); - if (he && !strcmp(he->h_name, askname)) match = 1; - } - } - if (*hostname == '+' ) { /* NIS */ -#ifdef YP - if (yp_get_default_domain(&yp_domain)) { - if (debug) warn("NIS"); - return(0); - } - if (yp_match(yp_domain, "bootparams", askname, strlen(askname), - &result, &resultlen)) - return (0); - if (strstr(result, fileid) == NULL) { - buffer[0] = '\0'; - } else { - snprintf(buffer, blen, - "%s",strchr(strstr(result,fileid), '=') + 1); - if (strchr(buffer, ' ') != NULL) - *(char *)(strchr(buffer, ' ')) = '\0'; - } - if (fclose(bpf)) - warnx("could not close %s", bootpfile); - return(1); -#else - return(0); /* ENOTSUP */ -#endif - } - /* skip to next entry */ - if ( match ) break; - pch = ch = getc(bpf); - while ( ! ( ch == '\n' && pch != '\\') && ch != EOF) { - pch = ch; ch = getc(bpf); - } - } - - /* if match is true we read the rest of the line to get the - info of the file */ - - if (match) { - fid_len = strlen(fileid); - while ( ! res && (fscanf(bpf,"%s", info)) > 0) { /* read a string */ - ch = getc(bpf); /* and a character */ - if ( *info != '#' ) { /* Comment ? */ - if (! strncmp(info, fileid, fid_len) && *(info + fid_len) == '=') { - where = info + fid_len + 1; - if ( isprint( *where )) { - strcpy(buffer, where); /* found file */ - res = 1; break; - } - } else { - while (isspace(ch) && ch != '\n') ch = getc(bpf); - /* read to end of line */ - if ( ch == '\n' ) { /* didn't find it */ - res = -1; break; /* but host is there */ - } - if ( ch == '\\' ) { /* more info */ - ch = getc(bpf); /* maybe on next line */ - if (ch == '\n') continue; /* read it in next loop */ - ungetc(ch, bpf); ungetc('\\',bpf); /* push the character(s) back */ - } else ungetc(ch, bpf); /* but who know what a `\` is */ - } /* needed for. */ - } else break; /* a commented rest-of-line */ - } - } - if (fclose(bpf)) { warnx("could not close %s", bootpfile); } - if ( res == -1) buffer[0] = '\0'; /* host found, file not */ - return(match); -} - -/* checkhost puts the hostname found in the database file in - the hostname-variable and returns 1, if askname is a valid - name for a host in the database */ - -int -checkhost(askname, hostname, len) -char *askname; -char *hostname; -int len; -{ - int ch, pch; - FILE *bpf; - int res = 0; -#ifdef YP - static char *result; - int resultlen; - static char *yp_domain; -#endif - -/* struct hostent *cmp_he;*/ - - bpf = fopen(bootpfile, "r"); - if ( ! bpf ) - errx(1, "no %s", bootpfile); - - /* XXX there is no way in ISO C to specify the maximal length for a - conversion in a variable way */ - while ( fscanf(bpf, "%254s", hostname) > 0 ) { - if ( *hostname != '#' ) { /* comment */ - if ( ! strcmp(hostname, askname) ) { - /* return true for match of hostname */ - res = 1; - break; - } else { - /* check the alias list */ - he = NULL; - he = gethostbyname(hostname); - if (he && !strcmp(askname, he->h_name)) { - res = 1; - break; - } - } - } - if (*hostname == '+' ) { /* NIS */ -#ifdef YP - if (yp_get_default_domain(&yp_domain)) { - if (debug) warn("NIS"); - return(0); - } - if (!yp_match(yp_domain, "bootparams", askname, strlen(askname), - &result, &resultlen)) { - /* return true for match of hostname */ - he = NULL; - he = gethostbyname(askname); - if (he && !strcmp(askname, he->h_name)) { - res = 1; - snprintf(hostname, len, "%s", he->h_name); - } - } - if (fclose(bpf)) - warnx("could not close %s", bootpfile); - return(res); -#else - return(0); /* ENOTSUP */ -#endif - } - /* skip to next entry */ - pch = ch = getc(bpf); - while ( ! ( ch == '\n' && pch != '\\') && ch != EOF) { - pch = ch; ch = getc(bpf); - } - } - if (fclose(bpf)) { warnx("could not close %s", bootpfile); } - return(res); -} diff --git a/usr.sbin/bootparamd/bootparamd/bootparams.5 b/usr.sbin/bootparamd/bootparamd/bootparams.5 deleted file mode 100644 index c7c6785..0000000 --- a/usr.sbin/bootparamd/bootparamd/bootparams.5 +++ /dev/null @@ -1,86 +0,0 @@ -.\" -.\" Copyright (c) 1994 Gordon W. Ross -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" from: Id: bootparams.5,v 1.2 1994/10/03 19:26:13 gwr Exp -.\" $FreeBSD$ -.\" -.Dd October 2, 1994 -.Dt BOOTPARAMS 5 -.Os -.Sh NAME -.Nm bootparams -.Nd boot parameter database -.Sh SYNOPSIS -.Nm /etc/bootparams -.Sh DESCRIPTION -The -.Nm -file specifies the boot parameters that -.Xr diskless 8 -clients may request when booting over the network. -Each client supported by this server must have an entry in the -.Nm -file containing the pathnames for its -.Dq root -and (optionally) -.Dq swap -areas. -.Pp -Each line in the file -(other than comment lines that begin with a -.Ql # ) -specifies the client name followed by the pathnames that -the client may request by their logical names. -The components of the line are delimited with blank or tab, -and may be continued onto multiple lines with a backslash. -.Pp -For example: -.Bd -literal -offset indent -dummy root=host:/export/dummy/root \\ - swap=host:/export/dummy/swap \\ - dump=host:/export/dummy/swap -.Ed -.Pp -When the client named -.Dq dummy -requests the pathname for its logical -.Dq root -it will be given the pathname -.Dq Pa host:/export/dummy/root -as the response to its -.Tn RPC -request. -The -.Dq host: -component must be supplied. -.Sh FILES -.Bl -tag -width /etc/bootparams -compact -.It Pa /etc/bootparams -default configuration file -.El -.Sh SEE ALSO -.Xr bootparamd 8 , -.Xr diskless 8 diff --git a/usr.sbin/bootparamd/bootparamd/main.c b/usr.sbin/bootparamd/bootparamd/main.c deleted file mode 100644 index 8c93c1f..0000000 --- a/usr.sbin/bootparamd/bootparamd/main.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - -This code is not copyright, and is placed in the public domain. Feel free to -use and modify. Please send modifications and/or suggestions + bug fixes to - - Klas Heggemann - -*/ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "bootparam_prot.h" - -int debug = 0; -int dolog = 0; -in_addr_t route_addr = -1; -struct sockaddr_in my_addr; -char *bootpfile = "/etc/bootparams"; - -extern void bootparamprog_1(); -static void usage(void); - -int -main(argc, argv) -int argc; -char **argv; -{ - SVCXPRT *transp; - struct hostent *he; - struct stat buf; - int c; - - while ((c = getopt(argc, argv,"dsr:f:")) != -1) - switch (c) { - case 'd': - debug = 1; - break; - case 'r': - if (isdigit((unsigned char)*optarg)) { - route_addr = inet_addr(optarg); - break; - } else { - he = gethostbyname(optarg); - if (he) { - bcopy(he->h_addr, (char *)&route_addr, sizeof(route_addr)); - break; - } else { - errx(1, "no such host %s", optarg); - } - } - case 'f': - bootpfile = optarg; - break; - case 's': - dolog = 1; -#ifndef LOG_DAEMON - openlog("bootparamd", 0 , 0); -#else - openlog("bootparamd", 0 , LOG_DAEMON); - setlogmask(LOG_UPTO(LOG_NOTICE)); -#endif - break; - default: - usage(); - } - - if ( stat(bootpfile, &buf ) ) - err(1, "%s", bootpfile); - - if (route_addr == -1) { - get_myaddress(&my_addr); - bcopy(&my_addr.sin_addr.s_addr, &route_addr, sizeof (route_addr)); - } - - if (!debug) { - if (daemon(0,0)) - err(1, "fork"); - } - - - (void)pmap_unset(BOOTPARAMPROG, BOOTPARAMVERS); - - transp = svcudp_create(RPC_ANYSOCK); - if (transp == NULL) - errx(1, "cannot create udp service"); - if (!svc_register(transp, BOOTPARAMPROG, BOOTPARAMVERS, bootparamprog_1, IPPROTO_UDP)) - errx(1, "unable to register (BOOTPARAMPROG, BOOTPARAMVERS, udp)"); - - svc_run(); - errx(1, "svc_run returned"); -} - -static void -usage() -{ - fprintf(stderr, - "usage: bootparamd [-d] [-s] [-r router] [-f bootparmsfile]\n"); - exit(1); -} diff --git a/usr.sbin/bootparamd/callbootd/Makefile b/usr.sbin/bootparamd/callbootd/Makefile deleted file mode 100644 index 5a08d60..0000000 --- a/usr.sbin/bootparamd/callbootd/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# from: @(#)Makefile 5.8 (Berkeley) 7/28/90 -# $FreeBSD$ - -PROG= callbootd -NO_MAN= -SRCS= callbootd.c ${GENSRCS} -GENSRCS=bootparam_prot.h bootparam_prot_clnt.c bootparam_prot_xdr.c - -CFLAGS+= -I. - -CLEANFILES= ${GENSRCS} - -RPCSRC= ${DESTDIR}/usr/include/rpcsvc/bootparam_prot.x - -bootparam_prot_clnt.c: ${RPCSRC} - rpcgen -C -l -o ${.TARGET} ${RPCSRC} - -bootparam_prot_xdr.c: ${RPCSRC} - rpcgen -C -c -o ${.TARGET} ${RPCSRC} - -bootparam_prot.h: ${RPCSRC} - rpcgen -C -h -o ${.TARGET} ${RPCSRC} - -.include diff --git a/usr.sbin/bootparamd/callbootd/callbootd.c b/usr.sbin/bootparamd/callbootd/callbootd.c deleted file mode 100644 index 4ec16df..0000000 --- a/usr.sbin/bootparamd/callbootd/callbootd.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - -This code is not copyright, and is placed in the public domain. Feel free to -use and modify. Please send modifications and/or suggestions + bug fixes to - - Klas Heggemann - -*/ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include "bootparam_prot.h" -#include -#include -#include -#include -#include -#include -#include -#include - - -/* #define bp_address_u bp_address */ -#include -#include - -int broadcast; - -char cln[MAX_MACHINE_NAME+1]; -char dmn[MAX_MACHINE_NAME+1]; -char path[MAX_PATH_LEN+1]; -extern char *inet_ntoa(); -static void usage(void); -int printgetfile(bp_getfile_res *); -int printwhoami(bp_whoami_res *); - -bool_t -eachres_whoami(resultp, raddr) -bp_whoami_res *resultp; -struct sockaddr_in *raddr; -{ - struct hostent *he; - - he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET); - printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr)); - printwhoami(resultp); - printf("\n"); - return(0); -} - -bool_t -eachres_getfile(resultp, raddr) -bp_getfile_res *resultp; -struct sockaddr_in *raddr; -{ - struct hostent *he; - - he = gethostbyaddr((char *)&raddr->sin_addr.s_addr,4,AF_INET); - printf("%s answered:\n", he ? he->h_name : inet_ntoa(raddr->sin_addr)); - printgetfile(resultp); - printf("\n"); - return(0); -} - - -int -main(argc, argv) -int argc; -char **argv; -{ - char *server; - - bp_whoami_arg whoami_arg; - bp_whoami_res *whoami_res, stat_whoami_res; - bp_getfile_arg getfile_arg; - bp_getfile_res *getfile_res, stat_getfile_res; - - - long the_inet_addr; - CLIENT *clnt; - enum clnt_stat clnt_stat; - - stat_whoami_res.client_name = cln; - stat_whoami_res.domain_name = dmn; - - stat_getfile_res.server_name = cln; - stat_getfile_res.server_path = path; - - if (argc < 3) - usage(); - - server = argv[1]; - if ( ! strcmp(server , "all") ) broadcast = 1; - - if ( ! broadcast ) { - clnt = clnt_create(server,BOOTPARAMPROG, BOOTPARAMVERS, "udp"); - if ( clnt == NULL ) - errx(1, "could not contact bootparam server on host %s", server); - } - - switch (argc) { - case 3: - whoami_arg.client_address.address_type = IP_ADDR_TYPE; - the_inet_addr = inet_addr(argv[2]); - if ( the_inet_addr == -1) - errx(2, "bogus addr %s", argv[2]); - bcopy(&the_inet_addr,&whoami_arg.client_address.bp_address_u.ip_addr,4); - - if (! broadcast ) { - whoami_res = bootparamproc_whoami_1(&whoami_arg, clnt); - printf("Whoami returning:\n"); - if (printwhoami(whoami_res)) { - errx(1, "bad answer returned from server %s", server); - } else - exit(0); - } else { - clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS, - BOOTPARAMPROC_WHOAMI, - (xdrproc_t)xdr_bp_whoami_arg, - (char *)&whoami_arg, - (xdrproc_t)xdr_bp_whoami_res, - (char *)&stat_whoami_res, - (resultproc_t)eachres_whoami); - exit(0); - } - - case 4: - - getfile_arg.client_name = argv[2]; - getfile_arg.file_id = argv[3]; - - if (! broadcast ) { - getfile_res = bootparamproc_getfile_1(&getfile_arg,clnt); - printf("getfile returning:\n"); - if (printgetfile(getfile_res)) { - errx(1, "bad answer returned from server %s", server); - } else - exit(0); - } else { - clnt_stat=clnt_broadcast(BOOTPARAMPROG, BOOTPARAMVERS, - BOOTPARAMPROC_GETFILE, - (xdrproc_t)xdr_bp_getfile_arg, - (char *)&getfile_arg, - (xdrproc_t)xdr_bp_getfile_res, - (char *)&stat_getfile_res, - (resultproc_t)eachres_getfile); - exit(0); - } - - default: - - usage(); - } - -} - - -static void -usage() -{ - fprintf(stderr, - "usage: callbootd server procnum (IP-addr | host fileid)\n"); - exit(1); -} - -int -printwhoami(res) -bp_whoami_res *res; -{ - if ( res) { - printf("client_name:\t%s\ndomain_name:\t%s\n", - res->client_name, res->domain_name); - printf("router:\t%d.%d.%d.%d\n", - 255 & res->router_address.bp_address_u.ip_addr.net, - 255 & res->router_address.bp_address_u.ip_addr.host, - 255 & res->router_address.bp_address_u.ip_addr.lh, - 255 & res->router_address.bp_address_u.ip_addr.impno); - return(0); - } else { - warnx("null answer!!!"); - return(1); - } - } - - - - -int -printgetfile(res) -bp_getfile_res *res; -{ - if (res) { - printf("server_name:\t%s\nserver_address:\t%s\npath:\t%s\n", - res->server_name, - inet_ntoa(*(struct in_addr *)&res->server_address.bp_address_u.ip_addr), - res->server_path); - return(0); - } else { - warnx("null answer!!!"); - return(1); - } - } diff --git a/usr.sbin/bsnmpd/Makefile b/usr.sbin/bsnmpd/Makefile deleted file mode 100644 index c948108..0000000 --- a/usr.sbin/bsnmpd/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -SUBDIR= gensnmptree \ - bsnmpd \ - modules - -.include diff --git a/usr.sbin/bsnmpd/Makefile.inc b/usr.sbin/bsnmpd/Makefile.inc deleted file mode 100644 index 265f86d..0000000 --- a/usr.sbin/bsnmpd/Makefile.inc +++ /dev/null @@ -1,3 +0,0 @@ -# $FreeBSD$ - -.include "../Makefile.inc" diff --git a/usr.sbin/bsnmpd/bsnmpd/Makefile b/usr.sbin/bsnmpd/bsnmpd/Makefile deleted file mode 100644 index e74f675..0000000 --- a/usr.sbin/bsnmpd/bsnmpd/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# $FreeBSD$ -# -# Author: Harti Brandt - -CONTRIB=${.CURDIR}/../../../contrib/bsnmp -.PATH: ${CONTRIB}/snmpd - -PROG= bsnmpd -SRCS= main.c action.c config.c export.c trap.c trans_udp.c trans_lsock.c -SRCS+= oid.h tree.c tree.h -XSYM= snmpMIB begemotSnmpdModuleTable begemotSnmpd begemotTrapSinkTable \ - sysUpTime snmpTrapOID coldStart authenticationFailure \ - begemotSnmpdTransUdp begemotSnmpdTransLsock begemotSnmpdLocalPortTable \ - freeBSDVersion -CLEANFILES= oid.h tree.c tree.h -MAN= bsnmpd.1 snmpmod.3 -NO_WERROR= - -FILESGROUPS= BMIBS DEFS - -BMIBS= FOKUS-MIB.txt BEGEMOT-MIB.txt BEGEMOT-SNMPD.txt -BMIBSDIR= ${SHAREDIR}/snmp/mibs -DEFS= tree.def -DEFSDIR= ${SHAREDIR}/snmp/defs - -CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -I. -DUSE_LIBBEGEMOT -CFLAGS+= -DUSE_TCPWRAPPERS -DQUADFMT='"llu"' -DQUADXFMT='"llx"' -CFLAGS+= -DHAVE_STDINT_H -DHAVE_INTTYPES_H -DHAVE_ERR_H -DHAVE_STRLCPY -DPADD= ${LIBBEGEMOT} ${LIBBSNMP} ${LIBWRAP} -LDADD= -lbegemot -lbsnmp -lwrap - -LDFLAGS= -export-dynamic - -oid.h: tree.def Makefile - gensnmptree -e ${XSYM} < ${.ALLSRC:M*.def} > ${.TARGET} - -.ORDER: tree.c tree.h -tree.c tree.h: tree.def - gensnmptree -l < ${.ALLSRC} - -MANFILTER= sed -e 's%@MODPATH@%${LIBDIR}/%g' \ - -e 's%@DEFPATH@%${DEFSDIR}/%g' \ - -e 's%@MIBSPATH@%${BMIBSDIR}/%g' - -.include diff --git a/usr.sbin/bsnmpd/gensnmptree/Makefile b/usr.sbin/bsnmpd/gensnmptree/Makefile deleted file mode 100644 index a92f4eb..0000000 --- a/usr.sbin/bsnmpd/gensnmptree/Makefile +++ /dev/null @@ -1,15 +0,0 @@ -# $FreeBSD$ -# -# Author: Harti Brandt - -CONTRIB=${.CURDIR}/../../../contrib/bsnmp -.PATH: ${CONTRIB}/gensnmptree - -PROG= gensnmptree -CFLAGS+= -I${CONTRIB}/lib -CFLAGS+= -DQUADFMT='"llu"' -DQUADXFMT='"llx"' -DHAVE_STDINT_H -CFLAGS+= -DHAVE_INTTYPES_H - -WARNS?= 5 - -.include diff --git a/usr.sbin/bsnmpd/modules/Makefile b/usr.sbin/bsnmpd/modules/Makefile deleted file mode 100644 index c2b7360..0000000 --- a/usr.sbin/bsnmpd/modules/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# $FreeBSD$ - -.include - -.PATH: ${.CURDIR}/../../../contrib/bsnmp/snmpd - -.if ${MK_ATM} != "no" -_snmp_atm= snmp_atm -.endif - -SUBDIR= ${_snmp_atm} \ - snmp_bridge \ - snmp_hostres \ - snmp_mibII \ - snmp_pf \ - snmp_wlan - -.if ${MK_NETGRAPH_SUPPORT} != "no" -SUBDIR+=snmp_netgraph -.endif - -INCS= snmpmod.h -INCSDIR= ${INCLUDEDIR}/bsnmp - -.include diff --git a/usr.sbin/bsnmpd/modules/Makefile.inc b/usr.sbin/bsnmpd/modules/Makefile.inc deleted file mode 100644 index b5dad56..0000000 --- a/usr.sbin/bsnmpd/modules/Makefile.inc +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD$ - -SHLIB_MAJOR= 6 - -MANFILTER= sed -e 's%@MODPATH@%${LIBDIR}/%g' \ - -e 's%@DEFPATH@%${DEFSDIR}/%g' \ - -e 's%@MIBSPATH@%${BMIBSDIR}/%g' - -.include "../Makefile.inc" diff --git a/usr.sbin/bsnmpd/modules/snmp_atm/BEGEMOT-ATM-FREEBSD-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_atm/BEGEMOT-ATM-FREEBSD-MIB.txt deleted file mode 100644 index 83c4e5c..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_atm/BEGEMOT-ATM-FREEBSD-MIB.txt +++ /dev/null @@ -1,99 +0,0 @@ --- --- Copyright (c) 2004 --- Hartmut Brandt. --- All rights reserved. --- --- Author: Hartmut Brandt --- --- Redistribution and use in source and binary forms, with or without --- modification, are permitted provided that the following conditions --- are met: --- 1. Redistributions of source code must retain the above copyright --- notice, this list of conditions and the following disclaimer. --- 2. Redistributions in binary form must reproduce the above copyright --- notice, this list of conditions and the following disclaimer in the --- documentation and/or other materials provided with the distribution. --- --- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND --- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE --- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE --- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE --- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL --- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS --- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) --- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT --- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY --- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF --- SUCH DAMAGE. --- --- $FreeBSD$ --- --- Private Begemot MIB for ATM interfaces on FreeBSD --- -BEGEMOT-ATM-FREEBSD-MIB DEFINITIONS ::= BEGIN - -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE - FROM SNMPv2-SMI - NgNodeIdOrZero - FROM BEGEMOT-NETGRAPH-MIB - begemotAtmSysGroup, begemotAtmIfEntry - FROM BEGEMOT-ATM-MIB; - -begemotAtmFreeBSDGroup MODULE-IDENTITY - LAST-UPDATED "200408060000Z" - ORGANIZATION "German Aerospace Centre" - CONTACT-INFO - " Hartmut Brandt - - Postal: German Aerospace Centre (DLR) - Institute of Communications and Navigation - 82234 Wessling - Germany - - Fax: +49 8153 28 2844 - - E-mail: harti@freebsd.org" - DESCRIPTION - "The FreeBSD specific Begemot MIB for ATM interfaces." - - ::= { begemotAtmSysGroup 1 } - --- Netgraph -begemotAtmNgGroup OBJECT IDENTIFIER ::= { begemotAtmFreeBSDGroup 1 } - --- --- Interfaces table --- -begemotAtmNgIfTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotAtmNgIfEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "This table contains an entry for each hardware ATM - interface. The table is indexed by the interface index." - ::= { begemotAtmNgGroup 1 } - -begemotAtmNgIfEntry OBJECT-TYPE - SYNTAX BegemotAtmNgIfEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "This is a table entry describing one ATM hardware interface." - AUGMENTS { begemotAtmIfEntry } - ::= { begemotAtmNgIfTable 1 } - -BegemotAtmNgIfEntry ::= SEQUENCE { - begemotAtmNgIfNodeId NgNodeIdOrZero -} - -begemotAtmNgIfNodeId OBJECT-TYPE - SYNTAX NgNodeIdOrZero - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The netgraph node id of the interface. If there is no - node corresponding to the interface, this is 0." - ::= { begemotAtmNgIfEntry 1 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_atm/Makefile b/usr.sbin/bsnmpd/modules/snmp_atm/Makefile deleted file mode 100644 index 4bba7cb..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_atm/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# $FreeBSD$ -# -# Author: Harti Brandt - -CONTRIB= ${.CURDIR}/../../../../contrib/ngatm -.PATH: ${CONTRIB}/snmp_atm - -MOD= atm -SRCS= snmp_atm.c atm_sys.c -XSYM= begemotAtm -MAN= snmp_atm.3 - -BMIBS= BEGEMOT-ATM.txt BEGEMOT-ATM-FREEBSD-MIB.txt -DEFS= ${MOD}_tree.def atm_freebsd.def -INCS= snmp_${MOD}.h - -EXTRAMIBDEFS= atm_freebsd.def - -CFLAGS+= -I${CONTRIB}/snmp_atm - -.include diff --git a/usr.sbin/bsnmpd/modules/snmp_atm/atm_freebsd.def b/usr.sbin/bsnmpd/modules/snmp_atm/atm_freebsd.def deleted file mode 100644 index 6cc61d0..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_atm/atm_freebsd.def +++ /dev/null @@ -1,56 +0,0 @@ -# -# Copyright (c) 2004 -# Hartmut Brandt. -# All rights reserved. -# -# Author: Hartmut Brandt -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ -# -# SNMP module for ATM hardware interfaces. -# -# $Begemot: libunimsg/snmp_atm/atm_tree.def,v 1.2 2004/08/05 07:14:22 brandt Exp $ -# -(1 internet - (4 private - (1 enterprises - (12325 fokus - (1 begemot - (101 begemotAtm - (1 begemotAtmObjects - (4 begemotAtmSysGroup - (1 begemotAtmFreeBSDGroup - (1 begemotAtmNgGroup - (1 begemotAtmNgIfTable - (1 begemotAtmNgIfEntry : INTEGER op_atmif_ng - (1 begemotAtmIfNodeId UNSIGNED32 GET) - )) - ) - ) - ) - ) - )) - ) - ) -)) diff --git a/usr.sbin/bsnmpd/modules/snmp_atm/atm_sys.c b/usr.sbin/bsnmpd/modules/snmp_atm/atm_sys.c deleted file mode 100644 index 525e805..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_atm/atm_sys.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (c) 2001-2002 - * Fraunhofer Institute for Open Communication Systems (FhG Fokus). - * All rights reserved. - * Copyright (c) 2003-2004 - * Hartmut Brandt. - * All rights reserved. - * - * Author: Hartmut Brandt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - * - * SNMP module for ATM hardware interfaces - FreeBSD/Ng specific part. - */ - -#include "atm.h" -#include "atm_tree.h" -#include "atm_oid.h" - -#include -#include -#include - -#include - -#include -#include -#include - -static const struct hwinfo { - const char *device; - const char *vendor; -} hwinfo[] = { - ATM_DEVICE_NAMES -}; - -struct atmif_sys { - ng_ID_t atm_node; - void *regc; /* cookie registration */ -}; - -/* - * Find the interface for a given node - */ -struct atmif * -atm_node2if(u_int node) -{ - struct atmif_priv *aif; - - if (node != 0) - TAILQ_FOREACH(aif, &atmif_list, link) - if (aif->sys->atm_node == node) - return (&aif->pub); - return (NULL); -} - -u_int -atm_if2node(struct atmif *pub) -{ - struct atmif_priv *aif = (struct atmif_priv *)pub; - - return (aif->sys->atm_node); -} - -/* - * Destroy system dependend stuff. - */ -void -atmif_sys_destroy(struct atmif_priv *aif) -{ - - ng_unregister_cookie(aif->sys->regc); - free(aif->sys); - free(aif->pub.mib); -} - -/* - * Handle a message from the ATM node - */ -static void -handle_atm_message(const struct ng_mesg *mesg, const char *path __unused, - ng_ID_t node, void *uarg) -{ - struct atmif_priv *aif = uarg; - enum atmif_carrier_state ost; - - switch (mesg->header.cmd) { - - case NGM_ATM_IF_CHANGE: - { - const struct ngm_atm_if_change *arg; - - ost = aif->pub.carrier; - if (mesg->header.arglen != sizeof(*arg)) { - syslog(LOG_ERR, "ATM_IF_CHANGE: wrong size"); - atmif_check_carrier(aif); - return; - } - arg = (const struct ngm_atm_if_change *) - (const void *)mesg->data; - - if (arg->carrier) - aif->pub.carrier = ATMIF_CARRIER_ON; - else - aif->pub.carrier = ATMIF_CARRIER_OFF; - - if (ost != aif->pub.carrier) - atmif_send_notification(aif, ATMIF_NOTIFY_CARRIER, - (uintptr_t)ost); - return; - } - - case NGM_ATM_VCC_CHANGE: - { - const struct ngm_atm_vcc_change *arg; - - if (mesg->header.arglen != sizeof(*arg)) { - syslog(LOG_ERR, "ATM_VCC_CHANGE: wrong size"); - return; - } - arg = (const struct ngm_atm_vcc_change *) - (const void *)mesg->data; - atmif_send_notification(aif, ATMIF_NOTIFY_VCC, - (uintptr_t)(((arg->vpi & 0xff) << 24) | - ((arg->vci & 0xffff) << 8) | (arg->state & 1))); - return; - } - } - syslog(LOG_WARNING, "spurious message %u from node [%x]", - mesg->header.cmd, node); -} - -/* - * Attach to an ATM interface - */ -int -atmif_sys_attach_if(struct atmif_priv *aif) -{ - struct ng_mesg *resp, *resp1; - struct namelist *list; - u_int i; - - if ((aif->sys = malloc(sizeof(*aif->sys))) == NULL) { - syslog(LOG_CRIT, "out of memory"); - return (-1); - } - memset(aif->sys, 0, sizeof(*aif->sys)); - - if ((aif->pub.mib = malloc(sizeof(*aif->pub.mib))) == NULL) { - free(aif->sys); - syslog(LOG_CRIT, "out of memory"); - return (-1); - } - - atmif_sys_fill_mib(aif); - - /* - * Get ATM node Id. Must do it the hard way by scanning all nodes - * because the name may be wrong. - */ - if ((resp = ng_dialog_id(snmp_node, NGM_GENERIC_COOKIE, NGM_LISTNODES, - NULL, 0)) == NULL) { - syslog(LOG_ERR, "cannot fetch node list: %m"); - free(aif->sys); - return (-1); - } - list = (struct namelist *)(void *)resp->data; - - for (i = 0; i < list->numnames; i++) { - if (strcmp(list->nodeinfo[i].type, NG_ATM_NODE_TYPE) != 0) - continue; - if ((resp1 = ng_dialog_id(list->nodeinfo[i].id, - NGM_ATM_COOKIE, NGM_ATM_GET_IFNAME, NULL, 0)) == NULL) - continue; - if (strcmp(resp1->data, aif->pub.ifp->name) == 0) { - free(resp1); - break; - } - free(resp1); - } - if (i == list->numnames) - aif->sys->atm_node = 0; - else - aif->sys->atm_node = list->nodeinfo[i].id; - - free(resp); - - if ((aif->sys->regc = ng_register_cookie(module, NGM_ATM_COOKIE, - aif->sys->atm_node, handle_atm_message, aif)) == NULL) { - syslog(LOG_ERR, "cannot register cookie: %m"); - free(aif->sys); - return (-1); - } - return (0); -} - -/* - * Table of all ATM interfaces - Ng part - */ -int -op_atmif_ng(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int vindex __unused, enum snmp_op op) -{ - struct atmif_priv *aif; - int err; - - if ((err = atmif_get_aif(value, sub, op, &aif)) != SNMP_ERR_NOERROR) - return (err); - - if (op == SNMP_OP_SET) { - switch (value->var.subs[sub - 1]) { - - default: - return (SNMP_ERR_NOT_WRITEABLE); - } - } - - switch (value->var.subs[sub - 1]) { - - case LEAF_begemotAtmIfNodeId: - value->v.uint32 = aif->sys->atm_node; - return (SNMP_ERR_NOERROR); - } - abort(); -} - -/* - * Get vendor string - */ -int -atm_sys_get_hw_vendor(struct atmif_priv *aif, struct snmp_value *value) -{ - - if (aif->pub.mib->device >= sizeof(hwinfo) / sizeof(hwinfo[0])) - return (string_get(value, "unknown", -1)); - return (string_get(value, hwinfo[aif->pub.mib->device].vendor, -1)); -} - -/* - * Get device string - */ -int -atm_sys_get_hw_device(struct atmif_priv *aif, struct snmp_value *value) -{ - - if (aif->pub.mib->device >= sizeof(hwinfo) / sizeof(hwinfo[0])) - return (string_get(value, "unknown", -1)); - return (string_get(value, hwinfo[aif->pub.mib->device].device, -1)); -} - -/* - * Extract the ATM MIB from the interface's private MIB - */ -void -atmif_sys_fill_mib(struct atmif_priv *aif) -{ - struct ifatm_mib *mib; - - if (aif->pub.ifp->specmiblen != sizeof(struct ifatm_mib)) { - syslog(LOG_ERR, "atmif MIB has wrong size %zu", - aif->pub.ifp->specmiblen); - memset(aif->pub.mib, 0, sizeof(*aif->pub.mib)); - aif->pub.mib->version = 0; - return; - } - mib = (struct ifatm_mib *)aif->pub.ifp->specmib; - - aif->pub.mib->device = mib->device; - aif->pub.mib->serial = mib->serial; - aif->pub.mib->hw_version = mib->hw_version; - aif->pub.mib->sw_version = mib->sw_version; - aif->pub.mib->media = mib->media; - - memcpy(aif->pub.mib->esi, mib->esi, 6); - aif->pub.mib->pcr = mib->pcr; - aif->pub.mib->vpi_bits = mib->vpi_bits; - aif->pub.mib->vci_bits = mib->vci_bits; - aif->pub.mib->max_vpcs = mib->max_vpcs; - aif->pub.mib->max_vccs = mib->max_vccs; -} diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/BEGEMOT-BRIDGE-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_bridge/BEGEMOT-BRIDGE-MIB.txt deleted file mode 100644 index d55ea3c..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/BEGEMOT-BRIDGE-MIB.txt +++ /dev/null @@ -1,1166 +0,0 @@ --- --- Copyright (C) 2006 Shteryana Shopova --- All rights reserved. --- --- Redistribution and use in source and binary forms, with or without --- modification, are permitted provided that the following conditions --- are met: --- 1. Redistributions of source code must retain the above copyright --- notice, this list of conditions and the following disclaimer. --- 2. Redistributions in binary form must reproduce the above copyright --- notice, this list of conditions and the following disclaimer in the --- documentation and/or other materials provided with the distribution. --- --- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND --- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE --- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE --- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE --- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL --- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS --- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) --- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT --- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY --- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF --- SUCH DAMAGE. --- --- $FreeBSD$ --- - -BEGEMOT-BRIDGE-MIB DEFINITIONS ::= BEGIN - -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE, - Counter32, Integer32, TimeTicks, mib-2 - FROM SNMPv2-SMI - TEXTUAL-CONVENTION, MacAddress, TruthValue, RowStatus - FROM SNMPv2-TC - BridgeId, Timeout - FROM BRIDGE-MIB - InterfaceIndex FROM IF-MIB - begemot - FROM BEGEMOT-MIB; - -begemotBridge MODULE-IDENTITY - LAST-UPDATED "200708060000Z" - ORGANIZATION "Sofia University St. Kliment Ohridski" - CONTACT-INFO - " Shteryana Shopova - - Postal: Faculty of Mathematics and Informatics - 5 James Bourchier Blvd. - 1164 Sofia - Bulgaria - - Fax: +359 2 687 180 - - E-Mail: syrinx@FreeBSD.org" - DESCRIPTION - "The Begemot MIB for managing bridge interfaces." - REVISION "200708060000Z" - DESCRIPTION - "Third revision adds begemotBridgeBasePortPrivate - object." - REVISION "200611210000Z" - DESCRIPTION - "Second revision adds support for monitoring RSTP - specific variables." - REVISION "200607270000Z" - DESCRIPTION - "Initial revision." - ::= { begemot 205 } - --- ---------------------------------------------------------- -- -BridgeIfName ::= TEXTUAL-CONVENTION - DISPLAY-HINT "16a" - STATUS current - DESCRIPTION - "Name of a bridge interface." - SYNTAX OCTET STRING (SIZE(1..16)) - -BridgeIfNameOrEmpty ::= TEXTUAL-CONVENTION - DISPLAY-HINT "16a" - STATUS current - DESCRIPTION - "Name of a bridge interface." - SYNTAX OCTET STRING (SIZE(0..16)) - -BridgePortId ::= TEXTUAL-CONVENTION - DISPLAY-HINT "1x.1x" - STATUS current - DESCRIPTION - "A port identifier that contains a bridge port's STP priority - in the first octet and the port number in the second octet." - SYNTAX OCTET STRING (SIZE(2)) - --- ---------------------------------------------------------- -- --- subtrees in the Begemot Bridge MIB --- ---------------------------------------------------------- -- -begemotBridgeNotifications OBJECT IDENTIFIER ::= { begemotBridge 0 } - -begemotBridgeBase OBJECT IDENTIFIER ::= { begemotBridge 1 } - -begemotBridgeStp OBJECT IDENTIFIER ::= { begemotBridge 2 } - -begemotBridgeTp OBJECT IDENTIFIER ::= { begemotBridge 3 } - -begemotBridgePf OBJECT IDENTIFIER ::= { begemotBridge 4 } - -begemotBridgeConfigObjects OBJECT IDENTIFIER ::= { begemotBridge 5 } - --- ---------------------------------------------------------- -- --- the base Bridge interface table --- ---------------------------------------------------------- -- - -begemotBridgeBaseTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeBaseEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains generic information for each - bridge interface on the managed device." - ::= { begemotBridgeBase 1 } - -begemotBridgeBaseEntry OBJECT-TYPE - SYNTAX BegemotBridgeBaseEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of information for the bridge interfaces on - the managed device." - INDEX { begemotBridgeBaseName } - ::= { begemotBridgeBaseTable 1 } - -BegemotBridgeBaseEntry ::= SEQUENCE { - begemotBridgeBaseName BridgeIfName, - begemotBridgeBaseAddress MacAddress, - begemotBridgeBaseNumPorts Integer32, - begemotBridgeBaseType INTEGER, - begemotBridgeBaseStatus RowStatus -} - -begemotBridgeBaseName OBJECT-TYPE - SYNTAX BridgeIfName - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The name of the bridge interface for which this - entry contains management information." - ::= { begemotBridgeBaseEntry 1 } - -begemotBridgeBaseAddress OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The MAC address of the bridge interface." - ::= { begemotBridgeBaseEntry 2 } - -begemotBridgeBaseNumPorts OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of ports, members of this bridge." - ::= { begemotBridgeBaseEntry 3 } - -begemotBridgeBaseType OBJECT-TYPE - SYNTAX INTEGER { - unknown(1), - transparent-only(2), - sourceroute-only(3), - srt(4) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Indicates what type of bridging this bridge can - perform." - ::= { begemotBridgeBaseEntry 4 } - -begemotBridgeBaseStatus OBJECT-TYPE - SYNTAX RowStatus - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "Used to create/destroy bridge interfaces on the - managed device." - ::= { begemotBridgeBaseEntry 5 } - --- ---------------------------------------------------------- -- --- the base Bridge ports table --- ---------------------------------------------------------- -- - -begemotBridgeBasePortTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeBasePortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table containing generic information about ports, - members of each bridge interface." - ::= { begemotBridgeBase 2 } - -begemotBridgeBasePortEntry OBJECT-TYPE - SYNTAX BegemotBridgeBasePortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of information about a specific port, member of - a bridge interface." - INDEX { begemotBridgeBaseName, begemotBridgeBasePortIfIndex } - ::= { begemotBridgeBasePortTable 1 } - -BegemotBridgeBasePortEntry ::= SEQUENCE { - begemotBridgeBasePort Integer32, - begemotBridgeBasePortIfIndex InterfaceIndex, - begemotBridgeBaseSpanEnabled INTEGER, - begemotBridgeBasePortDelayExceededDiscards Counter32, - begemotBridgeBasePortMtuExceededDiscards Counter32, - begemotBridgeBasePortStatus RowStatus, - begemotBridgeBasePortPrivate TruthValue -} - -begemotBridgeBasePort OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The system interface index of the interface corresponding - to this port." - ::= { begemotBridgeBasePortEntry 1 } - -begemotBridgeBasePortIfIndex OBJECT-TYPE - SYNTAX InterfaceIndex - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The value of the instance of the ifIndex object, - defined in IF-MIB, for the interface corresponding - to this port." - ::= { begemotBridgeBasePortEntry 2 } - -begemotBridgeBaseSpanEnabled OBJECT-TYPE - SYNTAX INTEGER { - enabled(1), - disabled(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this objects reflects whether the port - is a span port on the specified bridge interface." - ::= { begemotBridgeBasePortEntry 3 } - -begemotBridgeBasePortDelayExceededDiscards OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames discarded by this port due - to excessive transit delay through the bridge." - ::= { begemotBridgeBasePortEntry 4 } - -begemotBridgeBasePortMtuExceededDiscards OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames discarded by this port due - to an excessive size." - ::= { begemotBridgeBasePortEntry 5 } - -begemotBridgeBasePortStatus OBJECT-TYPE - SYNTAX RowStatus - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "Used to control addition of member ports to or - removal of member ports from a specified bridge." - ::= { begemotBridgeBasePortEntry 6 } - -begemotBridgeBasePortPrivate OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this objects reflects whether the port - has a PRIVATE flag set. A port with this flags set - can only communicate with ports not having the - PRIVATE flag set." - ::= { begemotBridgeBasePortEntry 7 } - --- ---------------------------------------------------------- -- --- the Bridge interface STP table --- ---------------------------------------------------------- -- - -begemotBridgeStpTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeStpEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains Spanning Tree Protocol information - for each bridge interface on the managed device." - ::= { begemotBridgeStp 1 } - -begemotBridgeStpEntry OBJECT-TYPE - SYNTAX BegemotBridgeStpEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of information about the Spanning Tree Protocol - operation on a bridge interface." - AUGMENTS { begemotBridgeBaseEntry } - ::= { begemotBridgeStpTable 1 } - -BegemotBridgeStpEntry ::= SEQUENCE { - begemotBridgeStpProtocolSpecification INTEGER, - begemotBridgeStpPriority Integer32, - begemotBridgeStpTimeSinceTopologyChange TimeTicks, - begemotBridgeStpTopChanges Counter32, - begemotBridgeStpDesignatedRoot BridgeId, - begemotBridgeStpRootCost Integer32, - begemotBridgeStpRootPort Integer32, - begemotBridgeStpMaxAge Timeout, - begemotBridgeStpHelloTime Timeout, - begemotBridgeStpHoldTime Integer32, - begemotBridgeStpForwardDelay Timeout, - begemotBridgeStpBridgeMaxAge Timeout, - begemotBridgeStpBridgeHelloTime Timeout, - begemotBridgeStpBridgeForwardDelay Timeout, - begemotBridgeStpVersion INTEGER, - begemotBridgeStpTxHoldCount Integer32 -} - -begemotBridgeStpProtocolSpecification OBJECT-TYPE - SYNTAX INTEGER { - unknown(1), - decLb100(2), - ieee8021d(3) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The Spanning Tree Protocol version being run on the - bridge interface. The value 'decLb100(2)' indicates the - DEC LANbridge 100 Spanning Tree protocol, 'ieee8021d(3)' - indicates the bridge is running IEEE 802.1D STP - implementation." - ::= { begemotBridgeStpEntry 1 } - -begemotBridgeStpPriority OBJECT-TYPE - SYNTAX Integer32 (0..65535) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The priority value of the bridge interface forming the - first two octets of the bridge identifier. Acceptable - values are 0-61440, in steps of 4096." - ::= { begemotBridgeStpEntry 2 } - -begemotBridgeStpTimeSinceTopologyChange OBJECT-TYPE - SYNTAX TimeTicks - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The time (in hundreds of a second) since a topology change - was last detected by this bridge." - ::= { begemotBridgeStpEntry 3 } - -begemotBridgeStpTopChanges OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times a topology change was detected by the - bridge interface since the management entity was initialized - or reset." - ::= { begemotBridgeStpEntry 4 } - -begemotBridgeStpDesignatedRoot OBJECT-TYPE - SYNTAX BridgeId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The bridge identifier of the root of the spanning tree as - calculated by the Spanning Tree Protocol." - ::= { begemotBridgeStpEntry 5 } - -begemotBridgeStpRootCost OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The cost of the path from this bridge to the root bridge." - ::= { begemotBridgeStpEntry 6 } - -begemotBridgeStpRootPort OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The port number of the port that offers the lowest - cost path from this bridge to the root bridge of - the spanning tree. If this bridge is the root bridge, - this object shall have a value of zero." - ::= { begemotBridgeStpEntry 7 } - -begemotBridgeStpMaxAge OBJECT-TYPE - SYNTAX Timeout - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The maximum age of Spanning Tree Protocol information - received from the network on any port, before that - information is discarded. This is the actual value that - the bridge is currently using." - ::= { begemotBridgeStpEntry 8 } - -begemotBridgeStpHelloTime OBJECT-TYPE - SYNTAX Timeout - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The amount of time between transmission of - Configuration BPDUs by this bridge on any port, - when it is the root of the spanning tree or is - trying to become so. This is the actual value that - this bridge is currently using." - ::= { begemotBridgeStpEntry 9 } - -begemotBridgeStpHoldTime OBJECT-TYPE - SYNTAX Integer32 - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "This time value determines the interval length - during which no more than two Configuration BPDUs - shall be transmitted by this node, in units of - hundredths of a second." - ::= { begemotBridgeStpEntry 10 } - -begemotBridgeStpForwardDelay OBJECT-TYPE - SYNTAX Timeout - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "This value, measured in units of hundredths of a second - determines how long a port will stay consecutively in the - Listening and Learning states before transitioning to - Forwarding state. - This is the actual value currently used by the bridge - as opposed to begemotBridgeStpBridgeForwardDelay, which - is the value this and all bridges participating in the - spanning tree were to use, if this was the root bridge." - ::= { begemotBridgeStpEntry 11 } - -begemotBridgeStpBridgeMaxAge OBJECT-TYPE - SYNTAX Timeout (600..4000) - UNITS "centi-seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value that all bridges participating in the - spanning tree would use for MaxAge if this bridge - was the root of the spanning tree." - ::= { begemotBridgeStpEntry 12 } - -begemotBridgeStpBridgeHelloTime OBJECT-TYPE - SYNTAX Timeout (100..1000) - UNITS "centi-seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value that all bridges participating in the - spanning tree would use for HelloTime if this - bridge was the root of the spanning tree." - ::= { begemotBridgeStpEntry 13 } - -begemotBridgeStpBridgeForwardDelay OBJECT-TYPE - SYNTAX Timeout (400..3000) - UNITS "centi-seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value that all bridges participating in the - spanning tree would use for ForwardDelay if this - bridge was the root of the spanning tree." - ::= { begemotBridgeStpEntry 14 } - -begemotBridgeStpVersion OBJECT-TYPE - SYNTAX INTEGER { - stpCompatible(0), - rstp(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The version of Spanning Tree Protocol the bridge is - currently running. The value 'stpCompatible(0)' - indicates the Spanning Tree Protocol specified in - IEEE 802.1D-1998 and 'rstp(2)' indicates the Rapid - Spanning Tree Protocol specified in IEEE 802.1w and - clause 17 of 802.1D-2004. The values are directly from - the IEEE standard. New values may be defined as future - versions of the protocol become available. - - The value of this object MUST be retained across - reinitializations of the management system." - DEFVAL { rstp } - ::= { begemotBridgeStpEntry 15 } - -begemotBridgeStpTxHoldCount OBJECT-TYPE - SYNTAX Integer32 (1..10) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value used by the Port Transmit state machine to limit - the maximum transmission rate of BPDUs on the bridge interface. - - The value of this object MUST be retained across - reinitializations of the management system." - DEFVAL { 3 } - ::= { begemotBridgeStpEntry 16 } - --- ---------------------------------------------------------- -- --- the Bridge STP ports table --- ---------------------------------------------------------- -- - -begemotBridgeStpPortTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeStpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table containing Spanning Tree Protocol information - about the members of each bridge interface." - ::= { begemotBridgeStp 2 } - -begemotBridgeStpPortEntry OBJECT-TYPE - SYNTAX BegemotBridgeStpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of Spanning Tree Protocol information about - a specific member of a bridge interface." - INDEX { begemotBridgeBaseName, begemotBridgeBasePortIfIndex } - ::= { begemotBridgeStpPortTable 1 } - -BegemotBridgeStpPortEntry ::= SEQUENCE { - begemotBridgeStpPort Integer32, - begemotBridgeStpPortPriority Integer32, - begemotBridgeStpPortState INTEGER, - begemotBridgeStpPortEnable INTEGER, - begemotBridgeStpPortPathCost Integer32, - begemotBridgeStpPortDesignatedRoot BridgeId, - begemotBridgeStpPortDesignatedCost Integer32, - begemotBridgeStpPortDesignatedBridge BridgeId, - begemotBridgeStpPortDesignatedPort BridgePortId, - begemotBridgeStpPortForwardTransitions Counter32 -} - -begemotBridgeStpPort OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The system interface index of the interface corresponding - to this port, for which the management entity has Spanning - Tree Protocol information." - ::= { begemotBridgeStpPortEntry 1 } - -begemotBridgeStpPortPriority OBJECT-TYPE - SYNTAX Integer32 (0..255) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The STP priority of this port that is contained in the first - octet of its Port Identifier. The second octet contains the - value of begemotBridgeStpPort." - ::= { begemotBridgeStpPortEntry 2 } - -begemotBridgeStpPortState OBJECT-TYPE - SYNTAX INTEGER { - disabled(1), - blocking(2), - listening(3), - learning(4), - forwarding(5), - broken(6) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The current state of the port as defined by the operation - of the Spanning Tree Protocol. If the Spanning Tree Protocol - is administratively disabled on the port, this object shall - have value disabled(1). A value of broken(6) does not correspond - to any legal state of a port, and if present should indicate - error in the operation of either the Spanning Tree Protocol - implementation running on the device or the management entity." - ::= { begemotBridgeStpPortEntry 3 } - -begemotBridgeStpPortEnable OBJECT-TYPE - SYNTAX INTEGER { - enabled(1), - disabled(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The administrative Spanning Tree Protocol state of the - port - value of enabled(1) indicates that the port is - participating in the Spanning Tree Protocol operation." - ::= { begemotBridgeStpPortEntry 4 } - -begemotBridgeStpPortPathCost OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The contribution of the path through this port, when the port - is the Root Port, to the total cost of the path to the root - bridge for this bridge." - ::= { begemotBridgeStpPortEntry 5 } - -begemotBridgeStpPortDesignatedRoot OBJECT-TYPE - SYNTAX BridgeId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The unique Bridge Identifier of the bridge recorded as the - root in the Root Identifier parameter of Configuration BPDUs - transmitted by the Designated Bridge for the LAN to which - the port is attached." - ::= { begemotBridgeStpPortEntry 6 } - -begemotBridgeStpPortDesignatedCost OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "For a Designated port, the path cost (equal to the Root - Path Cost of the bridge) offered to the LAN to which the - port is attached otherwise the cost of the path to the Root - offered by the Designated Port on the LAN to which this - Port is attached." - ::= { begemotBridgeStpPortEntry 7 } - -begemotBridgeStpPortDesignatedBridge OBJECT-TYPE - SYNTAX BridgeId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The unique Bridge Identifier of the bridge to which the - port belongs, in the case when the port is a designated - port, otherwise the bridge believed to be the Designated - Bridge for the LAN to which this port is attached." - ::= { begemotBridgeStpPortEntry 8 } - -begemotBridgeStpPortDesignatedPort OBJECT-TYPE - SYNTAX BridgePortId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The Port Identifier of the Bridge port, on the Designated - Bridge, through which the Designated Bridge transmits the - Configuration Message information stored by this port." - ::= { begemotBridgeStpPortEntry 9 } - -begemotBridgeStpPortForwardTransitions OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times this port has transitioned - from the Learning state to the Forwarding state." - ::= { begemotBridgeStpPortEntry 10 } - --- ---------------------------------------------------------- -- --- the Bridge STP extended ports table --- ---------------------------------------------------------- -- - -begemotBridgeStpExtPortTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeStpExtPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains port-specific Rapid Spanning Tree - information for the bridge interface members." - ::= { begemotBridgeStp 3 } - -begemotBridgeStpExtPortEntry OBJECT-TYPE - SYNTAX BegemotBridgeStpExtPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of Rapid Spanning Tree information maintained by - each bridge interface member." - AUGMENTS { begemotBridgeStpPortEntry } - ::= { begemotBridgeStpExtPortTable 1 } - -BegemotBridgeStpExtPortEntry ::= SEQUENCE { - begemotBridgeStpPortProtocolMigration TruthValue, - begemotBridgeStpPortAdminEdgePort TruthValue, - begemotBridgeStpPortOperEdgePort TruthValue, - begemotBridgeStpPortAdminPointToPoint INTEGER, - begemotBridgeStpPortOperPointToPoint TruthValue, - begemotBridgeStpPortAdminPathCost Integer32 -} - -begemotBridgeStpPortProtocolMigration OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "When operating in RSTP (version 2) mode, writing true(1) - to this object forces this port to transmit RSTP BPDUs. - Any other operation on this object has no effect and - it always returns false(2) when read." - ::= { begemotBridgeStpExtPortEntry 1 } - -begemotBridgeStpPortAdminEdgePort OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The administrative value of the Edge Port parameter. A - value of true(1) indicates that this port should be - assumed as an edge-port, and a value of false(2) indicates - that this port should be assumed as a non-edge-port. - Setting this object will also cause the corresponding - instance of begemotBridgeStpPortOperEdgePort to change to - the same value. Note that even when this object's value - is true, the value of the corresponding instance of - begemotBridgeStpPortOperEdgePort can be false if a BPDU - has been received. - - The value of this object MUST be retained across - reinitializations of the management system." - ::= { begemotBridgeStpExtPortEntry 2 } - -begemotBridgeStpPortOperEdgePort OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operational value of the Edge Port parameter. The - object is initialized to the value of the corresponding - instance of begemotBridgeStpPortAdminEdgePort. When the - corresponding instance of begemotBridgeStpPortAdminEdgePort - is set, this object will be changed as well. This object - will also be changed to false on reception of a BPDU." - ::= { begemotBridgeStpExtPortEntry 3 } - -begemotBridgeStpPortAdminPointToPoint OBJECT-TYPE - SYNTAX INTEGER { - forceTrue(0), - forceFalse(1), - auto(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The administrative point-to-point status of the LAN segment - attached to this port, using the enumeration values of the - IEEE 802.1w clause. A value of forceTrue(0) indicates - that this port should always be treated as if it is - connected to a point-to-point link. A value of - forceFalse(1) indicates that this port should be treated as - having a shared media connection. A value of auto(2) - indicates that this port is considered to have a - point-to-point link if it is an Aggregator and all of its - members are aggregatable, or if the MAC entity - is configured for full duplex operation, either through - auto-negotiation or by management means. Manipulating this - object changes the underlying adminPortToPortMAC. - - The value of this object MUST be retained across - reinitializations of the management system." - ::= { begemotBridgeStpExtPortEntry 4 } - -begemotBridgeStpPortOperPointToPoint OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operational point-to-point status of the LAN segment - attached to this port. It indicates whether a port is - considered to have a point-to-point connection. - If adminPointToPointMAC is set to auto(2), then the value - of operPointToPointMAC is determined in accordance with the - specific procedures defined for the MAC entity concerned, - as defined in IEEE 802.1w, clause 6.5. The value is - determined dynamically; that is, it is re-evaluated whenever - the value of adminPointToPointMAC changes, and whenever - the specific procedures defined for the MAC entity evaluates - a change in its point-to-point status." - ::= { begemotBridgeStpExtPortEntry 5 } - -begemotBridgeStpPortAdminPathCost OBJECT-TYPE - SYNTAX Integer32 (0..200000000) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The administratively assigned value for the contribution - of this port to the path cost of paths toward the spanning - tree root. - - Writing a value of '0' assigns the automatically calculated - default Path Cost value to the port. If the default Path - Cost is being used, this object returns '0' when read. - - This complements the object begemotBridgeStpPortPathCost or - begemotBridgeStpPortPathCost32, which returns the operational - value of the path cost. - - The value of this object MUST be retained across - reinitializations of the management system." - ::= { begemotBridgeStpExtPortEntry 6 } - --- ---------------------------------------------------------- -- --- the Bridge interface Transparent bridging table --- ---------------------------------------------------------- -- - -begemotBridgeTpTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeTpEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information regarding transparent - bridging for each bridge interface on the managed device." - ::= { begemotBridgeTp 1 } - -begemotBridgeTpEntry OBJECT-TYPE - SYNTAX BegemotBridgeTpEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of information regarding transparent bridging - on a bridge interface." - AUGMENTS { begemotBridgeBaseEntry } - ::= { begemotBridgeTpTable 1 } - -BegemotBridgeTpEntry ::= SEQUENCE { - begemotBridgeTpLearnedEntryDiscards Counter32, - begemotBridgeTpAgingTime Integer32, - begemotBridgeTpMaxAddresses Integer32 -} - -begemotBridgeTpLearnedEntryDiscards OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The total number of Forwarding Database entries that would - have been learnt, but have been discarded due to Forwarding - Address Table having reached it's maximum entries limit." - ::= { begemotBridgeTpEntry 1 } - -begemotBridgeTpAgingTime OBJECT-TYPE - SYNTAX Integer32 (10..1000000) - UNITS "seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The timeout period in seconds before aging out - dynamically learnt forwarding entries." - ::= { begemotBridgeTpEntry 2 } - -begemotBridgeTpMaxAddresses OBJECT-TYPE - SYNTAX Integer32 (1..10000) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of entires that this bridge can - learn in it's Forwarding Address Table and use for - making forwarding decisions." - ::= { begemotBridgeTpEntry 3 } - --- ---------------------------------------------------------- -- --- The Forwarding Database for Transparent Bridging interfaces --- ---------------------------------------------------------- -- - -begemotBridgeTpFdbTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeTpFdbEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information about unicast entries - for which the bridge interfaces have forwarding and/or - filtering information. This information is used by the - bridge interfaces to make forwarding decisions." - ::= { begemotBridgeTp 2 } - -begemotBridgeTpFdbEntry OBJECT-TYPE - SYNTAX BegemotBridgeTpFdbEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Information about a specific unicast MAC address - for which the bridge interface has some forwarding - and/or filtering information." - INDEX { begemotBridgeBaseName, begemotBridgeTpFdbAddress } - ::= { begemotBridgeTpFdbTable 1 } - -BegemotBridgeTpFdbEntry ::= SEQUENCE { - begemotBridgeTpFdbAddress MacAddress, - begemotBridgeTpFdbPort Integer32, - begemotBridgeTpFdbStatus INTEGER -} - -begemotBridgeTpFdbAddress OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "A unicast MAC address for which the bridge has which the - bridge interface has some forwarding and/or filtering - information." - ::= { begemotBridgeTpFdbEntry 1 } - -begemotBridgeTpFdbPort OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The port number of the bridge port on which a frame having - a source address equal to the value of the corresponding - instance of begemotBridgeTpFdbAddress has been seen." - ::= { begemotBridgeTpFdbEntry 2 } - -begemotBridgeTpFdbStatus OBJECT-TYPE - SYNTAX INTEGER { - other(1), - invalid(2), - learned(3), - self(4), - mgmt(5) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The status of this entry. The meanings of the - values are: - other(1) - none of the following. - invalid(2) - this entry is no longer valid (e.g., - it was learned but has since aged out), but has - not yet been flushed from the table. - learned(3) - the value of the corresponding instance - of begemotBridgeTpFdbPort was learned, and is being - used. - self(4) - the value of the corresponding instance of - begemotBridgeTpFdbAddress represents one of the - bridge's addresses. The corresponding instance of - begemotBridgeTpFdbPort indicates which of the bridge's - ports has this address. - mgmt(5) - the value of the corresponding instance of - begemotBridgeTpFdbAddress has been added to the - bridge's Forwarding Database by some management - means." - ::= { begemotBridgeTpFdbEntry 3 } - --- ---------------------------------------------------------- -- --- Ports table for Transparent Bridging interfaces --- ---------------------------------------------------------- -- - -begemotBridgeTpPortTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotBridgeTpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information about every bridge port, - member of a bridge interface, associated with the transparent - bridging function of the bridge." - ::= { begemotBridgeTp 3 } - -begemotBridgeTpPortEntry OBJECT-TYPE - SYNTAX BegemotBridgeTpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of information about every bridge port, member of a - bridge interface, associated with the bridge's transparent - bridging function." - INDEX { begemotBridgeBaseName, begemotBridgeBasePortIfIndex } - ::= { begemotBridgeTpPortTable 1 } - -BegemotBridgeTpPortEntry ::= SEQUENCE { - begemotBridgeTpPort Integer32, - begemotBridgeTpPortMaxInfo Integer32, - begemotBridgeTpPortInFrames Counter32, - begemotBridgeTpPortOutFrames Counter32, - begemotBridgeTpPortInDiscards Counter32 -} - -begemotBridgeTpPort OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The system interface index of the port for which this entry - contains Transparent bridging management information." - ::= { begemotBridgeTpPortEntry 1 } - -begemotBridgeTpPortMaxInfo OBJECT-TYPE - SYNTAX Integer32 - UNITS "bytes" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The maximum size of the INFO (non-MAC) field that this port - will receive or transmit." - ::= { begemotBridgeTpPortEntry 2 } - -begemotBridgeTpPortInFrames OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that have been received by this - port from its segment. Note that a frame received on the - interface corresponding to this port is only counted by - this object if and only if it is for a protocol being - processed by the local bridging function, including - bridge management frames." - ::= { begemotBridgeTpPortEntry 3 } - -begemotBridgeTpPortOutFrames OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that have been transmitted by this - port to its segment. Note that a frame transmitted on - the interface corresponding to this port is only counted - by this object if and only if it is for a protocol being - processed by the local bridging function, including - bridge management frames." - ::= { begemotBridgeTpPortEntry 4 } - -begemotBridgeTpPortInDiscards OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Count of received valid frames that were discarded - (i.e., filtered) by the Forwarding Process." - ::= { begemotBridgeTpPortEntry 5 } - --- ---------------------------------------------------------- -- --- the begemotBridgePf objects --- ---------------------------------------------------------- -- - -begemotBridgePfilStatus OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Indicates whether packet filtering by some firewall - package is enabled on the bridge interface." - ::= { begemotBridgePf 1 } - -begemotBridgePfilMembers OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "A value of true(1) indicates that packet filtering is - enabled on both incoming and outgoing bridge member - interfaces." - ::= { begemotBridgePf 2 } - -begemotBridgePfilIpOnly OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This value controls the handling of non-IP packets which - are not passed on for further processing to a firewall - package. A value of false(0) indicates that all non-IP - Ethernet frames are passed unconditionally." - ::= { begemotBridgePf 3 } - -begemotBridgeLayer2PfStatus OBJECT-TYPE - SYNTAX INTEGER { - enabled(1), - disabled(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This value indicates whether layer2 filtering by a - firewall package is enabled for bridge interfaces." - ::= { begemotBridgePf 4 } - --- ---------------------------------------------------------- -- --- the begemotBridgeConfigObjects objects --- ---------------------------------------------------------- -- - -begemotBridgeDefaultBridgeIf OBJECT-TYPE - - SYNTAX BridgeIfNameOrEmpty - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The name of the bridge interface that will be managed - via objects in IETF BRIDGE-MIB (RFC4188). If the - object's value is set to an empty string, bridge interfaces - will only be managed via objects in this MIB module." - DEFVAL { "bridge0" } - ::= { begemotBridgeConfigObjects 1 } - -begemotBridgeDataUpdate OBJECT-TYPE - - SYNTAX Timeout (1..300) - UNITS "seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum age in seconds of the cached data." - DEFVAL { 10 } - ::= { begemotBridgeConfigObjects 2 } - -begemotBridgeDataPoll OBJECT-TYPE - - SYNTAX Timeout (1..3600) - UNITS "seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The polling rate of data when the module is idle." - DEFVAL { 300 } - ::= { begemotBridgeConfigObjects 3 } - --- ---------------------------------------------------------- -- --- Notifications for the Spanning Tree Protocol --- ---------------------------------------------------------- -- - -begemotBridgeNewRoot NOTIFICATION-TYPE - OBJECTS { begemotBridgeBaseName } - STATUS current - DESCRIPTION - "The begemotBridgeNewRoot trap indicates that one of the - bridge interfaces on the sending agent's device has - become the new root of the spanning tree topology it is - participating in." - ::= { begemotBridgeNotifications 1 } - -begemotBridgeTopologyChange NOTIFICATION-TYPE - OBJECTS { begemotBridgeBaseName } - STATUS current - DESCRIPTION - "A begemotBridgeTopologyChange trap is send when a member - port on one of the bridge interfaces, monitored by the agent, - transitions from the Learning state to the Forwarding state, - or from the Forwarding state to the Blocking state. The trap - is not sent if a begemotBridgeNewRoot trap is sent for the - same transition." - ::= { begemotBridgeNotifications 2 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/BRIDGE-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_bridge/BRIDGE-MIB.txt deleted file mode 100644 index 9f87b65..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/BRIDGE-MIB.txt +++ /dev/null @@ -1,1483 +0,0 @@ --- --- Copyright (C) The Internet Society (2005). --- --- This document is subject to the rights, licenses and restrictions --- contained in BCP 78, and except as set forth therein, the authors --- retain all their rights. --- --- This document and the information contained herein are provided on an --- "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS --- OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET --- ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, --- INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE --- INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED --- WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. --- --- $FreeBSD$ --- - -BRIDGE-MIB DEFINITIONS ::= BEGIN - --- ---------------------------------------------------------- -- --- MIB for IEEE 802.1D devices --- ---------------------------------------------------------- -- -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE, - Counter32, Integer32, TimeTicks, mib-2 - FROM SNMPv2-SMI - TEXTUAL-CONVENTION, MacAddress - FROM SNMPv2-TC - MODULE-COMPLIANCE, OBJECT-GROUP, NOTIFICATION-GROUP - FROM SNMPv2-CONF - InterfaceIndex FROM IF-MIB - ; - -dot1dBridge MODULE-IDENTITY - LAST-UPDATED "200509190000Z" - ORGANIZATION "IETF Bridge MIB Working Group" - CONTACT-INFO - "Email: bridge-mib@ietf.org - - K.C. Norseth (Editor) - L-3 Communications - Tel: +1 801-594-2809 - Email: kenyon.c.norseth@L-3com.com - Postal: 640 N. 2200 West. - Salt Lake City, Utah 84116-0850 - Les Bell (Editor) - 3Com Europe Limited - Phone: +44 1442 438025 - Email: elbell@ntlworld.com - Postal: 3Com Centre, Boundary Way - Hemel Hempstead - Herts. HP2 7YU - UK - - Send comments to " - DESCRIPTION - "The Bridge MIB module for managing devices that support - IEEE 802.1D. - - Copyright (C) The Internet Society (2005). This version of - this MIB module is part of RFC 4188; see the RFC itself for - full legal notices." - REVISION "200509190000Z" - DESCRIPTION - "Third revision, published as part of RFC 4188. - - The MIB module has been converted to SMIv2 format. - Conformance statements have been added and some - description and reference clauses have been updated. - - The object dot1dStpPortPathCost32 was added to - support IEEE 802.1t and the permissible values of - dot1dStpPriority and dot1dStpPortPriority have been - clarified for bridges supporting IEEE 802.1t or - IEEE 802.1w. - - The interpretation of dot1dStpTimeSinceTopologyChange - has been clarified for bridges supporting the Rapid - Spanning Tree Protocol (RSTP)." - REVISION "199307310000Z" - DESCRIPTION - "Second revision, published as part of RFC 1493." - REVISION "199112310000Z" - DESCRIPTION - "Initial revision, published as part of RFC 1286." - ::= { mib-2 17 } - - --- ---------------------------------------------------------- -- --- Textual Conventions --- ---------------------------------------------------------- -- - -BridgeId ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "The Bridge-Identifier, as used in the Spanning Tree - Protocol, to uniquely identify a bridge. Its first two - octets (in network byte order) contain a priority value, - and its last 6 octets contain the MAC address used to - refer to a bridge in a unique fashion (typically, the - numerically smallest MAC address of all ports on the - bridge)." - SYNTAX OCTET STRING (SIZE (8)) - -Timeout ::= TEXTUAL-CONVENTION - DISPLAY-HINT "d" - STATUS current - DESCRIPTION - "A Spanning Tree Protocol (STP) timer in units of 1/100 - seconds. Several objects in this MIB module represent - values of timers used by the Spanning Tree Protocol. - In this MIB, these timers have values in units of - hundredths of a second (i.e., 1/100 secs). - - These timers, when stored in a Spanning Tree Protocol's - BPDU, are in units of 1/256 seconds. Note, however, that - 802.1D-1998 specifies a settable granularity of no more - than one second for these timers. To avoid ambiguity, - a conversion algorithm is defined below for converting - between the different units, which ensures a timer's - value is not distorted by multiple conversions. - - To convert a Timeout value into a value in units of - 1/256 seconds, the following algorithm should be used: - - b = floor( (n * 256) / 100) - - where: - floor = quotient [ignore remainder] - n is the value in 1/100 second units - b is the value in 1/256 second units - - To convert the value from 1/256 second units back to - 1/100 seconds, the following algorithm should be used: - - n = ceiling( (b * 100) / 256) - - where: - ceiling = quotient [if remainder is 0], or - quotient + 1 [if remainder is nonzero] - n is the value in 1/100 second units - b is the value in 1/256 second units - - Note: it is important that the arithmetic operations are - done in the order specified (i.e., multiply first, - divide second)." - SYNTAX Integer32 - --- ---------------------------------------------------------- -- --- subtrees in the Bridge MIB --- ---------------------------------------------------------- -- - -dot1dNotifications OBJECT IDENTIFIER ::= { dot1dBridge 0 } - -dot1dBase OBJECT IDENTIFIER ::= { dot1dBridge 1 } -dot1dStp OBJECT IDENTIFIER ::= { dot1dBridge 2 } - -dot1dSr OBJECT IDENTIFIER ::= { dot1dBridge 3 } --- documented in RFC 1525 - -dot1dTp OBJECT IDENTIFIER ::= { dot1dBridge 4 } -dot1dStatic OBJECT IDENTIFIER ::= { dot1dBridge 5 } - --- Subtrees used by Bridge MIB Extensions: --- pBridgeMIB MODULE-IDENTITY ::= { dot1dBridge 6 } --- qBridgeMIB MODULE-IDENTITY ::= { dot1dBridge 7 } --- Note that the practice of registering related MIB modules --- below dot1dBridge has been discouraged since there is no --- robust mechanism to track such registrations. - -dot1dConformance OBJECT IDENTIFIER ::= { dot1dBridge 8 } - --- ---------------------------------------------------------- -- --- the dot1dBase subtree --- ---------------------------------------------------------- -- --- Implementation of the dot1dBase subtree is mandatory for all --- bridges. --- ---------------------------------------------------------- -- - -dot1dBaseBridgeAddress OBJECT-TYPE - - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The MAC address used by this bridge when it must be - referred to in a unique fashion. It is recommended - that this be the numerically smallest MAC address of - all ports that belong to this bridge. However, it is only - required to be unique. When concatenated with - dot1dStpPriority, a unique BridgeIdentifier is formed, - which is used in the Spanning Tree Protocol." - REFERENCE - "IEEE 802.1D-1998: clauses 14.4.1.1.3 and 7.12.5" - ::= { dot1dBase 1 } - -dot1dBaseNumPorts OBJECT-TYPE - SYNTAX Integer32 - UNITS "ports" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of ports controlled by this bridging - entity." - REFERENCE - "IEEE 802.1D-1998: clause 14.4.1.1.3" - ::= { dot1dBase 2 } - -dot1dBaseType OBJECT-TYPE - SYNTAX INTEGER { - unknown(1), - transparent-only(2), - sourceroute-only(3), - srt(4) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Indicates what type of bridging this bridge can - perform. If a bridge is actually performing a - certain type of bridging, this will be indicated by - entries in the port table for the given type." - ::= { dot1dBase 3 } - --- ---------------------------------------------------------- -- --- The Generic Bridge Port Table --- ---------------------------------------------------------- -- -dot1dBasePortTable OBJECT-TYPE - SYNTAX SEQUENCE OF Dot1dBasePortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains generic information about every - port that is associated with this bridge. Transparent, - source-route, and srt ports are included." - ::= { dot1dBase 4 } - -dot1dBasePortEntry OBJECT-TYPE - SYNTAX Dot1dBasePortEntry - MAX-ACCESS not-accessible - STATUS current - - DESCRIPTION - "A list of information for each port of the bridge." - REFERENCE - "IEEE 802.1D-1998: clause 14.4.2, 14.6.1" - INDEX { dot1dBasePort } - ::= { dot1dBasePortTable 1 } - -Dot1dBasePortEntry ::= - SEQUENCE { - dot1dBasePort - Integer32, - dot1dBasePortIfIndex - InterfaceIndex, - dot1dBasePortCircuit - OBJECT IDENTIFIER, - dot1dBasePortDelayExceededDiscards - Counter32, - dot1dBasePortMtuExceededDiscards - Counter32 - } - -dot1dBasePort OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The port number of the port for which this entry - contains bridge management information." - ::= { dot1dBasePortEntry 1 } - -dot1dBasePortIfIndex OBJECT-TYPE - SYNTAX InterfaceIndex - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The value of the instance of the ifIndex object, - defined in IF-MIB, for the interface corresponding - to this port." - ::= { dot1dBasePortEntry 2 } - -dot1dBasePortCircuit OBJECT-TYPE - SYNTAX OBJECT IDENTIFIER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "For a port that (potentially) has the same value of - dot1dBasePortIfIndex as another port on the same bridge. - This object contains the name of an object instance - unique to this port. For example, in the case where - multiple ports correspond one-to-one with multiple X.25 - virtual circuits, this value might identify an (e.g., - the first) object instance associated with the X.25 - virtual circuit corresponding to this port. - - For a port which has a unique value of - dot1dBasePortIfIndex, this object can have the value - { 0 0 }." - ::= { dot1dBasePortEntry 3 } - -dot1dBasePortDelayExceededDiscards OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames discarded by this port due - to excessive transit delay through the bridge. It - is incremented by both transparent and source - route bridges." - REFERENCE - "IEEE 802.1D-1998: clause 14.6.1.1.3" - ::= { dot1dBasePortEntry 4 } - -dot1dBasePortMtuExceededDiscards OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames discarded by this port due - to an excessive size. It is incremented by both - transparent and source route bridges." - REFERENCE - "IEEE 802.1D-1998: clause 14.6.1.1.3" - ::= { dot1dBasePortEntry 5 } - --- ---------------------------------------------------------- -- --- the dot1dStp subtree --- ---------------------------------------------------------- -- --- Implementation of the dot1dStp subtree is optional. It is --- implemented by those bridges that support the Spanning Tree --- Protocol. --- ---------------------------------------------------------- -- -dot1dStpProtocolSpecification OBJECT-TYPE - SYNTAX INTEGER { - unknown(1), - decLb100(2), - ieee8021d(3) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "An indication of what version of the Spanning Tree - Protocol is being run. The value 'decLb100(2)' - indicates the DEC LANbridge 100 Spanning Tree protocol. - IEEE 802.1D implementations will return 'ieee8021d(3)'. - If future versions of the IEEE Spanning Tree Protocol - that are incompatible with the current version - are released a new value will be defined." - ::= { dot1dStp 1 } - -dot1dStpPriority OBJECT-TYPE - SYNTAX Integer32 (0..65535) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of the write-able portion of the Bridge ID - (i.e., the first two octets of the (8 octet long) Bridge - ID). The other (last) 6 octets of the Bridge ID are - given by the value of dot1dBaseBridgeAddress. - On bridges supporting IEEE 802.1t or IEEE 802.1w, - permissible values are 0-61440, in steps of 4096." - REFERENCE - "IEEE 802.1D-1998 clause 8.10.2, Table 8-4, - IEEE 802.1t clause 8.10.2, Table 8-4, clause 14.3." - ::= { dot1dStp 2 } - -dot1dStpTimeSinceTopologyChange OBJECT-TYPE - SYNTAX TimeTicks - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The time (in hundredths of a second) since the - last time a topology change was detected by the - bridge entity. - For RSTP, this reports the time since the tcWhile - timer for any port on this Bridge was nonzero." - REFERENCE - "IEEE 802.1D-1998 clause 14.8.1.1., - IEEE 802.1w clause 14.8.1.1." - ::= { dot1dStp 3 } - -dot1dStpTopChanges OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The total number of topology changes detected by - this bridge since the management entity was last - reset or initialized." - REFERENCE - "IEEE 802.1D-1998 clause 14.8.1.1." - ::= { dot1dStp 4 } - -dot1dStpDesignatedRoot OBJECT-TYPE - SYNTAX BridgeId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The bridge identifier of the root of the spanning - tree, as determined by the Spanning Tree Protocol, - as executed by this node. This value is used as - the Root Identifier parameter in all Configuration - Bridge PDUs originated by this node." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.1" - ::= { dot1dStp 5 } - -dot1dStpRootCost OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The cost of the path to the root as seen from - this bridge." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.2" - ::= { dot1dStp 6 } - -dot1dStpRootPort OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The port number of the port that offers the lowest - cost path from this bridge to the root bridge." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.3" - ::= { dot1dStp 7 } - -dot1dStpMaxAge OBJECT-TYPE - SYNTAX Timeout - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The maximum age of Spanning Tree Protocol information - learned from the network on any port before it is - discarded, in units of hundredths of a second. This is - the actual value that this bridge is currently using." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.4" - ::= { dot1dStp 8 } - -dot1dStpHelloTime OBJECT-TYPE - SYNTAX Timeout - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The amount of time between the transmission of - Configuration bridge PDUs by this node on any port when - it is the root of the spanning tree, or trying to become - so, in units of hundredths of a second. This is the - actual value that this bridge is currently using." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.5" - ::= { dot1dStp 9 } - -dot1dStpHoldTime OBJECT-TYPE - SYNTAX Integer32 - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "This time value determines the interval length - during which no more than two Configuration bridge - PDUs shall be transmitted by this node, in units - of hundredths of a second." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.14" - ::= { dot1dStp 10 } - -dot1dStpForwardDelay OBJECT-TYPE - SYNTAX Timeout - UNITS "centi-seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "This time value, measured in units of hundredths of a - second, controls how fast a port changes its spanning - state when moving towards the Forwarding state. The - value determines how long the port stays in each of the - Listening and Learning states, which precede the - Forwarding state. This value is also used when a - topology change has been detected and is underway, to - age all dynamic entries in the Forwarding Database. - [Note that this value is the one that this bridge is - currently using, in contrast to - dot1dStpBridgeForwardDelay, which is the value that this - bridge and all others would start using if/when this - bridge were to become the root.]" - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.6" - ::= { dot1dStp 11 } - -dot1dStpBridgeMaxAge OBJECT-TYPE - SYNTAX Timeout (600..4000) - UNITS "centi-seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value that all bridges use for MaxAge when this - bridge is acting as the root. Note that 802.1D-1998 - specifies that the range for this parameter is related - to the value of dot1dStpBridgeHelloTime. The - granularity of this timer is specified by 802.1D-1998 to - be 1 second. An agent may return a badValue error if a - set is attempted to a value that is not a whole number - of seconds." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.8" - ::= { dot1dStp 12 } - -dot1dStpBridgeHelloTime OBJECT-TYPE - SYNTAX Timeout (100..1000) - UNITS "centi-seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value that all bridges use for HelloTime when this - bridge is acting as the root. The granularity of this - timer is specified by 802.1D-1998 to be 1 second. An - agent may return a badValue error if a set is attempted - to a value that is not a whole number of seconds." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.9" - ::= { dot1dStp 13 } - -dot1dStpBridgeForwardDelay OBJECT-TYPE - SYNTAX Timeout (400..3000) - UNITS "centi-seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value that all bridges use for ForwardDelay when - this bridge is acting as the root. Note that - 802.1D-1998 specifies that the range for this parameter - is related to the value of dot1dStpBridgeMaxAge. The - granularity of this timer is specified by 802.1D-1998 to - be 1 second. An agent may return a badValue error if a - set is attempted to a value that is not a whole number - of seconds." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.3.10" - ::= { dot1dStp 14 } - --- ---------------------------------------------------------- -- --- The Spanning Tree Port Table --- ---------------------------------------------------------- -- - -dot1dStpPortTable OBJECT-TYPE - SYNTAX SEQUENCE OF Dot1dStpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains port-specific information - for the Spanning Tree Protocol." - ::= { dot1dStp 15 } - -dot1dStpPortEntry OBJECT-TYPE - SYNTAX Dot1dStpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of information maintained by every port about - the Spanning Tree Protocol state for that port." - INDEX { dot1dStpPort } - ::= { dot1dStpPortTable 1 } - -Dot1dStpPortEntry ::= - SEQUENCE { - dot1dStpPort - Integer32, - dot1dStpPortPriority - Integer32, - dot1dStpPortState - INTEGER, - dot1dStpPortEnable - INTEGER, - dot1dStpPortPathCost - Integer32, - dot1dStpPortDesignatedRoot - BridgeId, - dot1dStpPortDesignatedCost - Integer32, - dot1dStpPortDesignatedBridge - BridgeId, - dot1dStpPortDesignatedPort - OCTET STRING, - dot1dStpPortForwardTransitions - Counter32, - dot1dStpPortPathCost32 - Integer32 - } - -dot1dStpPort OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The port number of the port for which this entry - contains Spanning Tree Protocol management information." - REFERENCE - "IEEE 802.1D-1998: clause 14.8.2.1.2" - ::= { dot1dStpPortEntry 1 } - -dot1dStpPortPriority OBJECT-TYPE - SYNTAX Integer32 (0..255) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of the priority field that is contained in - the first (in network byte order) octet of the (2 octet - long) Port ID. The other octet of the Port ID is given - by the value of dot1dStpPort. - On bridges supporting IEEE 802.1t or IEEE 802.1w, - permissible values are 0-240, in steps of 16." - REFERENCE - "IEEE 802.1D-1998 clause 8.10.2, Table 8-4, - IEEE 802.1t clause 8.10.2, Table 8-4, clause 14.3." - ::= { dot1dStpPortEntry 2 } - -dot1dStpPortState OBJECT-TYPE - SYNTAX INTEGER { - disabled(1), - blocking(2), - listening(3), - learning(4), - forwarding(5), - broken(6) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The port's current state, as defined by application of - the Spanning Tree Protocol. This state controls what - action a port takes on reception of a frame. If the - bridge has detected a port that is malfunctioning, it - will place that port into the broken(6) state. For - ports that are disabled (see dot1dStpPortEnable), this - object will have a value of disabled(1)." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.5.2" - ::= { dot1dStpPortEntry 3 } - -dot1dStpPortEnable OBJECT-TYPE - SYNTAX INTEGER { - enabled(1), - disabled(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The enabled/disabled status of the port." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.5.2" - ::= { dot1dStpPortEntry 4 } - -dot1dStpPortPathCost OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The contribution of this port to the path cost of - paths towards the spanning tree root which include - this port. 802.1D-1998 recommends that the default - value of this parameter be in inverse proportion to - the speed of the attached LAN. - - New implementations should support dot1dStpPortPathCost32. - If the port path costs exceeds the maximum value of this - object then this object should report the maximum value, - namely 65535. Applications should try to read the - dot1dStpPortPathCost32 object if this object reports - the maximum value." - REFERENCE "IEEE 802.1D-1998: clause 8.5.5.3" - ::= { dot1dStpPortEntry 5 } - -dot1dStpPortDesignatedRoot OBJECT-TYPE - SYNTAX BridgeId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The unique Bridge Identifier of the Bridge - recorded as the Root in the Configuration BPDUs - transmitted by the Designated Bridge for the - segment to which the port is attached." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.5.4" - ::= { dot1dStpPortEntry 6 } - -dot1dStpPortDesignatedCost OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The path cost of the Designated Port of the segment - connected to this port. This value is compared to the - Root Path Cost field in received bridge PDUs." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.5.5" - ::= { dot1dStpPortEntry 7 } - -dot1dStpPortDesignatedBridge OBJECT-TYPE - SYNTAX BridgeId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The Bridge Identifier of the bridge that this - port considers to be the Designated Bridge for - this port's segment." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.5.6" - ::= { dot1dStpPortEntry 8 } - -dot1dStpPortDesignatedPort OBJECT-TYPE - SYNTAX OCTET STRING (SIZE (2)) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The Port Identifier of the port on the Designated - Bridge for this port's segment." - REFERENCE - "IEEE 802.1D-1998: clause 8.5.5.7" - ::= { dot1dStpPortEntry 9 } - -dot1dStpPortForwardTransitions OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times this port has transitioned - from the Learning state to the Forwarding state." - ::= { dot1dStpPortEntry 10 } - -dot1dStpPortPathCost32 OBJECT-TYPE - SYNTAX Integer32 (1..200000000) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The contribution of this port to the path cost of - paths towards the spanning tree root which include - this port. 802.1D-1998 recommends that the default - value of this parameter be in inverse proportion to - the speed of the attached LAN. - - This object replaces dot1dStpPortPathCost to support - IEEE 802.1t." - REFERENCE - "IEEE 802.1t clause 8.10.2, Table 8-5." - ::= { dot1dStpPortEntry 11 } - --- ---------------------------------------------------------- -- --- the dot1dTp subtree --- ---------------------------------------------------------- -- --- Implementation of the dot1dTp subtree is optional. It is --- implemented by those bridges that support the transparent --- bridging mode. A transparent or SRT bridge will implement --- this subtree. --- ---------------------------------------------------------- -- - -dot1dTpLearnedEntryDiscards OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The total number of Forwarding Database entries that - have been or would have been learned, but have been - discarded due to a lack of storage space in the - Forwarding Database. If this counter is increasing, it - indicates that the Forwarding Database is regularly - becoming full (a condition that has unpleasant - performance effects on the subnetwork). If this counter - has a significant value but is not presently increasing, - it indicates that the problem has been occurring but is - not persistent." - REFERENCE - "IEEE 802.1D-1998: clause 14.7.1.1.3" - ::= { dot1dTp 1 } - -dot1dTpAgingTime OBJECT-TYPE - SYNTAX Integer32 (10..1000000) - UNITS "seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The timeout period in seconds for aging out - dynamically-learned forwarding information. - 802.1D-1998 recommends a default of 300 seconds." - REFERENCE - "IEEE 802.1D-1998: clause 14.7.1.1.3" - ::= { dot1dTp 2 } - - --- ---------------------------------------------------------- -- --- The Forwarding Database for Transparent Bridges --- ---------------------------------------------------------- -- - -dot1dTpFdbTable OBJECT-TYPE - SYNTAX SEQUENCE OF Dot1dTpFdbEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information about unicast - entries for which the bridge has forwarding and/or - filtering information. This information is used - by the transparent bridging function in - determining how to propagate a received frame." - ::= { dot1dTp 3 } - -dot1dTpFdbEntry OBJECT-TYPE - SYNTAX Dot1dTpFdbEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Information about a specific unicast MAC address - for which the bridge has some forwarding and/or - filtering information." - INDEX { dot1dTpFdbAddress } - ::= { dot1dTpFdbTable 1 } - -Dot1dTpFdbEntry ::= - SEQUENCE { - dot1dTpFdbAddress - MacAddress, - dot1dTpFdbPort - Integer32, - dot1dTpFdbStatus - INTEGER - } - -dot1dTpFdbAddress OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "A unicast MAC address for which the bridge has - forwarding and/or filtering information." - REFERENCE - "IEEE 802.1D-1998: clause 7.9.1, 7.9.2" - ::= { dot1dTpFdbEntry 1 } - -dot1dTpFdbPort OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Either the value '0', or the port number of the port on - which a frame having a source address equal to the value - of the corresponding instance of dot1dTpFdbAddress has - been seen. A value of '0' indicates that the port - number has not been learned, but that the bridge does - have some forwarding/filtering information about this - address (e.g., in the dot1dStaticTable). Implementors - are encouraged to assign the port value to this object - whenever it is learned, even for addresses for which the - corresponding value of dot1dTpFdbStatus is not - learned(3)." - ::= { dot1dTpFdbEntry 2 } -dot1dTpFdbStatus OBJECT-TYPE - SYNTAX INTEGER { - other(1), - invalid(2), - learned(3), - self(4), - mgmt(5) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The status of this entry. The meanings of the - values are: - other(1) - none of the following. This would - include the case where some other MIB object - (not the corresponding instance of - dot1dTpFdbPort, nor an entry in the - dot1dStaticTable) is being used to determine if - and how frames addressed to the value of the - corresponding instance of dot1dTpFdbAddress are - being forwarded. - invalid(2) - this entry is no longer valid (e.g., - it was learned but has since aged out), but has - not yet been flushed from the table. - learned(3) - the value of the corresponding instance - of dot1dTpFdbPort was learned, and is being - used. - self(4) - the value of the corresponding instance of - dot1dTpFdbAddress represents one of the bridge's - addresses. The corresponding instance of - dot1dTpFdbPort indicates which of the bridge's - ports has this address. - mgmt(5) - the value of the corresponding instance of - dot1dTpFdbAddress is also the value of an - existing instance of dot1dStaticAddress." - ::= { dot1dTpFdbEntry 3 } - --- ---------------------------------------------------------- -- --- Port Table for Transparent Bridges --- ---------------------------------------------------------- -- - -dot1dTpPortTable OBJECT-TYPE - SYNTAX SEQUENCE OF Dot1dTpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information about every port that - is associated with this transparent bridge." - ::= { dot1dTp 4 } - -dot1dTpPortEntry OBJECT-TYPE - SYNTAX Dot1dTpPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of information for each port of a transparent - bridge." - INDEX { dot1dTpPort } - ::= { dot1dTpPortTable 1 } - -Dot1dTpPortEntry ::= - SEQUENCE { - dot1dTpPort - Integer32, - dot1dTpPortMaxInfo - Integer32, - dot1dTpPortInFrames - Counter32, - dot1dTpPortOutFrames - Counter32, - dot1dTpPortInDiscards - Counter32 - } - -dot1dTpPort OBJECT-TYPE - SYNTAX Integer32 (1..65535) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The port number of the port for which this entry - contains Transparent bridging management information." - ::= { dot1dTpPortEntry 1 } - --- It would be nice if we could use ifMtu as the size of the --- largest INFO field, but we can't because ifMtu is defined --- to be the size that the (inter-)network layer can use, which --- can differ from the MAC layer (especially if several layers --- of encapsulation are used). - -dot1dTpPortMaxInfo OBJECT-TYPE - SYNTAX Integer32 - UNITS "bytes" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The maximum size of the INFO (non-MAC) field that - this port will receive or transmit." - ::= { dot1dTpPortEntry 2 } - -dot1dTpPortInFrames OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that have been received by this - port from its segment. Note that a frame received on the - interface corresponding to this port is only counted by - this object if and only if it is for a protocol being - processed by the local bridging function, including - bridge management frames." - REFERENCE - "IEEE 802.1D-1998: clause 14.6.1.1.3" - ::= { dot1dTpPortEntry 3 } - -dot1dTpPortOutFrames OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that have been transmitted by this - port to its segment. Note that a frame transmitted on - the interface corresponding to this port is only counted - by this object if and only if it is for a protocol being - processed by the local bridging function, including - bridge management frames." - REFERENCE - "IEEE 802.1D-1998: clause 14.6.1.1.3" - ::= { dot1dTpPortEntry 4 } - -dot1dTpPortInDiscards OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Count of received valid frames that were discarded - (i.e., filtered) by the Forwarding Process." - REFERENCE - "IEEE 802.1D-1998: clause 14.6.1.1.3" - ::= { dot1dTpPortEntry 5 } - --- ---------------------------------------------------------- -- --- The Static (Destination-Address Filtering) Database --- ---------------------------------------------------------- -- --- Implementation of this subtree is optional. --- ---------------------------------------------------------- -- - -dot1dStaticTable OBJECT-TYPE - SYNTAX SEQUENCE OF Dot1dStaticEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table containing filtering information configured - into the bridge by (local or network) management - specifying the set of ports to which frames received - from specific ports and containing specific destination - addresses are allowed to be forwarded. The value of - zero in this table, as the port number from which frames - with a specific destination address are received, is - used to specify all ports for which there is no specific - entry in this table for that particular destination - address. Entries are valid for unicast and for - group/broadcast addresses." - REFERENCE - "IEEE 802.1D-1998: clause 14.7.2" - ::= { dot1dStatic 1 } - -dot1dStaticEntry OBJECT-TYPE - SYNTAX Dot1dStaticEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Filtering information configured into the bridge by - (local or network) management specifying the set of - ports to which frames received from a specific port and - containing a specific destination address are allowed to - be forwarded." - REFERENCE - "IEEE 802.1D-1998: clause 14.7.2" - INDEX { dot1dStaticAddress, dot1dStaticReceivePort } - ::= { dot1dStaticTable 1 } - -Dot1dStaticEntry ::= - SEQUENCE { - dot1dStaticAddress MacAddress, - dot1dStaticReceivePort Integer32, - dot1dStaticAllowedToGoTo OCTET STRING, - dot1dStaticStatus INTEGER - } - -dot1dStaticAddress OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The destination MAC address in a frame to which this - entry's filtering information applies. This object can - take the value of a unicast address, a group address, or - the broadcast address." - REFERENCE - "IEEE 802.1D-1998: clause 7.9.1, 7.9.2" - ::= { dot1dStaticEntry 1 } - -dot1dStaticReceivePort OBJECT-TYPE - SYNTAX Integer32 (0..65535) - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "Either the value '0', or the port number of the port - from which a frame must be received in order for this - entry's filtering information to apply. A value of zero - indicates that this entry applies on all ports of the - bridge for which there is no other applicable entry." - ::= { dot1dStaticEntry 2 } - -dot1dStaticAllowedToGoTo OBJECT-TYPE - SYNTAX OCTET STRING (SIZE (0..512)) - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The set of ports to which frames received from a - specific port and destined for a specific MAC address, - are allowed to be forwarded. Each octet within the - value of this object specifies a set of eight ports, - with the first octet specifying ports 1 through 8, the - second octet specifying ports 9 through 16, etc. Within - each octet, the most significant bit represents the - lowest numbered port, and the least significant bit - represents the highest numbered port. Thus, each port - of the bridge is represented by a single bit within the - value of this object. If that bit has a value of '1', - then that port is included in the set of ports; the port - is not included if its bit has a value of '0'. (Note - that the setting of the bit corresponding to the port - from which a frame is received is irrelevant.) The - default value of this object is a string of ones of - appropriate length. - - The value of this object may exceed the required minimum - maximum message size of some SNMP transport (484 bytes, - in the case of SNMP over UDP, see RFC 3417, section 3.2). - SNMP engines on bridges supporting a large number of - ports must support appropriate maximum message sizes." - ::= { dot1dStaticEntry 3 } - -dot1dStaticStatus OBJECT-TYPE - SYNTAX INTEGER { - other(1), - invalid(2), - permanent(3), - deleteOnReset(4), - deleteOnTimeout(5) - } - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "This object indicates the status of this entry. - The default value is permanent(3). - other(1) - this entry is currently in use but the - conditions under which it will remain so are - different from each of the following values. - invalid(2) - writing this value to the object - removes the corresponding entry. - permanent(3) - this entry is currently in use and - will remain so after the next reset of the - bridge. - deleteOnReset(4) - this entry is currently in use - and will remain so until the next reset of the - bridge. - deleteOnTimeout(5) - this entry is currently in use - and will remain so until it is aged out." - ::= { dot1dStaticEntry 4 } - --- ---------------------------------------------------------- -- --- Notifications for use by Bridges --- ---------------------------------------------------------- -- --- Notifications for the Spanning Tree Protocol --- ---------------------------------------------------------- -- - -newRoot NOTIFICATION-TYPE - -- OBJECTS { } - STATUS current - DESCRIPTION - "The newRoot trap indicates that the sending agent has - become the new root of the Spanning Tree; the trap is - sent by a bridge soon after its election as the new - root, e.g., upon expiration of the Topology Change Timer, - immediately subsequent to its election. Implementation - of this trap is optional." - ::= { dot1dNotifications 1 } - -topologyChange NOTIFICATION-TYPE - -- OBJECTS { } - STATUS current - DESCRIPTION - "A topologyChange trap is sent by a bridge when any of - its configured ports transitions from the Learning state - to the Forwarding state, or from the Forwarding state to - the Blocking state. The trap is not sent if a newRoot - trap is sent for the same transition. Implementation of - this trap is optional." - ::= { dot1dNotifications 2 } - --- ---------------------------------------------------------- -- --- IEEE 802.1D MIB - Conformance Information --- ---------------------------------------------------------- -- - -dot1dGroups OBJECT IDENTIFIER ::= { dot1dConformance 1 } -dot1dCompliances OBJECT IDENTIFIER ::= { dot1dConformance 2 } - --- ---------------------------------------------------------- -- --- units of conformance --- ---------------------------------------------------------- -- - --- ---------------------------------------------------------- -- --- the dot1dBase group --- ---------------------------------------------------------- -- - -dot1dBaseBridgeGroup OBJECT-GROUP - OBJECTS { - dot1dBaseBridgeAddress, - dot1dBaseNumPorts, - dot1dBaseType - } - STATUS current - DESCRIPTION - "Bridge level information for this device." - ::= { dot1dGroups 1 } - -dot1dBasePortGroup OBJECT-GROUP - OBJECTS { - dot1dBasePort, - dot1dBasePortIfIndex, - dot1dBasePortCircuit, - dot1dBasePortDelayExceededDiscards, - dot1dBasePortMtuExceededDiscards - } - STATUS current - DESCRIPTION - "Information for each port on this device." - ::= { dot1dGroups 2 } - --- ---------------------------------------------------------- -- --- the dot1dStp group --- ---------------------------------------------------------- -- - -dot1dStpBridgeGroup OBJECT-GROUP - OBJECTS { - dot1dStpProtocolSpecification, - dot1dStpPriority, - dot1dStpTimeSinceTopologyChange, - dot1dStpTopChanges, - dot1dStpDesignatedRoot, - dot1dStpRootCost, - dot1dStpRootPort, - dot1dStpMaxAge, - dot1dStpHelloTime, - dot1dStpHoldTime, - dot1dStpForwardDelay, - dot1dStpBridgeMaxAge, - dot1dStpBridgeHelloTime, - dot1dStpBridgeForwardDelay - } - STATUS current - DESCRIPTION - "Bridge level Spanning Tree data for this device." - ::= { dot1dGroups 3 } - -dot1dStpPortGroup OBJECT-GROUP - OBJECTS { - dot1dStpPort, - dot1dStpPortPriority, - dot1dStpPortState, - dot1dStpPortEnable, - dot1dStpPortPathCost, - dot1dStpPortDesignatedRoot, - dot1dStpPortDesignatedCost, - dot1dStpPortDesignatedBridge, - dot1dStpPortDesignatedPort, - dot1dStpPortForwardTransitions - } - STATUS current - DESCRIPTION - "Spanning Tree data for each port on this device." - ::= { dot1dGroups 4 } - -dot1dStpPortGroup2 OBJECT-GROUP - OBJECTS { - dot1dStpPort, - dot1dStpPortPriority, - dot1dStpPortState, - dot1dStpPortEnable, - dot1dStpPortDesignatedRoot, - dot1dStpPortDesignatedCost, - dot1dStpPortDesignatedBridge, - dot1dStpPortDesignatedPort, - dot1dStpPortForwardTransitions, - dot1dStpPortPathCost32 - } - STATUS current - DESCRIPTION - "Spanning Tree data for each port on this device." - ::= { dot1dGroups 5 } - -dot1dStpPortGroup3 OBJECT-GROUP - OBJECTS { - dot1dStpPortPathCost32 - } - STATUS current - DESCRIPTION - "Spanning Tree data for devices supporting 32-bit - path costs." - ::= { dot1dGroups 6 } - --- ---------------------------------------------------------- -- --- the dot1dTp group --- ---------------------------------------------------------- -- - -dot1dTpBridgeGroup OBJECT-GROUP - OBJECTS { - dot1dTpLearnedEntryDiscards, - dot1dTpAgingTime - } - STATUS current - DESCRIPTION - "Bridge level Transparent Bridging data." - ::= { dot1dGroups 7 } - -dot1dTpFdbGroup OBJECT-GROUP - OBJECTS { - dot1dTpFdbAddress, - dot1dTpFdbPort, - dot1dTpFdbStatus - } - - STATUS current - DESCRIPTION - "Filtering Database information for the Bridge." - ::= { dot1dGroups 8 } - -dot1dTpGroup OBJECT-GROUP - OBJECTS { - dot1dTpPort, - dot1dTpPortMaxInfo, - dot1dTpPortInFrames, - dot1dTpPortOutFrames, - dot1dTpPortInDiscards - } - STATUS current - DESCRIPTION - "Dynamic Filtering Database information for each port of - the Bridge." - ::= { dot1dGroups 9 } - --- ---------------------------------------------------------- -- --- The Static (Destination-Address Filtering) Database --- ---------------------------------------------------------- -- - -dot1dStaticGroup OBJECT-GROUP - OBJECTS { - dot1dStaticAddress, - dot1dStaticReceivePort, - dot1dStaticAllowedToGoTo, - dot1dStaticStatus - } - STATUS current - DESCRIPTION - "Static Filtering Database information for each port of - the Bridge." - ::= { dot1dGroups 10 } - --- ---------------------------------------------------------- -- --- The Trap Notification Group --- ---------------------------------------------------------- -- - -dot1dNotificationGroup NOTIFICATION-GROUP - NOTIFICATIONS { - newRoot, - topologyChange - } - STATUS current - DESCRIPTION - "Group of objects describing notifications (traps)." - ::= { dot1dGroups 11 } - --- ---------------------------------------------------------- -- --- compliance statements --- ---------------------------------------------------------- -- - -bridgeCompliance1493 MODULE-COMPLIANCE - STATUS current - DESCRIPTION - "The compliance statement for device support of bridging - services, as per RFC1493." - - MODULE - MANDATORY-GROUPS { - dot1dBaseBridgeGroup, - dot1dBasePortGroup - } - - GROUP dot1dStpBridgeGroup - DESCRIPTION - "Implementation of this group is mandatory for bridges - that support the Spanning Tree Protocol." - - GROUP dot1dStpPortGroup - DESCRIPTION - "Implementation of this group is mandatory for bridges - that support the Spanning Tree Protocol." - - GROUP dot1dTpBridgeGroup - DESCRIPTION - "Implementation of this group is mandatory for bridges - that support the transparent bridging mode. A - transparent or SRT bridge will implement this group." - - GROUP dot1dTpFdbGroup - DESCRIPTION - "Implementation of this group is mandatory for bridges - that support the transparent bridging mode. A - transparent or SRT bridge will implement this group." - - GROUP dot1dTpGroup - DESCRIPTION - "Implementation of this group is mandatory for bridges - that support the transparent bridging mode. A - transparent or SRT bridge will implement this group." - - GROUP dot1dStaticGroup - DESCRIPTION - "Implementation of this group is optional." - - GROUP dot1dNotificationGroup - DESCRIPTION - "Implementation of this group is optional." - ::= { dot1dCompliances 1 } - -bridgeCompliance4188 MODULE-COMPLIANCE - STATUS current - DESCRIPTION - "The compliance statement for device support of bridging - services. This supports 32-bit Path Cost values and the - more restricted bridge and port priorities, as per IEEE - 802.1t. - - Full support for the 802.1D management objects requires that - the SNMPv2-MIB [RFC3418] objects sysDescr, and sysUpTime, as - well as the IF-MIB [RFC2863] objects ifIndex, ifType, - ifDescr, ifPhysAddress, and ifLastChange are implemented." - - MODULE - MANDATORY-GROUPS { - dot1dBaseBridgeGroup, - dot1dBasePortGroup - } - - GROUP dot1dStpBridgeGroup - DESCRIPTION - "Implementation of this group is mandatory for - bridges that support the Spanning Tree Protocol." - - OBJECT dot1dStpPriority - SYNTAX Integer32 (0|4096|8192|12288|16384|20480|24576 - |28672|32768|36864|40960|45056|49152 - |53248|57344|61440) - DESCRIPTION - "The possible values defined by IEEE 802.1t." - - GROUP dot1dStpPortGroup2 - DESCRIPTION - "Implementation of this group is mandatory for - bridges that support the Spanning Tree Protocol." - - GROUP dot1dStpPortGroup3 - DESCRIPTION - "Implementation of this group is mandatory for bridges - that support the Spanning Tree Protocol and 32-bit path - costs. In particular, this includes devices supporting - IEEE 802.1t and IEEE 802.1w." - - OBJECT dot1dStpPortPriority - SYNTAX Integer32 (0|16|32|48|64|80|96|112|128 - |144|160|176|192|208|224|240) - DESCRIPTION - "The possible values defined by IEEE 802.1t." - - GROUP dot1dTpBridgeGroup - DESCRIPTION - "Implementation of this group is mandatory for - bridges that support the transparent bridging - mode. A transparent or SRT bridge will implement - this group." - - GROUP dot1dTpFdbGroup - DESCRIPTION - "Implementation of this group is mandatory for - bridges that support the transparent bridging - mode. A transparent or SRT bridge will implement - this group." - - GROUP dot1dTpGroup - DESCRIPTION - "Implementation of this group is mandatory for - bridges that support the transparent bridging - mode. A transparent or SRT bridge will implement - this group." - - GROUP dot1dStaticGroup - DESCRIPTION - "Implementation of this group is optional." - - GROUP dot1dNotificationGroup - DESCRIPTION - "Implementation of this group is optional." - - ::= { dot1dCompliances 2 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile b/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile deleted file mode 100644 index 5d0afec..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# -# $FreeBSD$ -# - -MOD= bridge -SRCS= bridge_snmp.c bridge_if.c bridge_port.c bridge_addrs.c \ - bridge_pf.c bridge_sys.c -CFLAGS+= -DSNMPTREE_TYPES - -XSYM= dot1dBridge newRoot topologyChange begemotBridgeNewRoot \ - begemotBridgeTopologyChange begemotBridgeBaseName - -MAN= snmp_bridge.3 - -BMIBS= BRIDGE-MIB.txt BEGEMOT-BRIDGE-MIB.txt RSTP-MIB.txt -DEFS= ${MOD}_tree.def -INCS= ${MOD}_snmp.h - -.include diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/RSTP-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_bridge/RSTP-MIB.txt deleted file mode 100644 index ea6648e..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/RSTP-MIB.txt +++ /dev/null @@ -1,325 +0,0 @@ --- --- Copyright (C) The Internet Society (2005). --- --- This document is subject to the rights, licenses and restrictions --- contained in BCP 78, and except as set forth therein, the authors --- retain all their rights. --- --- This document and the information contained herein are provided on an --- "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS --- OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY AND THE INTERNET --- ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, --- INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE --- INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED --- WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. --- --- $FreeBSD$ --- - -RSTP-MIB DEFINITIONS ::= BEGIN - --- ------------------------------------------------------------- --- MIB for IEEE 802.1w Rapid Spanning Tree Protocol --- ------------------------------------------------------------- - -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE, Integer32, mib-2 - FROM SNMPv2-SMI - TruthValue - FROM SNMPv2-TC - MODULE-COMPLIANCE, OBJECT-GROUP - FROM SNMPv2-CONF - dot1dStp, dot1dStpPortEntry - FROM BRIDGE-MIB; - -rstpMIB MODULE-IDENTITY - LAST-UPDATED "200512070000Z" - ORGANIZATION "IETF Bridge MIB Working Group" - CONTACT-INFO - "Email: Bridge-mib@ietf.org" - DESCRIPTION - "The Bridge MIB Extension module for managing devices - that support the Rapid Spanning Tree Protocol defined - by IEEE 802.1w. - - Copyright (C) The Internet Society (2005). This version of - this MIB module is part of RFC 4318; See the RFC itself for - full legal notices." - - REVISION "200512070000Z" - DESCRIPTION - "The initial version of this MIB module as published in - RFC 4318." - ::= { mib-2 134 } - --- ---------------------------------------------------------- -- --- subtrees in the RSTP-MIB --- ---------------------------------------------------------- -- - -rstpNotifications OBJECT IDENTIFIER ::= { rstpMIB 0 } -rstpObjects OBJECT IDENTIFIER ::= { rstpMIB 1 } -rstpConformance OBJECT IDENTIFIER ::= { rstpMIB 2 } - --- ------------------------------------------------------------- --- Addition to the dot1dStp group --- ------------------------------------------------------------- - -dot1dStpVersion OBJECT-TYPE - SYNTAX INTEGER { - stpCompatible(0), - rstp(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The version of Spanning Tree Protocol the bridge is - currently running. The value 'stpCompatible(0)' - indicates the Spanning Tree Protocol specified in - IEEE 802.1D-1998 and 'rstp(2)' indicates the Rapid - Spanning Tree Protocol specified in IEEE 802.1w and - clause 17 of 802.1D-2004. The values are directly from - the IEEE standard. New values may be defined as future - versions of the protocol become available. - - The value of this object MUST be retained across - reinitializations of the management system." - REFERENCE - "IEEE 802.1w clause 14.8.1, 17.12, 17.16.1" - DEFVAL { rstp } - ::= { dot1dStp 16 } - -dot1dStpTxHoldCount OBJECT-TYPE - SYNTAX Integer32 (1..10) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value used by the Port Transmit state machine to limit - the maximum transmission rate. - - The value of this object MUST be retained across - reinitializations of the management system." - - REFERENCE - "IEEE 802.1w clause 17.16.6" - DEFVAL { 3 } - ::= { dot1dStp 17 } - --- --- { dot1dStp 18 } was used to represent dot1dStpPathCostDefault --- in an earlier version of this MIB. It has since been --- obsoleted, and should not be used. --- - -dot1dStpExtPortTable OBJECT-TYPE - SYNTAX SEQUENCE OF Dot1dStpExtPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains port-specific Rapid Spanning Tree - information." - ::= { dot1dStp 19 } - -dot1dStpExtPortEntry OBJECT-TYPE - SYNTAX Dot1dStpExtPortEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of Rapid Spanning Tree information maintained by - each port." - AUGMENTS { dot1dStpPortEntry } - ::= { dot1dStpExtPortTable 1 } - -Dot1dStpExtPortEntry ::= - SEQUENCE { - dot1dStpPortProtocolMigration - TruthValue, - dot1dStpPortAdminEdgePort - TruthValue, - dot1dStpPortOperEdgePort - TruthValue, - dot1dStpPortAdminPointToPoint - INTEGER, - dot1dStpPortOperPointToPoint - TruthValue, - dot1dStpPortAdminPathCost - Integer32 - } - -dot1dStpPortProtocolMigration OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "When operating in RSTP (version 2) mode, writing true(1) - to this object forces this port to transmit RSTP BPDUs. - Any other operation on this object has no effect and - it always returns false(2) when read." - REFERENCE - "IEEE 802.1w clause 14.8.2.4, 17.18.10, 17.26" - ::= { dot1dStpExtPortEntry 1 } - -dot1dStpPortAdminEdgePort OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The administrative value of the Edge Port parameter. A - value of true(1) indicates that this port should be - assumed as an edge-port, and a value of false(2) indicates - that this port should be assumed as a non-edge-port. - Setting this object will also cause the corresponding - instance of dot1dStpPortOperEdgePort to change to the - same value. Note that even when this object's value - is true, the value of the corresponding instance of - dot1dStpPortOperEdgePort can be false if a BPDU has - been received. - - The value of this object MUST be retained across - reinitializations of the management system." - - REFERENCE - "IEEE 802.1t clause 14.8.2, 18.3.3" - ::= { dot1dStpExtPortEntry 2 } - -dot1dStpPortOperEdgePort OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operational value of the Edge Port parameter. The - object is initialized to the value of the corresponding - instance of dot1dStpPortAdminEdgePort. When the - corresponding instance of dot1dStpPortAdminEdgePort is - set, this object will be changed as well. This object - will also be changed to false on reception of a BPDU." - - REFERENCE - "IEEE 802.1t clause 14.8.2, 18.3.4" - ::= { dot1dStpExtPortEntry 3 } - -dot1dStpPortAdminPointToPoint OBJECT-TYPE - SYNTAX INTEGER { - forceTrue(0), - forceFalse(1), - auto(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The administrative point-to-point status of the LAN segment - attached to this port, using the enumeration values of the - IEEE 802.1w clause. A value of forceTrue(0) indicates - that this port should always be treated as if it is - connected to a point-to-point link. A value of - forceFalse(1) indicates that this port should be treated as - having a shared media connection. A value of auto(2) - indicates that this port is considered to have a - point-to-point link if it is an Aggregator and all of its - members are aggregatable, or if the MAC entity - is configured for full duplex operation, either through - auto-negotiation or by management means. Manipulating this - object changes the underlying adminPortToPortMAC. - - The value of this object MUST be retained across - reinitializations of the management system." - - REFERENCE - "IEEE 802.1w clause 6.4.3, 6.5, 14.8.2" - ::= { dot1dStpExtPortEntry 4 } - -dot1dStpPortOperPointToPoint OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operational point-to-point status of the LAN segment - attached to this port. It indicates whether a port is - considered to have a point-to-point connection. - If adminPointToPointMAC is set to auto(2), then the value - of operPointToPointMAC is determined in accordance with the - specific procedures defined for the MAC entity concerned, - as defined in IEEE 802.1w, clause 6.5. The value is - determined dynamically; that is, it is re-evaluated whenever - the value of adminPointToPointMAC changes, and whenever - the specific procedures defined for the MAC entity evaluate - a change in its point-to-point status." - REFERENCE - "IEEE 802.1w clause 6.4.3, 6.5, 14.8.2" - ::= { dot1dStpExtPortEntry 5 } - -dot1dStpPortAdminPathCost OBJECT-TYPE - SYNTAX Integer32 (0..200000000) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The administratively assigned value for the contribution - of this port to the path cost of paths toward the spanning - tree root. - - Writing a value of '0' assigns the automatically calculated - default Path Cost value to the port. If the default Path - Cost is being used, this object returns '0' when read. - - This complements the object dot1dStpPortPathCost or - dot1dStpPortPathCost32, which returns the operational value - of the path cost. - - The value of this object MUST be retained across - reinitializations of the management system." - REFERENCE - "IEEE 802.1D-1998: Section 8.5.5.3" - ::= { dot1dStpExtPortEntry 6 } - --- ------------------------------------------------------------- --- rstpMIB - Conformance Information --- ------------------------------------------------------------- - -rstpGroups OBJECT IDENTIFIER ::= { rstpConformance 1 } - -rstpCompliances OBJECT IDENTIFIER ::= { rstpConformance 2 } - --- ------------------------------------------------------------- --- Units of conformance --- ------------------------------------------------------------- - -rstpBridgeGroup OBJECT-GROUP - OBJECTS { - dot1dStpVersion, - dot1dStpTxHoldCount - } - STATUS current - DESCRIPTION - "Rapid Spanning Tree information for the bridge." - ::= { rstpGroups 1 } - -rstpPortGroup OBJECT-GROUP - OBJECTS { - dot1dStpPortProtocolMigration, - dot1dStpPortAdminEdgePort, - dot1dStpPortOperEdgePort, - dot1dStpPortAdminPointToPoint, - dot1dStpPortOperPointToPoint, - dot1dStpPortAdminPathCost - } - STATUS current - DESCRIPTION - "Rapid Spanning Tree information for individual ports." - ::= { rstpGroups 2 } - --- ------------------------------------------------------------- --- Compliance statements --- ------------------------------------------------------------- - -rstpCompliance MODULE-COMPLIANCE - STATUS current - DESCRIPTION - "The compliance statement for device support of Rapid - Spanning Tree Protocol (RSTP) bridging services." - MODULE - MANDATORY-GROUPS { - rstpBridgeGroup, - rstpPortGroup - } - ::= { rstpCompliances 1 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c deleted file mode 100644 index 781517f..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_addrs.c +++ /dev/null @@ -1,589 +0,0 @@ -/*- - * Copyright (c) 2006 Shteryana Shopova - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Bridge MIB implementation for SNMPd. - * Bridge addresses. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "bridge_tree.h" -#include "bridge_snmp.h" - -TAILQ_HEAD(tp_entries, tp_entry); - -/* - * Free the bridge address list. - */ -static void -bridge_tpe_free(struct tp_entries *headp) -{ - struct tp_entry *t; - - while ((t = TAILQ_FIRST(headp)) != NULL) { - TAILQ_REMOVE(headp, t, tp_e); - free(t); - } -} - -/* - * Free the bridge address entries from the address list, - * for the specified bridge interface only. - */ -static void -bridge_tpe_bif_free(struct tp_entries *headp, - struct bridge_if *bif) -{ - struct tp_entry *tp; - - while (bif->f_tpa != NULL && bif->sysindex == bif->f_tpa->sysindex) { - tp = TAILQ_NEXT(bif->f_tpa, tp_e); - TAILQ_REMOVE(headp, bif->f_tpa, tp_e); - free(bif->f_tpa); - bif->f_tpa = tp; - } -} - -/* - * Compare two mac addresses. - * m1 < m2 : -1 - * m1 > m2 : +1 - * m1 = m2 : 0 - */ -static int -bridge_compare_macs(const uint8_t *m1, const uint8_t *m2) -{ - int i; - - for (i = 0; i < ETHER_ADDR_LEN; i++) { - if (m1[i] < m2[i]) - return (-1); - if (m1[i] > m2[i]) - return (1); - } - - return (0); -} - -/* - * Insert an address entry in the bridge address TAILQ starting to search - * for its place from the position of the first bridge address for the bridge - * interface. Update the first bridge address if neccessary. - */ -static void -bridge_addrs_insert_at(struct tp_entries *headp, - struct tp_entry *ta, struct tp_entry **f_tpa) -{ - struct tp_entry *t1; - - assert(f_tpa != NULL); - - for (t1 = *f_tpa; - t1 != NULL && ta->sysindex == t1->sysindex; - t1 = TAILQ_NEXT(t1, tp_e)) { - if (bridge_compare_macs(ta->tp_addr, t1->tp_addr) < 0) { - TAILQ_INSERT_BEFORE(t1, ta, tp_e); - if (*f_tpa == t1) - (*f_tpa) = ta; - return; - } - } - - if (t1 == NULL) - TAILQ_INSERT_TAIL(headp, ta, tp_e); - else - TAILQ_INSERT_BEFORE(t1, ta, tp_e); -} - -/* - * Find an address entry's possition in the address list - * according to bridge interface name. - */ -static struct tp_entry * -bridge_addrs_find_pos(struct tp_entries *headp, uint32_t b_idx) -{ - uint32_t t_idx; - struct tp_entry *t1; - - if ((t1 = TAILQ_FIRST(headp)) == NULL || - bridge_compare_sysidx(b_idx, t1->sysindex) < 0) - return (NULL); - - t_idx = t1->sysindex; - - for (t1 = TAILQ_NEXT(t1, tp_e); t1 != NULL; t1 = TAILQ_NEXT(t1, tp_e)) { - - if (t1->sysindex != t_idx) { - if (bridge_compare_sysidx(b_idx, t1->sysindex) < 0) - return (TAILQ_PREV(t1, tp_entries, tp_e)); - else - t_idx = t1->sysindex; - } - } - - if (t1 == NULL) - t1 = TAILQ_LAST(headp, tp_entries); - - return (t1); -} - -/* - * Insert a bridge address in the bridge addresses list. - */ -static void -bridge_addrs_bif_insert(struct tp_entries *headp, struct tp_entry *te, - struct tp_entry **f_tpa) -{ - struct tp_entry *temp; - - if (*f_tpa != NULL) - bridge_addrs_insert_at(headp, te, f_tpa); - else { - temp = bridge_addrs_find_pos(headp, te->sysindex); - - if (temp == NULL) - TAILQ_INSERT_HEAD(headp, te, tp_e); - else - TAILQ_INSERT_AFTER(headp, temp, te, tp_e); - *f_tpa = te; - } -} - -static struct tp_entries tp_entries = TAILQ_HEAD_INITIALIZER(tp_entries); -static time_t address_list_age; - -void -bridge_addrs_update_listage(void) -{ - address_list_age = time(NULL); -} - -void -bridge_addrs_fini(void) -{ - bridge_tpe_free(&tp_entries); -} - -void -bridge_addrs_free(struct bridge_if *bif) -{ - bridge_tpe_bif_free(&tp_entries, bif); -} - -/* - * Find the first address in the list. - */ -static struct tp_entry * -bridge_addrs_first(void) -{ - return (TAILQ_FIRST(&tp_entries)); -} - -/* - * Find the next address in the list. - */ -static struct tp_entry * -bridge_addrs_next(struct tp_entry *te) -{ - return (TAILQ_NEXT(te, tp_e)); -} - -/* - * Find the first address, learnt by the specified bridge interface. - */ -struct tp_entry * -bridge_addrs_bif_first(struct bridge_if *bif) -{ - return (bif->f_tpa); -} - -/* - * Find the next address, learnt by the specified bridge interface. - */ -struct tp_entry * -bridge_addrs_bif_next(struct tp_entry *te) -{ - struct tp_entry *te_next; - - if ((te_next = TAILQ_NEXT(te, tp_e)) == NULL || - te_next->sysindex != te->sysindex) - return (NULL); - - return (te_next); -} - -/* - * Remove a bridge address from the list. - */ -void -bridge_addrs_remove(struct tp_entry *te, struct bridge_if *bif) -{ - if (bif->f_tpa == te) - bif->f_tpa = bridge_addrs_bif_next(te); - - TAILQ_REMOVE(&tp_entries, te, tp_e); - free(te); -} - -/* - * Allocate memory for a new bridge address and insert it in the list. - */ -struct tp_entry * -bridge_new_addrs(uint8_t *mac, struct bridge_if *bif) -{ - struct tp_entry *te; - - if ((te = (struct tp_entry *) malloc(sizeof(*te))) == NULL) { - syslog(LOG_ERR, "bridge new address: failed: %s", - strerror(errno)); - return (NULL); - } - - bzero(te, sizeof(*te)); - - te->sysindex = bif->sysindex; - bcopy(mac, te->tp_addr, ETHER_ADDR_LEN); - bridge_addrs_bif_insert(&tp_entries, te, &(bif->f_tpa)); - - return (te); -} - -/* - * Given a mac address, learnt on a bridge, - * find the corrsponding TP entry for it. - */ -struct tp_entry * -bridge_addrs_find(uint8_t *mac, struct bridge_if *bif) -{ - struct tp_entry *te; - - for (te = bif->f_tpa; te != NULL; te = TAILQ_NEXT(te, tp_e)) { - if (te->sysindex != bif->sysindex) { - te = NULL; - break; - } - - if (bridge_compare_macs(te->tp_addr, mac) == 0) - break; - } - - return (te); -} - -void -bridge_addrs_dump(struct bridge_if *bif) -{ - struct tp_entry *te; - - syslog(LOG_ERR, "Addresses count - %d", bif->num_addrs); - for (te = bridge_addrs_bif_first(bif); te != NULL; - te = bridge_addrs_bif_next(te)) { - syslog(LOG_ERR, "address %x:%x:%x:%x:%x:%x on port %d.%d", - te->tp_addr[0], te->tp_addr[1], te->tp_addr[2], - te->tp_addr[3], te->tp_addr[4], te->tp_addr[5], - te->sysindex, te->port_no); - } -} - -/* - * RFC4188 specifics. - */ - -/* - * Construct the SNMP index from the address DST Mac. - */ -static void -bridge_addrs_index_append(struct asn_oid *oid, uint sub, - const struct tp_entry *te) -{ - int i; - - oid->len = sub + ETHER_ADDR_LEN + 1; - oid->subs[sub] = ETHER_ADDR_LEN; - - for (i = 1; i <= ETHER_ADDR_LEN; i++) - oid->subs[sub + i] = te->tp_addr[i - 1]; -} - -/* - * Find the address entry for the SNMP index from the default bridge only. - */ -static struct tp_entry * -bridge_addrs_get(const struct asn_oid *oid, uint sub, - struct bridge_if *bif) -{ - int i; - uint8_t tp_addr[ETHER_ADDR_LEN]; - - if (oid->len - sub != ETHER_ADDR_LEN + 1 || - oid->subs[sub] != ETHER_ADDR_LEN) - return (NULL); - - for (i = 0; i < ETHER_ADDR_LEN; i++) - tp_addr[i] = oid->subs[sub + i + 1]; - - return (bridge_addrs_find(tp_addr, bif)); -} - -/* - * Find the next address entry for the SNMP index - * from the default bridge only. - */ -static struct tp_entry * -bridge_addrs_getnext(const struct asn_oid *oid, uint sub, - struct bridge_if *bif) -{ - int i; - uint8_t tp_addr[ETHER_ADDR_LEN]; - static struct tp_entry *te; - - if (oid->len - sub == 0) - return (bridge_addrs_bif_first(bif)); - - if (oid->len - sub != ETHER_ADDR_LEN + 1 || - oid->subs[sub] != ETHER_ADDR_LEN) - return (NULL); - - for (i = 0; i < ETHER_ADDR_LEN; i++) - tp_addr[i] = oid->subs[sub + i + 1]; - - if ((te = bridge_addrs_find(tp_addr, bif)) == NULL) - return (NULL); - - return (bridge_addrs_bif_next(te)); -} - -int -op_dot1d_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - struct tp_entry *te; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->addrs_age > bridge_get_data_maxage() && - bridge_update_addrs(bif) <= 0) - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - if ((te = bridge_addrs_get(&val->var, sub, bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((te = bridge_addrs_getnext(&val->var, sub, bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - bridge_addrs_index_append(&val->var, sub, te); - goto get; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - break; - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dTpFdbAddress: - return (string_get(val, te->tp_addr, ETHER_ADDR_LEN)); - case LEAF_dot1dTpFdbPort : - val->v.integer = te->port_no; - return (SNMP_ERR_NOERROR); - case LEAF_dot1dTpFdbStatus: - val->v.integer = te->status; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -/* - * Private BEGEMOT-BRIDGE-MIB specifics. - */ - -/* - * Construct the SNMP index from the bridge interface name - * and the address DST Mac. - */ -static int -bridge_addrs_begemot_index_append(struct asn_oid *oid, uint sub, - const struct tp_entry *te) -{ - uint i, n_len; - const char *b_name; - - if ((b_name = bridge_if_find_name(te->sysindex)) == NULL) - return (-1); - - n_len = strlen(b_name); - oid->len = sub++; - oid->subs[oid->len++] = n_len; - - for (i = 1; i <= n_len; i++) - oid->subs[oid->len++] = b_name[i - 1]; - - oid->subs[oid->len++] = ETHER_ADDR_LEN; - for (i = 1 ; i <= ETHER_ADDR_LEN; i++) - oid->subs[oid->len++] = te->tp_addr[i - 1]; - - return (0); -} - -/* - * Find a bridge address entry by the bridge interface name - * and the address DST Mac. - */ -static struct tp_entry * -bridge_addrs_begemot_get(const struct asn_oid *oid, uint sub) -{ - uint i, n_len; - uint8_t tp_addr[ETHER_ADDR_LEN]; - char bif_name[IFNAMSIZ]; - struct bridge_if *bif; - - n_len = oid->subs[sub]; - if (oid->len - sub != n_len + ETHER_ADDR_LEN + 3 || - n_len >= IFNAMSIZ || oid->subs[sub + n_len + 1] != ETHER_ADDR_LEN) - return (NULL); - - for (i = 0; i < n_len; i++) - bif_name[i] = oid->subs[n_len + i + 1]; - bif_name[i] = '\0'; - - for (i = 1; i <= ETHER_ADDR_LEN; i++) - tp_addr[i - 1] = oid->subs[n_len + i + 1]; - - if ((bif = bridge_if_find_ifname(bif_name)) == NULL) - return (NULL); - - return (bridge_addrs_find(tp_addr, bif)); -} - -/* - * Find the next bridge address entry by the bridge interface name - * and the address DST Mac. - */ -static struct tp_entry * -bridge_addrs_begemot_getnext(const struct asn_oid *oid, uint sub) -{ - uint i, n_len; - uint8_t tp_addr[ETHER_ADDR_LEN]; - char bif_name[IFNAMSIZ]; - struct bridge_if *bif; - struct tp_entry *tp; - - if (oid->len - sub == 0) - return (bridge_addrs_first()); - - n_len = oid->subs[sub]; - if (oid->len - sub != n_len + ETHER_ADDR_LEN + 2 || - n_len >= IFNAMSIZ || oid->subs[sub + n_len + 1] != ETHER_ADDR_LEN) - return (NULL); - - for (i = 1; i <= n_len; i++) - bif_name[i - 1] = oid->subs[sub + i]; - - bif_name[i - 1] = '\0'; - - for (i = 1; i <= ETHER_ADDR_LEN; i++) - tp_addr[i - 1] = oid->subs[sub + n_len + i + 1]; - - if ((bif = bridge_if_find_ifname(bif_name)) == NULL || - (tp = bridge_addrs_find(tp_addr, bif)) == NULL) - return (NULL); - - return (bridge_addrs_next(tp)); -} - -int -op_begemot_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct tp_entry *te; - - if (time(NULL) - address_list_age > bridge_get_data_maxage()) - bridge_update_all_addrs(); - - switch (op) { - case SNMP_OP_GET: - if ((te = bridge_addrs_begemot_get(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((te = bridge_addrs_begemot_getnext(&val->var, - sub)) == NULL || - bridge_addrs_begemot_index_append(&val->var, - sub, te) < 0) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - break; - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeTpFdbAddress: - return (string_get(val, te->tp_addr, ETHER_ADDR_LEN)); - case LEAF_begemotBridgeTpFdbPort: - val->v.integer = te->port_no; - return (SNMP_ERR_NOERROR); - case LEAF_begemotBridgeTpFdbStatus: - val->v.integer = te->status; - return (SNMP_ERR_NOERROR); - } - - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c deleted file mode 100644 index 4586e32..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_if.c +++ /dev/null @@ -1,1479 +0,0 @@ -/*- - * Copyright (c) 2006 Shteryana Shopova - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Bridge MIB implementation for SNMPd. - * Bridge interface objects. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include "bridge_tree.h" -#include "bridge_snmp.h" -#include "bridge_oid.h" - -static const struct asn_oid oid_newRoot = OIDX_newRoot; -static const struct asn_oid oid_TopologyChange = OIDX_topologyChange; -static const struct asn_oid oid_begemotBrigeName = \ - OIDX_begemotBridgeBaseName; -static const struct asn_oid oid_begemotNewRoot = OIDX_begemotBridgeNewRoot; -static const struct asn_oid oid_begemotTopologyChange = \ - OIDX_begemotBridgeTopologyChange; - -TAILQ_HEAD(bridge_ifs, bridge_if); - -/* - * Free the bridge interface list. - */ -static void -bridge_ifs_free(struct bridge_ifs *headp) -{ - struct bridge_if *b; - - while ((b = TAILQ_FIRST(headp)) != NULL) { - TAILQ_REMOVE(headp, b, b_if); - free(b); - } -} - -/* - * Insert an entry in the bridge interface TAILQ. Keep the - * TAILQ sorted by the bridge's interface name. - */ -static void -bridge_ifs_insert(struct bridge_ifs *headp, - struct bridge_if *b) -{ - struct bridge_if *temp; - - if ((temp = TAILQ_FIRST(headp)) == NULL || - strcmp(b->bif_name, temp->bif_name) < 0) { - TAILQ_INSERT_HEAD(headp, b, b_if); - return; - } - - TAILQ_FOREACH(temp, headp, b_if) - if(strcmp(b->bif_name, temp->bif_name) < 0) - TAILQ_INSERT_BEFORE(temp, b, b_if); - - TAILQ_INSERT_TAIL(headp, b, b_if); -} - -/* The global bridge interface list. */ -static struct bridge_ifs bridge_ifs = TAILQ_HEAD_INITIALIZER(bridge_ifs); -static time_t bridge_list_age; - -/* - * Free the global list. - */ -void -bridge_ifs_fini(void) -{ - bridge_ifs_free(&bridge_ifs); -} - -/* - * Find a bridge interface entry by the bridge interface system index. - */ -struct bridge_if * -bridge_if_find_ifs(uint32_t sysindex) -{ - struct bridge_if *b; - - TAILQ_FOREACH(b, &bridge_ifs, b_if) - if (b->sysindex == sysindex) - return (b); - - return (NULL); -} - -/* - * Find a bridge interface entry by the bridge interface name. - */ -struct bridge_if * -bridge_if_find_ifname(const char *b_name) -{ - struct bridge_if *b; - - TAILQ_FOREACH(b, &bridge_ifs, b_if) - if (strcmp(b_name, b->bif_name) == 0) - return (b); - - return (NULL); -} - -/* - * Find a bridge name by the bridge interface system index. - */ -const char * -bridge_if_find_name(uint32_t sysindex) -{ - struct bridge_if *b; - - TAILQ_FOREACH(b, &bridge_ifs, b_if) - if (b->sysindex == sysindex) - return (b->bif_name); - - return (NULL); -} - -/* - * Given two bridge interfaces' system indexes, find their - * corresponding names and return the result of the name - * comparison. Returns: - * error : -2 - * i1 < i2 : -1 - * i1 > i2 : +1 - * i1 = i2 : 0 - */ -int -bridge_compare_sysidx(uint32_t i1, uint32_t i2) -{ - int c; - const char *b1, *b2; - - if (i1 == i2) - return (0); - - if ((b1 = bridge_if_find_name(i1)) == NULL) { - syslog(LOG_ERR, "Bridge interface %d does not exist", i1); - return (-2); - } - - if ((b2 = bridge_if_find_name(i2)) == NULL) { - syslog(LOG_ERR, "Bridge interface %d does not exist", i2); - return (-2); - } - - if ((c = strcmp(b1, b2)) < 0) - return (-1); - else if (c > 0) - return (1); - - return (0); -} - -/* - * Fetch the first bridge interface from the list. - */ -struct bridge_if * -bridge_first_bif(void) -{ - return (TAILQ_FIRST(&bridge_ifs)); -} - -/* - * Fetch the next bridge interface from the list. - */ -struct bridge_if * -bridge_next_bif(struct bridge_if *b_pr) -{ - return (TAILQ_NEXT(b_pr, b_if)); -} - -/* - * Create a new entry for a bridge interface and insert - * it in the list. - */ -static struct bridge_if * -bridge_new_bif(const char *bif_n, uint32_t sysindex, const u_char *physaddr) -{ - struct bridge_if *bif; - - if ((bif = (struct bridge_if *) malloc(sizeof(*bif)))== NULL) { - syslog(LOG_ERR, "bridge new interface failed: %s", - strerror(errno)); - return (NULL); - } - - bzero(bif, sizeof(struct bridge_if)); - strlcpy(bif->bif_name, bif_n, IFNAMSIZ); - bcopy(physaddr, bif->br_addr.octet, ETHER_ADDR_LEN); - bif->sysindex = sysindex; - bif->br_type = BaseType_transparent_only; - /* 1 - all bridges default hold time * 100 - centi-seconds */ - bif->hold_time = 1 * 100; - bif->prot_spec = dot1dStpProtocolSpecification_ieee8021d; - bridge_ifs_insert(&bridge_ifs, bif); - - return (bif); -} - -/* - * Remove a bridge interface from the list, freeing all it's ports - * and address entries. - */ -void -bridge_remove_bif(struct bridge_if *bif) -{ - bridge_members_free(bif); - bridge_addrs_free(bif); - TAILQ_REMOVE(&bridge_ifs, bif, b_if); - free(bif); -} - - -/* - * Prepare the variable (bridge interface name) for the private - * begemot notifications. - */ -static struct snmp_value* -bridge_basename_var(struct bridge_if *bif, struct snmp_value* b_val) -{ - uint i; - - b_val->var = oid_begemotBrigeName; - b_val->var.subs[b_val->var.len++] = strlen(bif->bif_name); - - if ((b_val->v.octetstring.octets = (u_char *) - malloc(strlen(bif->bif_name))) == NULL) - return (NULL); - - for (i = 0; i < strlen(bif->bif_name); i++) - b_val->var.subs[b_val->var.len++] = bif->bif_name[i]; - - b_val->v.octetstring.len = strlen(bif->bif_name); - bcopy(bif->bif_name, b_val->v.octetstring.octets, - strlen(bif->bif_name)); - b_val->syntax = SNMP_SYNTAX_OCTETSTRING; - - return (b_val); -} - -/* - * Compare the values of the old and the new root port and - * send a new root notification, if they are not matching. - */ -static void -bridge_new_root(struct bridge_if *bif) -{ - struct snmp_value bif_idx; - - if (bridge_get_default() == bif) - snmp_send_trap(&oid_newRoot, (struct snmp_value *) NULL); - - if (bridge_basename_var(bif, &bif_idx) == NULL) - return; - - snmp_send_trap(&oid_begemotTopologyChange, - &bif_idx, (struct snmp_value *) NULL); -} - -/* - * Compare the new and old topology change times and send a - * topology change notification if necessary. - */ -static void -bridge_top_change(struct bridge_if *bif) -{ - struct snmp_value bif_idx; - - if (bridge_get_default() == bif) - snmp_send_trap(&oid_TopologyChange, - (struct snmp_value *) NULL); - - if (bridge_basename_var(bif, &bif_idx) == NULL) - return; - - snmp_send_trap(&oid_begemotNewRoot, - &bif_idx, (struct snmp_value *) NULL); -} - -static int -bridge_if_create(const char* b_name, int8_t up) -{ - if (bridge_create(b_name) < 0) - return (-1); - - if (up == 1 && (bridge_set_if_up(b_name, 1) < 0)) - return (-1); - - /* - * Do not create a new bridge entry here - - * wait until the mibII module notifies us. - */ - return (0); -} - -static int -bridge_if_destroy(struct bridge_if *bif) -{ - if (bridge_destroy(bif->bif_name) < 0) - return (-1); - - bridge_remove_bif(bif); - - return (0); -} - -/* - * Calculate the timeticks since the last topology change. - */ -static int -bridge_get_time_since_tc(struct bridge_if *bif, uint32_t *ticks) -{ - struct timeval ct; - - if (gettimeofday(&ct, NULL) < 0) { - syslog(LOG_ERR, "bridge get time since last TC:" - "getttimeofday failed: %s", strerror(errno)); - return (-1); - } - - if (ct.tv_usec - bif->last_tc_time.tv_usec < 0) { - ct.tv_sec -= 1; - ct.tv_usec += 1000000; - } - - ct.tv_sec -= bif->last_tc_time.tv_sec; - ct.tv_usec -= bif->last_tc_time.tv_usec; - - *ticks = ct.tv_sec * 100 + ct.tv_usec/10000; - - return (0); -} - -/* - * Update the info we have for a single bridge interface. - * Return: - * 1, if successful - * 0, if the interface was deleted - * -1, error occured while fetching the info from the kernel. - */ -static int -bridge_update_bif(struct bridge_if *bif) -{ - struct mibif *ifp; - - /* Walk through the mibII interface list. */ - for (ifp = mib_first_if(); ifp != NULL; ifp = mib_next_if(ifp)) - if (strcmp(ifp->name, bif->bif_name) == 0) - break; - - if (ifp == NULL) { - /* Ops, we do not exist anymore. */ - bridge_remove_bif(bif); - return (0); - } - - if (ifp->physaddr != NULL ) - bcopy(ifp->physaddr, bif->br_addr.octet, ETHER_ADDR_LEN); - else - bridge_get_basemac(bif->bif_name, bif->br_addr.octet, - ETHER_ADDR_LEN); - - if (ifp->mib.ifmd_flags & IFF_RUNNING) - bif->if_status = RowStatus_active; - else - bif->if_status = RowStatus_notInService; - - switch (bridge_getinfo_bif(bif)) { - case 2: - bridge_new_root(bif); - break; - case 1: - bridge_top_change(bif); - break; - case -1: - bridge_remove_bif(bif); - return (-1); - default: - break; - } - - /* - * The number of ports is accessible via SNMP - - * update the ports each time the bridge interface data - * is refreshed too. - */ - bif->num_ports = bridge_update_memif(bif); - bif->entry_age = time(NULL); - - return (1); -} - -/* - * Update all bridge interfaces' ports only - - * make sure each bridge interface exists first. - */ -void -bridge_update_all_ports(void) -{ - struct mibif *ifp; - struct bridge_if *bif, *t_bif; - - for (bif = bridge_first_bif(); bif != NULL; bif = t_bif) { - t_bif = bridge_next_bif(bif); - - for (ifp = mib_first_if(); ifp != NULL; - ifp = mib_next_if(ifp)) - if (strcmp(ifp->name, bif->bif_name) == 0) - break; - - if (ifp != NULL) - bif->num_ports = bridge_update_memif(bif); - else /* Ops, we do not exist anymore. */ - bridge_remove_bif(bif); - } - - bridge_ports_update_listage(); -} - -/* - * Update all addresses only. - */ -void -bridge_update_all_addrs(void) -{ - struct mibif *ifp; - struct bridge_if *bif, *t_bif; - - for (bif = bridge_first_bif(); bif != NULL; bif = t_bif) { - t_bif = bridge_next_bif(bif); - - for (ifp = mib_first_if(); ifp != NULL; - ifp = mib_next_if(ifp)) - if (strcmp(ifp->name, bif->bif_name) == 0) - break; - - if (ifp != NULL) - bif->num_addrs = bridge_update_addrs(bif); - else /* Ops, we don't exist anymore. */ - bridge_remove_bif(bif); - } - - bridge_addrs_update_listage(); -} - -/* - * Update only the bridge interfaces' data - skip addresses. - */ -void -bridge_update_all_ifs(void) -{ - struct bridge_if *bif, *t_bif; - - for (bif = bridge_first_bif(); bif != NULL; bif = t_bif) { - t_bif = bridge_next_bif(bif); - bridge_update_bif(bif); - } - - bridge_ports_update_listage(); - bridge_list_age = time(NULL); -} - -/* - * Update all info we have for all bridges. - */ -void -bridge_update_all(void *arg __unused) -{ - struct bridge_if *bif, *t_bif; - - for (bif = bridge_first_bif(); bif != NULL; bif = t_bif) { - t_bif = bridge_next_bif(bif); - if (bridge_update_bif(bif) <= 0) - continue; - - /* Update our learnt addresses. */ - bif->num_addrs = bridge_update_addrs(bif); - } - - bridge_list_age = time(NULL); - bridge_ports_update_listage(); - bridge_addrs_update_listage(); -} - -/* - * Callback for polling our last topology change time - - * check whether we are root or whether a TC was detected once every - * 30 seconds, so that we can send the newRoot and TopologyChange traps - * on time. The rest of the data is polled only once every 5 min. - */ -void -bridge_update_tc_time(void *arg __unused) -{ - struct bridge_if *bif; - struct mibif *ifp; - - TAILQ_FOREACH(bif, &bridge_ifs, b_if) { - /* Walk through the mibII interface list. */ - for (ifp = mib_first_if(); ifp != NULL; ifp = mib_next_if(ifp)) - if (strcmp(ifp->name, bif->bif_name) == 0) - break; - - if (ifp == NULL) { - bridge_remove_bif(bif); - continue; - } - - switch (bridge_get_op_param(bif)) { - case 2: - bridge_new_root(bif); - break; - case 1: - bridge_top_change(bif); - break; - } - } -} - -/* - * Callback for handling new bridge interface creation. - */ -int -bridge_attach_newif(struct mibif *ifp) -{ - u_char mac[ETHER_ADDR_LEN]; - struct bridge_if *bif; - - if (ifp->mib.ifmd_data.ifi_type != IFT_BRIDGE) - return (0); - - /* Make sure it does not exist in our list. */ - TAILQ_FOREACH(bif, &bridge_ifs, b_if) - if(strcmp(bif->bif_name, ifp->name) == 0) { - syslog(LOG_ERR, "bridge interface %s already " - "in list", bif->bif_name); - return (-1); - } - - if (ifp->physaddr == NULL) { - if (bridge_get_basemac(ifp->name, mac, sizeof(mac)) == NULL) { - syslog(LOG_ERR, "bridge attach new %s failed - " - "no bridge mac address", ifp->name); - return (-1); - } - } else - bcopy(ifp->physaddr, &mac, sizeof(mac)); - - if ((bif = bridge_new_bif(ifp->name, ifp->sysindex, mac)) == NULL) - return (-1); - - if (ifp->mib.ifmd_flags & IFF_RUNNING) - bif->if_status = RowStatus_active; - else - bif->if_status = RowStatus_notInService; - - /* Skip sending notifications if the interface was just created. */ - if (bridge_getinfo_bif(bif) < 0 || - (bif->num_ports = bridge_getinfo_bif_ports(bif)) < 0 || - (bif->num_addrs = bridge_getinfo_bif_addrs(bif)) < 0) { - bridge_remove_bif(bif); - return (-1); - } - - /* Check whether we are the default bridge interface. */ - if (strcmp(ifp->name, bridge_get_default_name()) == 0) - bridge_set_default(bif); - - return (0); -} - -void -bridge_ifs_dump(void) -{ - struct bridge_if *bif; - - for (bif = bridge_first_bif(); bif != NULL; - bif = bridge_next_bif(bif)) { - syslog(LOG_ERR, "Bridge %s, index - %d", bif->bif_name, - bif->sysindex); - bridge_ports_dump(bif); - bridge_addrs_dump(bif); - } -} - -/* - * RFC4188 specifics. - */ -int -op_dot1d_base(struct snmp_context *ctx __unused, struct snmp_value *value, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->entry_age > bridge_get_data_maxage() && - bridge_update_bif(bif) <= 0) /* It was just deleted. */ - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - switch (value->var.subs[sub - 1]) { - case LEAF_dot1dBaseBridgeAddress: - return (string_get(value, bif->br_addr.octet, - ETHER_ADDR_LEN)); - case LEAF_dot1dBaseNumPorts: - value->v.integer = bif->num_ports; - return (SNMP_ERR_NOERROR); - case LEAF_dot1dBaseType: - value->v.integer = bif->br_type; - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_GETNEXT: - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - break; - } - - abort(); -} - -int -op_dot1d_stp(struct snmp_context *ctx, struct snmp_value *val, uint sub, - uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->entry_age > bridge_get_data_maxage() && - bridge_update_bif(bif) <= 0) /* It was just deleted. */ - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpProtocolSpecification: - val->v.integer = bif->prot_spec; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPriority: - val->v.integer = bif->priority; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpTimeSinceTopologyChange: - if (bridge_get_time_since_tc(bif, - &(val->v.uint32)) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpTopChanges: - val->v.uint32 = bif->top_changes; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpDesignatedRoot: - return (string_get(val, bif->design_root, - SNMP_BRIDGE_ID_LEN)); - - case LEAF_dot1dStpRootCost: - val->v.integer = bif->root_cost; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpRootPort: - val->v.integer = bif->root_port; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpMaxAge: - val->v.integer = bif->max_age; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpHelloTime: - val->v.integer = bif->hello_time; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpHoldTime: - val->v.integer = bif->hold_time; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpForwardDelay: - val->v.integer = bif->fwd_delay; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpBridgeMaxAge: - val->v.integer = bif->bridge_max_age; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpBridgeHelloTime: - val->v.integer = bif->bridge_hello_time; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpBridgeForwardDelay: - val->v.integer = bif->bridge_fwd_delay; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpVersion: - val->v.integer = bif->stp_version; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpTxHoldCount: - val->v.integer = bif->tx_hold_count; - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_SET: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPriority: - if (val->v.integer > SNMP_BRIDGE_MAX_PRIORITY || - val->v.integer % 4096 != 0) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->priority; - if (bridge_set_priority(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpBridgeMaxAge: - if (val->v.integer < SNMP_BRIDGE_MIN_MAGE || - val->v.integer > SNMP_BRIDGE_MAX_MAGE) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->bridge_max_age; - if (bridge_set_maxage(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpBridgeHelloTime: - if (val->v.integer < SNMP_BRIDGE_MIN_HTIME || - val->v.integer > SNMP_BRIDGE_MAX_HTIME) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->bridge_hello_time; - if (bridge_set_hello_time(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpBridgeForwardDelay: - if (val->v.integer < SNMP_BRIDGE_MIN_FDELAY || - val->v.integer > SNMP_BRIDGE_MAX_FDELAY) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->bridge_fwd_delay; - if (bridge_set_forward_delay(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpVersion: - if (val->v.integer != dot1dStpVersion_stpCompatible && - val->v.integer != dot1dStpVersion_rstp) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->stp_version; - if (bridge_set_stp_version(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpTxHoldCount: - if (val->v.integer < SNMP_BRIDGE_MIN_TXHC || - val->v.integer > SNMP_BRIDGE_MAX_TXHC) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->tx_hold_count; - if (bridge_set_tx_hold_count(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpProtocolSpecification: - case LEAF_dot1dStpTimeSinceTopologyChange: - case LEAF_dot1dStpTopChanges: - case LEAF_dot1dStpDesignatedRoot: - case LEAF_dot1dStpRootCost: - case LEAF_dot1dStpRootPort: - case LEAF_dot1dStpMaxAge: - case LEAF_dot1dStpHelloTime: - case LEAF_dot1dStpHoldTime: - case LEAF_dot1dStpForwardDelay: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPriority: - bridge_set_priority(bif, ctx->scratch->int1); - break; - case LEAF_dot1dStpBridgeMaxAge: - bridge_set_maxage(bif, ctx->scratch->int1); - break; - case LEAF_dot1dStpBridgeHelloTime: - bridge_set_hello_time(bif, ctx->scratch->int1); - break; - case LEAF_dot1dStpBridgeForwardDelay: - bridge_set_forward_delay(bif, ctx->scratch->int1); - break; - case LEAF_dot1dStpVersion: - bridge_set_stp_version(bif, ctx->scratch->int1); - break; - case LEAF_dot1dStpTxHoldCount: - bridge_set_tx_hold_count(bif, ctx->scratch->int1); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_dot1d_tp(struct snmp_context *ctx, struct snmp_value *value, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->entry_age > bridge_get_data_maxage() && - bridge_update_bif(bif) <= 0) /* It was just deleted. */ - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - switch (value->var.subs[sub - 1]) { - case LEAF_dot1dTpLearnedEntryDiscards: - value->v.uint32 = bif->lrnt_drops; - return (SNMP_ERR_NOERROR); - case LEAF_dot1dTpAgingTime: - value->v.integer = bif->age_time; - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_SET: - switch (value->var.subs[sub - 1]) { - case LEAF_dot1dTpLearnedEntryDiscards: - return (SNMP_ERR_NOT_WRITEABLE); - - case LEAF_dot1dTpAgingTime: - if (value->v.integer < SNMP_BRIDGE_MIN_AGE_TIME || - value->v.integer > SNMP_BRIDGE_MAX_AGE_TIME) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->age_time; - if (bridge_set_aging_time(bif, value->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_ROLLBACK: - if (value->var.subs[sub - 1] == LEAF_dot1dTpAgingTime) - bridge_set_aging_time(bif, ctx->scratch->int1); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -/* - * Private BEGEMOT-BRIDGE-MIB specifics. - */ - -/* - * Get the bridge name from an OID index. - */ -static char * -bridge_name_index_get(const struct asn_oid *oid, uint sub, char *b_name) -{ - uint i; - - if (oid->len - sub != oid->subs[sub] + 1 || oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - for (i = 0; i < oid->subs[sub]; i++) - b_name[i] = oid->subs[sub + i + 1]; - b_name[i] = '\0'; - - return (b_name); -} - -static void -bridge_if_index_append(struct asn_oid *oid, uint sub, - const struct bridge_if *bif) -{ - uint i; - - oid->len = sub + strlen(bif->bif_name) + 1; - oid->subs[sub] = strlen(bif->bif_name); - - for (i = 1; i <= strlen(bif->bif_name); i++) - oid->subs[sub + i] = bif->bif_name[i - 1]; -} - -static struct bridge_if * -bridge_if_index_get(const struct asn_oid *oid, uint sub) -{ - uint i; - char bif_name[IFNAMSIZ]; - - if (oid->len - sub != oid->subs[sub] + 1 || oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - for (i = 0; i < oid->subs[sub]; i++) - bif_name[i] = oid->subs[sub + i + 1]; - bif_name[i] = '\0'; - - return (bridge_if_find_ifname(bif_name)); -} - -static struct bridge_if * -bridge_if_index_getnext(const struct asn_oid *oid, uint sub) -{ - uint i; - char bif_name[IFNAMSIZ]; - struct bridge_if *bif; - - if (oid->len - sub == 0) - return (bridge_first_bif()); - - if (oid->len - sub != oid->subs[sub] + 1 || oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - for (i = 0; i < oid->subs[sub]; i++) - bif_name[i] = oid->subs[sub + i + 1]; - bif_name[i] = '\0'; - - if ((bif = bridge_if_find_ifname(bif_name)) == NULL) - return (NULL); - - return (bridge_next_bif(bif)); -} - -static int -bridge_set_if_status(struct snmp_context *ctx, - struct snmp_value *val, uint sub) -{ - struct bridge_if *bif; - char bif_name[IFNAMSIZ]; - - bif = bridge_if_index_get(&val->var, sub); - - switch (val->v.integer) { - case RowStatus_active: - if (bif == NULL) - return (SNMP_ERR_INCONS_VALUE); - - ctx->scratch->int1 = bif->if_status; - - switch (bif->if_status) { - case RowStatus_active: - return (SNMP_ERR_NOERROR); - case RowStatus_notInService: - if (bridge_set_if_up(bif->bif_name, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - default: - break; - } - return (SNMP_ERR_INCONS_VALUE); - - case RowStatus_notInService: - if (bif == NULL) - return (SNMP_ERR_INCONS_VALUE); - - ctx->scratch->int1 = bif->if_status; - - switch (bif->if_status) { - case RowStatus_active: - if (bridge_set_if_up(bif->bif_name, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - case RowStatus_notInService: - return (SNMP_ERR_NOERROR); - default: - break; - } - return (SNMP_ERR_INCONS_VALUE); - - case RowStatus_notReady: - return (SNMP_ERR_INCONS_VALUE); - - case RowStatus_createAndGo: - if (bif != NULL) - return (SNMP_ERR_INCONS_VALUE); - - ctx->scratch->int1 = RowStatus_destroy; - - if (bridge_name_index_get(&val->var, sub, bif_name) == NULL) - return (SNMP_ERR_BADVALUE); - if (bridge_if_create(bif_name, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case RowStatus_createAndWait: - if (bif != NULL) - return (SNMP_ERR_INCONS_VALUE); - - if (bridge_name_index_get(&val->var, sub, bif_name) == NULL) - return (SNMP_ERR_BADVALUE); - - ctx->scratch->int1 = RowStatus_destroy; - - if (bridge_if_create(bif_name, 0) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case RowStatus_destroy: - if (bif == NULL) - return (SNMP_ERR_NOSUCHNAME); - - ctx->scratch->int1 = bif->if_status; - bif->if_status = RowStatus_destroy; - } - - return (SNMP_ERR_NOERROR); -} - -static int -bridge_rollback_if_status(struct snmp_context *ctx, - struct snmp_value *val, uint sub) -{ - struct bridge_if *bif; - - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_GENERR); - - switch (ctx->scratch->int1) { - case RowStatus_destroy: - bridge_if_destroy(bif); - return (SNMP_ERR_NOERROR); - - case RowStatus_notInService: - if (bif->if_status != ctx->scratch->int1) - bridge_set_if_up(bif->bif_name, 0); - bif->if_status = RowStatus_notInService; - return (SNMP_ERR_NOERROR); - - case RowStatus_active: - if (bif->if_status != ctx->scratch->int1) - bridge_set_if_up(bif->bif_name, 1); - bif->if_status = RowStatus_active; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -static int -bridge_commit_if_status(struct snmp_value *val, uint sub) -{ - struct bridge_if *bif; - - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_GENERR); - - if (bif->if_status == RowStatus_destroy && - bridge_if_destroy(bif) < 0) - return (SNMP_ERR_COMMIT_FAILED); - - return (SNMP_ERR_NOERROR); -} - -int -op_begemot_base_bridge(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - - if (time(NULL) - bridge_list_age > bridge_get_data_maxage()) - bridge_update_all_ifs(); - - switch (op) { - case SNMP_OP_GET: - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((bif = bridge_if_index_getnext(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - bridge_if_index_append(&val->var, sub, bif); - goto get; - - case SNMP_OP_SET: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeBaseStatus: - return (bridge_set_if_status(ctx, val, sub)); - case LEAF_begemotBridgeBaseName: - case LEAF_begemotBridgeBaseAddress: - case LEAF_begemotBridgeBaseNumPorts: - case LEAF_begemotBridgeBaseType: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - return (bridge_rollback_if_status(ctx, val, sub)); - - case SNMP_OP_COMMIT: - return (bridge_commit_if_status(val, sub)); - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeBaseName: - return (string_get(val, bif->bif_name, -1)); - - case LEAF_begemotBridgeBaseAddress: - return (string_get(val, bif->br_addr.octet, ETHER_ADDR_LEN)); - - case LEAF_begemotBridgeBaseNumPorts: - val->v.integer = bif->num_ports; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBaseType: - val->v.integer = bif->br_type; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBaseStatus: - val->v.integer = bif->if_status; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - - if (time(NULL) - bridge_list_age > bridge_get_data_maxage()) - bridge_update_all_ifs(); - - switch (op) { - case SNMP_OP_GET: - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((bif = bridge_if_index_getnext(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - bridge_if_index_append(&val->var, sub, bif); - goto get; - - case SNMP_OP_SET: - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPriority: - if (val->v.integer > SNMP_BRIDGE_MAX_PRIORITY || - val->v.integer % 4096 != 0) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->priority; - if (bridge_set_priority(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpBridgeMaxAge: - if (val->v.integer < SNMP_BRIDGE_MIN_MAGE || - val->v.integer > SNMP_BRIDGE_MAX_MAGE) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->bridge_max_age; - if (bridge_set_maxage(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpBridgeHelloTime: - if (val->v.integer < SNMP_BRIDGE_MIN_HTIME || - val->v.integer > SNMP_BRIDGE_MAX_HTIME) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->bridge_hello_time; - if (bridge_set_hello_time(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpBridgeForwardDelay: - if (val->v.integer < SNMP_BRIDGE_MIN_FDELAY || - val->v.integer > SNMP_BRIDGE_MAX_FDELAY) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->bridge_fwd_delay; - if (bridge_set_forward_delay(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpVersion: - if (val->v.integer != - begemotBridgeStpVersion_stpCompatible && - val->v.integer != begemotBridgeStpVersion_rstp) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->stp_version; - if (bridge_set_stp_version(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpTxHoldCount: - if (val->v.integer < SNMP_BRIDGE_MIN_TXHC || - val->v.integer > SNMP_BRIDGE_MAX_TXHC) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->tx_hold_count; - if (bridge_set_tx_hold_count(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpProtocolSpecification: - case LEAF_begemotBridgeStpTimeSinceTopologyChange: - case LEAF_begemotBridgeStpTopChanges: - case LEAF_begemotBridgeStpDesignatedRoot: - case LEAF_begemotBridgeStpRootCost: - case LEAF_begemotBridgeStpRootPort: - case LEAF_begemotBridgeStpMaxAge: - case LEAF_begemotBridgeStpHelloTime: - case LEAF_begemotBridgeStpHoldTime: - case LEAF_begemotBridgeStpForwardDelay: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPriority: - bridge_set_priority(bif, ctx->scratch->int1); - break; - - case LEAF_begemotBridgeStpBridgeMaxAge: - bridge_set_maxage(bif, ctx->scratch->int1); - break; - - case LEAF_begemotBridgeStpBridgeHelloTime: - bridge_set_hello_time(bif, ctx->scratch->int1); - break; - - case LEAF_begemotBridgeStpBridgeForwardDelay: - bridge_set_forward_delay(bif, ctx->scratch->int1); - break; - - case LEAF_begemotBridgeStpVersion: - bridge_set_stp_version(bif, ctx->scratch->int1); - break; - - case LEAF_begemotBridgeStpTxHoldCount: - bridge_set_tx_hold_count(bif, ctx->scratch->int1); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpProtocolSpecification: - val->v.integer = bif->prot_spec; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPriority: - val->v.integer = bif->priority; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpTimeSinceTopologyChange: - if (bridge_get_time_since_tc(bif, &(val->v.uint32)) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpTopChanges: - val->v.uint32 = bif->top_changes; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpDesignatedRoot: - return (string_get(val, bif->design_root, SNMP_BRIDGE_ID_LEN)); - - case LEAF_begemotBridgeStpRootCost: - val->v.integer = bif->root_cost; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpRootPort: - val->v.integer = bif->root_port; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpMaxAge: - val->v.integer = bif->max_age; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpHelloTime: - val->v.integer = bif->hello_time; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpHoldTime: - val->v.integer = bif->hold_time; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpForwardDelay: - val->v.integer = bif->fwd_delay; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpBridgeMaxAge: - val->v.integer = bif->bridge_max_age; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpBridgeHelloTime: - val->v.integer = bif->bridge_hello_time; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpBridgeForwardDelay: - val->v.integer = bif->bridge_fwd_delay; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpVersion: - val->v.integer = bif->stp_version; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpTxHoldCount: - val->v.integer = bif->tx_hold_count; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_begemot_tp(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - - if (time(NULL) - bridge_list_age > bridge_get_data_maxage()) - bridge_update_all_ifs(); - - switch (op) { - case SNMP_OP_GET: - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((bif = bridge_if_index_getnext(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - bridge_if_index_append(&val->var, sub, bif); - goto get; - - case SNMP_OP_SET: - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeTpAgingTime: - if (val->v.integer < SNMP_BRIDGE_MIN_AGE_TIME || - val->v.integer > SNMP_BRIDGE_MAX_AGE_TIME) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bif->age_time; - if (bridge_set_aging_time(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpMaxAddresses: - ctx->scratch->int1 = bif->max_addrs; - if (bridge_set_max_cache(bif, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpLearnedEntryDiscards: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - if ((bif = bridge_if_index_get(&val->var, sub)) == NULL) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeTpAgingTime: - bridge_set_aging_time(bif, ctx->scratch->int1); - break; - - case LEAF_begemotBridgeTpMaxAddresses: - bridge_set_max_cache(bif, ctx->scratch->int1); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeTpLearnedEntryDiscards: - val->v.uint32 = bif->lrnt_drops; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpAgingTime: - val->v.integer = bif->age_time; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpMaxAddresses: - val->v.integer = bif->max_addrs; - return (SNMP_ERR_NOERROR); - } - - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c deleted file mode 100644 index 0ad8cbf..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_pf.c +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * Copyright (c) 2006 Shteryana Shopova - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Bridge MIB implementation for SNMPd. - * Bridge pfil controls. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include "bridge_tree.h" -#include "bridge_snmp.h" - -static int -val2snmp_truth(uint8_t val) -{ - if (val == 0) - return (2); - - return (1); -} - -static int -snmp_truth2val(int32_t truth) -{ - if (truth == 2) - return (0); - else if (truth == 1) - return (1); - - return (-1); -} - -int -op_begemot_bridge_pf(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - int k_val; - - if (val->var.subs[sub - 1] > LEAF_begemotBridgeLayer2PfStatus) - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GETNEXT: - abort(); - case SNMP_OP_ROLLBACK: - bridge_do_pfctl(val->var.subs[sub - 1] - 1, - op, &(ctx->scratch->int1)); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - - case SNMP_OP_SET: - ctx->scratch->int1 = - bridge_get_pfval(val->var.subs[sub - 1]); - - if ((k_val = snmp_truth2val(val->v.integer)) < 0) - return (SNMP_ERR_BADVALUE); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_GET: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgePfilStatus: - case LEAF_begemotBridgePfilMembers: - case LEAF_begemotBridgePfilIpOnly: - case LEAF_begemotBridgeLayer2PfStatus: - if (bridge_do_pfctl(val->var.subs[sub - 1] - 1, - op, &k_val) < 0) - return (SNMP_ERR_GENERR); - val->v.integer = val2snmp_truth(k_val); - return (SNMP_ERR_NOERROR); - } - abort(); - } - - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c deleted file mode 100644 index fe2af04..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_port.c +++ /dev/null @@ -1,1513 +0,0 @@ -/*- - * Copyright (c) 2006 Shteryana Shopova - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Bridge MIB implementation for SNMPd. - * Bridge ports. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "bridge_tree.h" -#include "bridge_snmp.h" - -TAILQ_HEAD(bridge_ports, bridge_port); - -/* - * Free the bridge base ports list. - */ -static void -bridge_ports_free(struct bridge_ports *headp) -{ - struct bridge_port *bp; - - while ((bp = TAILQ_FIRST(headp)) != NULL) { - TAILQ_REMOVE(headp, bp, b_p); - free(bp); - } -} - -/* - * Free the bridge base ports from the base ports list, - * members of a specified bridge interface only. - */ -static void -bridge_port_memif_free(struct bridge_ports *headp, - struct bridge_if *bif) -{ - struct bridge_port *bp; - - while (bif->f_bp != NULL && bif->sysindex == bif->f_bp->sysindex) { - bp = TAILQ_NEXT(bif->f_bp, b_p); - TAILQ_REMOVE(headp, bif->f_bp, b_p); - free(bif->f_bp); - bif->f_bp = bp; - } -} - -/* - * Insert a port entry in the base port TAILQ starting to search - * for its place from the position of the first bridge port for the bridge - * interface. Update the first bridge port if neccessary. - */ -static void -bridge_port_insert_at(struct bridge_ports *headp, - struct bridge_port *bp, struct bridge_port **f_bp) -{ - struct bridge_port *t1; - - assert(f_bp != NULL); - - for (t1 = *f_bp; - t1 != NULL && bp->sysindex == t1->sysindex; - t1 = TAILQ_NEXT(t1, b_p)) { - if (bp->if_idx < t1->if_idx) { - TAILQ_INSERT_BEFORE(t1, bp, b_p); - if (*f_bp == t1) - *f_bp = bp; - return; - } - } - - /* - * Handle the case when our first port was actually the - * last element of the TAILQ. - */ - if (t1 == NULL) - TAILQ_INSERT_TAIL(headp, bp, b_p); - else - TAILQ_INSERT_BEFORE(t1, bp, b_p); -} - -/* - * Find a port entry's possition in the ports list according - * to it's parent bridge interface name. Returns a NULL if - * we should be at the TAILQ head, otherwise the entry after - * which we should be inserted. - */ -static struct bridge_port * -bridge_port_find_pos(struct bridge_ports *headp, uint32_t b_idx) -{ - uint32_t t_idx; - struct bridge_port *t1; - - if ((t1 = TAILQ_FIRST(headp)) == NULL || - bridge_compare_sysidx(b_idx, t1->sysindex) < 0) - return (NULL); - - t_idx = t1->sysindex; - - for (t1 = TAILQ_NEXT(t1, b_p); t1 != NULL; t1 = TAILQ_NEXT(t1, b_p)) { - if (t1->sysindex != t_idx) { - if (bridge_compare_sysidx(b_idx, t1->sysindex) < 0) - return (TAILQ_PREV(t1, bridge_ports, b_p)); - else - t_idx = t1->sysindex; - } - } - - if (t1 == NULL) - t1 = TAILQ_LAST(headp, bridge_ports); - - return (t1); -} - -/* - * Insert a bridge member interface in the ports TAILQ. - */ -static void -bridge_port_memif_insert(struct bridge_ports *headp, - struct bridge_port *bp, struct bridge_port **f_bp) -{ - struct bridge_port *temp; - - if (*f_bp != NULL) - bridge_port_insert_at(headp, bp, f_bp); - else { - temp = bridge_port_find_pos(headp, bp->sysindex); - - if (temp == NULL) - TAILQ_INSERT_HEAD(headp, bp, b_p); - else - TAILQ_INSERT_AFTER(headp, temp, bp, b_p); - *f_bp = bp; - } -} - -/* The global ports list. */ -static struct bridge_ports bridge_ports = TAILQ_HEAD_INITIALIZER(bridge_ports); -static time_t ports_list_age; - -void -bridge_ports_update_listage(void) -{ - ports_list_age = time(NULL); -} - -void -bridge_ports_fini(void) -{ - bridge_ports_free(&bridge_ports); -} - -void -bridge_members_free(struct bridge_if *bif) -{ - bridge_port_memif_free(&bridge_ports, bif); -} - -/* - * Find the first port in the ports list. - */ -static struct bridge_port * -bridge_port_first(void) -{ - return (TAILQ_FIRST(&bridge_ports)); -} - -/* - * Find the next port in the ports list. - */ -static struct bridge_port * -bridge_port_next(struct bridge_port *bp) -{ - return (TAILQ_NEXT(bp, b_p)); -} - -/* - * Find the first member of the specified bridge interface. - */ -struct bridge_port * -bridge_port_bif_first(struct bridge_if *bif) -{ - return (bif->f_bp); -} - -/* - * Find the next member of the specified bridge interface. - */ -struct bridge_port * -bridge_port_bif_next(struct bridge_port *bp) -{ - struct bridge_port *bp_next; - - if ((bp_next = TAILQ_NEXT(bp, b_p)) == NULL || - bp_next->sysindex != bp->sysindex) - return (NULL); - - return (bp_next); -} - -/* - * Remove a bridge port from the ports list. - */ -void -bridge_port_remove(struct bridge_port *bp, struct bridge_if *bif) -{ - if (bif->f_bp == bp) - bif->f_bp = bridge_port_bif_next(bp); - - TAILQ_REMOVE(&bridge_ports, bp, b_p); - free(bp); -} - -/* - * Allocate memory for a new bridge port and insert it - * in the base ports list. Return a pointer to the port's - * structure in case we want to do anything else with it. - */ -struct bridge_port * -bridge_new_port(struct mibif *mif, struct bridge_if *bif) -{ - struct bridge_port *bp; - - if ((bp = (struct bridge_port *) malloc(sizeof(*bp))) == NULL) { - syslog(LOG_ERR, "bridge new member: failed: %s", - strerror(errno)); - return (NULL); - } - - bzero(bp, sizeof(*bp)); - - bp->sysindex = bif->sysindex; - bp->if_idx = mif->index; - bp->port_no = mif->sysindex; - strlcpy(bp->p_name, mif->name, IFNAMSIZ); - bp->circuit = oid_zeroDotZero; - - /* - * Initialize all rstpMib specific values to false/default. - * These will be set to their true values later if the bridge - * supports RSTP. - */ - bp->proto_migr = TruthValue_false; - bp->admin_edge = TruthValue_false; - bp->oper_edge = TruthValue_false; - bp->oper_ptp = TruthValue_false; - bp->admin_ptp = StpPortAdminPointToPointType_auto; - - bridge_port_memif_insert(&bridge_ports, bp, &(bif->f_bp)); - - return (bp); -} - -/* - * Update our info from the corresponding mibII interface info. - */ -void -bridge_port_getinfo_mibif(struct mibif *m_if, struct bridge_port *bp) -{ - bp->max_info = m_if->mib.ifmd_data.ifi_mtu; - bp->in_frames = m_if->mib.ifmd_data.ifi_ipackets; - bp->out_frames = m_if->mib.ifmd_data.ifi_opackets; - bp->in_drops = m_if->mib.ifmd_data.ifi_iqdrops; -} - -/* - * Find a port, whose SNMP's mibII ifIndex matches one of the ports, - * members of the specified bridge interface. - */ -struct bridge_port * -bridge_port_find(int32_t if_idx, struct bridge_if *bif) -{ - struct bridge_port *bp; - - for (bp = bif->f_bp; bp != NULL; bp = TAILQ_NEXT(bp, b_p)) { - if (bp->sysindex != bif->sysindex) { - bp = NULL; - break; - } - - if (bp->if_idx == if_idx) - break; - } - - return (bp); -} - -void -bridge_ports_dump(struct bridge_if *bif) -{ - struct bridge_port *bp; - - for (bp = bridge_port_bif_first(bif); bp != NULL; - bp = bridge_port_bif_next(bp)) { - syslog(LOG_ERR, "memif - %s, index - %d", - bp->p_name, bp->port_no); - } -} - -/* - * RFC4188 specifics. - */ -int -op_dot1d_base_port(struct snmp_context *c __unused, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - struct bridge_port *bp; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->ports_age > bridge_get_data_maxage() && - bridge_update_memif(bif) <= 0) - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if (val->var.len - sub == 0) { - if ((bp = bridge_port_bif_first(bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } else { - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL || - (bp = bridge_port_bif_next(bp)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } - val->var.len = sub + 1; - val->var.subs[sub] = bp->port_no; - goto get; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - break; - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dBasePort: - val->v.integer = bp->port_no; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dBasePortIfIndex: - val->v.integer = bp->if_idx; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dBasePortCircuit: - val->v.oid = bp->circuit; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dBasePortDelayExceededDiscards: - val->v.uint32 = bp->dly_ex_drops; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dBasePortMtuExceededDiscards: - val->v.uint32 = bp->dly_mtu_drops; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - struct bridge_port *bp; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->ports_age > bridge_get_data_maxage() && - bridge_update_memif(bif) <= 0) - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if (val->var.len - sub == 0) { - if ((bp = bridge_port_bif_first(bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } else { - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL || - (bp = bridge_port_bif_next(bp)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } - val->var.len = sub + 1; - val->var.subs[sub] = bp->port_no; - goto get; - - case SNMP_OP_SET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPortPriority: - if (val->v.integer < 0 || val->v.integer > 255) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->priority; - if (bridge_port_set_priority(bif->bif_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortEnable: - if (val->v.integer != dot1dStpPortEnable_enabled && - val->v.integer != dot1dStpPortEnable_disabled) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->enable; - if (bridge_port_set_stp_enable(bif->bif_name, - bp, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortPathCost: - if (val->v.integer < SNMP_PORT_MIN_PATHCOST || - val->v.integer > SNMP_PORT_MAX_PATHCOST) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->path_cost; - if (bridge_port_set_path_cost(bif->bif_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPort: - case LEAF_dot1dStpPortState: - case LEAF_dot1dStpPortDesignatedRoot: - case LEAF_dot1dStpPortDesignatedCost: - case LEAF_dot1dStpPortDesignatedBridge: - case LEAF_dot1dStpPortDesignatedPort: - case LEAF_dot1dStpPortForwardTransitions: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_GENERR); - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPortPriority: - bridge_port_set_priority(bif->bif_name, bp, - ctx->scratch->int1); - break; - case LEAF_dot1dStpPortEnable: - bridge_port_set_stp_enable(bif->bif_name, bp, - ctx->scratch->int1); - break; - case LEAF_dot1dStpPortPathCost: - bridge_port_set_path_cost(bif->bif_name, bp, - ctx->scratch->int1); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPort: - val->v.integer = bp->port_no; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortPriority: - val->v.integer = bp->priority; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortState: - val->v.integer = bp->state; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortEnable: - val->v.integer = bp->enable; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortPathCost: - val->v.integer = bp->path_cost; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortDesignatedRoot: - return (string_get(val, bp->design_root, - SNMP_BRIDGE_ID_LEN)); - - case LEAF_dot1dStpPortDesignatedCost: - val->v.integer = bp->design_cost; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortDesignatedBridge: - return (string_get(val, bp->design_bridge, - SNMP_BRIDGE_ID_LEN)); - - case LEAF_dot1dStpPortDesignatedPort: - return (string_get(val, bp->design_port, 2)); - - case LEAF_dot1dStpPortForwardTransitions: - val->v.uint32 = bp->fwd_trans; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - struct bridge_port *bp; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->ports_age > bridge_get_data_maxage() && - bridge_update_memif(bif) <= 0) - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if (val->var.len - sub == 0) { - if ((bp = bridge_port_bif_first(bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } else { - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL || - (bp = bridge_port_bif_next(bp)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } - val->var.len = sub + 1; - val->var.subs[sub] = bp->port_no; - goto get; - - case SNMP_OP_SET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPortAdminEdgePort: - if (val->v.integer != TruthValue_true && - val->v.integer != TruthValue_false) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->admin_edge; - if (bridge_port_set_admin_edge(bif->bif_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortAdminPointToPoint: - if (val->v.integer < 0 || val->v.integer > - StpPortAdminPointToPointType_auto) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->admin_ptp; - if (bridge_port_set_admin_ptp(bif->bif_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortAdminPathCost: - if (val->v.integer < SNMP_PORT_MIN_PATHCOST || - val->v.integer > SNMP_PORT_MAX_PATHCOST) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->admin_path_cost; - if (bridge_port_set_path_cost(bif->bif_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortProtocolMigration: - case LEAF_dot1dStpPortOperEdgePort: - case LEAF_dot1dStpPortOperPointToPoint: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPortAdminEdgePort: - bridge_port_set_admin_edge(bif->bif_name, bp, - ctx->scratch->int1); - break; - case LEAF_dot1dStpPortAdminPointToPoint: - bridge_port_set_admin_ptp(bif->bif_name, bp, - ctx->scratch->int1); - break; - case LEAF_dot1dStpPortAdminPathCost: - bridge_port_set_path_cost(bif->bif_name, bp, - ctx->scratch->int1); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dStpPortProtocolMigration: - val->v.integer = bp->proto_migr; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortAdminEdgePort: - val->v.integer = bp->admin_edge; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortOperEdgePort: - val->v.integer = bp->oper_edge; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortAdminPointToPoint: - val->v.integer = bp->admin_ptp; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortOperPointToPoint: - val->v.integer = bp->oper_ptp; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dStpPortAdminPathCost: - val->v.integer = bp->admin_path_cost; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_dot1d_tp_port(struct snmp_context *c __unused, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_if *bif; - struct bridge_port *bp; - - if ((bif = bridge_get_default()) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - if (time(NULL) - bif->ports_age > bridge_get_data_maxage() && - bridge_update_memif(bif) <= 0) - return (SNMP_ERR_NOSUCHNAME); - - switch (op) { - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if (val->var.len - sub == 0) { - if ((bp = bridge_port_bif_first(bif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } else { - if ((bp = bridge_port_find(val->var.subs[sub], - bif)) == NULL || - (bp = bridge_port_bif_next(bp)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - } - val->var.len = sub + 1; - val->var.subs[sub] = bp->port_no; - goto get; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - break; - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_dot1dTpPort: - val->v.integer = bp->port_no; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dTpPortMaxInfo: - val->v.integer = bp->max_info; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dTpPortInFrames: - val->v.uint32 = bp->in_frames; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dTpPortOutFrames: - val->v.uint32 = bp->out_frames; - return (SNMP_ERR_NOERROR); - - case LEAF_dot1dTpPortInDiscards: - val->v.uint32 = bp->in_drops; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -/* - * Private BEGEMOT-BRIDGE-MIB specifics. - */ - -/* - * Construct a bridge port entry index. - */ -static int -bridge_port_index_append(struct asn_oid *oid, uint sub, - const struct bridge_port *bp) -{ - uint i; - const char *b_name; - - if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL) - return (-1); - - oid->len = sub + strlen(b_name) + 1 + 1; - oid->subs[sub] = strlen(b_name); - - for (i = 1; i <= strlen(b_name); i++) - oid->subs[sub + i] = b_name[i - 1]; - - oid->subs[sub + i] = bp->port_no; - - return (0); -} - -/* - * Get the port entry from an entry's index. - */ -static struct bridge_port * -bridge_port_index_get(const struct asn_oid *oid, uint sub, int8_t status) -{ - uint i; - int32_t port_no; - char bif_name[IFNAMSIZ]; - struct bridge_if *bif; - struct bridge_port *bp; - - if (oid->len - sub != oid->subs[sub] + 2 || - oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - for (i = 0; i < oid->subs[sub]; i++) - bif_name[i] = oid->subs[sub + i + 1]; - bif_name[i] = '\0'; - - port_no = oid->subs[sub + i + 1]; - - if ((bif = bridge_if_find_ifname(bif_name)) == NULL) - return (NULL); - - if ((bp = bridge_port_find(port_no, bif)) == NULL || - (status == 0 && bp->status != RowStatus_active)) - return (NULL); - - return (bp); -} - -/* - * Get the next port entry from an entry's index. - */ -static struct bridge_port * -bridge_port_index_getnext(const struct asn_oid *oid, uint sub, int8_t status) -{ - uint i; - int32_t port_no; - char bif_name[IFNAMSIZ]; - struct bridge_if *bif; - struct bridge_port *bp; - - if (oid->len - sub == 0) - bp = bridge_port_first(); - else { - if (oid->len - sub != oid->subs[sub] + 2 || - oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - for (i = 0; i < oid->subs[sub]; i++) - bif_name[i] = oid->subs[sub + i + 1]; - bif_name[i] = '\0'; - - port_no = oid->subs[sub + i + 1]; - - if ((bif = bridge_if_find_ifname(bif_name)) == NULL || - (bp = bridge_port_find(port_no, bif)) == NULL) - return (NULL); - - bp = bridge_port_next(bp); - } - - if (status == 1) - return (bp); - - while (bp != NULL) { - if (bp->status == RowStatus_active) - break; - bp = bridge_port_next(bp); - } - - return (bp); -} - -/* - * Read the bridge name and port index from a ASN OID structure. - */ -static int -bridge_port_index_decode(const struct asn_oid *oid, uint sub, - char *b_name, int32_t *idx) -{ - uint i; - - if (oid->len - sub != oid->subs[sub] + 2 || - oid->subs[sub] >= IFNAMSIZ) - return (-1); - - for (i = 0; i < oid->subs[sub]; i++) - b_name[i] = oid->subs[sub + i + 1]; - b_name[i] = '\0'; - - *idx = oid->subs[sub + i + 1]; - return (0); -} - -static int -bridge_port_set_status(struct snmp_context *ctx, - struct snmp_value *val, uint sub) -{ - int32_t if_idx; - char b_name[IFNAMSIZ]; - struct bridge_if *bif; - struct bridge_port *bp; - struct mibif *mif; - - if (bridge_port_index_decode(&val->var, sub, b_name, &if_idx) < 0) - return (SNMP_ERR_INCONS_VALUE); - - if ((bif = bridge_if_find_ifname(b_name)) == NULL || - (mif = mib_find_if(if_idx)) == NULL) - return (SNMP_ERR_INCONS_VALUE); - - bp = bridge_port_find(if_idx, bif); - - switch (val->v.integer) { - case RowStatus_active: - if (bp == NULL) - return (SNMP_ERR_INCONS_VALUE); - - if (bp->span_enable == 0) - return (SNMP_ERR_INCONS_VALUE); - - ctx->scratch->int1 = bp->status; - bp->status = RowStatus_active; - break; - - case RowStatus_notInService: - if (bp == NULL || bp->span_enable == 0 || - bp->status == RowStatus_active) - return (SNMP_ERR_INCONS_VALUE); - - ctx->scratch->int1 = bp->status; - bp->status = RowStatus_notInService; - - case RowStatus_notReady: - /* FALLTHROUGH */ - case RowStatus_createAndGo: - return (SNMP_ERR_INCONS_VALUE); - - case RowStatus_createAndWait: - if (bp != NULL) - return (SNMP_ERR_INCONS_VALUE); - - if ((bp = bridge_new_port(mif, bif)) == NULL) - return (SNMP_ERR_GENERR); - - ctx->scratch->int1 = RowStatus_destroy; - bp->status = RowStatus_notReady; - break; - - case RowStatus_destroy: - if (bp == NULL) - return (SNMP_ERR_INCONS_VALUE); - - ctx->scratch->int1 = bp->status; - bp->status = RowStatus_destroy; - break; - } - - return (SNMP_ERR_NOERROR); -} - -static int -bridge_port_rollback_status(struct snmp_context *ctx, - struct snmp_value *val, uint sub) -{ - int32_t if_idx; - char b_name[IFNAMSIZ]; - struct bridge_if *bif; - struct bridge_port *bp; - - if (bridge_port_index_decode(&val->var, sub, b_name, &if_idx) < 0) - return (SNMP_ERR_GENERR); - - if ((bif = bridge_if_find_ifname(b_name)) == NULL || - (bp = bridge_port_find(if_idx, bif)) == NULL) - return (SNMP_ERR_GENERR); - - if (ctx->scratch->int1 == RowStatus_destroy) - bridge_port_remove(bp, bif); - else - bp->status = ctx->scratch->int1; - - return (SNMP_ERR_NOERROR); -} - -static int -bridge_port_commit_status(struct snmp_value *val, uint sub) -{ - int32_t if_idx; - char b_name[IFNAMSIZ]; - struct bridge_if *bif; - struct bridge_port *bp; - - if (bridge_port_index_decode(&val->var, sub, b_name, &if_idx) < 0) - return (SNMP_ERR_GENERR); - - if ((bif = bridge_if_find_ifname(b_name)) == NULL || - (bp = bridge_port_find(if_idx, bif)) == NULL) - return (SNMP_ERR_GENERR); - - switch (bp->status) { - case RowStatus_active: - if (bridge_port_addm(bp, b_name) < 0) - return (SNMP_ERR_COMMIT_FAILED); - break; - - case RowStatus_destroy: - if (bridge_port_delm(bp, b_name) < 0) - return (SNMP_ERR_COMMIT_FAILED); - bridge_port_remove(bp, bif); - break; - } - - return (SNMP_ERR_NOERROR); -} - -static int -bridge_port_set_span_enable(struct snmp_context *ctx, - struct snmp_value *val, uint sub) -{ - int32_t if_idx; - char b_name[IFNAMSIZ]; - struct bridge_if *bif; - struct bridge_port *bp; - struct mibif *mif; - - if (val->v.integer != begemotBridgeBaseSpanEnabled_enabled && - val->v.integer != begemotBridgeBaseSpanEnabled_disabled) - return (SNMP_ERR_BADVALUE); - - if (bridge_port_index_decode(&val->var, sub, b_name, &if_idx) < 0) - return (SNMP_ERR_INCONS_VALUE); - - if ((bif = bridge_if_find_ifname(b_name)) == NULL) - return (SNMP_ERR_INCONS_VALUE); - - if ((bp = bridge_port_find(if_idx, bif)) == NULL) { - if ((mif = mib_find_if(if_idx)) == NULL) - return (SNMP_ERR_INCONS_VALUE); - - if ((bp = bridge_new_port(mif, bif)) == NULL) - return (SNMP_ERR_GENERR); - - ctx->scratch->int1 = RowStatus_destroy; - } else if (bp->status == RowStatus_active) { - return (SNMP_ERR_INCONS_VALUE); - } else { - ctx->scratch->int1 = bp->status; - } - - bp->span_enable = val->v.integer; - bp->status = RowStatus_notInService; - - return (SNMP_ERR_NOERROR); -} - -int -op_begemot_base_port(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - int8_t status, which; - const char *bname; - struct bridge_port *bp; - - if (time(NULL) - ports_list_age > bridge_get_data_maxage()) - bridge_update_all_ports(); - - which = val->var.subs[sub - 1]; - status = 0; - - switch (op) { - case SNMP_OP_GET: - if (which == LEAF_begemotBridgeBaseSpanEnabled || - which == LEAF_begemotBridgeBasePortStatus) - status = 1; - if ((bp = bridge_port_index_get(&val->var, sub, - status)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if (which == LEAF_begemotBridgeBaseSpanEnabled || - which == LEAF_begemotBridgeBasePortStatus) - status = 1; - if ((bp = bridge_port_index_getnext(&val->var, sub, - status)) == NULL || - bridge_port_index_append(&val->var, sub, bp) < 0) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - switch (which) { - case LEAF_begemotBridgeBaseSpanEnabled: - return (bridge_port_set_span_enable(ctx, val, sub)); - - case LEAF_begemotBridgeBasePortStatus: - return (bridge_port_set_status(ctx, val, sub)); - - case LEAF_begemotBridgeBasePortPrivate: - if ((bp = bridge_port_index_get(&val->var, sub, - status)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if ((bname = bridge_if_find_name(bp->sysindex)) == NULL) - return (SNMP_ERR_GENERR); - ctx->scratch->int1 = bp->priv_set; - return (bridge_port_set_private(bname, bp, - val->v.integer)); - - case LEAF_begemotBridgeBasePort: - case LEAF_begemotBridgeBasePortIfIndex: - case LEAF_begemotBridgeBasePortDelayExceededDiscards: - case LEAF_begemotBridgeBasePortMtuExceededDiscards: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - switch (which) { - case LEAF_begemotBridgeBaseSpanEnabled: - /* FALLTHROUGH */ - case LEAF_begemotBridgeBasePortStatus: - return (bridge_port_rollback_status(ctx, val, sub)); - case LEAF_begemotBridgeBasePortPrivate: - if ((bp = bridge_port_index_get(&val->var, sub, - status)) == NULL) - return (SNMP_ERR_GENERR); - if ((bname = bridge_if_find_name(bp->sysindex)) == NULL) - return (SNMP_ERR_GENERR); - return (bridge_port_set_private(bname, bp, - ctx->scratch->int1)); - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - if (which == LEAF_begemotBridgeBasePortStatus) - return (bridge_port_commit_status(val, sub)); - - return (SNMP_ERR_NOERROR); - } - abort(); - -get: - switch (which) { - case LEAF_begemotBridgeBasePort: - val->v.integer = bp->port_no; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBasePortIfIndex: - val->v.integer = bp->if_idx; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBaseSpanEnabled: - val->v.integer = bp->span_enable; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBasePortDelayExceededDiscards: - val->v.uint32 = bp->dly_ex_drops; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBasePortMtuExceededDiscards: - val->v.uint32 = bp->dly_mtu_drops; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBasePortStatus: - val->v.integer = bp->status; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeBasePortPrivate: - val->v.integer = bp->priv_set; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_port *bp; - const char *b_name; - - if (time(NULL) - ports_list_age > bridge_get_data_maxage()) - bridge_update_all_ports(); - - switch (op) { - case SNMP_OP_GET: - if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) == - NULL || bridge_port_index_append(&val->var, sub, bp) < 0) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPortPriority: - if (val->v.integer < 0 || val->v.integer > 255) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->priority; - if (bridge_port_set_priority(b_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortEnable: - if (val->v.integer != - begemotBridgeStpPortEnable_enabled || - val->v.integer != - begemotBridgeStpPortEnable_disabled) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->enable; - if (bridge_port_set_stp_enable(b_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortPathCost: - if (val->v.integer < SNMP_PORT_MIN_PATHCOST || - val->v.integer > SNMP_PORT_MAX_PATHCOST) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->path_cost; - if (bridge_port_set_path_cost(b_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPort: - case LEAF_begemotBridgeStpPortState: - case LEAF_begemotBridgeStpPortDesignatedRoot: - case LEAF_begemotBridgeStpPortDesignatedCost: - case LEAF_begemotBridgeStpPortDesignatedBridge: - case LEAF_begemotBridgeStpPortDesignatedPort: - case LEAF_begemotBridgeStpPortForwardTransitions: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL || - (b_name = bridge_if_find_name(bp->sysindex)) == NULL) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPortPriority: - bridge_port_set_priority(b_name, bp, - ctx->scratch->int1); - break; - case LEAF_begemotBridgeStpPortEnable: - bridge_port_set_stp_enable(b_name, bp, - ctx->scratch->int1); - break; - case LEAF_begemotBridgeStpPortPathCost: - bridge_port_set_path_cost(b_name, bp, - ctx->scratch->int1); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPort: - val->v.integer = bp->port_no; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortPriority: - val->v.integer = bp->priority; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortState: - val->v.integer = bp->state; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortEnable: - val->v.integer = bp->enable; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortPathCost: - val->v.integer = bp->path_cost; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortDesignatedRoot: - return (string_get(val, bp->design_root, SNMP_BRIDGE_ID_LEN)); - - case LEAF_begemotBridgeStpPortDesignatedCost: - val->v.integer = bp->design_cost; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortDesignatedBridge: - return (string_get(val, bp->design_bridge, SNMP_BRIDGE_ID_LEN)); - - case LEAF_begemotBridgeStpPortDesignatedPort: - return (string_get(val, bp->design_port, 2)); - - case LEAF_begemotBridgeStpPortForwardTransitions: - val->v.uint32 = bp->fwd_trans; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_port *bp; - const char *b_name; - - if (time(NULL) - ports_list_age > bridge_get_data_maxage()) - bridge_update_all_ports(); - - switch (op) { - case SNMP_OP_GET: - if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) == - NULL || bridge_port_index_append(&val->var, sub, bp) < 0) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPortAdminEdgePort: - if (val->v.integer != TruthValue_true && - val->v.integer != TruthValue_false) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->admin_edge; - if (bridge_port_set_admin_edge(b_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortAdminPointToPoint: - if (val->v.integer < 0 || val->v.integer > - StpPortAdminPointToPointType_auto) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->admin_ptp; - if (bridge_port_set_admin_ptp(b_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortAdminPathCost: - if (val->v.integer < SNMP_PORT_MIN_PATHCOST || - val->v.integer > SNMP_PORT_MAX_PATHCOST) - return (SNMP_ERR_WRONG_VALUE); - - ctx->scratch->int1 = bp->admin_path_cost; - if (bridge_port_set_path_cost(b_name, bp, - val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortProtocolMigration: - case LEAF_begemotBridgeStpPortOperEdgePort: - case LEAF_begemotBridgeStpPortOperPointToPoint: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_ROLLBACK: - if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL || - (b_name = bridge_if_find_name(bp->sysindex)) == NULL) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPortAdminEdgePort: - bridge_port_set_admin_edge(b_name, bp, - ctx->scratch->int1); - break; - case LEAF_begemotBridgeStpPortAdminPointToPoint: - bridge_port_set_admin_ptp(b_name, bp, - ctx->scratch->int1); - break; - case LEAF_begemotBridgeStpPortAdminPathCost: - bridge_port_set_path_cost(b_name, bp, - ctx->scratch->int1); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeStpPortProtocolMigration: - val->v.integer = bp->proto_migr; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortAdminEdgePort: - val->v.integer = bp->admin_edge; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortOperEdgePort: - val->v.integer = bp->oper_edge; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortAdminPointToPoint: - val->v.integer = bp->admin_ptp; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortOperPointToPoint: - val->v.integer = bp->oper_ptp; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeStpPortAdminPathCost: - val->v.integer = bp->admin_path_cost; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_begemot_tp_port(struct snmp_context *c __unused, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - struct bridge_port *bp; - - if (time(NULL) - ports_list_age > bridge_get_data_maxage()) - bridge_update_all_ports(); - - switch (op) { - case SNMP_OP_GET: - if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_GETNEXT: - if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) == - NULL || bridge_port_index_append(&val->var, sub, bp) < 0) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - break; - } - abort(); - -get: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeTpPort: - val->v.integer = bp->port_no; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpPortMaxInfo: - val->v.integer = bp->max_info; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpPortInFrames: - val->v.uint32 = bp->in_frames; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpPortOutFrames: - val->v.uint32 = bp->out_frames; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeTpPortInDiscards: - val->v.uint32 = bp->in_drops; - return (SNMP_ERR_NOERROR); - } - - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c deleted file mode 100644 index 81acc4d..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.c +++ /dev/null @@ -1,338 +0,0 @@ -/*- - * Copyright (c) 2006 Shteryana Shopova - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Bridge MIB implementation for SNMPd. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "bridge_tree.h" -#include "bridge_snmp.h" -#include "bridge_oid.h" - -static struct lmodule *bridge_module; - -/* For the registration. */ -static const struct asn_oid oid_dot1Bridge = OIDX_dot1dBridge; -/* The registration. */ -static uint reg_bridge; - -/* Periodic timer for polling all bridges' data. */ -static void *bridge_data_timer; -static void *bridge_tc_timer; - -static int bridge_data_maxage = SNMP_BRIDGE_DATA_MAXAGE; -static int bridge_poll_ticks = SNMP_BRIDGE_POLL_INTERVAL * 100; -static int bridge_tc_poll_ticks = SNMP_BRIDGE_TC_POLL_INTERVAL * 100; - -/* - * Our default bridge, whose info will be visible under - * the dot1dBridge subtree and functions to set/fetch it. - */ -static char bif_default_name[IFNAMSIZ] = "bridge0"; -static struct bridge_if *bif_default; - -struct bridge_if * -bridge_get_default(void) -{ - struct mibif *ifp; - - if (bif_default != NULL) { - - /* Walk through the mibII interface list. */ - for (ifp = mib_first_if(); ifp != NULL; ifp = mib_next_if(ifp)) - if (strcmp(ifp->name, bif_default->bif_name) == 0) - break; - - if (ifp == NULL) - bif_default = NULL; - } - - return (bif_default); -} - -void -bridge_set_default(struct bridge_if *bif) -{ - bif_default = bif; - - syslog(LOG_ERR, "Set default bridge interface to: %s", - bif == NULL ? "(none)" : bif->bif_name); -} - -const char * -bridge_get_default_name(void) -{ - return (bif_default_name); -} - -static int -bridge_set_default_name(const char *bif_name, uint len) -{ - struct bridge_if *bif; - - if (len >= IFNAMSIZ) - return (-1); - - bcopy(bif_name, bif_default_name, len); - bif_default_name[len] = '\0'; - - if ((bif = bridge_if_find_ifname(bif_default_name)) == NULL) { - bif_default = NULL; - return (0); - } - - bif_default = bif; - return (1); -} - -int -bridge_get_data_maxage(void) -{ - return (bridge_data_maxage); -} - -static void -bridge_set_poll_ticks(int poll_ticks) -{ - if (bridge_data_timer != NULL) - timer_stop(bridge_data_timer); - - bridge_poll_ticks = poll_ticks; - bridge_data_timer = timer_start_repeat(bridge_poll_ticks, - bridge_poll_ticks, bridge_update_all, NULL, bridge_module); -} -/* - * The bridge module configuration via SNMP. - */ -static int -bridge_default_name_save(struct snmp_context *ctx, const char *bridge_default) -{ - if ((ctx->scratch->int1 = strlen(bridge_default)) >= IFNAMSIZ) - return (-1); - - if ((ctx->scratch->ptr1 = malloc(IFNAMSIZ)) == NULL) - return (-1); - - strncpy(ctx->scratch->ptr1, bridge_default, ctx->scratch->int1); - return (0); -} - -int -op_begemot_bridge_config(struct snmp_context *ctx, struct snmp_value *val, - uint sub, uint iidx __unused, enum snmp_op op) -{ - switch (op) { - case SNMP_OP_GET: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeDefaultBridgeIf: - return (string_get(val, bridge_get_default_name(), -1)); - - case LEAF_begemotBridgeDataUpdate: - val->v.integer = bridge_data_maxage; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeDataPoll: - val->v.integer = bridge_poll_ticks / 100; - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_SET: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeDefaultBridgeIf: - /* - * Cannot use string_save() here - requires either - * a fixed-sized or var-length string - not less - * than or equal. - */ - if (bridge_default_name_save(ctx, - bridge_get_default_name()) < 0) - return (SNMP_ERR_RES_UNAVAIL); - - if (bridge_set_default_name(val->v.octetstring.octets, - val->v.octetstring.len) < 0) - return (SNMP_ERR_BADVALUE); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeDataUpdate: - if (val->v.integer < SNMP_BRIDGE_DATA_MAXAGE_MIN || - val->v.integer > SNMP_BRIDGE_DATA_MAXAGE_MAX) - return (SNMP_ERR_WRONG_VALUE); - ctx->scratch->int1 = bridge_data_maxage; - bridge_data_maxage = val->v.integer; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotBridgeDataPoll: - if (val->v.integer < SNMP_BRIDGE_POLL_INTERVAL_MIN || - val->v.integer > SNMP_BRIDGE_POLL_INTERVAL_MAX) - return (SNMP_ERR_WRONG_VALUE); - ctx->scratch->int1 = val->v.integer; - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_ROLLBACK: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeDefaultBridgeIf: - bridge_set_default_name(ctx->scratch->ptr1, - ctx->scratch->int1); - free(ctx->scratch->ptr1); - break; - case LEAF_begemotBridgeDataUpdate: - bridge_data_maxage = ctx->scratch->int1; - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - switch (val->var.subs[sub - 1]) { - case LEAF_begemotBridgeDefaultBridgeIf: - free(ctx->scratch->ptr1); - break; - case LEAF_begemotBridgeDataPoll: - bridge_set_poll_ticks(ctx->scratch->int1 * 100); - break; - } - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -/* - * Bridge mib module initialization hook. - * Returns 0 on success, < 0 on error. - */ -static int -bridge_init(struct lmodule * mod, int argc __unused, char *argv[] __unused) -{ - bridge_module = mod; - - if (bridge_kmod_load() < 0) - return (-1); - - if (bridge_ioctl_init() < 0) - return (-1); - - /* Register to get creation messages for bridge interfaces. */ - if (mib_register_newif(bridge_attach_newif, bridge_module)) { - syslog(LOG_ERR, "Cannot register newif function: %s", - strerror(errno)); - return (-1); - } - - return (0); -} - -/* - * Bridge mib module finalization hook. - */ -static int -bridge_fini(void) -{ - mib_unregister_newif(bridge_module); - or_unregister(reg_bridge); - - if (bridge_data_timer != NULL) { - timer_stop(bridge_data_timer); - bridge_data_timer = NULL; - } - - if (bridge_tc_timer != NULL) { - timer_stop(bridge_tc_timer); - bridge_tc_timer = NULL; - } - - bridge_ifs_fini(); - bridge_ports_fini(); - bridge_addrs_fini(); - - return (0); -} - -/* - * Bridge mib module start operation. - */ -static void -bridge_start(void) -{ - reg_bridge = or_register(&oid_dot1Bridge, - "The IETF MIB for Bridges (RFC 4188).", bridge_module); - - bridge_data_timer = timer_start_repeat(bridge_poll_ticks, - bridge_poll_ticks, bridge_update_all, NULL, bridge_module); - - bridge_tc_timer = timer_start_repeat(bridge_tc_poll_ticks, - bridge_tc_poll_ticks, bridge_update_tc_time, NULL, bridge_module); -} - -static void -bridge_dump(void) -{ - struct bridge_if *bif; - - if ((bif = bridge_get_default()) == NULL) - syslog(LOG_ERR, "Dump: no default bridge interface"); - else - syslog(LOG_ERR, "Dump: default bridge interface %s", - bif->bif_name); - - bridge_ifs_dump(); - bridge_pf_dump(); -} - -const struct snmp_module config = { - .comment = "This module implements the bridge mib (RFC 4188).", - .init = bridge_init, - .fini = bridge_fini, - .start = bridge_start, - .tree = bridge_ctree, - .dump = bridge_dump, - .tree_size = bridge_CTREE_SIZE, -}; diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h deleted file mode 100644 index 7f48950..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_snmp.h +++ /dev/null @@ -1,357 +0,0 @@ -/*- - * Copyright (c) 2006 Shteryana Shopova - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Bridge MIB implementation for SNMPd. - * - * $FreeBSD$ - */ - -#ifndef SNMP_BRIDGE_H -#define SNMP_BRIDGE_H - -#define SNMP_BRIDGE_ID_LEN 8 - -typedef uint8_t port_id[2]; -typedef u_char bridge_id[SNMP_BRIDGE_ID_LEN]; - -#define SNMP_BRIDGE_MAX_PRIORITY 65535 - -#define SNMP_BRIDGE_MIN_AGE_TIME 10 -#define SNMP_BRIDGE_MAX_AGE_TIME 1000000 - -#define SNMP_BRIDGE_MIN_TXHC 1 -#define SNMP_BRIDGE_MAX_TXHC 10 - -#define SNMP_BRIDGE_MIN_MAGE 600 -#define SNMP_BRIDGE_MAX_MAGE 4000 - -#define SNMP_BRIDGE_MIN_HTIME 100 -#define SNMP_BRIDGE_MAX_HTIME 1000 - -#define SNMP_BRIDGE_MIN_FDELAY 400 -#define SNMP_BRIDGE_MAX_FDELAY 3000 - -#define SNMP_PORT_PATHCOST_OBSOLETE 65535 -#define SNMP_PORT_MIN_PATHCOST 0 -#define SNMP_PORT_MAX_PATHCOST 200000000 -#define SNMP_PORT_PATHCOST_AUTO 0 - -#define SNMP_BRIDGE_DATA_MAXAGE 10 -#define SNMP_BRIDGE_DATA_MAXAGE_MIN 1 -#define SNMP_BRIDGE_DATA_MAXAGE_MAX 300 - -/* By default poll kernel data every 5 minutes. */ -#define SNMP_BRIDGE_POLL_INTERVAL (5 * 60) -#define SNMP_BRIDGE_POLL_INTERVAL_MIN 1 -#define SNMP_BRIDGE_POLL_INTERVAL_MAX 3600 - -/* Poll for a topology change once every 30 seconds. */ -#define SNMP_BRIDGE_TC_POLL_INTERVAL 30 - -struct bridge_if *bridge_get_default(void); - -void bridge_set_default(struct bridge_if *bif); - -const char *bridge_get_default_name(void); - -int bridge_get_data_maxage(void); - -/* - * Bridge Addresses Table. - */ -struct tp_entry { - uint32_t sysindex; /* The bridge if sysindex. */ - int32_t port_no; - enum TpFdbStatus status; - uint8_t tp_addr[ETHER_ADDR_LEN]; - uint8_t flags; - TAILQ_ENTRY(tp_entry) tp_e; -}; - -/* - * Bridge ports. - * The bridge port system interface index is used for a - * port number. Transparent bridging statistics and STP - * information for a port are also contained here. - */ -struct bridge_port { - /* dot1dBase subtree objects. */ - uint32_t sysindex; /* The bridge interface sysindex. */ - int32_t port_no; /* The bridge member system index. */ - int32_t if_idx; /* SNMP ifIndex from mibII. */ - int8_t span_enable; /* Span flag set - private MIB. */ - struct asn_oid circuit; /* Unused. */ - uint32_t dly_ex_drops; /* Drops on output. */ - uint32_t dly_mtu_drops; /* MTU exceeded drops. */ - int32_t status; /* The entry status. */ - enum TruthValue priv_set; /* The private flag. */ - - /* dot1dStp subtree objects. */ - int32_t path_cost; - int32_t priority; - int32_t design_cost; - uint32_t fwd_trans; - char p_name[IFNAMSIZ]; /* Not in BRIDGE-MIB. */ - enum StpPortState state; - enum dot1dStpPortEnable enable; - port_id design_port; - bridge_id design_root; - bridge_id design_bridge; - - /* rstpMib extensions. */ - int32_t admin_path_cost; - enum TruthValue proto_migr; - enum TruthValue admin_edge; - enum TruthValue oper_edge; - enum TruthValue oper_ptp; - enum StpPortAdminPointToPointType admin_ptp; - - /* dot1dTp subtree objects. */ - int32_t max_info; - int32_t in_frames; - int32_t out_frames; - int32_t in_drops; - - uint8_t flags; - TAILQ_ENTRY(bridge_port) b_p; -}; - -/* - * A bridge interface. - * The system interface index of the bridge is not required neither by the - * standard BRIDGE-MIB nor by the private BEGEMOT-BRIDGE-MIB, but is used - * as key for looking up the other info for this bridge. - */ -struct bridge_if { - /* dot1dBase subtree objects. */ - uint32_t sysindex; /* The system interface index. */ - int32_t num_ports; /* Number of ports. */ - enum BaseType br_type; /* Bridge type. */ - enum RowStatus if_status; /* Bridge status. */ - char bif_name[IFNAMSIZ]; /* Bridge interface name. */ - struct ether_addr br_addr; /* Bridge address. */ - struct bridge_port *f_bp; /* This bridge's first entry - * in the base ports TAILQ. */ - /* dot1dStp subtree objects. */ - int32_t priority; - int32_t root_cost; - int32_t root_port; - int32_t max_age; /* Current max age. */ - int32_t hello_time; /* Current hello time. */ - int32_t fwd_delay; /* Current forward delay. */ - int32_t hold_time; - int32_t bridge_max_age; /* Configured max age. */ - int32_t bridge_hello_time; /* Configured hello time. */ - int32_t bridge_fwd_delay; /* Configured forward delay. */ - int32_t tx_hold_count; - uint32_t top_changes; - enum dot1dStpVersion stp_version; - enum dot1dStpProtocolSpecification prot_spec; - struct timeval last_tc_time; - bridge_id design_root; - - /* dot1dTp subtree objects. */ - int32_t lrnt_drops; /* Dropped addresses. */ - int32_t age_time; /* Address entry timeout. */ - int32_t num_addrs; /* Current # of addresses in cache. */ - int32_t max_addrs; /* Max # of addresses in cache. */ - struct tp_entry *f_tpa; /* This bridge's first entry in - * the tp addresses TAILQ. */ - - time_t entry_age; - time_t ports_age; - time_t addrs_age; - TAILQ_ENTRY(bridge_if) b_if; -}; - -void bridge_ifs_fini(void); - -struct bridge_if *bridge_if_find_ifs(uint32_t sysindex); - -struct bridge_if *bridge_if_find_ifname(const char *b_name); - -const char *bridge_if_find_name(uint32_t sysindex); - -int bridge_compare_sysidx(uint32_t i1, uint32_t i2); - -int bridge_attach_newif(struct mibif *ifp); - -struct bridge_if *bridge_first_bif(void); - -struct bridge_if *bridge_next_bif(struct bridge_if *b_pr); - -void bridge_remove_bif(struct bridge_if *bif); - -void bridge_update_all_ports(void); - -void bridge_update_all_addrs(void); - -void bridge_update_all_ifs(void); - -void bridge_update_all(void *arg); - -void bridge_update_tc_time(void *arg); - -void bridge_ifs_dump(void); - -/* Bridge ports. */ -void bridge_ports_update_listage(void); - -void bridge_ports_fini(void); - -void bridge_members_free(struct bridge_if *bif); - -struct bridge_port *bridge_new_port(struct mibif *mif, struct bridge_if *bif); - -void bridge_port_remove(struct bridge_port *bp, struct bridge_if *bif); - -struct bridge_port *bridge_port_bif_first(struct bridge_if *bif); - -struct bridge_port *bridge_port_bif_next(struct bridge_port *bp); - -struct bridge_port *bridge_port_find(int32_t if_idx, struct bridge_if *bif); - -void bridge_port_getinfo_mibif(struct mibif *m_if, struct bridge_port *bp); - -int bridge_getinfo_bif_ports(struct bridge_if *bif); - -int bridge_update_memif(struct bridge_if *bif); - -void bridge_ports_dump(struct bridge_if *bif); - -/* Bridge addresses. */ -void bridge_addrs_update_listage(void); - -void bridge_addrs_fini(void); - -void bridge_addrs_free(struct bridge_if *bif); - -struct tp_entry *bridge_new_addrs(uint8_t *mac, struct bridge_if *bif); - -void bridge_addrs_remove(struct tp_entry *te, struct bridge_if *bif); - -struct tp_entry *bridge_addrs_find(uint8_t *mac, struct bridge_if *bif); - -struct tp_entry *bridge_addrs_bif_first(struct bridge_if *bif); - -struct tp_entry *bridge_addrs_bif_next(struct tp_entry *te); - -int bridge_getinfo_bif_addrs(struct bridge_if *bif); - -int bridge_update_addrs(struct bridge_if *bif); - -void bridge_addrs_dump(struct bridge_if *bif); - -/* Bridge PF. */ - -void bridge_pf_dump(void); - -/* System specific. */ - -/* Open the socket for the ioctls. */ -int bridge_ioctl_init(void); - -/* Load bridge kernel module. */ -int bridge_kmod_load(void); - -/* Get the bridge interface information. */ -int bridge_getinfo_bif(struct bridge_if *bif); - -/* Get the bridge interface STP parameters. */ -int bridge_get_op_param(struct bridge_if *bif); - -/* Set the bridge priority. */ -int bridge_set_priority(struct bridge_if *bif, int32_t priority); - -/* Set the bridge max age. */ -int bridge_set_maxage(struct bridge_if *bif, int32_t max_age); - -/* Set the bridge hello time.*/ -int bridge_set_hello_time(struct bridge_if *bif, int32_t hello_time); - -/* Set the bridge forward delay.*/ -int bridge_set_forward_delay(struct bridge_if *bif, int32_t fwd_delay); - -/* Set the bridge address cache max age. */ -int bridge_set_aging_time(struct bridge_if *bif, int32_t age_time); - -/* Set the max number of entries in the bridge address cache. */ -int bridge_set_max_cache(struct bridge_if *bif, int32_t max_cache); - -/* Set the bridge TX hold count. */ -int bridge_set_tx_hold_count(struct bridge_if *bif, int32_t tx_hc); - -/* Set the bridge STP protocol version. */ -int bridge_set_stp_version(struct bridge_if *bif, int32_t stp_proto); - -/* Set the bridge interface status to up/down. */ -int bridge_set_if_up(const char* b_name, int8_t up); - -/* Create a bridge interface. */ -int bridge_create(const char *b_name); - -/* Destroy a bridge interface. */ -int bridge_destroy(const char *b_name); - -/* Fetch the bridge mac address. */ -u_char *bridge_get_basemac(const char *bif_name, u_char *mac, size_t mlen); - -/* Set a bridge member priority. */ -int bridge_port_set_priority(const char *bif_name, struct bridge_port *bp, - int32_t priority); - -/* Set a bridge member STP-enabled flag. */ -int bridge_port_set_stp_enable(const char *bif_name, struct bridge_port *bp, - uint32_t enable); - -/* Set a bridge member STP path cost. */ -int bridge_port_set_path_cost(const char *bif_name, struct bridge_port *bp, - int32_t path_cost); - -/* Set admin point-to-point link. */ -int bridge_port_set_admin_ptp(const char *bif_name, struct bridge_port *bp, - uint32_t admin_ptp); - -/* Set admin edge. */ -int bridge_port_set_admin_edge(const char *bif_name, struct bridge_port *bp, - uint32_t enable); - -/* Set 'private' flag. */ -int bridge_port_set_private(const char *bif_name, struct bridge_port *bp, - uint32_t priv_set); - -/* Add a bridge member port. */ -int bridge_port_addm(struct bridge_port *bp, const char *b_name); - -/* Delete a bridge member port. */ -int bridge_port_delm(struct bridge_port *bp, const char *b_name); - -/* Get the current value from the module for bridge PF control. */ -int32_t bridge_get_pfval(uint8_t which); - -/* Get/Set a bridge PF control. */ -int32_t bridge_do_pfctl(int32_t bridge_ctl, enum snmp_op op, int32_t *val); - -#endif /* SNMP_BRIDGE_H */ diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c deleted file mode 100644 index 9684d68..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_sys.c +++ /dev/null @@ -1,1503 +0,0 @@ -/*- - * Copyright (c) 2006 Shteryana Shopova - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Bridge MIB implementation for SNMPd. - * Bridge OS specific ioctls. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "bridge_tree.h" -#include "bridge_snmp.h" - -int sock = -1; - -int -bridge_ioctl_init(void) -{ - if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - syslog(LOG_ERR, "cannot open socket : %s", strerror(errno)); - return (-1); - } - - return (0); -} - -/* - * Load the if_bridge.ko module in kernel if not already there. - */ -int -bridge_kmod_load(void) -{ - int fileid, modid; - const char mod_name[] = "if_bridge"; - struct module_stat mstat; - - /* Scan files in kernel. */ - mstat.version = sizeof(struct module_stat); - for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { - /* Scan modules in file. */ - for (modid = kldfirstmod(fileid); modid > 0; - modid = modfnext(modid)) { - - if (modstat(modid, &mstat) < 0) - continue; - - if (strcmp(mod_name, mstat.name) == 0) - return (0); - } - } - - /* Not present - load it. */ - if (kldload(mod_name) < 0) { - syslog(LOG_ERR, "failed to load %s kernel module", mod_name); - return (-1); - } - - return (1); -} - -/************************************************************************ - * Bridge interfaces. - */ - -/* - * Convert the kernel uint64_t value for a bridge id - */ -static void -snmp_uint64_to_bridgeid(uint64_t id, bridge_id b_id) -{ - int i; - u_char *o; - - o = (u_char *) &id; - - for (i = 0; i < SNMP_BRIDGE_ID_LEN; i++, o++) - b_id[SNMP_BRIDGE_ID_LEN - i - 1] = *o; -} - -/* - * Fetch the bridge configuration parameters from the kernel excluding - * it's base MAC address. - */ -static int -bridge_get_conf_param(struct bridge_if *bif) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - - /* Bridge priority. */ - ifd.ifd_cmd = BRDGGPRI; - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGGPRI) failed: %s", - strerror(errno)); - return (-1); - } - - bif->priority = b_param.ifbrp_prio; - - /* Configured max age. */ - ifd.ifd_cmd = BRDGGMA; - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGGMA) failed: %s", - strerror(errno)); - return (-1); - } - - /* Centi-seconds. */ - bif->bridge_max_age = 100 * b_param.ifbrp_maxage; - - /* Configured hello time. */ - ifd.ifd_cmd = BRDGGHT; - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGGHT) failed: %s", - strerror(errno)); - return (-1); - } - bif->bridge_hello_time = 100 * b_param.ifbrp_hellotime; - - /* Forward delay. */ - ifd.ifd_cmd = BRDGGFD; - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGGFD) failed: %s", - strerror(errno)); - return (-1); - } - bif->bridge_fwd_delay = 100 * b_param.ifbrp_fwddelay; - - /* Number of dropped addresses. */ - ifd.ifd_cmd = BRDGGRTE; - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGGRTE) failed: %s", - strerror(errno)); - return (-1); - } - bif->lrnt_drops = b_param.ifbrp_cexceeded; - - /* Address table timeout. */ - ifd.ifd_cmd = BRDGGTO; - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGGTO) failed: %s", - strerror(errno)); - return (-1); - } - bif->age_time = b_param.ifbrp_ctime; - - /* Address table size. */ - ifd.ifd_cmd = BRDGGCACHE; - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGGCACHE) " - "failed: %s", strerror(errno)); - return (-1); - } - bif->max_addrs = b_param.ifbrp_csize; - - return (0); -} - -/* - * Fetch the current bridge STP operational parameters. - * Returns: -1 - on error; - * 0 - old TC time and Root Port values are same; - * 1 - topologyChange notification should be sent; - * 2 - newRoot notification should be sent. - */ -int -bridge_get_op_param(struct bridge_if *bif) -{ - int new_root_send; - struct ifdrv ifd; - struct ifbropreq b_req; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - ifd.ifd_cmd = BRDGPARAM; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "update bridge: ioctl(BRDGPARAM) failed: %s", - strerror(errno)); - return (-1); - } - - bif->max_age = 100 * b_req.ifbop_maxage; - bif->hello_time = 100 * b_req.ifbop_hellotime; - bif->fwd_delay = 100 * b_req.ifbop_fwddelay; - bif->stp_version = b_req.ifbop_protocol; - bif->tx_hold_count = b_req.ifbop_holdcount; - - if (b_req.ifbop_root_port == 0 && - bif->root_port != b_req.ifbop_root_port) - new_root_send = 2; - else - new_root_send = 0; - - bif->root_port = b_req.ifbop_root_port; - bif->root_cost = b_req.ifbop_root_path_cost; - snmp_uint64_to_bridgeid(b_req.ifbop_designated_root, - bif->design_root); - - if (bif->last_tc_time.tv_sec != b_req.ifbop_last_tc_time.tv_sec) { - bif->top_changes++; - bif->last_tc_time.tv_sec = b_req.ifbop_last_tc_time.tv_sec; - bif->last_tc_time.tv_usec = b_req.ifbop_last_tc_time.tv_usec; - - /* - * "The trap is not sent if a (begemotBridge)NewRoot - * trap is sent for the same transition." - */ - if (new_root_send == 0) - return (1); - } - - return (new_root_send); -} - -int -bridge_getinfo_bif(struct bridge_if *bif) -{ - if (bridge_get_conf_param(bif) < 0) - return (-1); - - return (bridge_get_op_param(bif)); -} - -int -bridge_set_priority(struct bridge_if *bif, int32_t priority) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_prio = (uint32_t) priority; - ifd.ifd_cmd = BRDGSPRI; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSPRI) " - "failed: %s", strerror(errno)); - return (-1); - } - - /* - * Re-fetching the data from the driver after that might be a good - * idea, since changing our bridge's priority should invoke - * recalculation of the active spanning tree topology in the network. - */ - bif->priority = priority; - return (0); -} - -/* - * Convert 1/100 of seconds to 1/256 of seconds. - * Timeout ::= TEXTUAL-CONVENTION. - * To convert a Timeout value into a value in units of - * 1/256 seconds, the following algorithm should be used: - * b = floor( (n * 256) / 100) - * The conversion to 1/256 of a second happens in the kernel - - * just make sure we correctly convert the seconds to Timout - * and vice versa. - */ -static uint32_t -snmp_timeout2_sec(int32_t secs) -{ - return (secs / 100); -} - -int -bridge_set_maxage(struct bridge_if *bif, int32_t max_age) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_maxage = snmp_timeout2_sec(max_age); - ifd.ifd_cmd = BRDGSMA; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSMA) " - "failed: %s", strerror(errno)); - return (-1); - } - - bif->bridge_max_age = max_age; - return (0); -} - -int -bridge_set_hello_time(struct bridge_if *bif, int32_t hello_time) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_hellotime = snmp_timeout2_sec(hello_time); - ifd.ifd_cmd = BRDGSHT; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSHT) " - "failed: %s", strerror(errno)); - return (-1); - } - - bif->bridge_hello_time = b_param.ifbrp_hellotime; - return (0); -} - -int -bridge_set_forward_delay(struct bridge_if *bif, int32_t fwd_delay) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_fwddelay = snmp_timeout2_sec(fwd_delay); - ifd.ifd_cmd = BRDGSFD; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSFD) " - "failed: %s", strerror(errno)); - return (-1); - } - - bif->bridge_fwd_delay = b_param.ifbrp_fwddelay; - return (0); -} - -int -bridge_set_aging_time(struct bridge_if *bif, int32_t age_time) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_ctime = (uint32_t) age_time; - ifd.ifd_cmd = BRDGSTO; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSTO) " - "failed: %s", strerror(errno)); - return (-1); - } - - bif->age_time = age_time; - return (0); -} - -int -bridge_set_max_cache(struct bridge_if *bif, int32_t max_cache) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_csize = max_cache; - ifd.ifd_cmd = BRDGSCACHE; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSCACHE) " - "failed: %s", strerror(errno)); - return (-1); - } - - bif->max_addrs = b_param.ifbrp_csize; - return (0); -} - -int -bridge_set_tx_hold_count(struct bridge_if *bif, int32_t tx_hc) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - if (tx_hc < SNMP_BRIDGE_MIN_TXHC || tx_hc > SNMP_BRIDGE_MAX_TXHC) - return (-1); - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_txhc = tx_hc; - ifd.ifd_cmd = BRDGSTXHC; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSTXHC) " - "failed: %s", strerror(errno)); - return (-1); - } - - bif->tx_hold_count = b_param.ifbrp_txhc; - return (0); -} - -int -bridge_set_stp_version(struct bridge_if *bif, int32_t stp_proto) -{ - struct ifdrv ifd; - struct ifbrparam b_param; - - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_len = sizeof(b_param); - ifd.ifd_data = &b_param; - b_param.ifbrp_proto = stp_proto; - ifd.ifd_cmd = BRDGSPROTO; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set bridge param: ioctl(BRDGSPROTO) " - "failed: %s", strerror(errno)); - return (-1); - } - - bif->stp_version = b_param.ifbrp_proto; - return (0); -} - -/* - * Set the bridge interface status to up/down. - */ -int -bridge_set_if_up(const char* b_name, int8_t up) -{ - int flags; - struct ifreq ifr; - - bzero(&ifr, sizeof(ifr)); - strcpy(ifr.ifr_name, b_name); - if (ioctl(sock, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { - syslog(LOG_ERR, "set bridge up: ioctl(SIOCGIFFLAGS) " - "failed: %s", strerror(errno)); - return (-1); - } - - flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16); - if (up == 1) - flags |= IFF_UP; - else - flags &= ~IFF_UP; - - ifr.ifr_flags = flags & 0xffff; - ifr.ifr_flagshigh = flags >> 16; - if (ioctl(sock, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { - syslog(LOG_ERR, "set bridge up: ioctl(SIOCSIFFLAGS) " - "failed: %s", strerror(errno)); - return (-1); - } - - return (0); -} - -int -bridge_create(const char *b_name) -{ - char *new_name; - struct ifreq ifr; - - bzero(&ifr, sizeof(ifr)); - strcpy(ifr.ifr_name, b_name); - - if (ioctl(sock, SIOCIFCREATE, &ifr) < 0) { - syslog(LOG_ERR, "create bridge: ioctl(SIOCIFCREATE) " - "failed: %s", strerror(errno)); - return (-1); - } - - if (strcmp(b_name, ifr.ifr_name) == 0) - return (0); - - if ((new_name = strdup(b_name)) == NULL) { - syslog(LOG_ERR, "create bridge: strdup() failed"); - return (-1); - } - - ifr.ifr_data = new_name; - if (ioctl(sock, SIOCSIFNAME, (caddr_t) &ifr) < 0) { - syslog(LOG_ERR, "create bridge: ioctl(SIOCSIFNAME) " - "failed: %s", strerror(errno)); - free(new_name); - return (-1); - } - - return (0); -} - -int -bridge_destroy(const char *b_name) -{ - struct ifreq ifr; - - bzero(&ifr, sizeof(ifr)); - strcpy(ifr.ifr_name, b_name); - - if (ioctl(sock, SIOCIFDESTROY, &ifr) < 0) { - syslog(LOG_ERR, "destroy bridge: ioctl(SIOCIFDESTROY) " - "failed: %s", strerror(errno)); - return (-1); - } - - return (0); -} - -/* - * Fetch the bridge base MAC address. Return pointer to the - * buffer containing the MAC address, NULL on failure. - */ -u_char * -bridge_get_basemac(const char *bif_name, u_char *mac, size_t mlen) -{ - int len; - char if_name[IFNAMSIZ]; - struct ifaddrs *ifap, *ifa; - struct sockaddr_dl sdl; - - if (getifaddrs(&ifap) != 0) { - syslog(LOG_ERR, "bridge get mac: getifaddrs() failed - %s", - strerror(errno)); - return (NULL); - } - - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr->sa_family != AF_LINK) - continue; - - /* - * Not just casting because of alignment constraints - * on sparc64 and ia64. - */ - bcopy(ifa->ifa_addr, &sdl, sizeof(struct sockaddr_dl)); - - if (sdl.sdl_alen > mlen) - continue; - - if ((len = sdl.sdl_nlen) >= IFNAMSIZ) - len = IFNAMSIZ - 1; - - bcopy(sdl.sdl_data, if_name, len); - if_name[len] = '\0'; - - if (strcmp(bif_name, if_name) == 0) { - bcopy(sdl.sdl_data + sdl.sdl_nlen, mac, sdl.sdl_alen); - freeifaddrs(ifap); - return (mac); - } - } - - freeifaddrs(ifap); - return (NULL); -} - -/************************************************************************ - * Bridge ports. - */ - -/* - * Convert the kernel STP port state into - * the corresopnding enumerated type from SNMP Bridge MIB. - */ -static int -state2snmp_st(uint8_t ifbr_state) -{ - switch (ifbr_state) { - case BSTP_IFSTATE_DISABLED: - return (StpPortState_disabled); - case BSTP_IFSTATE_LISTENING: - return (StpPortState_listening); - case BSTP_IFSTATE_LEARNING: - return (StpPortState_learning); - case BSTP_IFSTATE_FORWARDING: - return (StpPortState_forwarding); - case BSTP_IFSTATE_BLOCKING: - case BSTP_IFSTATE_DISCARDING: - return (StpPortState_blocking); - } - - return (StpPortState_broken); -} - -/* - * Fill in a bridge member information according to data polled from kernel. - */ -static void -bridge_port_getinfo_conf(struct ifbreq *k_info, struct bridge_port *bp) -{ - bp->state = state2snmp_st(k_info->ifbr_state); - bp->priority = k_info->ifbr_priority; - - /* - * RFC 4188: - * "New implementations should support dot1dStpPortPathCost32. - * If the port path costs exceeds the maximum value of this - * object then this object should report the maximum value, - * namely 65535. Applications should try to read the - * dot1dStpPortPathCost32 object if this object reports - * the maximum value." - */ - - if (k_info->ifbr_ifsflags & IFBIF_BSTP_ADMCOST) - bp->admin_path_cost = k_info->ifbr_path_cost; - else - bp->admin_path_cost = 0; - - bp->path_cost = k_info->ifbr_path_cost; - - if (k_info->ifbr_ifsflags & IFBIF_STP) - bp->enable = dot1dStpPortEnable_enabled; - else - bp->enable = dot1dStpPortEnable_disabled; - - /* Begemot Bridge MIB only. */ - if (k_info->ifbr_ifsflags & IFBIF_SPAN) - bp->span_enable = begemotBridgeBaseSpanEnabled_enabled; - else - bp->span_enable = begemotBridgeBaseSpanEnabled_disabled; - - if (k_info->ifbr_ifsflags & IFBIF_PRIVATE) - bp->priv_set = TruthValue_true; - else - bp->priv_set = TruthValue_false; - - if (k_info->ifbr_ifsflags & IFBIF_BSTP_ADMEDGE) - bp->admin_edge = TruthValue_true; - else - bp->admin_edge = TruthValue_false; - - if (k_info->ifbr_ifsflags & IFBIF_BSTP_EDGE) - bp->oper_edge = TruthValue_true; - else - bp->oper_edge = TruthValue_false; - - if (k_info->ifbr_ifsflags & IFBIF_BSTP_AUTOPTP) { - bp->admin_ptp = StpPortAdminPointToPointType_auto; - if (k_info->ifbr_ifsflags & IFBIF_BSTP_PTP) - bp->oper_ptp = TruthValue_true; - else - bp->oper_ptp = TruthValue_false; - } else if (k_info->ifbr_ifsflags & IFBIF_BSTP_PTP) { - bp->admin_ptp = StpPortAdminPointToPointType_forceTrue; - bp->oper_ptp = TruthValue_true; - } else { - bp->admin_ptp = StpPortAdminPointToPointType_forceFalse; - bp->oper_ptp = TruthValue_false; - } -} - -/* - * Fill in a bridge interface STP information according to - * data polled from kernel. - */ -static void -bridge_port_getinfo_opstp(struct ifbpstpreq *bp_stp, struct bridge_port *bp) -{ - bp->enable = dot1dStpPortEnable_enabled; - bp->fwd_trans = bp_stp->ifbp_fwd_trans; - bp->design_cost = bp_stp->ifbp_design_cost; - snmp_uint64_to_bridgeid(bp_stp->ifbp_design_root, bp->design_root); - snmp_uint64_to_bridgeid(bp_stp->ifbp_design_bridge, bp->design_bridge); - bcopy(&(bp_stp->ifbp_design_port), &(bp->design_port), - sizeof(uint16_t)); -} - -/* - * Clear a bridge interface STP information. - */ -static void -bridge_port_clearinfo_opstp(struct bridge_port *bp) -{ - if (bp->enable == dot1dStpPortEnable_enabled) { - bp->design_cost = 0; - bzero(&(bp->design_root), sizeof(bridge_id)); - bzero(&(bp->design_bridge), sizeof(bridge_id)); - bzero(&(bp->design_port), sizeof(port_id)); - bp->fwd_trans = 0; - } - - bp->enable = dot1dStpPortEnable_disabled; -} - -/* - * Set a bridge member priority. - */ -int -bridge_port_set_priority(const char *bif_name, struct bridge_port *bp, - int32_t priority) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - - b_req.ifbr_priority = (uint8_t) priority; - ifd.ifd_cmd = BRDGSIFPRIO; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set member %s param: ioctl(BRDGSIFPRIO) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - bp->priority = priority; - return (0); -} - -/* - * Set a bridge member STP-enabled flag. - */ -int -bridge_port_set_stp_enable(const char *bif_name, struct bridge_port *bp, - uint32_t enable) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - if (bp->enable == enable) - return (0); - - bzero(&b_req, sizeof(b_req)); - strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - ifd.ifd_cmd = BRDGGIFFLGS; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "get member %s param: ioctl(BRDGGIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - if (enable == dot1dStpPortEnable_enabled) - b_req.ifbr_ifsflags |= IFBIF_STP; - else - b_req.ifbr_ifsflags &= ~IFBIF_STP; - - ifd.ifd_cmd = BRDGSIFFLGS; - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set member %s param: ioctl(BRDGSIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - bp->enable = enable; - return (0); -} - -/* - * Set a bridge member STP path cost. - */ -int -bridge_port_set_path_cost(const char *bif_name, struct bridge_port *bp, - int32_t path_cost) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - if (path_cost < SNMP_PORT_MIN_PATHCOST || - path_cost > SNMP_PORT_PATHCOST_OBSOLETE) - return (-2); - - strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - - b_req.ifbr_path_cost = path_cost; - ifd.ifd_cmd = BRDGSIFCOST; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set member %s param: ioctl(BRDGSIFCOST) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - bp->admin_path_cost = path_cost; - - return (0); -} - -/* - * Set the PonitToPoint status of the link administratively. - */ -int -bridge_port_set_admin_ptp(const char *bif_name, struct bridge_port *bp, - uint32_t admin_ptp) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - if (bp->admin_ptp == admin_ptp) - return (0); - - bzero(&b_req, sizeof(b_req)); - strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - ifd.ifd_cmd = BRDGGIFFLGS; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "get member %s param: ioctl(BRDGGIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - switch (admin_ptp) { - case StpPortAdminPointToPointType_forceTrue: - b_req.ifbr_ifsflags &= ~IFBIF_BSTP_AUTOPTP; - b_req.ifbr_ifsflags |= IFBIF_BSTP_PTP; - break; - case StpPortAdminPointToPointType_forceFalse: - b_req.ifbr_ifsflags &= ~IFBIF_BSTP_AUTOPTP; - b_req.ifbr_ifsflags &= ~IFBIF_BSTP_PTP; - break; - case StpPortAdminPointToPointType_auto: - b_req.ifbr_ifsflags |= IFBIF_BSTP_AUTOPTP; - break; - } - - ifd.ifd_cmd = BRDGSIFFLGS; - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set member %s param: ioctl(BRDGSIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - bp->admin_ptp = admin_ptp; - return (0); -} - -/* - * Set admin edge. - */ -int -bridge_port_set_admin_edge(const char *bif_name, struct bridge_port *bp, - uint32_t enable) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - if (bp->admin_edge == enable) - return (0); - - bzero(&b_req, sizeof(b_req)); - strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - ifd.ifd_cmd = BRDGGIFFLGS; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "get member %s param: ioctl(BRDGGIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - if (enable == TruthValue_true) { - b_req.ifbr_ifsflags &= ~IFBIF_BSTP_AUTOEDGE; - b_req.ifbr_ifsflags |= IFBIF_BSTP_EDGE; - } else - b_req.ifbr_ifsflags &= ~IFBIF_BSTP_EDGE; - - ifd.ifd_cmd = BRDGSIFFLGS; - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set member %s param: ioctl(BRDGSIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - bp->admin_edge = enable; - - return (0); -} - -/* - * Set 'private' flag. - */ -int -bridge_port_set_private(const char *bif_name, struct bridge_port *bp, - uint32_t priv_set) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - if (bp->priv_set == priv_set) - return (0); - - bzero(&b_req, sizeof(b_req)); - strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - ifd.ifd_cmd = BRDGGIFFLGS; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "get member %s param: ioctl(BRDGGIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - if (priv_set == TruthValue_true) - b_req.ifbr_ifsflags |= IFBIF_PRIVATE; - else if (priv_set == TruthValue_false) - b_req.ifbr_ifsflags &= ~IFBIF_PRIVATE; - else - return (SNMP_ERR_WRONG_VALUE); - - ifd.ifd_cmd = BRDGSIFFLGS; - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "set member %s param: ioctl(BRDGSIFFLGS) " - "failed: %s", bp->p_name, strerror(errno)); - return (-1); - } - - bp->priv_set = priv_set; - - return (0); -} - - -/* - * Add a bridge member port. - */ -int -bridge_port_addm(struct bridge_port *bp, const char *b_name) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - bzero(&ifd, sizeof(ifd)); - bzero(&b_req, sizeof(b_req)); - - strlcpy(ifd.ifd_name, b_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - - if (bp->span_enable == begemotBridgeBaseSpanEnabled_enabled) - ifd.ifd_cmd = BRDGADDS; - else - ifd.ifd_cmd = BRDGADD; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "%s - add member : ioctl(%s) failed: %s", - bp->p_name, - (ifd.ifd_cmd == BRDGADDS ? "BRDGADDS" : "BRDGADD"), - strerror(errno)); - return (-1); - } - - return (0); -} - -/* - * Delete a bridge member port. - */ -int -bridge_port_delm(struct bridge_port *bp, const char *b_name) -{ - struct ifdrv ifd; - struct ifbreq b_req; - - bzero(&ifd, sizeof(ifd)); - bzero(&b_req, sizeof(b_req)); - - strlcpy(ifd.ifd_name, b_name, sizeof(ifd.ifd_name)); - ifd.ifd_len = sizeof(b_req); - ifd.ifd_data = &b_req; - strlcpy(b_req.ifbr_ifsname, bp->p_name, sizeof(b_req.ifbr_ifsname)); - - if (bp->span_enable == begemotBridgeBaseSpanEnabled_enabled) - ifd.ifd_cmd = BRDGDELS; - else - ifd.ifd_cmd = BRDGDEL; - - if (ioctl(sock, SIOCSDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "%s - add member : ioctl(%s) failed: %s", - bp->p_name, - (ifd.ifd_cmd == BRDGDELS ? "BRDGDELS" : "BRDGDEL"), - strerror(errno)); - return (-1); - } - - return (0); -} - -/* - * Fetch the bridge member list from kernel. - * Return -1 on error, or buffer len if successful. - */ -static int32_t -bridge_port_get_iflist(struct bridge_if *bif, struct ifbreq **buf) -{ - int n = 128; - uint32_t len; - struct ifbreq *ninbuf; - struct ifbifconf ifbc; - struct ifdrv ifd; - - *buf = NULL; - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_cmd = BRDGGIFS; - ifd.ifd_len = sizeof(ifbc); - ifd.ifd_data = &ifbc; - - for ( ; ; ) { - len = n * sizeof(struct ifbreq); - if ((ninbuf = (struct ifbreq *)realloc(*buf, len)) == NULL) { - syslog(LOG_ERR, "get bridge member list: " - "realloc failed: %s", strerror(errno)); - free(*buf); - *buf = NULL; - return (-1); - } - - ifbc.ifbic_len = len; - ifbc.ifbic_req = *buf = ninbuf; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "get bridge member list: ioctl " - "(BRDGGIFS) failed: %s", strerror(errno)); - free(*buf); - buf = NULL; - return (-1); - } - - if ((ifbc.ifbic_len + sizeof(struct ifbreq)) < len) - break; - - n += 64; - } - - return (ifbc.ifbic_len); -} - -/* - * Fetch the bridge STP member list from kernel. - * Return -1 on error, or buffer len if successful. - */ -static int32_t -bridge_port_get_ifstplist(struct bridge_if *bif, struct ifbpstpreq **buf) -{ - int n = 128; - uint32_t len; - struct ifbpstpreq *ninbuf; - struct ifbpstpconf ifbstp; - struct ifdrv ifd; - - *buf = NULL; - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_cmd = BRDGGIFSSTP; - ifd.ifd_len = sizeof(ifbstp); - ifd.ifd_data = &ifbstp; - - for ( ; ; ) { - len = n * sizeof(struct ifbpstpreq); - if ((ninbuf = (struct ifbpstpreq *) - realloc(*buf, len)) == NULL) { - syslog(LOG_ERR, "get bridge STP ports list: " - "realloc failed: %s", strerror(errno)); - free(*buf); - *buf = NULL; - return (-1); - } - - ifbstp.ifbpstp_len = len; - ifbstp.ifbpstp_req = *buf = ninbuf; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "get bridge STP ports list: ioctl " - "(BRDGGIFSSTP) failed: %s", strerror(errno)); - free(*buf); - buf = NULL; - return (-1); - } - - if ((ifbstp.ifbpstp_len + sizeof(struct ifbpstpreq)) < len) - break; - - n += 64; - } - - return (ifbstp.ifbpstp_len); -} - -/* - * Locate a bridge if STP params structure in a buffer. - */ -static struct ifbpstpreq * -bridge_port_find_ifstplist(uint8_t port_no, struct ifbpstpreq *buf, - uint32_t buf_len) -{ - uint32_t i; - struct ifbpstpreq *bstp; - - for (i = 0; i < buf_len / sizeof(struct ifbpstpreq); i++) { - bstp = buf + i; - if (bstp->ifbp_portno == port_no) - return (bstp); - } - - return (NULL); -} - -/* - * Read the initial info for all members of a bridge interface. - * Returns the number of ports, 0 - if none, otherwise - * -1 if some other error occured. - */ -int -bridge_getinfo_bif_ports(struct bridge_if *bif) -{ - uint32_t i; - int32_t buf_len; - struct ifbreq *b_req_buf, *b_req; - struct ifbpstpreq *bs_req_buf, *bs_req; - struct bridge_port *bp; - struct mibif *m_if; - - if ((buf_len = bridge_port_get_iflist(bif, &b_req_buf)) < 0) - return (-1); - - for (i = 0; i < buf_len / sizeof(struct ifbreq); i++) { - b_req = b_req_buf + i; - - if ((m_if = mib_find_if_sys(b_req->ifbr_portno)) != NULL) { - /* Hopefully we will not fail here. */ - if ((bp = bridge_new_port(m_if, bif)) != NULL) { - bp->status = RowStatus_active; - bridge_port_getinfo_conf(b_req, bp); - bridge_port_getinfo_mibif(m_if, bp); - } - } else { - syslog(LOG_ERR, "bridge member %s not present " - "in mibII ifTable", b_req->ifbr_ifsname); - } - } - free(b_req_buf); - - if ((buf_len = bridge_port_get_ifstplist(bif, &bs_req_buf)) < 0) - return (-1); - - for (bp = bridge_port_bif_first(bif); bp != NULL; - bp = bridge_port_bif_next(bp)) { - if ((bs_req = bridge_port_find_ifstplist(bp->port_no, - bs_req_buf, buf_len)) == NULL) - bridge_port_clearinfo_opstp(bp); - else - bridge_port_getinfo_opstp(bs_req, bp); - } - free(bs_req_buf); - - return (i); -} - -/* - * Update the information for the bridge interface members. - */ -int -bridge_update_memif(struct bridge_if *bif) -{ - int added, updated; - uint32_t i; - int32_t buf_len; - struct ifbreq *b_req_buf, *b_req; - struct ifbpstpreq *bs_req_buf, *bs_req; - struct bridge_port *bp, *bp_next; - struct mibif *m_if; - - if ((buf_len = bridge_port_get_iflist(bif, &b_req_buf)) < 0) - return (-1); - - added = updated = 0; - -#define BP_FOUND 0x01 - for (i = 0; i < buf_len / sizeof(struct ifbreq); i++) { - b_req = b_req_buf + i; - - if ((m_if = mib_find_if_sys(b_req->ifbr_portno)) == NULL) { - syslog(LOG_ERR, "bridge member %s not present " - "in mibII ifTable", b_req->ifbr_ifsname); - continue; - } - - if ((bp = bridge_port_find(m_if->index, bif)) == NULL && - (bp = bridge_new_port(m_if, bif)) != NULL) { - bp->status = RowStatus_active; - added++; - } - - if (bp != NULL) { - updated++; - bridge_port_getinfo_conf(b_req, bp); - bridge_port_getinfo_mibif(m_if, bp); - bp->flags |= BP_FOUND; - } - } - free(b_req_buf); - - /* Clean up list. */ - for (bp = bridge_port_bif_first(bif); bp != NULL; bp = bp_next) { - bp_next = bridge_port_bif_next(bp); - - if ((bp->flags & BP_FOUND) == 0 && - bp->status == RowStatus_active) - bridge_port_remove(bp, bif); - else - bp->flags |= ~BP_FOUND; - } -#undef BP_FOUND - - if ((buf_len = bridge_port_get_ifstplist(bif, &bs_req_buf)) < 0) - return (-1); - - for (bp = bridge_port_bif_first(bif); bp != NULL; - bp = bridge_port_bif_next(bp)) { - if ((bs_req = bridge_port_find_ifstplist(bp->port_no, - bs_req_buf, buf_len)) == NULL) - bridge_port_clearinfo_opstp(bp); - else - bridge_port_getinfo_opstp(bs_req, bp); - } - free(bs_req_buf); - bif->ports_age = time(NULL); - - return (updated); -} - -/************************************************************************ - * Bridge addresses. - */ - -/* - * Update the bridge address info according to the polled data. - */ -static void -bridge_addrs_info_ifaddrlist(struct ifbareq *ifba, struct tp_entry *tpe) -{ - tpe->port_no = if_nametoindex(ifba->ifba_ifsname); - - if ((ifba->ifba_flags & IFBAF_TYPEMASK) == IFBAF_STATIC) - tpe->status = TpFdbStatus_mgmt; - else - tpe->status = TpFdbStatus_learned; -} - -/* - * Read the bridge addresses from kernel. - * Return -1 on error, or buffer len if successful. - */ -static int32_t -bridge_addrs_getinfo_ifalist(struct bridge_if *bif, struct ifbareq **buf) -{ - int n = 128; - uint32_t len; - struct ifbareq *ninbuf; - struct ifbaconf bac; - struct ifdrv ifd; - - *buf = NULL; - strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ); - ifd.ifd_cmd = BRDGRTS; - ifd.ifd_len = sizeof(bac); - ifd.ifd_data = &bac; - - for ( ; ; ) { - len = n * sizeof(struct ifbareq); - if ((ninbuf = (struct ifbareq *)realloc(*buf, len)) == NULL) { - syslog(LOG_ERR, "get bridge address list: " - " realloc failed: %s", strerror(errno)); - free(*buf); - *buf = NULL; - return (-1); - } - - bac.ifbac_len = len; - bac.ifbac_req = *buf = ninbuf; - - if (ioctl(sock, SIOCGDRVSPEC, &ifd) < 0) { - syslog(LOG_ERR, "get bridge address list: " - "ioctl(BRDGRTS) failed: %s", strerror(errno)); - free(*buf); - buf = NULL; - return (-1); - } - - if ((bac.ifbac_len + sizeof(struct ifbareq)) < len) - break; - - n += 64; - } - - return (bac.ifbac_len); -} - -/* - * Read the initial info for all addresses on a bridge interface. - * Returns the number of addresses, 0 - if none, otherwise - * -1 if some other error occured. - */ -int -bridge_getinfo_bif_addrs(struct bridge_if *bif) -{ - uint32_t i; - int32_t buf_len; - struct ifbareq *addr_req_buf, *addr_req; - struct tp_entry *te; - - if ((buf_len = bridge_addrs_getinfo_ifalist(bif, &addr_req_buf)) < 0) - return (-1); - - for (i = 0; i < buf_len / sizeof(struct ifbareq); i++) { - addr_req = addr_req_buf + i; - - if ((te = bridge_new_addrs(addr_req->ifba_dst, bif)) != NULL) - bridge_addrs_info_ifaddrlist(addr_req, te); - } - - free(addr_req_buf); - return (i); -} - -/* - * Update the addresses for the bridge interface. - */ -int -bridge_update_addrs(struct bridge_if *bif) -{ - int added, updated; - uint32_t i; - int32_t buf_len; - struct tp_entry *te, *te_next; - struct ifbareq *addr_req_buf, *addr_req; - - if ((buf_len = bridge_addrs_getinfo_ifalist(bif, &addr_req_buf)) < 0) - return (-1); - - added = updated = 0; - -#define BA_FOUND 0x01 - for (i = 0; i < buf_len / sizeof(struct ifbareq); i++) { - addr_req = addr_req_buf + i; - - if ((te = bridge_addrs_find(addr_req->ifba_dst, bif)) == NULL) { - added++; - - if ((te = bridge_new_addrs(addr_req->ifba_dst, bif)) - == NULL) - continue; - } else - updated++; - - bridge_addrs_info_ifaddrlist(addr_req, te); - te-> flags |= BA_FOUND; - } - free(addr_req_buf); - - for (te = bridge_addrs_bif_first(bif); te != NULL; te = te_next) { - te_next = bridge_addrs_bif_next(te); - - if ((te-> flags & BA_FOUND) == 0) - bridge_addrs_remove(te, bif); - else - te-> flags &= ~BA_FOUND; - } -#undef BA_FOUND - - bif->addrs_age = time(NULL); - return (updated + added); -} - -/************************************************************************ - * Bridge packet filtering. - */ -const char bridge_sysctl[] = "net.link.bridge."; - -static struct { - int32_t val; - const char *name; -} bridge_pf_sysctl[] = { - { 1, "pfil_bridge" }, - { 1, "pfil_member" }, - { 1, "pfil_onlyip" }, - { 0, "ipfw" }, -}; - -int32_t -bridge_get_pfval(uint8_t which) -{ - if (which > sizeof(bridge_pf_sysctl) / sizeof(bridge_pf_sysctl[0]) - || which < 1) - return (-1); - - return (bridge_pf_sysctl[which - 1].val); -} - -int32_t -bridge_do_pfctl(int32_t bridge_ctl, enum snmp_op op, int32_t *val) -{ - char mib_name[100]; - int32_t i, s_i; - size_t len, s_len; - - if (bridge_ctl >= LEAF_begemotBridgeLayer2PfStatus) - return (-2); - - if (op == SNMP_OP_SET) { - s_i = *val; - s_len = sizeof(s_i); - } else - s_len = 0; - - len = sizeof(i); - - strcpy(mib_name, bridge_sysctl); - - if (sysctlbyname(strcat(mib_name, - bridge_pf_sysctl[bridge_ctl].name), &i, &len, - (op == SNMP_OP_SET ? &s_i : NULL), s_len) == -1) { - syslog(LOG_ERR, "sysctl(%s%s) failed - %s", bridge_sysctl, - bridge_pf_sysctl[bridge_ctl].name, strerror(errno)); - return (-1); - } - - bridge_pf_sysctl[bridge_ctl].val = i; - *val = i; - - return (i); -} - -void -bridge_pf_dump(void) -{ - uint8_t i; - - for (i = 0; i < sizeof(bridge_pf_sysctl) / sizeof(bridge_pf_sysctl[0]); - i++) { - syslog(LOG_ERR, "%s%s = %d", bridge_sysctl, - bridge_pf_sysctl[i].name, bridge_pf_sysctl[i].val); - } -} diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_tree.def b/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_tree.def deleted file mode 100644 index cbebda0..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/bridge_tree.def +++ /dev/null @@ -1,283 +0,0 @@ -#- -# Copyright (c) 2006 Shteryana Shopova -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ -# - -#include "tc.def" - -typedef TruthValue ENUM ( - 1 true - 2 false -) - -typedef RowStatus ENUM ( - 1 active - 2 notInService - 3 notReady - 4 createAndGo - 5 createAndWait - 6 destroy -) - -typedef StpPortState ENUM ( - 1 disabled - 2 blocking - 3 listening - 4 learning - 5 forwarding - 6 broken -) - -typedef StpPortAdminPointToPointType ENUM ( - 0 forceTrue - 1 forceFalse - 2 auto -) - -typedef BaseType ENUM ( - 1 unknown - 2 transparent-only - 3 sourceroute-only - 4 srt -) - -typedef TpFdbStatus ENUM ( - 1 other - 2 invalid - 3 learned - 4 self - 5 mgmt -) - -(1 internet - (2 mgmt - (1 mib_2 - (17 dot1dBridge - (0 dot1dNotifications - (1 newRoot OID op_snmp_trap) - (2 topologyChange OID op_snmp_trap) - ) - (1 dot1dBase - (1 dot1dBaseBridgeAddress OCTETSTRING | MacAddress op_dot1d_base GET) - (2 dot1dBaseNumPorts INTEGER32 op_dot1d_base GET) - (3 dot1dBaseType BaseType op_dot1d_base GET) - (4 dot1dBasePortTable - (1 dot1dBasePortEntry : INTEGER op_dot1d_base_port - (1 dot1dBasePort INTEGER GET) - (2 dot1dBasePortIfIndex INTEGER GET) - (3 dot1dBasePortCircuit OID GET) - (4 dot1dBasePortDelayExceededDiscards COUNTER GET) - (5 dot1dBasePortMtuExceededDiscards COUNTER GET) - )) - ) - (2 dot1dStp - (1 dot1dStpProtocolSpecification ENUM ( 1 unknown 2 decLb100 3 ieee8021d ) op_dot1d_stp GET) - (2 dot1dStpPriority INTEGER op_dot1d_stp GET SET) - (3 dot1dStpTimeSinceTopologyChange TIMETICKS op_dot1d_stp GET) - (4 dot1dStpTopChanges COUNTER op_dot1d_stp GET) - (5 dot1dStpDesignatedRoot OCTETSTRING | BridgeId op_dot1d_stp GET) - (6 dot1dStpRootCost INTEGER32 op_dot1d_stp GET) - (7 dot1dStpRootPort INTEGER32 op_dot1d_stp GET) - (8 dot1dStpMaxAge INTEGER op_dot1d_stp GET) - (9 dot1dStpHelloTime INTEGER op_dot1d_stp GET) - (10 dot1dStpHoldTime INTEGER32 op_dot1d_stp GET) - (11 dot1dStpForwardDelay INTEGER op_dot1d_stp GET) - (12 dot1dStpBridgeMaxAge INTEGER op_dot1d_stp GET SET) - (13 dot1dStpBridgeHelloTime INTEGER op_dot1d_stp GET SET) - (14 dot1dStpBridgeForwardDelay INTEGER op_dot1d_stp GET SET) - (15 dot1dStpPortTable - (1 dot1dStpPortEntry : INTEGER op_dot1d_stp_port - (1 dot1dStpPort INTEGER GET) - (2 dot1dStpPortPriority INTEGER GET SET) - (3 dot1dStpPortState StpPortState GET) - (4 dot1dStpPortEnable ENUM ( 1 enabled 2 disabled ) GET SET) - (5 dot1dStpPortPathCost INTEGER GET SET) - (6 dot1dStpPortDesignatedRoot OCTETSTRING | BridgeId GET) - (7 dot1dStpPortDesignatedCost INTEGER32 GET) - (8 dot1dStpPortDesignatedBridge OCTETSTRING | BridgeId GET) - (9 dot1dStpPortDesignatedPort OCTETSTRING | BridgePortId GET) - (10 dot1dStpPortForwardTransitions COUNTER GET) - )) - (16 dot1dStpVersion ENUM ( 0 stpCompatible 2 rstp ) op_dot1d_stp GET SET) - (17 dot1dStpTxHoldCount INTEGER op_dot1d_stp GET SET) - (19 dot1dStpExtPortTable - (1 dot1dStpExtPortEntry : INTEGER op_dot1d_stp_ext_port - (1 dot1dStpPortProtocolMigration TruthValue GET) # SET - (2 dot1dStpPortAdminEdgePort TruthValue GET SET) - (3 dot1dStpPortOperEdgePort TruthValue GET) - (4 dot1dStpPortAdminPointToPoint StpPortAdminPointToPointType GET SET) - (5 dot1dStpPortOperPointToPoint TruthValue GET) - (6 dot1dStpPortAdminPathCost INTEGER GET SET) - )) - ) - (3 dot1dSr - ) - (4 dot1dTp - (1 dot1dTpLearnedEntryDiscards COUNTER op_dot1d_tp GET) - (2 dot1dTpAgingTime INTEGER op_dot1d_tp GET SET) - (3 dot1dTpFdbTable - (1 dot1dTpFdbEntry : OCTETSTRING | MacAddress op_dot1d_tp_fdb - (1 dot1dTpFdbAddress OCTETSTRING | MacAddress GET) - (2 dot1dTpFdbPort INTEGER32 GET) - (3 dot1dTpFdbStatus TpFdbStatus GET) - )) - (4 dot1dTpPortTable - (1 dot1dTpPortEntry : INTEGER op_dot1d_tp_port - (1 dot1dTpPort INTEGER GET) - (2 dot1dTpPortMaxInfo INTEGER32 GET) - (3 dot1dTpPortInFrames COUNTER GET) - (4 dot1dTpPortOutFrames COUNTER GET) - (5 dot1dTpPortInDiscards COUNTER GET) - )) - ) - (5 dot1dStatic - ) - (8 dot1dConformance - (1 dot1dGroups - ) - (2 dot1dCompliances - ) - ) - ) - (134 rstpMIB - (0 rstpNotifications - ) - (1 rstpObjects - ) - (2 rstpConformance - (1 rstpGroups - ) - (2 rstpCompliances - ) - ) - ))) - (4 private - (1 enterprises - (12325 fokus - (1 begemot - (205 begemotBridge - (0 begemotBridgeNotifications - (1 begemotBridgeNewRoot OID op_snmp_trap) - (2 begemotBridgeTopologyChange OID op_snmp_trap) - ) - (1 begemotBridgeBase - (1 begemotBridgeBaseTable - (1 begemotBridgeBaseEntry : OCTETSTRING | BridgeIfName op_begemot_base_bridge - (1 begemotBridgeBaseName OCTETSTRING | BridgeIfName GET) - (2 begemotBridgeBaseAddress OCTETSTRING | MacAddress GET) - (3 begemotBridgeBaseNumPorts INTEGER32 GET) - (4 begemotBridgeBaseType BaseType GET) - (5 begemotBridgeBaseStatus RowStatus GET SET) - )) - (2 begemotBridgeBasePortTable - (1 begemotBridgeBasePortEntry : OCTETSTRING | BridgeIfName INTEGER op_begemot_base_port - (1 begemotBridgeBasePort INTEGER GET) - (2 begemotBridgeBasePortIfIndex INTEGER GET) - (3 begemotBridgeBaseSpanEnabled ENUM ( 1 enabled 2 disabled ) GET SET) - (4 begemotBridgeBasePortDelayExceededDiscards COUNTER GET) - (5 begemotBridgeBasePortMtuExceededDiscards COUNTER GET) - (6 begemotBridgeBasePortStatus RowStatus GET SET) - (7 begemotBridgeBasePortPrivate TruthValue GET SET) - )) - ) - (2 begemotBridgeStp - (1 begemotBridgeStpTable - (1 begemotBridgeStpEntry : OCTETSTRING | BridgeIfName op_begemot_stp - (1 begemotBridgeStpProtocolSpecification ENUM ( 1 unknown 2 decLb100 3 ieee8021d ) GET) - (2 begemotBridgeStpPriority INTEGER GET SET) - (3 begemotBridgeStpTimeSinceTopologyChange TIMETICKS GET) - (4 begemotBridgeStpTopChanges COUNTER GET) - (5 begemotBridgeStpDesignatedRoot OCTETSTRING | BridgeId GET) - (6 begemotBridgeStpRootCost INTEGER32 GET) - (7 begemotBridgeStpRootPort INTEGER32 GET) - (8 begemotBridgeStpMaxAge INTEGER GET) - (9 begemotBridgeStpHelloTime INTEGER GET) - (10 begemotBridgeStpHoldTime INTEGER32 GET) - (11 begemotBridgeStpForwardDelay INTEGER GET) - (12 begemotBridgeStpBridgeMaxAge INTEGER GET SET) - (13 begemotBridgeStpBridgeHelloTime INTEGER GET SET) - (14 begemotBridgeStpBridgeForwardDelay INTEGER GET SET) - (15 begemotBridgeStpVersion ENUM ( 0 stpCompatible 2 rstp ) GET SET) - (16 begemotBridgeStpTxHoldCount INTEGER GET SET) - )) - (2 begemotBridgeStpPortTable - (1 begemotBridgeStpPortEntry : OCTETSTRING | BridgeIfName INTEGER op_begemot_stp_port - (1 begemotBridgeStpPort INTEGER GET) - (2 begemotBridgeStpPortPriority INTEGER GET SET) - (3 begemotBridgeStpPortState StpPortState GET) - (4 begemotBridgeStpPortEnable ENUM ( 1 enabled 2 disabled ) GET SET) - (5 begemotBridgeStpPortPathCost INTEGER GET SET) - (6 begemotBridgeStpPortDesignatedRoot OCTETSTRING | BridgeId GET) - (7 begemotBridgeStpPortDesignatedCost INTEGER32 GET) - (8 begemotBridgeStpPortDesignatedBridge OCTETSTRING | BridgeId GET) - (9 begemotBridgeStpPortDesignatedPort OCTETSTRING | BridgePortId GET) - (10 begemotBridgeStpPortForwardTransitions COUNTER GET) - )) - (3 begemotBridgeStpExtPortTable - (1 begemotBridgeStpExtPortEntry : OCTETSTRING | BridgeIfName INTEGER op_begemot_stp_ext_port - (1 begemotBridgeStpPortProtocolMigration TruthValue GET) # SET - (2 begemotBridgeStpPortAdminEdgePort TruthValue GET SET) - (3 begemotBridgeStpPortOperEdgePort TruthValue GET) - (4 begemotBridgeStpPortAdminPointToPoint StpPortAdminPointToPointType GET SET) - (5 begemotBridgeStpPortOperPointToPoint TruthValue GET) - (6 begemotBridgeStpPortAdminPathCost INTEGER GET SET) - )) - ) - (3 begemotBridgeTp - (1 begemotBridgeTpTable - (1 begemotBridgeTpEntry : OCTETSTRING | BridgeIfName op_begemot_tp - (1 begemotBridgeTpLearnedEntryDiscards COUNTER GET) - (2 begemotBridgeTpAgingTime INTEGER GET SET) - (3 begemotBridgeTpMaxAddresses INTEGER GET SET) - )) - (2 begemotBridgeTpFdbTable - (1 begemotBridgeTpFdbEntry : OCTETSTRING | BridgeIfName OCTETSTRING | MacAddress op_begemot_tp_fdb - (1 begemotBridgeTpFdbAddress OCTETSTRING | MacAddress GET) - (2 begemotBridgeTpFdbPort INTEGER32 GET) - (3 begemotBridgeTpFdbStatus TpFdbStatus GET) - )) - (3 begemotBridgeTpPortTable - (1 begemotBridgeTpPortEntry : OCTETSTRING | BridgeIfName INTEGER op_begemot_tp_port - (1 begemotBridgeTpPort INTEGER GET) - (2 begemotBridgeTpPortMaxInfo INTEGER32 GET) - (3 begemotBridgeTpPortInFrames COUNTER GET) - (4 begemotBridgeTpPortOutFrames COUNTER GET) - (5 begemotBridgeTpPortInDiscards COUNTER GET) - )) - ) - (4 begemotBridgePf - (1 begemotBridgePfilStatus TruthValue op_begemot_bridge_pf GET SET) - (2 begemotBridgePfilMembers TruthValue op_begemot_bridge_pf GET SET) - (3 begemotBridgePfilIpOnly TruthValue op_begemot_bridge_pf GET SET) - (4 begemotBridgeLayer2PfStatus ENUM ( 1 enabled 2 disabled ) op_begemot_bridge_pf GET SET) - ) - (5 begemotBridgeConfigObjects - (1 begemotBridgeDefaultBridgeIf OCTETSTRING | BridgeIfNameOrEmpty op_begemot_bridge_config GET SET) - (2 begemotBridgeDataUpdate INTEGER op_begemot_bridge_config GET SET) - (3 begemotBridgeDataPoll INTEGER op_begemot_bridge_config GET SET) - ) - ))))) -) diff --git a/usr.sbin/bsnmpd/modules/snmp_bridge/snmp_bridge.3 b/usr.sbin/bsnmpd/modules/snmp_bridge/snmp_bridge.3 deleted file mode 100644 index ebcf286..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_bridge/snmp_bridge.3 +++ /dev/null @@ -1,119 +0,0 @@ -.\"- -.\" Copyright (C) 2006 Shteryana Shopova -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd August 6, 2007 -.Dt snmp_bridge 3 -.Os -.Sh NAME -.Nm snmp_bridge -.Nd "bridge module for snmpd" -.Sh LIBRARY -.Pq begemotSnmpdModulePath."bridge" = "/usr/lib/snmp_bridge.so" -.Sh DESCRIPTION -The -.Nm snmp_bridge -module implements the BRIDGE-MIB as standardized in RFC 4188, the RSTP-MIB -standardized in RFC4318 and a private BEGEMOT-BRIDGE-MIB, which allows -management of multiple bridge interfaces. -Most of the objects defined in the private BEGEMOT-BRIDGE-MIB are duplicates -of the original objects defined by the standard BRIDGE-MIB, but the private -MIB also defines additional objects which make the functionality of -.Nm -similar to -.Xr ifconfig 8 -for configuring bridge interfaces. -Therefore one should consider adding write communities or loading the -.Nm -module on systems where security is crucial. -.Sh IMPLEMENTATION NOTES -The additional objects to configure a bridge are: -.Bl -tag -width "XXXXXXXXX" -.It Va begemotBridgeBaseStatus -Bridge interfaces can be created and destroyed via this object. -SNMP SET operations with the following values are allowed: -.Bl -tag -width ".It Va createAndWait" -.It Va createAndWait -will attempt to create a bridge interface with the name given by the table -index. -.It Va createAndGo -will attempt to create a bridge interface with the name given by the table -index and set the status of the interface to "active/up". -.It Va destroy -will attempt to destroy the bridge interface. -.El -.It Va begemotBridgeBaseSpanEnabled -A SNMP SET operation on this object is only successful if the corresponding -port has not been added as member of the bridge interface on the system. -.It Va begemotBridgeBasePortStatus -SNMP SET operations with the following values are allowed: -.Bl -tag -width ".It Va createAndWait" -.It Va createAndWait -will create a new row for the bridge member in the SNMP -.Va begemotBridgeBasePortTable -but will not try to commit the information to the system. -.It Va active -will attempt to commit the information to the system and will be successful -only if a value for -.Va begemotBridgeBaseSpanEnabled -has been SET already. -.It Va destroy -will attempt to remove the interface from the system bridge interface. -.El -.It Va begemotBridgeBasePortPrivate -This object controls a bridge interface flag called PRIVATE where any private -port can not communicate with another private port. -.El -.Sh RESTRICTIONS -Not all information in the MIBs is currently available in FreeBSD. -The following variables carry no information: -.Bl -tag -width "XXXXXXXXX" -.It Va dot1dBasePortCircuit -.It Va dot1dBasePortDelayExceededDiscards -.It Va dot1dBasePortMtuExceededDiscards -.It Va begemotBridgeBasePortDelayExceededDiscards -.It Va begemotBridgeBasePortMtuExceededDiscards -.El -.Sh FILES -.Bl -tag -width "XXXXXXXXX" -.It Pa /usr/share/snmp/defs/bridge_tree.def -The description of the MIB tree implemented by -.Nm . -.It Pa /usr/share/snmp/mibs/BRIDGE-MIB.txt -This is the BRIDGE-MIB that is implemented by this module. -.It Pa /usr/share/snmp/mibs/RSTP-MIB.txt -This is the RSTP-MIB implemented by this module. -.It Pa /usr/share/snmp/mibs/BEGEMOT-BRIDGE-MIB.txt -This is the private BEGEMOT-BRIDGE-MIB that is implemented by this module. -.El -.Sh SEE ALSO -.Xr bsnmpd 1 , -.Xr gensnmptree 1 , -.Xr if_bridge 4 , -.Xr ifconfig 8 , -.Xr snmpmod 3 -.Sh AUTHORS -.An Shteryana Shopova Aq syrinx@FreeBSD.org diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/BEGEMOT-HOSTRES-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_hostres/BEGEMOT-HOSTRES-MIB.txt deleted file mode 100644 index ee8d284..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/BEGEMOT-HOSTRES-MIB.txt +++ /dev/null @@ -1,125 +0,0 @@ --- --- Copyright (c) 2005-2006 --- Hartmut Brandt --- All rights reserved. --- --- Author: Harti Brandt --- --- Redistribution and use in source and binary forms, with or without --- modification, are permitted provided that the following conditions --- are met: --- 1. Redistributions of source code must retain the above copyright --- notice, this list of conditions and the following disclaimer. --- 2. Redistributions in binary form must reproduce the above copyright --- notice, this list of conditions and the following disclaimer in the --- documentation and/or other materials provided with the distribution. --- --- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND --- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE --- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE --- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE --- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL --- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS --- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) --- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT --- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY --- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF --- SUCH DAMAGE. --- --- $FreeBSD$ --- --- Additional stuff for the HOST-RESOURCES MIB. --- -BEGEMOT-HOSTRES-MIB DEFINITIONS ::= BEGIN - -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE, TimeTicks - FROM SNMPv2-SMI - begemot - FROM BEGEMOT-MIB; - -begemotHostres MODULE-IDENTITY - LAST-UPDATED "200601030000Z" - ORGANIZATION "German Aerospace Center" - CONTACT-INFO - " Hartmut Brandt - - Postal: German Aerospace Center - Oberpfaffenhofen - 82234 Wessling - Germany - - Fax: +49 8153 28 2843 - - E-mail: harti@freebsd.org" - DESCRIPTION - "The MIB for additional HOST-RESOURCES data." - ::= { begemot 202 } - -begemotHostresObjects OBJECT IDENTIFIER ::= { begemotHostres 1 } - -begemotHrStorageUpdate OBJECT-TYPE - SYNTAX TimeTicks - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of ticks the storage table is cached." - DEFVAL { 700 } - ::= { begemotHostresObjects 1 } - -begemotHrFSUpdate OBJECT-TYPE - SYNTAX TimeTicks - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of ticks the FS table is cached." - DEFVAL { 700 } - ::= { begemotHostresObjects 2 } - -begemotHrDiskStorageUpdate OBJECT-TYPE - SYNTAX TimeTicks - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of ticks the disk storage table is cached." - DEFVAL { 300 } - ::= { begemotHostresObjects 3 } - -begemotHrNetworkUpdate OBJECT-TYPE - SYNTAX TimeTicks - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of ticks the network table is cached." - DEFVAL { 700 } - ::= { begemotHostresObjects 4 } - -begemotHrSWInstalledUpdate OBJECT-TYPE - SYNTAX TimeTicks - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of ticks the hrSWInstalledTable is cached." - DEFVAL { 1200 } - ::= { begemotHostresObjects 5 } - -begemotHrSWRunUpdate OBJECT-TYPE - SYNTAX TimeTicks - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of ticks the hrSWRunTable and - hrSWRunPerfTable are cached." - DEFVAL { 300 } - ::= { begemotHostresObjects 6 } - -begemotHrPkgDir OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The path to the package DB directory." - DEFVAL { "/var/db/pkg" } - ::= { begemotHostresObjects 7 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile b/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile deleted file mode 100644 index 2922f45..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -# -# Copyright (c) 2005-2006 The FreeBSD Project -# All rights reserved. -# Author: Victor Cruceru -# -# Redistribution of this software and documentation and use in source and -# binary forms, with or without modification, are permitted provided that -# the following conditions are met: -# -# 1. Redistributions of source code or documentation must retain the above -# copyright notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ -# - -LPRSRC= ${.CURDIR}/../../../lpr/common_source -.PATH: ${LPRSRC} - -MOD= hostres -SRCS= hostres_begemot.c \ - hostres_device_tbl.c \ - hostres_diskstorage_tbl.c \ - hostres_fs_tbl.c \ - hostres_network_tbl.c \ - hostres_partition_tbl.c \ - hostres_printer_tbl.c \ - hostres_processor_tbl.c \ - hostres_scalars.c \ - hostres_snmp.c \ - hostres_storage_tbl.c \ - hostres_swinstalled_tbl.c \ - hostres_swrun_tbl.c \ - printcap.c - -#Not having NDEBUG defined will enable assertions and a lot of output on stderr -CFLAGS+= -DNDEBUG -I${LPRSRC} -XSYM= host hrStorageOther hrStorageRam hrStorageVirtualMemory \ - hrStorageFixedDisk hrStorageRemovableDisk hrStorageFloppyDisk \ - hrStorageCompactDisc hrStorageRamDisk hrStorageFlashMemory \ - hrStorageNetworkDisk hrDeviceOther hrDeviceUnknown \ - hrDeviceProcessor hrDeviceNetwork hrDevicePrinter \ - hrDeviceDiskStorage hrDeviceVideo hrDeviceAudio \ - hrDeviceCoprocessor hrDeviceKeyboard hrDeviceModem \ - hrDeviceParallelPort hrDevicePointing \ - hrDeviceSerialPort hrDeviceTape hrDeviceClock \ - hrDeviceVolatileMemory hrDeviceNonVolatileMemory \ - hrFSOther hrFSUnknown hrFSBerkeleyFFS hrFSSys5FS hrFSFat\ - hrFSHPFS hrFSHFS hrFSMFS hrFSNTFS hrFSVNode hrFSJournaled \ - hrFSiso9660 hrFSRockRidge hrFSNFS hrFSNetware hrFSAFS hrFSDFS \ - hrFSAppleshare hrFSRFS hrFSDGCFS hrFSBFS hrFSFAT32 hrFSLinuxExt2 - -MAN= snmp_hostres.3 - -DEFS= ${MOD}_tree.def -BMIBS= BEGEMOT-HOSTRES-MIB.txt - -DPADD= ${LIBKVM} ${LIBDEVINFO} ${LIBM} ${LIBGEOM} ${LIBMEMSTAT} -LDADD= -lkvm -ldevinfo -lm -lgeom -lmemstat - -.include - -printcap.So: printcap.c - ${CC} ${PICFLAG} -DPIC ${CFLAGS:C/^-W.*//} -c ${.IMPSRC} -o ${.TARGET} - -smilint: - env SMIPATH=.:/usr/share/snmp/mibs:/usr/local/share/snmp/mibs \ - smilint -c /dev/null -l6 -i group-membership BEGEMOT-HOSTRES-MIB diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_begemot.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_begemot.c deleted file mode 100644 index f1cc5e3..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_begemot.c +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * Copyright (c) 2005-2006. - * Hartmut Brandt. - * All rights reserved. - * - * Author: Hartmut Brandt - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -int -op_begemot(struct snmp_context *ctx, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op op) -{ - - switch (op) { - - case SNMP_OP_GET: - switch (value->var.subs[sub - 1]) { - - case LEAF_begemotHrStorageUpdate: - value->v.uint32 = storage_tbl_refresh; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrFSUpdate: - value->v.uint32 = fs_tbl_refresh; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrDiskStorageUpdate: - value->v.uint32 = disk_storage_tbl_refresh; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrNetworkUpdate: - value->v.uint32 = network_tbl_refresh; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrSWInstalledUpdate: - value->v.uint32 = swins_tbl_refresh; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrSWRunUpdate: - value->v.uint32 = swrun_tbl_refresh; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrPkgDir: - return (string_get(value, pkg_dir, -1)); - } - abort(); - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_SET: - switch (value->var.subs[sub - 1]) { - - case LEAF_begemotHrStorageUpdate: - ctx->scratch->int1 = storage_tbl_refresh; - storage_tbl_refresh = value->v.uint32; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrFSUpdate: - ctx->scratch->int1 = fs_tbl_refresh; - fs_tbl_refresh = value->v.uint32; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrDiskStorageUpdate: - ctx->scratch->int1 = disk_storage_tbl_refresh; - disk_storage_tbl_refresh = value->v.uint32; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrNetworkUpdate: - ctx->scratch->int1 = network_tbl_refresh; - network_tbl_refresh = value->v.uint32; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrSWInstalledUpdate: - ctx->scratch->int1 = swins_tbl_refresh; - swins_tbl_refresh = value->v.uint32; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrSWRunUpdate: - ctx->scratch->int1 = swrun_tbl_refresh; - swrun_tbl_refresh = value->v.uint32; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrPkgDir: - return (string_save(value, ctx, -1, &pkg_dir)); - } - abort(); - - case SNMP_OP_COMMIT: - switch (value->var.subs[sub - 1]) { - - case LEAF_begemotHrStorageUpdate: - case LEAF_begemotHrFSUpdate: - case LEAF_begemotHrDiskStorageUpdate: - case LEAF_begemotHrNetworkUpdate: - case LEAF_begemotHrSWInstalledUpdate: - case LEAF_begemotHrSWRunUpdate: - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrPkgDir: - string_commit(ctx); - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_ROLLBACK: - switch (value->var.subs[sub - 1]) { - - case LEAF_begemotHrStorageUpdate: - storage_tbl_refresh = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrFSUpdate: - fs_tbl_refresh = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrDiskStorageUpdate: - disk_storage_tbl_refresh = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrNetworkUpdate: - network_tbl_refresh = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrSWInstalledUpdate: - swins_tbl_refresh = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrSWRunUpdate: - swrun_tbl_refresh = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotHrPkgDir: - string_rollback(ctx, &pkg_dir); - return (SNMP_ERR_NOERROR); - } - abort(); - } - - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c deleted file mode 100644 index cb38145..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_device_tbl.c +++ /dev/null @@ -1,690 +0,0 @@ - /*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB: hrDeviceTable implementation for SNMPd. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -#define FREE_DEV_STRUCT(entry_p) do { \ - free(entry_p->name); \ - free(entry_p->location); \ - free(entry_p->descr); \ - free(entry_p); \ -} while (0) - -/* - * Status of a device - */ -enum DeviceStatus { - DS_UNKNOWN = 1, - DS_RUNNING = 2, - DS_WARNING = 3, - DS_TESTING = 4, - DS_DOWN = 5 -}; - -TAILQ_HEAD(device_tbl, device_entry); - -/* the head of the list with hrDeviceTable's entries */ -static struct device_tbl device_tbl = TAILQ_HEAD_INITIALIZER(device_tbl); - -/* Table used for consistent device table indexing. */ -struct device_map device_map = STAILQ_HEAD_INITIALIZER(device_map); - -/* next int available for indexing the hrDeviceTable */ -static uint32_t next_device_index = 1; - -/* last (agent) tick when hrDeviceTable was updated */ -static uint64_t device_tick = 0; - -/* maximum number of ticks between updates of device table */ -uint32_t device_tbl_refresh = 10 * 100; - -/* socket for /var/run/devd.pipe */ -static int devd_sock = -1; - -/* used to wait notifications from /var/run/devd.pipe */ -static void *devd_fd; - -/* some constants */ -static const struct asn_oid OIDX_hrDeviceProcessor_c = OIDX_hrDeviceProcessor; -static const struct asn_oid OIDX_hrDeviceOther_c = OIDX_hrDeviceOther; - -/** - * Create a new entry out of thin air. - */ -struct device_entry * -device_entry_create(const char *name, const char *location, const char *descr) -{ - struct device_entry *entry = NULL; - struct device_map_entry *map = NULL; - size_t name_len; - size_t location_len; - - assert((name[0] != 0) || (location[0] != 0)); - - if (name[0] == 0 && location[0] == 0) - return (NULL); - - STAILQ_FOREACH(map, &device_map, link) { - assert(map->name_key != NULL); - assert(map->location_key != NULL); - - if (strcmp(map->name_key, name) == 0 && - strcmp(map->location_key, location) == 0) { - break; - } - } - - if (map == NULL) { - /* new object - get a new index */ - if (next_device_index > INT_MAX) { - syslog(LOG_ERR, - "%s: hrDeviceTable index wrap", __func__); - /* There isn't much we can do here. - * If the next_swins_index is consumed - * then we can't add entries to this table - * So it is better to exit - if the table is sparsed - * at the next agent run we can fill it fully. - */ - errx(EX_SOFTWARE, "hrDeviceTable index wrap"); - /* not reachable */ - } - - if ((map = malloc(sizeof(*map))) == NULL) { - syslog(LOG_ERR, "hrDeviceTable: %s: %m", __func__ ); - return (NULL); - } - - map->entry_p = NULL; - - name_len = strlen(name) + 1; - if (name_len > DEV_NAME_MLEN) - name_len = DEV_NAME_MLEN; - - if ((map->name_key = malloc(name_len)) == NULL) { - syslog(LOG_ERR, "hrDeviceTable: %s: %m", __func__ ); - free(map); - return (NULL); - } - - location_len = strlen(location) + 1; - if (location_len > DEV_LOC_MLEN) - location_len = DEV_LOC_MLEN; - - if ((map->location_key = malloc(location_len )) == NULL) { - syslog(LOG_ERR, "hrDeviceTable: %s: %m", __func__ ); - free(map->name_key); - free(map); - return (NULL); - } - - map->hrIndex = next_device_index++; - - strlcpy(map->name_key, name, name_len); - strlcpy(map->location_key, location, location_len); - - STAILQ_INSERT_TAIL(&device_map, map, link); - HRDBG("%s at %s added into hrDeviceMap at index=%d", - name, location, map->hrIndex); - } else { - HRDBG("%s at %s exists in hrDeviceMap index=%d", - name, location, map->hrIndex); - } - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "hrDeviceTable: %s: %m", __func__); - return (NULL); - } - memset(entry, 0, sizeof(*entry)); - - entry->index = map->hrIndex; - map->entry_p = entry; - - if ((entry->name = strdup(map->name_key)) == NULL) { - syslog(LOG_ERR, "hrDeviceTable: %s: %m", __func__ ); - free(entry); - return (NULL); - } - - if ((entry->location = strdup(map->location_key)) == NULL) { - syslog(LOG_ERR, "hrDeviceTable: %s: %m", __func__ ); - free(entry->name); - free(entry); - return (NULL); - } - - /* - * From here till the end of this function we reuse name_len - * for a diferrent purpose - for device_entry::descr - */ - if (name[0] != '\0') - name_len = strlen(name) + strlen(descr) + - strlen(": ") + 1; - else - name_len = strlen(location) + strlen(descr) + - strlen("unknown at : ") + 1; - - if (name_len > DEV_DESCR_MLEN) - name_len = DEV_DESCR_MLEN; - - if ((entry->descr = malloc(name_len )) == NULL) { - syslog(LOG_ERR, "hrDeviceTable: %s: %m", __func__ ); - free(entry->name); - free(entry->location); - free(entry); - return (NULL); - } - - memset(&entry->descr[0], '\0', name_len); - - if (name[0] != '\0') - snprintf(entry->descr, name_len, - "%s: %s", name, descr); - else - snprintf(entry->descr, name_len, - "unknown at %s: %s", location, descr); - - entry->id = &oid_zeroDotZero; /* unknown id - FIXME */ - entry->status = (u_int)DS_UNKNOWN; - entry->errors = 0; - entry->type = &OIDX_hrDeviceOther_c; - - INSERT_OBJECT_INT(entry, &device_tbl); - - return (entry); -} - -/** - * Create a new entry into the device table. - */ -static struct device_entry * -device_entry_create_devinfo(const struct devinfo_dev *dev_p) -{ - - assert(dev_p->dd_name != NULL); - assert(dev_p->dd_location != NULL); - - return (device_entry_create(dev_p->dd_name, dev_p->dd_location, - dev_p->dd_desc)); -} - -/** - * Delete an entry from the device table. - */ -void -device_entry_delete(struct device_entry *entry) -{ - struct device_map_entry *map; - - assert(entry != NULL); - - TAILQ_REMOVE(&device_tbl, entry, link); - - STAILQ_FOREACH(map, &device_map, link) - if (map->entry_p == entry) { - map->entry_p = NULL; - break; - } - - FREE_DEV_STRUCT(entry); -} - -/** - * Find an entry given its name and location - */ -static struct device_entry * -device_find_by_dev(const struct devinfo_dev *dev_p) -{ - struct device_map_entry *map; - - assert(dev_p != NULL); - - STAILQ_FOREACH(map, &device_map, link) - if (strcmp(map->name_key, dev_p->dd_name) == 0 && - strcmp(map->location_key, dev_p->dd_location) == 0) - return (map->entry_p); - return (NULL); -} - -/** - * Find an entry given its index. - */ -struct device_entry * -device_find_by_index(int32_t idx) -{ - struct device_entry *entry; - - TAILQ_FOREACH(entry, &device_tbl, link) - if (entry->index == idx) - return (entry); - return (NULL); -} - -/** - * Find an device entry given its name. - */ -struct device_entry * -device_find_by_name(const char *dev_name) -{ - struct device_map_entry *map; - - assert(dev_name != NULL); - - STAILQ_FOREACH(map, &device_map, link) - if (strcmp(map->name_key, dev_name) == 0) - return (map->entry_p); - - return (NULL); -} - -/** - * Find out the type of device. CPU only currently. - */ -static void -device_get_type(struct devinfo_dev *dev_p, const struct asn_oid **out_type_p) -{ - - assert(dev_p != NULL); - assert(out_type_p != NULL); - - if (dev_p == NULL) - return; - - if (strncmp(dev_p->dd_name, "cpu", strlen("cpu")) == 0 && - strstr(dev_p->dd_location, ".CPU") != NULL) { - *out_type_p = &OIDX_hrDeviceProcessor_c; - return; - } -} - -/** - * Get the status of a device - */ -static enum DeviceStatus -device_get_status(struct devinfo_dev *dev) -{ - - assert(dev != NULL); - - switch (dev->dd_state) { - case DS_ALIVE: /* probe succeeded */ - case DS_NOTPRESENT: /* not probed or probe failed */ - return (DS_DOWN); - case DS_ATTACHED: /* attach method called */ - case DS_BUSY: /* device is open */ - return (DS_RUNNING); - default: - return (DS_UNKNOWN); - } -} - -/** - * Get the info for the given device and then recursively process all - * child devices. - */ -static int -device_collector(struct devinfo_dev *dev, void *arg) -{ - struct device_entry *entry; - - HRDBG("%llu/%llu name='%s' desc='%s' drivername='%s' location='%s'", - (unsigned long long)dev->dd_handle, - (unsigned long long)dev->dd_parent, dev->dd_name, dev->dd_desc, - dev->dd_drivername, dev->dd_location); - - if (dev->dd_name[0] != '\0' || dev->dd_location[0] != '\0') { - HRDBG("ANALYZING dev %s at %s", - dev->dd_name, dev->dd_location); - - if ((entry = device_find_by_dev(dev)) != NULL) { - entry->flags |= HR_DEVICE_FOUND; - entry->status = (u_int)device_get_status(dev); - } else if ((entry = device_entry_create_devinfo(dev)) != NULL) { - device_get_type(dev, &entry->type); - - entry->flags |= HR_DEVICE_FOUND; - entry->status = (u_int)device_get_status(dev); - } - } else { - HRDBG("SKIPPED unknown device at location '%s'", - dev->dd_location ); - } - - return (devinfo_foreach_device_child(dev, device_collector, arg)); -} - -/** - * Create the socket to the device daemon. - */ -static int -create_devd_socket(void) -{ - int d_sock; - struct sockaddr_un devd_addr; - - bzero(&devd_addr, sizeof(struct sockaddr_un)); - - if ((d_sock = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) { - syslog(LOG_ERR, "Failed to create the socket for %s: %m", - PATH_DEVD_PIPE); - return (-1); - } - - devd_addr.sun_family = PF_LOCAL; - devd_addr.sun_len = sizeof(devd_addr); - strlcpy(devd_addr.sun_path, PATH_DEVD_PIPE, - sizeof(devd_addr.sun_path) - 1); - - if (connect(d_sock, (struct sockaddr *)&devd_addr, - sizeof(devd_addr)) == -1) { - syslog(LOG_ERR,"Failed to connect socket for %s: %m", - PATH_DEVD_PIPE); - if (close(d_sock) < 0 ) - syslog(LOG_ERR,"Failed to close socket for %s: %m", - PATH_DEVD_PIPE); - return (-1); - } - - return (d_sock); -} - -/* - * Event on the devd socket. - * - * We should probably directly process entries here. For simplicity just - * call the refresh routine with the force flag for now. - */ -static void -devd_socket_callback(int fd, void *arg __unused) -{ - char buf[512]; - int read_len = -1; - - assert(fd == devd_sock); - - HRDBG("called"); - - read_len = read(fd, buf, sizeof(buf) - 1); - if (read_len < 0) { - if (errno == EBADF) { - devd_sock = -1; - if (devd_fd != NULL) { - fd_deselect(devd_fd); - devd_fd = NULL; - } - syslog(LOG_ERR, "Closing devd_fd, revert to " - "devinfo polling"); - } - - } else if (read_len == 0) { - syslog(LOG_ERR, "zero bytes read from devd pipe... " - "closing socket!"); - - if (close(devd_sock) < 0 ) - syslog(LOG_ERR, "Failed to close devd socket: %m"); - - devd_sock = -1; - if (devd_fd != NULL) { - fd_deselect(devd_fd); - devd_fd = NULL; - } - syslog(LOG_ERR, "Closing devd_fd, revert to devinfo polling"); - - } else { - switch (buf[0]) { - case '+': - case '-': - case '?': - case '!': - refresh_device_tbl(1); - return; - default: - syslog(LOG_ERR, "unknown message from devd socket"); - } - } -} - -/** - * Initialize and populate the device table. - */ -void -init_device_tbl(void) -{ - - /* initially populate table for the other tables */ - refresh_device_tbl(1); - - /* no problem if that fails - just use polling mode */ - devd_sock = create_devd_socket(); -} - -/** - * Start devd(8) monitoring. - */ -void -start_device_tbl(struct lmodule *mod) -{ - - if (devd_sock > 0) { - devd_fd = fd_select(devd_sock, devd_socket_callback, NULL, mod); - if (devd_fd == NULL) - syslog(LOG_ERR, "fd_select failed on devd socket: %m"); - } -} - -/** - * Finalization routine for hrDeviceTable - * It destroys the lists and frees any allocated heap memory - */ -void -fini_device_tbl(void) -{ - struct device_map_entry *n1; - - if (devd_fd != NULL) - fd_deselect(devd_fd); - - if (devd_sock != -1) - (void)close(devd_sock); - - devinfo_free(); - - while ((n1 = STAILQ_FIRST(&device_map)) != NULL) { - STAILQ_REMOVE_HEAD(&device_map, link); - if (n1->entry_p != NULL) { - TAILQ_REMOVE(&device_tbl, n1->entry_p, link); - FREE_DEV_STRUCT(n1->entry_p); - } - free(n1->name_key); - free(n1->location_key); - free(n1); - } - assert(TAILQ_EMPTY(&device_tbl)); -} - -/** - * Refresh routine for hrDeviceTable. We don't refresh here if the devd socket - * is open, because in this case we have the actual information always. We - * also don't refresh when the table is new enough (if we don't have a devd - * socket). In either case a refresh can be forced by passing a non-zero value. - */ -void -refresh_device_tbl(int force) -{ - struct device_entry *entry, *entry_tmp; - struct devinfo_dev *dev_root; - static int act = 0; - - if (!force && (devd_sock >= 0 || - (device_tick != 0 && this_tick - device_tick < device_tbl_refresh))){ - HRDBG("no refresh needed"); - return; - } - - if (act) { - syslog(LOG_ERR, "%s: recursive call", __func__); - return; - } - - if (devinfo_init() != 0) { - syslog(LOG_ERR,"%s: devinfo_init failed: %m", __func__); - return; - } - - act = 1; - if ((dev_root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL){ - syslog(LOG_ERR, "%s: can't get the root device: %m", __func__); - goto out; - } - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &device_tbl, link) - entry->flags &= ~HR_DEVICE_FOUND; - - if (devinfo_foreach_device_child(dev_root, device_collector, NULL)) - syslog(LOG_ERR, "%s: devinfo_foreach_device_child failed", - __func__); - - /* - * Purge items that disappeared - */ - TAILQ_FOREACH_SAFE(entry, &device_tbl, link, entry_tmp) { - /* - * If HR_DEVICE_IMMUTABLE bit is set then this means that - * this entry was not detected by the above - * devinfo_foreach_device() call. So we are not deleting - * it there. - */ - if (!(entry->flags & HR_DEVICE_FOUND) && - !(entry->flags & HR_DEVICE_IMMUTABLE)) - device_entry_delete(entry); - } - - device_tick = this_tick; - - /* - * Force a refresh for the hrDiskStorageTable - * XXX Why not the other dependen tables? - */ - refresh_disk_storage_tbl(1); - - out: - devinfo_free(); - act = 0; -} - -/** - * This is the implementation for a generated (by a SNMP tool) - * function prototype, see hostres_tree.h - * It handles the SNMP operations for hrDeviceTable - */ -int -op_hrDeviceTable(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - struct device_entry *entry; - - refresh_device_tbl(0); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&device_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&device_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&device_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrDeviceIndex: - value->v.integer = entry->index; - return (SNMP_ERR_NOERROR); - - case LEAF_hrDeviceType: - assert(entry->type != NULL); - value->v.oid = *(entry->type); - return (SNMP_ERR_NOERROR); - - case LEAF_hrDeviceDescr: - return (string_get(value, entry->descr, -1)); - - case LEAF_hrDeviceID: - value->v.oid = *(entry->id); - return (SNMP_ERR_NOERROR); - - case LEAF_hrDeviceStatus: - value->v.integer = entry->status; - return (SNMP_ERR_NOERROR); - - case LEAF_hrDeviceErrors: - value->v.uint32 = entry->errors; - return (SNMP_ERR_NOERROR); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c deleted file mode 100644 index 5460290..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_diskstorage_tbl.c +++ /dev/null @@ -1,646 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB for SNMPd. Implementation for the hrDiskStorageTable - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -enum hrDiskStrorageAccess { - DS_READ_WRITE = 1, - DS_READ_ONLY = 2 -}; - -enum hrDiskStrorageMedia { - DSM_OTHER = 1, - DSM_UNKNOWN = 2, - DSM_HARDDISK = 3, - DSM_FLOPPYDISK = 4, - DSM_OPTICALDISKROM= 5, - DSM_OPTICALDISKWORM= 6, - DSM_OPTICALDISKRW= 7, - DSM_RAMDISK = 8 -}; - -/* - * This structure is used to hold a SNMP table entry for HOST-RESOURCES-MIB's - * hrDiskStorageTable. Note that index is external being allocated and - * maintained by the hrDeviceTable code. - * - * NOTE: according to MIB removable means removable media, not the - * device itself (like a USB card reader) - */ -struct disk_entry { - int32_t index; - int32_t access; /* enum hrDiskStrorageAccess */ - int32_t media; /* enum hrDiskStrorageMedia*/ - int32_t removable; /* enum snmpTCTruthValue*/ - int32_t capacity; - TAILQ_ENTRY(disk_entry) link; - /* - * next items are not from the SNMP mib table, only to be used - * internally - */ -#define HR_DISKSTORAGE_FOUND 0x001 -#define HR_DISKSTORAGE_ATA 0x002 /* belongs to the ATA subsystem */ -#define HR_DISKSTORAGE_MD 0x004 /* it is a MD (memory disk) */ - uint32_t flags; - uint64_t r_tick; - u_char dev_name[32]; /* device name, i.e. "ad4" or "acd0" */ -}; -TAILQ_HEAD(disk_tbl, disk_entry); - -/* the head of the list with hrDiskStorageTable's entries */ -static struct disk_tbl disk_tbl = - TAILQ_HEAD_INITIALIZER(disk_tbl); - -/* last tick when hrFSTable was updated */ -static uint64_t disk_storage_tick; - -/* minimum number of ticks between refreshs */ -uint32_t disk_storage_tbl_refresh = HR_DISK_TBL_REFRESH * 100; - -/* fd for "/dev/mdctl"*/ -static int md_fd = -1; - -/* buffer for sysctl("kern.disks") */ -static char *disk_list; -static size_t disk_list_len; - -/* some constants */ -static const struct asn_oid OIDX_hrDeviceDiskStorage_c = - OIDX_hrDeviceDiskStorage; - -/** - * Load the MD driver if it isn't loaded already. - */ -static void -mdmaybeload(void) -{ - char name1[64], name2[64]; - - snprintf(name1, sizeof(name1), "g_%s", MD_NAME); - snprintf(name2, sizeof(name2), "geom_%s", MD_NAME); - if (modfind(name1) == -1) { - /* Not present in kernel, try loading it. */ - if (kldload(name2) == -1 || modfind(name1) == -1) { - if (errno != EEXIST) { - errx(EXIT_FAILURE, - "%s module not available!", name2); - } - } - } -} - -/** - * Create a new entry into the DiskStorageTable. - */ -static struct disk_entry * -disk_entry_create(const struct device_entry *devEntry) -{ - struct disk_entry *entry; - - assert(devEntry != NULL); - if (devEntry == NULL) - return NULL; - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "hrDiskStorageTable: %s: %m", __func__); - return (NULL); - } - - memset(entry, 0, sizeof(*entry)); - entry->index = devEntry->index; - INSERT_OBJECT_INT(entry, &disk_tbl); - - return (entry); -} - -/** - * Delete a disk table entry. - */ -static void -disk_entry_delete(struct disk_entry *entry) -{ - struct device_entry *devEntry; - - assert(entry != NULL); - TAILQ_REMOVE(&disk_tbl, entry, link); - - devEntry = device_find_by_index(entry->index); - - free(entry); - - /* - * Also delete the respective device entry - - * this is needed for disk devices that are not - * detected by libdevinfo - */ - if (devEntry != NULL && - (devEntry->flags & HR_DEVICE_IMMUTABLE) == HR_DEVICE_IMMUTABLE) - device_entry_delete(devEntry); -} - -/** - * Find a disk storage entry given its index. - */ -static struct disk_entry * -disk_find_by_index(int32_t idx) -{ - struct disk_entry *entry; - - TAILQ_FOREACH(entry, &disk_tbl, link) - if (entry->index == idx) - return (entry); - - return (NULL); -} - -/** - * Get the disk parameters - */ -static void -disk_query_disk(struct disk_entry *entry) -{ - char dev_path[128]; - int fd; - off_t mediasize; - - if (entry == NULL || entry->dev_name[0] == '\0') - return; - - snprintf(dev_path, sizeof(dev_path), - "%s%s", _PATH_DEV, entry->dev_name); - entry->capacity = 0; - - HRDBG("OPENING device %s", dev_path); - if ((fd = open(dev_path, O_RDONLY|O_NONBLOCK)) == -1) { - HRDBG("OPEN device %s failed: %s", dev_path, strerror(errno)); - return; - } - - if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) < 0) { - HRDBG("DIOCGMEDIASIZE for device %s failed: %s", - dev_path, strerror(errno)); - (void)close(fd); - return; - } - - mediasize = mediasize / 1024; - entry->capacity = (mediasize > INT_MAX ? INT_MAX : mediasize); - partition_tbl_handle_disk(entry->index, entry->dev_name); - - (void)close(fd); -} - -/** - * Find all ATA disks in the device table. - */ -static void -disk_OS_get_ATA_disks(void) -{ - struct device_map_entry *map; - struct device_entry *entry; - struct disk_entry *disk_entry; - const struct disk_entry *found; - - /* Things we know are ata disks */ - static const struct disk_entry lookup[] = { - { - .dev_name = "ad", - .media = DSM_HARDDISK, - .removable = SNMP_FALSE - }, - { - .dev_name = "ar", - .media = DSM_OTHER, - .removable = SNMP_FALSE - }, - { - .dev_name = "acd", - .media = DSM_OPTICALDISKROM, - .removable = SNMP_TRUE - }, - { - .dev_name = "afd", - .media = DSM_FLOPPYDISK, - .removable = SNMP_TRUE - }, - { - .dev_name = "ast", - .media = DSM_OTHER, - .removable = SNMP_TRUE - }, - - { .media = DSM_UNKNOWN } - }; - - /* Walk over the device table looking for ata disks */ - STAILQ_FOREACH(map, &device_map, link) { - for (found = lookup; found->media != DSM_UNKNOWN; found++) { - if (strncmp(map->name_key, found->dev_name, - strlen(found->dev_name)) != 0) - continue; - - /* - * Avoid false disk devices. For example adw(4) and - * adv(4) - they are not disks! - */ - if (strlen(map->name_key) > strlen(found->dev_name) && - !isdigit(map->name_key[strlen(found->dev_name)])) - continue; - - /* First get the entry from the hrDeviceTbl */ - entry = map->entry_p; - entry->type = &OIDX_hrDeviceDiskStorage_c; - - /* Then check hrDiskStorage table for this device */ - disk_entry = disk_find_by_index(entry->index); - if (disk_entry == NULL) { - disk_entry = disk_entry_create(entry); - if (disk_entry == NULL) - continue; - - disk_entry->access = DS_READ_WRITE; - strlcpy(disk_entry->dev_name, entry->name, - sizeof(disk_entry->dev_name)); - - disk_entry->media = found->media; - disk_entry->removable = found->removable; - } - - disk_entry->flags |= HR_DISKSTORAGE_FOUND; - disk_entry->flags |= HR_DISKSTORAGE_ATA; - - disk_query_disk(disk_entry); - disk_entry->r_tick = this_tick; - } - } -} - -/** - * Find MD disks in the device table. - */ -static void -disk_OS_get_MD_disks(void) -{ - struct device_map_entry *map; - struct device_entry *entry; - struct disk_entry *disk_entry; - struct md_ioctl mdio; - int unit; - - if (md_fd <= 0) - return; - - /* Look for md devices */ - STAILQ_FOREACH(map, &device_map, link) { - if (sscanf(map->name_key, "md%d", &unit) != 1) - continue; - - /* First get the entry from the hrDeviceTbl */ - entry = device_find_by_index(map->hrIndex); - entry->type = &OIDX_hrDeviceDiskStorage_c; - - /* Then check hrDiskStorage table for this device */ - disk_entry = disk_find_by_index(entry->index); - if (disk_entry == NULL) { - disk_entry = disk_entry_create(entry); - if (disk_entry == NULL) - continue; - - memset(&mdio, 0, sizeof(mdio)); - mdio.md_version = MDIOVERSION; - mdio.md_unit = unit; - - if (ioctl(md_fd, MDIOCQUERY, &mdio) < 0) { - syslog(LOG_ERR, - "hrDiskStorageTable: Couldnt ioctl"); - continue; - } - - if ((mdio.md_options & MD_READONLY) == MD_READONLY) - disk_entry->access = DS_READ_ONLY; - else - disk_entry->access = DS_READ_WRITE; - - strlcpy(disk_entry->dev_name, entry->name, - sizeof(disk_entry->dev_name)); - - disk_entry->media = DSM_RAMDISK; - disk_entry->removable = SNMP_FALSE; - } - - disk_entry->flags |= HR_DISKSTORAGE_FOUND; - disk_entry->flags |= HR_DISKSTORAGE_MD; - disk_entry->r_tick = this_tick; - } -} - -/** - * Find rest of disks - */ -static void -disk_OS_get_disks(void) -{ - size_t disk_cnt = 0; - struct device_entry *entry; - struct disk_entry *disk_entry; - - size_t need = 0; - - if (sysctlbyname("kern.disks", NULL, &need, NULL, 0) == -1) { - syslog(LOG_ERR, "%s: sysctl_1 kern.disks failed: %m", __func__); - return; - } - - if (need == 0) - return; - - if (disk_list_len != need + 1 || disk_list == NULL) { - disk_list_len = need + 1; - disk_list = reallocf(disk_list, disk_list_len); - } - - if (disk_list == NULL) { - syslog(LOG_ERR, "%s: reallocf failed", __func__); - disk_list_len = 0; - return; - } - - memset(disk_list, 0, disk_list_len); - - if (sysctlbyname("kern.disks", disk_list, &need, NULL, 0) == -1 || - disk_list[0] == 0) { - syslog(LOG_ERR, "%s: sysctl_2 kern.disks failed: %m", __func__); - return; - } - - for (disk_cnt = 0; disk_cnt < need; disk_cnt++) { - char *disk = NULL; - char disk_device[128] = ""; - - disk = strsep(&disk_list, " "); - if (disk == NULL) - break; - - snprintf(disk_device, sizeof(disk_device), - "%s%s", _PATH_DEV, disk); - - /* First check if the disk is in the hrDeviceTable. */ - if ((entry = device_find_by_name(disk)) == NULL) { - /* - * not found there - insert it as immutable - */ - syslog(LOG_WARNING, "%s: device '%s' not in " - "device list", __func__, disk); - - if ((entry = device_entry_create(disk, "", "")) == NULL) - continue; - - entry->flags |= HR_DEVICE_IMMUTABLE; - } - - entry->type = &OIDX_hrDeviceDiskStorage_c; - - /* Then check hrDiskStorage table for this device */ - disk_entry = disk_find_by_index(entry->index); - if (disk_entry == NULL) { - disk_entry = disk_entry_create(entry); - if (disk_entry == NULL) - continue; - } - - disk_entry->flags |= HR_DISKSTORAGE_FOUND; - - if ((disk_entry->flags & HR_DISKSTORAGE_ATA) || - (disk_entry->flags & HR_DISKSTORAGE_MD)) { - /* - * ATA/MD detection is running before this one, - * so don't waste the time here - */ - continue; - } - - disk_entry->access = DS_READ_WRITE; - disk_entry->media = DSM_UNKNOWN; - disk_entry->removable = SNMP_FALSE; - - if (strncmp(disk_entry->dev_name, "da", 2) == 0) { - disk_entry->media = DSM_HARDDISK; - disk_entry->removable = SNMP_FALSE; - } else if (strncmp(disk_entry->dev_name, "cd", 2) == 0) { - disk_entry->media = DSM_OPTICALDISKROM; - disk_entry->removable = SNMP_TRUE; - } else { - disk_entry->media = DSM_UNKNOWN; - disk_entry->removable = SNMP_FALSE; - } - - strlcpy((char *)disk_entry->dev_name, disk, - sizeof(disk_entry->dev_name)); - - disk_query_disk(disk_entry); - disk_entry->r_tick = this_tick; - } -} - -/** - * Refresh routine for hrDiskStorageTable - * Usable for polling the system for any changes. - */ -void -refresh_disk_storage_tbl(int force) -{ - struct disk_entry *entry, *entry_tmp; - - if (disk_storage_tick != 0 && !force && - this_tick - disk_storage_tick < disk_storage_tbl_refresh) { - HRDBG("no refresh needed"); - return; - } - - partition_tbl_pre_refresh(); - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &disk_tbl, link) - entry->flags &= ~HR_DISKSTORAGE_FOUND; - - disk_OS_get_ATA_disks(); /* this must be called first ! */ - disk_OS_get_MD_disks(); - disk_OS_get_disks(); - - /* - * Purge items that disappeared - */ - TAILQ_FOREACH_SAFE(entry, &disk_tbl, link, entry_tmp) - if (!(entry->flags & HR_DISKSTORAGE_FOUND)) - /* XXX remove IMMUTABLE entries that have disappeared */ - disk_entry_delete(entry); - - disk_storage_tick = this_tick; - - partition_tbl_post_refresh(); - - HRDBG("refresh DONE"); -} - -/* - * Init the things for both of hrDiskStorageTable - */ -int -init_disk_storage_tbl(void) -{ - char mddev[32] = ""; - - /* Try to load md.ko if not loaded already */ - mdmaybeload(); - - md_fd = -1; - snprintf(mddev, sizeof(mddev) - 1, "%s%s", _PATH_DEV, MDCTL_NAME); - if ((md_fd = open(mddev, O_RDWR)) == -1) { - syslog(LOG_ERR, "open %s failed - will not include md(4) " - "info: %m", mddev); - } - - refresh_disk_storage_tbl(1); - - return (0); -} - -/* - * Finalization routine for hrDiskStorageTable - * It destroys the lists and frees any allocated heap memory - */ -void -fini_disk_storage_tbl(void) -{ - struct disk_entry *n1; - - while ((n1 = TAILQ_FIRST(&disk_tbl)) != NULL) { - TAILQ_REMOVE(&disk_tbl, n1, link); - free(n1); - } - - free(disk_list); - - if (md_fd > 0) { - if (close(md_fd) == -1) - syslog(LOG_ERR,"close (/dev/mdctl) failed: %m"); - md_fd = -1; - } -} - -/* - * This is the implementation for a generated (by our SNMP "compiler" tool) - * function prototype, see hostres_tree.h - * It handles the SNMP operations for hrDiskStorageTable - */ -int -op_hrDiskStorageTable(struct snmp_context *ctx __unused, - struct snmp_value *value, u_int sub, u_int iidx __unused, - enum snmp_op curr_op) -{ - struct disk_entry *entry; - - refresh_disk_storage_tbl(0); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&disk_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&disk_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&disk_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrDiskStorageAccess: - value->v.integer = entry->access; - return (SNMP_ERR_NOERROR); - - case LEAF_hrDiskStorageMedia: - value->v.integer = entry->media; - return (SNMP_ERR_NOERROR); - - case LEAF_hrDiskStorageRemoveble: - value->v.integer = entry->removable; - return (SNMP_ERR_NOERROR); - - case LEAF_hrDiskStorageCapacity: - value->v.integer = entry->capacity; - return (SNMP_ERR_NOERROR); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c deleted file mode 100644 index 91505d5..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_fs_tbl.c +++ /dev/null @@ -1,473 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB for SNMPd. Implementation for hrFSTable - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -/* - * File system access enum - */ -enum hrFSAccess { - FS_READ_WRITE = 1, - FS_READ_ONLY = 2 -}; - -/* maximum length (according to MIB) for fs_entry::mountPoint */ -#define FS_MP_MLEN (128 + 1) - -/* maximum length (according to MIB) for fs_entry::remoteMountPoint */ -#define FS_RMP_MLEN (128 + 1) - -/* - * This structure is used to hold a SNMP table entry - * for HOST-RESOURCES-MIB's hrFSTable - */ -struct fs_entry { - int32_t index; - u_char *mountPoint; - u_char *remoteMountPoint; - const struct asn_oid *type; - int32_t access; /* enum hrFSAccess, see above */ - int32_t bootable; /* TruthValue */ - int32_t storageIndex; /* hrStorageTblEntry::index */ - u_char lastFullBackupDate[11]; - u_char lastPartialBackupDate[11]; -#define HR_FS_FOUND 0x001 - uint32_t flags; /* not in mib table, for internal use */ - TAILQ_ENTRY(fs_entry) link; -}; -TAILQ_HEAD(fs_tbl, fs_entry); - -/* - * Next structure is used to keep o list of mappings from a specific name - * (a_name) to an entry in the hrFSTblEntry. We are trying to keep the same - * index for a specific name at least for the duration of one SNMP agent run. - */ -struct fs_map_entry { - int32_t hrIndex; /* used for fs_entry::index */ - u_char *a_name; /* map key same as fs_entry::mountPoint */ - - /* may be NULL if the respective hrFSTblEntry is (temporally) gone */ - struct fs_entry *entry; - STAILQ_ENTRY(fs_map_entry) link; -}; -STAILQ_HEAD(fs_map, fs_map_entry); - -/* head of the list with hrFSTable's entries */ -static struct fs_tbl fs_tbl = TAILQ_HEAD_INITIALIZER(fs_tbl); - -/* for consistent table indexing */ -static struct fs_map fs_map = STAILQ_HEAD_INITIALIZER(fs_map); - -/* next index available for hrFSTable */ -static uint32_t next_fs_index = 1; - -/* last tick when hrFSTable was updated */ -static uint64_t fs_tick; - -/* maximum number of ticks between refreshs */ -uint32_t fs_tbl_refresh = HR_FS_TBL_REFRESH * 100; - -/* some constants */ -static const struct asn_oid OIDX_hrFSBerkeleyFFS_c = OIDX_hrFSBerkeleyFFS; -static const struct asn_oid OIDX_hrFSiso9660_c = OIDX_hrFSiso9660; -static const struct asn_oid OIDX_hrFSNFS_c = OIDX_hrFSNFS; -static const struct asn_oid OIDX_hrFSLinuxExt2_c = OIDX_hrFSLinuxExt2; -static const struct asn_oid OIDX_hrFSOther_c = OIDX_hrFSOther; -static const struct asn_oid OIDX_hrFSFAT32_c = OIDX_hrFSFAT32; -static const struct asn_oid OIDX_hrFSNTFS_c = OIDX_hrFSNTFS; -static const struct asn_oid OIDX_hrFSNetware_c = OIDX_hrFSNetware; -static const struct asn_oid OIDX_hrFSHPFS_c = OIDX_hrFSHPFS; -static const struct asn_oid OIDX_hrFSUnknown_c = OIDX_hrFSUnknown; - -/* file system type map */ -static const struct { - const char *str; /* the type string */ - const struct asn_oid *oid; /* the OID to return */ -} fs_type_map[] = { - { "ufs", &OIDX_hrFSBerkeleyFFS_c }, - { "zfs", &OIDX_hrFSOther_c }, - { "cd9660", &OIDX_hrFSiso9660_c }, - { "nfs", &OIDX_hrFSNFS_c }, - { "ext2fs", &OIDX_hrFSLinuxExt2_c }, - { "procfs", &OIDX_hrFSOther_c }, - { "devfs", &OIDX_hrFSOther_c }, - { "msdosfs", &OIDX_hrFSFAT32_c }, - { "ntfs", &OIDX_hrFSNTFS_c }, - { "nwfs", &OIDX_hrFSNetware_c }, - { "hpfs", &OIDX_hrFSHPFS_c }, - { "smbfs", &OIDX_hrFSOther_c }, -}; -#define N_FS_TYPE_MAP (sizeof(fs_type_map) / sizeof(fs_type_map[0])) - -/** - * Create an entry into the FS table and an entry in the map (if needed). - */ -static struct fs_entry * -fs_entry_create(const char *name) -{ - struct fs_entry *entry; - struct fs_map_entry *map; - - assert(name != NULL); - assert(strlen(name) > 0); - - STAILQ_FOREACH(map, &fs_map, link) - if (strcmp(map->a_name, name) == 0) - break; - - if (map == NULL) { - size_t mount_point_len; - - /* new object - get a new index */ - if (next_fs_index > INT_MAX) { - /* Unrecoverable error - die clean and quicly*/ - syslog(LOG_ERR, "%s: hrFSTable index wrap", __func__); - errx(EX_SOFTWARE, "hrFSTable index wrap"); - } - - if ((map = malloc(sizeof(*map))) == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); - return (NULL); - } - - mount_point_len = strlen(name) + 1; - if (mount_point_len > FS_MP_MLEN) - mount_point_len = FS_MP_MLEN; - - if ((map->a_name = malloc(mount_point_len)) == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); - free(map); - return (NULL); - } - - strlcpy(map->a_name, name, mount_point_len); - - map->hrIndex = next_fs_index++; - map->entry = NULL; - STAILQ_INSERT_TAIL(&fs_map, map, link); - - HRDBG("%s added into hrFSMap at index=%d", name, map->hrIndex); - } else { - HRDBG("%s exists in hrFSMap index=%d", name, map->hrIndex); - } - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "%s: %m", __func__); - return (NULL); - } - - if ((entry->mountPoint = strdup(name)) == NULL) { - syslog(LOG_ERR, "%s: %m", __func__); - free(entry); - return (NULL); - } - - entry->index = map->hrIndex; - map->entry = entry; - - INSERT_OBJECT_INT(entry, &fs_tbl); - return (entry); -} - -/** - * Delete an entry in the FS table. - */ -static void -fs_entry_delete(struct fs_entry* entry) -{ - struct fs_map_entry *map; - - assert(entry != NULL); - - TAILQ_REMOVE(&fs_tbl, entry, link); - STAILQ_FOREACH(map, &fs_map, link) - if (map->entry == entry) { - map->entry = NULL; - break; - } - free(entry->mountPoint); - free(entry->remoteMountPoint); - free(entry); -} - -/** - * Find a table entry by its name - */ -static struct fs_entry * -fs_find_by_name(const char *name) -{ - struct fs_entry *entry; - - TAILQ_FOREACH(entry, &fs_tbl, link) - if (strcmp(entry->mountPoint, name) == 0) - return (entry); - - return (NULL); -} - -/** - * Get rid of all data - */ -void -fini_fs_tbl(void) -{ - struct fs_map_entry *n1; - - while ((n1 = STAILQ_FIRST(&fs_map)) != NULL) { - STAILQ_REMOVE_HEAD(&fs_map, link); - if (n1->entry != NULL) { - TAILQ_REMOVE(&fs_tbl, n1->entry, link); - free(n1->entry->mountPoint); - free(n1->entry->remoteMountPoint); - free(n1->entry); - } - free(n1->a_name); - free(n1); - } - assert(TAILQ_EMPTY(&fs_tbl)); -} - -/** - * Called before the refreshing is started from the storage table. - */ -void -fs_tbl_pre_refresh(void) -{ - struct fs_entry *entry; - - /* mark each entry as missisng */ - TAILQ_FOREACH(entry, &fs_tbl, link) - entry->flags &= ~HR_FS_FOUND; -} - -/** - * Called after refreshing from the storage table. - */ -void -fs_tbl_post_refresh(void) -{ - struct fs_entry *entry, *entry_tmp; - - /* - * Purge items that disappeared - */ - TAILQ_FOREACH_SAFE(entry, &fs_tbl, link, entry_tmp) - if (!(entry->flags & HR_FS_FOUND)) - fs_entry_delete(entry); - - fs_tick = this_tick; -} - -/* - * Refresh the FS table. This is done by forcing a refresh of the storage table. - */ -void -refresh_fs_tbl(void) -{ - - if (fs_tick == 0 || this_tick - fs_tick >= fs_tbl_refresh) { - refresh_storage_tbl(1); - HRDBG("refresh DONE"); - } -} - -/** - * Get the type OID for a given file system - */ -const struct asn_oid * -fs_get_type(const struct statfs *fs_p) -{ - u_int t; - - assert(fs_p != NULL); - - for (t = 0; t < N_FS_TYPE_MAP; t++) - if (strcmp(fs_type_map[t].str, fs_p->f_fstypename) == 0) - return (fs_type_map[t].oid); - - return (&OIDX_hrFSUnknown_c); -} - -/* - * Given information returned from statfs(2) either create a new entry into - * the fs_tbl or refresh the entry if it is already there. - */ -void -fs_tbl_process_statfs_entry(const struct statfs *fs_p, int32_t storage_idx) -{ - struct fs_entry *entry; - - assert(fs_p != 0); - - HRDBG("for hrStorageEntry::index %d", storage_idx); - - if (fs_p == NULL) - return; - - if ((entry = fs_find_by_name(fs_p->f_mntonname)) != NULL || - (entry = fs_entry_create(fs_p->f_mntonname)) != NULL) { - entry->flags |= HR_FS_FOUND; - - if (!(fs_p->f_flags & MNT_LOCAL)) { - /* this is a remote mount */ - entry->remoteMountPoint = strdup(fs_p->f_mntfromname); - /* if strdup failed, let it be NULL */ - - } else { - entry->remoteMountPoint = strdup(""); - /* if strdup failed, let it be NULL */ - } - - entry->type = fs_get_type(fs_p); - - if ((fs_p->f_flags & MNT_RDONLY) == MNT_RDONLY) - entry->access = FS_READ_ONLY; - else - entry->access = FS_READ_WRITE; - - /* FIXME - bootable fs ?! */ - entry->bootable = TRUTH_MK((fs_p->f_flags & MNT_ROOTFS) - == MNT_ROOTFS); - - entry->storageIndex = storage_idx; - - /* Info not available */ - memset(entry->lastFullBackupDate, 0, - sizeof(entry->lastFullBackupDate)); - - /* Info not available */ - memset(entry->lastPartialBackupDate, 0, - sizeof(entry->lastPartialBackupDate)); - - handle_partition_fs_index(fs_p->f_mntfromname, entry->index); - } -} - -/* - * This is the implementation for a generated (by our SNMP "compiler" tool) - * function prototype, see hostres_tree.h - * It handles the SNMP operations for hrFSTable - */ -int -op_hrFSTable(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - struct fs_entry *entry; - - refresh_fs_tbl(); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&fs_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&fs_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&fs_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrFSIndex: - value->v.integer = entry->index; - return (SNMP_ERR_NOERROR); - - case LEAF_hrFSMountPoint: - return (string_get(value, entry->mountPoint, -1)); - - case LEAF_hrFSRemoteMountPoint: - if (entry->remoteMountPoint == NULL) - return (string_get(value, "", -1)); - else - return (string_get(value, entry->remoteMountPoint, -1)); - break; - - case LEAF_hrFSType: - assert(entry->type != NULL); - value->v.oid = *(entry->type); - return (SNMP_ERR_NOERROR); - - case LEAF_hrFSAccess: - value->v.integer = entry->access; - return (SNMP_ERR_NOERROR); - - case LEAF_hrFSBootable: - value->v.integer = entry->bootable; - return (SNMP_ERR_NOERROR); - - case LEAF_hrFSStorageIndex: - value->v.integer = entry->storageIndex; - return (SNMP_ERR_NOERROR); - - case LEAF_hrFSLastFullBackupDate: - return (string_get(value, entry->lastFullBackupDate, 8)); - - case LEAF_hrFSLastPartialBackupDate: - return (string_get(value, entry->lastPartialBackupDate, 8)); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c deleted file mode 100644 index 4329a1c..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_network_tbl.c +++ /dev/null @@ -1,302 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB implementation for SNMPd: instrumentation for - * hrNetworkTable - */ - -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -#include - -/* - * This structure is used to hold a SNMP table entry - * for HOST-RESOURCES-MIB's hrNetworkTable - */ -struct network_entry { - int32_t index; - int32_t ifIndex; - TAILQ_ENTRY(network_entry) link; -#define HR_NETWORK_FOUND 0x001 - uint32_t flags; - -}; -TAILQ_HEAD(network_tbl, network_entry); - -/* the head of the list with hrNetworkTable's entries */ -static struct network_tbl network_tbl = TAILQ_HEAD_INITIALIZER(network_tbl); - -/* last (agent) tick when hrNetworkTable was updated */ -static uint64_t network_tick; - -/* maximum number of ticks between updates of network table */ -uint32_t network_tbl_refresh = HR_NETWORK_TBL_REFRESH * 100; - -/* Constants */ -static const struct asn_oid OIDX_hrDeviceNetwork_c = OIDX_hrDeviceNetwork; - -/** - * Create a new entry into the network table - */ -static struct network_entry * -network_entry_create(const struct device_entry *devEntry) -{ - struct network_entry *entry; - - assert(devEntry != NULL); - if (devEntry == NULL) - return (NULL); - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "%s: %m", __func__); - return (NULL); - } - - memset(entry, 0, sizeof(*entry)); - entry->index = devEntry->index; - INSERT_OBJECT_INT(entry, &network_tbl); - - return (entry); -} - -/** - * Delete an entry in the network table - */ -static void -network_entry_delete(struct network_entry* entry) -{ - - TAILQ_REMOVE(&network_tbl, entry, link); - free(entry); -} - -/** - * Fetch the interfaces from the mibII module, get their real name from the - * kernel and try to find it in the device table. - */ -static void -network_get_interfaces(void) -{ - struct device_entry *dev; - struct network_entry *net; - struct mibif *ifp; - int name[6]; - size_t len; - char *dname; - - name[0] = CTL_NET; - name[1] = PF_LINK; - name[2] = NETLINK_GENERIC; - name[3] = IFMIB_IFDATA; - name[5] = IFDATA_DRIVERNAME; - - for (ifp = mib_first_if(); ifp != NULL; ifp = mib_next_if(ifp)) { - HRDBG("%s %s", ifp->name, ifp->descr); - - name[4] = ifp->sysindex; - - /* get the original name */ - len = 0; - if (sysctl(name, 6, NULL, &len, 0, 0) < 0) { - syslog(LOG_ERR, "sysctl(net.link.ifdata.%d." - "drivername): %m", ifp->sysindex); - continue; - } - if ((dname = malloc(len)) == NULL) { - syslog(LOG_ERR, "malloc: %m"); - continue; - } - if (sysctl(name, 6, dname, &len, 0, 0) < 0) { - syslog(LOG_ERR, "sysctl(net.link.ifdata.%d." - "drivername): %m", ifp->sysindex); - free(dname); - continue; - } - - HRDBG("got device %s (%s)", ifp->name, dname); - - if ((dev = device_find_by_name(dname)) == NULL) { - HRDBG("%s not in hrDeviceTable", dname); - free(dname); - continue; - } - HRDBG("%s found in hrDeviceTable", dname); - - dev->type = &OIDX_hrDeviceNetwork_c; - dev->flags |= HR_DEVICE_IMMUTABLE; - - free(dname); - - /* Then check hrNetworkTable for this device */ - TAILQ_FOREACH(net, &network_tbl, link) - if (net->index == dev->index) - break; - - if (net == NULL && (net = network_entry_create(dev)) == NULL) - continue; - - net->flags |= HR_NETWORK_FOUND; - net->ifIndex = ifp->index; - } - - network_tick = this_tick; -} - -/** - * Finalization routine for hrNetworkTable. - * It destroys the lists and frees any allocated heap memory. - */ -void -fini_network_tbl(void) -{ - struct network_entry *n1; - - while ((n1 = TAILQ_FIRST(&network_tbl)) != NULL) { - TAILQ_REMOVE(&network_tbl, n1, link); - free(n1); - } -} - -/** - * Get the interface list from mibII only at this point to be sure that - * it is there already. - */ -void -start_network_tbl(void) -{ - - mib_refresh_iflist(); - network_get_interfaces(); -} - -/** - * Refresh the table. - */ -static void -refresh_network_tbl(void) -{ - struct network_entry *entry, *entry_tmp; - - if (this_tick - network_tick < network_tbl_refresh) { - HRDBG("no refresh needed"); - return; - } - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &network_tbl, link) - entry->flags &= ~HR_NETWORK_FOUND; - - network_get_interfaces(); - - /* - * Purge items that disappeared - */ - TAILQ_FOREACH_SAFE(entry, &network_tbl, link, entry_tmp) { - if (!(entry->flags & HR_NETWORK_FOUND)) - network_entry_delete(entry); - } - - HRDBG("refresh DONE"); -} - -/* - * This is the implementation for a generated (by our SNMP tool) - * function prototype, see hostres_tree.h - * It handles the SNMP operations for hrNetworkTable - */ -int -op_hrNetworkTable(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - struct network_entry *entry; - - refresh_network_tbl(); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&network_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&network_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&network_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrNetworkIfIndex: - value->v.integer = entry->ifIndex; - return (SNMP_ERR_NOERROR); - - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c deleted file mode 100644 index 65c0012..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_partition_tbl.c +++ /dev/null @@ -1,630 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB: hrPartitionTable implementation for SNMPd. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -#ifdef PC98 -#define HR_FREEBSD_PART_TYPE 0xc494 -#else -#define HR_FREEBSD_PART_TYPE 165 -#endif - -/* Maximum length for label and id including \0 */ -#define PART_STR_MLEN (128 + 1) - -/* - * One row in the hrPartitionTable - */ -struct partition_entry { - asn_subid_t index[2]; - u_char *label; /* max allocated len will be PART_STR_MLEN */ - u_char *id; /* max allocated len will be PART_STR_MLEN */ - int32_t size; - int32_t fs_Index; - TAILQ_ENTRY(partition_entry) link; -#define HR_PARTITION_FOUND 0x001 - uint32_t flags; -}; -TAILQ_HEAD(partition_tbl, partition_entry); - -/* - * This table is used to get a consistent indexing. It saves the name -> index - * mapping while we rebuild the partition table. - */ -struct partition_map_entry { - int32_t index; /* partition_entry::index */ - u_char *id; /* max allocated len will be PART_STR_MLEN */ - - /* - * next may be NULL if the respective partition_entry - * is (temporally) gone. - */ - struct partition_entry *entry; - STAILQ_ENTRY(partition_map_entry) link; -}; -STAILQ_HEAD(partition_map, partition_map_entry); - -/* Mapping table for consistent indexing */ -static struct partition_map partition_map = - STAILQ_HEAD_INITIALIZER(partition_map); - -/* THE partition table. */ -static struct partition_tbl partition_tbl = - TAILQ_HEAD_INITIALIZER(partition_tbl); - -/* next int available for indexing the hrPartitionTable */ -static uint32_t next_partition_index = 1; - -/* - * Partition_entry_cmp is used for INSERT_OBJECT_FUNC_LINK - * macro. - */ -static int -partition_entry_cmp(const struct partition_entry *a, - const struct partition_entry *b) -{ - assert(a != NULL); - assert(b != NULL); - - if (a->index[0] < b->index[0]) - return (-1); - - if (a->index[0] > b->index[0]) - return (+1); - - if (a->index[1] < b->index[1]) - return (-1); - - if (a->index[1] > b->index[1]) - return (+1); - - return (0); -} - -/* - * Partition_idx_cmp is used for NEXT_OBJECT_FUNC and FIND_OBJECT_FUNC - * macros - */ -static int -partition_idx_cmp(const struct asn_oid *oid, u_int sub, - const struct partition_entry *entry) -{ - u_int i; - - for (i = 0; i < 2 && i < oid->len - sub; i++) { - if (oid->subs[sub + i] < entry->index[i]) - return (-1); - if (oid->subs[sub + i] > entry->index[i]) - return (+1); - } - if (oid->len - sub < 2) - return (-1); - if (oid->len - sub > 2) - return (+1); - - return (0); -} - -/** - * Create a new partition table entry - */ -static struct partition_entry * -partition_entry_create(int32_t ds_index, const char *chunk_name) -{ - struct partition_entry *entry; - struct partition_map_entry *map; - size_t id_len; - - /* sanity checks */ - assert(chunk_name != NULL); - if (chunk_name == NULL || chunk_name[0] == '\0') - return (NULL); - - /* check whether we already have seen this partition */ - STAILQ_FOREACH(map, &partition_map, link) - if (strcmp(map->id, chunk_name) == 0) - break; - - if (map == NULL) { - /* new object - get a new index and create a map */ - - if (next_partition_index > INT_MAX) { - /* Unrecoverable error - die clean and quicly*/ - syslog(LOG_ERR, "%s: hrPartitionTable index wrap", - __func__); - errx(EX_SOFTWARE, "hrPartitionTable index wrap"); - } - - if ((map = malloc(sizeof(*map))) == NULL) { - syslog(LOG_ERR, "hrPartitionTable: %s: %m", __func__); - return (NULL); - } - - id_len = strlen(chunk_name) + 1; - if (id_len > PART_STR_MLEN) - id_len = PART_STR_MLEN; - - if ((map->id = malloc(id_len)) == NULL) { - free(map); - return (NULL); - } - - map->index = next_partition_index++; - - strlcpy(map->id, chunk_name, id_len); - - map->entry = NULL; - - STAILQ_INSERT_TAIL(&partition_map, map, link); - - HRDBG("%s added into hrPartitionMap at index=%d", - chunk_name, map->index); - - } else { - HRDBG("%s exists in hrPartitionMap index=%d", - chunk_name, map->index); - } - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "hrPartitionTable: %s: %m", __func__); - return (NULL); - } - memset(entry, 0, sizeof(*entry)); - - /* create the index */ - entry->index[0] = ds_index; - entry->index[1] = map->index; - - map->entry = entry; - - if ((entry->id = strdup(map->id)) == NULL) { - free(entry); - return (NULL); - } - - /* - * reuse id_len from here till the end of this function - * for partition_entry::label - */ - id_len = strlen(_PATH_DEV) + strlen(chunk_name) + 1; - - if (id_len > PART_STR_MLEN) - id_len = PART_STR_MLEN; - - if ((entry->label = malloc(id_len )) == NULL) { - free(entry->id); - free(entry); - return (NULL); - } - - snprintf(entry->label, id_len, "%s%s", _PATH_DEV, chunk_name); - - INSERT_OBJECT_FUNC_LINK(entry, &partition_tbl, link, - partition_entry_cmp); - - return (entry); -} - -/** - * Delete a partition table entry but keep the map entry intact. - */ -static void -partition_entry_delete(struct partition_entry *entry) -{ - struct partition_map_entry *map; - - assert(entry != NULL); - - TAILQ_REMOVE(&partition_tbl, entry, link); - STAILQ_FOREACH(map, &partition_map, link) - if (map->entry == entry) { - map->entry = NULL; - break; - } - free(entry->id); - free(entry->label); - free(entry); -} - -/** - * Find a partition table entry by name. If none is found, return NULL. - */ -static struct partition_entry * -partition_entry_find_by_name(const char *name) -{ - struct partition_entry *entry = NULL; - - TAILQ_FOREACH(entry, &partition_tbl, link) - if (strcmp(entry->id, name) == 0) - return (entry); - - return (NULL); -} - -/** - * Find a partition table entry by label. If none is found, return NULL. - */ -static struct partition_entry * -partition_entry_find_by_label(const char *name) -{ - struct partition_entry *entry = NULL; - - TAILQ_FOREACH(entry, &partition_tbl, link) - if (strcmp(entry->label, name) == 0) - return (entry); - - return (NULL); -} - -/** - * Process a chunk from libgeom(4). A chunk is either a slice or a partition. - * If necessary create a new partition table entry for it. In any case - * set the size field of the entry and set the FOUND flag. - */ -static void -handle_chunk(int32_t ds_index, const char *chunk_name, off_t chunk_size) -{ - struct partition_entry *entry; - daddr_t k_size; - - assert(chunk_name != NULL); - assert(chunk_name[0] != '\0'); - if (chunk_name == NULL || chunk_name == '\0') - return; - - HRDBG("ANALYZE chunk %s", chunk_name); - - if ((entry = partition_entry_find_by_name(chunk_name)) == NULL) - if ((entry = partition_entry_create(ds_index, - chunk_name)) == NULL) - return; - - entry->flags |= HR_PARTITION_FOUND; - - /* actual size may overflow the SNMP type */ - k_size = chunk_size / 1024; - entry->size = (k_size > (off_t)INT_MAX ? INT_MAX : k_size); -} - -/** - * Start refreshing the partition table. A call to this function will - * be followed by a call to handleDiskStorage() for every disk, followed - * by a single call to the post_refresh function. - */ -void -partition_tbl_pre_refresh(void) -{ - struct partition_entry *entry; - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &partition_tbl, link) - entry->flags &= ~HR_PARTITION_FOUND; -} - -/** - * Try to find a geom(4) class by its name. Returns a pointer to that - * class if found NULL otherways. - */ -static struct gclass * -find_class(struct gmesh *mesh, const char *name) -{ - struct gclass *classp; - - LIST_FOREACH(classp, &mesh->lg_class, lg_class) - if (strcmp(classp->lg_name, name) == 0) - return (classp); - return (NULL); -} - -/** - * Process all MBR-type partitions from the given disk. - */ -static void -get_mbr(struct gclass *classp, int32_t ds_index, const char *disk_dev_name) -{ - struct ggeom *gp; - struct gprovider *pp; - struct gconfig *conf; - long part_type; - - LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { - /* We are only interested in partitions from this disk */ - if (strcmp(gp->lg_name, disk_dev_name) != 0) - continue; - - /* - * Find all the non-BSD providers (these are handled in get_bsd) - */ - LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { - LIST_FOREACH(conf, &pp->lg_config, lg_config) { - if (conf->lg_name == NULL || - conf->lg_val == NULL || - strcmp(conf->lg_name, "type") != 0) - continue; - - /* - * We are not interested in BSD partitions - * (ie ad0s1 is not interesting at this point). - * We'll take care of them in detail (slice - * by slice) in get_bsd. - */ - part_type = strtol(conf->lg_val, NULL, 10); - if (part_type == HR_FREEBSD_PART_TYPE) - break; - HRDBG("-> MBR PROVIDER Name: %s", pp->lg_name); - HRDBG("Mediasize: %jd", - (intmax_t)pp->lg_mediasize / 1024); - HRDBG("Sectorsize: %u", pp->lg_sectorsize); - HRDBG("Mode: %s", pp->lg_mode); - HRDBG("CONFIG: %s: %s", - conf->lg_name, conf->lg_val); - - handle_chunk(ds_index, pp->lg_name, - pp->lg_mediasize); - } - } - } -} - -/** - * Process all BSD-type partitions from the given disk. - */ -static void -get_bsd_sun(struct gclass *classp, int32_t ds_index, const char *disk_dev_name) -{ - struct ggeom *gp; - struct gprovider *pp; - - LIST_FOREACH(gp, &classp->lg_geom, lg_geom) { - /* - * We are only interested in those geoms starting with - * the disk_dev_name passed as parameter to this function. - */ - if (strncmp(gp->lg_name, disk_dev_name, - strlen(disk_dev_name)) != 0) - continue; - - LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { - if (pp->lg_name == NULL) - continue; - handle_chunk(ds_index, pp->lg_name, pp->lg_mediasize); - } - } -} - -/** - * Called from the DiskStorage table for every row. Open the GEOM(4) framework - * and process all the partitions in it. - * ds_index is the index into the DiskStorage table. - * This is done in two steps: for non BSD partitions the geom class "MBR" is - * used, for our BSD slices the "BSD" geom class. - */ -void -partition_tbl_handle_disk(int32_t ds_index, const char *disk_dev_name) -{ - struct gmesh mesh; /* GEOM userland tree */ - struct gclass *classp; - int error; - - assert(disk_dev_name != NULL); - assert(ds_index > 0); - - HRDBG("===> getting partitions for %s <===", disk_dev_name); - - /* try to construct the GEOM tree */ - if ((error = geom_gettree(&mesh)) != 0) { - syslog(LOG_WARNING, "cannot get GEOM tree: %m"); - return; - } - - /* - * First try the GEOM "MBR" class. - * This is needed for non-BSD slices (aka partitions) - * on PC architectures. - */ - if ((classp = find_class(&mesh, "MBR")) != NULL) { - get_mbr(classp, ds_index, disk_dev_name); - } else { - HRDBG("cannot find \"MBR\" geom class"); - } - - /* - * Get the "BSD" GEOM class. - * Here we'll find all the info needed about the BSD slices. - */ - if ((classp = find_class(&mesh, "BSD")) != NULL) { - get_bsd_sun(classp, ds_index, disk_dev_name); - } else { - /* no problem on sparc64 */ - HRDBG("cannot find \"BSD\" geom class"); - } - - /* - * Get the "SUN" GEOM class. - * Here we'll find all the info needed about the BSD slices. - */ - if ((classp = find_class(&mesh, "SUN")) != NULL) { - get_bsd_sun(classp, ds_index, disk_dev_name); - } else { - /* no problem on i386 */ - HRDBG("cannot find \"SUN\" geom class"); - } - - geom_deletetree(&mesh); -} - -/** - * Finish refreshing the table. - */ -void -partition_tbl_post_refresh(void) -{ - struct partition_entry *e, *etmp; - - /* - * Purge items that disappeared - */ - TAILQ_FOREACH_SAFE(e, &partition_tbl, link, etmp) - if (!(e->flags & HR_PARTITION_FOUND)) - partition_entry_delete(e); -} - -/* - * Finalization routine for hrPartitionTable - * It destroys the lists and frees any allocated heap memory - */ -void -fini_partition_tbl(void) -{ - struct partition_map_entry *m; - - while ((m = STAILQ_FIRST(&partition_map)) != NULL) { - STAILQ_REMOVE_HEAD(&partition_map, link); - if(m->entry != NULL) { - TAILQ_REMOVE(&partition_tbl, m->entry, link); - free(m->entry->id); - free(m->entry->label); - free(m->entry); - } - free(m->id); - free(m); - } - assert(TAILQ_EMPTY(&partition_tbl)); -} - -/** - * Called from the file system code to insert the file system table index - * into the partition table entry. Note, that an partition table entry exists - * only for local file systems. - */ -void -handle_partition_fs_index(const char *name, int32_t fs_idx) -{ - struct partition_entry *entry; - - if ((entry = partition_entry_find_by_label(name)) == NULL) { - HRDBG("%s IS MISSING from hrPartitionTable", name); - return; - } - HRDBG("%s [FS index = %d] IS in hrPartitionTable", name, fs_idx); - entry->fs_Index = fs_idx; -} - -/* - * This is the implementation for a generated (by our SNMP tool) - * function prototype, see hostres_tree.h - * It handles the SNMP operations for hrPartitionTable - */ -int -op_hrPartitionTable(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op op) -{ - struct partition_entry *entry; - - /* - * Refresh the disk storage table (which refreshes the partition - * table) if necessary. - */ - refresh_disk_storage_tbl(0); - - switch (op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_FUNC(&partition_tbl, - &value->var, sub, partition_idx_cmp)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - value->var.len = sub + 2; - value->var.subs[sub] = entry->index[0]; - value->var.subs[sub + 1] = entry->index[1]; - - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_FUNC(&partition_tbl, - &value->var, sub, partition_idx_cmp)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_FUNC(&partition_tbl, - &value->var, sub, partition_idx_cmp)) == NULL) - return (SNMP_ERR_NOT_WRITEABLE); - return (SNMP_ERR_NO_CREATION); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrPartitionIndex: - value->v.integer = entry->index[1]; - return (SNMP_ERR_NOERROR); - - case LEAF_hrPartitionLabel: - return (string_get(value, entry->label, -1)); - - case LEAF_hrPartitionID: - return(string_get(value, entry->id, -1)); - - case LEAF_hrPartitionSize: - value->v.integer = entry->size; - return (SNMP_ERR_NOERROR); - - case LEAF_hrPartitionFSIndex: - value->v.integer = entry->fs_Index; - return (SNMP_ERR_NOERROR); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_printer_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_printer_tbl.c deleted file mode 100644 index 883d67a..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_printer_tbl.c +++ /dev/null @@ -1,398 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB implementation for SNMPd: instrumentation for - * hrPrinterTable - */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -#include -#include "lp.h" - -/* Constants */ -static const struct asn_oid OIDX_hrDevicePrinter_c = OIDX_hrDevicePrinter; - -enum PrinterStatus { - PS_OTHER = 1, - PS_UNKNOWN = 2, - PS_IDLE = 3, - PS_PRINTING = 4, - PS_WARMUP = 5 -}; - -/* - * This structure is used to hold a SNMP table entry - * for HOST-RESOURCES-MIB's hrPrinterTable. - */ -struct printer_entry { - int32_t index; - int32_t status; /* values from PrinterStatus enum above */ - u_char detectedErrorState[2]; - TAILQ_ENTRY(printer_entry) link; -#define HR_PRINTER_FOUND 0x001 - uint32_t flags; - -}; -TAILQ_HEAD(printer_tbl, printer_entry); - -/* the hrPrinterTable */ -static struct printer_tbl printer_tbl = TAILQ_HEAD_INITIALIZER(printer_tbl); - -/* last (agent) tick when hrPrinterTable was updated */ -static uint64_t printer_tick; - -/** - * Create entry into the printer table. - */ -static struct printer_entry * -printer_entry_create(const struct device_entry *devEntry) -{ - struct printer_entry *entry = NULL; - - assert(devEntry != NULL); - if (devEntry == NULL) - return (NULL); - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "hrPrinterTable: %s: %m", __func__); - return (NULL); - } - memset(entry, 0, sizeof(*entry)); - entry->index = devEntry->index; - INSERT_OBJECT_INT(entry, &printer_tbl); - return (entry); -} - -/** - * Delete entry from the printer table. - */ -static void -printer_entry_delete(struct printer_entry *entry) -{ - - assert(entry != NULL); - if (entry == NULL) - return; - - TAILQ_REMOVE(&printer_tbl, entry, link); - free(entry); -} - -/** - * Find a printer by its index - */ -static struct printer_entry * -printer_find_by_index(int32_t idx) -{ - struct printer_entry *entry; - - TAILQ_FOREACH(entry, &printer_tbl, link) - if (entry->index == idx) - return (entry); - - return (NULL); -} - -/** - * Get the status of a printer - */ -static enum PrinterStatus -get_printer_status(const struct printer *pp) -{ - char statfile[MAXPATHLEN]; - char lockfile[MAXPATHLEN]; - char fline[128]; - int fd; - FILE *f = NULL; - enum PrinterStatus ps = PS_UNKNOWN; - - if (pp->lock_file[0] == '/') - strlcpy(lockfile, pp->lock_file, sizeof(lockfile)); - else - snprintf(lockfile, sizeof(lockfile), "%s/%s", - pp->spool_dir, pp->lock_file); - - fd = open(lockfile, O_RDONLY); - if (fd < 0 || flock(fd, LOCK_SH | LOCK_NB) == 0) { - ps = PS_IDLE; - goto LABEL_DONE; - } - - if (pp->status_file[0] == '/') - strlcpy(statfile, pp->status_file, sizeof(statfile)); - else - snprintf(statfile, sizeof(statfile), "%s/%s", - pp->spool_dir, pp->status_file); - - f = fopen(statfile, "r"); - if (f == NULL) { - syslog(LOG_ERR, "cannot open status file: %s", strerror(errno)); - ps = PS_UNKNOWN; - goto LABEL_DONE; - } - - memset(&fline[0], '\0', sizeof(line)); - if (fgets(fline, sizeof(fline) -1, f) == NULL) { - ps = PS_UNKNOWN; - goto LABEL_DONE; - } - - if (strstr(fline, "is ready and printing") != NULL) { - ps = PS_PRINTING; - goto LABEL_DONE; - } - - if (strstr(fline, "to become ready (offline?)") != NULL) { - ps = PS_OTHER; - goto LABEL_DONE; - } - -LABEL_DONE: - if (fd >= 0) - (void)close(fd); /* unlocks as well */ - - if (f != NULL) - (void)fclose(f); - - return (ps); -} - -/** - * Called for each printer found in /etc/printcap. - */ -static void -handle_printer(struct printer *pp) -{ - struct device_entry *dev_entry; - struct printer_entry *printer_entry; - char dev_only[128]; - struct stat sb; - - if (pp->remote_host != NULL) { - HRDBG("skipped %s -- remote", pp->printer); - return; - } - - if (strncmp(pp->lp, _PATH_DEV, strlen(_PATH_DEV)) != 0) { - HRDBG("skipped %s [device %s] -- remote", pp->printer, pp->lp); - return; - } - - memset(dev_only, '\0', sizeof(dev_only)); - snprintf(dev_only, sizeof(dev_only), "%s", pp->lp + strlen(_PATH_DEV)); - - HRDBG("printer %s has device %s", pp->printer, dev_only); - - if (stat(pp->lp, &sb) < 0) { - if (errno == ENOENT) { - HRDBG("skipped %s -- device %s missing", - pp->printer, pp->lp); - return; - } - } - - if ((dev_entry = device_find_by_name(dev_only)) == NULL) { - HRDBG("%s not in hrDeviceTable", pp->lp); - return; - } - HRDBG("%s found in hrDeviceTable", pp->lp); - dev_entry->type = &OIDX_hrDevicePrinter_c; - - dev_entry->flags |= HR_DEVICE_IMMUTABLE; - - /* Then check hrPrinterTable for this device */ - if ((printer_entry = printer_find_by_index(dev_entry->index)) == NULL && - (printer_entry = printer_entry_create(dev_entry)) == NULL) - return; - - printer_entry->flags |= HR_PRINTER_FOUND; - printer_entry->status = get_printer_status(pp); - memset(printer_entry->detectedErrorState, 0, - sizeof(printer_entry->detectedErrorState)); -} - -static void -hrPrinter_get_OS_entries(void) -{ - int status, more; - struct printer myprinter, *pp = &myprinter; - - init_printer(pp); - HRDBG("---->Getting printers ....."); - more = firstprinter(pp, &status); - if (status) - goto errloop; - - while (more) { - do { - HRDBG("---->Got printer %s", pp->printer); - - handle_printer(pp); - more = nextprinter(pp, &status); -errloop: - if (status) - syslog(LOG_WARNING, - "hrPrinterTable: printcap entry for %s " - "has errors, skipping", - pp->printer ? pp->printer : ""); - } while (more && status); - } - - lastprinter(); - printer_tick = this_tick; -} - -/** - * Init the things for hrPrinterTable - */ -void -init_printer_tbl(void) -{ - - hrPrinter_get_OS_entries(); -} - -/** - * Finalization routine for hrPrinterTable - * It destroys the lists and frees any allocated heap memory - */ -void -fini_printer_tbl(void) -{ - struct printer_entry *n1; - - while ((n1 = TAILQ_FIRST(&printer_tbl)) != NULL) { - TAILQ_REMOVE(&printer_tbl, n1, link); - free(n1); - } -} - -/** - * Refresh the printer table if needed. - */ -void -refresh_printer_tbl(void) -{ - struct printer_entry *entry; - struct printer_entry *entry_tmp; - - if (this_tick <= printer_tick) { - HRDBG("no refresh needed"); - return; - } - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &printer_tbl, link) - entry->flags &= ~HR_PRINTER_FOUND; - - hrPrinter_get_OS_entries(); - - /* - * Purge items that disappeared - */ - entry = TAILQ_FIRST(&printer_tbl); - while (entry != NULL) { - entry_tmp = TAILQ_NEXT(entry, link); - if (!(entry->flags & HR_PRINTER_FOUND)) - printer_entry_delete(entry); - entry = entry_tmp; - } - - printer_tick = this_tick; - - HRDBG("refresh DONE "); -} - -int -op_hrPrinterTable(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - struct printer_entry *entry; - - refresh_printer_tbl(); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&printer_tbl, &value->var, - sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&printer_tbl, &value->var, - sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&printer_tbl, &value->var, - sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrPrinterStatus: - value->v.integer = entry->status; - return (SNMP_ERR_NOERROR); - - case LEAF_hrPrinterDetectedErrorState: - return (string_get(value, entry->detectedErrorState, - sizeof(entry->detectedErrorState))); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c deleted file mode 100644 index 33f7b2d..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_processor_tbl.c +++ /dev/null @@ -1,507 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB for SNMPd. Implementation for hrProcessorTable - */ - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -/* - * This structure is used to hold a SNMP table entry - * for HOST-RESOURCES-MIB's hrProcessorTable. - * Note that index is external being allocated & maintained - * by the hrDeviceTable code.. - */ -struct processor_entry { - int32_t index; - const struct asn_oid *frwId; - int32_t load; - TAILQ_ENTRY(processor_entry) link; - u_char cpu_no; /* which cpu, counted from 0 */ - pid_t idle_pid; /* PID of idle process for this CPU */ - - /* the samples from the last minute, as required by MIB */ - double samples[MAX_CPU_SAMPLES]; - - /* current sample to fill in next time, must be < MAX_CPU_SAMPLES */ - uint32_t cur_sample_idx; - - /* number of useful samples */ - uint32_t sample_cnt; -}; -TAILQ_HEAD(processor_tbl, processor_entry); - -/* the head of the list with hrDeviceTable's entries */ -static struct processor_tbl processor_tbl = - TAILQ_HEAD_INITIALIZER(processor_tbl); - -/* number of processors in dev tbl */ -static int32_t detected_processor_count; - -/* sysctlbyname(hw.ncpu) */ -static int hw_ncpu; - -/* sysctlbyname(kern.{ccpu,fscale}) */ -static fixpt_t ccpu; -static int fscale; - -/* tick of PDU where we have refreshed the processor table last */ -static uint64_t proctbl_tick; - -/* periodic timer used to get cpu load stats */ -static void *cpus_load_timer; - -/* - * Average the samples. The entire algorithm seems to be wrong XXX. - */ -static int -get_avg_load(struct processor_entry *e) -{ - u_int i; - double sum = 0.0; - - assert(e != NULL); - - if (e->sample_cnt == 0) - return (0); - - for (i = 0; i < e->sample_cnt; i++) - sum += e->samples[i]; - - return ((int)floor((double)sum/(double)e->sample_cnt)); -} - -/* - * Stolen from /usr/src/bin/ps/print.c. The idle process should never - * be swapped out :-) - */ -static double -processor_getpcpu(struct kinfo_proc *ki_p) -{ - - if (ccpu == 0 || fscale == 0) - return (0.0); - -#define fxtofl(fixpt) ((double)(fixpt) / fscale) - return (100.0 * fxtofl(ki_p->ki_pctcpu) / - (1.0 - exp(ki_p->ki_swtime * log(fxtofl(ccpu))))); -} - -/** - * Save a new sample - */ -static void -save_sample(struct processor_entry *e, struct kinfo_proc *kp) -{ - - e->samples[e->cur_sample_idx] = 100.0 - processor_getpcpu(kp); - e->load = get_avg_load(e); - e->cur_sample_idx = (e->cur_sample_idx + 1) % MAX_CPU_SAMPLES; - - if (++e->sample_cnt > MAX_CPU_SAMPLES) - e->sample_cnt = MAX_CPU_SAMPLES; -} - -/** - * Create a new entry into the processor table. - */ -static struct processor_entry * -proc_create_entry(u_int cpu_no, struct device_map_entry *map) -{ - struct device_entry *dev; - struct processor_entry *entry; - char name[128]; - - /* - * If there is no map entry create one by creating a device table - * entry. - */ - if (map == NULL) { - snprintf(name, sizeof(name), "cpu%u", cpu_no); - if ((dev = device_entry_create(name, "", "")) == NULL) - return (NULL); - dev->flags |= HR_DEVICE_IMMUTABLE; - STAILQ_FOREACH(map, &device_map, link) - if (strcmp(map->name_key, name) == 0) - break; - if (map == NULL) - abort(); - } - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_ERR, "hrProcessorTable: %s malloc " - "failed: %m", __func__); - return (NULL); - } - memset(entry, 0, sizeof(*entry)); - - entry->index = map->hrIndex; - entry->load = 0; - entry->cpu_no = (u_char)cpu_no; - entry->idle_pid = 0; - entry->frwId = &oid_zeroDotZero; /* unknown id FIXME */ - - INSERT_OBJECT_INT(entry, &processor_tbl); - - HRDBG("CPU %d added with SNMP index=%d", - entry->cpu_no, entry->index); - - return (entry); -} - -/** - * Get the PIDs for the idle processes of the CPUs. - */ -static void -processor_get_pids(void) -{ - struct kinfo_proc *plist, *kp; - int i; - int nproc; - int cpu; - int nchars; - struct processor_entry *entry; - - plist = kvm_getprocs(hr_kd, KERN_PROC_ALL, 0, &nproc); - if (plist == NULL || nproc < 0) { - syslog(LOG_ERR, "hrProcessor: kvm_getprocs() failed: %m"); - return; - } - - for (i = 0, kp = plist; i < nproc; i++, kp++) { - if (!IS_KERNPROC(kp)) - continue; - - if (strcmp(kp->ki_comm, "idle") == 0) { - /* single processor system */ - cpu = 0; - } else if (sscanf(kp->ki_comm, "idle: cpu%d%n", &cpu, &nchars) - == 1 && (u_int)nchars == strlen(kp->ki_comm)) { - /* MP system */ - } else - /* not an idle process */ - continue; - - HRDBG("'%s' proc with pid %d is on CPU #%d (last on #%d)", - kp->ki_comm, kp->ki_pid, kp->ki_oncpu, kp->ki_lastcpu); - - TAILQ_FOREACH(entry, &processor_tbl, link) - if (entry->cpu_no == kp->ki_lastcpu) - break; - - if (entry == NULL) { - /* create entry on non-ACPI systems */ - if ((entry = proc_create_entry(cpu, NULL)) == NULL) - continue; - - detected_processor_count++; - } - - entry->idle_pid = kp->ki_pid; - HRDBG("CPU no. %d with SNMP index=%d has idle PID %d", - entry->cpu_no, entry->index, entry->idle_pid); - - save_sample(entry, kp); - } -} - -/** - * Scan the device map table for CPUs and create an entry into the - * processor table for each CPU. Then fetch the idle PIDs for all CPUs. - */ -static void -create_proc_table(void) -{ - struct device_map_entry *map; - struct processor_entry *entry; - int cpu_no; - - detected_processor_count = 0; - - /* - * Because hrProcessorTable depends on hrDeviceTable, - * the device detection must be performed at this point. - * If not, no entries will be present in the hrProcessor Table. - * - * For non-ACPI system the processors are not in the device table, - * therefor insert them when getting the idle pids. XXX - */ - STAILQ_FOREACH(map, &device_map, link) - if (strncmp(map->name_key, "cpu", strlen("cpu")) == 0 && - strstr(map->location_key, ".CPU") != NULL) { - if (sscanf(map->name_key,"cpu%d", &cpu_no) != 1) { - syslog(LOG_ERR, "hrProcessorTable: Failed to " - "get cpu no. from device named '%s'", - map->name_key); - continue; - } - - if ((entry = proc_create_entry(cpu_no, map)) == NULL) - continue; - - detected_processor_count++; - } - - HRDBG("%d CPUs detected", detected_processor_count); - - processor_get_pids(); -} - -/** - * Free the processor table - */ -static void -free_proc_table(void) -{ - struct processor_entry *n1; - - while ((n1 = TAILQ_FIRST(&processor_tbl)) != NULL) { - TAILQ_REMOVE(&processor_tbl, n1, link); - free(n1); - detected_processor_count--; - } - - assert(detected_processor_count == 0); - detected_processor_count = 0; -} - -/** - * Init the things for hrProcessorTable. - * Scan the device table for processor entries. - */ -void -init_processor_tbl(void) -{ - size_t len; - - /* get various parameters from the kernel */ - len = sizeof(ccpu); - if (sysctlbyname("kern.ccpu", &ccpu, &len, NULL, 0) == -1) { - syslog(LOG_ERR, "hrProcessorTable: sysctl(kern.ccpu) failed"); - ccpu = 0; - } - - len = sizeof(fscale); - if (sysctlbyname("kern.fscale", &fscale, &len, NULL, 0) == -1) { - syslog(LOG_ERR, "hrProcessorTable: sysctl(kern.fscale) failed"); - fscale = 0; - } - - /* create the initial processor table */ - create_proc_table(); -} - -/** - * Finalization routine for hrProcessorTable. - * It destroys the lists and frees any allocated heap memory. - */ -void -fini_processor_tbl(void) -{ - - if (cpus_load_timer != NULL) { - timer_stop(cpus_load_timer); - cpus_load_timer = NULL; - } - - free_proc_table(); -} - -/** - * Make sure that the number of processors announced by the kernel hw.ncpu - * is equal to the number of processors we have found in the device table. - * If they differ rescan the device table. - */ -static void -processor_refill_tbl(void) -{ - - HRDBG("hw_ncpu=%d detected_processor_count=%d", hw_ncpu, - detected_processor_count); - - if (hw_ncpu <= 0) { - size_t size = sizeof(hw_ncpu); - - if (sysctlbyname("hw.ncpu", &hw_ncpu, &size, NULL, 0) == -1 || - size != sizeof(hw_ncpu)) { - syslog(LOG_ERR, "hrProcessorTable: " - "sysctl(hw.ncpu) failed: %m"); - hw_ncpu = 0; - return; - } - } - - if (hw_ncpu != detected_processor_count) { - free_proc_table(); - create_proc_table(); - } -} - -/** - * Refresh all values in the processor table. We call this once for - * every PDU that accesses the table. - */ -static void -refresh_processor_tbl(void) -{ - struct processor_entry *entry; - int need_pids; - struct kinfo_proc *plist; - int nproc; - - processor_refill_tbl(); - - need_pids = 0; - TAILQ_FOREACH(entry, &processor_tbl, link) { - if (entry->idle_pid <= 0) { - need_pids = 1; - continue; - } - - assert(hr_kd != NULL); - - plist = kvm_getprocs(hr_kd, KERN_PROC_PID, - entry->idle_pid, &nproc); - if (plist == NULL || nproc != 1) { - syslog(LOG_ERR, "%s: missing item with " - "PID = %d for CPU #%d\n ", __func__, - entry->idle_pid, entry->cpu_no); - need_pids = 1; - continue; - } - save_sample(entry, plist); - } - - if (need_pids == 1) - processor_get_pids(); - - proctbl_tick = this_tick; -} - -/** - * This function is called MAX_CPU_SAMPLES times per minute to collect the - * CPU load. - */ -static void -get_cpus_samples(void *arg __unused) -{ - - HRDBG("[%llu] ENTER", (unsigned long long)get_ticks()); - refresh_processor_tbl(); - HRDBG("[%llu] EXIT", (unsigned long long)get_ticks()); -} - -/** - * Called to start this table. We need to start the periodic idle - * time collection. - */ -void -start_processor_tbl(struct lmodule *mod) -{ - - /* - * Start the cpu stats collector - * The semantics of timer_start parameters is in "SNMP ticks"; - * we have 100 "SNMP ticks" per second, thus we are trying below - * to get MAX_CPU_SAMPLES per minute - */ - cpus_load_timer = timer_start_repeat(100, 100 * 60 / MAX_CPU_SAMPLES, - get_cpus_samples, NULL, mod); -} - -/** - * Access routine for the processor table. - */ -int -op_hrProcessorTable(struct snmp_context *ctx __unused, - struct snmp_value *value, u_int sub, u_int iidx __unused, - enum snmp_op curr_op) -{ - struct processor_entry *entry; - - if (this_tick != proctbl_tick) - refresh_processor_tbl(); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&processor_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&processor_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&processor_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrProcessorFrwID: - assert(entry->frwId != NULL); - value->v.oid = *entry->frwId; - return (SNMP_ERR_NOERROR); - - case LEAF_hrProcessorLoad: - value->v.integer = entry->load; - return (SNMP_ERR_NOERROR); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c deleted file mode 100644 index f86334e..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c +++ /dev/null @@ -1,492 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB scalars implementation for SNMPd. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -/* boot timestamp in centi-seconds */ -static uint64_t kernel_boot; - -/* physical memory size in Kb */ -static uint64_t phys_mem_size; - -/* boot line (malloced) */ -static u_char *boot_line; - -/* maximum number of processes */ -static uint32_t max_proc; - -/** - * Free all static data - */ -void -fini_scalars(void) -{ - - free(boot_line); -} - -/** - * Get system uptime in hundredths of seconds since the epoch - * Returns 0 in case of an error - */ -static int -OS_getSystemUptime(uint32_t *ut) -{ - struct timeval right_now; - uint64_t now; - - if (kernel_boot == 0) { - /* first time, do the sysctl */ - struct timeval kernel_boot_timestamp; - int mib[2] = { CTL_KERN, KERN_BOOTTIME }; - size_t len = sizeof(kernel_boot_timestamp); - - if (sysctl(mib, 2, &kernel_boot_timestamp, - &len, NULL, 0) == -1) { - syslog(LOG_ERR, "sysctl KERN_BOOTTIME failed: %m"); - return (SNMP_ERR_GENERR); - } - - HRDBG("boot timestamp from kernel: {%lld, %ld}", - (long long)kernel_boot_timestamp.tv_sec, - (long)kernel_boot_timestamp.tv_usec); - - kernel_boot = ((uint64_t)kernel_boot_timestamp.tv_sec * 100) + - (kernel_boot_timestamp.tv_usec / 10000); - } - - if (gettimeofday(&right_now, NULL) < 0) { - syslog(LOG_ERR, "gettimeofday failed: %m"); - return (SNMP_ERR_GENERR); - } - now = ((uint64_t)right_now.tv_sec * 100) + (right_now.tv_usec / 10000); - - if (now - kernel_boot > UINT32_MAX) - *ut = UINT32_MAX; - else - *ut = now - kernel_boot; - - return (SNMP_ERR_NOERROR); -} - -/** - * Get system local date and time in a foramt suitable for DateAndTime TC: - * field octets contents range - * ----- ------ -------- ----- - * 1 1-2 year* 0..65536 - * 2 3 month 1..12 - * 3 4 day 1..31 - * 4 5 hour 0..23 - * 5 6 minutes 0..59 - * 6 7 seconds 0..60 - * (use 60 for leap-second) - * 7 8 deci-seconds 0..9 - * 8 9 direction from UTC '+' / '-' - * 9 10 hours from UTC* 0..13 - * 10 11 minutes from UTC 0..59 - * - * * Notes: - * - the value of year is in network-byte order - * - daylight saving time in New Zealand is +13 - * - * For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be - * displayed as: - * - * 1992-5-26,13:30:15.0,-4:0 - * - * Returns -1 in case of an error or the length of the string (8 or 11) - * Actually returns always 11 on freebsd - */ -static int -OS_getSystemDate(struct snmp_value *value) -{ - u_char s_date_time[11]; - struct tm tloc_tm; - time_t tloc_time_t; - struct timeval right_now; - int string_len; - - if (gettimeofday(&right_now, NULL) < 0) { - syslog(LOG_ERR, "gettimeofday failed: %m"); - return (SNMP_ERR_GENERR); - } - - tloc_time_t = right_now.tv_sec; - - if (localtime_r(&tloc_time_t, &tloc_tm) == NULL) { - syslog(LOG_ERR, "localtime_r() failed: %m "); - return (SNMP_ERR_GENERR); - } - - string_len = make_date_time(s_date_time, &tloc_tm, - right_now.tv_usec / 100000); - - return (string_get(value, s_date_time, string_len)); -} - -/** - * Get kernel boot path. For FreeBSD it seems that no arguments are - * present. Returns NULL if an error occured. The returned data is a - * pointer to a global strorage. - */ -int -OS_getSystemInitialLoadParameters(u_char **params) -{ - - if (boot_line == NULL) { - int mib[2] = { CTL_KERN, KERN_BOOTFILE }; - char *buf; - size_t buf_len = 0; - - /* get the needed buffer len */ - if (sysctl(mib, 2, NULL, &buf_len, NULL, 0) != 0) { - syslog(LOG_ERR, - "sysctl({CTL_KERN,KERN_BOOTFILE}) failed: %m"); - return (SNMP_ERR_GENERR); - } - - if ((buf = malloc(buf_len)) == NULL) { - syslog(LOG_ERR, "malloc failed"); - return (SNMP_ERR_GENERR); - } - if (sysctl(mib, 2, buf, &buf_len, NULL, 0)) { - syslog(LOG_ERR, - "sysctl({CTL_KERN,KERN_BOOTFILE}) failed: %m"); - free(buf); - return (SNMP_ERR_GENERR); - } - - boot_line = buf; - HRDBG("kernel boot file: %s", boot_line); - } - - *params = boot_line; - return (SNMP_ERR_NOERROR); -} - -/** - * Get number of current users which are logged in - */ -static int -OS_getSystemNumUsers(uint32_t *nu) -{ - struct utmpx *utmp; - - setutxent(); - *nu = 0; - while ((utmp = getutxent()) != NULL) { - if (utmp->ut_type == USER_PROCESS) - (*nu)++; - } - endutxent(); - - return (SNMP_ERR_NOERROR); -} - -/** - * Get number of current processes existing into the system - */ -static int -OS_getSystemProcesses(uint32_t *proc_count) -{ - int pc; - - if (hr_kd == NULL) - return (SNMP_ERR_GENERR); - - if (kvm_getprocs(hr_kd, KERN_PROC_ALL, 0, &pc) == NULL) { - syslog(LOG_ERR, "kvm_getprocs failed: %m"); - return (SNMP_ERR_GENERR); - } - - *proc_count = pc; - return (SNMP_ERR_NOERROR); -} - -/** - * Get maximum number of processes allowed on this system - */ -static int -OS_getSystemMaxProcesses(uint32_t *mproc) -{ - - if (max_proc == 0) { - int mib[2] = { CTL_KERN, KERN_MAXPROC }; - int mp; - size_t len = sizeof(mp); - - if (sysctl(mib, 2, &mp, &len, NULL, 0) == -1) { - syslog(LOG_ERR, "sysctl KERN_MAXPROC failed: %m"); - return (SNMP_ERR_GENERR); - } - max_proc = mp; - } - - *mproc = max_proc; - return (SNMP_ERR_NOERROR); -} - -/* - * Get the physical memeory size in Kbytes. - * Returns SNMP error code. - */ -static int -OS_getMemorySize(uint32_t *ms) -{ - - if (phys_mem_size == 0) { - int mib[2] = { CTL_HW, HW_PHYSMEM }; - u_long physmem; - size_t len = sizeof(physmem); - - if (sysctl(mib, 2, &physmem, &len, NULL, 0) == -1) { - syslog(LOG_ERR, - "sysctl({ CTL_HW, HW_PHYSMEM }) failed: %m"); - return (SNMP_ERR_GENERR); - } - - phys_mem_size = physmem / 1024; - } - - if (phys_mem_size > UINT32_MAX) - *ms = UINT32_MAX; - else - *ms = phys_mem_size; - return (SNMP_ERR_NOERROR); -} - -/* - * Try to use the s_date_time parameter as a DateAndTime TC to fill in - * the second parameter. - * Returns 0 on succes and -1 for an error. - * Bug: time zone info is not used - */ -static struct timeval * -OS_checkSystemDateInput(const u_char *str, u_int len) -{ - struct tm tm_to_set; - time_t t; - struct timeval *tv; - - if (len != 8 && len != 11) - return (NULL); - - if (str[2] == 0 || str[2] > 12 || - str[3] == 0 || str[3] > 31 || - str[4] > 23 || str[5] > 59 || str[6] > 60 || str[7] > 9) - return (NULL); - - tm_to_set.tm_year = ((str[0] << 8) + str[1]) - 1900; - tm_to_set.tm_mon = str[2] - 1; - tm_to_set.tm_mday = str[3]; - tm_to_set.tm_hour = str[4]; - tm_to_set.tm_min = str[5]; - tm_to_set.tm_sec = str[6]; - tm_to_set.tm_isdst = 0; - - /* now make UTC from it */ - if ((t = timegm(&tm_to_set)) == (time_t)-1) - return (NULL); - - /* now apply timezone if specified */ - if (len == 11) { - if (str[9] > 13 || str[10] > 59) - return (NULL); - if (str[8] == '+') - t += 3600 * str[9] + 60 * str[10]; - else - t -= 3600 * str[9] + 60 * str[10]; - } - - if ((tv = malloc(sizeof(*tv))) == NULL) - return (NULL); - - tv->tv_sec = t; - tv->tv_usec = (int32_t)str[7] * 100000; - - return (tv); -} - -/* - * Set system date and time. Timezone is not changed - */ -static int -OS_setSystemDate(const struct timeval *timeval_to_set) -{ - if (settimeofday(timeval_to_set, NULL) == -1) { - syslog(LOG_ERR, "settimeofday failed: %m"); - return (SNMP_ERR_GENERR); - } - return (SNMP_ERR_NOERROR); -} - -/* - * prototype of this function was genrated by gensnmptree tool in header file - * hostres_tree.h - * Returns SNMP_ERR_NOERROR on success - */ -int -op_hrSystem(struct snmp_context *ctx, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - int err; - u_char *str; - - switch (curr_op) { - - case SNMP_OP_GET: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSystemUptime: - return (OS_getSystemUptime(&value->v.uint32)); - - case LEAF_hrSystemDate: - return (OS_getSystemDate(value)); - - case LEAF_hrSystemInitialLoadDevice: - value->v.uint32 = 0; /* FIXME */ - return (SNMP_ERR_NOERROR); - - case LEAF_hrSystemInitialLoadParameters: - if ((err = OS_getSystemInitialLoadParameters(&str)) != - SNMP_ERR_NOERROR) - return (err); - return (string_get(value, str, -1)); - - case LEAF_hrSystemNumUsers: - return (OS_getSystemNumUsers(&value->v.uint32)); - - case LEAF_hrSystemProcesses: - return (OS_getSystemProcesses(&value->v.uint32)); - - case LEAF_hrSystemMaxProcesses: - return (OS_getSystemMaxProcesses(&value->v.uint32)); - } - abort(); - - case SNMP_OP_SET: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSystemDate: - if ((ctx->scratch->ptr1 = - OS_checkSystemDateInput(value->v.octetstring.octets, - value->v.octetstring.len)) == NULL) - return (SNMP_ERR_WRONG_VALUE); - - return (SNMP_ERR_NOERROR); - - case LEAF_hrSystemInitialLoadDevice: - case LEAF_hrSystemInitialLoadParameters: - return (SNMP_ERR_NOT_WRITEABLE); - - } - abort(); - - case SNMP_OP_ROLLBACK: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSystemDate: - free(ctx->scratch->ptr1); - return (SNMP_ERR_NOERROR); - - case LEAF_hrSystemInitialLoadDevice: - case LEAF_hrSystemInitialLoadParameters: - abort(); - } - abort(); - - case SNMP_OP_COMMIT: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSystemDate: - (void)OS_setSystemDate(ctx->scratch->ptr1); - free(ctx->scratch->ptr1); - return (SNMP_ERR_NOERROR); - - case LEAF_hrSystemInitialLoadDevice: - case LEAF_hrSystemInitialLoadParameters: - abort(); - } - abort(); - - case SNMP_OP_GETNEXT: - abort(); - } - abort(); -} - -/* - * prototype of this function was genrated by gensnmptree tool - * in the header file hostres_tree.h - * Returns SNMP_ERR_NOERROR on success - */ -int -op_hrStorage(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - - /* only GET is possible */ - switch (curr_op) { - - case SNMP_OP_GET: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrMemorySize: - return (OS_getMemorySize(&value->v.uint32)); - } - abort(); - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - case SNMP_OP_GETNEXT: - abort(); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c deleted file mode 100644 index c2a06db..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c +++ /dev/null @@ -1,208 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * This C file contains code developed by Poul-Henning Kamp under the - * following license: - * - * FreeBSD: src/sbin/mdconfig/mdconfig.c,v 1.33.2.1 2004/09/14 03:32:21 jmg Exp - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB implementation for bsnmpd. - */ - -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -/* Internal id got after we'll register this module with the agent */ -static u_int host_registration_id = 0; - -/* This our hostres module */ -static struct lmodule *hostres_module; - -/* See the generated file hostres_oid.h */ -static const struct asn_oid oid_host = OIDX_host; - -/* descriptor to access kernel memory */ -kvm_t *hr_kd; - -/* - * HOST RESOURCES mib module finalization hook. - * Returns 0 on success, < 0 on error - */ -static int -hostres_fini(void) -{ - - if (hr_kd != NULL) - (void)kvm_close(hr_kd); - - fini_storage_tbl(); - fini_fs_tbl(); - fini_processor_tbl(); - fini_disk_storage_tbl(); - fini_device_tbl(); - fini_partition_tbl(); - fini_network_tbl(); - fini_printer_tbl(); - - fini_swrun_tbl(); - fini_swins_tbl(); - - fini_scalars(); - - if (host_registration_id > 0) - or_unregister(host_registration_id); - - HRDBG("done."); - return (0); -} - -/* - * HOST RESOURCES mib module initialization hook. - * Returns 0 on success, < 0 on error - */ -static int -hostres_init(struct lmodule *mod, int argc __unused, char *argv[] __unused) -{ - - hostres_module = mod; - - /* - * NOTE: order of these calls is important here! - */ - if ((hr_kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, - "kvm_open")) == NULL) { - syslog(LOG_ERR, "kvm_open failed: %m "); - return (-1); - } - - /* - * The order is relevant here, because some table depend on each other. - */ - init_device_tbl(); - - /* populates partition table too */ - if (init_disk_storage_tbl()) { - hostres_fini(); - return (-1); - } - init_processor_tbl(); - init_printer_tbl(); - - /* - * populate storage and FS tables. Must be done after device - * initialisation because the FS refresh code calls into the - * partition refresh code. - */ - init_storage_tbl(); - - - /* also the hrSWRunPerfTable's support is initialized here */ - init_swrun_tbl(); - init_swins_tbl(); - - HRDBG("done."); - - return (0); -} - -/* - * HOST RESOURCES mib module start operation - * returns nothing - */ -static void -hostres_start(void) -{ - - host_registration_id = or_register(&oid_host, - "The MIB module for Host Resource MIB (RFC 2790).", - hostres_module); - - start_device_tbl(hostres_module); - start_processor_tbl(hostres_module); - start_network_tbl(); - - HRDBG("done."); -} - -/* this identifies the HOST RESOURCES mib module */ -const struct snmp_module config = { - "This module implements the host resource mib (rfc 2790)", - hostres_init, - hostres_fini, - NULL, /* idle function, do not use it */ - NULL, - NULL, - hostres_start, - NULL, /* proxy a PDU */ - hostres_ctree, /* see the generated hostres_tree.h */ - hostres_CTREE_SIZE, /* see the generated hostres_tree.h */ - NULL -}; - -/** - * Make an SNMP DateAndTime from a struct tm. This should be in the library. - */ -int -make_date_time(u_char *str, const struct tm *tm, u_int decisecs) -{ - - str[0] = (u_char)((tm->tm_year + 1900) >> 8); - str[1] = (u_char)(tm->tm_year + 1900); - str[2] = tm->tm_mon + 1; - str[3] = tm->tm_mday; - str[4] = tm->tm_hour; - str[5] = tm->tm_min; - str[6] = tm->tm_sec; - str[7] = decisecs; - if (tm->tm_gmtoff < 0) - str[8] = '-'; - else - str[8] = '+'; - - str[9] = (u_char)(abs(tm->tm_gmtoff) / 3600); - str[10] = (u_char)((abs(tm->tm_gmtoff) % 3600) / 60); - - return (11); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h deleted file mode 100644 index 567368a..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * Host Resources MIB for SNMPd. - * - * $FreeBSD$ - */ - -#ifndef HOSTRES_SNMP_H_1132245017 -#define HOSTRES_SNMP_H_1132245017 - -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include - -/* - * Default package directory for hrSWInstalledTable. Can be overridden - * via SNMP or configuration file. - */ -#define PATH_PKGDIR "/var/db/pkg" - -/* - * These are the default maximum caching intervals for the various tables - * in seconds. They can be overridden from the configuration file. - */ -#define HR_STORAGE_TBL_REFRESH 7 -#define HR_FS_TBL_REFRESH 7 -#define HR_DISK_TBL_REFRESH 7 -#define HR_NETWORK_TBL_REFRESH 7 -#define HR_SWINS_TBL_REFRESH 120 -#define HR_SWRUN_TBL_REFRESH 3 - -struct tm; -struct statfs; - -/* a debug macro */ -#ifndef NDEBUG - -#define HRDBG(...) do { \ - fprintf(stderr, "HRDEBUG: %s: ", __func__); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ - } while (0) - -#else - -#define HRDBG(...) do { } while (0) - -#endif /*NDEBUG*/ - -/* path to devd(8) output pipe */ -#define PATH_DEVD_PIPE "/var/run/devd.pipe" - -#define IS_KERNPROC(kp) (((kp)->ki_flag & P_KTHREAD) == P_KTHREAD) - -enum snmpTCTruthValue { - SNMP_TRUE = 1, - SNMP_FALSE= 2 -}; - -/* The number of CPU load samples per one minute, per each CPU */ -#define MAX_CPU_SAMPLES 4 - - -/* - * max len (including '\0'), for device_entry::descr field below, - * according to MIB - */ -#define DEV_DESCR_MLEN (64 + 1) - -/* - * max len (including '\0'), for device_entry::name and - * device_map_entry::name_key fields below, according to MIB - */ -#define DEV_NAME_MLEN (32 + 1) - -/* - * max len (including '\0'), for device_entry::location and - * device_map_entry::location_key fields below, according to MIB - */ -#define DEV_LOC_MLEN (128 + 1) - -/* - * This structure is used to hold a SNMP table entry - * for HOST-RESOURCES-MIB's hrDeviceTable - */ -struct device_entry { - int32_t index; - const struct asn_oid *type; - u_char *descr; - const struct asn_oid *id; /* only oid_zeroDotZero as (*id) value*/ - int32_t status; /* enum DeviceStatus */ - uint32_t errors; - -#define HR_DEVICE_FOUND 0x001 - /* not dectected by libdevice, so don't try to refresh it*/ -#define HR_DEVICE_IMMUTABLE 0x002 - - /* next 3 are not from the SNMP mib table, only to be used internally */ - uint32_t flags; - - u_char *name; - u_char *location; - TAILQ_ENTRY(device_entry) link; -}; - -/* - * Next structure is used to keep o list of mappings from a specific - * name (a_name) to an entry in the hrFSTblEntry; - * We are trying to keep the same index for a specific name at least - * for the duration of one SNMP agent run. - */ -struct device_map_entry { - int32_t hrIndex; /* used for hrDeviceTblEntry::index */ - - /* map key is the pair (name_key, location_key) */ - u_char *name_key; /* copy of device name */ - u_char *location_key; - - /* - * Next may be NULL if the respective hrDeviceTblEntry - * is (temporally) gone. - */ - struct device_entry *entry_p; - STAILQ_ENTRY(device_map_entry) link; -}; -STAILQ_HEAD(device_map, device_map_entry); - -/* descriptor to access kernel memory */ -extern kvm_t *hr_kd; - -/* Table used for consistent device table indexing. */ -extern struct device_map device_map; - -/* Maximum number of ticks between two updates for hrStorageTable */ -extern uint32_t storage_tbl_refresh; - -/* Maximum number of ticks between updated of FS table */ -extern uint32_t fs_tbl_refresh; - -/* maximum number of ticks between updates of SWRun and SWRunPerf table */ -extern uint32_t swrun_tbl_refresh; - -/* Maximum number of ticks between device table refreshs. */ -extern uint32_t device_tbl_refresh; - -/* maximum number of ticks between refreshs */ -extern uint32_t disk_storage_tbl_refresh; - -/* maximum number of ticks between updates of network table */ -extern uint32_t swins_tbl_refresh; - -/* maximum number of ticks between updates of network table */ -extern uint32_t network_tbl_refresh; - -/* package directory */ -extern u_char *pkg_dir; - -/* Initialize and populate storage table */ -void init_storage_tbl(void); - -/* Finalization routine for hrStorageTable. */ -void fini_storage_tbl(void); - -/* Refresh routine for hrStorageTable. */ -void refresh_storage_tbl(int); - -/* - * Get the type of filesystem referenced in a struct statfs * - - * used by FSTbl and StorageTbl functions. - */ -const struct asn_oid *fs_get_type(const struct statfs *); - -/* - * Because hrFSTable depends to hrStorageTable we are - * refreshing hrFSTable by refreshing hrStorageTable. - * When one entry "of type" fs from hrStorageTable is refreshed - * then the corresponding entry from hrFSTable is refreshed - * FS_tbl_pre_refresh_v() is called before refeshing fs part of hrStorageTable - */ -void fs_tbl_pre_refresh(void); -void fs_tbl_process_statfs_entry(const struct statfs *, int32_t); - -/* Called after refreshing fs part of hrStorageTable */ -void fs_tbl_post_refresh(void); - -/* Refresh the FS table if neccessary. */ -void refresh_fs_tbl(void); - -/* Finalization routine for hrFSTable. */ -void fini_fs_tbl(void); - -/* Init the things for both of hrSWRunTable and hrSWRunPerfTable */ -void init_swrun_tbl(void); - -/* Finalization routine for both of hrSWRunTable and hrSWRunPerfTable */ -void fini_swrun_tbl(void); - -/* Init and populate hrDeviceTable */ -void init_device_tbl(void); - -/* start devd monitoring */ -void start_device_tbl(struct lmodule *); - -/* Finalization routine for hrDeviceTable */ -void fini_device_tbl(void); - -/* Refresh routine for hrDeviceTable. */ -void refresh_device_tbl(int); - -/* Find an item in hrDeviceTbl by its entry->index. */ -struct device_entry *device_find_by_index(int32_t); - -/* Find an item in hrDeviceTbl by name. */ -struct device_entry *device_find_by_name(const char *); - -/* Create a new entry out of thin air. */ -struct device_entry *device_entry_create(const char *, const char *, - const char *); - -/* Delete an entry from hrDeviceTbl */ -void device_entry_delete(struct device_entry *entry); - -/* Init the things for hrProcessorTable. */ -void init_processor_tbl(void); - -/* Finalization routine for hrProcessorTable. */ -void fini_processor_tbl(void); - -/* Start the processor table CPU load collector. */ -void start_processor_tbl(struct lmodule *); - -/* Init the things for hrDiskStorageTable */ -int init_disk_storage_tbl(void); - -/* Finalization routine for hrDiskStorageTable. */ -void fini_disk_storage_tbl(void); - -/* Refresh routine for hrDiskStorageTable. */ -void refresh_disk_storage_tbl(int); - -/* Finalization routine for hrPartitionTable. */ -void fini_partition_tbl(void); - -/* Finalization routine for hrNetworkTable. */ -void fini_network_tbl(void); - -/* populate network table */ -void start_network_tbl(void); - -/* initialize installed software table */ -void init_swins_tbl(void); - -/* finalize installed software table */ -void fini_swins_tbl(void); - -/* refresh the hrSWInstalledTable if necessary */ -void refresh_swins_tbl(void); - -/* Init the things for hrPrinterTable */ -void init_printer_tbl(void); - -/* Finalization routine for hrPrinterTable. */ -void fini_printer_tbl(void); - -/* Refresh printer table */ -void refresh_printer_tbl(void); - -/* get boot command line */ -int OS_getSystemInitialLoadParameters(u_char **); - -/* Start refreshing the partition table */ -void partition_tbl_post_refresh(void); - -/* Handle refresh for the given disk */ -void partition_tbl_handle_disk(int32_t, const char *); - -/* Finish refreshing the partition table. */ -void partition_tbl_pre_refresh(void); - -/* Set the FS index in a partition table entry */ -void handle_partition_fs_index(const char *, int32_t); - -/* Make an SNMP DateAndTime from a struct tm. */ -int make_date_time(u_char *, const struct tm *, u_int); - -/* Free all static data */ -void fini_scalars(void); - -#endif /* HOSTRES_SNMP_H_1132245017 */ diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c deleted file mode 100644 index 488d9f5..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c +++ /dev/null @@ -1,668 +0,0 @@ -/*- - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * Host Resources MIB for SNMPd. Implementation for hrStorageTable - */ - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include /* for getpagesize() */ -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -/* maximum length for descritpion string according to MIB */ -#define SE_DESC_MLEN (255 + 1) - -/* - * This structure is used to hold a SNMP table entry - * for HOST-RESOURCES-MIB's hrStorageTable - */ -struct storage_entry { - int32_t index; - const struct asn_oid *type; - u_char *descr; - int32_t allocationUnits; - int32_t size; - int32_t used; - uint32_t allocationFailures; -#define HR_STORAGE_FOUND 0x001 - uint32_t flags; /* to be used internally*/ - TAILQ_ENTRY(storage_entry) link; -}; -TAILQ_HEAD(storage_tbl, storage_entry); - -/* - * Next structure is used to keep o list of mappings from a specific name - * (a_name) to an entry in the hrStorageTblEntry. We are trying to keep the - * same index for a specific name at least for the duration of one SNMP agent - * run. - */ -struct storage_map_entry { - int32_t hrIndex; /* used for storage_entry::index */ - - /* map key, also used for storage_entry::descr */ - u_char *a_name; - - /* - * next may be NULL if the respective storage_entry - * is (temporally) gone - */ - struct storage_entry *entry; - STAILQ_ENTRY(storage_map_entry) link; -}; -STAILQ_HEAD(storage_map, storage_map_entry); - -/* the head of the list with table's entries */ -static struct storage_tbl storage_tbl = TAILQ_HEAD_INITIALIZER(storage_tbl); - -/*for consistent table indexing*/ -static struct storage_map storage_map = - STAILQ_HEAD_INITIALIZER(storage_map); - -/* last (agent) tick when hrStorageTable was updated */ -static uint64_t storage_tick; - -/* maximum number of ticks between two refreshs */ -uint32_t storage_tbl_refresh = HR_STORAGE_TBL_REFRESH * 100; - -/* for kvm_getswapinfo, malloc'd */ -static struct kvm_swap *swap_devs; -static size_t swap_devs_len; /* item count for swap_devs */ - -/* for getfsstat, malloc'd */ -static struct statfs *fs_buf; -static size_t fs_buf_count; /* item count for fs_buf */ - -static struct vmtotal mem_stats; - -/* next int available for indexing the hrStorageTable */ -static uint32_t next_storage_index = 1; - -/* start of list for memory detailed stats */ -static struct memory_type_list *mt_list; - -/* Constants */ -static const struct asn_oid OIDX_hrStorageRam_c = OIDX_hrStorageRam; -static const struct asn_oid OIDX_hrStorageVirtualMemory_c = - OIDX_hrStorageVirtualMemory; - -/** - * Create a new entry into the storage table and, if neccessary, an - * entry into the storage map. - */ -static struct storage_entry * -storage_entry_create(const char *name) -{ - struct storage_entry *entry; - struct storage_map_entry *map; - size_t name_len; - - assert(name != NULL); - assert(strlen(name) > 0); - - STAILQ_FOREACH(map, &storage_map, link) - if (strcmp(map->a_name, name) == 0) - break; - - if (map == NULL) { - /* new object - get a new index */ - if (next_storage_index > INT_MAX) { - syslog(LOG_ERR, - "%s: hrStorageTable index wrap", __func__); - errx(EX_SOFTWARE, "hrStorageTable index wrap"); - } - - if ((map = malloc(sizeof(*map))) == NULL) { - syslog(LOG_ERR, "hrStorageTable: %s: %m", __func__ ); - return (NULL); - } - - name_len = strlen(name) + 1; - if (name_len > SE_DESC_MLEN) - name_len = SE_DESC_MLEN; - - if ((map->a_name = malloc(name_len)) == NULL) { - free(map); - return (NULL); - } - - strlcpy(map->a_name, name, name_len); - map->hrIndex = next_storage_index++; - - STAILQ_INSERT_TAIL(&storage_map, map, link); - - HRDBG("%s added into hrStorageMap at index=%d", - name, map->hrIndex); - } else { - HRDBG("%s exists in hrStorageMap index=%d\n", - name, map->hrIndex); - } - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "%s: %m", __func__); - return (NULL); - } - memset(entry, 0, sizeof(*entry)); - - entry->index = map->hrIndex; - - if ((entry->descr = strdup(map->a_name)) == NULL) { - free(entry); - return (NULL); - } - - map->entry = entry; - - INSERT_OBJECT_INT(entry, &storage_tbl); - - return (entry); -} - -/** - * Delete an entry from the storage table. - */ -static void -storage_entry_delete(struct storage_entry *entry) -{ - struct storage_map_entry *map; - - assert(entry != NULL); - - TAILQ_REMOVE(&storage_tbl, entry, link); - STAILQ_FOREACH(map, &storage_map, link) - if (map->entry == entry) { - map->entry = NULL; - break; - } - free(entry->descr); - free(entry); -} - -/** - * Find a table entry by its name. - */ -static struct storage_entry * -storage_find_by_name(const char *name) -{ - struct storage_entry *entry; - - TAILQ_FOREACH(entry, &storage_tbl, link) - if (strcmp(entry->descr, name) == 0) - return (entry); - - return (NULL); -} - -/* - * VM info. - */ -static void -storage_OS_get_vm(void) -{ - int mib[2] = { CTL_VM, VM_TOTAL }; - size_t len = sizeof(mem_stats); - int page_size_bytes; - struct storage_entry *entry; - - if (sysctl(mib, 2, &mem_stats, &len, NULL, 0) < 0) { - syslog(LOG_ERR, - "hrStoragetable: %s: sysctl({CTL_VM, VM_METER}) " - "failed: %m", __func__); - assert(0); - return; - } - - page_size_bytes = getpagesize(); - - /* Real Memory Metrics */ - if ((entry = storage_find_by_name("Real Memory Metrics")) == NULL && - (entry = storage_entry_create("Real Memory Metrics")) == NULL) - return; /* I'm out of luck now, maybe next time */ - - entry->flags |= HR_STORAGE_FOUND; - entry->type = &OIDX_hrStorageRam_c; - entry->allocationUnits = page_size_bytes; - entry->size = mem_stats.t_rm; - entry->used = mem_stats.t_arm; /* ACTIVE is not USED - FIXME */ - entry->allocationFailures = 0; - - /* Shared Real Memory Metrics */ - if ((entry = storage_find_by_name("Shared Real Memory Metrics")) == - NULL && - (entry = storage_entry_create("Shared Real Memory Metrics")) == - NULL) - return; - - entry->flags |= HR_STORAGE_FOUND; - entry->type = &OIDX_hrStorageRam_c; - entry->allocationUnits = page_size_bytes; - entry->size = mem_stats.t_rmshr; - /* ACTIVE is not USED - FIXME */ - entry->used = mem_stats.t_armshr; - entry->allocationFailures = 0; -} - -static void -storage_OS_get_memstat(void) -{ - struct memory_type *mt_item; - struct storage_entry *entry; - - if (mt_list == NULL) { - if ((mt_list = memstat_mtl_alloc()) == NULL) - /* again? we have a serious problem */ - return; - } - - if (memstat_sysctl_all(mt_list, 0) < 0) { - syslog(LOG_ERR, "memstat_sysctl_all failed: %s", - memstat_strerror(memstat_mtl_geterror(mt_list)) ); - return; - } - - if ((mt_item = memstat_mtl_first(mt_list)) == NULL) { - /* usually this is not an error, no errno for this failure*/ - HRDBG("memstat_mtl_first failed"); - return; - } - - do { - const char *memstat_name; - uint64_t tmp_size; - int allocator; - char alloc_descr[SE_DESC_MLEN]; - - memstat_name = memstat_get_name(mt_item); - - if (memstat_name == NULL || strlen(memstat_name) == 0) - continue; - - switch (allocator = memstat_get_allocator(mt_item)) { - - case ALLOCATOR_MALLOC: - snprintf(alloc_descr, sizeof(alloc_descr), - "MALLOC: %s", memstat_name); - break; - - case ALLOCATOR_UMA: - snprintf(alloc_descr, sizeof(alloc_descr), - "UMA: %s", memstat_name); - break; - - default: - snprintf(alloc_descr, sizeof(alloc_descr), - "UNKNOWN%d: %s", allocator, memstat_name); - break; - } - - if ((entry = storage_find_by_name(alloc_descr)) == NULL && - (entry = storage_entry_create(alloc_descr)) == NULL) - return; - - entry->flags |= HR_STORAGE_FOUND; - entry->type = &OIDX_hrStorageRam_c; - - if ((tmp_size = memstat_get_size(mt_item)) == 0) - tmp_size = memstat_get_sizemask(mt_item); - entry->allocationUnits = - (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); - - tmp_size = memstat_get_countlimit(mt_item); - entry->size = - (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); - - tmp_size = memstat_get_count(mt_item); - entry->used = - (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); - - tmp_size = memstat_get_failures(mt_item); - entry->allocationFailures = - (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); - - } while((mt_item = memstat_mtl_next(mt_item)) != NULL); -} - -/** - * Get swap info - */ -static void -storage_OS_get_swap(void) -{ - int nswapdev = 0; - size_t len = sizeof(nswapdev); - struct storage_entry *entry; - char swap_w_prefix[SE_DESC_MLEN]; - - if (sysctlbyname("vm.nswapdev", &nswapdev, &len, NULL,0 ) < 0) { - syslog(LOG_ERR, - "hrStorageTable: sysctlbyname(\"vm.nswapdev\") " - "failed. %m"); - assert(0); - return; - } - - if (nswapdev <= 0) { - HRDBG("vm.nswapdev is %d", nswapdev); - return; - } - - if (nswapdev + 1 != (int)swap_devs_len || swap_devs == NULL) { - swap_devs_len = nswapdev + 1; - swap_devs = reallocf(swap_devs, - swap_devs_len * sizeof(struct kvm_swap)); - - assert(swap_devs != NULL); - if (swap_devs == NULL) { - swap_devs_len = 0; - return; - } - } - - nswapdev = kvm_getswapinfo(hr_kd, swap_devs, swap_devs_len, 0); - if (nswapdev < 0) { - syslog(LOG_ERR, - "hrStorageTable: kvm_getswapinfo failed. %m\n"); - assert(0); - return; - } - - for (len = 0; len < (size_t)nswapdev; len++) { - memset(&swap_w_prefix[0], '\0', sizeof(swap_w_prefix)); - snprintf(swap_w_prefix, sizeof(swap_w_prefix) - 1, - "Swap:%s%s", _PATH_DEV, swap_devs[len].ksw_devname); - - entry = storage_find_by_name(swap_w_prefix); - if (entry == NULL) - entry = storage_entry_create(swap_w_prefix); - - assert (entry != NULL); - if (entry == NULL) - return; /* Out of luck */ - - entry->flags |= HR_STORAGE_FOUND; - entry->type = &OIDX_hrStorageVirtualMemory_c; - entry->allocationUnits = getpagesize(); - entry->size = swap_devs[len].ksw_total; - entry->used = swap_devs[len].ksw_used; - entry->allocationFailures = 0; - } -} - -/** - * Query the underlaying OS for the mounted file systems - * anf fill in the respective lists (for hrStorageTable and for hrFSTable) - */ -static void -storage_OS_get_fs(void) -{ - struct storage_entry *entry; - uint64_t used_blocks_count = 0; - char fs_string[SE_DESC_MLEN]; - int mounted_fs_count; - int i = 0; - - if ((mounted_fs_count = getfsstat(NULL, 0, MNT_NOWAIT)) < 0) { - syslog(LOG_ERR, "hrStorageTable: getfsstat() failed: %m"); - return; /* out of luck this time */ - } - - if (mounted_fs_count != (int)fs_buf_count || fs_buf == NULL) { - fs_buf_count = mounted_fs_count; - fs_buf = reallocf(fs_buf, fs_buf_count * sizeof(struct statfs)); - if (fs_buf == NULL) { - fs_buf_count = 0; - assert(0); - return; - } - } - - if ((mounted_fs_count = getfsstat(fs_buf, - fs_buf_count * sizeof(struct statfs), MNT_NOWAIT)) < 0) { - syslog(LOG_ERR, "hrStorageTable: getfsstat() failed: %m"); - return; /* out of luck this time */ - } - - HRDBG("got %d mounted FS", mounted_fs_count); - - fs_tbl_pre_refresh(); - - for (i = 0; i < mounted_fs_count; i++) { - snprintf(fs_string, sizeof(fs_string), - "%s, type: %s, dev: %s", fs_buf[i].f_mntonname, - fs_buf[i].f_fstypename, fs_buf[i].f_mntfromname); - - entry = storage_find_by_name(fs_string); - if (entry == NULL) - entry = storage_entry_create(fs_string); - - assert (entry != NULL); - if (entry == NULL) - return; /* Out of luck */ - - entry->flags |= HR_STORAGE_FOUND; - entry->type = fs_get_type(&fs_buf[i]); /*XXX - This is wrong*/ - - if (fs_buf[i].f_bsize > INT_MAX) - entry->allocationUnits = INT_MAX; - else - entry->allocationUnits = fs_buf[i].f_bsize; - - if (fs_buf[i].f_blocks > INT_MAX) - entry->size = INT_MAX; - else - entry->size = fs_buf[i].f_blocks; - - used_blocks_count = fs_buf[i].f_blocks - fs_buf[i].f_bfree; - - if (used_blocks_count > INT_MAX) - entry->used = INT_MAX; - else - entry->used = used_blocks_count; - - entry->allocationFailures = 0; - - /* take care of hrFSTable */ - fs_tbl_process_statfs_entry(&fs_buf[i], entry->index); - } - - fs_tbl_post_refresh(); -} - -/** - * Initialize storage table and populate it. - */ -void -init_storage_tbl(void) -{ - if ((mt_list = memstat_mtl_alloc()) == NULL) - syslog(LOG_ERR, - "hrStorageTable: memstat_mtl_alloc() failed: %m"); - - refresh_storage_tbl(1); -} - -void -fini_storage_tbl(void) -{ - struct storage_map_entry *n1; - - if (swap_devs != NULL) { - free(swap_devs); - swap_devs = NULL; - } - swap_devs_len = 0; - - if (fs_buf != NULL) { - free(fs_buf); - fs_buf = NULL; - } - fs_buf_count = 0; - - while ((n1 = STAILQ_FIRST(&storage_map)) != NULL) { - STAILQ_REMOVE_HEAD(&storage_map, link); - if (n1->entry != NULL) { - TAILQ_REMOVE(&storage_tbl, n1->entry, link); - free(n1->entry->descr); - free(n1->entry); - } - free(n1->a_name); - free(n1); - } - assert(TAILQ_EMPTY(&storage_tbl)); -} - -void -refresh_storage_tbl(int force) -{ - struct storage_entry *entry, *entry_tmp; - - if (!force && storage_tick != 0 && - this_tick - storage_tick < storage_tbl_refresh) { - HRDBG("no refresh needed"); - return; - } - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &storage_tbl, link) - entry->flags &= ~HR_STORAGE_FOUND; - - storage_OS_get_vm(); - storage_OS_get_swap(); - storage_OS_get_fs(); - storage_OS_get_memstat(); - - /* - * Purge items that disappeared - */ - TAILQ_FOREACH_SAFE(entry, &storage_tbl, link, entry_tmp) - if (!(entry->flags & HR_STORAGE_FOUND)) - storage_entry_delete(entry); - - storage_tick = this_tick; - - HRDBG("refresh DONE"); -} - -/* - * This is the implementation for a generated (by our SNMP tool) - * function prototype, see hostres_tree.h - * It handles the SNMP operations for hrStorageTable - */ -int -op_hrStorageTable(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - struct storage_entry *entry; - - refresh_storage_tbl(0); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&storage_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&storage_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&storage_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrStorageIndex: - value->v.integer = entry->index; - return (SNMP_ERR_NOERROR); - - case LEAF_hrStorageType: - assert(entry->type != NULL); - value->v.oid = *entry->type; - return (SNMP_ERR_NOERROR); - - case LEAF_hrStorageDescr: - assert(entry->descr != NULL); - return (string_get(value, entry->descr, -1)); - break; - - case LEAF_hrStorageAllocationUnits: - value->v.integer = entry->allocationUnits; - return (SNMP_ERR_NOERROR); - - case LEAF_hrStorageSize: - value->v.integer = entry->size; - return (SNMP_ERR_NOERROR); - - case LEAF_hrStorageUsed: - value->v.integer = entry->used; - return (SNMP_ERR_NOERROR); - - case LEAF_hrStorageAllocationFailures: - value->v.uint32 = entry->allocationFailures; - return (SNMP_ERR_NOERROR); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c deleted file mode 100644 index 5fa5b4c..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swinstalled_tbl.c +++ /dev/null @@ -1,555 +0,0 @@ -/* - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - * - * Host Resources MIB implementation for SNMPd: instrumentation for - * hrSWInstalledTable - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -#define CONTENTS_FNAME "+CONTENTS" - -enum SWInstalledType { - SWI_UNKNOWN = 1, - SWI_OPERATING_SYSTEM = 2, - SWI_DEVICE_DRIVER = 3, - SWI_APPLICATION = 4 -}; - -#define SW_NAME_MLEN (64 + 1) - -/* - * This structure is used to hold a SNMP table entry - * for HOST-RESOURCES-MIB's hrSWInstalledTable - */ -struct swins_entry { - int32_t index; - u_char *name; /* max len for this is SW_NAME_MLEN */ - const struct asn_oid *id; - int32_t type; /* from enum SWInstalledType */ - u_char date[11]; - u_int date_len; - -#define HR_SWINSTALLED_FOUND 0x001 -#define HR_SWINSTALLED_IMMUTABLE 0x002 - uint32_t flags; - - TAILQ_ENTRY(swins_entry) link; -}; -TAILQ_HEAD(swins_tbl, swins_entry); - -/* - * Table to keep a conistent mapping between software and indexes. - */ -struct swins_map_entry { - int32_t index; /* swins_entry::index */ - u_char *name; /* map key,a copy of swins_entry::name*/ - - /* - * next may be NULL if the respective hrSWInstalledTblEntry - * is (temporally) gone - */ - struct swins_entry *entry; - - STAILQ_ENTRY(swins_map_entry) link; -}; -STAILQ_HEAD(swins_map, swins_map_entry); - -/* map for consistent indexing */ -static struct swins_map swins_map = STAILQ_HEAD_INITIALIZER(swins_map); - -/* the head of the list with hrSWInstalledTable's entries */ -static struct swins_tbl swins_tbl = TAILQ_HEAD_INITIALIZER(swins_tbl); - -/* next int available for indexing the hrSWInstalledTable */ -static uint32_t next_swins_index = 1; - -/* last (agent) tick when hrSWInstalledTable was updated */ -static uint64_t swins_tick; - -/* maximum number of ticks between updates of network table */ -uint32_t swins_tbl_refresh = HR_SWINS_TBL_REFRESH * 100; - -/* package directory */ -u_char *pkg_dir; - -/* last change of package list */ -static time_t os_pkg_last_change; - -/** - * Create a new entry into the hrSWInstalledTable - */ -static struct swins_entry * -swins_entry_create(const char *name) -{ - struct swins_entry *entry; - struct swins_map_entry *map; - - STAILQ_FOREACH(map, &swins_map, link) - if (strcmp((const char *)map->name, name) == 0) - break; - - if (map == NULL) { - size_t name_len; - /* new object - get a new index */ - if (next_swins_index > INT_MAX) { - syslog(LOG_ERR, "%s: hrSWInstalledTable index wrap", - __func__ ); - /* There isn't much we can do here. - * If the next_swins_index is consumed - * then we can't add entries to this table - * So it is better to exit - if the table is sparsed - * at the next agent run we can fill it fully. - */ - errx(EX_SOFTWARE, "hrSWInstalledTable index wrap"); - } - - if ((map = malloc(sizeof(*map))) == NULL) { - syslog(LOG_ERR, "%s: %m", __func__ ); - return (NULL); - } - - name_len = strlen(name) + 1; - if (name_len > SW_NAME_MLEN) - name_len = SW_NAME_MLEN; - - if ((map->name = malloc(name_len)) == NULL) { - syslog(LOG_WARNING, "%s: %m", __func__); - free(map); - return (NULL); - } - - map->index = next_swins_index++; - strlcpy((char *)map->name, name, name_len); - - STAILQ_INSERT_TAIL(&swins_map, map, link); - - HRDBG("%s added into hrSWInstalled at %d", name, map->index); - } - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "%s: %m", __func__); - return (NULL); - } - memset(entry, 0, sizeof(*entry)); - - if ((entry->name = strdup(map->name)) == NULL) { - syslog(LOG_WARNING, "%s: %m", __func__); - free(entry); - return (NULL); - } - - entry->index = map->index; - map->entry = entry; - - INSERT_OBJECT_INT(entry, &swins_tbl); - - return (entry); -} - -/** - * Delete an entry in the hrSWInstalledTable - */ -static void -swins_entry_delete(struct swins_entry *entry) -{ - struct swins_map_entry *map; - - assert(entry != NULL); - - TAILQ_REMOVE(&swins_tbl, entry, link); - - STAILQ_FOREACH(map, &swins_map, link) - if (map->entry == entry) { - map->entry = NULL; - break; - } - - free(entry->name); - free(entry); -} - -/** - * Find an entry given it's name - */ -static struct swins_entry * -swins_find_by_name(const char *name) -{ - struct swins_entry *entry; - - TAILQ_FOREACH(entry, &swins_tbl, link) - if (strcmp((const char*)entry->name, name) == 0) - return (entry); - return (NULL); -} - -/** - * Finalize this table - */ -void -fini_swins_tbl(void) -{ - struct swins_map_entry *n1; - - while ((n1 = STAILQ_FIRST(&swins_map)) != NULL) { - STAILQ_REMOVE_HEAD(&swins_map, link); - if (n1->entry != NULL) { - TAILQ_REMOVE(&swins_tbl, n1->entry, link); - free(n1->entry->name); - free(n1->entry); - } - free(n1->name); - free(n1); - } - assert(TAILQ_EMPTY(&swins_tbl)); -} - -/** - * Get the *running* O/S identification - */ -static void -swins_get_OS_ident(void) -{ - struct utsname os_id; - char os_string[SW_NAME_MLEN] = ""; - struct swins_entry *entry; - u_char *boot; - struct stat sb; - struct tm k_ts; - - if (uname(&os_id) == -1) { - syslog(LOG_WARNING, "%s: %m", __func__); - return; - } - - snprintf(os_string, sizeof(os_string), "%s: %s", - os_id.sysname, os_id.version); - - if ((entry = swins_find_by_name(os_string)) != NULL || - (entry = swins_entry_create(os_string)) == NULL) - return; - - entry->flags |= (HR_SWINSTALLED_FOUND | HR_SWINSTALLED_IMMUTABLE); - entry->id = &oid_zeroDotZero; - entry->type = (int32_t)SWI_OPERATING_SYSTEM; - memset(entry->date, 0, sizeof(entry->date)); - - if (OS_getSystemInitialLoadParameters(&boot) == SNMP_ERR_NOERROR && - strlen(boot) > 0 && stat(boot, &sb) == 0 && - localtime_r(&sb.st_ctime, &k_ts) != NULL) - entry->date_len = make_date_time(entry->date, &k_ts, 0); -} - -/** - * Read the installed packages - */ -static int -swins_get_packages(void) -{ - struct stat sb; - DIR *p_dir; - struct dirent *ent; - struct tm k_ts; - char *pkg_file; - struct swins_entry *entry; - int ret = 0; - - if (pkg_dir == NULL) - /* initialisation may have failed */ - return (-1); - - if (stat(pkg_dir, &sb) != 0) { - syslog(LOG_ERR, "hrSWInstalledTable: stat(\"%s\") failed: %m", - pkg_dir); - return (-1); - } - if (!S_ISDIR(sb.st_mode)) { - syslog(LOG_ERR, "hrSWInstalledTable: \"%s\" is not a directory", - pkg_dir); - return (-1); - } - if (sb.st_ctime <= os_pkg_last_change) { - HRDBG("no need to rescan installed packages -- " - "directory time-stamp unmodified"); - - TAILQ_FOREACH(entry, &swins_tbl, link) - entry->flags |= HR_SWINSTALLED_FOUND; - - return (0); - } - - if ((p_dir = opendir(pkg_dir)) == NULL) { - syslog(LOG_ERR, "hrSWInstalledTable: opendir(\"%s\") failed: " - "%m", pkg_dir); - return (-1); - } - - while (errno = 0, (ent = readdir(p_dir)) != NULL) { - HRDBG(" pkg file: %s", ent->d_name); - - /* check that the contents file is a regular file */ - if (asprintf(&pkg_file, "%s/%s/%s", pkg_dir, ent->d_name, - CONTENTS_FNAME) == -1) - continue; - - if (stat(pkg_file, &sb) != 0 ) { - free(pkg_file); - continue; - } - - if (!S_ISREG(sb.st_mode)) { - syslog(LOG_ERR, "hrSWInstalledTable: \"%s\" not a " - "regular file -- skipped", pkg_file); - free(pkg_file); - continue; - } - free(pkg_file); - - /* read directory timestamp on package */ - if (asprintf(&pkg_file, "%s/%s", pkg_dir, ent->d_name) == -1) - continue; - - if (stat(pkg_file, &sb) == -1 || - localtime_r(&sb.st_ctime, &k_ts) == NULL) { - free(pkg_file); - continue; - } - free(pkg_file); - - /* update or create entry */ - if ((entry = swins_find_by_name(ent->d_name)) == NULL && - (entry = swins_entry_create(ent->d_name)) == NULL) { - ret = -1; - goto PKG_LOOP_END; - } - - entry->flags |= HR_SWINSTALLED_FOUND; - entry->id = &oid_zeroDotZero; - entry->type = (int32_t)SWI_APPLICATION; - - entry->date_len = make_date_time(entry->date, &k_ts, 0); - } - - if (errno != 0) { - syslog(LOG_ERR, "hrSWInstalledTable: readdir_r(\"%s\") failed:" - " %m", pkg_dir); - ret = -1; - } else { - /* - * save the timestamp of directory - * to avoid any further scanning - */ - os_pkg_last_change = sb.st_ctime; - } - PKG_LOOP_END: - (void)closedir(p_dir); - return (ret); -} - -/** - * Refresh the installed software table. - */ -void -refresh_swins_tbl(void) -{ - int ret; - struct swins_entry *entry, *entry_tmp; - - if (this_tick - swins_tick < swins_tbl_refresh) { - HRDBG("no refresh needed"); - return; - } - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &swins_tbl, link) - entry->flags &= ~HR_SWINSTALLED_FOUND; - - ret = swins_get_packages(); - - TAILQ_FOREACH_SAFE(entry, &swins_tbl, link, entry_tmp) - if (!(entry->flags & HR_SWINSTALLED_FOUND) && - !(entry->flags & HR_SWINSTALLED_IMMUTABLE)) - swins_entry_delete(entry); - - if (ret == 0) - swins_tick = this_tick; -} - -/** - * Create and populate the package table - */ -void -init_swins_tbl(void) -{ - - if ((pkg_dir = malloc(sizeof(PATH_PKGDIR))) == NULL) - syslog(LOG_ERR, "%s: %m", __func__); - else - strcpy(pkg_dir, PATH_PKGDIR); - - swins_get_OS_ident(); - refresh_swins_tbl(); - - HRDBG("init done"); -} - -/** - * SNMP handler - */ -int -op_hrSWInstalledTable(struct snmp_context *ctx __unused, - struct snmp_value *value, u_int sub, u_int iidx __unused, - enum snmp_op curr_op) -{ - struct swins_entry *entry; - - refresh_swins_tbl(); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&swins_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&swins_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&swins_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSWInstalledIndex: - value->v.integer = entry->index; - return (SNMP_ERR_NOERROR); - - case LEAF_hrSWInstalledName: - return (string_get(value, entry->name, -1)); - break; - - case LEAF_hrSWInstalledID: - assert(entry->id != NULL); - value->v.oid = *entry->id; - return (SNMP_ERR_NOERROR); - - case LEAF_hrSWInstalledType: - value->v.integer = entry->type; - return (SNMP_ERR_NOERROR); - - case LEAF_hrSWInstalledDate: - return (string_get(value, entry->date, entry->date_len)); - } - abort(); -} - -/** - * Scalars - */ -int -op_hrSWInstalled(struct snmp_context *ctx __unused, - struct snmp_value *value __unused, u_int sub, - u_int iidx __unused, enum snmp_op curr_op) -{ - - /* only SNMP GET is possible */ - switch (curr_op) { - - case SNMP_OP_GET: - goto get; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - case SNMP_OP_GETNEXT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSWInstalledLastChange: - case LEAF_hrSWInstalledLastUpdateTime: - /* - * We always update the entire table so these two tick - * values should be equal. - */ - refresh_swins_tbl(); - if (swins_tick <= start_tick) - value->v.uint32 = 0; - else { - uint64_t lastChange = swins_tick - start_tick; - - /* may overflow the SNMP type */ - value->v.uint32 = - (lastChange > UINT_MAX ? UINT_MAX : lastChange); - } - - return (SNMP_ERR_NOERROR); - - default: - abort(); - } -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c deleted file mode 100644 index 1f82648..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c +++ /dev/null @@ -1,792 +0,0 @@ -/* - * Copyright (c) 2005-2006 The FreeBSD Project - * All rights reserved. - * - * Author: Victor Cruceru - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - * - * Host Resources MIB for SNMPd. Implementation for hrSWRunTable - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "hostres_snmp.h" -#include "hostres_oid.h" -#include "hostres_tree.h" - -/* - * Ugly thing: PID_MAX, NO_PID defined only in kernel - */ -#define NO_PID 100000 - -enum SWRunType { - SRT_UNKNOWN = 1, - SRT_OPERATING_SYSTEM = 2, - SRT_DEVICE_DRIVER = 3, - SRT_APPLICATION = 4 - -}; - -enum SWRunStatus { - SRS_RUNNING = 1, - SRS_RUNNABLE = 2, - SRS_NOT_RUNNABLE = 3, - SRS_INVALID = 4 -}; - -/* Maximum lengths for the strings according to the MIB */ -#define SWR_NAME_MLEN (64 + 1) -#define SWR_PATH_MLEN (128 + 1) -#define SWR_PARAM_MLEN (128 + 1) - -/* - * This structure is used to hold a SNMP table entry - * for both hrSWRunTable and hrSWRunPerfTable because - * hrSWRunPerfTable AUGMENTS hrSWRunTable - */ -struct swrun_entry { - int32_t index; - u_char *name; /* it may be NULL */ - const struct asn_oid *id; - u_char *path; /* it may be NULL */ - u_char *parameters; /* it may be NULL */ - int32_t type; /* enum SWRunType */ - int32_t status; /* enum SWRunStatus */ - int32_t perfCPU; - int32_t perfMemory; -#define HR_SWRUN_FOUND 0x001 - uint32_t flags; - uint64_t r_tick; /* tick when entry refreshed */ - TAILQ_ENTRY(swrun_entry) link; -}; -TAILQ_HEAD(swrun_tbl, swrun_entry); - -/* the head of the list with hrSWRunTable's entries */ -static struct swrun_tbl swrun_tbl = TAILQ_HEAD_INITIALIZER(swrun_tbl); - -/* last (agent) tick when hrSWRunTable and hrSWRunPerTable was updated */ -static uint64_t swrun_tick; - -/* maximum number of ticks between updates of SWRun and SWRunPerf table */ -uint32_t swrun_tbl_refresh = HR_SWRUN_TBL_REFRESH * 100; - -/* the value of the MIB object with the same name */ -static int32_t SWOSIndex; - -/** - * Malloc a new entry and add it to the list - * associated to this table. The item identified by - * the index parameter must not exist in this list. - */ -static struct swrun_entry * -swrun_entry_create(int32_t idx) -{ - struct swrun_entry *entry; - - if ((entry = malloc(sizeof(*entry))) == NULL) { - syslog(LOG_WARNING, "%s: %m", __func__); - return (NULL); - } - memset(entry, 0, sizeof(*entry)); - entry->index = idx; - - INSERT_OBJECT_INT(entry, &swrun_tbl); - return (entry); -} - -/** - * Unlink the entry from the list and then free its heap memory - */ -static void -swrun_entry_delete(struct swrun_entry *entry) -{ - - assert(entry != NULL); - - TAILQ_REMOVE(&swrun_tbl, entry, link); - - free(entry->name); - free(entry->path); - free(entry->parameters); - free(entry); -} - -/** - * Search one item by its index, return NULL if none found - */ -static struct swrun_entry * -swrun_entry_find_by_index(int32_t idx) -{ - struct swrun_entry *entry; - - TAILQ_FOREACH(entry, &swrun_tbl, link) - if (entry->index == idx) - return (entry); - return (NULL); -} - -/** - * Translate the kernel's process status to SNMP. - */ -static enum SWRunStatus -swrun_OS_get_proc_status(const struct kinfo_proc *kp) -{ - - assert(kp != NULL); - if(kp == NULL) { - return (SRS_INVALID); - } - - /* - * I'm using the old style flags - they look cleaner to me, - * at least for the purpose of this SNMP table - */ - switch (kp->ki_stat) { - - case SSTOP: - return (SRS_NOT_RUNNABLE); - - case SWAIT: - case SLOCK: - case SSLEEP: - return (SRS_RUNNABLE); - - case SZOMB: - return (SRS_INVALID); - - case SIDL: - case SRUN: - return (SRS_RUNNING); - - default: - syslog(LOG_ERR,"Unknown process state: %d", kp->ki_stat); - return (SRS_INVALID); - } -} - -/** - * Make an SNMP table entry from a kernel one. - */ -static void -kinfo_proc_to_swrun_entry(const struct kinfo_proc *kp, - struct swrun_entry *entry) -{ - char **argv = NULL; - uint64_t cpu_time = 0; - size_t pname_len; - - pname_len = strlen(kp->ki_comm) + 1; - entry->name = reallocf(entry->name, pname_len); - if (entry->name != NULL) - strlcpy(entry->name, kp->ki_comm, pname_len); - - entry->id = &oid_zeroDotZero; /* unknown id - FIXME */ - - assert(hr_kd != NULL); - - argv = kvm_getargv(hr_kd, kp, SWR_PARAM_MLEN - 1); - if(argv != NULL){ - u_char param[SWR_PARAM_MLEN]; - - memset(param, '\0', sizeof(param)); - - /* - * FIXME - * Path seems to not be available. - * Try to hack the info in argv[0]; - * this argv is under control of the program so this info - * is not realiable - */ - if(*argv != NULL && (*argv)[0] == '/') { - size_t path_len; - - path_len = strlen(*argv) + 1; - if (path_len > SWR_PATH_MLEN) - path_len = SWR_PATH_MLEN; - - entry->path = reallocf(entry->path, path_len); - if (entry->path != NULL) { - memset(entry->path, '\0', path_len); - strlcpy((char*)entry->path, *argv, path_len); - } - } - - argv++; /* skip the first one which was used for path */ - - while (argv != NULL && *argv != NULL ) { - if (param[0] != 0) { - /* - * add a space between parameters, - * except before the first one - */ - strlcat((char *)param, " ", sizeof(param)); - } - strlcat((char *)param, *argv, sizeof(param)); - argv++; - } - /* reuse pname_len */ - pname_len = strlen(param) + 1; - if (pname_len > SWR_PARAM_MLEN) - pname_len = SWR_PARAM_MLEN; - - entry->parameters = reallocf(entry->parameters, pname_len); - strlcpy(entry->parameters, param, pname_len); - } - - entry->type = (int32_t)(IS_KERNPROC(kp) ? SRT_OPERATING_SYSTEM : - SRT_APPLICATION); - - entry->status = (int32_t)swrun_OS_get_proc_status(kp); - cpu_time = kp->ki_runtime / 100000; /* centi-seconds */ - - /* may overflow the snmp type */ - entry->perfCPU = (cpu_time > (uint64_t)INT_MAX ? INT_MAX : cpu_time); - entry->perfMemory = kp->ki_size / 1024; /* in kilo-bytes */ - entry->r_tick = get_ticks(); -} - -/** - * Create a table entry for a KLD - */ -static void -kld_file_stat_to_swrun(const struct kld_file_stat *kfs, - struct swrun_entry *entry) -{ - size_t name_len; - - assert(kfs != NULL); - assert(entry != NULL); - - name_len = strlen(kfs->name) + 1; - if (name_len > SWR_NAME_MLEN) - name_len = SWR_NAME_MLEN; - - entry->name = reallocf(entry->name, name_len); - if (entry->name != NULL) - strlcpy((char *)entry->name, kfs->name, name_len); - - /* FIXME: can we find the location where the module was loaded from? */ - entry->path = NULL; - - /* no parameters for kernel files (.ko) of for the kernel */ - entry->parameters = NULL; - - entry->id = &oid_zeroDotZero; /* unknown id - FIXME */ - - if (strcmp(kfs->name, "kernel") == 0) { - entry->type = (int32_t)SRT_OPERATING_SYSTEM; - SWOSIndex = entry->index; - } else { - entry->type = (int32_t)SRT_DEVICE_DRIVER; /* well, not really */ - } - entry->status = (int32_t)SRS_RUNNING; - entry->perfCPU = 0; /* Info not available */ - entry->perfMemory = kfs->size / 1024; /* in kilo-bytes */ - entry->r_tick = get_ticks(); -} - -/** - * Get all visible proceses including the kernel visible threads - */ -static void -swrun_OS_get_procs(void) -{ - struct kinfo_proc *plist, *kp; - int i; - int nproc; - struct swrun_entry *entry; - - plist = kvm_getprocs(hr_kd, KERN_PROC_ALL, 0, &nproc); - if (plist == NULL || nproc < 0) { - syslog(LOG_ERR, "kvm_getprocs() failed: %m"); - return; - } - for (i = 0, kp = plist; i < nproc; i++, kp++) { - /* - * The SNMP table's index must begin from 1 (as specified by - * this table definition), the PIDs are starting from 0 - * so we are translating the PIDs to +1 - */ - entry = swrun_entry_find_by_index((int32_t)kp->ki_pid + 1); - if (entry == NULL) { - /* new entry - get memory for it */ - entry = swrun_entry_create((int32_t)kp->ki_pid + 1); - if (entry == NULL) - continue; - } - entry->flags |= HR_SWRUN_FOUND; /* mark it as found */ - - kinfo_proc_to_swrun_entry(kp, entry); - } -} - -/* - * Get kernel items: first the kernel itself, then the loaded modules. - */ -static void -swrun_OS_get_kinfo(void) -{ - int fileid; - struct swrun_entry *entry; - struct kld_file_stat stat; - - for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { - stat.version = sizeof(struct kld_file_stat); - if (kldstat(fileid, &stat) < 0) { - syslog(LOG_ERR, "kldstat() failed: %m"); - continue; - } - - /* - * kernel and kernel files (*.ko) will be indexed starting with - * NO_PID + 1; NO_PID is PID_MAX + 1 thus it will be no risk to - * overlap with real PIDs which are in range of 1 .. NO_PID - */ - entry = swrun_entry_find_by_index(NO_PID + 1 + stat.id); - if (entry == NULL) { - /* new entry - get memory for it */ - entry = swrun_entry_create(NO_PID + 1 + stat.id); - if (entry == NULL) - continue; - } - entry->flags |= HR_SWRUN_FOUND; /* mark it as found */ - - kld_file_stat_to_swrun(&stat, entry); - } -} - -/** - * Refresh the hrSWRun and hrSWRunPert tables. - */ -static void -refresh_swrun_tbl(void) -{ - - struct swrun_entry *entry, *entry_tmp; - - if (this_tick - swrun_tick < swrun_tbl_refresh) { - HRDBG("no refresh needed "); - return; - } - - /* mark each entry as missing */ - TAILQ_FOREACH(entry, &swrun_tbl, link) - entry->flags &= ~HR_SWRUN_FOUND; - - swrun_OS_get_procs(); - swrun_OS_get_kinfo(); - - /* - * Purge items that disappeared - */ - TAILQ_FOREACH_SAFE(entry, &swrun_tbl, link, entry_tmp) - if (!(entry->flags & HR_SWRUN_FOUND)) - swrun_entry_delete(entry); - - swrun_tick = this_tick; - - HRDBG("refresh DONE"); -} - -/** - * Update the information in this entry - */ -static void -fetch_swrun_entry(struct swrun_entry *entry) -{ - struct kinfo_proc *plist; - int nproc; - struct kld_file_stat stat; - - assert(entry != NULL); - - if (entry->index >= NO_PID + 1) { - /* - * kernel and kernel files (*.ko) will be indexed - * starting with NO_PID + 1; NO_PID is PID_MAX + 1 - * thus it will be no risk to overlap with real PIDs - * which are in range of 1 .. NO_PID - */ - stat.version = sizeof(stat); - if (kldstat(entry->index - NO_PID - 1, &stat) == -1) { - /* - * not found, it's gone. Mark it as invalid for now, it - * will be removed from the list at next global refersh - */ - HRDBG("missing item with kid=%d", - entry->index - NO_PID - 1); - entry->status = (int32_t)SRS_INVALID; - } else - kld_file_stat_to_swrun(&stat, entry); - - } else { - /* this is a process */ - assert(hr_kd != NULL); - plist = kvm_getprocs(hr_kd, KERN_PROC_PID, - entry->index - 1, &nproc); - if (plist == NULL || nproc != 1) { - HRDBG("missing item with PID=%d", entry->index - 1); - entry->status = (int32_t)SRS_INVALID; - } else - kinfo_proc_to_swrun_entry(plist, entry); - } -} - -/** - * Invalidate entry. For KLDs we try to unload it, for processes we SIGKILL it. - */ -static int -invalidate_swrun_entry(struct swrun_entry *entry, int commit) -{ - struct kinfo_proc *plist; - int nproc; - struct kld_file_stat stat; - - assert(entry != NULL); - - if (entry->index >= NO_PID + 1) { - /* this is a kernel item */ - HRDBG("atempt to unload KLD %d", - entry->index - NO_PID - 1); - - if (entry->index == SWOSIndex) { - /* can't invalidate the kernel itself */ - return (SNMP_ERR_NOT_WRITEABLE); - } - - stat.version = sizeof(stat); - if (kldstat(entry->index - NO_PID - 1, &stat) == -1) { - /* - * not found, it's gone. Mark it as invalid for now, it - * will be removed from the list at next global - * refresh - */ - HRDBG("missing item with kid=%d", - entry->index - NO_PID - 1); - entry->status = (int32_t)SRS_INVALID; - return (SNMP_ERR_NOERROR); - } - /* - * There is no way to try to unload a module. There seems - * also no way to find out whether it is busy without unloading - * it. We can assume that it is busy, if the reference count - * is larger than 2, but if it is 1 nothing helps. - */ - if (!commit) { - if (stat.refs > 1) - return (SNMP_ERR_NOT_WRITEABLE); - return (SNMP_ERR_NOERROR); - } - if (kldunload(stat.id) == -1) { - syslog(LOG_ERR,"kldunload for %d/%s failed: %m", - stat.id, stat.name); - if (errno == EBUSY) - return (SNMP_ERR_NOT_WRITEABLE); - else - return (SNMP_ERR_RES_UNAVAIL); - } - } else { - /* this is a process */ - assert(hr_kd != NULL); - - plist = kvm_getprocs(hr_kd, KERN_PROC_PID, - entry->index - 1, &nproc); - if (plist == NULL || nproc != 1) { - HRDBG("missing item with PID=%d", entry->index - 1); - entry->status = (int32_t)SRS_INVALID; - return (SNMP_ERR_NOERROR); - } - if (IS_KERNPROC(plist)) { - /* you don't want to do this */ - return (SNMP_ERR_NOT_WRITEABLE); - } - if (kill(entry->index - 1, commit ? SIGKILL : 0) < 0) { - syslog(LOG_ERR,"kill (%d, SIGKILL) failed: %m", - entry->index - 1); - if (errno == ESRCH) { - /* race: just gone */ - entry->status = (int32_t)SRS_INVALID; - return (SNMP_ERR_NOERROR); - } - return (SNMP_ERR_GENERR); - } - } - return (SNMP_ERR_NOERROR); -} - -/** - * Popuplate the hrSWRunTable. - */ -void -init_swrun_tbl(void) -{ - - refresh_swrun_tbl(); - HRDBG("done"); -} - -/** - * Finalize the hrSWRunTable. - */ -void -fini_swrun_tbl(void) -{ - struct swrun_entry *n1; - - while ((n1 = TAILQ_FIRST(&swrun_tbl)) != NULL) { - TAILQ_REMOVE(&swrun_tbl, n1, link); - free(n1); - } -} - -/* - * This is the implementation for a generated (by a SNMP tool) - * function prototype, see hostres_tree.h - * It hanldes the SNMP operations for hrSWRunTable - */ -int -op_hrSWRunTable(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - struct swrun_entry *entry; - int ret; - - refresh_swrun_tbl(); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&swrun_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&swrun_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&swrun_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - - if (entry->r_tick < this_tick) - fetch_swrun_entry(entry); - - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSWRunStatus: - if (value->v.integer != (int32_t)SRS_INVALID) - return (SNMP_ERR_WRONG_VALUE); - - if (entry->status == (int32_t)SRS_INVALID) - return (SNMP_ERR_NOERROR); - - /* - * Here we have a problem with the entire SNMP - * model: if we kill now, we cannot rollback. - * If we kill in the commit code, we cannot - * return an error. Because things may change between - * SET and COMMIT this is impossible to handle - * correctly. - */ - return (invalidate_swrun_entry(entry, 0)); - } - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - if ((entry = FIND_OBJECT_INT(&swrun_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOERROR); - - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSWRunStatus: - if (value->v.integer == (int32_t)SRS_INVALID && - entry->status != (int32_t)SRS_INVALID) - (void)invalidate_swrun_entry(entry, 1); - return (SNMP_ERR_NOERROR); - } - abort(); - } - abort(); - - get: - ret = SNMP_ERR_NOERROR; - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSWRunIndex: - value->v.integer = entry->index; - break; - - case LEAF_hrSWRunName: - if (entry->name != NULL) - ret = string_get(value, entry->name, -1); - else - ret = string_get(value, "", -1); - break; - - case LEAF_hrSWRunID: - assert(entry->id != NULL); - value->v.oid = *entry->id; - break; - - case LEAF_hrSWRunPath: - if (entry->path != NULL) - ret = string_get(value, entry->path, -1); - else - ret = string_get(value, "", -1); - break; - - case LEAF_hrSWRunParameters: - if (entry->parameters != NULL) - ret = string_get(value, entry->parameters, -1); - else - ret = string_get(value, "", -1); - break; - - case LEAF_hrSWRunType: - value->v.integer = entry->type; - break; - - case LEAF_hrSWRunStatus: - value->v.integer = entry->status; - break; - - default: - abort(); - } - return (ret); -} - -/** - * Scalar(s) in the SWRun group - */ -int -op_hrSWRun(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op curr_op) -{ - - /* only SNMP GET is possible */ - switch (curr_op) { - - case SNMP_OP_GET: - goto get; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - case SNMP_OP_GETNEXT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSWOSIndex: - value->v.uint32 = SWOSIndex; - return (SNMP_ERR_NOERROR); - - default: - abort(); - } -} - -/* - * This is the implementation for a generated (by a SNMP tool) - * function prototype, see hostres_tree.h - * It handles the SNMP operations for hrSWRunPerfTable - */ -int -op_hrSWRunPerfTable(struct snmp_context *ctx __unused, - struct snmp_value *value, u_int sub, u_int iidx __unused, - enum snmp_op curr_op ) -{ - struct swrun_entry *entry; - - refresh_swrun_tbl(); - - switch (curr_op) { - - case SNMP_OP_GETNEXT: - if ((entry = NEXT_OBJECT_INT(&swrun_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = entry->index; - goto get; - - case SNMP_OP_GET: - if ((entry = FIND_OBJECT_INT(&swrun_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get; - - case SNMP_OP_SET: - if ((entry = FIND_OBJECT_INT(&swrun_tbl, - &value->var, sub)) == NULL) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); - - get: - switch (value->var.subs[sub - 1]) { - - case LEAF_hrSWRunPerfCPU: - value->v.integer = entry->perfCPU; - return (SNMP_ERR_NOERROR); - - case LEAF_hrSWRunPerfMem: - value->v.integer = entry->perfMemory; - return (SNMP_ERR_NOERROR); - } - abort(); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_tree.def b/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_tree.def deleted file mode 100644 index e92d903..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_tree.def +++ /dev/null @@ -1,292 +0,0 @@ -# -# Copyright (c) 2005-2006 The FreeBSD Project -# All rights reserved. -# -# Author: Victor Cruceru -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ -# -# This is the .def file for both HOST-RESOURCES-MIB and HOST-RESOURCES-TYPES -# - -(1 internet - (2 mgmt - (1 mib_2 - (25 host - (1 hrSystem - (1 hrSystemUptime TIMETICKS op_hrSystem GET) - (2 hrSystemDate OCTETSTRING op_hrSystem GET SET) - (3 hrSystemInitialLoadDevice INTEGER op_hrSystem GET SET) - (4 hrSystemInitialLoadParameters OCTETSTRING op_hrSystem GET SET) - (5 hrSystemNumUsers GAUGE op_hrSystem GET) - (6 hrSystemProcesses GAUGE op_hrSystem GET) - (7 hrSystemMaxProcesses INTEGER op_hrSystem GET) - ) - (2 hrStorage - (1 hrStorageTypes - (1 hrStorageOther - ) - (2 hrStorageRam - ) - (3 hrStorageVirtualMemory - ) - (4 hrStorageFixedDisk - ) - (5 hrStorageRemovableDisk - ) - (6 hrStorageFloppyDisk - ) - (7 hrStorageCompactDisc - ) - (8 hrStorageRamDisk - ) - (9 hrStorageFlashMemory - ) - (10 hrStorageNetworkDisk - ) - ) - (2 hrMemorySize INTEGER op_hrStorage GET) - (3 hrStorageTable - (1 hrStorageEntry : INTEGER op_hrStorageTable - (1 hrStorageIndex INTEGER GET) - (2 hrStorageType OID GET) - (3 hrStorageDescr OCTETSTRING GET) - (4 hrStorageAllocationUnits INTEGER GET) - (5 hrStorageSize INTEGER GET SET) - (6 hrStorageUsed INTEGER GET) - (7 hrStorageAllocationFailures COUNTER GET) - ) - ) - ) - (3 hrDevice - (1 hrDeviceTypes - (1 hrDeviceOther - ) - (2 hrDeviceUnknown - ) - (3 hrDeviceProcessor - ) - (4 hrDeviceNetwork - ) - (5 hrDevicePrinter - ) - (6 hrDeviceDiskStorage - ) - (10 hrDeviceVideo - ) - (11 hrDeviceAudio - ) - (12 hrDeviceCoprocessor - ) - (13 hrDeviceKeyboard - ) - (14 hrDeviceModem - ) - (15 hrDeviceParallelPort - ) - (16 hrDevicePointing - ) - (17 hrDeviceSerialPort - ) - (18 hrDeviceTape - ) - (19 hrDeviceClock - ) - (20 hrDeviceVolatileMemory - ) - (21 hrDeviceNonVolatileMemory - ) - ) - (2 hrDeviceTable - (1 hrDeviceEntry : INTEGER op_hrDeviceTable - (1 hrDeviceIndex INTEGER GET) - (2 hrDeviceType OID GET) - (3 hrDeviceDescr OCTETSTRING GET) - (4 hrDeviceID OID GET) - (5 hrDeviceStatus INTEGER GET) - (6 hrDeviceErrors COUNTER GET) - ) - ) - (3 hrProcessorTable - (1 hrProcessorEntry : INTEGER op_hrProcessorTable - (1 hrProcessorFrwID OID GET) - (2 hrProcessorLoad INTEGER GET) - ) - ) - (4 hrNetworkTable - (1 hrNetworkEntry : INTEGER op_hrNetworkTable - (1 hrNetworkIfIndex INTEGER GET) - ) - ) - (5 hrPrinterTable - (1 hrPrinterEntry : INTEGER op_hrPrinterTable - (1 hrPrinterStatus INTEGER GET) - (2 hrPrinterDetectedErrorState OCTETSTRING GET) - ) - ) - (6 hrDiskStorageTable - (1 hrDiskStorageEntry : INTEGER op_hrDiskStorageTable - (1 hrDiskStorageAccess INTEGER GET) - (2 hrDiskStorageMedia INTEGER GET) - (3 hrDiskStorageRemoveble INTEGER GET) - (4 hrDiskStorageCapacity INTEGER GET) - ) - ) - (7 hrPartitionTable - (1 hrPartitionEntry : INTEGER INTEGER op_hrPartitionTable - (1 hrPartitionIndex INTEGER GET) - (2 hrPartitionLabel OCTETSTRING GET) - (3 hrPartitionID OCTETSTRING GET) - (4 hrPartitionSize INTEGER GET) - (5 hrPartitionFSIndex INTEGER GET) - ) - ) - (8 hrFSTable - (1 hrFSEntry : INTEGER op_hrFSTable - (1 hrFSIndex INTEGER GET) - (2 hrFSMountPoint OCTETSTRING GET) - (3 hrFSRemoteMountPoint OCTETSTRING GET) - (4 hrFSType OID GET) - (5 hrFSAccess INTEGER GET) - (6 hrFSBootable INTEGER GET) - (7 hrFSStorageIndex INTEGER GET) - (8 hrFSLastFullBackupDate OCTETSTRING GET SET) - (9 hrFSLastPartialBackupDate OCTETSTRING GET SET) - ) - ) - (9 hrFSTypes - (1 hrFSOther - ) - (2 hrFSUnknown - ) - (3 hrFSBerkeleyFFS - ) - (4 hrFSSys5FS - ) - (5 hrFSFat - ) - (6 hrFSHPFS - ) - (7 hrFSHFS - ) - (8 hrFSMFS - ) - (9 hrFSNTFS - ) - (10 hrFSVNode - ) - (11 hrFSJournaled - ) - (12 hrFSiso9660 - ) - (13 hrFSRockRidge - ) - (14 hrFSNFS - ) - (15 hrFSNetware - ) - (16 hrFSAFS - ) - (17 hrFSDFS - ) - (18 hrFSAppleshare - ) - (19 hrFSRFS - ) - (20 hrFSDGCFS - ) - (21 hrFSBFS - ) - (22 hrFSFAT32 - ) - (23 hrFSLinuxExt2 - ) - ) - ) - (4 hrSWRun - (1 hrSWOSIndex INTEGER op_hrSWRun GET) - (2 hrSWRunTable - (1 hrSWRunEntry : INTEGER op_hrSWRunTable - (1 hrSWRunIndex INTEGER GET) - (2 hrSWRunName OCTETSTRING GET) - (3 hrSWRunID OID GET) - (4 hrSWRunPath OCTETSTRING GET) - (5 hrSWRunParameters OCTETSTRING GET) - (6 hrSWRunType INTEGER GET) - (7 hrSWRunStatus INTEGER GET SET) - ) - ) - ) - (5 hrSWRunPerf - (1 hrSWRunPerfTable - (1 hrSWRunPerfEntry : INTEGER op_hrSWRunPerfTable - (1 hrSWRunPerfCPU INTEGER GET) - (2 hrSWRunPerfMem INTEGER GET) - ) - ) - ) - (6 hrSWInstalled - (1 hrSWInstalledLastChange TIMETICKS op_hrSWInstalled GET) - (2 hrSWInstalledLastUpdateTime TIMETICKS op_hrSWInstalled GET) - (3 hrSWInstalledTable - (1 hrSWInstalledEntry : INTEGER op_hrSWInstalledTable - (1 hrSWInstalledIndex INTEGER GET) - (2 hrSWInstalledName OCTETSTRING GET) - (3 hrSWInstalledID OID GET) - (4 hrSWInstalledType INTEGER GET) - (5 hrSWInstalledDate OCTETSTRING GET) - ) - ) - ) - (7 hrMIBAdminInfo - (1 hostResourcesMibModule - ) - (2 hrMIBCompliances - ) - (3 hrMIBGroups - ) - ) - ) - ) - ) - (4 private - (1 enterprises - (12325 fokus - (1 begemot - (202 begemotHostres - (1 begemotHostresObjects - (1 begemotHrStorageUpdate TIMETICKS op_begemot GET SET) - (2 begemotHrFSUpdate TIMETICKS op_begemot GET SET) - (3 begemotHrDiskStorageUpdate TIMETICKS op_begemot GET SET) - (4 begemotHrNetworkUpdate TIMETICKS op_begemot GET SET) - (5 begemotHrSWInstalledUpdate TIMETICKS op_begemot GET SET) - (6 begemotHrSWRunUpdate TIMETICKS op_begemot GET SET) - (7 begemotHrPkgDir OCTETSTRING op_begemot GET SET) - ) - ) - ) - ) - ) - ) -) diff --git a/usr.sbin/bsnmpd/modules/snmp_hostres/snmp_hostres.3 b/usr.sbin/bsnmpd/modules/snmp_hostres/snmp_hostres.3 deleted file mode 100644 index 403d605..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_hostres/snmp_hostres.3 +++ /dev/null @@ -1,88 +0,0 @@ -.\" -.\" Copyright (C) 2005-2006 -.\" The FreeBSD Project. -.\" All rights reserved. -.\" -.\" Author: Harti Brandt -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd January 3, 2006 -.Dt snmp_hostres 3 -.Os -.Sh NAME -.Nm snmp_hostres -.Nd host resources module for -.Xr bsnmpd 8 -.Sh LIBRARY -.Pq begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so" -.Sh DESCRIPTION -The -.Nm -module implements the HOST-RESOURCES-MIB as standardized in RFC 2790. -.Sh RESTRICTIONS -Not all information in the MIB is meaningful in FreeBSD or is available. -The following variables are not implemented or carry no information: -.Bl -tag -width indent -.It Va hrFSType -There are several types of file systems for which no appropriate OID -exists yet which are supported by -.Fx . -For smbfs, procfs and devfs , -.Va hrFSOther -is returned. -In all other cases, -.Va hrFSUnknown . -.It Va hrFSBootable -It is questionable what bootable means here. -Does it mean that the BIOS is available to start a boot on that file system -or does it mean that there is something bootable? -In either case this information is not available so this variable returns True -for the root file system (which is not necessarily correct) and False for -all others. -.It Va hrFSLastFullBackupDate , hrFSLastPartialBackupDate -This is not available and always returns an empty string. -Theoretically, this could be retrieved from -.Pa /etc/dumpdates , -which would -hardly be correct given the different ways of doing backups. -.It Va hrDiskStorageTable -Floppy devices are currently not reported. -Also the names of the disks are hard-coded in the module. -.El -.Sh FILES -.Bl -tag -width indent -.It Pa /usr/share/snmp/defs/hostres_tree.def -The description of the MIB tree implemented by -.Nm . -.It Pa /usr/share/snmp/mibs/HOST-RESOURCES-TYPES.txt -.It Pa /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt -.It Pa /usr/share/snmp/mibs/BEGEMOT-HOSTRES-MIB.txt -This is the MIB that is implemented by this module. -.El -.Sh SEE ALSO -.Xr gensnmptree 1 , -.Xr snmpmod 3 -.Sh AUTHORS -.An Victor Cruceru Aq soc-victor@FreeBSD.org diff --git a/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile b/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile deleted file mode 100644 index 278dc24..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# $FreeBSD$ -# -# Author: Harti Brandt - -CONTRIB= ${.CURDIR}/../../../../contrib/bsnmp -.PATH: ${CONTRIB}/snmp_mibII - -MOD= mibII -SRCS= mibII.c mibII_begemot.c mibII_ifmib.c mibII_ifstack.c \ - mibII_interfaces.c mibII_ip.c mibII_ipaddr.c mibII_nettomedia.c \ - mibII_rcvaddr.c mibII_route.c mibII_tcp.c mibII_udp.c -XSYM= ipAddrTable ifTable ifRcvAddressEntry ifMIB ipMIB tcpMIB udpMIB \ - ipForward ifIndex linkDown linkUp -MAN= snmp_mibII.3 - -CFLAGS+= -I${CONTRIB}/lib -I${CONTRIB}/snmpd -CFLAGS+= -DHAVE_ERR_H -DHAVE_GETADDRINFO -DHAVE_STRLCPY -DHAVE_SYS_TREE_H - -DEFS= ${MOD}_tree.def -INCS= snmp_${MOD}.h -BMIBS= BEGEMOT-IP-MIB.txt BEGEMOT-MIB2-MIB.txt - -.include - -smilint: - env SMIPATH=/usr/share/snmp/mibs:/usr/local/share/snmp/mibs \ - smilint -c /dev/null -l6 -i group-membership ${BMIBS:C/^/${CONTRIB}\/snmp_mibII\//} diff --git a/usr.sbin/bsnmpd/modules/snmp_netgraph/BEGEMOT-NETGRAPH.txt b/usr.sbin/bsnmpd/modules/snmp_netgraph/BEGEMOT-NETGRAPH.txt deleted file mode 100644 index 1896fe6..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_netgraph/BEGEMOT-NETGRAPH.txt +++ /dev/null @@ -1,398 +0,0 @@ --- --- Copyright (c) 2001-2003 --- Fraunhofer Institute for Open Communication Systems (FhG Fokus). --- All rights reserved. --- --- Author: Harti Brandt --- --- Redistribution of this software and documentation and use in source and --- binary forms, with or without modification, are permitted provided that --- the following conditions are met: --- --- 1. Redistributions of source code or documentation must retain the above --- copyright notice, this list of conditions and the following disclaimer. --- 2. Redistributions in binary form must reproduce the above copyright --- notice, this list of conditions and the following disclaimer in the --- documentation and/or other materials provided with the distribution. --- --- THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS --- AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, --- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND --- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL --- FRAUNHOFER FOKUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, --- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT --- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, --- OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF --- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING --- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, --- EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --- --- $FreeBSD$ --- --- Private MIB for netgraph part of Begemot SNMP daemon. --- -BEGEMOT-NETGRAPH-MIB DEFINITIONS ::= BEGIN - -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE, Counter32, Unsigned32 - FROM SNMPv2-SMI - TEXTUAL-CONVENTION, TruthValue - FROM SNMPv2-TC - MODULE-COMPLIANCE, OBJECT-GROUP - FROM SNMPv2-CONF - begemot - FROM BEGEMOT-MIB; - -begemotNg MODULE-IDENTITY - LAST-UPDATED "200311140000Z" - ORGANIZATION "Fraunhofer FOKUS, CATS" - CONTACT-INFO - " Hartmut Brandt - - Postal: Fraunhofer Institute for Open Communication Systems - Kaiserin-Augusta-Allee 31 - 10589 Berlin - Germany - - Fax: +49 30 3463 7352 - - E-mail: harti@freebsd.org" - DESCRIPTION - "The MIB for the NetGraph access module for SNMP." - ::= { begemot 2 } - -begemotNgObjects OBJECT IDENTIFIER ::= { begemotNg 1 } - --- -------------------------------------------------------------------------- - -NgTypeName ::= TEXTUAL-CONVENTION - DISPLAY-HINT "31a" - STATUS current - DESCRIPTION - "Name of a netgraph type." - SYNTAX OCTET STRING (SIZE(1..31)) - -NgNodeName ::= TEXTUAL-CONVENTION - DISPLAY-HINT "31a" - STATUS current - DESCRIPTION - "Name of a netgraph node." - SYNTAX OCTET STRING (SIZE(1..31)) - -NgNodeNameOrEmpty ::= TEXTUAL-CONVENTION - DISPLAY-HINT "31a" - STATUS current - DESCRIPTION - "Name of a netgraph node." - SYNTAX OCTET STRING (SIZE(0..31)) - -NgHookName ::= TEXTUAL-CONVENTION - DISPLAY-HINT "31a" - STATUS current - DESCRIPTION - "Name of a netgraph hook." - SYNTAX OCTET STRING (SIZE(1..31)) - -NgNodeId ::= TEXTUAL-CONVENTION - DISPLAY-HINT "x" - STATUS current - DESCRIPTION - "Node identifier." - SYNTAX Unsigned32 (1..4294967295) - -NgNodeIdOrZero ::= TEXTUAL-CONVENTION - DISPLAY-HINT "x" - STATUS current - DESCRIPTION - "Node identifier or 0 for 'no-node'." - SYNTAX Unsigned32 (0..4294967295) - --- -------------------------------------------------------------------------- --- --- Configuration parameters --- -begemotNgConfig OBJECT IDENTIFIER ::= { begemotNgObjects 1 } - -begemotNgControlNodeName OBJECT-TYPE - SYNTAX NgNodeName - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The name of the netgraph node of this daemon. The name is - writeable during initialisation. If the name is set from - the empty string to the non-empty string, the netgraph socket - is created. Once set it cannot be changed." - ::= { begemotNgConfig 1 } - -begemotNgResBufSiz OBJECT-TYPE - SYNTAX INTEGER (1024..65536) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The size of the receive buffers for netgraph messages." - DEFVAL { 20000 } - ::= { begemotNgConfig 2 } - -begemotNgTimeout OBJECT-TYPE - SYNTAX INTEGER (10..10000) - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum time to wait for a response to a netgraph message." - DEFVAL { 1000 } - ::= { begemotNgConfig 3 } - -begemotNgDebugLevel OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The netgraph library debug level. This should be set only - if the daemon is run with a terminal attached." - DEFVAL { 0 } - ::= { begemotNgConfig 4 } - --- -------------------------------------------------------------------------- --- --- The STATISTICS Group --- -begemotNgStats OBJECT IDENTIFIER ::= { begemotNgObjects 2 } - -begemotNgNoMems OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of times a memory allocation has failed for buffers - or the message queue." - ::= { begemotNgStats 1 } - -begemotNgMsgReadErrs OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of times reading a netgraph message has failed." - ::= { begemotNgStats 2 } - -begemotNgTooLargeMsgs OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of times a netgraph message was too large for - the buffer. Try increasing begemotNgResBufSiz if - this happens." - ::= { begemotNgStats 3 } - -begemotNgDataReadErrs OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of times reading a netgraph data message has failed." - ::= { begemotNgStats 4 } - -begemotNgTooLargeDatas OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of times a netgraph data message was too large. - You need to increase begemotNgResBufSiz." - ::= { begemotNgStats 5 } - --- ----------------------------------------------------- --- --- The NODE table --- -begemotNgTypeTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotNgTypeEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table containing information about all netgraph node types." - ::= { begemotNgObjects 3 } - -begemotNgTypeEntry OBJECT-TYPE - SYNTAX BegemotNgTypeEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table entry that describes one netgraph node." - INDEX { begemotNgTypeName } - ::= { begemotNgTypeTable 1 } - -BegemotNgTypeEntry ::= SEQUENCE { - begemotNgTypeName NgTypeName, - begemotNgTypeStatus INTEGER -} - -begemotNgTypeName OBJECT-TYPE - SYNTAX NgTypeName - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The name of the type. Used as index." - ::= { begemotNgTypeEntry 1 } - -begemotNgTypeStatus OBJECT-TYPE - SYNTAX INTEGER { loaded(1), unloaded(2) } - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "If loaded then the node type is available. A type can be load - by setting this field to loaded. It is unload if the field is - set to unloaded. Note, that a type cannot be unloaded if it - is compiled into the kernel or has nodes of this type. The name - of the file containing the type implementation is constructed by - prepending ng_ to the type name." - ::= { begemotNgTypeEntry 2 } - --- --- Node table --- -begemotNgNodeTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotNgNodeEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table containing information about all netgraph nodes." - ::= { begemotNgObjects 4 } - -begemotNgNodeEntry OBJECT-TYPE - SYNTAX BegemotNgNodeEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table entry that describes one netgraph node." - INDEX { begemotNgNodeId } - ::= { begemotNgNodeTable 1 } - -BegemotNgNodeEntry ::= SEQUENCE { - begemotNgNodeId NgNodeId, - begemotNgNodeStatus INTEGER, - begemotNgNodeName NgNodeNameOrEmpty, - begemotNgNodeType NgTypeName, - begemotNgNodeHooks Unsigned32 -} - -begemotNgNodeId OBJECT-TYPE - SYNTAX NgNodeId - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The 32bit node id of this node. 0 is an illegal value." - ::= { begemotNgNodeEntry 1 } - -begemotNgNodeStatus OBJECT-TYPE - SYNTAX INTEGER { valid(1), invalid(2) } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Indicates whether the node exists or not." - ::= { begemotNgNodeEntry 2 } - -begemotNgNodeName OBJECT-TYPE - SYNTAX NgNodeNameOrEmpty - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Name of the node (if any)." - ::= { begemotNgNodeEntry 3 } - -begemotNgNodeType OBJECT-TYPE - SYNTAX NgTypeName - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Type name of the node." - ::= { begemotNgNodeEntry 4 } - -begemotNgNodeHooks OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of hooks on this node." - ::= { begemotNgNodeEntry 5 } - --- --- Hook table --- -begemotNgHookTable OBJECT-TYPE - SYNTAX SEQUENCE OF BegemotNgHookEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table containing information about all netgraph hooks." - ::= { begemotNgObjects 5 } - -begemotNgHookEntry OBJECT-TYPE - SYNTAX BegemotNgHookEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table entry that describes one netgraph node." - INDEX { begemotNgHookNodeId, begemotNgHookHook } - ::= { begemotNgHookTable 1 } - -BegemotNgHookEntry ::= SEQUENCE { - begemotNgHookNodeId NgNodeId, - begemotNgHookHook NgHookName, - begemotNgHookStatus INTEGER, - begemotNgHookPeerNodeId NgNodeId, - begemotNgHookPeerHook NgHookName, - begemotNgHookPeerType NgTypeName -} - -begemotNgHookNodeId OBJECT-TYPE - SYNTAX NgNodeId - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The 32bit node id of this node." - ::= { begemotNgHookEntry 1 } - -begemotNgHookHook OBJECT-TYPE - SYNTAX NgHookName - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Name of the hook." - ::= { begemotNgHookEntry 2 } - -begemotNgHookStatus OBJECT-TYPE - SYNTAX INTEGER { valid(1), invalid(2) } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Indicates whether the hook exists or not." - ::= { begemotNgHookEntry 3 } - -begemotNgHookPeerNodeId OBJECT-TYPE - SYNTAX NgNodeId - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The 32bit node id of the peer node of this hook." - ::= { begemotNgHookEntry 4 } - -begemotNgHookPeerHook OBJECT-TYPE - SYNTAX NgHookName - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Name of the peer hook." - ::= { begemotNgHookEntry 5 } - -begemotNgHookPeerType OBJECT-TYPE - SYNTAX NgTypeName - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Name of the peer type." - ::= { begemotNgHookEntry 6 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile b/usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile deleted file mode 100644 index 7caf7e4..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_netgraph/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# $FreeBSD$ -# -# Author: Harti Brandt - -MOD= netgraph -SRCS= snmp_netgraph.c -XSYM= begemotNg -MAN= snmp_netgraph.3 - -BMIBS= BEGEMOT-NETGRAPH.txt -DEFS= ${MOD}_tree.def -INCS= snmp_${MOD}.h - -DPADD= ${LIBNETGRAPH} -LDADD= -lnetgraph - -.include diff --git a/usr.sbin/bsnmpd/modules/snmp_netgraph/netgraph_tree.def b/usr.sbin/bsnmpd/modules/snmp_netgraph/netgraph_tree.def deleted file mode 100644 index eff59ff..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_netgraph/netgraph_tree.def +++ /dev/null @@ -1,78 +0,0 @@ -# -# Copyright (c) 2001-2003 -# Fraunhofer Institute for Open Communication Systems (FhG Fokus). -# All rights reserved. -# -# Author: Harti Brandt -# -# Redistribution of this software and documentation and use in source and -# binary forms, with or without modification, are permitted provided that -# the following conditions are met: -# -# 1. Redistributions of source code or documentation must retain the above -# copyright notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS -# AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -# FRAUNHOFER FOKUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, -# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -# -# $FreeBSD$ -# -# Definition of the tree implemented by snmp_netgraph. -# -(1 internet - (4 private - (1 enterprises - (12325 fokus - (1 begemot - (2 begemotNg - (1 begemotNgObjects - (1 begemotNgConfig - (1 begemotNgControlNodeName OCTETSTRING op_ng_config GET SET) - (2 begemotNgResBufSiz INTEGER op_ng_config GET SET) - (3 begemotNgTimeout INTEGER op_ng_config GET SET) - (4 begemotNgDebugLevel UNSIGNED32 op_ng_config GET SET) - ) -# Change definition of stats array if you change StatsGroup - (2 begemotNgStats - (1 begemotNgNoMems COUNTER op_ng_stats GET) - (2 begemotNgMsgReadErrs COUNTER op_ng_stats GET) - (3 begemotNgTooLargeMsgs COUNTER op_ng_stats GET) - (4 begemotNgDataReadErrs COUNTER op_ng_stats GET) - (5 begemotNgTooLargeDatas COUNTER op_ng_stats GET) - ) - (3 begemotNgTypeTable - (1 begemotNgTypeEntry : OCTETSTRING op_ng_type - (1 begemotNgTypeName OCTETSTRING) - (2 begemotNgTypeStatus INTEGER GET SET) - )) - (4 begemotNgNodeTable - (1 begemotNgNodeEntry : INTEGER op_ng_node - (1 begemotNgNodeId UNSIGNED32) - (2 begemotNgNodeStatus INTEGER GET) - (3 begemotNgNodeName OCTETSTRING GET) - (4 begemotNgNodeType OCTETSTRING GET) - (5 begemotNgNodeHooks UNSIGNED32 GET) - )) - (5 begemotNgHookTable - (1 begemotNgHookEntry : UNSIGNED32 OCTETSTRING op_ng_hook - (1 begemotNgHookNodeId UNSIGNED32) - (2 begemotNgHookHook OCTETSTRING) - (3 begemotNgHookStatus INTEGER GET) - (4 begemotNgHookPeerNodeId UNSIGNED32 GET) - (5 begemotNgHookPeerHook OCTETSTRING GET) - (6 begemotNgHookPeerType OCTETSTRING GET) - )) - )) -))))) diff --git a/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.3 b/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.3 deleted file mode 100644 index a7f99de..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.3 +++ /dev/null @@ -1,436 +0,0 @@ -.\" -.\" Copyright (c) 2001-2003 -.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). -.\" All rights reserved. -.\" -.\" Author: Harti Brandt -.\" -.\" Redistribution of this software and documentation and use in source and -.\" binary forms, with or without modification, are permitted provided that -.\" the following conditions are met: -.\" -.\" 1. Redistributions of source code or documentation must retain the above -.\" copyright notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS -.\" AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, -.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -.\" FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -.\" FRAUNHOFER FOKUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, -.\" OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd November 14, 2003 -.Dt SNMP_NETGRAPH 3 -.Os -.Sh NAME -.Nm snmp_netgraph , -.Nm snmp_node , -.Nm snmp_nodename , -.Nm ng_cookie_f , -.Nm ng_hook_f , -.Nm ng_register_cookie , -.Nm ng_unregister_cookie , -.Nm ng_register_hook , -.Nm ng_unregister_hook , -.Nm ng_unregister_module , -.Nm ng_output , -.Nm ng_output_node , -.Nm ng_output_id , -.Nm ng_dialog , -.Nm ng_dialog_node , -.Nm ng_dialog_id , -.Nm ng_send_data , -.Nm ng_mkpeer_id , -.Nm ng_connect_node , -.Nm ng_connect_id , -.Nm ng_connect2_id , -.Nm ng_connect2_tee_id , -.Nm ng_rmhook , -.Nm ng_rmhook_id , -.Nm ng_rmhook_tee_id , -.Nm ng_shutdown_id , -.Nm ng_next_node_id , -.Nm ng_node_id , -.Nm ng_node_id_node , -.Nm ng_node_name , -.Nm ng_node_type , -.Nm ng_peer_hook_id -.Nd "netgraph module for snmpd. -.Sh LIBRARY -.Pq begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so" -.Sh SYNOPSIS -.In bsnmp/snmpmod.h -.In bsnmp/snmp_netgraph.h -.Vt extern ng_ID_t snmp_node ; -.Vt extern u_char *snmp_nodename ; -.Ft typedef void -.Fn ng_cookie_f "const struct ng_mesg *mesg" "const char *path" "ng_ID_t id" "void *uarg" -.Ft typedef void -.Fn ng_hook_f "const char *hook" "const u_char *mesg" "size_t len" "void *uarg" -.Ft void * -.Fn ng_register_cookie "const struct lmodule *mod" "u_int32_t cookie" "ng_ID_t id" "ng_cookie_f *func" "void *uarg" -.Ft void -.Fn ng_unregister_cookie "void *reg" -.Ft void * -.Fn ng_register_hook "const struct lmodule *mod" "const char *hook" "ng_hook_f *func" "void *uarg" -.Ft void -.Fn ng_unregister_hook "void *reg" -.Ft void -.Fn ng_unregister_module "const struct lmodule *mod" -.Ft int -.Fn ng_output "const char *path" "u_int cookie" "u_int opcode" "const void *arg" "size_t arglen" -.Ft int -.Fn ng_output_node "const char *node" "u_int cookie" "u_int opcode" "const void *arg" "size_t arglen" -.Ft int -.Fn ng_output_id "ng_ID_t node" "u_int cookie" "u_int opcode" "const void *arg" "size_t arglen" -.Ft struct ng_mesg * -.Fn ng_dialog "const char *path" "u_int cookie" "u_int opcode" "const void *arg" "size_t arglen" -.Ft struct ng_mesg * -.Fn ng_dialog_node "const char *node" "u_int cookie" "u_int opcode" "const void *arg" "size_t arglen" -.Ft struct ng_mesg * -.Fn ng_dialog_id "ng_ID_t id" "u_int cookie" "u_int opcode" "const void *arg" "size_t arglen" -.Ft int -.Fn ng_send_data "const char *hook" "const void *sndbuf" "size_t sndlen" -.Ft ng_ID_t -.Fn ng_mkpeer_id "ng_ID_t id" "const char *name" "const char *type" "const char *hook" "const char *peerhook" -.Ft int -.Fn ng_connect_node "const char *node" "const char *ourhook" "const char *peerhook" -.Ft int -.Fn ng_connect_id "ng_ID_t id" "const char *ourhook" "const char *peerhook" -.Ft int -.Fn ng_connect2_id "ng_ID_t id" "ng_ID_t peer" "const char *ourhook" "const char *peerhook" -.Ft int -.Fn ng_connect2_tee_id "ng_ID_t id" "ng_ID_t peer" "const char *ourhook" "const char *peerhook" -.Ft int -.Fn ng_rmhook "const char *ourhook" -.Ft int -.Fn ng_rmhook_id "ng_ID_t id" "const char *hook" -.Ft int -.Fn ng_rmhook_tee_id "ng_ID_t id" "const char *hook" -.Ft int -.Fn ng_shutdown_id "ng_ID_t id" -.Ft ng_ID_t -.Fn ng_next_node_id "ng_ID_t node" "const char *type" "const char *hook" -.Ft ng_ID_t -.Fn ng_node_id "const char *path" -.Ft ng_ID_t -.Fn ng_node_id_node "const char *node" -.Ft ng_ID_t -.Fn ng_node_name "ng_ID_t id" "char *name" -.Ft ng_ID_t -.Fn ng_node_type "ng_ID_t id" "char *type" -.Ft int -.Fn ng_peer_hook_id "ng_ID_t id" "const char *hook" "char *peerhook" -.Sh DESCRIPTION -The -.Nm snmp_netgraph -module implements a number of tables and scalars that enable remote access to -the netgraph subsystem. -It also exports a number of global variables and -functions, that allow other modules to easily use the netgraph system. -.Pp -If upon start up of the module the variable -.Va begemotNgControlNodeName -is not empty the module opens a netgraph socket and names that socket node. -If the variable is empty, the socket is created, as soon as the variable is -written with a non-empty name. -The socket can be closed by writing an empty -string to the variable. -The socket itself and its name are available in -.Va snmp_node -and -.Va snmp_nodename . -.Ss SENDING AND RECEIVING MESSAGES AND DATA -There are three functions for sending control message: -.Bl -tag -width ".It Fn ng_output_node" -.It Fn ng_output -sends a control message along the given -.Fa path . -.It Fn ng_output_node -sends a control message to the node with name -.Fa node -and -.It Fn ng_output_id -sends a control message to the node with node id -.Fa id . -.El -.Pp -Each of these functions takes the following arguments: -.Bl -tag -width ".It Fa cookie" -.It Fa cookie -is the node specific command cookie, -.It Fa opcode -is the node specific code for the operation to perform, -.It Fa arg -is a pointer to the message itself. -This message must start with a -.Vt struct ng_mesg . -.It Fa arglen -is the overall length of the message (header plus arguments). -.El -The functions return the message id that can be used to match incoming responses -or -1 if an error occurs. -.Pp -Another class of functions is used to send a control message and to wait for -a matching response. -Note, that this operation blocks the daemon, so use it -only if you are sure that the response will happen. -There is a maximum timeout -that is configurable in the MIB variable -.Va begemotNgTimeout . -Other messages arriving while the functions are waiting for the response are -queued and delivered on the next call to the module's idle function. -.Bl -tag -width ".It Fn ng_output_node" -.It Fn ng_dialog -sends a control message along the given -.Fa path -and waits for a matching response. -.It Fn ng_dialog_node -sends a control message to the node with name -.Fa node -and waits for a matching response. -.It Fn ng_dialog_id -sends a control message to the node with id -.Fa id -and waits for a matching response. -.El -.Pp -All three functions take the same arguments as the -.Fn ng_output* -functions. -The functions return the response message in a buffer allocated by -.Xr malloc 3 -or NULL in case of an error. -The maximum size of the response buffer can be -configured in the variable -.Va begemotNgResBufSiz . -.Pp -A data message can be send with the function -.Fn ng_send_data . -This function takes the name of the -.Va snmp_node Ns 's -hook through which to send the data, a pointer to the message buffer and -the size of the message. -It returns -1 if an error happens. -.Ss ASYNCHRONOUS CONTROL AND DATA MESSAGES -A module can register functions to asynchronously receive control and data -message. -.Pp -The function -.Fn ng_register_cookie -registers a control message receive function. -If a control message is -received, that is not consumed by the dialog functions, the list of registered -control message receive functions is scanned. -If the cookie in the received -message is the same as the -.Fa cookie -argument to the -.Fn ng_register_cookie -call and the -.Fa id -argument to the -.Fn ng_register_cookie -call was either 0 or equals the node id which sent the control message, the -handler function -.Fa func -is called with a pointer to the received message, the hook on which the -message was received (or NULL if it was received not on a hook), the id -of the sender's node and the -.Fa uarg -argument of the registration call. -The handler function should not modify -the contents of the message, because more than one function may be registered -to the same cookie and node id. -.Pp -A control message registration can be undone by calling -.Fn ng_unregister_cookie -with the return value of the registration call. -If an error occurs while registering, -.Fn ng_register_cookie -returns NULL. -.Pp -A module can call -.Fn ng_register_hook -to register a callback for data messages on one of the -.Va snmp_node Ns 's -hooks. -If a data message is received on that hook, the callback function -.Fa func -is called with the hook name, a pointer to the data message, the size of -the message and the argument -.Fa uarg -to the registration function. -The message should be treated as read-only. -A data message registration can be undone by calling -.Fn ng_unregister_hook -with the return value of the registration call. -If an error occurs while registering, -.Fn ng_register_hook -returns NULL. -.Pp -The function -.Fn ng_unregister_module -removes all control and data registrations for that module. -.Ss FINDING NODES AND NODE CHARACTERISTICS -.Pp -The function -.Fn ng_node_id -returns the id of the node addressed by -.Fa path -or 0 if the node does not exists. -.Pp -The function -.Fn ng_node_id_node -returns the id of the node with name -.Fa node -or 0 if the node does not exist. -.Pp -The function -.Fn ng_node_node -retrieves the name of the node with id -.Fa id -and writes it to the buffer pointed to by -.Fa name . -This buffer should be at least -.Li NG_NODESIZ -bytes long. -The function returns the node id or 0 if the -node is not found -.Pp -The function -.Fn ng_node_type -retrieves the name of the node with id -.Fa id -and writes it to the buffer pointed to by -.Fa type . -This buffer should be at least -.Li NG_TYPESIZ -bytes long. -The function returns the node id or 0 if the -node is not found. -.Pp -The function -.Fn ng_peer_hook_id -writes the name of the peer hook of the hook -.Fa hook -on the node with -.Fa id -to the buffer pointed to by -.Fa peer_hook . -The buffer should be at least -.Li NG_HOOKSIZ -bytes long. -The function returns 0 if the node and the hook is found, -1 -otherwise. -The function skips intermediate tee nodes (see -.Xr ng_tee 4 ) . -.Pp -The function -.Fn ng_next_node_id -returns the node id of the peer node that is on the other side of hook -.Fa hook -of node -.Fa id . -If -.Fa type -is not NULL, the function checks, that the peer node's type is -.Fa type . -The function skips intermediate tee nodes (see -.Xr ng_tee 4 ) . -It returns the node id of the peer node or 0 if an error occurs or the -types do not match. -.Ss CHANGING THE GRAPH -A number of functions can be used to create or destroy nodes and hooks. -.Pp -The function -.Fn ng_mkpeer_id -creates a new node of type -.Fa type -whose hook -.Fa peerhook -will be connected to -.Fa hook -of node -.Fa id . -If -.Fa name -is not NULL the new node is named with this name. -The function returns -The node id of the new node or 0 if an error happens. -.Pp -The functions -.Fn ng_connect_node -and -.Fn ng_connect_id -make a new hook connecting -.Fa ourhook -of the modules socket node -.Va snmp_node -to -.Fa peerhook -of the node identified by id -.Fa id -or name -.Fa node . -The functions return 0 on success or -1 otherwise. -.Pp -The function -.Fn ng_connect2_id -connects hook -.Fa ourhook -of the node with id -.Fa id -to hook -.Fa peerhook -of the node with id -.Fa peer . -The functions return 0 on success or -1 otherwise. -The function -.Fn ng_connect2_tee_id does the same as -.Fn ng_connect2_id -except, that it puts an unnamed tee node between the two nodes. -.Pp -The function -.Fn ng_rmhook -removes hook -.Fa hook -on the module's -.Va snmp_node . -The function -.Fn ng_rmhook_id -removes hook -.Fa hook -on the node with id -.Fa id . -The function -.Fn ng_rmhook_tee_id -additionally shuts down all tee nodes between the node and the first non-tee -peer. -.Pp -The function -.Fn ng_shutdown_id -destroys the given node. -.Sh FILES -.Bl -tag -width "XXXXXXXXX" -.It Pa /usr/share/bsnmp/defs/netgraph_tree.def -The description of the MIB tree implemented by -.Nm . -.It Pa /usr/share/bsnmp/mibs/BEGEMOT-NETGRAPH.txt -This is the MIB that is implemented by this module. -.El -.Sh SEE ALSO -.Xr gensnmptree 1 , -.Xr snmpmod 3 -.Sh AUTHORS -.An Hartmut Brandt Aq harti@FreeBSD.org diff --git a/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.c b/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.c deleted file mode 100644 index d9d136a..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.c +++ /dev/null @@ -1,1690 +0,0 @@ -/* - * Copyright (c) 2001-2003 - * Fraunhofer Institute for Open Communication Systems (FhG Fokus). - * All rights reserved. - * - * Author: Harti Brandt - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS - * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * FRAUNHOFER FOKUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - * - * Netgraph interface for SNMPd. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "snmp_netgraph.h" -#include "netgraph_tree.h" -#include "netgraph_oid.h" - -/* maximum message size */ -#define RESBUFSIZ 20000 - -/* default node name */ -#define NODENAME "NgSnmpd" - -/* my node Id */ -ng_ID_t snmp_node; -u_char *snmp_nodename; - -/* the Object Resource registration index */ -static u_int reg_index; -static const struct asn_oid oid_begemotNg = OIDX_begemotNg; - -/* configuration */ -/* this must be smaller than int32_t because the functions in libnetgraph - * falsely return an int */ -static size_t resbufsiz = RESBUFSIZ; -static u_int timeout = 1000; -static u_int debug_level; - -/* number of microseconds per clock tick */ -static struct clockinfo clockinfo; - -/* Csock buffers. Communication on the csock is asynchronuous. This means - * if we wait for a specific response, we may get other messages. Put these - * into a queue and execute them when we are idle. */ -struct csock_buf { - STAILQ_ENTRY(csock_buf) link; - struct ng_mesg *mesg; - char path[NG_PATHSIZ]; -}; -static STAILQ_HEAD(, csock_buf) csock_bufs = - STAILQ_HEAD_INITIALIZER(csock_bufs); - -/* - * We dispatch unsolicieted messages by node cookies and ids. - * So we must keep a list of hook names and dispatch functions. - */ -struct msgreg { - u_int32_t cookie; - ng_ID_t id; - ng_cookie_f *func; - void *arg; - const struct lmodule *mod; - SLIST_ENTRY(msgreg) link; -}; -static SLIST_HEAD(, msgreg) msgreg_list = - SLIST_HEAD_INITIALIZER(msgreg_list); - -/* - * Data messages are dispatched by hook names. - */ -struct datareg { - char hook[NG_HOOKSIZ]; - ng_hook_f *func; - void *arg; - const struct lmodule *mod; - SLIST_ENTRY(datareg) link; -}; -static SLIST_HEAD(, datareg) datareg_list = - SLIST_HEAD_INITIALIZER(datareg_list); - -/* the netgraph sockets */ -static int csock, dsock; -static void *csock_fd, *dsock_fd; - -/* our module handle */ -static struct lmodule *module; - -/* statistics */ -static u_int32_t stats[LEAF_begemotNgTooLargeDatas+1]; - -/* netgraph type list */ -struct ngtype { - char name[NG_TYPESIZ]; - struct asn_oid index; - TAILQ_ENTRY(ngtype) link; -}; -TAILQ_HEAD(ngtype_list, ngtype); - -static struct ngtype_list ngtype_list; -static uint64_t ngtype_tick; - - -/* - * Register a function to receive unsolicited messages - */ -void * -ng_register_cookie(const struct lmodule *mod, u_int32_t cookie, ng_ID_t id, - ng_cookie_f *func, void *arg) -{ - struct msgreg *d; - - if ((d = malloc(sizeof(*d))) == NULL) - return (NULL); - - d->cookie = cookie; - d->id = id; - d->func = func; - d->arg = arg; - d->mod = mod; - - SLIST_INSERT_HEAD(&msgreg_list, d, link); - - return (d); -} - -/* - * Remove a registration. - */ -void -ng_unregister_cookie(void *dd) -{ - struct msgreg *d = dd; - - SLIST_REMOVE(&msgreg_list, d, msgreg, link); - free(d); -} - -/* - * Register a function for hook data. - */ -void * -ng_register_hook(const struct lmodule *mod, const char *hook, - ng_hook_f *func, void *arg) -{ - struct datareg *d; - - if ((d = malloc(sizeof(*d))) == NULL) - return (NULL); - - strcpy(d->hook, hook); - d->func = func; - d->arg = arg; - d->mod = mod; - - SLIST_INSERT_HEAD(&datareg_list, d, link); - - return (d); -} - -/* - * Unregister a hook function - */ -void -ng_unregister_hook(void *dd) -{ - struct datareg *d = dd; - - SLIST_REMOVE(&datareg_list, d, datareg, link); - free(d); -} - -/* - * Unregister all hooks and cookies for that module. Note: doesn't disconnect - * any hooks! - */ -void -ng_unregister_module(const struct lmodule *mod) -{ - struct msgreg *m, *m1; - struct datareg *d, *d1; - - m = SLIST_FIRST(&msgreg_list); - while (m != NULL) { - m1 = SLIST_NEXT(m, link); - if (m->mod == mod) { - SLIST_REMOVE(&msgreg_list, m, msgreg, link); - free(m); - } - m = m1; - } - - d = SLIST_FIRST(&datareg_list); - while (d != NULL) { - d1 = SLIST_NEXT(d, link); - if (d->mod == mod) { - SLIST_REMOVE(&datareg_list, d, datareg, link); - free(d); - } - d = d1; - } -} - -/* - * Dispatch a message to the correct module and delete it. More than one - * module can get a message. - */ -static void -csock_handle(struct ng_mesg *mesg, const char *path) -{ - struct msgreg *d, *d1; - u_int id; - int len; - - if (sscanf(path, "[%x]:%n", &id, &len) != 1 || - (u_int)len != strlen(path)) { - syslog(LOG_ERR, "cannot parse message path '%s'", path); - id = 0; - } - - d = SLIST_FIRST(&msgreg_list); - while (d != NULL) { - d1 = SLIST_NEXT(d, link); - if (d->cookie == mesg->header.typecookie && - (d->id == 0 || d->id == id || id == 0)) - (*d->func)(mesg, path, id, d->arg); - d = d1; - } - free(mesg); -} - -/* - * Input from the control socket. - */ -static struct ng_mesg * -csock_read(char *path) -{ - struct ng_mesg *mesg; - int ret, err; - - if ((mesg = malloc(resbufsiz + 1)) == NULL) { - stats[LEAF_begemotNgNoMems]++; - syslog(LOG_CRIT, "out of memory"); - errno = ENOMEM; - return (NULL); - } - if ((ret = NgRecvMsg(csock, mesg, resbufsiz + 1, path)) < 0) { - err = errno; - free(mesg); - if (errno == EWOULDBLOCK) { - errno = err; - return (NULL); - } - stats[LEAF_begemotNgMsgReadErrs]++; - syslog(LOG_WARNING, "read from csock: %m"); - errno = err; - return (NULL); - } - if (ret == 0) { - syslog(LOG_DEBUG, "node closed -- exiting"); - exit(0); - } - if ((size_t)ret > resbufsiz) { - stats[LEAF_begemotNgTooLargeMsgs]++; - syslog(LOG_WARNING, "ng message too large"); - free(mesg); - errno = EFBIG; - return (NULL); - } - return (mesg); -} - -static void -csock_input(int fd __unused, void *udata __unused) -{ - struct ng_mesg *mesg; - char path[NG_PATHSIZ]; - - if ((mesg = csock_read(path)) == NULL) - return; - - csock_handle(mesg, path); -} - -/* - * Write a message to a node. - */ -int -ng_output(const char *path, u_int cookie, u_int opcode, - const void *arg, size_t arglen) -{ - return (NgSendMsg(csock, path, (int)cookie, (int)opcode, arg, arglen)); -} -int -ng_output_node(const char *node, u_int cookie, u_int opcode, - const void *arg, size_t arglen) -{ - char path[NG_PATHSIZ]; - - sprintf(path, "%s:", node); - return (ng_output(path, cookie, opcode, arg, arglen)); -} -int -ng_output_id(ng_ID_t node, u_int cookie, u_int opcode, - const void *arg, size_t arglen) -{ - char path[NG_PATHSIZ]; - - sprintf(path, "[%x]:", node); - return (ng_output(path, cookie, opcode, arg, arglen)); -} - - - -/* - * Execute a synchronuous dialog with the csock. All message we receive, that - * do not match our request, are queue until the next call to the IDLE function. - */ -struct ng_mesg * -ng_dialog(const char *path, u_int cookie, u_int opcode, - const void *arg, size_t arglen) -{ - int token, err; - struct ng_mesg *mesg; - char rpath[NG_PATHSIZ]; - struct csock_buf *b; - struct timeval end, tv; - - if ((token = ng_output(path, cookie, opcode, arg, arglen)) < 0) - return (NULL); - - if (csock_fd) - fd_suspend(csock_fd); - - gettimeofday(&end, NULL); - tv.tv_sec = timeout / 1000; - tv.tv_usec = (timeout % 1000) * 1000; - timeradd(&end, &tv, &end); - for (;;) { - mesg = NULL; - gettimeofday(&tv, NULL); - if (timercmp(&tv, &end, >=)) { - block: - syslog(LOG_WARNING, "no response for request %u/%u", - cookie, opcode); - errno = EWOULDBLOCK; - break; - } - timersub(&end, &tv, &tv); - if (tv.tv_sec == 0 && tv.tv_usec < clockinfo.tick) - goto block; - - if (setsockopt(csock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) - syslog(LOG_WARNING, "setsockopt(SO_RCVTIMEO): %m"); - if ((mesg = csock_read(rpath)) == NULL) { - if (errno == EWOULDBLOCK) - continue; - break; - } - if (mesg->header.token == (u_int)token) - break; - if ((b = malloc(sizeof(*b))) == NULL) { - stats[LEAF_begemotNgNoMems]++; - syslog(LOG_ERR, "out of memory"); - free(mesg); - continue; - } - b->mesg = mesg; - strcpy(b->path, rpath); - STAILQ_INSERT_TAIL(&csock_bufs, b, link); - } - - tv.tv_sec = 0; - tv.tv_usec = 0; - if (setsockopt(csock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) - syslog(LOG_WARNING, "setsockopt(SO_RCVTIMEO,0): %m"); - - if (csock_fd) { - err = errno; - fd_resume(csock_fd); - errno = err; - } - - return (mesg); -} -struct ng_mesg * -ng_dialog_node(const char *node, u_int cookie, u_int opcode, - const void *arg, size_t arglen) -{ - char path[NG_PATHSIZ]; - - sprintf(path, "%s:", node); - return (ng_dialog(path, cookie, opcode, arg, arglen)); -} -struct ng_mesg * -ng_dialog_id(ng_ID_t id, u_int cookie, u_int opcode, - const void *arg, size_t arglen) -{ - char path[NG_PATHSIZ]; - - sprintf(path, "[%x]:", id); - return (ng_dialog(path, cookie, opcode, arg, arglen)); -} - - -/* - * Send a data message to a given hook. - */ -int -ng_send_data(const char *hook, const void *sndbuf, size_t sndlen) -{ - return (NgSendData(dsock, hook, sndbuf, sndlen)); -} - -/* - * Input from a data socket. Dispatch to the function for that hook. - */ -static void -dsock_input(int fd __unused, void *udata __unused) -{ - u_char *resbuf, embuf[100]; - ssize_t len; - char hook[NG_HOOKSIZ]; - struct datareg *d, *d1; - - if ((resbuf = malloc(resbufsiz + 1)) == NULL) { - stats[LEAF_begemotNgNoMems]++; - syslog(LOG_CRIT, "out of memory"); - (void)NgRecvData(fd, embuf, sizeof(embuf), hook); - errno = ENOMEM; - return; - } - if ((len = NgRecvData(fd, resbuf, resbufsiz + 1, hook)) == -1) { - stats[LEAF_begemotNgDataReadErrs]++; - syslog(LOG_ERR, "reading message: %m"); - free(resbuf); - return; - } - if (len == 0) { - free(resbuf); - return; - } - if ((size_t)len == resbufsiz + 1) { - stats[LEAF_begemotNgTooLargeDatas]++; - syslog(LOG_WARNING, "message too long"); - free(resbuf); - return; - } - - /* - * Dispatch message. Maybe dispatched to more than one function. - */ - d = SLIST_FIRST(&datareg_list); - while (d != NULL) { - d1 = SLIST_NEXT(d, link); - if (strcmp(hook, d->hook) == 0) - (*d->func)(hook, resbuf, len, d->arg); - d = d1; - } - - free(resbuf); -} - -/* - * The SNMP daemon is about to wait for an event. Look whether we have - * netgraph messages waiting. If yes, drain the queue. - */ -static void -ng_idle(void) -{ - struct csock_buf *b; - - /* execute waiting csock_bufs */ - while ((b = STAILQ_FIRST(&csock_bufs)) != NULL) { - STAILQ_REMOVE_HEAD(&csock_bufs, link); - csock_handle(b->mesg, b->path); - free(b); - } -} - -/* - * Called when the module is loaded. Returning a non-zero value means, - * rejecting the initialisation. - * - * We make the netgraph socket. - */ -static int -ng_init(struct lmodule *mod, int argc, char *argv[]) -{ - int name[2]; - size_t len; - - module = mod; - - if (argc == 0) { - if ((snmp_nodename = malloc(strlen(NODENAME) + 1)) == NULL) - return (ENOMEM); - strcpy(snmp_nodename, NODENAME); - } else { - if ((snmp_nodename = malloc(NG_NODESIZ)) == NULL) - return (ENOMEM); - strlcpy(snmp_nodename, argv[0], NG_NODESIZ); - } - - /* fetch clockinfo (for the number of microseconds per tick) */ - name[0] = CTL_KERN; - name[1] = KERN_CLOCKRATE; - len = sizeof(clockinfo); - if (sysctl(name, 2, &clockinfo, &len, NULL, 0) == -1) - return (errno); - - TAILQ_INIT(&ngtype_list); - - return (0); -} - -/* - * Get the node Id/name/type of a node. - */ -ng_ID_t -ng_node_id(const char *path) -{ - struct ng_mesg *resp; - ng_ID_t id; - - if ((resp = ng_dialog(path, NGM_GENERIC_COOKIE, NGM_NODEINFO, - NULL, 0)) == NULL) - return (0); - id = ((struct nodeinfo *)(void *)resp->data)->id; - free(resp); - return (id); -} -ng_ID_t -ng_node_id_node(const char *node) -{ - struct ng_mesg *resp; - ng_ID_t id; - - if ((resp = ng_dialog_node(node, NGM_GENERIC_COOKIE, NGM_NODEINFO, - NULL, 0)) == NULL) - return (0); - id = ((struct nodeinfo *)(void *)resp->data)->id; - free(resp); - return (id); -} -ng_ID_t -ng_node_name(ng_ID_t id, char *name) -{ - struct ng_mesg *resp; - - if ((resp = ng_dialog_id(id, NGM_GENERIC_COOKIE, NGM_NODEINFO, - NULL, 0)) == NULL) - return (0); - strcpy(name, ((struct nodeinfo *)(void *)resp->data)->name); - free(resp); - return (id); - -} -ng_ID_t -ng_node_type(ng_ID_t id, char *type) -{ - struct ng_mesg *resp; - - if ((resp = ng_dialog_id(id, NGM_GENERIC_COOKIE, NGM_NODEINFO, - NULL, 0)) == NULL) - return (0); - strcpy(type, ((struct nodeinfo *)(void *)resp->data)->type); - free(resp); - return (id); -} - -/* - * Connect our node to some other node - */ -int -ng_connect_node(const char *node, const char *ourhook, const char *peerhook) -{ - struct ngm_connect conn; - - snprintf(conn.path, NG_PATHSIZ, "%s:", node); - strlcpy(conn.ourhook, ourhook, NG_HOOKSIZ); - strlcpy(conn.peerhook, peerhook, NG_HOOKSIZ); - return (NgSendMsg(csock, ".:", - NGM_GENERIC_COOKIE, NGM_CONNECT, &conn, sizeof(conn))); -} -int -ng_connect_id(ng_ID_t id, const char *ourhook, const char *peerhook) -{ - struct ngm_connect conn; - - snprintf(conn.path, NG_PATHSIZ, "[%x]:", id); - strlcpy(conn.ourhook, ourhook, NG_HOOKSIZ); - strlcpy(conn.peerhook, peerhook, NG_HOOKSIZ); - return (NgSendMsg(csock, ".:", - NGM_GENERIC_COOKIE, NGM_CONNECT, &conn, sizeof(conn))); -} - -int -ng_connect2_id(ng_ID_t id, ng_ID_t peer, const char *ourhook, - const char *peerhook) -{ - struct ngm_connect conn; - char path[NG_PATHSIZ]; - - snprintf(path, NG_PATHSIZ, "[%x]:", id); - - snprintf(conn.path, NG_PATHSIZ, "[%x]:", peer); - strlcpy(conn.ourhook, ourhook, NG_HOOKSIZ); - strlcpy(conn.peerhook, peerhook, NG_HOOKSIZ); - return (NgSendMsg(csock, path, - NGM_GENERIC_COOKIE, NGM_CONNECT, &conn, sizeof(conn))); -} - -int -ng_connect2_tee_id(ng_ID_t id, ng_ID_t peer, const char *ourhook, - const char *peerhook) -{ - struct ngm_connect conn; - char path[NG_PATHSIZ]; - ng_ID_t tee; - - if ((tee = ng_mkpeer_id(id, NULL, "tee", ourhook, "left")) == 0) - return (-1); - - snprintf(path, NG_PATHSIZ, "[%x]:", tee); - - snprintf(conn.path, NG_PATHSIZ, "[%x]:", peer); - strlcpy(conn.ourhook, "right", NG_HOOKSIZ); - strlcpy(conn.peerhook, peerhook, NG_HOOKSIZ); - return (NgSendMsg(csock, path, - NGM_GENERIC_COOKIE, NGM_CONNECT, &conn, sizeof(conn))); -} - -/* - * Ensure that a node of type 'type' is connected to 'hook' of 'node' - * and return its node id. tee nodes between node and the target node - * are skipped. If the type is wrong, or the hook is a dead-end return 0. - * If type is NULL, it is not checked. - */ -static ng_ID_t -ng_next_node_id_internal(ng_ID_t node, const char *type, const char *hook, - int skip_tee) -{ - struct ng_mesg *resp; - struct hooklist *hooklist; - u_int i; - - if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, - NULL, 0)) == NULL) { - syslog(LOG_ERR, "get hook list: %m"); - exit(1); - } - hooklist = (struct hooklist *)(void *)resp->data; - - for (i = 0; i < hooklist->nodeinfo.hooks; i++) - if (strcmp(hooklist->link[i].ourhook, hook) == 0) - break; - - if (i == hooklist->nodeinfo.hooks) { - free(resp); - return (0); - } - - node = hooklist->link[i].nodeinfo.id; - - if (skip_tee && strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) { - if (strcmp(hooklist->link[i].peerhook, "left") == 0) - node = ng_next_node_id(node, type, "right"); - else if (strcmp(hooklist->link[i].peerhook, "right") == 0) - node = ng_next_node_id(node, type, "left"); - else if (type != NULL && - strcmp(hooklist->link[i].nodeinfo.type, type) != 0) - node = 0; - - } else if (type != NULL && - strcmp(hooklist->link[i].nodeinfo.type, type) != 0) - node = 0; - - free(resp); - - return (node); -} - -/* - * Ensure that a node of type 'type' is connected to 'hook' of 'node' - * and return its node id. tee nodes between node and the target node - * are skipped. If the type is wrong, or the hook is a dead-end return 0. - * If type is NULL, it is not checked. - */ -ng_ID_t -ng_next_node_id(ng_ID_t node, const char *type, const char *hook) -{ - return (ng_next_node_id_internal(node, type, hook, 1)); -} - -ng_ID_t -ng_mkpeer_id(ng_ID_t id, const char *nodename, const char *type, - const char *hook, const char *peerhook) -{ - char path[NG_PATHSIZ]; - struct ngm_mkpeer mkpeer; - struct ngm_name name; - - strlcpy(mkpeer.type, type, NG_TYPESIZ); - strlcpy(mkpeer.ourhook, hook, NG_HOOKSIZ); - strlcpy(mkpeer.peerhook, peerhook, NG_HOOKSIZ); - - sprintf(path, "[%x]:", id); - if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_MKPEER, - &mkpeer, sizeof(mkpeer)) == -1) - return (0); - - if ((id = ng_next_node_id_internal(id, NULL, hook, 0)) == 0) - return (0); - - if (nodename != NULL) { - strcpy(name.name, nodename); - sprintf(path, "[%x]:", id); - if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_NAME, - &name, sizeof(name)) == -1) - return (0); - } - return (id); -} - -/* - * SHutdown node - */ -int -ng_shutdown_id(ng_ID_t id) -{ - char path[NG_PATHSIZ]; - - snprintf(path, NG_PATHSIZ, "[%x]:", id); - return (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, - NGM_SHUTDOWN, NULL, 0)); -} - -/* - * Disconnect one of our hooks - */ -int -ng_rmhook(const char *ourhook) -{ - struct ngm_rmhook rmhook; - - strlcpy(rmhook.ourhook, ourhook, NG_HOOKSIZ); - return (NgSendMsg(csock, ".:", - NGM_GENERIC_COOKIE, NGM_RMHOOK, &rmhook, sizeof(rmhook))); -} - -/* - * Disconnect a hook of a node - */ -int -ng_rmhook_id(ng_ID_t id, const char *hook) -{ - struct ngm_rmhook rmhook; - char path[NG_PATHSIZ]; - - strlcpy(rmhook.ourhook, hook, NG_HOOKSIZ); - snprintf(path, NG_PATHSIZ, "[%x]:", id); - return (NgSendMsg(csock, path, - NGM_GENERIC_COOKIE, NGM_RMHOOK, &rmhook, sizeof(rmhook))); -} - -/* - * Disconnect a hook and shutdown all tee nodes that were connected to that - * hook. - */ -int -ng_rmhook_tee_id(ng_ID_t node, const char *hook) -{ - struct ng_mesg *resp; - struct hooklist *hooklist; - u_int i; - int first = 1; - ng_ID_t next_node; - const char *next_hook; - - again: - /* if we have just shutdown a tee node, which had no other hooks - * connected, the node id may already be wrong here. */ - if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, - NULL, 0)) == NULL) - return (0); - - hooklist = (struct hooklist *)(void *)resp->data; - - for (i = 0; i < hooklist->nodeinfo.hooks; i++) - if (strcmp(hooklist->link[i].ourhook, hook) == 0) - break; - - if (i == hooklist->nodeinfo.hooks) { - free(resp); - return (0); - } - - next_node = 0; - next_hook = NULL; - if (strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) { - if (strcmp(hooklist->link[i].peerhook, "left") == 0) { - next_node = hooklist->link[i].nodeinfo.id; - next_hook = "right"; - } else if (strcmp(hooklist->link[i].peerhook, "right") == 0) { - next_node = hooklist->link[i].nodeinfo.id; - next_hook = "left"; - } - } - free(resp); - - if (first) { - ng_rmhook_id(node, hook); - first = 0; - } else { - ng_shutdown_id(node); - } - if ((node = next_node) == 0) - return (0); - hook = next_hook; - - goto again; -} - -/* - * Get the peer hook of a hook on a given node. Skip any tee nodes in between - */ -int -ng_peer_hook_id(ng_ID_t node, const char *hook, char *peerhook) -{ - struct ng_mesg *resp; - struct hooklist *hooklist; - u_int i; - int ret; - - if ((resp = ng_dialog_id(node, NGM_GENERIC_COOKIE, NGM_LISTHOOKS, - NULL, 0)) == NULL) { - syslog(LOG_ERR, "get hook list: %m"); - exit(1); - } - hooklist = (struct hooklist *)(void *)resp->data; - - for (i = 0; i < hooklist->nodeinfo.hooks; i++) - if (strcmp(hooklist->link[i].ourhook, hook) == 0) - break; - - if (i == hooklist->nodeinfo.hooks) { - free(resp); - return (-1); - } - - node = hooklist->link[i].nodeinfo.id; - - ret = 0; - if (strcmp(hooklist->link[i].nodeinfo.type, "tee") == 0) { - if (strcmp(hooklist->link[i].peerhook, "left") == 0) - ret = ng_peer_hook_id(node, "right", peerhook); - else if (strcmp(hooklist->link[i].peerhook, "right") == 0) - ret = ng_peer_hook_id(node, "left", peerhook); - else - strcpy(peerhook, hooklist->link[i].peerhook); - - } else - strcpy(peerhook, hooklist->link[i].peerhook); - - free(resp); - - return (ret); -} - - -/* - * Now the module is started. Select on the sockets, so that we can get - * unsolicited input. - */ -static void -ng_start(void) -{ - if (snmp_node == 0) { - if (NgMkSockNode(snmp_nodename, &csock, &dsock) < 0) { - syslog(LOG_ERR, "NgMkSockNode: %m"); - exit(1); - } - snmp_node = ng_node_id(".:"); - } - - if ((csock_fd = fd_select(csock, csock_input, NULL, module)) == NULL) { - syslog(LOG_ERR, "fd_select failed on csock: %m"); - return; - } - if ((dsock_fd = fd_select(dsock, dsock_input, NULL, module)) == NULL) { - syslog(LOG_ERR, "fd_select failed on dsock: %m"); - return; - } - - reg_index = or_register(&oid_begemotNg, - "The MIB for the NetGraph access module for SNMP.", module); -} - -/* - * Called, when the module is to be unloaded after it was successfully loaded - */ -static int -ng_fini(void) -{ - struct ngtype *t; - - while ((t = TAILQ_FIRST(&ngtype_list)) != NULL) { - TAILQ_REMOVE(&ngtype_list, t, link); - free(t); - } - - if (csock_fd != NULL) - fd_deselect(csock_fd); - (void)close(csock); - - if (dsock_fd != NULL) - fd_deselect(dsock_fd); - (void)close(dsock); - - free(snmp_nodename); - - or_unregister(reg_index); - - return (0); -} - -const struct snmp_module config = { - "This module implements access to the netgraph sub-system", - ng_init, - ng_fini, - ng_idle, - NULL, - NULL, - ng_start, - NULL, - netgraph_ctree, - netgraph_CTREE_SIZE, - NULL -}; - -int -op_ng_config(struct snmp_context *ctx, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op op) -{ - asn_subid_t which = value->var.subs[sub - 1]; - int ret; - - switch (op) { - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_GET: - /* - * Come here for GET, GETNEXT and COMMIT - */ - switch (which) { - - case LEAF_begemotNgControlNodeName: - return (string_get(value, snmp_nodename, -1)); - - case LEAF_begemotNgResBufSiz: - value->v.integer = resbufsiz; - break; - - case LEAF_begemotNgTimeout: - value->v.integer = timeout; - break; - - case LEAF_begemotNgDebugLevel: - value->v.uint32 = debug_level; - break; - - default: - abort(); - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_SET: - switch (which) { - - case LEAF_begemotNgControlNodeName: - /* only at initialisation */ - if (community != COMM_INITIALIZE) - return (SNMP_ERR_NOT_WRITEABLE); - - if (snmp_node != 0) - return (SNMP_ERR_NOT_WRITEABLE); - - if ((ret = string_save(value, ctx, -1, &snmp_nodename)) - != SNMP_ERR_NOERROR) - return (ret); - - if (NgMkSockNode(snmp_nodename, &csock, &dsock) < 0) { - syslog(LOG_ERR, "NgMkSockNode: %m"); - string_rollback(ctx, &snmp_nodename); - return (SNMP_ERR_GENERR); - } - snmp_node = ng_node_id(".:"); - - return (SNMP_ERR_NOERROR); - - case LEAF_begemotNgResBufSiz: - ctx->scratch->int1 = resbufsiz; - if (value->v.integer < 1024 || - value->v.integer > 0x10000) - return (SNMP_ERR_WRONG_VALUE); - resbufsiz = value->v.integer; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotNgTimeout: - ctx->scratch->int1 = timeout; - if (value->v.integer < 10 || - value->v.integer > 10000) - return (SNMP_ERR_WRONG_VALUE); - timeout = value->v.integer; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotNgDebugLevel: - ctx->scratch->int1 = debug_level; - debug_level = value->v.uint32; - NgSetDebug(debug_level); - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_ROLLBACK: - switch (which) { - - case LEAF_begemotNgControlNodeName: - string_rollback(ctx, &snmp_nodename); - close(csock); - close(dsock); - snmp_node = 0; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotNgResBufSiz: - resbufsiz = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotNgTimeout: - timeout = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - case LEAF_begemotNgDebugLevel: - debug_level = ctx->scratch->int1; - NgSetDebug(debug_level); - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_COMMIT: - switch (which) { - - case LEAF_begemotNgControlNodeName: - string_commit(ctx); - return (SNMP_ERR_NOERROR); - - case LEAF_begemotNgResBufSiz: - case LEAF_begemotNgTimeout: - case LEAF_begemotNgDebugLevel: - return (SNMP_ERR_NOERROR); - } - abort(); - } - abort(); -} - -int -op_ng_stats(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op op) -{ - switch (op) { - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_GET: - value->v.uint32 = stats[value->var.subs[sub - 1] - 1]; - return (SNMP_ERR_NOERROR); - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - abort(); - } - abort(); -} - -/* - * Netgraph type table - */ -static int -fetch_types(void) -{ - struct ngtype *t; - struct typelist *typelist; - struct ng_mesg *resp; - u_int u, i; - - if (this_tick <= ngtype_tick) - return (0); - - while ((t = TAILQ_FIRST(&ngtype_list)) != NULL) { - TAILQ_REMOVE(&ngtype_list, t, link); - free(t); - } - - if ((resp = ng_dialog_id(snmp_node, NGM_GENERIC_COOKIE, - NGM_LISTTYPES, NULL, 0)) == NULL) - return (SNMP_ERR_GENERR); - typelist = (struct typelist *)(void *)resp->data; - - for (u = 0; u < typelist->numtypes; u++) { - if ((t = malloc(sizeof(*t))) == NULL) { - free(resp); - return (SNMP_ERR_GENERR); - } - strcpy(t->name, typelist->typeinfo[u].type_name); - t->index.subs[0] = strlen(t->name); - t->index.len = t->index.subs[0] + 1; - for (i = 0; i < t->index.subs[0]; i++) - t->index.subs[i + 1] = t->name[i]; - - INSERT_OBJECT_OID(t, &ngtype_list); - } - - ngtype_tick = this_tick; - - free(resp); - return (0); -} - -/* - * Try to load the netgraph type with the given name. We assume, that - * type 'type' is implemented in the kernel module 'ng_type'. - */ -static int -ngtype_load(const u_char *name, size_t namelen) -{ - char *mod; - int ret; - - if ((mod = malloc(namelen + 4)) == NULL) - return (-1); - strcpy(mod, "ng_"); - strncpy(mod + 3, name, namelen); - mod[namelen + 3] = '\0'; - - ret = kldload(mod); - free(mod); - return (ret); -} - -/* - * Unload a netgraph type. - */ -static int -ngtype_unload(const u_char *name, size_t namelen) -{ - char *mod; - int id; - - if ((mod = malloc(namelen + 4)) == NULL) - return (-1); - strcpy(mod, "ng_"); - strncpy(mod + 3, name, namelen); - mod[namelen + 3] = '\0'; - - if ((id = kldfind(mod)) == -1) { - free(mod); - return (-1); - } - free(mod); - return (kldunload(id)); -} - -int -op_ng_type(struct snmp_context *ctx, struct snmp_value *value, - u_int sub, u_int iidx, enum snmp_op op) -{ - asn_subid_t which = value->var.subs[sub - 1]; - struct ngtype *t; - u_char *name; - size_t namelen; - int status = 1; - int ret; - - switch (op) { - - case SNMP_OP_GETNEXT: - if ((ret = fetch_types()) != 0) - return (ret); - if ((t = NEXT_OBJECT_OID(&ngtype_list, &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - index_append(&value->var, sub, &t->index); - break; - - case SNMP_OP_GET: - if ((ret = fetch_types()) != 0) - return (ret); - if ((t = FIND_OBJECT_OID(&ngtype_list, &value->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_SET: - if (index_decode(&value->var, sub, iidx, &name, &namelen)) - return (SNMP_ERR_NO_CREATION); - if (namelen == 0 || namelen >= NG_TYPESIZ) { - free(name); - return (SNMP_ERR_NO_CREATION); - } - if ((ret = fetch_types()) != 0) { - free(name); - return (ret); - } - t = FIND_OBJECT_OID(&ngtype_list, &value->var, sub); - - if (which != LEAF_begemotNgTypeStatus) { - free(name); - if (t != NULL) - return (SNMP_ERR_NOT_WRITEABLE); - return (SNMP_ERR_NO_CREATION); - } - if (!TRUTH_OK(value->v.integer)) { - free(name); - return (SNMP_ERR_WRONG_VALUE); - } - ctx->scratch->int1 = TRUTH_GET(value->v.integer); - ctx->scratch->int1 |= (t != NULL) << 1; - ctx->scratch->ptr2 = name; - ctx->scratch->int2 = namelen; - - if (t == NULL) { - /* type not loaded */ - if (ctx->scratch->int1 & 1) { - /* request to load */ - if (ngtype_load(name, namelen) == -1) { - free(name); - if (errno == ENOENT) - return (SNMP_ERR_INCONS_NAME); - else - return (SNMP_ERR_GENERR); - } - } - } else { - /* is type loaded */ - if (!(ctx->scratch->int1 & 1)) { - /* request to unload */ - if (ngtype_unload(name, namelen) == -1) { - free(name); - return (SNMP_ERR_GENERR); - } - } - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - ret = SNMP_ERR_NOERROR; - if (!(ctx->scratch->int1 & 2)) { - /* did not exist */ - if (ctx->scratch->int1 & 1) { - /* request to load - unload */ - if (ngtype_unload(ctx->scratch->ptr2, - ctx->scratch->int2) == -1) - ret = SNMP_ERR_UNDO_FAILED; - } - } else { - /* did exist */ - if (!(ctx->scratch->int1 & 1)) { - /* request to unload - reload */ - if (ngtype_load(ctx->scratch->ptr2, - ctx->scratch->int2) == -1) - ret = SNMP_ERR_UNDO_FAILED; - } - } - free(ctx->scratch->ptr2); - return (ret); - - case SNMP_OP_COMMIT: - free(ctx->scratch->ptr2); - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - /* - * Come here for GET and COMMIT - */ - switch (which) { - - case LEAF_begemotNgTypeStatus: - value->v.integer = status; - break; - - default: - abort(); - } - return (SNMP_ERR_NOERROR); -} - -/* - * Implement the node table - */ -static int -find_node(const struct asn_oid *oid, u_int sub, struct nodeinfo *info) -{ - ng_ID_t id = oid->subs[sub]; - struct ng_mesg *resp; - - if ((resp = ng_dialog_id(id, NGM_GENERIC_COOKIE, NGM_NODEINFO, - NULL, 0)) == NULL) - return (-1); - - *info = *(struct nodeinfo *)(void *)resp->data; - free(resp); - return (0); -} - -static int -ncmp(const void *p1, const void *p2) -{ - const struct nodeinfo *i1 = p1; - const struct nodeinfo *i2 = p2; - - if (i1->id < i2->id) - return (-1); - if (i1->id > i2->id) - return (+1); - return (0); -} - -static int -find_node_next(const struct asn_oid *oid, u_int sub, struct nodeinfo *info) -{ - u_int idxlen = oid->len - sub; - struct ng_mesg *resp; - struct namelist *list; - ng_ID_t id; - u_int i; - - if ((resp = ng_dialog_id(snmp_node, NGM_GENERIC_COOKIE, NGM_LISTNODES, - NULL, 0)) == NULL) - return (-1); - list = (struct namelist *)(void *)resp->data; - - qsort(list->nodeinfo, list->numnames, sizeof(list->nodeinfo[0]), ncmp); - - if (idxlen == 0) { - if (list->numnames == 0) { - free(resp); - return (-1); - } - *info = list->nodeinfo[0]; - free(resp); - return (0); - } - id = oid->subs[sub]; - - for (i = 0; i < list->numnames; i++) - if (list->nodeinfo[i].id > id) { - *info = list->nodeinfo[i]; - free(resp); - return (0); - } - - free(resp); - return (-1); -} - -int -op_ng_node(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx __unused, enum snmp_op op) -{ - asn_subid_t which = value->var.subs[sub - 1]; - u_int idxlen = value->var.len - sub; - struct nodeinfo nodeinfo; - - switch (op) { - - case SNMP_OP_GETNEXT: - if (find_node_next(&value->var, sub, &nodeinfo) == -1) - return (SNMP_ERR_NOSUCHNAME); - value->var.len = sub + 1; - value->var.subs[sub] = nodeinfo.id; - break; - - case SNMP_OP_GET: - if (idxlen != 1) - return (SNMP_ERR_NOSUCHNAME); - if (find_node(&value->var, sub, &nodeinfo) == -1) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_SET: - if (idxlen != 1) - return (SNMP_ERR_NO_CREATION); - if (find_node(&value->var, sub, &nodeinfo) == -1) - return (SNMP_ERR_NO_CREATION); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - default: - abort(); - } - - /* - * Come here for GET and COMMIT - */ - switch (which) { - - case LEAF_begemotNgNodeStatus: - value->v.integer = 1; - break; - case LEAF_begemotNgNodeName: - return (string_get(value, nodeinfo.name, -1)); - case LEAF_begemotNgNodeType: - return (string_get(value, nodeinfo.type, -1)); - case LEAF_begemotNgNodeHooks: - value->v.uint32 = nodeinfo.hooks; - break; - - default: - abort(); - } - return (SNMP_ERR_NOERROR); -} - -/* - * Implement the hook table - */ -static int -find_hook(int32_t id, const u_char *hook, size_t hooklen, struct linkinfo *info) -{ - struct ng_mesg *resp; - struct hooklist *list; - u_int i; - - if ((resp = ng_dialog_id(id, NGM_GENERIC_COOKIE, - NGM_LISTHOOKS, NULL, 0)) == NULL) - return (-1); - - list = (struct hooklist *)(void *)resp->data; - - for (i = 0; i < list->nodeinfo.hooks; i++) { - if (strlen(list->link[i].ourhook) == hooklen && - strncmp(list->link[i].ourhook, hook, hooklen) == 0) { - *info = list->link[i]; - free(resp); - return (0); - } - } - free(resp); - return (-1); -} - -static int -hook_cmp(const void *p1, const void *p2) -{ - const struct linkinfo *i1 = p1; - const struct linkinfo *i2 = p2; - - if (strlen(i1->ourhook) < strlen(i2->ourhook)) - return (-1); - if (strlen(i1->ourhook) > strlen(i2->ourhook)) - return (+1); - return (strcmp(i1->ourhook, i2->ourhook)); -} - -static int -find_hook_next(const struct asn_oid *oid, u_int sub, struct nodeinfo *nodeinfo, - struct linkinfo *linkinfo) -{ - u_int idxlen = oid->len - sub; - struct namelist *list; - struct ng_mesg *resp; - struct hooklist *hooks; - struct ng_mesg *resp1; - u_int node_index; - struct asn_oid idx; - u_int i, j; - - /* - * Get and sort Node list - */ - if ((resp = ng_dialog_id(snmp_node, NGM_GENERIC_COOKIE, NGM_LISTNODES, - NULL, 0)) == NULL) - return (-1); - list = (struct namelist *)(void *)resp->data; - - qsort(list->nodeinfo, list->numnames, sizeof(list->nodeinfo[0]), ncmp); - - /* - * If we have no index, take the first node and return the - * first hook. - */ - if (idxlen == 0) { - node_index = 0; - goto return_first_hook; - } - - /* - * Locate node - */ - for (node_index = 0; node_index < list->numnames; node_index++) - if (list->nodeinfo[node_index].id >= oid->subs[sub]) - break; - - /* - * If we have only the node part of the index take, or - * there is no node with that Id, take the first hook of that node. - */ - if (idxlen == 1 || node_index >= list->numnames || - list->nodeinfo[node_index].id > oid->subs[sub]) - goto return_first_hook; - - /* - * We had an exact match on the node id and have (at last part) - * of the hook name index. Loop through the hooks of the node - * and find the next one. - */ - if ((resp1 = ng_dialog_id(list->nodeinfo[node_index].id, - NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0)) == NULL) { - free(resp); - return (-1); - } - hooks = (struct hooklist *)(void *)resp1->data; - if (hooks->nodeinfo.hooks > 0) { - qsort(hooks->link, hooks->nodeinfo.hooks, - sizeof(hooks->link[0]), hook_cmp); - for (i = 0; i < hooks->nodeinfo.hooks; i++) { - idx.len = strlen(hooks->link[i].ourhook) + 1; - idx.subs[0] = idx.len - 1; - for (j = 0; j < idx.len; j++) - idx.subs[j + 1] = hooks->link[i].ourhook[j]; - if (index_compare(oid, sub + 1, &idx) < 0) - break; - } - if (i < hooks->nodeinfo.hooks) { - *nodeinfo = hooks->nodeinfo; - *linkinfo = hooks->link[i]; - - free(resp); - free(resp1); - return (0); - } - } - - /* no hook found larger than the index on the index node - take - * first hook of next node */ - free(resp1); - node_index++; - - return_first_hook: - while (node_index < list->numnames) { - if ((resp1 = ng_dialog_id(list->nodeinfo[node_index].id, - NGM_GENERIC_COOKIE, NGM_LISTHOOKS, NULL, 0)) == NULL) - break; - hooks = (struct hooklist *)(void *)resp1->data; - if (hooks->nodeinfo.hooks > 0) { - qsort(hooks->link, hooks->nodeinfo.hooks, - sizeof(hooks->link[0]), hook_cmp); - - *nodeinfo = hooks->nodeinfo; - *linkinfo = hooks->link[0]; - - free(resp); - free(resp1); - return (0); - } - - /* if we don't have hooks, try next node */ - free(resp1); - node_index++; - } - - free(resp); - return (-1); -} - -int -op_ng_hook(struct snmp_context *ctx __unused, struct snmp_value *value, - u_int sub, u_int iidx, enum snmp_op op) -{ - asn_subid_t which = value->var.subs[sub - 1]; - struct linkinfo linkinfo; - struct nodeinfo nodeinfo; - u_int32_t lid; - u_char *hook; - size_t hooklen; - u_int i; - - switch (op) { - - case SNMP_OP_GETNEXT: - if (find_hook_next(&value->var, sub, &nodeinfo, &linkinfo) == -1) - return (SNMP_ERR_NOSUCHNAME); - - value->var.len = sub + 1 + 1 + strlen(linkinfo.ourhook); - value->var.subs[sub] = nodeinfo.id; - value->var.subs[sub + 1] = strlen(linkinfo.ourhook); - for (i = 0; i < strlen(linkinfo.ourhook); i++) - value->var.subs[sub + i + 2] = - linkinfo.ourhook[i]; - break; - - case SNMP_OP_GET: - if (index_decode(&value->var, sub, iidx, &lid, - &hook, &hooklen)) - return (SNMP_ERR_NOSUCHNAME); - if (find_hook(lid, hook, hooklen, &linkinfo) == -1) { - free(hook); - return (SNMP_ERR_NOSUCHNAME); - } - free(hook); - break; - - case SNMP_OP_SET: - if (index_decode(&value->var, sub, iidx, &lid, - &hook, &hooklen)) - return (SNMP_ERR_NO_CREATION); - if (find_hook(lid, hook, hooklen, &linkinfo) == -1) { - free(hook); - return (SNMP_ERR_NO_CREATION); - } - free(hook); - return (SNMP_ERR_NOT_WRITEABLE); - - case SNMP_OP_ROLLBACK: - case SNMP_OP_COMMIT: - default: - abort(); - - } - - switch (which) { - - case LEAF_begemotNgHookStatus: - value->v.integer = 1; - break; - case LEAF_begemotNgHookPeerNodeId: - value->v.uint32 = linkinfo.nodeinfo.id; - break; - case LEAF_begemotNgHookPeerHook: - return (string_get(value, linkinfo.peerhook, -1)); - case LEAF_begemotNgHookPeerType: - return (string_get(value, linkinfo.nodeinfo.type, -1)); - default: - abort(); - } - return (SNMP_ERR_NOERROR); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.h b/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.h deleted file mode 100644 index 21e553c..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_netgraph/snmp_netgraph.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2001-2003 - * Fraunhofer Institute for Open Communication Systems (FhG Fokus). - * All rights reserved. - * - * Author: Harti Brandt - * - * Redistribution of this software and documentation and use in source and - * binary forms, with or without modification, are permitted provided that - * the following conditions are met: - * - * 1. Redistributions of source code or documentation must retain the above - * copyright notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS - * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * FRAUNHOFER FOKUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, - * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - * - * Netgraph interface for SNMPd. Exported stuff. - */ -#ifndef SNMP_NETGRAPH_H_ -#define SNMP_NETGRAPH_H_ - -#include - -extern ng_ID_t snmp_node; -extern u_char *snmp_nodename; - -typedef void ng_cookie_f(const struct ng_mesg *, const char *, ng_ID_t, void *); -typedef void ng_hook_f(const char *, const u_char *, size_t, void *); - -void *ng_register_cookie(const struct lmodule *, u_int32_t cookie, - ng_ID_t, ng_cookie_f *, void *); -void ng_unregister_cookie(void *reg); - -void *ng_register_hook(const struct lmodule *, const char *, - ng_hook_f *, void *); -void ng_unregister_hook(void *reg); - -void ng_unregister_module(const struct lmodule *); - -int ng_output(const char *path, u_int cookie, u_int opcode, - const void *arg, size_t arglen); -int ng_output_node(const char *node, u_int cookie, u_int opcode, - const void *arg, size_t arglen); -int ng_output_id(ng_ID_t node, u_int cookie, u_int opcode, - const void *arg, size_t arglen); - -struct ng_mesg *ng_dialog(const char *path, u_int cookie, u_int opcode, - const void *arg, size_t arglen); -struct ng_mesg *ng_dialog_node(const char *node, u_int cookie, u_int opcode, - const void *arg, size_t arglen); -struct ng_mesg *ng_dialog_id(ng_ID_t id, u_int cookie, u_int opcode, - const void *arg, size_t arglen); - -int ng_send_data(const char *hook, const void *sndbuf, size_t sndlen); - -ng_ID_t ng_mkpeer_id(ng_ID_t, const char *name, const char *type, - const char *hook, const char *peerhook); -int ng_connect_node(const char *node, const char *ourhook, const char *peerhook); -int ng_connect_id(ng_ID_t id, const char *ourhook, const char *peerhook); -int ng_connect2_id(ng_ID_t id, ng_ID_t peer, const char *ourhook, - const char *peerhook); -int ng_connect2_tee_id(ng_ID_t id, ng_ID_t peer, const char *ourhook, - const char *peerhook); -int ng_rmhook(const char *ourhook); -int ng_rmhook_id(ng_ID_t, const char *); -int ng_rmhook_tee_id(ng_ID_t, const char *); -int ng_shutdown_id(ng_ID_t); - -ng_ID_t ng_next_node_id(ng_ID_t node, const char *type, const char *hook); -ng_ID_t ng_node_id(const char *path); -ng_ID_t ng_node_id_node(const char *node); -ng_ID_t ng_node_name(ng_ID_t, char *); -ng_ID_t ng_node_type(ng_ID_t, char *); -int ng_peer_hook_id(ng_ID_t, const char *, char *); - -#endif diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt deleted file mode 100644 index 0b90bb2..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_pf/BEGEMOT-PF-MIB.txt +++ /dev/null @@ -1,1347 +0,0 @@ --- --- ---------------------------------------------------------------------------- --- "THE BEER-WARE LICENSE" (Revision 42): --- wrote this file. As long as you retain this notice you --- can do whatever you want with this stuff. If we meet some day, and you think --- this stuff is worth it, you can buy me a beer in return. -Philip Paeps --- ---------------------------------------------------------------------------- --- --- $FreeBSD$ --- - -BEGEMOT-PF-MIB DEFINITIONS ::= BEGIN - -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE, Counter64, Integer32, - TimeTicks, Unsigned32 - FROM SNMPv2-SMI - TruthValue - FROM SNMPv2-TC - InetAddress, InetAddressType, InetAddressPrefixLength - FROM INET-ADDRESS-MIB - begemot - FROM BEGEMOT-MIB; - -begemotPf MODULE-IDENTITY - LAST-UPDATED "201003180000Z" - ORGANIZATION "NixSys BVBA" - CONTACT-INFO - " Philip Paeps - - Postal: NixSys BVBA - Louizastraat 14 - BE-2800 Mechelen - Belgium - - E-Mail: philip@FreeBSD.org" - DESCRIPTION - "The Begemot MIB for the pf packet filter." - REVISION "201003180000Z" - DESCRIPTION - "Modified pfTablesAddrEntry to support IPv6 - addresses - added pfTablesAddrNetType column - and modified type of pfTablesAddrNet to - InetAddress." - REVISION "200912050000Z" - DESCRIPTION - "Added support for retrieving counters of labeled - pf filter rules via pfLabelspfLabels subtree." - REVISION "200501240000Z" - DESCRIPTION - "Initial revision." - - ::= { begemot 200 } - -begemotPfObjects OBJECT IDENTIFIER ::= { begemotPf 1 } - --- -------------------------------------------------------------------------- - -pfStatus OBJECT IDENTIFIER ::= { begemotPfObjects 1 } -pfCounter OBJECT IDENTIFIER ::= { begemotPfObjects 2 } -pfStateTable OBJECT IDENTIFIER ::= { begemotPfObjects 3 } -pfSrcNodes OBJECT IDENTIFIER ::= { begemotPfObjects 4 } -pfLimits OBJECT IDENTIFIER ::= { begemotPfObjects 5 } -pfTimeouts OBJECT IDENTIFIER ::= { begemotPfObjects 6 } -pfLogInterface OBJECT IDENTIFIER ::= { begemotPfObjects 7 } -pfInterfaces OBJECT IDENTIFIER ::= { begemotPfObjects 8 } -pfTables OBJECT IDENTIFIER ::= { begemotPfObjects 9 } -pfAltq OBJECT IDENTIFIER ::= { begemotPfObjects 10 } -pfLabels OBJECT IDENTIFIER ::= { begemotPfObjects 11 } - --- -------------------------------------------------------------------------- - --- --- status information --- - -pfStatusRunning OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "True if pf is currently enabled." - ::= { pfStatus 1 } - -pfStatusRuntime OBJECT-TYPE - SYNTAX TimeTicks - UNITS "1/100th of a Second" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Indicates how long pf has been enabled. If pf is not currently - enabled, indicates how long it has been disabled. If pf has not - been enabled or disabled since the system was started, the value - will be 0." - ::= { pfStatus 2 } - -pfStatusDebug OBJECT-TYPE - SYNTAX INTEGER { none(0), urgent(1), misc(2), loud(3) } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Indicates the debug level at which pf is running." - ::= { pfStatus 3 } - -pfStatusHostId OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The (unique) host identifier of the machine running pf." - ::= { pfStatus 4 } - --- -------------------------------------------------------------------------- - --- --- counters --- - -pfCounterMatch OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of packets that matched a filter rule." - ::= { pfCounter 1 } - -pfCounterBadOffset OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of packets with bad offset." - ::= { pfCounter 2 } - -pfCounterFragment OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of fragmented packets." - ::= { pfCounter 3 } - -pfCounterShort OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of short packets." - ::= { pfCounter 4 } - -pfCounterNormalize OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of normalized packets." - ::= { pfCounter 5 } - -pfCounterMemDrop OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of packets dropped due to memory limitations." - ::= { pfCounter 6 } - --- -------------------------------------------------------------------------- - --- --- state table --- - -pfStateTableCount OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of entries in the state table." - ::= { pfStateTable 1 } - -pfStateTableSearches OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of searches against the state table." - ::= { pfStateTable 2 } - -pfStateTableInserts OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of entries inserted into the state table." - ::= { pfStateTable 3 } - -pfStateTableRemovals OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of entries removed from the state table." - ::= { pfStateTable 4 } - --- -------------------------------------------------------------------------- - --- --- source nodes --- - -pfSrcNodesCount OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of entries in the source tracking table." - ::= { pfSrcNodes 1 } - -pfSrcNodesSearches OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of searches against the source tracking table." - ::= { pfSrcNodes 2 } - -pfSrcNodesInserts OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of entries inserted into the source tracking table." - ::= { pfSrcNodes 3 } - -pfSrcNodesRemovals OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of entries removed from the source tracking table." - ::= { pfSrcNodes 4 } - --- -------------------------------------------------------------------------- - --- --- limits --- - -pfLimitsStates OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Maximum number of 'keep state' rules in the ruleset." - ::= { pfLimits 1 } - -pfLimitsSrcNodes OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Maximum number of 'sticky-address' or 'source-track' rules - in the ruleset." - ::= { pfLimits 2 } - -pfLimitsFrags OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Maximum number of 'scrub' rules in the ruleset." - ::= { pfLimits 3 } - --- -------------------------------------------------------------------------- - --- --- timeouts --- - -pfTimeoutsTcpFirst OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after the first packet in a connection." - ::= { pfTimeouts 1 } - -pfTimeoutsTcpOpening OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State before the destination host ever sends a packet." - ::= { pfTimeouts 2 } - -pfTimeoutsTcpEstablished OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The fully established state." - ::= { pfTimeouts 3 } - -pfTimeoutsTcpClosing OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after the first FIN has been sent." - ::= { pfTimeouts 4 } - -pfTimeoutsTcpFinWait OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after both FINs have been exchanged and the - connection is closed." - ::= { pfTimeouts 5 } - -pfTimeoutsTcpClosed OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after one endpoint sends an RST." - ::= { pfTimeouts 6 } - -pfTimeoutsUdpFirst OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after the first packet." - ::= { pfTimeouts 7 } - -pfTimeoutsUdpSingle OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State if the source host sends more than one packet but - the destination host has never sent one back." - ::= { pfTimeouts 8 } - -pfTimeoutsUdpMultiple OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State if both hosts have sent packets." - ::= { pfTimeouts 9 } - -pfTimeoutsIcmpFirst OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after the first packet." - ::= { pfTimeouts 10 } - -pfTimeoutsIcmpError OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after an ICMP error came back in response to an - ICMP packet." - ::= { pfTimeouts 11 } - -pfTimeoutsOtherFirst OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State after the first packet." - ::= { pfTimeouts 12 } - -pfTimeoutsOtherSingle OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State if the source host sends more than one packet but - the destination host has never sent one back." - ::= { pfTimeouts 13 } - -pfTimeoutsOtherMultiple OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "State if both hosts have sent packets." - ::= { pfTimeouts 14 } - -pfTimeoutsFragment OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Seconds before an unassembled fragment is expired." - ::= { pfTimeouts 15 } - -pfTimeoutsInterval OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Interval between purging expired states and fragments." - ::= { pfTimeouts 16 } - -pfTimeoutsAdaptiveStart OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "When the number of state entries exceeds this value, - adaptive scaling begins." - ::= { pfTimeouts 17 } - -pfTimeoutsAdaptiveEnd OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "When reaching this number of state entries, all timeout - values become zero, effectively purging all state entries - immediately." - ::= { pfTimeouts 18 } - -pfTimeoutsSrcNode OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Length of time to retain a source tracking entry after - the last state expires." - ::= { pfTimeouts 19 } - --- -------------------------------------------------------------------------- - --- --- log interface --- - -pfLogInterfaceName OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The name of the interface configured with 'set loginterface'. - If no interface has been configured, the object will be empty." - ::= { pfLogInterface 1 } - -pfLogInterfaceIp4BytesIn OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv4 bytes passed in on the loginterface." - ::= { pfLogInterface 2 } - -pfLogInterfaceIp4BytesOut OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv4 bytes passed out on the loginterface." - ::= { pfLogInterface 3 } - -pfLogInterfaceIp4PktsInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv4 packets passed in on the loginterface." - ::= { pfLogInterface 4 } - -pfLogInterfaceIp4PktsInDrop OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv4 packets dropped coming in on the loginterface." - ::= { pfLogInterface 5 } - -pfLogInterfaceIp4PktsOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv4 packets passed out on the loginterface." - ::= { pfLogInterface 6 } - -pfLogInterfaceIp4PktsOutDrop OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv4 packets dropped going out on the loginterface." - ::= { pfLogInterface 7 } - -pfLogInterfaceIp6BytesIn OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv6 bytes passed in on the loginterface." - ::= { pfLogInterface 8 } - -pfLogInterfaceIp6BytesOut OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv6 bytes passed out on the loginterface." - ::= { pfLogInterface 9 } - -pfLogInterfaceIp6PktsInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv6 packets passed in on the loginterface." - ::= { pfLogInterface 10 } - -pfLogInterfaceIp6PktsInDrop OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv6 packets dropped coming in on the loginterface." - ::= { pfLogInterface 11 } - -pfLogInterfaceIp6PktsOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv6 packets passed out on the loginterface." - ::= { pfLogInterface 12 } - -pfLogInterfaceIp6PktsOutDrop OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Number of IPv6 packets dropped going out on the loginterface." - ::= { pfLogInterface 13 } - --- -------------------------------------------------------------------------- - --- --- interfaces --- - -pfInterfacesIfNumber OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of network interfaces on this system." - ::= { pfInterfaces 1 } - -pfInterfacesIfTable OBJECT-TYPE - SYNTAX SEQUENCE OF PfInterfacesIfEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table of network interfaces, indexed on pfInterfacesIfNumber." - ::= { pfInterfaces 2 } - -pfInterfacesIfEntry OBJECT-TYPE - SYNTAX PfInterfacesIfEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "An entry in the pfInterfacesIfTable containing information - about a particular network interface in the machine." - INDEX { pfInterfacesIfIndex } - ::= { pfInterfacesIfTable 1 } - -PfInterfacesIfEntry ::= SEQUENCE { - pfInterfacesIfIndex Integer32, - pfInterfacesIfDescr OCTET STRING, - pfInterfacesIfType INTEGER, - pfInterfacesIfTZero TimeTicks, - pfInterfacesIfRefsState Unsigned32, - pfInterfacesIfRefsRule Unsigned32, - pfInterfacesIf4BytesInPass Counter64, - pfInterfacesIf4BytesInBlock Counter64, - pfInterfacesIf4BytesOutPass Counter64, - pfInterfacesIf4BytesOutBlock Counter64, - pfInterfacesIf4PktsInPass Counter64, - pfInterfacesIf4PktsInBlock Counter64, - pfInterfacesIf4PktsOutPass Counter64, - pfInterfacesIf4PktsOutBlock Counter64, - pfInterfacesIf6BytesInPass Counter64, - pfInterfacesIf6BytesInBlock Counter64, - pfInterfacesIf6BytesOutPass Counter64, - pfInterfacesIf6BytesOutBlock Counter64, - pfInterfacesIf6PktsInPass Counter64, - pfInterfacesIf6PktsInBlock Counter64, - pfInterfacesIf6PktsOutPass Counter64, - pfInterfacesIf6PktsOutBlock Counter64 -} - -pfInterfacesIfIndex OBJECT-TYPE - SYNTAX Integer32 (1..2147483647) - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A unique value, greater than zero, for each interface." - ::= { pfInterfacesIfEntry 1 } - -pfInterfacesIfDescr OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The name of the interface." - ::= { pfInterfacesIfEntry 2 } - -pfInterfacesIfType OBJECT-TYPE - SYNTAX INTEGER { group(0), instance(1), detached(2) } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Indicates whether the interface is a group inteface, an - interface instance, or whether it has been removed or - destroyed." - ::= { pfInterfacesIfEntry 3 } - -pfInterfacesIfTZero OBJECT-TYPE - SYNTAX TimeTicks - UNITS "1/100th of a Second" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Time since statistics were last reset or since the - interface was loaded." - ::= { pfInterfacesIfEntry 4 } - -pfInterfacesIfRefsState OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of state and/or source track entries referencing - this interface." - ::= { pfInterfacesIfEntry 5 } - -pfInterfacesIfRefsRule OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of rules referencing this interface." - ::= { pfInterfacesIfEntry 6 } - -pfInterfacesIf4BytesInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 bytes passed coming in on this interface." - ::= { pfInterfacesIfEntry 7 } - -pfInterfacesIf4BytesInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 bytes blocked coming in on this interface." - ::= { pfInterfacesIfEntry 8 } - -pfInterfacesIf4BytesOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 bytes passed going out on this interface." - ::= { pfInterfacesIfEntry 9 } - -pfInterfacesIf4BytesOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 bytes blocked going out on this interface." - ::= { pfInterfacesIfEntry 10 } - -pfInterfacesIf4PktsInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 packets passed coming in on this interface." - ::= { pfInterfacesIfEntry 11 } - -pfInterfacesIf4PktsInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 packets blocked coming in on this interface." - ::= { pfInterfacesIfEntry 12 } - -pfInterfacesIf4PktsOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 packets passed going out on this interface." - ::= { pfInterfacesIfEntry 13 } - -pfInterfacesIf4PktsOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv4 packets blocked going out on this interface." - ::= { pfInterfacesIfEntry 14 } - -pfInterfacesIf6BytesInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 bytes passed coming in on this interface." - ::= { pfInterfacesIfEntry 15 } - -pfInterfacesIf6BytesInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 bytes blocked coming in on this interface." - ::= { pfInterfacesIfEntry 16 } - -pfInterfacesIf6BytesOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 bytes passed going out on this interface." - ::= { pfInterfacesIfEntry 17 } - -pfInterfacesIf6BytesOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 bytes blocked going out on this interface." - ::= { pfInterfacesIfEntry 18 } - - -pfInterfacesIf6PktsInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 packets passed coming in on this interface." - ::= { pfInterfacesIfEntry 19 } - -pfInterfacesIf6PktsInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 packets blocked coming in on this interface." - ::= { pfInterfacesIfEntry 20 } - -pfInterfacesIf6PktsOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 packets passed going out on this interface." - ::= { pfInterfacesIfEntry 21 } - -pfInterfacesIf6PktsOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of IPv6 packets blocked going out on this interface." - ::= { pfInterfacesIfEntry 22 } - --- -------------------------------------------------------------------------- - --- --- tables --- - -pfTablesTblNumber OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of tables on this system." - ::= { pfTables 1 } - -pfTablesTblTable OBJECT-TYPE - SYNTAX SEQUENCE OF PfTablesTblEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table of tables, index on pfTablesTblIndex." - ::= { pfTables 2 } - -pfTablesTblEntry OBJECT-TYPE - SYNTAX PfTablesTblEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Any entry in the pfTablesTblTable containing information - about a particular table on the system." - INDEX { pfTablesTblIndex } - ::= { pfTablesTblTable 1 } - -PfTablesTblEntry ::= SEQUENCE { - pfTablesTblIndex Integer32, - pfTablesTblDescr OCTET STRING, - pfTablesTblCount Integer32, - pfTablesTblTZero TimeTicks, - pfTablesTblRefsAnchor Integer32, - pfTablesTblRefsRule Integer32, - pfTablesTblEvalMatch Counter64, - pfTablesTblEvalNoMatch Counter64, - pfTablesTblBytesInPass Counter64, - pfTablesTblBytesInBlock Counter64, - pfTablesTblBytesInXPass Counter64, - pfTablesTblBytesOutPass Counter64, - pfTablesTblBytesOutBlock Counter64, - pfTablesTblBytesOutXPass Counter64, - pfTablesTblPktsInPass Counter64, - pfTablesTblPktsInBlock Counter64, - pfTablesTblPktsInXPass Counter64, - pfTablesTblPktsOutPass Counter64, - pfTablesTblPktsOutBlock Counter64, - pfTablesTblPktsOutXPass Counter64 -} - -pfTablesTblIndex OBJECT-TYPE - SYNTAX Integer32 (1..2147483647) - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A unique value, greater than zero, for each table." - ::= { pfTablesTblEntry 1 } - -pfTablesTblDescr OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The name of the table." - ::= { pfTablesTblEntry 2 } - -pfTablesTblCount OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of addresses in the table." - ::= { pfTablesTblEntry 3 } - -pfTablesTblTZero OBJECT-TYPE - SYNTAX TimeTicks - UNITS "1/100th of a Second" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The time passed since the statistics of this table were last - cleared or the time since this table was loaded, whichever is - sooner." - ::= { pfTablesTblEntry 4 } - -pfTablesTblRefsAnchor OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of anchors referencing this table." - ::= { pfTablesTblEntry 5 } - -pfTablesTblRefsRule OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of rules referencing this table." - ::= { pfTablesTblEntry 6 } - -pfTablesTblEvalMatch OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of evaluations returning a match." - ::= { pfTablesTblEntry 7 } - -pfTablesTblEvalNoMatch OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of evaluations not returning a match." - ::= { pfTablesTblEntry 8 } - -pfTablesTblBytesInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of bytes passed in matching the table." - ::= { pfTablesTblEntry 9 } - -pfTablesTblBytesInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of bytes blocked coming in matching the table." - ::= { pfTablesTblEntry 10 } - -pfTablesTblBytesInXPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of bytes statefully passed in where the state - entry refers to the table, but the table no longer contains - the address in question." - ::= { pfTablesTblEntry 11 } - -pfTablesTblBytesOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of bytes passed out matching the table." - ::= { pfTablesTblEntry 12 } - -pfTablesTblBytesOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of bytes blocked going out matching the table." - ::= { pfTablesTblEntry 13 } - -pfTablesTblBytesOutXPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of bytes statefully passed out where the state - entry refers to the table, but the table no longer contains - the address in question." - ::= { pfTablesTblEntry 14 } - -pfTablesTblPktsInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of packets passed in matching the table." - ::= { pfTablesTblEntry 15 } - -pfTablesTblPktsInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of packets blocked coming in matching the table." - ::= { pfTablesTblEntry 16 } - -pfTablesTblPktsInXPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of packets statefully passed in where the state - entry refers to the table, but the table no longer contains - the address in question." - ::= { pfTablesTblEntry 17 } - -pfTablesTblPktsOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of packets passed out matching the table." - ::= { pfTablesTblEntry 18 } - -pfTablesTblPktsOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of packets blocked going out matching the table." - ::= { pfTablesTblEntry 19 } - -pfTablesTblPktsOutXPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of packets statefully passed out where the state - entry refers to the table, but the table no longer contains - the address in question." - ::= { pfTablesTblEntry 20 } - -pfTablesAddrTable OBJECT-TYPE - SYNTAX SEQUENCE OF PfTablesAddrEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table of addresses from every table on the system." - ::= { pfTables 3 } - -pfTablesAddrEntry OBJECT-TYPE - SYNTAX PfTablesAddrEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "An entry in the pfTablesAddrTable containing information - about a particular entry in a table." - INDEX { pfTablesAddrIndex } - ::= { pfTablesAddrTable 1 } - -PfTablesAddrEntry ::= SEQUENCE { - pfTablesAddrIndex Integer32, - pfTablesAddrNetType InetAddressType, - pfTablesAddrNet InetAddress, - pfTablesAddrPrefix InetAddressPrefixLength, - pfTablesAddrTZero TimeTicks, - pfTablesAddrBytesInPass Counter64, - pfTablesAddrBytesInBlock Counter64, - pfTablesAddrBytesOutPass Counter64, - pfTablesAddrBytesOutBlock Counter64, - pfTablesAddrPktsInPass Counter64, - pfTablesAddrPktsInBlock Counter64, - pfTablesAddrPktsOutPass Counter64, - pfTablesAddrPktsOutBlock Counter64 -} - -pfTablesAddrIndex OBJECT-TYPE - SYNTAX Integer32 (1..2147483647) - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A unique value, greater than zero, for each address." - ::= { pfTablesAddrEntry 1 } - -pfTablesAddrNetType OBJECT-TYPE - SYNTAX InetAddressType - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The type of address in the corresponding pfTablesAddrNet object." - ::= { pfTablesAddrEntry 2 } - -pfTablesAddrNet OBJECT-TYPE - SYNTAX InetAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The IP address of this particular table entry." - ::= { pfTablesAddrEntry 3 } - -pfTablesAddrPrefix OBJECT-TYPE - SYNTAX InetAddressPrefixLength - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The CIDR netmask of this particular table entry." - ::= { pfTablesAddrEntry 4 } - -pfTablesAddrTZero OBJECT-TYPE - SYNTAX TimeTicks - UNITS "1/100th of a Second" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The time passed since this entry's statistics were last - cleared, or the time passed since this entry was loaded - into the table, whichever is sooner." - ::= { pfTablesAddrEntry 5 } - -pfTablesAddrBytesInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of inbound bytes passed as a result of this entry." - ::= { pfTablesAddrEntry 6 } - -pfTablesAddrBytesInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of inbound bytes blocked as a result of this entry." - ::= { pfTablesAddrEntry 7 } - -pfTablesAddrBytesOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of outbound bytes passed as a result of this entry." - ::= { pfTablesAddrEntry 8 } - -pfTablesAddrBytesOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of outbound bytes blocked as a result of this entry." - ::= { pfTablesAddrEntry 9 } - -pfTablesAddrPktsInPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of inbound packets passed as a result of this entry." - ::= { pfTablesAddrEntry 10 } - -pfTablesAddrPktsInBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of inbound packets blocked as a result of this entry." - ::= { pfTablesAddrEntry 11 } - -pfTablesAddrPktsOutPass OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of outbound packets passed as a result of this entry." - ::= { pfTablesAddrEntry 12 } - -pfTablesAddrPktsOutBlock OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of outbound packets blocked as a result of this - entry." - ::= { pfTablesAddrEntry 13 } - --- -------------------------------------------------------------------------- - --- --- Altq information --- - -pfAltqQueueNumber OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of queues in the active set." - ::= { pfAltq 1 } - -pfAltqQueueTable OBJECT-TYPE - SYNTAX SEQUENCE OF PfAltqQueueEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table containing the rules that are active on this system." - ::= { pfAltq 2 } - -pfAltqQueueEntry OBJECT-TYPE - SYNTAX PfAltqQueueEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "An entry in the pfAltqQueueTable table." - INDEX { pfAltqQueueIndex } - ::= { pfAltqQueueTable 1 } - -PfAltqQueueEntry ::= SEQUENCE { - pfAltqQueueIndex Integer32, - pfAltqQueueDescr OCTET STRING, - pfAltqQueueParent OCTET STRING, - pfAltqQueueScheduler INTEGER, - pfAltqQueueBandwidth Unsigned32, - pfAltqQueuePriority Integer32, - pfAltqQueueLimit Integer32 -} - -pfAltqQueueIndex OBJECT-TYPE - SYNTAX Integer32 (1..2147483647) - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A unique value, greater than zero, for each queue." - ::= { pfAltqQueueEntry 1 } - -pfAltqQueueDescr OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The name of the queue." - ::= { pfAltqQueueEntry 2 } - -pfAltqQueueParent OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Name of the queue's parent if it has one." - ::= { pfAltqQueueEntry 3 } - -pfAltqQueueScheduler OBJECT-TYPE - SYNTAX INTEGER { cbq(1), hfsc(8), priq(11) } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Scheduler algorithm implemented by this queue." - ::= { pfAltqQueueEntry 4 } - -pfAltqQueueBandwidth OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Bandwitch assigned to this queue." - ::= { pfAltqQueueEntry 5 } - -pfAltqQueuePriority OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Priority level of the queue." - ::= { pfAltqQueueEntry 6 } - -pfAltqQueueLimit OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "Maximum number of packets in the queue." - ::= { pfAltqQueueEntry 7 } - -pfLabelsLblNumber OBJECT-TYPE - SYNTAX Integer32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of labeled filter rules on this system." - ::= { pfLabels 1 } - -pfLabelsLblTable OBJECT-TYPE - SYNTAX SEQUENCE OF PfLabelsLblEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Table of filter rules, index on pfLabelsLblIndex." - ::= { pfLabels 2 } - -pfLabelsLblEntry OBJECT-TYPE - SYNTAX PfLabelsLblEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Any entry in the pfLabelsLblTable containing information - about a particular filter rule on the system." - INDEX { pfLabelsLblIndex } - ::= { pfLabelsLblTable 1 } - -PfLabelsLblEntry ::= SEQUENCE { - pfLabelsLblIndex Integer32, - pfLabelsLblName OCTET STRING, - pfLabelsLblEvals Counter64, - pfLabelsLblBytesIn Counter64, - pfLabelsLblBytesOut Counter64, - pfLabelsLblPktsIn Counter64, - pfLabelsLblPktsOut Counter64 -} - -pfLabelsLblIndex OBJECT-TYPE - SYNTAX Integer32 (1..2147483647) - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A unique value, greater than zero, for each label." - ::= { pfLabelsLblEntry 1 } - -pfLabelsLblName OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The name of the rule label." - ::= { pfLabelsLblEntry 2 } - -pfLabelsLblEvals OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of rule evaluations." - ::= { pfLabelsLblEntry 3 } - -pfLabelsLblBytesIn OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of incoming bytes matched by the rule." - ::= { pfLabelsLblEntry 4 } - -pfLabelsLblBytesOut OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of outgoing bytes matched by the rule." - ::= { pfLabelsLblEntry 5 } - -pfLabelsLblPktsIn OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of incoming packets matched by the rule." - ::= { pfLabelsLblEntry 6 } - -pfLabelsLblPktsOut OBJECT-TYPE - SYNTAX Counter64 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of outgoing packets matched by the rule." - ::= { pfLabelsLblEntry 7 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile b/usr.sbin/bsnmpd/modules/snmp_pf/Makefile deleted file mode 100644 index 6218932..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_pf/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $FreeBSD$ -# -# Author: Philip Paeps - -MOD= pf -SRCS= pf_snmp.c -CFLAGS+= -DSNMPTREE_TYPES - -XSYM= begemotPf -DEFS= ${MOD}_tree.def -BMIBS= BEGEMOT-PF-MIB.txt - -.include diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c deleted file mode 100644 index c7178f3..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c +++ /dev/null @@ -1,1799 +0,0 @@ -/*- - * Copyright (c) 2005 Philip Paeps - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pf_oid.h" -#include "pf_tree.h" - -struct lmodule *module; - -static int dev = -1; -static int started; -static uint64_t pf_tick; - -static struct pf_status pfs; - -enum { IN, OUT }; -enum { IPV4, IPV6 }; -enum { PASS, BLOCK }; - -#define PFI_IFTYPE_GROUP 0 -#define PFI_IFTYPE_INSTANCE 1 -#define PFI_IFTYPE_DETACHED 2 - -struct pfi_entry { - struct pfi_kif pfi; - u_int index; - TAILQ_ENTRY(pfi_entry) link; -}; -TAILQ_HEAD(pfi_table, pfi_entry); - -static struct pfi_table pfi_table; -static time_t pfi_table_age; -static int pfi_table_count; - -#define PFI_TABLE_MAXAGE 5 - -struct pft_entry { - struct pfr_tstats pft; - u_int index; - TAILQ_ENTRY(pft_entry) link; -}; -TAILQ_HEAD(pft_table, pft_entry); - -static struct pft_table pft_table; -static time_t pft_table_age; -static int pft_table_count; - -#define PFT_TABLE_MAXAGE 5 - -struct pfa_entry { - struct pfr_astats pfas; - u_int index; - TAILQ_ENTRY(pfa_entry) link; -}; -TAILQ_HEAD(pfa_table, pfa_entry); - -static struct pfa_table pfa_table; -static time_t pfa_table_age; -static int pfa_table_count; - -#define PFA_TABLE_MAXAGE 5 - -struct pfq_entry { - struct pf_altq altq; - u_int index; - TAILQ_ENTRY(pfq_entry) link; -}; -TAILQ_HEAD(pfq_table, pfq_entry); - -static struct pfq_table pfq_table; -static time_t pfq_table_age; -static int pfq_table_count; - -static int altq_enabled = 0; - -#define PFQ_TABLE_MAXAGE 5 - -struct pfl_entry { - char name[MAXPATHLEN + PF_RULE_LABEL_SIZE]; - u_int64_t evals; - u_int64_t bytes[2]; - u_int64_t pkts[2]; - u_int index; - TAILQ_ENTRY(pfl_entry) link; -}; -TAILQ_HEAD(pfl_table, pfl_entry); - -static struct pfl_table pfl_table; -static time_t pfl_table_age; -static int pfl_table_count; - -#define PFL_TABLE_MAXAGE 5 - -/* Forward declarations */ -static int pfi_refresh(void); -static int pfq_refresh(void); -static int pfs_refresh(void); -static int pft_refresh(void); -static int pfa_refresh(void); -static int pfl_refresh(void); -static struct pfi_entry * pfi_table_find(u_int idx); -static struct pfq_entry * pfq_table_find(u_int idx); -static struct pft_entry * pft_table_find(u_int idx); -static struct pfa_entry * pfa_table_find(u_int idx); -static struct pfl_entry * pfl_table_find(u_int idx); - -static int altq_is_enabled(int pfdevice); - -int -pf_status(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - time_t runtime; - unsigned char str[128]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if (pfs_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfStatusRunning: - val->v.uint32 = pfs.running; - break; - case LEAF_pfStatusRuntime: - runtime = (pfs.since > 0) ? - time(NULL) - pfs.since : 0; - val->v.uint32 = runtime * 100; - break; - case LEAF_pfStatusDebug: - val->v.uint32 = pfs.debug; - break; - case LEAF_pfStatusHostId: - sprintf(str, "0x%08x", ntohl(pfs.hostid)); - return (string_get(val, str, strlen(str))); - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_counter(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if (pfs_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfCounterMatch: - val->v.counter64 = pfs.counters[PFRES_MATCH]; - break; - case LEAF_pfCounterBadOffset: - val->v.counter64 = pfs.counters[PFRES_BADOFF]; - break; - case LEAF_pfCounterFragment: - val->v.counter64 = pfs.counters[PFRES_FRAG]; - break; - case LEAF_pfCounterShort: - val->v.counter64 = pfs.counters[PFRES_SHORT]; - break; - case LEAF_pfCounterNormalize: - val->v.counter64 = pfs.counters[PFRES_NORM]; - break; - case LEAF_pfCounterMemDrop: - val->v.counter64 = pfs.counters[PFRES_MEMORY]; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_statetable(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if (pfs_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfStateTableCount: - val->v.uint32 = pfs.states; - break; - case LEAF_pfStateTableSearches: - val->v.counter64 = - pfs.fcounters[FCNT_STATE_SEARCH]; - break; - case LEAF_pfStateTableInserts: - val->v.counter64 = - pfs.fcounters[FCNT_STATE_INSERT]; - break; - case LEAF_pfStateTableRemovals: - val->v.counter64 = - pfs.fcounters[FCNT_STATE_REMOVALS]; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_srcnodes(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if (pfs_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfSrcNodesCount: - val->v.uint32 = pfs.src_nodes; - break; - case LEAF_pfSrcNodesSearches: - val->v.counter64 = - pfs.scounters[SCNT_SRC_NODE_SEARCH]; - break; - case LEAF_pfSrcNodesInserts: - val->v.counter64 = - pfs.scounters[SCNT_SRC_NODE_INSERT]; - break; - case LEAF_pfSrcNodesRemovals: - val->v.counter64 = - pfs.scounters[SCNT_SRC_NODE_REMOVALS]; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_limits(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - struct pfioc_limit pl; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - bzero(&pl, sizeof(struct pfioc_limit)); - - switch (which) { - case LEAF_pfLimitsStates: - pl.index = PF_LIMIT_STATES; - break; - case LEAF_pfLimitsSrcNodes: - pl.index = PF_LIMIT_SRC_NODES; - break; - case LEAF_pfLimitsFrags: - pl.index = PF_LIMIT_FRAGS; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - if (ioctl(dev, DIOCGETLIMIT, &pl)) { - syslog(LOG_ERR, "pf_limits(): ioctl(): %s", - strerror(errno)); - return (SNMP_ERR_GENERR); - } - - val->v.uint32 = pl.limit; - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_timeouts(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - struct pfioc_tm pt; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - bzero(&pt, sizeof(struct pfioc_tm)); - - switch (which) { - case LEAF_pfTimeoutsTcpFirst: - pt.timeout = PFTM_TCP_FIRST_PACKET; - break; - case LEAF_pfTimeoutsTcpOpening: - pt.timeout = PFTM_TCP_OPENING; - break; - case LEAF_pfTimeoutsTcpEstablished: - pt.timeout = PFTM_TCP_ESTABLISHED; - break; - case LEAF_pfTimeoutsTcpClosing: - pt.timeout = PFTM_TCP_CLOSING; - break; - case LEAF_pfTimeoutsTcpFinWait: - pt.timeout = PFTM_TCP_FIN_WAIT; - break; - case LEAF_pfTimeoutsTcpClosed: - pt.timeout = PFTM_TCP_CLOSED; - break; - case LEAF_pfTimeoutsUdpFirst: - pt.timeout = PFTM_UDP_FIRST_PACKET; - break; - case LEAF_pfTimeoutsUdpSingle: - pt.timeout = PFTM_UDP_SINGLE; - break; - case LEAF_pfTimeoutsUdpMultiple: - pt.timeout = PFTM_UDP_MULTIPLE; - break; - case LEAF_pfTimeoutsIcmpFirst: - pt.timeout = PFTM_ICMP_FIRST_PACKET; - break; - case LEAF_pfTimeoutsIcmpError: - pt.timeout = PFTM_ICMP_ERROR_REPLY; - break; - case LEAF_pfTimeoutsOtherFirst: - pt.timeout = PFTM_OTHER_FIRST_PACKET; - break; - case LEAF_pfTimeoutsOtherSingle: - pt.timeout = PFTM_OTHER_SINGLE; - break; - case LEAF_pfTimeoutsOtherMultiple: - pt.timeout = PFTM_OTHER_MULTIPLE; - break; - case LEAF_pfTimeoutsFragment: - pt.timeout = PFTM_FRAG; - break; - case LEAF_pfTimeoutsInterval: - pt.timeout = PFTM_INTERVAL; - break; - case LEAF_pfTimeoutsAdaptiveStart: - pt.timeout = PFTM_ADAPTIVE_START; - break; - case LEAF_pfTimeoutsAdaptiveEnd: - pt.timeout = PFTM_ADAPTIVE_END; - break; - case LEAF_pfTimeoutsSrcNode: - pt.timeout = PFTM_SRC_NODE; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - if (ioctl(dev, DIOCGETTIMEOUT, &pt)) { - syslog(LOG_ERR, "pf_timeouts(): ioctl(): %s", - strerror(errno)); - return (SNMP_ERR_GENERR); - } - - val->v.integer = pt.seconds; - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_logif(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - unsigned char str[IFNAMSIZ]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if (pfs_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfLogInterfaceName: - strlcpy(str, pfs.ifname, sizeof str); - return (string_get(val, str, strlen(str))); - case LEAF_pfLogInterfaceIp4BytesIn: - val->v.counter64 = pfs.bcounters[IPV4][IN]; - break; - case LEAF_pfLogInterfaceIp4BytesOut: - val->v.counter64 = pfs.bcounters[IPV4][OUT]; - break; - case LEAF_pfLogInterfaceIp4PktsInPass: - val->v.counter64 = - pfs.pcounters[IPV4][IN][PF_PASS]; - break; - case LEAF_pfLogInterfaceIp4PktsInDrop: - val->v.counter64 = - pfs.pcounters[IPV4][IN][PF_DROP]; - break; - case LEAF_pfLogInterfaceIp4PktsOutPass: - val->v.counter64 = - pfs.pcounters[IPV4][OUT][PF_PASS]; - break; - case LEAF_pfLogInterfaceIp4PktsOutDrop: - val->v.counter64 = - pfs.pcounters[IPV4][OUT][PF_DROP]; - break; - case LEAF_pfLogInterfaceIp6BytesIn: - val->v.counter64 = pfs.bcounters[IPV6][IN]; - break; - case LEAF_pfLogInterfaceIp6BytesOut: - val->v.counter64 = pfs.bcounters[IPV6][OUT]; - break; - case LEAF_pfLogInterfaceIp6PktsInPass: - val->v.counter64 = - pfs.pcounters[IPV6][IN][PF_PASS]; - break; - case LEAF_pfLogInterfaceIp6PktsInDrop: - val->v.counter64 = - pfs.pcounters[IPV6][IN][PF_DROP]; - break; - case LEAF_pfLogInterfaceIp6PktsOutPass: - val->v.counter64 = - pfs.pcounters[IPV6][OUT][PF_PASS]; - break; - case LEAF_pfLogInterfaceIp6PktsOutDrop: - val->v.counter64 = - pfs.pcounters[IPV6][OUT][PF_DROP]; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_interfaces(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if ((time(NULL) - pfi_table_age) > PFI_TABLE_MAXAGE) - if (pfi_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfInterfacesIfNumber: - val->v.uint32 = pfi_table_count; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_iftable(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - struct pfi_entry *e = NULL; - - if ((time(NULL) - pfi_table_age) > PFI_TABLE_MAXAGE) - pfi_refresh(); - - switch (op) { - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_GETNEXT: - if ((e = NEXT_OBJECT_INT(&pfi_table, - &val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - val->var.len = sub + 1; - val->var.subs[sub] = e->index; - break; - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((e = pfi_table_find(val->var.subs[sub])) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_COMMIT: - case SNMP_OP_ROLLBACK: - default: - abort(); - } - - switch (which) { - case LEAF_pfInterfacesIfDescr: - return (string_get(val, e->pfi.pfik_name, -1)); - case LEAF_pfInterfacesIfType: - val->v.integer = PFI_IFTYPE_INSTANCE; - break; - case LEAF_pfInterfacesIfTZero: - val->v.uint32 = - (time(NULL) - e->pfi.pfik_tzero) * 100; - break; - case LEAF_pfInterfacesIfRefsState: - val->v.uint32 = e->pfi.pfik_states; - break; - case LEAF_pfInterfacesIfRefsRule: - val->v.uint32 = e->pfi.pfik_rules; - break; - case LEAF_pfInterfacesIf4BytesInPass: - val->v.counter64 = - e->pfi.pfik_bytes[IPV4][IN][PASS]; - break; - case LEAF_pfInterfacesIf4BytesInBlock: - val->v.counter64 = - e->pfi.pfik_bytes[IPV4][IN][BLOCK]; - break; - case LEAF_pfInterfacesIf4BytesOutPass: - val->v.counter64 = - e->pfi.pfik_bytes[IPV4][OUT][PASS]; - break; - case LEAF_pfInterfacesIf4BytesOutBlock: - val->v.counter64 = - e->pfi.pfik_bytes[IPV4][OUT][BLOCK]; - break; - case LEAF_pfInterfacesIf4PktsInPass: - val->v.counter64 = - e->pfi.pfik_packets[IPV4][IN][PASS]; - break; - case LEAF_pfInterfacesIf4PktsInBlock: - val->v.counter64 = - e->pfi.pfik_packets[IPV4][IN][BLOCK]; - break; - case LEAF_pfInterfacesIf4PktsOutPass: - val->v.counter64 = - e->pfi.pfik_packets[IPV4][OUT][PASS]; - break; - case LEAF_pfInterfacesIf4PktsOutBlock: - val->v.counter64 = - e->pfi.pfik_packets[IPV4][OUT][BLOCK]; - break; - case LEAF_pfInterfacesIf6BytesInPass: - val->v.counter64 = - e->pfi.pfik_bytes[IPV6][IN][PASS]; - break; - case LEAF_pfInterfacesIf6BytesInBlock: - val->v.counter64 = - e->pfi.pfik_bytes[IPV6][IN][BLOCK]; - break; - case LEAF_pfInterfacesIf6BytesOutPass: - val->v.counter64 = - e->pfi.pfik_bytes[IPV6][OUT][PASS]; - break; - case LEAF_pfInterfacesIf6BytesOutBlock: - val->v.counter64 = - e->pfi.pfik_bytes[IPV6][OUT][BLOCK]; - break; - case LEAF_pfInterfacesIf6PktsInPass: - val->v.counter64 = - e->pfi.pfik_packets[IPV6][IN][PASS]; - break; - case LEAF_pfInterfacesIf6PktsInBlock: - val->v.counter64 = - e->pfi.pfik_packets[IPV6][IN][BLOCK]; - break; - case LEAF_pfInterfacesIf6PktsOutPass: - val->v.counter64 = - e->pfi.pfik_packets[IPV6][OUT][PASS]; - break; - case LEAF_pfInterfacesIf6PktsOutBlock: - val->v.counter64 = - e->pfi.pfik_packets[IPV6][OUT][BLOCK]; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); -} - -int -pf_tables(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if ((time(NULL) - pft_table_age) > PFT_TABLE_MAXAGE) - if (pft_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfTablesTblNumber: - val->v.uint32 = pft_table_count; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -pf_tbltable(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - struct pft_entry *e = NULL; - - if ((time(NULL) - pft_table_age) > PFT_TABLE_MAXAGE) - pft_refresh(); - - switch (op) { - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_GETNEXT: - if ((e = NEXT_OBJECT_INT(&pft_table, - &val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - val->var.len = sub + 1; - val->var.subs[sub] = e->index; - break; - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((e = pft_table_find(val->var.subs[sub])) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_COMMIT: - case SNMP_OP_ROLLBACK: - default: - abort(); - } - - switch (which) { - case LEAF_pfTablesTblDescr: - return (string_get(val, e->pft.pfrts_name, -1)); - case LEAF_pfTablesTblCount: - val->v.integer = e->pft.pfrts_cnt; - break; - case LEAF_pfTablesTblTZero: - val->v.uint32 = - (time(NULL) - e->pft.pfrts_tzero) * 100; - break; - case LEAF_pfTablesTblRefsAnchor: - val->v.integer = - e->pft.pfrts_refcnt[PFR_REFCNT_ANCHOR]; - break; - case LEAF_pfTablesTblRefsRule: - val->v.integer = - e->pft.pfrts_refcnt[PFR_REFCNT_RULE]; - break; - case LEAF_pfTablesTblEvalMatch: - val->v.counter64 = e->pft.pfrts_match; - break; - case LEAF_pfTablesTblEvalNoMatch: - val->v.counter64 = e->pft.pfrts_nomatch; - break; - case LEAF_pfTablesTblBytesInPass: - val->v.counter64 = - e->pft.pfrts_bytes[PFR_DIR_IN][PFR_OP_PASS]; - break; - case LEAF_pfTablesTblBytesInBlock: - val->v.counter64 = - e->pft.pfrts_bytes[PFR_DIR_IN][PFR_OP_BLOCK]; - break; - case LEAF_pfTablesTblBytesInXPass: - val->v.counter64 = - e->pft.pfrts_bytes[PFR_DIR_IN][PFR_OP_XPASS]; - break; - case LEAF_pfTablesTblBytesOutPass: - val->v.counter64 = - e->pft.pfrts_bytes[PFR_DIR_OUT][PFR_OP_PASS]; - break; - case LEAF_pfTablesTblBytesOutBlock: - val->v.counter64 = - e->pft.pfrts_bytes[PFR_DIR_OUT][PFR_OP_BLOCK]; - break; - case LEAF_pfTablesTblBytesOutXPass: - val->v.counter64 = - e->pft.pfrts_bytes[PFR_DIR_OUT][PFR_OP_XPASS]; - break; - case LEAF_pfTablesTblPktsInPass: - val->v.counter64 = - e->pft.pfrts_packets[PFR_DIR_IN][PFR_OP_PASS]; - break; - case LEAF_pfTablesTblPktsInBlock: - val->v.counter64 = - e->pft.pfrts_packets[PFR_DIR_IN][PFR_OP_BLOCK]; - break; - case LEAF_pfTablesTblPktsInXPass: - val->v.counter64 = - e->pft.pfrts_packets[PFR_DIR_IN][PFR_OP_XPASS]; - break; - case LEAF_pfTablesTblPktsOutPass: - val->v.counter64 = - e->pft.pfrts_packets[PFR_DIR_OUT][PFR_OP_PASS]; - break; - case LEAF_pfTablesTblPktsOutBlock: - val->v.counter64 = - e->pft.pfrts_packets[PFR_DIR_OUT][PFR_OP_BLOCK]; - break; - case LEAF_pfTablesTblPktsOutXPass: - val->v.counter64 = - e->pft.pfrts_packets[PFR_DIR_OUT][PFR_OP_XPASS]; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); -} - -int -pf_tbladdr(struct snmp_context __unused *ctx, struct snmp_value __unused *val, - u_int __unused sub, u_int __unused vindex, enum snmp_op __unused op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - struct pfa_entry *e = NULL; - - if ((time(NULL) - pfa_table_age) > PFA_TABLE_MAXAGE) - pfa_refresh(); - - switch (op) { - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_GETNEXT: - if ((e = NEXT_OBJECT_INT(&pfa_table, - &val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - val->var.len = sub + 1; - val->var.subs[sub] = e->index; - break; - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((e = pfa_table_find(val->var.subs[sub])) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_COMMIT: - case SNMP_OP_ROLLBACK: - default: - abort(); - } - - switch (which) { - case LEAF_pfTablesAddrNetType: - if (e->pfas.pfras_a.pfra_af == AF_INET) - val->v.integer = pfTablesAddrNetType_ipv4; - else if (e->pfas.pfras_a.pfra_af == AF_INET6) - val->v.integer = pfTablesAddrNetType_ipv6; - else - return (SNMP_ERR_GENERR); - break; - case LEAF_pfTablesAddrNet: - if (e->pfas.pfras_a.pfra_af == AF_INET) { - return (string_get(val, - (u_char *)&e->pfas.pfras_a.pfra_ip4addr, 4)); - } else if (e->pfas.pfras_a.pfra_af == AF_INET6) - return (string_get(val, - (u_char *)&e->pfas.pfras_a.pfra_ip6addr, 16)); - else - return (SNMP_ERR_GENERR); - break; - case LEAF_pfTablesAddrPrefix: - val->v.integer = (int32_t) e->pfas.pfras_a.pfra_net; - break; - case LEAF_pfTablesAddrTZero: - val->v.uint32 = - (time(NULL) - e->pfas.pfras_tzero) * 100; - break; - case LEAF_pfTablesAddrBytesInPass: - val->v.counter64 = - e->pfas.pfras_bytes[PFR_DIR_IN][PFR_OP_PASS]; - break; - case LEAF_pfTablesAddrBytesInBlock: - val->v.counter64 = - e->pfas.pfras_bytes[PFR_DIR_IN][PFR_OP_BLOCK]; - break; - case LEAF_pfTablesAddrBytesOutPass: - val->v.counter64 = - e->pfas.pfras_bytes[PFR_DIR_OUT][PFR_OP_PASS]; - break; - case LEAF_pfTablesAddrBytesOutBlock: - val->v.counter64 = - e->pfas.pfras_bytes[PFR_DIR_OUT][PFR_OP_BLOCK]; - break; - case LEAF_pfTablesAddrPktsInPass: - val->v.counter64 = - e->pfas.pfras_packets[PFR_DIR_IN][PFR_OP_PASS]; - break; - case LEAF_pfTablesAddrPktsInBlock: - val->v.counter64 = - e->pfas.pfras_packets[PFR_DIR_IN][PFR_OP_BLOCK]; - break; - case LEAF_pfTablesAddrPktsOutPass: - val->v.counter64 = - e->pfas.pfras_packets[PFR_DIR_OUT][PFR_OP_PASS]; - break; - case LEAF_pfTablesAddrPktsOutBlock: - val->v.counter64 = - e->pfas.pfras_packets[PFR_DIR_OUT][PFR_OP_BLOCK]; - break; - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); -} - -int -pf_altq(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - - if (!altq_enabled) - return (SNMP_ERR_NOSUCHNAME); - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if ((time(NULL) - pfq_table_age) > PFQ_TABLE_MAXAGE) - if (pfq_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfAltqQueueNumber: - val->v.uint32 = pfq_table_count; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); - return (SNMP_ERR_GENERR); -} - -int -pf_altqq(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - struct pfq_entry *e = NULL; - - if (!altq_enabled) - return (SNMP_ERR_NOSUCHNAME); - - if ((time(NULL) - pfq_table_age) > PFQ_TABLE_MAXAGE) - pfq_refresh(); - - switch (op) { - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_GETNEXT: - if ((e = NEXT_OBJECT_INT(&pfq_table, - &val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - val->var.len = sub + 1; - val->var.subs[sub] = e->index; - break; - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((e = pfq_table_find(val->var.subs[sub])) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_COMMIT: - case SNMP_OP_ROLLBACK: - default: - abort(); - } - - switch (which) { - case LEAF_pfAltqQueueDescr: - return (string_get(val, e->altq.qname, -1)); - case LEAF_pfAltqQueueParent: - return (string_get(val, e->altq.parent, -1)); - case LEAF_pfAltqQueueScheduler: - val->v.integer = e->altq.scheduler; - break; - case LEAF_pfAltqQueueBandwidth: - val->v.uint32 = e->altq.bandwidth; - break; - case LEAF_pfAltqQueuePriority: - val->v.integer = e->altq.priority; - break; - case LEAF_pfAltqQueueLimit: - val->v.integer = e->altq.qlimit; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); -} - -int -pf_labels(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - - if (op == SNMP_OP_SET) - return (SNMP_ERR_NOT_WRITEABLE); - - if (op == SNMP_OP_GET) { - if ((time(NULL) - pfl_table_age) > PFL_TABLE_MAXAGE) - if (pfl_refresh() == -1) - return (SNMP_ERR_GENERR); - - switch (which) { - case LEAF_pfLabelsLblNumber: - val->v.uint32 = pfl_table_count; - break; - - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); - } - - abort(); - return (SNMP_ERR_GENERR); -} - -int -pf_lbltable(struct snmp_context __unused *ctx, struct snmp_value *val, - u_int sub, u_int __unused vindex, enum snmp_op op) -{ - asn_subid_t which = val->var.subs[sub - 1]; - struct pfl_entry *e = NULL; - - if ((time(NULL) - pfl_table_age) > PFL_TABLE_MAXAGE) - pfl_refresh(); - - switch (op) { - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_GETNEXT: - if ((e = NEXT_OBJECT_INT(&pfl_table, - &val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - val->var.len = sub + 1; - val->var.subs[sub] = e->index; - break; - case SNMP_OP_GET: - if (val->var.len - sub != 1) - return (SNMP_ERR_NOSUCHNAME); - if ((e = pfl_table_find(val->var.subs[sub])) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_COMMIT: - case SNMP_OP_ROLLBACK: - default: - abort(); - } - - switch (which) { - case LEAF_pfLabelsLblName: - return (string_get(val, e->name, -1)); - case LEAF_pfLabelsLblEvals: - val->v.counter64 = e->evals; - break; - case LEAF_pfLabelsLblBytesIn: - val->v.counter64 = e->bytes[IN]; - break; - case LEAF_pfLabelsLblBytesOut: - val->v.counter64 = e->bytes[OUT]; - break; - case LEAF_pfLabelsLblPktsIn: - val->v.counter64 = e->pkts[IN]; - break; - case LEAF_pfLabelsLblPktsOut: - val->v.counter64 = e->pkts[OUT]; - break; - default: - return (SNMP_ERR_NOSUCHNAME); - } - - return (SNMP_ERR_NOERROR); -} - -static struct pfi_entry * -pfi_table_find(u_int idx) -{ - struct pfi_entry *e; - - TAILQ_FOREACH(e, &pfi_table, link) - if (e->index == idx) - return (e); - return (NULL); -} - -static struct pfq_entry * -pfq_table_find(u_int idx) -{ - struct pfq_entry *e; - - TAILQ_FOREACH(e, &pfq_table, link) - if (e->index == idx) - return (e); - return (NULL); -} - -static struct pft_entry * -pft_table_find(u_int idx) -{ - struct pft_entry *e; - - TAILQ_FOREACH(e, &pft_table, link) - if (e->index == idx) - return (e); - return (NULL); -} - -static struct pfa_entry * -pfa_table_find(u_int idx) -{ - struct pfa_entry *e; - - TAILQ_FOREACH(e, &pfa_table, link) - if (e->index == idx) - return (e); - return (NULL); -} - -static struct pfl_entry * -pfl_table_find(u_int idx) -{ - struct pfl_entry *e; - - TAILQ_FOREACH(e, &pfl_table, link) - if (e->index == idx) - return (e); - - return (NULL); -} - -static int -pfi_refresh(void) -{ - struct pfioc_iface io; - struct pfi_kif *p = NULL; - struct pfi_entry *e; - int i, numifs = 1; - - if (started && this_tick <= pf_tick) - return (0); - - while (!TAILQ_EMPTY(&pfi_table)) { - e = TAILQ_FIRST(&pfi_table); - TAILQ_REMOVE(&pfi_table, e, link); - free(e); - } - - bzero(&io, sizeof(io)); - io.pfiio_esize = sizeof(struct pfi_kif); - - for (;;) { - p = reallocf(p, numifs * sizeof(struct pfi_kif)); - if (p == NULL) { - syslog(LOG_ERR, "pfi_refresh(): reallocf() numifs=%d: %s", - numifs, strerror(errno)); - goto err2; - } - io.pfiio_size = numifs; - io.pfiio_buffer = p; - - if (ioctl(dev, DIOCIGETIFACES, &io)) { - syslog(LOG_ERR, "pfi_refresh(): ioctl(): %s", - strerror(errno)); - goto err2; - } - - if (numifs >= io.pfiio_size) - break; - - numifs = io.pfiio_size; - } - - for (i = 0; i < numifs; i++) { - e = malloc(sizeof(struct pfi_entry)); - if (e == NULL) - goto err1; - e->index = i + 1; - memcpy(&e->pfi, p+i, sizeof(struct pfi_kif)); - TAILQ_INSERT_TAIL(&pfi_table, e, link); - } - - pfi_table_age = time(NULL); - pfi_table_count = numifs; - pf_tick = this_tick; - - free(p); - return (0); - -err1: - while (!TAILQ_EMPTY(&pfi_table)) { - e = TAILQ_FIRST(&pfi_table); - TAILQ_REMOVE(&pfi_table, e, link); - free(e); - } -err2: - free(p); - return(-1); -} - -static int -pfq_refresh(void) -{ - struct pfioc_altq pa; - struct pfq_entry *e; - int i, numqs, ticket; - - if (started && this_tick <= pf_tick) - return (0); - - while (!TAILQ_EMPTY(&pfq_table)) { - e = TAILQ_FIRST(&pfq_table); - TAILQ_REMOVE(&pfq_table, e, link); - free(e); - } - - bzero(&pa, sizeof(pa)); - - if (ioctl(dev, DIOCGETALTQS, &pa)) { - syslog(LOG_ERR, "pfq_refresh: ioctl(DIOCGETALTQS): %s", - strerror(errno)); - return (-1); - } - - numqs = pa.nr; - ticket = pa.ticket; - - for (i = 0; i < numqs; i++) { - e = malloc(sizeof(struct pfq_entry)); - if (e == NULL) { - syslog(LOG_ERR, "pfq_refresh(): " - "malloc(): %s", - strerror(errno)); - goto err; - } - pa.ticket = ticket; - pa.nr = i; - - if (ioctl(dev, DIOCGETALTQ, &pa)) { - syslog(LOG_ERR, "pfq_refresh(): " - "ioctl(DIOCGETALTQ): %s", - strerror(errno)); - goto err; - } - - if (pa.altq.qid > 0) { - memcpy(&e->altq, &pa.altq, sizeof(struct pf_altq)); - e->index = pa.altq.qid; - pfq_table_count = i; - INSERT_OBJECT_INT_LINK_INDEX(e, &pfq_table, link, index); - } - } - - pfq_table_age = time(NULL); - pf_tick = this_tick; - - return (0); -err: - free(e); - while (!TAILQ_EMPTY(&pfq_table)) { - e = TAILQ_FIRST(&pfq_table); - TAILQ_REMOVE(&pfq_table, e, link); - free(e); - } - return(-1); -} - -static int -pfs_refresh(void) -{ - if (started && this_tick <= pf_tick) - return (0); - - bzero(&pfs, sizeof(struct pf_status)); - - if (ioctl(dev, DIOCGETSTATUS, &pfs)) { - syslog(LOG_ERR, "pfs_refresh(): ioctl(): %s", - strerror(errno)); - return (-1); - } - - pf_tick = this_tick; - return (0); -} - -static int -pft_refresh(void) -{ - struct pfioc_table io; - struct pfr_tstats *t = NULL; - struct pft_entry *e; - int i, numtbls = 1; - - if (started && this_tick <= pf_tick) - return (0); - - while (!TAILQ_EMPTY(&pft_table)) { - e = TAILQ_FIRST(&pft_table); - TAILQ_REMOVE(&pft_table, e, link); - free(e); - } - - bzero(&io, sizeof(io)); - io.pfrio_esize = sizeof(struct pfr_tstats); - - for (;;) { - t = reallocf(t, numtbls * sizeof(struct pfr_tstats)); - if (t == NULL) { - syslog(LOG_ERR, "pft_refresh(): reallocf() numtbls=%d: %s", - numtbls, strerror(errno)); - goto err2; - } - io.pfrio_size = numtbls; - io.pfrio_buffer = t; - - if (ioctl(dev, DIOCRGETTSTATS, &io)) { - syslog(LOG_ERR, "pft_refresh(): ioctl(): %s", - strerror(errno)); - goto err2; - } - - if (numtbls >= io.pfrio_size) - break; - - numtbls = io.pfrio_size; - } - - for (i = 0; i < numtbls; i++) { - e = malloc(sizeof(struct pft_entry)); - if (e == NULL) - goto err1; - e->index = i + 1; - memcpy(&e->pft, t+i, sizeof(struct pfr_tstats)); - TAILQ_INSERT_TAIL(&pft_table, e, link); - } - - pft_table_age = time(NULL); - pft_table_count = numtbls; - pf_tick = this_tick; - - free(t); - return (0); -err1: - while (!TAILQ_EMPTY(&pft_table)) { - e = TAILQ_FIRST(&pft_table); - TAILQ_REMOVE(&pft_table, e, link); - free(e); - } -err2: - free(t); - return(-1); -} - -static int -pfa_table_addrs(u_int sidx, struct pfr_table *pt) -{ - struct pfioc_table io; - struct pfr_astats *t = NULL; - struct pfa_entry *e; - int i, numaddrs = 1; - - if (pt == NULL) - return (-1); - - memset(&io, 0, sizeof(io)); - strlcpy(io.pfrio_table.pfrt_name, pt->pfrt_name, - sizeof(io.pfrio_table.pfrt_name)); - - for (;;) { - t = reallocf(t, numaddrs * sizeof(struct pfr_astats)); - if (t == NULL) { - syslog(LOG_ERR, "pfa_table_addrs(): reallocf(): %s", - strerror(errno)); - numaddrs = -1; - goto error; - } - - memset(t, 0, sizeof(*t)); - io.pfrio_size = numaddrs; - io.pfrio_buffer = t; - io.pfrio_esize = sizeof(struct pfr_astats); - - if (ioctl(dev, DIOCRGETASTATS, &io)) { - syslog(LOG_ERR, "pfa_table_addrs(): ioctl() on %s: %s", - pt->pfrt_name, strerror(errno)); - numaddrs = -1; - break; - } - - if (numaddrs >= io.pfrio_size) - break; - - numaddrs = io.pfrio_size; - } - - for (i = 0; i < numaddrs; i++) { - if ((t + i)->pfras_a.pfra_af != AF_INET && - (t + i)->pfras_a.pfra_af != AF_INET6) { - numaddrs = i; - break; - } - - e = (struct pfa_entry *)malloc(sizeof(struct pfa_entry)); - if (e == NULL) { - syslog(LOG_ERR, "pfa_table_addrs(): malloc(): %s", - strerror(errno)); - numaddrs = -1; - break; - } - e->index = sidx + i; - memcpy(&e->pfas, t + i, sizeof(struct pfr_astats)); - TAILQ_INSERT_TAIL(&pfa_table, e, link); - } - - free(t); -error: - return (numaddrs); -} - -static int -pfa_refresh(void) -{ - struct pfioc_table io; - struct pfr_table *pt = NULL, *it = NULL; - struct pfa_entry *e; - int i, numtbls = 1, cidx, naddrs; - - if (started && this_tick <= pf_tick) - return (0); - - while (!TAILQ_EMPTY(&pfa_table)) { - e = TAILQ_FIRST(&pfa_table); - TAILQ_REMOVE(&pfa_table, e, link); - free(e); - } - - memset(&io, 0, sizeof(io)); - io.pfrio_esize = sizeof(struct pfr_table); - - for (;;) { - pt = reallocf(pt, numtbls * sizeof(struct pfr_table)); - if (pt == NULL) { - syslog(LOG_ERR, "pfa_refresh(): reallocf() %s", - strerror(errno)); - return (-1); - } - memset(pt, 0, sizeof(*pt)); - io.pfrio_size = numtbls; - io.pfrio_buffer = pt; - - if (ioctl(dev, DIOCRGETTABLES, &io)) { - syslog(LOG_ERR, "pfa_refresh(): ioctl(): %s", - strerror(errno)); - goto err2; - } - - if (numtbls >= io.pfrio_size) - break; - - numtbls = io.pfrio_size; - } - - cidx = 1; - - for (it = pt, i = 0; i < numtbls; it++, i++) { - /* - * Skip the table if not active - ioctl(DIOCRGETASTATS) will - * return ESRCH for this entry anyway. - */ - if (!(it->pfrt_flags & PFR_TFLAG_ACTIVE)) - continue; - - if ((naddrs = pfa_table_addrs(cidx, it)) < 0) - goto err1; - - cidx += naddrs; - } - - pfa_table_age = time(NULL); - pfa_table_count = cidx; - pf_tick = this_tick; - - free(pt); - return (0); -err1: - while (!TAILQ_EMPTY(&pfa_table)) { - e = TAILQ_FIRST(&pfa_table); - TAILQ_REMOVE(&pfa_table, e, link); - free(e); - } - -err2: - free(pt); - return (-1); -} - -static int -pfl_scan_ruleset(const char *path) -{ - struct pfioc_rule pr; - struct pfl_entry *e; - u_int32_t nr, i; - - bzero(&pr, sizeof(pr)); - strlcpy(pr.anchor, path, sizeof(pr.anchor)); - pr.rule.action = PF_PASS; - if (ioctl(dev, DIOCGETRULES, &pr)) { - syslog(LOG_ERR, "pfl_scan_ruleset: ioctl(DIOCGETRULES): %s", - strerror(errno)); - goto err; - } - - for (nr = pr.nr, i = 0; i < nr; i++) { - pr.nr = i; - if (ioctl(dev, DIOCGETRULE, &pr)) { - syslog(LOG_ERR, "pfl_scan_ruleset: ioctl(DIOCGETRULE):" - " %s", strerror(errno)); - goto err; - } - - if (pr.rule.label[0]) { - e = (struct pfl_entry *)malloc(sizeof(*e)); - if (e == NULL) - goto err; - - strlcpy(e->name, path, sizeof(e->name)); - if (path[0]) - strlcat(e->name, "/", sizeof(e->name)); - strlcat(e->name, pr.rule.label, sizeof(e->name)); - - e->evals = pr.rule.evaluations; - e->bytes[IN] = pr.rule.bytes[IN]; - e->bytes[OUT] = pr.rule.bytes[OUT]; - e->pkts[IN] = pr.rule.packets[IN]; - e->pkts[OUT] = pr.rule.packets[OUT]; - e->index = ++pfl_table_count; - - TAILQ_INSERT_TAIL(&pfl_table, e, link); - } - } - - return (0); - -err: - return (-1); -} - -static int -pfl_walk_rulesets(const char *path) -{ - struct pfioc_ruleset prs; - char newpath[MAXPATHLEN]; - u_int32_t nr, i; - - if (pfl_scan_ruleset(path)) - goto err; - - bzero(&prs, sizeof(prs)); - strlcpy(prs.path, path, sizeof(prs.path)); - if (ioctl(dev, DIOCGETRULESETS, &prs)) { - syslog(LOG_ERR, "pfl_walk_rulesets: ioctl(DIOCGETRULESETS): %s", - strerror(errno)); - goto err; - } - - for (nr = prs.nr, i = 0; i < nr; i++) { - prs.nr = i; - if (ioctl(dev, DIOCGETRULESET, &prs)) { - syslog(LOG_ERR, "pfl_walk_rulesets: ioctl(DIOCGETRULESET):" - " %s", strerror(errno)); - goto err; - } - - if (strcmp(prs.name, PF_RESERVED_ANCHOR) == 0) - continue; - - strlcpy(newpath, path, sizeof(newpath)); - if (path[0]) - strlcat(newpath, "/", sizeof(newpath)); - - strlcat(newpath, prs.name, sizeof(newpath)); - if (pfl_walk_rulesets(newpath)) - goto err; - } - - return (0); - -err: - return (-1); -} - -static int -pfl_refresh(void) -{ - struct pfl_entry *e; - - if (started && this_tick <= pf_tick) - return (0); - - while (!TAILQ_EMPTY(&pfl_table)) { - e = TAILQ_FIRST(&pfl_table); - TAILQ_REMOVE(&pfl_table, e, link); - free(e); - } - pfl_table_count = 0; - - if (pfl_walk_rulesets("")) - goto err; - - pfl_table_age = time(NULL); - pf_tick = this_tick; - - return (0); - -err: - while (!TAILQ_EMPTY(&pfl_table)) { - e = TAILQ_FIRST(&pfl_table); - TAILQ_REMOVE(&pfl_table, e, link); - free(e); - } - pfl_table_count = 0; - - return (-1); -} - -/* - * check whether altq support is enabled in kernel - */ - -static int -altq_is_enabled(int pfdev) -{ - struct pfioc_altq pa; - - errno = 0; - if (ioctl(pfdev, DIOCGETALTQS, &pa)) { - if (errno == ENODEV) { - syslog(LOG_INFO, "No ALTQ support in kernel\n" - "ALTQ related functions disabled\n"); - return (0); - } else - syslog(LOG_ERR, "DIOCGETALTQS returned an error: %s", - strerror(errno)); - return (-1); - } - return (1); -} - -/* - * Implement the bsnmpd module interface - */ -static int -pf_init(struct lmodule *mod, int __unused argc, char __unused *argv[]) -{ - module = mod; - - if ((dev = open("/dev/pf", O_RDONLY)) == -1) { - syslog(LOG_ERR, "pf_init(): open(): %s\n", - strerror(errno)); - return (-1); - } - - if ((altq_enabled = altq_is_enabled(dev)) == -1) { - syslog(LOG_ERR, "pf_init(): altq test failed"); - return (-1); - } - - /* Prepare internal state */ - TAILQ_INIT(&pfi_table); - TAILQ_INIT(&pfq_table); - TAILQ_INIT(&pft_table); - TAILQ_INIT(&pfa_table); - TAILQ_INIT(&pfl_table); - - pfi_refresh(); - if (altq_enabled) { - pfq_refresh(); - } - - pfs_refresh(); - pft_refresh(); - pfa_refresh(); - pfl_refresh(); - - started = 1; - - return (0); -} - -static int -pf_fini(void) -{ - struct pfi_entry *i1, *i2; - struct pfq_entry *q1, *q2; - struct pft_entry *t1, *t2; - struct pfa_entry *a1, *a2; - struct pfl_entry *l1, *l2; - - /* Empty the list of interfaces */ - i1 = TAILQ_FIRST(&pfi_table); - while (i1 != NULL) { - i2 = TAILQ_NEXT(i1, link); - free(i1); - i1 = i2; - } - - /* List of queues */ - q1 = TAILQ_FIRST(&pfq_table); - while (q1 != NULL) { - q2 = TAILQ_NEXT(q1, link); - free(q1); - q1 = q2; - } - - /* List of tables */ - t1 = TAILQ_FIRST(&pft_table); - while (t1 != NULL) { - t2 = TAILQ_NEXT(t1, link); - free(t1); - t1 = t2; - } - - /* List of table addresses */ - a1 = TAILQ_FIRST(&pfa_table); - while (a1 != NULL) { - a2 = TAILQ_NEXT(a1, link); - free(a1); - a1 = a2; - } - - /* And the list of labeled filter rules */ - l1 = TAILQ_FIRST(&pfl_table); - while (l1 != NULL) { - l2 = TAILQ_NEXT(l1, link); - free(l1); - l1 = l2; - } - - close(dev); - return (0); -} - -static void -pf_dump(void) -{ - pfi_refresh(); - if (altq_enabled) { - pfq_refresh(); - } - pft_refresh(); - pfa_refresh(); - pfl_refresh(); - - syslog(LOG_ERR, "Dump: pfi_table_age = %jd", - (intmax_t)pfi_table_age); - syslog(LOG_ERR, "Dump: pfi_table_count = %d", - pfi_table_count); - - syslog(LOG_ERR, "Dump: pfq_table_age = %jd", - (intmax_t)pfq_table_age); - syslog(LOG_ERR, "Dump: pfq_table_count = %d", - pfq_table_count); - - syslog(LOG_ERR, "Dump: pft_table_age = %jd", - (intmax_t)pft_table_age); - syslog(LOG_ERR, "Dump: pft_table_count = %d", - pft_table_count); - - syslog(LOG_ERR, "Dump: pfa_table_age = %jd", - (intmax_t)pfa_table_age); - syslog(LOG_ERR, "Dump: pfa_table_count = %d", - pfa_table_count); - - syslog(LOG_ERR, "Dump: pfl_table_age = %jd", - (intmax_t)pfl_table_age); - syslog(LOG_ERR, "Dump: pfl_table_count = %d", - pfl_table_count); -} - -const struct snmp_module config = { - .comment = "This module implements a MIB for the pf packet filter.", - .init = pf_init, - .fini = pf_fini, - .tree = pf_ctree, - .dump = pf_dump, - .tree_size = pf_CTREE_SIZE, -}; diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def b/usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def deleted file mode 100644 index 7b791b3..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_tree.def +++ /dev/null @@ -1,210 +0,0 @@ -# -# Copyright (c) 2010 Philip Paeps -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ -# - -(1 internet - (4 private - (1 enterprises - (12325 fokus - (1 begemot - (200 begemotPf - (1 begemotPfObjects - (1 pfStatus - (1 pfStatusRunning ENUM ( 1 true 2 false ) pf_status GET) - (2 pfStatusRuntime TIMETICKS pf_status GET) - (3 pfStatusDebug ENUM ( 0 none 1 urgent 2 misc 3 loud ) pf_status GET) - (4 pfStatusHostId OCTETSTRING pf_status GET) - ) - (2 pfCounter - (1 pfCounterMatch COUNTER64 pf_counter GET) - (2 pfCounterBadOffset COUNTER64 pf_counter GET) - (3 pfCounterFragment COUNTER64 pf_counter GET) - (4 pfCounterShort COUNTER64 pf_counter GET) - (5 pfCounterNormalize COUNTER64 pf_counter GET) - (6 pfCounterMemDrop COUNTER64 pf_counter GET) - ) - (3 pfStateTable - (1 pfStateTableCount UNSIGNED32 pf_statetable GET) - (2 pfStateTableSearches COUNTER64 pf_statetable GET) - (3 pfStateTableInserts COUNTER64 pf_statetable GET) - (4 pfStateTableRemovals COUNTER64 pf_statetable GET) - ) - (4 pfSrcNodes - (1 pfSrcNodesCount UNSIGNED32 pf_srcnodes GET) - (2 pfSrcNodesSearches COUNTER64 pf_srcnodes GET) - (3 pfSrcNodesInserts COUNTER64 pf_srcnodes GET) - (4 pfSrcNodesRemovals COUNTER64 pf_srcnodes GET) - ) - (5 pfLimits - (1 pfLimitsStates UNSIGNED32 pf_limits GET) - (2 pfLimitsSrcNodes UNSIGNED32 pf_limits GET) - (3 pfLimitsFrags UNSIGNED32 pf_limits GET) - ) - (6 pfTimeouts - (1 pfTimeoutsTcpFirst INTEGER32 pf_timeouts GET) - (2 pfTimeoutsTcpOpening INTEGER32 pf_timeouts GET) - (3 pfTimeoutsTcpEstablished INTEGER32 pf_timeouts GET) - (4 pfTimeoutsTcpClosing INTEGER32 pf_timeouts GET) - (5 pfTimeoutsTcpFinWait INTEGER32 pf_timeouts GET) - (6 pfTimeoutsTcpClosed INTEGER32 pf_timeouts GET) - (7 pfTimeoutsUdpFirst INTEGER32 pf_timeouts GET) - (8 pfTimeoutsUdpSingle INTEGER32 pf_timeouts GET) - (9 pfTimeoutsUdpMultiple INTEGER32 pf_timeouts GET) - (10 pfTimeoutsIcmpFirst INTEGER32 pf_timeouts GET) - (11 pfTimeoutsIcmpError INTEGER32 pf_timeouts GET) - (12 pfTimeoutsOtherFirst INTEGER32 pf_timeouts GET) - (13 pfTimeoutsOtherSingle INTEGER32 pf_timeouts GET) - (14 pfTimeoutsOtherMultiple INTEGER32 pf_timeouts GET) - (15 pfTimeoutsFragment INTEGER32 pf_timeouts GET) - (16 pfTimeoutsInterval INTEGER32 pf_timeouts GET) - (17 pfTimeoutsAdaptiveStart INTEGER32 pf_timeouts GET) - (18 pfTimeoutsAdaptiveEnd INTEGER32 pf_timeouts GET) - (19 pfTimeoutsSrcNode INTEGER32 pf_timeouts GET) - ) - (7 pfLogInterface - (1 pfLogInterfaceName OCTETSTRING pf_logif GET) - (2 pfLogInterfaceIp4BytesIn COUNTER64 pf_logif GET) - (3 pfLogInterfaceIp4BytesOut COUNTER64 pf_logif GET) - (4 pfLogInterfaceIp4PktsInPass COUNTER64 pf_logif GET) - (5 pfLogInterfaceIp4PktsInDrop COUNTER64 pf_logif GET) - (6 pfLogInterfaceIp4PktsOutPass COUNTER64 pf_logif GET) - (7 pfLogInterfaceIp4PktsOutDrop COUNTER64 pf_logif GET) - (8 pfLogInterfaceIp6BytesIn COUNTER64 pf_logif GET) - (9 pfLogInterfaceIp6BytesOut COUNTER64 pf_logif GET) - (10 pfLogInterfaceIp6PktsInPass COUNTER64 pf_logif GET) - (11 pfLogInterfaceIp6PktsInDrop COUNTER64 pf_logif GET) - (12 pfLogInterfaceIp6PktsOutPass COUNTER64 pf_logif GET) - (13 pfLogInterfaceIp6PktsOutDrop COUNTER64 pf_logif GET) - ) - (8 pfInterfaces - (1 pfInterfacesIfNumber INTEGER32 pf_interfaces GET) - (2 pfInterfacesIfTable - (1 pfInterfacesIfEntry : INTEGER32 pf_iftable - (1 pfInterfacesIfIndex INTEGER32) - (2 pfInterfacesIfDescr OCTETSTRING GET) - (3 pfInterfacesIfType ENUM ( 0 group 1 instance 2 detached ) GET) - (4 pfInterfacesIfTZero TIMETICKS GET) - (5 pfInterfacesIfRefsState UNSIGNED32 GET) - (6 pfInterfacesIfRefsRule UNSIGNED32 GET) - (7 pfInterfacesIf4BytesInPass COUNTER64 GET) - (8 pfInterfacesIf4BytesInBlock COUNTER64 GET) - (9 pfInterfacesIf4BytesOutPass COUNTER64 GET) - (10 pfInterfacesIf4BytesOutBlock COUNTER64 GET) - (11 pfInterfacesIf4PktsInPass COUNTER64 GET) - (12 pfInterfacesIf4PktsInBlock COUNTER64 GET) - (13 pfInterfacesIf4PktsOutPass COUNTER64 GET) - (14 pfInterfacesIf4PktsOutBlock COUNTER64 GET) - (15 pfInterfacesIf6BytesInPass COUNTER64 GET) - (16 pfInterfacesIf6BytesInBlock COUNTER64 GET) - (17 pfInterfacesIf6BytesOutPass COUNTER64 GET) - (18 pfInterfacesIf6BytesOutBlock COUNTER64 GET) - (19 pfInterfacesIf6PktsInPass COUNTER64 GET) - (20 pfInterfacesIf6PktsInBlock COUNTER64 GET) - (21 pfInterfacesIf6PktsOutPass COUNTER64 GET) - (22 pfInterfacesIf6PktsOutBlock COUNTER64 GET) - ) - ) - ) - (9 pfTables - (1 pfTablesTblNumber INTEGER32 pf_tables GET) - (2 pfTablesTblTable - (1 pfTablesTblEntry : INTEGER32 pf_tbltable - (1 pfTablesTblIndex INTEGER32) - (2 pfTablesTblDescr OCTETSTRING GET) - (3 pfTablesTblCount INTEGER32 GET) - (4 pfTablesTblTZero TIMETICKS GET) - (5 pfTablesTblRefsAnchor INTEGER32 GET) - (6 pfTablesTblRefsRule INTEGER32 GET) - (7 pfTablesTblEvalMatch COUNTER64 GET) - (8 pfTablesTblEvalNoMatch COUNTER64 GET) - (9 pfTablesTblBytesInPass COUNTER64 GET) - (10 pfTablesTblBytesInBlock COUNTER64 GET) - (11 pfTablesTblBytesInXPass COUNTER64 GET) - (12 pfTablesTblBytesOutPass COUNTER64 GET) - (13 pfTablesTblBytesOutBlock COUNTER64 GET) - (14 pfTablesTblBytesOutXPass COUNTER64 GET) - (15 pfTablesTblPktsInPass COUNTER64 GET) - (16 pfTablesTblPktsInBlock COUNTER64 GET) - (17 pfTablesTblPktsInXPass COUNTER64 GET) - (18 pfTablesTblPktsOutPass COUNTER64 GET) - (19 pfTablesTblPktsOutBlock COUNTER64 GET) - (20 pfTablesTblPktsOutXPass COUNTER64 GET) - ) - ) - (3 pfTablesAddrTable - (1 pfTablesAddrEntry : INTEGER32 pf_tbladdr - (1 pfTablesAddrIndex INTEGER32) - (2 pfTablesAddrNetType ENUM ( 0 unknown 1 ipv4 2 ipv6) GET) - (3 pfTablesAddrNet OCTETSTRING | InetAddress GET) - (4 pfTablesAddrPrefix UNSIGNED32 GET) - (5 pfTablesAddrTZero TIMETICKS GET) - (6 pfTablesAddrBytesInPass COUNTER64 GET) - (7 pfTablesAddrBytesInBlock COUNTER64 GET) - (8 pfTablesAddrBytesOutPass COUNTER64 GET) - (9 pfTablesAddrBytesOutBlock COUNTER64 GET) - (10 pfTablesAddrPktsInPass COUNTER64 GET) - (11 pfTablesAddrPktsInBlock COUNTER64 GET) - (12 pfTablesAddrPktsOutPass COUNTER64 GET) - (13 pfTablesAddrPktsOutBlock COUNTER64 GET) - ) - ) - ) - (10 pfAltq - (1 pfAltqQueueNumber INTEGER32 pf_altq GET) - (2 pfAltqQueueTable - (1 pfAltqQueueEntry : INTEGER32 pf_altqq - (1 pfAltqQueueIndex INTEGER32) - (2 pfAltqQueueDescr OCTETSTRING GET) - (3 pfAltqQueueParent OCTETSTRING GET) - (4 pfAltqQueueScheduler ENUM ( 1 cbq 8 hfsc 11 priq ) GET) - (5 pfAltqQueueBandwidth UNSIGNED32 GET) - (6 pfAltqQueuePriority INTEGER32 GET) - (7 pfAltqQueueLimit INTEGER32 GET) - ) - ) - ) - (11 pfLabels - (1 pfLabelsLblNumber INTEGER32 pf_labels GET) - (2 pfLabelsLblTable - (1 pfLabelsLblEntry : INTEGER pf_lbltable - (1 pfLabelsLblIndex INTEGER) - (2 pfLabelsLblName OCTETSTRING GET) - (3 pfLabelsLblEvals COUNTER64 GET) - (4 pfLabelsLblBytesIn COUNTER64 GET) - (5 pfLabelsLblBytesOut COUNTER64 GET) - (6 pfLabelsLblPktsIn COUNTER64 GET) - (7 pfLabelsLblPktsOut COUNTER64 GET) - ) - ) - ) - ) - ) - ) - ) - ) - ) -) diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/BEGEMOT-WIRELESS-MIB.txt b/usr.sbin/bsnmpd/modules/snmp_wlan/BEGEMOT-WIRELESS-MIB.txt deleted file mode 100644 index 194ecd1..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/BEGEMOT-WIRELESS-MIB.txt +++ /dev/null @@ -1,3898 +0,0 @@ --- --- Copyright (C) 2010 The FreeBSD Foundation --- All rights reserved. --- --- This documentation was written by Shteryana Sotirova Shopova under --- sponsorship from the FreeBSD Foundation. --- --- Redistribution and use in source and binary forms, with or without --- modification, are permitted provided that the following conditions --- are met: --- 1. Redistributions of source code must retain the above copyright --- notice, this list of conditions and the following disclaimer. --- 2. Redistributions in binary form must reproduce the above copyright --- notice, this list of conditions and the following disclaimer in the --- documentation and/or other materials provided with the distribution. --- --- THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND --- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE --- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE --- ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE --- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL --- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS --- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) --- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT --- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY --- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF --- SUCH DAMAGE. --- --- $FreeBSD$ --- - -BEGEMOT-WIRELESS-MIB DEFINITIONS ::= BEGIN - -IMPORTS - MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE, - Counter32, Integer32, TimeTicks, Unsigned32, mib-2 - FROM SNMPv2-SMI - TEXTUAL-CONVENTION, MacAddress, TruthValue, RowStatus, - DisplayString - FROM SNMPv2-TC - InterfaceIndex, ifIndex FROM IF-MIB - begemot - FROM BEGEMOT-MIB; - -begemotWlan MODULE-IDENTITY - LAST-UPDATED "201005170000Z" - ORGANIZATION "The FreeBSD Foundation" - CONTACT-INFO - " Shteryana Shopova - - Postal: 12 Andrey Lyapchev Blvd. - block 2, ap.19 - 1797 Sofia - Bulgaria - - Fax: N/A - - E-Mail: syrinx@FreeBSD.org" - DESCRIPTION - "The Begemot MIB for managing IEEE802.11 interfaces." - REVISION "201005170000Z" - DESCRIPTION - "Initial revision." - ::= { begemot 210 } - --- ---------------------------------------------------------- -- --- Textual conventions --- ---------------------------------------------------------- -- -WlanMgmtReasonCode ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "Enumeration of reason and codes used in IEEE802.11 - management frames to indicate why an action took place." - SYNTAX INTEGER { - unspecified(1), - authenticationExpire(2), - authenticationLeave(3), - associationExpire(4), - associationTooMany(5), - notAuthenticated(6), - notAssociated(7), - associationLeave(8), - associationNotAuthenticated(9), --- XXX: TODO - FIXME - dissasocPwrcapBad(10), - dissasocSuperchanBad(11), - ieInvalid(13), - micFailure(14), - fourWayHandshakeTimeout(15), - groupKeyUpdateTimeout(16), - ieIn4FourWayDiffers(17), - groupCipherInvalid(18), - pairwiseCiherInvalid(19), - akmpInvalid(20), - unsupportedRsnIeVersion(21), - invalidRsnIeCap(22), - dot1xAuthFailed(23), - cipherSuiteRejected(24), - unspeciffiedQos(32), - insufficientBw(33), - tooManyFrames(34), - outsideTxOp(35), - leavingQbss(36), - badMechanism(37), - setupNeeded(38), - timeout(39) - } - -WlanMgmtMeshReasonCode ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "Enumeration of reason and codes used in IEEE802.11 - mesh routing management frames to indicate why an - action took place." - SYNTAX INTEGER { --- XXX: TODO - FIXME - peerLinkCancelled(2), - maxPeers(3), - cpViolation(4), - closeRcvd(5), - maxRetries(6), - confirmTimeout(7), - invalidGtk(8), - inconsistentParams(9), - invalidSecurity(10), - perrUnspecified(11), - perrNoFI(12), - perrDestUnreach(13) - } - -WlanMgmtStatusCode ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "Enumeration of reason and codes used in IEEE802.11 - management frames to indicate what the result of an - operation is." - SYNTAX INTEGER { --- XXX: TODO - FIXME - success(0), - unspecified(1), - capabilitiesInfo(10), - notAssociated(11), - other(12), - algorithm(13), - sequence(14), - challenge(15), - timeout(16), - tooMany(17), - basicRate(18), - spRequired(19), - pbccRequired(20), - caRequired(21), - specMgmtRequired(22), - pwrcapRequire(23), - superchanRequired(24), - shortSlotRequired(25), - dssofdmRequired(26), - missingHTCaps(27), - invalidIE(40), - groupCipherInvalid(41), - pairwiseCipherInvalid(42), - akmpInvalid(43), - unsupportedRsnIEVersion(44), - invalidRsnIECap(45), - cipherSuiteRejected(46) - } - -WlanRegDomainCode ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "Enumeration of regdomain codes." - SYNTAX INTEGER { - fcc(1), - ca(2), - etsi(3), - etsi2(4), - etsi3(5), - fcc3(6), - japan(7), - korea(8), - apac(9), - apac2(10), - apac3(11), - row(12), - none(13), - debug(14), - sr9(15), - xr9(16), - gz901(17) - } - -WlanIfaceDot11nPduType ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "Enumeration of values for PDU transmit/receive enabled." - SYNTAX INTEGER { - disabled(0), - rxOnly(1), - txOnly(2), - txAndRx(3) - } - -WlanPeerCapabilityFlags ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "A list of capability bits that may be advertised by a peer." - SYNTAX BITS { - ess(1), - ibss(2), - cfPollable(3), - cfPollRequest(4), - privacy(5), - shortPreamble(6), - pbcc(7), - channelAgility(8), - shortSlotTime(9), - rsn(10), - dsssofdm(11) - } - -WlanIfPhyMode ::= TEXTUAL-CONVENTION - STATUS current - DESCRIPTION - "A list of wireless PHY operating modes." - SYNTAX INTEGER { - auto(1), - dot11a(2), - dot11b(3), - dot11g(4), - fh(5), - turboA(6), - turboG(7), - sturboA(8), - dot11na(9), - dot11ng(10), - ofdmHalf(11), - ofdmQuarter(12) - } - --- ---------------------------------------------------------- -- --- Subtrees in the Begemot Wireless MIB --- ---------------------------------------------------------- -- -begemotWlanNotifications OBJECT IDENTIFIER ::= { begemotWlan 0 } - -begemotWlanInterface OBJECT IDENTIFIER ::= { begemotWlan 1 } - -begemotWlanScanning OBJECT IDENTIFIER ::= { begemotWlan 2 } - -begemotWlanStatistics OBJECT IDENTIFIER ::= { begemotWlan 3 } - -begemotWlanWep OBJECT IDENTIFIER ::= { begemotWlan 4 } - -begemotWlanMACAccessControl OBJECT IDENTIFIER ::= { begemotWlan 5 } - -begemotWlanMeshRouting OBJECT IDENTIFIER ::= { begemotWlan 6 } - --- ---------------------------------------------------------- -- --- begemotWlanMultimedia OBJECT IDENTIFIER ::= { begemotWlan 7 } --- ---------------------------------------------------------- -- - --- ---------------------------------------------------------- -- --- Cloned wireless interfaces' database --- ---------------------------------------------------------- -- -wlanInterfaceTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains the list of cloned wireless - interfaces created on the system." - ::= { begemotWlanInterface 1 } - -wlanInterfaceEntry OBJECT-TYPE - SYNTAX WlanInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Information for a cloned wireless interface." - INDEX { wlanIfaceName } - ::= { wlanInterfaceTable 1 } - -WlanInterfaceEntry ::= SEQUENCE { - wlanIfaceIndex InterfaceIndex, - wlanIfaceName DisplayString, - wlanParentIfName DisplayString, - wlanIfaceOperatingMode INTEGER, - wlanIfaceFlags BITS, - wlanIfaceBssid MacAddress, - wlanIfaceLocalAddress MacAddress, - wlanIfaceStatus RowStatus, - wlanIfaceState INTEGER -} - -wlanIfaceIndex OBJECT-TYPE - SYNTAX InterfaceIndex - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The ifIndex of this cloned wireless interface." - ::= { wlanInterfaceEntry 1 } - -wlanIfaceName OBJECT-TYPE - SYNTAX DisplayString (SIZE(1..32)) - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The name of this cloned wireless interface." - ::= { wlanInterfaceEntry 2 } - -wlanParentIfName OBJECT-TYPE - SYNTAX DisplayString (SIZE(1..32)) - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The name of this cloned wireless interface's parent hardware - interface." - ::= { wlanInterfaceEntry 3 } - -wlanIfaceOperatingMode OBJECT-TYPE - SYNTAX INTEGER { - ibss(0), - station(1), - wds(2), - adhocDemo(3), - hostAp(4), - monitor(5), - meshPoint(6), - tdma(7) - } - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The desired operating mode of the cloned wireless interface." - DEFVAL { station } - ::= { wlanInterfaceEntry 4 } - -wlanIfaceFlags OBJECT-TYPE - SYNTAX BITS { - uniqueBssid(1), - noBeacons(2), - wdsLegacy(3) - } - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "Flags per cloned wireless interface used during creation." - ::= { wlanInterfaceEntry 5 } - -wlanIfaceBssid OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The BSSID assigned to a cloned wireless interface operating in - WDS mode." - ::= { wlanInterfaceEntry 6 } - -wlanIfaceLocalAddress OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The unique local MAC address assigned to the cloned wireless - interface during creation." - ::= { wlanInterfaceEntry 7 } - -wlanIfaceStatus OBJECT-TYPE - SYNTAX RowStatus - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "This column allows creation or deletion of cloned wireless - interfaces." - ::= { wlanInterfaceEntry 8 } - -wlanIfaceState OBJECT-TYPE - SYNTAX INTEGER { - up(1), - down(2) - } - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The operating state of the interface." - ::= { wlanInterfaceEntry 9 } - -wlanIfParentTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanIfParentEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information about the parent hardware - interface of every cloned wireless interface in the system." - ::= { begemotWlanInterface 2 } - -wlanIfParentEntry OBJECT-TYPE - SYNTAX WlanIfParentEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Information for the parent hardware interface of a cloned - wireless interface." - AUGMENTS { wlanInterfaceEntry } - ::= { wlanIfParentTable 1 } - -WlanIfParentEntry ::= SEQUENCE { - wlanIfParentDriverCapabilities BITS, - wlanIfParentCryptoCapabilities BITS, - wlanIfParentHTCapabilities BITS -} - -wlanIfParentDriverCapabilities OBJECT-TYPE - SYNTAX BITS { - station(1), - ieee8023encap(2), - athFastFrames(3), - athTurbo(4), - ibss(5), - pmgt(6), - hostAp(7), - ahDemo(8), - swRetry(9), - txPmgt(10), - shortSlot(11), - shortPreamble(12), - monitor(13), - dfs(14), - mbss(15), - wpa1(16), - wpa2(17), - burst(18), - wme(19), - wds(20), - bgScan(21), - txFrag(22), - tdma(23) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The driver capabilities of this cloned interface's parent." - ::= { wlanIfParentEntry 1 } - -wlanIfParentCryptoCapabilities OBJECT-TYPE - SYNTAX BITS { - wep(1), - tkip(2), - aes(3), - aesCcm(4), - tkipMic(5), - ckip(6) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The hardware cryptographic capabilities of this cloned - interface's parent." - ::= { wlanIfParentEntry 2 } - -wlanIfParentHTCapabilities OBJECT-TYPE - SYNTAX BITS { - ldpc(1), - chwidth40(2), - greenField(3), - shortGi20(4), - shortGi40(5), - txStbc(6), - delba(7), - amsdu7935(8), - dssscck40(9), - psmp(10), - fortyMHzIntolerant(11), - lsigTxOpProt(12), - htcAmpdu(13), - htcAmsdu(14), - htcHt(15), - htcSmps(16), - htcRifs(17) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The hardware High Throughput capabilities of this cloned - interface's parent." - ::= { wlanIfParentEntry 3 } - -wlanIfaceConfigTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanIfaceConfigEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains a list of configuration parameters per - cloned wireless interface. Some of the parameters may not be - applicable depending on the underlying device's hardware - capabilities and operating mode of the virtual interface." - ::= { begemotWlanInterface 3 } - -wlanIfaceConfigEntry OBJECT-TYPE - SYNTAX WlanIfaceConfigEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of configuration parameters for a cloned wireless interface." - AUGMENTS { wlanInterfaceEntry } - ::= { wlanIfaceConfigTable 1 } - -WlanIfaceConfigEntry ::= SEQUENCE { - wlanIfacePacketBurst TruthValue, - wlanIfaceCountryCode OCTET STRING, - wlanIfaceRegDomain INTEGER, - wlanIfaceDesiredSsid OCTET STRING, - wlanIfaceDesiredChannel INTEGER, - wlanIfaceDynamicFreqSelection TruthValue, - wlanIfaceFastFrames TruthValue, - wlanIfaceDturbo TruthValue, - wlanIfaceTxPower INTEGER, - wlanIfaceFragmentThreshold INTEGER, - wlanIfaceRTSThreshold INTEGER, - wlanIfaceWlanPrivacySubscribe TruthValue, --- Parameters for station mode - wlanIfaceBgScan TruthValue, - wlanIfaceBgScanIdle INTEGER, - wlanIfaceBgScanInterval INTEGER, - wlanIfaceBeaconMissedThreshold INTEGER, - wlanIfaceDesiredBssid MacAddress, - wlanIfaceRoamingMode INTEGER, --- Additional parameters when operating in host-ap/ad-hoc mode - wlanIfaceDot11d TruthValue, - wlanIfaceDot11h TruthValue, - wlanIfaceDynamicWds TruthValue, - wlanIfacePowerSave TruthValue, - wlanIfaceApBridge TruthValue, - wlanIfaceBeaconInterval INTEGER, - wlanIfaceDtimPeriod INTEGER, - wlanIfaceHideSsid TruthValue, - wlanIfaceInactivityProccess TruthValue, - wlanIfaceDot11gProtMode INTEGER, - wlanIfaceDot11gPureMode TruthValue, - wlanIfaceDot11nPureMode TruthValue, - wlanIfaceDot11nAmpdu INTEGER, - wlanIfaceDot11nAmpduDensity INTEGER, - wlanIfaceDot11nAmpduLimit INTEGER, - wlanIfaceDot11nAmsdu INTEGER, - wlanIfaceDot11nAmsduLimit INTEGER, - wlanIfaceDot11nHighThroughput TruthValue, - wlanIfaceDot11nHTCompatible TruthValue, - wlanIfaceDot11nHTProtMode INTEGER, - wlanIfaceDot11nRIFS TruthValue, - wlanIfaceDot11nShortGI TruthValue, - wlanIfaceDot11nSMPSMode INTEGER, --- Parameters when operating in tdma mode - wlanIfaceTdmaSlot INTEGER, - wlanIfaceTdmaSlotCount INTEGER, - wlanIfaceTdmaSlotLength INTEGER, - wlanIfaceTdmaBeaconInterval INTEGER -} - -wlanIfacePacketBurst OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object controls whether packet bursting is - enabled on the interface." - ::= { wlanIfaceConfigEntry 1 } - -wlanIfaceCountryCode OBJECT-TYPE - SYNTAX OCTET STRING (SIZE(3)) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object controls the country regulatory - constraints for operation of this wireless interface. The first - two octets of this string is the two character country code as - described in ISO/IEC 3166-1. The third octet shall contain one - of the following: - - 1. an ASCII space character, if the regulations under which the - interface is operating include all environments in the specified - country. - - 2. an ASCII 'O' character, if the country's regulastions are for - Outdoor environment only. - - 3. an ASCII 'I' character, if the country's regulastions are for - Indoor environment only." - ::= { wlanIfaceConfigEntry 2 } - -wlanIfaceRegDomain OBJECT-TYPE - SYNTAX WlanRegDomainCode - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This object specifies the regulatory domain to use when calculating - the regulatory constraints for operation of the interface." - ::= { wlanIfaceConfigEntry 3 } - -wlanIfaceDesiredSsid OBJECT-TYPE - SYNTAX OCTET STRING (SIZE(0..32)) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The desired SSID for the interface as an ASCII string. - Specifying an empty string shall remove the current configured - SSID." - ::= { wlanIfaceConfigEntry 4 } - -wlanIfaceDesiredChannel OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The desired operating channel for this interface. The value of this - column is the channel index (wlanIfaceChannelId) of the corresponding - entry from the wlanIfaceChannelTable. The interface status must be - down so that the current operating channel may be set properly." - ::= { wlanIfaceConfigEntry 5 } - -wlanIfaceDynamicFreqSelection OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether Dynamic Frequency - Selection (DFS) as specified in 802.11h is enabled on an - interface that supports 802.11h and DFS." - DEFVAL { false } - ::= { wlanIfaceConfigEntry 6 } - -wlanIfaceFastFrames OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object controls whether use of Atheros Fast - Frames is enabled when when communicating with another Fast - Frames-capable station. The value is only meaningfull for - interfaces that support Atheros Fast Frames." - ::= { wlanIfaceConfigEntry 7 } - -wlanIfaceDturbo OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object controls whether use of Atheros Dynamic - Turbo mode is enabled when when communicating with another Dynamic - Turbo-capable station. The value is only meaningfull for interfaces - that support Atheros Dynamic Turbo mode." - ::= { wlanIfaceConfigEntry 8 } - -wlanIfaceTxPower OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object controls the power used to transmit - frames. Accepted values are in units of one tenths of a dBm in - steps of .5 dBm, e.g setting the value of this object to 155 - results in 15.5 dBm transmit power configured on the interface." - ::= { wlanIfaceConfigEntry 9 } - -wlanIfaceFragmentThreshold OBJECT-TYPE - SYNTAX INTEGER (256..2346) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object controls the threshold for which - transmitted frames are broken into fragments. Setting the value - of this object to 2346 will disable transmit fragmentation." - DEFVAL { 2346 } - ::= { wlanIfaceConfigEntry 10 } - -wlanIfaceRTSThreshold OBJECT-TYPE - SYNTAX INTEGER (1..2346) - UNITS "bytes" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object controls the threshold for which - transmitted frames are preceded by transmission of an RTS - control frame. Setting the value of this object to 2346 will - disable transmission of RTS frames." - DEFVAL { 2346 } - ::= { wlanIfaceConfigEntry 11 } - -wlanIfaceWlanPrivacySubscribe OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether Wireless Privacy - Subscriber support is enabled on the interface." - ::= { wlanIfaceConfigEntry 12 } - -wlanIfaceBgScan OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether background scanning - is enabled for an interface operating in station mode." - ::= { wlanIfaceConfigEntry 13 } - -wlanIfaceBgScanIdle OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the minimum time a station must - be idle before a background scan is initiated on an interface - operating in station mode." - DEFVAL { 250 } - ::= { wlanIfaceConfigEntry 14 } - -wlanIfaceBgScanInterval OBJECT-TYPE - SYNTAX INTEGER - UNITS "seconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the interval at which background - scanning is attempted when operating in station mode." - DEFVAL { 300 } - ::= { wlanIfaceConfigEntry 15 } - -wlanIfaceBeaconMissedThreshold OBJECT-TYPE - SYNTAX INTEGER (1..255) - UNITS "frames" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the number of consequtive missed - beacons before an interface operating in station mode will attempt - to search for a new access point." - DEFVAL { 7 } - ::= { wlanIfaceConfigEntry 16 } - -wlanIfaceDesiredBssid OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the MAC address of the desired - access point to use when an interface is operating as a station." - ::= { wlanIfaceConfigEntry 17 } - -wlanIfaceRoamingMode OBJECT-TYPE - SYNTAX INTEGER { - device(1), - auto(2), - manual(3) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the desired system behavior - when the interface is operating as a station and the communication - with the current access point is broken." - DEFVAL { auto } - ::= { wlanIfaceConfigEntry 18 } - -wlanIfaceDot11d OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether 802.11d specification - support is enabled." - DEFVAL { false } - ::= { wlanIfaceConfigEntry 19 } - -wlanIfaceDot11h OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether 802.11h support - including spectrum management is enabled. The value is only - meaningfull for interfaces that support 802.11h specification." - DEFVAL { false } - ::= { wlanIfaceConfigEntry 20 } - -wlanIfaceDynamicWds OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether Dynamic WDS (DWDS) - support is enabled. The value is only meaningfull for interfaces - that support Dynamic WDS." - ::= { wlanIfaceConfigEntry 21 } - -wlanIfacePowerSave OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether powersave operation - is enabled. The value is only meaningfull for interfaces that - support powersave operation." - ::= { wlanIfaceConfigEntry 22 } - -wlanIfaceApBridge OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether packets between - wireless clients will be passed directly by an interface - operating in host ap mode. Disabling it may be usefull in - situations when traffic between wireless clients needs to be - processed with packet filtering." - DEFVAL { true } - ::= { wlanIfaceConfigEntry 23 } - -wlanIfaceBeaconInterval OBJECT-TYPE - SYNTAX INTEGER (25..1000) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the interval at with beacon - frames are sent when an interface is operating in ad-hoc or ap - mode. The beacon interval is specified in TU's (1024 usecs)." - DEFVAL { 100 } - ::= { wlanIfaceConfigEntry 24 } - -wlanIfaceDtimPeriod OBJECT-TYPE - SYNTAX INTEGER (1..15) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the DTIM period at which - buffered multicast data frames are transmitted by an interface - operating in host ap mode. Its value indicates the number of - beacon intervals between DTIM." - DEFVAL { 1 } - ::= { wlanIfaceConfigEntry 25 } - -wlanIfaceHideSsid OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether broadcasting of the - SSID in beacon frames and responding to undirected probe request - frames is enabled for an interface operating in ap mode." - DEFVAL { false } - ::= { wlanIfaceConfigEntry 26 } - -wlanIfaceInactivityProccess OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether inactivity processing - for associated station on an interface operating in ap mode is - enabled." - DEFVAL { true } - ::= { wlanIfaceConfigEntry 27 } - -wlanIfaceDot11gProtMode OBJECT-TYPE - SYNTAX INTEGER { - off(1), - cts(2), - rtscts(3) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the technique used for - protecting OFDM frames in a mixed 11b/11g network." - ::= { wlanIfaceConfigEntry 28 } - -wlanIfaceDot11gPureMode OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether only 802.11g-capable - stations will be allowed to associate to an interface operating - as access point in 802.11g mode." - ::= { wlanIfaceConfigEntry 29 } - -wlanIfaceDot11nPureMode OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether only HT-capable - stations will be allowed to associate to an interface operating - as access point in 802.11n mode." - ::= { wlanIfaceConfigEntry 30 } - -wlanIfaceDot11nAmpdu OBJECT-TYPE - SYNTAX WlanIfaceDot11nPduType - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether sending and - receiving of AMPDU frames is enabled on an interface - operating in 802.11n mode." - DEFVAL { txAndRx } - ::= { wlanIfaceConfigEntry 31 } - -wlanIfaceDot11nAmpduDensity OBJECT-TYPE - SYNTAX INTEGER (0|25|50|100|200|400|800|1600) - UNITS "1/100ths-of-microsecond" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the AMPDU density parameter - for an interface operating in 802.11n mode." - ::= { wlanIfaceConfigEntry 32 } - -wlanIfaceDot11nAmpduLimit OBJECT-TYPE - SYNTAX INTEGER (8192|16384|32768|65536) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies a limit on the AMPDU packet - size for receiving AMPDU frames for an interface operating in - 802.11n mode." - ::= { wlanIfaceConfigEntry 33 } - -wlanIfaceDot11nAmsdu OBJECT-TYPE - SYNTAX WlanIfaceDot11nPduType - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether sending and receiving - of AMSDU frames is enabled on an interface operating in 802.11n - mode." - DEFVAL { rxOnly } - ::= { wlanIfaceConfigEntry 34 } - -wlanIfaceDot11nAmsduLimit OBJECT-TYPE - SYNTAX INTEGER (3839|7935) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies a limit on the AMSDU packet - size when sending and receiving AMSDU frames for an interface - operating in 802.11n mode." - ::= { wlanIfaceConfigEntry 35 } - -wlanIfaceDot11nHighThroughput OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether use of High Throughput - (HT) is enabled for an interface operating in 802.11n mode." - DEFVAL { true } - ::= { wlanIfaceConfigEntry 36 } - -wlanIfaceDot11nHTCompatible OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether use of compatibility - support for pre-802.11n devices is enabled for an interface - operating in 802.11n mode." - DEFVAL { true } - ::= { wlanIfaceConfigEntry 37 } - -wlanIfaceDot11nHTProtMode OBJECT-TYPE - SYNTAX INTEGER { - off(1), - rts(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the technique used for - protecting HT frames in a mixed legacy/HT network for interfaces - operating in 802.11n mode." - DEFVAL { rts } - ::= { wlanIfaceConfigEntry 38 } - -wlanIfaceDot11nRIFS OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether Reduced InterFrame - Spacing (RIFS) is enabled for an interface operating in 802.11n - mode on an HT channel." - ::= { wlanIfaceConfigEntry 39 } - -wlanIfaceDot11nShortGI OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether use of Short Guard - Interval is enabled on an interface operating in 802.11n mode - on an HT channel." - ::= { wlanIfaceConfigEntry 40 } - -wlanIfaceDot11nSMPSMode OBJECT-TYPE - SYNTAX INTEGER { - disabled(1), - static(2), - dynamic(3) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies whether use of Spatial Multiplexing - Power Save (SMPS) is enabled on an interface operating in 802.11n mode - and whether SMPS mode is set to Static or Dynamic. The value is only - meaningfull for interfaces that support SMPS." - ::= { wlanIfaceConfigEntry 41 } - -wlanIfaceTdmaSlot OBJECT-TYPE - SYNTAX INTEGER (0..2) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the slot configuration to use - when operating in TDMA mode." - ::= { wlanIfaceConfigEntry 42 } - -wlanIfaceTdmaSlotCount OBJECT-TYPE - SYNTAX INTEGER (0..2) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the number of slots to use to - setup a BSS for an interface operating in TDMA mode." - ::= { wlanIfaceConfigEntry 43 } - -wlanIfaceTdmaSlotLength OBJECT-TYPE - SYNTAX INTEGER (150..65000) - UNITS "microseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies a slot length that each station - has when a BSS is setup by an interface operating in TDMA mode." - DEFVAL { 10000 } - ::= { wlanIfaceConfigEntry 44 } - -wlanIfaceTdmaBeaconInterval OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the number of superframes at - which a beacon frame is sent to synchronize the TDMA slot timing - for interfaces operating in TDMA mode." - DEFVAL { 5 } - ::= { wlanIfaceConfigEntry 45 } - -wlanIfacePeerTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanIfacePeerEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information about the associated stations - for an interface operating as an access point, or the stations - identified as neighbors in the IBSS for an interface operating in - adhoc mode." - ::= { begemotWlanInterface 4 } - -wlanIfacePeerEntry OBJECT-TYPE - SYNTAX WlanIfacePeerEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "An entry that contains information for the associated stations - for an interface operating as an access point, or the neighboring - stations of an interface in adhoc mode." - INDEX { wlanIfaceName, wlanIfacePeerAddress } - ::= { wlanIfacePeerTable 1 } - -WlanIfacePeerEntry ::= SEQUENCE { - wlanIfacePeerAddress MacAddress, - wlanIfacePeerAssociationId INTEGER, - wlanIfacePeerVlanTag INTEGER, - wlanIfacePeerFrequency INTEGER, - wlanIfacePeerCurrentTXRate INTEGER, - wlanIfacePeerRxSignalStrength INTEGER, - wlanIfacePeerIdleTimer INTEGER, - wlanIfacePeerTxSequenceNo INTEGER, - wlanIfacePeerRxSequenceNo INTEGER, - wlanIfacePeerTxPower INTEGER, - wlanIfacePeerCapabilities BITS, - wlanIfacePeerFlags BITS -} - -wlanIfacePeerAddress OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The MAC address of this peer." - ::= { wlanIfacePeerEntry 1 } - -wlanIfacePeerAssociationId OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The ID of the associacition with this peer." - ::= { wlanIfacePeerEntry 2 } - -wlanIfacePeerVlanTag OBJECT-TYPE - SYNTAX INTEGER (0..4096) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The Vlan Tag for traffic to/from this peer." - ::= { wlanIfacePeerEntry 3 } - -wlanIfacePeerFrequency OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operating frequency for the link with this peer." - ::= { wlanIfacePeerEntry 4 } - -wlanIfacePeerCurrentTXRate OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The current transmit rate for this peer." - ::= { wlanIfacePeerEntry 5 } - -wlanIfacePeerRxSignalStrength OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The average receive signal strength for this peer." - ::= { wlanIfacePeerEntry 6 } - -wlanIfacePeerIdleTimer OBJECT-TYPE - SYNTAX INTEGER - UNITS "seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The value of this peer's inactivity timer." - ::= { wlanIfacePeerEntry 7 } - -wlanIfacePeerTxSequenceNo OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last sequence number transmitted to this peer." - ::= { wlanIfacePeerEntry 8 } - -wlanIfacePeerRxSequenceNo OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last sequence number received from this peer." - ::= { wlanIfacePeerEntry 9 } - -wlanIfacePeerTxPower OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The transmit power limit for this peer." - ::= { wlanIfacePeerEntry 10 } - -wlanIfacePeerCapabilities OBJECT-TYPE - SYNTAX WlanPeerCapabilityFlags - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The capabilities advertised by this peer." - ::= { wlanIfacePeerEntry 11 } - -wlanIfacePeerFlags OBJECT-TYPE - SYNTAX BITS { - authorizedForData(1), - qosEnabled(2), - erpEnabled(3), - powerSaveMode(4), - authRefHeld(5), - htEnabled(6), - htCompat(7), - wpsAssoc(8), - tsnAssoc(9), - ampduRx(10), - ampduTx(11), - mimoPowerSave(12), - sendRts(13), - rifs(14), - shortGiHT20(15), - shortGiHT40(16), - amsduRx(17), - amsduTx(18) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The peer state flags." - ::= { wlanIfacePeerEntry 12 } - -wlanIfaceChannelTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanIfaceChannelEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information about the active channels for - the cloned wireless interfaces in the system." - ::= { begemotWlanInterface 5 } - -wlanIfaceChannelEntry OBJECT-TYPE - SYNTAX WlanIfaceChannelEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "An entry that contains active channel information for the wireless - interface." - INDEX { wlanIfaceName, wlanIfaceChannelId } - ::= { wlanIfaceChannelTable 1 } - -WlanIfaceChannelEntry ::= SEQUENCE { - wlanIfaceChannelId INTEGER, - wlanIfaceChannelIeeeId INTEGER, - wlanIfaceChannelType INTEGER, - wlanIfaceChannelFlags BITS, - wlanIfaceChannelFrequency INTEGER, - wlanIfaceChannelMaxRegPower INTEGER, - wlanIfaceChannelMaxTxPower INTEGER, - wlanIfaceChannelMinTxPower INTEGER, - wlanIfaceChannelState BITS, - wlanIfaceChannelHTExtension INTEGER, - wlanIfaceChannelMaxAntennaGain INTEGER -} - -wlanIfaceChannelId OBJECT-TYPE - SYNTAX INTEGER (1..1536) - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The index of this channel entry." - ::= { wlanIfaceChannelEntry 1 } - -wlanIfaceChannelIeeeId OBJECT-TYPE - SYNTAX INTEGER (1..256) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The channel IEEE ID." - ::= { wlanIfaceChannelEntry 2 } - -wlanIfaceChannelType OBJECT-TYPE - SYNTAX INTEGER { - fhss(1), - dot11a(2), - dot11b(3), - dot11g(4), - tenMHz(5), - fiveMHz(6), - turbo(7), - ht(8) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operating channel type for this entry." - ::= { wlanIfaceChannelEntry 3 } - -wlanIfaceChannelFlags OBJECT-TYPE - SYNTAX BITS { - turbo(1), - cck(2), - ofdm(3), - spectrum2Ghz(4), - spectrum5Ghz(5), - passiveScan(6), - dynamicCckOfdm(7), - gfsk(8), - spectrum900Mhz(9), - dot11aStaticTurbo(10), - halfRate(11), - quarterRate(12), - ht20(13), - ht40u(14), - ht40d(15), - dfs(16), - xmit4ms(17), - noAdhoc(18), - noHostAp(19), - dot11d(20) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The channel flags." - ::= { wlanIfaceChannelEntry 4 } - -wlanIfaceChannelFrequency OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The channel frequency setting in Mhz." - ::= { wlanIfaceChannelEntry 5 } - -wlanIfaceChannelMaxRegPower OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The maximum regulatory tx power in dBm for this channel." - ::= { wlanIfaceChannelEntry 6 } - -wlanIfaceChannelMaxTxPower OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The maximum tx power in units of .5 dBm for this channel." - ::= { wlanIfaceChannelEntry 7 } - -wlanIfaceChannelMinTxPower OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The minimum tx power in units of .5 dBm for this channel." - ::= { wlanIfaceChannelEntry 8 } - -wlanIfaceChannelState OBJECT-TYPE - SYNTAX BITS { - radar(1), - cacDone(2), - interferenceDetected(3), - radarClear(4) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The channel dynamic state." - ::= { wlanIfaceChannelEntry 9 } - -wlanIfaceChannelHTExtension OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The HT40 extension channel number." - ::= { wlanIfaceChannelEntry 10 } - -wlanIfaceChannelMaxAntennaGain OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The maximum antenna gain in units of .5 dBm." - ::= { wlanIfaceChannelEntry 11 } - --- ---------------------------------------------------------- -- --- The Scan requests/results for cloned wireless interfaces --- ---------------------------------------------------------- -- - -wlanScanConfigTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanScanConfigEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains a configuration for channel scanning - initiated via SNMP." - ::= { begemotWlanScanning 1 } - -wlanScanConfigEntry OBJECT-TYPE - SYNTAX WlanScanConfigEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Per cloned wireless interface channel scan configuration data. - The entry will be empty if no scans were initiated via SNMP." - INDEX { wlanIfaceName } - ::= { wlanScanConfigTable 1 } - -WlanScanConfigEntry ::= SEQUENCE { - wlanScanFlags BITS, - wlanScanDuration INTEGER, - wlanScanMinChannelDwellTime INTEGER, - wlanScanMaxChannelDwellTime INTEGER, - wlanScanConfigStatus INTEGER -} - -wlanScanFlags OBJECT-TYPE - SYNTAX BITS { - noSelection(1), - activeScan(2), - pickFirst(3), - backgroundScan(4), - once(5), - noBroadcast(6), - noAutoSequencing(7), - flushCashe(8), - chechCashe(9) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Desired flags for the channel scan." - ::= { wlanScanConfigEntry 1 } - -wlanScanDuration OBJECT-TYPE - SYNTAX INTEGER (1..2147483647) - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The desired duration of the scan. Setting the value of this object - to the highest allowed value will initiate an infinite scan." - ::= { wlanScanConfigEntry 2 } - -wlanScanMinChannelDwellTime OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The minimum channel dwelltime for this scan." - ::= { wlanScanConfigEntry 3 } - -wlanScanMaxChannelDwellTime OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum channel dwelltime for this scan." - ::= { wlanScanConfigEntry 4 } - -wlanScanConfigStatus OBJECT-TYPE - SYNTAX INTEGER { - unknown(0), - notStarted(1), - running(2), - finished(3), - cancel(4) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This object is used to initiate or cancel channel scanning on the cloned - interface via SNMP. Setting its value to running(2) will initiate channel - scanning on the cloned interface, while setting the value to cancel will - cancel the current ongoing scan. All other values should be returned in - GET operations only." - ::= { wlanScanConfigEntry 5 } - -wlanScanResultsTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanScanResultsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains scan results for a virtual wireless interface." - ::= { begemotWlanScanning 2 } - -wlanScanResultsEntry OBJECT-TYPE - SYNTAX WlanScanResultsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Per virtual wireless interface channel scan results data." - INDEX { wlanIfaceName, wlanScanResultID, wlanScanResultBssid } - ::= { wlanScanResultsTable 1 } - -WlanScanResultsEntry ::= SEQUENCE { - wlanScanResultID OCTET STRING, - wlanScanResultBssid MacAddress, - wlanScanResultChannel INTEGER, - wlanScanResultRate INTEGER, - wlanScanResultNoise INTEGER, - wlanScanResultBeaconInterval INTEGER, - wlanScanResultCapabilities BITS -} - -wlanScanResultID OBJECT-TYPE - SYNTAX OCTET STRING (SIZE(0..32)) - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The SSID/MESH ID for this scan result entry." - ::= { wlanScanResultsEntry 1 } - -wlanScanResultBssid OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The BSSID for this scan result entry." - ::= { wlanScanResultsEntry 2 } - -wlanScanResultChannel OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operating channel for this scan result entry." - ::= { wlanScanResultsEntry 3 } - -wlanScanResultRate OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operating rate of this scan result entry." - ::= { wlanScanResultsEntry 4 } - -wlanScanResultNoise OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The channel noise for this scan result entry." - ::= { wlanScanResultsEntry 5 } - -wlanScanResultBeaconInterval OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The beacon interval reported for this scan result entry." - ::= { wlanScanResultsEntry 6 } - -wlanScanResultCapabilities OBJECT-TYPE - SYNTAX WlanPeerCapabilityFlags - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The capabilities advertised for this scan result entry." - ::= { wlanScanResultsEntry 7 } - -wlanIfRoamParamsTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanIfRoamParamsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains the parameters that govern the roaming - operation on a wireless interface." - ::= { begemotWlanInterface 6 } - -wlanIfRoamParamsEntry OBJECT-TYPE - SYNTAX WlanIfRoamParamsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "An entry that contains the roaming parameters of a wireless - interface." - INDEX { wlanIfaceName, wlanIfRoamPhyMode } - ::= { wlanIfRoamParamsTable 1 } - -WlanIfRoamParamsEntry ::= SEQUENCE { - wlanIfRoamPhyMode INTEGER, - wlanIfRoamRxSignalStrength INTEGER, - wlanIfRoamTxRateThreshold INTEGER -} - -wlanIfRoamPhyMode OBJECT-TYPE - SYNTAX WlanIfPhyMode - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The PHY mode for this roaming parameters entry." - ::= { wlanIfRoamParamsEntry 1 } - -wlanIfRoamRxSignalStrength OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The Receive Signal Strength for this roaming parameters entry." - ::= { wlanIfRoamParamsEntry 2 } - -wlanIfRoamTxRateThreshold OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The transmit rate threshold value for this roaming parameters - entry in Mb/s or MCS." - ::= { wlanIfRoamParamsEntry 3 } - -wlanIfTxParamsTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanIfTxParamsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains the parameters that govern the transmit - operation on a wireless interface." - ::= { begemotWlanInterface 7 } - -wlanIfTxParamsEntry OBJECT-TYPE - SYNTAX WlanIfTxParamsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "An entry that contains the transmit parameters of a wireless - interface." - INDEX { wlanIfaceName, wlanIfTxPhyMode } - ::= { wlanIfTxParamsTable 1 } - -WlanIfTxParamsEntry ::= SEQUENCE { - wlanIfTxPhyMode INTEGER, - wlanIfTxUnicastRate INTEGER, - wlanIfTxMcastRate INTEGER, - wlanIfTxMgmtRate INTEGER, - wlanIfTxMaxRetryCount INTEGER -} - -wlanIfTxPhyMode OBJECT-TYPE - SYNTAX WlanIfPhyMode - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The PHY mode for this entry." - ::= { wlanIfTxParamsEntry 1 } - -wlanIfTxUnicastRate OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies a fixed rate for transmitting - unicast frames in this phy mode." - ::= { wlanIfTxParamsEntry 2 } - -wlanIfTxMcastRate OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies a fixed rate for transmitting - broadcast and multicast frames in this phy mode." - ::= { wlanIfTxParamsEntry 3 } - -wlanIfTxMgmtRate OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies a fixed rate for transmitting - management and/or control frames in this phy mode." - ::= { wlanIfTxParamsEntry 4 } - -wlanIfTxMaxRetryCount OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of tries to use when sending unicast frames - in this phy mode." - ::= { wlanIfTxParamsEntry 5 } - --- ---------------------------------------------------------- -- --- The Statistics Database for Wireless interfaces --- ---------------------------------------------------------- -- - -wlanIfaceStatisticsTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanIfaceStatisticsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains summary statistics for each virtual wireless - interface on the managed device." - ::= { begemotWlanStatistics 1 } - -wlanIfaceStatisticsEntry OBJECT-TYPE - SYNTAX WlanIfaceStatisticsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of statistics for each virtual wireless interface." - AUGMENTS { wlanInterfaceEntry } - ::= { wlanIfaceStatisticsTable 1 } - -WlanIfaceStatisticsEntry ::= SEQUENCE { - wlanStatsRxBadVersion Counter32, - wlanStatsRxTooShort Counter32, - wlanStatsRxWrongBssid Counter32, - wlanStatsRxDiscardedDups Counter32, - wlanStatsRxWrongDir Counter32, - wlanStatsRxDiscardMcastEcho Counter32, - wlanStatsRxDiscardNoAssoc Counter32, - wlanStatsRxWepNoPrivacy Counter32, - wlanStatsRxWepUnencrypted Counter32, - wlanStatsRxWepFailed Counter32, - wlanStatsRxDecapsulationFailed Counter32, - wlanStatsRxDiscardMgmt Counter32, - wlanStatsRxControl Counter32, - wlanStatsRxBeacon Counter32, - wlanStatsRxRateSetTooBig Counter32, - wlanStatsRxElemMissing Counter32, - wlanStatsRxElemTooBig Counter32, - wlanStatsRxElemTooSmall Counter32, - wlanStatsRxElemUnknown Counter32, - wlanStatsRxChannelMismatch Counter32, - wlanStatsRxDropped Counter32, - wlanStatsRxSsidMismatch Counter32, - wlanStatsRxAuthNotSupported Counter32, - wlanStatsRxAuthFailed Counter32, - wlanStatsRxAuthCM Counter32, - wlanStatsRxAssocWrongBssid Counter32, - wlanStatsRxAssocNoAuth Counter32, - wlanStatsRxAssocCapMismatch Counter32, - wlanStatsRxAssocNoRateMatch Counter32, - wlanStatsRxBadWpaIE Counter32, - wlanStatsRxDeauthenticate Counter32, - wlanStatsRxDisassociate Counter32, - wlanStatsRxUnknownSubtype Counter32, - wlanStatsRxFailedNoBuf Counter32, - wlanStatsRxBadAuthRequest Counter32, - wlanStatsRxUnAuthorized Counter32, - wlanStatsRxBadKeyId Counter32, - wlanStatsRxCCMPSeqViolation Counter32, - wlanStatsRxCCMPBadFormat Counter32, - wlanStatsRxCCMPFailedMIC Counter32, - wlanStatsRxTKIPSeqViolation Counter32, - wlanStatsRxTKIPBadFormat Counter32, - wlanStatsRxTKIPFailedMIC Counter32, - wlanStatsRxTKIPFailedICV Counter32, - wlanStatsRxDiscardACL Counter32, - wlanStatsTxFailedNoBuf Counter32, - wlanStatsTxFailedNoNode Counter32, - wlanStatsTxUnknownMgmt Counter32, - wlanStatsTxBadCipher Counter32, - wlanStatsTxNoDefKey Counter32, - wlanStatsTxFragmented Counter32, - wlanStatsTxFragmentsCreated Counter32, - wlanStatsActiveScans Counter32, - wlanStatsPassiveScans Counter32, - wlanStatsTimeoutInactivity Counter32, - wlanStatsCryptoNoMem Counter32, - wlanStatsSwCryptoTKIP Counter32, - wlanStatsSwCryptoTKIPEnMIC Counter32, - wlanStatsSwCryptoTKIPDeMIC Counter32, - wlanStatsCryptoTKIPCM Counter32, - wlanStatsSwCryptoCCMP Counter32, - wlanStatsSwCryptoWEP Counter32, - wlanStatsCryptoCipherKeyRejected Counter32, - wlanStatsCryptoNoKey Counter32, - wlanStatsCryptoDeleteKeyFailed Counter32, - wlanStatsCryptoUnknownCipher Counter32, - wlanStatsCryptoAttachFailed Counter32, - wlanStatsCryptoKeyFailed Counter32, - wlanStatsCryptoEnMICFailed Counter32, - wlanStatsIBSSCapMismatch Counter32, - wlanStatsUnassocStaPSPoll Counter32, - wlanStatsBadAidPSPoll Counter32, - wlanStatsEmptyPSPoll Counter32, - wlanStatsRxFFBadHdr Counter32, - wlanStatsRxFFTooShort Counter32, - wlanStatsRxFFSplitError Counter32, - wlanStatsRxFFDecap Counter32, - wlanStatsTxFFEncap Counter32, - wlanStatsRxBadBintval Counter32, - wlanStatsRxDemicFailed Counter32, - wlanStatsRxDefragFailed Counter32, - wlanStatsRxMgmt Counter32, - wlanStatsRxActionMgmt Counter32, - wlanStatsRxAMSDUTooShort Counter32, - wlanStatsRxAMSDUSplitError Counter32, - wlanStatsRxAMSDUDecap Counter32, - wlanStatsTxAMSDUEncap Counter32, - wlanStatsAMPDUBadBAR Counter32, - wlanStatsAMPDUOowBar Counter32, - wlanStatsAMPDUMovedBAR Counter32, - wlanStatsAMPDURxBAR Counter32, - wlanStatsAMPDURxOor Counter32, - wlanStatsAMPDURxCopied Counter32, - wlanStatsAMPDURxDropped Counter32, - wlanStatsTxDiscardBadState Counter32, - wlanStatsTxFailedNoAssoc Counter32, - wlanStatsTxClassifyFailed Counter32, - wlanStatsDwdsMcastDiscard Counter32, - wlanStatsHTAssocRejectNoHT Counter32, - wlanStatsHTAssocDowngrade Counter32, - wlanStatsHTAssocRateMismatch Counter32, - wlanStatsAMPDURxAge Counter32, - wlanStatsAMPDUMoved Counter32, - wlanStatsADDBADisabledReject Counter32, - wlanStatsADDBANoRequest Counter32, - wlanStatsADDBABadToken Counter32, - wlanStatsADDBABadPolicy Counter32, - wlanStatsAMPDUStopped Counter32, - wlanStatsAMPDUStopFailed Counter32, - wlanStatsAMPDURxReorder Counter32, - wlanStatsScansBackground Counter32, - wlanLastDeauthReason INTEGER, - wlanLastDissasocReason INTEGER, - wlanLastAuthFailReason INTEGER, - wlanStatsBeaconMissedEvents Counter32, - wlanStatsRxDiscardBadStates Counter32, - wlanStatsFFFlushed Counter32, - wlanStatsTxControlFrames Counter32, - wlanStatsAMPDURexmt Counter32, - wlanStatsAMPDURexmtFailed Counter32, - wlanStatsReset INTEGER -} - -wlanStatsRxBadVersion OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that had bad version." - ::= { wlanIfaceStatisticsEntry 1 } - -wlanStatsRxTooShort OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were too short." - ::= { wlanIfaceStatisticsEntry 2 } - -wlanStatsRxWrongBssid OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with wrong BSSID." - ::= { wlanIfaceStatisticsEntry 3 } - -wlanStatsRxDiscardedDups OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received discarded duplicate frames by this interface." - ::= { wlanIfaceStatisticsEntry 4 } - -wlanStatsRxWrongDir OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received frames by this interface that were dropped - due to wrong direction." - ::= { wlanIfaceStatisticsEntry 5 } - -wlanStatsRxDiscardMcastEcho OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received multicast echo frames discarded by this - interface." - ::= { wlanIfaceStatisticsEntry 6 } - -wlanStatsRxDiscardNoAssoc OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were dropped - since no association existed with the sending station." - ::= { wlanIfaceStatisticsEntry 7 } - -wlanStatsRxWepNoPrivacy OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were dropped - since they contained WEP information and WEP privacy was off." - ::= { wlanIfaceStatisticsEntry 8 } - -wlanStatsRxWepUnencrypted OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were dropped - since they contained no WEP information and WEP privacy was on." - ::= { wlanIfaceStatisticsEntry 9 } - -wlanStatsRxWepFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were dropped - since processing of the WEP information contained in them failed." - ::= { wlanIfaceStatisticsEntry 10 } - -wlanStatsRxDecapsulationFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received frames that were discarded by this interface - due to decapsulation failure." - ::= { wlanIfaceStatisticsEntry 11 } - -wlanStatsRxDiscardMgmt OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received management frames discarded by this interface." - ::= { wlanIfaceStatisticsEntry 12 } - -wlanStatsRxControl OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of control frames received by this interface." - ::= { wlanIfaceStatisticsEntry 13 } - -wlanStatsRxBeacon OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of beacon frames received by this interface." - ::= { wlanIfaceStatisticsEntry 14 } - -wlanStatsRxRateSetTooBig OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with extended - supported rate element." - ::= { wlanIfaceStatisticsEntry 15 } - -wlanStatsRxElemMissing OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were missing - a required element." - ::= { wlanIfaceStatisticsEntry 16 } - -wlanStatsRxElemTooBig OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that contained an - information element whose size was too big." - ::= { wlanIfaceStatisticsEntry 17 } - -wlanStatsRxElemTooSmall OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that contained an - information element whose size was too small." - ::= { wlanIfaceStatisticsEntry 18 } - -wlanStatsRxElemUnknown OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that contained an - unknown information element." - ::= { wlanIfaceStatisticsEntry 19 } - -wlanStatsRxChannelMismatch OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface, that were discarded - since they were received on a channel different from the one indicated - in the DS params element id." - ::= { wlanIfaceStatisticsEntry 20 } - -wlanStatsRxDropped OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were dropped due - to unknown reason." - ::= { wlanIfaceStatisticsEntry 21 } - -wlanStatsRxSsidMismatch OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that had a bad SSID." - ::= { wlanIfaceStatisticsEntry 22 } - -wlanStatsRxAuthNotSupported OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that contained an - unknown authentication algorithm." - ::= { wlanIfaceStatisticsEntry 23 } - -wlanStatsRxAuthFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface for which the - authentication failed." - ::= { wlanIfaceStatisticsEntry 24 } - -wlanStatsRxAuthCM OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface for which the - authentication failed due to TKIP countermeasures enabled." - ::= { wlanIfaceStatisticsEntry 25 } - -wlanStatsRxAssocWrongBssid OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with association - request that had a bad BSSID." - ::= { wlanIfaceStatisticsEntry 26 } - -wlanStatsRxAssocNoAuth OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with association - request that came from unauthentication node." - ::= { wlanIfaceStatisticsEntry 27 } - -wlanStatsRxAssocCapMismatch OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with association - request that had bad capabilities set." - ::= { wlanIfaceStatisticsEntry 28 } - -wlanStatsRxAssocNoRateMatch OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with association - request that had unsupported rate set." - ::= { wlanIfaceStatisticsEntry 29 } - -wlanStatsRxBadWpaIE OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with association - request that had no or invalid WPA information element." - ::= { wlanIfaceStatisticsEntry 30 } - -wlanStatsRxDeauthenticate OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of deauthentication requests received by this interface." - ::= { wlanIfaceStatisticsEntry 31 } - -wlanStatsRxDisassociate OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of deassociation requests received by this interface." - ::= { wlanIfaceStatisticsEntry 32 } - -wlanStatsRxUnknownSubtype OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that had unknown - subtype." - ::= { wlanIfaceStatisticsEntry 33 } - -wlanStatsRxFailedNoBuf OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were dropped - due to lack of free buffers." - ::= { wlanIfaceStatisticsEntry 34 } - -wlanStatsRxBadAuthRequest OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface for which - authentication failed." - ::= { wlanIfaceStatisticsEntry 35 } - -wlanStatsRxUnAuthorized OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of non-PAE frames received by this interface prior to - authorization." - ::= { wlanIfaceStatisticsEntry 36 } - -wlanStatsRxBadKeyId OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface with bad key." - ::= { wlanIfaceStatisticsEntry 37 } - -wlanStatsRxCCMPSeqViolation OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that caused CCMP - sequence violation." - ::= { wlanIfaceStatisticsEntry 38 } - -wlanStatsRxCCMPBadFormat OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that had bad CCMP - format." - ::= { wlanIfaceStatisticsEntry 39 } - -wlanStatsRxCCMPFailedMIC OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames receivbed by this interface for which CCMP - decryption failed due to MIC mismatch." - ::= { wlanIfaceStatisticsEntry 40 } - -wlanStatsRxTKIPSeqViolation OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that caused TKIP - sequence violation.." - ::= { wlanIfaceStatisticsEntry 41 } - -wlanStatsRxTKIPBadFormat OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were missing - TKIP ExtIV." - ::= { wlanIfaceStatisticsEntry 42 } - -wlanStatsRxTKIPFailedMIC OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface for which TKIP - decryption failed due to MIC mismatch." - ::= { wlanIfaceStatisticsEntry 43 } - -wlanStatsRxTKIPFailedICV OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface for which TKIP - decryption failed due to ICV mismatch." - ::= { wlanIfaceStatisticsEntry 44 } - -wlanStatsRxDiscardACL OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface that were - disallowed by ACL." - ::= { wlanIfaceStatisticsEntry 45 } - -wlanStatsTxFailedNoBuf OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were not transmitted by this interface - due to lack of free buffers." - ::= { wlanIfaceStatisticsEntry 46 } - -wlanStatsTxFailedNoNode OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were queued for transmit on this interface - but were not sent since appropriate node for sending was not found." - ::= { wlanIfaceStatisticsEntry 47 } - -wlanStatsTxUnknownMgmt OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of unknown management frames transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 48 } - -wlanStatsTxBadCipher OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were queued for transmit on this interface - but were not send since the specified key was not setup." - ::= { wlanIfaceStatisticsEntry 49 } - -wlanStatsTxNoDefKey OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were queued for transmit on this interface - but were not send since an appropriate key was not found." - ::= { wlanIfaceStatisticsEntry 50 } - -wlanStatsTxFragmented OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of fragmented frames transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 51 } - -wlanStatsTxFragmentsCreated OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of created fragments transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 52 } - -wlanStatsActiveScans OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of active scans performed by this interface." - ::= { wlanIfaceStatisticsEntry 53 } - -wlanStatsPassiveScans OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of passive scans performed by this interface." - ::= { wlanIfaceStatisticsEntry 54 } - -wlanStatsTimeoutInactivity OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times a station/node was dropped by this interface - due to inactivity timeout." - ::= { wlanIfaceStatisticsEntry 55 } - -wlanStatsCryptoNoMem OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number times attaching a crypto protocol to this interface - failed due to lack of memory." - ::= { wlanIfaceStatisticsEntry 56 } - -wlanStatsSwCryptoTKIP OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times TKIP encryption/decryption was handled in - software for frames received/transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 57 } - -wlanStatsSwCryptoTKIPEnMIC OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times TKIP MIC was added in software to frames - transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 58 } - -wlanStatsSwCryptoTKIPDeMIC OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times TKIP MIC was stripped in software from frames - received by this interface." - ::= { wlanIfaceStatisticsEntry 59 } - -wlanStatsCryptoTKIPCM OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames discarded by this interface due to TKIP - counter measures." - ::= { wlanIfaceStatisticsEntry 60 } - -wlanStatsSwCryptoCCMP OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times CCMP encryption/decryption was handled in - software for frames received/transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 61 } - -wlanStatsSwCryptoWEP OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times WEP encryption/decryption was handled in - software for frames received/transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 62 } - -wlanStatsCryptoCipherKeyRejected OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times a key was rejected for this interface." - ::= { wlanIfaceStatisticsEntry 63 } - -wlanStatsCryptoNoKey OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times key setup for this interface failed." - ::= { wlanIfaceStatisticsEntry 64 } - -wlanStatsCryptoDeleteKeyFailed OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times key deletion from driver for this interface - failed." - ::= { wlanIfaceStatisticsEntry 65 } - -wlanStatsCryptoUnknownCipher OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times key setup for this interface failed due to - invalid cipher." - ::= { wlanIfaceStatisticsEntry 66 } - -wlanStatsCryptoAttachFailed OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times attaching a cipher for this interface failed." - ::= { wlanIfaceStatisticsEntry 67 } - -wlanStatsCryptoKeyFailed OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times setting a cipher in the driver for this - interface failed." - ::= { wlanIfaceStatisticsEntry 68 } - -wlanStatsCryptoEnMICFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were discarded by by this interface - due to failed enmic." - ::= { wlanIfaceStatisticsEntry 69 } - -wlanStatsIBSSCapMismatch OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times a BSSID change failed for an interface operating - in ad hoc mode due to capabilities mismatch." - ::= { wlanIfaceStatisticsEntry 70 } - -wlanStatsUnassocStaPSPoll OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of ps-poll frames from unassociated station received - by this interface." - ::= { wlanIfaceStatisticsEntry 71 } - -wlanStatsBadAidPSPoll OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of ps-poll frames with incorrect aid received by this - interface." - ::= { wlanIfaceStatisticsEntry 72 } - -wlanStatsEmptyPSPoll OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of empty ps-poll frames received by this interface." - ::= { wlanIfaceStatisticsEntry 73 } - -wlanStatsRxFFBadHdr OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of fast frames with bad header received by this interface." - ::= { wlanIfaceStatisticsEntry 74 } - -wlanStatsRxFFTooShort OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of fast frames received by this interface, for which - decapsulation failed." - ::= { wlanIfaceStatisticsEntry 75 } - -wlanStatsRxFFSplitError OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of fast frames received by this interface, for which - decapsulation failed during split." - ::= { wlanIfaceStatisticsEntry 76 } - -wlanStatsRxFFDecap OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of fast frames received by this interface, that were - successfully decapsulated." - ::= { wlanIfaceStatisticsEntry 77 } - -wlanStatsTxFFEncap OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of encapsulated fast frames transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 78 } - -wlanStatsRxBadBintval OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames with bogus beacon interval received by this - interface." - ::= { wlanIfaceStatisticsEntry 79 } - -wlanStatsRxDemicFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface for which - stripping of the MIC failed." - ::= { wlanIfaceStatisticsEntry 80 } - -wlanStatsRxDefragFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received by this interface for which - defragmentation failed." - ::= { wlanIfaceStatisticsEntry 81 } - -wlanStatsRxMgmt OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of management frames received by this interface." - ::= { wlanIfaceStatisticsEntry 82 } - -wlanStatsRxActionMgmt OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of action management frames received by this interface." - ::= { wlanIfaceStatisticsEntry 83 } - -wlanStatsRxAMSDUTooShort OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MSDU frames received by this interface for which - decapsulaiton failed." - ::= { wlanIfaceStatisticsEntry 84 } - -wlanStatsRxAMSDUSplitError OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MSDU frames received by this interface for which - split failed." - ::= { wlanIfaceStatisticsEntry 85 } - -wlanStatsRxAMSDUDecap OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MSDU frames received by this interface which - were successfully decapsulaited." - ::= { wlanIfaceStatisticsEntry 86 } - -wlanStatsTxAMSDUEncap OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of encapsulated A-MSDU frames transmitted by this - interface." - ::= { wlanIfaceStatisticsEntry 87 } - -wlanStatsAMPDUBadBAR OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU frames that were dropped by this interface - source BAR frame processing was disabled." - ::= { wlanIfaceStatisticsEntry 88 } - -wlanStatsAMPDUOowBar OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU BAR before ADDBA frames received by this - interface." - ::= { wlanIfaceStatisticsEntry 89 } - -wlanStatsAMPDUMovedBAR OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times a BAR moved window occurred." - ::= { wlanIfaceStatisticsEntry 90 } - -wlanStatsAMPDURxBAR OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU BAR frames received by this interface." - ::= { wlanIfaceStatisticsEntry 91 } - -wlanStatsAMPDURxOor OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of out-of-order A-MPDU frames by received this interface." - ::= { wlanIfaceStatisticsEntry 92 } - -wlanStatsAMPDURxCopied OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU frames by copied down this interface." - ::= { wlanIfaceStatisticsEntry 93 } - -wlanStatsAMPDURxDropped OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU frames by dropped this interface." - ::= { wlanIfaceStatisticsEntry 94 } - -wlanStatsTxDiscardBadState OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames queued for transmit on this interface that - were discarded due to interface state not ready for transmit." - ::= { wlanIfaceStatisticsEntry 95 } - -wlanStatsTxFailedNoAssoc OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames queued for transmit on this interface that - were discarded since the receiving station was not associated." - ::= { wlanIfaceStatisticsEntry 96 } - -wlanStatsTxClassifyFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames queued for transmit on this interface that - were discarded since their priority was not determined." - ::= { wlanIfaceStatisticsEntry 97 } - -wlanStatsDwdsMcastDiscard OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of multicast over DWDS frames discared by this interface." - ::= { wlanIfaceStatisticsEntry 98 } - -wlanStatsHTAssocRejectNoHT OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of management frames received from a non-HT stations - that were rejected by this interface." - ::= { wlanIfaceStatisticsEntry 99 } - -wlanStatsHTAssocDowngrade OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times HT was dissallowed for an association on - this interface due to WEP or TKIP requested." - ::= { wlanIfaceStatisticsEntry 100 } - -wlanStatsHTAssocRateMismatch OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times rate mismatch occured furing HT rate set - handling on this interface." - ::= { wlanIfaceStatisticsEntry 101 } - -wlanStatsAMPDURxAge OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU frames sent by this interface due to aging out." - ::= { wlanIfaceStatisticsEntry 102 } - -wlanStatsAMPDUMoved OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of time A-MPDU MSDU moved window occured for this - interface." - ::= { wlanIfaceStatisticsEntry 103 } - -wlanStatsADDBADisabledReject OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received ADDBA frames that were discarded by this - interface since ADDBA was disabled." - ::= { wlanIfaceStatisticsEntry 104 } - -wlanStatsADDBANoRequest OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received ADDBA responces frames that were discarded - by this interface due to no pending ADDBA." - ::= { wlanIfaceStatisticsEntry 105 } - -wlanStatsADDBABadToken OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received ADDBA responce frames that were discarded - by this interface since ADDBA response caused dialogtoken mismatch." - ::= { wlanIfaceStatisticsEntry 106 } - -wlanStatsADDBABadPolicy OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received ADDBA responce frames that were discarded - by this interface since ADDBA response caused policy mismatch." - ::= { wlanIfaceStatisticsEntry 107 } - -wlanStatsAMPDUStopped OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times a A-MPDU stream stopped on this interface." - ::= { wlanIfaceStatisticsEntry 108 } - -wlanStatsAMPDUStopFailed OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times a A-MPDU stream stop failed on this interface." - ::= { wlanIfaceStatisticsEntry 109 } - -wlanStatsAMPDURxReorder OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of received reordered A-MPDU frames on this interface." - ::= { wlanIfaceStatisticsEntry 110 } - -wlanStatsScansBackground OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of background scans started on this interface." - ::= { wlanIfaceStatisticsEntry 111 } - -wlanLastDeauthReason OBJECT-TYPE - SYNTAX WlanMgmtReasonCode - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last received deauthenticate reason on this interface." - ::= { wlanIfaceStatisticsEntry 112 } - -wlanLastDissasocReason OBJECT-TYPE - SYNTAX WlanMgmtReasonCode - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last received dissasociate reason on this interface." - ::= { wlanIfaceStatisticsEntry 113 } - -wlanLastAuthFailReason OBJECT-TYPE - SYNTAX WlanMgmtReasonCode - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last received authentication failed reason on this interface." - ::= { wlanIfaceStatisticsEntry 114 } - -wlanStatsBeaconMissedEvents OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of beacon miss notification events on this interface." - ::= { wlanIfaceStatisticsEntry 115 } - -wlanStatsRxDiscardBadStates OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames received on this interface that were discarded - due to interface state not ready for receive." - ::= { wlanIfaceStatisticsEntry 116 } - -wlanStatsFFFlushed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of fast frames flushed from the stage queue on this - interface." - ::= { wlanIfaceStatisticsEntry 117 } - -wlanStatsTxControlFrames OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of control frames transmitted by this interface." - ::= { wlanIfaceStatisticsEntry 118 } - -wlanStatsAMPDURexmt OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU frames successfully retransmitted by this - interface." - ::= { wlanIfaceStatisticsEntry 119 } - -wlanStatsAMPDURexmtFailed OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of A-MPDU frames for which retransmition failed on - this interface." - ::= { wlanIfaceStatisticsEntry 120 } - -wlanStatsReset OBJECT-TYPE - SYNTAX INTEGER { - no-op(1), - clear(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object is used to reset the statistics on this - interface." - ::= { wlanIfaceStatisticsEntry 121 } - --- ---------------------------------------------------------- -- --- The WEP Configuration Database for Wireless interfaces --- ---------------------------------------------------------- -- - -wlanWepInterfaceTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanWepInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains WEP configuration for the wireless interfaces - on the managed system." - ::= { begemotWlanWep 1 } - -wlanWepInterfaceEntry OBJECT-TYPE - SYNTAX WlanWepInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "WEP Configuration for wireless interface." - INDEX { wlanIfaceName} - ::= { wlanWepInterfaceTable 1 } - -WlanWepInterfaceEntry ::= SEQUENCE { - wlanWepMode INTEGER, - wlanWepDefTxKey INTEGER -} - -wlanWepMode OBJECT-TYPE - SYNTAX INTEGER { - off(0), - on(1), - mixed(2) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The WEP mode set on the interface." - DEFVAL { off } - ::= { wlanWepInterfaceEntry 1 } - -wlanWepDefTxKey OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The index of the default WEP key for the interface." - ::= { wlanWepInterfaceEntry 2 } - -wlanWepKeyTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanWepKeyEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains the configured WEP keys for a virtual - wireless interface." - ::= { begemotWlanWep 2 } - -wlanWepKeyEntry OBJECT-TYPE - SYNTAX WlanWepKeyEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A configured WEP Key entry." - INDEX { wlanIfaceName, wlanWepKeyID } - ::= { wlanWepKeyTable 1 } - -WlanWepKeyEntry ::= SEQUENCE { - wlanWepKeyID INTEGER, - wlanWepKeyLength INTEGER, - wlanWepKeySet OCTET STRING, - wlanWepKeyHash OCTET STRING, - wlanWepKeyStatus RowStatus -} - -wlanWepKeyID OBJECT-TYPE - SYNTAX INTEGER (1..4) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The WEP Key ID." - ::= { wlanWepKeyEntry 1 } - -wlanWepKeyLength OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The WEP Key length." - ::= { wlanWepKeyEntry 2 } - -wlanWepKeySet OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The WEP Key String to configure for this key. When GET is attempted - for this column, an empty Octet String is returned." - ::= { wlanWepKeyEntry 3 } - -wlanWepKeyHash OBJECT-TYPE - SYNTAX OCTET STRING - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The SHA256 hash produced of the WEP Key String." - ::= { wlanWepKeyEntry 4 } - -wlanWepKeyStatus OBJECT-TYPE - SYNTAX RowStatus - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This object is used for creating/deleting WEP keys." - ::= { wlanWepKeyEntry 5 } - --- ---------------------------------------------------------- -- --- The MAC Access Control Database for Wireless interfaces --- ---------------------------------------------------------- -- - -wlanMACAccessControlTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanMACAccessControlEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains Access Control configuration for wireless - interfaces operating as an access point." - ::= { begemotWlanMACAccessControl 1 } - -wlanMACAccessControlEntry OBJECT-TYPE - SYNTAX WlanMACAccessControlEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The MAC Access Control configuration for a wireless interface - operating as an access point." - INDEX { wlanIfaceName} - ::= { wlanMACAccessControlTable 1 } - -WlanMACAccessControlEntry ::= SEQUENCE { - wlanMACAccessControlPolicy INTEGER, - wlanMACAccessControlNacl Counter32, - wlanMACAccessControlFlush INTEGER -} - -wlanMACAccessControlPolicy OBJECT-TYPE - SYNTAX INTEGER { - open(0), - allow(1), - deny(2), - radius(7) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the MAC Access Control policy - for this Host AP interface." - DEFVAL { open } - ::= { wlanMACAccessControlEntry 1 } - -wlanMACAccessControlNacl OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of active MAC Access Control Entries in the Database - for this Host AP interface." - ::= { wlanMACAccessControlEntry 2 } - -wlanMACAccessControlFlush OBJECT-TYPE - SYNTAX INTEGER { - no-op(0), - flush(1) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This object is used to flush all entries from the MAC Access - Control Database for the specified virtual wireless interface." - ::= { wlanMACAccessControlEntry 3 } - -wlanMACAccessControlMACTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanMACAccessControlMACEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains Access Control MAC for virtual wireless - interfaces operating in Host AP mode." - ::= { begemotWlanMACAccessControl 2 } - -wlanMACAccessControlMACEntry OBJECT-TYPE - SYNTAX WlanMACAccessControlMACEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "The MAC Access Control configuration database with MAC addresses - for a virtual wireless interface." - INDEX { wlanIfaceName, wlanMACAccessControlMAC } - ::= { wlanMACAccessControlMACTable 1 } - -WlanMACAccessControlMACEntry ::= SEQUENCE { - wlanMACAccessControlMAC MacAddress, - wlanMACAccessControlMACStatus RowStatus -} - -wlanMACAccessControlMAC OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The value of this object specifies the station's MAC to which - the Access Control policy will be applied." - ::= { wlanMACAccessControlMACEntry 1 } - -wlanMACAccessControlMACStatus OBJECT-TYPE - SYNTAX RowStatus - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The object is used to add or delete MAC entries from the Access - Control Database for this interface operating in Host AP mode. - To add an entry the value of this object should be set to createAndGo, - a value of destroy will remove an existing entry. A GET on this object - will always return value active." - ::= { wlanMACAccessControlMACEntry 2 } - --- ---------------------------------------------------------- -- --- The Mesh Routing Database for interfaces operating in mesh mode --- ---------------------------------------------------------- -- - -wlanMeshRoutingConfig OBJECT IDENTIFIER ::= { begemotWlanMeshRouting 1 } - -wlanMeshInterface OBJECT IDENTIFIER ::= { begemotWlanMeshRouting 2 } - -wlanMeshRoute OBJECT IDENTIFIER ::= { begemotWlanMeshRouting 3 } - -wlanMeshStatistics OBJECT IDENTIFIER ::= { begemotWlanMeshRouting 4 } - -wlanMeshRouteProtocols OBJECT IDENTIFIER ::= { begemotWlanMeshRouting 5 } - -wlanMeshMaxRetries OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Maximum retries during peer link establishment for wireless mesh - routing operation." - DEFVAL { 2 } - ::= { wlanMeshRoutingConfig 1 } - -wlanMeshConfirmTimeout OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Confirm state timeout for wireless mesh routing operation." - DEFVAL { 40 } - ::= { wlanMeshRoutingConfig 2 } - -wlanMeshHoldingTimeout OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Holding state timeout for wireless mesh routing operation." - DEFVAL { 40 } - ::= { wlanMeshRoutingConfig 3 } - -wlanMeshRetryTimeout OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Retry timeout for wireless mesh routing operation." - DEFVAL { 40 } - ::= { wlanMeshRoutingConfig 4 } - -wlanMeshInterfaceTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanMeshInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information for wireless interfaces operating - as wireless mesh points." - ::= { wlanMeshInterface 1 } - -wlanMeshInterfaceEntry OBJECT-TYPE - SYNTAX WlanMeshInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Wireless Mesh Routing information for an interface operating as - mesh point." - INDEX { wlanIfaceName } - ::= { wlanMeshInterfaceTable 1 } - -WlanMeshInterfaceEntry ::= SEQUENCE { - wlanMeshId OCTET STRING, - wlanMeshTTL INTEGER, - wlanMeshPeeringEnabled TruthValue, - wlanMeshForwardingEnabled TruthValue, - wlanMeshMetric INTEGER, - wlanMeshPath INTEGER, - wlanMeshRoutesFlush INTEGER -} - -wlanMeshId OBJECT-TYPE - SYNTAX OCTET STRING (SIZE(1..32)) - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The desired Mesh Identifier for the interface." - ::= { wlanMeshInterfaceEntry 1 } - -wlanMeshTTL OBJECT-TYPE - SYNTAX INTEGER - UNITS "hops" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The number of hops a packet may be forwarded before it is discarded." - DEFVAL { 31 } - ::= { wlanMeshInterfaceEntry 2 } - -wlanMeshPeeringEnabled OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Enable or disable peering with neighbor mesh stations for this - interface." - DEFVAL { true } - ::= { wlanMeshInterfaceEntry 3 } - -wlanMeshForwardingEnabled OBJECT-TYPE - SYNTAX TruthValue - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "Enable or disable forwarding packets by this interface." - DEFVAL { true } - ::= { wlanMeshInterfaceEntry 4 } - -wlanMeshMetric OBJECT-TYPE - SYNTAX INTEGER { - unknown(0), - airtime(1) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The link metric protocol used by the interface." - DEFVAL { airtime } - ::= { wlanMeshInterfaceEntry 5 } - -wlanMeshPath OBJECT-TYPE - SYNTAX INTEGER { - unknown(0), - hwmp(1) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The path selection protocol used by the interface." - DEFVAL { hwmp } - ::= { wlanMeshInterfaceEntry 6 } - -wlanMeshRoutesFlush OBJECT-TYPE - SYNTAX INTEGER { - no-op(0), - flush(1) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This object is used to flush all mesh route entries from the mesh - routing table for the specified interface." - ::= { wlanMeshInterfaceEntry 7 } - -wlanMeshNeighborTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanMeshNeighborEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information for the neighbors of wireless - interfaces operating in mesh mode." - ::= { wlanMeshInterface 2 } - -wlanMeshNeighborEntry OBJECT-TYPE - SYNTAX WlanMeshNeighborEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Information for all neighbors of a wireless interface operating as - a mesh point." - INDEX { wlanIfaceName, wlanMeshNeighborAddress } - ::= { wlanMeshNeighborTable 1 } - -WlanMeshNeighborEntry ::= SEQUENCE { - wlanMeshNeighborAddress MacAddress, - wlanMeshNeighborFrequency INTEGER, - wlanMeshNeighborLocalId INTEGER, - wlanMeshNeighborPeerId INTEGER, - wlanMeshNeighborPeerState INTEGER, - wlanMeshNeighborCurrentTXRate INTEGER, - wlanMeshNeighborRxSignalStrength INTEGER, - wlanMeshNeighborIdleTimer INTEGER, - wlanMeshNeighborTxSequenceNo INTEGER, - wlanMeshNeighborRxSequenceNo INTEGER -} - -wlanMeshNeighborAddress OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The Ethernet address of this neighbor." - ::= { wlanMeshNeighborEntry 1 } - -wlanMeshNeighborFrequency OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The operating frequency for the link with this neighbor." - ::= { wlanMeshNeighborEntry 2 } - -wlanMeshNeighborLocalId OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The local mesh id for this neighbor." - ::= { wlanMeshNeighborEntry 3 } - -wlanMeshNeighborPeerId OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The mesh peer id of this neighbor." - ::= { wlanMeshNeighborEntry 4 } - -wlanMeshNeighborPeerState OBJECT-TYPE - SYNTAX INTEGER { - idle(0), - openTx(1), - openRx(2), - confirmRx(3), - established(4), - closing(5) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The current link state for this neighbor." - ::= { wlanMeshNeighborEntry 5 } - -wlanMeshNeighborCurrentTXRate OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The current transmit rate for this neighbor." - ::= { wlanMeshNeighborEntry 6 } - -wlanMeshNeighborRxSignalStrength OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The average receive signal strength for this neighbor." - ::= { wlanMeshNeighborEntry 7 } - -wlanMeshNeighborIdleTimer OBJECT-TYPE - SYNTAX INTEGER - UNITS "seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The value of this neighbor's inactivity timer." - ::= { wlanMeshNeighborEntry 8 } - -wlanMeshNeighborTxSequenceNo OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last sequence number transmitted to this neighbor." - ::= { wlanMeshNeighborEntry 9 } - -wlanMeshNeighborRxSequenceNo OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last sequence number received from this neighbor." - ::= { wlanMeshNeighborEntry 10 } - -wlanMeshRouteTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanMeshRouteEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains the mesh routing table for interfaces operating - as mesh points, used for forwarding packets on a mesh network." - ::= { wlanMeshRoute 1 } - -wlanMeshRouteEntry OBJECT-TYPE - SYNTAX WlanMeshRouteEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Wireless Mesh Routing Table entries for virtual wireless interfaces." - INDEX { wlanIfaceName, wlanMeshRouteDestination } - ::= { wlanMeshRouteTable 1 } - -WlanMeshRouteEntry ::= SEQUENCE { - wlanMeshRouteDestination MacAddress, - wlanMeshRouteNextHop MacAddress, - wlanMeshRouteHops INTEGER, - wlanMeshRouteMetric Unsigned32, - wlanMeshRouteLifeTime Unsigned32, - wlanMeshRouteLastMseq Unsigned32, - wlanMeshRouteFlags BITS, - wlanMeshRouteStatus RowStatus -} - -wlanMeshRouteDestination OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-create - STATUS current - DESCRIPTION - "The mesh route entry's destination address." - ::= { wlanMeshRouteEntry 1 } - -wlanMeshRouteNextHop OBJECT-TYPE - SYNTAX MacAddress - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The mesh route entry's next hop address." - ::= { wlanMeshRouteEntry 2 } - -wlanMeshRouteHops OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of hops for this mesh route entry." - ::= { wlanMeshRouteEntry 3 } - -wlanMeshRouteMetric OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The metric of this mesh route entry." - ::= { wlanMeshRouteEntry 4 } - -wlanMeshRouteLifeTime OBJECT-TYPE - SYNTAX Unsigned32 - UNITS "seconds" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The life time of this mesh route entry." - ::= { wlanMeshRouteEntry 5 } - -wlanMeshRouteLastMseq OBJECT-TYPE - SYNTAX Unsigned32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The last sequence number seen from this destination." - ::= { wlanMeshRouteEntry 6 } - -wlanMeshRouteFlags OBJECT-TYPE - SYNTAX BITS { - valid(1), - proxy(2) - } - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The Mesh Route entry's flags." - ::= { wlanMeshRouteEntry 7 } - -wlanMeshRouteStatus OBJECT-TYPE - SYNTAX RowStatus - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The object is used to add or delete entries from the mesh routing - table for the virtual wireless interface." - ::= { wlanMeshRouteEntry 8 } - -wlanMeshStatsTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanMeshStatsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains summary statistics for each virtual wireless - interface operating as mesh point." - ::= { wlanMeshStatistics 1 } - -wlanMeshStatsEntry OBJECT-TYPE - SYNTAX WlanMeshStatsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of statistics for each virtual wireless interface operating - as mesh point." - INDEX { wlanIfaceName } - ::= { wlanMeshStatsTable 1 } - -WlanMeshStatsEntry ::= SEQUENCE { - wlanMeshDroppedBadSta Counter32, - wlanMeshDroppedNoLink Counter32, - wlanMeshNoFwdTtl Counter32, - wlanMeshNoFwdBuf Counter32, - wlanMeshNoFwdTooShort Counter32, - wlanMeshNoFwdDisabled Counter32, - wlanMeshNoFwdPathUnknown Counter32, - wlanMeshDroppedBadAE Counter32, - wlanMeshRouteAddFailed Counter32, - wlanMeshDroppedNoProxy Counter32, - wlanMeshDroppedMisaligned Counter32 -} - -wlanMeshDroppedBadSta OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames dropped by this interface since they were - received from a non-mesh station." - ::= { wlanMeshStatsEntry 1 } - -wlanMeshDroppedNoLink OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames dropped by this interface since no link had - been established." - ::= { wlanMeshStatsEntry 2 } - -wlanMeshNoFwdTtl OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were not forwarded by this interface - because of a zero TTL." - ::= { wlanMeshStatsEntry 3 } - -wlanMeshNoFwdBuf OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were not forwarded by this interface - due to lack of free buffers." - ::= { wlanMeshStatsEntry 4 } - -wlanMeshNoFwdTooShort OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were not forwarded by this interface - due to missing headers." - ::= { wlanMeshStatsEntry 5 } - -wlanMeshNoFwdDisabled OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were not forwarded by this interface - since forwarding was disabled." - ::= { wlanMeshStatsEntry 6 } - -wlanMeshNoFwdPathUnknown OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were not forwarded by this interface - since the path was unknown." - ::= { wlanMeshStatsEntry 7 } - -wlanMeshDroppedBadAE OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were dropped by this interface since - the AE was invalid." - ::= { wlanMeshStatsEntry 8 } - -wlanMeshRouteAddFailed OBJECT-TYPE - SYNTAX Counter32 - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of times an addition of a route to the mesh routing - table for this interface failed." - ::= { wlanMeshStatsEntry 9 } - -wlanMeshDroppedNoProxy OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were dropped by this interface since - proxying was not enabled on the interface." - ::= { wlanMeshStatsEntry 10 } - -wlanMeshDroppedMisaligned OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of frames that were dropped by this interface due to - bad alighment." - ::= { wlanMeshStatsEntry 11 } - --- ---------------------------------------------------------- -- --- Subtrees containing data for each supported mesh routing protocol. --- ---------------------------------------------------------- -- - -wlanMeshProtoHWMP OBJECT IDENTIFIER ::= { wlanMeshRouteProtocols 1 } - --- ---------------------------------------------------------- -- --- Hybrid Wireless Mesh Protocol database. --- ---------------------------------------------------------- -- -wlanMeshHWMPConfig OBJECT IDENTIFIER ::= { wlanMeshProtoHWMP 1 } - -wlanMeshHWMPInterface OBJECT IDENTIFIER ::= { wlanMeshProtoHWMP 2 } - -wlanMeshHWMPStatistics OBJECT IDENTIFIER ::= { wlanMeshProtoHWMP 3 } - -wlanHWMPRouteInactiveTimeout OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The HWMP Route inactivity timeout." - DEFVAL { 5000 } - ::= { wlanMeshHWMPConfig 1 } - -wlanHWMPRootAnnounceInterval OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The HWMP Root Announcement interval." - DEFVAL { 1000 } - ::= { wlanMeshHWMPConfig 2 } - -wlanHWMPRootInterval OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The HWMP Root interval." - DEFVAL { 2000 } - ::= { wlanMeshHWMPConfig 3 } - -wlanHWMPRootTimeout OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The root PREQ timeout." - DEFVAL { 5000 } - ::= { wlanMeshHWMPConfig 4 } - -wlanHWMPPathLifetime OBJECT-TYPE - SYNTAX INTEGER - UNITS "milliseconds" - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The HWMP path entry lifetime." - DEFVAL { 500 } - ::= { wlanMeshHWMPConfig 5 } - -wlanHWMPReplyForwardBit OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "A non-zero value for this object specifies that RF bit shall be - set on generated PREQs." - DEFVAL { 1 } - ::= { wlanMeshHWMPConfig 6 } - -wlanHWMPTargetOnlyBit OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "A non-zero value for this object specifies that TO bit shall be - set on generated PREQs." - DEFVAL { 0 } - ::= { wlanMeshHWMPConfig 7 } - -wlanHWMPInterfaceTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanHWMPInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains information for wireless interfaces - operating in mesh mode." - ::= { wlanMeshHWMPInterface 1 } - -wlanHWMPInterfaceEntry OBJECT-TYPE - SYNTAX WlanHWMPInterfaceEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "Wireless Mesh Routing HWMP information for a wireless interface." - INDEX { wlanIfaceName } - ::= { wlanHWMPInterfaceTable 1 } - -WlanHWMPInterfaceEntry ::= SEQUENCE { - wlanHWMPRootMode INTEGER, - wlanHWMPMaxHops INTEGER -} - -wlanHWMPRootMode OBJECT-TYPE - SYNTAX INTEGER { - disabled(1), - normal(2), - proactive(3), - rann(4) - } - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "This object is used to configure whether the interface will operate - as root node and specify root node mode." - DEFVAL { disabled } - ::= { wlanHWMPInterfaceEntry 1 } - -wlanHWMPMaxHops OBJECT-TYPE - SYNTAX INTEGER - MAX-ACCESS read-write - STATUS current - DESCRIPTION - "The maximum number of hops allowed on an HMWP path for this interface." - DEFVAL { 31 } - ::= { wlanHWMPInterfaceEntry 2 } - -wlanMeshHWMPStatsTable OBJECT-TYPE - SYNTAX SEQUENCE OF WlanMeshHWMPStatsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A table that contains summary statistics for HWMP operation on an - interface operating as mesh point." - ::= { wlanMeshHWMPStatistics 1 } - -wlanMeshHWMPStatsEntry OBJECT-TYPE - SYNTAX WlanMeshHWMPStatsEntry - MAX-ACCESS not-accessible - STATUS current - DESCRIPTION - "A list of HWMP statistics for each wlan interface operating as HWMP - mesh point." - INDEX { wlanIfaceName } - ::= { wlanMeshHWMPStatsTable 1 } - -WlanMeshHWMPStatsEntry ::= SEQUENCE { - wlanMeshHWMPWrongSeqNo Counter32, - wlanMeshHWMPTxRootPREQ Counter32, - wlanMeshHWMPTxRootRANN Counter32, - wlanMeshHWMPProxy Counter32 -} - -wlanMeshHWMPWrongSeqNo OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of HWMP frames with wrong sequence number received by - this interface." - ::= { wlanMeshHWMPStatsEntry 1 } - -wlanMeshHWMPTxRootPREQ OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of HWMP Root PREQ frames sent by this interface." - ::= { wlanMeshHWMPStatsEntry 2 } - -wlanMeshHWMPTxRootRANN OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of HWMP Root RANN frames sent by this interface." - ::= { wlanMeshHWMPStatsEntry 3 } - -wlanMeshHWMPProxy OBJECT-TYPE - SYNTAX Counter32 - UNITS "frames" - MAX-ACCESS read-only - STATUS current - DESCRIPTION - "The number of HWMP PREP frames discarded by this interface due to - the HWMP route being marked as proxy." - ::= { wlanMeshHWMPStatsEntry 4 } - -END diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile b/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile deleted file mode 100644 index 9b8628b..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# -# $FreeBSD$ -# - -MOD= wlan -SRCS= wlan_snmp.c wlan_sys.c -CFLAGS+= -DSNMPTREE_TYPES - -WARNS= 6 - -XSYM= begemotWlan - -BMIBS= BEGEMOT-WIRELESS-MIB.txt -MAN= snmp_${MOD}.3 -DEFS= ${MOD}_tree.def - -.include diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/snmp_wlan.3 b/usr.sbin/bsnmpd/modules/snmp_wlan/snmp_wlan.3 deleted file mode 100644 index 9f366f1..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/snmp_wlan.3 +++ /dev/null @@ -1,160 +0,0 @@ -.\"- -.\" Copyright (C) 2010 The FreeBSD Foundation -.\" All rights reserved. -.\" -.\" This documentation was written by Shteryana Sotirova Shopova under -.\" sponsorship from the FreeBSD Foundation. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd June 28, 2010 -.Dt snmp_wlan 3 -.Os -.Sh NAME -.Nm snmp_wlan -.Nd "wireless networking module for -.Xr bsnmpd 1 -.Sh LIBRARY -.Pq begemotSnmpdModulePath."wlan" = "/usr/lib/snmp_wlan.so" -.Sh DESCRIPTION -The -.Nm snmp_wlan -module implements a private BEGEMOT-WIRELESS-MIB, which allows -management of virtual wireless interfaces. The MIB defines objects similar to the -state data and configuration capabilities of -.Xr ifconfig 8 -for configuring virtual wireless interfaces. -Therefore one should consider adding write communities or loading the -.Nm -module on systems where security is crucial. -.Sh IMPLEMENTATION NOTES -A short description of the Tables and interesting objects in the MIB follows. -.Bl -tag -width "XXXXXXXXX" -.It Va wlanInterfaceTable -The table is used for creation and deletion of virtual wireless interfaces. To -add a new interface, a SET should be executed on the -.Va wlanIfaceName -column with -value the desired name of the interface. Next the parent interface must be set -via -.Va wlanParentIfName -column. Any optional parameters may be set -via the -.Va wlanIfaceOperatingMode, -.Va wlanIfaceFlags, -.Va wlanIfaceBssid -and -.Va wlanIfaceLocalAddress -columns. -To finally create the interface in the system, a SET with value of active(1) to -.Va wlanIfaceStatus -column should be executed. -To destroy a wireless interface a SET with value of destroy(6) to the relevant -.Va wlanIfaceStatus -column should be executed. -.It Va wlanIfParentTable -The table contains information about the hardware capabilities of the parent of -a wireless interface. -.It Va wlanIfaceConfigTable -The table is used to get or set various configuration parameters for a virtual -wireless interface. Depending on the operating mode of the interface and the -hardware capabilities of the underlying hardware interface, not all parameters -and values may be supported. -.It Va wlanIfacePeerTable -The table contains information about the associated stations for interfaces -operating as access points, or the stations identified as neighbors in the IBSS -for interfaces operating in adhoc mode. -.It Va wlanIfaceChannelTable -Information about the active channels for the wireless interfaces in the system. -.It Va wlanIfRoamParamsTable -The parameters that govern the roaming operation on the wireless interfaces. -.It Va wlanIfTxParamsTable -The parameters that govern the transmit operation on the wireless interfaces. -.It Va wlanScanConfigTable -The table that contains a configuration for channel scanning initiated via SNMP. -.It Va wlanScanResultsTable -The table contains the scan results from the last scan for each wireless -interface on the system. -.It Va wlanIfaceStatisticsTable -Summary statistics for each wireless interface on the system. -.It Va wlanWepInterfaceTable -WEP configuration for the wireless interfaces on the system. -.It Va wlanMACAccessControlTable -Access Control configuration for wireless interfaces operating as access points. -.It Va wlanMACAccessControlMACTable -The table with Access Control MAC entries for which the configured Access -Control Policy on wireless interfaces operating in Host AP mode is applied. -.Va wlanMACAccessControlMACStatus -column is used to add or delete MAC ACL entries. A set with value createAndGo(4) -will add new entry, while with value destroy(6) will delete an existing one. -.It Va wlanMeshRoutingConfig -The subtree contains system configuration related to Wireless Mesh Routing. -.It Va wlanMeshInterfaceTable -The table contains information for wireless interfaces operating as wireless -mesh points. -.It Va wlanMeshNeighborTable -The table contains information for the neighbors of wireless interfaces -operating in mesh mode. -.It Va wlanMeshRouteTable -The mesh routing table for interfaces operating as mesh points, used for -forwarding packets on a mesh network. -.Va wlanMeshRouteStatus -column is used to add or delete entries in the mesh routing table for an -interface. A set with value createAndGo(4) will add new entry, while with value -destroy(6) will delete an existing one. -.It Va wlanMeshStatsTable -Summary statistics for each virtual wireless interface operating as mesh point. -.It Va wlanMeshHWMPConfig -The subtree contains system configuration related to Hybrid Wireless Mesh -Protocol. -.It Va wlanHWMPInterfaceTable -The table contains HWMP information for wireless interfaces operating in mesh -mode. -.It Va wlanMeshHWMPStatsTable -Summary statistics for HWMP operation on interfaces operating as mesh points. -.El -.Sh RESTRICTIONS -Not all information or configuration in the MIBs is currently available in FreeBSD. -The values of the following variables carry no information: -.Bl -tag -width "XXXXXXXXX" -.It Va wlanStatsReset -.El -.Sh FILES -.Bl -tag -width "XXXXXXXXX" -.It Pa /usr/share/snmp/defs/wlan_tree.def -The description of the MIB tree implemented by -.Nm . -.It Pa /usr/share/snmp/mibs/BEGEMOT-WIRELESS-MIB.txt -The private BEGEMOT-WIRELESS-MIB that is implemented by this module. -.El -.Sh SEE ALSO -.Xr bsnmpd 1 , -.Xr gensnmptree 1 , -.Xr wlan 4 , -.Xr wlan_acl 4 , -.Xr wlan_wep 4 , -.Xr ifconfig 8 , -.Xr snmpmod 3 -.Sh AUTHORS -.An Shteryana Shopova Aq syrinx@FreeBSD.org diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c deleted file mode 100644 index ec94ac6..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.c +++ /dev/null @@ -1,4513 +0,0 @@ -/*- - * Copyright (c) 2010 The FreeBSD Foundation - * All rights reserved. - * - * This software was developed by Shteryana Sotirova Shopova under - * sponsorship from the FreeBSD Foundation. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "wlan_tree.h" -#include "wlan_snmp.h" -#include "wlan_oid.h" - -static struct lmodule *wlan_module; - -/* For the registration. */ -static const struct asn_oid oid_wlan = OIDX_begemotWlan; -/* The registration. */ -static uint reg_wlan; - -/* Periodic timer for polling the module's data. */ -static void *wlan_data_timer; - -/* - * Poll data from kernel every 15 minutes unless explicitly requested by an - * SNMP client. - * XXX: make that configurable. - */ -static int wlan_poll_ticks = (15 * 60) * 100; - -/* The age of each table. */ -#define WLAN_LIST_MAXAGE 5 - -static time_t wlan_iflist_age; -static time_t wlan_peerlist_age; -static time_t wlan_chanlist_age; -static time_t wlan_roamlist_age; -static time_t wlan_tx_paramlist_age; -static time_t wlan_scanlist_age; -static time_t wlan_maclist_age; -static time_t wlan_mrlist_age; - -/* - * The list of all virtual wireless interfaces - sorted by name. - */ -SLIST_HEAD(wlan_ifaces, wlan_iface); -static struct wlan_ifaces wlan_ifaces = SLIST_HEAD_INITIALIZER(wlan_ifaces); - -static struct wlan_config wlan_config; - -/* Forward declarations */ -static int bits_get(struct snmp_value *, const u_char *, ssize_t); - -static int wlan_add_wif(struct wlan_iface *); -static void wlan_delete_wif(struct wlan_iface *); -static int wlan_attach_newif(struct mibif *); -static int wlan_iface_create(struct wlan_iface *); -static int wlan_iface_destroy(struct wlan_iface *); -static struct wlan_iface * wlan_new_wif(char *); - -static void wlan_free_interface(struct wlan_iface *); -static void wlan_free_iflist(void); -static void wlan_free_peerlist(struct wlan_iface *); -static void wlan_scan_free_results(struct wlan_iface *); -static void wlan_mac_free_maclist(struct wlan_iface *); -static void wlan_mesh_free_routes(struct wlan_iface *); - -static int wlan_update_interface(struct wlan_iface *); -static void wlan_update_interface_list(void); -static void wlan_update_peers(void); -static void wlan_update_channels(void); -static void wlan_update_roam_params(void); -static void wlan_update_tx_params(void); -static void wlan_scan_update_results(void); -static void wlan_mac_update_aclmacs(void); -static void wlan_mesh_update_routes(void); - -static struct wlan_iface * wlan_find_interface(const char *); -static struct wlan_peer * wlan_find_peer(struct wlan_iface *, uint8_t *); -static struct ieee80211_channel* wlan_find_channel(struct wlan_iface *, - uint32_t); -static struct wlan_scan_result * wlan_scan_find_result(struct wlan_iface *, - uint8_t *, uint8_t *); -static struct wlan_mac_mac * wlan_mac_find_mac(struct wlan_iface *, - uint8_t *); -static struct wlan_mesh_route * wlan_mesh_find_route(struct wlan_iface *, - uint8_t *); - -static struct wlan_iface * wlan_first_interface(void); -static struct wlan_iface * wlan_next_interface(struct wlan_iface *); -static struct wlan_iface * wlan_mesh_first_interface(void); -static struct wlan_iface * wlan_mesh_next_interface(struct wlan_iface *); - -static struct wlan_iface * wlan_get_interface(const struct asn_oid *, uint); -static struct wlan_iface * wlan_get_snmp_interface(const struct asn_oid *, - uint); -static struct wlan_peer * wlan_get_peer(const struct asn_oid *, uint, - struct wlan_iface **); -static struct ieee80211_channel *wlan_get_channel(const struct asn_oid *, uint, - struct wlan_iface **); -static struct ieee80211_roamparam *wlan_get_roam_param(const struct asn_oid *, - uint, struct wlan_iface **); -static struct ieee80211_txparam *wlan_get_tx_param(const struct asn_oid *, - uint, struct wlan_iface **, uint32_t *); -static struct wlan_scan_result *wlan_get_scanr(const struct asn_oid *, uint, - struct wlan_iface **); -static struct wlan_mac_mac * wlan_get_acl_mac(const struct asn_oid *, - uint, struct wlan_iface **); -static struct wlan_iface * wlan_mesh_get_iface(const struct asn_oid *, uint); -static struct wlan_peer * wlan_mesh_get_peer(const struct asn_oid *, uint, - struct wlan_iface **); -static struct wlan_mesh_route * wlan_mesh_get_route(const struct asn_oid *, - uint, struct wlan_iface **); - -static struct wlan_iface * wlan_get_next_interface(const struct asn_oid *, - uint); -static struct wlan_iface * wlan_get_next_snmp_interface(const struct - asn_oid *, uint); -static struct wlan_peer * wlan_get_next_peer(const struct asn_oid *, uint, - struct wlan_iface **); -static struct ieee80211_channel *wlan_get_next_channel(const struct asn_oid *, - uint, struct wlan_iface **); -static struct ieee80211_roamparam *wlan_get_next_roam_param(const struct - asn_oid *, uint sub, struct wlan_iface **, uint32_t *); -static struct ieee80211_txparam *wlan_get_next_tx_param(const struct asn_oid *, - uint, struct wlan_iface **, uint32_t *); -static struct wlan_scan_result *wlan_get_next_scanr(const struct asn_oid *, - uint , struct wlan_iface **); -static struct wlan_mac_mac * wlan_get_next_acl_mac(const struct asn_oid *, - uint, struct wlan_iface **); -static struct wlan_iface * wlan_mesh_get_next_iface(const struct asn_oid *, - uint); -static struct wlan_peer * wlan_mesh_get_next_peer(const struct asn_oid *, - uint, struct wlan_iface **); -static struct wlan_mesh_route * wlan_mesh_get_next_route(const struct asn_oid *, - uint sub, struct wlan_iface **); - -static uint8_t *wlan_get_ifname(const struct asn_oid *, uint, uint8_t *); -static int wlan_mac_index_decode(const struct asn_oid *, uint, char *, - uint8_t *); -static int wlan_channel_index_decode(const struct asn_oid *, uint, - char *, uint32_t *); -static int wlan_phy_index_decode(const struct asn_oid *, uint, char *, - uint32_t *); -static int wlan_scanr_index_decode(const struct asn_oid *oid, uint sub, - char *wname, uint8_t *ssid, uint8_t *bssid); - -static void wlan_append_ifindex(struct asn_oid *, uint, - const struct wlan_iface *); -static void wlan_append_mac_index(struct asn_oid *, uint, char *, uint8_t *); -static void wlan_append_channel_index(struct asn_oid *, uint, - const struct wlan_iface *, const struct ieee80211_channel *); -static void wlan_append_phy_index(struct asn_oid *, uint, char *, uint32_t); -static void wlan_append_scanr_index(struct asn_oid *, uint, char *, - uint8_t *, uint8_t *); - -static int wlan_acl_mac_set_status(struct snmp_context *, - struct snmp_value *, uint); -static int wlan_mesh_route_set_status(struct snmp_context *, - struct snmp_value *, uint); - -static int32_t wlan_get_channel_type(struct ieee80211_channel *); -static int wlan_scan_compare_result(struct wlan_scan_result *, - struct wlan_scan_result *); -static int wlan_mac_delete_mac(struct wlan_iface *, struct wlan_mac_mac *); -static int wlan_mesh_delete_route(struct wlan_iface *, - struct wlan_mesh_route *); - -/* - * The module's GET/SET data hooks per each table or group of objects as - * required by bsnmpd(1). - */ -int -op_wlan_iface(struct snmp_context *ctx, struct snmp_value *val, uint32_t sub, - uint32_t iidx __unused, enum snmp_op op) -{ - int rc; - char wname[IFNAMSIZ]; - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_get_snmp_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - if ((wif = wlan_get_next_snmp_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - - case SNMP_OP_SET: - if ((wif = wlan_get_snmp_interface(&val->var, sub)) == NULL) { - if (val->var.subs[sub - 1] != LEAF_wlanIfaceName) - return (SNMP_ERR_NOSUCHNAME); - if (wlan_get_ifname(&val->var, sub, wname) == NULL) - return (SNMP_ERR_INCONS_VALUE); - if ((wif = wlan_new_wif(wname)) == NULL) - return (SNMP_ERR_GENERR); - wif->internal = 1; - } - if (wif->status == RowStatus_active && - val->var.subs[sub - 1] != LEAF_wlanIfaceStatus && - val->var.subs[sub - 1] != LEAF_wlanIfaceState) - return (SNMP_ERR_INCONS_VALUE); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceIndex: - return (SNMP_ERR_NOT_WRITEABLE); - - case LEAF_wlanIfaceName: - if (val->v.octetstring.len >= IFNAMSIZ) - return (SNMP_ERR_INCONS_VALUE); - if ((ctx->scratch->ptr1 = malloc(IFNAMSIZ)) == NULL) - return (SNMP_ERR_GENERR); - strlcpy(ctx->scratch->ptr1, wif->wname, IFNAMSIZ); - memcpy(wif->wname, val->v.octetstring.octets, - val->v.octetstring.len); - wif->wname[val->v.octetstring.len] = '\0'; - return (SNMP_ERR_NOERROR); - - case LEAF_wlanParentIfName: - if (val->v.octetstring.len >= IFNAMSIZ) - return (SNMP_ERR_INCONS_VALUE); - if ((ctx->scratch->ptr1 = malloc(IFNAMSIZ)) == NULL) - return (SNMP_ERR_GENERR); - strlcpy(ctx->scratch->ptr1, wif->pname, IFNAMSIZ); - memcpy(wif->pname, val->v.octetstring.octets, - val->v.octetstring.len); - wif->pname[val->v.octetstring.len] = '\0'; - return (SNMP_ERR_NOERROR); - - case LEAF_wlanIfaceOperatingMode: - ctx->scratch->int1 = wif->mode; - wif->mode = val->v.integer; - return (SNMP_ERR_NOERROR); - - case LEAF_wlanIfaceFlags: - if (val->v.octetstring.len > sizeof(wif->flags)) - return (SNMP_ERR_INCONS_VALUE); - ctx->scratch->ptr1 = malloc(sizeof(wif->flags)); - if (ctx->scratch->ptr1 == NULL) - return (SNMP_ERR_GENERR); - memcpy(ctx->scratch->ptr1, (uint8_t *)&wif->flags, - sizeof(wif->flags)); - memcpy((uint8_t *)&wif->flags, val->v.octetstring.octets, - sizeof(wif->flags)); - return (SNMP_ERR_NOERROR); - - case LEAF_wlanIfaceBssid: - if (val->v.octetstring.len != IEEE80211_ADDR_LEN) - return (SNMP_ERR_INCONS_VALUE); - ctx->scratch->ptr1 = malloc(IEEE80211_ADDR_LEN); - if (ctx->scratch->ptr1 == NULL) - return (SNMP_ERR_GENERR); - memcpy(ctx->scratch->ptr1, wif->dbssid, - IEEE80211_ADDR_LEN); - memcpy(wif->dbssid, val->v.octetstring.octets, - IEEE80211_ADDR_LEN); - return (SNMP_ERR_NOERROR); - - case LEAF_wlanIfaceLocalAddress: - if (val->v.octetstring.len != IEEE80211_ADDR_LEN) - return (SNMP_ERR_INCONS_VALUE); - ctx->scratch->ptr1 = malloc(IEEE80211_ADDR_LEN); - if (ctx->scratch->ptr1 == NULL) - return (SNMP_ERR_GENERR); - memcpy(ctx->scratch->ptr1, wif->dlmac, - IEEE80211_ADDR_LEN); - memcpy(wif->dlmac, val->v.octetstring.octets, - IEEE80211_ADDR_LEN); - return (SNMP_ERR_NOERROR); - - case LEAF_wlanIfaceStatus: - ctx->scratch->int1 = wif->status; - wif->status = val->v.integer; - if (wif->status == RowStatus_active) { - rc = wlan_iface_create(wif); /* XXX */ - if (rc != SNMP_ERR_NOERROR) { - wif->status = ctx->scratch->int1; - return (rc); - } - } else if (wif->status == RowStatus_destroy) - return (wlan_iface_destroy(wif)); - else - wif->status = RowStatus_notReady; - return (SNMP_ERR_NOERROR); - - case LEAF_wlanIfaceState: - ctx->scratch->int1 = wif->state; - wif->state = val->v.integer; - if (wif->status == RowStatus_active) - if (wlan_config_state(wif, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - } - abort(); - - case SNMP_OP_ROLLBACK: - if ((wif = wlan_get_snmp_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceName: - strlcpy(wif->wname, ctx->scratch->ptr1, IFNAMSIZ); - free(ctx->scratch->ptr1); - break; - - case LEAF_wlanParentIfName: - strlcpy(wif->pname, ctx->scratch->ptr1, IFNAMSIZ); - free(ctx->scratch->ptr1); - break; - - case LEAF_wlanIfaceOperatingMode: - wif->mode = ctx->scratch->int1; - break; - - case LEAF_wlanIfaceFlags: - memcpy((uint8_t *)&wif->flags, ctx->scratch->ptr1, - sizeof(wif->flags)); - free(ctx->scratch->ptr1); - break; - - case LEAF_wlanIfaceBssid: - memcpy(wif->dbssid, ctx->scratch->ptr1, - IEEE80211_ADDR_LEN); - free(ctx->scratch->ptr1); - break; - - case LEAF_wlanIfaceLocalAddress: - memcpy(wif->dlmac, ctx->scratch->ptr1, - IEEE80211_ADDR_LEN); - free(ctx->scratch->ptr1); - break; - - case LEAF_wlanIfaceStatus: - wif->status = ctx->scratch->int1; - if (ctx->scratch->int1 == RowStatus_active) - return (SNMP_ERR_GENERR); /* XXX: FIXME */ - else if (wif->internal != 0) - return (wlan_iface_destroy(wif)); - break; - - case LEAF_wlanIfaceState: - wif->state = ctx->scratch->int1; - if (wif->status == RowStatus_active) - if (wlan_config_state(wif, 1) < 0) - return (SNMP_ERR_GENERR); - break; - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceName: - case LEAF_wlanParentIfName: - case LEAF_wlanIfaceFlags: - case LEAF_wlanIfaceBssid: - case LEAF_wlanIfaceLocalAddress: - free(ctx->scratch->ptr1); - /* FALLTHROUGH */ - default: - return (SNMP_ERR_NOERROR); - } - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceIndex: - val->v.integer = wif->index; - return (SNMP_ERR_NOERROR); - case LEAF_wlanIfaceName: - return (string_get(val, wif->wname, -1)); - case LEAF_wlanParentIfName: - return (string_get(val, wif->pname, -1)); - case LEAF_wlanIfaceOperatingMode: - val->v.integer = wif->mode; - return (SNMP_ERR_NOERROR); - case LEAF_wlanIfaceFlags: - return (bits_get(val, (uint8_t *)&wif->flags, - sizeof(wif->flags))); - case LEAF_wlanIfaceBssid: - return (string_get(val, wif->dbssid, IEEE80211_ADDR_LEN)); - case LEAF_wlanIfaceLocalAddress: - return (string_get(val, wif->dlmac, IEEE80211_ADDR_LEN)); - case LEAF_wlanIfaceStatus: - val->v.integer = wif->status; - return (SNMP_ERR_NOERROR); - case LEAF_wlanIfaceState: - val->v.integer = wif->state; - return (SNMP_ERR_NOERROR); - } - - abort(); -} - -int -op_wlan_if_parent(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - if ((wif = wlan_get_next_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfParentDriverCapabilities: - return (bits_get(val, (uint8_t *)&wif->drivercaps, - sizeof(wif->drivercaps))); - case LEAF_wlanIfParentCryptoCapabilities: - return (bits_get(val, (uint8_t *)&wif->cryptocaps, - sizeof(wif->cryptocaps))); - case LEAF_wlanIfParentHTCapabilities: - return (bits_get(val, (uint8_t *)&wif->htcaps, - sizeof(wif->htcaps))); - } - - abort(); -} - -int -op_wlan_iface_config(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - int intval, vlen, rc; - char *strval; - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get_config; - - case SNMP_OP_GETNEXT: - if ((wif = wlan_get_next_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - goto get_config; - - case SNMP_OP_SET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - - intval = val->v.integer; - strval = NULL; - vlen = 0; - - /* Simple sanity checks & save old data. */ - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceCountryCode: - if (val->v.octetstring.len != WLAN_COUNTRY_CODE_SIZE) - return (SNMP_ERR_INCONS_VALUE); - break; - case LEAF_wlanIfaceDesiredSsid: - if (val->v.octetstring.len > IEEE80211_NWID_LEN) - return (SNMP_ERR_INCONS_VALUE); - break; - case LEAF_wlanIfaceDesiredBssid: - if (val->v.octetstring.len != IEEE80211_ADDR_LEN) - return (SNMP_ERR_INCONS_VALUE); - break; - case LEAF_wlanIfacePacketBurst: - ctx->scratch->int1 = wif->packet_burst; - break; - case LEAF_wlanIfaceRegDomain: - ctx->scratch->int1 = wif->reg_domain; - break; - case LEAF_wlanIfaceDesiredChannel: - ctx->scratch->int1 = wif->desired_channel; - break; - case LEAF_wlanIfaceDynamicFreqSelection: - ctx->scratch->int1 = wif->dyn_frequency; - break; - case LEAF_wlanIfaceFastFrames: - ctx->scratch->int1 = wif->fast_frames; - break; - case LEAF_wlanIfaceDturbo: - ctx->scratch->int1 = wif->dturbo; - break; - case LEAF_wlanIfaceTxPower: - ctx->scratch->int1 = wif->tx_power; - break; - case LEAF_wlanIfaceFragmentThreshold: - ctx->scratch->int1 = wif->frag_threshold; - break; - case LEAF_wlanIfaceRTSThreshold: - ctx->scratch->int1 = wif->rts_threshold; - break; - case LEAF_wlanIfaceWlanPrivacySubscribe: - ctx->scratch->int1 = wif->priv_subscribe; - break; - case LEAF_wlanIfaceBgScan: - ctx->scratch->int1 = wif->bg_scan; - break; - case LEAF_wlanIfaceBgScanIdle: - ctx->scratch->int1 = wif->bg_scan_idle; - break; - case LEAF_wlanIfaceBgScanInterval: - ctx->scratch->int1 = wif->bg_scan_interval; - break; - case LEAF_wlanIfaceBeaconMissedThreshold: - ctx->scratch->int1 = wif->beacons_missed; - break; - case LEAF_wlanIfaceRoamingMode: - ctx->scratch->int1 = wif->roam_mode; - break; - case LEAF_wlanIfaceDot11d: - ctx->scratch->int1 = wif->dot11d; - break; - case LEAF_wlanIfaceDot11h: - ctx->scratch->int1 = wif->dot11h; - break; - case LEAF_wlanIfaceDynamicWds: - ctx->scratch->int1 = wif->dynamic_wds; - break; - case LEAF_wlanIfacePowerSave: - ctx->scratch->int1 = wif->power_save; - break; - case LEAF_wlanIfaceApBridge: - ctx->scratch->int1 = wif->ap_bridge; - break; - case LEAF_wlanIfaceBeaconInterval: - ctx->scratch->int1 = wif->beacon_interval; - break; - case LEAF_wlanIfaceDtimPeriod: - ctx->scratch->int1 = wif->dtim_period; - break; - case LEAF_wlanIfaceHideSsid: - ctx->scratch->int1 = wif->hide_ssid; - break; - case LEAF_wlanIfaceInactivityProccess: - ctx->scratch->int1 = wif->inact_process; - break; - case LEAF_wlanIfaceDot11gProtMode: - ctx->scratch->int1 = wif->do11g_protect; - break; - case LEAF_wlanIfaceDot11gPureMode: - ctx->scratch->int1 = wif->dot11g_pure; - break; - case LEAF_wlanIfaceDot11nPureMode: - ctx->scratch->int1 = wif->dot11n_pure; - break; - case LEAF_wlanIfaceDot11nAmpdu: - ctx->scratch->int1 = wif->ampdu; - break; - case LEAF_wlanIfaceDot11nAmpduDensity: - ctx->scratch->int1 = wif->ampdu_density; - break; - case LEAF_wlanIfaceDot11nAmpduLimit: - ctx->scratch->int1 = wif->ampdu_limit; - break; - case LEAF_wlanIfaceDot11nAmsdu: - ctx->scratch->int1 = wif->amsdu; - break; - case LEAF_wlanIfaceDot11nAmsduLimit: - ctx->scratch->int1 = wif->amsdu_limit; - break; - case LEAF_wlanIfaceDot11nHighThroughput: - ctx->scratch->int1 = wif->ht_enabled; - break; - case LEAF_wlanIfaceDot11nHTCompatible: - ctx->scratch->int1 = wif->ht_compatible; - break; - case LEAF_wlanIfaceDot11nHTProtMode: - ctx->scratch->int1 = wif->ht_prot_mode; - break; - case LEAF_wlanIfaceDot11nRIFS: - ctx->scratch->int1 = wif->rifs; - break; - case LEAF_wlanIfaceDot11nShortGI: - ctx->scratch->int1 = wif->short_gi; - break; - case LEAF_wlanIfaceDot11nSMPSMode: - ctx->scratch->int1 = wif->smps_mode; - break; - case LEAF_wlanIfaceTdmaSlot: - ctx->scratch->int1 = wif->tdma_slot; - break; - case LEAF_wlanIfaceTdmaSlotCount: - ctx->scratch->int1 = wif->tdma_slot_count; - break; - case LEAF_wlanIfaceTdmaSlotLength: - ctx->scratch->int1 = wif->tdma_slot_length; - break; - case LEAF_wlanIfaceTdmaBeaconInterval: - ctx->scratch->int1 = wif->tdma_binterval; - break; - default: - abort(); - } - - if (val->syntax != SNMP_SYNTAX_OCTETSTRING) - goto set_config; - - ctx->scratch->int1 = val->v.octetstring.len; - ctx->scratch->ptr1 = malloc(val->v.octetstring.len + 1); - if (ctx->scratch->ptr1 == NULL) - return (SNMP_ERR_GENERR); /* XXX */ - if (val->var.subs[sub - 1] == LEAF_wlanIfaceDesiredSsid) - strlcpy(ctx->scratch->ptr1, val->v.octetstring.octets, - val->v.octetstring.len + 1); - else - memcpy(ctx->scratch->ptr1, val->v.octetstring.octets, - val->v.octetstring.len); - strval = val->v.octetstring.octets; - vlen = val->v.octetstring.len; - goto set_config; - - case SNMP_OP_ROLLBACK: - intval = ctx->scratch->int1; - strval = NULL; - vlen = 0; - - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceCountryCode: - case LEAF_wlanIfaceDesiredSsid: - case LEAF_wlanIfaceDesiredBssid: - strval = ctx->scratch->ptr1; - vlen = ctx->scratch->int1; - break; - default: - break; - } - goto set_config; - - case SNMP_OP_COMMIT: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceCountryCode: - case LEAF_wlanIfaceDesiredSsid: - case LEAF_wlanIfaceDesiredBssid: - free(ctx->scratch->ptr1); - /* FALLTHROUGH */ - default: - return (SNMP_ERR_NOERROR); - } - } - abort(); - -get_config: - - if (wlan_config_get_ioctl(wif, val->var.subs[sub - 1]) < 0) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfacePacketBurst: - val->v.integer = wif->packet_burst; - break; - case LEAF_wlanIfaceCountryCode: - return (string_get(val, wif->country_code, - WLAN_COUNTRY_CODE_SIZE)); - case LEAF_wlanIfaceRegDomain: - val->v.integer = wif->reg_domain; - break; - case LEAF_wlanIfaceDesiredSsid: - return (string_get(val, wif->desired_ssid, -1)); - case LEAF_wlanIfaceDesiredChannel: - val->v.integer = wif->desired_channel; - break; - case LEAF_wlanIfaceDynamicFreqSelection: - val->v.integer = wif->dyn_frequency; - break; - case LEAF_wlanIfaceFastFrames: - val->v.integer = wif->fast_frames; - break; - case LEAF_wlanIfaceDturbo: - val->v.integer = wif->dturbo; - break; - case LEAF_wlanIfaceTxPower: - val->v.integer = wif->tx_power; - break; - case LEAF_wlanIfaceFragmentThreshold: - val->v.integer = wif->frag_threshold; - break; - case LEAF_wlanIfaceRTSThreshold: - val->v.integer = wif->rts_threshold; - break; - case LEAF_wlanIfaceWlanPrivacySubscribe: - val->v.integer = wif->priv_subscribe; - break; - case LEAF_wlanIfaceBgScan: - val->v.integer = wif->bg_scan; - break; - case LEAF_wlanIfaceBgScanIdle: - val->v.integer = wif->bg_scan_idle; - break; - case LEAF_wlanIfaceBgScanInterval: - val->v.integer = wif->bg_scan_interval; - break; - case LEAF_wlanIfaceBeaconMissedThreshold: - val->v.integer = wif->beacons_missed; - break; - case LEAF_wlanIfaceDesiredBssid: - return (string_get(val, wif->desired_bssid, - IEEE80211_ADDR_LEN)); - case LEAF_wlanIfaceRoamingMode: - val->v.integer = wif->roam_mode; - break; - case LEAF_wlanIfaceDot11d: - val->v.integer = wif->dot11d; - break; - case LEAF_wlanIfaceDot11h: - val->v.integer = wif->dot11h; - break; - case LEAF_wlanIfaceDynamicWds: - val->v.integer = wif->dynamic_wds; - break; - case LEAF_wlanIfacePowerSave: - val->v.integer = wif->power_save; - break; - case LEAF_wlanIfaceApBridge: - val->v.integer = wif->ap_bridge; - break; - case LEAF_wlanIfaceBeaconInterval: - val->v.integer = wif->beacon_interval; - break; - case LEAF_wlanIfaceDtimPeriod: - val->v.integer = wif->dtim_period; - break; - case LEAF_wlanIfaceHideSsid: - val->v.integer = wif->hide_ssid; - break; - case LEAF_wlanIfaceInactivityProccess: - val->v.integer = wif->inact_process; - break; - case LEAF_wlanIfaceDot11gProtMode: - val->v.integer = wif->do11g_protect; - break; - case LEAF_wlanIfaceDot11gPureMode: - val->v.integer = wif->dot11g_pure; - break; - case LEAF_wlanIfaceDot11nPureMode: - val->v.integer = wif->dot11n_pure; - break; - case LEAF_wlanIfaceDot11nAmpdu: - val->v.integer = wif->ampdu; - break; - case LEAF_wlanIfaceDot11nAmpduDensity: - val->v.integer = wif->ampdu_density; - break; - case LEAF_wlanIfaceDot11nAmpduLimit: - val->v.integer = wif->ampdu_limit; - break; - case LEAF_wlanIfaceDot11nAmsdu: - val->v.integer = wif->amsdu; - break; - case LEAF_wlanIfaceDot11nAmsduLimit: - val->v.integer = wif->amsdu_limit; - break; - case LEAF_wlanIfaceDot11nHighThroughput: - val->v.integer = wif->ht_enabled; - break; - case LEAF_wlanIfaceDot11nHTCompatible: - val->v.integer = wif->ht_compatible; - break; - case LEAF_wlanIfaceDot11nHTProtMode: - val->v.integer = wif->ht_prot_mode; - break; - case LEAF_wlanIfaceDot11nRIFS: - val->v.integer = wif->rifs; - break; - case LEAF_wlanIfaceDot11nShortGI: - val->v.integer = wif->short_gi; - break; - case LEAF_wlanIfaceDot11nSMPSMode: - val->v.integer = wif->smps_mode; - break; - case LEAF_wlanIfaceTdmaSlot: - val->v.integer = wif->tdma_slot; - break; - case LEAF_wlanIfaceTdmaSlotCount: - val->v.integer = wif->tdma_slot_count; - break; - case LEAF_wlanIfaceTdmaSlotLength: - val->v.integer = wif->tdma_slot_length; - break; - case LEAF_wlanIfaceTdmaBeaconInterval: - val->v.integer = wif->tdma_binterval; - break; - } - - return (SNMP_ERR_NOERROR); - -set_config: - rc = wlan_config_set_ioctl(wif, val->var.subs[sub - 1], intval, - strval, vlen); - - if (op == SNMP_OP_ROLLBACK) { - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceCountryCode: - case LEAF_wlanIfaceDesiredSsid: - case LEAF_wlanIfaceDesiredBssid: - free(ctx->scratch->ptr1); - /* FALLTHROUGH */ - default: - break; - } - } - - if (rc < 0) - return (SNMP_ERR_GENERR); - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_if_peer(struct snmp_context *ctx, struct snmp_value *val, uint32_t sub, - uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_peer *wip; - struct wlan_iface *wif; - - wlan_update_interface_list(); - wlan_update_peers(); - - switch (op) { - case SNMP_OP_GET: - if ((wip = wlan_get_peer(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - if ((wip = wlan_get_next_peer(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_mac_index(&val->var, sub, wif->wname, wip->pmac); - break; - case SNMP_OP_SET: - if ((wip = wlan_get_peer(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (val->var.subs[sub - 1] != LEAF_wlanIfacePeerVlanTag) - return (SNMP_ERR_GENERR); - ctx->scratch->int1 = wip->vlan; - if (wlan_peer_set_vlan(wif, wip, val->v.integer) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - case SNMP_OP_ROLLBACK: - if ((wip = wlan_get_peer(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (val->var.subs[sub - 1] != LEAF_wlanIfacePeerVlanTag) - return (SNMP_ERR_GENERR); - if (wlan_peer_set_vlan(wif, wip, ctx->scratch->int1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfacePeerAddress: - return (string_get(val, wip->pmac, IEEE80211_ADDR_LEN)); - case LEAF_wlanIfacePeerAssociationId: - val->v.integer = wip->associd; - break; - case LEAF_wlanIfacePeerVlanTag: - val->v.integer = wip->vlan; - break; - case LEAF_wlanIfacePeerFrequency: - val->v.integer = wip->frequency; - break; - case LEAF_wlanIfacePeerCurrentTXRate: - val->v.integer = wip->txrate; - break; - case LEAF_wlanIfacePeerRxSignalStrength: - val->v.integer = wip->rssi; - break; - case LEAF_wlanIfacePeerIdleTimer: - val->v.integer = wip->idle; - break; - case LEAF_wlanIfacePeerTxSequenceNo: - val->v.integer = wip->txseqs; - break; - case LEAF_wlanIfacePeerRxSequenceNo: - val->v.integer = wip->rxseqs; - break; - case LEAF_wlanIfacePeerTxPower: - val->v.integer = wip->txpower; - break; - case LEAF_wlanIfacePeerCapabilities: - return (bits_get(val, (uint8_t *)&wip->capinfo, - sizeof(wip->capinfo))); - case LEAF_wlanIfacePeerFlags: - return (bits_get(val, (uint8_t *)&wip->state, - sizeof(wip->state))); - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_channels(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - int32_t bits; - struct ieee80211_channel *channel; - struct wlan_iface *wif; - - wlan_update_interface_list(); - wlan_update_channels(); - - switch (op) { - case SNMP_OP_GET: - if ((channel = wlan_get_channel(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - channel = wlan_get_next_channel(&val->var, sub, &wif); - if (channel == NULL || wif == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_channel_index(&val->var, sub, wif, channel); - break; - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfaceChannelIeeeId: - val->v.integer = channel->ic_ieee; - break; - case LEAF_wlanIfaceChannelType: - val->v.integer = wlan_get_channel_type(channel); - break; - case LEAF_wlanIfaceChannelFlags: - bits = wlan_channel_flags_to_snmp(channel->ic_flags); - return (bits_get(val, (uint8_t *)&bits, sizeof(bits))); - case LEAF_wlanIfaceChannelFrequency: - val->v.integer = channel->ic_freq; - break; - case LEAF_wlanIfaceChannelMaxRegPower: - val->v.integer = channel->ic_maxregpower; - break; - case LEAF_wlanIfaceChannelMaxTxPower: - val->v.integer = channel->ic_maxpower; - break; - case LEAF_wlanIfaceChannelMinTxPower: - val->v.integer = channel->ic_minpower; - break; - case LEAF_wlanIfaceChannelState: - bits = wlan_channel_state_to_snmp(channel->ic_state); - return (bits_get(val, (uint8_t *)&bits, sizeof(bits))); - case LEAF_wlanIfaceChannelHTExtension: - val->v.integer = channel->ic_extieee; - break; - case LEAF_wlanIfaceChannelMaxAntennaGain: - val->v.integer = channel->ic_maxantgain; - break; - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_roam_params(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - uint32_t phy; - struct ieee80211_roamparam *rparam; - struct wlan_iface *wif; - - wlan_update_interface_list(); - wlan_update_roam_params(); - - switch (op) { - case SNMP_OP_GET: - rparam = wlan_get_roam_param(&val->var, sub, &wif); - if (rparam == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - rparam = wlan_get_next_roam_param(&val->var, sub, &wif, &phy); - if (rparam == NULL || wif == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_phy_index(&val->var, sub, wif->wname, phy); - break; - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfRoamRxSignalStrength: - val->v.integer = rparam->rssi/2; - break; - case LEAF_wlanIfRoamTxRateThreshold: - val->v.integer = rparam->rate/2; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_tx_params(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - uint32_t phy; - struct ieee80211_txparam *txparam; - struct wlan_iface *wif; - - wlan_update_interface_list(); - wlan_update_tx_params(); - - switch (op) { - case SNMP_OP_GET: - txparam = wlan_get_tx_param(&val->var, sub, &wif, &phy); - if (txparam == NULL) - return (SNMP_ERR_NOSUCHNAME); - goto get_txparams; - - case SNMP_OP_GETNEXT: - txparam = wlan_get_next_tx_param(&val->var, sub, &wif, &phy); - if (txparam == NULL || wif == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_phy_index(&val->var, sub, wif->wname, phy); - goto get_txparams; - - case SNMP_OP_SET: - txparam = wlan_get_tx_param(&val->var, sub, &wif, &phy); - if (txparam == NULL || wif == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfTxUnicastRate: - ctx->scratch->int1 = txparam->ucastrate; - txparam->ucastrate = val->v.integer * 2; - break; - case LEAF_wlanIfTxMcastRate: - ctx->scratch->int1 = txparam->mcastrate; - txparam->mcastrate = val->v.integer * 2; - break; - case LEAF_wlanIfTxMgmtRate: - ctx->scratch->int1 = txparam->mgmtrate; - txparam->mgmtrate = val->v.integer * 2; - break; - case LEAF_wlanIfTxMaxRetryCount: - ctx->scratch->int1 = txparam->maxretry; - txparam->maxretry = val->v.integer; - break; - default: - abort(); - } - if (wlan_set_tx_params(wif, phy) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - txparam = wlan_get_tx_param(&val->var, sub, &wif, &phy); - if (txparam == NULL || wif == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfTxUnicastRate: - txparam->ucastrate = ctx->scratch->int1; - break; - case LEAF_wlanIfTxMcastRate: - txparam->mcastrate = ctx->scratch->int1; - break; - case LEAF_wlanIfTxMgmtRate: - txparam->mgmtrate = ctx->scratch->int1; - break; - case LEAF_wlanIfTxMaxRetryCount: - txparam->maxretry = ctx->scratch->int1; - break; - default: - abort(); - } - if (wlan_set_tx_params(wif, phy) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - default: - abort(); - } - -get_txparams: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanIfTxUnicastRate: - val->v.integer = txparam->ucastrate / 2; - break; - case LEAF_wlanIfTxMcastRate: - val->v.integer = txparam->mcastrate / 2; - break; - case LEAF_wlanIfTxMgmtRate: - val->v.integer = txparam->mgmtrate / 2; - break; - case LEAF_wlanIfTxMaxRetryCount: - val->v.integer = txparam->maxretry; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_scan_config(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - if ((wif = wlan_get_next_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - - case SNMP_OP_SET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (wif->scan_status == wlanScanConfigStatus_running - && val->var.subs[sub - 1] != LEAF_wlanScanConfigStatus) - return (SNMP_ERR_INCONS_VALUE); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanScanFlags: - ctx->scratch->int1 = wif->scan_flags; - wif->scan_flags = val->v.integer; - break; - case LEAF_wlanScanDuration: - ctx->scratch->int1 = wif->scan_duration; - wif->scan_duration = val->v.integer; - break; - case LEAF_wlanScanMinChannelDwellTime: - ctx->scratch->int1 = wif->scan_mindwell; - wif->scan_mindwell = val->v.integer; - break; - case LEAF_wlanScanMaxChannelDwellTime: - ctx->scratch->int1 = wif->scan_maxdwell; - wif->scan_maxdwell = val->v.integer; - break; - case LEAF_wlanScanConfigStatus: - if (val->v.integer == wlanScanConfigStatus_running || - val->v.integer == wlanScanConfigStatus_cancel) { - ctx->scratch->int1 = wif->scan_status; - wif->scan_status = val->v.integer; - break; - } - return (SNMP_ERR_INCONS_VALUE); - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (val->var.subs[sub - 1] == LEAF_wlanScanConfigStatus) - if (wif->scan_status == wlanScanConfigStatus_running) - (void)wlan_set_scan_config(wif); /* XXX */ - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanScanFlags: - wif->scan_flags = ctx->scratch->int1; - break; - case LEAF_wlanScanDuration: - wif->scan_duration = ctx->scratch->int1; - break; - case LEAF_wlanScanMinChannelDwellTime: - wif->scan_mindwell = ctx->scratch->int1; - break; - case LEAF_wlanScanMaxChannelDwellTime: - wif->scan_maxdwell = ctx->scratch->int1; - break; - case LEAF_wlanScanConfigStatus: - wif->scan_status = ctx->scratch->int1; - break; - } - return (SNMP_ERR_NOERROR); - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanScanFlags: - val->v.integer = wif->scan_flags; - break; - case LEAF_wlanScanDuration: - val->v.integer = wif->scan_duration; - break; - case LEAF_wlanScanMinChannelDwellTime: - val->v.integer = wif->scan_mindwell; - break; - case LEAF_wlanScanMaxChannelDwellTime: - val->v.integer = wif->scan_maxdwell; - break; - case LEAF_wlanScanConfigStatus: - val->v.integer = wif->scan_status; - break; - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_scan_results(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_scan_result *sr; - struct wlan_iface *wif; - - wlan_update_interface_list(); - wlan_scan_update_results(); - - switch (op) { - case SNMP_OP_GET: - if ((sr = wlan_get_scanr(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - if ((sr = wlan_get_next_scanr(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_scanr_index(&val->var, sub, wif->wname, sr->ssid, - sr->bssid); - break; - - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanScanResultID: - return (string_get(val, sr->ssid, -1)); - case LEAF_wlanScanResultBssid: - return (string_get(val, sr->bssid, IEEE80211_ADDR_LEN)); - case LEAF_wlanScanResultChannel: - val->v.integer = sr->opchannel; /* XXX */ - break; - case LEAF_wlanScanResultRate: - val->v.integer = sr->rssi; - break; - case LEAF_wlanScanResultNoise: - val->v.integer = sr->noise; - break; - case LEAF_wlanScanResultBeaconInterval: - val->v.integer = sr->bintval; - break; - case LEAF_wlanScanResultCapabilities: - return (bits_get(val, &sr->capinfo, sizeof(sr->capinfo))); - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_iface_stats(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - if ((wif = wlan_get_next_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - case SNMP_OP_SET: - /* XXX: LEAF_wlanStatsReset */ - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - if (wlan_get_stats(wif) < 0) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanStatsRxBadVersion: - val->v.uint32 = wif->stats.is_rx_badversion; - break; - case LEAF_wlanStatsRxTooShort: - val->v.uint32 = wif->stats.is_rx_tooshort; - break; - case LEAF_wlanStatsRxWrongBssid: - val->v.uint32 = wif->stats.is_rx_wrongbss; - break; - case LEAF_wlanStatsRxDiscardedDups: - val->v.uint32 = wif->stats.is_rx_dup; - break; - case LEAF_wlanStatsRxWrongDir: - val->v.uint32 = wif->stats.is_rx_wrongdir; - break; - case LEAF_wlanStatsRxDiscardMcastEcho: - val->v.uint32 = wif->stats.is_rx_mcastecho; - break; - case LEAF_wlanStatsRxDiscardNoAssoc: - val->v.uint32 = wif->stats.is_rx_notassoc; - break; - case LEAF_wlanStatsRxWepNoPrivacy: - val->v.uint32 = wif->stats.is_rx_noprivacy; - break; - case LEAF_wlanStatsRxWepUnencrypted: - val->v.uint32 = wif->stats.is_rx_unencrypted; - break; - case LEAF_wlanStatsRxWepFailed: - val->v.uint32 = wif->stats.is_rx_wepfail; - break; - case LEAF_wlanStatsRxDecapsulationFailed: - val->v.uint32 = wif->stats.is_rx_decap; - break; - case LEAF_wlanStatsRxDiscardMgmt: - val->v.uint32 = wif->stats.is_rx_mgtdiscard; - break; - case LEAF_wlanStatsRxControl: - val->v.uint32 = wif->stats.is_rx_ctl; - break; - case LEAF_wlanStatsRxBeacon: - val->v.uint32 = wif->stats.is_rx_beacon; - break; - case LEAF_wlanStatsRxRateSetTooBig: - val->v.uint32 = wif->stats.is_rx_rstoobig; - break; - case LEAF_wlanStatsRxElemMissing: - val->v.uint32 = wif->stats.is_rx_elem_missing; - break; - case LEAF_wlanStatsRxElemTooBig: - val->v.uint32 = wif->stats.is_rx_elem_toobig; - break; - case LEAF_wlanStatsRxElemTooSmall: - val->v.uint32 = wif->stats.is_rx_elem_toosmall; - break; - case LEAF_wlanStatsRxElemUnknown: - val->v.uint32 = wif->stats.is_rx_elem_unknown; - break; - case LEAF_wlanStatsRxChannelMismatch: - val->v.uint32 = wif->stats.is_rx_chanmismatch; - break; - case LEAF_wlanStatsRxDropped: - val->v.uint32 = wif->stats.is_rx_nodealloc; - break; - case LEAF_wlanStatsRxSsidMismatch: - val->v.uint32 = wif->stats.is_rx_ssidmismatch; - break; - case LEAF_wlanStatsRxAuthNotSupported: - val->v.uint32 = wif->stats.is_rx_auth_unsupported; - break; - case LEAF_wlanStatsRxAuthFailed: - val->v.uint32 = wif->stats.is_rx_auth_fail; - break; - case LEAF_wlanStatsRxAuthCM: - val->v.uint32 = wif->stats.is_rx_auth_countermeasures; - break; - case LEAF_wlanStatsRxAssocWrongBssid: - val->v.uint32 = wif->stats.is_rx_assoc_bss; - break; - case LEAF_wlanStatsRxAssocNoAuth: - val->v.uint32 = wif->stats.is_rx_assoc_notauth; - break; - case LEAF_wlanStatsRxAssocCapMismatch: - val->v.uint32 = wif->stats.is_rx_assoc_capmismatch; - break; - case LEAF_wlanStatsRxAssocNoRateMatch: - val->v.uint32 = wif->stats.is_rx_assoc_norate; - break; - case LEAF_wlanStatsRxBadWpaIE: - val->v.uint32 = wif->stats.is_rx_assoc_badwpaie; - break; - case LEAF_wlanStatsRxDeauthenticate: - val->v.uint32 = wif->stats.is_rx_deauth; - break; - case LEAF_wlanStatsRxDisassociate: - val->v.uint32 = wif->stats.is_rx_disassoc; - break; - case LEAF_wlanStatsRxUnknownSubtype: - val->v.uint32 = wif->stats.is_rx_badsubtype; - break; - case LEAF_wlanStatsRxFailedNoBuf: - val->v.uint32 = wif->stats.is_rx_nobuf; - break; - case LEAF_wlanStatsRxBadAuthRequest: - val->v.uint32 = wif->stats.is_rx_bad_auth; - break; - case LEAF_wlanStatsRxUnAuthorized: - val->v.uint32 = wif->stats.is_rx_unauth; - break; - case LEAF_wlanStatsRxBadKeyId: - val->v.uint32 = wif->stats.is_rx_badkeyid; - break; - case LEAF_wlanStatsRxCCMPSeqViolation: - val->v.uint32 = wif->stats.is_rx_ccmpreplay; - break; - case LEAF_wlanStatsRxCCMPBadFormat: - val->v.uint32 = wif->stats.is_rx_ccmpformat; - break; - case LEAF_wlanStatsRxCCMPFailedMIC: - val->v.uint32 = wif->stats.is_rx_ccmpmic; - break; - case LEAF_wlanStatsRxTKIPSeqViolation: - val->v.uint32 = wif->stats.is_rx_tkipreplay; - break; - case LEAF_wlanStatsRxTKIPBadFormat: - val->v.uint32 = wif->stats.is_rx_tkipformat; - break; - case LEAF_wlanStatsRxTKIPFailedMIC: - val->v.uint32 = wif->stats.is_rx_tkipmic; - break; - case LEAF_wlanStatsRxTKIPFailedICV: - val->v.uint32 = wif->stats.is_rx_tkipicv; - break; - case LEAF_wlanStatsRxDiscardACL: - val->v.uint32 = wif->stats.is_rx_acl; - break; - case LEAF_wlanStatsTxFailedNoBuf: - val->v.uint32 = wif->stats.is_tx_nobuf; - break; - case LEAF_wlanStatsTxFailedNoNode: - val->v.uint32 = wif->stats.is_tx_nonode; - break; - case LEAF_wlanStatsTxUnknownMgmt: - val->v.uint32 = wif->stats.is_tx_unknownmgt; - break; - case LEAF_wlanStatsTxBadCipher: - val->v.uint32 = wif->stats.is_tx_badcipher; - break; - case LEAF_wlanStatsTxNoDefKey: - val->v.uint32 = wif->stats.is_tx_nodefkey; - break; - case LEAF_wlanStatsTxFragmented: - val->v.uint32 = wif->stats.is_tx_fragframes; - break; - case LEAF_wlanStatsTxFragmentsCreated: - val->v.uint32 = wif->stats.is_tx_frags; - break; - case LEAF_wlanStatsActiveScans: - val->v.uint32 = wif->stats.is_scan_active; - break; - case LEAF_wlanStatsPassiveScans: - val->v.uint32 = wif->stats.is_scan_passive; - break; - case LEAF_wlanStatsTimeoutInactivity: - val->v.uint32 = wif->stats.is_node_timeout; - break; - case LEAF_wlanStatsCryptoNoMem: - val->v.uint32 = wif->stats.is_crypto_nomem; - break; - case LEAF_wlanStatsSwCryptoTKIP: - val->v.uint32 = wif->stats.is_crypto_tkip; - break; - case LEAF_wlanStatsSwCryptoTKIPEnMIC: - val->v.uint32 = wif->stats.is_crypto_tkipenmic; - break; - case LEAF_wlanStatsSwCryptoTKIPDeMIC: - val->v.uint32 = wif->stats.is_crypto_tkipdemic; - break; - case LEAF_wlanStatsCryptoTKIPCM: - val->v.uint32 = wif->stats.is_crypto_tkipcm; - break; - case LEAF_wlanStatsSwCryptoCCMP: - val->v.uint32 = wif->stats.is_crypto_ccmp; - break; - case LEAF_wlanStatsSwCryptoWEP: - val->v.uint32 = wif->stats.is_crypto_wep; - break; - case LEAF_wlanStatsCryptoCipherKeyRejected: - val->v.uint32 = wif->stats.is_crypto_setkey_cipher; - break; - case LEAF_wlanStatsCryptoNoKey: - val->v.uint32 = wif->stats.is_crypto_setkey_nokey; - break; - case LEAF_wlanStatsCryptoDeleteKeyFailed: - val->v.uint32 = wif->stats.is_crypto_delkey; - break; - case LEAF_wlanStatsCryptoUnknownCipher: - val->v.uint32 = wif->stats.is_crypto_badcipher; - break; - case LEAF_wlanStatsCryptoAttachFailed: - val->v.uint32 = wif->stats.is_crypto_attachfail; - break; - case LEAF_wlanStatsCryptoKeyFailed: - val->v.uint32 = wif->stats.is_crypto_keyfail; - break; - case LEAF_wlanStatsCryptoEnMICFailed: - val->v.uint32 = wif->stats.is_crypto_enmicfail; - break; - case LEAF_wlanStatsIBSSCapMismatch: - val->v.uint32 = wif->stats.is_ibss_capmismatch; - break; - case LEAF_wlanStatsUnassocStaPSPoll: - val->v.uint32 = wif->stats.is_ps_unassoc; - break; - case LEAF_wlanStatsBadAidPSPoll: - val->v.uint32 = wif->stats.is_ps_badaid; - break; - case LEAF_wlanStatsEmptyPSPoll: - val->v.uint32 = wif->stats.is_ps_qempty; - break; - case LEAF_wlanStatsRxFFBadHdr: - val->v.uint32 = wif->stats.is_ff_badhdr; - break; - case LEAF_wlanStatsRxFFTooShort: - val->v.uint32 = wif->stats.is_ff_tooshort; - break; - case LEAF_wlanStatsRxFFSplitError: - val->v.uint32 = wif->stats.is_ff_split; - break; - case LEAF_wlanStatsRxFFDecap: - val->v.uint32 = wif->stats.is_ff_decap; - break; - case LEAF_wlanStatsTxFFEncap: - val->v.uint32 = wif->stats.is_ff_encap; - break; - case LEAF_wlanStatsRxBadBintval: - val->v.uint32 = wif->stats.is_rx_badbintval; - break; - case LEAF_wlanStatsRxDemicFailed: - val->v.uint32 = wif->stats.is_rx_demicfail; - break; - case LEAF_wlanStatsRxDefragFailed: - val->v.uint32 = wif->stats.is_rx_defrag; - break; - case LEAF_wlanStatsRxMgmt: - val->v.uint32 = wif->stats.is_rx_mgmt; - break; - case LEAF_wlanStatsRxActionMgmt: - val->v.uint32 = wif->stats.is_rx_action; - break; - case LEAF_wlanStatsRxAMSDUTooShort: - val->v.uint32 = wif->stats.is_amsdu_tooshort; - break; - case LEAF_wlanStatsRxAMSDUSplitError: - val->v.uint32 = wif->stats.is_amsdu_split; - break; - case LEAF_wlanStatsRxAMSDUDecap: - val->v.uint32 = wif->stats.is_amsdu_decap; - break; - case LEAF_wlanStatsTxAMSDUEncap: - val->v.uint32 = wif->stats.is_amsdu_encap; - break; - case LEAF_wlanStatsAMPDUBadBAR: - val->v.uint32 = wif->stats.is_ampdu_bar_bad; - break; - case LEAF_wlanStatsAMPDUOowBar: - val->v.uint32 = wif->stats.is_ampdu_bar_oow; - break; - case LEAF_wlanStatsAMPDUMovedBAR: - val->v.uint32 = wif->stats.is_ampdu_bar_move; - break; - case LEAF_wlanStatsAMPDURxBAR: - val->v.uint32 = wif->stats.is_ampdu_bar_rx; - break; - case LEAF_wlanStatsAMPDURxOor: - val->v.uint32 = wif->stats.is_ampdu_rx_oor; - break; - case LEAF_wlanStatsAMPDURxCopied: - val->v.uint32 = wif->stats.is_ampdu_rx_copy; - break; - case LEAF_wlanStatsAMPDURxDropped: - val->v.uint32 = wif->stats.is_ampdu_rx_drop; - break; - case LEAF_wlanStatsTxDiscardBadState: - val->v.uint32 = wif->stats.is_tx_badstate; - break; - case LEAF_wlanStatsTxFailedNoAssoc: - val->v.uint32 = wif->stats.is_tx_notassoc; - break; - case LEAF_wlanStatsTxClassifyFailed: - val->v.uint32 = wif->stats.is_tx_classify; - break; - case LEAF_wlanStatsDwdsMcastDiscard: - val->v.uint32 = wif->stats.is_dwds_mcast; - break; - case LEAF_wlanStatsHTAssocRejectNoHT: - val->v.uint32 = wif->stats.is_ht_assoc_nohtcap; - break; - case LEAF_wlanStatsHTAssocDowngrade: - val->v.uint32 = wif->stats.is_ht_assoc_downgrade; - break; - case LEAF_wlanStatsHTAssocRateMismatch: - val->v.uint32 = wif->stats.is_ht_assoc_norate; - break; - case LEAF_wlanStatsAMPDURxAge: - val->v.uint32 = wif->stats.is_ampdu_rx_age; - break; - case LEAF_wlanStatsAMPDUMoved: - val->v.uint32 = wif->stats.is_ampdu_rx_move; - break; - case LEAF_wlanStatsADDBADisabledReject: - val->v.uint32 = wif->stats.is_addba_reject; - break; - case LEAF_wlanStatsADDBANoRequest: - val->v.uint32 = wif->stats.is_addba_norequest; - break; - case LEAF_wlanStatsADDBABadToken: - val->v.uint32 = wif->stats.is_addba_badtoken; - break; - case LEAF_wlanStatsADDBABadPolicy: - val->v.uint32 = wif->stats.is_addba_badpolicy; - break; - case LEAF_wlanStatsAMPDUStopped: - val->v.uint32 = wif->stats.is_ampdu_stop; - break; - case LEAF_wlanStatsAMPDUStopFailed: - val->v.uint32 = wif->stats.is_ampdu_stop_failed; - break; - case LEAF_wlanStatsAMPDURxReorder: - val->v.uint32 = wif->stats.is_ampdu_rx_reorder; - break; - case LEAF_wlanStatsScansBackground: - val->v.uint32 = wif->stats.is_scan_bg; - break; - case LEAF_wlanLastDeauthReason: - val->v.uint32 = wif->stats.is_rx_deauth_code; - break; - case LEAF_wlanLastDissasocReason: - val->v.uint32 = wif->stats.is_rx_disassoc_code; - break; - case LEAF_wlanLastAuthFailReason: - val->v.uint32 = wif->stats.is_rx_authfail_code; - break; - case LEAF_wlanStatsBeaconMissedEvents: - val->v.uint32 = wif->stats.is_beacon_miss; - break; - case LEAF_wlanStatsRxDiscardBadStates: - val->v.uint32 = wif->stats.is_rx_badstate; - break; - case LEAF_wlanStatsFFFlushed: - val->v.uint32 = wif->stats.is_ff_flush; - break; - case LEAF_wlanStatsTxControlFrames: - val->v.uint32 = wif->stats.is_tx_ctl; - break; - case LEAF_wlanStatsAMPDURexmt: - val->v.uint32 = wif->stats.is_ampdu_rexmt; - break; - case LEAF_wlanStatsAMPDURexmtFailed: - val->v.uint32 = wif->stats.is_ampdu_rexmt_fail; - break; - case LEAF_wlanStatsReset: - val->v.uint32 = wlanStatsReset_no_op; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_wep_iface(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL || - !wif->wepsupported) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - /* XXX: filter wif->wepsupported */ - if ((wif = wlan_get_next_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - - case SNMP_OP_SET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL || - !wif->wepsupported) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanWepMode: - if (val->v.integer < wlanWepMode_off || - val->v.integer > wlanWepMode_mixed) - return (SNMP_ERR_INCONS_VALUE); - ctx->scratch->int1 = wif->wepmode; - wif->wepmode = val->v.integer; - if (wlan_set_wepmode(wif) < 0) { - wif->wepmode = ctx->scratch->int1; - return (SNMP_ERR_GENERR); - } - break; - case LEAF_wlanWepDefTxKey: - if (val->v.integer < 0 || - val->v.integer > IEEE80211_WEP_NKID) - return (SNMP_ERR_INCONS_VALUE); - ctx->scratch->int1 = wif->weptxkey; - wif->weptxkey = val->v.integer; - if (wlan_set_weptxkey(wif) < 0) { - wif->weptxkey = ctx->scratch->int1; - return (SNMP_ERR_GENERR); - } - break; - default: - abort(); - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanWepMode: - wif->wepmode = ctx->scratch->int1; - if (wlan_set_wepmode(wif) < 0) - return (SNMP_ERR_GENERR); - break; - case LEAF_wlanWepDefTxKey: - wif->weptxkey = ctx->scratch->int1; - if (wlan_set_weptxkey(wif) < 0) - return (SNMP_ERR_GENERR); - break; - default: - abort(); - } - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanWepMode: - if (wlan_get_wepmode(wif) < 0) - return (SNMP_ERR_GENERR); - val->v.integer = wif->wepmode; - break; - case LEAF_wlanWepDefTxKey: - if (wlan_get_weptxkey(wif) < 0) - return (SNMP_ERR_GENERR); - val->v.integer = wif->weptxkey; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_wep_key(struct snmp_context *ctx __unused, - struct snmp_value *val __unused, uint32_t sub __unused, - uint32_t iidx __unused, enum snmp_op op __unused) -{ - return (SNMP_ERR_NOSUCHNAME); -} - -int -op_wlan_mac_access_control(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL || - !wif->macsupported) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - /* XXX: filter wif->macsupported */ - if ((wif = wlan_get_next_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - - case SNMP_OP_SET: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL || - !wif->macsupported) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMACAccessControlPolicy: - ctx->scratch->int1 = wif->mac_policy; - wif->mac_policy = val->v.integer; - break; - case LEAF_wlanMACAccessControlNacl: - return (SNMP_ERR_NOT_WRITEABLE); - case LEAF_wlanMACAccessControlFlush: - break; - default: - abort(); - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMACAccessControlPolicy: - if (wlan_set_mac_policy(wif) < 0) { - wif->mac_policy = ctx->scratch->int1; - return (SNMP_ERR_GENERR); - } - break; - case LEAF_wlanMACAccessControlFlush: - if (wlan_flush_mac_mac(wif) < 0) - return (SNMP_ERR_GENERR); - break; - default: - abort(); - } - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - if ((wif = wlan_get_interface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (val->var.subs[sub - 1] == LEAF_wlanMACAccessControlPolicy) - wif->mac_policy = ctx->scratch->int1; - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - if (wlan_get_mac_policy(wif) < 0) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMACAccessControlPolicy: - val->v.integer = wif->mac_policy; - break; - case LEAF_wlanMACAccessControlNacl: - val->v.integer = wif->mac_nacls; - break; - case LEAF_wlanMACAccessControlFlush: - val->v.integer = wlanMACAccessControlFlush_no_op; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_mac_acl_mac(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - struct wlan_mac_mac *macl; - - wlan_update_interface_list(); - wlan_mac_update_aclmacs(); - - switch (op) { - case SNMP_OP_GET: - if ((macl = wlan_get_acl_mac(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - if ((macl = wlan_get_next_acl_mac(&val->var, sub, &wif)) - == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_mac_index(&val->var, sub, wif->wname, macl->mac); - break; - - case SNMP_OP_SET: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMACAccessControlMAC: - return (SNMP_ERR_INCONS_NAME); - case LEAF_wlanMACAccessControlMACStatus: - return(wlan_acl_mac_set_status(ctx, val, sub)); - default: - abort(); - } - - case SNMP_OP_COMMIT: - if ((macl = wlan_get_acl_mac(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (val->v.integer == RowStatus_destroy && - wlan_mac_delete_mac(wif, macl) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - if ((macl = wlan_get_acl_mac(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (ctx->scratch->int1 == RowStatus_destroy && - wlan_mac_delete_mac(wif, macl) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMACAccessControlMAC: - return (string_get(val, macl->mac, IEEE80211_ADDR_LEN)); - case LEAF_wlanMACAccessControlMACStatus: - val->v.integer = macl->mac_status; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_mesh_config(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - int which; - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshMaxRetries: - which = WLAN_MESH_MAX_RETRIES; - break; - case LEAF_wlanMeshHoldingTimeout: - which = WLAN_MESH_HOLDING_TO; - break; - case LEAF_wlanMeshConfirmTimeout: - which = WLAN_MESH_CONFIRM_TO; - break; - case LEAF_wlanMeshRetryTimeout: - which = WLAN_MESH_RETRY_TO; - break; - default: - abort(); - } - - switch (op) { - case SNMP_OP_GET: - if (wlan_do_sysctl(&wlan_config, which, 0) < 0) - return (SNMP_ERR_GENERR); - break; - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_SET: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshRetryTimeout : - ctx->scratch->int1 = wlan_config.mesh_retryto; - wlan_config.mesh_retryto = val->v.integer; - break; - case LEAF_wlanMeshHoldingTimeout: - ctx->scratch->int1 = wlan_config.mesh_holdingto; - wlan_config.mesh_holdingto = val->v.integer; - break; - case LEAF_wlanMeshConfirmTimeout: - ctx->scratch->int1 = wlan_config.mesh_confirmto; - wlan_config.mesh_confirmto = val->v.integer; - break; - case LEAF_wlanMeshMaxRetries: - ctx->scratch->int1 = wlan_config.mesh_maxretries; - wlan_config.mesh_maxretries = val->v.integer; - break; - } - if (wlan_do_sysctl(&wlan_config, which, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshRetryTimeout: - wlan_config.mesh_retryto = ctx->scratch->int1; - break; - case LEAF_wlanMeshConfirmTimeout: - wlan_config.mesh_confirmto = ctx->scratch->int1; - break; - case LEAF_wlanMeshHoldingTimeout: - wlan_config.mesh_holdingto= ctx->scratch->int1; - break; - case LEAF_wlanMeshMaxRetries: - wlan_config.mesh_maxretries = ctx->scratch->int1; - break; - } - if (wlan_do_sysctl(&wlan_config, which, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshRetryTimeout: - val->v.integer = wlan_config.mesh_retryto; - break; - case LEAF_wlanMeshHoldingTimeout: - val->v.integer = wlan_config.mesh_holdingto; - break; - case LEAF_wlanMeshConfirmTimeout: - val->v.integer = wlan_config.mesh_confirmto; - break; - case LEAF_wlanMeshMaxRetries: - val->v.integer = wlan_config.mesh_maxretries; - break; - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_mesh_iface(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - int rc; - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - if ((wif = wlan_mesh_get_next_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - - case SNMP_OP_SET: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshId: - if (val->v.octetstring.len > IEEE80211_NWID_LEN) - return (SNMP_ERR_INCONS_VALUE); - ctx->scratch->ptr1 = malloc(val->v.octetstring.len + 1); - if (ctx->scratch->ptr1 == NULL) - return (SNMP_ERR_GENERR); - strlcpy(ctx->scratch->ptr1, wif->desired_ssid, - val->v.octetstring.len + 1); - ctx->scratch->int1 = strlen(wif->desired_ssid); - memcpy(wif->desired_ssid, val->v.octetstring.octets, - val->v.octetstring.len); - wif->desired_ssid[val->v.octetstring.len] = '\0'; - break; - case LEAF_wlanMeshTTL: - ctx->scratch->int1 = wif->mesh_ttl; - wif->mesh_ttl = val->v.integer; - break; - case LEAF_wlanMeshPeeringEnabled: - ctx->scratch->int1 = wif->mesh_peering; - wif->mesh_peering = val->v.integer; - break; - case LEAF_wlanMeshForwardingEnabled: - ctx->scratch->int1 = wif->mesh_forwarding; - wif->mesh_forwarding = val->v.integer; - break; - case LEAF_wlanMeshMetric: - ctx->scratch->int1 = wif->mesh_metric; - wif->mesh_metric = val->v.integer; - break; - case LEAF_wlanMeshPath: - ctx->scratch->int1 = wif->mesh_path; - wif->mesh_path = val->v.integer; - break; - case LEAF_wlanMeshRoutesFlush: - if (val->v.integer != wlanMeshRoutesFlush_flush) - return (SNMP_ERR_INCONS_VALUE); - return (SNMP_ERR_NOERROR); - default: - abort(); - } - if (val->var.subs[sub - 1] == LEAF_wlanMeshId) - rc = wlan_config_set_dssid(wif, - val->v.octetstring.octets, val->v.octetstring.len); - else - rc = wlan_mesh_config_set(wif, val->var.subs[sub - 1]); - if (rc < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (val->var.subs[sub - 1] == LEAF_wlanMeshRoutesFlush && - wlan_mesh_flush_routes(wif) < 0) - return (SNMP_ERR_GENERR); - if (val->var.subs[sub - 1] == LEAF_wlanMeshId) - free(ctx->scratch->ptr1); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshId: - strlcpy(wif->desired_ssid, ctx->scratch->ptr1, - IEEE80211_NWID_LEN); - free(ctx->scratch->ptr1); - break; - case LEAF_wlanMeshTTL: - wif->mesh_ttl = ctx->scratch->int1; - break; - case LEAF_wlanMeshPeeringEnabled: - wif->mesh_peering = ctx->scratch->int1; - break; - case LEAF_wlanMeshForwardingEnabled: - wif->mesh_forwarding = ctx->scratch->int1; - break; - case LEAF_wlanMeshMetric: - wif->mesh_metric = ctx->scratch->int1; - break; - case LEAF_wlanMeshPath: - wif->mesh_path = ctx->scratch->int1; - break; - case LEAF_wlanMeshRoutesFlush: - return (SNMP_ERR_NOERROR); - default: - abort(); - } - if (val->var.subs[sub - 1] == LEAF_wlanMeshId) - rc = wlan_config_set_dssid(wif, wif->desired_ssid, - strlen(wif->desired_ssid)); - else - rc = wlan_mesh_config_set(wif, val->var.subs[sub - 1]); - if (rc < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - if (val->var.subs[sub - 1] == LEAF_wlanMeshId) - rc = wlan_config_get_dssid(wif); - else - rc = wlan_mesh_config_get(wif, val->var.subs[sub - 1]); - if (rc < 0) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshId: - return (string_get(val, wif->desired_ssid, -1)); - case LEAF_wlanMeshTTL: - val->v.integer = wif->mesh_ttl; - break; - case LEAF_wlanMeshPeeringEnabled: - val->v.integer = wif->mesh_peering; - break; - case LEAF_wlanMeshForwardingEnabled: - val->v.integer = wif->mesh_forwarding; - break; - case LEAF_wlanMeshMetric: - val->v.integer = wif->mesh_metric; - break; - case LEAF_wlanMeshPath: - val->v.integer = wif->mesh_path; - break; - case LEAF_wlanMeshRoutesFlush: - val->v.integer = wlanMeshRoutesFlush_no_op; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_mesh_neighbor(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_peer *wip; - struct wlan_iface *wif; - - wlan_update_interface_list(); - wlan_update_peers(); - - switch (op) { - case SNMP_OP_GET: - if ((wip = wlan_mesh_get_peer(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - wip = wlan_mesh_get_next_peer(&val->var, sub, &wif); - if (wip == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_mac_index(&val->var, sub, wif->wname, - wip->pmac); - break; - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshNeighborAddress: - return (string_get(val, wip->pmac, IEEE80211_ADDR_LEN)); - case LEAF_wlanMeshNeighborFrequency: - val->v.integer = wip->frequency; - break; - case LEAF_wlanMeshNeighborLocalId: - val->v.integer = wip->local_id; - break; - case LEAF_wlanMeshNeighborPeerId: - val->v.integer = wip->peer_id; - break; - case LEAF_wlanMeshNeighborPeerState: - return (bits_get(val, (uint8_t *)&wip->state, - sizeof(wip->state))); - case LEAF_wlanMeshNeighborCurrentTXRate: - val->v.integer = wip->txrate; - break; - case LEAF_wlanMeshNeighborRxSignalStrength: - val->v.integer = wip->rssi; - break; - case LEAF_wlanMeshNeighborIdleTimer: - val->v.integer = wip->idle; - break; - case LEAF_wlanMeshNeighborTxSequenceNo: - val->v.integer = wip->txseqs; - break; - case LEAF_wlanMeshNeighborRxSequenceNo: - val->v.integer = wip->rxseqs; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_mesh_route(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_mesh_route *wmr; - struct wlan_iface *wif; - - wlan_update_interface_list(); - wlan_mesh_update_routes(); - - switch (op) { - case SNMP_OP_GET: - if ((wmr = wlan_mesh_get_route(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - wmr = wlan_mesh_get_next_route(&val->var, sub, &wif); - if (wmr == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_mac_index(&val->var, sub, wif->wname, - wmr->imroute.imr_dest); - break; - - case SNMP_OP_SET: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshRouteDestination: - return (SNMP_ERR_INCONS_NAME); - case LEAF_wlanMeshRouteStatus: - return(wlan_mesh_route_set_status(ctx, val, sub)); - default: - return (SNMP_ERR_NOT_WRITEABLE); - } - abort(); - - case SNMP_OP_COMMIT: - if ((wmr = wlan_mesh_get_route(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (val->v.integer == RowStatus_destroy && - wlan_mesh_delete_route(wif, wmr) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - if ((wmr = wlan_mesh_get_route(&val->var, sub, &wif)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - if (ctx->scratch->int1 == RowStatus_destroy && - wlan_mesh_delete_route(wif, wmr) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshRouteDestination: - return (string_get(val, wmr->imroute.imr_dest, - IEEE80211_ADDR_LEN)); - case LEAF_wlanMeshRouteNextHop: - return (string_get(val, wmr->imroute.imr_nexthop, - IEEE80211_ADDR_LEN)); - case LEAF_wlanMeshRouteHops: - val->v.integer = wmr->imroute.imr_nhops; - break; - case LEAF_wlanMeshRouteMetric: - val->v.integer = wmr->imroute.imr_metric; - break; - case LEAF_wlanMeshRouteLifeTime: - val->v.integer = wmr->imroute.imr_lifetime; - break; - case LEAF_wlanMeshRouteLastMseq: - val->v.integer = wmr->imroute.imr_lastmseq; - break; - case LEAF_wlanMeshRouteFlags: - val->v.integer = 0; - if ((wmr->imroute.imr_flags & - IEEE80211_MESHRT_FLAGS_VALID) != 0) - val->v.integer |= (0x1 << wlanMeshRouteFlags_valid); - if ((wmr->imroute.imr_flags & - IEEE80211_MESHRT_FLAGS_PROXY) != 0) - val->v.integer |= (0x1 << wlanMeshRouteFlags_proxy); - return (bits_get(val, (uint8_t *)&val->v.integer, - sizeof(val->v.integer))); - case LEAF_wlanMeshRouteStatus: - val->v.integer = wmr->mroute_status; - break; - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_mesh_stats(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - if ((wif = wlan_mesh_get_next_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - if (wlan_get_stats(wif) < 0) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshDroppedBadSta: - val->v.uint32 = wif->stats.is_mesh_wrongmesh; - break; - case LEAF_wlanMeshDroppedNoLink: - val->v.uint32 = wif->stats.is_mesh_nolink; - break; - case LEAF_wlanMeshNoFwdTtl: - val->v.uint32 = wif->stats.is_mesh_fwd_ttl; - break; - case LEAF_wlanMeshNoFwdBuf: - val->v.uint32 = wif->stats.is_mesh_fwd_nobuf; - break; - case LEAF_wlanMeshNoFwdTooShort: - val->v.uint32 = wif->stats.is_mesh_fwd_tooshort; - break; - case LEAF_wlanMeshNoFwdDisabled: - val->v.uint32 = wif->stats.is_mesh_fwd_disabled; - break; - case LEAF_wlanMeshNoFwdPathUnknown: - val->v.uint32 = wif->stats.is_mesh_fwd_nopath; - break; - case LEAF_wlanMeshDroppedBadAE: - val->v.uint32 = wif->stats.is_mesh_badae; - break; - case LEAF_wlanMeshRouteAddFailed: - val->v.uint32 = wif->stats.is_mesh_rtaddfailed; - break; - case LEAF_wlanMeshDroppedNoProxy: - val->v.uint32 = wif->stats.is_mesh_notproxy; - break; - case LEAF_wlanMeshDroppedMisaligned: - val->v.uint32 = wif->stats.is_rx_badalign; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_hwmp_config(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - int which; - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanHWMPRouteInactiveTimeout: - which = WLAN_HWMP_INACTIVITY_TO; - break; - case LEAF_wlanHWMPRootAnnounceInterval: - which = WLAN_HWMP_RANN_INT; - break; - case LEAF_wlanHWMPRootInterval: - which = WLAN_HWMP_ROOT_INT; - break; - case LEAF_wlanHWMPRootTimeout: - which = WLAN_HWMP_ROOT_TO; - break; - case LEAF_wlanHWMPPathLifetime: - which = WLAN_HWMP_PATH_LIFETIME; - break; - case LEAF_wlanHWMPReplyForwardBit: - which = WLAN_HWMP_REPLY_FORWARD; - break; - case LEAF_wlanHWMPTargetOnlyBit: - which = WLAN_HWMP_TARGET_ONLY; - break; - default: - abort(); - } - - switch (op) { - case SNMP_OP_GET: - if (wlan_do_sysctl(&wlan_config, which, 0) < 0) - return (SNMP_ERR_GENERR); - break; - - case SNMP_OP_GETNEXT: - abort(); - - case SNMP_OP_SET: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanHWMPRouteInactiveTimeout: - ctx->scratch->int1 = wlan_config.hwmp_inact; - wlan_config.hwmp_inact = val->v.integer; - break; - case LEAF_wlanHWMPRootAnnounceInterval: - ctx->scratch->int1 = wlan_config.hwmp_rannint; - wlan_config.hwmp_rannint = val->v.integer; - break; - case LEAF_wlanHWMPRootInterval: - ctx->scratch->int1 = wlan_config.hwmp_rootint; - wlan_config.hwmp_rootint = val->v.integer; - break; - case LEAF_wlanHWMPRootTimeout: - ctx->scratch->int1 = wlan_config.hwmp_roottimeout; - wlan_config.hwmp_roottimeout = val->v.integer; - break; - case LEAF_wlanHWMPPathLifetime: - ctx->scratch->int1 = wlan_config.hwmp_pathlifetime; - wlan_config.hwmp_pathlifetime = val->v.integer; - break; - case LEAF_wlanHWMPReplyForwardBit: - ctx->scratch->int1 = wlan_config.hwmp_replyforward; - wlan_config.hwmp_replyforward = val->v.integer; - break; - case LEAF_wlanHWMPTargetOnlyBit: - ctx->scratch->int1 = wlan_config.hwmp_targetonly; - wlan_config.hwmp_targetonly = val->v.integer; - break; - } - if (wlan_do_sysctl(&wlan_config, which, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - switch (val->var.subs[sub - 1]) { - case LEAF_wlanHWMPRouteInactiveTimeout: - wlan_config.hwmp_inact = ctx->scratch->int1; - break; - case LEAF_wlanHWMPRootAnnounceInterval: - wlan_config.hwmp_rannint = ctx->scratch->int1; - break; - case LEAF_wlanHWMPRootInterval: - wlan_config.hwmp_rootint = ctx->scratch->int1; - break; - case LEAF_wlanHWMPRootTimeout: - wlan_config.hwmp_roottimeout = ctx->scratch->int1; - break; - case LEAF_wlanHWMPPathLifetime: - wlan_config.hwmp_pathlifetime = ctx->scratch->int1; - break; - case LEAF_wlanHWMPReplyForwardBit: - wlan_config.hwmp_replyforward = ctx->scratch->int1; - break; - case LEAF_wlanHWMPTargetOnlyBit: - wlan_config.hwmp_targetonly = ctx->scratch->int1; - break; - } - if (wlan_do_sysctl(&wlan_config, which, 1) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanHWMPRouteInactiveTimeout: - val->v.integer = wlan_config.hwmp_inact; - break; - case LEAF_wlanHWMPRootAnnounceInterval: - val->v.integer = wlan_config.hwmp_rannint; - break; - case LEAF_wlanHWMPRootInterval: - val->v.integer = wlan_config.hwmp_rootint; - break; - case LEAF_wlanHWMPRootTimeout: - val->v.integer = wlan_config.hwmp_roottimeout; - break; - case LEAF_wlanHWMPPathLifetime: - val->v.integer = wlan_config.hwmp_pathlifetime; - break; - case LEAF_wlanHWMPReplyForwardBit: - val->v.integer = wlan_config.hwmp_replyforward; - break; - case LEAF_wlanHWMPTargetOnlyBit: - val->v.integer = wlan_config.hwmp_targetonly; - break; - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_hwmp_iface(struct snmp_context *ctx, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - - case SNMP_OP_GETNEXT: - if ((wif = wlan_mesh_get_next_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - - case SNMP_OP_SET: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanHWMPRootMode: - ctx->scratch->int1 = wif->hwmp_root_mode; - wif->hwmp_root_mode = val->v.integer; - break; - case LEAF_wlanHWMPMaxHops: - ctx->scratch->int1 = wif->hwmp_max_hops; - wif->hwmp_max_hops = val->v.integer; - break; - default: - abort(); - } - if (wlan_hwmp_config_set(wif, val->var.subs[sub - 1]) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - case SNMP_OP_COMMIT: - return (SNMP_ERR_NOERROR); - - case SNMP_OP_ROLLBACK: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - switch (val->var.subs[sub - 1]) { - case LEAF_wlanHWMPRootMode: - wif->hwmp_root_mode = ctx->scratch->int1; - break; - case LEAF_wlanHWMPMaxHops: - wif->hwmp_max_hops = ctx->scratch->int1; - break; - default: - abort(); - } - if (wlan_hwmp_config_set(wif, val->var.subs[sub - 1]) < 0) - return (SNMP_ERR_GENERR); - return (SNMP_ERR_NOERROR); - - default: - abort(); - } - - if (wlan_hwmp_config_get(wif, val->var.subs[sub - 1]) < 0) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanHWMPRootMode: - val->v.integer = wif->hwmp_root_mode; - break; - case LEAF_wlanHWMPMaxHops: - val->v.integer = wif->hwmp_max_hops; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -int -op_wlan_hwmp_stats(struct snmp_context *ctx __unused, struct snmp_value *val, - uint32_t sub, uint32_t iidx __unused, enum snmp_op op) -{ - struct wlan_iface *wif; - - wlan_update_interface_list(); - - switch (op) { - case SNMP_OP_GET: - if ((wif = wlan_mesh_get_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - break; - case SNMP_OP_GETNEXT: - if ((wif = wlan_mesh_get_next_iface(&val->var, sub)) == NULL) - return (SNMP_ERR_NOSUCHNAME); - wlan_append_ifindex(&val->var, sub, wif); - break; - case SNMP_OP_SET: - return (SNMP_ERR_NOT_WRITEABLE); - case SNMP_OP_COMMIT: - /* FALLTHROUGH */ - case SNMP_OP_ROLLBACK: - /* FALLTHROUGH */ - default: - abort(); - } - - if (wlan_get_stats(wif) < 0) - return (SNMP_ERR_GENERR); - - switch (val->var.subs[sub - 1]) { - case LEAF_wlanMeshHWMPWrongSeqNo: - val->v.uint32 = wif->stats.is_hwmp_wrongseq; - break; - case LEAF_wlanMeshHWMPTxRootPREQ: - val->v.uint32 = wif->stats.is_hwmp_rootreqs; - break; - case LEAF_wlanMeshHWMPTxRootRANN: - val->v.uint32 = wif->stats.is_hwmp_rootrann; - break; - case LEAF_wlanMeshHWMPProxy: - val->v.uint32 = wif->stats.is_hwmp_proxy; - break; - default: - abort(); - } - - return (SNMP_ERR_NOERROR); -} - -/* - * Encode BITS type for a response packet - XXX: this belongs to the snmp lib. - */ -static int -bits_get(struct snmp_value *value, const u_char *ptr, ssize_t len) -{ - int size; - - if (ptr == NULL) { - value->v.octetstring.len = 0; - value->v.octetstring.octets = NULL; - return (SNMP_ERR_NOERROR); - } - - /* Determine length - up to 8 octets supported so far. */ - for (size = len; size > 0; size--) - if (ptr[size - 1] != 0) - break; - if (size == 0) - size = 1; - - value->v.octetstring.len = (u_long)size; - if ((value->v.octetstring.octets = malloc((size_t)size)) == NULL) - return (SNMP_ERR_RES_UNAVAIL); - memcpy(value->v.octetstring.octets, ptr, (size_t)size); - return (SNMP_ERR_NOERROR); -} - -/* - * Calls for adding/updating/freeing/etc of wireless interfaces. - */ -static void -wlan_free_interface(struct wlan_iface *wif) -{ - wlan_free_peerlist(wif); - free(wif->chanlist); - wlan_scan_free_results(wif); - wlan_mac_free_maclist(wif); - wlan_mesh_free_routes(wif); - free(wif); -} - -static void -wlan_free_iflist(void) -{ - struct wlan_iface *w; - - while ((w = SLIST_FIRST(&wlan_ifaces)) != NULL) { - SLIST_REMOVE_HEAD(&wlan_ifaces, w_if); - wlan_free_interface(w); - } -} - -static struct wlan_iface * -wlan_find_interface(const char *wname) -{ - struct wlan_iface *wif; - - SLIST_FOREACH(wif, &wlan_ifaces, w_if) - if (strcmp(wif->wname, wname) == 0) { - if (wif->status != RowStatus_active) - return (NULL); - break; - } - - return (wif); -} - -static struct wlan_iface * -wlan_first_interface(void) -{ - return (SLIST_FIRST(&wlan_ifaces)); -} - -static struct wlan_iface * -wlan_next_interface(struct wlan_iface *wif) -{ - if (wif == NULL) - return (NULL); - - return (SLIST_NEXT(wif, w_if)); -} - -/* - * Add a new interface to the list - sorted by name. - */ -static int -wlan_add_wif(struct wlan_iface *wif) -{ - int cmp; - struct wlan_iface *temp, *prev; - - if ((prev = SLIST_FIRST(&wlan_ifaces)) == NULL || - strcmp(wif->wname, prev->wname) < 0) { - SLIST_INSERT_HEAD(&wlan_ifaces, wif, w_if); - return (0); - } - - SLIST_FOREACH(temp, &wlan_ifaces, w_if) { - if ((cmp = strcmp(wif->wname, temp->wname)) <= 0) - break; - prev = temp; - } - - if (temp == NULL) - SLIST_INSERT_AFTER(prev, wif, w_if); - else if (cmp > 0) - SLIST_INSERT_AFTER(temp, wif, w_if); - else { - syslog(LOG_ERR, "Wlan iface %s already in list", wif->wname); - return (-1); - } - - return (0); -} - -static struct wlan_iface * -wlan_new_wif(char *wname) -{ - struct wlan_iface *wif; - - /* Make sure it's not in the list. */ - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) - if (strcmp(wname, wif->wname) == 0) { - wif->internal = 0; - return (wif); - } - - if ((wif = (struct wlan_iface *)malloc(sizeof(*wif))) == NULL) - return (NULL); - - memset(wif, 0, sizeof(struct wlan_iface)); - strlcpy(wif->wname, wname, IFNAMSIZ); - wif->status = RowStatus_notReady; - wif->state = wlanIfaceState_down; - wif->mode = WlanIfaceOperatingModeType_station; - - if (wlan_add_wif(wif) < 0) { - free(wif); - return (NULL); - } - - return (wif); -} - -static void -wlan_delete_wif(struct wlan_iface *wif) -{ - SLIST_REMOVE(&wlan_ifaces, wif, wlan_iface, w_if); - wlan_free_interface(wif); -} - -static int -wlan_attach_newif(struct mibif *mif) -{ - struct wlan_iface *wif; - - if (mif->mib.ifmd_data.ifi_type != IFT_ETHER || - wlan_check_media(mif->name) != IFM_IEEE80211) - return (0); - - if ((wif = wlan_new_wif(mif->name)) == NULL) - return (-1); - - (void)wlan_get_opmode(wif); - wif->index = mif->index; - wif->status = RowStatus_active; - (void)wlan_update_interface(wif); - - return (0); -} - -static int -wlan_iface_create(struct wlan_iface *wif) -{ - int rc; - - if ((rc = wlan_clone_create(wif)) == SNMP_ERR_NOERROR) { - /* - * The rest of the info will be updated once the - * snmp_mibII module notifies us of the interface. - */ - wif->status = RowStatus_active; - if (wif->state == wlanIfaceState_up) - (void)wlan_config_state(wif, 1); - } - - return (rc); -} - -static int -wlan_iface_destroy(struct wlan_iface *wif) -{ - int rc = SNMP_ERR_NOERROR; - - if (wif->internal == 0) - rc = wlan_clone_destroy(wif); - - if (rc == SNMP_ERR_NOERROR) - wlan_delete_wif(wif); - - return (rc); -} - -static int -wlan_update_interface(struct wlan_iface *wif) -{ - int i; - - (void)wlan_config_state(wif, 0); - (void)wlan_get_driver_caps(wif); - for (i = LEAF_wlanIfacePacketBurst; - i <= LEAF_wlanIfaceTdmaBeaconInterval; i++) - (void)wlan_config_get_ioctl(wif, i); - (void)wlan_get_stats(wif); - /* - * XXX: wlan_get_channel_list() not needed - - * fetched with wlan_get_driver_caps() - */ - (void)wlan_get_channel_list(wif); - (void)wlan_get_roam_params(wif); - (void)wlan_get_tx_params(wif); - (void)wlan_get_scan_results(wif); - (void)wlan_get_wepmode(wif); - (void)wlan_get_weptxkey(wif); - (void)wlan_get_mac_policy(wif); - (void)wlan_get_mac_acl_macs(wif); - (void)wlan_get_peerinfo(wif); - - if (wif->mode == WlanIfaceOperatingModeType_meshPoint) { - for (i = LEAF_wlanMeshTTL; i <= LEAF_wlanMeshPath; i++) - (void)wlan_mesh_config_get(wif, i); - (void)wlan_mesh_get_routelist(wif); - for (i = LEAF_wlanHWMPRootMode; i <= LEAF_wlanHWMPMaxHops; i++) - (void)wlan_hwmp_config_get(wif, i); - } - - return (0); -} - -static void -wlan_update_interface_list(void) -{ - struct wlan_iface *wif, *twif; - - if ((time(NULL) - wlan_iflist_age) <= WLAN_LIST_MAXAGE) - return; - - /* - * The snmp_mibII module would have notified us for new interfaces, - * so only check if any have been deleted. - */ - SLIST_FOREACH_SAFE(wif, &wlan_ifaces, w_if, twif) - if (wif->status == RowStatus_active && wlan_get_opmode(wif) < 0) - wlan_delete_wif(wif); - - wlan_iflist_age = time(NULL); -} - -static void -wlan_append_ifindex(struct asn_oid *oid, uint sub, const struct wlan_iface *w) -{ - uint32_t i; - - oid->len = sub + strlen(w->wname) + 1; - oid->subs[sub] = strlen(w->wname); - for (i = 1; i <= strlen(w->wname); i++) - oid->subs[sub + i] = w->wname[i - 1]; -} - -static uint8_t * -wlan_get_ifname(const struct asn_oid *oid, uint sub, uint8_t *wname) -{ - uint32_t i; - - memset(wname, 0, IFNAMSIZ); - - if (oid->len - sub != oid->subs[sub] + 1 || oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[i] = '\0'; - - return (wname); -} - -static struct wlan_iface * -wlan_get_interface(const struct asn_oid *oid, uint sub) -{ - uint8_t wname[IFNAMSIZ]; - - if (wlan_get_ifname(oid, sub, wname) == NULL) - return (NULL); - - return (wlan_find_interface(wname)); -} - -static struct wlan_iface * -wlan_get_next_interface(const struct asn_oid *oid, uint sub) -{ - uint32_t i; - uint8_t wname[IFNAMSIZ]; - struct wlan_iface *wif; - - if (oid->len - sub == 0) { - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) - if (wif->status == RowStatus_active) - break; - return (wif); - } - - if (oid->len - sub != oid->subs[sub] + 1 || oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - memset(wname, 0, IFNAMSIZ); - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[i] = '\0'; - if ((wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - while ((wif = wlan_next_interface(wif)) != NULL) - if (wif->status == RowStatus_active) - break; - - return (wif); -} - -static struct wlan_iface * -wlan_get_snmp_interface(const struct asn_oid *oid, uint sub) -{ - uint8_t wname[IFNAMSIZ]; - struct wlan_iface *wif; - - if (wlan_get_ifname(oid, sub, wname) == NULL) - return (NULL); - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) - if (strcmp(wif->wname, wname) == 0) - break; - - return (wif); -} - -static struct wlan_iface * -wlan_get_next_snmp_interface(const struct asn_oid *oid, uint sub) -{ - uint32_t i; - uint8_t wname[IFNAMSIZ]; - struct wlan_iface *wif; - - if (oid->len - sub == 0) - return (wlan_first_interface()); - - if (oid->len - sub != oid->subs[sub] + 1 || oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - memset(wname, 0, IFNAMSIZ); - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[i] = '\0'; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) - if (strcmp(wif->wname, wname) == 0) - break; - - return (wlan_next_interface(wif)); -} - -/* - * Decode/Append an index for tables indexed by the wireless interface - * name and a MAC address - ACL MACs and Mesh Routes. - */ -static int -wlan_mac_index_decode(const struct asn_oid *oid, uint sub, - char *wname, uint8_t *mac) -{ - uint32_t i; - int mac_off; - - if (oid->len - sub != oid->subs[sub] + 2 + IEEE80211_ADDR_LEN - || oid->subs[sub] >= IFNAMSIZ) - return (-1); - - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[i] = '\0'; - - mac_off = sub + oid->subs[sub] + 1; - if (oid->subs[mac_off] != IEEE80211_ADDR_LEN) - return (-1); - for (i = 0; i < IEEE80211_ADDR_LEN; i++) - mac[i] = oid->subs[mac_off + i + 1]; - - return (0); -} - -static void -wlan_append_mac_index(struct asn_oid *oid, uint sub, char *wname, uint8_t *mac) -{ - uint32_t i; - - oid->len = sub + strlen(wname) + IEEE80211_ADDR_LEN + 2; - oid->subs[sub] = strlen(wname); - for (i = 1; i <= strlen(wname); i++) - oid->subs[sub + i] = wname[i - 1]; - - sub += strlen(wname) + 1; - oid->subs[sub] = IEEE80211_ADDR_LEN; - for (i = 1; i <= IEEE80211_ADDR_LEN; i++) - oid->subs[sub + i] = mac[i - 1]; -} - -/* - * Decode/Append an index for tables indexed by the wireless interface - * name and the PHY mode - Roam and TX params. - */ -static int -wlan_phy_index_decode(const struct asn_oid *oid, uint sub, char *wname, - uint32_t *phy) -{ - uint32_t i; - - if (oid->len - sub != oid->subs[sub] + 2 || oid->subs[sub] >= IFNAMSIZ) - return (-1); - - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[i] = '\0'; - - *phy = oid->subs[sub + oid->subs[sub] + 1]; - return (0); -} - -static void -wlan_append_phy_index(struct asn_oid *oid, uint sub, char *wname, uint32_t phy) -{ - uint32_t i; - - oid->len = sub + strlen(wname) + 2; - oid->subs[sub] = strlen(wname); - for (i = 1; i <= strlen(wname); i++) - oid->subs[sub + i] = wname[i - 1]; - oid->subs[sub + strlen(wname) + 1] = phy; -} - -/* - * Calls for manipulating the peerlist of a wireless interface. - */ -static void -wlan_free_peerlist(struct wlan_iface *wif) -{ - struct wlan_peer *wip; - - while ((wip = SLIST_FIRST(&wif->peerlist)) != NULL) { - SLIST_REMOVE_HEAD(&wif->peerlist, wp); - free(wip); - } - - SLIST_INIT(&wif->peerlist); -} - -static struct wlan_peer * -wlan_find_peer(struct wlan_iface *wif, uint8_t *peermac) -{ - struct wlan_peer *wip; - - SLIST_FOREACH(wip, &wif->peerlist, wp) - if (memcmp(wip->pmac, peermac, IEEE80211_ADDR_LEN) == 0) - break; - - return (wip); -} - -struct wlan_peer * -wlan_new_peer(const uint8_t *pmac) -{ - struct wlan_peer *wip; - - if ((wip = (struct wlan_peer *)malloc(sizeof(*wip))) == NULL) - return (NULL); - - memset(wip, 0, sizeof(struct wlan_peer)); - memcpy(wip->pmac, pmac, IEEE80211_ADDR_LEN); - - return (wip); -} - -void -wlan_free_peer(struct wlan_peer *wip) -{ - free(wip); -} - -int -wlan_add_peer(struct wlan_iface *wif, struct wlan_peer *wip) -{ - struct wlan_peer *temp, *prev; - - SLIST_FOREACH(temp, &wif->peerlist, wp) - if (memcmp(temp->pmac, wip->pmac, IEEE80211_ADDR_LEN) == 0) - return (-1); - - if ((prev = SLIST_FIRST(&wif->peerlist)) == NULL || - memcmp(wip->pmac, prev->pmac, IEEE80211_ADDR_LEN) < 0) { - SLIST_INSERT_HEAD(&wif->peerlist, wip, wp); - return (0); - } - - SLIST_FOREACH(temp, &wif->peerlist, wp) { - if (memcmp(wip->pmac, temp->pmac, IEEE80211_ADDR_LEN) < 0) - break; - prev = temp; - } - - SLIST_INSERT_AFTER(prev, wip, wp); - return (0); -} - -static void -wlan_update_peers(void) -{ - struct wlan_iface *wif; - - if ((time(NULL) - wlan_peerlist_age) <= WLAN_LIST_MAXAGE) - return; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) { - if (wif->status != RowStatus_active) - continue; - wlan_free_peerlist(wif); - (void)wlan_get_peerinfo(wif); - } - wlan_peerlist_age = time(NULL); -} - -static struct wlan_peer * -wlan_get_peer(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - uint8_t pmac[IEEE80211_ADDR_LEN]; - - if (wlan_mac_index_decode(oid, sub, wname, pmac) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - return (wlan_find_peer(*wif, pmac)); -} - -static struct wlan_peer * -wlan_get_next_peer(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - char pmac[IEEE80211_ADDR_LEN]; - struct wlan_peer *wip; - - if (oid->len - sub == 0) { - for (*wif = wlan_first_interface(); *wif != NULL; - *wif = wlan_next_interface(*wif)) { - if ((*wif)->mode == - WlanIfaceOperatingModeType_meshPoint) - continue; - wip = SLIST_FIRST(&(*wif)->peerlist); - if (wip != NULL) - return (wip); - } - return (NULL); - } - - if (wlan_mac_index_decode(oid, sub, wname, pmac) < 0 || - (*wif = wlan_find_interface(wname)) == NULL || - (wip = wlan_find_peer(*wif, pmac)) == NULL) - return (NULL); - - if ((wip = SLIST_NEXT(wip, wp)) != NULL) - return (wip); - - while ((*wif = wlan_next_interface(*wif)) != NULL) { - if ((*wif)->mode == WlanIfaceOperatingModeType_meshPoint) - continue; - if ((wip = SLIST_FIRST(&(*wif)->peerlist)) != NULL) - break; - } - - return (wip); -} - -/* - * Calls for manipulating the active channel list of a wireless interface. - */ -static void -wlan_update_channels(void) -{ - struct wlan_iface *wif; - - if ((time(NULL) - wlan_chanlist_age) <= WLAN_LIST_MAXAGE) - return; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) { - if (wif->status != RowStatus_active) - continue; - (void)wlan_get_channel_list(wif); - } - wlan_chanlist_age = time(NULL); -} - -static int -wlan_channel_index_decode(const struct asn_oid *oid, uint sub, char *wname, - uint32_t *cindex) -{ - uint32_t i; - if (oid->len - sub != oid->subs[sub] + 2 || oid->subs[sub] >= IFNAMSIZ) - return (-1); - - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[i] = '\0'; - - *cindex = oid->subs[sub + oid->subs[sub] + 1]; - - return (0); -} - -static void -wlan_append_channel_index(struct asn_oid *oid, uint sub, - const struct wlan_iface *wif, const struct ieee80211_channel *channel) -{ - uint32_t i; - - oid->len = sub + strlen(wif->wname) + 2; - oid->subs[sub] = strlen(wif->wname); - for (i = 1; i <= strlen(wif->wname); i++) - oid->subs[sub + i] = wif->wname[i - 1]; - oid->subs[sub + strlen(wif->wname) + 1] = (channel - wif->chanlist) + 1; -} - -static int32_t -wlan_get_channel_type(struct ieee80211_channel *c) -{ - if (IEEE80211_IS_CHAN_FHSS(c)) - return (WlanChannelType_fhss); - if (IEEE80211_IS_CHAN_A(c)) - return (WlanChannelType_dot11a); - if (IEEE80211_IS_CHAN_B(c)) - return (WlanChannelType_dot11b); - if (IEEE80211_IS_CHAN_ANYG(c)) - return (WlanChannelType_dot11g); - if (IEEE80211_IS_CHAN_HALF(c)) - return (WlanChannelType_tenMHz); - if (IEEE80211_IS_CHAN_QUARTER(c)) - return (WlanChannelType_fiveMHz); - if (IEEE80211_IS_CHAN_TURBO(c)) - return (WlanChannelType_turbo); - if (IEEE80211_IS_CHAN_HT(c)) - return (WlanChannelType_ht); - - return (-1); -} - -static struct ieee80211_channel * -wlan_find_channel(struct wlan_iface *wif, uint32_t cindex) -{ - if (wif->chanlist == NULL || cindex > wif->nchannels) - return (NULL); - - return (wif->chanlist + cindex - 1); -} - -static struct ieee80211_channel * -wlan_get_channel(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - uint32_t cindex; - char wname[IFNAMSIZ]; - - if (wlan_channel_index_decode(oid, sub, wname, &cindex) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - return (wlan_find_channel(*wif, cindex)); -} - -static struct ieee80211_channel * -wlan_get_next_channel(const struct asn_oid *oid, uint sub, - struct wlan_iface **wif) -{ - uint32_t cindex; - char wname[IFNAMSIZ]; - - if (oid->len - sub == 0) { - for (*wif = wlan_first_interface(); *wif != NULL; - *wif = wlan_next_interface(*wif)) { - if ((*wif)->status != RowStatus_active) - continue; - if ((*wif)->nchannels != 0 && (*wif)->chanlist != NULL) - return ((*wif)->chanlist); - } - return (NULL); - } - - if (wlan_channel_index_decode(oid, sub, wname, &cindex) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - if (cindex < (*wif)->nchannels) - return ((*wif)->chanlist + cindex); - - while ((*wif = wlan_next_interface(*wif)) != NULL) - if ((*wif)->status == RowStatus_active) - if ((*wif)->nchannels != 0 && (*wif)->chanlist != NULL) - return ((*wif)->chanlist); - - return (NULL); -} - -/* - * Calls for manipulating the roam params of a wireless interface. - */ -static void -wlan_update_roam_params(void) -{ - struct wlan_iface *wif; - - if ((time(NULL) - wlan_roamlist_age) <= WLAN_LIST_MAXAGE) - return; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) { - if (wif->status != RowStatus_active) - continue; - (void)wlan_get_roam_params(wif); - } - wlan_roamlist_age = time(NULL); -} - -static struct ieee80211_roamparam * -wlan_get_roam_param(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - uint32_t phy; - char wname[IFNAMSIZ]; - - if (wlan_phy_index_decode(oid, sub, wname, &phy) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - if (phy == 0 || phy > IEEE80211_MODE_MAX) - return (NULL); - - return ((*wif)->roamparams.params + phy - 1); -} - -static struct ieee80211_roamparam * -wlan_get_next_roam_param(const struct asn_oid *oid, uint sub, - struct wlan_iface **wif, uint32_t *phy) -{ - char wname[IFNAMSIZ]; - - if (oid->len - sub == 0) { - for (*wif = wlan_first_interface(); *wif != NULL; - *wif = wlan_next_interface(*wif)) { - if ((*wif)->status != RowStatus_active) - continue; - *phy = 1; - return ((*wif)->roamparams.params); - } - return (NULL); - } - - if (wlan_phy_index_decode(oid, sub, wname, phy) < 0) - return (NULL); - - if (*phy == 0 || (*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - if (++(*phy) <= IEEE80211_MODE_MAX) - return ((*wif)->roamparams.params + *phy - 1); - - *phy = 1; - while ((*wif = wlan_next_interface(*wif)) != NULL) - if ((*wif)->status == RowStatus_active) - return ((*wif)->roamparams.params); - - return (NULL); -} - -/* - * Calls for manipulating the tx params of a wireless interface. - */ -static void -wlan_update_tx_params(void) -{ - struct wlan_iface *wif; - - if ((time(NULL) - wlan_tx_paramlist_age) <= WLAN_LIST_MAXAGE) - return; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) { - if (wif->status != RowStatus_active) - continue; - (void)wlan_get_tx_params(wif); - } - - wlan_tx_paramlist_age = time(NULL); -} - -static struct ieee80211_txparam * -wlan_get_tx_param(const struct asn_oid *oid, uint sub, struct wlan_iface **wif, - uint32_t *phy) -{ - char wname[IFNAMSIZ]; - - if (wlan_phy_index_decode(oid, sub, wname, phy) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - if (*phy == 0 || *phy > IEEE80211_MODE_MAX) - return (NULL); - - return ((*wif)->txparams.params + *phy - 1); -} - -static struct ieee80211_txparam * -wlan_get_next_tx_param(const struct asn_oid *oid, uint sub, - struct wlan_iface **wif, uint32_t *phy) -{ - char wname[IFNAMSIZ]; - - if (oid->len - sub == 0) { - for (*wif = wlan_first_interface(); *wif != NULL; - *wif = wlan_next_interface(*wif)) { - if ((*wif)->status != RowStatus_active) - continue; - *phy = 1; - return ((*wif)->txparams.params); - } - return (NULL); - } - - if (wlan_phy_index_decode(oid, sub, wname, phy) < 0) - return (NULL); - - if (*phy == 0 || (*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - if (++(*phy) <= IEEE80211_MODE_MAX) - return ((*wif)->txparams.params + *phy - 1); - - *phy = 1; - while ((*wif = wlan_next_interface(*wif)) != NULL) - if ((*wif)->status == RowStatus_active) - return ((*wif)->txparams.params); - - return (NULL); -} - -/* - * Calls for manipulating the scan results for a wireless interface. - */ -static void -wlan_scan_free_results(struct wlan_iface *wif) -{ - struct wlan_scan_result *sr; - - while ((sr = SLIST_FIRST(&wif->scanlist)) != NULL) { - SLIST_REMOVE_HEAD(&wif->scanlist, wsr); - free(sr); - } - - SLIST_INIT(&wif->scanlist); -} - -static struct wlan_scan_result * -wlan_scan_find_result(struct wlan_iface *wif, uint8_t *ssid, uint8_t *bssid) -{ - struct wlan_scan_result *sr; - - SLIST_FOREACH(sr, &wif->scanlist, wsr) - if (strlen(ssid) == strlen(sr->ssid) && - strcmp(sr->ssid, ssid) == 0 && - memcmp(sr->bssid, bssid, IEEE80211_ADDR_LEN) == 0) - break; - - return (sr); -} - -struct wlan_scan_result * -wlan_scan_new_result(const uint8_t *ssid, const uint8_t *bssid) -{ - struct wlan_scan_result *sr; - - sr = (struct wlan_scan_result *)malloc(sizeof(*sr)); - if (sr == NULL) - return (NULL); - - memset(sr, 0, sizeof(*sr)); - if (ssid[0] != '\0') - strlcpy(sr->ssid, ssid, IEEE80211_NWID_LEN + 1); - memcpy(sr->bssid, bssid, IEEE80211_ADDR_LEN); - - return (sr); -} - -void -wlan_scan_free_result(struct wlan_scan_result *sr) -{ - free(sr); -} - -static int -wlan_scan_compare_result(struct wlan_scan_result *sr1, - struct wlan_scan_result *sr2) -{ - uint32_t i; - - if (strlen(sr1->ssid) < strlen(sr2->ssid)) - return (-1); - if (strlen(sr1->ssid) > strlen(sr2->ssid)) - return (1); - - for (i = 0; i < strlen(sr1->ssid) && i < strlen(sr2->ssid); i++) { - if (sr1->ssid[i] < sr2->ssid[i]) - return (-1); - if (sr1->ssid[i] > sr2->ssid[i]) - return (1); - } - - for (i = 0; i < IEEE80211_ADDR_LEN; i++) { - if (sr1->bssid[i] < sr2->bssid[i]) - return (-1); - if (sr1->bssid[i] > sr2->bssid[i]) - return (1); - } - - return (0); -} - -int -wlan_scan_add_result(struct wlan_iface *wif, struct wlan_scan_result *sr) -{ - struct wlan_scan_result *prev, *temp; - - SLIST_FOREACH(temp, &wif->scanlist, wsr) - if (strlen(temp->ssid) == strlen(sr->ssid) && - strcmp(sr->ssid, temp->ssid) == 0 && - memcmp(sr->bssid, temp->bssid, IEEE80211_ADDR_LEN) == 0) - return (-1); - - if ((prev = SLIST_FIRST(&wif->scanlist)) == NULL || - wlan_scan_compare_result(sr, prev) < 0) { - SLIST_INSERT_HEAD(&wif->scanlist, sr, wsr); - return (0); - } - - SLIST_FOREACH(temp, &wif->scanlist, wsr) { - if (wlan_scan_compare_result(sr, temp) < 0) - break; - prev = temp; - } - - SLIST_INSERT_AFTER(prev, sr, wsr); - return (0); -} - -static void -wlan_scan_update_results(void) -{ - struct wlan_iface *wif; - - if ((time(NULL) - wlan_scanlist_age) <= WLAN_LIST_MAXAGE) - return; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) { - if (wif->status != RowStatus_active) - continue; - wlan_scan_free_results(wif); - (void)wlan_get_scan_results(wif); - } - wlan_scanlist_age = time(NULL); -} - -static int -wlan_scanr_index_decode(const struct asn_oid *oid, uint sub, - char *wname, uint8_t *ssid, uint8_t *bssid) -{ - uint32_t i; - int offset; - - if (oid->subs[sub] >= IFNAMSIZ) - return (-1); - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[oid->subs[sub]] = '\0'; - - offset = sub + oid->subs[sub] + 1; - if (oid->subs[offset] > IEEE80211_NWID_LEN) - return (-1); - for (i = 0; i < oid->subs[offset]; i++) - ssid[i] = oid->subs[offset + i + 1]; - ssid[i] = '\0'; - - offset = sub + oid->subs[sub] + oid->subs[offset] + 2; - if (oid->subs[offset] != IEEE80211_ADDR_LEN) - return (-1); - for (i = 0; i < IEEE80211_ADDR_LEN; i++) - bssid[i] = oid->subs[offset + i + 1]; - - return (0); -} - -static void -wlan_append_scanr_index(struct asn_oid *oid, uint sub, char *wname, - uint8_t *ssid, uint8_t *bssid) -{ - uint32_t i; - - oid->len = sub + strlen(wname) + strlen(ssid) + IEEE80211_ADDR_LEN + 3; - oid->subs[sub] = strlen(wname); - for (i = 1; i <= strlen(wname); i++) - oid->subs[sub + i] = wname[i - 1]; - - sub += strlen(wname) + 1; - oid->subs[sub] = strlen(ssid); - for (i = 1; i <= strlen(ssid); i++) - oid->subs[sub + i] = ssid[i - 1]; - - sub += strlen(ssid) + 1; - oid->subs[sub] = IEEE80211_ADDR_LEN; - for (i = 1; i <= IEEE80211_ADDR_LEN; i++) - oid->subs[sub + i] = bssid[i - 1]; -} - -static struct wlan_scan_result * -wlan_get_scanr(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - uint8_t ssid[IEEE80211_NWID_LEN + 1]; - uint8_t bssid[IEEE80211_ADDR_LEN]; - - if (wlan_scanr_index_decode(oid, sub, wname, ssid, bssid) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - return (wlan_scan_find_result(*wif, ssid, bssid)); -} - -static struct wlan_scan_result * -wlan_get_next_scanr(const struct asn_oid *oid, uint sub, - struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - uint8_t ssid[IEEE80211_NWID_LEN + 1]; - uint8_t bssid[IEEE80211_ADDR_LEN]; - struct wlan_scan_result *sr; - - if (oid->len - sub == 0) { - for (*wif = wlan_first_interface(); *wif != NULL; - *wif = wlan_next_interface(*wif)) { - sr = SLIST_FIRST(&(*wif)->scanlist); - if (sr != NULL) - return (sr); - } - return (NULL); - } - - if (wlan_scanr_index_decode(oid, sub, wname, ssid, bssid) < 0 || - (*wif = wlan_find_interface(wname)) == NULL || - (sr = wlan_scan_find_result(*wif, ssid, bssid)) == NULL) - return (NULL); - - if ((sr = SLIST_NEXT(sr, wsr)) != NULL) - return (sr); - - while ((*wif = wlan_next_interface(*wif)) != NULL) - if ((sr = SLIST_FIRST(&(*wif)->scanlist)) != NULL) - break; - - return (sr); -} - -/* - * MAC Access Control. - */ -static void -wlan_mac_free_maclist(struct wlan_iface *wif) -{ - struct wlan_mac_mac *wmm; - - while ((wmm = SLIST_FIRST(&wif->mac_maclist)) != NULL) { - SLIST_REMOVE_HEAD(&wif->mac_maclist, wm); - free(wmm); - } - - SLIST_INIT(&wif->mac_maclist); -} - -static struct wlan_mac_mac * -wlan_mac_find_mac(struct wlan_iface *wif, uint8_t *mac) -{ - struct wlan_mac_mac *wmm; - - SLIST_FOREACH(wmm, &wif->mac_maclist, wm) - if (memcmp(wmm->mac, mac, IEEE80211_ADDR_LEN) == 0) - break; - - return (wmm); -} - -struct wlan_mac_mac * -wlan_mac_new_mac(const uint8_t *mac) -{ - struct wlan_mac_mac *wmm; - - if ((wmm = (struct wlan_mac_mac *)malloc(sizeof(*wmm))) == NULL) - return (NULL); - - memset(wmm, 0, sizeof(*wmm)); - memcpy(wmm->mac, mac, IEEE80211_ADDR_LEN); - wmm->mac_status = RowStatus_notReady; - - return (wmm); -} - -void -wlan_mac_free_mac(struct wlan_mac_mac *wmm) -{ - free(wmm); -} - -int -wlan_mac_add_mac(struct wlan_iface *wif, struct wlan_mac_mac *wmm) -{ - struct wlan_mac_mac *temp, *prev; - - SLIST_FOREACH(temp, &wif->mac_maclist, wm) - if (memcmp(temp->mac, wmm->mac, IEEE80211_ADDR_LEN) == 0) - return (-1); - - if ((prev = SLIST_FIRST(&wif->mac_maclist)) == NULL || - memcmp(wmm->mac, prev->mac,IEEE80211_ADDR_LEN) < 0) { - SLIST_INSERT_HEAD(&wif->mac_maclist, wmm, wm); - return (0); - } - - SLIST_FOREACH(temp, &wif->mac_maclist, wm) { - if (memcmp(wmm->mac, temp->mac, IEEE80211_ADDR_LEN) < 0) - break; - prev = temp; - } - - SLIST_INSERT_AFTER(prev, wmm, wm); - return (0); -} - -static int -wlan_mac_delete_mac(struct wlan_iface *wif, struct wlan_mac_mac *wmm) -{ - if (wmm->mac_status == RowStatus_active && - wlan_del_mac_acl_mac(wif, wmm) < 0) - return (-1); - - SLIST_REMOVE(&wif->mac_maclist, wmm, wlan_mac_mac, wm); - free(wmm); - - return (0); -} - -static void -wlan_mac_update_aclmacs(void) -{ - struct wlan_iface *wif; - struct wlan_mac_mac *wmm, *twmm; - - if ((time(NULL) - wlan_maclist_age) <= WLAN_LIST_MAXAGE) - return; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) { - if (wif->status != RowStatus_active) - continue; - /* - * Nuke old entries - XXX - they are likely not to - * change often - reconsider. - */ - SLIST_FOREACH_SAFE(wmm, &wif->mac_maclist, wm, twmm) - if (wmm->mac_status == RowStatus_active) { - SLIST_REMOVE(&wif->mac_maclist, wmm, - wlan_mac_mac, wm); - wlan_mac_free_mac(wmm); - } - (void)wlan_get_mac_acl_macs(wif); - } - wlan_maclist_age = time(NULL); -} - -static struct wlan_mac_mac * -wlan_get_acl_mac(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - char mac[IEEE80211_ADDR_LEN]; - - if (wlan_mac_index_decode(oid, sub, wname, mac) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - return (wlan_mac_find_mac(*wif, mac)); -} - -static struct wlan_mac_mac * -wlan_get_next_acl_mac(const struct asn_oid *oid, uint sub, - struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - char mac[IEEE80211_ADDR_LEN]; - struct wlan_mac_mac *wmm; - - if (oid->len - sub == 0) { - for (*wif = wlan_first_interface(); *wif != NULL; - *wif = wlan_next_interface(*wif)) { - wmm = SLIST_FIRST(&(*wif)->mac_maclist); - if (wmm != NULL) - return (wmm); - } - return (NULL); - } - - if (wlan_mac_index_decode(oid, sub, wname, mac) < 0 || - (*wif = wlan_find_interface(wname)) == NULL || - (wmm = wlan_mac_find_mac(*wif, mac)) == NULL) - return (NULL); - - if ((wmm = SLIST_NEXT(wmm, wm)) != NULL) - return (wmm); - - while ((*wif = wlan_next_interface(*wif)) != NULL) - if ((wmm = SLIST_FIRST(&(*wif)->mac_maclist)) != NULL) - break; - - return (wmm); -} - -static int -wlan_acl_mac_set_status(struct snmp_context *ctx, struct snmp_value *val, - uint sub) -{ - char wname[IFNAMSIZ]; - uint8_t mac[IEEE80211_ADDR_LEN]; - struct wlan_iface *wif; - struct wlan_mac_mac *macl; - - if (wlan_mac_index_decode(&val->var, sub, wname, mac) < 0) - return (SNMP_ERR_GENERR); - macl = wlan_get_acl_mac(&val->var, sub, &wif); - - switch (val->v.integer) { - case RowStatus_createAndGo: - if (macl != NULL) - return (SNMP_ERR_INCONS_NAME); - break; - case RowStatus_destroy: - if (macl == NULL) - return (SNMP_ERR_NOSUCHNAME); - ctx->scratch->int1 = RowStatus_active; - return (SNMP_ERR_NOERROR); - default: - return (SNMP_ERR_INCONS_VALUE); - } - - - if (wif == NULL || !wif->macsupported) - return (SNMP_ERR_INCONS_VALUE); - - if ((macl = wlan_mac_new_mac((const uint8_t *)mac)) == NULL) - return (SNMP_ERR_GENERR); - - ctx->scratch->int1 = RowStatus_destroy; - - if (wlan_mac_add_mac(wif, macl) < 0) { - wlan_mac_free_mac(macl); - return (SNMP_ERR_GENERR); - } - - ctx->scratch->int1 = RowStatus_destroy; - if (wlan_add_mac_acl_mac(wif, macl) < 0) { - (void)wlan_mac_delete_mac(wif, macl); - return (SNMP_ERR_GENERR); - } - - return (SNMP_ERR_NOERROR); -} - -/* - * Wireless interfaces operating as mesh points. - */ -static struct wlan_iface * -wlan_mesh_first_interface(void) -{ - struct wlan_iface *wif; - - SLIST_FOREACH(wif, &wlan_ifaces, w_if) - if (wif->mode == WlanIfaceOperatingModeType_meshPoint && - wif->status == RowStatus_active) - break; - - return (wif); -} - -static struct wlan_iface * -wlan_mesh_next_interface(struct wlan_iface *wif) -{ - struct wlan_iface *nwif; - - while ((nwif = wlan_next_interface(wif)) != NULL) { - if (nwif->mode == WlanIfaceOperatingModeType_meshPoint && - nwif->status == RowStatus_active) - break; - wif = nwif; - } - - return (nwif); -} - -static struct wlan_iface * -wlan_mesh_get_iface(const struct asn_oid *oid, uint sub) -{ - struct wlan_iface *wif; - - if ((wif = wlan_get_interface(oid, sub)) == NULL) - return (NULL); - - if (wif->mode != WlanIfaceOperatingModeType_meshPoint) - return (NULL); - - return (wif); -} - -static struct wlan_iface * -wlan_mesh_get_next_iface(const struct asn_oid *oid, uint sub) -{ - uint32_t i; - uint8_t wname[IFNAMSIZ]; - struct wlan_iface *wif; - - if (oid->len - sub == 0) - return (wlan_mesh_first_interface()); - - if (oid->len - sub != oid->subs[sub] + 1 || oid->subs[sub] >= IFNAMSIZ) - return (NULL); - - memset(wname, 0, IFNAMSIZ); - for (i = 0; i < oid->subs[sub]; i++) - wname[i] = oid->subs[sub + i + 1]; - wname[i] = '\0'; - - if ((wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - return (wlan_mesh_next_interface(wif)); -} - -/* - * The neighbors of wireless interfaces operating as mesh points. - */ -static struct wlan_peer * -wlan_mesh_get_peer(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - uint8_t pmac[IEEE80211_ADDR_LEN]; - - if (wlan_mac_index_decode(oid, sub, wname, pmac) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL || - (*wif)->mode != WlanIfaceOperatingModeType_meshPoint) - return (NULL); - - return (wlan_find_peer(*wif, pmac)); -} - -static struct wlan_peer * -wlan_mesh_get_next_peer(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - char pmac[IEEE80211_ADDR_LEN]; - struct wlan_peer *wip; - - if (oid->len - sub == 0) { - for (*wif = wlan_mesh_first_interface(); *wif != NULL; - *wif = wlan_mesh_next_interface(*wif)) { - wip = SLIST_FIRST(&(*wif)->peerlist); - if (wip != NULL) - return (wip); - } - return (NULL); - } - - if (wlan_mac_index_decode(oid, sub, wname, pmac) < 0 || - (*wif = wlan_find_interface(wname)) == NULL || - (*wif)->mode != WlanIfaceOperatingModeType_meshPoint || - (wip = wlan_find_peer(*wif, pmac)) == NULL) - return (NULL); - - if ((wip = SLIST_NEXT(wip, wp)) != NULL) - return (wip); - - while ((*wif = wlan_mesh_next_interface(*wif)) != NULL) - if ((wip = SLIST_FIRST(&(*wif)->peerlist)) != NULL) - break; - - return (wip); -} - -/* - * Mesh routing table. - */ -static void -wlan_mesh_free_routes(struct wlan_iface *wif) -{ - struct wlan_mesh_route *wmr; - - while ((wmr = SLIST_FIRST(&wif->mesh_routelist)) != NULL) { - SLIST_REMOVE_HEAD(&wif->mesh_routelist, wr); - free(wmr); - } - - SLIST_INIT(&wif->mesh_routelist); -} - -static struct wlan_mesh_route * -wlan_mesh_find_route(struct wlan_iface *wif, uint8_t *dstmac) -{ - struct wlan_mesh_route *wmr; - - if (wif->mode != WlanIfaceOperatingModeType_meshPoint) - return (NULL); - - SLIST_FOREACH(wmr, &wif->mesh_routelist, wr) - if (memcmp(wmr->imroute.imr_dest, dstmac, - IEEE80211_ADDR_LEN) == 0) - break; - - return (wmr); -} - -struct wlan_mesh_route * -wlan_mesh_new_route(const uint8_t *dstmac) -{ - struct wlan_mesh_route *wmr; - - if ((wmr = (struct wlan_mesh_route *)malloc(sizeof(*wmr))) == NULL) - return (NULL); - - memset(wmr, 0, sizeof(*wmr)); - memcpy(wmr->imroute.imr_dest, dstmac, IEEE80211_ADDR_LEN); - wmr->mroute_status = RowStatus_notReady; - - return (wmr); -} - -void -wlan_mesh_free_route(struct wlan_mesh_route *wmr) -{ - free(wmr); -} - -int -wlan_mesh_add_rtentry(struct wlan_iface *wif, struct wlan_mesh_route *wmr) -{ - struct wlan_mesh_route *temp, *prev; - - SLIST_FOREACH(temp, &wif->mesh_routelist, wr) - if (memcmp(temp->imroute.imr_dest, wmr->imroute.imr_dest, - IEEE80211_ADDR_LEN) == 0) - return (-1); - - if ((prev = SLIST_FIRST(&wif->mesh_routelist)) == NULL || - memcmp(wmr->imroute.imr_dest, prev->imroute.imr_dest, - IEEE80211_ADDR_LEN) < 0) { - SLIST_INSERT_HEAD(&wif->mesh_routelist, wmr, wr); - return (0); - } - - SLIST_FOREACH(temp, &wif->mesh_routelist, wr) { - if (memcmp(wmr->imroute.imr_dest, temp->imroute.imr_dest, - IEEE80211_ADDR_LEN) < 0) - break; - prev = temp; - } - - SLIST_INSERT_AFTER(prev, wmr, wr); - return (0); -} - -static int -wlan_mesh_delete_route(struct wlan_iface *wif, struct wlan_mesh_route *wmr) -{ - if (wmr->mroute_status == RowStatus_active && - wlan_mesh_del_route(wif, wmr) < 0) - return (-1); - - SLIST_REMOVE(&wif->mesh_routelist, wmr, wlan_mesh_route, wr); - free(wmr); - - return (0); -} - -static void -wlan_mesh_update_routes(void) -{ - struct wlan_iface *wif; - struct wlan_mesh_route *wmr, *twmr; - - if ((time(NULL) - wlan_mrlist_age) <= WLAN_LIST_MAXAGE) - return; - - for (wif = wlan_mesh_first_interface(); wif != NULL; - wif = wlan_mesh_next_interface(wif)) { - /* - * Nuke old entries - XXX - they are likely not to - * change often - reconsider. - */ - SLIST_FOREACH_SAFE(wmr, &wif->mesh_routelist, wr, twmr) - if (wmr->mroute_status == RowStatus_active) { - SLIST_REMOVE(&wif->mesh_routelist, wmr, - wlan_mesh_route, wr); - wlan_mesh_free_route(wmr); - } - (void)wlan_mesh_get_routelist(wif); - } - wlan_mrlist_age = time(NULL); -} - -static struct wlan_mesh_route * -wlan_mesh_get_route(const struct asn_oid *oid, uint sub, struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - char dstmac[IEEE80211_ADDR_LEN]; - - if (wlan_mac_index_decode(oid, sub, wname, dstmac) < 0) - return (NULL); - - if ((*wif = wlan_find_interface(wname)) == NULL) - return (NULL); - - return (wlan_mesh_find_route(*wif, dstmac)); -} - -static struct wlan_mesh_route * -wlan_mesh_get_next_route(const struct asn_oid *oid, uint sub, - struct wlan_iface **wif) -{ - char wname[IFNAMSIZ]; - char dstmac[IEEE80211_ADDR_LEN]; - struct wlan_mesh_route *wmr; - - if (oid->len - sub == 0) { - for (*wif = wlan_mesh_first_interface(); *wif != NULL; - *wif = wlan_mesh_next_interface(*wif)) { - wmr = SLIST_FIRST(&(*wif)->mesh_routelist); - if (wmr != NULL) - return (wmr); - } - return (NULL); - } - - if (wlan_mac_index_decode(oid, sub, wname, dstmac) < 0 || - (*wif = wlan_find_interface(wname)) == NULL || - (wmr = wlan_mesh_find_route(*wif, dstmac)) == NULL) - return (NULL); - - if ((wmr = SLIST_NEXT(wmr, wr)) != NULL) - return (wmr); - - while ((*wif = wlan_mesh_next_interface(*wif)) != NULL) - if ((wmr = SLIST_FIRST(&(*wif)->mesh_routelist)) != NULL) - break; - - return (wmr); -} - -static int -wlan_mesh_route_set_status(struct snmp_context *ctx, struct snmp_value *val, - uint sub) -{ - char wname[IFNAMSIZ]; - char mac[IEEE80211_ADDR_LEN]; - struct wlan_mesh_route *wmr; - struct wlan_iface *wif; - - if (wlan_mac_index_decode(&val->var, sub, wname, mac) < 0) - return (SNMP_ERR_GENERR); - wmr = wlan_mesh_get_route(&val->var, sub, &wif); - - switch (val->v.integer) { - case RowStatus_createAndGo: - if (wmr != NULL) - return (SNMP_ERR_INCONS_NAME); - break; - case RowStatus_destroy: - if (wmr == NULL) - return (SNMP_ERR_NOSUCHNAME); - ctx->scratch->int1 = RowStatus_active; - return (SNMP_ERR_NOERROR); - default: - return (SNMP_ERR_INCONS_VALUE); - } - - if ((wif = wlan_find_interface(wname)) == NULL) - return (SNMP_ERR_INCONS_NAME); - - if ((wmr = wlan_mesh_new_route(mac)) == NULL) - return (SNMP_ERR_GENERR); - - if (wlan_mesh_add_rtentry(wif, wmr) < 0) { - wlan_mesh_free_route(wmr); - return (SNMP_ERR_GENERR); - } - - ctx->scratch->int1 = RowStatus_destroy; - if (wlan_mesh_add_route(wif, wmr) < 0) { - (void)wlan_mesh_delete_route(wif, wmr); - return (SNMP_ERR_GENERR); - } - - return (SNMP_ERR_NOERROR); -} - -/* - * Wlan snmp module initialization hook. - * Returns 0 on success, < 0 on error. - */ -static int -wlan_init(struct lmodule * mod __unused, int argc __unused, - char *argv[] __unused) -{ - if (wlan_kmodules_load() < 0) - return (-1); - - if (wlan_ioctl_init() < 0) - return (-1); - - /* Register for new interface creation notifications. */ - if (mib_register_newif(wlan_attach_newif, wlan_module)) { - syslog(LOG_ERR, "Cannot register newif function: %s", - strerror(errno)); - return (-1); - } - - return (0); -} - -/* - * Wlan snmp module finalization hook. - */ -static int -wlan_fini(void) -{ - mib_unregister_newif(wlan_module); - or_unregister(reg_wlan); - - /* XXX: Cleanup! */ - wlan_free_iflist(); - - return (0); -} - -/* - * Refetch all available data from the kernel. - */ -static void -wlan_update_data(void *arg __unused) -{ -} - -/* - * Wlan snmp module start operation. - */ -static void -wlan_start(void) -{ - struct mibif *ifp; - - reg_wlan = or_register(&oid_wlan, - "The MIB module for managing wireless networking.", wlan_module); - - /* Add the existing wlan interfaces. */ - for (ifp = mib_first_if(); ifp != NULL; ifp = mib_next_if(ifp)) - wlan_attach_newif(ifp); - - wlan_data_timer = timer_start_repeat(wlan_poll_ticks, - wlan_poll_ticks, wlan_update_data, NULL, wlan_module); -} - -/* - * Dump the Wlan snmp module data on SIGUSR1. - */ -static void -wlan_dump(void) -{ - /* XXX: Print some debug info to syslog. */ - struct wlan_iface *wif; - - for (wif = wlan_first_interface(); wif != NULL; - wif = wlan_next_interface(wif)) - syslog(LOG_ERR, "wlan iface %s", wif->wname); -} - -const char wlan_comment[] = \ -"This module implements the BEGEMOT MIB for wireless networking."; - -const struct snmp_module config = { - .comment = wlan_comment, - .init = wlan_init, - .fini = wlan_fini, - .start = wlan_start, - .tree = wlan_ctree, - .dump = wlan_dump, - .tree_size = wlan_CTREE_SIZE, -}; diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.h b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.h deleted file mode 100644 index 16632d3..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_snmp.h +++ /dev/null @@ -1,286 +0,0 @@ -/*- - * Copyright (c) 2010 The FreeBSD Foundation - * All rights reserved. - * - * This software was developed by Shteryana Sotirova Shopova under - * sponsorship from the FreeBSD Foundation. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#define WLAN_IFMODE_MAX WlanIfaceOperatingModeType_tdma -#define WLAN_COUNTRY_CODE_SIZE 3 -#define WLAN_BGSCAN_IDLE_MIN 100 /* XXX */ -#define WLAN_SCAN_VALID_MIN 10 /* XXX */ -#define WLAN_TDMA_MAXSLOTS 2 /* XXX */ - -struct wlan_iface; - -struct wlan_peer { - uint8_t pmac[IEEE80211_ADDR_LEN]; /* key */ - uint16_t associd; - uint16_t vlan; - uint16_t frequency; - uint32_t fflags; - uint8_t txrate; - int8_t rssi; - uint16_t idle; - uint16_t txseqs; - uint16_t rxseqs; - uint16_t txpower; - uint8_t capinfo; - uint32_t state; - uint16_t local_id; - uint16_t peer_id; - SLIST_ENTRY(wlan_peer) wp; -}; - -SLIST_HEAD(wlan_peerlist, wlan_peer); - -struct wlan_scan_result { - uint8_t ssid[IEEE80211_NWID_LEN + 1]; - uint8_t bssid[IEEE80211_ADDR_LEN]; - uint8_t opchannel; - int8_t rssi; - uint16_t frequency; - int8_t noise; - uint16_t bintval; - uint8_t capinfo; - struct wlan_iface *pwif; - SLIST_ENTRY(wlan_scan_result) wsr; -}; - -SLIST_HEAD(wlan_scanlist, wlan_scan_result); - -struct wlan_mac_mac { - uint8_t mac[IEEE80211_ADDR_LEN]; - enum RowStatus mac_status; - SLIST_ENTRY(wlan_mac_mac) wm; -}; - -SLIST_HEAD(wlan_maclist, wlan_mac_mac); - -struct wlan_mesh_route { - struct ieee80211req_mesh_route imroute; - enum RowStatus mroute_status; - SLIST_ENTRY(wlan_mesh_route) wr; -}; - -SLIST_HEAD(wlan_mesh_routes, wlan_mesh_route); - -struct wlan_iface { - char wname[IFNAMSIZ]; - uint32_t index; - char pname[IFNAMSIZ]; - enum WlanIfaceOperatingModeType mode; - uint32_t flags; - uint8_t dbssid[IEEE80211_ADDR_LEN]; - uint8_t dlmac[IEEE80211_ADDR_LEN]; - enum RowStatus status; - enum wlanIfaceState state; - uint8_t internal; - - uint32_t drivercaps; - uint32_t cryptocaps; - uint32_t htcaps; - - uint32_t packet_burst; - uint8_t country_code[WLAN_COUNTRY_CODE_SIZE]; - enum WlanRegDomainCode reg_domain; - uint8_t desired_ssid[IEEE80211_NWID_LEN + 1]; - uint32_t desired_channel; - enum TruthValue dyn_frequency; - enum TruthValue fast_frames; - enum TruthValue dturbo; - int32_t tx_power; - int32_t frag_threshold; - int32_t rts_threshold; - enum TruthValue priv_subscribe; - enum TruthValue bg_scan; - int32_t bg_scan_idle; - int32_t bg_scan_interval; - int32_t beacons_missed; - uint8_t desired_bssid[IEEE80211_ADDR_LEN]; - enum wlanIfaceRoamingMode roam_mode; - enum TruthValue dot11d; - enum TruthValue dot11h; - enum TruthValue dynamic_wds; - enum TruthValue power_save; - enum TruthValue ap_bridge; - int32_t beacon_interval; - int32_t dtim_period; - enum TruthValue hide_ssid; - enum TruthValue inact_process; - enum wlanIfaceDot11gProtMode do11g_protect; - enum TruthValue dot11g_pure; - enum TruthValue dot11n_pure; - enum WlanIfaceDot11nPduType ampdu; - int32_t ampdu_density; - int32_t ampdu_limit; - enum WlanIfaceDot11nPduType amsdu; - int32_t amsdu_limit; - enum TruthValue ht_enabled; - enum TruthValue ht_compatible; - enum wlanIfaceDot11nHTProtMode ht_prot_mode; - enum TruthValue rifs; - enum TruthValue short_gi; - enum wlanIfaceDot11nSMPSMode smps_mode; - int32_t tdma_slot; - int32_t tdma_slot_count; - int32_t tdma_slot_length; - int32_t tdma_binterval; - - struct wlan_peerlist peerlist; - struct ieee80211_stats stats; - uint32_t nchannels; - struct ieee80211_channel *chanlist; - struct ieee80211_roamparams_req roamparams; - struct ieee80211_txparams_req txparams; - - uint32_t scan_flags; - uint32_t scan_duration; - uint32_t scan_mindwell; - uint32_t scan_maxdwell; - enum wlanScanConfigStatus scan_status; - struct wlan_scanlist scanlist; - - uint8_t wepsupported; - enum wlanWepMode wepmode; - int32_t weptxkey; - - uint8_t macsupported; - enum wlanMACAccessControlPolicy mac_policy; - uint32_t mac_nacls; - struct wlan_maclist mac_maclist; - - uint32_t mesh_ttl; - enum TruthValue mesh_peering; - enum TruthValue mesh_forwarding; - enum wlanMeshMetric mesh_metric; - enum wlanMeshPath mesh_path; - enum wlanHWMPRootMode hwmp_root_mode; - uint32_t hwmp_max_hops; - struct wlan_mesh_routes mesh_routelist; - - SLIST_ENTRY(wlan_iface) w_if; -}; - -enum wlan_syscl { - WLAN_MESH_RETRY_TO = 0, - WLAN_MESH_HOLDING_TO, - WLAN_MESH_CONFIRM_TO, - WLAN_MESH_MAX_RETRIES, - WLAN_HWMP_TARGET_ONLY, - WLAN_HWMP_REPLY_FORWARD, - WLAN_HWMP_PATH_LIFETIME, - WLAN_HWMP_ROOT_TO, - WLAN_HWMP_ROOT_INT, - WLAN_HWMP_RANN_INT, - WLAN_HWMP_INACTIVITY_TO, - WLAN_SYSCTL_MAX -}; - -struct wlan_config { - int32_t mesh_retryto; - int32_t mesh_holdingto; - int32_t mesh_confirmto; - int32_t mesh_maxretries; - int32_t hwmp_targetonly; - int32_t hwmp_replyforward; - int32_t hwmp_pathlifetime; - int32_t hwmp_roottimeout; - int32_t hwmp_rootint; - int32_t hwmp_rannint; - int32_t hwmp_inact; -}; - -int wlan_ioctl_init(void); -int wlan_kmodules_load(void); -int wlan_check_media(char *); -int wlan_config_state(struct wlan_iface *, uint8_t); -int wlan_get_opmode(struct wlan_iface *wif); -int wlan_get_local_addr(struct wlan_iface *wif); -int wlan_get_parent(struct wlan_iface *wif); -int wlan_get_driver_caps(struct wlan_iface *wif); -uint8_t wlan_channel_state_to_snmp(uint8_t cstate); -uint32_t wlan_channel_flags_to_snmp(uint32_t cflags); -int wlan_get_channel_list(struct wlan_iface *wif); -int wlan_get_roam_params(struct wlan_iface *wif); -int wlan_get_tx_params(struct wlan_iface *wif); -int wlan_set_tx_params(struct wlan_iface *wif, int32_t pmode); -int wlan_clone_create(struct wlan_iface *); -int wlan_clone_destroy(struct wlan_iface *wif); -int wlan_config_get_dssid(struct wlan_iface *wif); -int wlan_config_set_dssid(struct wlan_iface *wif, char *ssid, int slen); -int wlan_config_get_ioctl(struct wlan_iface *wif, int which); -int wlan_config_set_ioctl(struct wlan_iface *wif, int which, int val, - char *strval, int len); -int wlan_set_scan_config(struct wlan_iface *wif); -int wlan_get_scan_results(struct wlan_iface *wif); -int wlan_get_stats(struct wlan_iface *wif); -int wlan_get_wepmode(struct wlan_iface *wif); -int wlan_set_wepmode(struct wlan_iface *wif); -int wlan_get_weptxkey(struct wlan_iface *wif); -int wlan_set_weptxkey(struct wlan_iface *wif); -int wlan_get_wepkeys(struct wlan_iface *wif); -int wlan_set_wepkeys(struct wlan_iface *wif); -int wlan_get_mac_policy(struct wlan_iface *wif); -int wlan_set_mac_policy(struct wlan_iface *wif); -int wlan_flush_mac_mac(struct wlan_iface *wif); -int wlan_get_mac_acl_macs(struct wlan_iface *wif); -int wlan_add_mac_acl_mac(struct wlan_iface *wif, struct wlan_mac_mac *mmac); -int wlan_del_mac_acl_mac(struct wlan_iface *wif, struct wlan_mac_mac *mmac); - -int32_t wlan_do_sysctl(struct wlan_config *cfg, enum wlan_syscl which, int set); -int wlan_mesh_config_get(struct wlan_iface *wif, int which); -int wlan_mesh_config_set(struct wlan_iface *wif, int which); -int wlan_mesh_flush_routes(struct wlan_iface *wif); -int wlan_mesh_add_route(struct wlan_iface *wif, struct wlan_mesh_route *wmr); -int wlan_mesh_del_route(struct wlan_iface *wif, struct wlan_mesh_route *wmr); -int wlan_mesh_get_routelist(struct wlan_iface *wif); -int wlan_hwmp_config_get(struct wlan_iface *wif, int which); -int wlan_hwmp_config_set(struct wlan_iface *wif, int which); - -/* XXX: static */ - -int wlan_peer_set_vlan(struct wlan_iface *wif, struct wlan_peer *wip, int vlan); -int wlan_get_peerinfo(struct wlan_iface *wif); - -/* XXX*/ -struct wlan_peer *wlan_new_peer(const uint8_t *pmac); -void wlan_free_peer(struct wlan_peer *wip); -int wlan_add_peer(struct wlan_iface *wif, struct wlan_peer *wip); - -struct wlan_scan_result * wlan_scan_new_result(const uint8_t *ssid, - const uint8_t *bssid); -void wlan_scan_free_result(struct wlan_scan_result *sr); -int wlan_scan_add_result(struct wlan_iface *wif, struct wlan_scan_result *sr); - -struct wlan_mac_mac *wlan_mac_new_mac(const uint8_t *mac); -void wlan_mac_free_mac(struct wlan_mac_mac *wmm); -int wlan_mac_add_mac(struct wlan_iface *wif, struct wlan_mac_mac *wmm); - -struct wlan_mesh_route *wlan_mesh_new_route(const uint8_t *dstmac); -int wlan_mesh_add_rtentry(struct wlan_iface *wif, struct wlan_mesh_route *wmr); -void wlan_mesh_free_route(struct wlan_mesh_route *wmr); diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c deleted file mode 100644 index 739f11f..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_sys.c +++ /dev/null @@ -1,3145 +0,0 @@ -/*- - * Copyright (c) 2010 The FreeBSD Foundation - * All rights reserved. - - * This software was developed by Shteryana Sotirova Shopova under - * sponsorship from the FreeBSD Foundation. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "wlan_tree.h" -#include "wlan_snmp.h" - -static int sock = -1; - -static int wlan_ioctl(char *, uint16_t, int *, void *, size_t *, int); -static int wlan_kmod_load(const char *); -static uint32_t wlan_drivercaps_to_snmp(uint32_t); -static uint32_t wlan_cryptocaps_to_snmp(uint32_t); -static uint32_t wlan_htcaps_to_snmp(uint32_t); -static uint32_t wlan_peerstate_to_snmp(uint32_t); -static uint32_t wlan_peercaps_to_snmp(uint32_t ); -static uint32_t wlan_channel_flags_to_snmp_phy(uint32_t); -static uint32_t wlan_regdomain_to_snmp(int); -static uint32_t wlan_snmp_to_scan_flags(int); -static int wlan_config_snmp2ioctl(int); -static int wlan_snmp_to_regdomain(enum WlanRegDomainCode); -static int wlan_config_get_country(struct wlan_iface *); -static int wlan_config_set_country(struct wlan_iface *, char *, int); -static int wlan_config_get_dchannel(struct wlan_iface *wif); -static int wlan_config_set_dchannel(struct wlan_iface *wif, uint32_t); -static int wlan_config_get_bssid(struct wlan_iface *); -static int wlan_config_set_bssid(struct wlan_iface *, uint8_t *); -static void wlan_config_set_snmp_intval(struct wlan_iface *, int, int); -static int wlan_config_snmp2value(int, int, int *); -static int wlan_config_check(struct wlan_iface *, int); -static int wlan_config_get_intval(struct wlan_iface *, int); -static int wlan_config_set_intval(struct wlan_iface *, int, int); -static int wlan_add_new_scan_result(struct wlan_iface *, - const struct ieee80211req_scan_result *, uint8_t *); -static int wlan_add_mac_macinfo(struct wlan_iface *, - const struct ieee80211req_maclist *); -static struct wlan_peer *wlan_add_peerinfo(const struct ieee80211req_sta_info *); - -int -wlan_ioctl_init(void) -{ - if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { - syslog(LOG_ERR, "cannot open socket : %s", strerror(errno)); - return (-1); - } - - return (0); -} -/* - * Load the needed modules in kernel if not already there. - */ -enum wlan_kmodules { - WLAN_KMOD = 0, - WLAN_KMOD_ACL, - WLAN_KMOD_WEP, - WLAN_KMODS_MAX -}; - -static const char *wmod_names[] = { - "wlan", - "wlan_wlan_acl", - "wlan_wep", - NULL -}; - -static int -wlan_kmod_load(const char *modname) -{ - int fileid, modid; - struct module_stat mstat; - - mstat.version = sizeof(struct module_stat); - for (fileid = kldnext(0); fileid > 0; fileid = kldnext(fileid)) { - for (modid = kldfirstmod(fileid); modid > 0; - modid = modfnext(modid)) { - if (modstat(modid, &mstat) < 0) - continue; - if (strcmp(modname, mstat.name) == 0) - return (0); - } - } - - /* Not present - load it. */ - if (kldload(modname) < 0) { - syslog(LOG_ERR, "failed to load %s kernel module - %s", modname, - strerror(errno)); - return (-1); - } - - return (1); -} - -int -wlan_kmodules_load(void) -{ - if (wlan_kmod_load(wmod_names[WLAN_KMOD]) < 0) - return (-1); - - if (wlan_kmod_load(wmod_names[WLAN_KMOD_ACL]) > 0) - syslog(LOG_NOTICE, "SNMP wlan loaded %s module", - wmod_names[WLAN_KMOD_ACL]); - - if (wlan_kmod_load(wmod_names[WLAN_KMOD_WEP]) > 0) - syslog(LOG_NOTICE, "SNMP wlan loaded %s module", - wmod_names[WLAN_KMOD_WEP]); - - return (0); -} - -/* XXX: FIXME */ -static int -wlan_ioctl(char *wif_name, uint16_t req_type, int *val, void *arg, - size_t *argsize, int set) -{ - struct ieee80211req ireq; - - memset(&ireq, 0, sizeof(struct ieee80211req)); - strlcpy(ireq.i_name, wif_name, IFNAMSIZ); - - ireq.i_type = req_type; - ireq.i_val = *val; - ireq.i_len = *argsize; - ireq.i_data = arg; - - if (ioctl(sock, set ? SIOCS80211 : SIOCG80211, &ireq) < 0) { - syslog(LOG_ERR, "iface %s - %s param: ioctl(%d) " - "failed: %s", wif_name, set ? "set" : "get", - req_type, strerror(errno)); - return (-1); - } - - *argsize = ireq.i_len; - *val = ireq.i_val; - - return (0); -} - -int -wlan_check_media(char *ifname) -{ - struct ifmediareq ifmr; - - memset(&ifmr, 0, sizeof(struct ifmediareq)); - strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); - - if (ioctl(sock, SIOCGIFMEDIA, &ifmr) < 0 || ifmr.ifm_count == 0) - return (0); /* Interface doesn't support SIOCGIFMEDIA. */ - - if ((ifmr.ifm_status & IFM_AVALID) == 0) - return (0); - - return (IFM_TYPE(ifmr.ifm_active)); -} - -int -wlan_get_opmode(struct wlan_iface *wif) -{ - struct ifmediareq ifmr; - - memset(&ifmr, 0, sizeof(struct ifmediareq)); - strlcpy(ifmr.ifm_name, wif->wname, sizeof(ifmr.ifm_name)); - - if (ioctl(sock, SIOCGIFMEDIA, &ifmr) < 0) { - if (errno == ENXIO) - return (-1); - wif->mode = WlanIfaceOperatingModeType_station; - return (0); - } - - if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { - if (ifmr.ifm_current & IFM_FLAG0) - wif->mode = WlanIfaceOperatingModeType_adhocDemo; - else - wif->mode = WlanIfaceOperatingModeType_ibss; - } else if (ifmr.ifm_current & IFM_IEEE80211_HOSTAP) - wif->mode = WlanIfaceOperatingModeType_hostAp; - else if (ifmr.ifm_current & IFM_IEEE80211_MONITOR) - wif->mode = WlanIfaceOperatingModeType_monitor; - else if (ifmr.ifm_current & IFM_IEEE80211_MBSS) - wif->mode = WlanIfaceOperatingModeType_meshPoint; - else if (ifmr.ifm_current & IFM_IEEE80211_WDS) - wif->mode = WlanIfaceOperatingModeType_wds; - - return (0); -} - -int -wlan_config_state(struct wlan_iface *wif, uint8_t set) -{ - int flags; - struct ifreq ifr; - - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, wif->wname); - - if (ioctl(sock, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { - syslog(LOG_ERR, "set %s status: ioctl(SIOCGIFFLAGS) " - "failed: %s", wif->wname, strerror(errno)); - return (-1); - } - - if (set == 0) { - if ((ifr.ifr_flags & IFF_UP) != 0) - wif->state = wlanIfaceState_up; - else - wif->state = wlanIfaceState_down; - return (0); - } - - flags = (ifr.ifr_flags & 0xffff) | (ifr.ifr_flagshigh << 16); - - if (wif->state == wlanIfaceState_up) - flags |= IFF_UP; - else - flags &= ~IFF_UP; - - ifr.ifr_flags = flags & 0xffff; - ifr.ifr_flagshigh = flags >> 16; - if (ioctl(sock, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { - syslog(LOG_ERR, "set %s %s: ioctl(SIOCSIFFLAGS) failed: %s", - wif->wname, wif->state == wlanIfaceState_up?"up":"down", - strerror(errno)); - return (-1); - } - - return (0); -} - -int -wlan_get_local_addr(struct wlan_iface *wif) -{ - int len; - char ifname[IFNAMSIZ]; - struct ifaddrs *ifap, *ifa; - struct sockaddr_dl sdl; - - if (getifaddrs(&ifap) != 0) { - syslog(LOG_ERR, "wlan get mac: getifaddrs() failed - %s", - strerror(errno)); - return (-1); - } - - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr->sa_family != AF_LINK) - continue; - memcpy(&sdl, ifa->ifa_addr, sizeof(struct sockaddr_dl)); - if (sdl.sdl_alen > IEEE80211_ADDR_LEN) - continue; - if ((len = sdl.sdl_nlen) >= IFNAMSIZ) - len = IFNAMSIZ - 1; - memcpy(ifname, sdl.sdl_data, len); - ifname[len] = '\0'; - if (strcmp(wif->wname, ifname) == 0) - break; - } - - freeifaddrs(ifap); - return (0); -} - -int -wlan_get_parent(struct wlan_iface *wif __unused) -{ - /* XXX: There's no way to fetch this from the kernel. */ - return (0); -} - -/* XXX */ -#define IEEE80211_C_STA 0x00000001 /* CAPABILITY: STA available */ -#define IEEE80211_C_8023ENCAP 0x00000002 /* CAPABILITY: 802.3 encap */ -#define IEEE80211_C_FF 0x00000040 /* CAPABILITY: ATH FF avail */ -#define IEEE80211_C_TURBOP 0x00000080 /* CAPABILITY: ATH Turbo avail*/ -#define IEEE80211_C_IBSS 0x00000100 /* CAPABILITY: IBSS available */ -#define IEEE80211_C_PMGT 0x00000200 /* CAPABILITY: Power mgmt */ -#define IEEE80211_C_HOSTAP 0x00000400 /* CAPABILITY: HOSTAP avail */ -#define IEEE80211_C_AHDEMO 0x00000800 /* CAPABILITY: Old Adhoc Demo */ -#define IEEE80211_C_SWRETRY 0x00001000 /* CAPABILITY: sw tx retry */ -#define IEEE80211_C_TXPMGT 0x00002000 /* CAPABILITY: tx power mgmt */ -#define IEEE80211_C_SHSLOT 0x00004000 /* CAPABILITY: short slottime */ -#define IEEE80211_C_SHPREAMBLE 0x00008000 /* CAPABILITY: short preamble */ -#define IEEE80211_C_MONITOR 0x00010000 /* CAPABILITY: monitor mode */ -#define IEEE80211_C_DFS 0x00020000 /* CAPABILITY: DFS/radar avail*/ -#define IEEE80211_C_MBSS 0x00040000 /* CAPABILITY: MBSS available */ -/* 0x7c0000 available */ -#define IEEE80211_C_WPA1 0x00800000 /* CAPABILITY: WPA1 avail */ -#define IEEE80211_C_WPA2 0x01000000 /* CAPABILITY: WPA2 avail */ -#define IEEE80211_C_WPA 0x01800000 /* CAPABILITY: WPA1+WPA2 avail*/ -#define IEEE80211_C_BURST 0x02000000 /* CAPABILITY: frame bursting */ -#define IEEE80211_C_WME 0x04000000 /* CAPABILITY: WME avail */ -#define IEEE80211_C_WDS 0x08000000 /* CAPABILITY: 4-addr support */ -/* 0x10000000 reserved */ -#define IEEE80211_C_BGSCAN 0x20000000 /* CAPABILITY: bg scanning */ -#define IEEE80211_C_TXFRAG 0x40000000 /* CAPABILITY: tx fragments */ -#define IEEE80211_C_TDMA 0x80000000 /* CAPABILITY: TDMA avail */ - -static uint32_t -wlan_drivercaps_to_snmp(uint32_t dcaps) -{ - uint32_t scaps = 0; - - if ((dcaps & IEEE80211_C_STA) != 0) - scaps |= (0x1 << WlanDriverCaps_station); - if ((dcaps & IEEE80211_C_8023ENCAP) != 0) - scaps |= (0x1 << WlanDriverCaps_ieee8023encap); - if ((dcaps & IEEE80211_C_FF) != 0) - scaps |= (0x1 << WlanDriverCaps_athFastFrames); - if ((dcaps & IEEE80211_C_TURBOP) != 0) - scaps |= (0x1 << WlanDriverCaps_athTurbo); - if ((dcaps & IEEE80211_C_IBSS) != 0) - scaps |= (0x1 << WlanDriverCaps_ibss); - if ((dcaps & IEEE80211_C_PMGT) != 0) - scaps |= (0x1 << WlanDriverCaps_pmgt); - if ((dcaps & IEEE80211_C_HOSTAP) != 0) - scaps |= (0x1 << WlanDriverCaps_hostAp); - if ((dcaps & IEEE80211_C_AHDEMO) != 0) - scaps |= (0x1 << WlanDriverCaps_ahDemo); - if ((dcaps & IEEE80211_C_SWRETRY) != 0) - scaps |= (0x1 << WlanDriverCaps_swRetry); - if ((dcaps & IEEE80211_C_TXPMGT) != 0) - scaps |= (0x1 << WlanDriverCaps_txPmgt); - if ((dcaps & IEEE80211_C_SHSLOT) != 0) - scaps |= (0x1 << WlanDriverCaps_shortSlot); - if ((dcaps & IEEE80211_C_SHPREAMBLE) != 0) - scaps |= (0x1 << WlanDriverCaps_shortPreamble); - if ((dcaps & IEEE80211_C_MONITOR) != 0) - scaps |= (0x1 << WlanDriverCaps_monitor); - if ((dcaps & IEEE80211_C_DFS) != 0) - scaps |= (0x1 << WlanDriverCaps_dfs); - if ((dcaps & IEEE80211_C_MBSS) != 0) - scaps |= (0x1 << WlanDriverCaps_mbss); - if ((dcaps & IEEE80211_C_WPA1) != 0) - scaps |= (0x1 << WlanDriverCaps_wpa1); - if ((dcaps & IEEE80211_C_WPA2) != 0) - scaps |= (0x1 << WlanDriverCaps_wpa2); - if ((dcaps & IEEE80211_C_BURST) != 0) - scaps |= (0x1 << WlanDriverCaps_burst); - if ((dcaps & IEEE80211_C_WME) != 0) - scaps |= (0x1 << WlanDriverCaps_wme); - if ((dcaps & IEEE80211_C_WDS) != 0) - scaps |= (0x1 << WlanDriverCaps_wds); - if ((dcaps & IEEE80211_C_BGSCAN) != 0) - scaps |= (0x1 << WlanDriverCaps_bgScan); - if ((dcaps & IEEE80211_C_TXFRAG) != 0) - scaps |= (0x1 << WlanDriverCaps_txFrag); - if ((dcaps & IEEE80211_C_TDMA) != 0) - scaps |= (0x1 << WlanDriverCaps_tdma); - - return (scaps); -} - -static uint32_t -wlan_cryptocaps_to_snmp(uint32_t ccaps) -{ - uint32_t scaps = 0; - -#if NOT_YET - if ((ccaps & IEEE80211_CRYPTO_WEP) != 0) - scaps |= (0x1 << wlanCryptoCaps_wep); - if ((ccaps & IEEE80211_CRYPTO_TKIP) != 0) - scaps |= (0x1 << wlanCryptoCaps_tkip); - if ((ccaps & IEEE80211_CRYPTO_AES_OCB) != 0) - scaps |= (0x1 << wlanCryptoCaps_aes); - if ((ccaps & IEEE80211_CRYPTO_AES_CCM) != 0) - scaps |= (0x1 << wlanCryptoCaps_aesCcm); - if ((ccaps & IEEE80211_CRYPTO_TKIPMIC) != 0) - scaps |= (0x1 << wlanCryptoCaps_tkipMic); - if ((ccaps & IEEE80211_CRYPTO_CKIP) != 0) - scaps |= (0x1 << wlanCryptoCaps_ckip); -#else /* !NOT_YET */ - scaps = ccaps; -#endif - return (scaps); -} - -#define IEEE80211_HTC_AMPDU 0x00010000 /* CAPABILITY: A-MPDU tx */ -#define IEEE80211_HTC_AMSDU 0x00020000 /* CAPABILITY: A-MSDU tx */ -/* NB: HT40 is implied by IEEE80211_HTCAP_CHWIDTH40 */ -#define IEEE80211_HTC_HT 0x00040000 /* CAPABILITY: HT operation */ -#define IEEE80211_HTC_SMPS 0x00080000 /* CAPABILITY: MIMO power save*/ -#define IEEE80211_HTC_RIFS 0x00100000 /* CAPABILITY: RIFS support */ - -static uint32_t -wlan_htcaps_to_snmp(uint32_t hcaps) -{ - uint32_t scaps = 0; - - if ((hcaps & IEEE80211_HTCAP_LDPC) != 0) - scaps |= (0x1 << WlanHTCaps_ldpc); - if ((hcaps & IEEE80211_HTCAP_CHWIDTH40) != 0) - scaps |= (0x1 << WlanHTCaps_chwidth40); - if ((hcaps & IEEE80211_HTCAP_GREENFIELD) != 0) - scaps |= (0x1 << WlanHTCaps_greenField); - if ((hcaps & IEEE80211_HTCAP_SHORTGI20) != 0) - scaps |= (0x1 << WlanHTCaps_shortGi20); - if ((hcaps & IEEE80211_HTCAP_SHORTGI40) != 0) - scaps |= (0x1 << WlanHTCaps_shortGi40); - if ((hcaps & IEEE80211_HTCAP_TXSTBC) != 0) - scaps |= (0x1 << WlanHTCaps_txStbc); - if ((hcaps & IEEE80211_HTCAP_DELBA) != 0) - scaps |= (0x1 << WlanHTCaps_delba); - if ((hcaps & IEEE80211_HTCAP_MAXAMSDU_7935) != 0) - scaps |= (0x1 << WlanHTCaps_amsdu7935); - if ((hcaps & IEEE80211_HTCAP_DSSSCCK40) != 0) - scaps |= (0x1 << WlanHTCaps_dssscck40); - if ((hcaps & IEEE80211_HTCAP_PSMP) != 0) - scaps |= (0x1 << WlanHTCaps_psmp); - if ((hcaps & IEEE80211_HTCAP_40INTOLERANT) != 0) - scaps |= (0x1 << WlanHTCaps_fortyMHzIntolerant); - if ((hcaps & IEEE80211_HTCAP_LSIGTXOPPROT) != 0) - scaps |= (0x1 << WlanHTCaps_lsigTxOpProt); - if ((hcaps & IEEE80211_HTC_AMPDU) != 0) - scaps |= (0x1 << WlanHTCaps_htcAmpdu); - if ((hcaps & IEEE80211_HTC_AMSDU) != 0) - scaps |= (0x1 << WlanHTCaps_htcAmsdu); - if ((hcaps & IEEE80211_HTC_HT) != 0) - scaps |= (0x1 << WlanHTCaps_htcHt); - if ((hcaps & IEEE80211_HTC_SMPS) != 0) - scaps |= (0x1 << WlanHTCaps_htcSmps); - if ((hcaps & IEEE80211_HTC_RIFS) != 0) - scaps |= (0x1 << WlanHTCaps_htcRifs); - - return (scaps); -} - -/* XXX: Not here? */ -#define WLAN_SET_TDMA_OPMODE(w) do { \ - if ((w)->mode == WlanIfaceOperatingModeType_adhocDemo && \ - ((w)->drivercaps & WlanDriverCaps_tdma) != 0) \ - (w)->mode = WlanIfaceOperatingModeType_tdma; \ -} while (0) -int -wlan_get_driver_caps(struct wlan_iface *wif) -{ - int val = 0; - size_t argsize; - struct ieee80211_devcaps_req dc; - - memset(&dc, 0, sizeof(struct ieee80211_devcaps_req)); - argsize = sizeof(struct ieee80211_devcaps_req); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_DEVCAPS, &val, &dc, - &argsize, 0) < 0) - return (-1); - - wif->drivercaps = wlan_drivercaps_to_snmp(dc.dc_drivercaps); - wif->cryptocaps = wlan_cryptocaps_to_snmp(dc.dc_cryptocaps); - wif->htcaps = wlan_htcaps_to_snmp(dc.dc_htcaps); - - WLAN_SET_TDMA_OPMODE(wif); - - argsize = dc.dc_chaninfo.ic_nchans * sizeof(struct ieee80211_channel); - wif->chanlist = (struct ieee80211_channel *)malloc(argsize); - if (wif->chanlist == NULL) - return (0); - - memcpy(wif->chanlist, dc.dc_chaninfo.ic_chans, argsize); - wif->nchannels = dc.dc_chaninfo.ic_nchans; - - return (0); -} - -uint8_t -wlan_channel_state_to_snmp(uint8_t cstate) -{ - uint8_t cs = 0; - - if ((cstate & IEEE80211_CHANSTATE_RADAR) != 0) - cs |= (0x1 << WlanIfaceChannelStateType_radar); - if ((cstate & IEEE80211_CHANSTATE_CACDONE) != 0) - cs |= (0x1 << WlanIfaceChannelStateType_cacDone); - if ((cstate & IEEE80211_CHANSTATE_CWINT) != 0) - cs |= (0x1 << WlanIfaceChannelStateType_interferenceDetected); - if ((cstate & IEEE80211_CHANSTATE_NORADAR) != 0) - cs |= (0x1 << WlanIfaceChannelStateType_radarClear); - - return (cs); -} - -uint32_t -wlan_channel_flags_to_snmp(uint32_t cflags) -{ - uint32_t cf = 0; - - if ((cflags & IEEE80211_CHAN_TURBO) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_turbo); - if ((cflags & IEEE80211_CHAN_CCK) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_cck); - if ((cflags & IEEE80211_CHAN_OFDM) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_ofdm); - if ((cflags & IEEE80211_CHAN_2GHZ) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_spectrum2Ghz); - if ((cflags & IEEE80211_CHAN_5GHZ) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_spectrum5Ghz); - if ((cflags & IEEE80211_CHAN_PASSIVE) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_passiveScan); - if ((cflags & IEEE80211_CHAN_DYN) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_dynamicCckOfdm); - if ((cflags & IEEE80211_CHAN_GFSK) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_gfsk); - if ((cflags & IEEE80211_CHAN_GSM) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_spectrum900Mhz); - if ((cflags & IEEE80211_CHAN_STURBO) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_dot11aStaticTurbo); - if ((cflags & IEEE80211_CHAN_HALF) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_halfRate); - if ((cflags & IEEE80211_CHAN_QUARTER) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_quarterRate); - if ((cflags & IEEE80211_CHAN_HT20) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_ht20); - if ((cflags & IEEE80211_CHAN_HT40U) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_ht40u); - if ((cflags & IEEE80211_CHAN_HT40D) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_ht40d); - if ((cflags & IEEE80211_CHAN_DFS) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_dfs); - if ((cflags & IEEE80211_CHAN_4MSXMIT) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_xmit4ms); - if ((cflags & IEEE80211_CHAN_NOADHOC) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_noAdhoc); - if ((cflags & IEEE80211_CHAN_NOHOSTAP) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_noHostAp); - if ((cflags & IEEE80211_CHAN_11D) != 0) - cf |= (0x1 << WlanIfaceChannelFlagsType_dot11d); - - return (cf); -} - -/* XXX: */ -#define WLAN_SNMP_MAX_CHANS 256 -int -wlan_get_channel_list(struct wlan_iface *wif) -{ - int val = 0; - uint32_t i, nchans; - size_t argsize; - struct ieee80211req_chaninfo *chaninfo; - struct ieee80211req_chanlist active; - const struct ieee80211_channel *c; - - argsize = sizeof(struct ieee80211req_chaninfo) + - sizeof(struct ieee80211_channel) * WLAN_SNMP_MAX_CHANS; - chaninfo = (struct ieee80211req_chaninfo *)malloc(argsize); - if (chaninfo == NULL) - return (-1); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_CHANINFO, &val, chaninfo, - &argsize, 0) < 0) - return (-1); - - argsize = sizeof(active); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_CHANLIST, &val, &active, - &argsize, 0) < 0) - goto error; - - for (i = 0, nchans = 0; i < chaninfo->ic_nchans; i++) { - c = &chaninfo->ic_chans[i]; - if (!isset(active.ic_channels, c->ic_ieee)) - continue; - nchans++; - } - wif->chanlist = (struct ieee80211_channel *)reallocf(wif->chanlist, - nchans * sizeof(*c)); - if (wif->chanlist == NULL) - goto error; - wif->nchannels = nchans; - for (i = 0, nchans = 0; i < chaninfo->ic_nchans; i++) { - c = &chaninfo->ic_chans[i]; - if (!isset(active.ic_channels, c->ic_ieee)) - continue; - memcpy(wif->chanlist + nchans, c, sizeof (*c)); - nchans++; - } - - free(chaninfo); - return (0); -error: - wif->nchannels = 0; - free(chaninfo); - return (-1); -} - -static enum WlanIfPhyMode -wlan_channel_flags_to_snmp_phy(uint32_t cflags) -{ - /* XXX: recheck */ - if ((cflags & IEEE80211_CHAN_A) != 0) - return (WlanIfPhyMode_dot11a); - if ((cflags & IEEE80211_CHAN_B) != 0) - return (WlanIfPhyMode_dot11b); - if ((cflags & IEEE80211_CHAN_G) != 0 || - (cflags & IEEE80211_CHAN_PUREG) != 0) - return (WlanIfPhyMode_dot11g); - if ((cflags & IEEE80211_CHAN_FHSS) != 0) - return (WlanIfPhyMode_fh); - if ((cflags & IEEE80211_CHAN_TURBO) != 0 && - (cflags & IEEE80211_CHAN_A) != 0) - return (WlanIfPhyMode_turboA); - if ((cflags & IEEE80211_CHAN_TURBO) != 0 && - (cflags & IEEE80211_CHAN_G) != 0) - return (WlanIfPhyMode_turboG); - if ((cflags & IEEE80211_CHAN_STURBO) != 0) - return (WlanIfPhyMode_sturboA); - if ((cflags & IEEE80211_CHAN_HALF) != 0) - return (WlanIfPhyMode_ofdmHalf); - if ((cflags & IEEE80211_CHAN_QUARTER) != 0) - return (WlanIfPhyMode_ofdmQuarter); - - return (WlanIfPhyMode_auto); -} - -int -wlan_get_roam_params(struct wlan_iface *wif) -{ - int val = 0; - size_t argsize; - - argsize = sizeof(struct ieee80211_roamparams_req); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_ROAM, &val, - &wif->roamparams, &argsize, 0) < 0) - return (-1); - - return (0); -} - -int -wlan_get_tx_params(struct wlan_iface *wif) -{ - int val = 0; - size_t argsize; - - /* - * XXX: Reset IEEE80211_RATE_MCS bit on IEEE80211_MODE_11NA - * and IEEE80211_MODE_11NG modes. - */ - argsize = sizeof(struct ieee80211_txparams_req); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_TXPARAMS, &val, - &wif->txparams, &argsize, 0) < 0) - return (-1); - - return (0); -} - -int -wlan_set_tx_params(struct wlan_iface *wif, int32_t pmode __unused) -{ - int val = 0; - size_t argsize; - - /* - * XXX: Set IEEE80211_RATE_MCS bit on IEEE80211_MODE_11NA - * and IEEE80211_MODE_11NG modes. - */ - argsize = sizeof(struct ieee80211_txparams_req); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_TXPARAMS, &val, - &wif->txparams, &argsize, 1) < 0) - return (-1); - - return (0); -} - -int -wlan_clone_create(struct wlan_iface *wif) -{ - struct ifreq ifr; - struct ieee80211_clone_params wcp; - static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; - - memset(&wcp, 0, sizeof(wcp)); - memset(&ifr, 0, sizeof(ifr)); - - /* Sanity checks. */ - if (wif == NULL || wif->pname[0] == '\0' || wif->mode > WLAN_IFMODE_MAX) - return (SNMP_ERR_INCONS_VALUE); - - if (wif->mode == WlanIfaceOperatingModeType_wds && - memcmp(wif->dbssid, zerobssid, IEEE80211_ADDR_LEN) == 0) - return (SNMP_ERR_INCONS_VALUE); - - strlcpy(wcp.icp_parent, wif->pname, IFNAMSIZ); - if ((wif->flags & WlanIfaceFlagsType_uniqueBssid) != 0) - wcp.icp_flags |= IEEE80211_CLONE_BSSID; - if ((wif->flags & WlanIfaceFlagsType_noBeacons) != 0) - wcp.icp_flags |= IEEE80211_CLONE_NOBEACONS; - if (wif->mode == WlanIfaceOperatingModeType_wds && - (wif->flags & WlanIfaceFlagsType_wdsLegacy) != 0) - wcp.icp_flags |= IEEE80211_CLONE_WDSLEGACY; - - switch (wif->mode) { - case WlanIfaceOperatingModeType_ibss: - wcp.icp_opmode = IEEE80211_M_IBSS; - break; - case WlanIfaceOperatingModeType_station: - wcp.icp_opmode = IEEE80211_M_STA; - break; - case WlanIfaceOperatingModeType_wds: - wcp.icp_opmode = IEEE80211_M_WDS; - break; - case WlanIfaceOperatingModeType_adhocDemo: - wcp.icp_opmode = IEEE80211_M_AHDEMO; - break; - case WlanIfaceOperatingModeType_hostAp: - wcp.icp_opmode = IEEE80211_M_HOSTAP; - break; - case WlanIfaceOperatingModeType_monitor: - wcp.icp_opmode = IEEE80211_M_MONITOR; - break; - case WlanIfaceOperatingModeType_meshPoint: - wcp.icp_opmode = IEEE80211_M_MBSS; - break; - case WlanIfaceOperatingModeType_tdma: - wcp.icp_opmode = IEEE80211_M_AHDEMO; - wcp.icp_flags |= IEEE80211_CLONE_TDMA; - break; - } - - memcpy(wcp.icp_bssid, wif->dbssid, IEEE80211_ADDR_LEN); - if (memcmp(wif->dlmac, zerobssid, IEEE80211_ADDR_LEN) != 0) { - memcpy(wcp.icp_macaddr, wif->dlmac, IEEE80211_ADDR_LEN); - wcp.icp_flags |= IEEE80211_CLONE_MACADDR; - } - - strlcpy(ifr.ifr_name, wif->wname, IFNAMSIZ); - ifr.ifr_data = (caddr_t) &wcp; - - if (ioctl(sock, SIOCIFCREATE2, (caddr_t) &ifr) < 0) { - syslog(LOG_ERR, "wlan clone create: ioctl(SIOCIFCREATE2) " - "failed: %s", strerror(errno)); - return (SNMP_ERR_GENERR); - } - - return (SNMP_ERR_NOERROR); -} - -int -wlan_clone_destroy(struct wlan_iface *wif) -{ - struct ifreq ifr; - - if (wif == NULL) - return (SNMP_ERR_INCONS_VALUE); - - memset(&ifr, 0, sizeof(ifr)); - strcpy(ifr.ifr_name, wif->wname); - - if (ioctl(sock, SIOCIFDESTROY, &ifr) < 0) { - syslog(LOG_ERR, "wlan clone destroy: ioctl(SIOCIFDESTROY) " - "failed: %s", strerror(errno)); - return (SNMP_ERR_GENERR); - } - - return (SNMP_ERR_NOERROR); -} - -static int -wlan_config_snmp2ioctl(int which) -{ - int op; - - switch (which) { - case LEAF_wlanIfacePacketBurst: - op = IEEE80211_IOC_BURST; - break; - case LEAF_wlanIfaceCountryCode: - op = IEEE80211_IOC_REGDOMAIN; - break; - case LEAF_wlanIfaceRegDomain: - op = IEEE80211_IOC_REGDOMAIN; - break; - case LEAF_wlanIfaceDesiredSsid: - op = IEEE80211_IOC_SSID; - break; - case LEAF_wlanIfaceDesiredChannel: - op = IEEE80211_IOC_CURCHAN; - break; - case LEAF_wlanIfaceDynamicFreqSelection: - op = IEEE80211_IOC_DFS; - break; - case LEAF_wlanIfaceFastFrames: - op = IEEE80211_IOC_FF; - break; - case LEAF_wlanIfaceDturbo: - op = IEEE80211_IOC_TURBOP; - break; - case LEAF_wlanIfaceTxPower: - op = IEEE80211_IOC_TXPOWER; - break; - case LEAF_wlanIfaceFragmentThreshold: - op = IEEE80211_IOC_FRAGTHRESHOLD; - break; - case LEAF_wlanIfaceRTSThreshold: - op = IEEE80211_IOC_RTSTHRESHOLD; - break; - case LEAF_wlanIfaceWlanPrivacySubscribe: - op = IEEE80211_IOC_WPS; - break; - case LEAF_wlanIfaceBgScan: - op = IEEE80211_IOC_BGSCAN; - break; - case LEAF_wlanIfaceBgScanIdle: - op = IEEE80211_IOC_BGSCAN_IDLE; - break; - case LEAF_wlanIfaceBgScanInterval: - op = IEEE80211_IOC_BGSCAN_INTERVAL; - break; - case LEAF_wlanIfaceBeaconMissedThreshold: - op = IEEE80211_IOC_BMISSTHRESHOLD; - break; - case LEAF_wlanIfaceDesiredBssid: - op = IEEE80211_IOC_BSSID; - break; - case LEAF_wlanIfaceRoamingMode: - op = IEEE80211_IOC_ROAMING; - break; - case LEAF_wlanIfaceDot11d: - op = IEEE80211_IOC_DOTD; - break; - case LEAF_wlanIfaceDot11h: - op = IEEE80211_IOC_DOTH; - break; - case LEAF_wlanIfaceDynamicWds: - op = IEEE80211_IOC_DWDS; - break; - case LEAF_wlanIfacePowerSave: - op = IEEE80211_IOC_POWERSAVE; - break; - case LEAF_wlanIfaceApBridge: - op = IEEE80211_IOC_APBRIDGE; - break; - case LEAF_wlanIfaceBeaconInterval: - op = IEEE80211_IOC_BEACON_INTERVAL; - break; - case LEAF_wlanIfaceDtimPeriod: - op = IEEE80211_IOC_DTIM_PERIOD; - break; - case LEAF_wlanIfaceHideSsid: - op = IEEE80211_IOC_HIDESSID; - break; - case LEAF_wlanIfaceInactivityProccess: - op = IEEE80211_IOC_INACTIVITY; - break; - case LEAF_wlanIfaceDot11gProtMode: - op = IEEE80211_IOC_PROTMODE; - break; - case LEAF_wlanIfaceDot11gPureMode: - op = IEEE80211_IOC_PUREG; - break; - case LEAF_wlanIfaceDot11nPureMode: - op = IEEE80211_IOC_PUREN; - break; - case LEAF_wlanIfaceDot11nAmpdu: - op = IEEE80211_IOC_AMPDU; - break; - case LEAF_wlanIfaceDot11nAmpduDensity: - op = IEEE80211_IOC_AMPDU_DENSITY; - break; - case LEAF_wlanIfaceDot11nAmpduLimit: - op = IEEE80211_IOC_AMPDU_LIMIT; - break; - case LEAF_wlanIfaceDot11nAmsdu: - op = IEEE80211_IOC_AMSDU; - break; - case LEAF_wlanIfaceDot11nAmsduLimit: - op = IEEE80211_IOC_AMSDU_LIMIT; - break; - case LEAF_wlanIfaceDot11nHighThroughput: - op = IEEE80211_IOC_HTCONF; - break; - case LEAF_wlanIfaceDot11nHTCompatible: - op = IEEE80211_IOC_HTCOMPAT; - break; - case LEAF_wlanIfaceDot11nHTProtMode: - op = IEEE80211_IOC_HTPROTMODE; - break; - case LEAF_wlanIfaceDot11nRIFS: - op = IEEE80211_IOC_RIFS; - break; - case LEAF_wlanIfaceDot11nShortGI: - op = IEEE80211_IOC_SHORTGI; - break; - case LEAF_wlanIfaceDot11nSMPSMode: - op = IEEE80211_IOC_SMPS; - break; - case LEAF_wlanIfaceTdmaSlot: - op = IEEE80211_IOC_TDMA_SLOT; - break; - case LEAF_wlanIfaceTdmaSlotCount: - op = IEEE80211_IOC_TDMA_SLOTCNT; - break; - case LEAF_wlanIfaceTdmaSlotLength: - op = IEEE80211_IOC_TDMA_SLOTLEN; - break; - case LEAF_wlanIfaceTdmaBeaconInterval: - op = IEEE80211_IOC_TDMA_BINTERVAL; - break; - default: - op = -1; - } - - return (op); -} - -static enum WlanRegDomainCode -wlan_regdomain_to_snmp(int which) -{ - enum WlanRegDomainCode reg_domain; - - switch (which) { - case SKU_FCC: - reg_domain = WlanRegDomainCode_fcc; - break; - case SKU_CA: - reg_domain = WlanRegDomainCode_ca; - break; - case SKU_ETSI: - reg_domain = WlanRegDomainCode_etsi; - break; - case SKU_ETSI2: - reg_domain = WlanRegDomainCode_etsi2; - break; - case SKU_ETSI3: - reg_domain = WlanRegDomainCode_etsi3; - break; - case SKU_FCC3: - reg_domain = WlanRegDomainCode_fcc3; - break; - case SKU_JAPAN: - reg_domain = WlanRegDomainCode_japan; - break; - case SKU_KOREA: - reg_domain = WlanRegDomainCode_korea; - break; - case SKU_APAC: - reg_domain = WlanRegDomainCode_apac; - break; - case SKU_APAC2: - reg_domain = WlanRegDomainCode_apac2; - break; - case SKU_APAC3: - reg_domain = WlanRegDomainCode_apac3; - break; - case SKU_ROW: - reg_domain = WlanRegDomainCode_row; - break; - case SKU_NONE: - reg_domain = WlanRegDomainCode_none; - break; - case SKU_DEBUG: - reg_domain = WlanRegDomainCode_debug; - break; - case SKU_SR9: - reg_domain = WlanRegDomainCode_sr9; - break; - case SKU_XR9: - reg_domain = WlanRegDomainCode_xr9; - break; - case SKU_GZ901: - reg_domain = WlanRegDomainCode_gz901; - break; - case 0: - reg_domain = WlanRegDomainCode_none; - break; - default: - syslog(LOG_ERR, "unknown regdomain (0x%x) ", which); - reg_domain = WlanRegDomainCode_none; - break; - } - - return (reg_domain); -} - -static int -wlan_snmp_to_regdomain(enum WlanRegDomainCode regdomain) -{ - int which; - - switch (regdomain) { - case WlanRegDomainCode_fcc: - which = SKU_FCC; - break; - case WlanRegDomainCode_ca: - which = SKU_CA; - break; - case WlanRegDomainCode_etsi: - which = SKU_ETSI; - break; - case WlanRegDomainCode_etsi2: - which = SKU_ETSI2; - break; - case WlanRegDomainCode_etsi3: - which = SKU_ETSI3; - break; - case WlanRegDomainCode_fcc3: - which = SKU_FCC3; - break; - case WlanRegDomainCode_japan: - which = SKU_JAPAN; - break; - case WlanRegDomainCode_korea: - which = SKU_KOREA; - break; - case WlanRegDomainCode_apac: - which = SKU_APAC; - break; - case WlanRegDomainCode_apac2: - which = SKU_APAC2; - break; - case WlanRegDomainCode_apac3: - which = SKU_APAC3; - break; - case WlanRegDomainCode_row: - which = SKU_ROW; - break; - case WlanRegDomainCode_none: - which = SKU_NONE; - break; - case WlanRegDomainCode_debug: - which = SKU_DEBUG; - break; - case WlanRegDomainCode_sr9: - which = SKU_SR9; - break; - case WlanRegDomainCode_xr9: - which = SKU_XR9; - break; - case WlanRegDomainCode_gz901: - which = SKU_GZ901; - break; - default: - syslog(LOG_ERR, "unknown snmp regdomain (0x%x) ", regdomain); - which = SKU_NONE; - break; - } - - return (which); -} - -static int -wlan_config_get_country(struct wlan_iface *wif) -{ - int val = 0; - size_t argsize; - struct ieee80211_regdomain regdomain; - - memset(®domain, 0, sizeof(regdomain)); - argsize = sizeof(regdomain); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_REGDOMAIN, &val, ®domain, - &argsize, 0) < 0) - return (-1); - - wif->reg_domain = wlan_regdomain_to_snmp(regdomain.regdomain); - wif->country_code[0] = regdomain.isocc[0]; - wif->country_code[1] = regdomain.isocc[1]; - wif->country_code[2] = regdomain.location; - - return (0); -} - -static int -wlan_config_set_country(struct wlan_iface *wif, char *ccode, int rdomain) -{ - int val = 0, txpowermax; - uint32_t i; - size_t argsize = 0; - struct ieee80211_regdomain_req *regdomain; - - if (wlan_get_channel_list(wif) < 0) - return (-1); - - if (wif->nchannels == 0) { - syslog(LOG_ERR, "iface %s - set regdomain failed", wif->wname); - return (-1); - } - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_TXPOWMAX, &txpowermax, 0, - &argsize, 0) < 0) - return (-1); - - regdomain = malloc(IEEE80211_REGDOMAIN_SIZE(wif->nchannels)); - if (regdomain == NULL) - return (-1); - memset(regdomain, 0, IEEE80211_REGDOMAIN_SIZE(wif->nchannels)); - argsize = IEEE80211_REGDOMAIN_SIZE(wif->nchannels); - - /* XXX: recheck with how this is done by ifconfig(8) */ - regdomain->rd.regdomain = wlan_snmp_to_regdomain(rdomain); - regdomain->rd.isocc[0] = ccode[0]; - regdomain->rd.isocc[1] = ccode[1]; - regdomain->rd.location = ccode[2]; - - /* XXX: fill the channel list properly */ - regdomain->chaninfo.ic_nchans = wif->nchannels; - memcpy(regdomain->chaninfo.ic_chans, wif->chanlist, - wif->nchannels * sizeof(struct ieee80211_channel)); - for (i = 0; i < wif->nchannels; i++) - regdomain->chaninfo.ic_chans[i].ic_maxregpower = txpowermax; - - wif->state = wlanIfaceState_down; - if (wlan_config_state(wif, 1) < 0 || - wlan_ioctl(wif->wname, IEEE80211_IOC_REGDOMAIN, &val, regdomain, - &argsize, 1) < 0) { - free(regdomain); - return (-1); - } - - wif->state = wlanIfaceState_up; - (void)wlan_config_state(wif, 1); - wif->reg_domain = wlan_regdomain_to_snmp(regdomain->rd.regdomain); - wif->country_code[0] = regdomain->rd.isocc[0]; - wif->country_code[1] = regdomain->rd.isocc[1]; - wif->country_code[2] = regdomain->rd.location; - free(regdomain); - - return (0); -} - -int -wlan_config_get_dssid(struct wlan_iface *wif) -{ - int val = -1; - size_t argsize = IEEE80211_NWID_LEN + 1; - char ssid[IEEE80211_NWID_LEN + 1]; - - memset(ssid, 0, IEEE80211_NWID_LEN + 1); - - if (wlan_ioctl(wif->wname, - (wif->mode == WlanIfaceOperatingModeType_meshPoint) ? - IEEE80211_IOC_MESH_ID : IEEE80211_IOC_SSID, &val, ssid, - &argsize, 0) < 0) - return (-1); - - if (argsize > IEEE80211_NWID_LEN) - argsize = IEEE80211_NWID_LEN; - memcpy(wif->desired_ssid, ssid, argsize); - wif->desired_ssid[argsize] = '\0'; - - return (0); -} - -int -wlan_config_set_dssid(struct wlan_iface *wif, char *ssid, int slen) -{ - int val = 0; - size_t argsize = slen; - - if (wlan_ioctl(wif->wname, - (wif->mode == WlanIfaceOperatingModeType_meshPoint) ? - IEEE80211_IOC_MESH_ID : IEEE80211_IOC_SSID, &val, ssid, - &argsize, 1) < 0) - return (-1); - - if (argsize > IEEE80211_NWID_LEN) - argsize = IEEE80211_NWID_LEN; - memcpy(wif->desired_ssid, ssid, argsize); - wif->desired_ssid[argsize] = '\0'; - - return (0); -} - -static int -wlan_config_get_dchannel(struct wlan_iface *wif) -{ - uint32_t i = 0; - int val = 0; - size_t argsize = sizeof(struct ieee80211_channel); - struct ieee80211_channel chan; - - if (wlan_get_channel_list(wif) < 0) - return (-1); - - memset(&chan, 0, sizeof(chan)); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_CURCHAN, &val, &chan, - &argsize, 0) < 0) - return (-1); - - for (i = 0; i < wif->nchannels; i++) - if (chan.ic_ieee == wif->chanlist[i].ic_ieee && - chan.ic_flags == wif->chanlist[i].ic_flags) { - wif->desired_channel = i + 1; - break; - } - - return (0); -} - -static int -wlan_config_set_dchannel(struct wlan_iface *wif, uint32_t dchannel) -{ - int val = 0; - size_t argsize = sizeof(struct ieee80211_channel); - struct ieee80211_channel chan; - - if (wlan_get_channel_list(wif) < 0) - return (-1); - - if (dchannel > wif->nchannels) - return (-1); - - memcpy(&chan, wif->chanlist + dchannel - 1, sizeof(chan)); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_CURCHAN, &val, &chan, - &argsize, 1) < 0) - return (-1); - - wif->desired_channel = dchannel; - - return (0); -} - -static int -wlan_config_get_bssid(struct wlan_iface *wif) -{ - int val = 0; - size_t argsize = IEEE80211_ADDR_LEN; - char bssid[IEEE80211_ADDR_LEN]; - - memset(bssid, 0, IEEE80211_ADDR_LEN); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_BSSID, &val, bssid, - &argsize, 0) < 0 || argsize != IEEE80211_ADDR_LEN) - return (-1); - - memcpy(wif->desired_bssid, bssid, IEEE80211_ADDR_LEN); - - return (0); -} - -static int -wlan_config_set_bssid(struct wlan_iface *wif, uint8_t *bssid) -{ - int val = 0; - size_t argsize = IEEE80211_ADDR_LEN; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_BSSID, &val, bssid, - &argsize, 1) < 0 || argsize != IEEE80211_ADDR_LEN) - return (-1); - - memcpy(wif->desired_bssid, bssid, IEEE80211_ADDR_LEN); - - return (0); -} - -/* - * Convert the value returned by the kernel to the appropriate SNMP - * representation and set the corresponding interface member accordingly. - */ -static void -wlan_config_set_snmp_intval(struct wlan_iface *wif, int op, int val) -{ - switch (op) { - case IEEE80211_IOC_BURST: - if (val == 0) - wif->packet_burst = TruthValue_false; - else - wif->packet_burst = TruthValue_true; - break; - case IEEE80211_IOC_DFS: - if (val == 0) - wif->dyn_frequency = TruthValue_false; - else - wif->dyn_frequency = TruthValue_true; - break; - case IEEE80211_IOC_FF: - if (val == 0) - wif->fast_frames = TruthValue_false; - else - wif->fast_frames = TruthValue_true; - break; - case IEEE80211_IOC_TURBOP: - if (val == 0) - wif->dturbo = TruthValue_false; - else - wif->dturbo = TruthValue_true; - break; - case IEEE80211_IOC_TXPOWER: - wif->tx_power = val / 2; - break; - case IEEE80211_IOC_FRAGTHRESHOLD: - wif->frag_threshold = val; - break; - case IEEE80211_IOC_RTSTHRESHOLD: - wif->rts_threshold = val; - break; - case IEEE80211_IOC_WPS: - if (val == 0) - wif->priv_subscribe = TruthValue_false; - else - wif->priv_subscribe = TruthValue_true; - break; - case IEEE80211_IOC_BGSCAN: - if (val == 0) - wif->bg_scan = TruthValue_false; - else - wif->bg_scan = TruthValue_true; - break; - case IEEE80211_IOC_BGSCAN_IDLE: - wif->bg_scan_idle = val; - break; - case IEEE80211_IOC_BGSCAN_INTERVAL: - wif->bg_scan_interval = val; - break; - case IEEE80211_IOC_BMISSTHRESHOLD: - wif->beacons_missed = val; - break; - case IEEE80211_IOC_ROAMING: - switch (val) { - case IEEE80211_ROAMING_DEVICE: - wif->roam_mode = wlanIfaceRoamingMode_device; - break; - case IEEE80211_ROAMING_MANUAL: - wif->roam_mode = wlanIfaceRoamingMode_manual; - break; - case IEEE80211_ROAMING_AUTO: - /* FALTHROUGH */ - default: - wif->roam_mode = wlanIfaceRoamingMode_auto; - break; - } - break; - case IEEE80211_IOC_DOTD: - if (val == 0) - wif->dot11d = TruthValue_false; - else - wif->dot11d = TruthValue_true; - break; - case IEEE80211_IOC_DOTH: - if (val == 0) - wif->dot11h = TruthValue_false; - else - wif->dot11h = TruthValue_true; - break; - case IEEE80211_IOC_DWDS: - if (val == 0) - wif->dynamic_wds = TruthValue_false; - else - wif->dynamic_wds = TruthValue_true; - break; - case IEEE80211_IOC_POWERSAVE: - if (val == 0) - wif->power_save = TruthValue_false; - else - wif->power_save = TruthValue_true; - break; - case IEEE80211_IOC_APBRIDGE: - if (val == 0) - wif->ap_bridge = TruthValue_false; - else - wif->ap_bridge = TruthValue_true; - break; - case IEEE80211_IOC_BEACON_INTERVAL: - wif->beacon_interval = val; - break; - case IEEE80211_IOC_DTIM_PERIOD: - wif->dtim_period = val; - break; - case IEEE80211_IOC_HIDESSID: - if (val == 0) - wif->hide_ssid = TruthValue_false; - else - wif->hide_ssid = TruthValue_true; - break; - case IEEE80211_IOC_INACTIVITY: - if (val == 0) - wif->inact_process = TruthValue_false; - else - wif->inact_process = TruthValue_true; - break; - case IEEE80211_IOC_PROTMODE: - switch (val) { - case IEEE80211_PROTMODE_CTS: - wif->do11g_protect = wlanIfaceDot11gProtMode_cts; - break; - case IEEE80211_PROTMODE_RTSCTS: - wif->do11g_protect = wlanIfaceDot11gProtMode_rtscts; - break; - case IEEE80211_PROTMODE_OFF: - /* FALLTHROUGH */ - default: - wif->do11g_protect = wlanIfaceDot11gProtMode_off; - break; - } - break; - case IEEE80211_IOC_PUREG: - if (val == 0) - wif->dot11g_pure = TruthValue_false; - else - wif->dot11g_pure = TruthValue_true; - break; - case IEEE80211_IOC_PUREN: - if (val == 0) - wif->dot11n_pure = TruthValue_false; - else - wif->dot11n_pure = TruthValue_true; - break; - case IEEE80211_IOC_AMPDU: - switch (val) { - case 0: - wif->ampdu = WlanIfaceDot11nPduType_disabled; - break; - case 1: - wif->ampdu = WlanIfaceDot11nPduType_txOnly; - break; - case 2: - wif->ampdu = WlanIfaceDot11nPduType_rxOnly; - break; - case 3: - /* FALLTHROUGH */ - default: - wif->ampdu = WlanIfaceDot11nPduType_txAndRx; - break; - } - break; - case IEEE80211_IOC_AMPDU_DENSITY: - switch (val) { - case IEEE80211_HTCAP_MPDUDENSITY_025: - wif->ampdu_density = 25; - break; - case IEEE80211_HTCAP_MPDUDENSITY_05: - wif->ampdu_density = 50; - break; - case IEEE80211_HTCAP_MPDUDENSITY_1: - wif->ampdu_density = 100; - break; - case IEEE80211_HTCAP_MPDUDENSITY_2: - wif->ampdu_density = 200; - break; - case IEEE80211_HTCAP_MPDUDENSITY_4: - wif->ampdu_density = 400; - break; - case IEEE80211_HTCAP_MPDUDENSITY_8: - wif->ampdu_density = 800; - break; - case IEEE80211_HTCAP_MPDUDENSITY_16: - wif->ampdu_density = 1600; - break; - case IEEE80211_HTCAP_MPDUDENSITY_NA: - default: - wif->ampdu_density = 0; - break; - } - break; - case IEEE80211_IOC_AMPDU_LIMIT: - switch (val) { - case IEEE80211_HTCAP_MAXRXAMPDU_8K: - wif->ampdu_limit = 8192; - break; - case IEEE80211_HTCAP_MAXRXAMPDU_16K: - wif->ampdu_limit = 16384; - break; - case IEEE80211_HTCAP_MAXRXAMPDU_32K: - wif->ampdu_limit = 32768; - break; - case IEEE80211_HTCAP_MAXRXAMPDU_64K: - default: - wif->ampdu_limit = 65536; - break; - } - break; - case IEEE80211_IOC_AMSDU: - switch (val) { - case 0: - wif->amsdu = WlanIfaceDot11nPduType_disabled; - break; - case 1: - wif->amsdu = WlanIfaceDot11nPduType_txOnly; - break; - case 3: - wif->amsdu = WlanIfaceDot11nPduType_txAndRx; - break; - case 2: - default: - /* FALLTHROUGH */ - wif->amsdu = WlanIfaceDot11nPduType_rxOnly; - break; - } - break; - case IEEE80211_IOC_AMSDU_LIMIT: - wif->amsdu_limit = val; - break; - case IEEE80211_IOC_HTCONF: - if (val == 0) /* XXX */ - wif->ht_enabled = TruthValue_false; - else - wif->ht_enabled = TruthValue_true; - break; - case IEEE80211_IOC_HTCOMPAT: - if (val == 0) - wif->ht_compatible = TruthValue_false; - else - wif->ht_compatible = TruthValue_true; - break; - case IEEE80211_IOC_HTPROTMODE: - if (val == IEEE80211_PROTMODE_RTSCTS) - wif->ht_prot_mode = wlanIfaceDot11nHTProtMode_rts; - else - wif->ht_prot_mode = wlanIfaceDot11nHTProtMode_off; - break; - case IEEE80211_IOC_RIFS: - if (val == 0) - wif->rifs = TruthValue_false; - else - wif->rifs = TruthValue_true; - break; - case IEEE80211_IOC_SHORTGI: - if (val == 0) - wif->short_gi = TruthValue_false; - else - wif->short_gi = TruthValue_true; - break; - case IEEE80211_IOC_SMPS: - switch (val) { - case IEEE80211_HTCAP_SMPS_DYNAMIC: - wif->smps_mode = wlanIfaceDot11nSMPSMode_dynamic; - break; - case IEEE80211_HTCAP_SMPS_ENA: - wif->smps_mode = wlanIfaceDot11nSMPSMode_static; - break; - case IEEE80211_HTCAP_SMPS_OFF: - /* FALLTHROUGH */ - default: - wif->smps_mode = wlanIfaceDot11nSMPSMode_disabled; - break; - } - break; - case IEEE80211_IOC_TDMA_SLOT: - wif->tdma_slot = val; - break; - case IEEE80211_IOC_TDMA_SLOTCNT: - wif->tdma_slot_count = val; - break; - case IEEE80211_IOC_TDMA_SLOTLEN: - wif->tdma_slot_length = val; - break; - case IEEE80211_IOC_TDMA_BINTERVAL: - wif->tdma_binterval = val; - break; - default: - break; - } -} - -/* - * Convert an SNMP value to the kernel equivalent and also do sanity check - * for each specific type. - */ -static int -wlan_config_snmp2value(int which, int sval, int *value) -{ - *value = 0; - - switch (which) { - case IEEE80211_IOC_BURST: - case IEEE80211_IOC_DFS: - case IEEE80211_IOC_FF: - case IEEE80211_IOC_TURBOP: - case IEEE80211_IOC_WPS: - case IEEE80211_IOC_BGSCAN: - case IEEE80211_IOC_DOTD: - case IEEE80211_IOC_DOTH: - case IEEE80211_IOC_DWDS: - case IEEE80211_IOC_POWERSAVE: - case IEEE80211_IOC_APBRIDGE: - case IEEE80211_IOC_HIDESSID: - case IEEE80211_IOC_INACTIVITY: - case IEEE80211_IOC_PUREG: - case IEEE80211_IOC_PUREN: - case IEEE80211_IOC_HTCONF: - case IEEE80211_IOC_HTCOMPAT: - case IEEE80211_IOC_RIFS: - if (sval == TruthValue_true) - *value = 1; - else if (sval != TruthValue_false) - return (SNMP_ERR_INCONS_VALUE); - break; - case IEEE80211_IOC_REGDOMAIN: - break; - case IEEE80211_IOC_SSID: - break; - case IEEE80211_IOC_CURCHAN: - break; - case IEEE80211_IOC_TXPOWER: - *value = sval * 2; - break; - case IEEE80211_IOC_FRAGTHRESHOLD: - if (sval < IEEE80211_FRAG_MIN || sval > IEEE80211_FRAG_MAX) - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_RTSTHRESHOLD: - if (sval < IEEE80211_RTS_MIN || sval > IEEE80211_RTS_MAX) - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_BGSCAN_IDLE: - if (sval < WLAN_BGSCAN_IDLE_MIN) - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_BGSCAN_INTERVAL: - if (sval < WLAN_SCAN_VALID_MIN) - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_BMISSTHRESHOLD: - if (sval < IEEE80211_HWBMISS_MIN || sval > IEEE80211_HWBMISS_MAX) - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_BSSID: - break; - case IEEE80211_IOC_ROAMING: - switch (sval) { - case wlanIfaceRoamingMode_device: - *value = IEEE80211_ROAMING_DEVICE; - break; - case wlanIfaceRoamingMode_manual: - *value = IEEE80211_ROAMING_MANUAL; - break; - case wlanIfaceRoamingMode_auto: - *value = IEEE80211_ROAMING_AUTO; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_BEACON_INTERVAL: - if (sval < IEEE80211_BINTVAL_MIN || sval > IEEE80211_BINTVAL_MAX) - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_DTIM_PERIOD: - if (sval < IEEE80211_DTIM_MIN || sval > IEEE80211_DTIM_MAX) - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_PROTMODE: - switch (sval) { - case wlanIfaceDot11gProtMode_cts: - *value = IEEE80211_PROTMODE_CTS; - break; - case wlanIfaceDot11gProtMode_rtscts: - *value = IEEE80211_PROTMODE_RTSCTS; - break; - case wlanIfaceDot11gProtMode_off: - *value = IEEE80211_PROTMODE_OFF; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_AMPDU: - switch (sval) { - case WlanIfaceDot11nPduType_disabled: - break; - case WlanIfaceDot11nPduType_txOnly: - *value = 1; - break; - case WlanIfaceDot11nPduType_rxOnly: - *value = 2; - break; - case WlanIfaceDot11nPduType_txAndRx: - *value = 3; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_AMPDU_DENSITY: - switch (sval) { - case 0: - *value = IEEE80211_HTCAP_MPDUDENSITY_NA; - break; - case 25: - *value = IEEE80211_HTCAP_MPDUDENSITY_025; - break; - case 50: - *value = IEEE80211_HTCAP_MPDUDENSITY_05; - break; - case 100: - *value = IEEE80211_HTCAP_MPDUDENSITY_1; - break; - case 200: - *value = IEEE80211_HTCAP_MPDUDENSITY_2; - break; - case 400: - *value = IEEE80211_HTCAP_MPDUDENSITY_4; - break; - case 800: - *value = IEEE80211_HTCAP_MPDUDENSITY_8; - break; - case 1600: - *value = IEEE80211_HTCAP_MPDUDENSITY_16; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_AMPDU_LIMIT: - switch (sval) { - case 8192: - *value = IEEE80211_HTCAP_MAXRXAMPDU_8K; - break; - case 16384: - *value = IEEE80211_HTCAP_MAXRXAMPDU_16K; - break; - case 32768: - *value = IEEE80211_HTCAP_MAXRXAMPDU_32K; - break; - case 65536: - *value = IEEE80211_HTCAP_MAXRXAMPDU_64K; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_AMSDU: - switch (sval) { - case WlanIfaceDot11nPduType_disabled: - break; - case WlanIfaceDot11nPduType_txOnly: - *value = 1; - break; - case WlanIfaceDot11nPduType_rxOnly: - *value = 2; - break; - case WlanIfaceDot11nPduType_txAndRx: - *value = 3; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_AMSDU_LIMIT: - if (sval == 3839 || sval == 0) - *value = IEEE80211_HTCAP_MAXAMSDU_3839; - else if (sval == 7935) - *value = IEEE80211_HTCAP_MAXAMSDU_7935; - else - return (SNMP_ERR_INCONS_VALUE); - break; - case IEEE80211_IOC_HTPROTMODE: - switch (sval) { - case wlanIfaceDot11nHTProtMode_rts: - *value = IEEE80211_PROTMODE_RTSCTS; - break; - case wlanIfaceDot11nHTProtMode_off: - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_SHORTGI: - if (sval == TruthValue_true) - *value = IEEE80211_HTCAP_SHORTGI20 | - IEEE80211_HTCAP_SHORTGI40; - else if (sval != TruthValue_false) - return (SNMP_ERR_INCONS_VALUE); - break; - case IEEE80211_IOC_SMPS: - switch (sval) { - case wlanIfaceDot11nSMPSMode_disabled: - *value = IEEE80211_HTCAP_SMPS_OFF; - break; - case wlanIfaceDot11nSMPSMode_static: - *value = IEEE80211_HTCAP_SMPS_ENA; - break; - case wlanIfaceDot11nSMPSMode_dynamic: - *value = IEEE80211_HTCAP_SMPS_DYNAMIC; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - break; - case IEEE80211_IOC_TDMA_SLOT: - if (sval < 0 || sval > WLAN_TDMA_MAXSLOTS) /* XXX */ - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_TDMA_SLOTCNT: - if (sval < 0 || sval > WLAN_TDMA_MAXSLOTS) /* XXX */ - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_TDMA_SLOTLEN: - if (sval < 2*100 || sval > 0xfffff) /* XXX */ - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - case IEEE80211_IOC_TDMA_BINTERVAL: - if (sval < 1) /* XXX */ - return (SNMP_ERR_INCONS_VALUE); - *value = sval; - break; - default: - return (SNMP_ERR_INCONS_VALUE); - } - - return (SNMP_ERR_NOERROR); -} - -/* - * Sanity checks for the wlanIfaceConfigTable. - */ -static int -wlan_config_check(struct wlan_iface *wif, int op) -{ - switch (op) { - case IEEE80211_IOC_BURST: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_burst)) == 0) { - wif->packet_burst = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_DFS: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_dfs)) == 0) { - wif->dyn_frequency = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_FF: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_athFastFrames)) - == 0) { - wif->fast_frames = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_TURBOP: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_athTurbo)) == 0) { - wif->dturbo = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_TXPOWER: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_txPmgt)) == 0) { - wif->tx_power = 0; - return (-1); - } - break; - case IEEE80211_IOC_FRAGTHRESHOLD: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_txFrag)) == 0) { - wif->frag_threshold = IEEE80211_FRAG_MAX; - return (-1); - } - break; - case IEEE80211_IOC_DWDS: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_wds)) == 0) { - wif->dynamic_wds = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_POWERSAVE: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_pmgt)) == 0) { - wif->power_save = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_BEACON_INTERVAL: - if (wif->mode != WlanIfaceOperatingModeType_hostAp && - wif->mode != WlanIfaceOperatingModeType_meshPoint && - wif->mode != WlanIfaceOperatingModeType_ibss) { - wif->beacon_interval = 100; /* XXX */ - return (-1); - } - break; - case IEEE80211_IOC_DTIM_PERIOD: - if (wif->mode != WlanIfaceOperatingModeType_hostAp && - wif->mode != WlanIfaceOperatingModeType_meshPoint && - wif->mode != WlanIfaceOperatingModeType_ibss) { - wif->dtim_period = 1; /* XXX */ - return (-1); - } - break; - case IEEE80211_IOC_PUREN: - if ((wif->htcaps & (0x1 << WlanHTCaps_htcHt)) == 0) { - wif->dot11n_pure = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_AMPDU: - if ((wif->htcaps & (0x1 << WlanHTCaps_htcAmpdu)) == 0) { - wif->ampdu = WlanIfaceDot11nPduType_disabled; - return (-1); - } - break; - case IEEE80211_IOC_AMSDU: - if ((wif->htcaps & (0x1 << WlanHTCaps_htcAmsdu)) == 0) { - wif->amsdu = WlanIfaceDot11nPduType_disabled; - return (-1); - } - break; - case IEEE80211_IOC_RIFS: - if ((wif->htcaps & (0x1 << WlanHTCaps_htcRifs)) == 0) { - wif->rifs = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_SHORTGI: - if ((wif->htcaps & (0x1 << WlanHTCaps_shortGi20 | - 0x1 << WlanHTCaps_shortGi40)) == 0) { - wif->short_gi = TruthValue_false; - return (-1); - } - break; - case IEEE80211_IOC_SMPS: - if ((wif->htcaps & (0x1 << WlanHTCaps_htcSmps)) == 0) { - wif->smps_mode = wlanIfaceDot11nSMPSMode_disabled; - return (-1); - } - break; - case IEEE80211_IOC_TDMA_SLOT: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_tdma)) == 0) { - wif->tdma_slot = 0; - return (-1); - } - break; - case IEEE80211_IOC_TDMA_SLOTCNT: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_tdma)) == 0) { - wif->tdma_slot_count = 0; - return (-1); - } - break; - case IEEE80211_IOC_TDMA_SLOTLEN: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_tdma)) == 0) { - wif->tdma_slot_length = 0; - return (-1); - } - break; - case IEEE80211_IOC_TDMA_BINTERVAL: - if ((wif->drivercaps & (0x1 << WlanDriverCaps_tdma)) == 0) { - wif->tdma_binterval = 0; - return (-1); - } - break; - default: - break; - } - - return (0); -} - -static int -wlan_config_get_intval(struct wlan_iface *wif, int op) -{ - int val = 0; - size_t argsize = 0; - - if (wlan_config_check(wif, op) < 0) - return (0); - if (wlan_ioctl(wif->wname, op, &val, NULL, &argsize, 0) < 0) - return (-1); - wlan_config_set_snmp_intval(wif, op, val); - - return (0); -} - -static int -wlan_config_set_intval(struct wlan_iface *wif, int op, int sval) -{ - size_t argsize = 0; - int val; - - if (wlan_config_check(wif, op) < 0) - return (-1); - if (wlan_config_snmp2value(op, sval, &val) != SNMP_ERR_NOERROR) - return (-1); - if (wlan_ioctl(wif->wname, op, &val, NULL, &argsize, 1) < 0) - return (-1); - wlan_config_set_snmp_intval(wif, op, val); - - return (0); -} - -int -wlan_config_get_ioctl(struct wlan_iface *wif, int which) -{ - int op; - - switch (which) { - case LEAF_wlanIfaceCountryCode: - /* FALLTHROUGH */ - case LEAF_wlanIfaceRegDomain: - return (wlan_config_get_country(wif)); - case LEAF_wlanIfaceDesiredSsid: - return (wlan_config_get_dssid(wif)); - case LEAF_wlanIfaceDesiredChannel: - return (wlan_config_get_dchannel(wif)); - case LEAF_wlanIfaceDesiredBssid: - return (wlan_config_get_bssid(wif)); - default: - op = wlan_config_snmp2ioctl(which); - return (wlan_config_get_intval(wif, op)); - } - - return (-1); -} - -int -wlan_config_set_ioctl(struct wlan_iface *wif, int which, int val, - char *strval, int len) -{ - int op; - - switch (which) { - case LEAF_wlanIfaceCountryCode: - return (wlan_config_set_country(wif, strval, - wif->reg_domain)); - case LEAF_wlanIfaceRegDomain: - return (wlan_config_set_country(wif, wif->country_code, - val)); - case LEAF_wlanIfaceDesiredSsid: - return (wlan_config_set_dssid(wif, strval, len)); - case LEAF_wlanIfaceDesiredChannel: - return (wlan_config_set_dchannel(wif, val)); - case LEAF_wlanIfaceDesiredBssid: - return (wlan_config_set_bssid(wif, strval)); - default: - op = wlan_config_snmp2ioctl(which); - return (wlan_config_set_intval(wif, op, val)); - } - - return (-1); -} - -static uint32_t -wlan_snmp_to_scan_flags(int flags) -{ - int sr_flags = 0; - - if ((flags & (0x1 << WlanScanFlagsType_noSelection)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_NOPICK; - if ((flags & (0x1 << WlanScanFlagsType_activeScan)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_ACTIVE; - if ((flags & (0x1 << WlanScanFlagsType_pickFirst)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_PICK1ST; - if ((flags & (0x1 << WlanScanFlagsType_backgroundScan)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_BGSCAN; - if ((flags & (0x1 << WlanScanFlagsType_once)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_ONCE; - if ((flags & (0x1 << WlanScanFlagsType_noBroadcast)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_NOBCAST; - if ((flags & (0x1 << WlanScanFlagsType_noAutoSequencing)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_NOJOIN; - if ((flags & (0x1 << WlanScanFlagsType_flushCashe)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_FLUSH; - if ((flags & (0x1 << WlanScanFlagsType_chechCashe)) != 0) - sr_flags |= IEEE80211_IOC_SCAN_CHECK; - - return (sr_flags); -} - -int -wlan_set_scan_config(struct wlan_iface *wif) -{ - int val = 0; - size_t argsize; - struct ieee80211_scan_req sr; - - - memset(&sr, 0, sizeof(sr)); - argsize = sizeof(struct ieee80211_scan_req); - sr.sr_flags = wlan_snmp_to_scan_flags(wif->scan_flags); - sr.sr_flags |= IEEE80211_IOC_SCAN_BGSCAN; - sr.sr_duration = wif->scan_duration; - sr.sr_mindwell = wif->scan_mindwell; - sr.sr_maxdwell = wif->scan_maxdwell; - sr.sr_nssid = 0; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_SCAN_REQ, - &val, &sr, &argsize, 1) < 0) - return (-1); - - wif->scan_status = wlanScanConfigStatus_running; - return (0); -} - -static uint32_t -wlan_peercaps_to_snmp(uint32_t pcaps) -{ - uint32_t scaps = 0; - - if ((pcaps & IEEE80211_CAPINFO_ESS) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_ess); - if ((pcaps & IEEE80211_CAPINFO_IBSS) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_ibss); - if ((pcaps & IEEE80211_CAPINFO_CF_POLLABLE) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_cfPollable); - if ((pcaps & IEEE80211_CAPINFO_CF_POLLREQ) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_cfPollRequest); - if ((pcaps & IEEE80211_CAPINFO_PRIVACY) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_privacy); - if ((pcaps & IEEE80211_CAPINFO_SHORT_PREAMBLE) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_shortPreamble); - if ((pcaps & IEEE80211_CAPINFO_PBCC) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_pbcc); - if ((pcaps & IEEE80211_CAPINFO_CHNL_AGILITY) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_channelAgility); - if ((pcaps & IEEE80211_CAPINFO_SHORT_SLOTTIME) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_shortSlotTime); - if ((pcaps & IEEE80211_CAPINFO_RSN) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_rsn); - if ((pcaps & IEEE80211_CAPINFO_DSSSOFDM) != 0) - scaps |= (0x1 << WlanPeerCapabilityFlags_dsssofdm); - - return (scaps); -} - -static int -wlan_add_new_scan_result(struct wlan_iface *wif, - const struct ieee80211req_scan_result *isr, uint8_t *ssid) -{ - struct wlan_scan_result *sr; - - if ((sr = wlan_scan_new_result(ssid, isr->isr_bssid)) == NULL) - return (-1); - - sr->opchannel = wlan_channel_flags_to_snmp_phy(isr->isr_flags); - sr->rssi = isr->isr_rssi; - sr->frequency = isr->isr_freq; - sr->noise = isr->isr_noise; - sr->bintval = isr->isr_intval; - sr->capinfo = wlan_peercaps_to_snmp(isr->isr_capinfo); - - if (wlan_scan_add_result(wif, sr) < 0) { - wlan_scan_free_result(sr); - return (-1); - } - - return (0); -} - -int -wlan_get_scan_results(struct wlan_iface *wif) -{ - int ssidlen, val = 0; - uint8_t buf[24 * 1024]; - size_t argsize; - const uint8_t *cp, *idp; - uint8_t ssid[IEEE80211_NWID_LEN + 1]; - struct ieee80211req_scan_result isr; - - argsize = sizeof(buf); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_SCAN_RESULTS, &val, &buf, - &argsize, 0) < 0) - return (-1); - - if (argsize < sizeof(struct ieee80211req_scan_result)) - return (0); - - cp = buf; - do { - memcpy(&isr, cp, sizeof(struct ieee80211req_scan_result)); - memset(ssid, 0, IEEE80211_NWID_LEN + 1); - - if (isr.isr_meshid_len) { - idp = cp + isr.isr_ie_off + isr.isr_ssid_len; - ssidlen = isr.isr_meshid_len; - } else { - idp = cp + isr.isr_ie_off; - ssidlen = isr.isr_ssid_len; - } - if (ssidlen > IEEE80211_NWID_LEN) - ssidlen = IEEE80211_NWID_LEN; - memcpy(ssid, idp, ssidlen); - ssid[IEEE80211_NWID_LEN] = '\0'; - (void)wlan_add_new_scan_result(wif, &isr, ssid); - cp += isr.isr_len; - argsize -= isr.isr_len; - } while (argsize >= sizeof(struct ieee80211req_scan_result)); - - return (0); -} - -int -wlan_get_stats(struct wlan_iface *wif) -{ - struct ifreq ifr; - - memset(&ifr, 0, sizeof(struct ifreq)); - strlcpy(ifr.ifr_name, wif->wname, IFNAMSIZ); - - ifr.ifr_data = (caddr_t) &wif->stats; - - if (ioctl(sock, SIOCG80211STATS, &ifr) < 0) { - syslog(LOG_ERR, "iface %s - ioctl(SIOCG80211STATS) failed: %s", - wif->wname, strerror(errno)); - return (-1); - } - - return (0); -} - -int -wlan_get_wepmode(struct wlan_iface *wif) -{ - int val = 0; - size_t argsize = 0; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_WEP, &val, NULL, - &argsize, 0) < 0 || val == IEEE80211_WEP_NOSUP) { - wif->wepsupported = 0; /* XXX */ - wif->wepmode = wlanWepMode_off; - wif->weptxkey = 0; - return (-1); - } - - wif->wepsupported = 1; - - switch (val) { - case IEEE80211_WEP_ON: - wif->wepmode = wlanWepMode_on; - break; - case IEEE80211_WEP_MIXED: - wif->wepmode = wlanWepMode_mixed; - break; - case IEEE80211_WEP_OFF: - /* FALLTHROUGH */ - default: - wif->wepmode = wlanWepMode_off; - break; - } - - return (0); -} - -int -wlan_set_wepmode(struct wlan_iface *wif) -{ - int val; - size_t argsize = 0; - - if (!wif->wepsupported) - return (-1); - - switch (wif->wepmode) { - case wlanWepMode_off: - val = IEEE80211_WEP_OFF; - break; - case wlanWepMode_on: - val = IEEE80211_WEP_ON; - break; - case wlanWepMode_mixed: - val = IEEE80211_WEP_MIXED; - break; - default: - return (-1); - } - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_WEP, &val, NULL, - &argsize, 1) < 0) - return (-1); - - return (0); -} - -int -wlan_get_weptxkey(struct wlan_iface *wif) -{ - int val; - size_t argsize = 0; - - if (!wif->wepsupported) - return (0); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_WEPTXKEY, &val, NULL, - &argsize, 0) < 0) - return (-1); - - if (val == IEEE80211_KEYIX_NONE) - wif->weptxkey = 0; - else - wif->weptxkey = val + 1; - - return (0); -} - -int -wlan_set_weptxkey(struct wlan_iface *wif) -{ - int val; - size_t argsize = 0; - - if (!wif->wepsupported) - return (0); - - if (wif->weptxkey >= IEEE80211_WEP_NKID) - return (-1); - - if (wif->weptxkey == 0) - val = IEEE80211_KEYIX_NONE; - else - val = wif->weptxkey - 1; - if (wlan_ioctl(wif->wname, IEEE80211_IOC_WEPTXKEY, &val, NULL, - &argsize, 1) < 0) - return (-1); - - return (0); -} - -int -wlan_get_wepkeys(struct wlan_iface *wif __unused) -{ - /* XXX: should they be visible via SNMP */ - return (0); -} - -int -wlan_set_wepkeys(struct wlan_iface *wif __unused) -{ - /* XXX: should they be configurable via SNMP */ - return (0); -} - -int -wlan_get_mac_policy(struct wlan_iface *wif) -{ - int val = IEEE80211_MACCMD_POLICY; - size_t argsize = 0; - struct ieee80211req ireq; - - memset(&ireq, 0, sizeof(struct ieee80211req)); - strlcpy(ireq.i_name, wif->wname, IFNAMSIZ); - ireq.i_type = IEEE80211_IOC_MACCMD; - ireq.i_val = IEEE80211_MACCMD_POLICY; - - if (ioctl(sock, SIOCG80211, &ireq) < 0) { - if (errno != EINVAL) { - syslog(LOG_ERR, "iface %s - get param: ioctl(%d) " - "failed: %s", wif->wname, ireq.i_type, - strerror(errno)); - wif->macsupported = 0; - return (-1); - } else { - wif->macsupported = 1; - wif->mac_policy = wlanMACAccessControlPolicy_open; - return (0); - } - - } - - wif->macsupported = 1; - - switch (val) { - case IEEE80211_MACCMD_POLICY_ALLOW: - wif->mac_policy = wlanMACAccessControlPolicy_allow; - break; - case IEEE80211_MACCMD_POLICY_DENY: - wif->mac_policy = wlanMACAccessControlPolicy_deny; - break; - case IEEE80211_MACCMD_POLICY_RADIUS: - wif->mac_policy = wlanMACAccessControlPolicy_radius; - break; - case IEEE80211_MACCMD_POLICY_OPEN: - /* FALLTHROUGH */ - default: - wif->mac_policy = wlanMACAccessControlPolicy_open; - break; - } - - argsize = 0; - val = IEEE80211_MACCMD_LIST; - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MACCMD, &val, NULL, - &argsize, 0) < 0) - return (-1); - - wif->mac_nacls = argsize / sizeof(struct ieee80211req_maclist *); - return (0); -} - -int -wlan_set_mac_policy(struct wlan_iface *wif) -{ - int val; - size_t argsize = 0; - - if (!wif->macsupported) - return (-1); - - switch (wif->mac_policy) { - case wlanMACAccessControlPolicy_allow: - val = IEEE80211_MACCMD_POLICY_ALLOW; - break; - case wlanMACAccessControlPolicy_deny: - val = IEEE80211_MACCMD_POLICY_DENY; - break; - case wlanMACAccessControlPolicy_radius: - val = IEEE80211_MACCMD_POLICY_RADIUS; - break; - case wlanMACAccessControlPolicy_open: - val = IEEE80211_MACCMD_POLICY_OPEN; - break; - default: - return (-1); - } - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MACCMD, &val, NULL, - &argsize, 1) < 0) - return (-1); - - return (0); -} - -int -wlan_flush_mac_mac(struct wlan_iface *wif) -{ - int val = IEEE80211_MACCMD_FLUSH; - size_t argsize = 0; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MACCMD, &val, NULL, - &argsize, 1) < 0) - return (-1); - - return (0); -} - -static int -wlan_add_mac_macinfo(struct wlan_iface *wif, - const struct ieee80211req_maclist *ml) -{ - struct wlan_mac_mac *mmac; - - if ((mmac = wlan_mac_new_mac(ml->ml_macaddr)) == NULL) - return (-1); - - mmac->mac_status = RowStatus_active; - if (wlan_mac_add_mac(wif, mmac) < 0) { - wlan_mac_free_mac(mmac); - return (-1); - } - - return (0); -} - -int -wlan_get_mac_acl_macs(struct wlan_iface *wif) -{ - int i, nacls, val = IEEE80211_MACCMD_LIST; - size_t argsize = 0; - uint8_t *data; - struct ieee80211req ireq; - const struct ieee80211req_maclist *acllist; - - if (wif->mac_policy == wlanMACAccessControlPolicy_radius) { - wif->mac_nacls = 0; - return (0); - } - - memset(&ireq, 0, sizeof(struct ieee80211req)); - strlcpy(ireq.i_name, wif->wname, IFNAMSIZ); - ireq.i_type = IEEE80211_IOC_MACCMD; - ireq.i_val = IEEE80211_MACCMD_LIST; - - - if (ioctl(sock, SIOCG80211, &ireq) < 0) { - if (errno != EINVAL) { - syslog(LOG_ERR, "iface %s - get param: ioctl(%d) " - "failed: %s", wif->wname, ireq.i_type, - strerror(errno)); - wif->macsupported = 0; - return (-1); - } - } - - if (argsize == 0) { - wif->mac_nacls = 0; - return (0); - } - - if ((data = (uint8_t *)malloc(argsize)) == NULL) - return (-1); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MACCMD, &val, data, - &argsize, 0) < 0) - return (-1); - - nacls = argsize / sizeof(*acllist); - acllist = (struct ieee80211req_maclist *) data; - for (i = 0; i < nacls; i++) - (void)wlan_add_mac_macinfo(wif, acllist + i); - - wif->mac_nacls = nacls; - return (0); -} - -int -wlan_add_mac_acl_mac(struct wlan_iface *wif, struct wlan_mac_mac *mmac) -{ - int val = 0; - size_t argsize = IEEE80211_ADDR_LEN; - struct ieee80211req_mlme mlme; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_ADDMAC, &val, - mmac->mac, &argsize, 1) < 0) - return (-1); - - mmac->mac_status = RowStatus_active; - - /* If policy is deny, try to kick the station just in case. */ - if (wif->mac_policy != wlanMACAccessControlPolicy_deny) - return (0); - - memset(&mlme, 0, sizeof(mlme)); - mlme.im_op = IEEE80211_MLME_DEAUTH; - mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE; - memcpy(mlme.im_macaddr, mmac->mac, IEEE80211_ADDR_LEN); - argsize = sizeof(struct ieee80211req_mlme); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MLME, &val, &mlme, - &argsize, 1) < 0 && errno != ENOENT) - return (-1); - - return (0); -} - -int -wlan_del_mac_acl_mac(struct wlan_iface *wif, struct wlan_mac_mac *mmac) -{ - int val = 0; - size_t argsize = IEEE80211_ADDR_LEN; - struct ieee80211req_mlme mlme; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_DELMAC, &val, - mmac->mac, &argsize, 1) < 0) - return (-1); - - mmac->mac_status = RowStatus_active; - - /* If policy is allow, try to kick the station just in case. */ - if (wif->mac_policy != wlanMACAccessControlPolicy_allow) - return (0); - - memset(&mlme, 0, sizeof(mlme)); - mlme.im_op = IEEE80211_MLME_DEAUTH; - mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE; - memcpy(mlme.im_macaddr, mmac->mac, IEEE80211_ADDR_LEN); - argsize = sizeof(struct ieee80211req_mlme); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MLME, &val, &mlme, - &argsize, 1) < 0 && errno != ENOENT) - return (-1); - - return (0); -} - -int -wlan_peer_set_vlan(struct wlan_iface *wif, struct wlan_peer *wip, int vlan) -{ - int val = 0; - size_t argsize; - struct ieee80211req_sta_vlan vreq; - - memcpy(vreq.sv_macaddr, wip->pmac, IEEE80211_ADDR_LEN); - vreq.sv_vlan = vlan; - argsize = sizeof(struct ieee80211req_sta_vlan); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_STA_VLAN, - &val, &vreq, &argsize, 1) < 0) - return (-1); - - wip->vlan = vlan; - - return (0); -} - -/* XXX */ -#ifndef IEEE80211_NODE_AUTH -#define IEEE80211_NODE_AUTH 0x000001 /* authorized for data */ -#define IEEE80211_NODE_QOS 0x000002 /* QoS enabled */ -#define IEEE80211_NODE_ERP 0x000004 /* ERP enabled */ -#define IEEE80211_NODE_PWR_MGT 0x000010 /* power save mode enabled */ -#define IEEE80211_NODE_AREF 0x000020 /* authentication ref held */ -#define IEEE80211_NODE_HT 0x000040 /* HT enabled */ -#define IEEE80211_NODE_HTCOMPAT 0x000080 /* HT setup w/ vendor OUI's */ -#define IEEE80211_NODE_WPS 0x000100 /* WPS association */ -#define IEEE80211_NODE_TSN 0x000200 /* TSN association */ -#define IEEE80211_NODE_AMPDU_RX 0x000400 /* AMPDU rx enabled */ -#define IEEE80211_NODE_AMPDU_TX 0x000800 /* AMPDU tx enabled */ -#define IEEE80211_NODE_MIMO_PS 0x001000 /* MIMO power save enabled */ -#define IEEE80211_NODE_MIMO_RTS 0x002000 /* send RTS in MIMO PS */ -#define IEEE80211_NODE_RIFS 0x004000 /* RIFS enabled */ -#define IEEE80211_NODE_SGI20 0x008000 /* Short GI in HT20 enabled */ -#define IEEE80211_NODE_SGI40 0x010000 /* Short GI in HT40 enabled */ -#define IEEE80211_NODE_ASSOCID 0x020000 /* xmit requires associd */ -#define IEEE80211_NODE_AMSDU_RX 0x040000 /* AMSDU rx enabled */ -#define IEEE80211_NODE_AMSDU_TX 0x080000 /* AMSDU tx enabled */ -#endif - -static uint32_t -wlan_peerstate_to_snmp(uint32_t pstate) -{ - uint32_t sstate = 0; - - if ((pstate & IEEE80211_NODE_AUTH) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_authorizedForData); - if ((pstate & IEEE80211_NODE_QOS) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_qosEnabled); - if ((pstate & IEEE80211_NODE_ERP) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_erpEnabled); - if ((pstate & IEEE80211_NODE_PWR_MGT) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_powerSaveMode); - if ((pstate & IEEE80211_NODE_AREF) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_authRefHeld); - if ((pstate & IEEE80211_NODE_HT) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_htEnabled); - if ((pstate & IEEE80211_NODE_HTCOMPAT) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_htCompat); - if ((pstate & IEEE80211_NODE_WPS) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_wpsAssoc); - if ((pstate & IEEE80211_NODE_TSN) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_tsnAssoc); - if ((pstate & IEEE80211_NODE_AMPDU_RX) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_ampduRx); - if ((pstate & IEEE80211_NODE_AMPDU_TX) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_ampduTx); - if ((pstate & IEEE80211_NODE_MIMO_PS) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_mimoPowerSave); - if ((pstate & IEEE80211_NODE_MIMO_RTS) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_sendRts); - if ((pstate & IEEE80211_NODE_RIFS) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_rifs); - if ((pstate & IEEE80211_NODE_SGI20) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_shortGiHT20); - if ((pstate & IEEE80211_NODE_SGI40) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_shortGiHT40); - if ((pstate & IEEE80211_NODE_AMSDU_RX) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_amsduRx); - if ((pstate & IEEE80211_NODE_AMSDU_TX) != 0) - sstate |= (0x1 << WlanIfacePeerFlagsType_amsduTx); - - return (sstate); -} - -static struct wlan_peer * -wlan_add_peerinfo(const struct ieee80211req_sta_info *si) -{ - struct wlan_peer *wip; - - if ((wip = wlan_new_peer(si->isi_macaddr))== NULL) - return (NULL); - - wip->associd = IEEE80211_AID(si->isi_associd); - wip->vlan = si->isi_vlan; - wip->frequency = si->isi_freq; - wip->fflags = si->isi_flags; - wip->txrate = si->isi_txrate; - wip->rssi = si->isi_rssi; - wip->idle = si->isi_inact; - wip->txseqs = si->isi_txseqs[0]; /* XXX */ - wip->rxseqs = si->isi_rxseqs[0]; /* XXX */ - wip->txpower = si->isi_txpower; - wip->capinfo = wlan_peercaps_to_snmp(si->isi_capinfo); - wip->state = wlan_peerstate_to_snmp(si->isi_state); - wip->local_id = si->isi_localid; - wip->peer_id = si->isi_peerid; - - return (wip); -} - -int -wlan_get_peerinfo(struct wlan_iface *wif) -{ - union { - struct ieee80211req_sta_req req; - uint8_t buf[24 * 1024]; - } u; - const uint8_t *cp; - int val = 0; - size_t len; - struct ieee80211req_sta_info si; - struct wlan_peer *wip; - - /* Get all stations - broadcast address */ - (void) memset(u.req.is_u.macaddr, 0xff, IEEE80211_ADDR_LEN); - len = sizeof(u); - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_STA_INFO, - & val, &u, &len, 0) < 0) - return (-1); - - if (len < sizeof(struct ieee80211req_sta_info)) - return (-1); - - cp = (const uint8_t *) u.req.info; - do { - memcpy(&si, cp, sizeof(struct ieee80211req_sta_info)); - if ((wip = wlan_add_peerinfo(&si)) != NULL && - wlan_add_peer(wif, wip) < 0) - wlan_free_peer(wip); - cp += si.isi_len, len -= si.isi_len; - } while (len >= sizeof(struct ieee80211req_sta_info)); - - return (0); -} - -/************************************************************************ - * Wireless MESH & HWMP sysctl config. - */ -const char wlan_sysctl_name[] = "net.wlan."; - -static const char *wlan_sysctl[] = { - "mesh.retrytimeout", - "mesh.holdingtimeout", - "mesh.confirmtimeout", - "mesh.maxretries", - "hwmp.targetonly", - "hwmp.replyforward", - "hwmp.pathlifetime", - "hwmp.roottimeout", - "hwmp.rootint", - "hwmp.rannint", - "hwmp.inact", -}; - -int32_t -wlan_do_sysctl(struct wlan_config *cfg, enum wlan_syscl which, int set) -{ - char mib_name[100]; - int val, sval; - size_t len, vlen; - - if (set) { - vlen = sizeof(sval); - switch (which) { - case WLAN_MESH_RETRY_TO: - sval = cfg->mesh_retryto; - break; - case WLAN_MESH_HOLDING_TO: - sval = cfg->mesh_holdingto; - break; - case WLAN_MESH_CONFIRM_TO: - sval = cfg->mesh_confirmto; - break; - case WLAN_MESH_MAX_RETRIES: - sval = cfg->mesh_maxretries; - break; - case WLAN_HWMP_TARGET_ONLY: - sval = cfg->hwmp_targetonly; - break; - case WLAN_HWMP_REPLY_FORWARD: - sval = cfg->hwmp_replyforward; - break; - case WLAN_HWMP_PATH_LIFETIME: - sval = cfg->hwmp_pathlifetime; - break; - case WLAN_HWMP_ROOT_TO: - sval = cfg->hwmp_roottimeout; - break; - case WLAN_HWMP_ROOT_INT: - sval = cfg->hwmp_rootint; - break; - case WLAN_HWMP_RANN_INT: - sval = cfg->hwmp_rannint; - break; - case WLAN_HWMP_INACTIVITY_TO: - sval = cfg->hwmp_inact; - break; - default: - return (-1); - } - } else { - if (which >= WLAN_SYSCTL_MAX) - return (-1); - vlen = 0; - } - - strlcpy(mib_name, wlan_sysctl_name, sizeof(mib_name)); - strlcat(mib_name, wlan_sysctl[which], sizeof(mib_name)); - len = sizeof (val); - - if (sysctlbyname(mib_name, &val, &len, (set? &sval : NULL), vlen) < 0) { - syslog(LOG_ERR, "sysctl(%s) failed - %s", mib_name, - strerror(errno)); - return (-1); - } - - switch (which) { - case WLAN_MESH_RETRY_TO: - cfg->mesh_retryto = val; - break; - case WLAN_MESH_HOLDING_TO: - cfg->mesh_holdingto = val; - break; - case WLAN_MESH_CONFIRM_TO: - cfg->mesh_confirmto = val; - break; - case WLAN_MESH_MAX_RETRIES: - cfg->mesh_maxretries = val; - break; - case WLAN_HWMP_TARGET_ONLY: - cfg->hwmp_targetonly = val; - break; - case WLAN_HWMP_REPLY_FORWARD: - cfg->hwmp_replyforward = val; - break; - case WLAN_HWMP_PATH_LIFETIME: - cfg->hwmp_pathlifetime = val; - break; - case WLAN_HWMP_ROOT_TO: - cfg->hwmp_roottimeout = val; - break; - case WLAN_HWMP_ROOT_INT: - cfg->hwmp_rootint = val; - break; - case WLAN_HWMP_RANN_INT: - cfg->hwmp_rannint = val; - break; - case WLAN_HWMP_INACTIVITY_TO: - cfg->hwmp_inact = val; - break; - default: - /* NOTREACHED */ - abort(); - } - - return (0); -} - -int -wlan_mesh_config_get(struct wlan_iface *wif, int which) -{ - int op, val = 0; - size_t argsize = 0; - uint8_t data[32], *pd = NULL; - - switch (which) { - case LEAF_wlanMeshTTL: - op = IEEE80211_IOC_MESH_TTL; - break; - case LEAF_wlanMeshPeeringEnabled: - op = IEEE80211_IOC_MESH_AP; - break; - case LEAF_wlanMeshForwardingEnabled: - op = IEEE80211_IOC_MESH_FWRD; - break; - case LEAF_wlanMeshMetric: - op = IEEE80211_IOC_MESH_PR_METRIC; - pd = data; - argsize = sizeof(data); - break; - case LEAF_wlanMeshPath: - op = IEEE80211_IOC_MESH_PR_PATH; - pd = data; - argsize = sizeof(data); - break; - case LEAF_wlanMeshRoutesFlush: - return (0); - default: - return (-1); - } - - if (wlan_ioctl(wif->wname, op, &val, pd, &argsize, 0) < 0) - return (-1); - - switch (which) { - case LEAF_wlanMeshTTL: - wif->mesh_ttl = val; - break; - case LEAF_wlanMeshPeeringEnabled: - if (val) - wif->mesh_peering = wlanMeshPeeringEnabled_true; - else - wif->mesh_peering = wlanMeshPeeringEnabled_false; - break; - case LEAF_wlanMeshForwardingEnabled: - if (val) - wif->mesh_forwarding = wlanMeshForwardingEnabled_true; - else - wif->mesh_forwarding = wlanMeshForwardingEnabled_false; - break; - case LEAF_wlanMeshMetric: - data[argsize] = '\0'; - if (strcmp(data, "AIRTIME") == 0) - wif->mesh_metric = wlanMeshMetric_airtime; - else - wif->mesh_metric = wlanMeshMetric_unknown; - break; - case LEAF_wlanMeshPath: - data[argsize] = '\0'; - if (strcmp(data, "HWMP") == 0) - wif->mesh_path = wlanMeshPath_hwmp; - else - wif->mesh_path = wlanMeshPath_unknown; - } - - return (0); -} - -int -wlan_mesh_config_set(struct wlan_iface *wif, int which) -{ - int op, val = 0; - size_t argsize = 0; - uint8_t data[32], *pd = NULL; - - switch (which) { - case LEAF_wlanMeshTTL: - op = IEEE80211_IOC_MESH_TTL; - val = wif->mesh_ttl; - break; - case LEAF_wlanMeshPeeringEnabled: - op = IEEE80211_IOC_MESH_AP; - if (wif->mesh_peering == wlanMeshPeeringEnabled_true) - val = 1; - break; - case LEAF_wlanMeshForwardingEnabled: - if (wif->mesh_forwarding == wlanMeshForwardingEnabled_true) - val = 1; - op = IEEE80211_IOC_MESH_FWRD; - break; - case LEAF_wlanMeshMetric: - op = IEEE80211_IOC_MESH_PR_METRIC; - if (wif->mesh_metric == wlanMeshMetric_airtime) - strcpy(data, "AIRTIME"); - else - return (-1); - pd = data; - argsize = sizeof(data); - break; - case LEAF_wlanMeshPath: - op = IEEE80211_IOC_MESH_PR_PATH; - if (wif->mesh_path == wlanMeshPath_hwmp) - strcpy(data, "HWMP"); - else - return (-1); - pd = data; - argsize = sizeof(data); - break; - default: - return (-1); - } - - if (wlan_ioctl(wif->wname, op, &val, pd, &argsize, 1) < 0) - return (-1); - - return(0); -} - -int -wlan_mesh_flush_routes(struct wlan_iface *wif) -{ - int val = IEEE80211_MESH_RTCMD_FLUSH; - size_t argsize = 0; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MESH_RTCMD, &val, NULL, - &argsize, 1) < 0) - return (-1); - - return (0); -} - -int -wlan_mesh_add_route(struct wlan_iface *wif, struct wlan_mesh_route *wmr) -{ - int val = IEEE80211_MESH_RTCMD_ADD; - size_t argsize = IEEE80211_ADDR_LEN; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MESH_RTCMD, &val, - wmr->imroute.imr_dest, &argsize, 1) < 0) - return (-1); - - wmr->mroute_status = RowStatus_active; - - return (0); -} - -int -wlan_mesh_del_route(struct wlan_iface *wif, struct wlan_mesh_route *wmr) -{ - int val = IEEE80211_MESH_RTCMD_DELETE; - size_t argsize = IEEE80211_ADDR_LEN; - - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MESH_RTCMD, &val, - wmr->imroute.imr_dest, &argsize, 1) < 0) - return (-1); - - wmr->mroute_status = RowStatus_destroy; - - return (0); -} - -int -wlan_mesh_get_routelist(struct wlan_iface *wif) -{ - int i, nroutes, val = IEEE80211_MESH_RTCMD_LIST; - size_t argsize; - struct ieee80211req_mesh_route routes[128]; - struct ieee80211req_mesh_route *rt; - struct wlan_mesh_route *wmr; - - argsize = sizeof(routes); - if (wlan_ioctl(wif->wname, IEEE80211_IOC_MESH_RTCMD, &val, routes, - &argsize, 0) < 0) /* XXX: ENOMEM? */ - return (-1); - - nroutes = argsize / sizeof(*rt); - for (i = 0; i < nroutes; i++) { - rt = routes + i; - if ((wmr = wlan_mesh_new_route(rt->imr_dest)) == NULL) - return (-1); - memcpy(&wmr->imroute, rt, sizeof(*rt)); - wmr->mroute_status = RowStatus_active; - if (wlan_mesh_add_rtentry(wif, wmr) < 0) - wlan_mesh_free_route(wmr); - } - - return (0); -} - -int -wlan_hwmp_config_get(struct wlan_iface *wif, int which) -{ - int op, val = 0; - size_t argsize = 0; - - switch (which) { - case LEAF_wlanHWMPRootMode: - op = IEEE80211_IOC_HWMP_ROOTMODE; - break; - case LEAF_wlanHWMPMaxHops: - op = IEEE80211_IOC_HWMP_MAXHOPS; - break; - default: - return (-1); - } - - if (wlan_ioctl(wif->wname, op, &val, NULL, &argsize, 0) < 0) - return (-1); - - switch (which) { - case LEAF_wlanHWMPRootMode: - switch (val) { - case IEEE80211_HWMP_ROOTMODE_NORMAL: - wif->hwmp_root_mode = wlanHWMPRootMode_normal; - break; - case IEEE80211_HWMP_ROOTMODE_PROACTIVE: - wif->hwmp_root_mode = wlanHWMPRootMode_proactive; - break; - case IEEE80211_HWMP_ROOTMODE_RANN: - wif->hwmp_root_mode = wlanHWMPRootMode_rann; - break; - case IEEE80211_HWMP_ROOTMODE_DISABLED: - default: - wif->hwmp_root_mode = wlanHWMPRootMode_disabled; - break; - } - break; - case LEAF_wlanHWMPMaxHops: - wif->hwmp_max_hops = val; - break; - } - - return (0); -} - -int -wlan_hwmp_config_set(struct wlan_iface *wif, int which) -{ - int op, val = 0; - size_t argsize = 0; - - switch (which) { - case LEAF_wlanHWMPRootMode: - op = IEEE80211_IOC_HWMP_ROOTMODE; - switch (wif->hwmp_root_mode) { - case wlanHWMPRootMode_disabled: - val = IEEE80211_HWMP_ROOTMODE_DISABLED; - break; - case wlanHWMPRootMode_normal: - val = IEEE80211_HWMP_ROOTMODE_NORMAL; - break; - case wlanHWMPRootMode_proactive: - val = IEEE80211_HWMP_ROOTMODE_PROACTIVE; - break; - case wlanHWMPRootMode_rann: - val = IEEE80211_HWMP_ROOTMODE_RANN; - break; - default: - return (-1); - } - break; - case LEAF_wlanHWMPMaxHops: - op = IEEE80211_IOC_HWMP_MAXHOPS; - val = wif->hwmp_max_hops; - break; - default: - return (-1); - } - - if (wlan_ioctl(wif->wname, op, &val, NULL, &argsize, 1) < 0) - return (-1); - - return (0); -} diff --git a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_tree.def b/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_tree.def deleted file mode 100644 index f267f76..0000000 --- a/usr.sbin/bsnmpd/modules/snmp_wlan/wlan_tree.def +++ /dev/null @@ -1,675 +0,0 @@ -#- -# Copyright (C) 2010 The FreeBSD Foundation -# All rights reserved. -# -# This software was developed by Shteryana Sotirova Shopova under -# sponsorship from the FreeBSD Foundation. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ -# - -typedef RowStatus ENUM ( - 1 active - 2 notInService - 3 notReady - 4 createAndGo - 5 createAndWait - 6 destroy -) - -typedef TruthValue ENUM ( - 1 true - 2 false -) - -typedef WlanRegDomainCode ENUM ( - 1 fcc - 2 ca - 3 etsi - 4 etsi2 - 5 etsi3 - 6 fcc3 - 7 japan - 8 korea - 9 apac - 10 apac2 - 11 apac3 - 12 row - 13 none - 14 debug - 15 sr9 - 16 xr9 - 17 gz901 -) - -typedef WlanMgmtReasonCode ENUM ( - 1 unspecified - 2 authenticationExpire - 3 authenticationLeave - 4 associationExpire - 5 associationTooMany - 6 notAuthenticated - 7 notAssociated - 8 associationLeave - 9 associationNotAuthenticated - 10 dissasocPwrcapBad - 11 dissasocSuperchanBad - 13 ieInvalid - 14 micFailure - 15 fourWayHandshakeTimeout - 16 groupKeyUpdateTimeout - 17 ieIn4FourWayDiffers - 18 groupCipherInvalid - 19 pairwiseCiherInvalid - 20 akmpInvalid - 21 unsupportedRsnIeVersion - 22 invalidRsnIeCap - 23 dot1xAuthFailed - 24 cipherSuiteRejected - 32 unspeciffiedQos - 33 insufficientBw - 34 tooManyFrames - 35 outsideTxOp - 36 leavingQbss - 37 badMechanism - 38 setupNeeded - 39 timeout -) - -typedef WlanIfaceOperatingModeType ENUM ( - 0 ibss - 1 station - 2 wds - 3 adhocDemo - 4 hostAp - 5 monitor - 6 meshPoint - 7 tdma -) - -typedef WlanIfaceFlagsType BITS ( - 1 uniqueBssid - 2 noBeacons - 3 wdsLegacy -) - -typedef WlanDriverCaps BITS ( - 1 station - 2 ieee8023encap - 3 athFastFrames - 4 athTurbo - 5 ibss - 6 pmgt - 7 hostAp - 8 ahDemo - 9 swRetry - 10 txPmgt - 11 shortSlot - 12 shortPreamble - 13 monitor - 14 dfs - 15 mbss - 16 wpa1 - 17 wpa2 - 18 burst - 19 wme - 20 wds - 21 bgScan - 22 txFrag - 23 tdma -) - -typedef WlanCryptoCaps BITS ( - 1 wep - 2 tkip - 3 aes - 4 aesCcm - 5 tkipMic - 6 ckip -) - -typedef WlanHTCaps BITS ( - 1 ldpc - 2 chwidth40 - 3 greenField - 4 shortGi20 - 5 shortGi40 - 6 txStbc - 7 delba - 8 amsdu7935 - 9 dssscck40 - 10 psmp - 11 fortyMHzIntolerant - 12 lsigTxOpProt - 13 htcAmpdu - 14 htcAmsdu - 15 htcHt - 16 htcSmps - 17 htcRifs -) - -typedef WlanIfaceDot11nPduType ENUM ( - 0 disabled - 1 rxOnly - 2 txOnly - 3 txAndRx -) - -typedef WlanPeerCapabilityFlags BITS ( - 1 ess - 2 ibss - 3 cfPollable - 4 cfPollRequest - 5 privacy - 6 shortPreamble - 7 pbcc - 8 channelAgility - 9 shortSlotTime - 10 rsn - 11 dsssofdm -) - -typedef WlanIfacePeerFlagsType BITS ( - 1 authorizedForData - 2 qosEnabled - 3 erpEnabled - 4 powerSaveMode - 5 authRefHeld - 6 htEnabled - 7 htCompat - 8 wpsAssoc - 9 tsnAssoc - 10 ampduRx - 11 ampduTx - 12 mimoPowerSave - 13 sendRts - 14 rifs - 15 shortGiHT20 - 16 shortGiHT40 - 17 amsduRx - 18 amsduTx -) - -typedef WlanIfaceChannelFlagsType BITS ( - 1 turbo - 2 cck - 3 ofdm - 4 spectrum2Ghz - 5 spectrum5Ghz - 6 passiveScan - 7 dynamicCckOfdm - 8 gfsk - 9 spectrum900Mhz - 10 dot11aStaticTurbo - 11 halfRate - 12 quarterRate - 13 ht20 - 14 ht40u - 15 ht40d - 16 dfs - 17 xmit4ms - 18 noAdhoc - 19 noHostAp - 20 dot11d -) - -typedef WlanIfaceChannelStateType BITS ( - 1 radar - 2 cacDone - 3 interferenceDetected - 4 radarClear -) - -typedef WlanIfPhyMode ENUM ( - 1 auto - 2 dot11a - 3 dot11b - 4 dot11g - 5 fh - 6 turboA - 7 turboG - 8 sturboA - 9 dot11na - 10 dot11ng - 11 ofdmHalf - 12 ofdmQuarter -) - -typedef WlanChannelType ENUM ( - 1 fhss - 2 dot11a - 3 dot11b - 4 dot11g - 5 tenMHz - 6 fiveMHz - 7 turbo - 8 ht -) - -typedef WlanScanFlagsType BITS ( - 1 noSelection - 2 activeScan - 3 pickFirst - 4 backgroundScan - 5 once - 6 noBroadcast - 7 noAutoSequencing - 8 flushCashe - 9 chechCashe -) - -typedef WlanMeshNeighborPeerStateType ENUM ( - 0 idle - 1 openTx - 2 openRx - 3 confirmRx - 4 established - 5 closing -) - -(1 internet - (4 private - (1 enterprises - (12325 fokus - (1 begemot - (210 begemotWlan - (0 begemotWlanNotifications - ) - (1 begemotWlanInterface - (1 wlanInterfaceTable - (1 wlanInterfaceEntry : OCTETSTRING op_wlan_iface - (1 wlanIfaceIndex INTEGER GET) - (2 wlanIfaceName OCTETSTRING GET SET) - (3 wlanParentIfName OCTETSTRING GET SET) - (4 wlanIfaceOperatingMode WlanIfaceOperatingModeType GET SET) - (5 wlanIfaceFlags WlanIfaceFlagsType GET SET) - (6 wlanIfaceBssid OCTETSTRING | MacAddress GET SET) - (7 wlanIfaceLocalAddress OCTETSTRING | MacAddress GET SET) - (8 wlanIfaceStatus RowStatus GET SET) - (9 wlanIfaceState ENUM ( 1 up 2 down ) GET SET) - )) - (2 wlanIfParentTable - (1 wlanIfParentEntry : OCTETSTRING op_wlan_if_parent - (1 wlanIfParentDriverCapabilities WlanDriverCaps GET) - (2 wlanIfParentCryptoCapabilities WlanCryptoCaps GET) - (3 wlanIfParentHTCapabilities WlanHTCaps GET) - )) - (3 wlanIfaceConfigTable - (1 wlanIfaceConfigEntry : OCTETSTRING op_wlan_iface_config - (1 wlanIfacePacketBurst ENUM ( 1 true 2 false ) GET SET) - (2 wlanIfaceCountryCode OCTETSTRING GET SET) - (3 wlanIfaceRegDomain WlanRegDomainCode GET SET) - (4 wlanIfaceDesiredSsid OCTETSTRING GET SET) - (5 wlanIfaceDesiredChannel INTEGER32 GET SET) - (6 wlanIfaceDynamicFreqSelection ENUM ( 1 true 2 false ) GET SET) - (7 wlanIfaceFastFrames ENUM ( 1 true 2 false ) GET SET) - (8 wlanIfaceDturbo ENUM ( 1 true 2 false ) GET SET) - (9 wlanIfaceTxPower INTEGER32 GET SET) - (10 wlanIfaceFragmentThreshold INTEGER GET SET) - (11 wlanIfaceRTSThreshold INTEGER GET SET) - (12 wlanIfaceWlanPrivacySubscribe ENUM ( 1 true 2 false ) GET SET) - (13 wlanIfaceBgScan ENUM ( 1 true 2 false ) GET SET) - (14 wlanIfaceBgScanIdle INTEGER32 GET SET) - (15 wlanIfaceBgScanInterval INTEGER32 GET SET) - (16 wlanIfaceBeaconMissedThreshold INTEGER GET SET) - (17 wlanIfaceDesiredBssid OCTETSTRING | MacAddress GET SET) - (18 wlanIfaceRoamingMode ENUM ( 1 device 2 auto 3 manual ) GET SET) - (19 wlanIfaceDot11d ENUM ( 1 true 2 false ) GET SET) - (20 wlanIfaceDot11h ENUM ( 1 true 2 false ) GET SET) - (21 wlanIfaceDynamicWds ENUM ( 1 true 2 false ) GET SET) - (22 wlanIfacePowerSave ENUM ( 1 true 2 false ) GET SET) - (23 wlanIfaceApBridge ENUM ( 1 true 2 false ) GET SET) - (24 wlanIfaceBeaconInterval INTEGER GET SET) - (25 wlanIfaceDtimPeriod INTEGER GET SET) - (26 wlanIfaceHideSsid ENUM ( 1 true 2 false ) GET SET) - (27 wlanIfaceInactivityProccess ENUM ( 1 true 2 false ) GET SET) - (28 wlanIfaceDot11gProtMode ENUM ( 1 off 2 cts 3 rtscts ) GET SET) - (29 wlanIfaceDot11gPureMode ENUM ( 1 true 2 false ) GET SET) - (30 wlanIfaceDot11nPureMode ENUM ( 1 true 2 false ) GET SET) - (31 wlanIfaceDot11nAmpdu WlanIfaceDot11nPduType GET SET) - (32 wlanIfaceDot11nAmpduDensity INTEGER GET SET) - (33 wlanIfaceDot11nAmpduLimit INTEGER GET SET) - (34 wlanIfaceDot11nAmsdu WlanIfaceDot11nPduType GET SET) - (35 wlanIfaceDot11nAmsduLimit INTEGER GET SET) - (36 wlanIfaceDot11nHighThroughput ENUM ( 1 true 2 false ) GET SET) - (37 wlanIfaceDot11nHTCompatible ENUM ( 1 true 2 false ) GET SET) - (38 wlanIfaceDot11nHTProtMode ENUM ( 1 off 2 rts ) GET SET) - (39 wlanIfaceDot11nRIFS ENUM ( 1 true 2 false ) GET SET) - (40 wlanIfaceDot11nShortGI ENUM ( 1 true 2 false ) GET SET) - (41 wlanIfaceDot11nSMPSMode ENUM ( 1 disabled 2 static 3 dynamic ) GET SET) - (42 wlanIfaceTdmaSlot INTEGER GET SET) - (43 wlanIfaceTdmaSlotCount INTEGER GET SET) - (44 wlanIfaceTdmaSlotLength INTEGER GET SET) - (45 wlanIfaceTdmaBeaconInterval INTEGER32 GET SET) - )) - (4 wlanIfacePeerTable - (1 wlanIfacePeerEntry : OCTETSTRING OCTETSTRING | MacAddress op_wlan_if_peer - (1 wlanIfacePeerAddress OCTETSTRING | MacAddress GET) - (2 wlanIfacePeerAssociationId INTEGER32 GET) - (3 wlanIfacePeerVlanTag INTEGER GET SET) - (4 wlanIfacePeerFrequency INTEGER32 GET) - (5 wlanIfacePeerCurrentTXRate INTEGER32 GET) - (6 wlanIfacePeerRxSignalStrength INTEGER32 GET) - (7 wlanIfacePeerIdleTimer INTEGER32 GET) - (8 wlanIfacePeerTxSequenceNo INTEGER32 GET) - (9 wlanIfacePeerRxSequenceNo INTEGER32 GET) - (10 wlanIfacePeerTxPower INTEGER32 GET) - (11 wlanIfacePeerCapabilities WlanPeerCapabilityFlags GET) - (12 wlanIfacePeerFlags WlanIfacePeerFlagsType GET) - )) - (5 wlanIfaceChannelTable - (1 wlanIfaceChannelEntry : OCTETSTRING INTEGER op_wlan_channels - (1 wlanIfaceChannelId INTEGER) - (2 wlanIfaceChannelIeeeId INTEGER GET) - (3 wlanIfaceChannelType WlanChannelType GET) - (4 wlanIfaceChannelFlags WlanIfaceChannelFlagsType GET) - (5 wlanIfaceChannelFrequency INTEGER32 GET) - (6 wlanIfaceChannelMaxRegPower INTEGER32 GET) - (7 wlanIfaceChannelMaxTxPower INTEGER32 GET) - (8 wlanIfaceChannelMinTxPower INTEGER32 GET) - (9 wlanIfaceChannelState WlanIfaceChannelStateType GET) - (10 wlanIfaceChannelHTExtension INTEGER32 GET) - (11 wlanIfaceChannelMaxAntennaGain INTEGER32 GET) - )) - (6 wlanIfRoamParamsTable - (1 wlanIfRoamParamsEntry : OCTETSTRING WlanIfPhyMode op_wlan_roam_params - (1 wlanIfRoamPhyMode WlanIfPhyMode) - (2 wlanIfRoamRxSignalStrength INTEGER32 GET) - (3 wlanIfRoamTxRateThreshold INTEGER32 GET) - )) - (7 wlanIfTxParamsTable - (1 wlanIfTxParamsEntry : OCTETSTRING WlanIfPhyMode op_wlan_tx_params - (1 wlanIfTxPhyMode WlanIfPhyMode) - (2 wlanIfTxUnicastRate INTEGER32 GET SET) - (3 wlanIfTxMcastRate INTEGER32 GET SET) - (4 wlanIfTxMgmtRate INTEGER32 GET SET) - (5 wlanIfTxMaxRetryCount INTEGER32 GET SET) - )) - ) - (2 begemotWlanScanning - (1 wlanScanConfigTable - (1 wlanScanConfigEntry : OCTETSTRING op_wlan_scan_config - (1 wlanScanFlags WlanScanFlagsType GET SET) - (2 wlanScanDuration INTEGER GET SET) - (3 wlanScanMinChannelDwellTime INTEGER32 GET SET) - (4 wlanScanMaxChannelDwellTime INTEGER32 GET SET) - (5 wlanScanConfigStatus ENUM ( 0 unknown 1 notStarted 2 running 3 finished 4 cancel ) GET SET) - )) - (2 wlanScanResultsTable - (1 wlanScanResultsEntry : OCTETSTRING OCTETSTRING OCTETSTRING | MacAddress op_wlan_scan_results - (1 wlanScanResultID OCTETSTRING GET) - (2 wlanScanResultBssid OCTETSTRING | MacAddress GET) - (3 wlanScanResultChannel INTEGER32 GET) - (4 wlanScanResultRate INTEGER32 GET) - (5 wlanScanResultNoise INTEGER32 GET) - (6 wlanScanResultBeaconInterval INTEGER32 GET) - (7 wlanScanResultCapabilities WlanPeerCapabilityFlags GET) - )) - ) - (3 begemotWlanStatistics - (1 wlanIfaceStatisticsTable - (1 wlanIfaceStatisticsEntry : OCTETSTRING op_wlan_iface_stats - (1 wlanStatsRxBadVersion COUNTER GET) - (2 wlanStatsRxTooShort COUNTER GET) - (3 wlanStatsRxWrongBssid COUNTER GET) - (4 wlanStatsRxDiscardedDups COUNTER GET) - (5 wlanStatsRxWrongDir COUNTER GET) - (6 wlanStatsRxDiscardMcastEcho COUNTER GET) - (7 wlanStatsRxDiscardNoAssoc COUNTER GET) - (8 wlanStatsRxWepNoPrivacy COUNTER GET) - (9 wlanStatsRxWepUnencrypted COUNTER GET) - (10 wlanStatsRxWepFailed COUNTER GET) - (11 wlanStatsRxDecapsulationFailed COUNTER GET) - (12 wlanStatsRxDiscardMgmt COUNTER GET) - (13 wlanStatsRxControl COUNTER GET) - (14 wlanStatsRxBeacon COUNTER GET) - (15 wlanStatsRxRateSetTooBig COUNTER GET) - (16 wlanStatsRxElemMissing COUNTER GET) - (17 wlanStatsRxElemTooBig COUNTER GET) - (18 wlanStatsRxElemTooSmall COUNTER GET) - (19 wlanStatsRxElemUnknown COUNTER GET) - (20 wlanStatsRxChannelMismatch COUNTER GET) - (21 wlanStatsRxDropped COUNTER GET) - (22 wlanStatsRxSsidMismatch COUNTER GET) - (23 wlanStatsRxAuthNotSupported COUNTER GET) - (24 wlanStatsRxAuthFailed COUNTER GET) - (25 wlanStatsRxAuthCM COUNTER GET) - (26 wlanStatsRxAssocWrongBssid COUNTER GET) - (27 wlanStatsRxAssocNoAuth COUNTER GET) - (28 wlanStatsRxAssocCapMismatch COUNTER GET) - (29 wlanStatsRxAssocNoRateMatch COUNTER GET) - (30 wlanStatsRxBadWpaIE COUNTER GET) - (31 wlanStatsRxDeauthenticate COUNTER GET) - (32 wlanStatsRxDisassociate COUNTER GET) - (33 wlanStatsRxUnknownSubtype COUNTER GET) - (34 wlanStatsRxFailedNoBuf COUNTER GET) - (35 wlanStatsRxBadAuthRequest COUNTER GET) - (36 wlanStatsRxUnAuthorized COUNTER GET) - (37 wlanStatsRxBadKeyId COUNTER GET) - (38 wlanStatsRxCCMPSeqViolation COUNTER GET) - (39 wlanStatsRxCCMPBadFormat COUNTER GET) - (40 wlanStatsRxCCMPFailedMIC COUNTER GET) - (41 wlanStatsRxTKIPSeqViolation COUNTER GET) - (42 wlanStatsRxTKIPBadFormat COUNTER GET) - (43 wlanStatsRxTKIPFailedMIC COUNTER GET) - (44 wlanStatsRxTKIPFailedICV COUNTER GET) - (45 wlanStatsRxDiscardACL COUNTER GET) - (46 wlanStatsTxFailedNoBuf COUNTER GET) - (47 wlanStatsTxFailedNoNode COUNTER GET) - (48 wlanStatsTxUnknownMgmt COUNTER GET) - (49 wlanStatsTxBadCipher COUNTER GET) - (50 wlanStatsTxNoDefKey COUNTER GET) - (51 wlanStatsTxFragmented COUNTER GET) - (52 wlanStatsTxFragmentsCreated COUNTER GET) - (53 wlanStatsActiveScans COUNTER GET) - (54 wlanStatsPassiveScans COUNTER GET) - (55 wlanStatsTimeoutInactivity COUNTER GET) - (56 wlanStatsCryptoNoMem COUNTER GET) - (57 wlanStatsSwCryptoTKIP COUNTER GET) - (58 wlanStatsSwCryptoTKIPEnMIC COUNTER GET) - (59 wlanStatsSwCryptoTKIPDeMIC COUNTER GET) - (60 wlanStatsCryptoTKIPCM COUNTER GET) - (61 wlanStatsSwCryptoCCMP COUNTER GET) - (62 wlanStatsSwCryptoWEP COUNTER GET) - (63 wlanStatsCryptoCipherKeyRejected COUNTER GET) - (64 wlanStatsCryptoNoKey COUNTER GET) - (65 wlanStatsCryptoDeleteKeyFailed COUNTER GET) - (66 wlanStatsCryptoUnknownCipher COUNTER GET) - (67 wlanStatsCryptoAttachFailed COUNTER GET) - (68 wlanStatsCryptoKeyFailed COUNTER GET) - (69 wlanStatsCryptoEnMICFailed COUNTER GET) - (70 wlanStatsIBSSCapMismatch COUNTER GET) - (71 wlanStatsUnassocStaPSPoll COUNTER GET) - (72 wlanStatsBadAidPSPoll COUNTER GET) - (73 wlanStatsEmptyPSPoll COUNTER GET) - (74 wlanStatsRxFFBadHdr COUNTER GET) - (75 wlanStatsRxFFTooShort COUNTER GET) - (76 wlanStatsRxFFSplitError COUNTER GET) - (77 wlanStatsRxFFDecap COUNTER GET) - (78 wlanStatsTxFFEncap COUNTER GET) - (79 wlanStatsRxBadBintval COUNTER GET) - (80 wlanStatsRxDemicFailed COUNTER GET) - (81 wlanStatsRxDefragFailed COUNTER GET) - (82 wlanStatsRxMgmt COUNTER GET) - (83 wlanStatsRxActionMgmt COUNTER GET) - (84 wlanStatsRxAMSDUTooShort COUNTER GET) - (85 wlanStatsRxAMSDUSplitError COUNTER GET) - (86 wlanStatsRxAMSDUDecap COUNTER GET) - (87 wlanStatsTxAMSDUEncap COUNTER GET) - (88 wlanStatsAMPDUBadBAR COUNTER GET) - (89 wlanStatsAMPDUOowBar COUNTER GET) - (90 wlanStatsAMPDUMovedBAR COUNTER GET) - (91 wlanStatsAMPDURxBAR COUNTER GET) - (92 wlanStatsAMPDURxOor COUNTER GET) - (93 wlanStatsAMPDURxCopied COUNTER GET) - (94 wlanStatsAMPDURxDropped COUNTER GET) - (95 wlanStatsTxDiscardBadState COUNTER GET) - (96 wlanStatsTxFailedNoAssoc COUNTER GET) - (97 wlanStatsTxClassifyFailed COUNTER GET) - (98 wlanStatsDwdsMcastDiscard COUNTER GET) - (99 wlanStatsHTAssocRejectNoHT COUNTER GET) - (100 wlanStatsHTAssocDowngrade COUNTER GET) - (101 wlanStatsHTAssocRateMismatch COUNTER GET) - (102 wlanStatsAMPDURxAge COUNTER GET) - (103 wlanStatsAMPDUMoved COUNTER GET) - (104 wlanStatsADDBADisabledReject COUNTER GET) - (105 wlanStatsADDBANoRequest COUNTER GET) - (106 wlanStatsADDBABadToken COUNTER GET) - (107 wlanStatsADDBABadPolicy COUNTER GET) - (108 wlanStatsAMPDUStopped COUNTER GET) - (109 wlanStatsAMPDUStopFailed COUNTER GET) - (110 wlanStatsAMPDURxReorder COUNTER GET) - (111 wlanStatsScansBackground COUNTER GET) - (112 wlanLastDeauthReason WlanMgmtReasonCode GET) - (113 wlanLastDissasocReason WlanMgmtReasonCode GET) - (114 wlanLastAuthFailReason WlanMgmtReasonCode GET) - (115 wlanStatsBeaconMissedEvents COUNTER GET) - (116 wlanStatsRxDiscardBadStates COUNTER GET) - (117 wlanStatsFFFlushed COUNTER GET) - (118 wlanStatsTxControlFrames COUNTER GET) - (119 wlanStatsAMPDURexmt COUNTER GET) - (120 wlanStatsAMPDURexmtFailed COUNTER GET) - (121 wlanStatsReset ENUM ( 1 no-op 2 clear ) GET SET) - )) - ) - (4 begemotWlanWep - (1 wlanWepInterfaceTable - (1 wlanWepInterfaceEntry : OCTETSTRING op_wlan_wep_iface - (1 wlanWepMode ENUM ( 0 off 1 on 2 mixed ) GET SET) - (2 wlanWepDefTxKey INTEGER32 GET SET) - )) - (2 wlanWepKeyTable - (1 wlanWepKeyEntry : OCTETSTRING INTEGER op_wlan_wep_key - (1 wlanWepKeyID INTEGER GET SET) - (2 wlanWepKeyLength INTEGER32 GET) - (3 wlanWepKeySet OCTETSTRING | OctetString GET SET) - (4 wlanWepKeyHash OCTETSTRING | OctetString GET) - (5 wlanWepKeyStatus RowStatus GET SET) - )) - ) - (5 begemotWlanMACAccessControl - (1 wlanMACAccessControlTable - (1 wlanMACAccessControlEntry : OCTETSTRING op_wlan_mac_access_control - (1 wlanMACAccessControlPolicy ENUM ( 0 open 1 allow 2 deny 7 radius ) GET SET) - (2 wlanMACAccessControlNacl COUNTER GET) - (3 wlanMACAccessControlFlush ENUM ( 0 no-op 1 flush ) GET SET) - )) - (2 wlanMACAccessControlMACTable - (1 wlanMACAccessControlMACEntry : OCTETSTRING OCTETSTRING | MacAddress op_wlan_mac_acl_mac - (1 wlanMACAccessControlMAC OCTETSTRING | MacAddress GET SET) - (2 wlanMACAccessControlMACStatus RowStatus GET SET) - )) - ) - (6 begemotWlanMeshRouting - (1 wlanMeshRoutingConfig - (1 wlanMeshMaxRetries INTEGER32 op_wlan_mesh_config GET SET) - (2 wlanMeshConfirmTimeout INTEGER32 op_wlan_mesh_config GET SET) - (3 wlanMeshHoldingTimeout INTEGER32 op_wlan_mesh_config GET SET) - (4 wlanMeshRetryTimeout INTEGER32 op_wlan_mesh_config GET SET) - ) - (2 wlanMeshInterface - (1 wlanMeshInterfaceTable - (1 wlanMeshInterfaceEntry : OCTETSTRING op_wlan_mesh_iface - (1 wlanMeshId OCTETSTRING GET SET) - (2 wlanMeshTTL INTEGER32 GET SET) - (3 wlanMeshPeeringEnabled ENUM ( 1 true 2 false ) GET SET) - (4 wlanMeshForwardingEnabled ENUM ( 1 true 2 false ) GET SET) - (5 wlanMeshMetric ENUM ( 0 unknown 1 airtime ) GET SET) - (6 wlanMeshPath ENUM ( 0 unknown 1 hwmp ) GET SET) - (7 wlanMeshRoutesFlush ENUM ( 0 no-op 1 flush ) GET SET) - )) - (2 wlanMeshNeighborTable - (1 wlanMeshNeighborEntry : OCTETSTRING OCTETSTRING | MacAddress op_wlan_mesh_neighbor - (1 wlanMeshNeighborAddress OCTETSTRING | MacAddress GET) - (2 wlanMeshNeighborFrequency INTEGER32 GET) - (3 wlanMeshNeighborLocalId INTEGER32 GET) - (4 wlanMeshNeighborPeerId INTEGER32 GET) - (5 wlanMeshNeighborPeerState WlanMeshNeighborPeerStateType GET) - (6 wlanMeshNeighborCurrentTXRate INTEGER32 GET) - (7 wlanMeshNeighborRxSignalStrength INTEGER32 GET) - (8 wlanMeshNeighborIdleTimer INTEGER32 GET) - (9 wlanMeshNeighborTxSequenceNo INTEGER32 GET) - (10 wlanMeshNeighborRxSequenceNo INTEGER32 GET) - )) - ) - (3 wlanMeshRoute - (1 wlanMeshRouteTable - (1 wlanMeshRouteEntry : OCTETSTRING OCTETSTRING | MacAddress op_wlan_mesh_route - (1 wlanMeshRouteDestination OCTETSTRING | MacAddress GET SET) - (2 wlanMeshRouteNextHop OCTETSTRING | MacAddress GET) - (3 wlanMeshRouteHops INTEGER32 GET) - (4 wlanMeshRouteMetric UNSIGNED32 GET) - (5 wlanMeshRouteLifeTime UNSIGNED32 GET) - (6 wlanMeshRouteLastMseq UNSIGNED32 GET) - (7 wlanMeshRouteFlags BITS ( 1 valid 2 proxy ) GET) - (8 wlanMeshRouteStatus RowStatus GET SET) - )) - ) - (4 wlanMeshStatistics - (1 wlanMeshStatsTable - (1 wlanMeshStatsEntry : OCTETSTRING op_wlan_mesh_stats - (1 wlanMeshDroppedBadSta COUNTER GET) - (2 wlanMeshDroppedNoLink COUNTER GET) - (3 wlanMeshNoFwdTtl COUNTER GET) - (4 wlanMeshNoFwdBuf COUNTER GET) - (5 wlanMeshNoFwdTooShort COUNTER GET) - (6 wlanMeshNoFwdDisabled COUNTER GET) - (7 wlanMeshNoFwdPathUnknown COUNTER GET) - (8 wlanMeshDroppedBadAE COUNTER GET) - (9 wlanMeshRouteAddFailed COUNTER GET) - (10 wlanMeshDroppedNoProxy COUNTER GET) - (11 wlanMeshDroppedMisaligned COUNTER GET) - )) - ) - (5 wlanMeshRouteProtocols - (1 wlanMeshProtoHWMP - (1 wlanMeshHWMPConfig - (1 wlanHWMPRouteInactiveTimeout INTEGER32 op_wlan_hwmp_config GET SET) - (2 wlanHWMPRootAnnounceInterval INTEGER32 op_wlan_hwmp_config GET SET) - (3 wlanHWMPRootInterval INTEGER32 op_wlan_hwmp_config GET SET) - (4 wlanHWMPRootTimeout INTEGER32 op_wlan_hwmp_config GET SET) - (5 wlanHWMPPathLifetime INTEGER32 op_wlan_hwmp_config GET SET) - (6 wlanHWMPReplyForwardBit INTEGER32 op_wlan_hwmp_config GET SET) - (7 wlanHWMPTargetOnlyBit INTEGER32 op_wlan_hwmp_config GET SET) - ) - (2 wlanMeshHWMPInterface - (1 wlanHWMPInterfaceTable - (1 wlanHWMPInterfaceEntry : OCTETSTRING op_wlan_hwmp_iface - (1 wlanHWMPRootMode ENUM ( 1 disabled 2 normal 3 proactive 4 rann ) GET SET) - (2 wlanHWMPMaxHops INTEGER32 GET SET) - )) - ) - (3 wlanMeshHWMPStatistics - (1 wlanMeshHWMPStatsTable - (1 wlanMeshHWMPStatsEntry : OCTETSTRING op_wlan_hwmp_stats - (1 wlanMeshHWMPWrongSeqNo COUNTER GET) - (2 wlanMeshHWMPTxRootPREQ COUNTER GET) - (3 wlanMeshHWMPTxRootRANN COUNTER GET) - (4 wlanMeshHWMPProxy COUNTER GET) - )) - ) - ) - ) - )))))) -) diff --git a/usr.sbin/btxld/Makefile b/usr.sbin/btxld/Makefile deleted file mode 100644 index 32cf99d..0000000 --- a/usr.sbin/btxld/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -PROG= btxld -MAN= btxld.8 -SRCS= btxld.c elfh.c - -.include diff --git a/usr.sbin/btxld/btx.h b/usr.sbin/btxld/btx.h deleted file mode 100644 index 86f0ede..0000000 --- a/usr.sbin/btxld/btx.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1998 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _BTX_H_ -#define _BTX_H_ - -#include - -#define BTX_PGSIZE 0x1000 /* Page size */ -#define BTX_PGBASE 0x5000 /* Start of page tables */ -#define BTX_MAXCWR 0x3bc /* Max. btx_pgctl adjustment */ - -/* - * BTX image header. - */ -struct btx_hdr { - uint8_t btx_machid; /* Machine ID */ - uint8_t btx_hdrsz; /* Header size */ - uint8_t btx_magic[3]; /* Magic */ - uint8_t btx_majver; /* Major version */ - uint8_t btx_minver; /* Minor version */ - uint8_t btx_flags; /* Flags */ - uint16_t btx_pgctl; /* Paging control */ - uint16_t btx_textsz; /* Text size */ - uint32_t btx_entry; /* Client entry address */ -}; - -/* btx_machid */ -#define BTX_I386 0xeb /* Intel i386 or compatible */ - -/* btx_magic */ -#define BTX_MAG0 'B' -#define BTX_MAG1 'T' -#define BTX_MAG2 'X' - -/* btx_flags */ -#define BTX_MAPONE 0x80 /* Start mapping at page 1 */ - -#define BTX_MAPPED(btx) (((btx).btx_pgctl | (BTX_PGSIZE / 4 - 1)) + 1) -#define BTX_ORIGIN(btx) (BTX_PGBASE + BTX_MAPPED(btx) * 4) -#define BTX_ENTRY(btx) (BTX_ORIGIN(btx) + 2 + (btx).btx_hdrsz) - -#endif /* !_BTX_H_ */ diff --git a/usr.sbin/btxld/btxld.8 b/usr.sbin/btxld/btxld.8 deleted file mode 100644 index 5b514f6..0000000 --- a/usr.sbin/btxld/btxld.8 +++ /dev/null @@ -1,98 +0,0 @@ -.\" Copyright (c) 1998 Robert Nordier -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -.\" OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -.\" OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, -.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd September 12, 1998 -.Dt BTXLD 8 -.Os -.Sh NAME -.Nm btxld -.Nd link editor for BTX clients -.Sh SYNOPSIS -.Nm -.Op Fl qv -.Op Fl b Ar file -.Op Fl E Ar address -.Op Fl e Ar address -.Op Fl f Ar format -.Op Fl l Ar file -.Op Fl o Ar filename -.Op Fl P Ar page -.Op Fl W Ar page -.Ar file -.Sh DESCRIPTION -The -.Nm -utility binds the specified client executable together with a BTX -loader program and the BTX kernel, and creates a composite object file -suitable for loading during the boot process. -.Pp -The options are: -.Bl -tag -width indent -.It Fl q -Quiet: inhibit warnings. -.It Fl v -Verbose: display information about the files processed. -.It Fl b Ar file -Specify the BTX kernel to be bound with the client. -.It Fl E Ar address -Set the client entry point. -.It Fl e Ar address -Set the BTX loader entry point. -.It Fl f Ar format -Specify the output format, where -.Ar format -is one of -.Sq bin , -.Sq aout , -or -.Sq elf . -.It Fl l Ar file -Specify the BTX loader to be bound with the client. -.It Fl o Ar filename -Name the output file. -The default is -.Dq a.out . -.It Fl P Ar page -Specify the first page of the client's segment to be marked -.Sq present , -where -.Ar page -may be 0 or 1. -.It Fl W Ar page -Specify the first page of the client's segment to be marked -.Sq writable , -where -.Ar page -may be 0, and should not exceed the number of pages occupied by the -combined .text and .data segments of the client image. -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr ld 1 , -.Xr boot 8 -.Sh AUTHORS -.An Robert Nordier Aq rnordier@FreeBSD.org . diff --git a/usr.sbin/btxld/btxld.c b/usr.sbin/btxld/btxld.c deleted file mode 100644 index 1102b5c..0000000 --- a/usr.sbin/btxld/btxld.c +++ /dev/null @@ -1,575 +0,0 @@ -/* - * Copyright (c) 1998 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include - -/* XXX make this work as an i386/amd64 cross-tool */ -#include -#undef __LDPGSZ -#define __LDPGSZ 4096 - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "btx.h" -#include "elfh.h" - -#define BTX_PATH "/sys/boot/i386/btx" - -#define I_LDR 0 /* BTX loader */ -#define I_BTX 1 /* BTX kernel */ -#define I_CLNT 2 /* Client program */ - -#define F_BIN 0 /* Binary */ -#define F_AOUT 1 /* ZMAGIC a.out */ -#define F_ELF 2 /* 32-bit ELF */ -#define F_CNT 3 /* Number of formats */ - -#define IMPURE 1 /* Writable text */ -#define MAXU32 0xffffffff /* Maximum unsigned 32-bit quantity */ - -#define align(x, y) (((x) + (y) - 1) & ~((y) - 1)) - -struct hdr { - uint32_t fmt; /* Format */ - uint32_t flags; /* Bit flags */ - uint32_t size; /* Size of file */ - uint32_t text; /* Size of text segment */ - uint32_t data; /* Size of data segment */ - uint32_t bss; /* Size of bss segment */ - uint32_t org; /* Program origin */ - uint32_t entry; /* Program entry point */ -}; - -static const char *const fmtlist[] = {"bin", "aout", "elf"}; - -static const char binfo[] = - "kernel: ver=%u.%02u size=%x load=%x entry=%x map=%uM " - "pgctl=%x:%x\n"; -static const char cinfo[] = - "client: fmt=%s size=%x text=%x data=%x bss=%x entry=%x\n"; -static const char oinfo[] = - "output: fmt=%s size=%x text=%x data=%x org=%x entry=%x\n"; - -static const char *lname = - BTX_PATH "/btxldr/btxldr"; /* BTX loader */ -static const char *bname = - BTX_PATH "/btx/btx"; /* BTX kernel */ -static const char *oname = - "a.out"; /* Output filename */ - -static int ppage = -1; /* First page present */ -static int wpage = -1; /* First page writable */ - -static unsigned int format; /* Output format */ - -static uint32_t centry; /* Client entry address */ -static uint32_t lentry; /* Loader entry address */ - -static int Eflag; /* Client entry option */ - -static int quiet; /* Inhibit warnings */ -static int verbose; /* Display information */ - -static const char *tname; /* Temporary output file */ -static const char *fname; /* Current input file */ - -static void cleanup(void); -static void btxld(const char *); -static void getbtx(int, struct btx_hdr *); -static void gethdr(int, struct hdr *); -static void puthdr(int, struct hdr *); -static void copy(int, int, size_t, off_t); -static size_t readx(int, void *, size_t, off_t); -static void writex(int, const void *, size_t); -static void seekx(int, off_t); -static unsigned int optfmt(const char *); -static uint32_t optaddr(const char *); -static int optpage(const char *, int); -static void Warn(const char *, const char *, ...); -static void usage(void); - -/* - * A link editor for BTX clients. - */ -int -main(int argc, char *argv[]) -{ - int c; - - while ((c = getopt(argc, argv, "qvb:E:e:f:l:o:P:W:")) != -1) - switch (c) { - case 'q': - quiet = 1; - break; - case 'v': - verbose = 1; - break; - case 'b': - bname = optarg; - break; - case 'E': - centry = optaddr(optarg); - Eflag = 1; - break; - case 'e': - lentry = optaddr(optarg); - break; - case 'f': - format = optfmt(optarg); - break; - case 'l': - lname = optarg; - break; - case 'o': - oname = optarg; - break; - case 'P': - ppage = optpage(optarg, 1); - break; - case 'W': - wpage = optpage(optarg, BTX_MAXCWR); - break; - default: - usage(); - } - argc -= optind; - argv += optind; - if (argc != 1) - usage(); - atexit(cleanup); - btxld(*argv); - return 0; -} - -/* - * Clean up after errors. - */ -static void -cleanup(void) -{ - if (tname) - remove(tname); -} - -/* - * Read the input files; write the output file; display information. - */ -static void -btxld(const char *iname) -{ - char name[FILENAME_MAX]; - struct btx_hdr btx, btxle; - struct hdr ihdr, ohdr; - unsigned int ldr_size, cwr; - int fdi[3], fdo, i; - - ldr_size = 0; - - for (i = I_LDR; i <= I_CLNT; i++) { - fname = i == I_LDR ? lname : i == I_BTX ? bname : iname; - if ((fdi[i] = open(fname, O_RDONLY)) == -1) - err(2, "%s", fname); - switch (i) { - case I_LDR: - gethdr(fdi[i], &ihdr); - if (ihdr.fmt != F_BIN) - Warn(fname, "Loader format is %s; processing as %s", - fmtlist[ihdr.fmt], fmtlist[F_BIN]); - ldr_size = ihdr.size; - break; - case I_BTX: - getbtx(fdi[i], &btx); - break; - case I_CLNT: - gethdr(fdi[i], &ihdr); - if (ihdr.org && ihdr.org != BTX_PGSIZE) - Warn(fname, - "Client origin is 0x%x; expecting 0 or 0x%x", - ihdr.org, BTX_PGSIZE); - } - } - memset(&ohdr, 0, sizeof(ohdr)); - ohdr.fmt = format; - ohdr.text = ldr_size; - ohdr.data = btx.btx_textsz + ihdr.size; - ohdr.org = lentry; - ohdr.entry = lentry; - cwr = 0; - if (wpage > 0 || (wpage == -1 && !(ihdr.flags & IMPURE))) { - if (wpage > 0) - cwr = wpage; - else { - cwr = howmany(ihdr.text, BTX_PGSIZE); - if (cwr > BTX_MAXCWR) - cwr = BTX_MAXCWR; - } - } - if (ppage > 0 || (ppage && wpage && ihdr.org >= BTX_PGSIZE)) { - btx.btx_flags |= BTX_MAPONE; - if (!cwr) - cwr++; - } - btx.btx_pgctl -= cwr; - btx.btx_entry = Eflag ? centry : ihdr.entry; - if ((size_t)snprintf(name, sizeof(name), "%s.tmp", oname) >= sizeof(name)) - errx(2, "%s: Filename too long", oname); - if ((fdo = open(name, O_CREAT | O_TRUNC | O_WRONLY, 0666)) == -1) - err(2, "%s", name); - if (!(tname = strdup(name))) - err(2, NULL); - puthdr(fdo, &ohdr); - for (i = I_LDR; i <= I_CLNT; i++) { - fname = i == I_LDR ? lname : i == I_BTX ? bname : iname; - switch (i) { - case I_LDR: - copy(fdi[i], fdo, ldr_size, 0); - seekx(fdo, ohdr.size += ohdr.text); - break; - case I_BTX: - btxle = btx; - btxle.btx_pgctl = htole16(btxle.btx_pgctl); - btxle.btx_textsz = htole16(btxle.btx_textsz); - btxle.btx_entry = htole32(btxle.btx_entry); - writex(fdo, &btxle, sizeof(btxle)); - copy(fdi[i], fdo, btx.btx_textsz - sizeof(btx), - sizeof(btx)); - break; - case I_CLNT: - copy(fdi[i], fdo, ihdr.size, 0); - if (ftruncate(fdo, ohdr.size += ohdr.data)) - err(2, "%s", tname); - } - if (close(fdi[i])) - err(2, "%s", fname); - } - if (close(fdo)) - err(2, "%s", tname); - if (rename(tname, oname)) - err(2, "%s: Can't rename to %s", tname, oname); - tname = NULL; - if (verbose) { - printf(binfo, btx.btx_majver, btx.btx_minver, btx.btx_textsz, - BTX_ORIGIN(btx), BTX_ENTRY(btx), BTX_MAPPED(btx) * - BTX_PGSIZE / 0x100000, !!(btx.btx_flags & BTX_MAPONE), - BTX_MAPPED(btx) - btx.btx_pgctl - BTX_PGBASE / - BTX_PGSIZE - BTX_MAPPED(btx) * 4 / BTX_PGSIZE); - printf(cinfo, fmtlist[ihdr.fmt], ihdr.size, ihdr.text, - ihdr.data, ihdr.bss, ihdr.entry); - printf(oinfo, fmtlist[ohdr.fmt], ohdr.size, ohdr.text, - ohdr.data, ohdr.org, ohdr.entry); - } -} - -/* - * Read BTX file header. - */ -static void -getbtx(int fd, struct btx_hdr * btx) -{ - if (readx(fd, btx, sizeof(*btx), 0) != sizeof(*btx) || - btx->btx_magic[0] != BTX_MAG0 || - btx->btx_magic[1] != BTX_MAG1 || - btx->btx_magic[2] != BTX_MAG2) - errx(1, "%s: Not a BTX kernel", fname); - btx->btx_pgctl = le16toh(btx->btx_pgctl); - btx->btx_textsz = le16toh(btx->btx_textsz); - btx->btx_entry = le32toh(btx->btx_entry); -} - -/* - * Get file size and read a.out or ELF header. - */ -static void -gethdr(int fd, struct hdr *hdr) -{ - struct stat sb; - const struct exec *ex; - const Elf32_Ehdr *ee; - const Elf32_Phdr *ep; - void *p; - unsigned int fmt, x, n, i; - - memset(hdr, 0, sizeof(*hdr)); - if (fstat(fd, &sb)) - err(2, "%s", fname); - if (sb.st_size > MAXU32) - errx(1, "%s: Too big", fname); - hdr->size = sb.st_size; - if (!hdr->size) - return; - if ((p = mmap(NULL, hdr->size, PROT_READ, MAP_SHARED, fd, - 0)) == MAP_FAILED) - err(2, "%s", fname); - for (fmt = F_CNT - 1; !hdr->fmt && fmt; fmt--) - switch (fmt) { - case F_AOUT: - ex = p; - if (hdr->size >= sizeof(struct exec) && !N_BADMAG(*ex)) { - hdr->fmt = fmt; - x = N_GETMAGIC(*ex); - if (x == OMAGIC || x == NMAGIC) { - if (x == NMAGIC) - Warn(fname, "Treating %s NMAGIC as OMAGIC", - fmtlist[fmt]); - hdr->flags |= IMPURE; - } - hdr->text = le32toh(ex->a_text); - hdr->data = le32toh(ex->a_data); - hdr->bss = le32toh(ex->a_bss); - hdr->entry = le32toh(ex->a_entry); - if (le32toh(ex->a_entry) >= BTX_PGSIZE) - hdr->org = BTX_PGSIZE; - } - break; - case F_ELF: - ee = p; - if (hdr->size >= sizeof(Elf32_Ehdr) && IS_ELF(*ee)) { - hdr->fmt = fmt; - for (n = i = 0; i < le16toh(ee->e_phnum); i++) { - ep = (void *)((uint8_t *)p + le32toh(ee->e_phoff) + - le16toh(ee->e_phentsize) * i); - if (le32toh(ep->p_type) == PT_LOAD) - switch (n++) { - case 0: - hdr->text = le32toh(ep->p_filesz); - hdr->org = le32toh(ep->p_paddr); - if (le32toh(ep->p_flags) & PF_W) - hdr->flags |= IMPURE; - break; - case 1: - hdr->data = le32toh(ep->p_filesz); - hdr->bss = le32toh(ep->p_memsz) - - le32toh(ep->p_filesz); - break; - case 2: - Warn(fname, - "Ignoring extra %s PT_LOAD segments", - fmtlist[fmt]); - } - } - hdr->entry = le32toh(ee->e_entry); - } - } - if (munmap(p, hdr->size)) - err(2, "%s", fname); -} - -/* - * Write a.out or ELF header. - */ -static void -puthdr(int fd, struct hdr *hdr) -{ - struct exec ex; - struct elfh eh; - - switch (hdr->fmt) { - case F_AOUT: - memset(&ex, 0, sizeof(ex)); - N_SETMAGIC(ex, ZMAGIC, MID_I386, 0); - hdr->text = N_ALIGN(ex, hdr->text); - ex.a_text = htole32(hdr->text); - hdr->data = N_ALIGN(ex, hdr->data); - ex.a_data = htole32(hdr->data); - ex.a_entry = htole32(hdr->entry); - writex(fd, &ex, sizeof(ex)); - hdr->size = N_ALIGN(ex, sizeof(ex)); - seekx(fd, hdr->size); - break; - case F_ELF: - eh = elfhdr; - eh.e.e_entry = htole32(hdr->entry); - eh.p[0].p_vaddr = eh.p[0].p_paddr = htole32(hdr->org); - eh.p[0].p_filesz = eh.p[0].p_memsz = htole32(hdr->text); - eh.p[1].p_offset = htole32(le32toh(eh.p[0].p_offset) + - le32toh(eh.p[0].p_filesz)); - eh.p[1].p_vaddr = eh.p[1].p_paddr = - htole32(align(le32toh(eh.p[0].p_paddr) + le32toh(eh.p[0].p_memsz), - 4)); - eh.p[1].p_filesz = eh.p[1].p_memsz = htole32(hdr->data); - eh.sh[2].sh_addr = eh.p[0].p_vaddr; - eh.sh[2].sh_offset = eh.p[0].p_offset; - eh.sh[2].sh_size = eh.p[0].p_filesz; - eh.sh[3].sh_addr = eh.p[1].p_vaddr; - eh.sh[3].sh_offset = eh.p[1].p_offset; - eh.sh[3].sh_size = eh.p[1].p_filesz; - writex(fd, &eh, sizeof(eh)); - hdr->size = sizeof(eh); - } -} - -/* - * Safe copy from input file to output file. - */ -static void -copy(int fdi, int fdo, size_t nbyte, off_t offset) -{ - char buf[8192]; - size_t n; - - while (nbyte) { - if ((n = sizeof(buf)) > nbyte) - n = nbyte; - if (readx(fdi, buf, n, offset) != n) - errx(2, "%s: Short read", fname); - writex(fdo, buf, n); - nbyte -= n; - offset = -1; - } -} - -/* - * Safe read from input file. - */ -static size_t -readx(int fd, void *buf, size_t nbyte, off_t offset) -{ - ssize_t n; - - if (offset != -1 && lseek(fd, offset, SEEK_SET) != offset) - err(2, "%s", fname); - if ((n = read(fd, buf, nbyte)) == -1) - err(2, "%s", fname); - return n; -} - -/* - * Safe write to output file. - */ -static void -writex(int fd, const void *buf, size_t nbyte) -{ - ssize_t n; - - if ((n = write(fd, buf, nbyte)) == -1) - err(2, "%s", tname); - if ((size_t)n != nbyte) - errx(2, "%s: Short write", tname); -} - -/* - * Safe seek in output file. - */ -static void -seekx(int fd, off_t offset) -{ - if (lseek(fd, offset, SEEK_SET) != offset) - err(2, "%s", tname); -} - -/* - * Convert an option argument to a format code. - */ -static unsigned int -optfmt(const char *arg) -{ - unsigned int i; - - for (i = 0; i < F_CNT && strcmp(arg, fmtlist[i]); i++); - if (i == F_CNT) - errx(1, "%s: Unknown format", arg); - return i; -} - -/* - * Convert an option argument to an address. - */ -static uint32_t -optaddr(const char *arg) -{ - char *s; - unsigned long x; - - errno = 0; - x = strtoul(arg, &s, 0); - if (errno || !*arg || *s || x > MAXU32) - errx(1, "%s: Illegal address", arg); - return x; -} - -/* - * Convert an option argument to a page number. - */ -static int -optpage(const char *arg, int hi) -{ - char *s; - long x; - - errno = 0; - x = strtol(arg, &s, 0); - if (errno || !*arg || *s || x < 0 || x > hi) - errx(1, "%s: Illegal page number", arg); - return x; -} - -/* - * Display a warning. - */ -static void -Warn(const char *locus, const char *fmt, ...) -{ - va_list ap; - char *s; - - if (!quiet) { - asprintf(&s, "%s: Warning: %s", locus, fmt); - va_start(ap, fmt); - vwarnx(s, ap); - va_end(ap); - free(s); - } -} - -/* - * Display usage information. - */ -static void -usage(void) -{ - fprintf(stderr, "%s\n%s\n", - "usage: btxld [-qv] [-b file] [-E address] [-e address] [-f format]", - " [-l file] [-o filename] [-P page] [-W page] file"); - exit(1); -} diff --git a/usr.sbin/btxld/elfh.c b/usr.sbin/btxld/elfh.c deleted file mode 100644 index 2790d5a..0000000 --- a/usr.sbin/btxld/elfh.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 1998 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include - -#include -#include "elfh.h" - -#define SET_ME 0xeeeeeeee /* filled in by btxld */ - -/* - * ELF header template. - */ -const struct elfh elfhdr = { - { - { - ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, /* e_ident */ - ELFCLASS32, ELFDATA2LSB, EV_CURRENT, 0, - 'F', 'r', 'e', 'e', 'B', 'S', 'D', 0 - }, - htole16(ET_EXEC), /* e_type */ - htole16(EM_386), /* e_machine */ - htole32(EV_CURRENT), /* e_version */ - htole32(SET_ME), /* e_entry */ - htole32(offsetof(struct elfh, p)), /* e_phoff */ - htole32(offsetof(struct elfh, sh)), /* e_shoff */ - 0, /* e_flags */ - htole16(sizeof(elfhdr.e)), /* e_ehsize */ - htole16(sizeof(elfhdr.p[0])), /* e_phentsize */ - htole16(sizeof(elfhdr.p) / sizeof(elfhdr.p[0])), /* e_phnum */ - htole16(sizeof(elfhdr.sh[0])), /* e_shentsize */ - htole16(sizeof(elfhdr.sh) / sizeof(elfhdr.sh[0])), /* e_shnum */ - htole16(1) /* e_shstrndx */ - }, - { - { - htole32(PT_LOAD), /* p_type */ - htole32(sizeof(elfhdr)), /* p_offset */ - htole32(SET_ME), /* p_vaddr */ - htole32(SET_ME), /* p_paddr */ - htole32(SET_ME), /* p_filesz */ - htole32(SET_ME), /* p_memsz */ - htole32(PF_R | PF_X), /* p_flags */ - htole32(0x1000) /* p_align */ - }, - { - htole32(PT_LOAD), /* p_type */ - htole32(SET_ME), /* p_offset */ - htole32(SET_ME), /* p_vaddr */ - htole32(SET_ME), /* p_paddr */ - htole32(SET_ME), /* p_filesz */ - htole32(SET_ME), /* p_memsz */ - htole32(PF_R | PF_W), /* p_flags */ - htole32(0x1000) /* p_align */ - } - }, - { - { - 0, htole32(SHT_NULL), 0, 0, 0, 0, htole32(SHN_UNDEF), 0, 0, 0 - }, - { - htole32(1), /* sh_name */ - htole32(SHT_STRTAB), /* sh_type */ - 0, /* sh_flags */ - 0, /* sh_addr */ - htole32(offsetof(struct elfh, shstrtab)), /* sh_offset */ - htole32(sizeof(elfhdr.shstrtab)), /* sh_size */ - htole32(SHN_UNDEF), /* sh_link */ - 0, /* sh_info */ - htole32(1), /* sh_addralign */ - 0 /* sh_entsize */ - }, - { - htole32(0xb), /* sh_name */ - htole32(SHT_PROGBITS), /* sh_type */ - htole32(SHF_EXECINSTR | SHF_ALLOC), /* sh_flags */ - htole32(SET_ME), /* sh_addr */ - htole32(SET_ME), /* sh_offset */ - htole32(SET_ME), /* sh_size */ - htole32(SHN_UNDEF), /* sh_link */ - 0, /* sh_info */ - htole32(4), /* sh_addralign */ - 0 /* sh_entsize */ - }, - { - htole32(0x11), /* sh_name */ - htole32(SHT_PROGBITS), /* sh_type */ - htole32(SHF_ALLOC | SHF_WRITE), /* sh_flags */ - htole32(SET_ME), /* sh_addr */ - htole32(SET_ME), /* sh_offset */ - htole32(SET_ME), /* sh_size */ - htole32(SHN_UNDEF), /* sh_link */ - 0, /* sh_info */ - htole32(4), /* sh_addralign */ - 0 /* sh_entsize */ - } - }, - "\0.shstrtab\0.text\0.data" /* shstrtab */ -}; diff --git a/usr.sbin/btxld/elfh.h b/usr.sbin/btxld/elfh.h deleted file mode 100644 index a4ab134..0000000 --- a/usr.sbin/btxld/elfh.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 1998 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, - * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include - -struct elfh { - Elf32_Ehdr e; /* ELF header */ - Elf32_Phdr p[2]; /* program header */ - Elf32_Shdr sh[4]; /* section header */ - char shstrtab[28]; /* section header string table */ -}; - -extern const struct elfh elfhdr; /* ELF header template */ diff --git a/usr.sbin/burncd/Makefile b/usr.sbin/burncd/Makefile deleted file mode 100644 index 11e07c7..0000000 --- a/usr.sbin/burncd/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= burncd -MAN= burncd.8 - -.include diff --git a/usr.sbin/burncd/burncd.8 b/usr.sbin/burncd/burncd.8 deleted file mode 100644 index e2996ba..0000000 --- a/usr.sbin/burncd/burncd.8 +++ /dev/null @@ -1,222 +0,0 @@ -.\" -.\" Copyright (c) 2000,2001,2002 Søren Schmidt -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer, -.\" without modification, immediately at the beginning of the file. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd December 21, 2009 -.Dt BURNCD 8 -.Os -.Sh NAME -.Nm burncd -.Nd control the ATAPI CD-R/RW driver -.Sh SYNOPSIS -.Nm -.Op Fl deFlmnpqtv -.Op Fl f Ar device -.Op Fl s Ar speed -.Op Ar command -.Op Ar command Ar -.Sh DESCRIPTION -The -.Nm -utility is used to burn CD-R/RW media using the ATAPI cd driver. -.Pp -Available options and operands: -.Bl -tag -width XXXXXXXXXXXX -.It Fl d -burn the CD-R/RW in DAO (disk at once) mode. -.It Fl e -eject the medium when done. -.It Fl f Ar device -set the device to use for the burning process. -.It Fl F -force operation regardless of warnings. -.It Fl l -read a list of image files from filename. -.It Fl m -close disk in multisession mode (otherwise disk is closed as singlesession). -.It Fl n -do not write gaps between data tracks in DAO mode. -.It Fl p -use preemphasis on audio tracks. -.It Fl q -quiet, do not print progress messages. -.It Fl s Ar speed -set the speed of the burner device. -Defaults to 4. -Specify -.Dq Li max -to use the drive's fastest speed. -.It Fl t -test write, do not actually write on the media. -.It Fl v -verbose, print extra progress messages. -.El -.Pp -.Ar command -may be one of: -.Bl -tag -width XXXXXXXXXXXX -.It Cm msinfo -Show the first LBA of the last track on the media -and the next writeable address on the media for use with the -.Xr mkisofs 8 Ns 's Pq Pa ports/sysutils/cdrtools -.Fl C -switch when adding additional data to ISO file systems with extra sessions. -.It Cm blank -Blank a CD-RW medium. -This uses the fast blanking method, so data are not physically overwritten, -only those areas that make the media appear blank for further usage are erased. -.It Cm eject -Eject the medium when done. -This is equivalent to the -.Fl e -option. -.It Cm erase -Erase a CD-RW medium. -This erases the entire media. -Can take up to 1 hour to finish. -.It Cm format Brq Cm dvd+rw | dvd-rw -Formats a DVD+RW or DVD-RW media to the default max size and 2048 byte blocks. -This operation can take a long time to finish. -Progress reporting is done during the process. -.It Cm fixate -Fixate the medium so that the TOC is generated and the media can be used -in an ordinary CD drive. -The driver defaults to creating singlesession media (see -.Fl m -option). -Ignored in DAO mode (see -.Fl d -option). -.It Cm raw | audio -Set the write mode to produce audio (raw mode) tracks for the following -images on the command line. -.It Cm data | mode1 -Set the write mode to produce data (mode1) tracks for the following -image files -on the command line. -.It Cm mode2 -Set the write mode to produce data (mode2) tracks for the following -image files -on the command line. -.It Cm XAmode1 -Set the write mode to produce data (XAmode1) tracks for the following image -files on the command line. -.It Cm XAmode2 -Set the write mode to produce data (XAmode2) tracks for the following image -files on the command line. -.It Cm vcd -Set the write mode to produce VCD/SVCD tracks for the following image files -on the command line. -This automatically sets DAO -.Pq Fl d -and -.Dq "no gaps" -.Pq Fl n -modes. -.It Cm dvdrw -Set the write mode to write a DVD+RW from the following image. -DVDs only have one track. -.It Ar file -All other arguments are treated as filenames of images to write to the media, -or in case the -.Fl l -option is used as files containing lists of images. -.El -.Pp -Files whose length are not a multiple of the current media blocksize are -quietly zero padded to fit the blocksize requirement. -The conventional filename -.Fl -refers to stdin, and can only be used once. -.Sh ENVIRONMENT -The following environment variables affect the execution of -.Nm : -.Bl -tag -width ".Ev BURNCD_SPEED" -.It Ev BURNCD_SPEED -The write speed to use if one is not specified with the -.Fl s -flag. -.It Ev CDROM -The CD device to use if one is not specified with the -.Fl f -flag. -.El -.Sh FILES -.Bl -tag -width ".Pa /dev/acd0" -.It Pa /dev/acd0 -The default device, if not overridden by the -.Ev CDROM -environment variable or the -.Fl f -option. -.El -.Sh EXAMPLES -The typical usage for burning a data CD-R: -.Pp -.Dl "burncd -f /dev/acd0 data file1 fixate" -.Pp -The typical usage for burning an audio CD-R: -.Pp -.Dl "burncd -f /dev/acd0 audio file1 file2 file3 fixate" -.Pp -The typical usage for burning an audio CD-R in DAO mode: -.Pp -.Dl "burncd -f /dev/acd0 -d audio file1 file2 file3" -.Pp -The typical usage for burning a mixed mode CD-R: -.Pp -.Dl "burncd -f /dev/acd0 data file1 audio file2 file3 fixate" -.Pp -The typical usage for burning from a compressed image file on stdin: -.Pp -.Dl "gunzip -c file.iso.gz | burncd -f /dev/acd0 data - fixate" -.Pp -In the examples above, the files burned to data CD-Rs are assumed to -be ISO9660 file systems. -.Xr mkisofs 8 , -available in the -.Fx -Ports Collection, -as part of the -.Pa sysutils/cdrtools -port, is commonly used to create ISO9660 file system images -from a given directory tree. -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 4.0 . -.Sh AUTHORS -The -.Nm -utility and this manpage was contributed by -.An S\(/oren Schmidt , -Denmark -.Aq sos@FreeBSD.org . -.Sh BUGS -Probably, please report when found. diff --git a/usr.sbin/burncd/burncd.c b/usr.sbin/burncd/burncd.c deleted file mode 100644 index 43a0a09..0000000 --- a/usr.sbin/burncd/burncd.c +++ /dev/null @@ -1,741 +0,0 @@ -/*- - * Copyright (c) 2000,2001,2002 Søren Schmidt - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * without modification, immediately at the beginning of the file. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BLOCKS 16 - -struct track_info { - int file; - char file_name[MAXPATHLEN + 1]; - off_t file_size; - int block_size; - int block_type; - int pregap; - int addr; -}; -static struct track_info tracks[100]; -static int quiet, verbose, saved_block_size, notracks; -static volatile sig_atomic_t global_fd_for_cleanup; - -void add_track(char *, int, int, int); -void do_DAO(int fd, int, int); -void do_TAO(int fd, int, int, int); -void do_format(int, int, char *); -int write_file(int fd, struct track_info *); -int roundup_blocks(struct track_info *); -void cue_ent(struct cdr_cue_entry *, int, int, int, int, int, int, int); -void cleanup(int); -void cleanup_flush(void); -void cleanup_signal(int); -void usage(void); - -int -main(int argc, char **argv) -{ - int arg, addr, ch, fd; - int dao = 0, eject = 0, fixate = 0, list = 0, multi = 0, preemp = 0; - int nogap = 0, speed = 4 * 177, test_write = 0, force = 0; - int block_size = 0, block_type = 0, cdopen = 0, dvdrw = 0; - const char *dev, *env_speed; - - if ((dev = getenv("CDROM")) == NULL) - dev = "/dev/acd0"; - - env_speed = getenv("BURNCD_SPEED"); - - while ((ch = getopt(argc, argv, "def:Flmnpqs:tv")) != -1) { - switch (ch) { - case 'd': - dao = 1; - break; - - case 'e': - eject = 1; - break; - - case 'f': - dev = optarg; - break; - - case 'F': - force = 1; - break; - - case 'l': - list = 1; - break; - - case 'm': - multi = 1; - break; - - case 'n': - nogap = 1; - break; - - case 'p': - preemp = 1; - break; - - case 'q': - quiet = 1; - break; - - case 's': - env_speed = optarg; - break; - - case 't': - test_write = 1; - break; - - case 'v': - verbose = 1; - break; - - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (env_speed == NULL) - ; - else if (strcasecmp("max", env_speed) == 0) - speed = CDR_MAX_SPEED; - else - speed = atoi(env_speed) * 177; - if (speed <= 0) - errx(EX_USAGE, "Invalid speed: %s", env_speed); - - if (argc == 0) - usage(); - - if ((fd = open(dev, O_RDWR, 0)) < 0) - err(EX_NOINPUT, "open(%s)", dev); - - if (ioctl(fd, CDRIOCGETBLOCKSIZE, &saved_block_size) < 0) - err(EX_IOERR, "ioctl(CDRIOCGETBLOCKSIZE)"); - - if (ioctl(fd, CDRIOCWRITESPEED, &speed) < 0) - err(EX_IOERR, "ioctl(CDRIOCWRITESPEED)"); - - global_fd_for_cleanup = fd; - err_set_exit(cleanup); - signal(SIGHUP, cleanup_signal); - signal(SIGINT, cleanup_signal); - signal(SIGTERM, cleanup_signal); - - for (arg = 0; arg < argc; arg++) { - if (!strcasecmp(argv[arg], "fixate")) { - fixate = 1; - continue; - } - if (!strcasecmp(argv[arg], "eject")) { - eject = 1; - break; - } - if (!strcasecmp(argv[arg], "msinfo")) { - struct ioc_read_toc_single_entry entry; - struct ioc_toc_header header; - - if (ioctl(fd, CDIOREADTOCHEADER, &header) < 0) - err(EX_IOERR, "ioctl(CDIOREADTOCHEADER)"); - bzero(&entry, sizeof(struct ioc_read_toc_single_entry)); - entry.address_format = CD_LBA_FORMAT; - entry.track = header.ending_track; - if (ioctl(fd, CDIOREADTOCENTRY, &entry) < 0) - err(EX_IOERR, "ioctl(CDIOREADTOCENTRY)"); - if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) < 0) - err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)"); - fprintf(stdout, "%d,%d\n", - ntohl(entry.entry.addr.lba), addr); - - break; - } - if ((!strcasecmp(argv[arg], "erase") || - !strcasecmp(argv[arg], "blank")) && !test_write) { - int blank, pct, last = 0; - - if (!strcasecmp(argv[arg], "erase")) - blank = CDR_B_ALL; - else - blank = CDR_B_MIN; - if (!quiet) - fprintf(stderr, "%sing CD, please wait..\r", - blank == CDR_B_ALL ? "eras" : "blank"); - - if (ioctl(fd, CDRIOCBLANK, &blank) < 0) - err(EX_IOERR, "ioctl(CDRIOCBLANK)"); - while (1) { - sleep(1); - if (ioctl(fd, CDRIOCGETPROGRESS, &pct) == -1) - err(EX_IOERR,"ioctl(CDRIOGETPROGRESS)"); - if (pct > 0 && !quiet) - fprintf(stderr, - "%sing CD - %d %% done \r", - blank == CDR_B_ALL ? - "eras" : "blank", pct); - if (pct == 100 || (pct == 0 && last > 90)) - break; - last = pct; - } - if (!quiet) - printf("\n"); - continue; - } - if (!strcasecmp(argv[arg], "format") && !test_write) { - if (arg + 1 < argc && - (!strcasecmp(argv[arg + 1], "dvd+rw") || - !strcasecmp(argv[arg + 1], "dvd-rw"))) - do_format(fd, force, argv[arg + 1]); - else - errx(EX_NOINPUT, "format media type invalid"); - arg++; - continue; - } - if (!strcasecmp(argv[arg], "audio") || !strcasecmp(argv[arg], "raw")) { - block_type = CDR_DB_RAW; - block_size = 2352; - continue; - } - if (!strcasecmp(argv[arg], "data") || !strcasecmp(argv[arg], "mode1")) { - block_type = CDR_DB_ROM_MODE1; - block_size = 2048; - continue; - } - if (!strcasecmp(argv[arg], "mode2")) { - block_type = CDR_DB_ROM_MODE2; - block_size = 2336; - continue; - } - if (!strcasecmp(argv[arg], "xamode1")) { - block_type = CDR_DB_XA_MODE1; - block_size = 2048; - continue; - } - if (!strcasecmp(argv[arg], "xamode2")) { - block_type = CDR_DB_XA_MODE2_F2; - block_size = 2324; - continue; - } - if (!strcasecmp(argv[arg], "vcd")) { - block_type = CDR_DB_XA_MODE2_F2; - block_size = 2352; - dao = 1; - nogap = 1; - continue; - } - if (!strcasecmp(argv[arg], "dvdrw")) { - block_type = CDR_DB_ROM_MODE1; - block_size = 2048; - dvdrw = 1; - continue; - } - - if (!block_size) - errx(EX_NOINPUT, "no data format selected"); - if (list) { - char file_buf[MAXPATHLEN + 1], *eol; - FILE *fp; - - if ((fp = fopen(argv[arg], "r")) == NULL) - err(EX_NOINPUT, "fopen(%s)", argv[arg]); - - while (fgets(file_buf, sizeof(file_buf), fp) != NULL) { - if (*file_buf == '#' || *file_buf == '\n') - continue; - if ((eol = strchr(file_buf, '\n'))) - *eol = '\0'; - add_track(file_buf, block_size, block_type, nogap); - } - if (feof(fp)) - fclose(fp); - else - err(EX_IOERR, "fgets(%s)", file_buf); - } - else - add_track(argv[arg], block_size, block_type, nogap); - } - if (notracks) { - if (dvdrw && notracks > 1) - errx(EX_USAGE, "DVD's only have 1 track"); - if (ioctl(fd, CDIOCSTART, 0) < 0) - err(EX_IOERR, "ioctl(CDIOCSTART)"); - if (!cdopen) { - if (ioctl(fd, CDRIOCINITWRITER, &test_write) < 0) - err(EX_IOERR, "ioctl(CDRIOCINITWRITER)"); - cdopen = 1; - } - if (dao) - do_DAO(fd, test_write, multi); - else - do_TAO(fd, test_write, preemp, dvdrw); - } - if (!test_write && fixate && !dao && !dvdrw) { - if (!quiet) - fprintf(stderr, "fixating CD, please wait..\n"); - if (ioctl(fd, CDRIOCFIXATE, &multi) < 0) - err(EX_IOERR, "ioctl(CDRIOCFIXATE)"); - } - - if (ioctl(fd, CDRIOCSETBLOCKSIZE, &saved_block_size) < 0) { - err_set_exit(NULL); - err(EX_IOERR, "ioctl(CDRIOCSETBLOCKSIZE)"); - } - - if (eject) - if (ioctl(fd, CDIOCEJECT) < 0) - err(EX_IOERR, "ioctl(CDIOCEJECT)"); - - signal(SIGHUP, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - close(fd); - exit(EX_OK); -} - -void -add_track(char *name, int block_size, int block_type, int nogap) -{ - struct stat sb; - int file; - static int done_stdin = 0; - - if (!strcmp(name, "-")) { - if (done_stdin) { - warn("skipping multiple usages of stdin"); - return; - } - file = STDIN_FILENO; - done_stdin = 1; - } - else if ((file = open(name, O_RDONLY, 0)) < 0) - err(EX_NOINPUT, "open(%s)", name); - if (fstat(file, &sb) < 0) - err(EX_IOERR, "fstat(%s)", name); - tracks[notracks].file = file; - strncpy(tracks[notracks].file_name, name, MAXPATHLEN); - if (file == STDIN_FILENO) - tracks[notracks].file_size = -1; - else - tracks[notracks].file_size = sb.st_size; - tracks[notracks].block_size = block_size; - tracks[notracks].block_type = block_type; - - if (nogap && notracks) - tracks[notracks].pregap = 0; - else { - if (tracks[notracks - (notracks > 0)].block_type == block_type) - tracks[notracks].pregap = 150; - else - tracks[notracks].pregap = 255; - } - - if (verbose) { - int pad = 0; - - if (tracks[notracks].file_size / tracks[notracks].block_size != - roundup_blocks(&tracks[notracks])) - pad = 1; - fprintf(stderr, - "adding type 0x%02x file %s size %jd KB %d blocks %s\n", - tracks[notracks].block_type, name, - (intmax_t)sb.st_size/1024, - roundup_blocks(&tracks[notracks]), - pad ? "(0 padded)" : ""); - } - notracks++; -} - -void -do_DAO(int fd, int test_write, int multi) -{ - struct cdr_cuesheet sheet; - struct cdr_cue_entry cue[100]; - int format = CDR_SESS_CDROM; - int addr, i, j = 0; - - int bt2ctl[16] = { 0x0, -1, -1, -1, -1, -1, -1, -1, - 0x4, 0x4, 0x4, 0x4, 0x4, 0x4, -1, -1 }; - - int bt2df[16] = { 0x0, -1, -1, -1, -1, -1, -1, -1, - 0x10, 0x30, 0x20, -1, 0x21, -1, -1, -1 }; - - if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) < 0) - err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)"); - if (verbose) - fprintf(stderr, "next writeable LBA %d\n", addr); - - cue_ent(&cue[j++], bt2ctl[tracks[0].block_type], 0x01, 0x00, 0x0, - (bt2df[tracks[0].block_type] & 0xf0) | - (tracks[0].block_type < 8 ? 0x01 : 0x04), 0x00, addr); - - for (i = 0; i < notracks; i++) { - if (bt2ctl[tracks[i].block_type] < 0 || - bt2df[tracks[i].block_type] < 0) - errx(EX_IOERR, "track type not supported in DAO mode"); - - if (tracks[i].block_type >= CDR_DB_XA_MODE1) - format = CDR_SESS_CDROM_XA; - - if (i == 0) { - addr += tracks[i].pregap; - tracks[i].addr = addr; - - cue_ent(&cue[j++], bt2ctl[tracks[i].block_type], - 0x01, i+1, 0x1, bt2df[tracks[i].block_type], - 0x00, addr); - - } - else { - if (tracks[i].pregap) { - if (tracks[i].block_type > 0x7) { - cue_ent(&cue[j++],bt2ctl[tracks[i].block_type], - 0x01, i+1, 0x0, - (bt2df[tracks[i].block_type] & 0xf0) | - (tracks[i].block_type < 8 ? 0x01 :0x04), - 0x00, addr); - } - else - cue_ent(&cue[j++],bt2ctl[tracks[i].block_type], - 0x01, i+1, 0x0, - bt2df[tracks[i].block_type], - 0x00, addr); - } - tracks[i].addr = tracks[i - 1].addr + - roundup_blocks(&tracks[i - 1]); - - cue_ent(&cue[j++], bt2ctl[tracks[i].block_type], - 0x01, i+1, 0x1, bt2df[tracks[i].block_type], - 0x00, addr + tracks[i].pregap); - - if (tracks[i].block_type > 0x7) - addr += tracks[i].pregap; - } - addr += roundup_blocks(&tracks[i]); - } - - cue_ent(&cue[j++], bt2ctl[tracks[i - 1].block_type], 0x01, 0xaa, 0x01, - (bt2df[tracks[i - 1].block_type] & 0xf0) | - (tracks[i - 1].block_type < 8 ? 0x01 : 0x04), 0x00, addr); - - sheet.len = j * 8; - sheet.entries = cue; - sheet.test_write = test_write; - sheet.session_type = multi ? CDR_SESS_MULTI : CDR_SESS_NONE; - sheet.session_format = format; - if (verbose) { - u_int8_t *ptr = (u_int8_t *)sheet.entries; - - fprintf(stderr,"CUE sheet:"); - for (i = 0; i < sheet.len; i++) - if (i % 8) - fprintf(stderr," %02x", ptr[i]); - else - fprintf(stderr,"\n%02x", ptr[i]); - fprintf(stderr,"\n"); - } - - if (ioctl(fd, CDRIOCSENDCUE, &sheet) < 0) - err(EX_IOERR, "ioctl(CDRIOCSENDCUE)"); - - for (i = 0; i < notracks; i++) { - if (write_file(fd, &tracks[i])) { - cleanup_flush(); - err(EX_IOERR, "write_file"); - } - } - - ioctl(fd, CDRIOCFLUSH); -} - -void -do_TAO(int fd, int test_write, int preemp, int dvdrw) -{ - struct cdr_track track; - int i; - - for (i = 0; i < notracks; i++) { - track.test_write = test_write; - track.datablock_type = tracks[i].block_type; - track.preemp = preemp; - if (ioctl(fd, CDRIOCINITTRACK, &track) < 0) - err(EX_IOERR, "ioctl(CDRIOCINITTRACK)"); - - if (dvdrw) - tracks[i].addr = 0; - else - if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, - &tracks[i].addr) < 0) - err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)"); - - if (!quiet) - fprintf(stderr, "next writeable LBA %d\n", - tracks[i].addr); - if (write_file(fd, &tracks[i])) { - cleanup_flush(); - err(EX_IOERR, "write_file"); - } - if (ioctl(fd, CDRIOCFLUSH) < 0) - err(EX_IOERR, "ioctl(CDRIOCFLUSH)"); - } -} - -#define NTOH3B(x) ((x&0x0000ff)<<16) | (x&0x00ff00) | ((x&0xff0000)>>16) - -void -do_format(int the_fd, int force, char *type) -{ - struct cdr_format_capacities capacities; - struct cdr_format_params format_params; - int count, i, pct, last = 0; - - if (ioctl(the_fd, CDRIOCREADFORMATCAPS, &capacities) == -1) - err(EX_IOERR, "ioctl(CDRIOCREADFORMATCAPS)"); - - if (verbose) { - fprintf(stderr, "format list entries=%zd\n", - capacities.length / sizeof(struct cdr_format_capacity)); - fprintf(stderr, "current format: blocks=%u type=0x%x block_size=%u\n", - ntohl(capacities.blocks), capacities.type, - NTOH3B(capacities.block_size)); - } - - count = capacities.length / sizeof(struct cdr_format_capacity); - if (verbose) { - for (i = 0; i < count; ++i) - fprintf(stderr, - "format %d: blocks=%u type=0x%x param=%u\n", - i, ntohl(capacities.format[i].blocks), - capacities.format[i].type, - NTOH3B(capacities.format[i].param)); - } - - for (i = 0; i < count; ++i) { - if (!strcasecmp(type, "dvd+rw")) { - if (capacities.format[i].type == 0x26) { - break; - } - } - if (!strcasecmp(type, "dvd-rw")) { - if (capacities.format[i].type == 0x0) { - break; - } - } - } - if (i == count) - errx(EX_IOERR, "could not find a valid format capacity"); - - if (!quiet) - fprintf(stderr,"formatting with blocks=%u type=0x%x param=%u\n", - ntohl(capacities.format[i].blocks), - capacities.format[i].type, - NTOH3B(capacities.format[i].param)); - - if (!force && capacities.type == 2) - errx(EX_IOERR, "media already formatted (use -F to override)"); - - memset(&format_params, 0, sizeof(struct cdr_format_params)); - format_params.fov = 1; - format_params.immed = 1; - format_params.length = ntohs(sizeof(struct cdr_format_capacity)); - memcpy(&format_params.format, &capacities.format[i], - sizeof(struct cdr_format_capacity)); - - if(ioctl(the_fd, CDRIOCFORMAT, &format_params) == -1) - err(EX_IOERR, "ioctl(CDRIOCFORMAT)"); - - while (1) { - sleep(1); - if (ioctl(the_fd, CDRIOCGETPROGRESS, &pct) == -1) - err(EX_IOERR, "ioctl(CDRIOGETPROGRESS)"); - if (pct > 0 && !quiet) - fprintf(stderr, "formatting DVD - %d %% done \r", - pct); - if (pct == 100 || (pct == 0 && last > 90)) - break; - last = pct; - } - if (!quiet) - fprintf(stderr, "\n"); -} - -int -write_file(int fd, struct track_info *track_info) -{ - off_t size, count, filesize; - char buf[2352*BLOCKS]; - static off_t tot_size = 0; - - filesize = track_info->file_size / 1024; - - if (ioctl(fd, CDRIOCSETBLOCKSIZE, &track_info->block_size) < 0) - err(EX_IOERR, "ioctl(CDRIOCSETBLOCKSIZE)"); - - if (track_info->addr >= 0) - lseek(fd, track_info->addr * track_info->block_size, SEEK_SET); - - if (verbose) - fprintf(stderr, "addr = %d size = %jd blocks = %d\n", - track_info->addr, (intmax_t)track_info->file_size, - roundup_blocks(track_info)); - - if (!quiet) { - if (track_info->file == STDIN_FILENO) - fprintf(stderr, "writing from stdin\n"); - else - fprintf(stderr, - "writing from file %s size %jd KB\n", - track_info->file_name, (intmax_t)filesize); - } - size = 0; - - while ((count = read(track_info->file, buf, - track_info->file_size == -1 - ? track_info->block_size * BLOCKS - : MIN((track_info->file_size - size), - track_info->block_size * BLOCKS))) > 0) { - int res; - - if (count % track_info->block_size) { - /* pad file to % block_size */ - bzero(&buf[count], - (track_info->block_size * BLOCKS) - count); - count = ((count / track_info->block_size) + 1) * - track_info->block_size; - } - if ((res = write(fd, buf, count)) != count) { - if (res == -1) { - fprintf(stderr, "\n"); - close(track_info->file); - return errno; - } else - fprintf(stderr, "\nonly wrote %d of %jd" - " bytes\n", res, (intmax_t)count); - break; - } - size += count; - tot_size += count; - if (!quiet) { - int pct; - - fprintf(stderr, "written this track %jd KB", - (intmax_t)size/1024); - if (track_info->file != STDIN_FILENO && filesize) { - pct = (size / 1024) * 100 / filesize; - fprintf(stderr, " (%d%%)", pct); - } - fprintf(stderr, " total %jd KB\r", - (intmax_t)tot_size / 1024); - } - if (track_info->file_size != -1 - && size >= track_info->file_size) - break; - } - - if (!quiet) - fprintf(stderr, "\n"); - close(track_info->file); - return 0; -} - -int -roundup_blocks(struct track_info *track) -{ - return ((track->file_size + track->block_size - 1) / track->block_size); -} - -void -cue_ent(struct cdr_cue_entry *cue, int ctl, int adr, int track, int idx, - int dataform, int scms, int lba) -{ - cue->adr = adr; - cue->ctl = ctl; - cue->track = track; - cue->index = idx; - cue->dataform = dataform; - cue->scms = scms; - lba += 150; - cue->min = lba / (60*75); - cue->sec = (lba % (60*75)) / 75; - cue->frame = (lba % (60*75)) % 75; -} - -void -cleanup(int dummy __unused) -{ - if (ioctl(global_fd_for_cleanup, CDRIOCSETBLOCKSIZE, - &saved_block_size) < 0) - err(EX_IOERR, "ioctl(CDRIOCSETBLOCKSIZE)"); -} - -void -cleanup_flush(void) -{ - if (ioctl(global_fd_for_cleanup, CDRIOCFLUSH) < 0) - err(EX_IOERR, "ioctl(CDRIOCFLUSH)"); -} - -void -cleanup_signal(int sig) -{ - signal(sig, SIG_IGN); - ioctl(global_fd_for_cleanup, CDRIOCFLUSH); - write(STDERR_FILENO, "\nAborted\n", 10); - _exit(EXIT_FAILURE); -} - -void -usage(void) -{ - fprintf(stderr, - "usage: %s [-deFlmnpqtv] [-f device] [-s speed] [command]" - " [command file ...]\n", getprogname()); - exit(EX_USAGE); -} diff --git a/usr.sbin/cdcontrol/Makefile b/usr.sbin/cdcontrol/Makefile deleted file mode 100644 index a505e3a..0000000 --- a/usr.sbin/cdcontrol/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= cdcontrol - -DPADD= ${LIBEDIT} ${LIBTERMCAP} -LDADD= -ledit -ltermcap - -.include diff --git a/usr.sbin/cdcontrol/cdcontrol.1 b/usr.sbin/cdcontrol/cdcontrol.1 deleted file mode 100644 index b8cf92d..0000000 --- a/usr.sbin/cdcontrol/cdcontrol.1 +++ /dev/null @@ -1,222 +0,0 @@ -.\" $FreeBSD$ -.\" -.Dd June 27, 2008 -.Dt CDCONTROL 1 -.Os -.Sh NAME -.Nm cdcontrol -.Nd compact disc control utility -.Sh SYNOPSIS -.Nm -.Op Fl sv -.Op Fl f Ar device -.Op Ar command ... -.Sh DESCRIPTION -The -.Nm -utility is a program to control audio features of a CD drive. -The device is a name such -as -.Pa cd0 -or -.Pa acd0 . -.Pp -If no -.Ar command -is given, then -.Nm -enters an interactive mode, reading commands from the standard input. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl s -Silent mode. -Do not print table headers and human readable comments. -.It Fl v -Verbose mode. -Print as much information as possible. -.It Fl f Ar device -Specify a device, such as -.Pa /dev/cd0 -or -.Pa acd0 . -Both absolute path and relative to -.Pa /dev -filename are possible. -The -.Fl f -option overrides -.Ev CDROM . -If neither -.Ev CDROM -nor the -.Fl f -option is specified, -.Nm -tries opening first -.Pa /dev/cdrom , -then -.Pa /dev/cd0 , -and finally -.Pa /dev/acd0 . -.El -.Pp -The available commands are listed below. -Only as many -characters as are required to uniquely identify a command -need be specified. -The word -.Ic play -can be omitted or the characters -.Ic + -and -.Ic - -can be used in the -place of -.Ic next -and -.Ic prev . -.Bl -tag -width indent -.It Ic play Ar first_track Op Ar last_track -Play from track -.Ar first_track -to track -.Ar last_track . -The first track has number 1. -Can be omitted in all cases. -.It Xo -.Ic play -.Ar start_m : Ns Ar start_s . Ns Ar start_f -.Op Ar end_m : Ns Ar end_s . Ns Ar end_f -.Xc -Play from the absolute address -(MSF) defined by -.Ar start_m -in minutes, -.Ar start_s , -in seconds and -.Ar start_f -(frame number) to the absolute address defined by -.Ar end_m -in minutes, -.Ar end_s , -in seconds and -.Ar end_f -(frame number). -Minutes are in the range 0-99. -Seconds are in the range 0-59. -Frame numbers are in the range 0-74. -.It Ic play Op # Ns Ar start_block Op Ar length -Play starting from the logical block -.Ar start_block -using -.Ar length -logical blocks. -.It Ic next Op Ar tracks -Skip forward a number of tracks (default 1). -.It Ic prev Op Ar tracks -Skip backward a number of tracks (default 1). -.It Ic pause -Stop playing. -Do not stop the disc. -.It Ic resume -Resume playing. -Used after the -.Ic pause -command. -.It Ic stop -Stop the disc. -.It Ic eject -Eject the disc. -.It Ic close -Inject the disc. -.It Ic volume -Same as -.Em status volume -command. -.It Ic volume Ar level -Set the volume of both channels to -.Ar level . -Allowed values are in the range 0-255. -.It Ic volume Ar left_channel right_channel -Set the volume of left channel to -.Ar left_channel -and the volume of right channel to -.Ar right_channel . -Allowed values are in the range 0-255. -.It Ic volume Cm mute -Turn the sound off. -.It Ic volume Cm mono -Set the mono mode. -.It Ic volume Cm stereo -Set the stereo mode. -.It Ic volume Cm left -Play the left subtrack on both left and right channels. -.It Ic volume Cm right -Play the right subtrack on both left and right channels. -.It Ic info -Print the table of contents. -.It Ic status Op Cm audio | media | volume -Print the information about the disc: -.Pp -.Bl -tag -width ".Cm volume" -compact -.It Cm audio -the current playing status and position -.It Cm media -the current media catalog status -.It Cm volume -the current values of the volume for left and right channels. -.El -.It Ic cdid -Display the serial number of the CD using the method used by the -.Tn CDDB -project -.Pq Pa http://www.cddb.org/ . -.It Ic help -Print the list of available commands. -.It Ic debug Cm on -Enable the debugging mode of the CD device driver. -.It Ic debug Cm off -Disable the driver debugging mode. -.It Ic reset -Perform the hardware reset of the device. -.It Ic set Cm msf -Set minute-second-frame ioctl mode (default). -.It Ic set Cm lba -Set LBA ioctl mode. -.It Ic speed Ar s -Set the highest speed that the drive should use for reading data. -The units are multiples of a single speed CDROM (150 KB/s). -Specify -.Dq Li max -to use the drive's fastest speed. -.It Ic quit -Quit the program. -.El -.Sh ENVIRONMENT -The following environment variables affect the execution of -.Nm : -.Bl -tag -width ".Ev CD_DRIVE" -.It Ev CDROM -The CD device to use, if one is not specified with the -.Fl f -option. -.It Ev CDPLAY , CD_DRIVE , DISC , MUSIC_CD -These variables have been deprecated in favour of -.Ev CDROM . -.El -.Sh FILES -.Bl -tag -width ".Pa /dev/mcd0" -compact -.It Pa /dev/cd0 -.It Pa /dev/mcd0 -.It Pa /dev/acd0 -.El -.Sh HISTORY -The -.Nm -command appeared in -.Fx 2.1 . -.Sh AUTHORS -.An Jean-Marc Zucconi -.An Andrey A. Chernov -.An Serge V. Vakulenko diff --git a/usr.sbin/cdcontrol/cdcontrol.c b/usr.sbin/cdcontrol/cdcontrol.c deleted file mode 100644 index 526f599..0000000 --- a/usr.sbin/cdcontrol/cdcontrol.c +++ /dev/null @@ -1,1289 +0,0 @@ -/* - * Compact Disc Control Utility by Serge V. Vakulenko . - * Based on the non-X based CD player by Jean-Marc Zucconi and - * Andrey A. Chernov. - * - * Fixed and further modified on 5-Sep-1995 by Jukka Ukkonen . - * - * 11-Sep-1995: Jukka A. Ukkonen - * A couple of further fixes to my own earlier "fixes". - * - * 18-Sep-1995: Jukka A. Ukkonen - * Added an ability to specify addresses relative to the - * beginning of a track. This is in fact a variation of - * doing the simple play_msf() call. - * - * 11-Oct-1995: Serge V.Vakulenko - * New eject algorithm. - * Some code style reformatting. - * - * 13-Dec-1999: Knut A. Syed - * Volume-command modified. If used with only one - * parameter it now sets both channels. If used without - * parameters it will print volume-info. - * Version 2.0.1 - * - * 27-Jun-2008 Pietro Cerutti - * Further enhancement to volume. Values not in range 0-255 - * are now reduced to be in range. This prevents overflow in - * the uchar storing the volume (256 -> 0, -20 -> 236, ...). - * Version 2.0.2 - * - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define VERSION "2.0.2" - -#define ASTS_INVALID 0x00 /* Audio status byte not valid */ -#define ASTS_PLAYING 0x11 /* Audio play operation in progress */ -#define ASTS_PAUSED 0x12 /* Audio play operation paused */ -#define ASTS_COMPLETED 0x13 /* Audio play operation successfully completed */ -#define ASTS_ERROR 0x14 /* Audio play operation stopped due to error */ -#define ASTS_VOID 0x15 /* No current audio status to return */ - -#ifdef DEFAULT_CD_DRIVE -# error "Setting DEFAULT_CD_DRIVE is no longer supported" -#endif - -#define CMD_DEBUG 1 -#define CMD_EJECT 2 -#define CMD_HELP 3 -#define CMD_INFO 4 -#define CMD_PAUSE 5 -#define CMD_PLAY 6 -#define CMD_QUIT 7 -#define CMD_RESUME 8 -#define CMD_STOP 9 -#define CMD_VOLUME 10 -#define CMD_CLOSE 11 -#define CMD_RESET 12 -#define CMD_SET 13 -#define CMD_STATUS 14 -#define CMD_CDID 15 -#define CMD_NEXT 16 -#define CMD_PREVIOUS 17 -#define CMD_SPEED 18 -#define STATUS_AUDIO 0x1 -#define STATUS_MEDIA 0x2 -#define STATUS_VOLUME 0x4 - -struct cmdtab { - int command; - const char *name; - unsigned min; - const char *args; -} cmdtab[] = { -{ CMD_CLOSE, "close", 1, "" }, -{ CMD_DEBUG, "debug", 1, "on | off" }, -{ CMD_EJECT, "eject", 1, "" }, -{ CMD_HELP, "?", 1, 0 }, -{ CMD_HELP, "help", 1, "" }, -{ CMD_INFO, "info", 1, "" }, -{ CMD_NEXT, "next", 1, "" }, -{ CMD_PAUSE, "pause", 2, "" }, -{ CMD_PLAY, "play", 1, "min1:sec1[.fram1] [min2:sec2[.fram2]]" }, -{ CMD_PLAY, "play", 1, "track1[.index1] [track2[.index2]]" }, -{ CMD_PLAY, "play", 1, "tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]]" }, -{ CMD_PLAY, "play", 1, "[#block [len]]" }, -{ CMD_PREVIOUS, "previous", 2, "" }, -{ CMD_QUIT, "quit", 1, "" }, -{ CMD_RESET, "reset", 4, "" }, -{ CMD_RESUME, "resume", 1, "" }, -{ CMD_SET, "set", 2, "msf | lba" }, -{ CMD_STATUS, "status", 1, "[audio | media | volume]" }, -{ CMD_STOP, "stop", 3, "" }, -{ CMD_VOLUME, "volume", 1, - " | left | right | mute | mono | stereo" }, -{ CMD_CDID, "cdid", 2, "" }, -{ CMD_SPEED, "speed", 2, "speed" }, -{ 0, NULL, 0, NULL } -}; - -struct cd_toc_entry toc_buffer[100]; - -const char *cdname; -int fd = -1; -int verbose = 1; -int msf = 1; - -int setvol(int, int); -int read_toc_entrys(int); -int play_msf(int, int, int, int, int, int); -int play_track(int, int, int, int); -int get_vol(int *, int *); -int status(int *, int *, int *, int *); -int open_cd(void); -int next_prev(char *arg, int); -int play(char *arg); -int info(char *arg); -int cdid(void); -int pstatus(char *arg); -char *input(int *); -void prtrack(struct cd_toc_entry *e, int lastflag); -void lba2msf(unsigned long lba, u_char *m, u_char *s, u_char *f); -unsigned int msf2lba(u_char m, u_char s, u_char f); -int play_blocks(int blk, int len); -int run(int cmd, char *arg); -char *parse(char *buf, int *cmd); -void help(void); -void usage(void); -char *use_cdrom_instead(const char *); -__const char *strstatus(int); -static u_int dbprog_discid(void); -__const char *cdcontrol_prompt(void); - -void help (void) -{ - struct cmdtab *c; - const char *s; - char n; - int i; - - for (c=cmdtab; c->name; ++c) { - if (! c->args) - continue; - printf("\t"); - for (i = c->min, s = c->name; *s; s++, i--) { - if (i > 0) - n = toupper(*s); - else - n = *s; - putchar(n); - } - if (*c->args) - printf (" %s", c->args); - printf ("\n"); - } - printf ("\n\tThe word \"play\" is not required for the play commands.\n"); - printf ("\tThe plain target address is taken as a synonym for play.\n"); -} - -void usage (void) -{ - fprintf (stderr, "usage: cdcontrol [-sv] [-f device] [command ...]\n"); - exit (1); -} - -char *use_cdrom_instead(const char *old_envvar) -{ - char *device; - - device = getenv(old_envvar); - if (device) - warnx("%s environment variable deprecated, " - "please use CDROM in the future.", old_envvar); - return device; -} - - -int main (int argc, char **argv) -{ - int cmd; - char *arg; - - for (;;) { - switch (getopt (argc, argv, "svhf:")) { - case -1: - break; - case 's': - verbose = 0; - continue; - case 'v': - verbose = 2; - continue; - case 'f': - cdname = optarg; - continue; - case 'h': - default: - usage (); - } - break; - } - argc -= optind; - argv += optind; - - if (argc > 0 && ! strcasecmp (*argv, "help")) - usage (); - - if (! cdname) { - cdname = getenv("CDROM"); - } - - if (! cdname) - cdname = use_cdrom_instead("MUSIC_CD"); - if (! cdname) - cdname = use_cdrom_instead("CD_DRIVE"); - if (! cdname) - cdname = use_cdrom_instead("DISC"); - if (! cdname) - cdname = use_cdrom_instead("CDPLAY"); - - if (argc > 0) { - char buf[80], *p; - int len, rc; - - for (p=buf; argc-->0; ++argv) { - len = strlen (*argv); - - if (p + len >= buf + sizeof (buf) - 1) - usage (); - - if (p > buf) - *p++ = ' '; - - strcpy (p, *argv); - p += len; - } - *p = 0; - arg = parse (buf, &cmd); - rc = run (cmd, arg); - if (rc < 0 && verbose) - warn(NULL); - - return (rc); - } - - if (verbose == 1) - verbose = isatty (0); - - if (verbose) { - printf ("Compact Disc Control utility, version %s\n", VERSION); - printf ("Type `?' for command list\n\n"); - } - - for (;;) { - arg = input (&cmd); - if (run (cmd, arg) < 0) { - if (verbose) - warn(NULL); - close (fd); - fd = -1; - } - fflush (stdout); - } -} - -int run (int cmd, char *arg) -{ - long speed; - int l, r, rc, count; - - switch (cmd) { - - case CMD_QUIT: - exit (0); - - case CMD_INFO: - if (fd < 0 && ! open_cd ()) - return (0); - - return info (arg); - - case CMD_CDID: - if (fd < 0 && ! open_cd ()) - return (0); - - return cdid (); - - case CMD_STATUS: - if (fd < 0 && ! open_cd ()) - return (0); - - return pstatus (arg); - - case CMD_NEXT: - case CMD_PREVIOUS: - if (fd < 0 && ! open_cd ()) - return (0); - - while (isspace (*arg)) - arg++; - - return next_prev (arg, cmd); - - case CMD_PAUSE: - if (fd < 0 && ! open_cd ()) - return (0); - - return ioctl (fd, CDIOCPAUSE); - - case CMD_RESUME: - if (fd < 0 && ! open_cd ()) - return (0); - - return ioctl (fd, CDIOCRESUME); - - case CMD_STOP: - if (fd < 0 && ! open_cd ()) - return (0); - - rc = ioctl (fd, CDIOCSTOP); - - (void) ioctl (fd, CDIOCALLOW); - - return (rc); - - case CMD_RESET: - if (fd < 0 && ! open_cd ()) - return (0); - - rc = ioctl (fd, CDIOCRESET); - if (rc < 0) - return rc; - close(fd); - fd = -1; - return (0); - - case CMD_DEBUG: - if (fd < 0 && ! open_cd ()) - return (0); - - if (! strcasecmp (arg, "on")) - return ioctl (fd, CDIOCSETDEBUG); - - if (! strcasecmp (arg, "off")) - return ioctl (fd, CDIOCCLRDEBUG); - - warnx("invalid command arguments"); - - return (0); - - case CMD_EJECT: - if (fd < 0 && ! open_cd ()) - return (0); - - (void) ioctl (fd, CDIOCALLOW); - rc = ioctl (fd, CDIOCEJECT); - if (rc < 0) - return (rc); - return (0); - - case CMD_CLOSE: - if (fd < 0 && ! open_cd ()) - return (0); - - (void) ioctl (fd, CDIOCALLOW); - rc = ioctl (fd, CDIOCCLOSE); - if (rc < 0) - return (rc); - close(fd); - fd = -1; - return (0); - - case CMD_PLAY: - if (fd < 0 && ! open_cd ()) - return (0); - - while (isspace (*arg)) - arg++; - - return play (arg); - - case CMD_SET: - if (! strcasecmp (arg, "msf")) - msf = 1; - else if (! strcasecmp (arg, "lba")) - msf = 0; - else - warnx("invalid command arguments"); - return (0); - - case CMD_VOLUME: - if (fd < 0 && !open_cd ()) - return (0); - - if (! strlen (arg)) { - char volume[] = "volume"; - - return pstatus (volume); - } - - if (! strncasecmp (arg, "left", strlen(arg))) - return ioctl (fd, CDIOCSETLEFT); - - if (! strncasecmp (arg, "right", strlen(arg))) - return ioctl (fd, CDIOCSETRIGHT); - - if (! strncasecmp (arg, "mono", strlen(arg))) - return ioctl (fd, CDIOCSETMONO); - - if (! strncasecmp (arg, "stereo", strlen(arg))) - return ioctl (fd, CDIOCSETSTERIO); - - if (! strncasecmp (arg, "mute", strlen(arg))) - return ioctl (fd, CDIOCSETMUTE); - - count = sscanf (arg, "%d %d", &l, &r); - if (count == 1) - return setvol (l, l); - if (count == 2) - return setvol (l, r); - warnx("invalid command arguments"); - return (0); - - case CMD_SPEED: - if (fd < 0 && ! open_cd ()) - return (0); - - errno = 0; - if (strcasecmp("max", arg) == 0) - speed = CDR_MAX_SPEED; - else - speed = strtol(arg, NULL, 10) * 177; - if (speed <= 0 || speed > INT_MAX) { - warnx("invalid command arguments %s", arg); - return (0); - } - return ioctl(fd, CDRIOCREADSPEED, &speed); - - default: - case CMD_HELP: - help (); - return (0); - - } -} - -int play (char *arg) -{ - struct ioc_toc_header h; - unsigned int n; - int rc, start, end = 0, istart = 1, iend = 1; - - rc = ioctl (fd, CDIOREADTOCHEADER, &h); - - if (rc < 0) - return (rc); - - n = h.ending_track - h.starting_track + 1; - rc = read_toc_entrys ((n + 1) * sizeof (struct cd_toc_entry)); - - if (rc < 0) - return (rc); - - if (! arg || ! *arg) { - /* Play the whole disc */ - if (msf) - return play_blocks (0, msf2lba (toc_buffer[n].addr.msf.minute, - toc_buffer[n].addr.msf.second, - toc_buffer[n].addr.msf.frame)); - else - return play_blocks (0, ntohl(toc_buffer[n].addr.lba)); - } - - if (strchr (arg, '#')) { - /* Play block #blk [ len ] */ - int blk, len = 0; - - if (2 != sscanf (arg, "#%d%d", &blk, &len) && - 1 != sscanf (arg, "#%d", &blk)) - goto Clean_up; - - if (len == 0) { - if (msf) - len = msf2lba (toc_buffer[n].addr.msf.minute, - toc_buffer[n].addr.msf.second, - toc_buffer[n].addr.msf.frame) - blk; - else - len = ntohl(toc_buffer[n].addr.lba) - blk; - } - return play_blocks (blk, len); - } - - if (strchr (arg, ':')) { - /* - * Play MSF m1:s1 [ .f1 ] [ m2:s2 [ .f2 ] ] - * - * Will now also undestand timed addresses relative - * to the beginning of a track in the form... - * - * tr1 m1:s1[.f1] [[tr2] [m2:s2[.f2]]] - */ - unsigned tr1, tr2; - unsigned m1, m2, s1, s2, f1, f2; - unsigned char tm, ts, tf; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (8 == sscanf (arg, "%d %d:%d.%d %d %d:%d.%d", - &tr1, &m1, &s1, &f1, &tr2, &m2, &s2, &f2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (7 == sscanf (arg, "%d %d:%d %d %d:%d.%d", - &tr1, &m1, &s1, &tr2, &m2, &s2, &f2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (7 == sscanf (arg, "%d %d:%d.%d %d %d:%d", - &tr1, &m1, &s1, &f1, &tr2, &m2, &s2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (7 == sscanf (arg, "%d %d:%d.%d %d:%d.%d", - &tr1, &m1, &s1, &f1, &m2, &s2, &f2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (6 == sscanf (arg, "%d %d:%d.%d %d:%d", - &tr1, &m1, &s1, &f1, &m2, &s2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (6 == sscanf (arg, "%d %d:%d %d:%d.%d", - &tr1, &m1, &s1, &m2, &s2, &f2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (6 == sscanf (arg, "%d %d:%d.%d %d %d", - &tr1, &m1, &s1, &f1, &tr2, &m2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (5 == sscanf (arg, "%d %d:%d %d:%d", &tr1, &m1, &s1, &m2, &s2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (5 == sscanf (arg, "%d %d:%d %d %d", - &tr1, &m1, &s1, &tr2, &m2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (5 == sscanf (arg, "%d %d:%d.%d %d", - &tr1, &m1, &s1, &f1, &tr2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (4 == sscanf (arg, "%d %d:%d %d", &tr1, &m1, &s1, &tr2)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (4 == sscanf (arg, "%d %d:%d.%d", &tr1, &m1, &s1, &f1)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - if (3 == sscanf (arg, "%d %d:%d", &tr1, &m1, &s1)) - goto Play_Relative_Addresses; - - tr2 = m2 = s2 = f2 = f1 = 0; - goto Try_Absolute_Timed_Addresses; - -Play_Relative_Addresses: - if (! tr1) - tr1 = 1; - else if (tr1 > n) - tr1 = n; - - tr1--; - - if (msf) { - tm = toc_buffer[tr1].addr.msf.minute; - ts = toc_buffer[tr1].addr.msf.second; - tf = toc_buffer[tr1].addr.msf.frame; - } else - lba2msf(ntohl(toc_buffer[tr1].addr.lba), - &tm, &ts, &tf); - if ((m1 > tm) - || ((m1 == tm) - && ((s1 > ts) - || ((s1 == ts) - && (f1 > tf))))) { - printf ("Track %d is not that long.\n", tr1); - return (0); - } - - f1 += tf; - if (f1 >= 75) { - s1 += f1 / 75; - f1 %= 75; - } - - s1 += ts; - if (s1 >= 60) { - m1 += s1 / 60; - s1 %= 60; - } - - m1 += tm; - - if (! tr2) { - if (m2 || s2 || f2) { - tr2 = tr1; - f2 += f1; - if (f2 >= 75) { - s2 += f2 / 75; - f2 %= 75; - } - - s2 += s1; - if (s2 > 60) { - m2 += s2 / 60; - s2 %= 60; - } - - m2 += m1; - } else { - tr2 = n; - if (msf) { - m2 = toc_buffer[n].addr.msf.minute; - s2 = toc_buffer[n].addr.msf.second; - f2 = toc_buffer[n].addr.msf.frame; - } else { - lba2msf(ntohl(toc_buffer[n].addr.lba), - &tm, &ts, &tf); - m2 = tm; - s2 = ts; - f2 = tf; - } - } - } else if (tr2 > n) { - tr2 = n; - m2 = s2 = f2 = 0; - } else { - if (m2 || s2 || f2) - tr2--; - if (msf) { - tm = toc_buffer[tr2].addr.msf.minute; - ts = toc_buffer[tr2].addr.msf.second; - tf = toc_buffer[tr2].addr.msf.frame; - } else - lba2msf(ntohl(toc_buffer[tr2].addr.lba), - &tm, &ts, &tf); - f2 += tf; - if (f2 >= 75) { - s2 += f2 / 75; - f2 %= 75; - } - - s2 += ts; - if (s2 > 60) { - m2 += s2 / 60; - s2 %= 60; - } - - m2 += tm; - } - - if (msf) { - tm = toc_buffer[n].addr.msf.minute; - ts = toc_buffer[n].addr.msf.second; - tf = toc_buffer[n].addr.msf.frame; - } else - lba2msf(ntohl(toc_buffer[n].addr.lba), - &tm, &ts, &tf); - if ((tr2 < n) - && ((m2 > tm) - || ((m2 == tm) - && ((s2 > ts) - || ((s2 == ts) - && (f2 > tf)))))) { - printf ("The playing time of the disc is not that long.\n"); - return (0); - } - return (play_msf (m1, s1, f1, m2, s2, f2)); - -Try_Absolute_Timed_Addresses: - if (6 != sscanf (arg, "%d:%d.%d%d:%d.%d", - &m1, &s1, &f1, &m2, &s2, &f2) && - 5 != sscanf (arg, "%d:%d.%d%d:%d", &m1, &s1, &f1, &m2, &s2) && - 5 != sscanf (arg, "%d:%d%d:%d.%d", &m1, &s1, &m2, &s2, &f2) && - 3 != sscanf (arg, "%d:%d.%d", &m1, &s1, &f1) && - 4 != sscanf (arg, "%d:%d%d:%d", &m1, &s1, &m2, &s2) && - 2 != sscanf (arg, "%d:%d", &m1, &s1)) - goto Clean_up; - - if (m2 == 0) { - if (msf) { - m2 = toc_buffer[n].addr.msf.minute; - s2 = toc_buffer[n].addr.msf.second; - f2 = toc_buffer[n].addr.msf.frame; - } else { - lba2msf(ntohl(toc_buffer[n].addr.lba), - &tm, &ts, &tf); - m2 = tm; - s2 = ts; - f2 = tf; - } - } - return play_msf (m1, s1, f1, m2, s2, f2); - } - - /* - * Play track trk1 [ .idx1 ] [ trk2 [ .idx2 ] ] - */ - if (4 != sscanf (arg, "%d.%d%d.%d", &start, &istart, &end, &iend) && - 3 != sscanf (arg, "%d.%d%d", &start, &istart, &end) && - 3 != sscanf (arg, "%d%d.%d", &start, &end, &iend) && - 2 != sscanf (arg, "%d.%d", &start, &istart) && - 2 != sscanf (arg, "%d%d", &start, &end) && - 1 != sscanf (arg, "%d", &start)) - goto Clean_up; - - if (end == 0) - end = n; - return (play_track (start, istart, end, iend)); - -Clean_up: - warnx("invalid command arguments"); - return (0); -} - -int next_prev (char *arg, int cmd) -{ - struct ioc_toc_header h; - int dir, junk, n, off, rc, trk; - - dir = (cmd == CMD_NEXT) ? 1 : -1; - rc = ioctl (fd, CDIOREADTOCHEADER, &h); - if (rc < 0) - return (rc); - - n = h.ending_track - h.starting_track + 1; - rc = status (&trk, &junk, &junk, &junk); - if (rc < 0) - return (-1); - - if (arg && *arg) { - if (sscanf (arg, "%u", &off) != 1) { - warnx("invalid command argument"); - return (0); - } else - trk += off * dir; - } else - trk += dir; - - if (trk > h.ending_track) - trk = 1; - - return (play_track (trk, 1, n, 1)); -} - -const char *strstatus (int sts) -{ - switch (sts) { - case ASTS_INVALID: return ("invalid"); - case ASTS_PLAYING: return ("playing"); - case ASTS_PAUSED: return ("paused"); - case ASTS_COMPLETED: return ("completed"); - case ASTS_ERROR: return ("error"); - case ASTS_VOID: return ("void"); - default: return ("??"); - } -} - -int pstatus (char *arg) -{ - struct ioc_vol v; - struct ioc_read_subchannel ss; - struct cd_sub_channel_info data; - int rc, trk, m, s, f; - int what = 0; - char *p, vmcn[(4 * 15) + 1]; - - while ((p = strtok(arg, " \t"))) { - arg = 0; - if (!strncasecmp(p, "audio", strlen(p))) - what |= STATUS_AUDIO; - else if (!strncasecmp(p, "media", strlen(p))) - what |= STATUS_MEDIA; - else if (!strncasecmp(p, "volume", strlen(p))) - what |= STATUS_VOLUME; - else { - warnx("invalid command arguments"); - return 0; - } - } - if (!what) - what = STATUS_AUDIO|STATUS_MEDIA|STATUS_VOLUME; - if (what & STATUS_AUDIO) { - rc = status (&trk, &m, &s, &f); - if (rc >= 0) - if (verbose) - printf ("Audio status = %d<%s>, current track = %d, current position = %d:%02d.%02d\n", - rc, strstatus (rc), trk, m, s, f); - else - printf ("%d %d %d:%02d.%02d\n", rc, trk, m, s, f); - else - printf ("No current status info available\n"); - } - if (what & STATUS_MEDIA) { - bzero (&ss, sizeof (ss)); - ss.data = &data; - ss.data_len = sizeof (data); - ss.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT; - ss.data_format = CD_MEDIA_CATALOG; - rc = ioctl (fd, CDIOCREADSUBCHANNEL, (char *) &ss); - if (rc >= 0) { - printf("Media catalog is %sactive", - ss.data->what.media_catalog.mc_valid ? "": "in"); - if (ss.data->what.media_catalog.mc_valid && - ss.data->what.media_catalog.mc_number[0]) - { - strvisx (vmcn, ss.data->what.media_catalog.mc_number, - (sizeof (vmcn) - 1) / 4, VIS_OCTAL | VIS_NL); - printf(", number \"%.*s\"", (int)sizeof (vmcn), vmcn); - } - putchar('\n'); - } else - printf("No media catalog info available\n"); - } - if (what & STATUS_VOLUME) { - rc = ioctl (fd, CDIOCGETVOL, &v); - if (rc >= 0) - if (verbose) - printf ("Left volume = %d, right volume = %d\n", - v.vol[0], v.vol[1]); - else - printf ("%d %d\n", v.vol[0], v.vol[1]); - else - printf ("No volume level info available\n"); - } - return(0); -} - -/* - * dbprog_sum - * Convert an integer to its text string representation, and - * compute its checksum. Used by dbprog_discid to derive the - * disc ID. - * - * Args: - * n - The integer value. - * - * Return: - * The integer checksum. - */ -static int -dbprog_sum(int n) -{ - char buf[12], - *p; - int ret = 0; - - /* For backward compatibility this algorithm must not change */ - sprintf(buf, "%u", n); - for (p = buf; *p != '\0'; p++) - ret += (*p - '0'); - - return(ret); -} - - -/* - * dbprog_discid - * Compute a magic disc ID based on the number of tracks, - * the length of each track, and a checksum of the string - * that represents the offset of each track. - * - * Args: - * s - Pointer to the curstat_t structure. - * - * Return: - * The integer disc ID. - */ -static u_int -dbprog_discid(void) -{ - struct ioc_toc_header h; - int rc; - int i, ntr, - t = 0, - n = 0; - - rc = ioctl (fd, CDIOREADTOCHEADER, &h); - if (rc < 0) - return 0; - ntr = h.ending_track - h.starting_track + 1; - i = msf; - msf = 1; - rc = read_toc_entrys ((ntr + 1) * sizeof (struct cd_toc_entry)); - msf = i; - if (rc < 0) - return 0; - /* For backward compatibility this algorithm must not change */ - for (i = 0; i < ntr; i++) { -#define TC_MM(a) toc_buffer[a].addr.msf.minute -#define TC_SS(a) toc_buffer[a].addr.msf.second - n += dbprog_sum((TC_MM(i) * 60) + TC_SS(i)); - - t += ((TC_MM(i+1) * 60) + TC_SS(i+1)) - - ((TC_MM(i) * 60) + TC_SS(i)); - } - - return((n % 0xff) << 24 | t << 8 | ntr); -} - -int cdid (void) -{ - u_int id; - - id = dbprog_discid(); - if (id) - { - if (verbose) - printf ("CDID="); - printf ("%08x\n",id); - } - return id ? 0 : 1; -} - -int info (char *arg __unused) -{ - struct ioc_toc_header h; - int rc, i, n; - - rc = ioctl (fd, CDIOREADTOCHEADER, &h); - if (rc >= 0) { - if (verbose) - printf ("Starting track = %d, ending track = %d, TOC size = %d bytes\n", - h.starting_track, h.ending_track, h.len); - else - printf ("%d %d %d\n", h.starting_track, - h.ending_track, h.len); - } else { - warn("getting toc header"); - return (rc); - } - - n = h.ending_track - h.starting_track + 1; - rc = read_toc_entrys ((n + 1) * sizeof (struct cd_toc_entry)); - if (rc < 0) - return (rc); - - if (verbose) { - printf ("track start duration block length type\n"); - printf ("-------------------------------------------------\n"); - } - - for (i = 0; i < n; i++) { - printf ("%5d ", toc_buffer[i].track); - prtrack (toc_buffer + i, 0); - } - printf ("%5d ", toc_buffer[n].track); - prtrack (toc_buffer + n, 1); - return (0); -} - -void lba2msf (unsigned long lba, u_char *m, u_char *s, u_char *f) -{ - lba += 150; /* block start offset */ - lba &= 0xffffff; /* negative lbas use only 24 bits */ - *m = lba / (60 * 75); - lba %= (60 * 75); - *s = lba / 75; - *f = lba % 75; -} - -unsigned int msf2lba (u_char m, u_char s, u_char f) -{ - return (((m * 60) + s) * 75 + f) - 150; -} - -void prtrack (struct cd_toc_entry *e, int lastflag) -{ - int block, next, len; - u_char m, s, f; - - if (msf) { - /* Print track start */ - printf ("%2d:%02d.%02d ", e->addr.msf.minute, - e->addr.msf.second, e->addr.msf.frame); - - block = msf2lba (e->addr.msf.minute, e->addr.msf.second, - e->addr.msf.frame); - } else { - block = ntohl(e->addr.lba); - lba2msf(block, &m, &s, &f); - /* Print track start */ - printf ("%2d:%02d.%02d ", m, s, f); - } - if (lastflag) { - /* Last track -- print block */ - printf (" - %6d - -\n", block); - return; - } - - if (msf) - next = msf2lba (e[1].addr.msf.minute, e[1].addr.msf.second, - e[1].addr.msf.frame); - else - next = ntohl(e[1].addr.lba); - len = next - block; - /* Take into account a start offset time. */ - lba2msf (len - 150, &m, &s, &f); - - /* Print duration, block, length, type */ - printf ("%2d:%02d.%02d %6d %6d %5s\n", m, s, f, block, len, - (e->control & 4) ? "data" : "audio"); -} - -int play_track (int tstart, int istart, int tend, int iend) -{ - struct ioc_play_track t; - - t.start_track = tstart; - t.start_index = istart; - t.end_track = tend; - t.end_index = iend; - - return ioctl (fd, CDIOCPLAYTRACKS, &t); -} - -int play_blocks (int blk, int len) -{ - struct ioc_play_blocks t; - - t.blk = blk; - t.len = len; - - return ioctl (fd, CDIOCPLAYBLOCKS, &t); -} - -int setvol (int left, int right) -{ - struct ioc_vol v; - - left = left < 0 ? 0 : left > 255 ? 255 : left; - right = right < 0 ? 0 : right > 255 ? 255 : right; - - v.vol[0] = left; - v.vol[1] = right; - v.vol[2] = 0; - v.vol[3] = 0; - - return ioctl (fd, CDIOCSETVOL, &v); -} - -int read_toc_entrys (int len) -{ - struct ioc_read_toc_entry t; - - t.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT; - t.starting_track = 0; - t.data_len = len; - t.data = toc_buffer; - - return (ioctl (fd, CDIOREADTOCENTRYS, (char *) &t)); -} - -int play_msf (int start_m, int start_s, int start_f, - int end_m, int end_s, int end_f) -{ - struct ioc_play_msf a; - - a.start_m = start_m; - a.start_s = start_s; - a.start_f = start_f; - a.end_m = end_m; - a.end_s = end_s; - a.end_f = end_f; - - return ioctl (fd, CDIOCPLAYMSF, (char *) &a); -} - -int status (int *trk, int *min, int *sec, int *frame) -{ - struct ioc_read_subchannel s; - struct cd_sub_channel_info data; - u_char mm, ss, ff; - - bzero (&s, sizeof (s)); - s.data = &data; - s.data_len = sizeof (data); - s.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT; - s.data_format = CD_CURRENT_POSITION; - - if (ioctl (fd, CDIOCREADSUBCHANNEL, (char *) &s) < 0) - return -1; - - *trk = s.data->what.position.track_number; - if (msf) { - *min = s.data->what.position.reladdr.msf.minute; - *sec = s.data->what.position.reladdr.msf.second; - *frame = s.data->what.position.reladdr.msf.frame; - } else { - lba2msf(ntohl(s.data->what.position.reladdr.lba), - &mm, &ss, &ff); - *min = mm; - *sec = ss; - *frame = ff; - } - - return s.data->header.audio_status; -} - -const char * -cdcontrol_prompt(void) -{ - return ("cdcontrol> "); -} - -char * -input (int *cmd) -{ -#define MAXLINE 80 - static EditLine *el = NULL; - static History *hist = NULL; - HistEvent he; - static char buf[MAXLINE]; - int num = 0; - int len; - const char *bp = NULL; - char *p; - - do { - if (verbose) { - if (!el) { - el = el_init("cdcontrol", stdin, stdout, - stderr); - hist = history_init(); - history(hist, &he, H_SETSIZE, 100); - el_set(el, EL_HIST, history, hist); - el_set(el, EL_EDITOR, "emacs"); - el_set(el, EL_PROMPT, cdcontrol_prompt); - el_set(el, EL_SIGNAL, 1); - el_source(el, NULL); - } - if ((bp = el_gets(el, &num)) == NULL || num == 0) { - *cmd = CMD_QUIT; - fprintf (stderr, "\r\n"); - return (0); - } - - len = (num > MAXLINE) ? MAXLINE : num; - memcpy(buf, bp, len); - buf[len] = 0; - history(hist, &he, H_ENTER, bp); -#undef MAXLINE - - } else { - if (! fgets (buf, sizeof (buf), stdin)) { - *cmd = CMD_QUIT; - fprintf (stderr, "\r\n"); - return (0); - } - } - p = parse (buf, cmd); - } while (! p); - return (p); -} - -char *parse (char *buf, int *cmd) -{ - struct cmdtab *c; - char *p; - unsigned int len; - - for (p=buf; isspace (*p); p++) - continue; - - if (isdigit (*p) || (p[0] == '#' && isdigit (p[1]))) { - *cmd = CMD_PLAY; - return (p); - } else if (*p == '+') { - *cmd = CMD_NEXT; - return (p + 1); - } else if (*p == '-') { - *cmd = CMD_PREVIOUS; - return (p + 1); - } - - for (buf = p; *p && ! isspace (*p); p++) - continue; - - len = p - buf; - if (! len) - return (0); - - if (*p) { /* It must be a spacing character! */ - char *q; - - *p++ = 0; - for (q=p; *q && *q != '\n' && *q != '\r'; q++) - continue; - *q = 0; - } - - *cmd = -1; - for (c=cmdtab; c->name; ++c) { - /* Is it an exact match? */ - if (! strcasecmp (buf, c->name)) { - *cmd = c->command; - break; - } - - /* Try short hand forms then... */ - if (len >= c->min && ! strncasecmp (buf, c->name, len)) { - if (*cmd != -1 && *cmd != c->command) { - warnx("ambiguous command"); - return (0); - } - *cmd = c->command; - } - } - - if (*cmd == -1) { - warnx("invalid command, enter ``help'' for commands"); - return (0); - } - - while (isspace (*p)) - p++; - return p; -} - -int open_cd (void) -{ - char devbuf[MAXPATHLEN]; - const char *dev; - - if (fd > -1) - return (1); - - if (cdname) { - if (*cdname == '/') { - snprintf (devbuf, MAXPATHLEN, "%s", cdname); - } else { - snprintf (devbuf, MAXPATHLEN, "%s%s", _PATH_DEV, cdname); - } - fd = open (dev = devbuf, O_RDONLY); - } else { - fd = open(dev = "/dev/cdrom", O_RDONLY); - if (fd < 0 && errno == ENOENT) - fd = open(dev = "/dev/cd0", O_RDONLY); - if (fd < 0 && errno == ENOENT) - fd = open(dev = "/dev/acd0", O_RDONLY); - } - - if (fd < 0) { - if (errno == ENXIO) { - /* ENXIO has an overloaded meaning here. - * The original "Device not configured" should - * be interpreted as "No disc in drive %s". */ - warnx("no disc in drive %s", dev); - return (0); - } - err(1, "%s", dev); - } - return (1); -} diff --git a/usr.sbin/chkgrp/Makefile b/usr.sbin/chkgrp/Makefile deleted file mode 100644 index a7bfc54..0000000 --- a/usr.sbin/chkgrp/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= chkgrp -MAN= chkgrp.8 - -.include diff --git a/usr.sbin/chkgrp/chkgrp.8 b/usr.sbin/chkgrp/chkgrp.8 deleted file mode 100644 index 581fd64..0000000 --- a/usr.sbin/chkgrp/chkgrp.8 +++ /dev/null @@ -1,86 +0,0 @@ -.\" Copyright (c) 1998 Dag-Erling Coïdan Smørgrav -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer -.\" in this position and unchanged. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd May 26, 2005 -.Dt CHKGRP 8 -.Os -.Sh NAME -.Nm chkgrp -.Nd check the syntax of the group file -.Sh SYNOPSIS -.Nm -.Op Ar groupfile -.Sh DESCRIPTION -The -.Nm -utility -scans the given file or, failing that, the system-wide group file for -errors. -Specifically, it checks that every non-blank, non-comment -entry is composed of four colon-separated fields, that none of them -contains whitespace, and that the third field (the group ID) is -numeric. -It will also check for invalid characters in the group names -and group members. -.Sh FILES -.Bl -tag -width /etc/group -compact -.It Pa /etc/group -group database file -.El -.Sh EXIT STATUS -The -.Nm -utility returns -.Dv EX_DATAERR -if errors were found in the group file, -and -.Dv EX_OK -otherwise. -.Sh DIAGNOSTICS -For each error found, -.Nm -will print an error message containing the name of the file being -scanned and the line number on which the error was found. -.Sh SEE ALSO -.Xr getgrent 3 , -.Xr group 5 -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 3.0 . -.Sh AUTHORS -.An -nosplit -The -.Nm -utility and this manual page were written by -.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org . -Further functionality was added by -.An Liam J. Foy Aq liamfoy@dragonflybsd.org . -.Sh BUGS -Should check the range of the group ID. diff --git a/usr.sbin/chkgrp/chkgrp.c b/usr.sbin/chkgrp/chkgrp.c deleted file mode 100644 index eca26af..0000000 --- a/usr.sbin/chkgrp/chkgrp.c +++ /dev/null @@ -1,169 +0,0 @@ -/*- - * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer - * in this position and unchanged. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -static char empty[] = { 0 }; - -static void -usage(void) -{ - fprintf(stderr, "usage: chkgrp [groupfile]\n"); - exit(EX_USAGE); -} - -int -main(int argc, char *argv[]) -{ - unsigned int i; - size_t len; - int n = 0, k, e = 0; - char *line, *f[4], *p; - const char *cp, *gfn; - FILE *gf; - - /* check arguments */ - switch (argc) { - case 1: - gfn = "/etc/group"; - break; - case 2: - gfn = argv[1]; - break; - default: - gfn = NULL; /* silence compiler */ - usage(); - } - - /* open group file */ - if ((gf = fopen(gfn, "r")) == NULL) - err(EX_IOERR, "%s", gfn); /* XXX - is IO_ERR the correct exit code? */ - - /* check line by line */ - while (++n) { - if ((line = fgetln(gf, &len)) == NULL) - break; - if (len > 0 && line[len - 1] != '\n') { - warnx("%s: line %d: no newline character", gfn, n); - e++; - } - while (len && isspace(line[len-1])) - len--; - - /* ignore blank lines and comments */ - for (p = line; p < (line + len); p++) - if (!isspace(*p)) break; - if (!len || (*p == '#')) { -#if 0 - /* entry is correct, so print it */ - printf("%*.*s\n", len, len, line); -#endif - continue; - } - - /* - * A correct group entry has four colon-separated fields, the third - * of which must be entirely numeric and the fourth of which may - * be empty. - */ - for (i = k = 0; k < 4; k++) { - for (f[k] = line+i; (i < len) && (line[i] != ':'); i++) - /* nothing */ ; - if ((k < 3) && (line[i] != ':')) - break; - line[i++] = 0; - } - - if (k < 4) { - warnx("%s: line %d: missing field(s)", gfn, n); - for ( ; k < 4; k++) - f[k] = empty; - e++; - } - - for (cp = f[0] ; *cp ; cp++) { - if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-' && - (cp > f[0] || *cp != '+')) { - warnx("%s: line %d: '%c' invalid character", gfn, n, *cp); - e++; - } - } - - for (cp = f[3] ; *cp ; cp++) { - if (!isalnum(*cp) && *cp != '.' && *cp != '_' && *cp != '-' && - *cp != ',') { - warnx("%s: line %d: '%c' invalid character", gfn, n, *cp); - e++; - } - } - - /* check if fourth field ended with a colon */ - if (i < len) { - warnx("%s: line %d: too many fields", gfn, n); - e++; - } - - /* check that none of the fields contain whitespace */ - for (k = 0; k < 4; k++) { - if (strcspn(f[k], " \t") != strlen(f[k])) { - warnx("%s: line %d: field %d contains whitespace", - gfn, n, k+1); - e++; - } - } - - /* check that the GID is numeric */ - if (strspn(f[2], "0123456789") != strlen(f[2])) { - warnx("%s: line %d: GID is not numeric", gfn, n); - e++; - } - -#if 0 - /* entry is correct, so print it */ - printf("%s:%s:%s:%s\n", f[0], f[1], f[2], f[3]); -#endif - } - - /* check what broke the loop */ - if (ferror(gf)) - err(EX_IOERR, "%s: line %d", gfn, n); - - /* done */ - fclose(gf); - if (e == 0) - printf("%s is fine\n", gfn); - exit(e ? EX_DATAERR : EX_OK); -} diff --git a/usr.sbin/chown/Makefile b/usr.sbin/chown/Makefile deleted file mode 100644 index 97972e5..0000000 --- a/usr.sbin/chown/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -PROG= chown -LINKS= ${BINDIR}/chown /usr/bin/chgrp -MAN= chgrp.1 chown.8 - -.include diff --git a/usr.sbin/chown/chgrp.1 b/usr.sbin/chown/chgrp.1 deleted file mode 100644 index 8a4c271..0000000 --- a/usr.sbin/chown/chgrp.1 +++ /dev/null @@ -1,145 +0,0 @@ -.\" Copyright (c) 1983, 1990, 1993, 1994 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" the Institute of Electrical and Electronics Engineers, Inc. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)chgrp.1 8.3 (Berkeley) 3/31/94 -.\" $FreeBSD$ -.\" -.Dd February 21, 2010 -.Dt CHGRP 1 -.Os -.Sh NAME -.Nm chgrp -.Nd change group -.Sh SYNOPSIS -.Nm -.Op Fl fhvx -.Oo -.Fl R -.Op Fl H | Fl L | Fl P -.Oc -.Ar group -.Ar -.Sh DESCRIPTION -The -.Nm -utility sets the group ID of the file named by each -.Ar file -operand to the -.Ar group -ID specified by the group operand. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl H -If the -.Fl R -option is specified, symbolic links on the command line are followed. -(Symbolic links encountered in the tree traversal are not followed.) -.It Fl L -If the -.Fl R -option is specified, all symbolic links are followed. -.It Fl P -If the -.Fl R -option is specified, no symbolic links are followed. -This is the default. -.It Fl R -Change the group ID for the file hierarchies rooted -in the files instead of just the files themselves. -.It Fl f -The force option ignores errors, except for usage errors and does not -query about strange modes (unless the user does not have proper permissions). -.It Fl h -If the file is a symbolic link, the group ID of the link itself is changed -rather than the file that is pointed to. -.It Fl v -Cause -.Nm -to be verbose, showing files as the group is modified. -If the -.Fl v -flag is specified more than once, -.Nm -will print the filename, followed by the old and new numeric group ID. -.It Fl x -File system mount points are not traversed. -.El -.Pp -The -.Fl H , -.Fl L -and -.Fl P -options are ignored unless the -.Fl R -option is specified. -In addition, these options override each other and the -command's actions are determined by the last one specified. -.Pp -The -.Ar group -operand can be either a group name from the group database, -or a numeric group ID. -If a group name is also a numeric group ID, the operand is used as a -group name. -.Pp -The user invoking -.Nm -must belong to the specified group and be the owner of the file, -or be the super-user. -.Sh FILES -.Bl -tag -width /etc/group -compact -.It Pa /etc/group -group ID file -.El -.Sh EXIT STATUS -.Ex -std -.Sh COMPATIBILITY -In previous versions of this system, symbolic links did not have groups. -.Pp -The -.Fl v -and -.Fl x -options are non-standard and their use in scripts is not recommended. -.Sh SEE ALSO -.Xr chown 2 , -.Xr fts 3 , -.Xr group 5 , -.Xr passwd 5 , -.Xr symlink 7 , -.Xr chown 8 -.Sh STANDARDS -The -.Nm -utility is expected to be -.St -p1003.2 -compatible. diff --git a/usr.sbin/chown/chown.8 b/usr.sbin/chown/chown.8 deleted file mode 100644 index b5882a3..0000000 --- a/usr.sbin/chown/chown.8 +++ /dev/null @@ -1,170 +0,0 @@ -.\" Copyright (c) 1990, 1991, 1993, 1994 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)chown.8 8.3 (Berkeley) 3/31/94 -.\" $FreeBSD$ -.\" -.Dd February 21, 2010 -.Dt CHOWN 8 -.Os -.Sh NAME -.Nm chown -.Nd change file owner and group -.Sh SYNOPSIS -.Nm -.Op Fl fhvx -.Oo -.Fl R -.Op Fl H | Fl L | Fl P -.Oc -.Ar owner Ns Op : Ns Ar group -.Ar -.Nm -.Op Fl fhvx -.Oo -.Fl R -.Op Fl H | Fl L | Fl P -.Oc -.No : Ns Ar group -.Ar -.Sh DESCRIPTION -The -.Nm -utility changes the user ID and/or the group ID of the specified files. -Symbolic links named by arguments are silently left unchanged unless -.Fl h -is used. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl H -If the -.Fl R -option is specified, symbolic links on the command line are followed. -(Symbolic links encountered in the tree traversal are not followed.) -.It Fl L -If the -.Fl R -option is specified, all symbolic links are followed. -.It Fl P -If the -.Fl R -option is specified, no symbolic links are followed. -This is the default. -.It Fl R -Change the user ID and/or the group ID of the specified directory trees -(recursively, including their contents) and files. -Beware of unintentionally matching the -.Dq Pa ".." -hard link to the parent directory when using wildcards like -.Dq Li ".*" . -.It Fl f -Do not report any failure to change file owner or group, nor modify -the exit status to reflect such failures. -.It Fl h -If the file is a symbolic link, change the user ID and/or the -group ID of the link itself. -.It Fl v -Cause -.Nm -to be verbose, showing files as the owner is modified. -If the -.Fl v -flag is specified more than once, -.Nm -will print the filename, followed by the old and new numeric user/group ID. -.It Fl x -File system mount points are not traversed. -.El -.Pp -The -.Fl H , -.Fl L -and -.Fl P -options are ignored unless the -.Fl R -option is specified. -In addition, these options override each other and the -command's actions are determined by the last one specified. -.Pp -The -.Ar owner -and -.Ar group -operands are both optional, however, one must be specified. -If the -.Ar group -operand is specified, it must be preceded by a colon (``:'') character. -.Pp -The -.Ar owner -may be either a numeric user ID or a user name. -If a user name is also a numeric user ID, the operand is used as a -user name. -The -.Ar group -may be either a numeric group ID or a group name. -If a group name is also a numeric group ID, the operand is used as a -group name. -.Pp -The ownership of a file may only be altered by a super-user for -obvious security reasons. -.Sh EXIT STATUS -.Ex -std -.Sh COMPATIBILITY -Previous versions of the -.Nm -utility used the dot (``.'') character to distinguish the group name. -This has been changed to be a colon (``:'') character so that user and -group names may contain the dot character. -.Pp -On previous versions of this system, symbolic links did not have -owners. -.Pp -The -.Fl v -and -.Fl x -options are non-standard and their use in scripts is not recommended. -.Sh SEE ALSO -.Xr chgrp 1 , -.Xr find 1 , -.Xr chown 2 , -.Xr fts 3 , -.Xr symlink 7 -.Sh STANDARDS -The -.Nm -utility is expected to be -.St -p1003.2 -compliant. -.Sh HISTORY -A -.Nm -utility appeared in -.At v1 . diff --git a/usr.sbin/chown/chown.c b/usr.sbin/chown/chown.c deleted file mode 100644 index e13235c..0000000 --- a/usr.sbin/chown/chown.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * Copyright (c) 1988, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1988, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)chown.c 8.8 (Berkeley) 4/4/94"; -#endif /* not lint */ -#endif - -#include -__FBSDID("$FreeBSD$"); - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -void a_gid(const char *); -void a_uid(const char *); -void chownerr(const char *); -uid_t id(const char *, const char *); -void usage(void); - -uid_t uid; -gid_t gid; -int ischown; -const char *gname; - -int -main(int argc, char **argv) -{ - FTS *ftsp; - FTSENT *p; - int Hflag, Lflag, Rflag, fflag, hflag, vflag, xflag; - int ch, fts_options, rval; - char *cp; - - ischown = (strcmp(basename(argv[0]), "chown") == 0); - - Hflag = Lflag = Rflag = fflag = hflag = vflag = xflag = 0; - while ((ch = getopt(argc, argv, "HLPRfhvx")) != -1) - switch (ch) { - case 'H': - Hflag = 1; - Lflag = 0; - break; - case 'L': - Lflag = 1; - Hflag = 0; - break; - case 'P': - Hflag = Lflag = 0; - break; - case 'R': - Rflag = 1; - break; - case 'f': - fflag = 1; - break; - case 'h': - hflag = 1; - break; - case 'v': - vflag++; - break; - case 'x': - xflag = 1; - break; - case '?': - default: - usage(); - } - argv += optind; - argc -= optind; - - if (argc < 2) - usage(); - - if (Rflag) { - fts_options = FTS_PHYSICAL; - if (hflag && (Hflag || Lflag)) - errx(1, "the -R%c and -h options may not be " - "specified together", Hflag ? 'H' : 'L'); - if (Hflag) - fts_options |= FTS_COMFOLLOW; - else if (Lflag) { - fts_options &= ~FTS_PHYSICAL; - fts_options |= FTS_LOGICAL; - } - } else - fts_options = hflag ? FTS_PHYSICAL : FTS_LOGICAL; - if (xflag) - fts_options |= FTS_XDEV; - - uid = (uid_t)-1; - gid = (gid_t)-1; - if (ischown) { - if ((cp = strchr(*argv, ':')) != NULL) { - *cp++ = '\0'; - a_gid(cp); - } -#ifdef SUPPORT_DOT - else if ((cp = strchr(*argv, '.')) != NULL) { - warnx("separation of user and group with a period is deprecated"); - *cp++ = '\0'; - a_gid(cp); - } -#endif - a_uid(*argv); - } else - a_gid(*argv); - - if ((ftsp = fts_open(++argv, fts_options, 0)) == NULL) - err(1, NULL); - - for (rval = 0; (p = fts_read(ftsp)) != NULL;) { - switch (p->fts_info) { - case FTS_D: /* Change it at FTS_DP. */ - if (!Rflag) - fts_set(ftsp, p, FTS_SKIP); - continue; - case FTS_DNR: /* Warn, chown. */ - warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); - rval = 1; - break; - case FTS_ERR: /* Warn, continue. */ - case FTS_NS: - warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); - rval = 1; - continue; - case FTS_SL: - case FTS_SLNONE: - /* - * The only symlinks that end up here are ones that - * don't point to anything and ones that we found - * doing a physical walk. - */ - if (hflag) - break; - else - continue; - default: - break; - } - if ((uid == (uid_t)-1 || uid == p->fts_statp->st_uid) && - (gid == (gid_t)-1 || gid == p->fts_statp->st_gid)) - continue; - if ((hflag ? lchown : chown)(p->fts_accpath, uid, gid) == -1) { - if (!fflag) { - chownerr(p->fts_path); - rval = 1; - } - } else { - if (vflag) { - printf("%s", p->fts_path); - if (vflag > 1) { - if (ischown) { - printf(": %ju:%ju -> %ju:%ju", - (uintmax_t) - p->fts_statp->st_uid, - (uintmax_t) - p->fts_statp->st_gid, - (uid == (uid_t)-1) ? - (uintmax_t) - p->fts_statp->st_uid : - (uintmax_t)uid, - (gid == (gid_t)-1) ? - (uintmax_t) - p->fts_statp->st_gid : - (uintmax_t)gid); - } else { - printf(": %ju -> %ju", - (uintmax_t) - p->fts_statp->st_gid, - (gid == (gid_t)-1) ? - (uintmax_t) - p->fts_statp->st_gid : - (uintmax_t)gid); - } - } - printf("\n"); - } - } - } - if (errno) - err(1, "fts_read"); - exit(rval); -} - -void -a_gid(const char *s) -{ - struct group *gr; - - if (*s == '\0') /* Argument was "uid[:.]". */ - return; - gname = s; - gid = ((gr = getgrnam(s)) != NULL) ? gr->gr_gid : id(s, "group"); -} - -void -a_uid(const char *s) -{ - struct passwd *pw; - - if (*s == '\0') /* Argument was "[:.]gid". */ - return; - uid = ((pw = getpwnam(s)) != NULL) ? pw->pw_uid : id(s, "user"); -} - -uid_t -id(const char *name, const char *type) -{ - uid_t val; - char *ep; - - /* - * XXX - * We know that uid_t's and gid_t's are unsigned longs. - */ - errno = 0; - val = strtoul(name, &ep, 10); - if (errno || *ep != '\0') - errx(1, "%s: illegal %s name", name, type); - return (val); -} - -void -chownerr(const char *file) -{ - static uid_t euid = -1; - static int ngroups = -1; - static long ngroups_max; - gid_t *groups; - - /* Check for chown without being root. */ - if (errno != EPERM || (uid != (uid_t)-1 && - euid == (uid_t)-1 && (euid = geteuid()) != 0)) { - warn("%s", file); - return; - } - - /* Check group membership; kernel just returns EPERM. */ - if (gid != (gid_t)-1 && ngroups == -1 && - euid == (uid_t)-1 && (euid = geteuid()) != 0) { - ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1; - if ((groups = malloc(sizeof(gid_t) * ngroups_max)) == NULL) - err(1, "malloc"); - ngroups = getgroups(ngroups_max, groups); - while (--ngroups >= 0 && gid != groups[ngroups]); - free(groups); - if (ngroups < 0) { - warnx("you are not a member of group %s", gname); - return; - } - } - warn("%s", file); -} - -void -usage(void) -{ - - if (ischown) - (void)fprintf(stderr, "%s\n%s\n", - "usage: chown [-fhvx] [-R [-H | -L | -P]] owner[:group]" - " file ...", - " chown [-fhvx] [-R [-H | -L | -P]] :group file ..."); - else - (void)fprintf(stderr, "%s\n", - "usage: chgrp [-fhvx] [-R [-H | -L | -P]] group file ..."); - exit(1); -} diff --git a/usr.sbin/chroot/Makefile b/usr.sbin/chroot/Makefile deleted file mode 100644 index 652de79..0000000 --- a/usr.sbin/chroot/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -PROG= chroot -MAN= chroot.8 - -.include diff --git a/usr.sbin/chroot/chroot.8 b/usr.sbin/chroot/chroot.8 deleted file mode 100644 index d847175..0000000 --- a/usr.sbin/chroot/chroot.8 +++ /dev/null @@ -1,94 +0,0 @@ -.\" Copyright (c) 1988, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)chroot.8 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" -.Dd June 7, 2003 -.Dt CHROOT 8 -.Os -.Sh NAME -.Nm chroot -.Nd change root directory -.Sh SYNOPSIS -.Nm -.Op Fl u Ar user -.Op Fl g Ar group -.Op Fl G Ar group,group,... -.Ar newroot -.Op Ar command -.Sh DESCRIPTION -The -.Nm -utility changes its current and root directories to the supplied directory -.Ar newroot -and then exec's -.Ar command , -if supplied, -or an interactive copy of the user's login shell. -.Pp -If the -.Fl u , -.Fl g -or -.Fl G -options are given, -the user, -group and group list of the process are set to -these values after the -.Xr chroot 8 -has taken place. -.Sh ENVIRONMENT -The following environment variable is referenced by -.Nm : -.Bl -tag -width ".Ev SHELL" -.It Ev SHELL -If set, -the string specified by -.Ev SHELL -is interpreted as the name of -the shell to exec. -If the variable -.Ev SHELL -is not set, -.Pa /bin/sh -is used. -.El -.Sh SEE ALSO -.Xr chdir 2 , -.Xr chroot 2 , -.Xr setgid 2 , -.Xr setgroups 2 , -.Xr setuid 2 , -.Xr getgrnam 3 , -.Xr environ 7 , -.Xr jail 8 -.Sh HISTORY -The -.Nm -utility first appeared in -.Bx 4.4 . diff --git a/usr.sbin/chroot/chroot.c b/usr.sbin/chroot/chroot.c deleted file mode 100644 index a0122f7..0000000 --- a/usr.sbin/chroot/chroot.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1988, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)chroot.c 8.1 (Berkeley) 6/9/93"; -#endif /* not lint */ -#endif -#include -__FBSDID("$FreeBSD$"); - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void usage(void); - -char *user; /* user to switch to before running program */ -char *group; /* group to switch to ... */ -char *grouplist; /* group list to switch to ... */ - -int -main(int argc, char *argv[]) -{ - struct group *gp; - struct passwd *pw; - char *endp, *p; - const char *shell; - gid_t gid, *gidlist; - uid_t uid; - int ch, gids; - long ngroups_max; - - gid = 0; - uid = 0; - while ((ch = getopt(argc, argv, "G:g:u:")) != -1) { - switch(ch) { - case 'u': - user = optarg; - if (*user == '\0') - usage(); - break; - case 'g': - group = optarg; - if (*group == '\0') - usage(); - break; - case 'G': - grouplist = optarg; - if (*grouplist == '\0') - usage(); - break; - case '?': - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc < 1) - usage(); - - if (group != NULL) { - if (isdigit((unsigned char)*group)) { - gid = (gid_t)strtoul(group, &endp, 0); - if (*endp != '\0') - goto getgroup; - } else { - getgroup: - if ((gp = getgrnam(group)) != NULL) - gid = gp->gr_gid; - else - errx(1, "no such group `%s'", group); - } - } - - ngroups_max = sysconf(_SC_NGROUPS_MAX) + 1; - if ((gidlist = malloc(sizeof(gid_t) * ngroups_max)) == NULL) - err(1, "malloc"); - for (gids = 0; - (p = strsep(&grouplist, ",")) != NULL && gids < ngroups_max; ) { - if (*p == '\0') - continue; - - if (isdigit((unsigned char)*p)) { - gidlist[gids] = (gid_t)strtoul(p, &endp, 0); - if (*endp != '\0') - goto getglist; - } else { - getglist: - if ((gp = getgrnam(p)) != NULL) - gidlist[gids] = gp->gr_gid; - else - errx(1, "no such group `%s'", p); - } - gids++; - } - if (p != NULL && gids == ngroups_max) - errx(1, "too many supplementary groups provided"); - - if (user != NULL) { - if (isdigit((unsigned char)*user)) { - uid = (uid_t)strtoul(user, &endp, 0); - if (*endp != '\0') - goto getuser; - } else { - getuser: - if ((pw = getpwnam(user)) != NULL) - uid = pw->pw_uid; - else - errx(1, "no such user `%s'", user); - } - } - - if (chdir(argv[0]) == -1 || chroot(".") == -1) - err(1, "%s", argv[0]); - - if (gids && setgroups(gids, gidlist) == -1) - err(1, "setgroups"); - if (group && setgid(gid) == -1) - err(1, "setgid"); - if (user && setuid(uid) == -1) - err(1, "setuid"); - - if (argv[1]) { - execvp(argv[1], &argv[1]); - err(1, "%s", argv[1]); - } - - if (!(shell = getenv("SHELL"))) - shell = _PATH_BSHELL; - execlp(shell, shell, "-i", (char *)NULL); - err(1, "%s", shell); - /* NOTREACHED */ -} - -static void -usage(void) -{ - (void)fprintf(stderr, "usage: chroot [-g group] [-G group,group,...] " - "[-u user] newroot [command]\n"); - exit(1); -} diff --git a/usr.sbin/ckdist/Makefile b/usr.sbin/ckdist/Makefile deleted file mode 100644 index 23430a8..0000000 --- a/usr.sbin/ckdist/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../usr.bin/cksum - -PROG= ckdist -SRCS= ckdist.c crc.c - -DPADD= ${LIBMD} -LDADD= -lmd - -.include diff --git a/usr.sbin/ckdist/ckdist.1 b/usr.sbin/ckdist/ckdist.1 deleted file mode 100644 index 86175c9..0000000 --- a/usr.sbin/ckdist/ckdist.1 +++ /dev/null @@ -1,132 +0,0 @@ -.\" Copyright (c) 1997 Robert Nordier -.\" All rights reserved. -.\" -.\" $FreeBSD$ -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS -.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, -.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd January 20, 1997 -.Dt CKDIST 1 -.Os -.Sh NAME -.Nm ckdist -.Nd check software distributions -.Sh SYNOPSIS -.Nm -.Bq Fl airsx -.Bq Fl d Ar dir -.Bq Fl n Ar name -.Bq Fl t Ar type -.Ar -.Sh DESCRIPTION -The -.Nm -utility reads -.Dq checksum -files (which are assumed to specify components -of a software distribution) and verifies the integrity of the -distribution by validating the checksum of each component file. -Both MD5 (128-bit -.Dq "message digest" ) -and -.Pa .inf -(32-bit CRC) checksum -formats are supported. -.Pp -The -.Ar file -operands may refer to regular files or to directories. -Regular files -named -.Pa md5 , -or which have an -.Pa .md5 -or an -.Pa .inf -extension, are -assumed to be of the implied type, otherwise format is determined from -content. -If a directory is specified, it is searched for -appropriately-named files only. -.Pp -The options are as follows: -.\"Bl -tag -width ".Fl n Ar name" -.Bl -tag -width 8n -offset indent -.It Fl a -Report on all distribution components, not just those in respect of -which errors are detected. -.It Fl i -Ignore missing distribution components. -.It Fl r -Search specified directories recursively. -.It Fl s -Suppress complaints about inaccessible checksum files and directories. -.It Fl x -Verify the existence of distribution components (and also check sizes, -in the case of -.Pa .inf -files), but omit the more time-consuming step of -actually computing and comparing checksums. -.It Fl d Ar dir -Look for distribution components in the directory -.Ar dir . -.It Fl n Ar name -Access distribution components using the filename -.Ar name . -When accessing -.Pa .inf -file components, append the appropriate -extension to the filename. -.It Fl t Ar type -Assume that all specified checksum files are of the format -.Ar type , -and search directories only for files in this format (where -.Ar type -is either -.Cm md5 -or -.Cm inf ) . -.El -.Sh EXIT STATUS -The -.Nm -utility exits with one of the following values: -.Bl -tag -width indent -.It 0 -No errors were detected. -.It 1 -Errors were found in a distribution. -.It 2 -Usage errors, inaccessible input files, or -other system errors were encountered. -.El -.Sh SEE ALSO -.Xr cksum 1 , -.Xr md5 1 -.Sh NOTES -Both -.Bx -and -.Tn DOS -versions of -.Nm -are available. diff --git a/usr.sbin/ckdist/ckdist.c b/usr.sbin/ckdist/ckdist.c deleted file mode 100644 index dcaa9f3..0000000 --- a/usr.sbin/ckdist/ckdist.c +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Copyright (c) 1997 Robert Nordier - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS - * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER - * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -extern int crc(int fd, uint32_t *cval, off_t *clen); - -#define DISTMD5 1 /* MD5 format */ -#define DISTINF 2 /* .inf format */ -#define DISTTYPES 2 /* types supported */ - -#define E_UNKNOWN 1 /* Unknown format */ -#define E_BADMD5 2 /* Invalid MD5 format */ -#define E_BADINF 3 /* Invalid .inf format */ -#define E_NAME 4 /* Can't derive component name */ -#define E_LENGTH 5 /* Length mismatch */ -#define E_CHKSUM 6 /* Checksum mismatch */ -#define E_ERRNO 7 /* sys_errlist[errno] */ - -#define isfatal(err) ((err) && (err) <= E_NAME) - -#define NAMESIZE 256 /* filename buffer size */ -#define MDSUMLEN 32 /* length of MD5 message digest */ - -#define isstdin(path) ((path)[0] == '-' && !(path)[1]) - -static const char *opt_dir; /* where to look for components */ -static const char *opt_name; /* name for accessing components */ -static int opt_all; /* report on all components */ -static int opt_ignore; /* ignore missing components */ -static int opt_recurse; /* search directories recursively */ -static int opt_silent; /* silent about inaccessible files */ -static int opt_type; /* dist type: md5 or inf */ -static int opt_exist; /* just verify existence */ - -static int ckdist(const char *path, int type); -static int chkmd5(FILE * fp, const char *path); -static int chkinf(FILE * fp, const char *path); -static int report(const char *path, const char *name, int error); -static const char *distname(const char *path, const char *name, - const char *ext); -static const char *stripath(const char *path); -static int distfile(const char *path); -static int disttype(const char *name); -static int fail(const char *path, const char *msg); -static void usage(void); - -int -main(int argc, char *argv[]) -{ - static char *arg[2]; - struct stat sb; - FTS *ftsp; - FTSENT *f; - int rval, c, type; - - while ((c = getopt(argc, argv, "ad:in:rst:x")) != -1) - switch (c) { - case 'a': - opt_all = 1; - break; - case 'd': - opt_dir = optarg; - break; - case 'i': - opt_ignore = 1; - break; - case 'n': - opt_name = optarg; - break; - case 'r': - opt_recurse = 1; - break; - case 's': - opt_silent = 1; - break; - case 't': - if ((opt_type = disttype(optarg)) == 0) { - warnx("illegal argument to -t option"); - usage(); - } - break; - case 'x': - opt_exist = 1; - break; - default: - usage(); - } - argc -= optind; - argv += optind; - if (argc < 1) - usage(); - if (opt_dir) { - if (stat(opt_dir, &sb)) - err(2, "%s", opt_dir); - if (!S_ISDIR(sb.st_mode)) - errx(2, "%s: not a directory", opt_dir); - } - rval = 0; - do { - if (isstdin(*argv)) - rval |= ckdist(*argv, opt_type); - else if (stat(*argv, &sb)) - rval |= fail(*argv, NULL); - else if (S_ISREG(sb.st_mode)) - rval |= ckdist(*argv, opt_type); - else { - arg[0] = *argv; - if ((ftsp = fts_open(arg, FTS_LOGICAL, NULL)) == NULL) - err(2, "fts_open"); - while ((f = fts_read(ftsp)) != NULL) - switch (f->fts_info) { - case FTS_DC: - rval = fail(f->fts_path, "Directory causes a cycle"); - break; - case FTS_DNR: - case FTS_ERR: - case FTS_NS: - rval = fail(f->fts_path, sys_errlist[f->fts_errno]); - break; - case FTS_D: - if (!opt_recurse && f->fts_level > FTS_ROOTLEVEL && - fts_set(ftsp, f, FTS_SKIP)) - err(2, "fts_set"); - break; - case FTS_F: - if ((type = distfile(f->fts_name)) != 0 && - (!opt_type || type == opt_type)) - rval |= ckdist(f->fts_path, type); - break; - default: ; - } - if (errno) - err(2, "fts_read"); - if (fts_close(ftsp)) - err(2, "fts_close"); - } - } while (*++argv); - return rval; -} - -static int -ckdist(const char *path, int type) -{ - FILE *fp; - int rval, c; - - if (isstdin(path)) { - path = "(stdin)"; - fp = stdin; - } else if ((fp = fopen(path, "r")) == NULL) - return fail(path, NULL); - if (!type) { - if (fp != stdin) - type = distfile(path); - if (!type) - if ((c = fgetc(fp)) != EOF) { - type = c == 'M' ? DISTMD5 : c == 'P' ? DISTINF : 0; - (void)ungetc(c, fp); - } - } - switch (type) { - case DISTMD5: - rval = chkmd5(fp, path); - break; - case DISTINF: - rval = chkinf(fp, path); - break; - default: - rval = report(path, NULL, E_UNKNOWN); - } - if (ferror(fp)) - warn("%s", path); - if (fp != stdin && fclose(fp)) - err(2, "%s", path); - return rval; -} - -static int -chkmd5(FILE * fp, const char *path) -{ - char buf[298]; /* "MD5 (NAMESIZE = MDSUMLEN" */ - char name[NAMESIZE + 1]; - char sum[MDSUMLEN + 1], chk[MDSUMLEN + 1]; - const char *dname; - char *s; - int rval, error, c, fd; - char ch; - - rval = 0; - while (fgets(buf, sizeof(buf), fp)) { - dname = NULL; - error = 0; - if (((c = sscanf(buf, "MD5 (%256s = %32s%c", name, sum, - &ch)) != 3 && (!feof(fp) || c != 2)) || - (c == 3 && ch != '\n') || - (s = strrchr(name, ')')) == NULL || - strlen(sum) != MDSUMLEN) - error = E_BADMD5; - else { - *s = 0; - if ((dname = distname(path, name, NULL)) == NULL) - error = E_NAME; - else if (opt_exist) { - if ((fd = open(dname, O_RDONLY)) == -1) - error = E_ERRNO; - else if (close(fd)) - err(2, "%s", dname); - } else if (!MD5File(dname, chk)) - error = E_ERRNO; - else if (strcmp(chk, sum)) - error = E_CHKSUM; - } - if (opt_ignore && error == E_ERRNO && errno == ENOENT) - continue; - if (error || opt_all) - rval |= report(path, dname, error); - if (isfatal(error)) - break; - } - return rval; -} - -static int -chkinf(FILE * fp, const char *path) -{ - char buf[30]; /* "cksum.2 = 10 6" */ - char ext[3]; - struct stat sb; - const char *dname; - off_t len; - u_long sum; - intmax_t sumlen; - uint32_t chk; - int rval, error, c, pieces, cnt, fd; - char ch; - - rval = 0; - for (cnt = -1; fgets(buf, sizeof(buf), fp); cnt++) { - fd = -1; - dname = NULL; - error = 0; - if (cnt == -1) { - if ((c = sscanf(buf, "Pieces = %d%c", &pieces, &ch)) != 2 || - ch != '\n' || pieces < 1) - error = E_BADINF; - } else if (((c = sscanf(buf, "cksum.%2s = %lu %jd%c", ext, &sum, - &sumlen, &ch)) != 4 && - (!feof(fp) || c != 3)) || (c == 4 && ch != '\n') || - ext[0] != 'a' + cnt / 26 || ext[1] != 'a' + cnt % 26) - error = E_BADINF; - else if ((dname = distname(fp == stdin ? NULL : path, NULL, - ext)) == NULL) - error = E_NAME; - else if ((fd = open(dname, O_RDONLY)) == -1) - error = E_ERRNO; - else if (fstat(fd, &sb)) - error = E_ERRNO; - else if (sb.st_size != (off_t)sumlen) - error = E_LENGTH; - else if (!opt_exist) { - if (crc(fd, &chk, &len)) - error = E_ERRNO; - else if (chk != sum) - error = E_CHKSUM; - } - if (fd != -1 && close(fd)) - err(2, "%s", dname); - if (opt_ignore && error == E_ERRNO && errno == ENOENT) - continue; - if (error || (opt_all && cnt >= 0)) - rval |= report(path, dname, error); - if (isfatal(error)) - break; - } - return rval; -} - -static int -report(const char *path, const char *name, int error) -{ - if (name) - name = stripath(name); - switch (error) { - case E_UNKNOWN: - printf("%s: Unknown format\n", path); - break; - case E_BADMD5: - printf("%s: Invalid MD5 format\n", path); - break; - case E_BADINF: - printf("%s: Invalid .inf format\n", path); - break; - case E_NAME: - printf("%s: Can't derive component name\n", path); - break; - case E_LENGTH: - printf("%s: %s: Size mismatch\n", path, name); - break; - case E_CHKSUM: - printf("%s: %s: Checksum mismatch\n", path, name); - break; - case E_ERRNO: - printf("%s: %s: %s\n", path, name, sys_errlist[errno]); - break; - default: - printf("%s: %s: OK\n", path, name); - } - return error != 0; -} - -static const char * -distname(const char *path, const char *name, const char *ext) -{ - static char buf[NAMESIZE]; - size_t plen, nlen; - char *s; - - if (opt_name) - name = opt_name; - else if (!name) { - if (!path) - return NULL; - name = stripath(path); - } - nlen = strlen(name); - if (ext && nlen > 4 && name[nlen - 4] == '.' && - disttype(name + nlen - 3) == DISTINF) - nlen -= 4; - if (opt_dir) { - path = opt_dir; - plen = strlen(path); - } else - plen = path && (s = strrchr(path, '/')) != NULL ? - (size_t)(s - path) : 0; - if (plen + (plen > 0) + nlen + (ext ? 3 : 0) >= sizeof(buf)) - return NULL; - s = buf; - if (plen) { - memcpy(s, path, plen); - s += plen; - *s++ = '/'; - } - memcpy(s, name, nlen); - s += nlen; - if (ext) { - *s++ = '.'; - memcpy(s, ext, 2); - s += 2; - } - *s = 0; - return buf; -} - -static const char * -stripath(const char *path) -{ - const char *s; - - return ((s = strrchr(path, '/')) != NULL && s[1] ? - s + 1 : path); -} - -static int -distfile(const char *path) -{ - const char *s; - int type; - - if ((type = disttype(path)) == DISTMD5 || - ((s = strrchr(path, '.')) != NULL && s > path && - (type = disttype(s + 1)) != 0)) - return type; - return 0; -} - -static int -disttype(const char *name) -{ - static const char dname[DISTTYPES][4] = {"md5", "inf"}; - int i; - - for (i = 0; i < DISTTYPES; i++) - if (!strcmp(dname[i], name)) - return 1 + i; - return 0; -} - -static int -fail(const char *path, const char *msg) -{ - if (opt_silent) - return 0; - warnx("%s: %s", path, msg ? msg : sys_errlist[errno]); - return 2; -} - -static void -usage(void) -{ - fprintf(stderr, - "usage: ckdist [-airsx] [-d dir] [-n name] [-t type] file ...\n"); - exit(2); -} diff --git a/usr.sbin/clear_locks/Makefile b/usr.sbin/clear_locks/Makefile deleted file mode 100644 index 00ff3ce..0000000 --- a/usr.sbin/clear_locks/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= clear_locks -MAN= clear_locks.8 -DPADD= ${LIBRPCSVC} -LDADD= -lrpcsvc - -.include diff --git a/usr.sbin/clear_locks/clear_locks.8 b/usr.sbin/clear_locks/clear_locks.8 deleted file mode 100644 index 6b601ea..0000000 --- a/usr.sbin/clear_locks/clear_locks.8 +++ /dev/null @@ -1,51 +0,0 @@ -.\" Copyright (c) 2008 Isilon Inc http://www.isilon.com/ -.\" Authors: Doug Rabson -.\" Developed with Red Inc: Alfred Perlstein -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd March 19, 2008 -.Dt CLEAR_LOCKS 8 -.Os -.Sh NAME -.Nm clear_locks -.Nd clear locks held on behalf of an NFS client -.Sh SYNOPSIS -.Nm -.Ar hostname -.Sh DESCRIPTION -The -.Nm -command can be used to clear file locks held by an NFS client. -This should only be used to handle problems caused by an NFS client -crashing while holding locks and failing to clear them itself when it -reboots. -.Sh SEE ALSO -.Xr rpc.lockd 8 -.Sh HISTORY -A version of -.Nm -appeared in -.Tn SunOS -4. diff --git a/usr.sbin/clear_locks/clear_locks.c b/usr.sbin/clear_locks/clear_locks.c deleted file mode 100644 index 1249c12..0000000 --- a/usr.sbin/clear_locks/clear_locks.c +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ - * Authors: Doug Rabson - * Developed with Red Inc: Alfred Perlstein - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include - -#include -#include - -int -main(int argc, char **argv) -{ - enum clnt_stat stat; - char *hostname; - nlm4_notify notify; - - if (argc != 2) { - fprintf(stderr, "Usage: clear_locks \n"); - exit(1); - } - hostname = argv[1]; - - if (geteuid() != 0) { - fprintf(stderr, "clear_locks: must be root\n"); - exit(1); - } - - notify.name = hostname; - notify.state = 0; - stat = rpc_call("localhost", NLM_PROG, NLM_VERS4, NLM4_FREE_ALL, - (xdrproc_t) xdr_nlm4_notify, (void *) ¬ify, - (xdrproc_t) xdr_void, NULL, NULL); - - if (stat != RPC_SUCCESS) { - clnt_perrno(stat); - exit(1); - } - fprintf(stderr, "clear_locks: cleared locks for hostname %s\n", - hostname); - - return (0); -} diff --git a/usr.sbin/config/Makefile b/usr.sbin/config/Makefile deleted file mode 100644 index 6faf847..0000000 --- a/usr.sbin/config/Makefile +++ /dev/null @@ -1,21 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -PROG= config -MAN= config.5 config.8 -SRCS= config.y main.c lang.l mkmakefile.c mkheaders.c \ - mkoptions.c y.tab.h kernconf.c - -kernconf.c: kernconf.tmpl - file2c 'char kernconfstr[] = {' ',0};' < ${.CURDIR}/kernconf.tmpl > kernconf.c - -CFLAGS+= -I. -I${.CURDIR} - -DPADD= ${LIBL} ${LIBSBUF} -LDADD= -ll -lsbuf - -CLEANFILES+= kernconf.c - -mkmakefile.o: configvers.h - -.include diff --git a/usr.sbin/config/SMM.doc/0.t b/usr.sbin/config/SMM.doc/0.t deleted file mode 100644 index ae5bf77..0000000 --- a/usr.sbin/config/SMM.doc/0.t +++ /dev/null @@ -1,88 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)0.t 8.1 (Berkeley) 7/5/93 -.\" -.bd S B 3 -.de UX -.ie \\n(GA>0 \\$2UNIX\\$1 -.el \{\ -.if n \\$2UNIX\\$1* -.if t \\$2UNIX\\$1\\f1\(dg\\fP -.FS -.if n *UNIX -.if t \(dgUNIX -.ie \\$3=1 is a Footnote of Bell Laboratories. -.el is a Trademark of Bell Laboratories. -.FE -.nr GA 1\} -.. -.de BR -\fB\\$1\fP\\$2 -.. -.TL -Building 4.4BSD Kernels with Config -.AU -Samuel J. Leffler and Michael J. Karels -.AI -Computer Systems Research Group -Department of Electrical Engineering and Computer Science -University of California, Berkeley -Berkeley, California 94720 -.de IR -\fI\\$1\fP\\$2 -.. -.de DT -.TA 8 16 24 32 40 48 56 64 72 80 -.. -.AB -.PP -This document describes the use of -\fIconfig\fP\|(8) to configure and create bootable -4.4BSD system images. -It discusses the structure of system -configuration files and how to configure -systems with non-standard hardware configurations. -Sections describing the preferred way to -add new code to the system and how the system's autoconfiguration -process operates are included. An appendix -contains a summary of the rules used by the system -in calculating the size of system data structures, -and also indicates some of the standard system size -limitations (and how to change them). -Other configuration options are also listed. -.sp -.LP -Revised July 5, 1993 -.AE -.LP -.OH 'Building 4.4BSD Kernels with Config''SMM:2-%' -.EH 'SMM:2-%''Building 4.4BSD Kernels with Config' diff --git a/usr.sbin/config/SMM.doc/1.t b/usr.sbin/config/SMM.doc/1.t deleted file mode 100644 index 453041b..0000000 --- a/usr.sbin/config/SMM.doc/1.t +++ /dev/null @@ -1,61 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)1.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH Introduction -.ne 2i -.sp 3 -.NH -INTRODUCTION -.PP -.I Config -is a tool used in building 4.4BSD system images (the UNIX kernel). -It takes a file describing a system's tunable parameters and -hardware support, and generates a collection -of files which are then used to build a copy of UNIX appropriate -to that configuration. -.I Config -simplifies system maintenance by isolating system dependencies -in a single, easy to understand, file. -.PP -This document describes the content and -format of system configuration -files and the rules which must be followed when creating -these files. Example configuration files are constructed -and discussed. -.PP -Later sections suggest guidelines to be used in modifying -system source and explain some of the inner workings of the -autoconfiguration process. Appendix D summarizes the rules -used in calculating the most important system data structures -and indicates some inherent system data structure size -limitations (and how to go about modifying them). diff --git a/usr.sbin/config/SMM.doc/2.t b/usr.sbin/config/SMM.doc/2.t deleted file mode 100644 index 34e6b63..0000000 --- a/usr.sbin/config/SMM.doc/2.t +++ /dev/null @@ -1,188 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)2.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Configuration File Contents -.ne 2i -.NH -CONFIGURATION FILE CONTENTS -.PP -A system configuration must include at least the following -pieces of information: -.IP \(bu 3 -machine type -.IP \(bu 3 -cpu type -.IP \(bu 3 -system identification -.IP \(bu 3 -timezone -.IP \(bu 3 -maximum number of users -.IP \(bu 3 -location of the root file system -.IP \(bu 3 -available hardware -.PP -.I Config -allows multiple system images to be generated from a single -configuration description. Each system image is configured -for identical hardware, but may have different locations for the root -file system and, possibly, other system devices. -.NH 2 -Machine type -.PP -The -.I "machine type" -indicates if the system is going to operate on a DEC VAX-11\(dg computer, -.FS -\(dg DEC, VAX, UNIBUS, MASSBUS and MicroVAX are trademarks of Digital -Equipment Corporation. -.FE -or some other machine on which 4.4BSD operates. The machine type -is used to locate certain data files which are machine specific, and -also to select rules used in constructing the resultant -configuration files. -.NH 2 -Cpu type -.PP -The -.I "cpu type" -indicates which, of possibly many, cpu's the system is to operate on. -For example, if the system is being configured for a VAX-11, it could -be running on a VAX 8600, VAX-11/780, VAX-11/750, VAX-11/730 or MicroVAX II. -(Other VAX cpu types, including the 8650, 785 and 725, are configured using -the cpu designation for compatible machines introduced earlier.) -Specifying -more than one cpu type implies that the system should be configured to run -on any of the cpu's specified. For some types of machines this is not -possible and -.I config -will print a diagnostic indicating such. -.NH 2 -System identification -.PP -The -.I "system identification" -is a moniker attached to the system, and often the machine on which the -system is to run. For example, at Berkeley we have machines named Ernie -(Co-VAX), Kim (No-VAX), and so on. The system identifier selected is used to -create a global C ``#define'' which may be used to isolate system dependent -pieces of code in the kernel. For example, Ernie's Varian driver used -to be special cased because its interrupt vectors were wired together. The -code in the driver which understood how to handle this non-standard hardware -configuration was conditionally compiled in only if the system -was for Ernie. -.PP -The system identifier ``GENERIC'' is given to a system which -will run on any cpu of a particular machine type; it should not -otherwise be used for a system identifier. -.NH 2 -Timezone -.PP -The timezone in which the system is to run is used to define the -information returned by the \fIgettimeofday\fP\|(2) -system call. This value is specified as the number of hours east -or west of GMT. Negative numbers indicate a value east of GMT. -The timezone specification may also indicate the -type of daylight savings time rules to be applied. -.NH 2 -Maximum number of users -.PP -The system allocates many system data structures at boot time -based on the maximum number of users the system will support. -This number is normally between 8 and 40, depending -on the hardware and expected job mix. The rules -used to calculate system data structures are discussed in -Appendix D. -.NH 2 -Root file system location -.PP -When the system boots it must know the location of -the root of the file system -tree. This location and the part(s) of the disk(s) to be used -for paging and swapping must be specified in order to create -a complete configuration description. -.I Config -uses many rules to calculate default locations for these items; -these are described in Appendix B. -.PP -When a generic system is configured, the root file system is left -undefined until the system is booted. In this case, the root file -system need not be specified, only that the system is a generic system. -.NH 2 -Hardware devices -.PP -When the system boots it goes through an -.I autoconfiguration -phase. During this period, the system searches for all -those hardware devices -which the system builder has indicated might be present. This probing -sequence requires certain pieces of information such as register -addresses, bus interconnects, etc. A system's hardware may be configured -in a very flexible manner or be specified without any flexibility -whatsoever. Most people do not configure hardware devices into the -system unless they are currently present on the machine, expect -them to be present in the near future, or are simply guarding -against a hardware -failure somewhere else at the site (it is often wise to configure in -extra disks in case an emergency requires moving one off a machine which -has hardware problems). -.PP -The specification of hardware devices usually occupies the majority of -the configuration file. As such, a large portion of this document will -be spent understanding it. Section 6.3 contains a description of -the autoconfiguration process, as it applies to those planning to -write, or modify existing, device drivers. -.NH 2 -Pseudo devices -.PP -Several system facilities are configured in a manner like that used -for hardware devices although they are not associated with specific hardware. -These system options are configured as -.IR pseudo-devices . -Some pseudo devices allow an optional parameter that sets the limit -on the number of instances of the device that are active simultaneously. -.NH 2 -System options -.PP -Other than the mandatory pieces of information described above, it -is also possible to include various optional system facilities -or to modify system behavior and/or limits. -For example, 4.4BSD can be configured to support binary compatibility for -programs built under 4.3BSD. Also, optional support is provided -for disk quotas and tracing the performance of the virtual memory -subsystem. Any optional facilities to be configured into -the system are specified in the configuration file. The resultant -files generated by -.I config -will automatically include the necessary pieces of the system. diff --git a/usr.sbin/config/SMM.doc/3.t b/usr.sbin/config/SMM.doc/3.t deleted file mode 100644 index e0b6234..0000000 --- a/usr.sbin/config/SMM.doc/3.t +++ /dev/null @@ -1,299 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)3.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "System Building Process -.ne 2i -.NH -SYSTEM BUILDING PROCESS -.PP -In this section we consider the steps necessary to build a bootable system -image. We assume the system source is located in the ``/sys'' directory -and that, initially, the system is being configured from source code. -.PP -Under normal circumstances there are 5 steps in building a system. -.IP 1) 3 -Create a configuration file for the system. -.IP 2) 3 -Make a directory for the system to be constructed in. -.IP 3) 3 -Run -.I config -on the configuration file to generate the files required -to compile and load the system image. -.IP 4) -Construct the source code interdependency rules for the -configured system with -.I make depend -using -.IR make (1). -.IP 5) -Compile and load the system with -.IR make . -.PP -Steps 1 and 2 are usually done only once. When a system configuration -changes it usually suffices to just run -.I config -on the modified configuration file, rebuild the source code dependencies, -and remake the system. Sometimes, -however, configuration dependencies may not be noticed in which case -it is necessary to clean out the relocatable object files saved -in the system's directory; this will be discussed later. -.NH 2 -Creating a configuration file -.PP -Configuration files normally reside in the directory ``/sys/conf''. -A configuration file is most easily constructed by copying an -existing configuration file and modifying it. The 4.4BSD distribution -contains a number of configuration files for machines at Berkeley; -one may be suitable or, in worst case, a copy -of the generic configuration file may be edited. -.PP -The configuration file must have the same name as the directory in -which the configured system is to be built. -Further, -.I config -assumes this directory is located in the parent directory of -the directory in which it -is run. For example, the generic -system has a configuration file ``/sys/conf/GENERIC'' and an accompanying -directory named ``/sys/GENERIC''. -Although it is not required that the system sources and configuration -files reside in ``/sys,'' the configuration and compilation procedure -depends on the relative locations of directories within that hierarchy, -as most of the system code and the files created by -.I config -use pathnames of the form ``../''. -If the system files are not located in ``/sys,'' -it is desirable to make a symbolic link there for use in installation -of other parts of the system that share files with the kernel. -.PP -When building the configuration file, be sure to include the items -described in section 2. In particular, the machine type, -cpu type, timezone, system identifier, maximum users, and root device -must be specified. The specification of the hardware present may take -a bit of work; particularly if your hardware is configured at non-standard -places (e.g. device registers located at funny places or devices not -supported by the system). Section 4 of this document -gives a detailed description of the configuration file syntax, -section 5 explains some sample configuration files, and -section 6 discusses how to add new devices to -the system. If the devices to be configured are not already -described in one of the existing configuration files you should check -the manual pages in section 4 of the UNIX Programmers Manual. For each -supported device, the manual page synopsis entry gives a -sample configuration line. -.PP -Once the configuration file is complete, run it through -.I config -and look for any errors. Never try and use a system which -.I config -has complained about; the results are unpredictable. -For the most part, -.IR config 's -error diagnostics are self explanatory. It may be the case that -the line numbers given with the error messages are off by one. -.PP -A successful run of -.I config -on your configuration file will generate a number of files in -the configuration directory. These files are: -.IP \(bu 3 -A file to be used by \fImake\fP\|(1) -in compiling and loading the system, -.IR Makefile . -.IP \(bu 3 -One file for each possible system image for this machine, -.IR swapxxx.c , -where -.I xxx -is the name of the system image, -which describes where swapping, the root file system, and other -miscellaneous system devices are located. -.IP \(bu 3 -A collection of header files, one per possible device the -system supports, which define the hardware configured. -.IP \(bu 3 -A file containing the I/O configuration tables used by the system -during its -.I autoconfiguration -phase, -.IR ioconf.c . -.IP \(bu 3 -An assembly language file of interrupt vectors which -connect interrupts from the machine's external buses to the main -system path for handling interrupts, -and a file that contains counters and names for the interrupt vectors. -.PP -Unless you have reason to doubt -.IR config , -or are curious how the system's autoconfiguration scheme -works, you should never have to look at any of these files. -.NH 2 -Constructing source code dependencies -.PP -When -.I config -is done generating the files needed to compile and link your system it -will terminate with a message of the form ``Don't forget to run make depend''. -This is a reminder that you should change over to the configuration -directory for the system just configured and type ``make depend'' -to build the rules used by -.I make -to recognize interdependencies in the system source code. -This will insure that any changes to a piece of the system -source code will result in the proper modules being recompiled -the next time -.I make -is run. -.PP -This step is particularly important if your site makes changes -to the system include files. The rules generated specify which source code -files are dependent on which include files. Without these rules, -.I make -will not recognize when it must rebuild modules -due to the modification of a system header file. -The dependency rules are generated by a pass of the C preprocessor -and reflect the global system options. -This step must be repeated when the configuration file is changed -and -.I config -is used to regenerate the system makefile. -.NH 2 -Building the system -.PP -The makefile constructed by -.I config -should allow a new system to be rebuilt by simply typing ``make image-name''. -For example, if you have named your bootable system image ``kernel'', -then ``make kernel'' -will generate a bootable image named ``kernel''. Alternate system image names -are used when the root file system location and/or swapping configuration -is done in more than one way. The makefile which -.I config -creates has entry points for each system image defined in -the configuration file. -Thus, if you have configured ``kernel'' to be a system with the root file -system on an ``hp'' device and ``hkkernel'' to be a system with the root -file system on an ``hk'' device, then ``make kernel hkkernel'' will generate -binary images for each. -As the system will generally use the disk from which it is loaded -as the root filesystem, separate system images are only required -to support different swap configurations. -.PP -Note that the name of a bootable image is different from the system -identifier. All bootable images are configured for the same system; -only the information about the root file system and paging devices differ. -(This is described in more detail in section 4.) -.PP -The last step in the system building process is to rearrange certain commonly -used symbols in the symbol table of the system image; the makefile -generated by -.I config -does this automatically for you. -This is advantageous for programs such as -\fInetstat\fP\|(1) and \fIvmstat\fP\|(1), -which run much faster when the symbols they need are located at -the front of the symbol table. -Remember also that many programs expect -the currently executing system to be named ``/kernel''. If you install -a new system and name it something other than ``/kernel'', many programs -are likely to give strange results. -.NH 2 -Sharing object modules -.PP -If you have many systems which are all built on a single machine -there are at least two approaches to saving time in building system -images. The best way is to have a single system image which is run on -all machines. This is attractive since it minimizes disk space used -and time required to rebuild systems after making changes. However, -it is often the case that one or more systems will require a separately -configured system image. This may be due to limited memory (building -a system with many unused device drivers can be expensive), or to -configuration requirements (one machine may be a development machine -where disk quotas are not needed, while another is a production machine -where they are), etc. In these cases it is possible -for common systems to share relocatable object modules which are not -configuration dependent; most of the modules in the directory ``/sys/sys'' -are of this sort. -.PP -To share object modules, a generic system should be built. Then, for -each system configure the system as before, but before recompiling and -linking the system, type ``make links'' in the system compilation directory. -This will cause the system -to be searched for source modules which are safe to share between systems -and generate symbolic links in the current directory to the appropriate -object modules in the directory ``../GENERIC''. A shell script, -``makelinks'' is generated with this request and may be checked for -correctness. The file ``/sys/conf/defines'' contains a list of symbols -which we believe are safe to ignore when checking the source code -for modules which may be shared. Note that this list includes the definitions -used to conditionally compile in the virtual memory tracing facilities, and -the trace point support used only rarely (even at Berkeley). -It may be necessary -to modify this file to reflect local needs. Note further that -interdependencies which are not directly visible -in the source code are not caught. This means that if you place -per-system dependencies in an include file, they will not be recognized -and the shared code may be selected in an unexpected fashion. -.NH 2 -Building profiled systems -.PP -It is simple to configure a system which will automatically -collect profiling information as it operates. The profiling data -may be collected with \fIkgmon\fP\|(8) and processed with -\fIgprof\fP\|(1) -to obtain information regarding the system's operation. Profiled -systems maintain histograms of the program counter as well as the -number of invocations of each routine. The \fIgprof\fP -command will also generate a dynamic call graph of the executing -system and propagate time spent in each routine along the arcs -of the call graph (consult the \fIgprof\fP documentation for elaboration). -The program counter sampling can be driven by the system clock, or -if you have an alternate real time clock, this can be used. The -latter is highly recommended, as use of the system clock will result -in statistical anomalies, and time spent in the clock routine will -not be accurately attributed. -.PP -To configure a profiled system, the -.B \-p -option should be supplied to \fIconfig\fP. -A profiled system is about 5-10% larger in its text space due to -the calls to count the subroutine invocations. When the system -executes, the profiling data is stored in a buffer which is 1.2 -times the size of the text space. The overhead for running a -profiled system varies; under normal load we see anywhere from 5-25% -of the system time spent in the profiling code. -.PP -Note that systems configured for profiling should not be shared as -described above unless all the other shared systems are also to be -profiled. diff --git a/usr.sbin/config/SMM.doc/4.t b/usr.sbin/config/SMM.doc/4.t deleted file mode 100644 index 7498185..0000000 --- a/usr.sbin/config/SMM.doc/4.t +++ /dev/null @@ -1,442 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)4.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Configuration File Syntax -.ne 2i -.NH -CONFIGURATION FILE SYNTAX -.PP -In this section we consider the specific rules used in writing -a configuration file. A complete grammar for the input language -can be found in Appendix A and may be of use if you should have -problems with syntax errors. -.PP -A configuration file is broken up into three logical pieces: -.IP \(bu 3 -configuration parameters global to all system images -specified in the configuration file, -.IP \(bu 3 -parameters specific to each -system image to be generated, and -.IP \(bu 3 -device specifications. -.NH 2 -Global configuration parameters -.PP -The global configuration parameters are the type of machine, -cpu types, options, timezone, system identifier, and maximum users. -Each is specified with a separate line in the configuration file. -.IP "\fBmachine\fP \fItype\fP" -.br -The system is to run on the machine type specified. No more than -one machine type can appear in the configuration file. Legal values -are -.B vax -and -\fBsun\fP. -.IP "\fBcpu\fP ``\fItype\fP''" -.br -This system is to run on the cpu type specified. -More than one cpu type specification -can appear in a configuration file. -Legal types for a -.B vax -machine are -\fBVAX8600\fP, \fBVAX780\fP, \fBVAX750\fP, -\fBVAX730\fP -and -\fBVAX630\fP (MicroVAX II). -The 8650 is listed as an 8600, the 785 as a 780, and a 725 as a 730. -.IP "\fBoptions\fP \fIoptionlist\fP" -.br -Compile the listed optional code into the system. -Options in this list are separated by commas. -Possible options are listed at the top of the generic makefile. -A line of the form ``options FUNNY,HAHA'' generates global ``#define''s -\-DFUNNY \-DHAHA in the resultant makefile. -An option may be given a value by following its name with ``\fB=\fP'', -then the value enclosed in (double) quotes. -The following are major options are currently in use: -COMPAT (include code for compatibility with 4.1BSD binaries), -INET (Internet communication protocols), -NS (Xerox NS communication protocols), -and -QUOTA (enable disk quotas). -Other kernel options controlling system sizes and limits -are listed in Appendix D; -options for the network are found in Appendix E. -There are additional options which are associated with certain -peripheral devices; those are listed in the Synopsis section -of the manual page for the device. -.IP "\fBmakeoptions\fP \fIoptionlist\fP" -.br -Options that are used within the system makefile -and evaluated by -.I make -are listed as -.IR makeoptions . -Options are listed with their values with the form -``makeoptions name=value,name2=value2.'' -The values must be enclosed in double quotes if they include numerals -or begin with a dash. -.IP "\fBtimezone\fP \fInumber\fP [ \fBdst\fP [ \fInumber\fP ] ]" -.br -Specifies the timezone used by the system. This is measured in the -number of hours your timezone is west of GMT. -EST is 5 hours west of GMT, PST is 8. Negative numbers -indicate hours east of GMT. If you specify -\fBdst\fP, the system will operate under daylight savings time. -An optional integer or floating point number may be included -to specify a particular daylight saving time correction algorithm; -the default value is 1, indicating the United States. -Other values are: 2 (Australian style), 3 (Western European), -4 (Middle European), and 5 (Eastern European). See -\fIgettimeofday\fP\|(2) and \fIctime\fP\|(3) for more information. -.IP "\fBident\fP \fIname\fP" -.br -This system is to be known as -.IR name . -This is usually a cute name like ERNIE (short for Ernie Co-Vax) or -VAXWELL (for Vaxwell Smart). -This value is defined for use in conditional compilation, -and is also used to locate an optional list of source files specific -to this system. -.IP "\fBmaxusers\fP \fInumber\fP" -.br -The maximum expected number of simultaneously active user on this system is -.IR number . -This number is used to size several system data structures. -.NH 2 -System image parameters -.PP -Multiple bootable images may be specified in a single configuration -file. The systems will have the same global configuration parameters -and devices, but the location of the root file system and other -system specific devices may be different. A system image is specified -with a ``config'' line: -.IP -\fBconfig\fP\ \fIsysname\fP\ \fIconfig-clauses\fP -.LP -The -.I sysname -field is the name given to the loaded system image; almost everyone -names their standard system image ``kernel''. The configuration clauses -are one or more specifications indicating where the root file system -is located and the number and location of paging devices. -The device used by the system to process argument lists during -.IR execve (2) -calls may also be specified, though in practice this is almost -always selected by -.I config -using one of its rules for selecting default locations for -system devices. -.PP -A configuration clause is one of the following -.IP -.nf -\fBroot\fP [ \fBon\fP ] \fIroot-device\fP -\fBswap\fP [ \fBon\fP ] \fIswap-device\fP [ \fBand\fP \fIswap-device\fP ] ... -\fBdumps\fP [ \fBon\fP ] \fIdump-device\fP -\fBargs\fP [ \fBon\fP ] \fIarg-device\fP -.LP -(the ``on'' is optional.) Multiple configuration clauses -are separated by white space; -.I config -allows specifications to be continued across multiple lines -by beginning the continuation line with a tab character. -The ``root'' clause specifies where the root file system -is located, the ``swap'' clause indicates swapping and paging -area(s), the ``dumps'' clause can be used to force system dumps -to be taken on a particular device, and the ``args'' clause -can be used to specify that argument list processing for -.I execve -should be done on a particular device. -.PP -The device names supplied in the clauses may be fully specified -as a device, unit, and file system partition; or underspecified -in which case -.I config -will use builtin rules to select default unit numbers and file -system partitions. The defaulting rules are a bit complicated -as they are dependent on the overall system configuration. -For example, the swap area need not be specified at all if -the root device is specified; in this case the swap area is -placed in the ``b'' partition of the same disk where the root -file system is located. Appendix B contains a complete list -of the defaulting rules used in selecting system configuration -devices. -.PP -The device names are translated to the -appropriate major and minor device -numbers on a per-machine basis. A file, -``/sys/conf/devices.machine'' (where ``machine'' -is the machine type specified in the configuration file), -is used to map a device name to its major block device number. -The minor device number is calculated using the standard -disk partitioning rules: on unit 0, partition ``a'' is minor device -0, partition ``b'' is minor device 1, and so on; for units -other than 0, add 8 times the unit number to get the minor -device. -.PP -If the default mapping of device name to major/minor device -number is incorrect for your configuration, it can be replaced -by an explicit specification of the major/minor device. -This is done by substituting -.IP -\fBmajor\fP \fIx\fP \fBminor\fP \fIy\fP -.LP -where the device name would normally be found. For example, -.IP -.nf -\fBconfig\fP kernel \fBroot\fP \fBon\fP \fBmajor\fP 99 \fBminor\fP 1 -.fi -.PP -Normally, the areas configured for swap space are sized by the system -at boot time. If a non-standard size is to be used for one -or more swap areas (less than the full partition), -this can also be specified. To do this, the -device name specified for a swap area should have a ``size'' -specification appended. For example, -.IP -.nf -\fBconfig\fP kernel \fBroot\fP \fBon\fP hp0 \fBswap\fP \fBon\fP hp0b \fBsize\fP 1200 -.fi -.LP -would force swapping to be done in partition ``b'' of ``hp0'' and -the swap partition size would be set to 1200 sectors. A swap area -sized larger than the associated disk partition is trimmed to the -partition size. -.PP -To create a generic configuration, only the clause ``swap generic'' -should be specified; any extra clauses will cause an error. -.NH 2 -Device specifications -.PP -Each device attached to a machine must be specified -to -.I config -so that the system generated will know to probe for it during -the autoconfiguration process carried out at boot time. Hardware -specified in the configuration need not actually be present on -the machine where the generated system is to be run. Only the -hardware actually found at boot time will be used by the system. -.PP -The specification of hardware devices in the configuration file -parallels the interconnection hierarchy of the machine to be -configured. On the VAX, this means that a configuration file must -indicate what MASSBUS and UNIBUS adapters are present, and to -which \fInexi\fP they might be connected.* -.FS -* While VAX-11/750's and VAX-11/730 do not actually have -nexi, the system treats them as having -.I "simulated nexi" -to simplify device configuration. -.FE -Similarly, devices -and controllers must be indicated as possibly being connected -to one or more adapters. A device description may provide a -complete definition of the possible configuration parameters -or it may leave certain parameters undefined and make the system -probe for all the possible values. The latter allows a single -device configuration list to match many possible physical -configurations. For example, a disk may be indicated as present -at UNIBUS adapter 0, or at any UNIBUS adapter which the system -locates at boot time. The latter scheme, termed -.IR wildcarding , -allows more flexibility in the physical configuration of a system; -if a disk must be moved around for some reason, the system will -still locate it at the alternate location. -.PP -A device specification takes one of the following forms: -.IP -.nf -\fBmaster\fP \fIdevice-name\fP \fIdevice-info\fP -\fBcontroller\fP \fIdevice-name\fP \fIdevice-info\fP [ \fIinterrupt-spec\fP ] -\fBdevice\fP \fIdevice-name\fP \fIdevice-info\fP \fIinterrupt-spec\fP -\fBdisk\fP \fIdevice-name\fP \fIdevice-info\fP -\fBtape\fP \fIdevice-name\fP \fIdevice-info\fP -.fi -.LP -A ``master'' is a MASSBUS tape controller; a ``controller'' is a -disk controller, a UNIBUS tape controller, a MASSBUS adapter, or -a UNIBUS adapter. A ``device'' is an autonomous device which -connects directly to a UNIBUS adapter (as opposed to something -like a disk which connects through a disk controller). ``Disk'' -and ``tape'' identify disk drives and tape drives connected to -a ``controller'' or ``master.'' -.PP -The -.I device-name -is one of the standard device names, as -indicated in section 4 of the UNIX Programmers Manual, -concatenated with the -.I logical -unit number to be assigned the device (the -.I logical -unit number may be different than the -.I physical -unit number indicated on the front of something -like a disk; the -.I logical -unit number is used to refer to the UNIX device, not -the physical unit number). For example, ``hp0'' is logical -unit 0 of a MASSBUS storage device, even though it might -be physical unit 3 on MASSBUS adapter 1. -.PP -The -.I device-info -clause specifies how the hardware is -connected in the interconnection hierarchy. On the VAX, -UNIBUS and MASSBUS adapters are connected to the internal -system bus through -a \fInexus\fP. -Thus, one of the following -specifications would be used: -.IP -.ta 1.5i 2.5i 4.0i -.nf -\fBcontroller\fP mba0 \fBat\fP \fBnexus\fP \fIx\fP -\fBcontroller\fP uba0 \fBat\fP \fBnexus\fP \fIx\fP -.fi -.LP -To tie a controller to a specific nexus, ``x'' would be supplied -as the number of that nexus; otherwise ``x'' may be specified as -``?'', in which -case the system will probe all nexi present looking -for the specified controller. -.PP -The remaining interconnections on the VAX are: -.IP \(bu 3 -a controller -may be connected to another controller (e.g. a disk controller attached -to a UNIBUS adapter), -.IP \(bu 3 -a master is always attached to a controller (a MASSBUS adapter), -.IP \(bu 3 -a tape is always attached to a master (for MASSBUS -tape drives), -.IP \(bu 3 -a disk is always attached to a controller, and -.IP \(bu 3 -devices -are always attached to controllers (e.g. UNIBUS controllers attached -to UNIBUS adapters). -.LP -The following lines give an example of each of these interconnections: -.IP -.ta 1.5i 2.5i 4.0i -.nf -\fBcontroller\fP hk0 \fBat\fP uba0 ... -\fBmaster\fP ht0 \fBat\fP mba0 ... -\fBdisk\fP hp0 \fBat\fP mba0 ... -\fBtape\fP tu0 \fBat\fP ht0 ... -\fBdisk\fP rk1 \fBat\fP hk0 ... -\fBdevice\fP dz0 \fBat\fP uba0 ... -.fi -.LP -Any piece of hardware which may be connected to a specific -controller may also be wildcarded across multiple controllers. -.PP -The final piece of information needed by the system to configure -devices is some indication of where or how a device will interrupt. -For tapes and disks, simply specifying the \fIslave\fP or \fIdrive\fP -number is sufficient to locate the control status register for the -device. -\fIDrive\fP numbers may be wildcarded -on MASSBUS devices, but not on disks on a UNIBUS controller. -For controllers, the control status register must be -given explicitly, as well the number of interrupt vectors used and -the names of the routines to which they should be bound. -Thus the example lines given above might be completed as: -.IP -.ta 1.5i 2.5i 4.0i -.nf -\fBcontroller\fP hk0 \fBat\fP uba0 \fBcsr\fP 0177440 \fBvector\fP rkintr -\fBmaster\fP ht0 \fBat\fP mba0 \fBdrive\fP 0 -\fBdisk\fP hp0 \fBat\fP mba0 \fBdrive\fP ? -\fBtape\fP tu0 \fBat\fP ht0 \fBslave\fP 0 -\fBdisk\fP rk1 \fBat\fP hk0 \fBdrive\fP 1 -\fBdevice\fP dz0 \fBat\fP uba0 \fBcsr\fP 0160100 \fBvector\fP dzrint dzxint -.fi -.PP -Certain device drivers require extra information passed to them -at boot time to tailor their operation to the actual hardware present. -The line printer driver, for example, needs to know how many columns -are present on each non-standard line printer (i.e. a line printer -with other than 80 columns). The drivers for the terminal multiplexors -need to know which lines are attached to modem lines so that no one will -be allowed to use them unless a connection is present. For this reason, -one last parameter may be specified to a -.IR device , -a -.I flags -field. It has the syntax -.IP -\fBflags\fP \fInumber\fP -.LP -and is usually placed after the -.I csr -specification. The -.I number -is passed directly to the associated driver. The manual pages -in section 4 should be consulted to determine how each driver -uses this value (if at all). -Communications interface drivers commonly use the flags -to indicate whether modem control signals are in use. -.PP -The exact syntax for each specific device is given in the Synopsis -section of its manual page in section 4 of the manual. -.NH 2 -Pseudo-devices -.PP -A number of drivers and software subsystems -are treated like device drivers without any associated hardware. -To include any of these pieces, a ``pseudo-device'' specification -must be used. A specification for a pseudo device takes the form -.IP -.DT -.nf -\fBpseudo-device\fP \fIdevice-name\fP [ \fIhowmany\fP ] -.fi -.PP -Examples of pseudo devices are -\fBpty\fP, the pseudo terminal driver (where the optional -.I howmany -value indicates the number of pseudo terminals to configure, 32 default), -and \fBloop\fP, the software loopback network pseudo-interface. -Other pseudo devices for the network include -\fBimp\fP (required when a CSS or ACC imp is configured) -and \fBether\fP (used by the Address Resolution Protocol -on 10 Mb/sec Ethernets). -More information on configuring each of these can also be found -in section 4 of the manual. diff --git a/usr.sbin/config/SMM.doc/5.t b/usr.sbin/config/SMM.doc/5.t deleted file mode 100644 index 81f2a52..0000000 --- a/usr.sbin/config/SMM.doc/5.t +++ /dev/null @@ -1,271 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)5.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Sample Configuration Files -.ne 2i -.NH -SAMPLE CONFIGURATION FILES -.PP -In this section we will consider how to configure a -sample VAX-11/780 system on which the hardware can be -reconfigured to guard against various hardware mishaps. -We then study the rules needed to configure a VAX-11/750 -to run in a networking environment. -.NH 2 -VAX-11/780 System -.PP -Our VAX-11/780 is configured with hardware -recommended in the document ``Hints on Configuring a VAX for 4.2BSD'' -(this is one of the high-end configurations). -Table 1 lists the pertinent hardware to be configured. -.DS B -.TS -box; -l | l | l | l | l -l | l | l | l | l. -Item Vendor Connection Name Reference -_ -cpu DEC VAX780 -MASSBUS controller Emulex nexus ? mba0 hp(4) -disk Fujitsu mba0 hp0 -disk Fujitsu mba0 hp1 -MASSBUS controller Emulex nexus ? mba1 -disk Fujitsu mba1 hp2 -disk Fujitsu mba1 hp3 -UNIBUS adapter DEC nexus ? -tape controller Emulex uba0 tm0 tm(4) -tape drive Kennedy tm0 te0 -tape drive Kennedy tm0 te1 -terminal multiplexor Emulex uba0 dh0 dh(4) -terminal multiplexor Emulex uba0 dh1 -terminal multiplexor Emulex uba0 dh2 -.TE -.DE -.ce -Table 1. VAX-11/780 Hardware support. -.LP -We will call this machine ANSEL and construct a configuration -file one step at a time. -.PP -The first step is to fill in the global configuration parameters. -The machine is a VAX, so the -.I "machine type" -is ``vax''. We will assume this system will -run only on this one processor, so the -.I "cpu type" -is ``VAX780''. The options are empty since this is going to -be a ``vanilla'' VAX. The system identifier, as mentioned before, -is ``ANSEL,'' and the maximum number of users we plan to support is -about 40. Thus the beginning of the configuration file looks like -this: -.DS -.ta 1.5i 2.5i 4.0i -# -# ANSEL VAX (a picture perfect machine) -# -machine vax -cpu VAX780 -timezone 8 dst -ident ANSEL -maxusers 40 -.DE -.PP -To this we must then add the specifications for three -system images. The first will be our standard system with the -root on ``hp0'' and swapping on the same drive as the root. -The second will have the root file system in the same location, -but swap space interleaved among drives on each controller. -Finally, the third will be a generic system, -to allow us to boot off any of the four disk drives. -.DS -.ta 1.5i 2.5i -config kernel root on hp0 -config hpkernel root on hp0 swap on hp0 and hp2 -config genkernel swap generic -.DE -.PP -Finally, the hardware must be specified. Let us first just try -transcribing the information from Table 1. -.DS -.ta 1.5i 2.5i 4.0i -controller mba0 at nexus ? -disk hp0 at mba0 disk 0 -disk hp1 at mba0 disk 1 -controller mba1 at nexus ? -disk hp2 at mba1 disk 2 -disk hp3 at mba1 disk 3 -controller uba0 at nexus ? -controller tm0 at uba0 csr 0172520 vector tmintr -tape te0 at tm0 drive 0 -tape te1 at tm0 drive 1 -device dh0 at uba0 csr 0160020 vector dhrint dhxint -device dm0 at uba0 csr 0170500 vector dmintr -device dh1 at uba0 csr 0160040 vector dhrint dhxint -device dh2 at uba0 csr 0160060 vector dhrint dhxint -.DE -.LP -(Oh, I forgot to mention one panel of the terminal multiplexor -has modem control, thus the ``dm0'' device.) -.PP -This will suffice, but leaves us with little flexibility. Suppose -our first disk controller were to break. We would like to recable the -drives normally on the second controller so that all our disks could -still be used without reconfiguring the system. To do this we wildcard -the MASSBUS adapter connections and also the slave numbers. Further, -we wildcard the UNIBUS adapter connections in case we decide some time -in the future to purchase another adapter to offload the single UNIBUS -we currently have. The revised device specifications would then be: -.DS -.ta 1.5i 2.5i 4.0i -controller mba0 at nexus ? -disk hp0 at mba? disk ? -disk hp1 at mba? disk ? -controller mba1 at nexus ? -disk hp2 at mba? disk ? -disk hp3 at mba? disk ? -controller uba0 at nexus ? -controller tm0 at uba? csr 0172520 vector tmintr -tape te0 at tm0 drive 0 -tape te1 at tm0 drive 1 -device dh0 at uba? csr 0160020 vector dhrint dhxint -device dm0 at uba? csr 0170500 vector dmintr -device dh1 at uba? csr 0160040 vector dhrint dhxint -device dh2 at uba? csr 0160060 vector dhrint dhxint -.DE -.LP -The completed configuration file for ANSEL is shown in Appendix C. -.NH 2 -VAX-11/750 with network support -.PP -Our VAX-11/750 system will be located on two 10Mb/s Ethernet -local area networks and also the DARPA Internet. The system -will have a MASSBUS drive for the root file system and two -UNIBUS drives. Paging is interleaved among all three drives. -We have sold our standard DEC terminal multiplexors since this -machine will be accessed solely through the network. This -machine is not intended to have a large user community, it -does not have a great deal of memory. First the global parameters: -.DS -.ta 1.5i 2.5i 4.0i -# -# UCBVAX (Gateway to the world) -# -machine vax -cpu "VAX780" -cpu "VAX750" -ident UCBVAX -timezone 8 dst -maxusers 32 -options INET -options NS -.DE -.PP -The multiple cpu types allow us to replace UCBVAX with a -more powerful cpu without reconfiguring the system. The -value of 32 given for the maximum number of users is done to -force the system data structures to be over-allocated. That -is desirable on this machine because, while it is not expected -to support many users, it is expected to perform a great deal -of work. -The ``INET'' indicates that we plan to use the -DARPA standard Internet protocols on this machine, -and ``NS'' also includes support for Xerox NS protocols. -Note that unlike 4.2BSD configuration files, -the network protocol options do not require corresponding pseudo devices. -.PP -The system images and disks are configured next. -.DS -.ta 1.5i 2.5i 4.0i -config kernel root on hp swap on hp and rk0 and rk1 -config upkernel root on up -config hkkernel root on hk swap on rk0 and rk1 - -controller mba0 at nexus ? -controller uba0 at nexus ? -disk hp0 at mba? drive 0 -disk hp1 at mba? drive 1 -controller sc0 at uba? csr 0176700 vector upintr -disk up0 at sc0 drive 0 -disk up1 at sc0 drive 1 -controller hk0 at uba? csr 0177440 vector rkintr -disk rk0 at hk0 drive 0 -disk rk1 at hk0 drive 1 -.DE -.PP -UCBVAX requires heavy interleaving of its paging area to keep up -with all the mail traffic it handles. The limiting factor on this -system's performance is usually the number of disk arms, as opposed -to memory or cpu cycles. The extra UNIBUS controller, ``sc0'', -is in case the MASSBUS controller breaks and a spare controller -must be installed (most of our old UNIBUS controllers have been -replaced with the newer MASSBUS controllers, so we have a number -of these around as spares). -.PP -Finally, we add in the network devices. -Pseudo terminals are needed to allow users to -log in across the network (remember the only hardwired terminal -is the console). -The software loopback device is used for on-machine communications. -The connection to the Internet is through -an IMP, this requires yet another -.I pseudo-device -(in addition to the actual hardware device used by the -IMP software). And, finally, there are the two Ethernet devices. -These use a special protocol, the Address Resolution Protocol (ARP), -to map between Internet and Ethernet addresses. Thus, yet another -.I pseudo-device -is needed. The additional device specifications are show below. -.DS -.ta 1.5i 2.5i 4.0i -pseudo-device pty -pseudo-device loop -pseudo-device imp -device acc0 at uba? csr 0167600 vector accrint accxint -pseudo-device ether -device ec0 at uba? csr 0164330 vector ecrint eccollide ecxint -device il0 at uba? csr 0164000 vector ilrint ilcint -.DE -.LP -The completed configuration file for UCBVAX is shown in Appendix C. -.NH 2 -Miscellaneous comments -.PP -It should be noted in these examples that neither system was -configured to use disk quotas or the 4.1BSD compatibility mode. -To use these optional facilities, and others, we would probably -clean out our current configuration, reconfigure the system, then -recompile and relink the system image(s). This could, of course, -be avoided by figuring out which relocatable object files are -affected by the reconfiguration, then reconfiguring and recompiling -only those files affected by the configuration change. This technique -should be used carefully. diff --git a/usr.sbin/config/SMM.doc/6.t b/usr.sbin/config/SMM.doc/6.t deleted file mode 100644 index f02baed..0000000 --- a/usr.sbin/config/SMM.doc/6.t +++ /dev/null @@ -1,239 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)6.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Adding New Devices -.ne 2i -.NH -ADDING NEW SYSTEM SOFTWARE -.PP -This section is not for the novice, it describes -some of the inner workings of the configuration process as -well as the pertinent parts of the system autoconfiguration process. -It is intended to give -those people who intend to install new device drivers and/or -other system facilities sufficient information to do so in the -manner which will allow others to easily share the changes. -.PP -This section is broken into four parts: -.IP \(bu 3 -general guidelines to be followed in modifying system code, -.IP \(bu 3 -how to add non-standard system facilities to 4.4BSD, -.IP \(bu 3 -how to add a device driver to 4.4BSD, and -.NH 2 -Modifying system code -.PP -If you wish to make site-specific modifications to the system -it is best to bracket them with -.DS -#ifdef SITENAME -\&... -#endif -.DE -to allow your source to be easily distributed to others, and -also to simplify \fIdiff\fP\|(1) listings. If you choose not -to use a source code control system (e.g. SCCS, RCS), and -perhaps even if you do, it is -recommended that you save the old code with something -of the form: -.DS -#ifndef SITENAME -\&... -#endif -.DE -We try to isolate our site-dependent code in individual files -which may be configured with pseudo-device specifications. -.PP -Indicate machine-specific code with ``#ifdef vax'' (or other machine, -as appropriate). -4.4BSD underwent extensive work to make it extremely portable to -machines with similar architectures\- you may someday find -yourself trying to use a single copy of the source code on -multiple machines. -.NH 2 -Adding non-standard system facilities -.PP -This section considers the work needed to augment -.IR config 's -data base files for non-standard system facilities. -.I Config -uses a set of files that list the source modules that may be required -when building a system. -The data bases are taken from the directory in which -.I config -is run, normally /sys/conf. -Three such files may be used: -.IR files , -.IR files .machine, -and -.IR files .ident. -The first is common to all systems, -the second contains files unique to a single machine type, -and the third is an optional list of modules for use on a specific machine. -This last file may override specifications in the first two. -The format of the -.I files -file has grown somewhat complex over time. Entries are normally of -the form -.IP -.nf -.DT -\fIdir/source.c\fP \fItype\fP \fIoption-list\fP \fImodifiers\fP -.LP -for example, -.IP -.nf -.DT -\fIvaxuba/foo.c\fP \fBoptional\fP foo \fBdevice-driver\fP -.LP -The -.I type -is one of -.B standard -or -.BR optional . -Files marked as standard are included in all system configurations. -Optional file specifications include a list of one or more system -options that together require the inclusion of this module. -The options in the list may be either names of devices that may -be in the configuration file, -or the names of system options that may be defined. -An optional file may be listed multiple times with different options; -if all of the options for any of the entries are satisfied, -the module is included. -.PP -If a file is specified as a -.IR device-driver , -any special compilation options for device drivers will be invoked. -On the VAX this results in the use of the -.B \-i -option for the C optimizer. This is required when pointer references -are made to memory locations in the VAX I/O address space. -.PP -Two other optional keywords modify the usage of the file. -.I Config -understands that certain files are used especially for -kernel profiling. These files are indicated in the -.I files -files with a -.I profiling-routine -keyword. For example, the current profiling subroutines -are sequestered off in a separate file with the following -entry: -.IP -.nf -.DT -\fIsys/subr_mcount.c\fP \fBoptional\fP \fBprofiling-routine\fP -.fi -.LP -The -.I profiling-routine -keyword forces -.I config -not to compile the source file with the -.B \-pg -option. -.PP -The second keyword which can be of use is the -.I config-dependent -keyword. This causes -.I config -to compile the indicated module with the global configuration -parameters. This allows certain modules, such as -.I machdep.c -to size system data structures based on the maximum number -of users configured for the system. -.NH 2 -Adding device drivers to 4.4BSD -.PP -The I/O system and -.I config -have been designed to easily allow new device support to be added. -The system source directories are organized as follows: -.DS -.TS -lw(1.0i) l. -/sys/h machine independent include files -/sys/sys machine-independent system source files -/sys/conf site configuration files and basic templates -/sys/net network-protocol-independent, but network-related code -/sys/netinet DARPA Internet code -/sys/netimp IMP support code -/sys/netns Xerox NS code -/sys/vax VAX-specific mainline code -/sys/vaxif VAX network interface code -/sys/vaxmba VAX MASSBUS device drivers and related code -/sys/vaxuba VAX UNIBUS device drivers and related code -.TE -.DE -.PP -Existing block and character device drivers for the VAX -reside in ``/sys/vax'', ``/sys/vaxmba'', and ``/sys/vaxuba''. Network -interface drivers reside in ``/sys/vaxif''. Any new device -drivers should be placed in the appropriate source code directory -and named so as not to conflict with existing devices. -Normally, definitions for things like device registers are placed in -a separate file in the same directory. For example, the ``dh'' -device driver is named ``dh.c'' and its associated include file is -named ``dhreg.h''. -.PP -Once the source for the device driver has been placed in a directory, -the file ``/sys/conf/files.machine'', and possibly -``/sys/conf/devices.machine'' should be modified. The -.I files -files in the conf directory contain a line for each C source or binary-only -file in the system. Those files which are machine independent are -located in ``/sys/conf/files,'' while machine specific files -are in ``/sys/conf/files.machine.'' The ``devices.machine'' file -is used to map device names to major block device numbers. If the device -driver being added provides support for a new disk -you will want to modify this file (the format is obvious). -.PP -In addition to including the driver in the -.I files -file, it must also be added to the device configuration tables. These -are located in ``/sys/vax/conf.c'', or similar for machines other than -the VAX. If you don't understand what to add to this file, you should -study an entry for an existing driver. -Remember that the position in the -device table specifies the major device number. -The block major number is needed in the ``devices.machine'' file -if the device is a disk. -.PP -With the configuration information in place, your configuration -file appropriately modified, and a system reconfigured and rebooted -you should incorporate the shell commands needed to install the special -files in the file system to the file ``/dev/MAKEDEV'' or -``/dev/MAKEDEV.local''. This is discussed in the document ``Installing -and Operating 4.4BSD''. diff --git a/usr.sbin/config/SMM.doc/a.t b/usr.sbin/config/SMM.doc/a.t deleted file mode 100644 index dfcb954..0000000 --- a/usr.sbin/config/SMM.doc/a.t +++ /dev/null @@ -1,162 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)a.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Configuration File Grammar -.bp -.LG -.B -.ce -APPENDIX A. CONFIGURATION FILE GRAMMAR -.sp -.R -.NL -.PP -The following grammar is a compressed form of the actual -\fIyacc\fP\|(1) grammar used by -.I config -to parse configuration files. -Terminal symbols are shown all in upper case, literals -are emboldened; optional clauses are enclosed in brackets, ``['' -and ``]''; zero or more instantiations are denoted with ``*''. -.sp -.nf -.DT -Configuration ::= [ Spec \fB;\fP ]* - -Spec ::= Config_spec - | Device_spec - | \fBtrace\fP - | /* lambda */ - -/* configuration specifications */ - -Config_spec ::= \fBmachine\fP ID - | \fBcpu\fP ID - | \fBoptions\fP Opt_list - | \fBident\fP ID - | System_spec - | \fBtimezone\fP [ \fB\-\fP ] NUMBER [ \fBdst\fP [ NUMBER ] ] - | \fBtimezone\fP [ \fB\-\fP ] FPNUMBER [ \fBdst\fP [ NUMBER ] ] - | \fBmaxusers\fP NUMBER - -/* system configuration specifications */ - -System_spec ::= \fBconfig\fP ID System_parameter [ System_parameter ]* - -System_parameter ::= swap_spec | root_spec | dump_spec | arg_spec - -swap_spec ::= \fBswap\fP [ \fBon\fP ] swap_dev [ \fBand\fP swap_dev ]* - -swap_dev ::= dev_spec [ \fBsize\fP NUMBER ] - -root_spec ::= \fBroot\fP [ \fBon\fP ] dev_spec - -dump_spec ::= \fBdumps\fP [ \fBon\fP ] dev_spec - -arg_spec ::= \fBargs\fP [ \fBon\fP ] dev_spec - -dev_spec ::= dev_name | major_minor - -major_minor ::= \fBmajor\fP NUMBER \fBminor\fP NUMBER - -dev_name ::= ID [ NUMBER [ ID ] ] - -/* option specifications */ - -Opt_list ::= Option [ \fB,\fP Option ]* - -Option ::= ID [ \fB=\fP Opt_value ] - -Opt_value ::= ID | NUMBER - -Mkopt_list ::= Mkoption [ \fB,\fP Mkoption ]* - -Mkoption ::= ID \fB=\fP Opt_value - -/* device specifications */ - -Device_spec ::= \fBdevice\fP Dev_name Dev_info Int_spec - | \fBmaster\fP Dev_name Dev_info - | \fBdisk\fP Dev_name Dev_info - | \fBtape\fP Dev_name Dev_info - | \fBcontroller\fP Dev_name Dev_info [ Int_spec ] - | \fBpseudo-device\fP Dev [ NUMBER ] - -Dev_name ::= Dev NUMBER - -Dev ::= \fBuba\fP | \fBmba\fP | ID - -Dev_info ::= Con_info [ Info ]* - -Con_info ::= \fBat\fP Dev NUMBER - | \fBat\fP \fBnexus\fP NUMBER - -Info ::= \fBcsr\fP NUMBER - | \fBdrive\fP NUMBER - | \fBslave\fP NUMBER - | \fBflags\fP NUMBER - -Int_spec ::= \fBvector\fP ID [ ID ]* - | \fBpriority\fP NUMBER -.fi -.sp -.SH -Lexical Conventions -.LP -The terminal symbols are loosely defined as: -.IP ID -.br -One or more alphabetics, either upper or lower case, and underscore, -``_''. -.IP NUMBER -.br -Approximately the C language specification for an integer number. -That is, a leading ``0x'' indicates a hexadecimal value, -a leading ``0'' indicates an octal value, otherwise the number is -expected to be a decimal value. Hexadecimal numbers may use either -upper or lower case alphabetics. -.IP FPNUMBER -.br -A floating point number without exponent. That is a number of the -form ``nnn.ddd'', where the fractional component is optional. -.LP -In special instances a question mark, ``?'', can be substituted for -a ``NUMBER'' token. This is used to effect wildcarding in device -interconnection specifications. -.LP -Comments in configuration files are indicated by a ``#'' character -at the beginning of the line; the remainder of the line is discarded. -.LP -A specification -is interpreted as a continuation of the previous line -if the first character of the line is tab. diff --git a/usr.sbin/config/SMM.doc/b.t b/usr.sbin/config/SMM.doc/b.t deleted file mode 100644 index 901a009..0000000 --- a/usr.sbin/config/SMM.doc/b.t +++ /dev/null @@ -1,137 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)b.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Device Defaulting Rules -.bp -.LG -.B -.ce -APPENDIX B. RULES FOR DEFAULTING SYSTEM DEVICES -.sp -.R -.NL -.PP -When \fIconfig\fP processes a ``config'' rule which does -not fully specify the location of the root file system, -paging area(s), device for system dumps, and device for -argument list processing it applies a set of rules to -define those values left unspecified. The following list -of rules are used in defaulting system devices. -.IP 1) 3 -If a root device is not specified, the swap -specification must indicate a ``generic'' system is to be built. -.IP 2) 3 -If the root device does not specify a unit number, it -defaults to unit 0. -.IP 3) 3 -If the root device does not include a partition specification, -it defaults to the ``a'' partition. -.IP 4) 3 -If no swap area is specified, it defaults to the ``b'' -partition of the root device. -.IP 5) 3 -If no device is specified for processing argument lists, the -first swap partition is selected. -.IP 6) 3 -If no device is chosen for system dumps, the first swap -partition is selected (see below to find out where dumps are -placed within the partition). -.PP -The following table summarizes the default partitions selected -when a device specification is incomplete, e.g. ``hp0''. -.DS -.TS -l l. -Type Partition -_ -root ``a'' -swap ``b'' -args ``b'' -dumps ``b'' -.TE -.DE -.SH -Multiple swap/paging areas -.PP -When multiple swap partitions are specified, the system treats the -first specified as a ``primary'' swap area which is always used. -The remaining partitions are then interleaved into the paging -system at the time a -.IR swapon (2) -system call is made. This is normally done at boot time with -a call to -.IR swapon (8) -from the /etc/rc file. -.SH -System dumps -.PP -System dumps are automatically taken after a system crash, -provided the device driver for the ``dumps'' device supports -this. The dump contains the contents of memory, but not -the swap areas. Normally the dump device is a disk in -which case the information is copied to a location at the -back of the partition. The dump is placed in the back of the -partition because the primary swap and dump device are commonly -the same device and this allows the system to be rebooted without -immediately overwriting the saved information. When a dump has -occurred, the system variable \fIdumpsize\fP -is set to a non-zero value indicating the size (in bytes) of -the dump. The \fIsavecore\fP\|(8) -program then copies the information from the dump partition to -a file in a ``crash'' directory and also makes a copy of the -system which was running at the time of the crash (usually -``/kernel''). The offset to the system dump is defined in the -system variable \fIdumplo\fP (a sector offset from -the front of the dump partition). The -.I savecore -program operates by reading the contents of \fIdumplo\fP, \fIdumpdev\fP, -and \fIdumpmagic\fP from /dev/kmem, then comparing the value -of \fIdumpmagic\fP read from /dev/kmem to that located in -corresponding location in the dump area of the dump partition. -If a match is found, -.I savecore -assumes a crash occurred and reads \fIdumpsize\fP from the dump area -of the dump partition. This value is then used in copying the -system dump. Refer to -\fIsavecore\fP\|(8) -for more information about its operation. -.PP -The value \fIdumplo\fP is calculated to be -.DS -\fIdumpdev-size\fP \- \fImemsize\fP -.DE -where \fIdumpdev-size\fP is the size of the disk partition -where system dumps are to be placed, and -\fImemsize\fP is the size of physical memory. -If the disk partition is not large enough to hold a full -dump, \fIdumplo\fP is set to 0 (the start of the partition). diff --git a/usr.sbin/config/SMM.doc/c.t b/usr.sbin/config/SMM.doc/c.t deleted file mode 100644 index 67b63ec..0000000 --- a/usr.sbin/config/SMM.doc/c.t +++ /dev/null @@ -1,109 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)c.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Sample Config Files -.bp -.LG -.B -.ce -APPENDIX C. SAMPLE CONFIGURATION FILES -.sp -.R -.NL -.PP -The following configuration files are developed in section 5; -they are included here for completeness. -.sp 2 -.nf -.ta 1.5i 2.5i 4.0i -# -# ANSEL VAX (a picture perfect machine) -# -machine vax -cpu VAX780 -timezone 8 dst -ident ANSEL -maxusers 40 - -config kernel root on hp0 -config hpkernel root on hp0 swap on hp0 and hp2 -config genkernel swap generic - -controller mba0 at nexus ? -disk hp0 at mba? disk ? -disk hp1 at mba? disk ? -controller mba1 at nexus ? -disk hp2 at mba? disk ? -disk hp3 at mba? disk ? -controller uba0 at nexus ? -controller tm0 at uba? csr 0172520 vector tmintr -tape te0 at tm0 drive 0 -tape te1 at tm0 drive 1 -device dh0 at uba? csr 0160020 vector dhrint dhxint -device dm0 at uba? csr 0170500 vector dmintr -device dh1 at uba? csr 0160040 vector dhrint dhxint -device dh2 at uba? csr 0160060 vector dhrint dhxint -.bp -# -# UCBVAX - Gateway to the world -# -machine vax -cpu "VAX780" -cpu "VAX750" -ident UCBVAX -timezone 8 dst -maxusers 32 -options INET -options NS - -config kernel root on hp swap on hp and rk0 and rk1 -config upkernel root on up -config hkkernel root on hk swap on rk0 and rk1 - -controller mba0 at nexus ? -controller uba0 at nexus ? -disk hp0 at mba? drive 0 -disk hp1 at mba? drive 1 -controller sc0 at uba? csr 0176700 vector upintr -disk up0 at sc0 drive 0 -disk up1 at sc0 drive 1 -controller hk0 at uba? csr 0177440 vector rkintr -disk rk0 at hk0 drive 0 -disk rk1 at hk0 drive 1 -pseudo-device pty -pseudo-device loop -pseudo-device imp -device acc0 at uba? csr 0167600 vector accrint accxint -pseudo-device ether -device ec0 at uba? csr 0164330 vector ecrint eccollide ecxint -device il0 at uba? csr 0164000 vector ilrint ilcint diff --git a/usr.sbin/config/SMM.doc/d.t b/usr.sbin/config/SMM.doc/d.t deleted file mode 100644 index db9ab80..0000000 --- a/usr.sbin/config/SMM.doc/d.t +++ /dev/null @@ -1,272 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)d.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Data Structure Sizing Rules -.bp -.LG -.B -.ce -APPENDIX D. VAX KERNEL DATA STRUCTURE SIZING RULES -.sp -.R -.NL -.PP -Certain system data structures are sized at compile time -according to the maximum number of simultaneous users expected, -while others are calculated at boot time based on the -physical resources present, e.g. memory. This appendix lists -both sets of rules and also includes some hints on changing -built-in limitations on certain data structures. -.SH -Compile time rules -.PP -The file \fI/sys/conf\|/param.c\fP contains the definitions of -almost all data structures sized at compile time. This file -is copied into the directory of each configured system to allow -configuration-dependent rules and values to be maintained. -(Each copy normally depends on the copy in /sys/conf, -and global modifications cause the file to be recopied unless -the makefile is modified.) -The rules implied by its contents are summarized below (here -MAXUSERS refers to the value defined in the configuration file -in the ``maxusers'' rule). -Most limits are computed at compile time and stored in global variables -for use by other modules; they may generally be patched in the system -binary image before rebooting to test new values. -.IP \fBnproc\fP -.br -The maximum number of processes which may be running at any time. -It is referred to in other calculations as NPROC and is defined to be -.DS -20 + 8 * MAXUSERS -.DE -.IP \fBntext\fP -.br -The maximum number of active shared text segments. -The constant is intended to allow for network servers and common commands -that remain in the table. -It is defined as -.DS -36 + MAXUSERS. -.DE -.IP \fBninode\fP -.br -The maximum number of files in the file system which may be -active at any time. This includes files in use by users, as -well as directory files being read or written by the system -and files associated with bound sockets in the UNIX IPC domain. -It is defined as -.DS -(NPROC + 16 + MAXUSERS) + 32 -.DE -.IP \fBnfile\fP -.br -The number of ``file table'' structures. One file -table structure is used for each open, unshared, file descriptor. -Multiple file descriptors may reference a single file table -entry when they are created through a \fIdup\fP call, or as the -result of a \fIfork\fP. This is defined to be -.DS -16 * (NPROC + 16 + MAXUSERS) / 10 + 32 -.DE -.IP \fBncallout\fP -.br -The number of ``callout'' structures. One callout -structure is used per internal system event handled with -a timeout. Timeouts are used for terminal delays, -watchdog routines in device drivers, protocol timeout processing, etc. -This is defined as -.DS -16 + NPROC -.DE -.IP \fBnclist\fP -.br -The number of ``c-list'' structures. C-list structures are -used in terminal I/O, and currently each holds 60 characters. -Their number is defined as -.DS -60 + 12 * MAXUSERS -.DE -.IP \fBnmbclusters\fP -.br -The maximum number of pages which may be allocated by the network. -This is defined as 256 (a quarter megabyte of memory) in /sys/h/mbuf.h. -In practice, the network rarely uses this much memory. It starts off -by allocating 8 kilobytes of memory, then requesting more as -required. This value represents an upper bound. -.IP \fBnquota\fP -.br -The number of ``quota'' structures allocated. Quota structures -are present only when disc quotas are configured in the system. One -quota structure is kept per user. This is defined to be -.DS -(MAXUSERS * 9) / 7 + 3 -.DE -.IP \fBndquot\fP -.br -The number of ``dquot'' structures allocated. Dquot structures -are present only when disc quotas are configured in the system. -One dquot structure is required per user, per active file system quota. -That is, when a user manipulates a file on a file system on which -quotas are enabled, the information regarding the user's quotas on -that file system must be in-core. This information is cached, so -that not all information must be present in-core all the time. -This is defined as -.DS -NINODE + (MAXUSERS * NMOUNT) / 4 -.DE -where NMOUNT is the maximum number of mountable file systems. -.LP -In addition to the above values, the system page tables (used to -map virtual memory in the kernel's address space) are sized at -compile time by the SYSPTSIZE definition in the file /sys/vax/vmparam.h. -This is defined to be -.DS -20 + MAXUSERS -.DE -pages of page tables. -Its definition affects -the size of many data structures allocated at boot time because -it constrains the amount of virtual memory which may be addressed -by the running system. This is often the limiting factor -in the size of the buffer cache, in which case a message is printed -when the system configures at boot time. -.SH -Run-time calculations -.PP -The most important data structures sized at run-time are those used in -the buffer cache. Allocation is done by allocating physical memory -(and system virtual memory) immediately after the system -has been started up; look in the file /sys/vax/machdep.c. -The amount of physical memory which may be allocated to the buffer -cache is constrained by the size of the system page tables, among -other things. While the system may calculate -a large amount of memory to be allocated to the buffer cache, -if the system page -table is too small to map this physical -memory into the virtual address space -of the system, only as much as can be mapped will be used. -.PP -The buffer cache is comprised of a number of ``buffer headers'' -and a pool of pages attached to these headers. Buffer headers -are divided into two categories: those used for swapping and -paging, and those used for normal file I/O. The system tries -to allocate 10% of the first two megabytes and 5% of the remaining -available physical memory for the buffer -cache (where \fIavailable\fP does not count that space occupied by -the system's text and data segments). If this results in fewer -than 16 pages of memory allocated, then 16 pages are allocated. -This value is kept in the initialized variable \fIbufpages\fP -so that it may be patched in the binary image (to allow tuning -without recompiling the system), -or the default may be overridden with a configuration-file option. -For example, the option \fBoptions BUFPAGES="3200"\fP -causes 3200 pages (3.2M bytes) to be used by the buffer cache. -A sufficient number of file I/O buffer headers are then allocated -to allow each to hold 2 pages each. -Each buffer maps 8K bytes. -If the number of buffer pages is larger than can be mapped -by the buffer headers, the number of pages is reduced. -The number of buffer headers allocated -is stored in the global variable \fInbuf\fP, -which may be patched before the system is booted. -The system option \fBoptions NBUF="1000"\fP forces the allocation -of 1000 buffer headers. -Half as many swap I/O buffer headers as file I/O buffers -are allocated, -but no more than 256. -.SH -System size limitations -.PP -As distributed, the sum of the virtual sizes of the core-resident -processes is limited to 256M bytes. The size of the text -segment of a single process is currently limited to 6M bytes. -It may be increased to no greater than the data segment size limit -(see below) by redefining MAXTSIZ. -This may be done with a configuration file option, -e.g. \fBoptions MAXTSIZ="(10*1024*1024)"\fP -to set the limit to 10 million bytes. -Other per-process limits discussed here may be changed with similar options -with names given in parentheses. -Soft, user-changeable limits are set to 512K bytes for stack (DFLSSIZ) -and 6M bytes for the data segment (DFLDSIZ) by default; -these may be increased up to the hard limit -with the \fIsetrlimit\fP\|(2) system call. -The data and stack segment size hard limits are set by a system configuration -option to one of 17M, 33M or 64M bytes. -One of these sizes is chosen based on the definition of MAXDSIZ; -with no option, the limit is 17M bytes; with an option -\fBoptions MAXDSIZ="(32*1024*1024)"\fP (or any value between 17M and 33M), -the limit is increased to 33M bytes, and values larger than 33M -result in a limit of 64M bytes. -You must be careful in doing this that you have adequate paging space. -As normally configured , the system has 16M or 32M bytes per paging area, -depending on disk size. -The best way to get more space is to provide multiple, thereby -interleaved, paging areas. -Increasing the virtual memory limits results in interleaving of -swap space in larger sections (from 500K bytes to 1M or 2M bytes). -.PP -By default, the virtual memory system allocates enough memory -for system page tables mapping user page tables -to allow 256 megabytes of simultaneous active virtual memory. -That is, the sum of the virtual memory sizes of all (completely- or partially-) -resident processes can not exceed this limit. -If the limit is exceeded, some process(es) must be swapped out. -To increase the amount of resident virtual space possible, -you can alter the constant USRPTSIZE (in -/sys/vax/vmparam.h). -Each page of system page tables allows 8 megabytes of user virtual memory. -.PP -Because the file system block numbers are stored in -page table \fIpg_blkno\fP -entries, the maximum size of a file system is limited to -2^24 1024 byte blocks. Thus no file system can be larger than 8 gigabytes. -.PP -The number of mountable file systems is set at 20 by the definition -of NMOUNT in /sys/h/param.h. -This should be sufficient; if not, the value can be increased up to 255. -If you have many disks, it makes sense to make some of -them single file systems, and the paging areas don't count in this total. -.PP -The limit to the number of files that a process may have open simultaneously -is set to 64. -This limit is set by the NOFILE definition in /sys/h/param.h. -It may be increased arbitrarily, with the caveat that the user structure -expands by 5 bytes for each file, and thus UPAGES (/sys/vax/machparam.h) -must be increased accordingly. -.PP -The amount of physical memory is currently limited to 64 Mb -by the size of the index fields in the core-map (/sys/h/cmap.h). -The limit may be increased by following instructions in that file -to enlarge those fields. diff --git a/usr.sbin/config/SMM.doc/e.t b/usr.sbin/config/SMM.doc/e.t deleted file mode 100644 index 0a9505b..0000000 --- a/usr.sbin/config/SMM.doc/e.t +++ /dev/null @@ -1,114 +0,0 @@ -.\" Copyright (c) 1983, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)e.t 8.1 (Berkeley) 6/8/93 -.\" -.\".ds RH "Network configuration options -.bp -.LG -.B -.ce -APPENDIX E. NETWORK CONFIGURATION OPTIONS -.sp -.R -.NL -.PP -The network support in the kernel is self-configuring -according to the protocol support options (INET and NS) and the network -hardware discovered during autoconfiguration. -There are several changes that may be made to customize network behavior -due to local restrictions. -Within the Internet protocol routines, the following options -set in the system configuration file are supported: -.IP \fBGATEWAY\fP -.br -The machine is to be used as a gateway. -This option currently makes only minor changes. -First, the size of the network routing hash table is increased. -Secondly, machines that have only a single hardware network interface -will not forward IP packets; without this option, they will also refrain -from sending any error indication to the source of unforwardable packets. -Gateways with only a single interface are assumed to have missing -or broken interfaces, and will return ICMP unreachable errors to hosts -sending them packets to be forwarded. -.IP \fBTCP_COMPAT_42\fP -.br -This option forces the system to limit its initial TCP sequence numbers -to positive numbers. -Without this option, 4.4BSD systems may have problems with TCP connections -to 4.2BSD systems that connect but never transfer data. -The problem is a bug in the 4.2BSD TCP. -.IP \fBIPFORWARDING\fP -.br -Normally, 4.4BSD machines with multiple network interfaces -will forward IP packets received that should be resent to another host. -If the line ``options IPFORWARDING="0"'' is in the system configuration -file, IP packet forwarding will be disabled. -.IP \fBIPSENDREDIRECTS\fP -.br -When forwarding IP packets, 4.4BSD IP will note when a packet is forwarded -using the same interface on which it arrived. -When this is noted, if the source machine is on the directly-attached -network, an ICMP redirect is sent to the source host. -If the packet was forwarded using a route to a host or to a subnet, -a host redirect is sent, otherwise a network redirect is sent. -The generation of redirects may be inhibited with the configuration -option ``options IPSENDREDIRECTS="0".'' -.br -.IP \fBSUBNETSARELOCAL\fP -TCP calculates a maximum segment size to use for each connection, -and sends no datagrams larger than that size. -This size will be no larger than that supported on the outgoing -interface. -Furthermore, if the destination is not on the local network, -the size will be no larger than 576 bytes. -For this test, other subnets of a directly-connected subnetted -network are considered to be local unless the line -``options SUBNETSARELOCAL="0"'' is used in the system configuration file. -.LP -The following options are supported by the Xerox NS protocols: -.IP \fBNSIP\fP -.br -This option allows NS IDP datagrams to be encapsulated in Internet IP -packets for transmission to a collaborating NSIP host. -This may be used to pass IDP packets through IP-only link layer networks. -See -.IR nsip (4P) -for details. -.IP \fBTHREEWAYSHAKE\fP -.br -The NS Sequenced Packet Protocol does not require a three-way handshake -before considering a connection to be in the established state. -(A three-way handshake consists of a connection request, an acknowledgement -of the request along with a symmetrical opening indication, -and then an acknowledgement of the reciprocal opening packet.) -This option forces a three-way handshake before data may be transmitted -on Sequenced Packet sockets. diff --git a/usr.sbin/config/SMM.doc/spell.ok b/usr.sbin/config/SMM.doc/spell.ok deleted file mode 100644 index 50c4ef2..0000000 --- a/usr.sbin/config/SMM.doc/spell.ok +++ /dev/null @@ -1,306 +0,0 @@ -ACC -ANSEL -ARP -Autoconfiguration -BUFPAGES -CANTWAIT -CH -COMPAT -CSS -Co -Config -Config''SMM:2 -DCLR -DFLDSIZ -DFLSSIZ -DFUNNY -DHAHA -DMA -Dev -Dquot -ECC -EMULEX -Emulex -Ethernet -FPNUMBER -FUNNY,HAHA -HAVEBDP -ICMP -IDP -IE -INET -IP -IPC -IPFORWARDING -IPL -IPSENDREDIRECTS -Info -Karels -LH -Leffler -MAKEDEV -MAKEDEV.local -MASSBUS -MAXDSIZ -MAXTSIZ -Makefile -Mb -MicroVAX -Mkopt -Mkoption -NBUF -NEED16 -NEEDBDP -NINODE -NMOUNT -NOFILE -NPROC -NS -NSC -NSIP -NUP -PST -RCS -RDY -RH -RK07 -RK611 -SCCS -SITENAME -SMM:2 -SUBNETSARELOCAL -SYSPTSIZE -TCP -THREEWAYSHAKE -Timezone -UCBVAX -UDP -UNIBUS -UPAGES -UPCS2 -USRPTSIZE -VAX -VAX630 -VAX730 -VAX750 -VAX780 -VAX8600 -VAXWELL -VAXen -Vax -Vaxwell -acc0 -accrint -accxint -addr -arg -args -assym.s -autoconfiguration -autoconfigure -autoconfigured -backpointer -badaddr -blkno -br -br5 -buf -bufpages -buses -caddr -callout -catchall -cmap.h -cmd -conf -conf.c -config -csr -ct.c -ctlr -cvec -datagrams -define''s -dev -devices.machine -dgo -dh.c -dh0 -dh1 -dh2 -dhreg.h -dhrint -dhxint -dinfo -dk -dk.h -dm0 -dmintr -dname -dquot -dst -dumpdev -dumplo -dumpmagic -dumpsize -dz.c -dz0 -dzrint -dzxint -ec0 -eccollide -ecrint -ecxint -endif -es -files.machine -filesystem -foo -foo.c -genkernel -gettimeofday -gigabytes -gprof -hardwired -hd -hk -hk0 -hkkernel -howmany -hp0 -hp0b -hp1 -hp2 -hp3 -hpkernel -ht0 -hz -ident -ifdef -ifndef -il0 -ilcint -ilrint -info -intr -ioconf.c -kgmon -linterrs -loopback -machdep.c -machparam.h -makefile -makelinks -makeoptions -maxusers -mba -mba0 -mba1 -mbuf.h -mcount.c -memsize -minfo -mname -moniker -mspw -nbuf -ncallout -nclist -ndquot -ndrive -netimp -netinet -netns -netstat -nexi -nexus -nfile -ninode -nmbclusters -nnn.ddd -nproc -nquota -nsip -ntext -optionlist -param.c -param.h -pathnames -pg -physaddr -pty -rc -reg -rk.c -rk0 -rk1 -rkintr -savecore -sc -sc0 -sc1 -scdriver -setrlimit -sizeof -softc -source.c -subr -swapxxx.c -sysname -te0 -te1 -timezone -tm0 -tmintr -tu0 -uba -uba.c -uba0 -ubago -uballoc -ubamem -ubanum -ubareg.h -ubarelse -ubavar.h -ubglue.s -ubinfo -ud -ui -um -up.c -up0 -up1 -up2 -upaddr -upattach -upba -upcs1 -upcs2 -updevice -updgo -updinfo -updtab -upintr -upip -upmaptype -upminfo -upprobe -upslave -upstd -upkernel -upwatch -upwstart -value,name2 -value2 -vax -vaxif -vaxmba -vaxuba -vmparam.h -kernel -wildcard -wildcarded -wildcarding -xclu -xxx diff --git a/usr.sbin/config/config.5 b/usr.sbin/config/config.5 deleted file mode 100644 index 7513db1..0000000 --- a/usr.sbin/config/config.5 +++ /dev/null @@ -1,407 +0,0 @@ -.\" Copyright (c) 2003 Joseph Koshy -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd December 3, 2005 -.Dt CONFIG 5 -.Os -.Sh NAME -.Nm config -.Nd kernel configuration file format -.Sh DESCRIPTION -A kernel configuration file specifies the configuration of a -.Fx -kernel. -It is processed by -.Xr config 8 -to create a build environment where a kernel may be built using -.Xr make 1 . -.Ss Lexical Structure -A kernel configuration file comprises a sequence of specification -directives. -.Pp -A specification directive starts with a keyword at the beginning -of the line and is followed by additional parameters. -.Pp -A specification directive may be terminated by a semicolon -.Ql \&; -or by a newline. -Long input lines may be broken into shorter lines by starting the -second and subsequent lines with a white space character. -.Pp -Case is significant, -.Dq Li machine -and -.Dq Li MACHINE -are different tokens. -.Pp -A double quote character -.Ql \[dq] -starts a quoted string. -All characters up to the next quote character form the value -of the quoted string. -A -.Ql \[dq] -character may be inserted into a quoted string by -using the sequence -.Ql \e\[dq] . -.Pp -Numbers are specified using -.Tn C Ns -style -syntax. -.Pp -A -.Ql # -character starts a comment; all characters from the -.Ql # -character till the end of the current line are ignored. -.Pp -Whitespace between tokens is ignored, except inside quoted strings. -Whitespace following a comment line is ignored. -.Ss Configuration Directives -Kernel configuration directives may appear in any order -in a kernel configuration file. -Directives are processed in order of appearance with subsequent -directive lines overriding the effect of prior ones. -.Pp -The list of keywords and their meanings are as follows: -.Pp -.Bl -tag -width indent -compact -.\" -------- CPU -------- -.It Ic cpu Ar cputype -Specify the CPU this kernel will run on. -There can be more than one -.Ic cpu -directive in a configuration file. -The allowed list of CPU names is architecture specific and is -defined in the file -.Pa sys/conf/options. Ns Aq Ar arch . -.\" -------- DEVICE -------- -.Pp -.It Ic device Ar name Op , Ar name Op ... -.It Ic devices Ar name Op , Ar name Op ... -Configures the specified devices -for inclusion into the kernel image. -Devices that are common to all architectures are -defined in the file -.Pa sys/conf/files . -Devices that are specific to architecture -.Ar arch -are defined in the file -.Pa sys/conf/files. Ns Aq Ar arch . -.\" -------- ENV -------- -.Pp -.It Ic env Ar filename -Specifies a filename containing a kernel environment definition. -The kernel normally uses an environment prepared for it at boot time -by -.Xr loader 8 . -This directive makes the kernel ignore the boot environment and use -the compiled-in environment instead. -.Pp -This directive is useful for setting kernel tunables in -embedded environments that do not start from -.Xr loader 8 . -.\" -------- FILES -------- -.Pp -.It Ic files Ar filename -Specifies a file containing a list of files specific to that kernel -configuration file (a la -.Pa files. Ns Aq Ar arch ) . -.\" -------- HINTS -------- -.Pp -.It Ic hints Ar filename -Specifies a file to load a static device configuration specification -from. -From -.Fx 5.0 -onwards, the kernel reads the system's device configuration at boot -time (see -.Xr device.hints 5 ) . -This directive configures the kernel to use the static device configuration -listed in -.Ar filename . -The file -.Ar filename -must conform to the syntax specified by -.Xr device.hints 5 . -Multiple hints lines are allowed. -The resulting hints will be the files concatenated in the order of appearance. -.\" -------- IDENT -------- -.Pp -.It Ic ident Ar name -Set the kernel name to -.Ar name . -At least one -.Ic ident -directive is required. -.\" -------- INCLUDE -------- -.Pp -.It Ic include Ar filename -Read subsequent text from file -.Ar filename -and return to the current file after -.Ar filename -is successfully processed. -.\" -------- MACHINE -------- -.Pp -.It Ic machine Ar arch Op Ar cpuarch -Specifies the architecture of the machine the kernel is being -compiled for. -Legal values for -.Ar arch -include: -.Pp -.Bl -tag -width ".Cm powerpc" -compact -.It Cm alpha -The DEC Alpha architecture. -.It Cm arm -The ARM architecture. -.It Cm amd64 -The AMD x86-64 architecture. -.It Cm i386 -The Intel x86 based PC architecture. -.It Cm ia64 -The Intel IA64 architecture. -.It Cm mips -The MIPS architecture. -.It Cm pc98 -The PC98 architecture. -.It Cm powerpc -The IBM PowerPC architecture. -.It Cm sparc64 -The Sun Sparc64 architecture. -.El -.Pp -If argument -.Ar cpuarch -is specified, it points -.Xr config 8 -to the cpu architecture of the machine. -Currently the -.Cm pc98 -architecture requires its cpu architecture -to be set to -.Cm i386 . -When -.Ar cpuarch -is not specified, it is assumed to be the same as -.Ar arch . -.Ar arch -corresponds to MACHINE. -.Ar cpuarch -corresponds to MACHINE_ARCH. -.Pp -A kernel configuration file may have only one -.Ic machine -directive. -.\" -------- MAKEOPTION -------- -.Pp -.It Ic makeoption Ar options -.It Ic makeoptions Ar options -Add -.Ar options -to the generated makefile. -.Pp -The -.Ar options -argument is a comma separated list of one or more option -specifications. -Each option specification has the form -.Pp -.D1 Ar MakeVariableName Ns Op = Ns Ar Value -.D1 Ar MakeVariableName Ns += Ns Ar Value -.Pp -and results in the appropriate -.Xr make 1 -variable definition being inserted into the generated makefile. -If only the name of the -.Xr make 1 -variable is specified, -.Ar value -is assumed to be the empty string. -.Pp -Example: -.Bd -literal -offset indent -compact -makeoptions MYMAKEOPTION="foo" -makeoptions MYMAKEOPTION+="bar" -makeoptions MYNULLMAKEOPTION -.Ed -.\" -------- MAXUSERS -------- -.Pp -.It Ic maxusers Ar number -This optional directive is used to configure the size -of some kernel data structures. -The parameter -.Ar number -can be 0 (the default) or an integer greater than or equal to 2. -A value of 0 indicates that the kernel should configure -its data structures according to the size of available -physical memory. -If auto configuration is requested, the kernel will set -this tunable to a value between 32 and 384. -.Pp -As explained in -.Xr tuning 7 , -this tunable can also be set at boot time using -.Xr loader 8 . -.\" -------- NOCPU -------- -.Pp -.It Ic nocpu Ar cputype -Remove the specified CPU -from the list of previously selected CPUs. -This directive can be used to cancel the effect of -.Ic cpu -directives in files included using -.Ic include . -.\" -------- NODEVICE -------- -.Pp -.It Ic nodevice Ar name Op , Ar name Op ... -.It Ic nodevices Ar name Op , Ar name Op ... -Remove the specified devices -from the list of previously selected devices. -This directive can be used to cancel the effects of -.Ic device -or -.Ic devices -directives in files included using -.Ic include . -.\" -------- NOMAKEOPTION -------- -.Pp -.It Ic nomakeoption Ar name -.It Ic nomakeoptions Ar name -Removes previously defined -.Xr make 1 -option -.Ar name -from the kernel build. -This directive can be used to cancel the effects of -.Ic makeoption -directives in files included using -.Ic include . -.\" -------- NOOPTION -------- -.Pp -.It Ic nooption Ar name Op , Ar name Op ... -.It Ic nooptions Ar name Op , Ar name Op ... -Remove the specified kernel options -from the list of previously defined options. -This directive can be used to cancel the effects of -.Ic option -or -.Ic options -directives in files included using -.Ic include . -.\" -------- OPTIONS -------- -.Pp -.It Ic option Ar optionspec Op , Ar optionspec Op ... -.It Ic options Ar optionspec Op , Ar optionspec Op ... -Add compile time kernel options to the kernel build. -Each option specification has the form -.Pp -.D1 Ar name Ns Op = Ns Ar value -.Pp -If -.Ar value -is not specified, it is assumed to be -.Dv NULL . -Options common to all architectures are specified in -the file -.Pa sys/conf/options . -Options specific to architecture -.Ar arch -are specified in the file -.Pa sys/conf/options. Ns Aq Ar arch . -.\" -------- PROFILE -------- -.Pp -.It Ic profile Ar number -Enables kernel profiling if -.Ar number -is non-zero. -If -.Ar number -is 2 or greater, the kernel is configured for -high-resolution profiling. -Kernels can also be built for profiling using the -.Fl p -option to -.Xr config 8 . -.El -.Ss Obsolete Directives -The following kernel configuration directives are obsolete. -.Bl -tag -width indent -.\" -------- CONFIG -------- -.It Ic config -This directive was used to specify the device to be used for the root -file system. -From -.Fx 4.0 -onwards, this information is passed to a booting kernel by -.Xr loader 8 . -.El -.Sh FILES -.Bl -tag -width ".Pa sys/conf/Makefile. Ns Ar arch" -compact -.It Pa sys/compile/ Ns Ar NAME -Compile directory created from a kernel configuration. -.It Pa sys/conf/Makefile. Ns Ar arch -.Pa Makefile -fragments for architecture -.Ar arch . -.It Pa sys/conf/files -Devices common to all architectures. -.It Pa sys/conf/files. Ns Ar arch -Devices for architecture -.Ar arch . -.It Pa sys/conf/options -Options common to all architectures. -.It Pa sys/conf/options. Ns Ar arch -Options for architecture -.Ar arch . -.El -.Sh SEE ALSO -.Xr kenv 1 , -.Xr make 1 , -.Xr device.hints 5 , -.Xr loader.conf 5 , -.Xr config 8 , -.Xr kldload 8 , -.Xr loader 8 -.Rs -.%T "Building 4.4BSD Kernels with Config" -.%A "Samuel J. Leffler" -.%A "Michael J. Karels" -.Re -.Sh HISTORY -The -.Xr config 8 -utility first appeared in -.Bx 4.1 , -and was subsequently revised in -.Bx 4.4 . -.Pp -The kernel configuration mechanism changed further in -.Fx 4.0 -and -.Fx 5.0 , -moving toward an architecture supporting dynamic kernel -configuration. diff --git a/usr.sbin/config/config.8 b/usr.sbin/config/config.8 deleted file mode 100644 index 03cffb4..0000000 --- a/usr.sbin/config/config.8 +++ /dev/null @@ -1,263 +0,0 @@ -.\" Copyright (c) 1980, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)config.8 8.2 (Berkeley) 4/19/94 -.\" $FreeBSD$ -.\" -.Dd May 8, 2007 -.Dt CONFIG 8 -.Os -.Sh NAME -.Nm config -.Nd build system configuration files -.Sh SYNOPSIS -.Nm -.Op Fl CVgp -.Op Fl d Ar destdir -.Ar SYSTEM_NAME -.Nm -.Op Fl x Ar kernel -.Sh DESCRIPTION -The -.Nm -utility builds a set of system configuration files from the file -.Ar SYSTEM_NAME -which describes -the system to configure. -A second file -tells -.Nm -what files are needed to generate a system and -can be augmented by configuration specific set of files -that give alternate files for a specific machine -(see the -.Sx FILES -section below). -.Pp -Available options and operands: -.Bl -tag -width ".Ar SYSTEM_NAME" -.It Fl V -Print the -.Nm -version number. -.It Fl C -If the INCLUDE_CONFIG_FILE is present in a configuration file, -kernel image will contain full configuration files included -literally (preserving comments). -This flag is kept for backward compatibility. -.It Fl d Ar destdir -Use -.Ar destdir -as the output directory, instead of the default one. -Note that -.Nm -does not append -.Ar SYSTEM_NAME -to the directory given. -.It Fl m -Print the MACHINE and MACHINE_ARCH values for this -kernel and exit. -.It Fl g -Configure a system for debugging. -.It Fl x Ar kernel -Print kernel configuration file embedded into a kernel -file. -This option makes sense only if -.Cd "options INCLUDE_CONFIG_FILE" -entry was present in your configuration file. -.It Fl p -Configure a system for profiling; for example, -.Xr kgmon 8 -and -.Xr gprof 1 . -If two or more -.Fl p -options are supplied, -.Nm -configures a system for high resolution profiling. -.It Ar SYSTEM_NAME -Specify the name of the system configuration file -containing device specifications, configuration options -and other system parameters for one system configuration. -.El -.Pp -The -.Nm -utility should be run from the -.Pa conf -subdirectory of the system source (usually -.Pa /sys/ Ns Va ARCH Ns Pa /conf ) , -where -.Va ARCH -represents one of the architectures supported by -.Fx . -The -.Nm -utility creates the directory -.Pa ../compile/ Ns Ar SYSTEM_NAME -or the one given with the -.Fl d -option -as necessary and places all output files there. -The output of -.Nm -consists of a number of files; for the -.Tn i386 , -they are: -.Pa Makefile , -used by -.Xr make 1 -in building the system; -header files, -definitions of -the number of various devices that will be compiled into the system. -.Pp -After running -.Nm , -it is necessary to run -.Dq Li make depend -in the directory where the new makefile -was created. -The -.Nm -utility prints a reminder of this when it completes. -.Pp -If any other error messages are produced by -.Nm , -the problems in the configuration file should be corrected and -.Nm -should be run again. -Attempts to compile a system that had configuration errors -are likely to fail. -.Sh DEBUG KERNELS -Traditional -.Bx -kernels are compiled without symbols due to the heavy load on the -system when compiling a -.Dq debug -kernel. -A debug kernel contains complete symbols for all the source files, and -enables an experienced kernel programmer to analyse the cause of a problem. -The -debuggers available prior to -.Bx 4.4 Lite -were able to find some information -from a normal kernel; -.Xr gdb 1 -provides very little support for normal kernels, and a debug kernel is needed -for any meaningful analysis. -.Pp -For reasons of history, time and space, building a debug kernel is not the -default with -.Fx : -a debug kernel takes up to 30% longer to build and -requires about 30 MB of disk storage in the build directory, compared to about 6 -MB for a non-debug kernel. -A debug kernel is about 11 MB in size, compared to -about 2 MB for a non-debug kernel. -This space is used both in the root file -system and at run time in memory. -Use the -.Fl g -option to build a debug kernel. -With this option, -.Nm -causes two kernel files to be built in the kernel build directory: -.Bl -bullet -.It -.Pa kernel.debug -is the complete debug kernel. -.It -.Pa kernel -is a copy of the kernel with the debug symbols stripped off. -This is equivalent -to the normal non-debug kernel. -.El -.Pp -There is currently little sense in installing and booting from a debug kernel, -since the only tools available which use the symbols do not run on-line. -There -are therefore two options for installing a debug kernel: -.Bl -bullet -.It -.Dq Li "make install" -installs -.Pa kernel -in the root file system. -.It -.Dq Li "make install.debug" -installs -.Pa kernel.debug -in the root file system. -.El -.Sh FILES -.Bl -tag -width ".Pa /sys/ Ns Va ARCH Ns Pa /compile/ Ns Ar SYSTEM_NAME" -compact -.It Pa /sys/conf/files -list of common files system is built from -.It Pa /sys/conf/Makefile. Ns Va ARCH -generic makefile for the -.Va ARCH -.It Pa /sys/conf/files. Ns Va ARCH -list of -.Va ARCH -specific files -.It Pa /sys/ Ns Va ARCH Ns Pa /compile/ Ns Ar SYSTEM_NAME -default kernel build directory for system -.Ar SYSTEM_NAME -on -.Va ARCH . -.El -.Sh SEE ALSO -.Xr config 5 -.Pp -The -.Sx SYNOPSIS -portion of each device in section 4. -.Rs -.%T "Building 4.3 BSD UNIX System with Config" -.Re -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 4.1 . -.Pp -Before support for -.Fl x -was introduced, -.Cd "options INCLUDE_CONFIG_FILE" -included entire configuration file that used to be embedded in -the new kernel. -This meant that -.Xr strings 1 -could be used to extract it from a kernel: -to extract the configuration information, you had to use -the command: -.Pp -.Dl "strings -n 3 kernel | sed -n 's/^___//p'" -.Sh BUGS -The line numbers reported in error messages are usually off by one. diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h deleted file mode 100644 index 4abb567..0000000 --- a/usr.sbin/config/config.h +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)config.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD$ - */ - -/* - * Config. - */ -#include -#include -#include -#include - -struct cfgfile { - STAILQ_ENTRY(cfgfile) cfg_next; - char *cfg_path; -}; -STAILQ_HEAD(, cfgfile) cfgfiles; - -struct file_list { - STAILQ_ENTRY(file_list) f_next; - char *f_fn; /* the name */ - int f_type; /* type */ - u_char f_flags; /* see below */ - char *f_compilewith; /* special make rule if present */ - char *f_depends; /* additional dependancies */ - char *f_clean; /* File list to add to clean rule */ - char *f_warn; /* warning message */ -}; - -struct files_name { - char *f_name; - STAILQ_ENTRY(files_name) f_next; -}; - -/* - * Types. - */ -#define NORMAL 1 -#define PROFILING 3 -#define NODEPEND 4 -#define LOCAL 5 -#define DEVDONE 0x80000000 -#define TYPEMASK 0x7fffffff - -/* - * Attributes (flags). - */ -#define NO_IMPLCT_RULE 1 -#define NO_OBJ 2 -#define BEFORE_DEPEND 4 -#define NOWERROR 16 - -struct device { - int d_done; /* processed */ - char *d_name; /* name of device (e.g. rk11) */ -#define UNKNOWN -2 /* -2 means not set yet */ - STAILQ_ENTRY(device) d_next; /* Next one in list */ -}; - -struct config { - char *s_sysname; -}; - -/* - * Config has a global notion of which machine type is - * being used. It uses the name of the machine in choosing - * files and directories. Thus if the name of the machine is ``i386'', - * it will build from ``Makefile.i386'' and use ``../i386/inline'' - * in the makerules, etc. machinearch is the global notion of the - * MACHINE_ARCH for this MACHINE. - */ -char *machinename; -char *machinearch; - -/* - * For each machine, a set of CPU's may be specified as supported. - * These and the options (below) are put in the C flags in the makefile. - */ -struct cputype { - char *cpu_name; - SLIST_ENTRY(cputype) cpu_next; -}; - -SLIST_HEAD(, cputype) cputype; - -/* - * A set of options may also be specified which are like CPU types, - * but which may also specify values for the options. - * A separate set of options may be defined for make-style options. - */ -struct opt { - char *op_name; - char *op_value; - int op_ownfile; /* true = own file, false = makefile */ - SLIST_ENTRY(opt) op_next; - SLIST_ENTRY(opt) op_append; -}; - -SLIST_HEAD(opt_head, opt) opt, mkopt, rmopts; - -struct opt_list { - char *o_name; - char *o_file; - int o_flags; -#define OL_ALIAS 1 - SLIST_ENTRY(opt_list) o_next; -}; - -SLIST_HEAD(, opt_list) otab; - -struct hint { - char *hint_name; - STAILQ_ENTRY(hint) hint_next; -}; - -STAILQ_HEAD(hint_head, hint) hints; - -/* - * Tag present in the kernelconf.tmlp template file. It's mandatory for those - * two strings to be the same. Otherwise you'll get into trouble. - */ -#define KERNCONFTAG "%%KERNCONFFILE%%" - -/* - * Faked option to note, that the configuration file has been taken from the - * kernel file and inclusion of DEFAULTS etc.. isn't nessesery, because we - * already have a list of all required devices. - */ -#define OPT_AUTOGEN "CONFIG_AUTOGENERATED" - -extern char *ident; -extern char *env; -extern char kernconfstr[]; -extern int do_trace; -extern int envmode; -extern int hintmode; -extern int incignore; - -char *get_word(FILE *); -char *get_quoted_word(FILE *); -char *path(const char *); -char *raisestr(char *); -void remember(const char *); -void moveifchanged(const char *, const char *); -int yyparse(void); -int yylex(void); -void options(void); -void makefile(void); -void makeenv(void); -void makehints(void); -void headers(void); -void cfgfile_add(const char *); -void cfgfile_removeall(void); -FILE *open_makefile_template(void); - -extern STAILQ_HEAD(device_head, device) dtab; - -extern char errbuf[80]; -extern int yyline; -extern const char *yyfile; - -extern STAILQ_HEAD(file_list_head, file_list) ftab; - -extern STAILQ_HEAD(files_name_head, files_name) fntab; - -extern int profiling; -extern int debugging; -extern int found_defaults; - -extern int maxusers; - -extern char *PREFIX; /* Config file name - for error messages */ -extern char srcdir[]; /* root of the kernel source tree */ - -#define eq(a,b) (!strcmp(a,b)) -#define ns(s) strdup(s) diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y deleted file mode 100644 index 808b673..0000000 --- a/usr.sbin/config/config.y +++ /dev/null @@ -1,463 +0,0 @@ -%union { - char *str; - int val; - struct file_list *file; -} - -%token ARCH -%token COMMA -%token CONFIG -%token CPU -%token NOCPU -%token DEVICE -%token NODEVICE -%token ENV -%token EQUALS -%token PLUSEQUALS -%token HINTS -%token IDENT -%token MAXUSERS -%token PROFILE -%token OPTIONS -%token NOOPTION -%token MAKEOPTIONS -%token NOMAKEOPTION -%token SEMICOLON -%token INCLUDE -%token FILES - -%token ID -%token NUMBER - -%type Save_id -%type Opt_value -%type Dev -%token PATH - -%{ - -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)config.y 8.1 (Berkeley) 6/6/93 - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include - -#include "config.h" - -struct device_head dtab; -char *ident; -char *env; -int envmode; -int hintmode; -int yyline; -const char *yyfile; -struct file_list_head ftab; -struct files_name_head fntab; -char errbuf[80]; -int maxusers; - -#define ns(s) strdup(s) -int include(const char *, int); -void yyerror(const char *s); -int yywrap(void); - -static void newdev(char *name); -static void newfile(char *name); -static void rmdev_schedule(struct device_head *dh, char *name); -static void newopt(struct opt_head *list, char *name, char *value, int append); -static void rmopt_schedule(struct opt_head *list, char *name); - -static char * -devopt(char *dev) -{ - char *ret = malloc(strlen(dev) + 5); - - sprintf(ret, "DEV_%s", dev); - raisestr(ret); - return ret; -} - -%} -%% -Configuration: - Many_specs - ; - -Many_specs: - Many_specs Spec - | - /* lambda */ - ; - -Spec: - Device_spec SEMICOLON - | - Config_spec SEMICOLON - | - INCLUDE PATH SEMICOLON { - if (incignore == 0) - include($2, 0); - }; - | - INCLUDE ID SEMICOLON { - if (incignore == 0) - include($2, 0); - }; - | - FILES ID SEMICOLON { newfile($2); }; - | - SEMICOLON - | - error SEMICOLON - ; - -Config_spec: - ARCH Save_id { - if (machinename != NULL && !eq($2, machinename)) - errx(1, "%s:%d: only one machine directive is allowed", - yyfile, yyline); - machinename = $2; - machinearch = $2; - } | - ARCH Save_id Save_id { - if (machinename != NULL && - !(eq($2, machinename) && eq($3, machinearch))) - errx(1, "%s:%d: only one machine directive is allowed", - yyfile, yyline); - machinename = $2; - machinearch = $3; - } | - CPU Save_id { - struct cputype *cp = - (struct cputype *)calloc(1, sizeof (struct cputype)); - if (cp == NULL) - err(EXIT_FAILURE, "calloc"); - cp->cpu_name = $2; - SLIST_INSERT_HEAD(&cputype, cp, cpu_next); - } | - NOCPU Save_id { - struct cputype *cp, *cp2; - SLIST_FOREACH_SAFE(cp, &cputype, cpu_next, cp2) { - if (eq(cp->cpu_name, $2)) { - SLIST_REMOVE(&cputype, cp, cputype, cpu_next); - free(cp); - } - } - } | - OPTIONS Opt_list - | - NOOPTION Save_id { rmopt_schedule(&opt, $2); } | - MAKEOPTIONS Mkopt_list - | - NOMAKEOPTION Save_id { rmopt_schedule(&mkopt, $2); } | - IDENT ID { ident = $2; } | - System_spec - | - MAXUSERS NUMBER { maxusers = $2; } | - PROFILE NUMBER { profiling = $2; } | - ENV ID { - env = $2; - envmode = 1; - } | - HINTS ID { - struct hint *hint; - - hint = (struct hint *)calloc(1, sizeof (struct hint)); - if (hint == NULL) - err(EXIT_FAILURE, "calloc"); - hint->hint_name = $2; - STAILQ_INSERT_TAIL(&hints, hint, hint_next); - hintmode = 1; - } - -System_spec: - CONFIG System_id System_parameter_list { - errx(1, "%s:%d: root/dump/swap specifications obsolete", - yyfile, yyline); - } - | - CONFIG System_id - ; - -System_id: - Save_id { newopt(&mkopt, ns("KERNEL"), $1, 0); }; - -System_parameter_list: - System_parameter_list ID - | ID - ; - -Opt_list: - Opt_list COMMA Option - | - Option - ; - -Option: - Save_id { - newopt(&opt, $1, NULL, 0); - if (strchr($1, '=') != NULL) - errx(1, "%s:%d: The `=' in options should not be " - "quoted", yyfile, yyline); - } | - Save_id EQUALS Opt_value { - newopt(&opt, $1, $3, 0); - } ; - -Opt_value: - ID { $$ = $1; } | - NUMBER { - char buf[80]; - - (void) snprintf(buf, sizeof(buf), "%d", $1); - $$ = ns(buf); - } ; - -Save_id: - ID { $$ = $1; } - ; - -Mkopt_list: - Mkopt_list COMMA Mkoption - | - Mkoption - ; - -Mkoption: - Save_id { newopt(&mkopt, $1, ns(""), 0); } | - Save_id EQUALS { newopt(&mkopt, $1, ns(""), 0); } | - Save_id EQUALS Opt_value { newopt(&mkopt, $1, $3, 0); } | - Save_id PLUSEQUALS Opt_value { newopt(&mkopt, $1, $3, 1); } ; - -Dev: - ID { $$ = $1; } - ; - -Device_spec: - DEVICE Dev_list - | - NODEVICE NoDev_list - ; - -Dev_list: - Dev_list COMMA Device - | - Device - ; - -NoDev_list: - NoDev_list COMMA NoDevice - | - NoDevice - ; - -Device: - Dev { - newopt(&opt, devopt($1), ns("1"), 0); - /* and the device part */ - newdev($1); - } - -NoDevice: - Dev { - char *s = devopt($1); - - rmopt_schedule(&opt, s); - free(s); - /* and the device part */ - rmdev_schedule(&dtab, $1); - } ; - -%% - -void -yyerror(const char *s) -{ - - errx(1, "%s:%d: %s", yyfile, yyline + 1, s); -} - -int -yywrap(void) -{ - if (found_defaults) { - if (freopen(PREFIX, "r", stdin) == NULL) - err(2, "%s", PREFIX); - yyfile = PREFIX; - yyline = 0; - found_defaults = 0; - return 0; - } - return 1; -} - -/* - * Add a new file to the list of files. - */ -static void -newfile(char *name) -{ - struct files_name *nl; - - nl = (struct files_name *) calloc(1, sizeof *nl); - if (nl == NULL) - err(EXIT_FAILURE, "calloc"); - nl->f_name = name; - STAILQ_INSERT_TAIL(&fntab, nl, f_next); -} - -/* - * Find a device in the list of devices. - */ -static struct device * -finddev(struct device_head *dlist, char *name) -{ - struct device *dp; - - STAILQ_FOREACH(dp, dlist, d_next) - if (eq(dp->d_name, name)) - return (dp); - - return (NULL); -} - -/* - * Add a device to the list of devices. - */ -static void -newdev(char *name) -{ - struct device *np; - - if (finddev(&dtab, name)) { - fprintf(stderr, - "WARNING: duplicate device `%s' encountered.\n", name); - return; - } - - np = (struct device *) calloc(1, sizeof *np); - if (np == NULL) - err(EXIT_FAILURE, "calloc"); - np->d_name = name; - STAILQ_INSERT_TAIL(&dtab, np, d_next); -} - -/* - * Schedule a device to removal. - */ -static void -rmdev_schedule(struct device_head *dh, char *name) -{ - struct device *dp; - - dp = finddev(dh, name); - if (dp != NULL) { - STAILQ_REMOVE(dh, dp, device, d_next); - free(dp->d_name); - free(dp); - } -} - -/* - * Find an option in the list of options. - */ -static struct opt * -findopt(struct opt_head *list, char *name) -{ - struct opt *op; - - SLIST_FOREACH(op, list, op_next) - if (eq(op->op_name, name)) - return (op); - - return (NULL); -} - -/* - * Add an option to the list of options. - */ -static void -newopt(struct opt_head *list, char *name, char *value, int append) -{ - struct opt *op, *op2; - - /* - * Ignore inclusions listed explicitly for configuration files. - */ - if (eq(name, OPT_AUTOGEN)) { - incignore = 1; - return; - } - - op2 = findopt(list, name); - if (op2 != NULL && !append) { - fprintf(stderr, - "WARNING: duplicate option `%s' encountered.\n", name); - return; - } - - op = (struct opt *)calloc(1, sizeof (struct opt)); - if (op == NULL) - err(EXIT_FAILURE, "calloc"); - op->op_name = name; - op->op_ownfile = 0; - op->op_value = value; - if (op2 != NULL) { - while (SLIST_NEXT(op2, op_append) != NULL) - op2 = SLIST_NEXT(op2, op_append); - SLIST_NEXT(op2, op_append) = op; - } else - SLIST_INSERT_HEAD(list, op, op_next); -} - -/* - * Remove an option from the list of options. - */ -static void -rmopt_schedule(struct opt_head *list, char *name) -{ - struct opt *op; - - op = findopt(list, name); - if (op != NULL) { - SLIST_REMOVE(list, op, opt, op_next); - free(op->op_name); - free(op); - } -} diff --git a/usr.sbin/config/configvers.h b/usr.sbin/config/configvers.h deleted file mode 100644 index a2ce89a..0000000 --- a/usr.sbin/config/configvers.h +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * This file is in the public domain - * - * $FreeBSD$ - */ - -/* - * 6 digits of version. The most significant are branch indicators at the - * time when the last incompatible change was made (which is why it is - * presently 6 on 7-current). The least significant digits are incremented - * as described below. The format is similar to the __FreeBSD_version, but - * not tied to it. - * - * DO NOT CASUALLY BUMP THIS NUMBER! The rules are not the same as shared - * libs or param.h/osreldate. - * - * It is the version number of the protocol between config(8) and the - * sys/conf/ Makefiles (the kernel build system). - * - * It is now also used to trap certain problems that the syntax parser cannot - * detect. - * - * Unfortunately, there is no version number for user supplied config files. - * - * Once, config(8) used to silently report errors and continue anyway. This - * was a huge problem for 'make buildkernel' which was run with the installed - * /usr/sbin/config, not a cross built one. We started bumping the version - * number as a way to trap cases where the previous installworld was not - * compatable with the new buildkernel. The buildtools phase and much more - * comprehensive error code returns solved this original problem. - * - * Most end-users will use buildkernel and the build tools from buildworld. - * The people that are inconvenienced by gratuitous bumps are developers - * who run config by hand. However, developers shouldn't gratuitously be - * inconvenienced. - * - * One should bump the CONFIGVERS in the following ways: - * - * (1) If you change config such that it won't read old config files, - * then bump the major number. You shouldn't be doing this unless - * you are overhauling config. Do not casually bump this number - * and by implication do not make changes that would force a bump - * of this number casually. You should limit major bumps to once - * per branch. - * (2) For each new feature added, bump the minor version of this file. - * When a new feature is actually used by the build system, update the - * %VERSREQ field in the Makefile.$ARCH of all the affected makefiles - * (typically all of them). - * - * $FreeBSD$ - */ -#define CONFIGVERS 600011 -#define MAJOR_VERS(x) ((x) / 100000) diff --git a/usr.sbin/config/kernconf.tmpl b/usr.sbin/config/kernconf.tmpl deleted file mode 100644 index 182614b..0000000 --- a/usr.sbin/config/kernconf.tmpl +++ /dev/null @@ -1,17 +0,0 @@ -/* - * This file acts as a template for config.c that will be generated in the - * kernel build directory after config(8) has been successfully run. - * - * $FreeBSD$ - */ -#include "opt_config.h" -#ifdef INCLUDE_CONFIG_FILE - -/* - * For !INCLUDE_CONFIG_FILE case, you should look at kern_mib.c. This is - * where kernconfstring is defined then. - */ -const char kernconfstring[] __attribute__ ((section("kern_conf"))) = -"%%KERNCONFFILE%%"; - -#endif /* INCLUDE_CONFIG_FILE */ diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l deleted file mode 100644 index 4eb94da..0000000 --- a/usr.sbin/config/lang.l +++ /dev/null @@ -1,309 +0,0 @@ -%{ -/*- - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)lang.l 8.1 (Berkeley) 6/6/93 - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include "y.tab.h" -#include "config.h" - -#define YY_NO_UNPUT - -/* - * Data for returning to previous files from include files. - */ -struct incl { - struct incl *in_prev; /* previous includes in effect, if any */ - YY_BUFFER_STATE in_buf; /* previous lex state */ - const char *in_fname; /* previous file name */ - int in_lineno; /* previous line number */ - int in_ateof; /* token to insert at EOF */ -}; -static struct incl *inclp; -static const char *lastfile; - -/* - * Key word table - */ - -struct kt { - const char *kt_name; - int kt_val; -} key_words[] = { - { "config", CONFIG }, - { "cpu", CPU }, - { "nocpu", NOCPU }, - { "device", DEVICE }, - { "devices", DEVICE }, - { "nodevice", NODEVICE }, - { "nodevices", NODEVICE }, - { "env", ENV }, - { "hints", HINTS }, - { "ident", IDENT }, - { "machine", ARCH }, /* MACHINE is defined in /sys/param.h */ - { "makeoption", MAKEOPTIONS }, - { "makeoptions", MAKEOPTIONS }, - { "nomakeoption", NOMAKEOPTION }, - { "nomakeoptions", NOMAKEOPTION }, - { "maxusers", MAXUSERS }, - { "profile", PROFILE }, - { "option", OPTIONS }, - { "options", OPTIONS }, - { "nooption", NOOPTION }, - { "nooptions", NOOPTION }, - { "include", INCLUDE }, - { "files", FILES }, - { 0, 0 }, -}; - - -static int endinclude(void); -int include(const char *, int); -int kw_lookup(char *); -unsigned int octal(const char *); -unsigned int hex(const char *); -int yyerror(const char *); - -%} -ID [A-Za-z_][-A-Za-z_0-9]* -PATH [./][-/.%^A-Za-z_0-9]+ -%START TOEOL -%% -{ID} { - int i; - - BEGIN 0; - if ((i = kw_lookup(yytext)) == -1) - { - yylval.str = strdup(yytext); - return ID; - } - return i; - } -\\\"[^"]+\\\" { - BEGIN 0; - yytext[yyleng-2] = '"'; - yytext[yyleng-1] = '\0'; - yylval.str = strdup(yytext + 1); - return ID; - } -\"[^"]+\" { - BEGIN 0; - yytext[yyleng-1] = '\0'; - yylval.str = strdup(yytext + 1); - return ID; - } -[^# \t\n]* { - BEGIN 0; - yylval.str = strdup(yytext); - return ID; - } -0[0-7]* { - yylval.val = octal(yytext); - return NUMBER; - } -0x[0-9a-fA-F]+ { - yylval.val = hex(yytext); - return NUMBER; - } --?[1-9][0-9]* { - yylval.val = atoi(yytext); - return NUMBER; - } -"?" { - yylval.val = -1; - return NUMBER; - } -\n/[ \t] { - yyline++; - } -\n { - yyline++; - return SEMICOLON; - } -#.* { /* Ignored (comment) */; } -[ \t\f]* { /* Ignored (white space) */; } -";" { return SEMICOLON; } -"," { return COMMA; } -"=" { BEGIN TOEOL; return EQUALS; } -"+=" { BEGIN TOEOL; return PLUSEQUALS; } -<> { - int tok; - - if (inclp == NULL) - return YY_NULL; - tok = endinclude(); - if (tok != 0) - return tok; - /* otherwise continue scanning */ - } -{PATH} { - BEGIN 0; - yylval.str = strdup(yytext); - return PATH; - } -. { return yytext[0]; } - -%% -/* - * kw_lookup - * Look up a string in the keyword table. Returns a -1 if the - * string is not a keyword otherwise it returns the keyword number - */ - -int -kw_lookup(char *word) -{ - struct kt *kp; - - for (kp = key_words; kp->kt_name != 0; kp++) - if (eq(word, kp->kt_name)) - return kp->kt_val; - return -1; -} - -/* - * Number conversion routines - */ - -unsigned int -octal(const char *str) -{ - unsigned int num; - - (void) sscanf(str, "%o", &num); - return num; -} - -unsigned int -hex(const char *str) -{ - unsigned int num; - - (void) sscanf(str+2, "%x", &num); - return num; -} - -void -cfgfile_add(const char *fname) -{ - struct cfgfile *cf; - - cf = calloc(1, sizeof(*cf)); - if (cf == NULL) - err(EXIT_FAILURE, "calloc"); - assert(cf != NULL); - asprintf(&cf->cfg_path, "%s", fname); - STAILQ_INSERT_TAIL(&cfgfiles, cf, cfg_next); -} - -void -cfgfile_removeall(void) -{ - struct cfgfile *cf; - - while (!STAILQ_EMPTY(&cfgfiles)) { - cf = STAILQ_FIRST(&cfgfiles); - STAILQ_REMOVE_HEAD(&cfgfiles, cfg_next); - if (cf->cfg_path != NULL) - free(cf->cfg_path); - free(cf); - } -} - -/* - * Open the named file for inclusion at the current point. Returns 0 on - * success (file opened and previous state pushed), nonzero on failure - * (fopen failed, complaint made). The `ateof' parameter controls the - * token to be inserted at the end of the include file. If ateof == 0, - * then nothing is inserted. - */ -int -include(const char *fname, int ateof) -{ - FILE *fp; - struct incl *in; - char *fnamebuf; - - fnamebuf = NULL; - fp = fopen(fname, "r"); - if (fp == NULL && fname[0] != '.' && fname[0] != '/') { - asprintf(&fnamebuf, "../../conf/%s", fname); - if (fnamebuf != NULL) { - fp = fopen(fnamebuf, "r"); - free(fnamebuf); - } - } - if (fp == NULL) { - yyerror("cannot open included file"); - return (-1); - } - cfgfile_add(fnamebuf == NULL ? fname : fnamebuf); - in = malloc(sizeof(*in)); - assert(in != NULL); - in->in_prev = inclp; - in->in_buf = YY_CURRENT_BUFFER; - in->in_fname = yyfile; - in->in_lineno = yyline; - in->in_ateof = ateof; - inclp = in; - yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); - yyfile = fname; - yyline = 0; - return (0); -} - -/* - * Terminate the most recent inclusion. - */ -static int -endinclude(void) -{ - struct incl *in; - int ateof; - - in = inclp; - assert(in != NULL); - inclp = in->in_prev; - lastfile = yyfile; - yy_delete_buffer(YY_CURRENT_BUFFER); - (void)fclose(yyin); - yy_switch_to_buffer(in->in_buf); - yyfile = in->in_fname; - yyline = in->in_lineno; - ateof = in->in_ateof; - free(in); - - return (ateof); -} diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c deleted file mode 100644 index b59bba4..0000000 --- a/usr.sbin/config/main.c +++ /dev/null @@ -1,778 +0,0 @@ -/* - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1980, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include "y.tab.h" -#include "config.h" -#include "configvers.h" - -#ifndef TRUE -#define TRUE (1) -#endif - -#ifndef FALSE -#define FALSE (0) -#endif - -#define CDIR "../compile/" - -char * PREFIX; -char destdir[MAXPATHLEN]; -char srcdir[MAXPATHLEN]; - -int debugging; -int profiling; -int found_defaults; -int incignore; - -/* - * Preserve old behaviour in INCLUDE_CONFIG_FILE handling (files are included - * literally). - */ -int filebased = 0; - -static void configfile(void); -static void get_srcdir(void); -static void usage(void); -static void cleanheaders(char *); -static void kernconfdump(const char *); -static void checkversion(void); - -struct hdr_list { - char *h_name; - struct hdr_list *h_next; -} *htab; - -/* - * Config builds a set of files for building a UNIX - * system given a description of the desired system. - */ -int -main(int argc, char **argv) -{ - - struct stat buf; - int ch, len; - char *p; - char xxx[MAXPATHLEN]; - char *kernfile; - int printmachine; - - printmachine = 0; - kernfile = NULL; - while ((ch = getopt(argc, argv, "Cd:gmpVx:")) != -1) - switch (ch) { - case 'C': - filebased = 1; - break; - case 'm': - printmachine = 1; - break; - case 'd': - if (*destdir == '\0') - strlcpy(destdir, optarg, sizeof(destdir)); - else - errx(EXIT_FAILURE, "directory already set"); - break; - case 'g': - debugging++; - break; - case 'p': - profiling++; - break; - case 'V': - printf("%d\n", CONFIGVERS); - exit(0); - case 'x': - kernfile = optarg; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (kernfile != NULL) { - kernconfdump(kernfile); - exit(EXIT_SUCCESS); - } - - if (argc != 1) - usage(); - - PREFIX = *argv; - if (stat(PREFIX, &buf) != 0 || !S_ISREG(buf.st_mode)) - err(2, "%s", PREFIX); - if (freopen("DEFAULTS", "r", stdin) != NULL) { - found_defaults = 1; - yyfile = "DEFAULTS"; - } else { - if (freopen(PREFIX, "r", stdin) == NULL) - err(2, "%s", PREFIX); - yyfile = PREFIX; - } - if (*destdir != '\0') { - len = strlen(destdir); - while (len > 1 && destdir[len - 1] == '/') - destdir[--len] = '\0'; - get_srcdir(); - } else { - strlcpy(destdir, CDIR, sizeof(destdir)); - strlcat(destdir, PREFIX, sizeof(destdir)); - } - - SLIST_INIT(&cputype); - SLIST_INIT(&mkopt); - SLIST_INIT(&opt); - SLIST_INIT(&rmopts); - STAILQ_INIT(&cfgfiles); - STAILQ_INIT(&dtab); - STAILQ_INIT(&fntab); - STAILQ_INIT(&ftab); - STAILQ_INIT(&hints); - if (yyparse()) - exit(3); - - /* - * Ensure that required elements (machine, cpu, ident) are present. - */ - if (machinename == NULL) { - printf("Specify machine type, e.g. ``machine i386''\n"); - exit(1); - } - if (ident == NULL) { - printf("no ident line specified\n"); - exit(1); - } - if (SLIST_EMPTY(&cputype)) { - printf("cpu type must be specified\n"); - exit(1); - } - checkversion(); - - if (printmachine) { - printf("%s\t%s\n",machinename,machinearch); - exit(0); - } - - /* Make compile directory */ - p = path((char *)NULL); - if (stat(p, &buf)) { - if (mkdir(p, 0777)) - err(2, "%s", p); - } else if (!S_ISDIR(buf.st_mode)) - errx(EXIT_FAILURE, "%s isn't a directory", p); - - /* - * make symbolic links in compilation directory - * for "sys" (to make genassym.c work along with #include ) - * and similarly for "machine". - */ - if (*srcdir == '\0') - (void)snprintf(xxx, sizeof(xxx), "../../include"); - else - (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", - srcdir, machinename); - (void) unlink(path("machine")); - (void) symlink(xxx, path("machine")); - if (strcmp(machinename, machinearch) != 0) { - /* - * make symbolic links in compilation directory for - * machinearch, if it is different than machinename. - */ - if (*srcdir == '\0') - (void)snprintf(xxx, sizeof(xxx), "../../../%s/include", - machinearch); - else - (void)snprintf(xxx, sizeof(xxx), "%s/%s/include", - srcdir, machinearch); - (void) unlink(path(machinearch)); - (void) symlink(xxx, path(machinearch)); - } - configfile(); /* put config file into kernel*/ - options(); /* make options .h files */ - makefile(); /* build Makefile */ - makeenv(); /* build env.c */ - makehints(); /* build hints.c */ - headers(); /* make a lot of .h files */ - cleanheaders(p); - printf("Kernel build directory is %s\n", p); - printf("Don't forget to do ``make cleandepend && make depend''\n"); - exit(0); -} - -/* - * get_srcdir - * determine the root of the kernel source tree - * and save that in srcdir. - */ -static void -get_srcdir(void) -{ - struct stat lg, phy; - char *p, *pwd; - int i; - - if (realpath("../..", srcdir) == NULL) - err(EXIT_FAILURE, "Unable to find root of source tree"); - if ((pwd = getenv("PWD")) != NULL && *pwd == '/' && - (pwd = strdup(pwd)) != NULL) { - /* Remove the last two path components. */ - for (i = 0; i < 2; i++) { - if ((p = strrchr(pwd, '/')) == NULL) { - free(pwd); - return; - } - *p = '\0'; - } - if (stat(pwd, &lg) != -1 && stat(srcdir, &phy) != -1 && - lg.st_dev == phy.st_dev && lg.st_ino == phy.st_ino) - strlcpy(srcdir, pwd, MAXPATHLEN); - free(pwd); - } -} - -static void -usage(void) -{ - - fprintf(stderr, "usage: config [-CgmpV] [-d destdir] sysname\n"); - fprintf(stderr, " config -x kernel\n"); - exit(EX_USAGE); -} - -/* - * get_word - * returns EOF on end of file - * NULL on end of line - * pointer to the word otherwise - */ -char * -get_word(FILE *fp) -{ - static char line[80]; - int ch; - char *cp; - int escaped_nl = 0; - -begin: - while ((ch = getc(fp)) != EOF) - if (ch != ' ' && ch != '\t') - break; - if (ch == EOF) - return ((char *)EOF); - if (ch == '\\'){ - escaped_nl = 1; - goto begin; - } - if (ch == '\n') { - if (escaped_nl){ - escaped_nl = 0; - goto begin; - } - else - return (NULL); - } - cp = line; - *cp++ = ch; - while ((ch = getc(fp)) != EOF) { - if (isspace(ch)) - break; - *cp++ = ch; - } - *cp = 0; - if (ch == EOF) - return ((char *)EOF); - (void) ungetc(ch, fp); - return (line); -} - -/* - * get_quoted_word - * like get_word but will accept something in double or single quotes - * (to allow embedded spaces). - */ -char * -get_quoted_word(FILE *fp) -{ - static char line[256]; - int ch; - char *cp; - int escaped_nl = 0; - -begin: - while ((ch = getc(fp)) != EOF) - if (ch != ' ' && ch != '\t') - break; - if (ch == EOF) - return ((char *)EOF); - if (ch == '\\'){ - escaped_nl = 1; - goto begin; - } - if (ch == '\n') { - if (escaped_nl){ - escaped_nl = 0; - goto begin; - } - else - return (NULL); - } - cp = line; - if (ch == '"' || ch == '\'') { - int quote = ch; - - while ((ch = getc(fp)) != EOF) { - if (ch == quote) - break; - if (ch == '\n') { - *cp = 0; - printf("config: missing quote reading `%s'\n", - line); - exit(2); - } - *cp++ = ch; - } - } else { - *cp++ = ch; - while ((ch = getc(fp)) != EOF) { - if (isspace(ch)) - break; - *cp++ = ch; - } - if (ch != EOF) - (void) ungetc(ch, fp); - } - *cp = 0; - if (ch == EOF) - return ((char *)EOF); - return (line); -} - -/* - * prepend the path to a filename - */ -char * -path(const char *file) -{ - char *cp = NULL; - - if (file) - asprintf(&cp, "%s/%s", destdir, file); - else - cp = strdup(destdir); - return (cp); -} - -/* - * Generate configuration file based on actual settings. With this mode, user - * will be able to obtain and build conifguration file with one command. - */ -static void -configfile_dynamic(struct sbuf *sb) -{ - struct cputype *cput; - struct device *d; - struct opt *ol; - char *lend; - unsigned int i; - - asprintf(&lend, "\\n\\\n"); - assert(lend != NULL); - sbuf_printf(sb, "options\t%s%s", OPT_AUTOGEN, lend); - sbuf_printf(sb, "ident\t%s%s", ident, lend); - sbuf_printf(sb, "machine\t%s%s", machinename, lend); - SLIST_FOREACH(cput, &cputype, cpu_next) - sbuf_printf(sb, "cpu\t%s%s", cput->cpu_name, lend); - SLIST_FOREACH(ol, &mkopt, op_next) - sbuf_printf(sb, "makeoptions\t%s=%s%s", ol->op_name, - ol->op_value, lend); - SLIST_FOREACH(ol, &opt, op_next) { - if (strncmp(ol->op_name, "DEV_", 4) == 0) - continue; - sbuf_printf(sb, "options\t%s", ol->op_name); - if (ol->op_value != NULL) { - sbuf_putc(sb, '='); - for (i = 0; i < strlen(ol->op_value); i++) { - if (ol->op_value[i] == '"') - sbuf_printf(sb, "\\%c", - ol->op_value[i]); - else - sbuf_printf(sb, "%c", - ol->op_value[i]); - } - sbuf_printf(sb, "%s", lend); - } else { - sbuf_printf(sb, "%s", lend); - } - } - /* - * Mark this file as containing everything we need. - */ - STAILQ_FOREACH(d, &dtab, d_next) - sbuf_printf(sb, "device\t%s%s", d->d_name, lend); - free(lend); -} - -/* - * Generate file from the configuration files. - */ -static void -configfile_filebased(struct sbuf *sb) -{ - FILE *cff; - struct cfgfile *cf; - int i; - - /* - * Try to read all configuration files. Since those will be present as - * C string in the macro, we have to slash their ends then the line - * wraps. - */ - STAILQ_FOREACH(cf, &cfgfiles, cfg_next) { - cff = fopen(cf->cfg_path, "r"); - if (cff == NULL) { - warn("Couldn't open file %s", cf->cfg_path); - continue; - } - while ((i = getc(cff)) != EOF) { - if (i == '\n') - sbuf_printf(sb, "\\n\\\n"); - else if (i == '"' || i == '\'') - sbuf_printf(sb, "\\%c", i); - else - sbuf_putc(sb, i); - } - fclose(cff); - } -} - -static void -configfile(void) -{ - FILE *fo; - struct sbuf *sb; - char *p; - - /* Add main configuration file to the list of files to be included */ - cfgfile_add(PREFIX); - p = path("config.c.new"); - fo = fopen(p, "w"); - if (!fo) - err(2, "%s", p); - sb = sbuf_new(NULL, NULL, 2048, SBUF_AUTOEXTEND); - assert(sb != NULL); - sbuf_clear(sb); - if (filebased) { - /* Is needed, can be used for backward compatibility. */ - configfile_filebased(sb); - } else { - configfile_dynamic(sb); - } - sbuf_finish(sb); - /* - * We print first part of the template, replace our tag with - * configuration files content and later continue writing our - * template. - */ - p = strstr(kernconfstr, KERNCONFTAG); - if (p == NULL) - errx(EXIT_FAILURE, "Something went terribly wrong!"); - *p = '\0'; - fprintf(fo, "%s", kernconfstr); - fprintf(fo, "%s", sbuf_data(sb)); - p += strlen(KERNCONFTAG); - fprintf(fo, "%s", p); - sbuf_delete(sb); - fclose(fo); - moveifchanged(path("config.c.new"), path("config.c")); - cfgfile_removeall(); -} - -/* - * moveifchanged -- - * compare two files; rename if changed. - */ -void -moveifchanged(const char *from_name, const char *to_name) -{ - char *p, *q; - int changed; - size_t tsize; - struct stat from_sb, to_sb; - int from_fd, to_fd; - - changed = 0; - - if ((from_fd = open(from_name, O_RDONLY)) < 0) - err(EX_OSERR, "moveifchanged open(%s)", from_name); - - if ((to_fd = open(to_name, O_RDONLY)) < 0) - changed++; - - if (!changed && fstat(from_fd, &from_sb) < 0) - err(EX_OSERR, "moveifchanged fstat(%s)", from_name); - - if (!changed && fstat(to_fd, &to_sb) < 0) - err(EX_OSERR, "moveifchanged fstat(%s)", to_name); - - if (!changed && from_sb.st_size != to_sb.st_size) - changed++; - - tsize = (size_t)from_sb.st_size; - - if (!changed) { - p = mmap(NULL, tsize, PROT_READ, MAP_SHARED, from_fd, (off_t)0); - if (p == MAP_FAILED) - err(EX_OSERR, "mmap %s", from_name); - q = mmap(NULL, tsize, PROT_READ, MAP_SHARED, to_fd, (off_t)0); - if (q == MAP_FAILED) - err(EX_OSERR, "mmap %s", to_name); - - changed = memcmp(p, q, tsize); - munmap(p, tsize); - munmap(q, tsize); - } - if (changed) { - if (rename(from_name, to_name) < 0) - err(EX_OSERR, "rename(%s, %s)", from_name, to_name); - } else { - if (unlink(from_name) < 0) - err(EX_OSERR, "unlink(%s)", from_name); - } -} - -static void -cleanheaders(char *p) -{ - DIR *dirp; - struct dirent *dp; - struct file_list *fl; - struct hdr_list *hl; - int i; - - remember("y.tab.h"); - remember("setdefs.h"); - STAILQ_FOREACH(fl, &ftab, f_next) - remember(fl->f_fn); - - /* - * Scan the build directory and clean out stuff that looks like - * it might have been a leftover NFOO header, etc. - */ - if ((dirp = opendir(p)) == NULL) - err(EX_OSERR, "opendir %s", p); - while ((dp = readdir(dirp)) != NULL) { - i = dp->d_namlen - 2; - /* Skip non-headers */ - if (dp->d_name[i] != '.' || dp->d_name[i + 1] != 'h') - continue; - /* Skip special stuff, eg: bus_if.h, but check opt_*.h */ - if (index(dp->d_name, '_') && - strncmp(dp->d_name, "opt_", 4) != 0) - continue; - /* Check if it is a target file */ - for (hl = htab; hl != NULL; hl = hl->h_next) { - if (eq(dp->d_name, hl->h_name)) { - break; - } - } - if (hl) - continue; - printf("Removing stale header: %s\n", dp->d_name); - if (unlink(path(dp->d_name)) == -1) - warn("unlink %s", dp->d_name); - } - (void)closedir(dirp); -} - -void -remember(const char *file) -{ - char *s; - struct hdr_list *hl; - - if ((s = strrchr(file, '/')) != NULL) - s = ns(s + 1); - else - s = ns(file); - - if (index(s, '_') && strncmp(s, "opt_", 4) != 0) { - free(s); - return; - } - for (hl = htab; hl != NULL; hl = hl->h_next) { - if (eq(s, hl->h_name)) { - free(s); - return; - } - } - hl = calloc(1, sizeof(*hl)); - if (hl == NULL) - err(EXIT_FAILURE, "calloc"); - hl->h_name = s; - hl->h_next = htab; - htab = hl; -} - -/* - * This one is quick hack. Will be probably moved to elf(3) interface. - * It takes kernel configuration file name, passes it as an argument to - * elfdump -a, which output is parsed by some UNIX tools... - */ -static void -kernconfdump(const char *file) -{ - struct stat st; - FILE *fp, *pp; - int error, len, osz, r; - unsigned int i, off, size, t1, t2, align; - char *cmd, *o; - - r = open(file, O_RDONLY); - if (r == -1) - err(EXIT_FAILURE, "Couldn't open file '%s'", file); - error = fstat(r, &st); - if (error == -1) - err(EXIT_FAILURE, "fstat() failed"); - if (S_ISDIR(st.st_mode)) - errx(EXIT_FAILURE, "'%s' is a directory", file); - fp = fdopen(r, "r"); - if (fp == NULL) - err(EXIT_FAILURE, "fdopen() failed"); - osz = 1024; - o = calloc(1, osz); - if (o == NULL) - err(EXIT_FAILURE, "Couldn't allocate memory"); - /* ELF note section header. */ - asprintf(&cmd, "/usr/bin/elfdump -c %s | grep -A 8 kern_conf" - "| tail -5 | cut -d ' ' -f 2 | paste - - - - -", file); - if (cmd == NULL) - errx(EXIT_FAILURE, "asprintf() failed"); - pp = popen(cmd, "r"); - if (pp == NULL) - errx(EXIT_FAILURE, "popen() failed"); - free(cmd); - len = fread(o, osz, 1, pp); - pclose(pp); - r = sscanf(o, "%d%d%d%d%d", &off, &size, &t1, &t2, &align); - free(o); - if (r != 5) - errx(EXIT_FAILURE, "File %s doesn't contain configuration " - "file. Either unsupported, or not compiled with " - "INCLUDE_CONFIG_FILE", file); - r = fseek(fp, off, SEEK_CUR); - if (r != 0) - err(EXIT_FAILURE, "fseek() failed"); - for (i = 0; i < size; i++) { - r = fgetc(fp); - if (r == EOF) - break; - /* - * If '\0' is present in the middle of the configuration - * string, this means something very weird is happening. - * Make such case very visible. However, some architectures - * pad the length of the section with NULs to a multiple of - * sh_addralign, allow a NUL in that part of the section. - */ - if (r == '\0' && (size - i) < align) - break; - assert(r != '\0' && ("Char present in the configuration " - "string mustn't be equal to 0")); - fputc(r, stdout); - } - fclose(fp); -} - -static void -badversion(int versreq) -{ - fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n"); - fprintf(stderr, "config version = %d, ", CONFIGVERS); - fprintf(stderr, "version required = %d\n\n", versreq); - fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n"); - fprintf(stderr, "with your /usr/src/sys and install a new config binary\n"); - fprintf(stderr, "before trying this again.\n\n"); - fprintf(stderr, "If running the new config fails check your config\n"); - fprintf(stderr, "file against the GENERIC or LINT config files for\n"); - fprintf(stderr, "changes in config syntax, or option/device naming\n"); - fprintf(stderr, "conventions\n\n"); - exit(1); -} - -static void -checkversion(void) -{ - FILE *ifp; - char line[BUFSIZ]; - int versreq; - - ifp = open_makefile_template(); - while (fgets(line, BUFSIZ, ifp) != 0) { - if (*line != '%') - continue; - if (strncmp(line, "%VERSREQ=", 9) != 0) - continue; - versreq = atoi(line + 9); - if (MAJOR_VERS(versreq) == MAJOR_VERS(CONFIGVERS) && - versreq <= CONFIGVERS) - continue; - badversion(versreq); - } - fclose(ifp); -} diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c deleted file mode 100644 index fd7f1b3..0000000 --- a/usr.sbin/config/mkheaders.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Make all the .h files for the optional entries - */ - -#include -#include -#include -#include -#include -#include "config.h" -#include "y.tab.h" - -void -headers(void) -{ - struct device *dp; - int errors; - - errors = 0; - STAILQ_FOREACH(dp, &dtab, d_next) { - if (!(dp->d_done & DEVDONE)) { - warnx("Error: device \"%s\" is unknown", - dp->d_name); - errors++; - } - } - if (errors) - errx(1, "%d errors", errors); -} diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c deleted file mode 100644 index 6a59698..0000000 --- a/usr.sbin/config/mkmakefile.c +++ /dev/null @@ -1,788 +0,0 @@ -/* - * Copyright (c) 1993, 19801990 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)mkmakefile.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Build the makefile for the system, from - * the information in the files files and the - * additional files for the machine being compiled to. - */ - -#include -#include -#include -#include -#include -#include "y.tab.h" -#include "config.h" -#include "configvers.h" - -#define next_word(fp, wd) \ - { char *word = get_word(fp); \ - if (word == (char *)EOF) \ - return; \ - else \ - wd = word; \ - } -#define next_quoted_word(fp, wd) \ - { char *word = get_quoted_word(fp); \ - if (word == (char *)EOF) \ - return; \ - else \ - wd = word; \ - } - -static char *tail(char *); -static void do_clean(FILE *); -static void do_rules(FILE *); -static void do_xxfiles(char *, FILE *); -static void do_objs(FILE *); -static void do_before_depend(FILE *); -static int opteq(const char *, const char *); -static void read_files(void); - -/* - * Lookup a file, by name. - */ -static struct file_list * -fl_lookup(char *file) -{ - struct file_list *fp; - - STAILQ_FOREACH(fp, &ftab, f_next) { - if (eq(fp->f_fn, file)) - return (fp); - } - return (0); -} - -/* - * Make a new file list entry - */ -static struct file_list * -new_fent(void) -{ - struct file_list *fp; - - fp = (struct file_list *) calloc(1, sizeof *fp); - if (fp == NULL) - err(EXIT_FAILURE, "calloc"); - STAILQ_INSERT_TAIL(&ftab, fp, f_next); - return (fp); -} - -/* - * Open the correct Makefile and return it, or error out. - */ -FILE * -open_makefile_template(void) -{ - FILE *ifp; - char line[BUFSIZ]; - - snprintf(line, sizeof(line), "../../conf/Makefile.%s", machinename); - ifp = fopen(line, "r"); - if (ifp == 0) { - snprintf(line, sizeof(line), "Makefile.%s", machinename); - ifp = fopen(line, "r"); - } - if (ifp == 0) - err(1, "%s", line); - return (ifp); -} - -/* - * Build the makefile from the skeleton - */ -void -makefile(void) -{ - FILE *ifp, *ofp; - char line[BUFSIZ]; - struct opt *op, *t; - - read_files(); - ifp = open_makefile_template(); - ofp = fopen(path("Makefile.new"), "w"); - if (ofp == 0) - err(1, "%s", path("Makefile.new")); - fprintf(ofp, "KERN_IDENT=%s\n", ident); - SLIST_FOREACH_SAFE(op, &mkopt, op_next, t) { - fprintf(ofp, "%s=%s", op->op_name, op->op_value); - while ((op = SLIST_NEXT(op, op_append)) != NULL) - fprintf(ofp, " %s", op->op_value); - fprintf(ofp, "\n"); - } - if (debugging) - fprintf(ofp, "DEBUG=-g\n"); - if (profiling) - fprintf(ofp, "PROFLEVEL=%d\n", profiling); - if (*srcdir != '\0') - fprintf(ofp,"S=%s\n", srcdir); - while (fgets(line, BUFSIZ, ifp) != 0) { - if (*line != '%') { - fprintf(ofp, "%s", line); - continue; - } - if (eq(line, "%BEFORE_DEPEND\n")) - do_before_depend(ofp); - else if (eq(line, "%OBJS\n")) - do_objs(ofp); - else if (strncmp(line, "%FILES.", 7) == 0) - do_xxfiles(line, ofp); - else if (eq(line, "%RULES\n")) - do_rules(ofp); - else if (eq(line, "%CLEAN\n")) - do_clean(ofp); - else if (strncmp(line, "%VERSREQ=", 9) == 0) - line[0] = '\0'; /* handled elsewhere */ - else - fprintf(stderr, - "Unknown %% construct in generic makefile: %s", - line); - } - (void) fclose(ifp); - (void) fclose(ofp); - moveifchanged(path("Makefile.new"), path("Makefile")); -} - -/* - * Build hints.c from the skeleton - */ -void -makehints(void) -{ - FILE *ifp, *ofp; - char line[BUFSIZ]; - char *s; - struct hint *hint; - - ofp = fopen(path("hints.c.new"), "w"); - if (ofp == NULL) - err(1, "%s", path("hints.c.new")); - fprintf(ofp, "#include \n"); - fprintf(ofp, "#include \n"); - fprintf(ofp, "\n"); - fprintf(ofp, "int hintmode = %d;\n", hintmode); - fprintf(ofp, "char static_hints[] = {\n"); - STAILQ_FOREACH(hint, &hints, hint_next) { - ifp = fopen(hint->hint_name, "r"); - if (ifp == NULL) - err(1, "%s", hint->hint_name); - while (fgets(line, BUFSIZ, ifp) != 0) { - /* zap trailing CR and/or LF */ - while ((s = rindex(line, '\n')) != NULL) - *s = '\0'; - while ((s = rindex(line, '\r')) != NULL) - *s = '\0'; - /* remove # comments */ - s = index(line, '#'); - if (s) - *s = '\0'; - /* remove any whitespace and " characters */ - s = line; - while (*s) { - if (*s == ' ' || *s == '\t' || *s == '"') { - while (*s) { - s[0] = s[1]; - s++; - } - /* start over */ - s = line; - continue; - } - s++; - } - /* anything left? */ - if (*line == '\0') - continue; - fprintf(ofp, "\"%s\\0\"\n", line); - } - fclose(ifp); - } - fprintf(ofp, "\"\\0\"\n};\n"); - fclose(ofp); - moveifchanged(path("hints.c.new"), path("hints.c")); -} - -/* - * Build env.c from the skeleton - */ -void -makeenv(void) -{ - FILE *ifp, *ofp; - char line[BUFSIZ]; - char *s; - - if (env) { - ifp = fopen(env, "r"); - if (ifp == NULL) - err(1, "%s", env); - } else { - ifp = NULL; - } - ofp = fopen(path("env.c.new"), "w"); - if (ofp == NULL) - err(1, "%s", path("env.c.new")); - fprintf(ofp, "#include \n"); - fprintf(ofp, "#include \n"); - fprintf(ofp, "\n"); - fprintf(ofp, "int envmode = %d;\n", envmode); - fprintf(ofp, "char static_env[] = {\n"); - if (ifp) { - while (fgets(line, BUFSIZ, ifp) != 0) { - /* zap trailing CR and/or LF */ - while ((s = rindex(line, '\n')) != NULL) - *s = '\0'; - while ((s = rindex(line, '\r')) != NULL) - *s = '\0'; - /* remove # comments */ - s = index(line, '#'); - if (s) - *s = '\0'; - /* remove any whitespace and " characters */ - s = line; - while (*s) { - if (*s == ' ' || *s == '\t' || *s == '"') { - while (*s) { - s[0] = s[1]; - s++; - } - /* start over */ - s = line; - continue; - } - s++; - } - /* anything left? */ - if (*line == '\0') - continue; - fprintf(ofp, "\"%s\\0\"\n", line); - } - } - fprintf(ofp, "\"\\0\"\n};\n"); - if (ifp) - fclose(ifp); - fclose(ofp); - moveifchanged(path("env.c.new"), path("env.c")); -} - -static void -read_file(char *fname) -{ - char ifname[MAXPATHLEN]; - FILE *fp; - struct file_list *tp; - struct device *dp; - struct opt *op; - char *wd, *this, *compilewith, *depends, *clean, *warning; - int compile, match, nreqs, std, filetype, - imp_rule, no_obj, before_depend, mandatory, nowerror; - - fp = fopen(fname, "r"); - if (fp == 0) - err(1, "%s", fname); -next: - /* - * include "filename" - * filename [ standard | mandatory | optional ] - * [ dev* [ | dev* ... ] | profiling-routine ] [ no-obj ] - * [ compile-with "compile rule" [no-implicit-rule] ] - * [ dependency "dependency-list"] [ before-depend ] - * [ clean "file-list"] [ warning "text warning" ] - */ - wd = get_word(fp); - if (wd == (char *)EOF) { - (void) fclose(fp); - return; - } - if (wd == 0) - goto next; - if (wd[0] == '#') - { - while (((wd = get_word(fp)) != (char *)EOF) && wd) - ; - goto next; - } - if (eq(wd, "include")) { - next_quoted_word(fp, wd); - if (wd == 0) { - fprintf(stderr, "%s: missing include filename.\n", - fname); - exit(1); - } - (void) snprintf(ifname, sizeof(ifname), "../../%s", wd); - read_file(ifname); - while (((wd = get_word(fp)) != (char *)EOF) && wd) - ; - goto next; - } - this = ns(wd); - next_word(fp, wd); - if (wd == 0) { - fprintf(stderr, "%s: No type for %s.\n", fname, this); - exit(1); - } - tp = fl_lookup(this); - compile = 0; - match = 1; - nreqs = 0; - compilewith = 0; - depends = 0; - clean = 0; - warning = 0; - std = mandatory = 0; - imp_rule = 0; - no_obj = 0; - before_depend = 0; - nowerror = 0; - filetype = NORMAL; - if (eq(wd, "standard")) { - std = 1; - /* - * If an entry is marked "mandatory", config will abort if it's - * not called by a configuration line in the config file. Apart - * from this, the device is handled like one marked "optional". - */ - } else if (eq(wd, "mandatory")) { - mandatory = 1; - } else if (!eq(wd, "optional")) { - fprintf(stderr, - "%s: %s must be optional, mandatory or standard\n", - fname, this); - exit(1); - } -nextparam: - next_word(fp, wd); - if (wd == 0) { - compile += match; - if (compile && tp == NULL) - goto doneparam; - goto next; - } - if (eq(wd, "|")) { - if (nreqs == 0) { - fprintf(stderr, "%s: syntax error describing %s\n", - fname, this); - exit(1); - } - compile += match; - match = 1; - nreqs = 0; - goto nextparam; - } - if (eq(wd, "no-obj")) { - no_obj++; - goto nextparam; - } - if (eq(wd, "no-implicit-rule")) { - if (compilewith == 0) { - fprintf(stderr, "%s: alternate rule required when " - "\"no-implicit-rule\" is specified.\n", - fname); - } - imp_rule++; - goto nextparam; - } - if (eq(wd, "before-depend")) { - before_depend++; - goto nextparam; - } - if (eq(wd, "dependency")) { - next_quoted_word(fp, wd); - if (wd == 0) { - fprintf(stderr, - "%s: %s missing compile command string.\n", - fname, this); - exit(1); - } - depends = ns(wd); - goto nextparam; - } - if (eq(wd, "clean")) { - next_quoted_word(fp, wd); - if (wd == 0) { - fprintf(stderr, "%s: %s missing clean file list.\n", - fname, this); - exit(1); - } - clean = ns(wd); - goto nextparam; - } - if (eq(wd, "compile-with")) { - next_quoted_word(fp, wd); - if (wd == 0) { - fprintf(stderr, - "%s: %s missing compile command string.\n", - fname, this); - exit(1); - } - compilewith = ns(wd); - goto nextparam; - } - if (eq(wd, "warning")) { - next_quoted_word(fp, wd); - if (wd == 0) { - fprintf(stderr, - "%s: %s missing warning text string.\n", - fname, this); - exit(1); - } - warning = ns(wd); - goto nextparam; - } - nreqs++; - if (eq(wd, "local")) { - filetype = LOCAL; - goto nextparam; - } - if (eq(wd, "no-depend")) { - filetype = NODEPEND; - goto nextparam; - } - if (eq(wd, "profiling-routine")) { - filetype = PROFILING; - goto nextparam; - } - if (eq(wd, "nowerror")) { - nowerror = 1; - goto nextparam; - } - STAILQ_FOREACH(dp, &dtab, d_next) - if (eq(dp->d_name, wd)) { - dp->d_done |= DEVDONE; - goto nextparam; - } - if (mandatory) { - fprintf(stderr, "%s: mandatory device \"%s\" not found\n", - fname, wd); - exit(1); - } - if (std) { - fprintf(stderr, - "standard entry %s has a device keyword - %s!\n", - this, wd); - exit(1); - } - SLIST_FOREACH(op, &opt, op_next) - if (op->op_value == 0 && opteq(op->op_name, wd)) - goto nextparam; - match = 0; - goto nextparam; - -doneparam: - if (std == 0 && nreqs == 0) { - fprintf(stderr, "%s: what is %s optional on?\n", - fname, this); - exit(1); - } - - if (wd) { - fprintf(stderr, "%s: syntax error describing %s\n", - fname, this); - exit(1); - } - if (filetype == PROFILING && profiling == 0) - goto next; - tp = new_fent(); - tp->f_fn = this; - tp->f_type = filetype; - if (imp_rule) - tp->f_flags |= NO_IMPLCT_RULE; - if (no_obj) - tp->f_flags |= NO_OBJ; - if (before_depend) - tp->f_flags |= BEFORE_DEPEND; - if (nowerror) - tp->f_flags |= NOWERROR; - tp->f_compilewith = compilewith; - tp->f_depends = depends; - tp->f_clean = clean; - tp->f_warn = warning; - goto next; -} - -/* - * Read in the information about files used in making the system. - * Store it in the ftab linked list. - */ -static void -read_files(void) -{ - char fname[MAXPATHLEN]; - struct files_name *nl, *tnl; - - (void) snprintf(fname, sizeof(fname), "../../conf/files"); - read_file(fname); - (void) snprintf(fname, sizeof(fname), - "../../conf/files.%s", machinename); - read_file(fname); - for (nl = STAILQ_FIRST(&fntab); nl != NULL; nl = tnl) { - read_file(nl->f_name); - tnl = STAILQ_NEXT(nl, f_next); - free(nl->f_name); - free(nl); - } -} - -static int -opteq(const char *cp, const char *dp) -{ - char c, d; - - for (; ; cp++, dp++) { - if (*cp != *dp) { - c = isupper(*cp) ? tolower(*cp) : *cp; - d = isupper(*dp) ? tolower(*dp) : *dp; - if (c != d) - return (0); - } - if (*cp == 0) - return (1); - } -} - -static void -do_before_depend(FILE *fp) -{ - struct file_list *tp; - int lpos, len; - - fputs("BEFORE_DEPEND=", fp); - lpos = 15; - STAILQ_FOREACH(tp, &ftab, f_next) - if (tp->f_flags & BEFORE_DEPEND) { - len = strlen(tp->f_fn); - if ((len = 3 + len) + lpos > 72) { - lpos = 8; - fputs("\\\n\t", fp); - } - if (tp->f_flags & NO_IMPLCT_RULE) - fprintf(fp, "%s ", tp->f_fn); - else - fprintf(fp, "$S/%s ", tp->f_fn); - lpos += len + 1; - } - if (lpos != 8) - putc('\n', fp); -} - -static void -do_objs(FILE *fp) -{ - struct file_list *tp; - int lpos, len; - char *cp, och, *sp; - - fprintf(fp, "OBJS="); - lpos = 6; - STAILQ_FOREACH(tp, &ftab, f_next) { - if (tp->f_flags & NO_OBJ) - continue; - sp = tail(tp->f_fn); - cp = sp + (len = strlen(sp)) - 1; - och = *cp; - *cp = 'o'; - if (len + lpos > 72) { - lpos = 8; - fprintf(fp, "\\\n\t"); - } - fprintf(fp, "%s ", sp); - lpos += len + 1; - *cp = och; - } - if (lpos != 8) - putc('\n', fp); -} - -static void -do_xxfiles(char *tag, FILE *fp) -{ - struct file_list *tp; - int lpos, len, slen; - char *suff, *SUFF; - - if (tag[strlen(tag) - 1] == '\n') - tag[strlen(tag) - 1] = '\0'; - - suff = ns(tag + 7); - SUFF = ns(suff); - raisestr(SUFF); - slen = strlen(suff); - - fprintf(fp, "%sFILES=", SUFF); - lpos = 8; - STAILQ_FOREACH(tp, &ftab, f_next) - if (tp->f_type != NODEPEND) { - len = strlen(tp->f_fn); - if (tp->f_fn[len - slen - 1] != '.') - continue; - if (strcasecmp(&tp->f_fn[len - slen], suff) != 0) - continue; - if ((len = 3 + len) + lpos > 72) { - lpos = 8; - fputs("\\\n\t", fp); - } - if (tp->f_type != LOCAL) - fprintf(fp, "$S/%s ", tp->f_fn); - else - fprintf(fp, "%s ", tp->f_fn); - lpos += len + 1; - } - if (lpos != 8) - putc('\n', fp); -} - -static char * -tail(char *fn) -{ - char *cp; - - cp = rindex(fn, '/'); - if (cp == 0) - return (fn); - return (cp+1); -} - -/* - * Create the makerules for each file - * which is part of the system. - */ -static void -do_rules(FILE *f) -{ - char *cp, *np, och; - struct file_list *ftp; - char *compilewith; - char cmd[128]; - - STAILQ_FOREACH(ftp, &ftab, f_next) { - if (ftp->f_warn) - fprintf(stderr, "WARNING: %s\n", ftp->f_warn); - cp = (np = ftp->f_fn) + strlen(ftp->f_fn) - 1; - och = *cp; - if (ftp->f_flags & NO_IMPLCT_RULE) { - if (ftp->f_depends) - fprintf(f, "%s: %s\n", np, ftp->f_depends); - else - fprintf(f, "%s: \n", np); - } - else { - *cp = '\0'; - if (och == 'o') { - fprintf(f, "%so:\n\t-cp $S/%so .\n\n", - tail(np), np); - continue; - } - if (ftp->f_depends) { - fprintf(f, "%sln: $S/%s%c %s\n", tail(np), - np, och, ftp->f_depends); - fprintf(f, "\t${NORMAL_LINT}\n\n"); - fprintf(f, "%so: $S/%s%c %s\n", tail(np), - np, och, ftp->f_depends); - } - else { - fprintf(f, "%sln: $S/%s%c\n", tail(np), - np, och); - fprintf(f, "\t${NORMAL_LINT}\n\n"); - fprintf(f, "%so: $S/%s%c\n", tail(np), - np, och); - } - } - compilewith = ftp->f_compilewith; - if (compilewith == 0) { - const char *ftype = NULL; - - switch (ftp->f_type) { - case NORMAL: - ftype = "NORMAL"; - break; - case PROFILING: - if (!profiling) - continue; - ftype = "PROFILE"; - break; - default: - fprintf(stderr, - "config: don't know rules for %s\n", np); - break; - } - snprintf(cmd, sizeof(cmd), - "${%s_%c%s}\n\t@${NORMAL_CTFCONVERT}", ftype, - toupper(och), - ftp->f_flags & NOWERROR ? "_NOWERROR" : ""); - compilewith = cmd; - } - *cp = och; - fprintf(f, "\t%s\n\n", compilewith); - } -} - -static void -do_clean(FILE *fp) -{ - struct file_list *tp; - int lpos, len; - - fputs("CLEAN=", fp); - lpos = 7; - STAILQ_FOREACH(tp, &ftab, f_next) - if (tp->f_clean) { - len = strlen(tp->f_clean); - if (len + lpos > 72) { - lpos = 8; - fputs("\\\n\t", fp); - } - fprintf(fp, "%s ", tp->f_clean); - lpos += len + 1; - } - if (lpos != 8) - putc('\n', fp); -} - -char * -raisestr(char *str) -{ - char *cp = str; - - while (*str) { - if (islower(*str)) - *str = toupper(*str); - str++; - } - return (cp); -} diff --git a/usr.sbin/config/mkoptions.c b/usr.sbin/config/mkoptions.c deleted file mode 100644 index b5d6e34..0000000 --- a/usr.sbin/config/mkoptions.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * Copyright (c) 1995 Peter Wemm - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)mkheaders.c 8.1 (Berkeley) 6/6/93"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Make all the .h files for the optional entries - */ - -#include -#include -#include -#include -#include -#include "config.h" -#include "y.tab.h" - -static struct users { - int u_default; - int u_min; - int u_max; -} users = { 8, 2, 512 }; - -static char *lower(char *); -static void read_options(void); -static void do_option(char *); -static char *tooption(char *); - -void -options(void) -{ - char buf[40]; - struct cputype *cp; - struct opt_list *ol; - struct opt *op; - - /* Fake the cpu types as options. */ - SLIST_FOREACH(cp, &cputype, cpu_next) { - op = (struct opt *)calloc(1, sizeof(*op)); - if (op == NULL) - err(EXIT_FAILURE, "calloc"); - op->op_name = ns(cp->cpu_name); - SLIST_INSERT_HEAD(&opt, op, op_next); - } - - if (maxusers == 0) { - /* fprintf(stderr, "maxusers not specified; will auto-size\n"); */ - } else if (maxusers < users.u_min) { - fprintf(stderr, "minimum of %d maxusers assumed\n", - users.u_min); - maxusers = users.u_min; - } else if (maxusers > users.u_max) - fprintf(stderr, "warning: maxusers > %d (%d)\n", - users.u_max, maxusers); - - /* Fake MAXUSERS as an option. */ - op = (struct opt *)calloc(1, sizeof(*op)); - if (op == NULL) - err(EXIT_FAILURE, "calloc"); - op->op_name = ns("MAXUSERS"); - snprintf(buf, sizeof(buf), "%d", maxusers); - op->op_value = ns(buf); - SLIST_INSERT_HEAD(&opt, op, op_next); - - read_options(); - - /* Fake the value of MACHINE_ARCH as an option if necessary */ - SLIST_FOREACH(ol, &otab, o_next) { - if (strcasecmp(ol->o_name, machinearch) != 0) - continue; - - op = (struct opt *)calloc(1, sizeof(*op)); - if (op == NULL) - err(EXIT_FAILURE, "calloc"); - op->op_name = ns(ol->o_name); - SLIST_INSERT_HEAD(&opt, op, op_next); - break; - } - - SLIST_FOREACH(op, &opt, op_next) { - SLIST_FOREACH(ol, &otab, o_next) { - if (eq(op->op_name, ol->o_name) && - (ol->o_flags & OL_ALIAS)) { - fprintf(stderr, "Mapping option %s to %s.\n", - op->op_name, ol->o_file); - op->op_name = ol->o_file; - break; - } - } - } - SLIST_FOREACH(ol, &otab, o_next) - do_option(ol->o_name); - SLIST_FOREACH(op, &opt, op_next) { - if (!op->op_ownfile && strncmp(op->op_name, "DEV_", 4)) { - fprintf(stderr, "%s: unknown option \"%s\"\n", - PREFIX, op->op_name); - exit(1); - } - } -} - -/* - * Generate an .h file - */ - -static void -do_option(char *name) -{ - char *file, *inw; - const char *basefile; - struct opt_list *ol; - struct opt *op; - struct opt_head op_head; - FILE *inf, *outf; - char *value; - char *oldvalue; - int seen; - int tidy; - - file = tooption(name); - /* - * Check to see if the option was specified.. - */ - value = NULL; - SLIST_FOREACH(op, &opt, op_next) { - if (eq(name, op->op_name)) { - oldvalue = value; - value = op->op_value; - if (value == NULL) - value = ns("1"); - if (oldvalue != NULL && !eq(value, oldvalue)) - fprintf(stderr, - "%s: option \"%s\" redefined from %s to %s\n", - PREFIX, op->op_name, oldvalue, - value); - op->op_ownfile++; - } - } - - remember(file); - inf = fopen(file, "r"); - if (inf == 0) { - outf = fopen(file, "w"); - if (outf == 0) - err(1, "%s", file); - - /* was the option in the config file? */ - if (value) { - fprintf(outf, "#define %s %s\n", name, value); - } /* else empty file */ - - (void)fclose(outf); - return; - } - basefile = ""; - SLIST_FOREACH(ol, &otab, o_next) - if (eq(name, ol->o_name)) { - basefile = ol->o_file; - break; - } - oldvalue = NULL; - SLIST_INIT(&op_head); - seen = 0; - tidy = 0; - for (;;) { - char *cp; - char *invalue; - - /* get the #define */ - if ((inw = get_word(inf)) == 0 || inw == (char *)EOF) - break; - /* get the option name */ - if ((inw = get_word(inf)) == 0 || inw == (char *)EOF) - break; - inw = ns(inw); - /* get the option value */ - if ((cp = get_word(inf)) == 0 || cp == (char *)EOF) - break; - /* option value */ - invalue = ns(cp); /* malloced */ - if (eq(inw, name)) { - oldvalue = invalue; - invalue = value; - seen++; - } - SLIST_FOREACH(ol, &otab, o_next) - if (eq(inw, ol->o_name)) - break; - if (!eq(inw, name) && !ol) { - fprintf(stderr, - "WARNING: unknown option `%s' removed from %s\n", - inw, file); - tidy++; - } else if (ol != NULL && !eq(basefile, ol->o_file)) { - fprintf(stderr, - "WARNING: option `%s' moved from %s to %s\n", - inw, basefile, ol->o_file); - tidy++; - } else { - op = (struct opt *) calloc(1, sizeof *op); - if (op == NULL) - err(EXIT_FAILURE, "calloc"); - op->op_name = inw; - op->op_value = invalue; - SLIST_INSERT_HEAD(&op_head, op, op_next); - } - - /* EOL? */ - cp = get_word(inf); - if (cp == (char *)EOF) - break; - } - (void)fclose(inf); - if (!tidy && ((value == NULL && oldvalue == NULL) || - (value && oldvalue && eq(value, oldvalue)))) { - while (!SLIST_EMPTY(&op_head)) { - op = SLIST_FIRST(&op_head); - SLIST_REMOVE_HEAD(&op_head, op_next); - free(op->op_name); - free(op->op_value); - free(op); - } - return; - } - - if (value && !seen) { - /* New option appears */ - op = (struct opt *) calloc(1, sizeof *op); - if (op == NULL) - err(EXIT_FAILURE, "calloc"); - op->op_name = ns(name); - op->op_value = value ? ns(value) : NULL; - SLIST_INSERT_HEAD(&op_head, op, op_next); - } - - outf = fopen(file, "w"); - if (outf == 0) - err(1, "%s", file); - while (!SLIST_EMPTY(&op_head)) { - op = SLIST_FIRST(&op_head); - /* was the option in the config file? */ - if (op->op_value) { - fprintf(outf, "#define %s %s\n", - op->op_name, op->op_value); - } - SLIST_REMOVE_HEAD(&op_head, op_next); - free(op->op_name); - free(op->op_value); - free(op); - } - (void)fclose(outf); -} - -/* - * Find the filename to store the option spec into. - */ -static char * -tooption(char *name) -{ - static char hbuf[MAXPATHLEN]; - char nbuf[MAXPATHLEN]; - struct opt_list *po; - - /* "cannot happen"? the otab list should be complete.. */ - (void)strlcpy(nbuf, "options.h", sizeof(nbuf)); - - SLIST_FOREACH(po, &otab, o_next) { - if (eq(po->o_name, name)) { - strlcpy(nbuf, po->o_file, sizeof(nbuf)); - break; - } - } - - (void)strlcpy(hbuf, path(nbuf), sizeof(hbuf)); - return (hbuf); -} - - -static void -check_duplicate(const char *fname, const char *this) -{ - struct opt_list *po; - - SLIST_FOREACH(po, &otab, o_next) { - if (eq(po->o_name, this)) { - fprintf(stderr, "%s: Duplicate option %s.\n", - fname, this); - exit(1); - } - } -} - -static void -insert_option(const char *fname, char *this, char *val) -{ - struct opt_list *po; - - check_duplicate(fname, this); - po = (struct opt_list *) calloc(1, sizeof *po); - if (po == NULL) - err(EXIT_FAILURE, "calloc"); - po->o_name = this; - po->o_file = val; - po->o_flags = 0; - SLIST_INSERT_HEAD(&otab, po, o_next); -} - -static void -update_option(const char *this, char *val, int flags) -{ - struct opt_list *po; - - SLIST_FOREACH(po, &otab, o_next) { - if (eq(po->o_name, this)) { - free(po->o_file); - po->o_file = val; - po->o_flags = flags; - return; - } - } - /* - * Option not found, but that's OK, we just ignore it since it - * may be for another arch. - */ - return; -} - -static int -read_option_file(const char *fname, int flags) -{ - FILE *fp; - char *wd, *this, *val; - char genopt[MAXPATHLEN]; - - fp = fopen(fname, "r"); - if (fp == 0) - return (0); - while ((wd = get_word(fp)) != (char *)EOF) { - if (wd == 0) - continue; - if (wd[0] == '#') { - while (((wd = get_word(fp)) != (char *)EOF) && wd) - continue; - continue; - } - this = ns(wd); - val = get_word(fp); - if (val == (char *)EOF) - return (1); - if (val == 0) { - if (flags) { - fprintf(stderr, "%s: compat file requires two" - " words per line at %s\n", fname, this); - exit(1); - } - char *s = ns(this); - (void)snprintf(genopt, sizeof(genopt), "opt_%s.h", - lower(s)); - val = genopt; - free(s); - } - val = ns(val); - if (flags == 0) - insert_option(fname, this, val); - else - update_option(this, val, flags); - } - (void)fclose(fp); - return (1); -} - -/* - * read the options and options. files - */ -static void -read_options(void) -{ - char fname[MAXPATHLEN]; - - SLIST_INIT(&otab); - read_option_file("../../conf/options", 0); - (void)snprintf(fname, sizeof fname, "../../conf/options.%s", - machinename); - if (!read_option_file(fname, 0)) { - (void)snprintf(fname, sizeof fname, "options.%s", machinename); - read_option_file(fname, 0); - } - read_option_file("../../conf/options-compat", OL_ALIAS); -} - -static char * -lower(char *str) -{ - char *cp = str; - - while (*str) { - if (isupper(*str)) - *str = tolower(*str); - str++; - } - return (cp); -} diff --git a/usr.sbin/cpucontrol/Makefile b/usr.sbin/cpucontrol/Makefile deleted file mode 100644 index a048dd7..0000000 --- a/usr.sbin/cpucontrol/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -# $FreeBSD$ - -PROG= cpucontrol -MAN= cpucontrol.8 -SRCS= cpucontrol.c intel.c amd.c - -.include diff --git a/usr.sbin/cpucontrol/amd.c b/usr.sbin/cpucontrol/amd.c deleted file mode 100644 index be0e0de..0000000 --- a/usr.sbin/cpucontrol/amd.c +++ /dev/null @@ -1,181 +0,0 @@ -/*- - * Copyright (c) 2006, 2008 Stanislav Sedov . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "cpucontrol.h" -#include "amd.h" - -int -amd_probe(int fd) -{ - char vendor[13]; - int error; - cpuctl_cpuid_args_t idargs = { - .level = 0, - }; - - error = ioctl(fd, CPUCTL_CPUID, &idargs); - if (error < 0) { - WARN(0, "ioctl()"); - return (1); - } - ((uint32_t *)vendor)[0] = idargs.data[1]; - ((uint32_t *)vendor)[1] = idargs.data[3]; - ((uint32_t *)vendor)[2] = idargs.data[2]; - vendor[12] = '\0'; - if (strncmp(vendor, AMD_VENDOR_ID, sizeof(AMD_VENDOR_ID)) != 0) - return (1); - return (0); -} - -void -amd_update(const char *dev, const char *path) -{ - int fd, devfd; - unsigned int i; - struct stat st; - uint32_t *fw_image; - amd_fw_header_t *fw_header; - uint32_t sum; - uint32_t signature; - uint32_t *fw_data; - size_t fw_size; - cpuctl_cpuid_args_t idargs = { - .level = 1, /* Request signature. */ - }; - cpuctl_update_args_t args; - int error; - - assert(path); - assert(dev); - - fd = -1; - fw_image = MAP_FAILED; - devfd = open(dev, O_RDWR); - if (devfd < 0) { - WARN(0, "could not open %s for writing", dev); - return; - } - error = ioctl(devfd, CPUCTL_CPUID, &idargs); - if (error < 0) { - WARN(0, "ioctl()"); - goto fail; - } - signature = idargs.data[0]; - WARNX(2, "found cpu family %#x model %#x " - "stepping %#x extfamily %#x extmodel %#x.", - (signature >> 8) & 0x0f, (signature >> 4) & 0x0f, - (signature >> 0) & 0x0f, (signature >> 20) & 0xff, - (signature >> 16) & 0x0f); - - /* - * Open the firmware file. - */ - fd = open(path, O_RDONLY, 0); - if (fd < 0) { - WARN(0, "open(%s)", path); - goto fail; - } - error = fstat(fd, &st); - if (error != 0) { - WARN(0, "fstat(%s)", path); - goto fail; - } - if (st.st_size < 0 || (unsigned)st.st_size < sizeof(*fw_header)) { - WARNX(2, "file too short: %s", path); - goto fail; - } - /* - * mmap the whole image. - */ - fw_image = (uint32_t *)mmap(NULL, st.st_size, PROT_READ, - MAP_PRIVATE, fd, 0); - if (fw_image == MAP_FAILED) { - WARN(0, "mmap(%s)", path); - goto fail; - } - fw_header = (amd_fw_header_t *)fw_image; - if ((fw_header->magic >> 8) != AMD_MAGIC) { - WARNX(2, "%s is not a valid amd firmware: version mismatch", - path); - goto fail; - } - fw_data = (uint32_t *)(fw_header + 1); - fw_size = (st.st_size - sizeof(*fw_header)) / sizeof(uint32_t); - - /* - * Check the primary checksum. - */ - sum = 0; - for (i = 0; i < fw_size; i++) - sum += fw_data[i]; - if (sum != fw_header->checksum) { - WARNX(2, "%s: update data checksum invalid", path); - goto fail; - } - if (signature == fw_header->signature) { - fprintf(stderr, "%s: updating cpu %s... ", path, dev); - - args.data = fw_image; - args.size = st.st_size; - error = ioctl(fd, CPUCTL_UPDATE, &args); - if (error < 0) { - fprintf(stderr, "failed.\n"); - warn("ioctl()"); - goto fail; - } - fprintf(stderr, "done.\n"); - } - -fail: - if (fd >= 0) - close(fd); - if (devfd >= 0) - close(devfd); - if (fw_image != MAP_FAILED) - if(munmap(fw_image, st.st_size) != 0) - warn("munmap(%s)", path); - return; -} diff --git a/usr.sbin/cpucontrol/amd.h b/usr.sbin/cpucontrol/amd.h deleted file mode 100644 index cf109c2..0000000 --- a/usr.sbin/cpucontrol/amd.h +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * Copyright (c) 2006, 2008 Stanislav Sedov . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef AMD_H -#define AMD_H - -/* - * Prototypes. - */ -ucode_probe_t amd_probe; -ucode_update_t amd_update; - -typedef struct amd_fw_header { - uint32_t date; /* Update creation date. */ - uint32_t xz0[2]; - uint32_t checksum; /* ucode checksum. */ - uint32_t xz1[2]; - uint32_t signature; /* Low byte of cpuid(0). */ - uint32_t magic; /* 0x0Xaaaaaa */ - uint32_t xz2[8]; -} amd_fw_header_t; - -#define AMD_MAGIC 0xaaaaaa - -#endif /* !AMD_H */ diff --git a/usr.sbin/cpucontrol/cpucontrol.8 b/usr.sbin/cpucontrol/cpucontrol.8 deleted file mode 100644 index 62221c3..0000000 --- a/usr.sbin/cpucontrol/cpucontrol.8 +++ /dev/null @@ -1,173 +0,0 @@ -.\" Copyright (c) 2006, 2008 Stanislav Sedov . -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd June 30, 2009 -.Dt CPUCONTROL 8 -.Os -.Sh NAME -.Nm cpucontrol -.Nd control utility for the -.Xr cpuctl 4 -device. -.Sh SYNOPSIS -.Nm -.Op Fl vh -.Fl m Ar msr -.Bk -.Ar device -.Ek -.Nm -.Op Fl vh -.Fl m Ar msr Ns = Ns Ar value -.Bk -.Ar device -.Ek -.Nm -.Op Fl vh -.Fl m Ar msr Ns &= Ns Ar mask -.Bk -.Ar device -.Ek -.Nm -.Op Fl vh -.Fl m Ar msr Ns |= Ns Ar mask -.Bk -.Ar device -.Ek -.Nm -.Op Fl vh -.Fl i Ar level -.Bk -.Ar device -.Ek -.Nm -.Op Fl vh -.Op Fl d Ar datadir -.Fl u -.Bk -.Ar device -.Ek -.Sh DESCRIPTION -The -.Nm -utility can be used to read and write arbitrary machine-specific -CPU registers via the -.Xr cpuctl 4 -special device. -It can also be used to apply CPU firmware updates. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl d Ar datadir -Where to look for microcode images. -The option can be specified multiple times. -.It Fl m Ar msr Ns Op = Ns Ar value -Show value of the specified MSR. -MSR register number should be given as a hexadecimal number. -.It Fl m Ar msr Ns = Ns Ar value -Store the -.Ar value -in the specified MSR register. -The -.Ar value -argument can be prefixed with ~ operator. -In this case the inverted value of argument will be stored in the register. -.It Fl m Ar msr Ns &= Ns Ar mask -Store the result of bitwise AND operation between -.Ar mask -and the current MSR value in the MSR register. -The -.Ar mask -argument can be prefixed with ~ operator. -In this case the inverted value of mask will be used. -.It Fl m Ar msr Ns |= Ns Ar mask -Store the result of bitwise OR operation between -.Ar mask -and the current MSR value in the MSR register. -The -.Ar mask -argument can be prefixed with ~ operator. -In this case the inverted value of mask will be used. -.It Fl i Ar level -Retrieve CPUID info. -Level should be given as a hex number. -.It Fl u -Apply CPU firmware updates. -The -.Nm -utility will walk through the configured data directories -and apply all firmware updates available for this CPU. -.It Fl v -Increase the verbosity level. -.It Fl h -Show help message. -.El -.Sh EXIT STATUS -.Ex -std -.Sh EXAMPLES -The command -.Pp -.Dq Li "cpucontrol -m 0x10 /dev/cpuctl0" -.Pp -will read the contents of TSC MSR from CPU 0. -.Pp -To set the CPU 0 TSC MSR register value to 0x1 issue -.Pp -.Dq Li "cpucontrol -m 0x10=0x1 /dev/cpuctl0" . -.Pp -The following command will clear the second bit of TSC register: -.Pp -.Dq Li "cpucontrol -m 0x10&=~0x02 /dev/cpuctl0" . -.Pp -The following command will set the forth and second bit of TSC register: -.Pp -.Dq Li "cpucontrol -m 0x10|=0x0a /dev/cpuctl0" . -.Pp -The command -.Pp -.Dq Li "cpucontrol -i 0x1 /dev/cpuctl1" -.Pp -will retrieve the CPUID level 0x1 from CPU 1. -.Pp -To perform firmware updates on CPU 0 from images located at -.Pa /usr/local/share/cpuctl/ -use the following command: -.Pp -.Dq Li "cpucontrol -d /usr/local/share/cpuctl/ -u /dev/cpuctl0" -.Sh SEE ALSO -.Xr cpuctl 4 -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 7.2 . -.Sh AUTHORS -The -.Nm -utility and this manual page was written by -.An Stanislav Sedov Aq stas@FreeBSD.org . -.Sh BUGS -Yes, probably, report if any. diff --git a/usr.sbin/cpucontrol/cpucontrol.c b/usr.sbin/cpucontrol/cpucontrol.c deleted file mode 100644 index 7193080..0000000 --- a/usr.sbin/cpucontrol/cpucontrol.c +++ /dev/null @@ -1,423 +0,0 @@ -/*- - * Copyright (c) 2008 Stanislav Sedov . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* - * This utility provides userland access to the cpuctl(4) pseudo-device - * features. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "cpucontrol.h" -#include "amd.h" -#include "intel.h" - -int verbosity_level = 0; - -#define DEFAULT_DATADIR "/usr/local/share/cpucontrol" - -#define FLAG_I 0x01 -#define FLAG_M 0x02 -#define FLAG_U 0x04 - -#define OP_INVAL 0x00 -#define OP_READ 0x01 -#define OP_WRITE 0x02 -#define OP_OR 0x04 -#define OP_AND 0x08 - -#define HIGH(val) (uint32_t)(((val) >> 32) & 0xffffffff) -#define LOW(val) (uint32_t)((val) & 0xffffffff) - -/* - * Macros for freeing SLISTs, probably must be in /sys/queue.h - */ -#define SLIST_FREE(head, field, freef) do { \ - typeof(SLIST_FIRST(head)) __elm0; \ - typeof(SLIST_FIRST(head)) __elm; \ - SLIST_FOREACH_SAFE(__elm, (head), field, __elm0) \ - (void)(freef)(__elm); \ -} while(0); - -struct datadir { - const char *path; - SLIST_ENTRY(datadir) next; -}; -static SLIST_HEAD(, datadir) datadirs = SLIST_HEAD_INITIALIZER(datadirs); - -struct ucode_handler { - ucode_probe_t *probe; - ucode_update_t *update; -} handlers[] = { - { intel_probe, intel_update }, - { amd_probe, amd_update }, -}; -#define NHANDLERS (sizeof(handlers) / sizeof(*handlers)) - -static void usage(void); -static int isdir(const char *path); -static int do_cpuid(const char *cmdarg, const char *dev); -static int do_msr(const char *cmdarg, const char *dev); -static int do_update(const char *dev); -static void datadir_add(const char *path); - -static void __dead2 -usage(void) -{ - const char *name; - - name = getprogname(); - if (name == NULL) - name = "cpuctl"; - fprintf(stderr, "Usage: %s [-vh] [-d datadir] [-m msr[=value] | " - "-i level | -u] device\n", name); - exit(EX_USAGE); -} - -static int -isdir(const char *path) -{ - int error; - struct stat st; - - error = stat(path, &st); - if (error < 0) { - WARN(0, "stat(%s)", path); - return (error); - } - return (st.st_mode & S_IFDIR); -} - -static int -do_cpuid(const char *cmdarg, const char *dev) -{ - unsigned int level; - cpuctl_cpuid_args_t args; - int fd, error; - char *endptr; - - assert(cmdarg != NULL); - assert(dev != NULL); - - level = strtoul(cmdarg, &endptr, 16); - if (*cmdarg == '\0' || *endptr != '\0') { - WARNX(0, "incorrect operand: %s", cmdarg); - usage(); - /* NOTREACHED */ - } - - /* - * Fill ioctl argument structure. - */ - args.level = level; - fd = open(dev, O_RDONLY); - if (fd < 0) { - WARN(0, "error opening %s for reading", dev); - return (1); - } - error = ioctl(fd, CPUCTL_CPUID, &args); - if (error < 0) { - WARN(0, "ioctl(%s, CPUCTL_CPUID)", dev); - close(fd); - return (error); - } - fprintf(stdout, "cpuid level 0x%x: 0x%.8x 0x%.8x 0x%.8x 0x%.8x\n", - level, args.data[0], args.data[1], args.data[2], args.data[3]); - close(fd); - return (0); -} - -static int -do_msr(const char *cmdarg, const char *dev) -{ - unsigned int msr; - cpuctl_msr_args_t args; - size_t len; - uint64_t data = 0; - unsigned long command; - int do_invert = 0, op; - int fd, error; - char *endptr; - char *p; - - assert(cmdarg != NULL); - assert(dev != NULL); - len = strlen(cmdarg); - if (len == 0) { - WARNX(0, "MSR register expected"); - usage(); - /* NOTREACHED */ - } - - /* - * Parse command string. - */ - msr = strtoul(cmdarg, &endptr, 16); - switch (*endptr) { - case '\0': - op = OP_READ; - break; - case '=': - op = OP_WRITE; - break; - case '&': - op = OP_AND; - endptr++; - break; - case '|': - op = OP_OR; - endptr++; - break; - default: - op = OP_INVAL; - } - if (op != OP_READ) { /* Complex operation. */ - if (*endptr != '=') - op = OP_INVAL; - else { - p = ++endptr; - if (*p == '~') { - do_invert = 1; - p++; - } - data = strtoull(p, &endptr, 16); - if (*p == '\0' || *endptr != '\0') { - WARNX(0, "argument required: %s", cmdarg); - usage(); - /* NOTREACHED */ - } - } - } - if (op == OP_INVAL) { - WARNX(0, "invalid operator: %s", cmdarg); - usage(); - /* NOTREACHED */ - } - - /* - * Fill ioctl argument structure. - */ - args.msr = msr; - if ((do_invert != 0) ^ (op == OP_AND)) - args.data = ~data; - else - args.data = data; - switch (op) { - case OP_READ: - command = CPUCTL_RDMSR; - break; - case OP_WRITE: - command = CPUCTL_WRMSR; - break; - case OP_OR: - command = CPUCTL_MSRSBIT; - break; - case OP_AND: - command = CPUCTL_MSRCBIT; - break; - default: - abort(); - } - fd = open(dev, op == OP_READ ? O_RDONLY : O_WRONLY); - if (fd < 0) { - WARN(0, "error opening %s for %s", dev, - op == OP_READ ? "reading" : "writing"); - return (1); - } - error = ioctl(fd, command, &args); - if (error < 0) { - WARN(0, "ioctl(%s, %lu)", dev, command); - close(fd); - return (1); - } - if (op == OP_READ) - fprintf(stdout, "MSR 0x%x: 0x%.8x 0x%.8x\n", msr, - HIGH(args.data), LOW(args.data)); - close(fd); - return (0); -} - -static int -do_update(const char *dev) -{ - int fd; - unsigned int i; - int error; - struct ucode_handler *handler; - struct datadir *dir; - DIR *dirfd; - struct dirent *direntry; - char buf[MAXPATHLEN]; - - fd = open(dev, O_RDONLY); - if (fd < 0) { - WARN(0, "error opening %s for reading", dev); - return (1); - } - - /* - * Find the appropriate handler for device. - */ - for (i = 0; i < NHANDLERS; i++) - if (handlers[i].probe(fd) == 0) - break; - if (i < NHANDLERS) - handler = &handlers[i]; - else { - WARNX(0, "cannot find the appropriate handler for device"); - close(fd); - return (1); - } - close(fd); - - /* - * Process every image in specified data directories. - */ - SLIST_FOREACH(dir, &datadirs, next) { - dirfd = opendir(dir->path); - if (dirfd == NULL) { - WARNX(1, "skipping directory %s: not accessible", dir->path); - continue; - } - while ((direntry = readdir(dirfd)) != NULL) { - if (direntry->d_namlen == 0) - continue; - error = snprintf(buf, sizeof(buf), "%s/%s", dir->path, - direntry->d_name); - if ((unsigned)error >= sizeof(buf)) - WARNX(0, "skipping %s, buffer too short", - direntry->d_name); - if (isdir(buf) != 0) { - WARNX(2, "skipping %s: is a directory", buf); - continue; - } - handler->update(dev, buf); - } - error = closedir(dirfd); - if (error != 0) - WARN(0, "closedir(%s)", dir->path); - } - return (0); -} - -/* - * Add new data directory to the search list. - */ -static void -datadir_add(const char *path) -{ - struct datadir *newdir; - - newdir = (struct datadir *)malloc(sizeof(*newdir)); - if (newdir == NULL) - err(EX_OSERR, "cannot allocate memory"); - newdir->path = path; - SLIST_INSERT_HEAD(&datadirs, newdir, next); -} - -int -main(int argc, char *argv[]) -{ - int c, flags; - const char *cmdarg; - const char *dev; - int error; - - flags = 0; - error = 0; - cmdarg = ""; /* To keep gcc3 happy. */ - - /* - * Add all default data dirs to the list first. - */ - datadir_add(DEFAULT_DATADIR); - while ((c = getopt(argc, argv, "d:hi:m:uv")) != -1) { - switch (c) { - case 'd': - datadir_add(optarg); - break; - case 'i': - flags |= FLAG_I; - cmdarg = optarg; - break; - case 'm': - flags |= FLAG_M; - cmdarg = optarg; - break; - case 'u': - flags |= FLAG_U; - break; - case 'v': - verbosity_level++; - break; - case 'h': - /* FALLTHROUGH */ - default: - usage(); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - if (argc < 1) { - usage(); - /* NOTREACHED */ - } - dev = argv[0]; - c = flags & (FLAG_I | FLAG_M | FLAG_U); - switch (c) { - case FLAG_I: - error = do_cpuid(cmdarg, dev); - break; - case FLAG_M: - error = do_msr(cmdarg, dev); - break; - case FLAG_U: - error = do_update(dev); - break; - default: - usage(); /* Only one command can be selected. */ - } - SLIST_FREE(&datadirs, next, free); - return (error); -} diff --git a/usr.sbin/cpucontrol/cpucontrol.h b/usr.sbin/cpucontrol/cpucontrol.h deleted file mode 100644 index 63d3995..0000000 --- a/usr.sbin/cpucontrol/cpucontrol.h +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * Copyright (c) 2008 Stanislav Sedov . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef CPUCONTROL_H -#define CPUCONTROL_H - -typedef int ucode_probe_t(int fd); -typedef void ucode_update_t(const char *dev, const char *image); - -extern int verbosity_level; - -#ifdef DEBUG -# define WARNX(level, ...) \ - if ((level) <= verbosity_level) { \ - fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \ - warnx(__VA_ARGS__); \ - } -# define WARN(level, ...) \ - if ((level) <= verbosity_level) { \ - fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \ - warn(__VA_ARGS__); \ - } -#else -# define WARNX(level, ...) \ - if ((level) <= verbosity_level) \ - warnx(__VA_ARGS__); -# define WARN(level, ...) \ - if ((level) <= verbosity_level) \ - warn(__VA_ARGS__); -#endif - -#endif /* !CPUCONTROL_H */ diff --git a/usr.sbin/cpucontrol/intel.c b/usr.sbin/cpucontrol/intel.c deleted file mode 100644 index 15ac939..0000000 --- a/usr.sbin/cpucontrol/intel.c +++ /dev/null @@ -1,284 +0,0 @@ -/*- - * Copyright (c) 2006, 2008 Stanislav Sedov . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "cpucontrol.h" -#include "intel.h" - -#define DEFAULT_UCODE_SIZE 2000 /* Size of update data if not specified. */ - -int -intel_probe(int fd) -{ - char vendor[13]; - int error; - cpuctl_cpuid_args_t idargs = { - .level = 0, - }; - - error = ioctl(fd, CPUCTL_CPUID, &idargs); - if (error < 0) { - WARN(0, "ioctl()"); - return (1); - } - ((uint32_t *)vendor)[0] = idargs.data[1]; - ((uint32_t *)vendor)[1] = idargs.data[3]; - ((uint32_t *)vendor)[2] = idargs.data[2]; - vendor[12] = '\0'; - if (strncmp(vendor, INTEL_VENDOR_ID, sizeof(INTEL_VENDOR_ID)) != 0) - return (1); - return (0); -} - -void -intel_update(const char *dev, const char *path) -{ - int fd, devfd; - struct stat st; - uint32_t *fw_image; - int have_ext_table; - uint32_t sum; - unsigned int i; - size_t payload_size; - intel_fw_header_t *fw_header; - intel_cpu_signature_t *ext_table; - intel_ext_header_t *ext_header; - uint32_t signature, flags; - int32_t revision; - ssize_t ext_size; - size_t ext_table_size; - void *fw_data; - size_t data_size, total_size; - cpuctl_msr_args_t msrargs = { - .msr = MSR_IA32_PLATFORM_ID, - }; - cpuctl_cpuid_args_t idargs = { - .level = 1, /* Signature. */ - }; - cpuctl_update_args_t args; - int error; - - assert(path); - assert(dev); - - fd = -1; - fw_image = MAP_FAILED; - ext_table = NULL; - ext_header = NULL; - devfd = open(dev, O_RDWR); - if (devfd < 0) { - WARN(0, "could not open %s for writing", dev); - return; - } - error = ioctl(devfd, CPUCTL_CPUID, &idargs); - if (error < 0) { - WARN(0, "ioctl(%s)", dev); - goto fail; - } - signature = idargs.data[0]; - error = ioctl(devfd, CPUCTL_RDMSR, &msrargs); - if (error < 0) { - WARN(0, "ioctl(%s)", dev); - goto fail; - } - - /* - * MSR_IA32_PLATFORM_ID contains flag in BCD in bits 52-50. - */ - flags = 1 << ((msrargs.data >> 50) & 7); - msrargs.msr = MSR_BIOS_SIGN; - error = ioctl(devfd, CPUCTL_RDMSR, &msrargs); - if (error < 0) { - WARN(0, "ioctl(%s)", dev); - goto fail; - } - revision = msrargs.data >> 32; /* Revision in the high dword. */ - WARNX(2, "found cpu type %#x family %#x model %#x stepping %#x.", - (signature >> 12) & 0x03, (signature >> 8) & 0x0f, - (signature >> 4) & 0x0f, (signature >> 0) & 0x0f); - /* - * Open firmware image. - */ - fd = open(path, O_RDONLY, 0); - if (fd < 0) { - WARN(0, "open(%s)", path); - return; - } - error = fstat(fd, &st); - if (error != 0) { - WARN(0, "fstat(%s)", path); - goto fail; - } - if (st.st_size < 0 || (unsigned)st.st_size < sizeof(*fw_header)) { - WARNX(2, "file too short: %s", path); - goto fail; - } - - /* - * mmap the whole image. - */ - fw_image = (uint32_t *)mmap(NULL, st.st_size, PROT_READ, - MAP_PRIVATE, fd, 0); - if (fw_image == MAP_FAILED) { - WARN(0, "mmap(%s)", path); - goto fail; - } - fw_header = (intel_fw_header_t *)fw_image; - if (fw_header->header_version != INTEL_HEADER_VERSION || - fw_header->loader_revision != INTEL_LOADER_REVISION) { - WARNX(2, "%s is not a valid intel firmware: version mismatch", - path); - goto fail; - } - /* - * According to spec, if data_size == 0, then size of ucode = 2000. - */ - if (fw_header->data_size == 0) - data_size = DEFAULT_UCODE_SIZE; - else - data_size = fw_header->data_size; - if (fw_header->total_size == 0) - total_size = data_size + sizeof(*fw_header); - else - total_size = fw_header->total_size; - if (total_size > (unsigned)st.st_size || st.st_size < 0) { - WARNX(2, "file too short: %s", path); - goto fail; - } - payload_size = data_size + sizeof(*fw_header); - - /* - * Check the primary checksum. - */ - sum = 0; - for (i = 0; i < (payload_size / sizeof(uint32_t)); i++) - sum += *((uint32_t *)fw_image + i); - if (sum != 0) { - WARNX(2, "%s: update data checksum invalid", path); - goto fail; - } - - /* - * Check if there is an extended signature table. - */ - ext_size = total_size - payload_size; - have_ext_table = 0; - - if (ext_size > (signed)sizeof(*ext_header)) { - ext_header = - (intel_ext_header_t *)((char *)fw_image + payload_size); - ext_table = (intel_cpu_signature_t *)(ext_header + 1); - - /* - * Check the extended table size. - */ - ext_table_size = sizeof(*ext_header) + - ext_header->sig_count * sizeof(*ext_table); - if (ext_table_size + payload_size > total_size) { - WARNX(2, "%s: broken extended signature table", path); - goto no_table; - } - - /* - * Check the extended table signature. - */ - sum = 0; - for (i = 0; i < (ext_table_size / sizeof(uint32_t)); i++) - sum += *((uint32_t *)ext_header + i); - if (sum != 0) { - WARNX(2, "%s: extended signature table checksum invalid", - path); - goto no_table; - } - have_ext_table = 1; - } - -no_table: - fw_data = fw_header + 1; /* Pointer to the update data. */ - - /* - * Check if the given image is ok for this cpu. - */ - if (signature == fw_header->cpu_signature && - (flags & fw_header->cpu_flags) != 0) - goto matched; - else if (have_ext_table != 0) { - for (i = 0; i < ext_header->sig_count; i++) { - uint32_t sig = ext_table[i].cpu_signature; - if (signature == sig && - (flags & ext_table[i].cpu_flags) != 0) - goto matched; - } - } else - goto fail; - -matched: - if (revision >= fw_header->revision) { - WARNX(1, "skipping %s of rev %#x: up to date", - path, fw_header->revision); - return; - } - fprintf(stderr, "%s: updating cpu %s from rev %#x to rev %#x... ", - path, dev, revision, fw_header->revision); - args.data = fw_data; - args.size = data_size; - error = ioctl(devfd, CPUCTL_UPDATE, &args); - if (error < 0) { - fprintf(stderr, "failed.\n"); - WARN(0, "ioctl()"); - goto fail; - } - fprintf(stderr, "done.\n"); - -fail: - if (fw_image != MAP_FAILED) - if (munmap(fw_image, st.st_size) != 0) - warn("munmap(%s)", path); - if (devfd >= 0) - close(devfd); - if (fd >= 0) - close(fd); - return; -} diff --git a/usr.sbin/cpucontrol/intel.h b/usr.sbin/cpucontrol/intel.h deleted file mode 100644 index 0303e69..0000000 --- a/usr.sbin/cpucontrol/intel.h +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * Copyright (c) 2006, 2008 Stanislav Sedov . - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef INTEL_H -#define INTEL_H - -/* - * Prototypes. - */ -ucode_probe_t intel_probe; -ucode_update_t intel_update; - -typedef struct intel_fw_header { - uint32_t header_version; /* Version of the header. */ - int32_t revision; /* Unique version number. */ - uint32_t date; /* Date of creation in BCD. */ - uint32_t cpu_signature; /* Extended family, extended - model, type, family, model - and stepping. */ - uint32_t checksum; /* Sum of all DWORDS should - be 0. */ - uint32_t loader_revision; /* Version of the loader - required to load update. */ - uint32_t cpu_flags; /* Platform IDs encoded in - the lower 8 bits. */ - uint32_t data_size; - uint32_t total_size; - uint8_t reserved[12]; -} intel_fw_header_t; - -typedef struct intel_cpu_signature { - uint32_t cpu_signature; - uint32_t cpu_flags; - uint32_t checksum; -} intel_cpu_signature_t; - -typedef struct intel_ext_header { - uint32_t sig_count; - uint32_t checksum; - uint8_t reserved[12]; -} intel_ext_header_t; - -#define INTEL_HEADER_VERSION 0x00000001 -#define INTEL_LOADER_REVISION 0x00000001 - -#endif /* !INTEL_H */ diff --git a/usr.sbin/crashinfo/Makefile b/usr.sbin/crashinfo/Makefile deleted file mode 100644 index fa2a19c..0000000 --- a/usr.sbin/crashinfo/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -SCRIPTS= crashinfo.sh -MAN= crashinfo.8 - -.include diff --git a/usr.sbin/crashinfo/crashinfo.8 b/usr.sbin/crashinfo/crashinfo.8 deleted file mode 100644 index 897fc59..0000000 --- a/usr.sbin/crashinfo/crashinfo.8 +++ /dev/null @@ -1,109 +0,0 @@ -.\" Copyright (c) 2008 Yahoo!, Inc. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the author nor the names of any co-contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd June 28, 2008 -.Dt CRASHINFO 8 -.Os -.Sh NAME -.Nm crashinfo -.Nd "analyze a core dump of the operating system" -.Sh SYNOPSIS -.Nm -.Op Fl d Ar crashdir -.Op Fl n Ar dumpnr -.Op Fl k Ar kernel -.Op Ar core -.Sh DESCRIPTION -The -.Nm -utility analyzes a core dump saved by -.Xr savecore 8 . -It generates a text file containing the analysis in the same directory as -the core dump. -For a given core dump file named -.Pa vmcore.XX -the generated text file will be named -.Pa core.txt.XX . -.Pp -By default, -.Nm -analyzes the most recent core dump in the core dump directory. -A specific core dump may be specified via either the -.Ar core -or -.Ar dumpnr -arguments. -Once -.Nm -has located a core dump, -it analyzes the core dump to determine the exact version of the kernel -that generated the core. -It then looks for a matching kernel file under each of the subdirectories in -.Pa /boot . -The location of the kernel file can also be explicitly provided via the -.Ar kernel -argument. -.Pp -Once -.Nm -has located a core dump and kernel, -it uses several utilities to analyze the core including -.Xr dmesg 8 , -.Xr fstat 1 , -.Xr iostat 8 , -.Xr ipcs 1 , -.Xr kgdb 1 , -.Xr netstat 1 , -.Xr nfsstat 1 , -.Xr ps 1 , -.Xr pstat 8 , -and -.Xr vmstat 8 . -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl d Ar crashdir -Specify an alternate core dump directory. -The default crash dump directory is -.Pa /var/crash . -.It Fl n Ar dumpnr -Use the core dump saved in -.Pa vmcore. Ns Ar dumpnr -instead of the latest core in the core dump directory. -.It Fl k Ar kernel -Specify an explicit kernel file. -.El -.Sh SEE ALSO -.Xr textdump 4 , -.Xr savecore 8 -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 6.4 . diff --git a/usr.sbin/crashinfo/crashinfo.sh b/usr.sbin/crashinfo/crashinfo.sh deleted file mode 100755 index 60f0360..0000000 --- a/usr.sbin/crashinfo/crashinfo.sh +++ /dev/null @@ -1,315 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2008 Yahoo!, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the author nor the names of any co-contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ - -usage() -{ - echo "usage: crashinfo [-d crashdir] [-n dumpnr] [-k kernel] [core]" - exit 1 -} - -find_kernel() -{ - local ivers k kvers - - ivers=$(awk ' - /Version String/ { - print - nextline=1 - next - } - // { - if (nextline) { - print - nextline=0 - } - }' $INFO) - - # Look for a matching kernel version. - for k in /boot/kernel/kernel $(ls -t /boot/*/kernel); do - kvers=$(echo 'printf " Version String: %s", version' | \ - gdb -x /dev/stdin -batch $k 2>/dev/null) - if [ "$ivers" = "$kvers" ]; then - KERNEL=$k - break - fi - done -} - -CRASHDIR=/var/crash -DUMPNR= -KERNEL= - -while getopts "d:n:k:" opt; do - case "$opt" in - d) - CRASHDIR=$OPTARG - ;; - n) - DUMPNR=$OPTARG - ;; - k) - KERNEL=$OPTARG - ;; - \?) - usage - ;; - esac -done - -shift $((OPTIND - 1)) - -if [ $# -eq 1 ]; then - if [ -n "$DUMPNR" ]; then - echo "-n and an explicit vmcore are mutually exclusive" - usage - fi - - # Figure out the crash directory and number from the vmcore name. - CRASHDIR=`dirname $1` - DUMPNR=$(expr $(basename $1) : 'vmcore\.\([0-9]*\)$') - if [ -z "$DUMPNR" ]; then - echo "Unable to determine dump number from vmcore file $1." - exit 1 - fi -elif [ $# -gt 1 ]; then - usage -else - # If we don't have an explicit dump number, operate on the most - # recent dump. - if [ -z "$DUMPNR" ]; then - if ! [ -r $CRASHDIR/bounds ]; then - echo "No crash dumps in $CRASHDIR." - exit 1 - fi - next=`cat $CRASHDIR/bounds` - if [ -z "$next" ] || [ "$next" -eq 0 ]; then - echo "No crash dumps in $CRASHDIR." - exit 1 - fi - DUMPNR=$(($next - 1)) - fi -fi - -VMCORE=$CRASHDIR/vmcore.$DUMPNR -INFO=$CRASHDIR/info.$DUMPNR -FILE=$CRASHDIR/core.txt.$DUMPNR -HOSTNAME=`hostname` - -if [ ! -e $VMCORE ]; then - echo "$VMCORE not found" - exit 1 -fi - -if [ ! -e $INFO ]; then - echo "$INFO not found" - exit 1 -fi - -# If the user didn't specify a kernel, then try to find one. -if [ -z "$KERNEL" ]; then - find_kernel - if [ -z "$KERNEL" ]; then - echo "Unable to find matching kernel for $VMCORE" - exit 1 - fi -elif [ ! -e $KERNEL ]; then - echo "$KERNEL not found" - exit 1 -fi - -echo "Writing crash summary to $FILE." - -umask 077 - -# Simulate uname -ostype=$(echo -e printf '"%s", ostype' | gdb -x /dev/stdin -batch $KERNEL) -osrelease=$(echo -e printf '"%s", osrelease' | gdb -x /dev/stdin -batch $KERNEL) -version=$(echo -e printf '"%s", version' | gdb -x /dev/stdin -batch $KERNEL | \ - tr '\t\n' ' ') -machine=$(echo -e printf '"%s", machine' | gdb -x /dev/stdin -batch $KERNEL) - -exec > $FILE 2>&1 - -echo "$HOSTNAME dumped core - see $VMCORE" -echo -date -echo -echo "$ostype $HOSTNAME $osrelease $version $machine" -echo -sed -ne '/^ Panic String: /{s//panic: /;p;}' $INFO -echo - -# XXX: /bin/sh on 7.0+ is broken so we can't simply pipe the commands to -# kgdb via stdin and have to use a temporary file instead. -file=`mktemp /tmp/crashinfo.XXXXXX` -if [ $? -eq 0 ]; then - echo "bt" >> $file - echo "quit" >> $file - kgdb $KERNEL $VMCORE < $file - rm -f $file - echo -fi -echo - -echo "------------------------------------------------------------------------" -echo "ps -axl" -echo -ps -M $VMCORE -N $KERNEL -axl -echo - -echo "------------------------------------------------------------------------" -echo "vmstat -s" -echo -vmstat -M $VMCORE -N $KERNEL -s -echo - -echo "------------------------------------------------------------------------" -echo "vmstat -m" -echo -vmstat -M $VMCORE -N $KERNEL -m -echo - -echo "------------------------------------------------------------------------" -echo "vmstat -z" -echo -vmstat -M $VMCORE -N $KERNEL -z -echo - -echo "------------------------------------------------------------------------" -echo "vmstat -i" -echo -vmstat -M $VMCORE -N $KERNEL -i -echo - -echo "------------------------------------------------------------------------" -echo "pstat -T" -echo -pstat -M $VMCORE -N $KERNEL -T -echo - -echo "------------------------------------------------------------------------" -echo "pstat -s" -echo -pstat -M $VMCORE -N $KERNEL -s -echo - -echo "------------------------------------------------------------------------" -echo "iostat" -echo -iostat -M $VMCORE -N $KERNEL -echo - -echo "------------------------------------------------------------------------" -echo "ipcs -a" -echo -ipcs -C $VMCORE -N $KERNEL -a -echo - -echo "------------------------------------------------------------------------" -echo "ipcs -T" -echo -ipcs -C $VMCORE -N $KERNEL -T -echo - -# XXX: This doesn't actually work in 5.x+ -if false; then -echo "------------------------------------------------------------------------" -echo "w -dn" -echo -w -M $VMCORE -N $KERNEL -dn -echo -fi - -echo "------------------------------------------------------------------------" -echo "nfsstat" -echo -nfsstat -M $VMCORE -N $KERNEL -echo - -echo "------------------------------------------------------------------------" -echo "netstat -s" -echo -netstat -M $VMCORE -N $KERNEL -s -echo - -echo "------------------------------------------------------------------------" -echo "netstat -m" -echo -netstat -M $VMCORE -N $KERNEL -m -echo - -echo "------------------------------------------------------------------------" -echo "netstat -id" -echo -netstat -M $VMCORE -N $KERNEL -id -echo - -echo "------------------------------------------------------------------------" -echo "netstat -anr" -echo -netstat -M $VMCORE -N $KERNEL -anr -echo - -echo "------------------------------------------------------------------------" -echo "netstat -anA" -echo -netstat -M $VMCORE -N $KERNEL -anA -echo - -echo "------------------------------------------------------------------------" -echo "netstat -aL" -echo -netstat -M $VMCORE -N $KERNEL -aL -echo - -echo "------------------------------------------------------------------------" -echo "fstat" -echo -fstat -M $VMCORE -N $KERNEL -echo - -echo "------------------------------------------------------------------------" -echo "dmesg" -echo -dmesg -a -M $VMCORE -N $KERNEL -echo - -echo "------------------------------------------------------------------------" -echo "kernel config" -echo -config -x $KERNEL - -echo -echo "------------------------------------------------------------------------" -echo "ddb capture buffer" -echo - -ddb capture -M $VMCORE -N $KERNEL print diff --git a/usr.sbin/cron/Makefile b/usr.sbin/cron/Makefile deleted file mode 100644 index 62f853c..0000000 --- a/usr.sbin/cron/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -SUBDIR= lib cron crontab - -.include diff --git a/usr.sbin/cron/Makefile.inc b/usr.sbin/cron/Makefile.inc deleted file mode 100644 index 900730b..0000000 --- a/usr.sbin/cron/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -LIBCRON= ${.OBJDIR}/../lib/libcron.a - -.include "../Makefile.inc" diff --git a/usr.sbin/cron/cron/Makefile b/usr.sbin/cron/cron/Makefile deleted file mode 100644 index d9a1d24..0000000 --- a/usr.sbin/cron/cron/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $FreeBSD$ - -PROG= cron -MAN= cron.8 -SRCS= cron.c database.c do_command.c job.c user.c popen.c - -CFLAGS+= -DLOGIN_CAP -DPAM - -DPADD= ${LIBCRON} ${LIBPAM} ${LIBUTIL} -LDADD= ${LIBCRON} ${MINUSLPAM} -lutil - -WARNS?= 2 - -.include diff --git a/usr.sbin/cron/cron/compat.h b/usr.sbin/cron/cron/compat.h deleted file mode 100644 index 905c3aa..0000000 --- a/usr.sbin/cron/cron/compat.h +++ /dev/null @@ -1,140 +0,0 @@ -/* Copyright 1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -/* - * $FreeBSD$ - */ - -#ifndef __P -# ifdef __STDC__ -# define __P(x) x -# else -# define __P(x) () -# define const -# endif -#endif - -#if defined(UNIXPC) || defined(unixpc) -# define UNIXPC 1 -# define ATT 1 -#endif - -#if defined(hpux) || defined(_hpux) || defined(__hpux) -# define HPUX 1 -# define seteuid(e) setresuid(-1,e,-1) -# define setreuid(r,e) setresuid(r,e,-1) -#endif - -#if defined(_IBMR2) -# define AIX 1 -#endif - -#if defined(__convex__) -# define CONVEX 1 -#endif - -#if defined(sgi) || defined(_sgi) || defined(__sgi) -# define IRIX 1 -/* IRIX 4 hdrs are broken: one cannot #include both - * and because they disagree on system(), perror(). - * Therefore we must zap the "const" keyword BEFORE including - * either of them. - */ -# define const -#endif - -#if defined(_UNICOS) -# define UNICOS 1 -#endif - -#ifndef POSIX -# if (BSD >= 199103) || defined(__linux) || defined(ultrix) || defined(AIX) ||\ - defined(HPUX) || defined(CONVEX) || defined(IRIX) -# define POSIX -# endif -#endif - -#ifndef BSD -# if defined(ultrix) -# define BSD 198902 -# endif -#endif - -/*****************************************************************/ - -#if !defined(BSD) && !defined(HPUX) && !defined(CONVEX) && !defined(__linux) -# define NEED_VFORK -#endif - -#if (!defined(BSD) || (BSD < 198902)) && !defined(__linux) && \ - !defined(IRIX) && !defined(NeXT) && !defined(HPUX) -# define NEED_STRCASECMP -#endif - -#if (!defined(BSD) || (BSD < 198911)) && !defined(__linux) &&\ - !defined(IRIX) && !defined(UNICOS) && !defined(HPUX) -# define NEED_STRDUP -#endif - -#if (!defined(BSD) || (BSD < 198911)) && !defined(POSIX) && !defined(NeXT) -# define NEED_STRERROR -#endif - -#if defined(HPUX) || defined(AIX) || defined(UNIXPC) -# define NEED_FLOCK -#endif - -#ifndef POSIX -# define NEED_SETSID -#endif - -#if (defined(POSIX) && !defined(BSD)) && !defined(__linux) -# define NEED_GETDTABLESIZE -#endif - -#ifdef POSIX -#include -#ifdef _POSIX_SAVED_IDS -# define HAVE_SAVED_UIDS -#endif -#endif - -#if !defined(ATT) && !defined(__linux) && !defined(IRIX) && !defined(UNICOS) -# define USE_SIGCHLD -#endif - -#if !defined(AIX) && !defined(UNICOS) -# define SYS_TIME_H 1 -#else -# define SYS_TIME_H 0 -#endif - -#if defined(BSD) && !defined(POSIX) -# define USE_UTIMES -#endif - -#if defined(AIX) || defined(HPUX) || defined(IRIX) -# define NEED_SETENV -#endif - -#if !defined(UNICOS) && !defined(UNIXPC) -# define HAS_FCHOWN -#endif - -#if !defined(UNICOS) && !defined(UNIXPC) -# define HAS_FCHMOD -#endif diff --git a/usr.sbin/cron/cron/config.h b/usr.sbin/cron/cron/config.h deleted file mode 100644 index 6d77da2..0000000 --- a/usr.sbin/cron/cron/config.h +++ /dev/null @@ -1,87 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -/* config.h - configurables for Vixie Cron - * - * $FreeBSD$ - */ - -#if !defined(_PATH_SENDMAIL) -# define _PATH_SENDMAIL "/usr/lib/sendmail" -#endif /*SENDMAIL*/ - -/* - * these are site-dependent - */ - -#ifndef DEBUGGING -#define DEBUGGING 1 /* 1 or 0 -- do you want debugging code built in? */ -#endif - - /* - * choose one of these MAILCMD commands. I use - * /bin/mail for speed; it makes biff bark but doesn't - * do aliasing. /usr/lib/sendmail does aliasing but is - * a hog for short messages. aliasing is not needed - * if you make use of the MAILTO= feature in crontabs. - * (hint: MAILTO= was added for this reason). - */ - -#define MAILCMD _PATH_SENDMAIL /*-*/ -#define MAILARGS "%s -FCronDaemon -odi -oem -oi -t" /*-*/ - /* -Fx = set full-name of sender - * -odi = Option Deliverymode Interactive - * -oem = Option Errors Mailedtosender - * -oi = Option dot message terminator - * -t = read recipients from header of message - */ - -/* #define MAILCMD "/bin/mail" */ /*-*/ -/* #define MAILARGS "%s -d %s" */ /*-*/ - /* -d = undocumented but common flag: deliver locally? - */ - -/* #define MAILCMD "/usr/mmdf/bin/submit" */ /*-*/ -/* #define MAILARGS "%s -mlrxto %s" */ /*-*/ - -/* #define MAIL_DATE */ /*-*/ - /* should we include an ersatz Date: header in - * generated mail? if you are using sendmail - * for MAILCMD, it is better to let sendmail - * generate the Date: header. - */ - - /* if ALLOW_FILE and DENY_FILE are not defined or are - * defined but neither exists, should crontab(1) be - * usable only by root? - */ -/* #define ALLOW_ONLY_ROOT */ /*-*/ - - /* if you want to use syslog(3) instead of appending - * to CRONDIR/LOG_FILE (/var/cron/log, e.g.), define - * SYSLOG here. Note that quite a bit of logging - * info is written, and that you probably don't want - * to use this on 4.2bsd since everything goes in - * /usr/spool/mqueue/syslog. On 4.[34]bsd you can - * tell /etc/syslog.conf to send cron's logging to - * a separate file. - * - * Note that if this and LOG_FILE in "pathnames.h" - * are both defined, then logging will go to both - * places. - */ -#define SYSLOG /*-*/ diff --git a/usr.sbin/cron/cron/cron.8 b/usr.sbin/cron/cron/cron.8 deleted file mode 100644 index 5d5a8d9..0000000 --- a/usr.sbin/cron/cron/cron.8 +++ /dev/null @@ -1,221 +0,0 @@ -.\"/* Copyright 1988,1990,1993 by Paul Vixie -.\" * All rights reserved -.\" * -.\" * Distribute freely, except: don't remove my name from the source or -.\" * documentation (don't take credit for my work), mark your changes (don't -.\" * get me blamed for your possible bugs), don't alter or remove this -.\" * notice. May be sold if buildable source is provided to buyer. No -.\" * warrantee of any kind, express or implied, is included with this -.\" * software; use at your own risk, responsibility for damages (if any) to -.\" * anyone resulting from the use of this software rests entirely with the -.\" * user. -.\" * -.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and -.\" * I'll try to keep a version up to date. I can be reached as follows: -.\" * Paul Vixie uunet!decwrl!vixie!paul -.\" */ -.\" -.\" $FreeBSD$ -.\" -.Dd June 29, 2008 -.Dt CRON 8 -.Os -.Sh NAME -.Nm cron -.Nd daemon to execute scheduled commands (Vixie Cron) -.Sh SYNOPSIS -.Nm -.Op Fl j Ar jitter -.Op Fl J Ar rootjitter -.Op Fl m Ar mailto -.Op Fl s -.Op Fl o -.Op Fl x Ar debugflag Ns Op , Ns Ar ... -.Sh DESCRIPTION -The -.Nm -utility should be started from -.Pa /etc/rc -or -.Pa /etc/rc.local . -It will return immediately, -so you do not need to start it with '&'. -.Pp -The -.Nm -utility searches -.Pa /var/cron/tabs -for crontab files which are named after accounts in -.Pa /etc/passwd ; -crontabs found are loaded into memory. -The -.Nm -utility also searches for -.Pa /etc/crontab -which is in a different format (see -.Xr crontab 5 ) . -.Pp -The -.Nm -utility -then wakes up every minute, examining all stored crontabs, checking each -command to see if it should be run in the current minute. -Before running a command from a per-account crontab file, -.Nm -checks the status of the account with -.Xr pam 3 -and skips the command if the account is unavailable, -e.g., locked out or expired. -Commands from -.Pa /etc/crontab -bypass this check. -When executing -commands, any output is mailed to the owner of the crontab (or to the user -named in the -.Ev MAILTO -environment variable in the crontab, if such exists). -.Pp -Additionally, -.Nm -checks each minute to see if its spool directory's modification time (or -the modification time on -.Pa /etc/crontab ) -has changed, and if it has, -.Nm -will then examine the modification time on all crontabs and reload those -which have changed. -Thus -.Nm -need not be restarted whenever a crontab file is modified. -Note that the -.Xr crontab 1 -command updates the modification time of the spool directory whenever it -changes a crontab. -.Pp -Available options: -.Bl -tag -width indent -.It Fl j Ar jitter -Enable time jitter. -Prior to executing commands, -.Nm -will sleep a random number of seconds in the range from 0 to -.Ar jitter . -This will not affect superuser jobs (see -.Fl J ) . -A value for -.Ar jitter -must be between 0 and 60 inclusive. -Default is 0, which effectively disables time jitter. -.Pp -This option can help to smooth down system load spikes during -moments when a lot of jobs are likely to start at once, e.g., -at the beginning of the first minute of each hour. -.It Fl J Ar rootjitter -Enable time jitter for superuser jobs. -The same as -.Fl j -except that it will affect jobs run by the superuser only. -.It Fl m Ar mailto -Overrides the default recipient for -.Nm -mail. -Each -.Xr crontab 5 -without -.Ev MAILTO -explicitly set will send mail to the -.Ar mailto -mailbox. -Sending mail will be disabled by default if -.Ar mailto -set to a null string, usually specified in a shell as -.Li '' -or -.Li \*q\*q . -.It Fl s -Enable special handling of situations when the GMT offset of the local -timezone changes, such as the switches between the standard time and -daylight saving time. -.Pp -The jobs run during the GMT offset changes time as -intuitively expected. -If a job falls into a time interval that disappears -(for example, during the switch from -standard time) to daylight saving time or is -duplicated (for example, during the reverse switch), then it is handled -in one of two ways: -.Pp -The first case is for the jobs that run every at hour of a time interval -overlapping with the disappearing or duplicated interval. -In other words, if the job had run within one hour before the GMT offset change -(and cron was not restarted nor the -.Xr crontab 5 -changed after that) -or would run after the change at the next hour. -They work as always, skip the skipped time or run in the added -time as usual. -.Pp -The second case is for the jobs that run less frequently. -They are executed exactly once, they are not skipped nor -executed twice (unless cron is restarted or the user's -.Xr crontab 5 -is changed during such a time interval). -If an interval disappears -due to the GMT offset change, such jobs are -executed at the same absolute point of time as they would be in the -old time zone. -For example, if exactly one hour disappears, this -point would be during the next hour at the first minute that is -specified for them in -.Xr crontab 5 . -.It Fl o -Disable the special handling of situations when the GMT offset of the local -timezone changes, to be compatible with the old (default) behavior. -If both options -.Fl o -and -.Fl s -are specified, the option specified last wins. -.It Fl x Ar debugflag Ns Op , Ns Ar ... -Enable writing of debugging information to standard output. -One or more of the following comma separated -.Ar debugflag -identifiers must be specified: -.Pp -.Bl -tag -width ".Cm proc" -compact -.It Cm bit -currently not used -.It Cm ext -make the other debug flags more verbose -.It Cm load -be verbose when loading crontab files -.It Cm misc -be verbose about miscellaneous one-off events -.It Cm pars -be verbose about parsing individual crontab lines -.It Cm proc -be verbose about the state of the process, including all of its offspring -.It Cm sch -be verbose when iterating through the scheduling algorithms -.It Cm test -trace through the execution, but do not perform any actions -.El -.El -.Sh FILES -.Bl -tag -width /etc/pam.d/cron -compact -.It Pa /etc/crontab -System crontab file -.It Pa /etc/pam.d/cron -.Xr pam.conf 5 -configuration file for -.Nm -.It Pa /var/cron/tabs -Directory for personal crontab files -.El -.Sh SEE ALSO -.Xr crontab 1 , -.Xr pam 3 , -.Xr crontab 5 , -.Xr pam.conf 5 -.Sh AUTHORS -.An Paul Vixie Aq paul@vix.com diff --git a/usr.sbin/cron/cron/cron.c b/usr.sbin/cron/cron/cron.c deleted file mode 100644 index 52cdcc8..0000000 --- a/usr.sbin/cron/cron/cron.c +++ /dev/null @@ -1,482 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - -#define MAIN_PROGRAM - - -#include "cron.h" -#include -#include -#if SYS_TIME_H -# include -#else -# include -#endif - - -static void usage(void), - run_reboot_jobs(cron_db *), - cron_tick(cron_db *), - cron_sync(void), - cron_sleep(cron_db *), - cron_clean(cron_db *), -#ifdef USE_SIGCHLD - sigchld_handler(int), -#endif - sighup_handler(int), - parse_args(int c, char *v[]); - -static time_t last_time = 0; -static int dst_enabled = 0; -struct pidfh *pfh; - -static void -usage() { - char **dflags; - - fprintf(stderr, "usage: cron [-j jitter] [-J rootjitter] " - "[-m mailto] [-s] [-o] [-x debugflag[,...]]\n"); - fprintf(stderr, "\ndebugflags: "); - - for(dflags = DebugFlagNames; *dflags; dflags++) { - fprintf(stderr, "%s ", *dflags); - } - fprintf(stderr, "\n"); - - exit(ERROR_EXIT); -} - -static void -open_pidfile(void) -{ - char pidfile[MAX_FNAME]; - char buf[MAX_TEMPSTR]; - int otherpid; - - (void) snprintf(pidfile, sizeof(pidfile), PIDFILE, PIDDIR); - pfh = pidfile_open(pidfile, 0600, &otherpid); - if (pfh == NULL) { - if (errno == EEXIST) { - snprintf(buf, sizeof(buf), - "cron already running, pid: %d", otherpid); - } else { - snprintf(buf, sizeof(buf), - "can't open or create %s: %s", pidfile, - strerror(errno)); - } - log_it("CRON", getpid(), "DEATH", buf); - errx(ERROR_EXIT, "%s", buf); - } -} - -int -main(argc, argv) - int argc; - char *argv[]; -{ - cron_db database; - - ProgramName = argv[0]; - -#if defined(BSD) - setlinebuf(stdout); - setlinebuf(stderr); -#endif - - parse_args(argc, argv); - -#ifdef USE_SIGCHLD - (void) signal(SIGCHLD, sigchld_handler); -#else - (void) signal(SIGCLD, SIG_IGN); -#endif - (void) signal(SIGHUP, sighup_handler); - - open_pidfile(); - set_cron_uid(); - set_cron_cwd(); - -#if defined(POSIX) - setenv("PATH", _PATH_DEFPATH, 1); -#endif - - /* if there are no debug flags turned on, fork as a daemon should. - */ -# if DEBUGGING - if (DebugFlags) { -# else - if (0) { -# endif - (void) fprintf(stderr, "[%d] cron started\n", getpid()); - } else { - if (daemon(1, 0) == -1) { - pidfile_remove(pfh); - log_it("CRON",getpid(),"DEATH","can't become daemon"); - exit(0); - } - } - - if (madvise(NULL, 0, MADV_PROTECT) != 0) - log_it("CRON", getpid(), "WARNING", "madvise() failed"); - - pidfile_write(pfh); - database.head = NULL; - database.tail = NULL; - database.mtime = (time_t) 0; - load_database(&database); - run_reboot_jobs(&database); - cron_sync(); - while (TRUE) { -# if DEBUGGING - /* if (!(DebugFlags & DTEST)) */ -# endif /*DEBUGGING*/ - cron_sleep(&database); - - load_database(&database); - - /* do this iteration - */ - cron_tick(&database); - - /* sleep 1 minute - */ - TargetTime += 60; - } -} - - -static void -run_reboot_jobs(db) - cron_db *db; -{ - register user *u; - register entry *e; - - for (u = db->head; u != NULL; u = u->next) { - for (e = u->crontab; e != NULL; e = e->next) { - if (e->flags & WHEN_REBOOT) { - job_add(e, u); - } - } - } - (void) job_runqueue(); -} - - -static void -cron_tick(db) - cron_db *db; -{ - static struct tm lasttm; - static time_t diff = 0, /* time difference in seconds from the last offset change */ - difflimit = 0; /* end point for the time zone correction */ - struct tm otztm; /* time in the old time zone */ - int otzminute, otzhour, otzdom, otzmonth, otzdow; - register struct tm *tm = localtime(&TargetTime); - register int minute, hour, dom, month, dow; - register user *u; - register entry *e; - - /* make 0-based values out of these so we can use them as indicies - */ - minute = tm->tm_min -FIRST_MINUTE; - hour = tm->tm_hour -FIRST_HOUR; - dom = tm->tm_mday -FIRST_DOM; - month = tm->tm_mon +1 /* 0..11 -> 1..12 */ -FIRST_MONTH; - dow = tm->tm_wday -FIRST_DOW; - - Debug(DSCH, ("[%d] tick(%d,%d,%d,%d,%d)\n", - getpid(), minute, hour, dom, month, dow)) - - if (dst_enabled && last_time != 0 - && TargetTime > last_time /* exclude stepping back */ - && tm->tm_gmtoff != lasttm.tm_gmtoff ) { - - diff = tm->tm_gmtoff - lasttm.tm_gmtoff; - - if ( diff > 0 ) { /* ST->DST */ - /* mark jobs for an earlier run */ - difflimit = TargetTime + diff; - for (u = db->head; u != NULL; u = u->next) { - for (e = u->crontab; e != NULL; e = e->next) { - e->flags &= ~NOT_UNTIL; - if ( e->lastrun >= TargetTime ) - e->lastrun = 0; - /* not include the ends of hourly ranges */ - if ( e->lastrun < TargetTime - 3600 ) - e->flags |= RUN_AT; - else - e->flags &= ~RUN_AT; - } - } - } else { /* diff < 0 : DST->ST */ - /* mark jobs for skipping */ - difflimit = TargetTime - diff; - for (u = db->head; u != NULL; u = u->next) { - for (e = u->crontab; e != NULL; e = e->next) { - e->flags |= NOT_UNTIL; - e->flags &= ~RUN_AT; - } - } - } - } - - if (diff != 0) { - /* if the time was reset of the end of special zone is reached */ - if (last_time == 0 || TargetTime >= difflimit) { - /* disable the TZ switch checks */ - diff = 0; - difflimit = 0; - for (u = db->head; u != NULL; u = u->next) { - for (e = u->crontab; e != NULL; e = e->next) { - e->flags &= ~(RUN_AT|NOT_UNTIL); - } - } - } else { - /* get the time in the old time zone */ - time_t difftime = TargetTime + tm->tm_gmtoff - diff; - gmtime_r(&difftime, &otztm); - - /* make 0-based values out of these so we can use them as indicies - */ - otzminute = otztm.tm_min -FIRST_MINUTE; - otzhour = otztm.tm_hour -FIRST_HOUR; - otzdom = otztm.tm_mday -FIRST_DOM; - otzmonth = otztm.tm_mon +1 /* 0..11 -> 1..12 */ -FIRST_MONTH; - otzdow = otztm.tm_wday -FIRST_DOW; - } - } - - /* the dom/dow situation is odd. '* * 1,15 * Sun' will run on the - * first and fifteenth AND every Sunday; '* * * * Sun' will run *only* - * on Sundays; '* * 1,15 * *' will run *only* the 1st and 15th. this - * is why we keep 'e->dow_star' and 'e->dom_star'. yes, it's bizarre. - * like many bizarre things, it's the standard. - */ - for (u = db->head; u != NULL; u = u->next) { - for (e = u->crontab; e != NULL; e = e->next) { - Debug(DSCH|DEXT, ("user [%s:%d:%d:...] cmd=\"%s\"\n", - env_get("LOGNAME", e->envp), - e->uid, e->gid, e->cmd)) - - if ( diff != 0 && (e->flags & (RUN_AT|NOT_UNTIL)) ) { - if (bit_test(e->minute, otzminute) - && bit_test(e->hour, otzhour) - && bit_test(e->month, otzmonth) - && ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR)) - ? (bit_test(e->dow,otzdow) && bit_test(e->dom,otzdom)) - : (bit_test(e->dow,otzdow) || bit_test(e->dom,otzdom)) - ) - ) { - if ( e->flags & RUN_AT ) { - e->flags &= ~RUN_AT; - e->lastrun = TargetTime; - job_add(e, u); - continue; - } else - e->flags &= ~NOT_UNTIL; - } else if ( e->flags & NOT_UNTIL ) - continue; - } - - if (bit_test(e->minute, minute) - && bit_test(e->hour, hour) - && bit_test(e->month, month) - && ( ((e->flags & DOM_STAR) || (e->flags & DOW_STAR)) - ? (bit_test(e->dow,dow) && bit_test(e->dom,dom)) - : (bit_test(e->dow,dow) || bit_test(e->dom,dom)) - ) - ) { - e->flags &= ~RUN_AT; - e->lastrun = TargetTime; - job_add(e, u); - } - } - } - - last_time = TargetTime; - lasttm = *tm; -} - - -/* the task here is to figure out how long it's going to be until :00 of the - * following minute and initialize TargetTime to this value. TargetTime - * will subsequently slide 60 seconds at a time, with correction applied - * implicitly in cron_sleep(). it would be nice to let cron execute in - * the "current minute" before going to sleep, but by restarting cron you - * could then get it to execute a given minute's jobs more than once. - * instead we have the chance of missing a minute's jobs completely, but - * that's something sysadmin's know to expect what with crashing computers.. - */ -static void -cron_sync() { - register struct tm *tm; - - TargetTime = time((time_t*)0); - tm = localtime(&TargetTime); - TargetTime += (60 - tm->tm_sec); -} - - -static void -cron_sleep(db) - cron_db *db; -{ - int seconds_to_wait = 0; - - /* - * Loop until we reach the top of the next minute, sleep when possible. - */ - - for (;;) { - seconds_to_wait = (int) (TargetTime - time((time_t*)0)); - - /* - * If the seconds_to_wait value is insane, jump the cron - */ - - if (seconds_to_wait < -600 || seconds_to_wait > 600) { - cron_clean(db); - cron_sync(); - continue; - } - - Debug(DSCH, ("[%d] TargetTime=%ld, sec-to-wait=%d\n", - getpid(), (long)TargetTime, seconds_to_wait)) - - /* - * If we've run out of wait time or there are no jobs left - * to run, break - */ - - if (seconds_to_wait <= 0) - break; - if (job_runqueue() == 0) { - Debug(DSCH, ("[%d] sleeping for %d seconds\n", - getpid(), seconds_to_wait)) - - sleep(seconds_to_wait); - } - } -} - - -/* if the time was changed abruptly, clear the flags related - * to the daylight time switch handling to avoid strange effects - */ - -static void -cron_clean(db) - cron_db *db; -{ - user *u; - entry *e; - - last_time = 0; - - for (u = db->head; u != NULL; u = u->next) { - for (e = u->crontab; e != NULL; e = e->next) { - e->flags &= ~(RUN_AT|NOT_UNTIL); - } - } -} - -#ifdef USE_SIGCHLD -static void -sigchld_handler(int x) -{ - WAIT_T waiter; - PID_T pid; - - for (;;) { -#ifdef POSIX - pid = waitpid(-1, &waiter, WNOHANG); -#else - pid = wait3(&waiter, WNOHANG, (struct rusage *)0); -#endif - switch (pid) { - case -1: - Debug(DPROC, - ("[%d] sigchld...no children\n", getpid())) - return; - case 0: - Debug(DPROC, - ("[%d] sigchld...no dead kids\n", getpid())) - return; - default: - Debug(DPROC, - ("[%d] sigchld...pid #%d died, stat=%d\n", - getpid(), pid, WEXITSTATUS(waiter))) - } - } -} -#endif /*USE_SIGCHLD*/ - - -static void -sighup_handler(int x) -{ - log_close(); -} - - -static void -parse_args(argc, argv) - int argc; - char *argv[]; -{ - int argch; - char *endp; - - while ((argch = getopt(argc, argv, "j:J:m:osx:")) != -1) { - switch (argch) { - case 'j': - Jitter = strtoul(optarg, &endp, 10); - if (*optarg == '\0' || *endp != '\0' || Jitter > 60) - errx(ERROR_EXIT, - "bad value for jitter: %s", optarg); - break; - case 'J': - RootJitter = strtoul(optarg, &endp, 10); - if (*optarg == '\0' || *endp != '\0' || RootJitter > 60) - errx(ERROR_EXIT, - "bad value for root jitter: %s", optarg); - break; - case 'm': - defmailto = optarg; - break; - case 'o': - dst_enabled = 0; - break; - case 's': - dst_enabled = 1; - break; - case 'x': - if (!set_debug_flags(optarg)) - usage(); - break; - default: - usage(); - } - } -} - diff --git a/usr.sbin/cron/cron/cron.h b/usr.sbin/cron/cron/cron.h deleted file mode 100644 index 38eb33b..0000000 --- a/usr.sbin/cron/cron/cron.h +++ /dev/null @@ -1,301 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -/* cron.h - header for vixie's cron - * - * $FreeBSD$ - * - * vix 14nov88 [rest of log is in RCS] - * vix 14jan87 [0 or 7 can be sunday; thanks, mwm@berkeley] - * vix 30dec86 [written] - */ - -/* reorder these #include's at your peril */ - -#include -#include -#include "compat.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pathnames.h" -#include "config.h" -#include "externs.h" - - /* these are really immutable, and are - * defined for symbolic convenience only - * TRUE, FALSE, and ERR must be distinct - * ERR must be < OK. - */ -#define TRUE 1 -#define FALSE 0 - /* system calls return this on success */ -#define OK 0 - /* or this on error */ -#define ERR (-1) - - /* turn this on to get '-x' code */ -#ifndef DEBUGGING -#define DEBUGGING FALSE -#endif - -#define READ_PIPE 0 /* which end of a pipe pair do you read? */ -#define WRITE_PIPE 1 /* or write to? */ -#define STDIN 0 /* what is stdin's file descriptor? */ -#define STDOUT 1 /* stdout's? */ -#define STDERR 2 /* stderr's? */ -#define ERROR_EXIT 1 /* exit() with this will scare the shell */ -#define OK_EXIT 0 /* exit() with this is considered 'normal' */ -#define MAX_FNAME 100 /* max length of internally generated fn */ -#define MAX_COMMAND 1000 /* max length of internally generated cmd */ -#define MAX_ENVSTR 1000 /* max length of envvar=value\0 strings */ -#define MAX_TEMPSTR 100 /* obvious */ -#define MAX_UNAME 20 /* max length of username, should be overkill */ -#define ROOT_UID 0 /* don't change this, it really must be root */ -#define ROOT_USER "root" /* ditto */ -#define SYS_NAME "*system*" /* magic owner name for system crontab */ - - /* NOTE: these correspond to DebugFlagNames, - * defined below. - */ -#define DEXT 0x0001 /* extend flag for other debug masks */ -#define DSCH 0x0002 /* scheduling debug mask */ -#define DPROC 0x0004 /* process control debug mask */ -#define DPARS 0x0008 /* parsing debug mask */ -#define DLOAD 0x0010 /* database loading debug mask */ -#define DMISC 0x0020 /* misc debug mask */ -#define DTEST 0x0040 /* test mode: don't execute any commands */ -#define DBIT 0x0080 /* bit twiddling shown (long) */ - -#define CRON_TAB(u) "%s/%s", SPOOL_DIR, u -#define REG register -#define PPC_NULL ((char **)NULL) - -#ifndef MAXHOSTNAMELEN -#define MAXHOSTNAMELEN 256 -#endif - -#define Skip_Blanks(c, f) \ - while (c == '\t' || c == ' ') \ - c = get_char(f); - -#define Skip_Nonblanks(c, f) \ - while (c!='\t' && c!=' ' && c!='\n' && c != EOF) \ - c = get_char(f); - -#define Skip_Line(c, f) \ - do {c = get_char(f);} while (c != '\n' && c != EOF); - -#if DEBUGGING -# define Debug(mask, message) \ - if ( (DebugFlags & (mask) ) == (mask) ) \ - printf message; -#else /* !DEBUGGING */ -# define Debug(mask, message) \ - ; -#endif /* DEBUGGING */ - -#define MkLower(ch) (isupper(ch) ? tolower(ch) : ch) -#define MkUpper(ch) (islower(ch) ? toupper(ch) : ch) -#define Set_LineNum(ln) {Debug(DPARS|DEXT,("linenum=%d\n",ln)); \ - LineNumber = ln; \ - } - -#define FIRST_MINUTE 0 -#define LAST_MINUTE 59 -#define MINUTE_COUNT (LAST_MINUTE - FIRST_MINUTE + 1) - -#define FIRST_HOUR 0 -#define LAST_HOUR 23 -#define HOUR_COUNT (LAST_HOUR - FIRST_HOUR + 1) - -#define FIRST_DOM 1 -#define LAST_DOM 31 -#define DOM_COUNT (LAST_DOM - FIRST_DOM + 1) - -#define FIRST_MONTH 1 -#define LAST_MONTH 12 -#define MONTH_COUNT (LAST_MONTH - FIRST_MONTH + 1) - -/* note on DOW: 0 and 7 are both Sunday, for compatibility reasons. */ -#define FIRST_DOW 0 -#define LAST_DOW 7 -#define DOW_COUNT (LAST_DOW - FIRST_DOW + 1) - -#ifdef LOGIN_CAP -/* see init.c */ -#define RESOURCE_RC "daemon" -#endif - - /* each user's crontab will be held as a list of - * the following structure. - * - * These are the cron commands. - */ - -typedef struct _entry { - struct _entry *next; - uid_t uid; - gid_t gid; -#ifdef LOGIN_CAP - char *class; -#endif - char **envp; - char *cmd; - bitstr_t bit_decl(minute, MINUTE_COUNT); - bitstr_t bit_decl(hour, HOUR_COUNT); - bitstr_t bit_decl(dom, DOM_COUNT); - bitstr_t bit_decl(month, MONTH_COUNT); - bitstr_t bit_decl(dow, DOW_COUNT); - int flags; -#define DOM_STAR 0x01 -#define DOW_STAR 0x02 -#define WHEN_REBOOT 0x04 -#define RUN_AT 0x08 -#define NOT_UNTIL 0x10 - time_t lastrun; -} entry; - - /* the crontab database will be a list of the - * following structure, one element per user - * plus one for the system. - * - * These are the crontabs. - */ - -typedef struct _user { - struct _user *next, *prev; /* links */ - char *name; - time_t mtime; /* last modtime of crontab */ - entry *crontab; /* this person's crontab */ -} user; - -typedef struct _cron_db { - user *head, *tail; /* links */ - time_t mtime; /* last modtime on spooldir */ -} cron_db; - - -void set_cron_uid(void), - set_cron_cwd(void), - load_database(cron_db *), - open_logfile(void), - sigpipe_func(void), - job_add(entry *, user *), - do_command(entry *, user *), - link_user(cron_db *, user *), - unlink_user(cron_db *, user *), - free_user(user *), - env_free(char **), - unget_char(int, FILE *), - free_entry(entry *), - skip_comments(FILE *), - log_it(char *, int, char *, char *), - log_close(void); - -int job_runqueue(void), - set_debug_flags(char *), - get_char(FILE *), - get_string(char *, int, FILE *, char *), - swap_uids(void), - swap_uids_back(void), - load_env(char *, FILE *), - cron_pclose(FILE *), - strcmp_until(char *, char *, int), - allowed(char *), - strdtb(char *); - -char *env_get(char *, char **), - *arpadate(time_t *), - *mkprints(unsigned char *, unsigned int), - *first_word(char *, char *), - **env_init(void), - **env_copy(char **), - **env_set(char **, char *); - -user *load_user(int, struct passwd *, char *), - *find_user(cron_db *, char *); - -entry *load_entry(FILE *, void (*)(char *), - struct passwd *, char **); - -FILE *cron_popen(char *, char *, entry *); - - - /* in the C tradition, we only create - * variables for the main program, just - * extern them elsewhere. - */ - -#ifdef MAIN_PROGRAM -# if !defined(LINT) && !defined(lint) -char *copyright[] = { - "@(#) Copyright 1988,1989,1990,1993,1994 by Paul Vixie", - "@(#) All rights reserved" - }; -# endif - -char *MonthNames[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", - NULL - }; - -char *DowNames[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", - NULL - }; - -char *ProgramName, - *defmailto; -int LineNumber; -unsigned Jitter, - RootJitter; -time_t TargetTime; - -# if DEBUGGING -int DebugFlags; -char *DebugFlagNames[] = { /* sync with #defines */ - "ext", "sch", "proc", "pars", "load", "misc", "test", "bit", - NULL /* NULL must be last element */ - }; -# endif /* DEBUGGING */ -#else /*MAIN_PROGRAM*/ -extern char *copyright[], - *MonthNames[], - *DowNames[], - *ProgramName, - *defmailto; -extern int LineNumber; -extern unsigned Jitter, - RootJitter; -extern time_t TargetTime; -extern struct pidfh *pfh; -# if DEBUGGING -extern int DebugFlags; -extern char *DebugFlagNames[]; -# endif /* DEBUGGING */ -#endif /*MAIN_PROGRAM*/ diff --git a/usr.sbin/cron/cron/database.c b/usr.sbin/cron/cron/database.c deleted file mode 100644 index 7a44d14..0000000 --- a/usr.sbin/cron/cron/database.c +++ /dev/null @@ -1,263 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - -/* vix 26jan87 [RCS has the log] - */ - - -#include "cron.h" -#include -#include -#include - - -#define TMAX(a,b) ((a)>(b)?(a):(b)) - - -static void process_crontab(char *, char *, char *, - struct stat *, - cron_db *, cron_db *); - - -void -load_database(old_db) - cron_db *old_db; -{ - DIR *dir; - struct stat statbuf; - struct stat syscron_stat; - DIR_T *dp; - cron_db new_db; - user *u, *nu; - - Debug(DLOAD, ("[%d] load_database()\n", getpid())) - - /* before we start loading any data, do a stat on SPOOL_DIR - * so that if anything changes as of this moment (i.e., before we've - * cached any of the database), we'll see the changes next time. - */ - if (stat(SPOOL_DIR, &statbuf) < OK) { - log_it("CRON", getpid(), "STAT FAILED", SPOOL_DIR); - (void) exit(ERROR_EXIT); - } - - /* track system crontab file - */ - if (stat(SYSCRONTAB, &syscron_stat) < OK) - syscron_stat.st_mtime = 0; - - /* if spooldir's mtime has not changed, we don't need to fiddle with - * the database. - * - * Note that old_db->mtime is initialized to 0 in main(), and - * so is guaranteed to be different than the stat() mtime the first - * time this function is called. - */ - if (old_db->mtime == TMAX(statbuf.st_mtime, syscron_stat.st_mtime)) { - Debug(DLOAD, ("[%d] spool dir mtime unch, no load needed.\n", - getpid())) - return; - } - - /* something's different. make a new database, moving unchanged - * elements from the old database, reloading elements that have - * actually changed. Whatever is left in the old database when - * we're done is chaff -- crontabs that disappeared. - */ - new_db.mtime = TMAX(statbuf.st_mtime, syscron_stat.st_mtime); - new_db.head = new_db.tail = NULL; - - if (syscron_stat.st_mtime) { - process_crontab("root", SYS_NAME, - SYSCRONTAB, &syscron_stat, - &new_db, old_db); - } - - /* we used to keep this dir open all the time, for the sake of - * efficiency. however, we need to close it in every fork, and - * we fork a lot more often than the mtime of the dir changes. - */ - if (!(dir = opendir(SPOOL_DIR))) { - log_it("CRON", getpid(), "OPENDIR FAILED", SPOOL_DIR); - (void) exit(ERROR_EXIT); - } - - while (NULL != (dp = readdir(dir))) { - char fname[MAXNAMLEN+1], - tabname[MAXNAMLEN+1]; - - /* avoid file names beginning with ".". this is good - * because we would otherwise waste two guaranteed calls - * to getpwnam() for . and .., and also because user names - * starting with a period are just too nasty to consider. - */ - if (dp->d_name[0] == '.') - continue; - - (void) strncpy(fname, dp->d_name, sizeof(fname)); - fname[sizeof(fname)-1] = '\0'; - (void) snprintf(tabname, sizeof tabname, CRON_TAB(fname)); - - process_crontab(fname, fname, tabname, - &statbuf, &new_db, old_db); - } - closedir(dir); - - /* if we don't do this, then when our children eventually call - * getpwnam() in do_command.c's child_process to verify MAILTO=, - * they will screw us up (and v-v). - */ - endpwent(); - - /* whatever's left in the old database is now junk. - */ - Debug(DLOAD, ("unlinking old database:\n")) - for (u = old_db->head; u != NULL; u = nu) { - Debug(DLOAD, ("\t%s\n", u->name)) - nu = u->next; - unlink_user(old_db, u); - free_user(u); - } - - /* overwrite the database control block with the new one. - */ - *old_db = new_db; - Debug(DLOAD, ("load_database is done\n")) -} - - -void -link_user(db, u) - cron_db *db; - user *u; -{ - if (db->head == NULL) - db->head = u; - if (db->tail) - db->tail->next = u; - u->prev = db->tail; - u->next = NULL; - db->tail = u; -} - - -void -unlink_user(db, u) - cron_db *db; - user *u; -{ - if (u->prev == NULL) - db->head = u->next; - else - u->prev->next = u->next; - - if (u->next == NULL) - db->tail = u->prev; - else - u->next->prev = u->prev; -} - - -user * -find_user(db, name) - cron_db *db; - char *name; -{ - char *env_get(); - user *u; - - for (u = db->head; u != NULL; u = u->next) - if (!strcmp(u->name, name)) - break; - return u; -} - - -static void -process_crontab(uname, fname, tabname, statbuf, new_db, old_db) - char *uname; - char *fname; - char *tabname; - struct stat *statbuf; - cron_db *new_db; - cron_db *old_db; -{ - struct passwd *pw = NULL; - int crontab_fd = OK - 1; - user *u; - - if (strcmp(fname, SYS_NAME) && !(pw = getpwnam(uname))) { - /* file doesn't have a user in passwd file. - */ - log_it(fname, getpid(), "ORPHAN", "no passwd entry"); - goto next_crontab; - } - - if ((crontab_fd = open(tabname, O_RDONLY, 0)) < OK) { - /* crontab not accessible? - */ - log_it(fname, getpid(), "CAN'T OPEN", tabname); - goto next_crontab; - } - - if (fstat(crontab_fd, statbuf) < OK) { - log_it(fname, getpid(), "FSTAT FAILED", tabname); - goto next_crontab; - } - - Debug(DLOAD, ("\t%s:", fname)) - u = find_user(old_db, fname); - if (u != NULL) { - /* if crontab has not changed since we last read it - * in, then we can just use our existing entry. - */ - if (u->mtime == statbuf->st_mtime) { - Debug(DLOAD, (" [no change, using old data]")) - unlink_user(old_db, u); - link_user(new_db, u); - goto next_crontab; - } - - /* before we fall through to the code that will reload - * the user, let's deallocate and unlink the user in - * the old database. This is more a point of memory - * efficiency than anything else, since all leftover - * users will be deleted from the old database when - * we finish with the crontab... - */ - Debug(DLOAD, (" [delete old data]")) - unlink_user(old_db, u); - free_user(u); - log_it(fname, getpid(), "RELOAD", tabname); - } - u = load_user(crontab_fd, pw, fname); - if (u != NULL) { - u->mtime = statbuf->st_mtime; - link_user(new_db, u); - } - -next_crontab: - if (crontab_fd >= OK) { - Debug(DLOAD, (" [done]\n")) - close(crontab_fd); - } -} diff --git a/usr.sbin/cron/cron/do_command.c b/usr.sbin/cron/cron/do_command.c deleted file mode 100644 index daf695f..0000000 --- a/usr.sbin/cron/cron/do_command.c +++ /dev/null @@ -1,617 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - - -#include "cron.h" -#include -#if defined(sequent) -# include -#endif -#if defined(SYSLOG) -# include -#endif -#if defined(LOGIN_CAP) -# include -#endif -#ifdef PAM -# include -# include -#endif - - -static void child_process(entry *, user *), - do_univ(user *); - - -void -do_command(e, u) - entry *e; - user *u; -{ - Debug(DPROC, ("[%d] do_command(%s, (%s,%d,%d))\n", - getpid(), e->cmd, u->name, e->uid, e->gid)) - - /* fork to become asynchronous -- parent process is done immediately, - * and continues to run the normal cron code, which means return to - * tick(). the child and grandchild don't leave this function, alive. - * - * vfork() is unsuitable, since we have much to do, and the parent - * needs to be able to run off and fork other processes. - */ - switch (fork()) { - case -1: - log_it("CRON",getpid(),"error","can't fork"); - break; - case 0: - /* child process */ - pidfile_close(pfh); - child_process(e, u); - Debug(DPROC, ("[%d] child process done, exiting\n", getpid())) - _exit(OK_EXIT); - break; - default: - /* parent process */ - break; - } - Debug(DPROC, ("[%d] main process returning to work\n", getpid())) -} - - -static void -child_process(e, u) - entry *e; - user *u; -{ - int stdin_pipe[2], stdout_pipe[2]; - register char *input_data; - char *usernm, *mailto; - int children = 0; -# if defined(LOGIN_CAP) - struct passwd *pwd; - login_cap_t *lc; -# endif - - Debug(DPROC, ("[%d] child_process('%s')\n", getpid(), e->cmd)) - - /* mark ourselves as different to PS command watchers by upshifting - * our program name. This has no effect on some kernels. - */ - setproctitle("running job"); - - /* discover some useful and important environment settings - */ - usernm = env_get("LOGNAME", e->envp); - mailto = env_get("MAILTO", e->envp); - -#ifdef PAM - /* use PAM to see if the user's account is available, - * i.e., not locked or expired or whatever. skip this - * for system tasks from /etc/crontab -- they can run - * as any user. - */ - if (strcmp(u->name, SYS_NAME)) { /* not equal */ - pam_handle_t *pamh = NULL; - int pam_err; - struct pam_conv pamc = { - .conv = openpam_nullconv, - .appdata_ptr = NULL - }; - - Debug(DPROC, ("[%d] checking account with PAM\n", getpid())) - - /* u->name keeps crontab owner name while LOGNAME is the name - * of user to run command on behalf of. they should be the - * same for a task from a per-user crontab. - */ - if (strcmp(u->name, usernm)) { - log_it(usernm, getpid(), "username ambiguity", u->name); - exit(ERROR_EXIT); - } - - pam_err = pam_start("cron", usernm, &pamc, &pamh); - if (pam_err != PAM_SUCCESS) { - log_it("CRON", getpid(), "error", "can't start PAM"); - exit(ERROR_EXIT); - } - - pam_err = pam_acct_mgmt(pamh, PAM_SILENT); - /* Expired password shouldn't prevent the job from running. */ - if (pam_err != PAM_SUCCESS && pam_err != PAM_NEW_AUTHTOK_REQD) { - log_it(usernm, getpid(), "USER", "account unavailable"); - exit(ERROR_EXIT); - } - - pam_end(pamh, pam_err); - } -#endif - -#ifdef USE_SIGCHLD - /* our parent is watching for our death by catching SIGCHLD. we - * do not care to watch for our children's deaths this way -- we - * use wait() explictly. so we have to disable the signal (which - * was inherited from the parent). - */ - (void) signal(SIGCHLD, SIG_DFL); -#else - /* on system-V systems, we are ignoring SIGCLD. we have to stop - * ignoring it now or the wait() in cron_pclose() won't work. - * because of this, we have to wait() for our children here, as well. - */ - (void) signal(SIGCLD, SIG_DFL); -#endif /*BSD*/ - - /* create some pipes to talk to our future child - */ - pipe(stdin_pipe); /* child's stdin */ - pipe(stdout_pipe); /* child's stdout */ - - /* since we are a forked process, we can diddle the command string - * we were passed -- nobody else is going to use it again, right? - * - * if a % is present in the command, previous characters are the - * command, and subsequent characters are the additional input to - * the command. Subsequent %'s will be transformed into newlines, - * but that happens later. - * - * If there are escaped %'s, remove the escape character. - */ - /*local*/{ - register int escaped = FALSE; - register int ch; - register char *p; - - for (input_data = p = e->cmd; (ch = *input_data); - input_data++, p++) { - if (p != input_data) - *p = ch; - if (escaped) { - if (ch == '%' || ch == '\\') - *--p = ch; - escaped = FALSE; - continue; - } - if (ch == '\\') { - escaped = TRUE; - continue; - } - if (ch == '%') { - *input_data++ = '\0'; - break; - } - } - *p = '\0'; - } - - /* fork again, this time so we can exec the user's command. - */ - switch (vfork()) { - case -1: - log_it("CRON",getpid(),"error","can't vfork"); - exit(ERROR_EXIT); - /*NOTREACHED*/ - case 0: - Debug(DPROC, ("[%d] grandchild process Vfork()'ed\n", - getpid())) - - if (e->uid == ROOT_UID) - Jitter = RootJitter; - if (Jitter != 0) { - srandom(getpid()); - sleep(random() % Jitter); - } - - /* write a log message. we've waited this long to do it - * because it was not until now that we knew the PID that - * the actual user command shell was going to get and the - * PID is part of the log message. - */ - /*local*/{ - char *x = mkprints((u_char *)e->cmd, strlen(e->cmd)); - - log_it(usernm, getpid(), "CMD", x); - free(x); - } - - /* that's the last thing we'll log. close the log files. - */ -#ifdef SYSLOG - closelog(); -#endif - - /* get new pgrp, void tty, etc. - */ - (void) setsid(); - - /* close the pipe ends that we won't use. this doesn't affect - * the parent, who has to read and write them; it keeps the - * kernel from recording us as a potential client TWICE -- - * which would keep it from sending SIGPIPE in otherwise - * appropriate circumstances. - */ - close(stdin_pipe[WRITE_PIPE]); - close(stdout_pipe[READ_PIPE]); - - /* grandchild process. make std{in,out} be the ends of - * pipes opened by our daddy; make stderr go to stdout. - */ - close(STDIN); dup2(stdin_pipe[READ_PIPE], STDIN); - close(STDOUT); dup2(stdout_pipe[WRITE_PIPE], STDOUT); - close(STDERR); dup2(STDOUT, STDERR); - - /* close the pipes we just dup'ed. The resources will remain. - */ - close(stdin_pipe[READ_PIPE]); - close(stdout_pipe[WRITE_PIPE]); - - /* set our login universe. Do this in the grandchild - * so that the child can invoke /usr/lib/sendmail - * without surprises. - */ - do_univ(u); - -# if defined(LOGIN_CAP) - /* Set user's entire context, but skip the environment - * as cron provides a separate interface for this - */ - if ((pwd = getpwnam(usernm)) == NULL) - pwd = getpwuid(e->uid); - lc = NULL; - if (pwd != NULL) { - pwd->pw_gid = e->gid; - if (e->class != NULL) - lc = login_getclass(e->class); - } - if (pwd && - setusercontext(lc, pwd, e->uid, - LOGIN_SETALL & ~(LOGIN_SETPATH|LOGIN_SETENV)) == 0) - (void) endpwent(); - else { - /* fall back to the old method */ - (void) endpwent(); -# endif - /* set our directory, uid and gid. Set gid first, - * since once we set uid, we've lost root privileges. - */ - if (setgid(e->gid) != 0) { - log_it(usernm, getpid(), - "error", "setgid failed"); - exit(ERROR_EXIT); - } -# if defined(BSD) - if (initgroups(usernm, e->gid) != 0) { - log_it(usernm, getpid(), - "error", "initgroups failed"); - exit(ERROR_EXIT); - } -# endif - if (setlogin(usernm) != 0) { - log_it(usernm, getpid(), - "error", "setlogin failed"); - exit(ERROR_EXIT); - } - if (setuid(e->uid) != 0) { - log_it(usernm, getpid(), - "error", "setuid failed"); - exit(ERROR_EXIT); - } - /* we aren't root after this..*/ -#if defined(LOGIN_CAP) - } - if (lc != NULL) - login_close(lc); -#endif - chdir(env_get("HOME", e->envp)); - - /* exec the command. - */ - { - char *shell = env_get("SHELL", e->envp); - -# if DEBUGGING - if (DebugFlags & DTEST) { - fprintf(stderr, - "debug DTEST is on, not exec'ing command.\n"); - fprintf(stderr, - "\tcmd='%s' shell='%s'\n", e->cmd, shell); - _exit(OK_EXIT); - } -# endif /*DEBUGGING*/ - execle(shell, shell, "-c", e->cmd, (char *)0, e->envp); - warn("execl: couldn't exec `%s'", shell); - _exit(ERROR_EXIT); - } - break; - default: - /* parent process */ - break; - } - - children++; - - /* middle process, child of original cron, parent of process running - * the user's command. - */ - - Debug(DPROC, ("[%d] child continues, closing pipes\n", getpid())) - - /* close the ends of the pipe that will only be referenced in the - * grandchild process... - */ - close(stdin_pipe[READ_PIPE]); - close(stdout_pipe[WRITE_PIPE]); - - /* - * write, to the pipe connected to child's stdin, any input specified - * after a % in the crontab entry. while we copy, convert any - * additional %'s to newlines. when done, if some characters were - * written and the last one wasn't a newline, write a newline. - * - * Note that if the input data won't fit into one pipe buffer (2K - * or 4K on most BSD systems), and the child doesn't read its stdin, - * we would block here. thus we must fork again. - */ - - if (*input_data && fork() == 0) { - register FILE *out = fdopen(stdin_pipe[WRITE_PIPE], "w"); - register int need_newline = FALSE; - register int escaped = FALSE; - register int ch; - - if (out == NULL) { - warn("fdopen failed in child2"); - _exit(ERROR_EXIT); - } - - Debug(DPROC, ("[%d] child2 sending data to grandchild\n", getpid())) - - /* close the pipe we don't use, since we inherited it and - * are part of its reference count now. - */ - close(stdout_pipe[READ_PIPE]); - - /* translation: - * \% -> % - * % -> \n - * \x -> \x for all x != % - */ - while ((ch = *input_data++)) { - if (escaped) { - if (ch != '%') - putc('\\', out); - } else { - if (ch == '%') - ch = '\n'; - } - - if (!(escaped = (ch == '\\'))) { - putc(ch, out); - need_newline = (ch != '\n'); - } - } - if (escaped) - putc('\\', out); - if (need_newline) - putc('\n', out); - - /* close the pipe, causing an EOF condition. fclose causes - * stdin_pipe[WRITE_PIPE] to be closed, too. - */ - fclose(out); - - Debug(DPROC, ("[%d] child2 done sending to grandchild\n", getpid())) - exit(0); - } - - /* close the pipe to the grandkiddie's stdin, since its wicked uncle - * ernie back there has it open and will close it when he's done. - */ - close(stdin_pipe[WRITE_PIPE]); - - children++; - - /* - * read output from the grandchild. it's stderr has been redirected to - * it's stdout, which has been redirected to our pipe. if there is any - * output, we'll be mailing it to the user whose crontab this is... - * when the grandchild exits, we'll get EOF. - */ - - Debug(DPROC, ("[%d] child reading output from grandchild\n", getpid())) - - /*local*/{ - register FILE *in = fdopen(stdout_pipe[READ_PIPE], "r"); - register int ch; - - if (in == NULL) { - warn("fdopen failed in child"); - _exit(ERROR_EXIT); - } - - ch = getc(in); - if (ch != EOF) { - register FILE *mail; - register int bytes = 1; - int status = 0; - - Debug(DPROC|DEXT, - ("[%d] got data (%x:%c) from grandchild\n", - getpid(), ch, ch)) - - /* get name of recipient. this is MAILTO if set to a - * valid local username; USER otherwise. - */ - if (mailto == NULL) { - /* MAILTO not present, set to USER, - * unless globally overriden. - */ - if (defmailto) - mailto = defmailto; - else - mailto = usernm; - } - if (mailto && *mailto == '\0') - mailto = NULL; - - /* if we are supposed to be mailing, MAILTO will - * be non-NULL. only in this case should we set - * up the mail command and subjects and stuff... - */ - - if (mailto) { - register char **env; - auto char mailcmd[MAX_COMMAND]; - auto char hostname[MAXHOSTNAMELEN]; - - (void) gethostname(hostname, MAXHOSTNAMELEN); - (void) snprintf(mailcmd, sizeof(mailcmd), - MAILARGS, MAILCMD); - if (!(mail = cron_popen(mailcmd, "w", e))) { - warn("%s", MAILCMD); - (void) _exit(ERROR_EXIT); - } - fprintf(mail, "From: %s (Cron Daemon)\n", usernm); - fprintf(mail, "To: %s\n", mailto); - fprintf(mail, "Subject: Cron <%s@%s> %s\n", - usernm, first_word(hostname, "."), - e->cmd); -# if defined(MAIL_DATE) - fprintf(mail, "Date: %s\n", - arpadate(&TargetTime)); -# endif /* MAIL_DATE */ - for (env = e->envp; *env; env++) - fprintf(mail, "X-Cron-Env: <%s>\n", - *env); - fprintf(mail, "\n"); - - /* this was the first char from the pipe - */ - putc(ch, mail); - } - - /* we have to read the input pipe no matter whether - * we mail or not, but obviously we only write to - * mail pipe if we ARE mailing. - */ - - while (EOF != (ch = getc(in))) { - bytes++; - if (mailto) - putc(ch, mail); - } - - /* only close pipe if we opened it -- i.e., we're - * mailing... - */ - - if (mailto) { - Debug(DPROC, ("[%d] closing pipe to mail\n", - getpid())) - /* Note: the pclose will probably see - * the termination of the grandchild - * in addition to the mail process, since - * it (the grandchild) is likely to exit - * after closing its stdout. - */ - status = cron_pclose(mail); - } - - /* if there was output and we could not mail it, - * log the facts so the poor user can figure out - * what's going on. - */ - if (mailto && status) { - char buf[MAX_TEMPSTR]; - - snprintf(buf, sizeof(buf), - "mailed %d byte%s of output but got status 0x%04x\n", - bytes, (bytes==1)?"":"s", - status); - log_it(usernm, getpid(), "MAIL", buf); - } - - } /*if data from grandchild*/ - - Debug(DPROC, ("[%d] got EOF from grandchild\n", getpid())) - - fclose(in); /* also closes stdout_pipe[READ_PIPE] */ - } - - /* wait for children to die. - */ - for (; children > 0; children--) - { - WAIT_T waiter; - PID_T pid; - - Debug(DPROC, ("[%d] waiting for grandchild #%d to finish\n", - getpid(), children)) - pid = wait(&waiter); - if (pid < OK) { - Debug(DPROC, ("[%d] no more grandchildren--mail written?\n", - getpid())) - break; - } - Debug(DPROC, ("[%d] grandchild #%d finished, status=%04x", - getpid(), pid, WEXITSTATUS(waiter))) - if (WIFSIGNALED(waiter) && WCOREDUMP(waiter)) - Debug(DPROC, (", dumped core")) - Debug(DPROC, ("\n")) - } -} - - -static void -do_univ(u) - user *u; -{ -#if defined(sequent) -/* Dynix (Sequent) hack to put the user associated with - * the passed user structure into the ATT universe if - * necessary. We have to dig the gecos info out of - * the user's password entry to see if the magic - * "universe(att)" string is present. - */ - - struct passwd *p; - char *s; - int i; - - p = getpwuid(u->uid); - (void) endpwent(); - - if (p == NULL) - return; - - s = p->pw_gecos; - - for (i = 0; i < 4; i++) - { - if ((s = strchr(s, ',')) == NULL) - return; - s++; - } - if (strcmp(s, "universe(att)")) - return; - - (void) universe(U_ATT); -#endif -} diff --git a/usr.sbin/cron/cron/externs.h b/usr.sbin/cron/cron/externs.h deleted file mode 100644 index 64bc8ac..0000000 --- a/usr.sbin/cron/cron/externs.h +++ /dev/null @@ -1,147 +0,0 @@ -/* $FreeBSD$ */ - -/* Copyright 1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if defined(POSIX) || defined(ATT) -# include -# include -# include -# include -# define DIR_T struct dirent -# define WAIT_T int -# define WAIT_IS_INT 1 -extern char *tzname[2]; -# define TZONE(tm) tzname[(tm).tm_isdst] -#endif - -#if defined(UNIXPC) -# undef WAIT_T -# undef WAIT_IS_INT -# define WAIT_T union wait -#endif - -#if defined(POSIX) -# define SIG_T sig_t -# define TIME_T time_t -# define PID_T pid_t -#endif - -#if defined(ATT) -# define SIG_T void -# define TIME_T long -# define PID_T int -#endif - -#if !defined(POSIX) && !defined(ATT) -/* classic BSD */ -extern time_t time(); -extern unsigned sleep(); -extern struct tm *localtime(); -extern struct passwd *getpwnam(); -extern int errno; -extern void perror(), exit(), free(); -extern char *getenv(), *strcpy(), *strchr(), *strtok(); -extern void *malloc(), *realloc(); -# define SIG_T void -# define TIME_T long -# define PID_T int -# define WAIT_T union wait -# define DIR_T struct direct -# include -# define TZONE(tm) (tm).tm_zone -#endif - -/* getopt() isn't part of POSIX. some systems define it in anyway. - * of those that do, some complain that our definition is different and some - * do not. to add to the misery and confusion, some systems define getopt() - * in ways that we cannot predict or comprehend, yet do not define the adjunct - * external variables needed for the interface. - */ -#if (!defined(BSD) || (BSD < 198911)) && !defined(ATT) && !defined(UNICOS) -int getopt(int, char * const *, const char *); -#endif - -#if (!defined(BSD) || (BSD < 199103)) -extern char *optarg; -extern int optind, opterr, optopt; -#endif - -#if WAIT_IS_INT -# ifndef WEXITSTATUS -# define WEXITSTATUS(x) (((x) >> 8) & 0xff) -# endif -# ifndef WTERMSIG -# define WTERMSIG(x) ((x) & 0x7f) -# endif -# ifndef WCOREDUMP -# define WCOREDUMP(x) ((x) & 0x80) -# endif -#else /*WAIT_IS_INT*/ -# ifndef WEXITSTATUS -# define WEXITSTATUS(x) ((x).w_retcode) -# endif -# ifndef WTERMSIG -# define WTERMSIG(x) ((x).w_termsig) -# endif -# ifndef WCOREDUMP -# define WCOREDUMP(x) ((x).w_coredump) -# endif -#endif /*WAIT_IS_INT*/ - -#ifndef WIFSIGNALED -#define WIFSIGNALED(x) (WTERMSIG(x) != 0) -#endif -#ifndef WIFEXITED -#define WIFEXITED(x) (WTERMSIG(x) == 0) -#endif - -#ifdef NEED_STRCASECMP -extern int strcasecmp(char *, char *); -#endif - -#ifdef NEED_STRDUP -extern char *strdup(char *); -#endif - -#ifdef NEED_STRERROR -extern char *strerror(int); -#endif - -#ifdef NEED_FLOCK -extern int flock(int, int); -# define LOCK_SH 1 -# define LOCK_EX 2 -# define LOCK_NB 4 -# define LOCK_UN 8 -#endif - -#ifdef NEED_SETSID -extern int setsid(void); -#endif - -#ifdef NEED_GETDTABLESIZE -extern int getdtablesize(void); -#endif - -#ifdef NEED_SETENV -extern int setenv(char *, char *, int); -#endif - -#ifdef NEED_VFORK -extern PID_T vfork(void); -#endif diff --git a/usr.sbin/cron/cron/job.c b/usr.sbin/cron/cron/job.c deleted file mode 100644 index 6d1b1af..0000000 --- a/usr.sbin/cron/cron/job.c +++ /dev/null @@ -1,76 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - - -#include "cron.h" - - -typedef struct _job { - struct _job *next; - entry *e; - user *u; -} job; - - -static job *jhead = NULL, *jtail = NULL; - - -void -job_add(e, u) - register entry *e; - register user *u; -{ - register job *j; - - /* if already on queue, keep going */ - for (j=jhead; j; j=j->next) - if (j->e == e && j->u == u) { return; } - - /* build a job queue element */ - if ((j = (job*)malloc(sizeof(job))) == NULL) - return; - j->next = (job*) NULL; - j->e = e; - j->u = u; - - /* add it to the tail */ - if (!jhead) { jhead=j; } - else { jtail->next=j; } - jtail = j; -} - - -int -job_runqueue() -{ - register job *j, *jn; - register int run = 0; - - for (j=jhead; j; j=jn) { - do_command(j->e, j->u); - jn = j->next; - free(j); - run++; - } - jhead = jtail = NULL; - return run; -} diff --git a/usr.sbin/cron/cron/pathnames.h b/usr.sbin/cron/cron/pathnames.h deleted file mode 100644 index ba91bfd..0000000 --- a/usr.sbin/cron/cron/pathnames.h +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright 1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -/* - * $FreeBSD$ - */ - -#if (defined(BSD)) && (BSD >= 199103) || defined(__linux) || defined(AIX) -# include -#endif /*BSD*/ - -#ifndef CRONDIR - /* CRONDIR is where crond(8) and crontab(1) both chdir - * to; SPOOL_DIR, ALLOW_FILE, DENY_FILE, and LOG_FILE - * are all relative to this directory. - */ -#define CRONDIR "/var/cron" -#endif - - /* SPOOLDIR is where the crontabs live. - * This directory will have its modtime updated - * whenever crontab(1) changes a crontab; this is - * the signal for crond(8) to look at each individual - * crontab file and reload those whose modtimes are - * newer than they were last time around (or which - * didn't exist last time around...) - */ -#define SPOOL_DIR "tabs" - - /* undefining these turns off their features. note - * that ALLOW_FILE and DENY_FILE must both be defined - * in order to enable the allow/deny code. If neither - * LOG_FILE or SYSLOG is defined, we don't log. If - * both are defined, we log both ways. - */ -#define ALLOW_FILE "allow" /*-*/ -#define DENY_FILE "deny" /*-*/ -/*#define LOG_FILE "log"*/ /*-*/ - - /* where should the daemon stick its PID? - */ -#ifdef _PATH_VARRUN -# define PIDDIR _PATH_VARRUN -#else -# define PIDDIR "/etc/" -#endif -#define PIDFILE "%scron.pid" - - /* 4.3BSD-style crontab */ -#define SYSCRONTAB "/etc/crontab" - - /* what editor to use if no EDITOR or VISUAL - * environment variable specified. - */ -#if defined(_PATH_VI) -# define EDITOR _PATH_VI -#else -# define EDITOR "/usr/ucb/vi" -#endif - -#ifndef _PATH_BSHELL -# define _PATH_BSHELL "/bin/sh" -#endif - -#ifndef _PATH_DEFPATH -# define _PATH_DEFPATH "/usr/bin:/bin" -#endif diff --git a/usr.sbin/cron/cron/popen.c b/usr.sbin/cron/cron/popen.c deleted file mode 100644 index 428de2e..0000000 --- a/usr.sbin/cron/cron/popen.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 1988 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software written by Ken Arnold and - * published in UNIX Review, Vol. 6, No. 8. - * - * Redistribution and use in source and binary forms are permitted - * provided that the above copyright notice and this paragraph are - * duplicated in all such forms and that any documentation, - * advertising materials, and other materials related to such - * distribution and use acknowledge that the software was developed - * by the University of California, Berkeley. The name of the - * University may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * - */ - -/* this came out of the ftpd sources; it's been modified to avoid the - * globbing stuff since we don't need it. also execvp instead of execv. - */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)popen.c 5.7 (Berkeley) 2/14/89"; -#endif -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include "cron.h" -#include -#include -#include -#if defined(SYSLOG) -# include -#endif -#if defined(LOGIN_CAP) -# include -#endif - - -#define MAX_ARGS 100 -#define WANT_GLOBBING 0 - -/* - * Special version of popen which avoids call to shell. This insures noone - * may create a pipe to a hidden program as a side effect of a list or dir - * command. - */ -static PID_T *pids; -static int fds; - -FILE * -cron_popen(program, type, e) - char *program, *type; - entry *e; -{ - register char *cp; - FILE *iop; - int argc, pdes[2]; - PID_T pid; - char *usernm; - char *argv[MAX_ARGS + 1]; -# if defined(LOGIN_CAP) - struct passwd *pwd; - login_cap_t *lc; -# endif -#if WANT_GLOBBING - char **pop, *vv[2]; - int gargc; - char *gargv[1000]; - extern char **glob(), **copyblk(); -#endif - - if ((*type != 'r' && *type != 'w') || type[1]) - return(NULL); - - if (!pids) { - if ((fds = getdtablesize()) <= 0) - return(NULL); - if (!(pids = (PID_T *)malloc((u_int)(fds * sizeof(PID_T))))) - return(NULL); - bzero((char *)pids, fds * sizeof(PID_T)); - } - if (pipe(pdes) < 0) - return(NULL); - - /* break up string into pieces */ - for (argc = 0, cp = program; argc < MAX_ARGS; cp = NULL) - if (!(argv[argc++] = strtok(cp, " \t\n"))) - break; - argv[MAX_ARGS] = NULL; - -#if WANT_GLOBBING - /* glob each piece */ - gargv[0] = argv[0]; - for (gargc = argc = 1; argv[argc]; argc++) { - if (!(pop = glob(argv[argc]))) { /* globbing failed */ - vv[0] = argv[argc]; - vv[1] = NULL; - pop = copyblk(vv); - } - argv[argc] = (char *)pop; /* save to free later */ - while (*pop && gargc < 1000) - gargv[gargc++] = *pop++; - } - gargv[gargc] = NULL; -#endif - - iop = NULL; - switch(pid = vfork()) { - case -1: /* error */ - (void)close(pdes[0]); - (void)close(pdes[1]); - goto pfree; - /* NOTREACHED */ - case 0: /* child */ - if (e != NULL) { -#ifdef SYSLOG - closelog(); -#endif - - /* get new pgrp, void tty, etc. - */ - (void) setsid(); - } - if (*type == 'r') { - /* Do not share our parent's stdin */ - (void)close(0); - (void)open(_PATH_DEVNULL, O_RDWR); - if (pdes[1] != 1) { - dup2(pdes[1], 1); - dup2(pdes[1], 2); /* stderr, too! */ - (void)close(pdes[1]); - } - (void)close(pdes[0]); - } else { - if (pdes[0] != 0) { - dup2(pdes[0], 0); - (void)close(pdes[0]); - } - /* Hack: stdout gets revoked */ - (void)close(1); - (void)open(_PATH_DEVNULL, O_RDWR); - (void)close(2); - (void)open(_PATH_DEVNULL, O_RDWR); - (void)close(pdes[1]); - } - if (e != NULL) { - /* Set user's entire context, but skip the environment - * as cron provides a separate interface for this - */ - usernm = env_get("LOGNAME", e->envp); -# if defined(LOGIN_CAP) - if ((pwd = getpwnam(usernm)) == NULL) - pwd = getpwuid(e->uid); - lc = NULL; - if (pwd != NULL) { - pwd->pw_gid = e->gid; - if (e->class != NULL) - lc = login_getclass(e->class); - } - if (pwd && - setusercontext(lc, pwd, e->uid, - LOGIN_SETALL & ~(LOGIN_SETPATH|LOGIN_SETENV)) == 0) - (void) endpwent(); - else { - /* fall back to the old method */ - (void) endpwent(); -# endif - /* - * Set our directory, uid and gid. Set gid - * first since once we set uid, we've lost - * root privileges. - */ - if (setgid(e->gid) != 0) - _exit(ERROR_EXIT); -# if defined(BSD) - if (initgroups(usernm, e->gid) != 0) - _exit(ERROR_EXIT); -# endif - if (setlogin(usernm) != 0) - _exit(ERROR_EXIT); - if (setuid(e->uid) != 0) - _exit(ERROR_EXIT); - /* we aren't root after this..*/ -#if defined(LOGIN_CAP) - } - if (lc != NULL) - login_close(lc); -#endif - chdir(env_get("HOME", e->envp)); - } -#if WANT_GLOBBING - execvp(gargv[0], gargv); -#else - execvp(argv[0], argv); -#endif - _exit(1); - } - /* parent; assume fdopen can't fail... */ - if (*type == 'r') { - iop = fdopen(pdes[0], type); - (void)close(pdes[1]); - } else { - iop = fdopen(pdes[1], type); - (void)close(pdes[0]); - } - pids[fileno(iop)] = pid; - -pfree: -#if WANT_GLOBBING - for (argc = 1; argv[argc] != NULL; argc++) { -/* blkfree((char **)argv[argc]); */ - free((char *)argv[argc]); - } -#endif - return(iop); -} - -int -cron_pclose(iop) - FILE *iop; -{ - register int fdes; - int omask; - WAIT_T stat_loc; - PID_T pid; - - /* - * pclose returns -1 if stream is not associated with a - * `popened' command, or, if already `pclosed'. - */ - if (pids == 0 || pids[fdes = fileno(iop)] == 0) - return(-1); - (void)fclose(iop); - omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); - while ((pid = wait(&stat_loc)) != pids[fdes] && pid != -1) - ; - (void)sigsetmask(omask); - pids[fdes] = 0; - return (pid == -1 ? -1 : WEXITSTATUS(stat_loc)); -} diff --git a/usr.sbin/cron/cron/user.c b/usr.sbin/cron/cron/user.c deleted file mode 100644 index 16fd617..0000000 --- a/usr.sbin/cron/cron/user.c +++ /dev/null @@ -1,128 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - -/* vix 26jan87 [log is in RCS file] - */ - - -#include "cron.h" - -static char *User_name; - -void -free_user(u) - user *u; -{ - entry *e, *ne; - - free(u->name); - for (e = u->crontab; e != NULL; e = ne) { - ne = e->next; - free_entry(e); - } - free(u); -} - -static void -log_error(msg) - char *msg; -{ - log_it(User_name, getpid(), "PARSE", msg); -} - -user * -load_user(crontab_fd, pw, name) - int crontab_fd; - struct passwd *pw; /* NULL implies syscrontab */ - char *name; -{ - char envstr[MAX_ENVSTR]; - FILE *file; - user *u; - entry *e; - int status; - char **envp, **tenvp; - - if (!(file = fdopen(crontab_fd, "r"))) { - warn("fdopen on crontab_fd in load_user"); - return NULL; - } - - Debug(DPARS, ("load_user()\n")) - - /* file is open. build user entry, then read the crontab file. - */ - if ((u = (user *) malloc(sizeof(user))) == NULL) { - errno = ENOMEM; - return NULL; - } - if ((u->name = strdup(name)) == NULL) { - free(u); - errno = ENOMEM; - return NULL; - } - u->crontab = NULL; - - /* - * init environment. this will be copied/augmented for each entry. - */ - if ((envp = env_init()) == NULL) { - free(u->name); - free(u); - return NULL; - } - - /* - * load the crontab - */ - while ((status = load_env(envstr, file)) >= OK) { - switch (status) { - case ERR: - free_user(u); - u = NULL; - goto done; - case FALSE: - User_name = u->name; /* for log_error */ - e = load_entry(file, log_error, pw, envp); - if (e) { - e->next = u->crontab; - u->crontab = e; - } - break; - case TRUE: - if ((tenvp = env_set(envp, envstr))) { - envp = tenvp; - } else { - free_user(u); - u = NULL; - goto done; - } - break; - } - } - - done: - env_free(envp); - fclose(file); - Debug(DPARS, ("...load_user() done\n")) - return u; -} diff --git a/usr.sbin/cron/crontab/Makefile b/usr.sbin/cron/crontab/Makefile deleted file mode 100644 index 829128e..0000000 --- a/usr.sbin/cron/crontab/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# $FreeBSD$ - -BINDIR= /usr/bin - -PROG= crontab -MAN= crontab.1 crontab.5 -BINOWN= root -BINMODE=4555 -PRECIOUSPROG= - -WARNS?= 3 - -CFLAGS+= -I${.CURDIR}/../cron - -DPADD= ${LIBCRON} ${LIBMD} ${LIBUTIL} -LDADD= ${LIBCRON} -lmd -lutil - -.include diff --git a/usr.sbin/cron/crontab/crontab.1 b/usr.sbin/cron/crontab/crontab.1 deleted file mode 100644 index eed515e..0000000 --- a/usr.sbin/cron/crontab/crontab.1 +++ /dev/null @@ -1,145 +0,0 @@ -.\"/* Copyright 1988,1990,1993 by Paul Vixie -.\" * All rights reserved -.\" * -.\" * Distribute freely, except: don't remove my name from the source or -.\" * documentation (don't take credit for my work), mark your changes (don't -.\" * get me blamed for your possible bugs), don't alter or remove this -.\" * notice. May be sold if buildable source is provided to buyer. No -.\" * warrantee of any kind, express or implied, is included with this -.\" * software; use at your own risk, responsibility for damages (if any) to -.\" * anyone resulting from the use of this software rests entirely with the -.\" * user. -.\" * -.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and -.\" * I'll try to keep a version up to date. I can be reached as follows: -.\" * Paul Vixie uunet!decwrl!vixie!paul -.\" */ -.\" -.\" $FreeBSD$ -.\" -.Dd May 13, 2010 -.Dt CRONTAB 1 -.Os -.Sh NAME -.Nm crontab -.Nd maintain crontab files for individual users (V3) -.Sh SYNOPSIS -.Nm -.Op Fl u Ar user -.Ar file -.Nm -.Op Fl u Ar user -{ -.Fl l | -.Fl r | -.Fl e -} -.Sh DESCRIPTION -The -.Nm -utility is the program used to install, deinstall or list the tables -used to drive the -.Xr cron 8 -daemon in Vixie Cron. -Each user can have their own crontab, and though -these are files in -.Pa /var , -they are not intended to be edited directly. -.Pp -If the -.Pa allow -file exists, then you must be listed therein in order to be allowed to use -this command. -If the -.Pa allow -file does not exist but the -.Pa deny -file does exist, then you must -.Em not -be listed in the -.Pa deny -file in order to use this command. -If neither of these files exists, then -depending on site-dependent configuration parameters, only the super user -will be allowed to use this command, or all users will be able to use this -command. -The format of these files is one username per line, -with no leading or trailing whitespace. -Lines of other formats will be ignored, -and so can be used for comments. -.Pp -The first form of this command is used to install a new crontab from some -named file or standard input if the pseudo-filename -.Sq Fl -is given. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl u -Specify the name of the user whose crontab is to be -tweaked. -If this option is not given, -.Nm -examines -.Dq your -crontab, i.e., the crontab of the person executing the -command. -Note that -.Xr su 1 -can confuse -.Nm -and that if you are running inside of -.Xr su 1 -you should always use the -.Fl u -option for safety's sake. -.It Fl l -Display the current crontab on standard output. -.It Fl r -Remove the current crontab. -.It Fl e -Edit the current crontab using the editor specified by -the -.Ev VISUAL -or -.Ev EDITOR -environment variables. -The specified editor -.Em must -edit the file in place; -any editor that unlinks the file and recreates it cannot be used. -After you exit -from the editor, the modified crontab will be installed automatically. -.El -.Sh FILES -.Bl -tag -width /var/cron/allow -compact -.It Pa /var/cron/allow -List of users allowed to use crontab -.It Pa /var/cron/deny -List of users prohibited from using crontab -.It Pa /var/cron/tabs -Directory for personal crontab files -.El -.Sh DIAGNOSTICS -A fairly informative usage message appears if you run it with a bad command -line. -.Sh SEE ALSO -.Xr crontab 5 , -.Xr cron 8 -.Sh STANDARDS -The -.Nm -command conforms to -.St -p1003.2 -with the exception that the dangerous variant of calling -.Nm -without a file name in the first form of the command is not allowed by -this implementation. -The pseudo-filename -.Sq Fl -must be specified to read from standard input. -The new command syntax -differs from previous versions of Vixie Cron, as well as from the classic -SVR3 syntax. -.Sh AUTHORS -.An Paul Vixie Aq paul@vix.com diff --git a/usr.sbin/cron/crontab/crontab.5 b/usr.sbin/cron/crontab/crontab.5 deleted file mode 100644 index ba88569..0000000 --- a/usr.sbin/cron/crontab/crontab.5 +++ /dev/null @@ -1,310 +0,0 @@ -.\"/* Copyright 1988,1990,1993,1994 by Paul Vixie -.\" * All rights reserved -.\" * -.\" * Distribute freely, except: don't remove my name from the source or -.\" * documentation (don't take credit for my work), mark your changes (don't -.\" * get me blamed for your possible bugs), don't alter or remove this -.\" * notice. May be sold if buildable source is provided to buyer. No -.\" * warrantee of any kind, express or implied, is included with this -.\" * software; use at your own risk, responsibility for damages (if any) to -.\" * anyone resulting from the use of this software rests entirely with the -.\" * user. -.\" * -.\" * Send bug reports, bug fixes, enhancements, requests, flames, etc., and -.\" * I'll try to keep a version up to date. I can be reached as follows: -.\" * Paul Vixie uunet!decwrl!vixie!paul -.\" */ -.\" -.\" $FreeBSD$ -.\" -.Dd July 31, 2005 -.Dt CRONTAB 5 -.Os -.Sh NAME -.Nm crontab -.Nd tables for driving cron -.Sh DESCRIPTION -A -.Nm -file contains instructions to the -.Xr cron 8 -daemon of the general form: ``run this command at this time on this date''. -Each user has their own crontab, and commands in any given crontab will be -executed as the user who owns the crontab. -Uucp and News will usually have -their own crontabs, eliminating the need for explicitly running -.Xr su 1 -as part of a cron command. -.Pp -Blank lines and leading spaces and tabs are ignored. -Lines whose first -non-space character is a pound-sign (#) are comments, and are ignored. -Note that comments are not allowed on the same line as cron commands, since -they will be taken to be part of the command. -Similarly, comments are not -allowed on the same line as environment variable settings. -.Pp -An active line in a crontab will be either an environment setting or a cron -command. -An environment setting is of the form, -.Bd -literal - name = value -.Ed -.Pp -where the spaces around the equal-sign (=) are optional, and any subsequent -non-leading spaces in -.Em value -will be part of the value assigned to -.Em name . -The -.Em value -string may be placed in quotes (single or double, but matching) to preserve -leading or trailing blanks. -The -.Em name -string may also be placed in quote (single or double, but matching) -to preserve leading, trailing or inner blanks. -.Pp -Several environment variables are set up -automatically by the -.Xr cron 8 -daemon. -.Ev SHELL -is set to -.Pa /bin/sh , -.Ev PATH -is set to -.Pa /usr/bin:/bin , -and -.Ev LOGNAME -and -.Ev HOME -are set from the -.Pa /etc/passwd -line of the crontab's owner. -.Ev HOME , -.Ev PATH -and -.Ev SHELL -may be overridden by settings in the crontab; -.Ev LOGNAME -may not. -.Pp -(Another note: the -.Ev LOGNAME -variable is sometimes called -.Ev USER -on -.Bx -systems... -On these systems, -.Ev USER -will be set also). -.Pp -In addition to -.Ev LOGNAME , -.Ev HOME , -.Ev PATH , -and -.Ev SHELL , -.Xr cron 8 -will look at -.Ev MAILTO -if it has any reason to send mail as a result of running -commands in ``this'' crontab. -If -.Ev MAILTO -is defined (and non-empty), mail is -sent to the user so named. -.Ev MAILTO -may also be used to direct mail to multiple recipients -by separating recipient users with a comma. -If -.Ev MAILTO -is defined but empty (MAILTO=""), no -mail will be sent. -Otherwise mail is sent to the owner of the crontab. -This -option is useful if you decide on -.Pa /bin/mail -instead of -.Pa /usr/lib/sendmail -as -your mailer when you install cron -- -.Pa /bin/mail -does not do aliasing, and UUCP -usually does not read its mail. -.Pp -The format of a cron command is very much the V7 standard, with a number of -upward-compatible extensions. -Each line has five time and date fields, -followed by a user name -(with optional ``:'' and ``/'' suffixes) -if this is the system crontab file, -followed by a command. -Commands are executed by -.Xr cron 8 -when the minute, hour, and month of year fields match the current time, -.Em and -when at least one of the two day fields (day of month, or day of week) -matches the current time (see ``Note'' below). -.Xr cron 8 -examines cron entries once every minute. -The time and date fields are: -.Bd -literal -offset indent -field allowed values ------ -------------- -minute 0-59 -hour 0-23 -day of month 1-31 -month 1-12 (or names, see below) -day of week 0-7 (0 or 7 is Sun, or use names) -.Ed -.Pp -A field may be an asterisk (*), which always stands for ``first\-last''. -.Pp -Ranges of numbers are allowed. -Ranges are two numbers separated -with a hyphen. -The specified range is inclusive. -For example, -8-11 for an ``hours'' entry specifies execution at hours 8, 9, 10 -and 11. -.Pp -Lists are allowed. -A list is a set of numbers (or ranges) -separated by commas. -Examples: ``1,2,5,9'', ``0-4,8-12''. -.Pp -Step values can be used in conjunction with ranges. -Following -a range with ``/'' specifies skips of the number's value -through the range. -For example, ``0-23/2'' can be used in the hours -field to specify command execution every other hour (the alternative -in the V7 standard is ``0,2,4,6,8,10,12,14,16,18,20,22''). -Steps are -also permitted after an asterisk, so if you want to say ``every two -hours'', just use ``*/2''. -.Pp -Names can also be used for the ``month'' and ``day of week'' -fields. -Use the first three letters of the particular -day or month (case does not matter). -Ranges or -lists of names are not allowed. -.Pp -The ``sixth'' field (the rest of the line) specifies the command to be -run. -The entire command portion of the line, up to a newline or % -character, will be executed by -.Pa /bin/sh -or by the shell -specified in the -.Ev SHELL -variable of the cronfile. -Percent-signs (%) in the command, unless escaped with backslash -(\\), will be changed into newline characters, and all data -after the first % will be sent to the command as standard -input. -.Pp -Note: The day of a command's execution can be specified by two -fields \(em day of month, and day of week. -If both fields are -restricted (ie, are not *), the command will be run when -.Em either -field matches the current time. -For example, -``30 4 1,15 * 5'' -would cause a command to be run at 4:30 am on the 1st and 15th of each -month, plus every Friday. -.Pp -Instead of the first five fields, -one of eight special strings may appear: -.Bd -literal -offset indent -string meaning ------- ------- -@reboot Run once, at startup. -@yearly Run once a year, "0 0 1 1 *". -@annually (same as @yearly) -@monthly Run once a month, "0 0 1 * *". -@weekly Run once a week, "0 0 * * 0". -@daily Run once a day, "0 0 * * *". -@midnight (same as @daily) -@hourly Run once an hour, "0 * * * *". -.Ed -.Sh EXAMPLE CRON FILE -.Bd -literal - -# use /bin/sh to run commands, overriding the default set by cron -SHELL=/bin/sh -# mail any output to `paul', no matter whose crontab this is -MAILTO=paul -# -# run five minutes after midnight, every day -5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 -# run at 2:15pm on the first of every month -- output mailed to paul -15 14 1 * * $HOME/bin/monthly -# run at 10 pm on weekdays, annoy Joe -0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?% -23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday" -5 4 * * sun echo "run at 5 after 4 every sunday" -.Ed -.Sh SEE ALSO -.Xr crontab 1 , -.Xr cron 8 -.Sh EXTENSIONS -When specifying day of week, both day 0 and day 7 will be considered Sunday. -.Bx -and -.Tn ATT -seem to disagree about this. -.Pp -Lists and ranges are allowed to co-exist in the same field. -"1-3,7-9" would -be rejected by -.Tn ATT -or -.Bx -cron -- they want to see "1-3" or "7,8,9" ONLY. -.Pp -Ranges can include "steps", so "1-9/2" is the same as "1,3,5,7,9". -.Pp -Names of months or days of the week can be specified by name. -.Pp -Environment variables can be set in the crontab. -In -.Bx -or -.Tn ATT , -the -environment handed to child processes is basically the one from -.Pa /etc/rc . -.Pp -Command output is mailed to the crontab owner -.No ( Bx -cannot do this), can be -mailed to a person other than the crontab owner (SysV cannot do this), or the -feature can be turned off and no mail will be sent at all (SysV cannot do this -either). -.Pp -All of the -.Sq @ -commands that can appear in place of the first five fields -are extensions. -.Sh AUTHORS -.An Paul Vixie Aq paul@vix.com -.Sh BUGS -If you are in one of the 70-odd countries that observe Daylight -Savings Time, jobs scheduled during the rollback or advance will be -affected. -In general, it is not a good idea to schedule jobs during -this period. -.Pp -For US timezones (except parts of IN, AZ, and HI) the time shift occurs at -2AM local time. -For others, the output of the -.Xr zdump 8 -program's verbose -.Fl ( v ) -option can be used to determine the moment of time shift. diff --git a/usr.sbin/cron/crontab/crontab.c b/usr.sbin/cron/crontab/crontab.c deleted file mode 100644 index f7af626..0000000 --- a/usr.sbin/cron/crontab/crontab.c +++ /dev/null @@ -1,626 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - * From Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - -/* crontab - install and manage per-user crontab files - * vix 02may87 [RCS has the rest of the log] - * vix 26jan87 [original] - */ - -#define MAIN_PROGRAM - -#include "cron.h" -#include -#include -#include -#include -#include -#include -#ifdef USE_UTIMES -# include -#else -# include -# include -#endif -#if defined(POSIX) -# include -#endif - -#define MD5_SIZE 33 -#define NHEADER_LINES 3 - - -enum opt_t { opt_unknown, opt_list, opt_delete, opt_edit, opt_replace }; - -#if DEBUGGING -static char *Options[] = { "???", "list", "delete", "edit", "replace" }; -#endif - - -static PID_T Pid; -static char User[MAX_UNAME], RealUser[MAX_UNAME]; -static char Filename[MAX_FNAME]; -static FILE *NewCrontab; -static int CheckErrorCount; -static enum opt_t Option; -static struct passwd *pw; -static void list_cmd(void), - delete_cmd(void), - edit_cmd(void), - poke_daemon(void), - check_error(char *), - parse_args(int c, char *v[]); -static int replace_cmd(void); - - -static void -usage(char *msg) -{ - fprintf(stderr, "crontab: usage error: %s\n", msg); - fprintf(stderr, "%s\n%s\n", - "usage: crontab [-u user] file", - " crontab [-u user] { -e | -l | -r }"); - exit(ERROR_EXIT); -} - - -int -main(int argc, char *argv[]) -{ - int exitstatus; - - Pid = getpid(); - ProgramName = argv[0]; - -#if defined(POSIX) - setlocale(LC_ALL, ""); -#endif - -#if defined(BSD) - setlinebuf(stderr); -#endif - parse_args(argc, argv); /* sets many globals, opens a file */ - set_cron_uid(); - set_cron_cwd(); - if (!allowed(User)) { - warnx("you (%s) are not allowed to use this program", User); - log_it(RealUser, Pid, "AUTH", "crontab command not allowed"); - exit(ERROR_EXIT); - } - exitstatus = OK_EXIT; - switch (Option) { - case opt_list: list_cmd(); - break; - case opt_delete: delete_cmd(); - break; - case opt_edit: edit_cmd(); - break; - case opt_replace: if (replace_cmd() < 0) - exitstatus = ERROR_EXIT; - break; - case opt_unknown: - break; - } - exit(exitstatus); - /*NOTREACHED*/ -} - - -static void -parse_args(argc, argv) - int argc; - char *argv[]; -{ - int argch; - char resolved_path[PATH_MAX]; - - if (!(pw = getpwuid(getuid()))) - errx(ERROR_EXIT, "your UID isn't in the passwd file, bailing out"); - bzero(pw->pw_passwd, strlen(pw->pw_passwd)); - (void) strncpy(User, pw->pw_name, (sizeof User)-1); - User[(sizeof User)-1] = '\0'; - strcpy(RealUser, User); - Filename[0] = '\0'; - Option = opt_unknown; - while ((argch = getopt(argc, argv, "u:lerx:")) != -1) { - switch (argch) { - case 'x': - if (!set_debug_flags(optarg)) - usage("bad debug option"); - break; - case 'u': - if (getuid() != ROOT_UID) - errx(ERROR_EXIT, "must be privileged to use -u"); - if (!(pw = getpwnam(optarg))) - errx(ERROR_EXIT, "user `%s' unknown", optarg); - bzero(pw->pw_passwd, strlen(pw->pw_passwd)); - (void) strncpy(User, pw->pw_name, (sizeof User)-1); - User[(sizeof User)-1] = '\0'; - break; - case 'l': - if (Option != opt_unknown) - usage("only one operation permitted"); - Option = opt_list; - break; - case 'r': - if (Option != opt_unknown) - usage("only one operation permitted"); - Option = opt_delete; - break; - case 'e': - if (Option != opt_unknown) - usage("only one operation permitted"); - Option = opt_edit; - break; - default: - usage("unrecognized option"); - } - } - - endpwent(); - - if (Option != opt_unknown) { - if (argv[optind] != NULL) { - usage("no arguments permitted after this option"); - } - } else { - if (argv[optind] != NULL) { - Option = opt_replace; - (void) strncpy (Filename, argv[optind], (sizeof Filename)-1); - Filename[(sizeof Filename)-1] = '\0'; - - } else { - usage("file name must be specified for replace"); - } - } - - if (Option == opt_replace) { - /* we have to open the file here because we're going to - * chdir(2) into /var/cron before we get around to - * reading the file. - */ - if (!strcmp(Filename, "-")) { - NewCrontab = stdin; - } else if (realpath(Filename, resolved_path) != NULL && - !strcmp(resolved_path, SYSCRONTAB)) { - err(ERROR_EXIT, SYSCRONTAB " must be edited manually"); - } else { - /* relinquish the setuid status of the binary during - * the open, lest nonroot users read files they should - * not be able to read. we can't use access() here - * since there's a race condition. thanks go out to - * Arnt Gulbrandsen for spotting - * the race. - */ - - if (swap_uids() < OK) - err(ERROR_EXIT, "swapping uids"); - if (!(NewCrontab = fopen(Filename, "r"))) - err(ERROR_EXIT, "%s", Filename); - if (swap_uids_back() < OK) - err(ERROR_EXIT, "swapping uids back"); - } - } - - Debug(DMISC, ("user=%s, file=%s, option=%s\n", - User, Filename, Options[(int)Option])) -} - -static void -copy_file(FILE *in, FILE *out) { - int x, ch; - - Set_LineNum(1) - /* ignore the top few comments since we probably put them there. - */ - for (x = 0; x < NHEADER_LINES; x++) { - ch = get_char(in); - if (EOF == ch) - break; - if ('#' != ch) { - putc(ch, out); - break; - } - while (EOF != (ch = get_char(in))) - if (ch == '\n') - break; - if (EOF == ch) - break; - } - - /* copy the rest of the crontab (if any) to the output file. - */ - if (EOF != ch) - while (EOF != (ch = get_char(in))) - putc(ch, out); -} - -static void -list_cmd() { - char n[MAX_FNAME]; - FILE *f; - - log_it(RealUser, Pid, "LIST", User); - (void) snprintf(n, sizeof(n), CRON_TAB(User)); - if (!(f = fopen(n, "r"))) { - if (errno == ENOENT) - errx(ERROR_EXIT, "no crontab for %s", User); - else - err(ERROR_EXIT, "%s", n); - } - - /* file is open. copy to stdout, close. - */ - copy_file(f, stdout); - fclose(f); -} - - -static void -delete_cmd() { - char n[MAX_FNAME]; - int ch, first; - - if (isatty(STDIN_FILENO)) { - (void)fprintf(stderr, "remove crontab for %s? ", User); - first = ch = getchar(); - while (ch != '\n' && ch != EOF) - ch = getchar(); - if (first != 'y' && first != 'Y') - return; - } - - log_it(RealUser, Pid, "DELETE", User); - (void) snprintf(n, sizeof(n), CRON_TAB(User)); - if (unlink(n)) { - if (errno == ENOENT) - errx(ERROR_EXIT, "no crontab for %s", User); - else - err(ERROR_EXIT, "%s", n); - } - poke_daemon(); -} - - -static void -check_error(msg) - char *msg; -{ - CheckErrorCount++; - fprintf(stderr, "\"%s\":%d: %s\n", Filename, LineNumber-1, msg); -} - - -static void -edit_cmd() { - char n[MAX_FNAME], q[MAX_TEMPSTR], *editor; - FILE *f; - int t; - struct stat statbuf, fsbuf; - WAIT_T waiter; - PID_T pid, xpid; - mode_t um; - int syntax_error = 0; - char orig_md5[MD5_SIZE]; - char new_md5[MD5_SIZE]; - - log_it(RealUser, Pid, "BEGIN EDIT", User); - (void) snprintf(n, sizeof(n), CRON_TAB(User)); - if (!(f = fopen(n, "r"))) { - if (errno != ENOENT) - err(ERROR_EXIT, "%s", n); - warnx("no crontab for %s - using an empty one", User); - if (!(f = fopen(_PATH_DEVNULL, "r"))) - err(ERROR_EXIT, _PATH_DEVNULL); - } - - um = umask(077); - (void) snprintf(Filename, sizeof(Filename), "/tmp/crontab.XXXXXXXXXX"); - if ((t = mkstemp(Filename)) == -1) { - warn("%s", Filename); - (void) umask(um); - goto fatal; - } - (void) umask(um); -#ifdef HAS_FCHOWN - if (fchown(t, getuid(), getgid()) < 0) { -#else - if (chown(Filename, getuid(), getgid()) < 0) { -#endif - warn("fchown"); - goto fatal; - } - if (!(NewCrontab = fdopen(t, "r+"))) { - warn("fdopen"); - goto fatal; - } - - copy_file(f, NewCrontab); - fclose(f); - if (fflush(NewCrontab)) - err(ERROR_EXIT, "%s", Filename); - if (fstat(t, &fsbuf) < 0) { - warn("unable to fstat temp file"); - goto fatal; - } - again: - if (stat(Filename, &statbuf) < 0) { - warn("stat"); - fatal: unlink(Filename); - exit(ERROR_EXIT); - } - if (statbuf.st_dev != fsbuf.st_dev || statbuf.st_ino != fsbuf.st_ino) - errx(ERROR_EXIT, "temp file must be edited in place"); - if (MD5File(Filename, orig_md5) == NULL) { - warn("MD5"); - goto fatal; - } - - if ((!(editor = getenv("VISUAL"))) - && (!(editor = getenv("EDITOR"))) - ) { - editor = EDITOR; - } - - /* we still have the file open. editors will generally rewrite the - * original file rather than renaming/unlinking it and starting a - * new one; even backup files are supposed to be made by copying - * rather than by renaming. if some editor does not support this, - * then don't use it. the security problems are more severe if we - * close and reopen the file around the edit. - */ - - switch (pid = fork()) { - case -1: - warn("fork"); - goto fatal; - case 0: - /* child */ - if (setuid(getuid()) < 0) - err(ERROR_EXIT, "setuid(getuid())"); - if (chdir("/tmp") < 0) - err(ERROR_EXIT, "chdir(/tmp)"); - if (strlen(editor) + strlen(Filename) + 2 >= MAX_TEMPSTR) - errx(ERROR_EXIT, "editor or filename too long"); - execlp(editor, editor, Filename, (char *)NULL); - err(ERROR_EXIT, "%s", editor); - /*NOTREACHED*/ - default: - /* parent */ - break; - } - - /* parent */ - { - void (*sig[3])(int signal); - sig[0] = signal(SIGHUP, SIG_IGN); - sig[1] = signal(SIGINT, SIG_IGN); - sig[2] = signal(SIGTERM, SIG_IGN); - xpid = wait(&waiter); - signal(SIGHUP, sig[0]); - signal(SIGINT, sig[1]); - signal(SIGTERM, sig[2]); - } - if (xpid != pid) { - warnx("wrong PID (%d != %d) from \"%s\"", xpid, pid, editor); - goto fatal; - } - if (WIFEXITED(waiter) && WEXITSTATUS(waiter)) { - warnx("\"%s\" exited with status %d", editor, WEXITSTATUS(waiter)); - goto fatal; - } - if (WIFSIGNALED(waiter)) { - warnx("\"%s\" killed; signal %d (%score dumped)", - editor, WTERMSIG(waiter), WCOREDUMP(waiter) ?"" :"no "); - goto fatal; - } - if (stat(Filename, &statbuf) < 0) { - warn("stat"); - goto fatal; - } - if (statbuf.st_dev != fsbuf.st_dev || statbuf.st_ino != fsbuf.st_ino) - errx(ERROR_EXIT, "temp file must be edited in place"); - if (MD5File(Filename, new_md5) == NULL) { - warn("MD5"); - goto fatal; - } - if (strcmp(orig_md5, new_md5) == 0 && !syntax_error) { - warnx("no changes made to crontab"); - goto remove; - } - warnx("installing new crontab"); - switch (replace_cmd()) { - case 0: /* Success */ - break; - case -1: /* Syntax error */ - for (;;) { - printf("Do you want to retry the same edit? "); - fflush(stdout); - q[0] = '\0'; - (void) fgets(q, sizeof q, stdin); - switch (islower(q[0]) ? q[0] : tolower(q[0])) { - case 'y': - syntax_error = 1; - goto again; - case 'n': - goto abandon; - default: - fprintf(stderr, "Enter Y or N\n"); - } - } - /*NOTREACHED*/ - case -2: /* Install error */ - abandon: - warnx("edits left in %s", Filename); - goto done; - default: - warnx("panic: bad switch() in replace_cmd()"); - goto fatal; - } - remove: - unlink(Filename); - done: - log_it(RealUser, Pid, "END EDIT", User); -} - - -/* returns 0 on success - * -1 on syntax error - * -2 on install error - */ -static int -replace_cmd() { - char n[MAX_FNAME], envstr[MAX_ENVSTR], tn[MAX_FNAME]; - FILE *tmp; - int ch, eof; - entry *e; - time_t now = time(NULL); - char **envp = env_init(); - - if (envp == NULL) { - warnx("cannot allocate memory"); - return (-2); - } - - (void) snprintf(n, sizeof(n), "tmp.%d", Pid); - (void) snprintf(tn, sizeof(tn), CRON_TAB(n)); - - if (!(tmp = fopen(tn, "w+"))) { - warn("%s", tn); - return (-2); - } - - /* write a signature at the top of the file. - * - * VERY IMPORTANT: make sure NHEADER_LINES agrees with this code. - */ - fprintf(tmp, "# DO NOT EDIT THIS FILE - edit the master and reinstall.\n"); - fprintf(tmp, "# (%s installed on %-24.24s)\n", Filename, ctime(&now)); - fprintf(tmp, "# (Cron version -- %s)\n", rcsid); - - /* copy the crontab to the tmp - */ - rewind(NewCrontab); - Set_LineNum(1) - while (EOF != (ch = get_char(NewCrontab))) - putc(ch, tmp); - ftruncate(fileno(tmp), ftell(tmp)); - fflush(tmp); rewind(tmp); - - if (ferror(tmp)) { - warnx("error while writing new crontab to %s", tn); - fclose(tmp); unlink(tn); - return (-2); - } - - /* check the syntax of the file being installed. - */ - - /* BUG: was reporting errors after the EOF if there were any errors - * in the file proper -- kludged it by stopping after first error. - * vix 31mar87 - */ - Set_LineNum(1 - NHEADER_LINES) - CheckErrorCount = 0; eof = FALSE; - while (!CheckErrorCount && !eof) { - switch (load_env(envstr, tmp)) { - case ERR: - eof = TRUE; - break; - case FALSE: - e = load_entry(tmp, check_error, pw, envp); - if (e) - free(e); - break; - case TRUE: - break; - } - } - - if (CheckErrorCount != 0) { - warnx("errors in crontab file, can't install"); - fclose(tmp); unlink(tn); - return (-1); - } - -#ifdef HAS_FCHOWN - if (fchown(fileno(tmp), ROOT_UID, -1) < OK) -#else - if (chown(tn, ROOT_UID, -1) < OK) -#endif - { - warn("chown"); - fclose(tmp); unlink(tn); - return (-2); - } - -#ifdef HAS_FCHMOD - if (fchmod(fileno(tmp), 0600) < OK) -#else - if (chmod(tn, 0600) < OK) -#endif - { - warn("chown"); - fclose(tmp); unlink(tn); - return (-2); - } - - if (fclose(tmp) == EOF) { - warn("fclose"); - unlink(tn); - return (-2); - } - - (void) snprintf(n, sizeof(n), CRON_TAB(User)); - if (rename(tn, n)) { - warn("error renaming %s to %s", tn, n); - unlink(tn); - return (-2); - } - - log_it(RealUser, Pid, "REPLACE", User); - - poke_daemon(); - - return (0); -} - - -static void -poke_daemon() { -#ifdef USE_UTIMES - struct timeval tvs[2]; - struct timezone tz; - - (void) gettimeofday(&tvs[0], &tz); - tvs[1] = tvs[0]; - if (utimes(SPOOL_DIR, tvs) < OK) { - warn("can't update mtime on spooldir %s", SPOOL_DIR); - return; - } -#else - if (utime(SPOOL_DIR, NULL) < OK) { - warn("can't update mtime on spooldir %s", SPOOL_DIR); - return; - } -#endif /*USE_UTIMES*/ -} diff --git a/usr.sbin/cron/doc/CHANGES b/usr.sbin/cron/doc/CHANGES deleted file mode 100644 index 59f6803..0000000 --- a/usr.sbin/cron/doc/CHANGES +++ /dev/null @@ -1,155 +0,0 @@ -Vixie Cron Changes from V2 to V3 -Paul Vixie -29-Dec-1993 - -The crontab command now conforms to POSIX 1003.2. This means that when you -install it, if you have any "crontab" command lines floating around in shell -scripts (such as /etc/rc or /etc/rc.local), you will need to change them. - -I have integrated several changes made by BSDi for their BSD/386 operating -system; these were offerred to me before I started consulting for them, so -it is safe to say that they were intended for publication. Most notably, -the name of the cron daemon has changed from "crond" to "cron". This was -done for compatibility with 4.3BSD. Another change made for the same reason -is the ability to read in an /etc/crontab file which has an extra field in -each entry, between the time fields and the command. This field is a user -name, and it permits the /etc/crontab command to contain commands which are -to be run by any user on the system. /etc/crontab is not "installed" via -the crontab(1) command; it is automatically read at startup time and it will -be reread whenever it changes. - -I also added a "-e" option to crontab(1). Nine people also sent me diffs -to add this option, but I had already implemented it on my own. I actually -released an interrim version (V2.2, I think) for limited testing, and got a -chance to fix a bad security bug in the "-e" option thanks to XXX. - -The daemon used to be extraordinarily sloppy in its use of file descriptors. -A heck of a lot of them were left open in spawned jobs, which caused problems -for the daemon and also caused problems with the spawned jobs if they were -shell scripts since "sh" and "csh" have traditionally used hidden file -descriptors to pass information to subshells, and cron was causing them to -think they were subshells. If you had trouble with "sh" or "csh" scripts in -V2, chances are good that V3 will fix your problems. - -About a dozen people have reminded me that I forgot to initialize -"crontab_fd" in database.c. Keith Cantrell was the first, so he gets the -point. - -Steve Simmons reminded me that once an account has been deleted from the -system, "crontab -u USER -d" will not work. My solution is to suggest to -all of you that before you delete a user's account, you first delete that -user's crontab file if any. From cron's point of view, usernames can never -be treated as arbitrary strings. Either they are valid user names, or they -are not. I will not make an exception for the "-d" case, for security -reasons that I consider reasonable. It is trivial for a root user to delete -the entry by hand if necessary. - -Dan O'Neil reminded me that I forgot to reset "log_fd" in misc.c. A lot of -others also reminded me of this, but Dan gets the point. I didn't fix it -there, since the real bug was that it should have been open in the parent. - -Peter Kabal reminded me that I forgot to "#ifdef DEBUGGING" some code in -misc.c. Hans Trompert actually told me first, but Peter sent the patch so -he gets the point. - -Russell Nelson told me that I'd forgotten to "#include " in misc.c, -which explains why a lot of other people complained that it wasn't using -syslog even when they configured it that way :-). Steve Simmons told me -first, though, so he gets the point. - -An interrim version of the daemon tried to "stat" every file before -executing it; this turned out to be a horribly bad idea since finding the -name of a file from a shell command is a hard job (that's why we have -shells, right?) I removed this bogus code. Dave Burgess gets the point. - -Dennis R. Conley sent a suggestion for MMDF systems, which I've added to the -comments in cron.h. - -Mike Heisler noted that I use comments in the CONVERSION file which are -documented as illegal in the man pages. Thanks, Mike. - -Irving Wolfe sent me some very cheerful changes for a NeXT system, but I -consider the system itself broken and I can't bring myself to #ifdef for -something as screwed up as this system seems to be. However, various others -did send me smaller patches which appear to have cause cron to build and run -correctly on (the latest) NeXT machines, with or without the "-posix" CFLAG. -Irving also asked for a per-job MAILTO, and this was finally added later when -I integrated the BSD/386 changes contributed by BSDi, and generalized some of -the parsing. - -Lots of folks complained that the autogenerated "Date:" header wasn't in -ARPA format. I didn't understand this -- either folks will use Sendmail and -not generate a Date: at all (since Sendmail will do it), or folks will use -something other than Sendmail which won't care about Date: formats. But -I've "fixed" it anyway... - -Several people suggested that "*" should be able to take a "/step". One person -suggested that "N/step" ought to mean "N-last/step", but that's stretching things -a bit far. "*/step" seems quite intuitive to me, so I've added it. Colin Plumb -sent in the first and most polite request for this feature. - -As with every release of Cron, BIND, and seemingly everything else I do, one -user stands out with the most critical but also the most useful analysis. -Cron V3's high score belongs to Peter Holzer, who sent in the nicest looking -patch for the "%" interpretation problem and also helped me understand a -tricky bit of badness in the "log_fd" problem. - -agulbra@flode.nvg.unit.no wins the honors for being the first to point out the -nasty security hole in "crontab -r". 'Nuff said. - -Several folks pointed out that log_it() needed to exist even if logging was -disabled. Some day I will create a tool that will compile a subsystem with -every possible combination and permutation of #ifdef options, but meanwhile -thanks to everybody. - -job_runqueue() was using storage after freeing it, since Jordan told me back -in 1983 that C let you do that, and I believed him in 1986 when I wrote all -this junk. Linux was the first to die from this error, and the Linux people -sent me the most amazing, um, collection of patches for this problem. Thanks -for all the fish. - -Jeremy Bettis reminded me that popen() isn't safe. I grabbed Ken Arnold's -version of popen/pclose from the ftpd and hacked it to taste. We're safe now, -from this at least. - -Branko Lankester sent me a very timely and helpful fix for a looming security -problem in my "crontab -e" implementation. - --------- - -Vixie Cron Changes from V1 to V2 -Paul Vixie -8-Feb-1988 - -Many changes were made in a rash of activity about six months ago, the exact -list of which is no longer clear in my memory. I know that V1 used a file -called POKECRON in /usr/spool/cron to tell it that it was time to re-read -all the crontab files; V2 uses the modtime the crontab directory as a flag to -check out the crontab files; those whose modtime has changed will be re-read, -and the others left alone. Note that the crontab(1) command will do a utimes -call to make sure the mtime of the dir changes, since the filename/inode will -often remain the same after a replacement and the mtime wouldn't change in -that case. - -8-Feb-88: made it possible to use much larger environment variable strings. - V1 allowed 100 characters; V2 allows 1000. This was needed for PATH - variables on some systems. Thanks to Toerless Eckert for this idea. - E-mail: UUCP: ...pyramid!fauern!faui10!eckert - -16-Feb-88: added allow/deny, moved /usr/spool/cron/crontabs to - /usr/lib/cron/tabs. allow and deny are /usr/lib/cron/{allow,deny}, - since the sysv naming for this depends on 'at' using the same - dir, which would be stupid (hint: use /usr/{lib,spool}/at). - -22-Feb-88: made it read the spool directory for crontabs and look each one - up using getpwnam() rather than reading all passwds with getpwent() - and trying to open each crontab. - -9-Dec-88: made it sync to :00 after the minute, makes cron predictable. - added logging to /var/cron/log. - -14-Apr-90: (actually, changes since December 1989) - fixed a number of bugs reported from the net and from John Gilmore. - added syslog per Keith Bostic. security features including not - being willing to run a command owned or writable by other than - the owner of the crontab 9not working well yet) diff --git a/usr.sbin/cron/doc/CONVERSION b/usr.sbin/cron/doc/CONVERSION deleted file mode 100644 index f30df7d..0000000 --- a/usr.sbin/cron/doc/CONVERSION +++ /dev/null @@ -1,85 +0,0 @@ -$FreeBSD$ - -Conversion of BSD 4.[23] crontab files: - -Edit your current crontab (/usr/lib/crontab) into little pieces, with each -users' commands in a different file. This is different on 4.2 and 4.3, -but I'll get to that below. The biggest feature of this cron is that you -can move 'news' and 'uucp' cron commands into files owned and maintainable -by those two users. You also get to rip all the fancy 'su' footwork out -of the cron commands. On 4.3, there's no need for the 'su' stuff since the -user name appears on each command -- but I'd still rather have separate -crontabs with separate environments and so on. - -Leave the original /usr/lib/crontab! This cron doesn't use it, so you may -as well keep it around for a while in case something goes wakko with this -fancy version. - -Most commands in most crontabs are run by root, have to run by root, and -should continue to be run by root. They still have to be in their own file; -I recommend /etc/crontab.src or /usr/adm/crontab.src. - -'uucp's commands need their own file; how about /usr/lib/uucp/crontab.src? -'news' also, perhaps in /usr/lib/news/crontab.src... - -I say `how about' and `perhaps' because it really doesn't matter to anyone -(except you) where you put the crontab source files. The `crontab' command -COPIES them into a protected directory (CRONDIR/SPOOL_DIR in cron.h), named -after the user whose crontab it is. If you want to examine, replace, or -delete a crontab, the `crontab' command does all of those things. The -various `crontab.src' (my suggested name for them) files are just source -files---they have to be copied to SPOOLDIR using `crontab' before they'll be -executed. - -On 4.2, your crontab might have a few lines like this: - - 5 * * * * su uucp < /usr/lib/uucp/uudemon.hr - 10 4 * * * su uucp < /usr/lib/uucp/uudemon.day - 15 5 * * 0 su uucp < /usr/lib/uucp/uudemon.wk - -...or like this: - - 5 * * * * echo /usr/lib/uucp/uudemon.hr | su uucp - 10 4 * * * echo /usr/lib/uucp/uudemon.day | su uucp - 15 5 * * 0 echo /usr/lib/uucp/uudemon.wk | su uucp - -On 4.3, they'd look a little bit better, but not much: - - 5 * * * * uucp /usr/lib/uucp/uudemon.hr - 10 4 * * * uucp /usr/lib/uucp/uudemon.day - 15 5 * * 0 uucp /usr/lib/uucp/uudemon.wk - -For this cron, you'd create /usr/lib/uucp/crontab.src (or wherever you want -to keep uucp's commands) which would look like this: - - # /usr/lib/uucp/crontab.src - uucp's crontab - # - PATH=/usr/lib/uucp:/bin:/usr/bin - SHELL=/bin/sh - HOME=/usr/lib/uucp - # - 5 * * * * uudemon.hr - 10 4 * * * uudemon.day - 15 5 * * 0 uudemon.wk - -The application to the `news' cron commands (if any) is left for you to -figure out. Likewise if there are any other cruddy-looking 'su' commands in -your crontab commands, you don't need them anymore: just find a good place -to put the `crontab.src' (or whatever you want to call it) file for that -user, put the cron commands into it, and install it using the `crontab' -command (probably with "-u USERNAME", but see the man page). - -If you run a 4.2-derived cron, you could of course just install your current -crontab in toto as root's crontab. It would work exactly the way your -current one does, barring the extra steps in installing or changing it. -There would still be advantages to this cron, mostly that you get mail if -there is any output from your cron commands. - -One note about getting mail from cron: you will probably find, after you -install this version of cron, that your cron commands are generating a lot -of irritating output. The work-around for this is to redirect all EXPECTED -output to a per-execution log file, which you can examine if you want to -see the output from the "last time" a command was executed; if you get any -UNEXPECTED output, it will be mailed to you. This takes a while to get -right, but it's amazingly convenient. Trust me. - diff --git a/usr.sbin/cron/doc/FEATURES b/usr.sbin/cron/doc/FEATURES deleted file mode 100644 index 821d1f3..0000000 --- a/usr.sbin/cron/doc/FEATURES +++ /dev/null @@ -1,84 +0,0 @@ -$FreeBSD$ - -Features of Vixie's cron relative to BSD 4.[23] and SysV crons: - --- Environment variables can be set in each crontab. SHELL, USER, - LOGNAME, and HOME are set from the user's passwd entry; all except - USER can be changed in the crontab. PATH is especially useful to - set there. TZ can be set, but cron ignores it other than passing - it on through to the commands it runs. Format is - - variable=value - - Blanks surrounding the '=' will be eaten; other blanks in value are - okay. Leading or trailing blanks can be preserved by quoting, single - or double quotes are okay, just so they match. - - PATH=.:/bin:/usr/bin - SHELL=/bin/sh - FOOBAR = this is a long blanky example - - Above, FOOBAR would get "this is a long blanky example" as its value. - - SHELL and HOME will be used when it's time to run a command; if - you don't set them, HOME defaults to your /etc/passwd entry - and SHELL defaults to /bin/sh. - - MAILTO, if set to the login name of a user on your system, will be the - person that cron mails the output of commands in that crontab. This is - useful if you decide on BINMAIL when configuring cron.h, since binmail - doesn't know anything about aliasing. - --- Weekdays can be specified by name. Case is not significant, but only - the first three letters should be specified. - --- Months can likewise be specified by name. Three letters only. - --- Ranges and lists can be mixed. Standard crons won't allow '1,3-5'. - --- Ranges can specify 'step' values. '10-16/2' is like '10,12,14,16'. - --- Sunday is both day 0 and day 7 -- apparently BSD and ATT disagree - about this. - --- Each user gets their own crontab file. This is a win over BSD 4.2, - where only root has one, and over BSD 4.3, where they made the crontab - format incompatible and although the commands can be run by non-root - uid's, root is still the only one who can edit the crontab file. This - feature mimics the SysV cron. - --- The 'crontab' command is loosely compatible with SysV, but has more - options which just generally make more sense. Running crontab with - no arguments will print a cute little summary of the command syntax. - --- Comments and blank lines are allowed in the crontab file. Comments - must be on a line by themselves; leading whitespace is ignored, and - a '#' introduces the comment. - --- (big win) If the `crontab' command changes anything in any crontab, - the 'cron' daemon will reload all the tables before running the - next iteration. In some crons, you have to kill and restart the - daemon whenever you change a crontab. In other crons, the crontab - file is reread and reparsed every minute even if it didn't change. - --- In order to support the automatic reload, the crontab files are not - readable or writable except by 'crontab' or 'cron'. This is not a - problem, since 'crontab' will let you do pretty much whatever you - want to your own crontab, or if you are root, to anybody's crontab. - --- If any output is generated by a command (on stdout OR stderr), it will - be mailed to the owner of the crontab that contained the command (or - MAILTO, see discussion of environment variables, above). The headers - of the mail message will include the command that was run, and a - complete list of the environment that was passed to it, which will - contain (at least) the USER (LOGNAME on SysV), HOME, and SHELL. - --- the dom/dow situation is odd. '* * 1,15 * Sun' will run on the - first and fifteenth AND every Sunday; '* * * * Sun' will run *only* - on Sundays; '* * 1,15 * *' will run *only* the 1st and 15th. this - is why we keep 'e->dow_star' and 'e->dom_star'. I didn't think up - this behaviour; it's how cron has always worked but the documentation - hasn't been very clear. I have been told that some AT&T crons do not - act this way and do the more reasonable thing, which is (IMHO) to "or" - the various field-matches together. In that sense this cron may not - be completely similar to some AT&T crons. diff --git a/usr.sbin/cron/doc/INSTALL b/usr.sbin/cron/doc/INSTALL deleted file mode 100644 index 7f4c997..0000000 --- a/usr.sbin/cron/doc/INSTALL +++ /dev/null @@ -1,87 +0,0 @@ -/* Copyright 1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -$FreeBSD$ - -Read the comments at the top of the Makefile, then edit the area marked -'configurable stuff'. - -Edit config.h. The stuff I expect you to change is down a bit from the -top of the file, but it's clearly marked. Also look at pathnames.h. - -You don't have to create the /var/cron or /var/cron/tabs directories, since -both the daemon and the `crontab' program will do this the first time they -run if they don't exist. You do need to have a /var, though -- just "mkdir -/var" if you don't have one, or you can "mkdir /usr/var; ln -s /usr/var /var" -if you expect your /var to have a lot of stuff in it. - -You will also need /usr/local/etc and /usr/local/bin directories unless you -change the Makefile. These will have to be created by hand, but if you are -a long-time Usenet user you probably have them already. /usr/local/man is -where I keep my man pages, but I have the source for `man' and you probably -do not. Therefore you may have to put the man pages into /usr/man/manl, -which will be hard since there will be name collisions. (Note that the man -command was originally written by Bill Joy before he left Berkeley, and it -contains no AT&T code, so it is in UUNET's archive of freely-distributable -BSD code.) - -LINUX note: /usr/include/paths.h on some linux systems shows _PATH_SENDMAIL - to be /usr/bin/sendmail even though sendmail is installed in /usr/lib. - you should check this out. - -say: - make all - -su and say: - make install - -Note that if I can get you to "su and say" something just by asking, you have -a very serious security problem on your system and you should look into it. - -Edit your /usr/lib/crontab file into little pieces -- see the CONVERSION file -for help on this. - -Use the `crontab' command to install all the little pieces you just created. -Some examples (see below before trying any of these!) - - crontab -u uucp -r /usr/lib/uucp/crontab.src - crontab -u news -r /usr/lib/news/crontab.src - crontab -u root -r /usr/adm/crontab.src - -Notes on above examples: (1) the .src files are copied at the time the -command is issued; changing the source files later will have no effect until -they are reinstalled with another `crontab -r' command. (2) The crontab -command will affect the crontab of the person using the command unless `-u -USER' is given; `-u' only works for root. When using most `su' commands -under most BSD's, `crontab' will still think of you as yourself even though -you may think of yourself as root -- so use `-u' liberally. (3) the `-r' -option stands for `replace'; check the man page for crontab(1) for other -possibilities. - -Kill your existing cron daemon -- do `ps aux' and look for /etc/cron. - -Edit your /etc/rc or /etc/rc.local, looking for the line that starts up -/etc/cron. Comment it out and add a line to start the new cron daemon --- usually /usr/local/etc/cron, unless you changed it in the Makefile. - -Start up this cron daemon yourself as root. Just type /usr/local/etc/cron -(or whatever); no '&' is needed since the daemon forks itself and the -process you executed returns immediately. - -ATT notes: for those people unfortunate enough to be stuck on a AT&T UNIX, -you will need the public-domain "libndir", found in the B News source and in -any comp.sources.unix archive. You will also need to hack the code some. diff --git a/usr.sbin/cron/doc/MAIL b/usr.sbin/cron/doc/MAIL deleted file mode 100644 index 3549e94..0000000 --- a/usr.sbin/cron/doc/MAIL +++ /dev/null @@ -1,475 +0,0 @@ -[ this is really old mail that came to me in response to my 1986 posting - to usenet asking for feature suggestions before releasing the first - version of cron. it is presented here for its entertainment value. - --vix ] - -$FreeBSD$ - -From ptsfa!lll-crg!ames!acornrc!bob Wed Dec 31 10:07:08 1986 -Date: Wed, 31 Dec 86 08:59:31 pst -From: lll-crg!ames!acornrc!bob (Bob Weissman) -To: ptsfa!vixie!paul -Status: RO - -Sure, here's a suggestion: I'd like to be able to run a program, say, -every two hours. Current cron requires me to write -0,2,4,6,8,10,12,14,16,18,20,22 in the hours field. How about a notation -to handle this more elegantly? - -<< Okay, I've allowed 0-22/2 as a means of handling this. - The time specification for my cron is as follows: - specification = range {"," range} - range = (start "-" finish ["/" step]) | single-unit - This allows "1,3,5-7", which the current cron doesn't (it won't - do a range inside a list), and handles your specific need. >> - -From drw@mit-eddie Wed Dec 31 18:25:27 1986 -Date: Wed, 31 Dec 86 14:28:19 est -From: drw@mit-eddie (Dale Worley) -To: mit-eddie!vixie!paul -Status: RO - -We have a lot of lines in our crontab of the form - - 00 12 * * * su user < /usr/users/user/script.file - -This barfs (silently!) on our system (Dec Ultrix 1.2 == 4.2bsd) if -user's shell is csh. This, I am told, is because csh requires that -the environment be set up in certain ways, which cron doesn't do. -(Actually, I believe, it is because /etc/rc, which runs cron, doesn't -set up the environment enough for csh to run, and cron just inherits -the situation.) Anyway, the point is that if you find out what csh -really needs in its environment, you might want to set up cron to -provide some reasonable defaults (if it isn't supplied by cron's -parent). Also, could you tell me what csh needs, if you find out, so -we can hack our /etc/rc? - -<< well, the environment IS a problem. processes that cron forks - will inherit the environment of the person who ran the cron - daemon... I plan to edit out such useless things as TERMCAP, - TERM, and the like; supply correct values for HOME, USER, CWD, - and whatever else comes to mind. I'll make sure csh works... >> -From ptsfa!ames!seismo!dgis!generous Thu Jan 1 07:33:17 1987 -Date: Thu Jan 1 10:29:20 1987 -From: ames!seismo!dgis!generous (Curtis Generous) -To: nike!ptsfa!vixie!paul -Status: RO - -Paul: - -One of the limitations of the present versions of cron is the lack -of the capability of specifying a way to execute a command every -n units of time. - -Here is a good example: - -# Present method to start up uucico -02,12,22,32,42,52 * * * * exec /usr/lib/uucp/uucico -r1 - -# New method ?? (the ':' here is just one possibility for syntax) -02:10 * * * * exec /usr/lib/uucp/uucico -r1 - -This method would prove very helpful for those programs that get started -every few minutes, making the entry long and not easily readable. The first -number would specify the base time, and the second number the repetition -interval. - -<< Good idea, but bob@acornrc beat you to it. I used '/' instead of - ':'. This is my personal preference, and seems intuitive when you - think of the divide operator in C... Does anyone have a preference? >> - -From ptsfa!lll-lcc!seismo!decuac!c3pe!c3engr!charles Thu Jan 1 17:04:24 1987 -From: lll-lcc!seismo!c3pe!c3engr!charles (Charles Green) -To: c3pe!decuac!dolqci!vrdxhq!seismo!lll-lcc!ptsfa!vixie!paul -Date: Thu Jan 1 19:22:47 1987 -Status: RO - -Well, this isn't a compatible extension, but I have in times past wondered -about a facility to let you start a process at intervals of, say, 17 minutes, -instead of particular minutes out of each hour. - -<< This was a popular request! >> - -From seismo!uwvax!astroatc!nicmad!norvax!mann Sun Jan 4 13:04:01 1987 -Date: Fri, 2 Jan 87 09:23:53 cst -From: lll-lcc!seismo!uwvax!astroatc!nicmad!norvax!mann (Tom Mann) -To: ptsfa!vixie!paul -Status: RO - -I'm not sure if it is in cron (either SysV or BSD ... if it is, I haven't -figured it out ) but a comment feature would SURE BE NICE!. -There are times when I want to comment out an entry -for a period of time; it might also make it a lot more legible. - -<< My cron allows blank lines and standard #-type comments. I know - that one BSD4.2 cron I've used had it. I don't know about SysV. >> - -From ptsfa!hoptoad!hugh Mon Jan 5 10:26:46 1987 -Date: Mon, 5 Jan 87 01:22:17 PST -From: hoptoad!hugh (Hugh Daniel) -To: ptsfa!vixie!paul -Status: RO - - Hi, I do have a BIG one that I would like. I want to log ALL output -from command lines into a file for each line. Thus I might have a chance -of finding out why my crontab entry did not work. - This would seem to work best if done by cron, as it is now I have a google -of shell scripts laying about just to put the error output where I can see -it. - -<< My cron (and the SysV cron) will send mail to the owner of the - particular crontab file if a command generates any output on stdout - or stderr. This can be irritating, but if you write a script such - that any output means a problem occurred, you can avoid most logfile - needs, and not generate mail except in unforeseen circumstances. >> - -From ptsfa!dual!ucbvax!ihnp4!anvil!es!Robert_Toxen Mon Jan 5 13:08:46 1987 -From: dual!ucbvax!ihnp4!anvil!es!Robert_Toxen -Date: Fri, 2 Jan 87 14:25:29 EST -To: anvil!ihnp4!ucbvax!dual!ptsfa!vixie!paul -Status: RO - -Here are some suggestions: -1. Run it through the C preprocessor via "/lib/". - -<< hmmm. this seems of limited utility, and if you really wanted - to do it that way, you could do it yourself (since users can - write to their own crontab files). I'll add '-' (read stdin) - to the crontab installer program to facilitate this. >> - -2. Allow specifying every Nth day of week, i.e., every second Wednesday. - I did this to calendar by separating the day of week (Wed=4, which one - to start on and N with slashes). I took modulo the day of year as a - starting point so that someone with a desk calendar documenting such - things can easily determine the offset (second number). I did this - while at SGI; alas I don't have a copy of the code. - -<< I can see how this could be useful, but I'm not sure how I'd - implement it. Cron currently doesn't keep track of the last time - a given command was run; whether the current Wednesday is the first - or second since the command was last run would be pretty hard to - figure out. I'd have to keep a database of commands and their - execution around, and purge it when the crontab was overwritten. - This is too much work for me, but if someone adds it, let me know. >> - -From ptsfa!ames!seismo!cbmvax!devon!paul Tue Jan 6 05:50:17 1987 -From: ames!seismo!cbmvax!devon!paul -To: cbmvax!seismo!nike!ptsfa!vixie!paul -Date: Mon Jan 5 09:29:57 1987 -Status: RO - -One problem that has always plagued me with cron is the assumed ORing. -I'd like to see some type of ANDing implemented. I guess I can best -describe this by example. Say I have the following line in my crontab -file: - -* * 4-31 * 1-6 /usr/bin/command - -What this does is run 'command' on the 4th thru 31st days of the -month, AND on Monday thru Saturday; which probably means running it -every day of the month (unless Sunday falls on days 1-3). This -happens because cron runs the command if the day-of-month OR the -day-of-week is true. - -What I'd like to happen with the above line is to run the command ONLY -on Monday thru Saturday any time after the 3rd of the month, e.g. if -the day-of-month AND the day-of-week are true. - -My proposal to you is to implement some special chars for the first -five fields. Examples: - -* * !1-3 * 1-6 /usr/bin/command - -(run command Mon-Sat, but NOT [!] on the first 3 days of the month) - -* * &4-31 * &1-6 /usr/bin/command - -(run command if day-of-month AND day-of-week are true) - -Get the picture? This would be compatable with existing versions of -cron (which wouldn't currently be using any special characters, so -that old crontabs would be handled correctly). - -<< This message made me aware of the actual boolean expression involved - in a crontab entry. I'd assumed that it was - (minute && hour && DoM && month && DoW) - But it's really - (minute && hour && month && (DoM || DoW)) - - I can see some value in changing this, but with a fixed order of - fields, operators get to be kindof unary, which && and || really - aren't. If someone has an idea on a syntax that allows useful - variations to the standard (&& && && (||)) default, please suggest. >> - -From bobkat!pedz Tue Jan 6 20:02:10 1987 -From: pedz@bobkat.UUCP (Pedz Thing) -Date: 2 Jan 87 17:34:44 GMT -Status: RO - -Log files! It would be nice to be able to specify a log for cron -itself and also a log for each program's stdout and stderr to go to. -The latter can of course be done with > and 2> but it would be nice if -there could be a single line with some sort of pattern like -`> /usr/spool/log/%' and the command would be substituted for the %. -Another thing which would be nice is to be able to specify which shell -to call to give the command to. - -<< Log files are done with mail. The '%' idea could be useful if - a different character were used (% is special to cron, see man - page); a different directory would have to be chosen, since each - user has their own crontab file; and something intelligent would - have to be done in the file naming, since the first word of the - command might be ambiguous (with other commands). In short, it's - too much work. Sorry. >> - -From guy%gorodish@sun Tue Jan 6 20:03:13 1987 -From: guy%gorodish@sun (Guy Harris) -Message-ID: <10944@sun.uucp> -Date: 5 Jan 87 12:09:09 GMT -References: <429@vixie.UUCP> <359@bobkat.UUCP> -Sender: news@sun.uucp -Status: RO - -> Another thing which would be nice is to be able to specify which shell -> to call to give the command to. - -Well, the obvious choice would be the user's shell, but this wouldn't work -for accounts like "uucico". - -<< I use the owning user's shell, and to handle "uucico" I check a - list of "acceptable shells" (currently compiled in, does anybody - mind?), substituting a default (compiled in) shell if the user's - shell isn't on the list. - - BTW, "compiled in" means that it's in a .h file, easily changed - during installation, but requiring recompilation to modify. You - don't have to go digging through the code to find it... >> - -From qantel!hplabs!ucbvax!mwm@violet.berkeley.edu Tue Jan 6 21:24:48 1987 -To: hplabs!qantel!vixie!paul (Paul Vixie Esq) -Date: 04 Jan 87 00:42:35 PST (Sun) -From: Mike Meyer -Status: RO - -<<[Discussion of RMS/FSF, and mwm's GNU Cron deleted]>> - -Oh, yeah - here are the extensions on my cron: - -1) Sunday is both day 0 and day 7, so it complies with both SysV and -BSD cron. - -<< Good idea. I did it too, thanks for informing me. >> - -2) At is integrated into the cron. Instead of atrun to scan the -/usr/spool/at directory, at files are put into the /usr/lib/cron -directory along with users cron files, and cron fabricates a line from -a crontab file to run them. This is considered a major win by all who -use it. - -<< I don't use 'at', and my cron doesn't do anything with it. To run - 'at', I use 'atrun' the same way the current BSD cron does. My - crontab files are in /usr/spool/cron/crontabs, in the SysV - tradition -- not in /usr/lib/cron. This is a configuration - parameter, of course. >> - -There are two known restrictions: - -1) I don't support any of the SysV security hooks. I don't have a use -for them, and RMS didn't like the idea at all :-). - -<< This means cron.allow and cron.deny. I plan to support them, as - they've been quite helpful at various HPUX sites I've administered. >> - -2) Cron expects to be able to create files with names longer than 14 -characters, which makes it hard to run on SysV. At least one person -was working on a port, but I don't know how it's going. That might -make for a good reason for releasing yours, right there. - -<< If someone has SysV (with the 14-character limit), they probably - won't want my cron, since it doesn't add much to the standard - version (which they may have support for). My cron is not currently - portable to non-BSD systems, since it relies on interval timers (I - needed to sleep for intervals more granular than seconds alone would - allow). The port would be trivial, and I will do it if a lot of - people ask for it... >> - -Oh, yeah - I'm going to see about getting this cron integrated into -the next 4BSD release. - -<< How does one go about this? I have a few nifty gadgets I'd like - to contribute, this cron being one of them... >> - -<<[more FSF/GNU discussion deleted]>> - -From qantel!hplabs!ames!ut-sally!ut-ngp!melpad!bigtex!james Tue Jan 6 21:24:57 1987 -Posted-Date: Fri, 2 Jan 87 19:26:16 est -Date: Fri, 2 Jan 87 19:26:16 est -From: hplabs!ames!ut-sally!ut-ngp!bigtex!james -To: vixie!paul -Status: RO - -Yes!!! There are several critical failures in System V cron... - -1. Pass all variables in cron's environment into the environment of things - cron starts up, or at least into the crontab entries started up (at jobs - will inherit the environment of the user). If nothing else it is critically - important that the TZ variable be passed on. PATH should be passed on too. - Basically, passing environment values allows one to design a standard - environment with TZ and PATH and have that run by everything. If anyone - tells you this is no big deal, consider what happens when uucico is - started by cron in CA to make a long distance phone link... Unless the - administrator is really on his/her toes, calls scheduled at 5pm will really - go at two in the afternoon, needlessly incurring huge phone bills, all - because System V refuses to pass the TZ from its environment down. There - are work arounds, but only putting it in cron will really work. This is - not a security hole. - -<< delete TERM and TERMCAP; modify HOME, USER, and CWD; pass TZ and - PATH through undisturbed. any other requests out there? - - BSD doesn't have this problem -- TZ is passed right on through if - you define it in the shell before starting my cron daemon. However, - the BSD I'm running this on doesn't need TZ to be defined anyway... - The default in the kernel has been just fine so far... But just the - same, if/when I port to SysV (I guess I really should), I'll make - sure this works right. - - I guess I've been spoiled. HPUX is SysV-based, and I never had a - problem with cron and TZ when I used it. >> - -2. A way to avoid logging stuff in /usr/lib/cron/log. I have a cron entry - run uudemon.hr every 10 minutes. This is 144 times/day. Each run generates - three lines of text, for a total of 432 lines of text I don't want to see. - Obviously this should be optional, but it would be nice if there were a - way to flag an entry so that it wasn't logged at all unless there was an - error. - -<< I don't know nothin' 'bout no /usr/lib/cron/log. What is this file? - I don't see any reason to create log entries, given the mail-the- - output behaviour. Opinions, anyone? >> - -I will come up with other ideas no doubt, but I can always implement them -myself. - -<< That's what I like about PD software. Please send me the diffs! >> - -The other problem you have is making sure you can run standard -crontabs. I would suggest something like this: if the command part of the -entry starts with an unescaped -, then flags and options follow immediately -thereafter. As in: - -2,12,22,32,42,52 * * * * -q /usr/lib/uucp/uudemon.hr - -This could mean do not log the uudemon.hr run unless there is a problem of -some kind. This is probably safe as not many filenames start with "-", and -those that do are already a problem for people. - -<< Since I don't plan on supporting /usr/lib/cron/log in ANY form unless - many people request it, I won't be needing -q as you've defined it. - I could use something like this to avoid sending mail on errors, for - the occasional script that you don't want to bullet-proof. - - The compatibility issue is CRITICAL. The 4.3BSD crontab format is - a crime against the whole philosophy of Unix(TM), in my opinion. >> - -One other minor thing to consider is the ulimit: can different users get -different ulimits for their crontab entries? - -<< Boy I'm ignorant today. What's a ulimit, and what should I do with - it in a crontab? Suggestions, enlightenment, etc ?? >> - -From qantel!lll-crg!ames!uw-beaver!uw-nsr!john Tue Jan 6 23:32:44 1987 -Date: Thu, 1 Jan 87 10:53:05 pst -From: lll-crg!ames!uw-beaver!uw-nsr!john (John Sambrook 5-7433) -To: vixie!paul -Status: RO - -How about not hardwiring the default environment that cron builds for its -children in the cron program itself? Our cron does this and it's the pits -because we are TZ=PST8PDT not TZ=EST5EDT ! - -<< yeachk. I assure you, I will not hardwire the TZ! >> -From ptsfa!well!dv Fri Jan 9 04:01:50 1987 -Date: Thu, 8 Jan 87 23:50:40 pst -From: well!dv (David W. Vezie) -To: ptsfa!vixie!paul -Status: RO - -6, have a special notation called 'H' which would expand to weekends - and holidays (you'd have to keep a database somewhere of real - holidays), and also 'W' for workdays (neither weekend or holiday). - -<< Too much work. There should be a standard way to define and - detect holidays under Unix(TM); if there were, I'd use it. As - it is, I'll leave this for someone else to add. - - I can see the usefulness; it just doesn't quite seem worth it. >> -From qantel!gatech!akgua!blnt1!jat Wed Jan 14 20:00:40 1987 -Date: Tue, 13 Jan 87 16:39:38 EST -From: gatech!akgua!blnt1!jat -Status: RO - -1) Add some way to tell cron to reread the files, say kill -1 - -<< whenever the 'crontab' program is run and updates a crontab file, - a file /usr/spool/cron/POKECRON is created; next time the cron - daemon wakes up, it sees it, and re-reads the crontab files. - - I thought of handling the signal; even implemented it. Then this - clever idea hit me and I ripped it all out and added a single - IF-statement to handle the POKECRON file. >> - -2) Have some kind of retry time so that if a command fails, cron will try to - execute it again after a certain period. This is useful if you have some - type of cleanup program that can run at the scheduled time for some reason - (such as locked device, unmounted filesystem, etc). - -<< Hmmm, sounds useful. I could do this by submitting an 'at' job... - I'll think about it. >> -From ptsfa!dual!ucbvax!ihnp4!mtuxo!ender Sat Jan 3 16:54:00 1987 -From: dual!ucbvax!ihnp4!mtuxo!ender -Date: Sat, 3 Jan 87 14:05:13 PST -To: ucbvax!dual!ptsfa!vixie!paul -Status: RO - -It would be nice if nonprivileged users can setup personal crontab files -(~/.cronrc, say) and be able to run personal jobs at regular intervals. - -<< this is done, but in the SysV style: the 'crontab' program installs - a new crontab file for the executing user (can be overridden by root - for setup of uucp and news). the advantage of this is that (1) when - a crontab is changed, the daemon can be informed automatically; and - (2) the file can be syntax-checked before installation. >> -From ptsfa!ames!seismo!ihnp4!lcc!richard Fri Jan 16 04:47:33 1987 -Date: Fri, 16 Jan 87 07:44:57 EST -To: nike!ptsfa!vixie!paul -Status: RO - -The System V cron is nice, but it has a few annoying features. One is that -its mail files will say that the previous message is the output of "one of your -cron commands." I wish it would say WHICH cron commmand. - -<< Done. Also which shell, which user (useful when the mail gets - forwarded), which home directory, and other useful crud. >> - -Another problem is with timezones. It is necessary to specify TZ=PST8PDT (or -whatever) when you invoke cron (from inittab, or /etc/rc) and it is also -necessary to add TZ=PST8PDT to each crontab line which might need it. Cron -should automatically export its idea of the "TZ" to each invoked command, and -it should be possible to put a line in the crontab file which overrides that -for every command in the file (e.g., most users are on EST, so cron is run -with TZ=EST5EDT; but one user is usually on PST and wants all of his cron -commands to run with TZ=PST8PDT). This might be extended to allow any -environment variable to be specified once for the whole crontab file (e.g., -PATH). - -<< Well, since I run the user's shell, you could put this into .cshrc. - generic environment-variable setting could be useful, though. Since - I have to modify the environment anyway, I'll consider this. >> - -A log file might be a nice idea, but the System V cron log is too verbose. -I seem to remember that cron keeps it open, too; so you can't even have -something go and periodically clean it out. - -<< I don't do /usr/lib/cron/log. I wasn't aware of this file until I - got all these suggestions. Do people want this file? Tell me! >> diff --git a/usr.sbin/cron/doc/Makefile.vixie b/usr.sbin/cron/doc/Makefile.vixie deleted file mode 100644 index 8df1301..0000000 --- a/usr.sbin/cron/doc/Makefile.vixie +++ /dev/null @@ -1,128 +0,0 @@ -#/* Copyright 1988,1990,1993,1994 by Paul Vixie -# * All rights reserved -# * -# * Distribute freely, except: don't remove my name from the source or -# * documentation (don't take credit for my work), mark your changes (don't -# * get me blamed for your possible bugs), don't alter or remove this -# * notice. May be sold if buildable source is provided to buyer. No -# * warrantee of any kind, express or implied, is included with this -# * software; use at your own risk, responsibility for damages (if any) to -# * anyone resulting from the use of this software rests entirely with the -# * user. -# * -# * Send bug reports, bug fixes, enhancements, requests, flames, etc., and -# * I'll try to keep a version up to date. I can be reached as follows: -# * Paul Vixie uunet!decwrl!vixie!paul -# */ - -# Makefile for vixie's cron -# -# $FreeBSD$ -# -# vix 03mar88 [moved to RCS, rest of log is in there] -# vix 30mar87 [goodbye, time.c; hello, getopt] -# vix 12feb87 [cleanup for distribution] -# vix 30dec86 [written] - -# NOTES: -# 'make' can be done by anyone -# 'make install' must be done by root -# -# this package needs getopt(3), bitstring(3), and BSD install(8). -# -# the configurable stuff in this makefile consists of compilation -# options (use -O, cron runs forever) and destination directories. -# SHELL is for the 'augumented make' systems where 'make' imports -# SHELL from the environment and then uses it to run its commands. -# if your environment SHELL variable is /bin/csh, make goes real -# slow and sometimes does the wrong thing. -# -# this package needs the 'bitstring macros' library, which is -# available from me or from the comp.sources.unix archive. if you -# put 'bitstring.h' in a non-standard place (i.e., not intuited by -# cc(1)), you will have to define INCLUDE to set the include -# directory for cc. INCLUDE should be `-Isomethingorother'. -# -# there's more configuration info in config.h; edit that first! - -#################################### begin configurable stuff -#<> -DESTROOT = $(DESTDIR)/usr -DESTSBIN = $(DESTROOT)/sbin -DESTBIN = $(DESTROOT)/bin -DESTMAN = $(DESTROOT)/share/man -#<> -INCLUDE = -I. -#INCLUDE = -#<> -LIBS = -#<> -#OPTIM = -O -OPTIM = -g -#<> -# (ATT untested) -#COMPAT = -DATT -#(BSD is only needed if does not define it, as on ULTRIX) -#COMPAT = -DBSD -# (POSIX) -#COMPAT = -DPOSIX -#<> -LINTFLAGS = -hbxa $(INCLUDE) $(COMPAT) $(DEBUGGING) -#<> -#CC = vcc -#<> -DEFS = -#(SGI IRIX systems need this) -#DEFS = -D_BSD_SIGNALS -Dconst= -#<> -#INSTALL = installbsd -INSTALL = install -#<> -LDFLAGS = -#################################### end configurable stuff - -SHELL = /bin/sh -CFLAGS = $(OPTIM) $(INCLUDE) $(COMPAT) $(DEFS) - -INFOS = README CHANGES FEATURES INSTALL CONVERSION THANKS MAIL -MANPAGES = bitstring.3 crontab.5 crontab.1 cron.8 putman.sh -HEADERS = bitstring.h cron.h config.h pathnames.h \ - externs.h compat.h -SOURCES = cron.c crontab.c database.c do_command.c entry.c \ - env.c job.c user.c popen.c misc.c compat.c -SHAR_SOURCE = $(INFOS) $(MANPAGES) Makefile $(HEADERS) $(SOURCES) -LINT_CRON = cron.c database.c user.c entry.c compat.c \ - misc.c job.c do_command.c env.c popen.c -LINT_CRONTAB = crontab.c misc.c entry.c env.c compat.c -CRON_OBJ = cron.o database.o user.o entry.o job.o do_command.o \ - misc.o env.o popen.o compat.o -CRONTAB_OBJ = crontab.o misc.o entry.o env.o compat.o - -all : cron crontab - -lint : - lint $(LINTFLAGS) $(LINT_CRON) $(LIBS) \ - |grep -v "constant argument to NOT" 2>&1 - lint $(LINTFLAGS) $(LINT_CRONTAB) $(LIBS) \ - |grep -v "constant argument to NOT" 2>&1 - -cron : $(CRON_OBJ) - $(CC) $(LDFLAGS) -o cron $(CRON_OBJ) $(LIBS) - -crontab : $(CRONTAB_OBJ) - $(CC) $(LDFLAGS) -o crontab $(CRONTAB_OBJ) $(LIBS) - -install : all - $(INSTALL) -c -m 111 -o root -s cron $(DESTSBIN)/ - $(INSTALL) -c -m 4111 -o root -s crontab $(DESTBIN)/ - sh putman.sh crontab.1 $(DESTMAN) - sh putman.sh cron.8 $(DESTMAN) - sh putman.sh crontab.5 $(DESTMAN) - -clean :; rm -f *.o cron crontab a.out core tags *~ #* - -kit : $(SHAR_SOURCE) - makekit -m -s99k $(SHAR_SOURCE) - -$(CRON_OBJ) : cron.h compat.h config.h externs.h pathnames.h Makefile -$(CRONTAB_OBJ) : cron.h compat.h config.h externs.h pathnames.h Makefile diff --git a/usr.sbin/cron/doc/README b/usr.sbin/cron/doc/README deleted file mode 100644 index eaced9e..0000000 --- a/usr.sbin/cron/doc/README +++ /dev/null @@ -1,72 +0,0 @@ -#/* Copyright 1988,1990,1993 by Paul Vixie -# * All rights reserved -# * -# * Distribute freely, except: don't remove my name from the source or -# * documentation (don't take credit for my work), mark your changes (don't -# * get me blamed for your possible bugs), don't alter or remove this -# * notice. May be sold if buildable source is provided to buyer. No -# * warrantee of any kind, express or implied, is included with this -# * software; use at your own risk, responsibility for damages (if any) to -# * anyone resulting from the use of this software rests entirely with the -# * user. -# * -# * Send bug reports, bug fixes, enhancements, requests, flames, etc., and -# * I'll try to keep a version up to date. I can be reached as follows: -# * Paul Vixie uunet!decwrl!vixie!paul -# */ - -Vixie Cron V3.0 -December 27, 1993 -[V2.2 was some time in 1992] -[V2.1 was May 29, 1991] -[V2.0 was July 5, 1990] -[V2.0-beta was December 9, 1988] -[V1.0 was May 6, 1987] -Paul Vixie - -This is a version of 'cron' that is known to run on BSD 4.[23] systems. It -is functionally based on the SysV cron, which means that each user can have -their own crontab file (all crontab files are stored in a read-protected -directory, usually /var/cron/tabs). No direct support is provided for -'at'; you can continue to run 'atrun' from the crontab as you have been -doing. If you don't have atrun (i.e., System V) you are in trouble. - -A messages is logged each time a command is executed; also, the files -"allow" and "deny" in /var/cron can be used to control access to the -"crontab" command (which installs crontabs). It hasn't been tested on -SysV, although some effort has gone into making the port an easy one. - -This is more or less the copyright that USENET contributed software usually -has. Since ATT couldn't use this version if they had to freely distribute -source, and since I'd love to see them use it, I'll offer some rediculously -low license fee just to have them take it. In the unlikely event that they -do this, I will continue to support and distribute the pseudo-PD version, so -please, don't flame me for wanting my work to see a wider distribution. - -To use this: Sorry, folks, there is no cutesy 'Configure' script. You'll -have to go edit a couple of files... So, here's the checklist: - - Read all the FEATURES, INSTALL, and CONVERSION files - Edit config.h - Edit Makefile - (both of these files have instructions inside; note that - some things in config.h are definable in Makefile and are - therefore surrounded by #ifndef...#endif) - 'make' - 'su' and 'make install' - (you may have to install the man pages by hand) - kill your existing cron process - (actually you can run your existing cron if you want, but why?) - build new crontabs using /usr/lib/{crontab,crontab.local} - (either put them all in "root"'s crontab, or divide it up - and rip out all the 'su' commands, collapse the lengthy - lists into ranges with steps -- basically, this step is - as much work as you want to make it) - start up the new cron - (must be done as root) - watch it. test it with 'crontab -r' and watch the daemon track your - changes. - if you like it, change your /etc/{rc,rc.local} to use it instead of - the old one. - -$FreeBSD$ diff --git a/usr.sbin/cron/doc/README.1ST b/usr.sbin/cron/doc/README.1ST deleted file mode 100644 index 66cd0b2..0000000 --- a/usr.sbin/cron/doc/README.1ST +++ /dev/null @@ -1,4 +0,0 @@ -Sources substantially rearranged 26 Aug 94, Jordan Hubbard. Content -remains faithful to the original 3.0 cron source from Paul Vixie, but -any bugs introduced by this reorganization or the port to FreeBSD remain -purely my own. - Jordan diff --git a/usr.sbin/cron/doc/THANKS b/usr.sbin/cron/doc/THANKS deleted file mode 100644 index 3787c29..0000000 --- a/usr.sbin/cron/doc/THANKS +++ /dev/null @@ -1,29 +0,0 @@ -15 January 1990 -Paul Vixie - -Many people have contributed to cron. Many more than I can remember, in fact. -Rich Salz and Carl Gutekunst were each of enormous help to me in V1; Carl for -helping me understand UNIX well enough to write it, and Rich for helping me -get the features right. - -John Gilmore wrote me a wonderful review of V2, which took me a whole year to -answer even though it made me clean up some really awful things in the code. -(According to John the most awful things are still in here, of course.) - -Paul Close made a suggestion which led to /etc/crond.pid and the mutex locking -on it. Kevin Braunsdorf of Purdue made a suggestion that led to @reboot and -its brothers and sisters; he also sent some diffs that lead cron toward compil- -ability with System V, though without at(1) capabilities, this cron isn't going -to be that useful on System V. Bob Alverson fixed a silly bug in the line -number counting. Brian Reid made suggestions which led to the run queue and -the source-file labelling in installed crontabs. - -Scott Narveson ported V2 to a Sequent, and sent in the most useful single batch -of diffs I got from anybody. Changes attributable to Scott are: - -> sendmail won't time out if the command is slow to generate output - -> day-of-week names aren't off by one anymore - -> crontab says the right thing if you do something you shouldn't do - -> crontab(5) man page is longer and more informative - -> misc changes related to the side effects of fclose() - -> Sequent "universe" support added (may also help on Pyramids) - -> null pw_shell is dealt with now; default is /bin/sh diff --git a/usr.sbin/cron/lib/Makefile b/usr.sbin/cron/lib/Makefile deleted file mode 100644 index 51316c1..0000000 --- a/usr.sbin/cron/lib/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $FreeBSD$ - -LIB= cron -INTERNALLIB= -SRCS= entry.c env.c misc.c - -WARNS?= 3 - -CFLAGS+= -I${.CURDIR}/../cron -CFLAGS+= -DLOGIN_CAP -DPAM - -.include diff --git a/usr.sbin/cron/lib/compat.c b/usr.sbin/cron/lib/compat.c deleted file mode 100644 index 9686012..0000000 --- a/usr.sbin/cron/lib/compat.c +++ /dev/null @@ -1,237 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static char rcsid[] = "$FreeBSD$"; -#endif - -/* vix 30dec93 [broke this out of misc.c - see RCS log for history] - * vix 15jan87 [added TIOCNOTTY, thanks csg@pyramid] - */ - - -#include "cron.h" -#ifdef NEED_GETDTABLESIZE -# include -#endif -#if defined(NEED_SETSID) && defined(BSD) -# include -#endif -#include -#include - - -/* the code does not depend on any of vfork's - * side-effects; it just uses it as a quick - * fork-and-exec. - */ -#ifdef NEED_VFORK -PID_T -vfork() { - return (fork()); -} -#endif - - -#ifdef NEED_STRDUP -char * -strdup(str) - char *str; -{ - char *temp; - - if ((temp = malloc(strlen(str) + 1)) == NULL) { - errno = ENOMEM; - return NULL; - } - (void) strcpy(temp, str); - return temp; -} -#endif - - -#ifdef NEED_STRERROR -char * -strerror(error) - int error; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - static char buf[32]; - - if ((error <= sys_nerr) && (error > 0)) { - return sys_errlist[error]; - } - - sprintf(buf, "Unknown error: %d", error); - return buf; -} -#endif - - -#ifdef NEED_STRCASECMP -int -strcasecmp(left, right) - char *left; - char *right; -{ - while (*left && (MkLower(*left) == MkLower(*right))) { - left++; - right++; - } - return MkLower(*left) - MkLower(*right); -} -#endif - - -#ifdef NEED_SETSID -int -setsid() -{ - int newpgrp; -# if defined(BSD) - int fd; -# if defined(POSIX) - newpgrp = setpgid((pid_t)0, getpid()); -# else - newpgrp = setpgrp(0, getpid()); -# endif - if ((fd = open(_PATH_TTY, 2)) >= 0) - { - (void) ioctl(fd, TIOCNOTTY, (char*)0); - (void) close(fd); - } -# else /*BSD*/ - newpgrp = setpgrp(); - - (void) close(STDIN); (void) open(_PATH_DEVNULL, 0); - (void) close(STDOUT); (void) open(_PATH_DEVNULL, 1); - (void) close(STDERR); (void) open(_PATH_DEVNULL, 2); -# endif /*BSD*/ - return newpgrp; -} -#endif /*NEED_SETSID*/ - - -#ifdef NEED_GETDTABLESIZE -int -getdtablesize() { -#ifdef _SC_OPEN_MAX - return sysconf(_SC_OPEN_MAX); -#else - return _POSIX_OPEN_MAX; -#endif -} -#endif - - -#ifdef NEED_FLOCK -/* The following flock() emulation snarfed intact *) from the HP-UX - * "BSD to HP-UX porting tricks" maintained by - * system@alchemy.chem.utoronto.ca (System Admin (Mike Peterson)) - * from the version "last updated: 11-Jan-1993" - * Snarfage done by Jarkko Hietaniemi - * *) well, almost, had to K&R the function entry, HPUX "cc" - * does not grok ANSI function prototypes */ - -/* - * flock (fd, operation) - * - * This routine performs some file locking like the BSD 'flock' - * on the object described by the int file descriptor 'fd', - * which must already be open. - * - * The operations that are available are: - * - * LOCK_SH - get a shared lock. - * LOCK_EX - get an exclusive lock. - * LOCK_NB - don't block (must be ORed with LOCK_SH or LOCK_EX). - * LOCK_UN - release a lock. - * - * Return value: 0 if lock successful, -1 if failed. - * - * Note that whether the locks are enforced or advisory is - * controlled by the presence or absence of the SETGID bit on - * the executable. - * - * Note that there is no difference between shared and exclusive - * locks, since the 'lockf' system call in SYSV doesn't make any - * distinction. - * - * The file "" should be modified to contain the definitions - * of the available operations, which must be added manually (see below - * for the values). - */ - -/* this code has been reformatted by vixie */ - -int -flock(fd, operation) - int fd; - int operation; -{ - int i; - - switch (operation) { - case LOCK_SH: /* get a shared lock */ - case LOCK_EX: /* get an exclusive lock */ - i = lockf (fd, F_LOCK, 0); - break; - - case LOCK_SH|LOCK_NB: /* get a non-blocking shared lock */ - case LOCK_EX|LOCK_NB: /* get a non-blocking exclusive lock */ - i = lockf (fd, F_TLOCK, 0); - if (i == -1) - if ((errno == EAGAIN) || (errno == EACCES)) - errno = EWOULDBLOCK; - break; - - case LOCK_UN: /* unlock */ - i = lockf (fd, F_ULOCK, 0); - break; - - default: /* can't decipher operation */ - i = -1; - errno = EINVAL; - break; - } - - return (i); -} -#endif /*NEED_FLOCK*/ - - -#ifdef NEED_SETENV -int -setenv(name, value, overwrite) - char *name, *value; - int overwrite; -{ - char *tmp; - - if (overwrite && getenv(name)) - return -1; - - if (!(tmp = malloc(strlen(name) + strlen(value) + 2))) { - errno = ENOMEM; - return -1; - } - - sprintf(tmp, "%s=%s", name, value); - return putenv(tmp); /* intentionally orphan 'tmp' storage */ -} -#endif diff --git a/usr.sbin/cron/lib/entry.c b/usr.sbin/cron/lib/entry.c deleted file mode 100644 index b6be69c..0000000 --- a/usr.sbin/cron/lib/entry.c +++ /dev/null @@ -1,644 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - -/* vix 26jan87 [RCS'd; rest of log is in RCS file] - * vix 01jan87 [added line-level error recovery] - * vix 31dec86 [added /step to the from-to range, per bob@acornrc] - * vix 30dec86 [written] - */ - - -#include "cron.h" -#include -#ifdef LOGIN_CAP -#include -#endif - -typedef enum ecode { - e_none, e_minute, e_hour, e_dom, e_month, e_dow, - e_cmd, e_timespec, e_username, e_group, e_mem -#ifdef LOGIN_CAP - , e_class -#endif -} ecode_e; - -static char get_list(bitstr_t *, int, int, char *[], int, FILE *), - get_range(bitstr_t *, int, int, char *[], int, FILE *), - get_number(int *, int, char *[], int, FILE *); -static int set_element(bitstr_t *, int, int, int); - -static char *ecodes[] = - { - "no error", - "bad minute", - "bad hour", - "bad day-of-month", - "bad month", - "bad day-of-week", - "bad command", - "bad time specifier", - "bad username", - "bad group name", - "out of memory", -#ifdef LOGIN_CAP - "bad class name", -#endif - }; - - -void -free_entry(e) - entry *e; -{ -#ifdef LOGIN_CAP - if (e->class != NULL) - free(e->class); -#endif - if (e->cmd != NULL) - free(e->cmd); - if (e->envp != NULL) - env_free(e->envp); - free(e); -} - - -/* return NULL if eof or syntax error occurs; - * otherwise return a pointer to a new entry. - */ -entry * -load_entry(file, error_func, pw, envp) - FILE *file; - void (*error_func)(char *); - struct passwd *pw; - char **envp; -{ - /* this function reads one crontab entry -- the next -- from a file. - * it skips any leading blank lines, ignores comments, and returns - * EOF if for any reason the entry can't be read and parsed. - * - * the entry is also parsed here. - * - * syntax: - * user crontab: - * minutes hours doms months dows cmd\n - * system crontab (/etc/crontab): - * minutes hours doms months dows USERNAME cmd\n - */ - - ecode_e ecode = e_none; - entry *e; - int ch; - char cmd[MAX_COMMAND]; - char envstr[MAX_ENVSTR]; - char **prev_env; - - Debug(DPARS, ("load_entry()...about to eat comments\n")) - - skip_comments(file); - - ch = get_char(file); - if (ch == EOF) - return NULL; - - /* ch is now the first useful character of a useful line. - * it may be an @special or it may be the first character - * of a list of minutes. - */ - - e = (entry *) calloc(sizeof(entry), sizeof(char)); - - if (e == NULL) { - warn("load_entry: calloc failed"); - return NULL; - } - - if (ch == '@') { - /* all of these should be flagged and load-limited; i.e., - * instead of @hourly meaning "0 * * * *" it should mean - * "close to the front of every hour but not 'til the - * system load is low". Problems are: how do you know - * what "low" means? (save me from /etc/cron.conf!) and: - * how to guarantee low variance (how low is low?), which - * means how to we run roughly every hour -- seems like - * we need to keep a history or let the first hour set - * the schedule, which means we aren't load-limited - * anymore. too much for my overloaded brain. (vix, jan90) - * HINT - */ - Debug(DPARS, ("load_entry()...about to test shortcuts\n")) - ch = get_string(cmd, MAX_COMMAND, file, " \t\n"); - if (!strcmp("reboot", cmd)) { - Debug(DPARS, ("load_entry()...reboot shortcut\n")) - e->flags |= WHEN_REBOOT; - } else if (!strcmp("yearly", cmd) || !strcmp("annually", cmd)){ - Debug(DPARS, ("load_entry()...yearly shortcut\n")) - bit_set(e->minute, 0); - bit_set(e->hour, 0); - bit_set(e->dom, 0); - bit_set(e->month, 0); - bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); - e->flags |= DOW_STAR; - } else if (!strcmp("monthly", cmd)) { - Debug(DPARS, ("load_entry()...monthly shortcut\n")) - bit_set(e->minute, 0); - bit_set(e->hour, 0); - bit_set(e->dom, 0); - bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); - bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); - e->flags |= DOW_STAR; - } else if (!strcmp("weekly", cmd)) { - Debug(DPARS, ("load_entry()...weekly shortcut\n")) - bit_set(e->minute, 0); - bit_set(e->hour, 0); - bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); - e->flags |= DOM_STAR; - bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); - bit_set(e->dow, 0); - } else if (!strcmp("daily", cmd) || !strcmp("midnight", cmd)) { - Debug(DPARS, ("load_entry()...daily shortcut\n")) - bit_set(e->minute, 0); - bit_set(e->hour, 0); - bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); - bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); - bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); - } else if (!strcmp("hourly", cmd)) { - Debug(DPARS, ("load_entry()...hourly shortcut\n")) - bit_set(e->minute, 0); - bit_nset(e->hour, 0, (LAST_HOUR-FIRST_HOUR+1)); - bit_nset(e->dom, 0, (LAST_DOM-FIRST_DOM+1)); - bit_nset(e->month, 0, (LAST_MONTH-FIRST_MONTH+1)); - bit_nset(e->dow, 0, (LAST_DOW-FIRST_DOW+1)); - } else { - ecode = e_timespec; - goto eof; - } - /* Advance past whitespace between shortcut and - * username/command. - */ - Skip_Blanks(ch, file); - if (ch == EOF) { - ecode = e_cmd; - goto eof; - } - } else { - Debug(DPARS, ("load_entry()...about to parse numerics\n")) - - ch = get_list(e->minute, FIRST_MINUTE, LAST_MINUTE, - PPC_NULL, ch, file); - if (ch == EOF) { - ecode = e_minute; - goto eof; - } - - /* hours - */ - - ch = get_list(e->hour, FIRST_HOUR, LAST_HOUR, - PPC_NULL, ch, file); - if (ch == EOF) { - ecode = e_hour; - goto eof; - } - - /* DOM (days of month) - */ - - if (ch == '*') - e->flags |= DOM_STAR; - ch = get_list(e->dom, FIRST_DOM, LAST_DOM, - PPC_NULL, ch, file); - if (ch == EOF) { - ecode = e_dom; - goto eof; - } - - /* month - */ - - ch = get_list(e->month, FIRST_MONTH, LAST_MONTH, - MonthNames, ch, file); - if (ch == EOF) { - ecode = e_month; - goto eof; - } - - /* DOW (days of week) - */ - - if (ch == '*') - e->flags |= DOW_STAR; - ch = get_list(e->dow, FIRST_DOW, LAST_DOW, - DowNames, ch, file); - if (ch == EOF) { - ecode = e_dow; - goto eof; - } - } - - /* make sundays equivilent */ - if (bit_test(e->dow, 0) || bit_test(e->dow, 7)) { - bit_set(e->dow, 0); - bit_set(e->dow, 7); - } - - /* ch is the first character of a command, or a username */ - unget_char(ch, file); - - if (!pw) { - char *username = cmd; /* temp buffer */ - char *s; - struct group *grp; -#ifdef LOGIN_CAP - login_cap_t *lc; -#endif - - Debug(DPARS, ("load_entry()...about to parse username\n")) - ch = get_string(username, MAX_COMMAND, file, " \t"); - - Debug(DPARS, ("load_entry()...got %s\n",username)) - if (ch == EOF) { - ecode = e_cmd; - goto eof; - } - -#ifdef LOGIN_CAP - if ((s = strrchr(username, '/')) != NULL) { - *s = '\0'; - e->class = strdup(s + 1); - if (e->class == NULL) - warn("strdup(\"%s\")", s + 1); - } else { - e->class = strdup(RESOURCE_RC); - if (e->class == NULL) - warn("strdup(\"%s\")", RESOURCE_RC); - } - if (e->class == NULL) { - ecode = e_mem; - goto eof; - } - if ((lc = login_getclass(e->class)) == NULL) { - ecode = e_class; - goto eof; - } - login_close(lc); -#endif - grp = NULL; - if ((s = strrchr(username, ':')) != NULL) { - *s = '\0'; - if ((grp = getgrnam(s + 1)) == NULL) { - ecode = e_group; - goto eof; - } - } - - pw = getpwnam(username); - if (pw == NULL) { - ecode = e_username; - goto eof; - } - if (grp != NULL) - pw->pw_gid = grp->gr_gid; - Debug(DPARS, ("load_entry()...uid %d, gid %d\n",pw->pw_uid,pw->pw_gid)) -#ifdef LOGIN_CAP - Debug(DPARS, ("load_entry()...class %s\n",e->class)) -#endif - } - -#ifndef PAM /* PAM takes care of account expiration by itself */ - if (pw->pw_expire && time(NULL) >= pw->pw_expire) { - ecode = e_username; - goto eof; - } -#endif /* !PAM */ - - e->uid = pw->pw_uid; - e->gid = pw->pw_gid; - - /* copy and fix up environment. some variables are just defaults and - * others are overrides. - */ - e->envp = env_copy(envp); - if (e->envp == NULL) { - warn("env_copy"); - ecode = e_mem; - goto eof; - } - if (!env_get("SHELL", e->envp)) { - prev_env = e->envp; - sprintf(envstr, "SHELL=%s", _PATH_BSHELL); - e->envp = env_set(e->envp, envstr); - if (e->envp == NULL) { - warn("env_set(%s)", envstr); - env_free(prev_env); - ecode = e_mem; - goto eof; - } - } - if (!env_get("HOME", e->envp)) { - prev_env = e->envp; - sprintf(envstr, "HOME=%s", pw->pw_dir); - e->envp = env_set(e->envp, envstr); - if (e->envp == NULL) { - warn("env_set(%s)", envstr); - env_free(prev_env); - ecode = e_mem; - goto eof; - } - } - if (!env_get("PATH", e->envp)) { - prev_env = e->envp; - sprintf(envstr, "PATH=%s", _PATH_DEFPATH); - e->envp = env_set(e->envp, envstr); - if (e->envp == NULL) { - warn("env_set(%s)", envstr); - env_free(prev_env); - ecode = e_mem; - goto eof; - } - } - prev_env = e->envp; - sprintf(envstr, "%s=%s", "LOGNAME", pw->pw_name); - e->envp = env_set(e->envp, envstr); - if (e->envp == NULL) { - warn("env_set(%s)", envstr); - env_free(prev_env); - ecode = e_mem; - goto eof; - } -#if defined(BSD) - prev_env = e->envp; - sprintf(envstr, "%s=%s", "USER", pw->pw_name); - e->envp = env_set(e->envp, envstr); - if (e->envp == NULL) { - warn("env_set(%s)", envstr); - env_free(prev_env); - ecode = e_mem; - goto eof; - } -#endif - - Debug(DPARS, ("load_entry()...about to parse command\n")) - - /* Everything up to the next \n or EOF is part of the command... - * too bad we don't know in advance how long it will be, since we - * need to malloc a string for it... so, we limit it to MAX_COMMAND. - * XXX - should use realloc(). - */ - ch = get_string(cmd, MAX_COMMAND, file, "\n"); - - /* a file without a \n before the EOF is rude, so we'll complain... - */ - if (ch == EOF) { - ecode = e_cmd; - goto eof; - } - - /* got the command in the 'cmd' string; save it in *e. - */ - e->cmd = strdup(cmd); - if (e->cmd == NULL) { - warn("strdup(\"%s\")", cmd); - ecode = e_mem; - goto eof; - } - Debug(DPARS, ("load_entry()...returning successfully\n")) - - /* success, fini, return pointer to the entry we just created... - */ - return e; - - eof: - free_entry(e); - if (ecode != e_none && error_func) - (*error_func)(ecodes[(int)ecode]); - while (ch != EOF && ch != '\n') - ch = get_char(file); - return NULL; -} - - -static char -get_list(bits, low, high, names, ch, file) - bitstr_t *bits; /* one bit per flag, default=FALSE */ - int low, high; /* bounds, impl. offset for bitstr */ - char *names[]; /* NULL or *[] of names for these elements */ - int ch; /* current character being processed */ - FILE *file; /* file being read */ -{ - register int done; - - /* we know that we point to a non-blank character here; - * must do a Skip_Blanks before we exit, so that the - * next call (or the code that picks up the cmd) can - * assume the same thing. - */ - - Debug(DPARS|DEXT, ("get_list()...entered\n")) - - /* list = range {"," range} - */ - - /* clear the bit string, since the default is 'off'. - */ - bit_nclear(bits, 0, (high-low+1)); - - /* process all ranges - */ - done = FALSE; - while (!done) { - ch = get_range(bits, low, high, names, ch, file); - if (ch == ',') - ch = get_char(file); - else - done = TRUE; - } - - /* exiting. skip to some blanks, then skip over the blanks. - */ - Skip_Nonblanks(ch, file) - Skip_Blanks(ch, file) - - Debug(DPARS|DEXT, ("get_list()...exiting w/ %02x\n", ch)) - - return ch; -} - - -static char -get_range(bits, low, high, names, ch, file) - bitstr_t *bits; /* one bit per flag, default=FALSE */ - int low, high; /* bounds, impl. offset for bitstr */ - char *names[]; /* NULL or names of elements */ - int ch; /* current character being processed */ - FILE *file; /* file being read */ -{ - /* range = number | number "-" number [ "/" number ] - */ - - register int i; - auto int num1, num2, num3; - - Debug(DPARS|DEXT, ("get_range()...entering, exit won't show\n")) - - if (ch == '*') { - /* '*' means "first-last" but can still be modified by /step - */ - num1 = low; - num2 = high; - ch = get_char(file); - if (ch == EOF) - return EOF; - } else { - if (EOF == (ch = get_number(&num1, low, names, ch, file))) - return EOF; - - if (ch == '/') - num2 = high; - else if (ch != '-') { - /* not a range, it's a single number. - */ - if (EOF == set_element(bits, low, high, num1)) - return EOF; - return ch; - } else { - /* eat the dash - */ - ch = get_char(file); - if (ch == EOF) - return EOF; - - /* get the number following the dash - */ - ch = get_number(&num2, low, names, ch, file); - if (ch == EOF) - return EOF; - } - } - - /* check for step size - */ - if (ch == '/') { - /* eat the slash - */ - ch = get_char(file); - if (ch == EOF) - return EOF; - - /* get the step size -- note: we don't pass the - * names here, because the number is not an - * element id, it's a step size. 'low' is - * sent as a 0 since there is no offset either. - */ - ch = get_number(&num3, 0, PPC_NULL, ch, file); - if (ch == EOF || num3 == 0) - return EOF; - } else { - /* no step. default==1. - */ - num3 = 1; - } - - /* range. set all elements from num1 to num2, stepping - * by num3. (the step is a downward-compatible extension - * proposed conceptually by bob@acornrc, syntactically - * designed then implmented by paul vixie). - */ - for (i = num1; i <= num2; i += num3) - if (EOF == set_element(bits, low, high, i)) - return EOF; - - return ch; -} - - -static char -get_number(numptr, low, names, ch, file) - int *numptr; /* where does the result go? */ - int low; /* offset applied to result if symbolic enum used */ - char *names[]; /* symbolic names, if any, for enums */ - int ch; /* current character */ - FILE *file; /* source */ -{ - char temp[MAX_TEMPSTR], *pc; - int len, i, all_digits; - - /* collect alphanumerics into our fixed-size temp array - */ - pc = temp; - len = 0; - all_digits = TRUE; - while (isalnum(ch)) { - if (++len >= MAX_TEMPSTR) - return EOF; - - *pc++ = ch; - - if (!isdigit(ch)) - all_digits = FALSE; - - ch = get_char(file); - } - *pc = '\0'; - if (len == 0) - return (EOF); - - /* try to find the name in the name list - */ - if (names) { - for (i = 0; names[i] != NULL; i++) { - Debug(DPARS|DEXT, - ("get_num, compare(%s,%s)\n", names[i], temp)) - if (!strcasecmp(names[i], temp)) { - *numptr = i+low; - return ch; - } - } - } - - /* no name list specified, or there is one and our string isn't - * in it. either way: if it's all digits, use its magnitude. - * otherwise, it's an error. - */ - if (all_digits) { - *numptr = atoi(temp); - return ch; - } - - return EOF; -} - - -static int -set_element(bits, low, high, number) - bitstr_t *bits; /* one bit per flag, default=FALSE */ - int low; - int high; - int number; -{ - Debug(DPARS|DEXT, ("set_element(?,%d,%d,%d)\n", low, high, number)) - - if (number < low || number > high) - return EOF; - - bit_set(bits, (number-low)); - return OK; -} diff --git a/usr.sbin/cron/lib/env.c b/usr.sbin/cron/lib/env.c deleted file mode 100644 index fd35817..0000000 --- a/usr.sbin/cron/lib/env.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - - -#include "cron.h" - - -char ** -env_init() -{ - register char **p = (char **) malloc(sizeof(char *)); - - if (p) - p[0] = NULL; - return (p); -} - - -void -env_free(envp) - char **envp; -{ - char **p; - - if ((p = envp)) - for (; *p; p++) - free(*p); - free(envp); -} - - -char ** -env_copy(envp) - register char **envp; -{ - register int count, i; - register char **p; - - for (count = 0; envp[count] != NULL; count++) - ; - p = (char **) malloc((count+1) * sizeof(char *)); /* 1 for the NULL */ - if (p == NULL) { - errno = ENOMEM; - return NULL; - } - for (i = 0; i < count; i++) - if ((p[i] = strdup(envp[i])) == NULL) { - while (--i >= 0) - (void) free(p[i]); - free(p); - errno = ENOMEM; - return NULL; - } - p[count] = NULL; - return (p); -} - - -char ** -env_set(envp, envstr) - char **envp; - char *envstr; -{ - register int count, found; - register char **p; - char *q; - - /* - * count the number of elements, including the null pointer; - * also set 'found' to -1 or index of entry if already in here. - */ - found = -1; - for (count = 0; envp[count] != NULL; count++) { - if (!strcmp_until(envp[count], envstr, '=')) - found = count; - } - count++; /* for the NULL */ - - if (found != -1) { - /* - * it exists already, so just free the existing setting, - * save our new one there, and return the existing array. - */ - q = envp[found]; - if ((envp[found] = strdup(envstr)) == NULL) { - envp[found] = q; - /* XXX env_free(envp); */ - errno = ENOMEM; - return NULL; - } - free(q); - return (envp); - } - - /* - * it doesn't exist yet, so resize the array, move null pointer over - * one, save our string over the old null pointer, and return resized - * array. - */ - p = (char **) realloc((void *) envp, - (unsigned) ((count+1) * sizeof(char *))); - if (p == NULL) { - /* XXX env_free(envp); */ - errno = ENOMEM; - return NULL; - } - p[count] = p[count-1]; - if ((p[count-1] = strdup(envstr)) == NULL) { - env_free(p); - errno = ENOMEM; - return NULL; - } - return (p); -} - - -/* return ERR = end of file - * FALSE = not an env setting (file was repositioned) - * TRUE = was an env setting - */ -int -load_env(envstr, f) - char *envstr; - FILE *f; -{ - long filepos; - int fileline; - char name[MAX_ENVSTR], val[MAX_ENVSTR]; - char quotechar, *c, *str; - int state; - - /* The following states are traversed in order: */ -#define NAMEI 0 /* First char of NAME, may be quote */ -#define NAME 1 /* Subsequent chars of NAME */ -#define EQ1 2 /* After end of name, looking for '=' sign */ -#define EQ2 3 /* After '=', skipping whitespace */ -#define VALUEI 4 /* First char of VALUE, may be quote */ -#define VALUE 5 /* Subsequent chars of VALUE */ -#define FINI 6 /* All done, skipping trailing whitespace */ -#define ERROR 7 /* Error */ - - filepos = ftell(f); - fileline = LineNumber; - skip_comments(f); - if (EOF == get_string(envstr, MAX_ENVSTR, f, "\n")) - return (ERR); - - Debug(DPARS, ("load_env, read <%s>\n", envstr)); - - bzero (name, sizeof name); - bzero (val, sizeof val); - str = name; - state = NAMEI; - quotechar = '\0'; - c = envstr; - while (state != ERROR && *c) { - switch (state) { - case NAMEI: - case VALUEI: - if (*c == '\'' || *c == '"') - quotechar = *c++; - ++state; - /* FALLTHROUGH */ - case NAME: - case VALUE: - if (quotechar) { - if (*c == quotechar) { - state++; - c++; - break; - } - if (state == NAME && *c == '=') { - state = ERROR; - break; - } - } else { - if (state == NAME) { - if (isspace (*c)) { - c++; - state++; - break; - } - if (*c == '=') { - state++; - break; - } - } - } - *str++ = *c++; - break; - - case EQ1: - if (*c == '=') { - state++; - str = val; - quotechar = '\0'; - } else { - if (!isspace (*c)) - state = ERROR; - } - c++; - break; - case EQ2: - case FINI: - if (isspace (*c)) - c++; - else - state++; - break; - } - } - if (state != FINI && !(state == VALUE && !quotechar)) { - Debug(DPARS, ("load_env, parse error, state = %d\n", state)) - fseek(f, filepos, 0); - Set_LineNum(fileline); - return (FALSE); - } - if (state == VALUE) { - /* End of unquoted value: trim trailing whitespace */ - c = val + strlen (val); - while (c > val && isspace (*(c - 1))) - *(--c) = '\0'; - } - - /* 2 fields from parser; looks like an env setting */ - - if (strlen(name) + 1 + strlen(val) >= MAX_ENVSTR-1) - return (FALSE); - (void) sprintf(envstr, "%s=%s", name, val); - Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr)) - return (TRUE); -} - - -char * -env_get(name, envp) - register char *name; - register char **envp; -{ - register int len = strlen(name); - register char *p, *q; - - while ((p = *envp++)) { - if (!(q = strchr(p, '='))) - continue; - if ((q - p) == len && !strncmp(p, name, len)) - return (q+1); - } - return (NULL); -} diff --git a/usr.sbin/cron/lib/misc.c b/usr.sbin/cron/lib/misc.c deleted file mode 100644 index 5a08ad0..0000000 --- a/usr.sbin/cron/lib/misc.c +++ /dev/null @@ -1,598 +0,0 @@ -/* Copyright 1988,1990,1993,1994 by Paul Vixie - * All rights reserved - * - * Distribute freely, except: don't remove my name from the source or - * documentation (don't take credit for my work), mark your changes (don't - * get me blamed for your possible bugs), don't alter or remove this - * notice. May be sold if buildable source is provided to buyer. No - * warrantee of any kind, express or implied, is included with this - * software; use at your own risk, responsibility for damages (if any) to - * anyone resulting from the use of this software rests entirely with the - * user. - * - * Send bug reports, bug fixes, enhancements, requests, flames, etc., and - * I'll try to keep a version up to date. I can be reached as follows: - * Paul Vixie uunet!decwrl!vixie!paul - */ - -#if !defined(lint) && !defined(LINT) -static const char rcsid[] = - "$FreeBSD$"; -#endif - -/* vix 26jan87 [RCS has the rest of the log] - * vix 30dec86 [written] - */ - - -#include "cron.h" -#if SYS_TIME_H -# include -#else -# include -#endif -#include -#include -#include -#include -#include -#include -#if defined(SYSLOG) -# include -#endif - - -#if defined(LOG_DAEMON) && !defined(LOG_CRON) -#define LOG_CRON LOG_DAEMON -#endif - - -static int LogFD = ERR; - - -int -strcmp_until(left, right, until) - char *left; - char *right; - int until; -{ - register int diff; - - while (*left && *left != until && *left == *right) { - left++; - right++; - } - - if ((*left=='\0' || *left == until) && - (*right=='\0' || *right == until)) { - diff = 0; - } else { - diff = *left - *right; - } - - return diff; -} - - -/* strdtb(s) - delete trailing blanks in string 's' and return new length - */ -int -strdtb(s) - char *s; -{ - char *x = s; - - /* scan forward to the null - */ - while (*x) - x++; - - /* scan backward to either the first character before the string, - * or the last non-blank in the string, whichever comes first. - */ - do {x--;} - while (x >= s && isspace(*x)); - - /* one character beyond where we stopped above is where the null - * goes. - */ - *++x = '\0'; - - /* the difference between the position of the null character and - * the position of the first character of the string is the length. - */ - return x - s; -} - - -int -set_debug_flags(flags) - char *flags; -{ - /* debug flags are of the form flag[,flag ...] - * - * if an error occurs, print a message to stdout and return FALSE. - * otherwise return TRUE after setting ERROR_FLAGS. - */ - -#if !DEBUGGING - - printf("this program was compiled without debugging enabled\n"); - return FALSE; - -#else /* DEBUGGING */ - - char *pc = flags; - - DebugFlags = 0; - - while (*pc) { - char **test; - int mask; - - /* try to find debug flag name in our list. - */ - for ( test = DebugFlagNames, mask = 1; - *test && strcmp_until(*test, pc, ','); - test++, mask <<= 1 - ) - ; - - if (!*test) { - fprintf(stderr, - "unrecognized debug flag <%s> <%s>\n", - flags, pc); - return FALSE; - } - - DebugFlags |= mask; - - /* skip to the next flag - */ - while (*pc && *pc != ',') - pc++; - if (*pc == ',') - pc++; - } - - if (DebugFlags) { - int flag; - - fprintf(stderr, "debug flags enabled:"); - - for (flag = 0; DebugFlagNames[flag]; flag++) - if (DebugFlags & (1 << flag)) - fprintf(stderr, " %s", DebugFlagNames[flag]); - fprintf(stderr, "\n"); - } - - return TRUE; - -#endif /* DEBUGGING */ -} - - -void -set_cron_uid() -{ -#if defined(BSD) || defined(POSIX) - if (seteuid(ROOT_UID) < OK) - err(ERROR_EXIT, "seteuid"); -#else - if (setuid(ROOT_UID) < OK) - err(ERROR_EXIT, "setuid"); -#endif -} - - -void -set_cron_cwd() -{ - struct stat sb; - - /* first check for CRONDIR ("/var/cron" or some such) - */ - if (stat(CRONDIR, &sb) < OK && errno == ENOENT) { - warn("%s", CRONDIR); - if (OK == mkdir(CRONDIR, 0700)) { - warnx("%s: created", CRONDIR); - stat(CRONDIR, &sb); - } else { - err(ERROR_EXIT, "%s: mkdir", CRONDIR); - } - } - if (!(sb.st_mode & S_IFDIR)) - err(ERROR_EXIT, "'%s' is not a directory, bailing out", CRONDIR); - if (chdir(CRONDIR) < OK) - err(ERROR_EXIT, "cannot chdir(%s), bailing out", CRONDIR); - - /* CRONDIR okay (now==CWD), now look at SPOOL_DIR ("tabs" or some such) - */ - if (stat(SPOOL_DIR, &sb) < OK && errno == ENOENT) { - warn("%s", SPOOL_DIR); - if (OK == mkdir(SPOOL_DIR, 0700)) { - warnx("%s: created", SPOOL_DIR); - stat(SPOOL_DIR, &sb); - } else { - err(ERROR_EXIT, "%s: mkdir", SPOOL_DIR); - } - } - if (!(sb.st_mode & S_IFDIR)) - err(ERROR_EXIT, "'%s' is not a directory, bailing out", SPOOL_DIR); -} - - -/* get_char(file) : like getc() but increment LineNumber on newlines - */ -int -get_char(file) - FILE *file; -{ - int ch; - - ch = getc(file); - if (ch == '\n') - Set_LineNum(LineNumber + 1) - return ch; -} - - -/* unget_char(ch, file) : like ungetc but do LineNumber processing - */ -void -unget_char(ch, file) - int ch; - FILE *file; -{ - ungetc(ch, file); - if (ch == '\n') - Set_LineNum(LineNumber - 1) -} - - -/* get_string(str, max, file, termstr) : like fgets() but - * (1) has terminator string which should include \n - * (2) will always leave room for the null - * (3) uses get_char() so LineNumber will be accurate - * (4) returns EOF or terminating character, whichever - */ -int -get_string(string, size, file, terms) - char *string; - int size; - FILE *file; - char *terms; -{ - int ch; - - while (EOF != (ch = get_char(file)) && !strchr(terms, ch)) { - if (size > 1) { - *string++ = (char) ch; - size--; - } - } - - if (size > 0) - *string = '\0'; - - return ch; -} - - -/* skip_comments(file) : read past comment (if any) - */ -void -skip_comments(file) - FILE *file; -{ - int ch; - - while (EOF != (ch = get_char(file))) { - /* ch is now the first character of a line. - */ - - while (ch == ' ' || ch == '\t') - ch = get_char(file); - - if (ch == EOF) - break; - - /* ch is now the first non-blank character of a line. - */ - - if (ch != '\n' && ch != '#') - break; - - /* ch must be a newline or comment as first non-blank - * character on a line. - */ - - while (ch != '\n' && ch != EOF) - ch = get_char(file); - - /* ch is now the newline of a line which we're going to - * ignore. - */ - } - if (ch != EOF) - unget_char(ch, file); -} - - -/* int in_file(char *string, FILE *file) - * return TRUE if one of the lines in file matches string exactly, - * FALSE otherwise. - */ -static int -in_file(char *string, FILE *file) -{ - char line[MAX_TEMPSTR]; - - rewind(file); - while (fgets(line, MAX_TEMPSTR, file)) { - if (line[0] != '\0') - if (line[strlen(line)-1] == '\n') - line[strlen(line)-1] = '\0'; - if (0 == strcmp(line, string)) - return TRUE; - } - return FALSE; -} - - -/* int allowed(char *username) - * returns TRUE if (ALLOW_FILE exists and user is listed) - * or (DENY_FILE exists and user is NOT listed) - * or (neither file exists but user=="root" so it's okay) - */ -int -allowed(username) - char *username; -{ - FILE *allow, *deny; - int isallowed; - - isallowed = FALSE; - - deny = NULL; -#if defined(ALLOW_FILE) && defined(DENY_FILE) - if ((allow = fopen(ALLOW_FILE, "r")) == NULL && errno != ENOENT) - goto out; - if ((deny = fopen(DENY_FILE, "r")) == NULL && errno != ENOENT) - goto out; - Debug(DMISC, ("allow/deny enabled, %d/%d\n", !!allow, !!deny)) -#else - allow = NULL; -#endif - - if (allow) - isallowed = in_file(username, allow); - else if (deny) - isallowed = !in_file(username, deny); - else { -#if defined(ALLOW_ONLY_ROOT) - isallowed = (strcmp(username, ROOT_USER) == 0); -#else - isallowed = TRUE; -#endif - } -out: if (allow) - fclose(allow); - if (deny) - fclose(deny); - return (isallowed); -} - - -void -log_it(username, xpid, event, detail) - char *username; - int xpid; - char *event; - char *detail; -{ - PID_T pid = xpid; -#if defined(LOG_FILE) - char *msg; - TIME_T now = time((TIME_T) 0); - register struct tm *t = localtime(&now); -#endif /*LOG_FILE*/ - -#if defined(SYSLOG) - static int syslog_open = 0; -#endif - -#if defined(LOG_FILE) - /* we assume that MAX_TEMPSTR will hold the date, time, &punctuation. - */ - msg = malloc(strlen(username) - + strlen(event) - + strlen(detail) - + MAX_TEMPSTR); - - if (msg == NULL) - warnx("failed to allocate memory for log message"); - else { - if (LogFD < OK) { - LogFD = open(LOG_FILE, O_WRONLY|O_APPEND|O_CREAT, 0600); - if (LogFD < OK) { - warn("can't open log file %s", LOG_FILE); - } else { - (void) fcntl(LogFD, F_SETFD, 1); - } - } - - /* we have to sprintf() it because fprintf() doesn't always - * write everything out in one chunk and this has to be - * atomically appended to the log file. - */ - sprintf(msg, "%s (%02d/%02d-%02d:%02d:%02d-%d) %s (%s)\n", - username, - t->tm_mon+1, t->tm_mday, t->tm_hour, t->tm_min, - t->tm_sec, pid, event, detail); - - /* we have to run strlen() because sprintf() returns (char*) - * on old BSD. - */ - if (LogFD < OK || write(LogFD, msg, strlen(msg)) < OK) { - if (LogFD >= OK) - warn("%s", LOG_FILE); - warnx("can't write to log file"); - write(STDERR, msg, strlen(msg)); - } - - free(msg); - } -#endif /*LOG_FILE*/ - -#if defined(SYSLOG) - if (!syslog_open) { - /* we don't use LOG_PID since the pid passed to us by - * our client may not be our own. therefore we want to - * print the pid ourselves. - */ -# ifdef LOG_DAEMON - openlog(ProgramName, LOG_PID, LOG_CRON); -# else - openlog(ProgramName, LOG_PID); -# endif - syslog_open = TRUE; /* assume openlog success */ - } - - syslog(LOG_INFO, "(%s) %s (%s)\n", username, event, detail); - -#endif /*SYSLOG*/ - -#if DEBUGGING - if (DebugFlags) { - fprintf(stderr, "log_it: (%s %d) %s (%s)\n", - username, pid, event, detail); - } -#endif -} - - -void -log_close() { - if (LogFD != ERR) { - close(LogFD); - LogFD = ERR; - } -} - - -/* two warnings: - * (1) this routine is fairly slow - * (2) it returns a pointer to static storage - */ -char * -first_word(s, t) - register char *s; /* string we want the first word of */ - register char *t; /* terminators, implicitly including \0 */ -{ - static char retbuf[2][MAX_TEMPSTR + 1]; /* sure wish C had GC */ - static int retsel = 0; - register char *rb, *rp; - - /* select a return buffer */ - retsel = 1-retsel; - rb = &retbuf[retsel][0]; - rp = rb; - - /* skip any leading terminators */ - while (*s && (NULL != strchr(t, *s))) { - s++; - } - - /* copy until next terminator or full buffer */ - while (*s && (NULL == strchr(t, *s)) && (rp < &rb[MAX_TEMPSTR])) { - *rp++ = *s++; - } - - /* finish the return-string and return it */ - *rp = '\0'; - return rb; -} - - -/* warning: - * heavily ascii-dependent. - */ -static void -mkprint(register char *dst, register unsigned char *src, register int len) -{ - while (len-- > 0) - { - register unsigned char ch = *src++; - - if (ch < ' ') { /* control character */ - *dst++ = '^'; - *dst++ = ch + '@'; - } else if (ch < 0177) { /* printable */ - *dst++ = ch; - } else if (ch == 0177) { /* delete/rubout */ - *dst++ = '^'; - *dst++ = '?'; - } else { /* parity character */ - sprintf(dst, "\\%03o", ch); - dst += 4; - } - } - *dst = '\0'; -} - - -/* warning: - * returns a pointer to malloc'd storage, you must call free yourself. - */ -char * -mkprints(src, len) - register unsigned char *src; - register unsigned int len; -{ - register char *dst = malloc(len*4 + 1); - - if (dst != NULL) - mkprint(dst, src, len); - - return dst; -} - - -#ifdef MAIL_DATE -/* Sat, 27 Feb 93 11:44:51 CST - * 123456789012345678901234567 - */ -char * -arpadate(clock) - time_t *clock; -{ - time_t t = clock ?*clock :time(0L); - struct tm *tm = localtime(&t); - static char ret[32]; /* zone name might be >3 chars */ - - if (tm->tm_year >= 100) - tm->tm_year += 1900; - - (void) snprintf(ret, sizeof(ret), "%s, %2d %s %d %02d:%02d:%02d %s", - DowNames[tm->tm_wday], - tm->tm_mday, - MonthNames[tm->tm_mon], - tm->tm_year, - tm->tm_hour, - tm->tm_min, - tm->tm_sec, - TZONE(*tm)); - return ret; -} -#endif /*MAIL_DATE*/ - - -#ifdef HAVE_SAVED_UIDS -static int save_euid; -int swap_uids() { save_euid = geteuid(); return seteuid(getuid()); } -int swap_uids_back() { return seteuid(save_euid); } -#else /*HAVE_SAVED_UIDS*/ -int swap_uids() { return setreuid(geteuid(), getuid()); } -int swap_uids_back() { return swap_uids(); } -#endif /*HAVE_SAVED_UIDS*/ diff --git a/usr.sbin/crunch/COPYRIGHT b/usr.sbin/crunch/COPYRIGHT deleted file mode 100644 index c7b4d2f..0000000 --- a/usr.sbin/crunch/COPYRIGHT +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 1994 University of Maryland - * All Rights Reserved. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of U.M. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. U.M. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: James da Silva, Systems Design and Analysis Group - * Computer Science Department - * University of Maryland at College Park - */ diff --git a/usr.sbin/crunch/Makefile b/usr.sbin/crunch/Makefile deleted file mode 100644 index 6bf600f..0000000 --- a/usr.sbin/crunch/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -SUBDIR= crunchgen crunchide - -.include diff --git a/usr.sbin/crunch/Makefile.inc b/usr.sbin/crunch/Makefile.inc deleted file mode 100644 index 36175b7..0000000 --- a/usr.sbin/crunch/Makefile.inc +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -# modify to taste -BINDIR?= /usr/bin - -WARNS?= 2 diff --git a/usr.sbin/crunch/README b/usr.sbin/crunch/README deleted file mode 100644 index 27c2d02..0000000 --- a/usr.sbin/crunch/README +++ /dev/null @@ -1,88 +0,0 @@ - -CRUNCH 0.2 README 6/14/94 - -Crunch is available via anonymous ftp to ftp.cs.umd.edu in - pub/bsd/crunch-0.2.tar.gz - - -WHAT'S NEW IN 0.2 - -* The prototype awk script has been replaced by a more capable and - hopefully more robust C program. -* No fragile template makefiles or dependencies on the details of the - bsd build environment. -* You can build crunched binaries even with no sources on-line, you - just need the .o files. Crunchgen still will try to figure out as - much as possible on its own, but you can override its guessing by - specifying the list of .o files explicitly. -* Crunch itself has been bmake'd and some man pages written, so it - should be ready to install. - - -INTRODUCTION - -Crunch is a little package that helps create "crunched" binaries for use -on boot, install, and fixit floppies. A crunched binary in this case is -one where many programs have been linked together into one a.out file. -The different programs are run depending on the value of argv[0], so -hard links to the crunched binary suffice to simulate a perfectly normal -system. - -As an example, I have created an 980K crunched "fixit" binary containing -the following programs in their entirety: - - cat chmod cp date dd df echo ed expr hostname kill ln ls mkdir - mt mv pwd rcp rm rmdir sh sleep stty sync test [ badsect chown - clri disklabel dump rdump dmesg fdisk fsck halt ifconfig init - mknod mount newfs ping reboot restore rrestore swapon umount - ftp rsh sed telnet rlogin vi cpio gzip gunzip gzcat - -Note carefully: vi, cpio, gzip, ed, sed, dump/restore, some networking -utilities, and the disk management utilities, all in a binary small -enough to fit on a 1.2 MB root filesystem floppy (albeit with the kernel -on its own boot floppy). A more reasonable subset can be made to fit -easily with a kernel for a decent one-disk fixit filesystem. - -The linking together of different programs by hand is an old -space-saving technique. Crunch automates the process by building the -necessary stub files and makefile for you (via the crunchgen program), -and by doctoring the symbol tables of the component .o files to allow -them to link without "symbol multiply defined" conflicts (via the -crunchide program). - - -BUILDING CRUNCH - -Just type make, then make install. - -Crunch was written and tested under NetBSD/i386, but should work under -other PC BSD systems that use GNU ld. - -The crunchgen(1) and crunchide(1) man pages have more details on using -crunch, and the examples subdirectory contains some working .conf files -and a sample Makefile. - -CREDITS - -Thanks to the NetBSD team for a consistently high quality effort in -bringing together a solid, state of the art development environment. - -Thanks to the FreeBSD guys; Rod Grimes, Nate Williams and Jordan -Hubbard; and to Bruce Evans, for immediate and detailed feedback on -crunch 0.1, and for pressing me to make the prototype more useable. - -Crunch was written for the Maruti Hard Real-Time Operating System -project at the University of Maryland, to help make for better install -and recovery procedures for our NetBSD-based development environment. It -is copyright (c) 1994 by the University of Maryland under a UCB-style -freely- redistributable notice. See the file COPYRIGHT for details. - -Please let me know of any problems or of enhancements you make to this -package. I'm particularly interested in the details of what you found -was good to put on your fixit or install disks. Thanks! - -Share and Enjoy, -Jaime -............................................................................ -: Stand on my shoulders, : jds@cs.umd.edu : James da Silva -: not on my toes. : uunet!mimsy!jds : http://www.cs.umd.edu/users/jds diff --git a/usr.sbin/crunch/crunchgen/Makefile b/usr.sbin/crunch/crunchgen/Makefile deleted file mode 100644 index 8d0a78b..0000000 --- a/usr.sbin/crunch/crunchgen/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $FreeBSD$ - -PROG= crunchgen -SRCS= crunchgen.c crunched_skel.c -CLEANFILES+= crunched_skel.c - -crunched_skel.c: crunched_main.c - sh -e ${.CURDIR}/mkskel.sh ${.CURDIR}/crunched_main.c >crunched_skel.c - -.include diff --git a/usr.sbin/crunch/crunchgen/crunched_main.c b/usr.sbin/crunch/crunchgen/crunched_main.c deleted file mode 100644 index df40d9d..0000000 --- a/usr.sbin/crunch/crunchgen/crunched_main.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 1994 University of Maryland - * All Rights Reserved. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of U.M. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. U.M. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: James da Silva, Systems Design and Analysis Group - * Computer Science Department - * University of Maryland at College Park - * - * $FreeBSD$ - */ -/* - * crunched_main.c - main program for crunched binaries, it branches to a - * particular subprogram based on the value of argv[0]. Also included - * is a little program invoked when the crunched binary is called via - * its EXECNAME. This one prints out the list of compiled-in binaries, - * or calls one of them based on argv[1]. This allows the testing of - * the crunched binary without creating all the links. - */ -#include -#include -#include - -struct stub { - char *name; - int (*f)(); -}; - -extern char *__progname; -extern struct stub entry_points[]; - -int main(int argc, char **argv, char **envp) -{ - char *slash, *basename; - struct stub *ep; - - if(argv[0] == NULL || *argv[0] == '\0') - crunched_usage(); - - slash = strrchr(argv[0], '/'); - basename = slash? slash+1 : argv[0]; - - for(ep=entry_points; ep->name != NULL; ep++) - if(!strcmp(basename, ep->name)) break; - - if(ep->name) - return ep->f(argc, argv, envp); - else { - fprintf(stderr, "%s: %s not compiled in\n", EXECNAME, basename); - crunched_usage(); - } -} - - -int crunched_here(char *path) -{ - char *slash, *basename; - struct stub *ep; - - slash = strrchr(path, '/'); - basename = slash? slash+1 : path; - - for(ep=entry_points; ep->name != NULL; ep++) - if(!strcmp(basename, ep->name)) - return 1; - return 0; -} - - -int crunched_main(int argc, char **argv, char **envp) -{ - char *slash; - struct stub *ep; - int columns, len; - - if(argc <= 1) - crunched_usage(); - - slash = strrchr(argv[1], '/'); - __progname = slash? slash+1 : argv[1]; - - return main(--argc, ++argv, envp); -} - - -int crunched_usage() -{ - int columns, len; - struct stub *ep; - - fprintf(stderr, "usage: %s ..., where is one of:\n", - EXECNAME); - columns = 0; - for(ep=entry_points; ep->name != NULL; ep++) { - len = strlen(ep->name) + 1; - if(columns+len < 80) - columns += len; - else { - fprintf(stderr, "\n"); - columns = len; - } - fprintf(stderr, " %s", ep->name); - } - fprintf(stderr, "\n"); - exit(1); -} - -/* end of crunched_main.c */ - diff --git a/usr.sbin/crunch/crunchgen/crunchgen.1 b/usr.sbin/crunch/crunchgen/crunchgen.1 deleted file mode 100644 index 66fe8f3..0000000 --- a/usr.sbin/crunch/crunchgen/crunchgen.1 +++ /dev/null @@ -1,475 +0,0 @@ -.\" -.\" Copyright (c) 1994 University of Maryland -.\" All Rights Reserved. -.\" -.\" Permission to use, copy, modify, distribute, and sell this software and its -.\" documentation for any purpose is hereby granted without fee, provided that -.\" the above copyright notice appear in all copies and that both that -.\" copyright notice and this permission notice appear in supporting -.\" documentation, and that the name of U.M. not be used in advertising or -.\" publicity pertaining to distribution of the software without specific, -.\" written prior permission. U.M. makes no representations about the -.\" suitability of this software for any purpose. It is provided "as is" -.\" without express or implied warranty. -.\" -.\" U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. -.\" BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -.\" IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.\" Author: James da Silva, Systems Design and Analysis Group -.\" Computer Science Department -.\" University of Maryland at College Park -.\" $FreeBSD$ -.\" -.Dd December 23, 2005 -.Dt CRUNCHGEN 1 -.Os -.Sh NAME -.Nm crunchgen -.Nd generates build environment for a crunched binary -.Sh SYNOPSIS -.Bk -words -.Nm -.Op Fl foql -.Op Fl h Ar makefile-header-name -.Op Fl m Ar makefile-name -.Op Fl p Ar obj-prefix -.Op Fl c Ar c-file-name -.Op Fl e Ar exec-file-name -.Op Ar conf-file -.Ek -.Sh DESCRIPTION -A crunched binary is a program made up of many other programs linked -together into a single executable. -The crunched binary -.Fn main -function determines which component program to run by the contents of -.Va argv[0] . -The main reason to crunch programs together is for fitting -as many programs as possible onto an installation or system recovery -floppy. -.Pp -The -.Nm -utility reads in the specifications in -.Ar conf-file -for a crunched binary, and generates a -.Pa Makefile -and accompanying -top-level C source file that when built creates the crunched executable -file from the component programs. -For each component program, -.Nm -can optionally attempt to determine the object (.o) files that make up -the program from its source directory -.Pa Makefile . -This information is cached between runs. -The -.Nm -utility uses the companion program -.Xr crunchide 1 -to eliminate link-time conflicts between the component programs by -hiding all unnecessary symbols. -.Pp -The -.Nm -utility places specific requirements on package -.Pa Makefile Ns s -which make it unsuitable for use with -.No non- Ns Bx -sources. -In particular, the -.Pa Makefile -must contain the target -.Ic depend , -and it must define all object files in the variable -.Va OBJS . -In some cases, you can use a fake -.Pa Makefile : -before looking for -.Pa Makefile -in the source directory -.Pa foo , -.Nm -looks for the file -.Pa Makefile.foo -in the current directory. -.Pp -After -.Nm -is run, the crunched binary can be built by running -.Dq Li make -f .mk . -The component programs' object files must already be built. -An -.Ic objs -target, included in the output makefile, will -run -.Xr make 1 -in each component program's source dir to build the object -files for the user. -This is not done automatically since in release -engineering circumstances it is generally not desirable to be -modifying objects in other directories. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl c Ar c-file-name -Set output C file name to -.Ar c-file-name . -The default name is -.Pa .c . -.It Fl e Ar exec-file-name -Set crunched binary executable file name to -.Ar exec-file-name . -The default name is -.Pa . -.It Fl f -Flush cache. -Forces the recalculation of cached parameters. -.It Fl l -List names. -Lists the names this binary will respond to. -.It Fl h Ar makefile-header-name -Set the name of a file to be included at the beginning of the -.Pa Makefile Ns s -generated by -.Nm . -This is useful to define some make variables such as -.Va RELEASE_CRUNCH -or similar, which might affect the behavior of -.Xr make 1 -and are annoying to pass through environment variables. -.It Fl m Ar makefile-name -Set output -.Pa Makefile -name to -.Ar makefile-name . -The default name is -.Pa .mk . -.It Fl o -Add -.Dq Li make obj -rules to each program make target. -.It Fl p Ar obj-prefix -Set the pathname to be prepended to the -.Ic srcdir -when computing the -.Ic objdir . -If this option is not present, then the prefix used -is the content of the -.Ev MAKEOBJDIRPREFIX -environment variable, or -.Pa /usr/obj . -.It Fl q -Quiet operation. -Status messages are suppressed. -.El -.Sh CRUNCHGEN CONFIGURATION FILE COMMANDS -The -.Nm -utility reads specifications from the -.Ar conf-file -that describe the components of the crunched binary. -In its simplest -use, the component program names are merely listed along with the -top-level source directories in which their sources can be found. -The -.Nm -utility then calculates (via the source makefiles) and caches the -list of object files and their locations. -For more specialized -situations, the user can specify by hand all the parameters that -.Nm -needs. -.Pp -The -.Ar conf-file -commands are as follows: -.Bl -tag -width indent -.It Ic srcdirs Ar dirname ... -A list of source trees in which the source directories of the -component programs can be found. -These dirs are searched using the -.Bx -.Dq Pa // -convention. -Multiple -.Ic srcdirs -lines can be specified. -The directories are searched in the order they are given. -.It Ic progs Ar progname ... -A list of programs that make up the crunched binary. -Multiple -.Ic progs -lines can be specified. -.It Ic libs Ar libspec ... -A list of library specifications to be included in the crunched binary link. -Multiple -.Ic libs -lines can be specified. -.It Ic libs_so Ar libspec ... -A list of library specifications to be dynamically linked in the -crunched binary. -These libraries will need to be made available via the run-time link-editor -.Xr rtld 1 -when the component program that requires them is executed from -the crunched binary. -Multiple -.Ic libs_so -lines can be specified. -The -.Ic libs_so -directive overrides a library specified gratuitously on a -.Ic libs -line. -.It Ic buildopts Ar buildopts ... -A list of build options to be added to every make target. -.It Ic ln Ar progname linkname -Causes the crunched binary to invoke -.Ar progname -whenever -.Ar linkname -appears in -.Va argv[0] . -This allows programs that change their behavior when -run under different names to operate correctly. -.El -.Pp -To handle specialized situations, such as when the source is not -available or not built via a conventional -.Pa Makefile , -the following -.Ic special -commands can be used to set -.Nm -parameters for a component program. -.Bl -tag -width indent -.It Ic special Ar progname Ic srcdir Ar pathname -Set the source directory for -.Ar progname . -This is normally calculated by searching the specified -.Ic srcdirs -for a directory named -.Ar progname . -.It Ic special Ar progname Ic objdir Ar pathname -Set the -.Pa obj -directory for -.Ar progname . -The -.Pa obj -directory is normally calculated by looking for a directory -whose name is that of the source directory prepended by -one of the following components, in order of priority: -the -.Fl p -argument passed to the command line; or, -the value of the -.Ev MAKEOBJDIRPREFIX -environment variable, or -.Pa /usr/obj . -If the directory is not found, the -.Ic srcdir -itself becomes the -.Ic objdir . -.It Ic special Ar progname Ic buildopts Ar buildopts -Define a set of build options that should be added to -.Xr make 1 -targets in addition to those specified using -.Ic buildopts -when processing -.Ar progname . -.It Ic special Ar progname Ic objs Ar object-file-name ... -Set the list of object files for program -.Ar progname . -This is normally calculated by constructing a temporary makefile that includes -.Dq Ic srcdir Ns / Ns Pa Makefile -and outputs the value of -.Va $(OBJS) . -.It Ic special Ar progname Ic objpaths Ar full-pathname-to-object-file ... -Sets the pathnames of the object files for program -.Ar progname . -This is normally calculated by prepending the -.Ic objdir -pathname to each file in the -.Ic objs -list. -.It Ic special Ar progname Ic objvar Ar variable_name -Sets the name of the -.Xr make 1 -variable which holds the list of -object files for program -.Ar progname . -This is normally -.Va OBJS -but some -.Pa Makefile Ns s -might like to use other conventions or -prepend the program's name to the variable, e.g.\& -.Va SSHD_OBJS . -.It Ic special Ar progname Ic lib Ar library-name ... -Specifies libraries to be linked with object files to produce -.Ar progname Ns Pa .lo . -This can be useful with libraries which redefine routines in -the standard libraries, or poorly written libraries which -reference symbols in the object files. -.It Ic special Ar progname Ic keep Ar symbol-name ... -Add specified list of symbols to the keep list for program -.Ar progname . -An underscore -.Pq Ql _ -is prepended to each symbol and it becomes the argument to a -.Fl k -option for the -.Xr crunchide 1 -phase. -This option is to be used as a last resort as its use can cause a -symbol conflict, however in certain instances it may be the only way to -have a symbol resolve. -.It Ic special Ar progname Ic ident Ar identifier -Set the -.Pa Makefile Ns / Ns Tn C -identifier for -.Ar progname . -This is normally generated from a -.Ar progname , -mapping -.Ql - -to -.Ql _ -and ignoring all other non-identifier characters. -This leads to programs named -.Qq Li foo.bar -and -.Qq Li foobar -to map to the same identifier. -.El -.Pp -Only the -.Ic objpaths -parameter is actually needed by -.Nm , -but it is calculated from -.Ic objdir -and -.Ic objs , -which are in turn calculated from -.Ic srcdir , -so is sometimes convenient to specify the earlier parameters and let -.Nm -calculate forward from there if it can. -.Pp -The makefile produced by -.Nm -contains an optional -.Ic objs -target that will build the object files for each component program by -running -.Xr make 1 -inside that program's source directory. -For this to work the -.Ic srcdir -and -.Ic objs -parameters must also be valid. -If they are not valid for a particular program, that -program is skipped in the -.Ic objs -target. -.Sh EXAMPLES -Here is an example -.Nm -input conf file, named -.Dq Pa kcopy.conf : -.Bd -literal -offset indent -srcdirs /usr/src/bin /usr/src/sbin - -progs test cp echo sh fsck halt init mount umount myinstall -progs anotherprog -ln test [ # test can be invoked via [ -ln sh -sh # init invokes the shell with "-sh" in argv[0] - -special myprog objpaths /homes/leroy/src/myinstall.o # no sources - -special anotherprog -DNO_FOO WITHOUT_BAR=YES - -libs -lutil -lcrypt -.Ed -.Pp -This conf file specifies a small crunched binary consisting of some -basic system utilities plus a homegrown install program -.Dq Pa myinstall , -for which no source directory is specified, but its object file is -specified directly with the -.Ic special -line. -.Pp -Additionally when -.Dq Pa anotherprog -is built the arguments -.Pp -.Dl -DNO_FOO WITHOUT_BAR=YES -.Pp -are added to all build targets. -.Pp -The crunched binary -.Dq Pa kcopy -can be built as follows: -.Bd -literal -offset indent -% crunchgen -m Makefile kcopy.conf # gen Makefile and kcopy.c -% make objs # build the component programs' .o files -% make # build the crunched binary kcopy -% kcopy sh # test that this invokes a sh shell -$ # it works! -.Ed -.Pp -At this point the binary -.Dq Pa kcopy -can be copied onto an install floppy -and hard-linked to the names of the component programs. -.Pp -Note that if the -.Ic libs_so -command had been used, copies of the libraries so named -would also need to be copied to the install floppy. -.Sh SEE ALSO -.Xr crunchide 1 , -.Xr make 1 , -.Xr rtld 1 -.Sh AUTHORS -.An -nosplit -The -.Nm -utility was written by -.An James da Silva Aq jds@cs.umd.edu . -.Pp -Copyright (c) 1994 University of Maryland. -All Rights Reserved. -.Pp -The -.Ic libs_so -keyword was added in 2005 by -.An Adrian Steinmann Aq ast@marabu.ch -and -.An Ceri Davies Aq ceri@FreeBSD.org . -.Sh CAVEATS -While -.Nm -takes care to eliminate link conflicts between the component programs -of a crunched binary, conflicts are still possible between the -libraries that are linked in. -Some shuffling in the order of -libraries may be required, and in some rare cases two libraries may -have an unresolvable conflict and thus cannot be crunched together. -.Pp -Some versions of the -.Bx -build environment do not by default build the -intermediate object file for single-source file programs. -The -.Dq Li make objs -must then be used to get those object files built, or -some other arrangements made. diff --git a/usr.sbin/crunch/crunchgen/crunchgen.c b/usr.sbin/crunch/crunchgen/crunchgen.c deleted file mode 100644 index 752acc6..0000000 --- a/usr.sbin/crunch/crunchgen/crunchgen.c +++ /dev/null @@ -1,1196 +0,0 @@ -/* - * Copyright (c) 1994 University of Maryland - * All Rights Reserved. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of U.M. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. U.M. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: James da Silva, Systems Design and Analysis Group - * Computer Science Department - * University of Maryland at College Park - * - * $FreeBSD$ - */ -/* - * ======================================================================== - * crunchgen.c - * - * Generates a Makefile and main C file for a crunched executable, - * from specs given in a .conf file. - */ -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define CRUNCH_VERSION "0.2" - -#define MAXLINELEN 16384 -#define MAXFIELDS 2048 - - -/* internal representation of conf file: */ - -/* simple lists of strings suffice for most parms */ - -typedef struct strlst { - struct strlst *next; - char *str; -} strlst_t; - -/* progs have structure, each field can be set with "special" or calculated */ - -typedef struct prog { - struct prog *next; /* link field */ - char *name; /* program name */ - char *ident; /* C identifier for the program name */ - char *srcdir; - char *realsrcdir; - char *objdir; - char *objvar; /* Makefile variable to replace OBJS */ - strlst_t *objs, *objpaths; - strlst_t *buildopts; - strlst_t *keeplist; - strlst_t *links; - strlst_t *libs; - strlst_t *libs_so; - int goterror; -} prog_t; - - -/* global state */ - -strlst_t *buildopts = NULL; -strlst_t *srcdirs = NULL; -strlst_t *libs = NULL; -strlst_t *libs_so = NULL; -prog_t *progs = NULL; - -char confname[MAXPATHLEN], infilename[MAXPATHLEN]; -char outmkname[MAXPATHLEN], outcfname[MAXPATHLEN], execfname[MAXPATHLEN]; -char tempfname[MAXPATHLEN], cachename[MAXPATHLEN], curfilename[MAXPATHLEN]; -char outhdrname[MAXPATHLEN] ; /* user-supplied header for *.mk */ -char *objprefix; /* where are the objects ? */ -int linenum = -1; -int goterror = 0; - -int verbose, readcache; /* options */ -int reading_cache; -int makeobj = 0; /* add 'make obj' rules to the makefile */ - -int list_mode; - -/* general library routines */ - -void status(char *str); -void out_of_memory(void); -void add_string(strlst_t **listp, char *str); -int is_dir(char *pathname); -int is_nonempty_file(char *pathname); -int subtract_strlst(strlst_t **lista, strlst_t **listb); -int in_list(strlst_t **listp, char *str); - -/* helper routines for main() */ - -void usage(void); -void parse_conf_file(void); -void gen_outputs(void); - - -int main(int argc, char **argv) -{ - char *p; - int optc; - - verbose = 1; - readcache = 1; - *outmkname = *outcfname = *execfname = '\0'; - - p = getenv("MAKEOBJDIRPREFIX"); - if (p == NULL || *p == '\0') - objprefix = "/usr/obj"; /* default */ - else - if ((objprefix = strdup(p)) == NULL) - out_of_memory(); - - while((optc = getopt(argc, argv, "lh:m:c:e:p:foq")) != -1) { - switch(optc) { - case 'f': - readcache = 0; - break; - case 'o': - makeobj = 1; - break; - case 'q': - verbose = 0; - break; - - case 'm': - strlcpy(outmkname, optarg, sizeof(outmkname)); - break; - case 'p': - if ((objprefix = strdup(optarg)) == NULL) - out_of_memory(); - break; - - case 'h': - strlcpy(outhdrname, optarg, sizeof(outhdrname)); - break; - case 'c': - strlcpy(outcfname, optarg, sizeof(outcfname)); - break; - case 'e': - strlcpy(execfname, optarg, sizeof(execfname)); - break; - - case 'l': - list_mode++; - verbose = 0; - break; - - case '?': - default: - usage(); - } - } - - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - /* - * generate filenames - */ - - strlcpy(infilename, argv[0], sizeof(infilename)); - - /* confname = `basename infilename .conf` */ - - if ((p=strrchr(infilename, '/')) != NULL) - strlcpy(confname, p + 1, sizeof(confname)); - else - strlcpy(confname, infilename, sizeof(confname)); - - if ((p=strrchr(confname, '.')) != NULL && !strcmp(p, ".conf")) - *p = '\0'; - - if (!*outmkname) - snprintf(outmkname, sizeof(outmkname), "%s.mk", confname); - if (!*outcfname) - snprintf(outcfname, sizeof(outcfname), "%s.c", confname); - if (!*execfname) - snprintf(execfname, sizeof(execfname), "%s", confname); - - snprintf(cachename, sizeof(cachename), "%s.cache", confname); - snprintf(tempfname, sizeof(tempfname), "%s/crunchgen_%sXXXXXX", - getenv("TMPDIR") ? getenv("TMPDIR") : _PATH_TMP, confname); - - parse_conf_file(); - if (list_mode) - exit(goterror); - - gen_outputs(); - - exit(goterror); -} - - -void usage(void) -{ - fprintf(stderr, "%s%s\n\t%s%s\n", "usage: crunchgen [-foq] ", - "[-h ] [-m ]", - "[-p ] [-c ] [-e ] ", - ""); - exit(1); -} - - -/* - * ======================================================================== - * parse_conf_file subsystem - * - */ - -/* helper routines for parse_conf_file */ - -void parse_one_file(char *filename); -void parse_line(char *line, int *fc, char **fv, int nf); -void add_srcdirs(int argc, char **argv); -void add_progs(int argc, char **argv); -void add_link(int argc, char **argv); -void add_libs(int argc, char **argv); -void add_libs_so(int argc, char **argv); -void add_buildopts(int argc, char **argv); -void add_special(int argc, char **argv); - -prog_t *find_prog(char *str); -void add_prog(char *progname); - - -void parse_conf_file(void) -{ - if (!is_nonempty_file(infilename)) - errx(1, "fatal: input file \"%s\" not found", infilename); - - parse_one_file(infilename); - if (readcache && is_nonempty_file(cachename)) { - reading_cache = 1; - parse_one_file(cachename); - } -} - - -void parse_one_file(char *filename) -{ - char *fieldv[MAXFIELDS]; - int fieldc; - void (*f)(int c, char **v); - FILE *cf; - char line[MAXLINELEN]; - - snprintf(line, sizeof(line), "reading %s", filename); - status(line); - strlcpy(curfilename, filename, sizeof(curfilename)); - - if ((cf = fopen(curfilename, "r")) == NULL) { - warn("%s", curfilename); - goterror = 1; - return; - } - - linenum = 0; - while (fgets(line, MAXLINELEN, cf) != NULL) { - linenum++; - parse_line(line, &fieldc, fieldv, MAXFIELDS); - - if (fieldc < 1) - continue; - - if (!strcmp(fieldv[0], "srcdirs")) - f = add_srcdirs; - else if(!strcmp(fieldv[0], "progs")) - f = add_progs; - else if(!strcmp(fieldv[0], "ln")) - f = add_link; - else if(!strcmp(fieldv[0], "libs")) - f = add_libs; - else if(!strcmp(fieldv[0], "libs_so")) - f = add_libs_so; - else if(!strcmp(fieldv[0], "buildopts")) - f = add_buildopts; - else if(!strcmp(fieldv[0], "special")) - f = add_special; - else { - warnx("%s:%d: skipping unknown command `%s'", - curfilename, linenum, fieldv[0]); - goterror = 1; - continue; - } - - if (fieldc < 2) { - warnx("%s:%d: %s %s", - curfilename, linenum, fieldv[0], - "command needs at least 1 argument, skipping"); - goterror = 1; - continue; - } - - f(fieldc, fieldv); - } - - if (ferror(cf)) { - warn("%s", curfilename); - goterror = 1; - } - fclose(cf); -} - - -void parse_line(char *line, int *fc, char **fv, int nf) -{ - char *p; - - p = line; - *fc = 0; - - while (1) { - while (isspace(*p)) - p++; - - if (*p == '\0' || *p == '#') - break; - - if (*fc < nf) - fv[(*fc)++] = p; - - while (*p && !isspace(*p) && *p != '#') - p++; - - if (*p == '\0' || *p == '#') - break; - - *p++ = '\0'; - } - - if (*p) - *p = '\0'; /* needed for '#' case */ -} - - -void add_srcdirs(int argc, char **argv) -{ - int i; - - for (i = 1; i < argc; i++) { - if (is_dir(argv[i])) - add_string(&srcdirs, argv[i]); - else { - warnx("%s:%d: `%s' is not a directory, skipping it", - curfilename, linenum, argv[i]); - goterror = 1; - } - } -} - - -void add_progs(int argc, char **argv) -{ - int i; - - for (i = 1; i < argc; i++) - add_prog(argv[i]); -} - - -void add_prog(char *progname) -{ - prog_t *p1, *p2; - - /* add to end, but be smart about dups */ - - for (p1 = NULL, p2 = progs; p2 != NULL; p1 = p2, p2 = p2->next) - if (!strcmp(p2->name, progname)) - return; - - p2 = malloc(sizeof(prog_t)); - if(p2) { - memset(p2, 0, sizeof(prog_t)); - p2->name = strdup(progname); - } - if (!p2 || !p2->name) - out_of_memory(); - - p2->next = NULL; - if (p1 == NULL) - progs = p2; - else - p1->next = p2; - - p2->ident = NULL; - p2->srcdir = NULL; - p2->realsrcdir = NULL; - p2->objdir = NULL; - p2->links = NULL; - p2->libs = NULL; - p2->libs_so = NULL; - p2->objs = NULL; - p2->keeplist = NULL; - p2->buildopts = NULL; - p2->goterror = 0; - - if (list_mode) - printf("%s\n",progname); -} - - -void add_link(int argc, char **argv) -{ - int i; - prog_t *p = find_prog(argv[1]); - - if (p == NULL) { - warnx("%s:%d: no prog %s previously declared, skipping link", - curfilename, linenum, argv[1]); - goterror = 1; - return; - } - - for (i = 2; i < argc; i++) { - if (list_mode) - printf("%s\n",argv[i]); - - add_string(&p->links, argv[i]); - } -} - - -void add_libs(int argc, char **argv) -{ - int i; - - for(i = 1; i < argc; i++) { - add_string(&libs, argv[i]); - if ( in_list(&libs_so, argv[i]) ) - warnx("%s:%d: " - "library `%s' specified as dynamic earlier", - curfilename, linenum, argv[i]); - } -} - - -void add_libs_so(int argc, char **argv) -{ - int i; - - for(i = 1; i < argc; i++) { - add_string(&libs_so, argv[i]); - if ( in_list(&libs, argv[i]) ) - warnx("%s:%d: " - "library `%s' specified as static earlier", - curfilename, linenum, argv[i]); - } -} - - -void add_buildopts(int argc, char **argv) -{ - int i; - - for (i = 1; i < argc; i++) - add_string(&buildopts, argv[i]); -} - - -void add_special(int argc, char **argv) -{ - int i; - prog_t *p = find_prog(argv[1]); - - if (p == NULL) { - if (reading_cache) - return; - - warnx("%s:%d: no prog %s previously declared, skipping special", - curfilename, linenum, argv[1]); - goterror = 1; - return; - } - - if (!strcmp(argv[2], "ident")) { - if (argc != 4) - goto argcount; - if ((p->ident = strdup(argv[3])) == NULL) - out_of_memory(); - } else if (!strcmp(argv[2], "srcdir")) { - if (argc != 4) - goto argcount; - if ((p->srcdir = strdup(argv[3])) == NULL) - out_of_memory(); - } else if (!strcmp(argv[2], "objdir")) { - if(argc != 4) - goto argcount; - if((p->objdir = strdup(argv[3])) == NULL) - out_of_memory(); - } else if (!strcmp(argv[2], "objs")) { - p->objs = NULL; - for (i = 3; i < argc; i++) - add_string(&p->objs, argv[i]); - } else if (!strcmp(argv[2], "objpaths")) { - p->objpaths = NULL; - for (i = 3; i < argc; i++) - add_string(&p->objpaths, argv[i]); - } else if (!strcmp(argv[2], "keep")) { - p->keeplist = NULL; - for(i = 3; i < argc; i++) - add_string(&p->keeplist, argv[i]); - } else if (!strcmp(argv[2], "objvar")) { - if(argc != 4) - goto argcount; - if ((p->objvar = strdup(argv[3])) == NULL) - out_of_memory(); - } else if (!strcmp(argv[2], "buildopts")) { - p->buildopts = NULL; - for (i = 3; i < argc; i++) - add_string(&p->buildopts, argv[i]); - } else if (!strcmp(argv[2], "lib")) { - for (i = 3; i < argc; i++) - add_string(&p->libs, argv[i]); - } else { - warnx("%s:%d: bad parameter name `%s', skipping line", - curfilename, linenum, argv[2]); - goterror = 1; - } - return; - - argcount: - warnx("%s:%d: too %s arguments, expected \"special %s %s \"", - curfilename, linenum, argc < 4? "few" : "many", argv[1], argv[2]); - goterror = 1; -} - - -prog_t *find_prog(char *str) -{ - prog_t *p; - - for (p = progs; p != NULL; p = p->next) - if (!strcmp(p->name, str)) - return p; - - return NULL; -} - - -/* - * ======================================================================== - * gen_outputs subsystem - * - */ - -/* helper subroutines */ - -void remove_error_progs(void); -void fillin_program(prog_t *p); -void gen_specials_cache(void); -void gen_output_makefile(void); -void gen_output_cfile(void); - -void fillin_program_objs(prog_t *p, char *path); -void top_makefile_rules(FILE *outmk); -void prog_makefile_rules(FILE *outmk, prog_t *p); -void output_strlst(FILE *outf, strlst_t *lst); -char *genident(char *str); -char *dir_search(char *progname); - - -void gen_outputs(void) -{ - prog_t *p; - - for (p = progs; p != NULL; p = p->next) - fillin_program(p); - - remove_error_progs(); - gen_specials_cache(); - gen_output_cfile(); - gen_output_makefile(); - status(""); - fprintf(stderr, - "Run \"make -f %s\" to build crunched binary.\n", outmkname); -} - -/* - * run the makefile for the program to find which objects are necessary - */ -void fillin_program(prog_t *p) -{ - char path[MAXPATHLEN]; - char line[MAXLINELEN]; - FILE *f; - - snprintf(line, MAXLINELEN, "filling in parms for %s", p->name); - status(line); - - if (!p->ident) - p->ident = genident(p->name); - - /* look for the source directory if one wasn't specified by a special */ - if (!p->srcdir) { - p->srcdir = dir_search(p->name); - } - - /* Determine the actual srcdir (maybe symlinked). */ - if (p->srcdir) { - snprintf(line, MAXLINELEN, "cd %s && echo -n `/bin/pwd`", - p->srcdir); - f = popen(line,"r"); - if (!f) - errx(1, "Can't execute: %s\n", line); - - path[0] = '\0'; - fgets(path, sizeof path, f); - if (pclose(f)) - errx(1, "Can't execute: %s\n", line); - - if (!*path) - errx(1, "Can't perform pwd on: %s\n", p->srcdir); - - p->realsrcdir = strdup(path); - } - - /* Unless the option to make object files was specified the - * the objects will be built in the source directory unless - * an object directory already exists. - */ - if (!makeobj && !p->objdir && p->srcdir) { - snprintf(line, sizeof line, "%s/%s", objprefix, p->realsrcdir); - if (is_dir(line)) { - if ((p->objdir = strdup(line)) == NULL) - out_of_memory(); - } else - p->objdir = p->realsrcdir; - } - - /* - * XXX look for a Makefile.{name} in local directory first. - * This lets us override the original Makefile. - */ - snprintf(path, sizeof(path), "Makefile.%s", p->name); - if (is_nonempty_file(path)) { - snprintf(line, MAXLINELEN, "Using %s for %s", path, p->name); - status(line); - } else - if (p->srcdir) - snprintf(path, sizeof(path), "%s/Makefile", p->srcdir); - if (!p->objs && p->srcdir && is_nonempty_file(path)) - fillin_program_objs(p, path); - - if (!p->srcdir && !p->objdir && verbose) - warnx("%s: %s: %s", - "warning: could not find source directory", - infilename, p->name); - if (!p->objs && verbose) - warnx("%s: %s: warning: could not find any .o files", - infilename, p->name); - - if ((!p->srcdir || !p->objdir) && !p->objs) - p->goterror = 1; -} - -void fillin_program_objs(prog_t *p, char *path) -{ - char *obj, *cp; - int fd, rc; - FILE *f; - char *objvar="OBJS"; - strlst_t *s; - char line[MAXLINELEN]; - - /* discover the objs from the srcdir Makefile */ - - if ((fd = mkstemp(tempfname)) == -1) { - perror(tempfname); - exit(1); - } - if ((f = fdopen(fd, "w")) == NULL) { - warn("%s", tempfname); - goterror = 1; - return; - } - if (p->objvar) - objvar = p->objvar; - - /* - * XXX include outhdrname (e.g. to contain Make variables) - */ - if (outhdrname[0] != '\0') - fprintf(f, ".include \"%s\"\n", outhdrname); - fprintf(f, ".include \"%s\"\n", path); - fprintf(f, ".POSIX:\n"); - if (buildopts) { - fprintf(f, "BUILDOPTS+="); - output_strlst(f, buildopts); - } - fprintf(f, ".if defined(PROG)\n"); - fprintf(f, "%s?=${PROG}.o\n", objvar); - fprintf(f, ".endif\n"); - fprintf(f, "loop:\n\t@echo 'OBJS= '${%s}\n", objvar); - - fprintf(f, "crunchgen_objs:\n" - "\t@cd %s && make -f %s $(BUILDOPTS) $(%s_OPTS)", - p->srcdir, tempfname, p->ident); - for (s = p->buildopts; s != NULL; s = s->next) - fprintf(f, " %s", s->str); - fprintf(f, " loop\n"); - - fclose(f); - - snprintf(line, MAXLINELEN, "cd %s && make -f %s -B crunchgen_objs", - p->srcdir, tempfname); - if ((f = popen(line, "r")) == NULL) { - warn("submake pipe"); - goterror = 1; - return; - } - - while(fgets(line, MAXLINELEN, f)) { - if (strncmp(line, "OBJS= ", 6)) { - warnx("make error: %s", line); - goterror = 1; - continue; - } - - cp = line + 6; - while (isspace(*cp)) - cp++; - - while(*cp) { - obj = cp; - while (*cp && !isspace(*cp)) - cp++; - if (*cp) - *cp++ = '\0'; - add_string(&p->objs, obj); - while (isspace(*cp)) - cp++; - } - } - - if ((rc=pclose(f)) != 0) { - warnx("make error: make returned %d", rc); - goterror = 1; - } - - unlink(tempfname); -} - -void remove_error_progs(void) -{ - prog_t *p1, *p2; - - p1 = NULL; p2 = progs; - while (p2 != NULL) { - if (!p2->goterror) - p1 = p2, p2 = p2->next; - else { - /* delete it from linked list */ - warnx("%s: %s: ignoring program because of errors", - infilename, p2->name); - if (p1) - p1->next = p2->next; - else - progs = p2->next; - p2 = p2->next; - } - } -} - -void gen_specials_cache(void) -{ - FILE *cachef; - prog_t *p; - char line[MAXLINELEN]; - - snprintf(line, MAXLINELEN, "generating %s", cachename); - status(line); - - if ((cachef = fopen(cachename, "w")) == NULL) { - warn("%s", cachename); - goterror = 1; - return; - } - - fprintf(cachef, "# %s - parm cache generated from %s by crunchgen " - " %s\n\n", - cachename, infilename, CRUNCH_VERSION); - - for (p = progs; p != NULL; p = p->next) { - fprintf(cachef, "\n"); - if (p->srcdir) - fprintf(cachef, "special %s srcdir %s\n", - p->name, p->srcdir); - if (p->objdir) - fprintf(cachef, "special %s objdir %s\n", - p->name, p->objdir); - if (p->objs) { - fprintf(cachef, "special %s objs", p->name); - output_strlst(cachef, p->objs); - } - if (p->objpaths) { - fprintf(cachef, "special %s objpaths", p->name); - output_strlst(cachef, p->objpaths); - } - } - fclose(cachef); -} - - -void gen_output_makefile(void) -{ - prog_t *p; - FILE *outmk; - char line[MAXLINELEN]; - - snprintf(line, MAXLINELEN, "generating %s", outmkname); - status(line); - - if ((outmk = fopen(outmkname, "w")) == NULL) { - warn("%s", outmkname); - goterror = 1; - return; - } - - fprintf(outmk, "# %s - generated from %s by crunchgen %s\n\n", - outmkname, infilename, CRUNCH_VERSION); - - if (outhdrname[0] != '\0') - fprintf(outmk, ".include \"%s\"\n", outhdrname); - - top_makefile_rules(outmk); - for (p = progs; p != NULL; p = p->next) - prog_makefile_rules(outmk, p); - - fprintf(outmk, "\n# ========\n"); - fclose(outmk); -} - - -void gen_output_cfile(void) -{ - extern char *crunched_skel[]; - char **cp; - FILE *outcf; - prog_t *p; - strlst_t *s; - char line[MAXLINELEN]; - - snprintf(line, MAXLINELEN, "generating %s", outcfname); - status(line); - - if((outcf = fopen(outcfname, "w")) == NULL) { - warn("%s", outcfname); - goterror = 1; - return; - } - - fprintf(outcf, - "/* %s - generated from %s by crunchgen %s */\n", - outcfname, infilename, CRUNCH_VERSION); - - fprintf(outcf, "#define EXECNAME \"%s\"\n", execfname); - for (cp = crunched_skel; *cp != NULL; cp++) - fprintf(outcf, "%s\n", *cp); - - for (p = progs; p != NULL; p = p->next) - fprintf(outcf, "extern int _crunched_%s_stub();\n", p->ident); - - fprintf(outcf, "\nstruct stub entry_points[] = {\n"); - for (p = progs; p != NULL; p = p->next) { - fprintf(outcf, "\t{ \"%s\", _crunched_%s_stub },\n", - p->name, p->ident); - for (s = p->links; s != NULL; s = s->next) - fprintf(outcf, "\t{ \"%s\", _crunched_%s_stub },\n", - s->str, p->ident); - } - - fprintf(outcf, "\t{ EXECNAME, crunched_main },\n"); - fprintf(outcf, "\t{ NULL, NULL }\n};\n"); - fclose(outcf); -} - - -char *genident(char *str) -{ - char *n, *s, *d; - - /* - * generates a Makefile/C identifier from a program name, - * mapping '-' to '_' and ignoring all other non-identifier - * characters. This leads to programs named "foo.bar" and - * "foobar" to map to the same identifier. - */ - - if ((n = strdup(str)) == NULL) - return NULL; - for (d = s = n; *s != '\0'; s++) { - if (*s == '-') - *d++ = '_'; - else if (*s == '_' || isalnum(*s)) - *d++ = *s; - } - *d = '\0'; - return n; -} - - -char *dir_search(char *progname) -{ - char path[MAXPATHLEN]; - strlst_t *dir; - char *srcdir; - - for (dir = srcdirs; dir != NULL; dir = dir->next) { - snprintf(path, MAXPATHLEN, "%s/%s", dir->str, progname); - if (!is_dir(path)) - continue; - - if ((srcdir = strdup(path)) == NULL) - out_of_memory(); - - return srcdir; - } - return NULL; -} - - -void top_makefile_rules(FILE *outmk) -{ - prog_t *p; - - if ( subtract_strlst(&libs, &libs_so) ) - fprintf(outmk, "# NOTE: Some LIBS declarations below overridden by LIBS_SO\n"); - - fprintf(outmk, "LIBS+="); - output_strlst(outmk, libs); - - fprintf(outmk, "LIBS_SO+="); - output_strlst(outmk, libs_so); - - if (makeobj) { - fprintf(outmk, "MAKEOBJDIRPREFIX?=%s\n", objprefix); - fprintf(outmk, "MAKEENV=env MAKEOBJDIRPREFIX=$(MAKEOBJDIRPREFIX)\n"); - fprintf(outmk, "CRUNCHMAKE=$(MAKEENV) $(MAKE)\n"); - } else { - fprintf(outmk, "CRUNCHMAKE=$(MAKE)\n"); - } - - if (buildopts) { - fprintf(outmk, "BUILDOPTS+="); - output_strlst(outmk, buildopts); - } - - fprintf(outmk, "CRUNCHED_OBJS="); - for (p = progs; p != NULL; p = p->next) - fprintf(outmk, " %s.lo", p->name); - fprintf(outmk, "\n"); - - fprintf(outmk, "SUBMAKE_TARGETS="); - for (p = progs; p != NULL; p = p->next) - fprintf(outmk, " %s_make", p->ident); - fprintf(outmk, "\nSUBCLEAN_TARGETS="); - for (p = progs; p != NULL; p = p->next) - fprintf(outmk, " %s_clean", p->ident); - fprintf(outmk, "\n\n"); - - fprintf(outmk, "all: objs exe\nobjs: $(SUBMAKE_TARGETS)\n"); - fprintf(outmk, "exe: %s\n", execfname); - fprintf(outmk, "%s: %s.o $(CRUNCHED_OBJS) $(SUBMAKE_TARGETS)\n", execfname, execfname); - fprintf(outmk, ".if defined(LIBS_SO) && !empty(LIBS_SO)\n"); - fprintf(outmk, "\t$(CC) -o %s %s.o $(CRUNCHED_OBJS) \\\n", - execfname, execfname); - fprintf(outmk, "\t\t-Xlinker -Bstatic $(LIBS) \\\n"); - fprintf(outmk, "\t\t-Xlinker -Bdynamic $(LIBS_SO)\n"); - fprintf(outmk, ".else\n"); - fprintf(outmk, "\t$(CC) -static -o %s %s.o $(CRUNCHED_OBJS) $(LIBS)\n", - execfname, execfname); - fprintf(outmk, ".endif\n"); - fprintf(outmk, "\tstrip %s\n", execfname); - fprintf(outmk, "realclean: clean subclean\n"); - fprintf(outmk, "clean:\n\trm -f %s *.lo *.o *_stub.c\n", execfname); - fprintf(outmk, "subclean: $(SUBCLEAN_TARGETS)\n"); -} - - -void prog_makefile_rules(FILE *outmk, prog_t *p) -{ - strlst_t *lst; - - fprintf(outmk, "\n# -------- %s\n\n", p->name); - - fprintf(outmk, "%s_OBJDIR=", p->ident); - if (p->objdir) - fprintf(outmk, "%s", p->objdir); - else - fprintf(outmk, "$(MAKEOBJDIRPREFIX)/$(%s_REALSRCDIR)\n", - p->ident); - fprintf(outmk, "\n"); - - fprintf(outmk, "%s_OBJPATHS=", p->ident); - if (p->objpaths) - output_strlst(outmk, p->objpaths); - else { - for (lst = p->objs; lst != NULL; lst = lst->next) { - fprintf(outmk, " $(%s_OBJDIR)/%s", p->ident, lst->str); - } - fprintf(outmk, "\n"); - } - - if (p->srcdir && p->objs) { - fprintf(outmk, "%s_SRCDIR=%s\n", p->ident, p->srcdir); - fprintf(outmk, "%s_REALSRCDIR=%s\n", p->ident, p->realsrcdir); - - fprintf(outmk, "%s_OBJS=", p->ident); - output_strlst(outmk, p->objs); - if (p->buildopts != NULL) { - fprintf(outmk, "%s_OPTS+=", p->ident); - output_strlst(outmk, p->buildopts); - } -#if 0 - fprintf(outmk, "$(%s_OBJPATHS): %s_make\n\n", p->ident, p->ident); -#endif - fprintf(outmk, "%s_make:\n", p->ident); - fprintf(outmk, "\t(cd $(%s_SRCDIR) && ", p->ident); - if (makeobj) - fprintf(outmk, "$(CRUNCHMAKE) obj && "); - fprintf(outmk, "\\\n"); - fprintf(outmk, "\t\t$(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS) depend &&", - p->ident); - fprintf(outmk, "\\\n"); - fprintf(outmk, "\t\t$(CRUNCHMAKE) $(BUILDOPTS) $(%s_OPTS) " - "$(%s_OBJS))", - p->ident, p->ident); - fprintf(outmk, "\n"); - fprintf(outmk, "%s_clean:\n", p->ident); - fprintf(outmk, "\t(cd $(%s_SRCDIR) && $(CRUNCHMAKE) $(BUILDOPTS) clean cleandepend)\n\n", - p->ident); - } else { - fprintf(outmk, "%s_make:\n", p->ident); - fprintf(outmk, "\t@echo \"** cannot make objs for %s\"\n\n", - p->name); - } - - if (p->libs) { - fprintf(outmk, "%s_LIBS=", p->ident); - output_strlst(outmk, p->libs); - } - - fprintf(outmk, "%s_stub.c:\n", p->name); - fprintf(outmk, "\techo \"" - "int _crunched_%s_stub(int argc, char **argv, char **envp)" - "{return main(argc,argv,envp);}\" >%s_stub.c\n", - p->ident, p->name); - fprintf(outmk, "%s.lo: %s_stub.o $(%s_OBJPATHS)", - p->name, p->name, p->ident); - if (p->libs) - fprintf(outmk, " $(%s_LIBS)", p->ident); - - fprintf(outmk, "\n"); - fprintf(outmk, "\tld -dc -r -o %s.lo %s_stub.o $(%s_OBJPATHS)", - p->name, p->name, p->ident); - if (p->libs) - fprintf(outmk, " $(%s_LIBS)", p->ident); - fprintf(outmk, "\n"); - fprintf(outmk, "\tcrunchide -k _crunched_%s_stub ", p->ident); - for (lst = p->keeplist; lst != NULL; lst = lst->next) - fprintf(outmk, "-k _%s ", lst->str); - fprintf(outmk, "%s.lo\n", p->name); -} - -void output_strlst(FILE *outf, strlst_t *lst) -{ - for (; lst != NULL; lst = lst->next) - if ( strlen(lst->str) ) - fprintf(outf, " %s", lst->str); - fprintf(outf, "\n"); -} - - -/* - * ======================================================================== - * general library routines - * - */ - -void status(char *str) -{ - static int lastlen = 0; - int len, spaces; - - if (!verbose) - return; - - len = strlen(str); - spaces = lastlen - len; - if (spaces < 1) - spaces = 1; - - fprintf(stderr, " [%s]%*.*s\r", str, spaces, spaces, " "); - fflush(stderr); - lastlen = len; -} - - -void out_of_memory(void) -{ - err(1, "%s: %d: out of memory, stopping", infilename, linenum); -} - - -void add_string(strlst_t **listp, char *str) -{ - strlst_t *p1, *p2; - - /* add to end, but be smart about dups */ - - for (p1 = NULL, p2 = *listp; p2 != NULL; p1 = p2, p2 = p2->next) - if (!strcmp(p2->str, str)) - return; - - p2 = malloc(sizeof(strlst_t)); - if (p2) { - p2->next = NULL; - p2->str = strdup(str); - } - if (!p2 || !p2->str) - out_of_memory(); - - if (p1 == NULL) - *listp = p2; - else - p1->next = p2; -} - -int subtract_strlst(strlst_t **lista, strlst_t **listb) -{ - int subtract_count = 0; - strlst_t *p1; - for (p1 = *listb; p1 != NULL; p1 = p1->next) - if ( in_list(lista, p1->str) ) { - warnx("Will compile library `%s' dynamically", p1->str); - strcat(p1->str, ""); - subtract_count++; - } - return subtract_count; -} - -int in_list(strlst_t **listp, char *str) -{ - strlst_t *p1; - for (p1 = *listp; p1 != NULL; p1 = p1->next) - if (!strcmp(p1->str, str)) - return 1; - return 0; -} - -int is_dir(char *pathname) -{ - struct stat buf; - - if (stat(pathname, &buf) == -1) - return 0; - - return S_ISDIR(buf.st_mode); -} - -int is_nonempty_file(char *pathname) -{ - struct stat buf; - - if (stat(pathname, &buf) == -1) - return 0; - - return S_ISREG(buf.st_mode) && buf.st_size > 0; -} diff --git a/usr.sbin/crunch/crunchgen/mkskel.sh b/usr.sbin/crunch/crunchgen/mkskel.sh deleted file mode 100644 index fd53d78..0000000 --- a/usr.sbin/crunch/crunchgen/mkskel.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/sh -# idea and sed lines taken straight from flex - -cat < diff --git a/usr.sbin/crunch/crunchide/crunchide.1 b/usr.sbin/crunch/crunchide/crunchide.1 deleted file mode 100644 index ef9947d..0000000 --- a/usr.sbin/crunch/crunchide/crunchide.1 +++ /dev/null @@ -1,92 +0,0 @@ -.\" -.\" Copyright (c) 1994 University of Maryland -.\" All Rights Reserved. -.\" -.\" Permission to use, copy, modify, distribute, and sell this software and its -.\" documentation for any purpose is hereby granted without fee, provided that -.\" the above copyright notice appear in all copies and that both that -.\" copyright notice and this permission notice appear in supporting -.\" documentation, and that the name of U.M. not be used in advertising or -.\" publicity pertaining to distribution of the software without specific, -.\" written prior permission. U.M. makes no representations about the -.\" suitability of this software for any purpose. It is provided "as is" -.\" without express or implied warranty. -.\" -.\" U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. -.\" BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR -.\" IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.\" -.\" Author: James da Silva, Systems Design and Analysis Group -.\" Computer Science Department -.\" University of Maryland at College Park -.\" $FreeBSD$ -.\" -.Dd June 14, 1994 -.Dt CRUNCHIDE 1 -.Os -.Sh NAME -.Nm crunchide -.Nd hides symbol names from ld, for crunching programs together -.Sh SYNOPSIS -.Nm -.Op Fl f Ar keep-list-file -.Op Fl k Ar keep-symbol -.Op Ar object-file ... -.Sh DESCRIPTION -The -.Nm -utility hides the global symbols of -.Ar object-file -such that they are ignored by subsequent runs of the linker, -.Xr ld 1 . -Some symbols may be left visible via the -.Fl k Ar keep-symbol -and -.Fl f Ar keep-list-file -options. -The -.Ar keep-list-file -must contain a list of symbols to keep visible, one symbol per line. -The names given by -.Ar keep-symbol -or in -.Ar keep-list-file -should be C names. -For example, -to keep the C function -.Dq foo -visible, the option -.Dq -k foo -should be used. -.Pp -The -.Nm -utility is designed as a companion program for -.Xr crunchgen 1 , -which automates the process of creating crunched binaries from -multiple component programs. -.Sh SEE ALSO -.Xr crunchgen 1 , -.Xr ld 1 -.Sh AUTHORS -.An -nosplit -The -.Nm crunch -utility was written by -.An James da Silva Aq jds@cs.umd.edu . -.Pp -Copyright (c) 1994 University of Maryland. -All Rights Reserved. -.Pp -.An Chris Demetriou Aq cgd@netbsd.org -reorganized -.Nm -so that it supported multiple object formats, and added -ELF object support and ECOFF object recognition. -.Pp -Copyright (c) 1997 -.An Christopher G. Demetriou . -All Rights Reserved. diff --git a/usr.sbin/crunch/crunchide/crunchide.c b/usr.sbin/crunch/crunchide/crunchide.c deleted file mode 100644 index 32c42db..0000000 --- a/usr.sbin/crunch/crunchide/crunchide.c +++ /dev/null @@ -1,268 +0,0 @@ -/* $NetBSD: crunchide.c,v 1.8 1997/11/01 06:51:45 lukem Exp $ */ -/* $FreeBSD$ */ -/* - * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. - * Copyright (c) 1994 University of Maryland - * All Rights Reserved. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of U.M. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. U.M. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: James da Silva, Systems Design and Analysis Group - * Computer Science Department - * University of Maryland at College Park - */ -/* - * crunchide.c - tiptoes through an a.out symbol table, hiding all defined - * global symbols. Allows the user to supply a "keep list" of symbols - * that are not to be hidden. This program relies on the use of the - * linker's -dc flag to actually put global bss data into the file's - * bss segment (rather than leaving it as undefined "common" data). - * - * The point of all this is to allow multiple programs to be linked - * together without getting multiple-defined errors. - * - * For example, consider a program "foo.c". It can be linked with a - * small stub routine, called "foostub.c", eg: - * int foo_main(int argc, char **argv){ return main(argc, argv); } - * like so: - * cc -c foo.c foostub.c - * ld -dc -r foo.o foostub.o -o foo.combined.o - * crunchide -k _foo_main foo.combined.o - * at this point, foo.combined.o can be linked with another program - * and invoked with "foo_main(argc, argv)". foo's main() and any - * other globals are hidden and will not conflict with other symbols. - * - * TODO: - * - resolve the theoretical hanging reloc problem (see check_reloc() - * below). I have yet to see this problem actually occur in any real - * program. In what cases will gcc/gas generate code that needs a - * relative reloc from a global symbol, other than PIC? The - * solution is to not hide the symbol from the linker in this case, - * but to generate some random name for it so that it doesn't link - * with anything but holds the place for the reloc. - * - arrange that all the BSS segments start at the same address, so - * that the final crunched binary BSS size is the max of all the - * component programs' BSS sizes, rather than their sum. - */ -#include -#ifndef lint -__RCSID("$NetBSD: crunchide.c,v 1.8 1997/11/01 06:51:45 lukem Exp $"); -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "extern.h" - -char *pname = "crunchide"; - -void usage(void); - -void add_to_keep_list(char *symbol); -void add_file_to_keep_list(char *filename); - -int hide_syms(const char *filename); - -int verbose; - -int main(int, char *[]); - -int main(argc, argv) -int argc; -char **argv; -{ - int ch, errors; - - if(argc > 0) pname = argv[0]; - - while ((ch = getopt(argc, argv, "k:f:v")) != -1) - switch(ch) { - case 'k': - add_to_keep_list(optarg); - break; - case 'f': - add_file_to_keep_list(optarg); - break; - case 'v': - verbose = 1; - break; - default: - usage(); - } - - argc -= optind; - argv += optind; - - if(argc == 0) usage(); - - errors = 0; - while(argc) { - if (hide_syms(*argv)) - errors = 1; - argc--, argv++; - } - - return errors; -} - -void usage(void) -{ - fprintf(stderr, - "usage: %s [-k ] [-f ] ...\n", - pname); - exit(1); -} - -/* ---------------------------- */ - -struct keep { - struct keep *next; - char *sym; -} *keep_list; - -void add_to_keep_list(char *symbol) -{ - struct keep *newp, *prevp, *curp; - int cmp; - - cmp = 0; - - for(curp = keep_list, prevp = NULL; curp; prevp = curp, curp = curp->next) - if((cmp = strcmp(symbol, curp->sym)) <= 0) break; - - if(curp && cmp == 0) - return; /* already in table */ - - newp = (struct keep *) malloc(sizeof(struct keep)); - if(newp) newp->sym = strdup(symbol); - if(newp == NULL || newp->sym == NULL) { - fprintf(stderr, "%s: out of memory for keep list\n", pname); - exit(1); - } - - newp->next = curp; - if(prevp) prevp->next = newp; - else keep_list = newp; -} - -int in_keep_list(const char *symbol) -{ - struct keep *curp; - int cmp; - - cmp = 0; - - for(curp = keep_list; curp; curp = curp->next) - if((cmp = strcmp(symbol, curp->sym)) <= 0) break; - - return curp && cmp == 0; -} - -void add_file_to_keep_list(char *filename) -{ - FILE *keepf; - char symbol[1024]; - int len; - - if((keepf = fopen(filename, "r")) == NULL) { - perror(filename); - usage(); - } - - while(fgets(symbol, sizeof(symbol), keepf)) { - len = strlen(symbol); - if(len && symbol[len-1] == '\n') - symbol[len-1] = '\0'; - - add_to_keep_list(symbol); - } - fclose(keepf); -} - -/* ---------------------------- */ - -struct { - const char *name; - int (*check)(int, const char *); /* 1 if match, zero if not */ - int (*hide)(int, const char *); /* non-zero if error */ -} exec_formats[] = { -#ifdef NLIST_AOUT - { "a.out", check_aout, hide_aout, }, -#endif -#ifdef NLIST_ECOFF - { "ECOFF", check_elf64, hide_elf64, }, -#endif -#ifdef NLIST_ELF32 - { "ELF32", check_elf32, hide_elf32, }, -#endif -#ifdef NLIST_ELF64 - { "ELF64", check_elf64, hide_elf64, }, -#endif -}; - -int hide_syms(const char *filename) -{ - int fd, i, n, rv; - - fd = open(filename, O_RDWR, 0); - if (fd == -1) { - perror(filename); - return 1; - } - - rv = 0; - - n = sizeof exec_formats / sizeof exec_formats[0]; - for (i = 0; i < n; i++) { - if (lseek(fd, 0, SEEK_SET) != 0) { - perror(filename); - goto err; - } - if ((*exec_formats[i].check)(fd, filename) != 0) - break; - } - if (i == n) { - fprintf(stderr, "%s: unknown executable format\n", filename); - goto err; - } - - if (verbose) - fprintf(stderr, "%s is an %s binary\n", filename, - exec_formats[i].name); - - if (lseek(fd, 0, SEEK_SET) != 0) { - perror(filename); - goto err; - } - rv = (*exec_formats[i].hide)(fd, filename); - -out: - close (fd); - return (rv); - -err: - rv = 1; - goto out; -} diff --git a/usr.sbin/crunch/crunchide/exec_aout.c b/usr.sbin/crunch/crunchide/exec_aout.c deleted file mode 100644 index a608c23..0000000 --- a/usr.sbin/crunch/crunchide/exec_aout.c +++ /dev/null @@ -1,198 +0,0 @@ -/* $NetBSD: exec_aout.c,v 1.6 1997/08/02 21:30:17 perry Exp $ */ -/* - * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. - * Copyright (c) 1994 University of Maryland - * All Rights Reserved. - * - * Permission to use, copy, modify, distribute, and sell this software and its - * documentation for any purpose is hereby granted without fee, provided that - * the above copyright notice appear in all copies and that both that - * copyright notice and this permission notice appear in supporting - * documentation, and that the name of U.M. not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. U.M. makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. - * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: James da Silva, Systems Design and Analysis Group - * Computer Science Department - * University of Maryland at College Park - */ -#include -#ifndef lint -__RCSID("$NetBSD: exec_aout.c,v 1.6 1997/08/02 21:30:17 perry Exp $"); -__FBSDID("$FreeBSD$"); -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "extern.h" - -#if defined(NLIST_AOUT) - -int nsyms, ntextrel, ndatarel; -struct exec *hdrp; -char *aoutdata, *strbase; -struct relocation_info *textrel, *datarel; -struct nlist *symbase; - - -#define SYMSTR(sp) (&strbase[(sp)->n_un.n_strx]) - -/* is the symbol a global symbol defined in the current file? */ -#define IS_GLOBAL_DEFINED(sp) \ - (((sp)->n_type & N_EXT) && ((sp)->n_type & N_TYPE) != N_UNDF) - -/* is the relocation entry dependent on a symbol? */ -#define IS_SYMBOL_RELOC(rp) \ - ((rp)->r_extern||(rp)->r_baserel||(rp)->r_jmptable) - -static void check_reloc(const char *filename, struct relocation_info *relp); - -int check_aout(int inf, const char *filename) -{ - struct stat infstat; - struct exec eh; - - /* - * check the header to make sure it's an a.out-format file. - */ - - if(fstat(inf, &infstat) == -1) - return 0; - if(infstat.st_size < sizeof eh) - return 0; - if(read(inf, &eh, sizeof eh) != sizeof eh) - return 0; - - if(N_BADMAG(eh)) - return 0; - - return 1; -} - -int hide_aout(int inf, const char *filename) -{ - struct stat infstat; - struct relocation_info *relp; - struct nlist *symp; - int rc; - - /* - * do some error checking. - */ - - if(fstat(inf, &infstat) == -1) { - perror(filename); - return 1; - } - - /* - * Read the entire file into memory. XXX - Really, we only need to - * read the header and from TRELOFF to the end of the file. - */ - - if((aoutdata = (char *) malloc(infstat.st_size)) == NULL) { - fprintf(stderr, "%s: too big to read into memory\n", filename); - return 1; - } - - if((rc = read(inf, aoutdata, infstat.st_size)) < infstat.st_size) { - fprintf(stderr, "%s: read error: %s\n", filename, - rc == -1? strerror(errno) : "short read"); - return 1; - } - - /* - * Calculate offsets and sizes from the header. - */ - - hdrp = (struct exec *) aoutdata; - -#ifdef __FreeBSD__ - textrel = (struct relocation_info *) (aoutdata + N_RELOFF(*hdrp)); - datarel = (struct relocation_info *) (aoutdata + N_RELOFF(*hdrp) + - hdrp->a_trsize); -#else - textrel = (struct relocation_info *) (aoutdata + N_TRELOFF(*hdrp)); - datarel = (struct relocation_info *) (aoutdata + N_DRELOFF(*hdrp)); -#endif - symbase = (struct nlist *) (aoutdata + N_SYMOFF(*hdrp)); - strbase = (char *) (aoutdata + N_STROFF(*hdrp)); - - ntextrel = hdrp->a_trsize / sizeof(struct relocation_info); - ndatarel = hdrp->a_drsize / sizeof(struct relocation_info); - nsyms = hdrp->a_syms / sizeof(struct nlist); - - /* - * Zap the type field of all globally-defined symbols. The linker will - * subsequently ignore these entries. Don't zap any symbols in the - * keep list. - */ - - for(symp = symbase; symp < symbase + nsyms; symp++) { - if(!IS_GLOBAL_DEFINED(symp)) /* keep undefined syms */ - continue; - - /* keep (C) symbols which are on the keep list */ - if(SYMSTR(symp)[0] == '_' && in_keep_list(SYMSTR(symp) + 1)) - continue; - - symp->n_type = 0; - } - - /* - * Check whether the relocation entries reference any symbols that we - * just zapped. I don't know whether ld can handle this case, but I - * haven't encountered it yet. These checks are here so that the program - * doesn't fail silently should such symbols be encountered. - */ - - for(relp = textrel; relp < textrel + ntextrel; relp++) - check_reloc(filename, relp); - for(relp = datarel; relp < datarel + ndatarel; relp++) - check_reloc(filename, relp); - - /* - * Write the .o file back out to disk. XXX - Really, we only need to - * write the symbol table entries back out. - */ - lseek(inf, 0, SEEK_SET); - if((rc = write(inf, aoutdata, infstat.st_size)) < infstat.st_size) { - fprintf(stderr, "%s: write error: %s\n", filename, - rc == -1? strerror(errno) : "short write"); - return 1; - } - - return 0; -} - - -static void check_reloc(const char *filename, struct relocation_info *relp) -{ - /* bail out if we zapped a symbol that is needed */ - if(IS_SYMBOL_RELOC(relp) && symbase[relp->r_symbolnum].n_type == 0) { - fprintf(stderr, - "%s: oops, have hanging relocation for %s: bailing out!\n", - filename, SYMSTR(&symbase[relp->r_symbolnum])); - exit(1); - } -} - -#endif /* defined(NLIST_AOUT) */ diff --git a/usr.sbin/crunch/crunchide/exec_elf32.c b/usr.sbin/crunch/crunchide/exec_elf32.c deleted file mode 100644 index 2b2e27f..0000000 --- a/usr.sbin/crunch/crunchide/exec_elf32.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou - * for the NetBSD Project. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#ifndef lint -#if 0 -__RCSID("$NetBSD: exec_elf32.c,v 1.4 1997/08/12 06:07:24 mikel Exp $"); -#endif -#endif -__FBSDID("$FreeBSD$"); - -#ifndef ELFSIZE -#define ELFSIZE 32 -#endif - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "extern.h" - -#if (defined(NLIST_ELF32) && (ELFSIZE == 32)) || \ - (defined(NLIST_ELF64) && (ELFSIZE == 64)) - -#define __ELF_WORD_SIZE ELFSIZE -#if (ELFSIZE == 32) -#include -#define xewtoh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) -#define htoxew(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) -#define wewtoh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) -#define htowew(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) -#elif (ELFSIZE == 64) -#include -#define xewtoh(x) ((data == ELFDATA2MSB) ? be64toh(x) : le64toh(x)) -#define htoxew(x) ((data == ELFDATA2MSB) ? htobe64(x) : htole64(x)) -/* elf64 Elf64_Word are 32 bits */ -#define wewtoh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) -#define htowew(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) -#endif -#include - -#define CONCAT(x,y) __CONCAT(x,y) -#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x))) -#define ELFNAME2(x,y) CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y)))) -#define ELFNAMEEND(x) CONCAT(x,CONCAT(_elf,ELFSIZE)) -#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x))) - -#define xe16toh(x) ((data == ELFDATA2MSB) ? be16toh(x) : le16toh(x)) -#define xe32toh(x) ((data == ELFDATA2MSB) ? be32toh(x) : le32toh(x)) -#define htoxe32(x) ((data == ELFDATA2MSB) ? htobe32(x) : htole32(x)) - -struct listelem { - struct listelem *next; - void *mem; - off_t file; - size_t size; -}; - -static ssize_t -xreadatoff(int fd, void *buf, off_t off, size_t size, const char *fn) -{ - ssize_t rv; - - if (lseek(fd, off, SEEK_SET) != off) { - perror(fn); - return -1; - } - if ((rv = read(fd, buf, size)) != size) { - fprintf(stderr, "%s: read error: %s\n", fn, - rv == -1 ? strerror(errno) : "short read"); - return -1; - } - return size; -} - -static ssize_t -xwriteatoff(int fd, void *buf, off_t off, size_t size, const char *fn) -{ - ssize_t rv; - - if (lseek(fd, off, SEEK_SET) != off) { - perror(fn); - return -1; - } - if ((rv = write(fd, buf, size)) != size) { - fprintf(stderr, "%s: write error: %s\n", fn, - rv == -1 ? strerror(errno) : "short write"); - return -1; - } - return size; -} - -static void * -xmalloc(size_t size, const char *fn, const char *use) -{ - void *rv; - - rv = malloc(size); - if (rv == NULL) - fprintf(stderr, "%s: out of memory (allocating for %s)\n", - fn, use); - return (rv); -} - -static void * -xrealloc(void *ptr, size_t size, const char *fn, const char *use) -{ - void *rv; - - rv = realloc(ptr, size); - if (rv == NULL) { - free(ptr); - fprintf(stderr, "%s: out of memory (reallocating for %s)\n", - fn, use); - } - return (rv); -} - -int -ELFNAMEEND(check)(int fd, const char *fn) -{ - Elf_Ehdr eh; - struct stat sb; - unsigned char data; - - /* - * Check the header to maek sure it's an ELF file (of the - * appropriate size). - */ - if (fstat(fd, &sb) == -1) - return 0; - if (sb.st_size < sizeof eh) - return 0; - if (read(fd, &eh, sizeof eh) != sizeof eh) - return 0; - - if (IS_ELF(eh) == 0) - return 0; - - data = eh.e_ident[EI_DATA]; - - switch (xe16toh(eh.e_machine)) { - case EM_386: break; - case EM_ALPHA: break; -#ifndef EM_ARM -#define EM_ARM 40 -#endif - case EM_ARM: break; -#ifndef EM_MIPS -#define EM_MIPS 8 -#endif -#ifndef EM_MIPS_RS4_BE /* same as EM_MIPS_RS3_LE */ -#define EM_MIPS_RS4_BE 10 -#endif - case EM_MIPS: break; - case /* EM_MIPS_RS3_LE */ EM_MIPS_RS4_BE: break; -#ifndef EM_IA_64 -#define EM_IA_64 50 -#endif - case EM_IA_64: break; -#ifndef EM_PPC -#define EM_PPC 20 -#endif - case EM_PPC: break; -#ifndef EM_PPC64 -#define EM_PPC64 21 -#endif - case EM_PPC64: break; -#ifndef EM_SPARCV9 -#define EM_SPARCV9 43 -#endif - case EM_SPARCV9: break; -#ifndef EM_X86_64 -#define EM_X86_64 62 -#endif - case EM_X86_64: break; -/* ELFDEFNNAME(MACHDEP_ID_CASES) */ - - default: - return 0; - } - - return 1; -} - -/* - * This function 'hides' (some of) ELF executable file's symbols. - * It hides them by renaming them to "_$$hide$$ ". - * Symbols in the global keep list, or which are marked as being undefined, - * are left alone. - * - * An old version of this code shuffled various tables around, turning - * global symbols to be hidden into local symbols. That lost on the - * mips, because CALL16 relocs must reference global symbols, and, if - * those symbols were being hidden, they were no longer global. - * - * The new renaming behaviour doesn't take global symbols out of the - * namespace. However, it's ... unlikely that there will ever be - * any collisions in practice because of the new method. - */ -int -ELFNAMEEND(hide)(int fd, const char *fn) -{ - Elf_Ehdr ehdr; - Elf_Shdr *shdrp = NULL, *symtabshdr, *strtabshdr; - Elf_Sym *symtabp = NULL; - char *strtabp = NULL; - Elf_Size nsyms, nlocalsyms, ewi; - ssize_t shdrsize; - int rv, i, weird; - size_t nstrtab_size, nstrtab_nextoff, fn_size; - char *nstrtabp = NULL; - unsigned char data; - Elf_Off maxoff, stroff; - const char *weirdreason = NULL; - - rv = 0; - if (xreadatoff(fd, &ehdr, 0, sizeof ehdr, fn) != sizeof ehdr) - goto bad; - - data = ehdr.e_ident[EI_DATA]; - - shdrsize = xe16toh(ehdr.e_shnum) * xe16toh(ehdr.e_shentsize); - if ((shdrp = xmalloc(shdrsize, fn, "section header table")) == NULL) - goto bad; - if (xreadatoff(fd, shdrp, xewtoh(ehdr.e_shoff), shdrsize, fn) != - shdrsize) - goto bad; - - symtabshdr = strtabshdr = NULL; - weird = 0; - maxoff = stroff = 0; - for (i = 0; i < xe16toh(ehdr.e_shnum); i++) { - if (xewtoh(shdrp[i].sh_offset) > maxoff) - maxoff = xewtoh(shdrp[i].sh_offset); - switch (xe32toh(shdrp[i].sh_type)) { - case SHT_SYMTAB: - if (symtabshdr != NULL) - weird = 1; - symtabshdr = &shdrp[i]; - strtabshdr = &shdrp[xe32toh(shdrp[i].sh_link)]; - - /* Check whether the string table is the last section */ - stroff = xewtoh(shdrp[xe32toh(shdrp[i].sh_link)].sh_offset); - if (!weird && xe32toh(shdrp[i].sh_link) != (xe16toh(ehdr.e_shnum) - 1)) { - weird = 1; - weirdreason = "string table not last section"; - } - break; - } - } - if (! weirdreason) - weirdreason = "unsupported"; - if (symtabshdr == NULL) - goto out; - if (strtabshdr == NULL) - weird = 1; - if (!weird && stroff != maxoff) { - weird = 1; - weirdreason = "string table section not last in file"; - } - if (weird) { - fprintf(stderr, "%s: weird executable (%s)\n", fn, weirdreason); - goto bad; - } - - /* - * load up everything we need - */ - - /* symbol table */ - if ((symtabp = xmalloc(xewtoh(symtabshdr->sh_size), fn, "symbol table")) - == NULL) - goto bad; - if (xreadatoff(fd, symtabp, xewtoh(symtabshdr->sh_offset), - xewtoh(symtabshdr->sh_size), fn) != xewtoh(symtabshdr->sh_size)) - goto bad; - - /* string table */ - if ((strtabp = xmalloc(xewtoh(strtabshdr->sh_size), fn, "string table")) - == NULL) - goto bad; - if (xreadatoff(fd, strtabp, xewtoh(strtabshdr->sh_offset), - xewtoh(strtabshdr->sh_size), fn) != xewtoh(strtabshdr->sh_size)) - goto bad; - - nstrtab_size = 256; - nstrtabp = xmalloc(nstrtab_size, fn, "new string table"); - if (nstrtabp == NULL) - goto bad; - nstrtab_nextoff = 0; - - fn_size = strlen(fn); - - /* Prepare data structures for symbol movement. */ - nsyms = xewtoh(symtabshdr->sh_size) / xewtoh(symtabshdr->sh_entsize); - nlocalsyms = xe32toh(symtabshdr->sh_info); - - /* move symbols, making them local */ - for (ewi = 0; ewi < nsyms; ewi++) { - Elf_Sym *sp = &symtabp[ewi]; - const char *symname = strtabp + xe32toh(sp->st_name); - size_t newent_len; - /* - * make sure there's size for the next entry, even if it's - * as large as it can be. - * - * "_$$hide$$ " -> - * 9 + 3 + sizes of fn and sym name - */ - while ((nstrtab_size - nstrtab_nextoff) < - strlen(symname) + fn_size + 12) { - nstrtab_size *= 2; - nstrtabp = xrealloc(nstrtabp, nstrtab_size, fn, - "new string table"); - if (nstrtabp == NULL) - goto bad; - } - - sp->st_name = htowew(nstrtab_nextoff); - - /* if it's a keeper or is undefined, don't rename it. */ - if (in_keep_list(symname) || - (xe16toh(sp->st_shndx) == SHN_UNDEF)) { - newent_len = sprintf(nstrtabp + nstrtab_nextoff, - "%s", symname) + 1; - } else { - newent_len = sprintf(nstrtabp + nstrtab_nextoff, - "_$$hide$$ %s %s", fn, symname) + 1; - } - nstrtab_nextoff += newent_len; - } - strtabshdr->sh_size = htoxew(nstrtab_nextoff); - - /* - * write new tables to the file - */ - if (xwriteatoff(fd, shdrp, xewtoh(ehdr.e_shoff), shdrsize, fn) != - shdrsize) - goto bad; - if (xwriteatoff(fd, symtabp, xewtoh(symtabshdr->sh_offset), - xewtoh(symtabshdr->sh_size), fn) != xewtoh(symtabshdr->sh_size)) - goto bad; - /* write new symbol table strings */ - if ((size_t)xwriteatoff(fd, nstrtabp, xewtoh(strtabshdr->sh_offset), - xewtoh(strtabshdr->sh_size), fn) != xewtoh(strtabshdr->sh_size)) - goto bad; - -out: - if (shdrp != NULL) - free(shdrp); - if (symtabp != NULL) - free(symtabp); - if (strtabp != NULL) - free(strtabp); - return (rv); - -bad: - rv = 1; - goto out; -} - -#endif /* include this size of ELF */ diff --git a/usr.sbin/crunch/crunchide/exec_elf64.c b/usr.sbin/crunch/crunchide/exec_elf64.c deleted file mode 100644 index 962cc07..0000000 --- a/usr.sbin/crunch/crunchide/exec_elf64.c +++ /dev/null @@ -1,40 +0,0 @@ -/* $NetBSD: exec_elf64.c,v 1.2 1997/08/02 21:30:19 perry Exp $ */ - -/* - * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou - * for the NetBSD Project. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#ifndef lint -__IDSTRING(elf64rcsid, "$NetBSD: exec_elf64.c,v 1.2 1997/08/02 21:30:19 perry Exp $"); -#endif - -#define ELFSIZE 64 - -#include "exec_elf32.c" diff --git a/usr.sbin/crunch/crunchide/extern.h b/usr.sbin/crunch/crunchide/extern.h deleted file mode 100644 index 4200bc3..0000000 --- a/usr.sbin/crunch/crunchide/extern.h +++ /dev/null @@ -1,51 +0,0 @@ -/* $NetBSD: extern.h,v 1.5 1998/05/06 13:16:57 mycroft Exp $ */ -/* $FreeBSD$ */ - -/* - * Copyright (c) 1997 Christopher G. Demetriou. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Christopher G. Demetriou - * for the NetBSD Project. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef NLIST_AOUT -int check_aout(int, const char *); -int hide_aout(int, const char *); -#endif -#ifdef NLIST_ECOFF -int check_ecoff(int, const char *); -int hide_ecoff(int, const char *); -#endif -#ifdef NLIST_ELF32 -int check_elf32(int, const char *); -int hide_elf32(int, const char *); -#endif -#ifdef NLIST_ELF64 -int check_elf64(int, const char *); -int hide_elf64(int, const char *); -#endif - -int in_keep_list(const char *symbol); diff --git a/usr.sbin/crunch/examples/Makefile b/usr.sbin/crunch/examples/Makefile deleted file mode 100644 index 6dd49ac..0000000 --- a/usr.sbin/crunch/examples/Makefile +++ /dev/null @@ -1,33 +0,0 @@ -# $FreeBSD$ - -CRUNCHED= fixit - -# below is boiler-plate to make $(CRUNCHED) from $(CRUNCHED).conf -# I'd use PROG instead of CRUNCHED, but the system makefiles REALLY want -# to build things in the normal way if you use PROG. - -CONF= $(CRUNCHED).conf - -OUTMK= $(CRUNCHED).mk -OUTPUTS= $(OUTMK) $(CRUNCHED).c $(CRUNCHED).cache - -NO_MAN= -CLEANFILES+= $(CRUNCHED) *.o *.lo *.c *.mk *.cache -CLEANDIRFILES+= $(OUTPUTS) - -all: $(CRUNCHED) -exe: $(CRUNCHED) - -$(OUTPUTS): $(CONF) - crunchgen ${.CURDIR}/$(CONF) - -$(CRUNCHED): $(OUTPUTS) submake - -submake: - make -f $(OUTMK) -objs: - make -f $(OUTMK) objs -cleandir: - rm -f $(CLEANDIRFILES) - -.include diff --git a/usr.sbin/crunch/examples/filesystem.conf b/usr.sbin/crunch/examples/filesystem.conf deleted file mode 100644 index 1fb9385..0000000 --- a/usr.sbin/crunch/examples/filesystem.conf +++ /dev/null @@ -1,31 +0,0 @@ -# $FreeBSD$ - -srcdirs /usr/src/bin /usr/src/sbin /usr/src/gnu/usr.bin /usr/src/usr.sbin -srcdirs /usr/src/sbin/i386 - -# /bin -progs sh expr ls mkdir rm sync test -ln test [ - -# These are needed because of UN*X's idiotic way of indicating that something -# is a login shell. -ln sh - -ln sh -sh - -# /sbin -progs disklabel fdisk init mount newfs reboot umount -ln reboot halt -ln reboot fastboot -ln reboot fasthalt - - -# /usr/bin -progs cpio gzip -ln gzip gunzip -ln gzip gzcat -ln gzip zcat - -# /usr/sbin -progs bad144 - -libs -ll -ledit -ltermcap -lutil -lscrypt diff --git a/usr.sbin/crunch/examples/fixit.conf b/usr.sbin/crunch/examples/fixit.conf deleted file mode 100644 index 80a2346..0000000 --- a/usr.sbin/crunch/examples/fixit.conf +++ /dev/null @@ -1,45 +0,0 @@ -# fixit.conf - put in anything we think we might want on a fixit floppy - -# first, we list the source dirs that our programs reside in. These are -# searched in order listed to find the dir containing each program. - -srcdirs /usr/src/bin /usr/src/sbin /usr/src/usr.bin /usr/src/usr.sbin -srcdirs /usr/src/gnu/usr.bin /usr/src/usr.bin/vi -srcdirs /usr/src/sbin/i386 - -# second, we list all the programs we want to include in our crunched binary. -# The order doesn't matter. Any program that needs hard links to it gets an -# `ln' directive. - -# /bin stuff - -progs cat chmod cp date dd df echo ed expr hostname kill ln ls mkdir -progs mt mv pwd rcp rm rmdir sh sleep stty sync test - -ln test [ -ln sh -sh # init invokes the shell this way - -# /sbin stuff - -progs badsect chown clri disklabel dump dmesg fdisk fsck ifconfig init -progs mknod mount newfs ping reboot restore swapon umount -ln dump rdump -ln restore rrestore - -# /usr/bin stuff - -progs ftp rsh sed telnet rlogin common find -ln common vi -ln common view -ln common ex - -# gnu stuff - -progs cpio gzip -ln gzip gunzip -ln gzip gzcat - -# finally, we specify the libraries to link in with our binary - -libs -lcrypt -ltelnet -lutil -ll -libs -lcurses -ltermcap -ledit -lkvm diff --git a/usr.sbin/crunch/examples/kcopy.conf b/usr.sbin/crunch/examples/kcopy.conf deleted file mode 100644 index 3284e86..0000000 --- a/usr.sbin/crunch/examples/kcopy.conf +++ /dev/null @@ -1,21 +0,0 @@ -# $FreeBSD$ - -srcdirs /usr/src/bin /usr/src/sbin - -# Programs from bin/ -progs sh cp echo test -ln test [ - -# These are needed because of UN*X's idiotic way of indicating that something -# is a login shell. -ln sh - -ln sh -sh - -# -# Programs from sbin/ -progs mount mount_cd9660 fsck init reboot umount -ln reboot halt -ln reboot fastboot -ln reboot fasthalt - -libs -ll -ledit -ltermcap -lcompat -lutil -lscrypt diff --git a/usr.sbin/crunch/examples/really-big.conf b/usr.sbin/crunch/examples/really-big.conf deleted file mode 100644 index ab8a939..0000000 --- a/usr.sbin/crunch/examples/really-big.conf +++ /dev/null @@ -1,158 +0,0 @@ -# really-big.conf - just about everything, just for testing. -# This ends up having some good examples of the use of specials for -# those hard-to-reach programs. I stopped when I got tired, but we -# could probably get even more stuff (like libexec stuff) in here. -# -# This produces a 4608000 byte binary. Pretty sick and twisted, eh? -# -# $FreeBSD$ -# - -# ========================================================================= - -srcdirs /usr/src/bin - -progs cat chmod cp csh date dd df domainname echo ed expr hostname kill -progs ln ls mkdir mt mv ps pwd rcp rm rmail rmdir sh sleep stty sync test - -ln test [ -ln sh -sh - - -# ========================================================================= - -srcdirs /usr/src/sbin - -progs badsect bim clri disklabel dmesg dump dumpfs fdisk fsck halt -progs ifconfig init mknod modload modunload mount mount_isofs -progs mount_lofs mount_msdosfs mount_portalfs mountd -progs newfs nfsd nfsiod ping quotacheck reboot restore route routed savecore -progs shutdown swapon ttyflags tunefs umount -# shell scripts: fastboot - -ln dump rdump -ln restore rrestore - - -# ========================================================================= - -srcdirs /usr/src/usr.bin - -progs apropos ar asa at basename biff cal calendar cap_mkdb checknr chpass -progs cksum cmp col colcrt colrm column comm compress crontab ctags cut -progs dirname du env error expand false file find finger fmt fold fpr from -progs fsplit fstat ftp getconf getopt gprof head hexdump id indent ipcrm -progs ipcs join kdump ktrace last lastcomm leave lex lock logger locate -progs login logname look m4 machine mail make man mesg mkfifo -progs mkstr modstat more msgs netstat newsyslog nfsstat nice nm nohup -progs pagesize passwd paste patch pr printenv printf quota ranlib -progs renice rev rlogin rpcgen rpcinfo rsh rup ruptime rusers rwall rwho -progs script sed showmount size soelim split strings strip su tail talk -progs tcopy tee telnet tftp time tip tn3270 touch tput tr true tset tsort -progs tty ul uname unexpand unifdef uniq units unvis users uudecode uuencode -progs vacation vgrind vi vis vmstat w wall wc what whatis whereis who -progs whois window write xargs xinstall xstr yacc yes ypcat ypmatch ypwhich - -# shell scripts: lorder mkdep shar which -# problems: rdist uses libcompat.a(regex.o), which conflicts with -# libedit(readline.o) over regerror(). - -# special requirements - -special locate srcdir /usr/src/usr.bin/locate/locate -special tn3270 srcdir /usr/src/usr.bin/tn3270/tn3270 - - -# ========================================================================= - -srcdirs /usr/src/usr.sbin - -progs ac accton amd arp bad144 catman chown chroot config config.new cron -progs dev_mkdb diskpart edquota flcopy gettable grfinfo hilinfo htable inetd -progs iostat iteconfig kvm_mkdb mtree named portmap pppd -progs pstat pwd_mkdb quot quotaon rarpd rbootd repquota rmt rpc.bootparamd -progs rwhod sa spray sysctl syslogd tcpdump -progs traceroute trpt trsp update vipw vnconfig ypbind yppoll ypset - -special amd srcdir /usr/src/usr.sbin/amd/amd -special amd objs vers.amd.o afs_ops.o am_ops.o clock.o util.o xutil.o efs_ops.o mapc.o info_file.o info_hes.o info_ndbm.o info_passwd.o info_nis.o info_union.o map.o srvr_afs.o srvr_nfs.o mntfs.o misc_rpc.o mount_fs.o mtab.o mtab_bsd.o nfs_ops.o nfs_prot_svc.o nfs_start.o nfs_subr.o opts.o pfs_ops.o rpc_fwd.o sched.o sfs_ops.o amq_svc.o amq_subr.o umount_fs.o host_ops.o nfsx_ops.o ufs_ops.o ifs_ops.o amd.o get_args.o restart.o wire.o - - -srcdirs /usr/src/usr.sbin/lpr # lpr subsystem -progs lpr lpc lpq lprm pac lptest -special lpr srcdir /usr/src/usr.sbin/lpr/lpr - -srcdirs /usr/src/usr.sbin/sendmail # sendmail subsystem -progs mailstats makemap praliases sendmail -special sendmail srcdir /usr/src/usr.sbin/sendmail/src -ln sendmail newaliases -ln sendmail mailq - -srcdirs /usr/src/usr.sbin/timed # timed & timedc -progs timed timedc -special timed srcdir /usr/src/usr.sbin/timed/timed - -srcdirs /usr/src/usr.sbin/xntpd # NTP subsystem -# xntpd uses a gross hack to pass some information in the global -# variable `progname' between the actual program (ntpdate in this -# case), and the NTP library. Add `progname' to the keep list. -progs ntpdate -special ntpdate srcdir /usr/src/usr.sbin/xntpd/ntpdate -special ntpdate keep progname -libs -L/usr/src/usr.sbin/xntpd/lib -lntp - -srcdirs /usr/src/usr.sbin/yp # yp subsystem -progs ypbind ypwhich ypcat ypmatch ypset yppoll - - -# ========================================================================= - -srcdirs /usr/src/gnu/usr.bin - -progs bc cpio diff diff3 gas gawk grep gzip sdiff sort tar -# shell scripts: send-pr - -srcdirs /usr/src/gnu/usr.bin/ld # ldd and ldconfig -progs ld ldd ldconfig - -# rcs stuff loses because there are cross dependencies between librcs.a and -# the individual programs. The solution would be to specify the objpaths -# directly for each one, and include the full path to librcs.a each the -# objpaths. - -# srcdirs /usr/src/gnu/usr.bin/rcs # rcs subsystem -# progs ci co ident merge rcs rcsclean rcsdiff rcsmerge rlog -# # shell script: rcsfreeze -# special rcs srcdir /usr/src/gnu/usr.bin/rcs/rcs -# libs /usr/src/gnu/usr.bin/rcs/lib/obj/librcs.a - -# gdb loses too -# progs gdb -# special gdb srcdir /usr/src/gnu/usr.bin/gdb/gdb -# libs /usr/src/gnu/usr.bin/gdb/bfd/obj/libbfd.a -# libs /usr/src/gnu/usr.bin/gdb/readline/obj/libreadline.a -# libs /usr/src/gnu/usr.bin/gdb/libiberty/obj/libiberty.a - -# groff has the same problem as rcs -# srcdirs /usr/src/gnu/usr.bin/groff # groff subsystem -# progs groff troff tbl pic eqn grops grotty grodvi refer lookbib -# progs indxbib lkbib tfmtodit addftinfo pfbtops psbb -# shell script: nroff -# special groff srcdir /usr/src/gnu/usr.bin/groff/groff -# libs /usr/src/gnu/usr.bin/groff/libgroff/obj/libgroff.a -# libs /usr/src/gnu/usr.bin/groff/libbib/obj/libbib.a -# libs /usr/src/gnu/usr.bin/groff/libdriver/obj/libdriver.a - -srcdirs /usr/src/gnu/usr.bin/gcc2 # gcc & friends -progs cc cpp cc1 - -# cc1 has the same problem as rcs and groff, but since there's only one program -# I'll go ahead and solve it as an example. - -special cc1 objpaths /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-parse.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-lang.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-lex.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-pragma.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-decl.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-typeck.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-convert.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-aux-info.o /usr/src/gnu/usr.bin/gcc2/cc1/obj/c-iterate.o /usr/src/gnu/usr.bin/gcc2/common/obj/libcc1.a - -ln gzip gunzip -ln gzip gzcat - -libs -ledit -lgnumalloc -lc -lcrypt -ltermcap -lcurses -ltelnet -lutil -lkvm -libs -ll -ly -lm -lresolv -lrpcsvc -lcompat diff --git a/usr.sbin/ctm/Makefile b/usr.sbin/ctm/Makefile deleted file mode 100644 index 630aab0..0000000 --- a/usr.sbin/ctm/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -SUBDIR= ctm ctm_rmail ctm_smail ctm_dequeue - -.include diff --git a/usr.sbin/ctm/Makefile.inc b/usr.sbin/ctm/Makefile.inc deleted file mode 100644 index c6c2c5a..0000000 --- a/usr.sbin/ctm/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -.if exists(${.CURDIR}/../../Makefile.inc) -.include "${.CURDIR}/../../Makefile.inc" -.endif diff --git a/usr.sbin/ctm/README b/usr.sbin/ctm/README deleted file mode 100644 index 94c779a..0000000 --- a/usr.sbin/ctm/README +++ /dev/null @@ -1,85 +0,0 @@ -# ---------------------------------------------------------------------------- -# "THE BEER-WARE LICENSE" (Revision 42): -# wrote this file. As long as you retain this notice you -# can do whatever you want with this stuff. If we meet some day, and you think -# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp -# ---------------------------------------------------------------------------- -# -# $FreeBSD$ -# - -What will I not find in this file ? ------------------------------------ -Instructions on how to obtain FreeBSD via CTM. -Contact for that. - -What is CTM ? -------------- -CTM was originally "CVS Through eMail", but has since changed scope to be -much more general. -CTM is now meant to be the definitive way to make and apply a delta between -two versions of a directory tree. -There are two parts to this, making the delta and applying it. These are two -entirely different things. CTM concentrates the computation-burden on the -generation of the deltas, as a delta very often is applied more times than -it is made. Second CTM tries to make the minimal size delta. - -Why not use diff/patch ? ------------------------- -Good question. Primarily because diff and patch doesn't do their job very -well. They don't deal with binary files (in this case files with '\0' or -'\0377' characters in them or files that doesn't end in '\n') which isn't -a big surprise: they were made to deal with text-files only. As a second -gripe, with patch you send the entire file to delete it. Not particular -efficient. - -So what does CTM do exactly ? ------------------------------ -CTM will produce a file, (a delta) containing the instructions and data needed -to take another copy of the tree from the old to the new status. CTM means to -do this in the exact sense, and therefore the delta contains MD5 checksums to -verify that the tree it is applied to is indeed in the state CTM expects. - -This means that if you have modified the tree locally, CTM might not be able -to upgrade your copy. - -How do I make a CTM-delta ? ---------------------------- - -Read the source, and be prepared to have 2 copies of the tree; One is -the reference ("From") tree, and the other is the delta ("To") tree. -The mkCTM script will create the CTM diff of the differences between -the reference tree and the delta tree. A lot of scratch space is -required, and your machine will work hard. - -How do I apply a CTM-delta ? ----------------------------- -You pass it to the 'ctm' command. You can pass a CTM-delta on stdin, or -you can give the filename as an argument. If you do the latter, you make -life a lot easier for your self, since the program can accept gzip'ed files -and since it will not have to make a temporary copy of your file. You can -specify multiple deltas at one time, they will be processed one at a time. - -The ctm command runs in a number of passes. It will process the entire -input file in each pass, before commencing with the next pass. - -Pass 1 will validate that the input file is OK. The syntax, the data and -the global MD5 checksum will be checked. If any of these fail, ctm will -never be able to do anything with the file, so it will simply reject it. - -Pass 2 will validate that the directory tree is in the state expected by -the CTM-delta. This is done by looking for files and directories which -should/should not exists and by checking the MD5 checksums of files. - -Pass 3 will actually apply the delta. - -Should I delete the delta when I have applied it ? --------------------------------------------------- -No. You might want to selectively reconstruct a file latter on. - -Why is CTM not being maintained? --------------------------------- -Because CVSUP has improved on the concept quite a bit, and is now -the method of choice. - -Poul-Henning diff --git a/usr.sbin/ctm/ctm/Makefile b/usr.sbin/ctm/ctm/Makefile deleted file mode 100644 index cc2c9b9..0000000 --- a/usr.sbin/ctm/ctm/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# ---------------------------------------------------------------------------- -# "THE BEER-WARE LICENSE" (Revision 42): -# wrote this file. As long as you retain this notice you -# can do whatever you want with this stuff. If we meet some day, and you think -# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp -# ---------------------------------------------------------------------------- -# -# $FreeBSD$ - -PROG= ctm -MAN= ctm.1 ctm.5 -SRCS= ctm.c ctm_input.c ctm_pass1.c ctm_pass2.c ctm_pass3.c \ - ctm_passb.c ctm_syntax.c ctm_ed.c - -NOTYET= ctm_ed.c - -LDADD= -lmd -DPADD= ${LIBMD} - -WARNS?= 2 - -.if exists(${.CURDIR}/../../Makefile.inc) -.include "${.CURDIR}/../../Makefile.inc" -.endif -.include diff --git a/usr.sbin/ctm/ctm/ctm.1 b/usr.sbin/ctm/ctm/ctm.1 deleted file mode 100644 index d5cc614..0000000 --- a/usr.sbin/ctm/ctm/ctm.1 +++ /dev/null @@ -1,325 +0,0 @@ -.\" ---------------------------------------------------------------------------- -.\" "THE BEER-WARE LICENSE" (Revision 42): -.\" wrote this file. As long as you retain this notice you -.\" can do whatever you want with this stuff. If we meet some day, and you think -.\" this stuff is worth it, you can buy me a beer in return. Joerg Wunsch -.\" ---------------------------------------------------------------------------- -.\" -.\" This manual page is partially obtained from Poul-Hennings CTM README -.\" file. -.\" -.\" CTM and ctm(1) by -.\" -.\" $FreeBSD$ -.\" -.Dd March 25, 1995 -.Dt CTM 1 -.Os -.Sh NAME -.Nm ctm -.Nd source code mirror program -.Sh SYNOPSIS -.Nm -.Op Fl cFklquv -.Op Fl b Ar basedir -.Op Fl B Ar backup-file -.Op Fl e Ar include-regex -.Op Fl t Ar tar-command -.Op Fl T Ar tmpdir -.Op Fl V Ar level -.Op Fl x Ar exclude-regex -.Ar -.Sh DESCRIPTION -The -.Nm -utility was originally -.Dq Cvs Through eMail , -but now instead it seems more fitting to call it -.Dq Current Through eMail . -.Pp -The -.Nm -utility is now meant to be the definitive way to make and apply a delta between -two versions of a directory tree. -.Pp -There are two parts to this, making the delta and applying it. -These are two -entirely different things. -.Ss Usage -To apply a CTM delta, you pass it to the -.Nm -command. -You can pass a CTM delta on stdin, or you can give the -filename as an argument. -If you do the latter, you make life a lot -easier for your self, since the program can accept gzip'ed files and -since it will not have to make a temporary copy of your file. -You can -specify multiple deltas at one time, they will be processed one at a -time. -Deltas that are already applied will be ignored. -.Pp -The -.Nm -command runs in a number of passes. -It will process the entire -input file in each pass, before commencing with the next pass. -.Pp -Before working on a file -.Ar name -.Nm -first checks for the existence of the file -.Ar name.ctm . -If this file exists, -.Nm -works on it instead. -.Pp -Pass 1 will verify that the input file is OK. -The syntax, the data -and the global MD5 checksum will be checked. -If any of these fail, -.Nm -will simply reject the input file. -.Pp -Pass 2 will validate that the directory tree is in the state expected by -the CTM delta. -This is done by looking for files and directories which -should/should not exist and by checking the MD5 checksums of files. -.Pp -If a -.Ar backup-file -had been specified using the -.Fl B -option, all files that would be modified by this -.Nm -invocation are backed up -to this file using the archiver command specified by the -.Fl t -option. -The default archiver command is -.Nm "tar -rf %s -T -" . -.Pp -Pass 3 will actually apply the delta. -.Pp -The list of files that would be modified by -.Nm -is subject to filtering regular expressions specified -using the -.Fl e -and -.Fl x -options. -The -.Fl e -and -.Fl x -options are applied in order of appearance on the command line. -The last -filter that matched a given file name determines whether the file would be -operated on or left alone by -.Nm . -.Pp -The -.Nm -utility -will extract the file hierarchy below its working directory. -Absolute -filenames or filenames containing references through -.Sq Pa .\& -and -.Sq Pa ..\& -are explicitly prohibited as a security measure. -.Ss Options -.Bl -tag -width indent -.It Fl b Ar basedir -Prepend the path -.Ar basedir -to every filename. -.It Fl B Ar backup-file -Backup all files that would be modified by this CTM run to -.Ar backup-file . -If any filters are specified using the -.Fl e -and -.Fl x -options, then the final set of files backed up are those that would be -modified by CTM after the filters are applied. -.It Fl c -Check it out, do not do anything. -.It Fl e Ar regular_expression -Match each name in the CTM file against -.Ar regular_expression , -and if it matches process the file, otherwise leave it alone. -There may be -any number of these options. -Use of this option disables the -.Pa .ctm_status -sequence number checks. -For example, the expression -.Ic ^usr.sbin/ctm -for example, will select the -.Pa usr.sbin/ctm -source directory and all pathnames under it. -.Pp -Pathnames can be disabled from being considered by CTM using the -.Fl x -option. -.It Fl F -Force. -.It Fl k -Keep files and directories and do not remove them even if the CTM file -specifies they are to be removed. -If the -.Fl B -option is specified, these files and directories will not be backed up. -.It Fl l -List files that would be modified by this invocation of CTM and the -actions that would be performed on them. -Use of the -.Fl l -option disables the -.Pa .ctm_status -checks and integrity checks on the source tree being operated on. -The -.Fl l -option can be combined with the -.Fl e -and -.Fl x -options to determine which files would be modified by the given set of -command line options. -.It Fl q -Tell us less. -.It Fl t Ar tar-command -Use -.Ar tar-command -instead of the default archiver -.Nm tar . -This option takes effect only if a backup file had been specified using the -.Fl B -option. -A %s in the tar command will be replaced by the name of the backup -file. -.It Fl T Ar tmpdir -Put temporary files under -.Ar tmpdir . -.It Fl u -Set modification time of created and modified files to the CTM delta -creation time. -.It Fl v -Tell us more. -.It Fl V Ar level -Tell us more. -.Ar Level -is the level of verbosity. -.It Fl x Ar regular_expression -Match each name in the CTM file against -.Ar regular_expression -and if it matches, leave the file alone. -There may be any number of these -options. -Use of this option disables the -.Pa .ctm_status -sequence number checks. -.Pp -Pathnames can be selected for CTM's consideration using the -.Fl e -option. -.El -.Sh SECURITY -On its own, CTM is an insecure protocol -- there is no authentication performed that the -changes applied to the source code were sent by a -trusted party, and so care should be taken if the -CTM deltas are obtained via an unauthenticated -medium such as regular email. -It is a relatively simple matter for an attacker -to forge a CTM delta to replace or precede the -legitimate one and insert malicious code into your -source tree. -If the legitimate delta is somehow prevented from -arriving, this will go unnoticed until a later -delta attempts to touch the same file, at which -point the MD5 checksum will fail. -.Pp -To remedy this insecurity, CTM pieces generated by -FreeBSD.org are cryptographically signed in a -format compatible with the GNU Privacy Guard -utility, available in /usr/ports/security/gpg, and -the Pretty Good Privacy v5 utility, -/usr/ports/security/pgp5. -The relevant public key can be obtained by -fingering ctm@FreeBSD.org. -.Pp -CTM deltas which are thus signed cannot be -undetectably altered by an attacker. -Therefore it is recommended that you make use of -GPG or PGP5 to verify the signatures if you -receive your CTM deltas via email. -.Sh ENVIRONMENT -.Ev TMPDIR , -if set to a pathname, will cause ctm to use that pathname -as the location of temporary file. -See -.Xr tempnam 3 , -for more details on this. -The same effect may be achieved with the -.Fl T -flag. -.Sh FILES -.Pa .ctm_status -contains the sequence number of the last CTM delta applied. -Changing -or removing this file will greatly confuse -.Nm . -.Pp -Using the -.Fl e -and -.Fl x -options can update a partial subset of the source tree and causes sources -to be in an inconsistent state. -It is assumed that you know what you are -doing when you use these options. -.Sh EXAMPLES -.Bd -literal -cd ~cvs -/usr/sbin/ctm ~ctm/cvs-* -.Ed -.Pp -To extract and patch all sources under `lib' -.Bd -literal -cd ~/lib-srcs -/usr/sbin/ctm -e '^lib' ~ctm/src-cur* -.Ed -.Sh DIAGNOSTICS -Numerous messages, hopefully self-explanatory. -The -.Dq noise level -can be adjusted with the -.Fl q , -.Fl v -and -.Fl V -options. -.Sh SEE ALSO -.Xr ctm_rmail 1 , -.Xr ctm 5 -.Sh HISTORY -Initial trials were run during the work on -.Fx 1.1.5 , -and many bugs and -methods were hashed out. -.Pp -The -.Nm -command appeared in -.Fx 2.1 . -.Sh AUTHORS -The CTM system has been designed and implemented by -.An Poul-Henning Kamp -.Aq phk@FreeBSD.org . -.Pp -.An Joerg Wunsch -.Aq joerg@FreeBSD.org -wrote this man-page. diff --git a/usr.sbin/ctm/ctm/ctm.5 b/usr.sbin/ctm/ctm/ctm.5 deleted file mode 100644 index a51c93b..0000000 --- a/usr.sbin/ctm/ctm/ctm.5 +++ /dev/null @@ -1,183 +0,0 @@ -.\" ---------------------------------------------------------------------------- -.\" "THE BEER-WARE LICENSE" (Revision 42): -.\" wrote this file. As long as you retain this notice you -.\" can do whatever you want with this stuff. If we meet some day, and you think -.\" this stuff is worth it, you can buy me a beer in return. Joerg Wunsch -.\" ---------------------------------------------------------------------------- -.\" -.\" This manual page is partially obtained from Poul-Hennings CTM README -.\" file. -.\" -.\" CTM and ctm(1) by -.\" -.\" $FreeBSD$ -.\" -.Dd March 25, 1995 -.Dt CTM 5 -.Os -.Sh NAME -.Nm ctm -.Nd source code mirror system -.Sh DESCRIPTION -The -.Nm -transfers data in a specific file format, called a CTM delta. -.Pp -CTM deltas consist of control lines and data chunks. -Each control -line starts with the letters -.Dq CTM , -followed by a CTM statement and control data, and ends with a '\en' -character. -.Pp -Data chunks always belong to the preceding control line, and the -last field on that control line is the number of bytes in the data -chunk. -A trailing newline '\en' character follows each data chunk, this -newline is not part of the chunk and is not included in the count. -.Pp -The CTM statements are as follows. -.Bl -tag -width indent -.It _BEGIN Ar version name number timestamp prefix -This is the overall begin of a CTM delta file. -The -.Ar version -field must match the program version -(currently 2.0). -.Ar Name -is the name and -.Ar number -the sequence number of the CTM service, it is matched against the file -.Pa .ctm_status -to see if the delta has already been applied. -.Ar Timestamp -contains the year, month, day, hour, minute, and second of the -time of delta creation for reference -(followed by the letter -.Sq Z -meaning this is a UTC timestamp). -The -.Ar prefix -field is currently not implemented. -.It _END Ar md5 -This statement ends the CTM delta, the global -.Ar md5 -checksum is matched against the MD5 checksum of the entire delta, up to -and including the space (0x20) character following ``_END''. -.It \&FM Ar name uid gid mode md5 count -Make the file -.Ar name , -the original file had the uid -.Ar uid -(numerical, decimal), -the gid -.Ar gid -(numerical, decimal), -mode -.Ar mode -(numerical, octal), -and the MD5 checksum -.Ar md5 . -.Pp -The following -.Ar count -bytes data are the contents of the new file. -.It \&FS Ar name uid gid mode md5before md5after count -Substitute the contents of file -.Ar name , -the original file had the new uid -.Ar uid -(numerical, decimal), -the new gid -.Ar gid -(numerical, decimal), -new mode -.Ar mode -(numerical, octal), -the old MD5 checksum -.Ar md5before , -and the new MD5 checksum -.Ar md5after . -.Pp -The following -.Ar count -bytes data are the contents of the new file. -.Pp -File substitution is used if the commands to edit a file would exceed -the total file length, so substituting it is more efficient. -.It \&FN Ar name uid gid mode md5before md5after count -Edit the file -.Ar name . -The arguments are as above, but the data sections contains an -.Xr diff 1 --n script which should be applied to the file in question. -.It \&FR Ar name md5 -Remove the file -.Ar name , -which must match the MD5 checksum -.Ar md5 . -.It \&AS Ar name uid gid mode -The original file -.Ar name -changed its owner to -.Ar uid , -its group to -.Ar gid , -and/or its mode to -.Ar mode . -.It \&DM Ar name uid gid mode -The directory -.Ar name -is to be created, it had originally the owner -.Ar uid , -group -.Ar gid , -and mode -.Ar mode . -.It \&DR Ar name -The directory -.Ar name -is to be removed. -.El -.Sh EXAMPLES -In the following example, long lines have been folded to make them -printable -(marked by backslashes). -.Bd -literal -CTM_BEGIN 2.0 cvs-cur 485 19950324214652Z . -CTMFR src/sys/gnu/i386/isa/scd.c,v 5225f13aa3c7e458f9dd0d4bb637b18d -CTMFR src/sys/gnu/i386/isa/scdreg.h,v e5af42b8a06f2c8030b93a7d71afb223 -CTMDM src/sys/gnu/i386/isa/Attic 0 552 775 -CTMFS .ctm_status 545 552 664 d9ccd2a84a9dbb8db56ba85663adebf0 \\ -e2a10c6f66428981782a0a18a789ee2e 12 -cvs-cur 485 - -CTMFN CVSROOT/commitlogs/gnu 545 552 664 \\ -5d7bc3549140d860bd9641b5782c002d 7fb04ed84b48160c9b8eea84b4c0b6e3 394 -a6936 21 -ache 95/03/24 09:59:50 - - Modified: gnu/lib/libdialog kernel.c prgbox.c - Log: -[...] -CTM_END 74ddd298d76215ae45a077a4b6a74e9c -.Ed -.Sh SEE ALSO -.Xr ctm 1 , -.Xr ctm_rmail 1 , -.Xr ed 1 -.Sh HISTORY -Initial trials ran during the -.Fx 1.1.5 , -and many bugs and -methods were hashed out. -The CTM system has been made publicly available in -.Fx 2.1 . -.Sh AUTHORS -The CTM system has been designed and implemented by -.An Poul-Henning Kamp -.Aq phk@FreeBSD.org . -.Pp -.An Joerg Wunsch -.Aq joerg@FreeBSD.org -wrote this man-page. diff --git a/usr.sbin/ctm/ctm/ctm.c b/usr.sbin/ctm/ctm/ctm.c deleted file mode 100644 index 0ea4895..0000000 --- a/usr.sbin/ctm/ctm/ctm.c +++ /dev/null @@ -1,331 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - * This is the client program of 'CTM'. It will apply a CTM-patch to a - * collection of files. - * - * Options we'd like to see: - * - * -a Attempt best effort. - * -d Debug TBD. - * -m Email me instead. - * -r Reconstruct file. - * -R Read list of files to reconstruct. - * - * Options we have: - * -b Base-dir - * -B Backup to tar-file. - * -t Tar command (default as in TARCMD). - * -c Check it out, don't do anything. - * -F Force - * -q Tell us less. - * -T . Temporary files. - * -u Set all file modification times to the timestamp - * -v Tell us more. - * -V Tell us more level = number of -v - * -k Keep files and directories that would have been removed. - * -l List actions. - * - * Options we don't actually use: - * -p Less paranoid. - * -P Paranoid. - */ - -#define EXTERN /* */ -#include -#include "ctm.h" - -#define CTM_STATUS ".ctm_status" - -extern int Proc(char *, unsigned applied); - -int -main(int argc, char **argv) -{ - int stat=0, err=0; - int c; - unsigned applied = 0; - FILE *statfile; - struct CTM_Filter *nfilter = NULL; /* new filter */ - u_char * basedir; - - basedir = NULL; - Verbose = 1; - Paranoid = 1; - SetTime = 0; - KeepIt = 0; - ListIt = 0; - BackupFile = NULL; - TarCmd = TARCMD; - LastFilter = FilterList = NULL; - TmpDir = getenv("TMPDIR"); - if (TmpDir == NULL) - TmpDir = strdup(_PATH_TMP); - setbuf(stderr,0); - setbuf(stdout,0); - - while((c=getopt(argc,argv,"ab:B:cd:e:Fklm:pPqr:R:t:T:uV:vx:")) != -1) { - switch (c) { - case 'b': basedir = optarg; break; /* Base Directory */ - case 'B': BackupFile = optarg; break; - case 'c': CheckIt++; break; /* Only check it */ - case 'F': Force = 1; break; - case 'k': KeepIt++; break; /* Don't do removes */ - case 'l': ListIt++; break; /* Only list actions and files */ - case 'p': Paranoid--; break; /* Less Paranoid */ - case 'P': Paranoid++; break; /* More Paranoid */ - case 'q': Verbose--; break; /* Quiet */ - case 't': TarCmd = optarg; break; /* archiver command */ - case 'T': TmpDir = optarg; break; /* set temporary directory */ - case 'u': SetTime++; break; /* Set timestamp on files */ - case 'v': Verbose++; break; /* Verbose */ - case 'V': sscanf(optarg,"%d", &c); /* Verbose */ - Verbose += c; - break; - case 'e': /* filter expressions */ - case 'x': - if (NULL == (nfilter = Malloc(sizeof(struct CTM_Filter)))) { - warnx("out of memory for expressions: \"%s\"", optarg); - stat++; - break; - } - - (void) memset(nfilter, 0, sizeof(struct CTM_Filter)); - - if (0 != (err = - regcomp(&nfilter->CompiledRegex, optarg, REG_NOSUB))) { - - char errmsg[128]; - - regerror(err, &nfilter->CompiledRegex, errmsg, - sizeof(errmsg)); - warnx("regular expression: \"%s\"", errmsg); - stat++; - break; - } - - /* note whether the filter enables or disables on match */ - nfilter->Action = - (('e' == c) ? CTM_FILTER_ENABLE : CTM_FILTER_DISABLE); - - /* link in the expression into the list */ - nfilter->Next = NULL; - if (NULL == FilterList) { - LastFilter = FilterList = nfilter; /* init head and tail */ - } else { /* place at tail */ - LastFilter->Next = nfilter; - LastFilter = nfilter; - } - break; - case ':': - warnx("option '%c' requires an argument",optopt); - stat++; - break; - case '?': - warnx("option '%c' not supported",optopt); - stat++; - break; - default: - warnx("option '%c' not yet implemented",optopt); - break; - } - } - - if(stat) { - warnx("%d errors during option processing",stat); - return Exit_Pilot; - } - stat = Exit_Done; - argc -= optind; - argv += optind; - - if (basedir == NULL) { - Buffer = (u_char *)Malloc(BUFSIZ + strlen(SUBSUFF) +1); - CatPtr = Buffer; - *Buffer = '\0'; - } else { - Buffer = (u_char *)Malloc(strlen(basedir)+ BUFSIZ + strlen(SUBSUFF) +1); - strcpy(Buffer, basedir); - CatPtr = Buffer + strlen(basedir); - if (CatPtr[-1] != '/') { - strcat(Buffer, "/"); - CatPtr++; - } - } - strcat(Buffer, CTM_STATUS); - - if(ListIt) - applied = 0; - else - if((statfile = fopen(Buffer, "r")) == NULL) { - if (Verbose > 0) - warnx("warning: %s not found", Buffer); - } else { - fscanf(statfile, "%*s %u", &applied); - fclose(statfile); - } - - if(!argc) - stat |= Proc("-", applied); - - while(argc-- && stat == Exit_Done) { - stat |= Proc(*argv++, applied); - stat &= ~(Exit_Version | Exit_NoMatch); - } - - if(stat == Exit_Done) - stat = Exit_OK; - - if(Verbose > 0) - warnx("exit(%d)",stat); - - if (FilterList) - for (nfilter = FilterList; nfilter; ) { - struct CTM_Filter *tmp = nfilter->Next; - Free(nfilter); - nfilter = tmp; - } - return stat; -} - -int -Proc(char *filename, unsigned applied) -{ - FILE *f; - int i; - char *p = strrchr(filename,'.'); - - if(!strcmp(filename,"-")) { - p = 0; - f = stdin; - } else if(p && (!strcmp(p,".gz") || !strcmp(p,".Z"))) { - p = alloca(20 + strlen(filename)); - strcpy(p,"gunzip < "); - strcat(p,filename); - f = popen(p,"r"); - if(!f) { warn("%s", p); return Exit_Garbage; } - } else { - p = 0; - f = fopen(filename,"r"); - } - if(!f) { - warn("%s", filename); - return Exit_Garbage; - } - - if(Verbose > 1) - fprintf(stderr,"Working on <%s>\n",filename); - - Delete(FileName); - FileName = String(filename); - - /* If we cannot seek, we're doomed, so copy to a tmp-file in that case */ - if(!p && -1 == fseek(f,0,SEEK_END)) { - char *fn; - FILE *f2; - int fd; - - if (asprintf(&fn, "%s/CTMclient.XXXXXXXXXX", TmpDir) == -1) { - fprintf(stderr, "Cannot allocate memory\n"); - fclose(f); - return Exit_Broke; - } - if ((fd = mkstemp(fn)) == -1 || (f2 = fdopen(fd, "w+")) == NULL) { - warn("%s", fn); - free(fn); - if (fd != -1) - close(fd); - fclose(f); - return Exit_Broke; - } - unlink(fn); - if (Verbose > 0) - fprintf(stderr,"Writing tmp-file \"%s\"\n",fn); - free(fn); - while(EOF != (i=getc(f))) - if(EOF == putc(i,f2)) { - fclose(f2); - return Exit_Broke; - } - fclose(f); - f = f2; - } - - if(!p) - rewind(f); - - if((i=Pass1(f, applied))) - goto exit_and_close; - - if(ListIt) { - i = Exit_Done; - goto exit_and_close; - } - - if(!p) { - rewind(f); - } else { - pclose(f); - f = popen(p,"r"); - if(!f) { warn("%s", p); return Exit_Broke; } - } - - i=Pass2(f); - - if(!p) { - rewind(f); - } else { - pclose(f); - f = popen(p,"r"); - if(!f) { warn("%s", p); return Exit_Broke; } - } - - if(i) { - if((!Force) || (i & ~Exit_Forcible)) - goto exit_and_close; - } - - if(CheckIt) { - if (Verbose > 0) - fprintf(stderr,"All checks out ok.\n"); - i = Exit_Done; - goto exit_and_close; - } - - /* backup files if requested */ - if(BackupFile) { - - i = PassB(f); - - if(!p) { - rewind(f); - } else { - pclose(f); - f = popen(p,"r"); - if(!f) { warn("%s", p); return Exit_Broke; } - } - } - - i=Pass3(f); - -exit_and_close: - if(!p) - fclose(f); - else - pclose(f); - - if(i) - return i; - - if (Verbose > 0) - fprintf(stderr,"All done ok\n"); - - return Exit_Done; -} diff --git a/usr.sbin/ctm/ctm/ctm.h b/usr.sbin/ctm/ctm/ctm.h deleted file mode 100644 index b733539..0000000 --- a/usr.sbin/ctm/ctm/ctm.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define VERSION "2.0" - -#define SUBSUFF ".ctm" -#define TMPSUFF ".ctmtmp" -#define TARCMD "tar -rf %s -T -" - -/* The fields... */ -#define CTM_F_MASK 0xff -#define CTM_F_Name 0x01 -#define CTM_F_Uid 0x02 -#define CTM_F_Gid 0x03 -#define CTM_F_Mode 0x04 -#define CTM_F_MD5 0x05 -#define CTM_F_Count 0x06 -#define CTM_F_Bytes 0x07 - -/* The qualifiers... */ -#define CTM_Q_MASK 0xff00 -#define CTM_Q_Name_File 0x0100 -#define CTM_Q_Name_Dir 0x0200 -#define CTM_Q_Name_New 0x0400 -#define CTM_Q_Name_Subst 0x0800 -#define CTM_Q_MD5_After 0x0100 -#define CTM_Q_MD5_Before 0x0200 -#define CTM_Q_MD5_Chunk 0x0400 -#define CTM_Q_MD5_Force 0x0800 - -struct CTM_Syntax { - char *Key; /* CTM key for operation */ - int *List; /* List of operations */ - }; - -extern struct CTM_Syntax Syntax[]; - -struct CTM_Filter { - struct CTM_Filter *Next; /* next filter in the list */ - int Action; /* enable or disable */ - regex_t CompiledRegex; /* compiled regex */ -}; - -#define CTM_FILTER_DISABLE 0 -#define CTM_FILTER_ENABLE 1 - -#define Malloc malloc -#define Free free -#define Delete(foo) if (!foo) ; else {Free(foo); foo = 0; } -#define String(foo) strdup(foo) - -#ifndef EXTERN -# define EXTERN extern -#endif -EXTERN u_char *Version; -EXTERN u_char *Name; -EXTERN u_char *Nbr; -EXTERN u_char *TimeStamp; -EXTERN u_char *Prefix; -EXTERN u_char *FileName; -EXTERN u_char *TmpDir; -EXTERN u_char *CatPtr; -EXTERN u_char *Buffer; -EXTERN u_char *BackupFile; -EXTERN u_char *TarCmd; - -/* - * Paranoid -- Just in case they should be after us... - * 0 not at all. - * 1 normal. - * 2 somewhat. - * 3 you bet!. - * - * Verbose -- What to tell mom... - * 0 Nothing which wouldn't surprise. - * 1 Normal. - * 2 Show progress '.'. - * 3 Show progress names, and actions. - * 4 even more... - * and so on - * - * ExitCode -- our Epitaph - * 0 Perfect, all input digested, no problems - * 1 Bad input, no point in retrying. - * 2 Pilot error, commandline problem &c - * 4 Out of resources. - * 8 Destination-tree not correct. - * 16 Destination-tree not correct, can force. - * 32 Internal problems. - * - */ - -EXTERN int Paranoid; -EXTERN int Verbose; -EXTERN int Exit; -EXTERN int Force; -EXTERN int CheckIt; -EXTERN int KeepIt; -EXTERN int ListIt; -EXTERN int SetTime; -EXTERN struct timeval Times[2]; -EXTERN struct CTM_Filter *FilterList; -EXTERN struct CTM_Filter *LastFilter; - -#define Exit_OK 0 -#define Exit_Garbage 1 -#define Exit_Pilot 2 -#define Exit_Broke 4 -#define Exit_NotOK 8 -#define Exit_Forcible 16 -#define Exit_Mess 32 -#define Exit_Done 64 -#define Exit_Version 128 -#define Exit_NoMatch 256 - -void Fatal_(int ln, char *fn, char *kind); -#define Fatal(foo) Fatal_(__LINE__,__FILE__,foo) -#define Assert() Fatal_(__LINE__,__FILE__,"Assert failed.") -#define WRONG {Assert(); return Exit_Mess;} - -u_char * Ffield(FILE *fd, MD5_CTX *ctx,u_char term); -u_char * Fname(FILE *fd, MD5_CTX *ctx,u_char term,int qual, int verbose); - -int Fbytecnt(FILE *fd, MD5_CTX *ctx, u_char term); - -u_char * Fdata(FILE *fd, int u_chars, MD5_CTX *ctx); - -#define GETFIELD(p,q) if(!((p)=Ffield(fd,&ctx,(q)))) return BADREAD -#define GETFIELDCOPY(p,q) if(!((p)=Ffield(fd,&ctx,(q)))) return BADREAD; else p=String(p) -#define GETBYTECNT(p,q) if(0 >((p)= Fbytecnt(fd,&ctx,(q)))) return BADREAD -#define GETDATA(p,q) if(!((p) = Fdata(fd,(q),&ctx))) return BADREAD -#define GETNAMECOPY(p,q,r,v) if(!((p)=Fname(fd,&ctx,(q),(r),(v)))) return BADREAD; else p=String(p) - -int Pass1(FILE *fd, unsigned applied); -int Pass2(FILE *fd); -int PassB(FILE *fd); -int Pass3(FILE *fd); - -int ctm_edit(u_char *script, int length, char *filein, char *fileout); diff --git a/usr.sbin/ctm/ctm/ctm_ed.c b/usr.sbin/ctm/ctm/ctm_ed.c deleted file mode 100644 index e3ec464..0000000 --- a/usr.sbin/ctm/ctm/ctm_ed.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include "ctm.h" - -int -ctm_edit(u_char *script, int length, char *filein, char *fileout) -{ - u_char *ep, cmd; - int ln, ln2, iln, ret=0, c; - FILE *fi=0,*fo=0; - - fi = fopen(filein,"r"); - if(!fi) { - warn("%s", filein); - return 8; - } - - fo = fopen(fileout,"w"); - if(!fo) { - warn("%s", fileout); - fclose(fi); - return 4; - } - iln = 1; - for(ep=script;ep < script+length;) { - cmd = *ep++; - if(cmd != 'a' && cmd != 'd') { ret = 1; goto bye; } - ln = 0; - while(isdigit(*ep)) { - ln *= 10; - ln += (*ep++ - '0'); - } - if(*ep++ != ' ') { ret = 1; goto bye; } - ln2 = 0; - while(isdigit(*ep)) { - ln2 *= 10; - ln2 += (*ep++ - '0'); - } - if(*ep++ != '\n') { ret = 1; goto bye; } - - - if(cmd == 'd') { - while(iln < ln) { - c = getc(fi); - if(c == EOF) { ret = 1; goto bye; } - putc(c,fo); - if(c == '\n') - iln++; - } - while(ln2) { - c = getc(fi); - if(c == EOF) { ret = 1; goto bye; } - if(c != '\n') - continue; - ln2--; - iln++; - } - continue; - } - if(cmd == 'a') { - while(iln <= ln) { - c = getc(fi); - if(c == EOF) { ret = 1; goto bye; } - putc(c,fo); - if(c == '\n') - iln++; - } - while(ln2) { - c = *ep++; - putc(c,fo); - if(c != '\n') - continue; - ln2--; - } - continue; - } - ret = 1; - goto bye; - } - while(1) { - c = getc(fi); - if(c == EOF) break; - putc(c,fo); - } - ret = 0; -bye: - if(fi) { - if(fclose(fi) != 0) { - warn("%s", filein); - ret = 1; - } - } - if(fo) { - if(fflush(fo) != 0) { - warn("%s", fileout); - ret = 1; - } - if(fclose(fo) != 0) { - warn("%s", fileout); - ret = 1; - } - } - return ret; -} diff --git a/usr.sbin/ctm/ctm/ctm_input.c b/usr.sbin/ctm/ctm/ctm_input.c deleted file mode 100644 index 32166d3..0000000 --- a/usr.sbin/ctm/ctm/ctm_input.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include "ctm.h" - -/*---------------------------------------------------------------------------*/ -void -Fatal_(int ln, char *fn, char *kind) -{ - if(Verbose > 2) - fprintf(stderr,"Fatal error. (%s:%d)\n",fn,ln); - fprintf(stderr,"%s Fatal error: %s\n",FileName, kind); -} -#define Fatal(foo) Fatal_(__LINE__,__FILE__,foo) -#define Assert() Fatal_(__LINE__,__FILE__,"Assert failed.") - -/*---------------------------------------------------------------------------*/ -/* get next field, check that the terminating whitespace is what we expect */ -u_char * -Ffield(FILE *fd, MD5_CTX *ctx,u_char term) -{ - static u_char buf[BUFSIZ]; - int i,l; - - for(l=0;;) { - if((i=getc(fd)) == EOF) { - Fatal("Truncated patch."); - return 0; - } - buf[l++] = i; - if(isspace(i)) - break; - if(l >= sizeof buf) { - Fatal("Corrupt patch."); - printf("Token is too long.\n"); - return 0; - } - } - buf[l] = '\0'; - MD5Update(ctx,buf,l); - if(buf[l-1] != term) { - Fatal("Corrupt patch."); - fprintf(stderr,"Expected \"%s\" but didn't find it {%02x}.\n", - term == '\n' ? "\\n" : " ",buf[l-1]); - if(Verbose > 4) - fprintf(stderr,"{%s}\n",buf); - return 0; - } - buf[--l] = '\0'; - if(Verbose > 4) - fprintf(stderr,"<%s>\n",buf); - return buf; -} - -int -Fbytecnt(FILE *fd, MD5_CTX *ctx, u_char term) -{ - u_char *p,*q; - int u_chars=0; - - p = Ffield(fd,ctx,term); - if(!p) return -1; - for(q=p;*q;q++) { - if(!isdigit(*q)) { - Fatal("Bytecount contains non-digit."); - return -1; - } - u_chars *= 10; - u_chars += (*q - '0'); - } - return u_chars; -} - -u_char * -Fdata(FILE *fd, int u_chars, MD5_CTX *ctx) -{ - u_char *p = Malloc(u_chars+1); - - if(u_chars+1 != fread(p,1,u_chars+1,fd)) { - Fatal("Truncated patch."); - return 0; - } - MD5Update(ctx,p,u_chars+1); - if(p[u_chars] != '\n') { - if(Verbose > 3) - printf("FileData wasn't followed by a newline.\n"); - Fatal("Corrupt patch."); - return 0; - } - p[u_chars] = '\0'; - return p; -} - -/*---------------------------------------------------------------------------*/ -/* get the filename in the next field, prepend BaseDir and give back the result - strings. The sustitute filename is return (the one with the suffix SUBSUFF) - if it exists and the qualifier contains CTM_Q_Name_Subst - NOTA: Buffer is already initialize with BaseDir, CatPtr is the insertion - point on this buffer + the length test in Ffield() is enough for Fname() */ - -u_char * -Fname(FILE *fd, MD5_CTX *ctx,u_char term,int qual, int verbose) -{ - u_char * p; - struct stat st; - - if ((p = Ffield(fd,ctx,term)) == NULL) return(NULL); - - strcpy(CatPtr, p); - - if (!(qual & CTM_Q_Name_Subst)) return(Buffer); - - p = Buffer + strlen(Buffer); - - strcat(Buffer, SUBSUFF); - - if ( -1 == stat(Buffer, &st) ) { - *p = '\0'; - } else { - if(verbose > 2) - fprintf(stderr,"Using %s as substitute file\n", Buffer); - } - - return (Buffer); -} diff --git a/usr.sbin/ctm/ctm/ctm_pass1.c b/usr.sbin/ctm/ctm/ctm_pass1.c deleted file mode 100644 index 026a320..0000000 --- a/usr.sbin/ctm/ctm/ctm_pass1.c +++ /dev/null @@ -1,250 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include "ctm.h" -#define BADREAD 1 - -/*---------------------------------------------------------------------------*/ -/* Pass1 -- Validate the incoming CTM-file. - */ - -int -Pass1(FILE *fd, unsigned applied) -{ - u_char *p,*q; - MD5_CTX ctx; - int i,j,sep,cnt; - u_char *md5=0,*name=0,*trash=0; - struct CTM_Syntax *sp; - int slashwarn=0, match=0, total_matches=0; - unsigned current; - char md5_1[33]; - - if(Verbose>3) - printf("Pass1 -- Checking integrity of incoming CTM-patch\n"); - MD5Init (&ctx); - - GETFIELD(p,' '); /* CTM_BEGIN */ - if(strcmp(p,"CTM_BEGIN")) { - Fatal("Probably not a CTM-patch at all."); - if(Verbose>3) - fprintf(stderr,"Expected \"CTM_BEGIN\" got \"%s\".\n",p); - return 1; - } - - GETFIELDCOPY(Version,' '); /* */ - if(strcmp(Version,VERSION)) { - Fatal("CTM-patch is wrong version."); - if(Verbose>3) - fprintf(stderr,"Expected \"%s\" got \"%s\".\n",VERSION,p); - return 1; - } - - GETFIELDCOPY(Name,' '); /* */ - GETFIELDCOPY(Nbr,' '); /* */ - GETFIELDCOPY(TimeStamp,' '); /* */ - GETFIELDCOPY(Prefix,'\n'); /* */ - - sscanf(Nbr, "%u", ¤t); - if (FilterList || ListIt) - current = 0; /* ignore if -l or if filters are present */ - if(current && current <= applied) { - if(Verbose > 0) - fprintf(stderr,"Delta number %u is already applied; ignoring.\n", - current); - return Exit_Version; - } - - for(;;) { - Delete(md5); - Delete(name); - Delete(trash); - cnt = -1; - /* if a filter list is defined we assume that all pathnames require - an action opposite to that requested by the first filter in the - list. - If no filter is defined, all pathnames are assumed to match. */ - match = (FilterList ? !(FilterList->Action) : CTM_FILTER_ENABLE); - - GETFIELD(p,' '); /* CTM_something */ - - if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') { - Fatal("Expected CTM keyword."); - fprintf(stderr,"Got [%s]\n",p); - return 1; - } - - if(!strcmp(p+3,"_END")) - break; - - for(sp=Syntax;sp->Key;sp++) - if(!strcmp(p+3,sp->Key)) - goto found; - Fatal("Expected CTM keyword."); - fprintf(stderr,"Got [%s]\n",p); - return 1; - found: - if(Verbose > 5) - fprintf(stderr,"%s ",sp->Key); - for(i=0;(j = sp->List[i]);i++) { - if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes) - sep = ' '; - else - sep = '\n'; - - if(Verbose > 5) - fprintf(stderr," %x(%d)",sp->List[i],sep); - - switch (j & CTM_F_MASK) { - case CTM_F_Name: /* XXX check for garbage and .. */ - GETFIELDCOPY(name,sep); - j = strlen(name); - if(name[j-1] == '/' && !slashwarn) { - fprintf(stderr,"Warning: contains trailing slash\n"); - slashwarn++; - } - if (name[0] == '/') { - Fatal("Absolute paths are illegal."); - return Exit_Mess; - } - q = name; - for (;;) { - if (q[0] == '.' && q[1] == '.') - if (q[2] == '/' || q[2] == '\0') { - Fatal("Paths containing '..' are illegal."); - return Exit_Mess; - } - if ((q = strchr(q, '/')) == NULL) - break; - q++; - } - - /* if we have been asked to `keep' files then skip - removes; i.e. we don't match these entries at - all. */ - if (KeepIt && - (!strcmp(sp->Key,"DR") || !strcmp(sp->Key,"FR"))) { - match = CTM_FILTER_DISABLE; - break; - } - - /* If filter expression have been defined, match the - path name against the expression list. */ - - if (FilterList) { - struct CTM_Filter *filter; - - for (filter = FilterList; filter; - filter = filter->Next) { - if (0 == regexec(&filter->CompiledRegex, name, - 0, 0, 0)) - /* if the name matches, adopt the - action */ - match = filter->Action; - } - } - - /* Add up the total number of matches */ - total_matches += match; - break; - case CTM_F_Uid: - GETFIELD(p,sep); - while(*p) { - if(!isdigit(*p)) { - Fatal("Non-digit in uid."); - return 32; - } - p++; - } - break; - case CTM_F_Gid: - GETFIELD(p,sep); - while(*p) { - if(!isdigit(*p)) { - Fatal("Non-digit in gid."); - return 32; - } - p++; - } - break; - case CTM_F_Mode: - GETFIELD(p,sep); - while(*p) { - if(!isdigit(*p)) { - Fatal("Non-digit in mode."); - return 32; - } - p++; - } - break; - case CTM_F_MD5: - if(j & CTM_Q_MD5_Chunk) { - GETFIELDCOPY(md5,sep); /* XXX check for garbage */ - } else if(j & CTM_Q_MD5_Before) { - GETFIELD(p,sep); /* XXX check for garbage */ - } else if(j & CTM_Q_MD5_After) { - GETFIELD(p,sep); /* XXX check for garbage */ - } else { - fprintf(stderr,"List = 0x%x\n",j); - Fatal("Unqualified MD5."); - return 32; - } - break; - case CTM_F_Count: - GETBYTECNT(cnt,sep); - break; - case CTM_F_Bytes: - if(cnt < 0) WRONG - GETDATA(trash,cnt); - p = MD5Data(trash,cnt,md5_1); - if(md5 && strcmp(md5,p)) { - Fatal("Internal MD5 failed."); - return Exit_Garbage; - default: - fprintf(stderr,"List = 0x%x\n",j); - Fatal("List had garbage."); - return Exit_Garbage; - } - } - } - if(Verbose > 5) - putc('\n',stderr); - if(ListIt && match) - printf("> %s %s\n", sp->Key, name); - } - - Delete(md5); - Delete(name); - Delete(trash); - - q = MD5End (&ctx,md5_1); - if(Verbose > 2) - printf("Expecting Global MD5 <%s>\n",q); - GETFIELD(p,'\n'); /* */ - if(Verbose > 2) - printf("Reference Global MD5 <%s>\n",p); - if(strcmp(q,p)) { - Fatal("MD5 sum doesn't match."); - fprintf(stderr,"\tI have:<%s>\n",q); - fprintf(stderr,"\tShould have been:<%s>\n",p); - return Exit_Garbage; - } - if (-1 != getc(fd)) { - if(!Force) { - Fatal("Trailing junk in CTM-file. Can Force with -F."); - return 16; - } - } - if ((Verbose > 1) && (0 == total_matches)) - printf("No matches in \"%s\"\n", FileName); - return (total_matches ? Exit_OK : Exit_NoMatch); -} diff --git a/usr.sbin/ctm/ctm/ctm_pass2.c b/usr.sbin/ctm/ctm/ctm_pass2.c deleted file mode 100644 index a0b857a..0000000 --- a/usr.sbin/ctm/ctm/ctm_pass2.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include "ctm.h" -#define BADREAD 32 - -/*---------------------------------------------------------------------------*/ -/* Pass2 -- Validate the incoming CTM-file. - */ - -int -Pass2(FILE *fd) -{ - u_char *p,*q,*md5=0; - MD5_CTX ctx; - int i,j,sep,cnt,fdesc; - u_char *trash=0,*name=0; - struct CTM_Syntax *sp; - struct stat st; - int ret = 0; - int match = 0; - char md5_1[33]; - struct CTM_Filter *filter; - FILE *ed = NULL; - static char *template = NULL; - - if(Verbose>3) - printf("Pass2 -- Checking if CTM-patch will apply\n"); - MD5Init (&ctx); - - GETFIELD(p,' '); if(strcmp("CTM_BEGIN",p)) WRONG - GETFIELD(p,' '); if(strcmp(Version,p)) WRONG - GETFIELD(p,' '); if(strcmp(Name,p)) WRONG - /* XXX Lookup name in /etc/ctm,conf, read stuff */ - GETFIELD(p,' '); if(strcmp(Nbr,p)) WRONG - /* XXX Verify that this is the next patch to apply */ - GETFIELD(p,' '); if(strcmp(TimeStamp,p)) WRONG - GETFIELD(p,'\n'); if(strcmp(Prefix,p)) WRONG - /* XXX drop or use ? */ - - for(;;) { - Delete(trash); - Delete(name); - Delete(md5); - cnt = -1; - - /* if a filter list was specified, check file name against - the filters specified - if no filter was given operate on all files. */ - match = (FilterList ? - !(FilterList->Action) : CTM_FILTER_ENABLE); - - GETFIELD(p,' '); - - if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') WRONG - - if(!strcmp(p+3,"_END")) - break; - - for(sp=Syntax;sp->Key;sp++) - if(!strcmp(p+3,sp->Key)) - goto found; - WRONG - found: - for(i=0;(j = sp->List[i]);i++) { - if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes) - sep = ' '; - else - sep = '\n'; - - switch (j & CTM_F_MASK) { - case CTM_F_Name: - GETNAMECOPY(name,sep,j,0); - /* If `keep' was specified, we won't remove any files, - so don't check if the file exists */ - if (KeepIt && - (!strcmp(sp->Key,"FR") || !strcmp(sp->Key,"DR"))) { - match = CTM_FILTER_DISABLE; - break; - } - - for (filter = FilterList; filter; filter = filter->Next) if (0 == regexec(&filter->CompiledRegex, name, - 0, 0, 0)) { - match = filter->Action; - } - - if (CTM_FILTER_DISABLE == match) - break; /* should ignore this file */ - - /* XXX Check DR DM rec's for parent-dir */ - if(j & CTM_Q_Name_New) { - /* XXX Check DR FR rec's for item */ - if(-1 != stat(name,&st)) { - fprintf(stderr," %s: %s exists.\n", - sp->Key,name); - ret |= Exit_Forcible; - } - break; - } - if(-1 == stat(name,&st)) { - fprintf(stderr," %s: %s doesn't exist.\n", - sp->Key,name); - if (sp->Key[1] == 'R') - ret |= Exit_Forcible; - else - ret |= Exit_NotOK; - break; - } - if (SetTime && getuid() && (getuid() != st.st_uid)) { - fprintf(stderr, - " %s: %s not mine, cannot set time.\n", - sp->Key,name); - ret |= Exit_NotOK; - } - if (j & CTM_Q_Name_Dir) { - if((st.st_mode & S_IFMT) != S_IFDIR) { - fprintf(stderr, - " %s: %s exist, but isn't dir.\n", - sp->Key,name); - ret |= Exit_NotOK; - } - break; - } - if (j & CTM_Q_Name_File) { - if((st.st_mode & S_IFMT) != S_IFREG) { - fprintf(stderr, - " %s: %s exist, but isn't file.\n", - sp->Key,name); - ret |= Exit_NotOK; - } - break; - } - break; - case CTM_F_Uid: - case CTM_F_Gid: - case CTM_F_Mode: - GETFIELD(p,sep); - break; - case CTM_F_MD5: - if(!name) WRONG - if(j & CTM_Q_MD5_Before) { - char *tmp; - GETFIELD(p,sep); - if(match && (st.st_mode & S_IFMT) == S_IFREG && - (tmp = MD5File(name,md5_1)) != NULL && - strcmp(tmp,p)) { - fprintf(stderr," %s: %s md5 mismatch.\n", - sp->Key,name); - GETFIELDCOPY(md5,sep); - if(md5 != NULL && strcmp(tmp,md5) == 0) { - fprintf(stderr," %s: %s already applied.\n", - sp->Key,name); - match = CTM_FILTER_DISABLE; - } else if(j & CTM_Q_MD5_Force) { - if(Force) - fprintf(stderr," Can and will force.\n"); - else - fprintf(stderr," Could have forced.\n"); - ret |= Exit_Forcible; - } else { - ret |= Exit_NotOK; - } - } - break; - } else if(j & CTM_Q_MD5_After) { - if(md5 == NULL) { - GETFIELDCOPY(md5,sep); - } - break; - } - /* Unqualified MD5 */ - WRONG - break; - case CTM_F_Count: - GETBYTECNT(cnt,sep); - break; - case CTM_F_Bytes: - if(cnt < 0) WRONG - GETDATA(trash,cnt); - if (!match) - break; - if (!template) { - if (asprintf(&template, "%s/CTMclientXXXXXX", - TmpDir) == -1) { - fprintf(stderr, " %s: malloc failed.\n", - sp->Key); - ret |= Exit_Mess; - return ret; - } - } - if(!strcmp(sp->Key,"FN")) { - if ((p = strdup(template)) == NULL) { - fprintf(stderr, " %s: malloc failed.\n", - sp->Key); - ret |= Exit_Mess; - return ret; - } - if ((fdesc = mkstemp(p)) == -1) { - fprintf(stderr, " %s: mkstemp failed.\n", - sp->Key); - ret |= Exit_Mess; - Free(p); - return ret; - } - if (close(fdesc) == -1) { - fprintf(stderr, " %s: close failed.\n", - sp->Key); - ret |= Exit_Mess; - unlink(p); - Free(p); - return ret; - } - j = ctm_edit(trash,cnt,name,p); - if(j) { - fprintf(stderr," %s: %s edit returned %d.\n", - sp->Key,name,j); - ret |= j; - unlink(p); - Free(p); - return ret; - } else if(strcmp(md5,MD5File(p,md5_1))) { - fprintf(stderr," %s: %s edit fails.\n", - sp->Key,name); - ret |= Exit_Mess; - unlink(p); - Free(p); - return ret; - } - unlink(p); - Free(p); - } else if (!strcmp(sp->Key,"FE")) { - if ((p = strdup(template)) == NULL) { - fprintf(stderr, " %s: malloc failed.\n", - sp->Key); - ret |= Exit_Mess; - return ret; - } - if ((fdesc = mkstemp(p)) == -1) { - fprintf(stderr, " %s: mkstemp failed.\n", - sp->Key); - ret |= Exit_Mess; - Free(p); - return ret; - } - if (close(fdesc) == -1) { - fprintf(stderr, " %s: close failed.\n", - sp->Key); - ret |= Exit_Mess; - unlink(p); - Free(p); - return ret; - } - ed = popen("ed","w"); - if (!ed) { - WRONG - } - fprintf(ed,"e %s\n", name); - if (cnt != fwrite(trash,1,cnt,ed)) { - warn("%s", name); - pclose(ed); - WRONG - } - fprintf(ed,"w %s\n",p); - if (pclose(ed)) { - warn("%s", p); - WRONG - } - if(strcmp(md5,MD5File(p,md5_1))) { - fprintf(stderr,"%s %s MD5 didn't come out right\n", - sp->Key, name); - WRONG - } - unlink(p); - Free(p); - } - - break; - default: WRONG - } - } - } - - Delete(trash); - Delete(name); - Delete(md5); - - q = MD5End (&ctx,md5_1); - GETFIELD(p,'\n'); /* */ - if(strcmp(q,p)) WRONG - if (-1 != getc(fd)) WRONG - return ret; -} diff --git a/usr.sbin/ctm/ctm/ctm_pass3.c b/usr.sbin/ctm/ctm/ctm_pass3.c deleted file mode 100644 index 34c6d87c1d..0000000 --- a/usr.sbin/ctm/ctm/ctm_pass3.c +++ /dev/null @@ -1,295 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include "ctm.h" -#define BADREAD 32 - -/*---------------------------------------------------------------------------*/ -/* Pass3 -- Validate the incoming CTM-file. - */ - -int -settime(const char *name, const struct timeval *times) -{ - if (SetTime) - if (utimes(name,times)) { - warn("utimes(): %s", name); - return -1; - } - return 0; -} - -int -Pass3(FILE *fd) -{ - u_char *p,*q,buf[BUFSIZ]; - MD5_CTX ctx; - int i,j,sep,cnt; - u_char *md5=0,*md5before=0,*trash=0,*name=0,*uid=0,*gid=0,*mode=0; - struct CTM_Syntax *sp; - FILE *ed=0; - struct stat st; - char md5_1[33]; - int match=0; - struct timeval times[2]; - struct CTM_Filter *filter = NULL; - if(Verbose>3) - printf("Pass3 -- Applying the CTM-patch\n"); - MD5Init (&ctx); - - GETFIELD(p,' '); if(strcmp("CTM_BEGIN",p)) WRONG - GETFIELD(p,' '); if(strcmp(Version,p)) WRONG - GETFIELD(p,' '); if(strcmp(Name,p)) WRONG - GETFIELD(p,' '); if(strcmp(Nbr,p)) WRONG - GETFIELD(p,' '); if(strcmp(TimeStamp,p)) WRONG - GETFIELD(p,'\n'); if(strcmp(Prefix,p)) WRONG - - /* - * This would be cleaner if mktime() worked in UTC rather than - * local time. - */ - if (SetTime) { - struct tm tm; - char *tz; - char buf[5]; - int i; - -#define SUBSTR(off,len) strncpy(buf, &TimeStamp[off], len), buf[len] = '\0' -#define WRONGDATE { fprintf(stderr, " %s failed date validation\n",\ - TimeStamp); WRONG} - - if (strlen(TimeStamp) != 15 || TimeStamp[14] != 'Z') WRONGDATE - for (i = 0; i < 14; i++) - if (!isdigit(TimeStamp[i])) WRONGDATE - - tz = getenv("TZ"); - if (setenv("TZ", "UTC", 1) < 0) WRONG - tzset(); - - tm.tm_isdst = tm.tm_gmtoff = 0; - - SUBSTR(0, 4); - tm.tm_year = atoi(buf) - 1900; - SUBSTR(4, 2); - tm.tm_mon = atoi(buf) - 1; - if (tm.tm_mon < 0 || tm.tm_mon > 11) WRONGDATE - SUBSTR(6, 2); - tm.tm_mday = atoi(buf); - if (tm.tm_mday < 1 || tm.tm_mday > 31) WRONG; - SUBSTR(8, 2); - tm.tm_hour = atoi(buf); - if (tm.tm_hour > 24) WRONGDATE - SUBSTR(10, 2); - tm.tm_min = atoi(buf); - if (tm.tm_min > 59) WRONGDATE - SUBSTR(12, 2); - tm.tm_sec = atoi(buf); - if (tm.tm_min > 62) WRONGDATE /* allow leap seconds */ - - times[0].tv_sec = times[1].tv_sec = mktime(&tm); - if (times[0].tv_sec == -1) WRONGDATE - times[0].tv_usec = times[1].tv_usec = 0; - - if (tz) { - if (setenv("TZ", tz, 1) < 0) WRONGDATE - } else { - unsetenv("TZ"); - } - } - - for(;;) { - Delete(md5); - Delete(uid); - Delete(gid); - Delete(mode); - Delete(md5before); - Delete(trash); - Delete(name); - cnt = -1; - - GETFIELD(p,' '); - - if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') WRONG - - if(!strcmp(p+3,"_END")) - break; - - for(sp=Syntax;sp->Key;sp++) - if(!strcmp(p+3,sp->Key)) - goto found; - WRONG - found: - for(i=0;(j = sp->List[i]);i++) { - if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes) - sep = ' '; - else - sep = '\n'; - - switch (j & CTM_F_MASK) { - case CTM_F_Name: GETNAMECOPY(name,sep,j, Verbose); break; - case CTM_F_Uid: GETFIELDCOPY(uid,sep); break; - case CTM_F_Gid: GETFIELDCOPY(gid,sep); break; - case CTM_F_Mode: GETFIELDCOPY(mode,sep); break; - case CTM_F_MD5: - if(j & CTM_Q_MD5_Before) - GETFIELDCOPY(md5before,sep); - else - GETFIELDCOPY(md5,sep); - break; - case CTM_F_Count: GETBYTECNT(cnt,sep); break; - case CTM_F_Bytes: GETDATA(trash,cnt); break; - default: WRONG - } - } - /* XXX This should go away. Disallow trailing '/' */ - j = strlen(name)-1; - if(name[j] == '/') name[j] = '\0'; - - /* - * If a filter list is specified, run thru the filter list and - * match `name' against filters. If the name matches, set the - * required action to that specified in the filter. - * The default action if no filterlist is given is to match - * everything. - */ - - match = (FilterList ? !(FilterList->Action) : CTM_FILTER_ENABLE); - for (filter = FilterList; filter; filter = filter->Next) { - if (0 == regexec(&filter->CompiledRegex, name, - 0, 0, 0)) { - match = filter->Action; - } - } - - if (CTM_FILTER_DISABLE == match) /* skip file if disabled */ - continue; - - if (Verbose > 0) - fprintf(stderr,"> %s %s\n",sp->Key,name); - if(!strcmp(sp->Key,"FM") || !strcmp(sp->Key, "FS")) { - i = open(name,O_WRONLY|O_CREAT|O_TRUNC,0666); - if(i < 0) { - warn("%s", name); - WRONG - } - if(cnt != write(i,trash,cnt)) { - warn("%s", name); - WRONG - } - close(i); - if(strcmp(md5,MD5File(name,md5_1))) { - fprintf(stderr," %s %s MD5 didn't come out right\n", - sp->Key,name); - WRONG - } - if (settime(name,times)) WRONG - continue; - } - if(!strcmp(sp->Key,"FE")) { - ed = popen("ed","w"); - if(!ed) { - WRONG - } - fprintf(ed,"e %s\n",name); - if(cnt != fwrite(trash,1,cnt,ed)) { - warn("%s", name); - pclose(ed); - WRONG - } - fprintf(ed,"w %s\n",name); - if(pclose(ed)) { - warn("ed"); - WRONG - } - if(strcmp(md5,MD5File(name,md5_1))) { - fprintf(stderr," %s %s MD5 didn't come out right\n", - sp->Key,name); - WRONG - } - if (settime(name,times)) WRONG - continue; - } - if(!strcmp(sp->Key,"FN")) { - strcpy(buf,name); - strcat(buf,TMPSUFF); - i = ctm_edit(trash,cnt,name,buf); - if(i) { - fprintf(stderr," %s %s Edit failed with code %d.\n", - sp->Key,name,i); - WRONG - } - if(strcmp(md5,MD5File(buf,md5_1))) { - fprintf(stderr," %s %s Edit failed MD5 check.\n", - sp->Key,name); - WRONG - } - if (rename(buf,name) == -1) - WRONG - if (settime(name,times)) WRONG - continue; - } - if(!strcmp(sp->Key,"DM")) { - if(0 > mkdir(name,0777)) { - sprintf(buf,"mkdir -p %s",name); - system(buf); - } - if(0 > stat(name,&st) || ((st.st_mode & S_IFMT) != S_IFDIR)) { - fprintf(stderr,"<%s> mkdir failed\n",name); - WRONG - } - if (settime(name,times)) WRONG - continue; - } - if(!strcmp(sp->Key,"FR")) { - if (KeepIt) { - if (Verbose > 1) - printf("<%s> not removed\n", name); - } - else if (0 != unlink(name)) { - fprintf(stderr,"<%s> unlink failed\n",name); - if (!Force) - WRONG - } - continue; - } - if(!strcmp(sp->Key,"DR")) { - /* - * We cannot use rmdir() because we do not get the directories - * in '-depth' order (cvs-cur.0018.gz for examples) - */ - if (KeepIt) { - if (Verbose > 1) { - printf("<%s> not removed\n", name); - } - } else { - sprintf(buf,"rm -rf %s",name); - system(buf); - } - continue; - } - WRONG - } - - Delete(md5); - Delete(uid); - Delete(gid); - Delete(mode); - Delete(md5before); - Delete(trash); - Delete(name); - - q = MD5End (&ctx,md5_1); - GETFIELD(p,'\n'); - if(strcmp(q,p)) WRONG - if (-1 != getc(fd)) WRONG - return 0; -} diff --git a/usr.sbin/ctm/ctm/ctm_passb.c b/usr.sbin/ctm/ctm/ctm_passb.c deleted file mode 100644 index ee3a69c5f..0000000 --- a/usr.sbin/ctm/ctm/ctm_passb.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Joseph Koshy - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include "ctm.h" -#define BADREAD 32 - -/*---------------------------------------------------------------------------*/ -/* PassB -- Backup modified files. - */ - -int -PassB(FILE *fd) -{ - u_char *p,*q; - MD5_CTX ctx; - int i,j,sep,cnt; - u_char *md5=0,*md5before=0,*trash=0,*name=0,*uid=0,*gid=0,*mode=0; - struct CTM_Syntax *sp; - FILE *b = 0; /* backup command */ - u_char buf[BUFSIZ]; - char md5_1[33]; - int ret = 0; - int match = 0; - struct CTM_Filter *filter = NULL; - - if(Verbose>3) - printf("PassB -- Backing up files which would be changed.\n"); - - MD5Init (&ctx); - snprintf(buf, sizeof(buf), fmtcheck(TarCmd, TARCMD), BackupFile); - b=popen(buf, "w"); - if(!b) { warn("%s", buf); return Exit_Garbage; } - - GETFIELD(p,' '); if(strcmp("CTM_BEGIN",p)) WRONG - GETFIELD(p,' '); if(strcmp(Version,p)) WRONG - GETFIELD(p,' '); if(strcmp(Name,p)) WRONG - GETFIELD(p,' '); if(strcmp(Nbr,p)) WRONG - GETFIELD(p,' '); if(strcmp(TimeStamp,p)) WRONG - GETFIELD(p,'\n'); if(strcmp(Prefix,p)) WRONG - - for(;;) { - Delete(md5); - Delete(uid); - Delete(gid); - Delete(mode); - Delete(md5before); - Delete(trash); - Delete(name); - cnt = -1; - - GETFIELD(p,' '); - - if (p[0] != 'C' || p[1] != 'T' || p[2] != 'M') WRONG - - if(!strcmp(p+3,"_END")) - break; - - for(sp=Syntax;sp->Key;sp++) - if(!strcmp(p+3,sp->Key)) - goto found; - WRONG - found: - for(i=0;(j = sp->List[i]);i++) { - if (sp->List[i+1] && (sp->List[i+1] & CTM_F_MASK) != CTM_F_Bytes) - sep = ' '; - else - sep = '\n'; - - switch (j & CTM_F_MASK) { - case CTM_F_Name: GETNAMECOPY(name,sep,j, Verbose); break; - case CTM_F_Uid: GETFIELDCOPY(uid,sep); break; - case CTM_F_Gid: GETFIELDCOPY(gid,sep); break; - case CTM_F_Mode: GETFIELDCOPY(mode,sep); break; - case CTM_F_MD5: - if(j & CTM_Q_MD5_Before) - GETFIELDCOPY(md5before,sep); - else - GETFIELDCOPY(md5,sep); - break; - case CTM_F_Count: GETBYTECNT(cnt,sep); break; - case CTM_F_Bytes: GETDATA(trash,cnt); break; - default: WRONG - } - } - /* XXX This should go away. Disallow trailing '/' */ - j = strlen(name)-1; - if(name[j] == '/') name[j] = '\0'; - - if (KeepIt && - (!strcmp(sp->Key,"DR") || !strcmp(sp->Key,"FR"))) - continue; - - /* match the name against the elements of the filter list. The - action associated with the last matched filter determines whether - this file should be ignored or backed up. */ - match = (FilterList ? !(FilterList->Action) : CTM_FILTER_ENABLE); - for (filter = FilterList; filter; filter = filter->Next) { - if (0 == regexec(&filter->CompiledRegex, name, 0, 0, 0)) - match = filter->Action; - } - - if (CTM_FILTER_DISABLE == match) - continue; - - if (!strcmp(sp->Key,"FS") || !strcmp(sp->Key,"FN") || - !strcmp(sp->Key,"AS") || !strcmp(sp->Key,"DR") || - !strcmp(sp->Key,"FR")) { - /* send name to the archiver for a backup */ - cnt = strlen(name); - if (cnt != fwrite(name,1,cnt,b) || EOF == fputc('\n',b)) { - warn("%s", name); - pclose(b); - WRONG; - } - } - } - - ret = pclose(b); - - Delete(md5); - Delete(uid); - Delete(gid); - Delete(mode); - Delete(md5before); - Delete(trash); - Delete(name); - - q = MD5End (&ctx,md5_1); - GETFIELD(p,'\n'); /* */ - if(strcmp(q,p)) WRONG - if (-1 != getc(fd)) WRONG - return ret; -} diff --git a/usr.sbin/ctm/ctm/ctm_syntax.c b/usr.sbin/ctm/ctm/ctm_syntax.c deleted file mode 100644 index 6638943..0000000 --- a/usr.sbin/ctm/ctm/ctm_syntax.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include "ctm.h" - -/* The fields... */ -#define Name CTM_F_Name -#define Uid CTM_F_Uid -#define Gid CTM_F_Gid -#define Mode CTM_F_Mode -#define MD5 CTM_F_MD5 -#define Count CTM_F_Count -#define Bytes CTM_F_Bytes - -/* The qualifiers... */ -#define File CTM_Q_Name_File -#define Dir CTM_Q_Name_Dir -#define New CTM_Q_Name_New -#define Subst CTM_Q_Name_Subst -#define After CTM_Q_MD5_After -#define Before CTM_Q_MD5_Before -#define Chunk CTM_Q_MD5_Chunk -#define Force CTM_Q_MD5_Force - -static int ctmFM[] = /* File Make */ - { Name|File|New|Subst, Uid, Gid, Mode, - MD5|After|Chunk, Count, Bytes,0 }; - -static int ctmFS[] = /* File Substitute */ - { Name|File|Subst, Uid, Gid, Mode, - MD5|Before|Force, MD5|After|Chunk, Count, Bytes,0 }; - -static int ctmFE[] = /* File Edit */ - { Name|File|Subst, Uid, Gid, Mode, - MD5|Before, MD5|After, Count, Bytes,0 }; - -static int ctmFR[] = /* File Remove */ - { Name|File|Subst, MD5|Before, 0 }; - -static int ctmAS[] = /* Attribute Substitute */ - { Name|Subst, Uid, Gid, Mode, 0 }; - -static int ctmDM[] = /* Directory Make */ - { Name|Dir|New , Uid, Gid, Mode, 0 }; - -static int ctmDR[] = /* Directory Remove */ - { Name|Dir, 0 }; - -struct CTM_Syntax Syntax[] = { - { "FM", ctmFM }, - { "FS", ctmFS }, - { "FE", ctmFE }, - { "FN", ctmFE }, - { "FR", ctmFR }, - { "AS", ctmAS }, - { "DM", ctmDM }, - { "DR", ctmDR }, - { 0, 0} }; diff --git a/usr.sbin/ctm/ctm_dequeue/Makefile b/usr.sbin/ctm/ctm_dequeue/Makefile deleted file mode 100644 index 18dd525..0000000 --- a/usr.sbin/ctm/ctm_dequeue/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../ctm_rmail - -PROG= ctm_dequeue -NO_MAN= -SRCS= ctm_dequeue.c error.c - -CFLAGS+= -I${.CURDIR}/../ctm_rmail - -WARNS?= 1 - -.include diff --git a/usr.sbin/ctm/ctm_dequeue/ctm_dequeue.c b/usr.sbin/ctm/ctm_dequeue/ctm_dequeue.c deleted file mode 100644 index 783fd3f..0000000 --- a/usr.sbin/ctm/ctm_dequeue/ctm_dequeue.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (c) 1996, Gary J. Palmer - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer, - * verbatim and that no modifications are made prior to this - * point in the file. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -/* - * ctm_dequeue: Dequeue queued delta pieces and mail them. - * - * The pieces have already been packaged up as mail messages by ctm_smail, - * and will be simply passed to sendmail in alphabetical order. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "error.h" -#include "options.h" - -#define DEFAULT_NUM 1 /* Default number of pieces mailed per run. */ - -int fts_sort(const FTSENT * const *, const FTSENT * const *); -int run_sendmail(int ifd); - -int -main(int argc, char **argv) -{ - char *log_file = NULL; - char *queue_dir = NULL; - char *list[2]; - int num_to_send = DEFAULT_NUM, chunk; - int fd; - FTS *fts; - FTSENT *ftsent; - int piece, npieces; - char filename[PATH_MAX]; - - err_prog_name(argv[0]); - - OPTIONS("[-l log] [-n num] queuedir") - NUMBER('n', num_to_send) - STRING('l', log_file) - ENDOPTS - - if (argc != 2) - usage(); - - if (log_file) - err_set_log(log_file); - - queue_dir = argv[1]; - list[0] = queue_dir; - list[1] = NULL; - - fts = fts_open(list, FTS_PHYSICAL|FTS_COMFOLLOW, fts_sort); - if (fts == NULL) - { - err("fts failed on `%s'", queue_dir); - exit(1); - } - - ftsent = fts_read(fts); - if (ftsent == NULL || ftsent->fts_info != FTS_D) - { - err("not a directory: %s", queue_dir); - exit(1); - } - - ftsent = fts_children(fts, 0); - if (ftsent == NULL && errno) - { - err("*ftschildren failed"); - exit(1); - } - - for (chunk = 1; ftsent != NULL; ftsent = ftsent->fts_link) - { - /* - * Skip non-files and ctm_smail tmp files (ones starting with `.') - */ - if (ftsent->fts_info != FTS_F || ftsent->fts_name[0] == '.') - continue; - - sprintf(filename, "%s/%s", queue_dir, ftsent->fts_name); - fd = open(filename, O_RDONLY); - if (fd < 0) - { - err("*open: %s", filename); - exit(1); - } - - if (run_sendmail(fd)) - exit(1); - - close(fd); - - if (unlink(filename) < 0) - { - err("*unlink: %s", filename); - exit(1); - } - - /* - * Deduce the delta, piece number, and number of pieces from - * the name of the file in the queue. Ideally, we should be - * able to get the mail alias name too. - * - * NOTE: This depends intimately on the queue name used in ctm_smail. - */ - npieces = atoi(&ftsent->fts_name[ftsent->fts_namelen-3]); - piece = atoi(&ftsent->fts_name[ftsent->fts_namelen-7]); - err("%.*s %d/%d sent", ftsent->fts_namelen-8, ftsent->fts_name, - piece, npieces); - - if (chunk++ == num_to_send) - break; - } - - fts_close(fts); - - return(0); -} - -int -fts_sort(const FTSENT * const * a, const FTSENT * const * b) -{ - if ((*a)->fts_info != FTS_F) - return(0); - if ((*a)->fts_info != FTS_F) - return(0); - - return (strcmp((*a)->fts_name, (*b)->fts_name)); -} - -/* - * Run sendmail with the given file descriptor as standard input. - * Sendmail will decode the destination from the message contents. - * Returns 0 on success, 1 on failure. - */ -int -run_sendmail(int ifd) -{ - pid_t child, pid; - int status; - - switch (child = fork()) - { - case -1: - err("*fork"); - return(1); - - case 0: /* Child */ - dup2(ifd, 0); - execl(_PATH_SENDMAIL, _PATH_SENDMAIL, "-odq", "-t", (char *)NULL); - err("*exec: %s", _PATH_SENDMAIL); - _exit(1); - - default: /* Parent */ - while ((pid = wait(&status)) != child) - { - if (pid == -1 && errno != EINTR) - { - err("*wait"); - return(1); - } - } - if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) - { - err("sendmail failed"); - return(1); - } - } - - return(0); -} diff --git a/usr.sbin/ctm/ctm_rmail/Makefile b/usr.sbin/ctm/ctm_rmail/Makefile deleted file mode 100644 index 1278ab4..0000000 --- a/usr.sbin/ctm/ctm_rmail/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $FreeBSD$ - -PROG= ctm_rmail -MLINKS= ctm_rmail.1 ctm_smail.1 \ - ctm_rmail.1 ctm_dequeue.1 -SRCS= ctm_rmail.c error.c - -WARNS?= 2 - -.include diff --git a/usr.sbin/ctm/ctm_rmail/ctm_rmail.1 b/usr.sbin/ctm/ctm_rmail/ctm_rmail.1 deleted file mode 100644 index 5476e49..0000000 --- a/usr.sbin/ctm/ctm_rmail/ctm_rmail.1 +++ /dev/null @@ -1,510 +0,0 @@ -.\" NOTICE: This is free documentation. I hope you get some use from these -.\" words. In return you should think about all the nice people who sweat -.\" blood to document their free software. Maybe you should write some -.\" documentation and give it away. Maybe with a free program attached! -.\" -.\" Author: Stephen McKay -.\" -.\" $FreeBSD$ -.\" -.Dd January 24, 1995 -.Dt CTM_MAIL 1 -.Os -.Sh NAME -.Nm ctm_smail , -.Nm ctm_dequeue , -.Nm ctm_rmail -.Nd send and receive -.Xr ctm 1 -deltas via mail -.Sh SYNOPSIS -.Nm ctm_smail -.Op Fl l Ar log -.Op Fl m Ar maxmsgsize -.Op Fl c Ar maxctmsize -.Op Fl q Ar queue-dir -.Ar ctm-delta -.Ar mail-alias -.Nm ctm_dequeue -.Op Fl l Ar log -.Op Fl n Ar numchunks -.Ar queue-dir -.Nm ctm_rmail -.Op Fl Dfuv -.Op Fl l Ar log -.Op Fl p Ar piecedir -.Op Fl d Ar deltadir -.Op Fl b Ar basedir -.Op Ar -.Sh DESCRIPTION -In conjunction with the -.Xr ctm 1 -command, -.Nm ctm_smail , -.Nm ctm_dequeue -and -.Nm ctm_rmail -are used to distribute changes to a source tree via email. -The -.Nm ctm_smail -utility is given a compressed -.Xr ctm -delta, and a mailing list to send it to. -It splits the delta into manageable -pieces, encodes them as mail messages and sends them to the mailing list -(optionally queued to spread the mail load). -Each recipient uses -.Nm ctm_rmail -(either manually or automatically) to decode and reassemble the delta, and -optionally call -.Xr ctm -to apply it to the source tree. -At the moment, -several source trees are distributed, and by several sites. -These include -the -.Fx Ns -current -source and CVS trees, distributed by -.Li freefall.FreeBSD.org . -.Pp -Command line arguments for -.Nm ctm_smail : -.Bl -tag -width indent -.It Fl l Ar log -Instead of appearing on -.Em stderr , -error diagnostics and informational messages (other than command line errors) -are time stamped and written to the file -.Em log . -.It Fl m Ar maxmsgsize -Limit the maximum size mail message that -.Nm ctm_smail -is allowed to send. -It is approximate since mail headers and other niceties -are not counted in this limit. -If not specified, it will default to 64000 -bytes, leaving room for 1535 bytes of headers before the rumoured 64k mail -limit. -.It Fl c Ar maxctmsize -Limit the maximum size delta that will be sent. -Deltas bigger that this -limit will cause an apology mail message to be sent to the mailing list. -This is to prevent massive changes overwhelming users' mail boxes. -Note that -this is the size before encoding. -Encoding causes a 4/3 size increase before -mail headers are added. -If not specified, there is no limit. -.It Fl q Ar queue-dir -Instead of mailing the delta pieces now, store them in the given directory -to be mailed later using -.Nm ctm_dequeue . -This feature allows the mailing of large deltas to be spread out over -hours or even days to limit the impact on recipients with limited network -bandwidth or small mail spool areas. -.El -.Pp -.Ar ctm-delta -is the delta to be sent, and -.Ar mail-alias -is the mailing list to send the delta to. -The mail messages are sent using -.Xr sendmail 8 . -.Pp -Command line arguments for -.Nm ctm_dequeue : -.Bl -tag -width indent -.It Fl l Ar log -Instead of appearing on -.Em stderr , -error diagnostics and informational messages (other than command line errors) -are time stamped and written to the file -.Em log . -.It Fl n Ar numchunks -Limit the number of mail messages that -.Nm ctm_dequeue -will send per run. -By default, -.Nm ctm_dequeue -will send one mail message per run. -.El -.Pp -.Ar queuedir -is the directory containing the mail messages stored by -.Nm ctm_smail . -Up to -.Ar numchunks -mail messages will be sent in each run. -The recipient mailing list is already -encoded in the queued files. -.Pp -It is safe to run -.Nm ctm_dequeue -while -.Nm ctm_smail -is adding entries to the queue, or even to run -.Nm ctm_smail -multiple times concurrently, but a separate queue directory should be used -for each tree being distributed. -This is because entries are served in -alphabetical order, and one tree will be unfairly serviced before any others, -based on the delta names, not delta creation times. -.Pp -Command line arguments for -.Nm ctm_rmail : -.Bl -tag -width indent -.It Fl l Ar log -Instead of appearing on -.Em stderr , -error diagnostics and informational messages (other than command line errors) -are time stamped and written to the file -.Em log . -.It Fl p Ar piecedir -Collect pieces of deltas in this directory. -Each piece corresponds to a -single mail message. -Pieces are removed when complete deltas are built. -If this flag is not given, no input files will be read, but completed -deltas may still be applied with -.Xr ctm -if the -.Fl b -flag is given. -.It Fl d Ar deltadir -Collect completed deltas in this directory. -Deltas are built from one or -more pieces when all pieces are present. -.It Fl b Ar basedir -Apply any completed deltas to this source tree. -If this flag is not given, -deltas will be stored, but not applied. -The user may then apply the deltas -manually, or by using -.Nm ctm_rmail -without the -.Fl p -flag. -Deltas will not be applied if they do not match the -.Li .ctm_status -file in -.Ar basedir -(or if -.Li .ctm_status -does not exist). -.It Fl D -Delete deltas after successful application by -.Xr ctm . -It is probably a good idea to avoid this flag (and keep all the deltas) as -.Xr ctm -has the ability to recover small groups of files from a full set of deltas. -.It Fl f -Fork and execute in the background while applying deltas with -.Xr ctm . -This is useful when automatically invoking -.Nm ctm_rmail -from -.Xr sendmail -because -.Xr ctm -can take a very long time to complete, causing other people's mail to -be delayed, and can in theory cause spurious -mail retransmission due to the remote -.Xr sendmail -timing out, or even termination of -.Nm ctm_rmail -by mail filters such as -.Xr "MH's" -.Xr slocal . -Do not worry about zillions of background -.Xr ctm -processes loading your machine, since locking is used to prevent more than one -.Xr ctm -invocation at a time. -.It Fl u -Pass the -.Fl u -flag to the -.Xr ctm -command when applying the complete deltas, causing it to set the modification -time of created and modified files to the CTM delta creation time. -.It Fl v -Pass the -.Fl v -flag to the -.Xr ctm -command when applying the complete deltas, causing a more informative -output. -All -.Xr ctm -output appears in the -.Nm ctm_rmail -log file. -.El -.Pp -The file arguments (or -.Em stdin , -if there are none) are scanned for delta pieces. -Multiple delta pieces -can be read from a single file, so an entire maildrop can be scanned -and processed with a single command. -.Pp -It is safe to invoke -.Nm ctm_rmail -multiple times concurrently (with different input files), -as might happen when -.Xr sendmail -is delivering mail asynchronously. -This is because locking is used to -keep things orderly. -.Sh FILE FORMAT -Following are the important parts of an actual (very small) delta piece: -.Bd -literal -From: owner-src-cur -To: src-cur -Subject: ctm-mail src-cur.0003.gz 1/4 - -CTM_MAIL BEGIN src-cur.0003.gz 1 4 -H4sIAAAAAAACA3VU72/bNhD9bP0VByQoEiyRSZEUSQP9kKTeYCR2gDTdsGFAwB/HRogtG5K8NCj6 -v4+UZSdtUQh6Rz0eee/xaF/dzx8up3/MFlDkBNrGnbttAwyo1pxoRgoiBNX/QJ5d3c9/X8DcPGGo -lggkPiXngE4W1gUjKPJCYyk5MZRbIqmNW/ASglIFcdwIzTUxaAqhnCPcBqloKEkJVNDMF0Azk+Bo -dDzzk0Ods/+A5gXv9YyJHjMCtJwQNeESNma7hOmXDRxn -CTM_MAIL END 61065 -.Ed -.Pp -The subject of the message always begins with -.Dq ctm-mail -followed by the name of the delta, which piece this is, and how many total -pieces there are. -The data are bracketed by -.Dq CTM_MAIL BEGIN -and -.Dq CTM_MAIL END -lines, duplicating the information in the subject line, plus a simple checksum. -.Pp -If the delta exceeds -.Ar maxctmsize , -then a message like this will be received instead: -.Bd -literal -From: owner-src-cur -To: src-cur -Subject: ctm-notice src-cur.0999.gz - -src-cur.0999.gz is 792843 bytes. The limit is 300000 bytes. - -You can retrieve this delta via ftp. -.Ed -.Pp -You are then on your own! -.Sh ENVIRONMENT -If deltas are to be applied then -.Xr ctm 1 -and -.Xr gunzip 1 -must be in your -.Ev PATH . -.Sh FILES -.Bl -tag -width indent -.It Pa QUEUEDIR/* -Pieces of deltas encoded as mail messages waiting to be sent to the -mailing list. -.It Pa PIECEDIR/* -Pieces of deltas waiting for the rest to arrive. -.It Pa DELTADIR/* -Completed deltas. -.It Pa BASEDIR/.ctm_status -File containing the name and number of the next delta to be applied to this -source tree. -.El -.Sh EXIT STATUS -The -.Nm ctm_smail , -.Nm ctm_dequeue -and -.Nm ctm_rmail -utilities return exit status 0 for success, and 1 for various failures. -The -.Nm ctm_rmail -utility is expected to be called from a mail transfer program, and thus signals -failure only when the input mail message should be bounced (preferably into -your regular maildrop, not back to the sender). -In short, failure to -apply a completed delta with -.Xr ctm -is not considered an error important enough to bounce the mail, and -.Nm ctm_rmail -returns an exit status of 0. -.Sh EXAMPLES -To send delta 32 of -.Em src-cur -to a group of wonderful code hackers known to -.Xr sendmail -as -.Em src-guys , -limiting the mail size to roughly 60000 bytes, you could use: -.Bd -literal -offset indent -ctm_smail -m 60000 /wherever/it/is/src-cur.0032.gz src-guys -.Ed -.Pp -To decode every -.Nm ctm-mail -message in your mailbox, assemble them into complete deltas, then apply -any deltas built or lying around, you could use: -.Bd -literal -offset indent -ctm_rmail -p ~/pieces -d ~/deltas -b /usr/ctm-src-cur $MAIL -.Ed -.Pp -(Note that no messages are deleted by -.Nm ctm_rmail . -Any mail reader could be used for that purpose.) -.Pp -To create a mail alias called -.Em receiver-dude -that will automatically decode and assemble deltas, but not apply them, -you could put the following lines in your -.Pa /etc/mail/aliases -file (assuming the -.Pa /ctm/tmp -and -.Pa /ctm/deltas -directories and -.Pa /ctm/log -file are writable by user -.Em daemon -or group -.Em wheel ) : -.Bd -literal -offset indent -receiver-dude: "|ctm_rmail -p /ctm/tmp -d /ctm/deltas -l /ctm/log" -owner-receiver-dude: real_dude@wherever.you.like -.Ed -.Pp -The second line will catch failures and drop them into your regular mailbox, -or wherever else you like. -.Pp -To apply all the deltas collected, and delete those applied, you could use: -.Bd -literal -offset indent -ctm_rmail -D -d /ctm/deltas -b /ctm/src-cur -l /ctm/apply.log -.Ed -.Pp -For maximum flexibility, consider this excerpt from a -.Xr procmail -script: -.Bd -literal -offset indent -PATH=$HOME/bin:$PATH - -:0 w -* ^Subject: ctm-mail cvs-cur -| ctm_incoming -.Ed -.Pp -together with the -shell script -.Pa ~/bin/ctm_incoming : -.Bd -literal -offset indent -#! /bin/sh -PATH="$HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" -export PATH - -cd $HOME/ctm && ctm_rmail -f -p pieces -d deltas -l log -b /ctm -.Ed -.Pp -which will deposit all -.Xr ctm -deltas in -.Pa ~/ctm/deltas , -apply them to the tree in -.Pa /ctm , -and drop any failures into your regular mail box. -Note the -.Ev PATH -manipulation in -.Pa ctm_incoming -which allows -.Nm ctm_rmail -to execute -.Xr ctm 1 -on the -.Pq non- Ns Fx -machine that this example was taken from. -.Sh SECURITY -On its own, CTM is an insecure protocol -- there is no authentication performed that the -changes applied to the source code were sent by a -trusted party, and so care should be taken if the -CTM deltas are obtained via an unauthenticated -medium such as regular email. -It is a relatively simple matter for an attacker -to forge a CTM delta to replace or precede the -legitimate one and insert malicious code into your -source tree. -If the legitimate delta is somehow prevented from -arriving, this will go unnoticed until a later -delta attempts to touch the same file, at which -point the MD5 checksum will fail. -.Pp -To remedy this insecurity, CTM delta pieces generated by -FreeBSD.org are cryptographically signed in a -format compatible with the GNU Privacy Guard -utility, available in /usr/ports/security/gpg, and -the Pretty Good Privacy v5 utility, -/usr/ports/security/pgp5. -The relevant public key can be obtained by -fingering ctm@FreeBSD.org. -.Pp -CTM deltas which are thus signed cannot be -undetectably altered by an attacker. -Therefore it is recommended that you make use of -GPG or PGP5 to verify the signatures if you -receive your CTM deltas via email. -.Sh DIAGNOSTICS -In normal operation, -.Nm ctm_smail -will report messages like: -.Bd -literal -offset indent -ctm_smail: src-cur.0250.gz 1/2 sent to src-guys -.Ed -.Pp -or, if queueing, -.Bd -literal -offset indent -ctm_smail: src-cur.0250.gz 1/2 queued for src-guys -.Ed -.Pp -The -.Nm ctm_dequeue -utility will report messages like: -.Bd -literal -offset indent -ctm_dequeue: src-cur.0250.gz 1/2 sent -.Ed -.Pp -The -.Nm ctm_rmail -utility will report messages like: -.Bd -literal -offset indent -ctm_rmail: src-cur.0250.gz 1/2 stored -ctm_rmail: src-cur.0250.gz 2/2 stored -ctm_rmail: src-cur.0250.gz complete -.Ed -.Pp -If any of the input files do not contain a valid delta piece, -.Nm ctm_rmail -will report: -.Bd -literal -offset indent -ctm_rmail: message contains no delta -.Ed -.Pp -and return an exit status of 1. -You can use this to redirect wayward messages -back into your real mailbox if your mail filter goes wonky. -.Pp -These messages go to -.Em stderr -or to the log file. -Messages from -.Xr ctm 1 -turn up here too. -Error messages should be self explanatory. -.Sh SEE ALSO -.Xr ctm 1 , -.Xr ctm 5 -.\" .Sh HISTORY -.Sh AUTHORS -.An Stephen McKay Aq mckay@FreeBSD.org diff --git a/usr.sbin/ctm/ctm_rmail/ctm_rmail.c b/usr.sbin/ctm/ctm_rmail/ctm_rmail.c deleted file mode 100644 index a46a58aa..0000000 --- a/usr.sbin/ctm/ctm_rmail/ctm_rmail.c +++ /dev/null @@ -1,672 +0,0 @@ -/* - * Accept one (or more) ASCII encoded chunks that together make a compressed - * CTM delta. Decode them and reconstruct the deltas. Any completed - * deltas may be passed to ctm for unpacking. - * - * Author: Stephen McKay - * - * NOTICE: This is free software. I hope you get some use from this program. - * In return you should think about all the nice people who give away software. - * Maybe you should write some free software too. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "error.h" -#include "options.h" - -#define CTM_STATUS ".ctm_status" - -char *piece_dir = NULL; /* Where to store pieces of deltas. */ -char *delta_dir = NULL; /* Where to store completed deltas. */ -char *base_dir = NULL; /* The tree to apply deltas to. */ -int delete_after = 0; /* Delete deltas after ctm applies them. */ -int apply_verbose = 0; /* Run with '-v' */ -int set_time = 0; /* Set the time of the files that is changed. */ -int mask = 0; /* The current umask */ - -void apply_complete(void); -int read_piece(char *input_file); -int combine_if_complete(char *delta, int pce, int npieces); -int combine(char *delta, int npieces, char *dname, char *pname, char *tname); -int decode_line(char *line, char *out_buf); -int lock_file(char *name); - -/* - * If given a '-p' flag, read encoded delta pieces from stdin or file - * arguments, decode them and assemble any completed deltas. If given - * a '-b' flag, pass any completed deltas to 'ctm' for application to - * the source tree. The '-d' flag is mandatory, but either of '-p' or - * '-b' can be omitted. If given the '-l' flag, notes and errors will - * be timestamped and written to the given file. - * - * Exit status is 0 for success or 1 for indigestible input. That is, - * 0 means the encode input pieces were decoded and stored, and 1 means - * some input was discarded. If a delta fails to apply, this won't be - * reflected in the exit status. In this case, the delta is left in - * 'deltadir'. - */ -int -main(int argc, char **argv) - { - char *log_file = NULL; - int status = 0; - int fork_ctm = 0; - - mask = umask(0); - umask(mask); - - err_prog_name(argv[0]); - - OPTIONS("[-Dfuv] [-p piecedir] [-d deltadir] [-b basedir] [-l log] [file ...]") - FLAG('D', delete_after) - FLAG('f', fork_ctm) - FLAG('u', set_time) - FLAG('v', apply_verbose) - STRING('p', piece_dir) - STRING('d', delta_dir) - STRING('b', base_dir) - STRING('l', log_file) - ENDOPTS - - if (delta_dir == NULL) - usage(); - - if (piece_dir == NULL && (base_dir == NULL || argc > 1)) - usage(); - - if (log_file != NULL) - err_set_log(log_file); - - /* - * Digest each file in turn, or just stdin if no files were given. - */ - if (argc <= 1) - { - if (piece_dir != NULL) - status = read_piece(NULL); - } - else - { - while (*++argv != NULL) - status |= read_piece(*argv); - } - - /* - * Maybe it's time to look for and apply completed deltas with ctm. - * - * Shall we report back to sendmail immediately, and let a child do - * the work? Sendmail will be waiting for us to complete, delaying - * other mail, and possibly some intermediate process (like MH slocal) - * will terminate us if we take too long! - * - * If fork() fails, it's unlikely we'll be able to run ctm, so give up. - * Also, the child exit status is unimportant. - */ - if (base_dir != NULL) - if (!fork_ctm || fork() == 0) - apply_complete(); - - return status; - } - - -/* - * Construct the file name of a piece of a delta. - */ -#define mk_piece_name(fn,d,p,n) \ - sprintf((fn), "%s/%s+%03d-%03d", piece_dir, (d), (p), (n)) - -/* - * Construct the file name of an assembled delta. - */ -#define mk_delta_name(fn,d) \ - sprintf((fn), "%s/%s", delta_dir, (d)) - -/* - * If the next required delta is now present, let ctm lunch on it and any - * contiguous deltas. - */ -void -apply_complete() - { - int i, dn; - int lfd; - FILE *fp, *ctm; - struct stat sb; - char class[20]; - char delta[30]; - char junk[2]; - char fname[PATH_MAX]; - char here[PATH_MAX]; - char buf[PATH_MAX*2]; - - /* - * Grab a lock on the ctm mutex file so that we can be sure we are - * working alone, not fighting another ctm_rmail! - */ - strcpy(fname, delta_dir); - strcat(fname, "/.mutex_apply"); - if ((lfd = lock_file(fname)) < 0) - return; - - /* - * Find out which delta ctm needs next. - */ - sprintf(fname, "%s/%s", base_dir, CTM_STATUS); - if ((fp = fopen(fname, "r")) == NULL) - { - close(lfd); - return; - } - - i = fscanf(fp, "%19s %d %c", class, &dn, junk); - fclose(fp); - if (i != 2) - { - close(lfd); - return; - } - - /* - * We might need to convert the delta filename to an absolute pathname. - */ - here[0] = '\0'; - if (delta_dir[0] != '/') - { - getcwd(here, sizeof(here)-1); - i = strlen(here) - 1; - if (i >= 0 && here[i] != '/') - { - here[++i] = '/'; - here[++i] = '\0'; - } - } - - /* - * Keep applying deltas until we run out or something bad happens. - */ - for (;;) - { - sprintf(delta, "%s.%04d.gz", class, ++dn); - mk_delta_name(fname, delta); - - if (stat(fname, &sb) < 0) - break; - - sprintf(buf, "(cd %s && ctm %s%s%s%s) 2>&1", base_dir, - set_time ? "-u " : "", - apply_verbose ? "-v " : "", here, fname); - if ((ctm = popen(buf, "r")) == NULL) - { - err("ctm failed to apply %s", delta); - break; - } - - while (fgets(buf, sizeof(buf), ctm) != NULL) - { - i = strlen(buf) - 1; - if (i >= 0 && buf[i] == '\n') - buf[i] = '\0'; - err("ctm: %s", buf); - } - - if (pclose(ctm) != 0) - { - err("ctm failed to apply %s", delta); - break; - } - - if (delete_after) - unlink(fname); - - err("%s applied%s", delta, delete_after ? " and deleted" : ""); - } - - /* - * Closing the lock file clears the lock. - */ - close(lfd); - } - - -/* - * This cheap plastic checksum effectively rotates our checksum-so-far - * left one, then adds the character. We only want 16 bits of it, and - * don't care what happens to the rest. It ain't much, but it's small. - */ -#define add_ck(sum,x) \ - ((sum) += ((x)&0xff) + (sum) + (((sum)&0x8000) ? 1 : 0)) - - -/* - * Decode the data between BEGIN and END, and stash it in the staging area. - * Multiple pieces can be present in a single file, bracketed by BEGIN/END. - * If we have all pieces of a delta, combine them. Returns 0 on success, - * and 1 for any sort of failure. - */ -int -read_piece(char *input_file) - { - int status = 0; - FILE *ifp, *ofp = 0; - int decoding = 0; - int got_one = 0; - int line_no = 0; - int i, n; - int pce, npieces; - unsigned claimed_cksum; - unsigned short cksum = 0; - char out_buf[200]; - char line[200]; - char delta[30]; - char pname[PATH_MAX]; - char tname[PATH_MAX]; - char junk[2]; - - ifp = stdin; - if (input_file != NULL && (ifp = fopen(input_file, "r")) == NULL) - { - err("cannot open '%s' for reading", input_file); - return 1; - } - - while (fgets(line, sizeof(line), ifp) != NULL) - { - line_no++; - - /* - * Remove all trailing white space. - */ - i = strlen(line) - 1; - while (i > 0 && isspace(line[i])) - line[i--] = '\0'; - - /* - * Look for the beginning of an encoded piece. - */ - if (!decoding) - { - char *s; - int fd = -1; - - if (sscanf(line, "CTM_MAIL BEGIN %29s %d %d %c", - delta, &pce, &npieces, junk) != 3) - continue; - - while ((s = strchr(delta, '/')) != NULL) - *s = '_'; - - got_one++; - strcpy(tname, piece_dir); - strcat(tname, "/p.XXXXXXXXXX"); - if ((fd = mkstemp(tname)) == -1 || - (ofp = fdopen(fd, "w")) == NULL) - { - if (fd != -1) { - err("cannot open '%s' for writing", tname); - close(fd); - } - else - err("*mkstemp: '%s'", tname); - status++; - continue; - } - - cksum = 0xffff; - decoding++; - continue; - } - - /* - * We are decoding. Stop if we see the end flag. - */ - if (sscanf(line, "CTM_MAIL END %d %c", &claimed_cksum, junk) == 1) - { - int e; - - decoding = 0; - - fflush(ofp); - e = ferror(ofp); - fclose(ofp); - - if (e) - err("error writing %s", tname); - - if (cksum != claimed_cksum) - err("checksum: read %d, calculated %d", claimed_cksum, cksum); - - if (e || cksum != claimed_cksum) - { - err("%s %d/%d discarded", delta, pce, npieces); - unlink(tname); - status++; - continue; - } - - mk_piece_name(pname, delta, pce, npieces); - if (rename(tname, pname) < 0) - { - err("*rename: '%s' to '%s'", tname, pname); - err("%s %d/%d lost!", delta, pce, npieces); - unlink(tname); - status++; - continue; - } - - err("%s %d/%d stored", delta, pce, npieces); - - if (!combine_if_complete(delta, pce, npieces)) - status++; - continue; - } - - /* - * Must be a line of encoded data. Decode it, sum it, and save it. - */ - n = decode_line(line, out_buf); - if (n <= 0) - { - err("line %d: illegal character: '%c'", line_no, line[-n]); - err("%s %d/%d discarded", delta, pce, npieces); - - fclose(ofp); - unlink(tname); - - status++; - decoding = 0; - continue; - } - - for (i = 0; i < n; i++) - add_ck(cksum, out_buf[i]); - - fwrite(out_buf, sizeof(char), n, ofp); - } - - if (decoding) - { - err("truncated file"); - err("%s %d/%d discarded", delta, pce, npieces); - - fclose(ofp); - unlink(tname); - - status++; - } - - if (ferror(ifp)) - { - err("error reading %s", input_file == NULL ? "stdin" : input_file); - status++; - } - - if (input_file != NULL) - fclose(ifp); - - if (!got_one) - { - err("message contains no delta"); - status++; - } - - return (status != 0); - } - - -/* - * Put the pieces together to form a delta, if they are all present. - * Returns 1 on success (even if we didn't do anything), and 0 on failure. - */ -int -combine_if_complete(char *delta, int pce, int npieces) - { - int i, e; - int lfd; - struct stat sb; - char pname[PATH_MAX]; - char dname[PATH_MAX]; - char tname[PATH_MAX]; - - /* - * We can probably just rename() it into place if it is a small delta. - */ - if (npieces == 1) - { - mk_delta_name(dname, delta); - mk_piece_name(pname, delta, 1, 1); - if (rename(pname, dname) == 0) - { - chmod(dname, 0666 & ~mask); - err("%s complete", delta); - return 1; - } - } - - /* - * Grab a lock on the reassembly mutex file so that we can be sure we are - * working alone, not fighting another ctm_rmail! - */ - strcpy(tname, delta_dir); - strcat(tname, "/.mutex_build"); - if ((lfd = lock_file(tname)) < 0) - return 0; - - /* - * Are all of the pieces present? Of course the current one is, - * unless all pieces are missing because another ctm_rmail has - * processed them already. - */ - for (i = 1; i <= npieces; i++) - { - if (i == pce) - continue; - mk_piece_name(pname, delta, i, npieces); - if (stat(pname, &sb) < 0) - { - close(lfd); - return 1; - } - } - - /* - * Stick them together. Let combine() use our file name buffers, since - * we're such good buddies. :-) - */ - e = combine(delta, npieces, dname, pname, tname); - close(lfd); - return e; - } - - -/* - * Put the pieces together to form a delta. - * Returns 1 on success, and 0 on failure. - * Note: dname, pname, and tname are room for some file names that just - * happened to by lying around in the calling routine. Waste not, want not! - */ -int -combine(char *delta, int npieces, char *dname, char *pname, char *tname) - { - FILE *dfp, *pfp; - int i, n, e; - char buf[BUFSIZ]; - int fd = -1; - - strcpy(tname, delta_dir); - strcat(tname, "/d.XXXXXXXXXX"); - if ((fd = mkstemp(tname)) == -1 || - (dfp = fdopen(fd, "w")) == NULL) - { - if (fd != -1) { - close(fd); - err("cannot open '%s' for writing", tname); - } - else - err("*mkstemp: '%s'", tname); - return 0; - } - - /* - * Reconstruct the delta by reading each piece in order. - */ - for (i = 1; i <= npieces; i++) - { - mk_piece_name(pname, delta, i, npieces); - if ((pfp = fopen(pname, "r")) == NULL) - { - err("cannot open '%s' for reading", pname); - fclose(dfp); - unlink(tname); - return 0; - } - while ((n = fread(buf, sizeof(char), sizeof(buf), pfp)) != 0) - fwrite(buf, sizeof(char), n, dfp); - e = ferror(pfp); - fclose(pfp); - if (e) - { - err("error reading '%s'", pname); - fclose(dfp); - unlink(tname); - return 0; - } - } - fflush(dfp); - e = ferror(dfp); - fclose(dfp); - if (e) - { - err("error writing '%s'", tname); - unlink(tname); - return 0; - } - - mk_delta_name(dname, delta); - if (rename(tname, dname) < 0) - { - err("*rename: '%s' to '%s'", tname, dname); - unlink(tname); - return 0; - } - chmod(dname, 0666 & ~mask); - - /* - * Throw the pieces away. - */ - for (i = 1; i <= npieces; i++) - { - mk_piece_name(pname, delta, i, npieces); - if (unlink(pname) < 0) - err("*unlink: '%s'", pname); - } - - err("%s complete", delta); - return 1; - } - - -/* - * MIME BASE64 decode table. - */ -static unsigned char from_b64[0x80] = - { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, - 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, - 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, - 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, - 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, - 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff - }; - - -/* - * Decode a line of ASCII into binary. Returns the number of bytes in - * the output buffer, or < 0 on indigestable input. Error output is - * the negative of the index of the inedible character. - */ -int -decode_line(char *line, char *out_buf) - { - unsigned char *ip = (unsigned char *)line; - unsigned char *op = (unsigned char *)out_buf; - unsigned long bits; - unsigned x; - - for (;;) - { - if (*ip >= 0x80 || (x = from_b64[*ip]) >= 0x40) - break; - bits = x << 18; - ip++; - if (*ip < 0x80 && (x = from_b64[*ip]) < 0x40) - { - bits |= x << 12; - *op++ = bits >> 16; - ip++; - if (*ip < 0x80 && (x = from_b64[*ip]) < 0x40) - { - bits |= x << 6; - *op++ = bits >> 8; - ip++; - if (*ip < 0x80 && (x = from_b64[*ip]) < 0x40) - { - bits |= x; - *op++ = bits; - ip++; - } - } - } - } - - if (*ip == '\0' || *ip == '\n') - return op - (unsigned char *)out_buf; - else - return -(ip - (unsigned char *)line); - } - - -/* - * Create and lock the given file. - * - * Clearing the lock is as simple as closing the file descriptor we return. - */ -int -lock_file(char *name) - { - int lfd; - - if ((lfd = open(name, O_WRONLY|O_CREAT, 0600)) < 0) - { - err("*open: '%s'", name); - return -1; - } - if (flock(lfd, LOCK_EX) < 0) - { - close(lfd); - err("*flock: '%s'", name); - return -1; - } - return lfd; - } diff --git a/usr.sbin/ctm/ctm_rmail/error.c b/usr.sbin/ctm/ctm_rmail/error.c deleted file mode 100644 index 56d3dc6..0000000 --- a/usr.sbin/ctm/ctm_rmail/error.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Routines for logging error messages or other informative messages. - * - * Log messages can easily contain the program name, a time stamp, system - * error messages, and arbitrary printf-style strings, and can be directed - * to stderr or a log file. - * - * Author: Stephen McKay - * - * NOTICE: This is free software. I hope you get some use from this program. - * In return you should think about all the nice people who give away software. - * Maybe you should write some free software too. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include "error.h" - -static FILE *error_fp = NULL; -static char *prog = NULL; - - -/* - * Log errors to the given file. - */ -void -err_set_log(char *log_file) - { - FILE *fp; - - if ((fp = fopen(log_file, "a")) == NULL) - err("cannot log to '%s'", log_file); - else - error_fp = fp; - } - - -/* - * Set the error prefix if not logging to a file. - */ -void -err_prog_name(char *name) - { - if ((prog = strrchr(name, '/')) == NULL) - prog = name; - else - prog++; - } - - -/* - * Log an error. - * - * A leading '*' in the message format means we want the system errno - * decoded and appended. - */ -void -err(const char *fmt, ...) - { - va_list ap; - time_t now; - struct tm *tm; - FILE *fp; - int x = errno; - int want_errno; - - if ((fp = error_fp) == NULL) - { - fp = stderr; - if (prog != NULL) - fprintf(fp, "%s: ", prog); - } - else - { - time(&now); - tm = localtime(&now); - fprintf(fp, "%04d-%02d-%02d %02d:%02d ", tm->tm_year+1900, - tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min); - } - - want_errno = 0; - if (*fmt == '*') - want_errno++, fmt++; - - va_start(ap, fmt); - vfprintf(fp, fmt, ap); - va_end(ap); - - if (want_errno) - fprintf(fp, ": %s", strerror(x)); - - fprintf(fp, "\n"); - fflush(fp); - } diff --git a/usr.sbin/ctm/ctm_rmail/error.h b/usr.sbin/ctm/ctm_rmail/error.h deleted file mode 100644 index c631b67..0000000 --- a/usr.sbin/ctm/ctm_rmail/error.h +++ /dev/null @@ -1,5 +0,0 @@ -/* $FreeBSD$ */ - -extern void err_set_log(char *log_file); -extern void err_prog_name(char *name); -extern void err(const char *fmt, ...) __printflike(1, 2); diff --git a/usr.sbin/ctm/ctm_rmail/options.h b/usr.sbin/ctm/ctm_rmail/options.h deleted file mode 100644 index 86c1247..0000000 --- a/usr.sbin/ctm/ctm_rmail/options.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Macros for processing command arguments. - * - * Conforms closely to the command option requirements of intro(1) in System V - * and intro(C) in Xenix. - * - * A command consists of: cmdname [ options ] [ cmdarguments ] - * - * Options consist of a leading dash '-' and a flag letter. An argument may - * follow optionally preceded by white space. - * Options without arguments may be grouped behind a single dash. - * A dash on its own is interpreted as the end of the options and is retained - * as a command argument. - * A double dash '--' is interpreted as the end of the options and is discarded. - * - * For example: - * zap -xz -f flame -q34 -- -x - * - * where zap.c contains the following in main(): - * - * OPTIONS("[-xz] [-q queue-id] [-f dump-file] user") - * FLAG('x', xecute) - * FLAG('z', zot) - * STRING('f', file) - * fp = fopen(file, "w"); - * NUMBER('q', queue) - * ENDOPTS - * - * Results in: - * xecute = 1 - * zot = 1 - * file = "flame" - * fp = fopen("flame", "w") - * queue = 34 - * argc = 2 - * argv[0] = "zap" - * argv[1] = "-x" - * - * Should the user enter unknown flags or leave out required arguments, - * the message: - * - * Usage: zap [-xz] [-q queue-id] [-f dump-file] user - * - * will be printed. This message can be printed by calling pusage(), or - * usage(). usage() will also cause program termination with exit code 1. - * - * Author: Stephen McKay, February 1991 - * - * Based on recollection of the original options.h produced at the University - * of Queensland by Ross Patterson (and possibly others). - * - * $FreeBSD$ - */ - -static char *O_usage; -static char *O_name; -extern long atol(); - -void -pusage() - { - /* - * Avoid gratuitously loading stdio. - */ - write(STDERR_FILENO, "usage: ", 7); - write(STDERR_FILENO, O_name, strlen(O_name)); - write(STDERR_FILENO, " ", 1); - write(STDERR_FILENO, O_usage, strlen(O_usage)); - write(STDERR_FILENO, "\n", 1); - } - -#define usage() (pusage(), exit(1)) - -#define OPTIONS(usage_msg) \ - { \ - char O_cont; \ - O_usage = (usage_msg); \ - O_name = argv[0]; \ - while (*++argv && **argv == '-') \ - { \ - if ((*argv)[1] == '\0') \ - break; \ - argc--; \ - if ((*argv)[1] == '-' && (*argv)[2] == '\0') \ - { \ - argv++; \ - break; \ - } \ - O_cont = 1; \ - while (O_cont) \ - switch (*++*argv) \ - { \ - default: \ - case '-': \ - usage(); \ - case '\0': \ - O_cont = 0; - -#define FLAG(x,flag) \ - break; \ - case (x): \ - (flag) = 1; - -#define CHAR(x,ch) \ - break; \ - case (x): \ - O_cont = 0; \ - if (*++*argv == '\0' && (--argc, *++argv == 0)) \ - usage(); \ - (ch) = **argv; - -#define NUMBER(x,n) \ - break; \ - case (x): \ - O_cont = 0; \ - if (*++*argv == '\0' && (--argc, *++argv == 0)) \ - usage(); \ - (n) = atol(*argv); - -#define STRING(x,str) \ - break; \ - case (x): \ - O_cont = 0; \ - if (*++*argv == '\0' && (--argc, *++argv == 0)) \ - usage(); \ - (str) = *argv; - -#define SUFFIX(x,str) \ - break; \ - case (x): \ - (str) = ++*argv; \ - O_cont = 0; - -#define ENDOPTS \ - break; \ - } \ - } \ - *--argv = O_name; \ - } diff --git a/usr.sbin/ctm/ctm_smail/Makefile b/usr.sbin/ctm/ctm_smail/Makefile deleted file mode 100644 index 15209e4..0000000 --- a/usr.sbin/ctm/ctm_smail/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../ctm_rmail - -PROG= ctm_smail -NO_MAN= -SRCS= ctm_smail.c error.c - -CFLAGS+= -I${.CURDIR}/../ctm_rmail - -WARNS?= 2 - -.include diff --git a/usr.sbin/ctm/ctm_smail/ctm_smail.c b/usr.sbin/ctm/ctm_smail/ctm_smail.c deleted file mode 100644 index c90fa2f..0000000 --- a/usr.sbin/ctm/ctm_smail/ctm_smail.c +++ /dev/null @@ -1,497 +0,0 @@ -/* - * Send a compressed CTM delta to a recipient mailing list by encoding it - * in safe ASCII characters, in mailer-friendly chunks, and passing them - * to sendmail. Optionally, the chunks can be queued to be sent later by - * ctm_dequeue in controlled bursts. The encoding is almost the same as - * MIME BASE64, and is protected by a simple checksum. - * - * Author: Stephen McKay - * - * NOTICE: This is free software. I hope you get some use from this program. - * In return you should think about all the nice people who give away software. - * Maybe you should write some free software too. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "error.h" -#include "options.h" - -#define DEF_MAX_MSG 64000 /* Default maximum mail msg minus headers. */ - -#define LINE_LENGTH 72 /* Chars per encoded line. Divisible by 4. */ - -int chop_and_send_or_queue(FILE *dfp, char *delta, off_t ctm_size, - long max_msg_size, char *mail_alias, char *queue_dir); -int chop_and_send(FILE *dfp, char *delta, long msg_size, int npieces, - char *mail_alias); -int chop_and_queue(FILE *dfp, char *delta, long msg_size, int npieces, - char *mail_alias, char *queue_dir); -void clean_up_queue(char *queue_dir); -int encode_body(FILE *sm_fp, FILE *delta_fp, long msg_size, unsigned *sum); -void write_header(FILE *sfp, char *mail_alias, char *delta, int pce, - int npieces); -void write_trailer(FILE *sfp, unsigned sum); -int apologise(char *delta, off_t ctm_size, long max_ctm_size, - char *mail_alias, char *queue_dir); -FILE *open_sendmail(void); -int close_sendmail(FILE *fp); - -int -main(int argc, char **argv) - { - int status = 0; - char *delta_file; - char *mail_alias; - long max_msg_size = DEF_MAX_MSG; - long max_ctm_size = 0; - char *log_file = NULL; - char *queue_dir = NULL; - char *delta; - FILE *dfp; - struct stat sb; - - err_prog_name(argv[0]); - - OPTIONS("[-l log] [-m maxmsgsize] [-c maxctmsize] [-q queuedir] ctm-delta mail-alias") - NUMBER('m', max_msg_size) - NUMBER('c', max_ctm_size) - STRING('l', log_file) - STRING('q', queue_dir) - ENDOPTS - - if (argc != 3) - usage(); - - if (log_file != NULL) - err_set_log(log_file); - - delta_file = argv[1]; - mail_alias = argv[2]; - - if ((delta = strrchr(delta_file, '/')) == NULL) - delta = delta_file; - else - delta++; - - if ((dfp = fopen(delta_file, "r")) == NULL || fstat(fileno(dfp), &sb) < 0) - { - err("*%s", delta_file); - exit(1); - } - - if (max_ctm_size != 0 && sb.st_size > max_ctm_size) - status = apologise(delta, sb.st_size, max_ctm_size, mail_alias, - queue_dir); - else - status = chop_and_send_or_queue(dfp, delta, sb.st_size, max_msg_size, - mail_alias, queue_dir); - - fclose(dfp); - - return status; - } - - -/* - * Carve our CTM delta into pieces, encode them, and send or queue them. - * Returns 0 on success, and 1 on failure. - */ -int -chop_and_send_or_queue(FILE *dfp, char *delta, off_t ctm_size, - long max_msg_size, char *mail_alias, char *queue_dir) - { - int npieces; - long msg_size; - long exp_size; - int status; - -#undef howmany -#define howmany(x,y) (((x)+((y)-1)) / (y)) - - /* - * Work out how many pieces we need, bearing in mind that each piece - * grows by 4/3 when encoded. We count the newlines too, but ignore - * all mail headers and piece headers. They are a "small" (almost - * constant) per message overhead that we make the user worry about. :-) - */ - exp_size = ctm_size * 4 / 3; - exp_size += howmany(exp_size, LINE_LENGTH); - npieces = howmany(exp_size, max_msg_size); - msg_size = howmany(ctm_size, npieces); - -#undef howmany - - if (queue_dir == NULL) - status = chop_and_send(dfp, delta, msg_size, npieces, mail_alias); - else - { - status = chop_and_queue(dfp, delta, msg_size, npieces, mail_alias, - queue_dir); - if (status) - clean_up_queue(queue_dir); - } - - return status; - } - - -/* - * Carve our CTM delta into pieces, encode them, and send them. - * Returns 0 on success, and 1 on failure. - */ -int -chop_and_send(FILE *dfp, char *delta, long msg_size, int npieces, - char *mail_alias) - { - int pce; - FILE *sfp; - unsigned sum; - - /* - * Send each chunk directly to sendmail as it is generated. - * No temporary files necessary. If things turn ugly, we just - * have to live with the fact the we have sent only part of - * the delta. - */ - for (pce = 1; pce <= npieces; pce++) - { - int read_error; - - if ((sfp = open_sendmail()) == NULL) - return 1; - - write_header(sfp, mail_alias, delta, pce, npieces); - read_error = encode_body(sfp, dfp, msg_size, &sum); - if (!read_error) - write_trailer(sfp, sum); - - if (!close_sendmail(sfp) || read_error) - return 1; - - err("%s %d/%d sent to %s", delta, pce, npieces, mail_alias); - } - - return 0; - } - - -/* - * Construct the tmp queue file name of a delta piece. - */ -#define mk_tmp_name(fn,qd,p) \ - sprintf((fn), "%s/.%08ld.%03d", (qd), (long)getpid(), (p)) - -/* - * Construct the final queue file name of a delta piece. - */ -#define mk_queue_name(fn,qd,d,p,n) \ - sprintf((fn), "%s/%s+%03d-%03d", (qd), (d), (p), (n)) - -/* - * Carve our CTM delta into pieces, encode them, and queue them. - * Returns 0 on success, and 1 on failure. - */ -int -chop_and_queue(FILE *dfp, char *delta, long msg_size, int npieces, - char *mail_alias, char *queue_dir) - { - int pce; - FILE *qfp; - unsigned sum; - char tname[PATH_MAX]; - char qname[PATH_MAX]; - - /* - * Store each piece in the queue directory, but under temporary names, - * so that they can be deleted without unpleasant consequences if - * anything goes wrong. We could easily fill up a disk, for example. - */ - for (pce = 1; pce <= npieces; pce++) - { - int write_error; - - mk_tmp_name(tname, queue_dir, pce); - if ((qfp = fopen(tname, "w")) == NULL) - { - err("cannot open '%s' for writing", tname); - return 1; - } - - write_header(qfp, mail_alias, delta, pce, npieces); - if (encode_body(qfp, dfp, msg_size, &sum)) - return 1; - write_trailer(qfp, sum); - - fflush(qfp); - write_error = ferror(qfp); - fclose(qfp); - if (write_error) - { - err("error writing '%s'", tname); - return 1; - } - - /* - * Give the warm success message now, instead of all in a rush - * during the rename phase. - */ - err("%s %d/%d queued for %s", delta, pce, npieces, mail_alias); - } - - /* - * Rename the pieces into place. If an error occurs now, we are - * stuffed, but there is no neat way to back out. rename() should - * only fail now under extreme circumstances. - */ - for (pce = 1; pce <= npieces; pce++) - { - mk_tmp_name(tname, queue_dir, pce); - mk_queue_name(qname, queue_dir, delta, pce, npieces); - if (rename(tname, qname) < 0) - { - err("*rename: '%s' to '%s'", tname, qname); - unlink(tname); - } - } - - return 0; - } - - -/* - * There may be temporary files cluttering up the queue directory. - */ -void -clean_up_queue(char *queue_dir) - { - int pce; - char tname[PATH_MAX]; - - err("discarding queued delta pieces"); - for (pce = 1; ; pce++) - { - mk_tmp_name(tname, queue_dir, pce); - if (unlink(tname) < 0) - break; - } - } - - -/* - * MIME BASE64 encode table. - */ -static char to_b64[0x40] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - -/* - * This cheap plastic checksum effectively rotates our checksum-so-far - * left one, then adds the character. We only want 16 bits of it, and - * don't care what happens to the rest. It ain't much, but it's small. - */ -#define add_ck(sum,x) \ - ((sum) += ((x)&0xff) + (sum) + (((sum)&0x8000) ? 1 : 0)) - -/* - * Encode the body. Use an encoding almost the same as MIME BASE64. - * - * Characters are read from delta_fp and encoded characters are written - * to sm_fp. At most 'msg_size' characters should be read from delta_fp. - * - * The body consists of lines of up to LINE_LENGTH characters. Each group - * of 4 characters encodes 3 input characters. Each output character encodes - * 6 bits. Thus 64 different characters are needed in this representation. - */ -int -encode_body(FILE *sm_fp, FILE *delta_fp, long msg_size, unsigned *sum) - { - unsigned short cksum = 0xffff; - unsigned char *ip; - char *op; - int want, n, i; - unsigned char inbuf[LINE_LENGTH*3/4]; - char outbuf[LINE_LENGTH+1]; - - /* - * Round up to the nearest line boundary, for the tiniest of gains, - * and lots of neatness. :-) - */ - msg_size += (LINE_LENGTH*3/4) - 1; - msg_size -= msg_size % (LINE_LENGTH*3/4); - - while (msg_size > 0) - { - want = (msg_size < sizeof(inbuf)) ? msg_size : sizeof(inbuf); - if ((n = fread(inbuf, sizeof(char), want, delta_fp)) == 0) - break; - msg_size -= n; - - for (i = 0; i < n; i++) - add_ck(cksum, inbuf[i]); - - /* - * Produce a line of encoded data. Every line length will be a - * multiple of 4, except for, perhaps, the last line. - */ - ip = inbuf; - op = outbuf; - while (n >= 3) - { - *op++ = to_b64[ip[0] >> 2]; - *op++ = to_b64[(ip[0] << 4 & 0x3f) | ip[1] >> 4]; - *op++ = to_b64[(ip[1] << 2 & 0x3f) | ip[2] >> 6]; - *op++ = to_b64[ip[2] & 0x3f]; - ip += 3; - n -= 3; - } - if (n > 0) - { - *op++ = to_b64[ip[0] >> 2]; - *op++ = to_b64[(ip[0] << 4 & 0x3f) | ip[1] >> 4]; - if (n >= 2) - *op++ = to_b64[ip[1] << 2 & 0x3f]; - } - *op++ = '\n'; - fwrite(outbuf, sizeof(char), op - outbuf, sm_fp); - } - - if (ferror(delta_fp)) - { - err("error reading input file."); - return 1; - } - - *sum = cksum; - - return 0; - } - - -/* - * Write the mail header and data header. - */ -void -write_header(FILE *sfp, char *mail_alias, char *delta, int pce, int npieces) - { - fprintf(sfp, "From: owner-%s\n", mail_alias); - fprintf(sfp, "To: %s\n", mail_alias); - fprintf(sfp, "Subject: ctm-mail %s %d/%d\n\n", delta, pce, npieces); - - fprintf(sfp, "CTM_MAIL BEGIN %s %d %d\n", delta, pce, npieces); - } - - -/* - * Write the data trailer. - */ -void -write_trailer(FILE *sfp, unsigned sum) - { - fprintf(sfp, "CTM_MAIL END %ld\n", (long)sum); - } - - -/* - * We're terribly sorry, but the delta is too big to send. - * Returns 0 on success, 1 on failure. - */ -int -apologise(char *delta, off_t ctm_size, long max_ctm_size, char *mail_alias, - char *queue_dir) - { - FILE *sfp; - char qname[PATH_MAX]; - - if (queue_dir == NULL) - { - sfp = open_sendmail(); - if (sfp == NULL) - return 1; - } - else - { - mk_queue_name(qname, queue_dir, delta, 1, 1); - sfp = fopen(qname, "w"); - if (sfp == NULL) - { - err("cannot open '%s' for writing", qname); - return 1; - } - } - - - fprintf(sfp, "From: owner-%s\n", mail_alias); - fprintf(sfp, "To: %s\n", mail_alias); - fprintf(sfp, "Subject: ctm-notice %s\n\n", delta); - - fprintf(sfp, "%s is %ld bytes. The limit is %ld bytes.\n\n", delta, - (long)ctm_size, max_ctm_size); - fprintf(sfp, "You can retrieve this delta via ftp.\n"); - - if (queue_dir == NULL) - { - if (!close_sendmail(sfp)) - return 1; - } - else - { - if (fclose(sfp)!=0) - { - err("error writing '%s'", qname); - unlink(qname); - return 1; - } - } - - return 0; - } - - -/* - * Start a pipe to sendmail. Sendmail will decode the destination - * from the message contents. - */ -FILE * -open_sendmail() - { - FILE *fp; - char buf[100]; - - sprintf(buf, "%s -odq -t", _PATH_SENDMAIL); - if ((fp = popen(buf, "w")) == NULL) - err("cannot start sendmail"); - return fp; - } - - -/* - * Close a pipe to sendmail. Sendmail will then do its bit. - * Return 1 on success, 0 on failure. - */ -int -close_sendmail(FILE *fp) - { - int status; - - fflush(fp); - if (ferror(fp)) - { - err("error writing to sendmail"); - return 0; - } - - if ((status = pclose(fp)) != 0) - err("sendmail failed with status %d", status); - - return (status == 0); - } diff --git a/usr.sbin/ctm/mkCTM/Makefile b/usr.sbin/ctm/mkCTM/Makefile deleted file mode 100644 index cefd704..0000000 --- a/usr.sbin/ctm/mkCTM/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# $FreeBSD$ - -PROG= mkctm -NO_MAN= - -DPADD= ${LIBMD} -LDADD= -lmd - -test: mkctm - rm -f tst.out* - time ./mkctm -v -v /3c/210src /a/r1/usr/src \ - 2>a | md5 -p > /a/tst.out - ls -l /a/tst.out - gzip -9 -v /a/tst.out - ls -l /a/tst.out.gz - # cd /usr/src/release && ctm -c -v -v ${.CURDIR}/tst.out - -test1: mkctm - rm -f tst.out* - time ./mkctm -v -v /3c/210src /home/ncvs/src \ - 2> b | md5 -p > /a/tst2.out - ls -l /a/tst2.out - gzip -9 -v /a/tst2.out - ls -l /a/tst2.out.gz - -.include diff --git a/usr.sbin/ctm/mkCTM/ctm_conf.cvs-cur b/usr.sbin/ctm/mkCTM/ctm_conf.cvs-cur deleted file mode 100644 index fbb5bf2..0000000 --- a/usr.sbin/ctm/mkCTM/ctm_conf.cvs-cur +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/local/bin/tclsh - -set CTMname cvs-cur -set CTMref /home/ncvs -set CTMignore {^src/secure|^src/eBones|^src/kerberosIV|^CVSROOT/val-tags$|CVSROOT/\\.#} -set CTMbogus {\\.core$|/#cvs|/\\.#} -set CTMmail ctm-cvs-cur-fast@freebsd.org -set CTMqueuemail ctm-cvs-cur@freebsd.org -set CTMqueue /home/ctm/queue/ctm-cvs-cur diff --git a/usr.sbin/ctm/mkCTM/ctm_conf.gnats b/usr.sbin/ctm/mkCTM/ctm_conf.gnats deleted file mode 100644 index c2223f0..0000000 --- a/usr.sbin/ctm/mkCTM/ctm_conf.gnats +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/local/bin/tclsh - -#set CTMfirst 1 -set CTMname gnats -set CTMref /home/gnats -set CTMdest $CTMSW/../CTM-pub/$CTMname -set CTMignore {\\.lock$} -set CTMmail ctm-gnats@freebsd.org diff --git a/usr.sbin/ctm/mkCTM/ctm_conf.ports-cur b/usr.sbin/ctm/mkCTM/ctm_conf.ports-cur deleted file mode 100644 index b9d3d13..0000000 --- a/usr.sbin/ctm/mkCTM/ctm_conf.ports-cur +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/local/bin/tclsh - -set CTMname ports-cur -set CTMref /usr/ports -set CTMignore {/CVS$|/CVS/|^distfiles} -set CTMbogus {\\.core$|/#cvs|/\\.#} -set CTMmail ctm-ports-cur@freebsd.org diff --git a/usr.sbin/ctm/mkCTM/ctm_conf.smp-cur b/usr.sbin/ctm/mkCTM/ctm_conf.smp-cur deleted file mode 100644 index 5c3e1d1..0000000 --- a/usr.sbin/ctm/mkCTM/ctm_conf.smp-cur +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/local/bin/tclsh - -set CTMname smp-cur -set CTMref /home/smp -set CTMignore {^CVSROOT/history.*$|^CVSROOT/val-tags$|^CVSROOT/\\.#} -set CTMbogus {\\.core$|/#cvs|/\\.#} -set CTMmail smp-cvs-cur@freebsd.org diff --git a/usr.sbin/ctm/mkCTM/ctm_conf.src-cur b/usr.sbin/ctm/mkCTM/ctm_conf.src-cur deleted file mode 100644 index 8589d04..0000000 --- a/usr.sbin/ctm/mkCTM/ctm_conf.src-cur +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/local/bin/tclsh - -set CTMname src-cur -set CTMref /c/src -set CTMignore {/CVS$|/CVS/|^/secure|^/eBones} -set CTMbogus {\\.core$|/#cvs|/\\.#} -set CTMmail ctm-src-cur-fast@freebsd.org -set CTMqueue /home/ctm/queue/ctm-src-cur -set CTMqueuemail ctm-src-cur@freebsd.org diff --git a/usr.sbin/ctm/mkCTM/ctm_conf.src-special b/usr.sbin/ctm/mkCTM/ctm_conf.src-special deleted file mode 100644 index 2a8ca70..0000000 --- a/usr.sbin/ctm/mkCTM/ctm_conf.src-special +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/local/bin/tclsh - -set CTMname src-cur -set CTMref $CTMSW/../$CTMname -set CTMcopy /c/phk/20R/usr/src -set CTMdont {\.core$|/CVS$|/CVS/|^/secure|^/eBones|/#cvs|/\.#} -set CTMtest 1 -set CTMspecial 1 -set CTMsuff R20 diff --git a/usr.sbin/ctm/mkCTM/dequeue b/usr.sbin/ctm/mkCTM/dequeue deleted file mode 100755 index 697ec0b..0000000 --- a/usr.sbin/ctm/mkCTM/dequeue +++ /dev/null @@ -1,6 +0,0 @@ -#! /bin/sh -# $FreeBSD$ - -L=/home/ctm/log.dequeue -/usr/sbin/ctm_dequeue -n 1 -l $L /home/ctm/queue/ctm-cvs-cur -/usr/sbin/ctm_dequeue -n 1 -l $L /home/ctm/queue/ctm-src-cur diff --git a/usr.sbin/ctm/mkCTM/mkCTM b/usr.sbin/ctm/mkCTM/mkCTM deleted file mode 100644 index 02b1544..0000000 --- a/usr.sbin/ctm/mkCTM/mkCTM +++ /dev/null @@ -1,188 +0,0 @@ -#!/usr/local/bin/tclsh7.4 -# -# $FreeBSD$ - -############################################################################# -### Do we already have this delta ? -############################################################################# - -proc find_delta {nbr} { - global CTMname CTMdest - if {[file exists [format "%s/$CTMname.%04d" $CTMdest $nbr]]} { return 1 } - if {[file exists [format "%s/$CTMname.%04d.gz" $CTMdest $nbr]]} { return 1 } - return 0 -} - -############################################################################# -### The top level code... -############################################################################# - -set CTMSW /home/ctm/SW - -cd $CTMSW - -# Defaults... -set CTMapply 1 -set CTMignore {^///} -set CTMbogus {\.core$} -set CTMmail {} -set CTMqueue {} -set CTMqueuemail {} -set CTMmaxctm 10000000 -set CTMmaxmsg 100000 -set CTMsuff {} -set CTMdate [exec date -u +%Y%m%d%H%M%SZ] -set CTMtmp {} -set CTMcopy {} -set CTMdest {} -set CTMprefix . -set CTMtest 0 -set CTMspecial 0 -set CTMscan . -set CTMfirst 0 -set max_damage 100 - -set damage 0 -set changes 0 - -source $argv -exec sh -c "date -u '+%Y%m%d%H%M%S $argv'" >> ${CTMSW}/log - -if {$CTMtmp == ""} { - set CTMtmp $CTMSW/../tmp/${CTMname}_${CTMsuff} -} -if {$CTMcopy == ""} { - set CTMcopy $CTMSW/../$CTMname -} -if {$CTMdest == ""} { - set CTMdest $CTMSW/../CTM-pub/$CTMname -} - -# Make sure we only run one at a time... - -set CTMlock Lck.${CTMname}.${CTMdate}.[pid] -exec rm -f ${CTMlock} -exec echo starting > ${CTMlock} -if {[catch "exec ln $CTMlock LCK.$CTMname" a]} { - puts "Not going, lock exists..." - exec rm -f $CTMlock - exit 1 -} -exec rm -f $CTMlock -set CTMlock LCK.$CTMname - -set CTMscratch ${CTMtmp}.tmp - -while 1 { - if { ! $CTMspecial} { - if {$CTMfirst} { - set CTMnbr 0 - } else { - set CTMnbr [lindex [exec cat $CTMcopy/.ctm_status] 1] - } - - if {$CTMnbr > 0 && ![find_delta $CTMnbr]} { - puts "$CTMname delta $CTMnbr doesn't exist..." - exec rm -f $CTMlock - exit 1 - } - - incr CTMnbr - - if {[find_delta $CTMnbr]} { - puts "$CTMname delta $CTMnbr does already exist..." - exec rm -f $CTMlock - exit 1 - } - - set fo [open $CTMref/.ctm_status w] - puts $fo "$CTMname $CTMnbr" - close $fo - incr changes -1 - - } else { - set CTMnbr [lindex [exec cat $CTMref/.ctm_status] 1] - } - - puts "Doing CTMname $CTMname CTMnbr $CTMnbr$CTMsuff CTMdate $CTMdate" - flush stdout - exec sh -c "rm -f ${CTMtmp}.* ${CTMtmp}:*" >&@ stdout - - set nm [format "%s.%04d%s" $CTMname $CTMnbr $CTMsuff] - - set x1 $CTMcopy - if {$x1 == ""} { - exec mkdir ${CTMtmp}.dir - set x1 ${CTMtmp}.dir - } - set r1 [catch "exec ${CTMSW}/mkctm -I ${CTMignore} -B ${CTMbogus} -l ${CTMtmp}.log -D $max_damage $CTMname $CTMnbr $CTMdate . $x1 $CTMref | md5 -p | gzip -9 > ${CTMtmp}:${nm}.gz 2>@ stderr" r2] - - if {$r1} { - if {[lindex $errorCode 2] == 4} { - puts "No changes, stopping." - exec rm -f $CTMlock - exit 0 - } - puts "problems, stopping now." - puts "errorCode $errorCode" - puts "$r2" - exec rm -f $CTMlock - exit 1 - } - - puts "mkctm done" - - if {$CTMtest} { - puts "testing, stopping now." - exec rm -f $CTMlock - exit 0 - } - if {$CTMapply} { - puts "Applying delta" - flush stdout - exec echo now applying > $CTMlock - exec sh -e -c "cd $CTMcopy ; $CTMSW/ctm -v -v -v ${CTMtmp}:${nm}.gz" >& ${CTMtmp}.apply - exec echo did apply > $CTMlock - } - puts "Moving delta" - flush stdout - exec mv ${CTMtmp}:${nm}.gz $CTMdest/.CTMtmp_${nm}.gz >&@ stdout - exec mv $CTMdest/.CTMtmp_${nm}.gz $CTMdest/${nm}.gz >&@ stdout - exec echo moved > $CTMlock - - exec sh -c "rm -rf ${CTMtmp}.*" >&@ stdout - - if {$CTMmail != ""} { - puts "Mailing delta" - flush stdout - exec $CTMSW/ctm_smail -m $CTMmaxmsg -c $CTMmaxctm $CTMdest/${nm}.gz $CTMmail >&@ stdout - if {$CTMqueue != "" && $CTMqueuemail != ""} { - puts "Queueing delta" - flush stdout - exec $CTMSW/ctm_smail -m $CTMmaxmsg -c $CTMmaxctm -q $CTMqueue $CTMdest/${nm}.gz $CTMqueuemail >&@ stdout - puts "Sending initial two deltas" - flush stdout - exec $CTMSW/ctm_dequeue -n 2 $CTMqueue >&@ stdout - } - } - exec echo mailed > $CTMlock - - # If we did an absolute delta: stop. - if {$CTMsuff != ""} break - - # Make an absolute delta (!) every 100 deltas - if {$CTMnbr == 0 || ($CTMnbr % 100)} break - - # Make an absolute delta too... - set CTMref $CTMcopy - set CTMsuff A - set CTMcopy "" - set CTMmail "" - set CTMqueue "" - set CTMqueuemail "" - set CTMapply 0 - set CTMspecial 1 - exec rm -f $CTMlock -} -puts "done." -exec rm -f $CTMlock diff --git a/usr.sbin/ctm/mkCTM/mkctm.c b/usr.sbin/ctm/mkCTM/mkctm.c deleted file mode 100644 index d2c73e2..0000000 --- a/usr.sbin/ctm/mkCTM/mkctm.c +++ /dev/null @@ -1,597 +0,0 @@ -/* $FreeBSD$ */ - -/* Still missing: - * - * mkctm - * -B regex Bogus - * -I regex Ignore - * -D int Damage - * -q decrease verbosity - * -v increase verbosity - * -l file logfile - * name cvs-cur - * prefix src/secure - * dir1 "Soll" - * dir2 "Ist" - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DEFAULT_IGNORE "/CVS$|/\\.#|00_TRANS\\.TBL$" -#define DEFAULT_BOGUS "\\.core$|\\.orig$|\\.rej$|\\.o$" -regex_t reg_ignore, reg_bogus; -int flag_ignore, flag_bogus; - -int verbose; -int damage, damage_limit; -int change; - -FILE *logf; - -u_long s1_ignored, s2_ignored; -u_long s1_bogus, s2_bogus; -u_long s1_wrong, s2_wrong; -u_long s_new_dirs, s_new_files, s_new_bytes; -u_long s_del_dirs, s_del_files, s_del_bytes; -u_long s_files_chg, s_bytes_add, s_bytes_del; -u_long s_same_dirs, s_same_files, s_same_bytes; -u_long s_edit_files, s_edit_bytes, s_edit_saves; -u_long s_sub_files, s_sub_bytes; - -void -Usage(void) -{ - fprintf(stderr, - "usage: mkctm [-options] name number timestamp prefix dir1 dir2\n"); - fprintf(stderr, "options:\n"); - fprintf(stderr, "\t\t-B bogus_regexp\n"); - fprintf(stderr, "\t\t-D damage_limit\n"); - fprintf(stderr, "\t\t-I ignore_regexp\n"); - fprintf(stderr, "\t\t-q\n"); - fprintf(stderr, "\t\t-v\n"); -} - -void -print_stat(FILE *fd, char *pre) -{ - fprintf(fd, "%sNames:\n", pre); - fprintf(fd, "%s ignore: %5lu ref %5lu target\n", - pre, s1_ignored, s2_ignored); - fprintf(fd, "%s bogus: %5lu ref %5lu target\n", - pre, s1_bogus, s2_bogus); - fprintf(fd, "%s wrong: %5lu ref %5lu target\n", - pre, s1_wrong, s2_wrong); - fprintf(fd, "%sDelta:\n", pre); - fprintf(fd, "%s new: %5lu dirs %5lu files %9lu plus\n", - pre, s_new_dirs, s_new_files, s_new_bytes); - fprintf(fd, "%s del: %5lu dirs %5lu files %9lu minus\n", - pre, s_del_dirs, s_del_files, s_del_bytes); - fprintf(fd, "%s chg: %5lu files %9lu plus %9lu minus\n", - pre, s_files_chg, s_bytes_add, s_bytes_del); - fprintf(fd, "%s same: %5lu dirs %5lu files %9lu bytes\n", - pre, s_same_dirs, s_same_files, s_same_bytes); - fprintf(fd, "%sMethod:\n", pre); - fprintf(fd, "%s edit: %5lu files %9lu bytes %9lu saved\n", - pre, s_edit_files, s_edit_bytes, s_edit_saves); - fprintf(fd, "%s sub: %5lu files %9lu bytes\n", - pre, s_sub_files, s_sub_bytes); - -} - -void -stat_info(int foo) -{ - signal(SIGINFO, stat_info); - print_stat(stderr, "INFO: "); -} - -void DoDir(const char *dir1, const char *dir2, const char *name); - -static struct stat st; -static __inline struct stat * -StatFile(char *name) -{ - if (lstat(name, &st) < 0) - err(1, "couldn't stat %s", name); - return &st; -} - -int -dirselect(struct dirent *de) -{ - if (!strcmp(de->d_name, ".")) return 0; - if (!strcmp(de->d_name, "..")) return 0; - return 1; -} - -void -name_stat(const char *pfx, const char *dir, const char *name, struct dirent *de) -{ - char *buf = alloca(strlen(dir) + strlen(name) + - strlen(de->d_name) + 3); - struct stat *st; - - strcpy(buf, dir); - strcat(buf, "/"); strcat(buf, name); - strcat(buf, "/"); strcat(buf, de->d_name); - st = StatFile(buf); - printf("%s %s%s %u %u %o", - pfx, name, de->d_name, - st->st_uid, st->st_gid, st->st_mode & ~S_IFMT); - fprintf(logf, "%s %s%s\n", pfx, name, de->d_name); - if (verbose > 1) { - fprintf(stderr, "%s %s%s\n", pfx, name, de->d_name); - } -} - -void -Equ(const char *dir1, const char *dir2, const char *name, struct dirent *de) -{ - if (de->d_type == DT_DIR) { - char *p = alloca(strlen(name)+strlen(de->d_name)+2); - - strcpy(p, name); strcat(p, de->d_name); strcat(p, "/"); - DoDir(dir1, dir2, p); - s_same_dirs++; - } else { - char *buf1 = alloca(strlen(dir1) + strlen(name) + - strlen(de->d_name) + 3); - char *buf2 = alloca(strlen(dir2) + strlen(name) + - strlen(de->d_name) + 3); - char *m1, md5_1[33], *m2, md5_2[33]; - u_char *p1, *p2; - int fd1, fd2; - struct stat s1, s2; - - strcpy(buf1, dir1); - strcat(buf1, "/"); strcat(buf1, name); - strcat(buf1, "/"); strcat(buf1, de->d_name); - fd1 = open(buf1, O_RDONLY); - if(fd1 < 0) { err(3, "%s", buf1); } - fstat(fd1, &s1); - strcpy(buf2, dir2); - strcat(buf2, "/"); strcat(buf2, name); - strcat(buf2, "/"); strcat(buf2, de->d_name); - fd2 = open(buf2, O_RDONLY); - if(fd2 < 0) { err(3, "%s", buf2); } - fstat(fd2, &s2); -#if 0 - /* XXX if we could just trust the size to change... */ - if (s1.st_size == s2.st_size) { - s_same_files++; - s_same_bytes += s1.st_size; - close(fd1); - close(fd2); - goto finish; - } -#endif - p1=mmap(0, s1.st_size, PROT_READ, MAP_PRIVATE, fd1, 0); - if (p1 == (u_char *)MAP_FAILED) { err(3, "%s", buf1); } - close(fd1); - - p2=mmap(0, s2.st_size, PROT_READ, MAP_PRIVATE, fd2, 0); - if (p2 == (u_char *)MAP_FAILED) { err(3, "%s", buf2); } - close(fd2); - - /* If identical, we're done. */ - if((s1.st_size == s2.st_size) && !memcmp(p1, p2, s1.st_size)) { - s_same_files++; - s_same_bytes += s1.st_size; - goto finish; - } - - s_files_chg++; - change++; - if (s1.st_size > s2.st_size) - s_bytes_del += (s1.st_size - s2.st_size); - else - s_bytes_add += (s2.st_size - s1.st_size); - - m1 = MD5Data(p1, s1.st_size, md5_1); - m2 = MD5Data(p2, s2.st_size, md5_2); - - /* Just a curiosity... */ - if(!strcmp(m1, m2)) { - if (s1.st_size != s2.st_size) - fprintf(stderr, - "Notice: MD5 same for files of diffent size:\n\t%s\n\t%s\n", - buf1, buf2); - goto finish; - } - - { - u_long l = s2.st_size + 2; - u_char *cmd = alloca(strlen(buf1)+strlen(buf2)+100); - u_char *ob = malloc(l), *p; - int j; - FILE *F; - - if (s1.st_size && p1[s1.st_size-1] != '\n') { - if (verbose > 0) - fprintf(stderr, - "last char != \\n in %s\n", - buf1); - goto subst; - } - - if (s2.st_size && p2[s2.st_size-1] != '\n') { - if (verbose > 0) - fprintf(stderr, - "last char != \\n in %s\n", - buf2); - goto subst; - } - - for (p=p1; p 0) - fprintf(stderr, - "NULL char in %s\n", - buf1); - goto subst; - } - - for (p=p2; p 0) - fprintf(stderr, - "NULL char in %s\n", - buf2); - goto subst; - } - - strcpy(cmd, "diff -n "); - strcat(cmd, buf1); - strcat(cmd, " "); - strcat(cmd, buf2); - F = popen(cmd, "r"); - for (j = 1, l = 0; l < s2.st_size; ) { - j = fread(ob+l, 1, s2.st_size - l, F); - if (j < 1) - break; - l += j; - continue; - } - if (j) { - l = 0; - while (EOF != fgetc(F)) - continue; - } - pclose(F); - - if (l && l < s2.st_size) { - name_stat("CTMFN", dir2, name, de); - printf(" %s %s %d\n", m1, m2, (unsigned)l); - fwrite(ob, 1, l, stdout); - putchar('\n'); - s_edit_files++; - s_edit_bytes += l; - s_edit_saves += (s2.st_size - l); - } else { - subst: - name_stat("CTMFS", dir2, name, de); - printf(" %s %s %u\n", m1, m2, (unsigned)s2.st_size); - fwrite(p2, 1, s2.st_size, stdout); - putchar('\n'); - s_sub_files++; - s_sub_bytes += s2.st_size; - } - free(ob); - } - finish: - munmap(p1, s1.st_size); - munmap(p2, s2.st_size); - } -} - -void -Add(const char *dir1, const char *dir2, const char *name, struct dirent *de) -{ - change++; - if (de->d_type == DT_DIR) { - char *p = alloca(strlen(name)+strlen(de->d_name)+2); - strcpy(p, name); strcat(p, de->d_name); strcat(p, "/"); - name_stat("CTMDM", dir2, name, de); - putchar('\n'); - s_new_dirs++; - DoDir(dir1, dir2, p); - } else if (de->d_type == DT_REG) { - char *buf2 = alloca(strlen(dir2) + strlen(name) + - strlen(de->d_name) + 3); - char *m2, md5_2[33]; - u_char *p1; - struct stat st; - int fd1; - - strcpy(buf2, dir2); - strcat(buf2, "/"); strcat(buf2, name); - strcat(buf2, "/"); strcat(buf2, de->d_name); - fd1 = open(buf2, O_RDONLY); - if (fd1 < 0) { err(3, "%s", buf2); } - fstat(fd1, &st); - p1=mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd1, 0); - if (p1 == (u_char *)MAP_FAILED) { err(3, "%s", buf2); } - close(fd1); - m2 = MD5Data(p1, st.st_size, md5_2); - name_stat("CTMFM", dir2, name, de); - printf(" %s %u\n", m2, (unsigned)st.st_size); - fwrite(p1, 1, st.st_size, stdout); - putchar('\n'); - munmap(p1, st.st_size); - s_new_files++; - s_new_bytes += st.st_size; - } -} - -void -Del (const char *dir1, const char *dir2, const char *name, struct dirent *de) -{ - damage++; - change++; - if (de->d_type == DT_DIR) { - char *p = alloca(strlen(name)+strlen(de->d_name)+2); - strcpy(p, name); strcat(p, de->d_name); strcat(p, "/"); - DoDir(dir1, dir2, p); - printf("CTMDR %s%s\n", name, de->d_name); - fprintf(logf, "CTMDR %s%s\n", name, de->d_name); - if (verbose > 1) { - fprintf(stderr, "CTMDR %s%s\n", name, de->d_name); - } - s_del_dirs++; - } else if (de->d_type == DT_REG) { - char *buf1 = alloca(strlen(dir1) + strlen(name) + - strlen(de->d_name) + 3); - char *m1, md5_1[33]; - strcpy(buf1, dir1); - strcat(buf1, "/"); strcat(buf1, name); - strcat(buf1, "/"); strcat(buf1, de->d_name); - m1 = MD5File(buf1, md5_1); - printf("CTMFR %s%s %s\n", name, de->d_name, m1); - fprintf(logf, "CTMFR %s%s %s\n", name, de->d_name, m1); - if (verbose > 1) { - fprintf(stderr, "CTMFR %s%s\n", name, de->d_name); - } - s_del_files++; - s_del_bytes += StatFile(buf1)->st_size; - } -} - -void -GetNext(int *i, int *n, struct dirent **nl, const char *dir, const char *name, u_long *ignored, u_long *bogus, u_long *wrong) -{ - char buf[BUFSIZ]; - char buf1[BUFSIZ]; - - for (;;) { - for (;;) { - (*i)++; - if (*i >= *n) - return; - strcpy(buf1, name); - if (buf1[strlen(buf1)-1] != '/') - strcat(buf1, "/"); - strcat(buf1, nl[*i]->d_name); - if (flag_ignore && - !regexec(®_ignore, buf1, 0, 0, 0)) { - (*ignored)++; - fprintf(logf, "Ignore %s\n", buf1); - if (verbose > 2) { - fprintf(stderr, "Ignore %s\n", buf1); - } - } else if (flag_bogus && - !regexec(®_bogus, buf1, 0, 0, 0)) { - (*bogus)++; - fprintf(logf, "Bogus %s\n", buf1); - fprintf(stderr, "Bogus %s\n", buf1); - damage++; - } else { - *buf = 0; - if (*dir != '/') - strcat(buf, "/"); - strcat(buf, dir); - if (buf[strlen(buf)-1] != '/') - strcat(buf, "/"); - strcat(buf, buf1); - break; - } - free(nl[*i]); nl[*i] = 0; - } - /* If the filesystem didn't tell us, find type */ - if (nl[*i]->d_type == DT_UNKNOWN) - nl[*i]->d_type = IFTODT(StatFile(buf)->st_mode); - if (nl[*i]->d_type == DT_REG || nl[*i]->d_type == DT_DIR) - break; - (*wrong)++; - if (verbose > 0) - fprintf(stderr, "Wrong %s\n", buf); - free(nl[*i]); nl[*i] = 0; - } -} - -void -DoDir(const char *dir1, const char *dir2, const char *name) -{ - int i1, i2, n1, n2, i; - struct dirent **nl1, **nl2; - char *buf1 = alloca(strlen(dir1) + strlen(name) + 4); - char *buf2 = alloca(strlen(dir2) + strlen(name) + 4); - - strcpy(buf1, dir1); strcat(buf1, "/"); strcat(buf1, name); - strcpy(buf2, dir2); strcat(buf2, "/"); strcat(buf2, name); - n1 = scandir(buf1, &nl1, dirselect, alphasort); - n2 = scandir(buf2, &nl2, dirselect, alphasort); - i1 = i2 = -1; - GetNext(&i1, &n1, nl1, dir1, name, &s1_ignored, &s1_bogus, &s1_wrong); - GetNext(&i2, &n2, nl2, dir2, name, &s2_ignored, &s2_bogus, &s2_wrong); - for (;i1 < n1 || i2 < n2;) { - - if (damage_limit && damage > damage_limit) - break; - - /* Get next item from list 1 */ - if (i1 < n1 && !nl1[i1]) - GetNext(&i1, &n1, nl1, dir1, name, - &s1_ignored, &s1_bogus, &s1_wrong); - - /* Get next item from list 2 */ - if (i2 < n2 && !nl2[i2]) - GetNext(&i2, &n2, nl2, dir2, name, - &s2_ignored, &s2_bogus, &s2_wrong); - - if (i1 >= n1 && i2 >= n2) { - /* Done */ - break; - } else if (i1 >= n1 && i2 < n2) { - /* end of list 1, add anything left on list 2 */ - Add(dir1, dir2, name, nl2[i2]); - free(nl2[i2]); nl2[i2] = 0; - } else if (i1 < n1 && i2 >= n2) { - /* end of list 2, delete anything left on list 1 */ - Del(dir1, dir2, name, nl1[i1]); - free(nl1[i1]); nl1[i1] = 0; - } else if (!(i = strcmp(nl1[i1]->d_name, nl2[i2]->d_name))) { - /* Identical names */ - if (nl1[i1]->d_type == nl2[i2]->d_type) { - /* same type */ - Equ(dir1, dir2, name, nl1[i1]); - } else { - /* different types */ - Del(dir1, dir2, name, nl1[i1]); - Add(dir1, dir2, name, nl2[i2]); - } - free(nl1[i1]); nl1[i1] = 0; - free(nl2[i2]); nl2[i2] = 0; - } else if (i < 0) { - /* Something extra in list 1, delete it */ - Del(dir1, dir2, name, nl1[i1]); - free(nl1[i1]); nl1[i1] = 0; - } else { - /* Something extra in list 2, add it */ - Add(dir1, dir2, name, nl2[i2]); - free(nl2[i2]); nl2[i2] = 0; - } - } - if (n1 >= 0) - free(nl1); - if (n2 >= 0) - free(nl2); -} - -int -main(int argc, char **argv) -{ - int i; - - setbuf(stderr, NULL); - -#if 0 - if (regcomp(®_bogus, DEFAULT_BOGUS, REG_EXTENDED | REG_NEWLINE)) - /* XXX use regerror to explain it */ - errx(1, "default regular expression argument to -B is botched"); - flag_bogus = 1; - - if (regcomp(®_ignore, DEFAULT_IGNORE, REG_EXTENDED | REG_NEWLINE)) - /* XXX use regerror to explain it */ - errx(1, "default regular expression argument to -I is botched"); - flag_ignore = 1; -#endif - - while ((i = getopt(argc, argv, "D:I:B:l:qv")) != -1) - switch (i) { - case 'D': - damage_limit = strtol(optarg, 0, 0); - if (damage_limit < 0) - errx(1, "damage limit must be positive"); - break; - case 'I': - if (flag_ignore) - regfree(®_ignore); - flag_ignore = 0; - if (!*optarg) - break; - if (regcomp(®_ignore, optarg, - REG_EXTENDED | REG_NEWLINE)) - /* XXX use regerror to explain it */ - errx(1, "regular expression argument to -I is botched"); - flag_ignore = 1; - break; - case 'B': - if (flag_bogus) - regfree(®_bogus); - flag_bogus = 0; - if (!*optarg) - break; - if (regcomp(®_bogus, optarg, - REG_EXTENDED | REG_NEWLINE)) - /* XXX use regerror to explain it */ - errx(1, "regular expression argument to -B is botched"); - flag_bogus = 1; - break; - case 'l': - logf = fopen(optarg, "w"); - if (!logf) - err(1, "%s", optarg); - setlinebuf(logf); - break; - case 'q': - verbose--; - break; - case 'v': - verbose++; - break; - case '?': - default: - Usage(); - return (1); - } - argc -= optind; - argv += optind; - - if (!logf) - logf = fopen(_PATH_DEVNULL, "w"); - - setbuf(stdout, 0); - - if (argc != 6) { - Usage(); - return (1); - } - - signal(SIGINFO, stat_info); - - fprintf(stderr, "CTM_BEGIN 2.0 %s %s %s %s\n", - argv[0], argv[1], argv[2], argv[3]); - fprintf(logf, "CTM_BEGIN 2.0 %s %s %s %s\n", - argv[0], argv[1], argv[2], argv[3]); - printf("CTM_BEGIN 2.0 %s %s %s %s\n", - argv[0], argv[1], argv[2], argv[3]); - DoDir(argv[4], argv[5], ""); - if (damage_limit && damage > damage_limit) { - print_stat(stderr, "DAMAGE: "); - errx(1, "damage of %d would exceed %d files", - damage, damage_limit); - } else if (change < 2) { - errx(4, "no changes"); - } else { - printf("CTM_END "); - fprintf(logf, "CTM_END\n"); - print_stat(stderr, "END: "); - } - exit(0); -} diff --git a/usr.sbin/cxgbtool/Makefile b/usr.sbin/cxgbtool/Makefile deleted file mode 100644 index f8e5175..0000000 --- a/usr.sbin/cxgbtool/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $FreeBSD$ - -PROG= cxgbtool -SRCS= cxgbtool.c -NO_MAN= -CFLAGS+= -I${.CURDIR}/../../sys/dev/cxgb -I. -CFLAGS+= -DCONFIG_T3_REGS -DCHELSIO_INTERNAL - -install: - -.include diff --git a/usr.sbin/cxgbtool/cxgbtool.c b/usr.sbin/cxgbtool/cxgbtool.c deleted file mode 100644 index b705ff8..0000000 --- a/usr.sbin/cxgbtool/cxgbtool.c +++ /dev/null @@ -1,1768 +0,0 @@ -/************************************************************************** - -Copyright (c) 2007-2010, Chelsio Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. Neither the name of the Chelsio Corporation nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - - -***************************************************************************/ -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#define NMTUS 16 -#define TCB_SIZE 128 -#define TCB_WORDS (TCB_SIZE / 4) -#define PROTO_SRAM_LINES 128 -#define PROTO_SRAM_LINE_BITS 132 -#define PROTO_SRAM_LINE_NIBBLES (132 / 4) -#define PROTO_SRAM_SIZE (PROTO_SRAM_LINE_NIBBLES * PROTO_SRAM_LINES / 2) -#define PROTO_SRAM_EEPROM_ADDR 4096 - -#include -#include -#include "version.h" - -struct reg_info { - const char *name; - uint16_t addr; - uint16_t len; -}; - - -#include "reg_defs.c" -#if defined(CONFIG_T3_REGS) -# include "reg_defs_t3.c" -# include "reg_defs_t3b.c" -# include "reg_defs_t3c.c" -#endif - -static const char *progname; - -static void -usage(FILE *fp) -{ - fprintf(fp, "Usage: %s [operation]\n", progname); - fprintf(fp, - "\tclearstats clear MAC statistics\n" - "\tcontext show an SGE context\n" - "\tdesc [] dump SGE descriptors\n" - "\tfilter [ ] ... set a filter\n" - "\tfilter delete|clear delete a filter\n" - "\tfilter list list all filters\n" - "\tioqs dump uP IOQs\n" - "\tla dump uP logic analyzer info\n" - "\tloadboot download boot image\n" - "\tloadfw download firmware\n" - "\tmdio \n" - "\t [] read/write MDIO register\n" - "\tmemdump cm|tx|rx dump a mem range\n" - "\tmeminfo show memory info\n" - "\tmtus [...] read/write MTU table\n" - "\tpktsched port set TX port scheduler params\n" - "\tpktsched tunnelq \n" - "\t set TX tunnelq scheduler params\n" - "\tpktsched tx \n" - "\t [ ] ... set Tx HW scheduler\n" - "\tpm [ ] read/write PM config\n" - "\tproto read proto SRAM\n" - "\tqset read qset parameters\n" - "\tqsets read # of qsets\n" - "\treg
[=] read/write register\n" - "\tregdump [] dump registers\n" - "\ttcamdump
show TCAM contents\n" - "\ttcb read TCB\n" - "\ttrace tx|rx|all on|off [not]\n" - "\t [ [:]] ... write trace parameters\n" - ); - exit(fp == stderr ? 1 : 0); -} - -static int -doit(const char *iff_name, unsigned long cmd, void *data) -{ - static int fd = 0; - - if (fd == 0) { - char buf[64]; - snprintf(buf, 64, "/dev/%s", iff_name); - - if ((fd = open(buf, O_RDWR)) < 0) - return -1; - } - - return ioctl(fd, cmd, data) < 0 ? -1 : 0; -} - -static int -get_int_arg(const char *s, uint32_t *valp) -{ - char *p; - - *valp = strtoul(s, &p, 0); - if (*p) { - warnx("bad parameter \"%s\"", s); - return -1; - } - return 0; -} - -static uint32_t -read_reg(const char *iff_name, uint32_t addr) -{ - struct ch_reg reg; - - reg.addr = addr; - - if (doit(iff_name, CHELSIO_GETREG, ®) < 0) - err(1, "register read"); - return reg.val; -} - -static void -write_reg(const char *iff_name, uint32_t addr, uint32_t val) -{ - struct ch_reg ch_reg; - - ch_reg.addr = addr; - ch_reg.val = val; - - if (doit(iff_name, CHELSIO_SETREG, &ch_reg) < 0) - err(1, "register write"); -} - -static int -register_io(int argc, char *argv[], int start_arg, - const char *iff_name) -{ - char *p; - uint32_t addr, val = 0, w = 0; - - if (argc != start_arg + 1) return -1; - - addr = strtoul(argv[start_arg], &p, 0); - if (p == argv[start_arg]) return -1; - if (*p == '=' && p[1]) { - val = strtoul(p + 1, &p, 0); - w = 1; - } - if (*p) { - warnx("bad parameter \"%s\"", argv[start_arg]); - return -1; - } - - if (w) - write_reg(iff_name, addr, val); - else { - val = read_reg(iff_name, addr); - printf("%#x [%u]\n", val, val); - } - return 0; -} - -static int -mdio_io(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_mii_data p; - unsigned int cmd, phy_addr, reg, mmd, val; - - if (argc == start_arg + 3) - cmd = CHELSIO_GET_MIIREG; - else if (argc == start_arg + 4) - cmd = CHELSIO_SET_MIIREG; - else - return -1; - - if (get_int_arg(argv[start_arg], &phy_addr) || - get_int_arg(argv[start_arg + 1], &mmd) || - get_int_arg(argv[start_arg + 2], ®) || - (cmd == CHELSIO_SET_MIIREG && get_int_arg(argv[start_arg + 3], &val))) - return -1; - - p.phy_id = phy_addr | (mmd << 8); - p.reg_num = reg; - p.val_in = val; - - if (doit(iff_name, cmd, &p) < 0) - err(1, "MDIO %s", cmd == CHELSIO_GET_MIIREG ? "read" : "write"); - if (cmd == CHELSIO_GET_MIIREG) - printf("%#x [%u]\n", p.val_out, p.val_out); - return 0; -} - -static inline -uint32_t xtract(uint32_t val, int shift, int len) -{ - return (val >> shift) & ((1 << len) - 1); -} - -static int -dump_block_regs(const struct reg_info *reg_array, uint32_t *regs) -{ - uint32_t reg_val = 0; // silence compiler warning - - for ( ; reg_array->name; ++reg_array) - if (!reg_array->len) { - reg_val = regs[reg_array->addr / 4]; - printf("[%#5x] %-40s %#-10x [%u]\n", reg_array->addr, - reg_array->name, reg_val, reg_val); - } else { - uint32_t v = xtract(reg_val, reg_array->addr, - reg_array->len); - - printf(" %-40s %#-10x [%u]\n", reg_array->name, - v, v); - } - return 1; -} - -static int -dump_regs_t2(int argc, char *argv[], int start_arg, uint32_t *regs) -{ - int match = 0; - char *block_name = NULL; - - if (argc == start_arg + 1) - block_name = argv[start_arg]; - else if (argc != start_arg) - return -1; - - if (!block_name || !strcmp(block_name, "sge")) - match += dump_block_regs(sge_regs, regs); - if (!block_name || !strcmp(block_name, "mc3")) - match += dump_block_regs(mc3_regs, regs); - if (!block_name || !strcmp(block_name, "mc4")) - match += dump_block_regs(mc4_regs, regs); - if (!block_name || !strcmp(block_name, "tpi")) - match += dump_block_regs(tpi_regs, regs); - if (!block_name || !strcmp(block_name, "tp")) - match += dump_block_regs(tp_regs, regs); - if (!block_name || !strcmp(block_name, "rat")) - match += dump_block_regs(rat_regs, regs); - if (!block_name || !strcmp(block_name, "cspi")) - match += dump_block_regs(cspi_regs, regs); - if (!block_name || !strcmp(block_name, "espi")) - match += dump_block_regs(espi_regs, regs); - if (!block_name || !strcmp(block_name, "ulp")) - match += dump_block_regs(ulp_regs, regs); - if (!block_name || !strcmp(block_name, "pl")) - match += dump_block_regs(pl_regs, regs); - if (!block_name || !strcmp(block_name, "mc5")) - match += dump_block_regs(mc5_regs, regs); - if (!match) - errx(1, "unknown block \"%s\"", block_name); - return 0; -} - -#if defined(CONFIG_T3_REGS) -static int -dump_regs_t3(int argc, char *argv[], int start_arg, uint32_t *regs, int is_pcie) -{ - int match = 0; - char *block_name = NULL; - - if (argc == start_arg + 1) - block_name = argv[start_arg]; - else if (argc != start_arg) - return -1; - - if (!block_name || !strcmp(block_name, "sge")) - match += dump_block_regs(sge3_regs, regs); - if (!block_name || !strcmp(block_name, "pci")) - match += dump_block_regs(is_pcie ? pcie0_regs : pcix1_regs, - regs); - if (!block_name || !strcmp(block_name, "t3dbg")) - match += dump_block_regs(t3dbg_regs, regs); - if (!block_name || !strcmp(block_name, "pmrx")) - match += dump_block_regs(mc7_pmrx_regs, regs); - if (!block_name || !strcmp(block_name, "pmtx")) - match += dump_block_regs(mc7_pmtx_regs, regs); - if (!block_name || !strcmp(block_name, "cm")) - match += dump_block_regs(mc7_cm_regs, regs); - if (!block_name || !strcmp(block_name, "cim")) - match += dump_block_regs(cim_regs, regs); - if (!block_name || !strcmp(block_name, "tp")) - match += dump_block_regs(tp1_regs, regs); - if (!block_name || !strcmp(block_name, "ulp_rx")) - match += dump_block_regs(ulp2_rx_regs, regs); - if (!block_name || !strcmp(block_name, "ulp_tx")) - match += dump_block_regs(ulp2_tx_regs, regs); - if (!block_name || !strcmp(block_name, "pmrx")) - match += dump_block_regs(pm1_rx_regs, regs); - if (!block_name || !strcmp(block_name, "pmtx")) - match += dump_block_regs(pm1_tx_regs, regs); - if (!block_name || !strcmp(block_name, "mps")) - match += dump_block_regs(mps0_regs, regs); - if (!block_name || !strcmp(block_name, "cplsw")) - match += dump_block_regs(cpl_switch_regs, regs); - if (!block_name || !strcmp(block_name, "smb")) - match += dump_block_regs(smb0_regs, regs); - if (!block_name || !strcmp(block_name, "i2c")) - match += dump_block_regs(i2cm0_regs, regs); - if (!block_name || !strcmp(block_name, "mi1")) - match += dump_block_regs(mi1_regs, regs); - if (!block_name || !strcmp(block_name, "sf")) - match += dump_block_regs(sf1_regs, regs); - if (!block_name || !strcmp(block_name, "pl")) - match += dump_block_regs(pl3_regs, regs); - if (!block_name || !strcmp(block_name, "mc5")) - match += dump_block_regs(mc5a_regs, regs); - if (!block_name || !strcmp(block_name, "xgmac0")) - match += dump_block_regs(xgmac0_0_regs, regs); - if (!block_name || !strcmp(block_name, "xgmac1")) - match += dump_block_regs(xgmac0_1_regs, regs); - if (!match) - errx(1, "unknown block \"%s\"", block_name); - return 0; -} - -static int -dump_regs_t3b(int argc, char *argv[], int start_arg, uint32_t *regs, - int is_pcie) -{ - int match = 0; - char *block_name = NULL; - - if (argc == start_arg + 1) - block_name = argv[start_arg]; - else if (argc != start_arg) - return -1; - - if (!block_name || !strcmp(block_name, "sge")) - match += dump_block_regs(t3b_sge3_regs, regs); - if (!block_name || !strcmp(block_name, "pci")) - match += dump_block_regs(is_pcie ? t3b_pcie0_regs : - t3b_pcix1_regs, regs); - if (!block_name || !strcmp(block_name, "t3dbg")) - match += dump_block_regs(t3b_t3dbg_regs, regs); - if (!block_name || !strcmp(block_name, "pmrx")) - match += dump_block_regs(t3b_mc7_pmrx_regs, regs); - if (!block_name || !strcmp(block_name, "pmtx")) - match += dump_block_regs(t3b_mc7_pmtx_regs, regs); - if (!block_name || !strcmp(block_name, "cm")) - match += dump_block_regs(t3b_mc7_cm_regs, regs); - if (!block_name || !strcmp(block_name, "cim")) - match += dump_block_regs(t3b_cim_regs, regs); - if (!block_name || !strcmp(block_name, "tp")) - match += dump_block_regs(t3b_tp1_regs, regs); - if (!block_name || !strcmp(block_name, "ulp_rx")) - match += dump_block_regs(t3b_ulp2_rx_regs, regs); - if (!block_name || !strcmp(block_name, "ulp_tx")) - match += dump_block_regs(t3b_ulp2_tx_regs, regs); - if (!block_name || !strcmp(block_name, "pmrx")) - match += dump_block_regs(t3b_pm1_rx_regs, regs); - if (!block_name || !strcmp(block_name, "pmtx")) - match += dump_block_regs(t3b_pm1_tx_regs, regs); - if (!block_name || !strcmp(block_name, "mps")) - match += dump_block_regs(t3b_mps0_regs, regs); - if (!block_name || !strcmp(block_name, "cplsw")) - match += dump_block_regs(t3b_cpl_switch_regs, regs); - if (!block_name || !strcmp(block_name, "smb")) - match += dump_block_regs(t3b_smb0_regs, regs); - if (!block_name || !strcmp(block_name, "i2c")) - match += dump_block_regs(t3b_i2cm0_regs, regs); - if (!block_name || !strcmp(block_name, "mi1")) - match += dump_block_regs(t3b_mi1_regs, regs); - if (!block_name || !strcmp(block_name, "sf")) - match += dump_block_regs(t3b_sf1_regs, regs); - if (!block_name || !strcmp(block_name, "pl")) - match += dump_block_regs(t3b_pl3_regs, regs); - if (!block_name || !strcmp(block_name, "mc5")) - match += dump_block_regs(t3b_mc5a_regs, regs); - if (!block_name || !strcmp(block_name, "xgmac0")) - match += dump_block_regs(t3b_xgmac0_0_regs, regs); - if (!block_name || !strcmp(block_name, "xgmac1")) - match += dump_block_regs(t3b_xgmac0_1_regs, regs); - if (!match) - errx(1, "unknown block \"%s\"", block_name); - return 0; -} - -static int -dump_regs_t3c(int argc, char *argv[], int start_arg, uint32_t *regs, - int is_pcie) -{ - int match = 0; - char *block_name = NULL; - - if (argc == start_arg + 1) - block_name = argv[start_arg]; - else if (argc != start_arg) - return -1; - - if (!block_name || !strcmp(block_name, "sge")) - match += dump_block_regs(t3c_sge3_regs, regs); - if (!block_name || !strcmp(block_name, "pci")) - match += dump_block_regs(is_pcie ? t3c_pcie0_regs : - t3c_pcix1_regs, regs); - if (!block_name || !strcmp(block_name, "t3dbg")) - match += dump_block_regs(t3c_t3dbg_regs, regs); - if (!block_name || !strcmp(block_name, "pmrx")) - match += dump_block_regs(t3c_mc7_pmrx_regs, regs); - if (!block_name || !strcmp(block_name, "pmtx")) - match += dump_block_regs(t3c_mc7_pmtx_regs, regs); - if (!block_name || !strcmp(block_name, "cm")) - match += dump_block_regs(t3c_mc7_cm_regs, regs); - if (!block_name || !strcmp(block_name, "cim")) - match += dump_block_regs(t3c_cim_regs, regs); - if (!block_name || !strcmp(block_name, "tp")) - match += dump_block_regs(t3c_tp1_regs, regs); - if (!block_name || !strcmp(block_name, "ulp_rx")) - match += dump_block_regs(t3c_ulp2_rx_regs, regs); - if (!block_name || !strcmp(block_name, "ulp_tx")) - match += dump_block_regs(t3c_ulp2_tx_regs, regs); - if (!block_name || !strcmp(block_name, "pmrx")) - match += dump_block_regs(t3c_pm1_rx_regs, regs); - if (!block_name || !strcmp(block_name, "pmtx")) - match += dump_block_regs(t3c_pm1_tx_regs, regs); - if (!block_name || !strcmp(block_name, "mps")) - match += dump_block_regs(t3c_mps0_regs, regs); - if (!block_name || !strcmp(block_name, "cplsw")) - match += dump_block_regs(t3c_cpl_switch_regs, regs); - if (!block_name || !strcmp(block_name, "smb")) - match += dump_block_regs(t3c_smb0_regs, regs); - if (!block_name || !strcmp(block_name, "i2c")) - match += dump_block_regs(t3c_i2cm0_regs, regs); - if (!block_name || !strcmp(block_name, "mi1")) - match += dump_block_regs(t3c_mi1_regs, regs); - if (!block_name || !strcmp(block_name, "sf")) - match += dump_block_regs(t3c_sf1_regs, regs); - if (!block_name || !strcmp(block_name, "pl")) - match += dump_block_regs(t3c_pl3_regs, regs); - if (!block_name || !strcmp(block_name, "mc5")) - match += dump_block_regs(t3c_mc5a_regs, regs); - if (!block_name || !strcmp(block_name, "xgmac0")) - match += dump_block_regs(t3c_xgmac0_0_regs, regs); - if (!block_name || !strcmp(block_name, "xgmac1")) - match += dump_block_regs(t3c_xgmac0_1_regs, regs); - if (!match) - errx(1, "unknown block \"%s\"", block_name); - return 0; -} -#endif - -static int -dump_regs(int argc, char *argv[], int start_arg, const char *iff_name) -{ - int vers, revision, is_pcie; - struct ch_ifconf_regs regs; - - regs.len = REGDUMP_SIZE; - - /* XXX: This is never freed. Looks like we don't care. */ - if ((regs.data = malloc(regs.len)) == NULL) - err(1, "can't malloc"); - - if (doit(iff_name, CHELSIO_IFCONF_GETREGS, ®s)) - err(1, "can't read registers"); - - vers = regs.version & 0x3ff; - revision = (regs.version >> 10) & 0x3f; - is_pcie = (regs.version & 0x80000000) != 0; - - if (vers <= 2) - return dump_regs_t2(argc, argv, start_arg, (uint32_t *)regs.data); -#if defined(CONFIG_T3_REGS) - if (vers == 3) { - if (revision == 0) - return dump_regs_t3(argc, argv, start_arg, - (uint32_t *)regs.data, is_pcie); - if (revision == 2 || revision == 3) - return dump_regs_t3b(argc, argv, start_arg, - (uint32_t *)regs.data, is_pcie); - if (revision == 4) - return dump_regs_t3c(argc, argv, start_arg, - (uint32_t *)regs.data, is_pcie); - } -#endif - errx(1, "unknown card type %d.%d", vers, revision); - return 0; -} - -static int -t3_meminfo(const uint32_t *regs) -{ - enum { - SG_EGR_CNTX_BADDR = 0x58, - SG_CQ_CONTEXT_BADDR = 0x6c, - CIM_SDRAM_BASE_ADDR = 0x28c, - CIM_SDRAM_ADDR_SIZE = 0x290, - TP_CMM_MM_BASE = 0x314, - TP_CMM_TIMER_BASE = 0x318, - TP_CMM_MM_RX_FLST_BASE = 0x460, - TP_CMM_MM_TX_FLST_BASE = 0x464, - TP_CMM_MM_PS_FLST_BASE = 0x468, - ULPRX_ISCSI_LLIMIT = 0x50c, - ULPRX_ISCSI_ULIMIT = 0x510, - ULPRX_TDDP_LLIMIT = 0x51c, - ULPRX_TDDP_ULIMIT = 0x520, - ULPRX_STAG_LLIMIT = 0x52c, - ULPRX_STAG_ULIMIT = 0x530, - ULPRX_RQ_LLIMIT = 0x534, - ULPRX_RQ_ULIMIT = 0x538, - ULPRX_PBL_LLIMIT = 0x53c, - ULPRX_PBL_ULIMIT = 0x540, - }; - - unsigned int egr_cntxt = regs[SG_EGR_CNTX_BADDR / 4], - cq_cntxt = regs[SG_CQ_CONTEXT_BADDR / 4], - timers = regs[TP_CMM_TIMER_BASE / 4] & 0xfffffff, - pstructs = regs[TP_CMM_MM_BASE / 4], - pstruct_fl = regs[TP_CMM_MM_PS_FLST_BASE / 4], - rx_fl = regs[TP_CMM_MM_RX_FLST_BASE / 4], - tx_fl = regs[TP_CMM_MM_TX_FLST_BASE / 4], - cim_base = regs[CIM_SDRAM_BASE_ADDR / 4], - cim_size = regs[CIM_SDRAM_ADDR_SIZE / 4]; - unsigned int iscsi_ll = regs[ULPRX_ISCSI_LLIMIT / 4], - iscsi_ul = regs[ULPRX_ISCSI_ULIMIT / 4], - tddp_ll = regs[ULPRX_TDDP_LLIMIT / 4], - tddp_ul = regs[ULPRX_TDDP_ULIMIT / 4], - stag_ll = regs[ULPRX_STAG_LLIMIT / 4], - stag_ul = regs[ULPRX_STAG_ULIMIT / 4], - rq_ll = regs[ULPRX_RQ_LLIMIT / 4], - rq_ul = regs[ULPRX_RQ_ULIMIT / 4], - pbl_ll = regs[ULPRX_PBL_LLIMIT / 4], - pbl_ul = regs[ULPRX_PBL_ULIMIT / 4]; - - printf("CM memory map:\n"); - printf(" TCB region: 0x%08x - 0x%08x [%u]\n", 0, egr_cntxt - 1, - egr_cntxt); - printf(" Egress contexts: 0x%08x - 0x%08x [%u]\n", egr_cntxt, - cq_cntxt - 1, cq_cntxt - egr_cntxt); - printf(" CQ contexts: 0x%08x - 0x%08x [%u]\n", cq_cntxt, - timers - 1, timers - cq_cntxt); - printf(" Timers: 0x%08x - 0x%08x [%u]\n", timers, - pstructs - 1, pstructs - timers); - printf(" Pstructs: 0x%08x - 0x%08x [%u]\n", pstructs, - pstruct_fl - 1, pstruct_fl - pstructs); - printf(" Pstruct FL: 0x%08x - 0x%08x [%u]\n", pstruct_fl, - rx_fl - 1, rx_fl - pstruct_fl); - printf(" Rx FL: 0x%08x - 0x%08x [%u]\n", rx_fl, tx_fl - 1, - tx_fl - rx_fl); - printf(" Tx FL: 0x%08x - 0x%08x [%u]\n", tx_fl, cim_base - 1, - cim_base - tx_fl); - printf(" uP RAM: 0x%08x - 0x%08x [%u]\n", cim_base, - cim_base + cim_size - 1, cim_size); - - printf("\nPMRX memory map:\n"); - printf(" iSCSI region: 0x%08x - 0x%08x [%u]\n", iscsi_ll, iscsi_ul, - iscsi_ul - iscsi_ll + 1); - printf(" TCP DDP region: 0x%08x - 0x%08x [%u]\n", tddp_ll, tddp_ul, - tddp_ul - tddp_ll + 1); - printf(" TPT region: 0x%08x - 0x%08x [%u]\n", stag_ll, stag_ul, - stag_ul - stag_ll + 1); - printf(" RQ region: 0x%08x - 0x%08x [%u]\n", rq_ll, rq_ul, - rq_ul - rq_ll + 1); - printf(" PBL region: 0x%08x - 0x%08x [%u]\n", pbl_ll, pbl_ul, - pbl_ul - pbl_ll + 1); - return 0; -} - -static int -meminfo(int argc, char *argv[], int start_arg, const char *iff_name) -{ - int vers; - struct ch_ifconf_regs regs; - - (void) argc; - (void) argv; - (void) start_arg; - - regs.len = REGDUMP_SIZE; - if ((regs.data = malloc(regs.len)) == NULL) - err(1, "can't malloc"); - - if (doit(iff_name, CHELSIO_IFCONF_GETREGS, ®s)) - err(1, "can't read registers"); - - vers = regs.version & 0x3ff; - if (vers == 3) - return t3_meminfo((uint32_t *)regs.data); - - errx(1, "unknown card type %d", vers); - return 0; -} - -static int -mtu_tab_op(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_mtus m; - unsigned int i; - - if (argc == start_arg) { - if (doit(iff_name, CHELSIO_GETMTUTAB, &m) < 0) - err(1, "get MTU table"); - for (i = 0; i < m.nmtus; ++i) - printf("%u ", m.mtus[i]); - printf("\n"); - } else if (argc <= start_arg + NMTUS) { - m.nmtus = argc - start_arg; - - for (i = 0; i < m.nmtus; ++i) { - char *p; - unsigned long mt = strtoul(argv[start_arg + i], &p, 0); - - if (*p || mt > 9600) { - warnx("bad parameter \"%s\"", - argv[start_arg + i]); - return -1; - } - if (i && mt < m.mtus[i - 1]) - errx(1, "MTUs must be in ascending order"); - m.mtus[i] = mt; - } - if (doit(iff_name, CHELSIO_SETMTUTAB, &m) < 0) - err(1, "set MTU table"); - } else - return -1; - - return 0; -} - -#ifdef CHELSIO_INTERNAL -static void -show_egress_cntxt(uint32_t data[]) -{ - printf("credits: %u\n", data[0] & 0x7fff); - printf("GTS: %u\n", (data[0] >> 15) & 1); - printf("index: %u\n", data[0] >> 16); - printf("queue size: %u\n", data[1] & 0xffff); - printf("base address: 0x%" PRIx64 "\n", - ((data[1] >> 16) | ((uint64_t)data[2] << 16) | - (((uint64_t)data[3] & 0xf) << 48)) << 12); - printf("rsp queue #: %u\n", (data[3] >> 4) & 7); - printf("cmd queue #: %u\n", (data[3] >> 7) & 1); - printf("TUN: %u\n", (data[3] >> 8) & 1); - printf("TOE: %u\n", (data[3] >> 9) & 1); - printf("generation: %u\n", (data[3] >> 10) & 1); - printf("uP token: %u\n", (data[3] >> 11) & 0xfffff); - printf("valid: %u\n", (data[3] >> 31) & 1); -} - -static void -show_fl_cntxt(uint32_t data[]) -{ - printf("base address: 0x%" PRIx64 "\n", - ((uint64_t)data[0] | ((uint64_t)data[1] & 0xfffff) << 32) << 12); - printf("index: %u\n", (data[1] >> 20) | ((data[2] & 0xf) << 12)); - printf("queue size: %u\n", (data[2] >> 4) & 0xffff); - printf("generation: %u\n", (data[2] >> 20) & 1); - printf("entry size: %u\n", - (data[2] >> 21) | (data[3] & 0x1fffff) << 11); - printf("congest thr: %u\n", (data[3] >> 21) & 0x3ff); - printf("GTS: %u\n", (data[3] >> 31) & 1); -} - -static void -show_response_cntxt(uint32_t data[]) -{ - printf("index: %u\n", data[0] & 0xffff); - printf("size: %u\n", data[0] >> 16); - printf("base address: 0x%" PRIx64 "\n", - ((uint64_t)data[1] | ((uint64_t)data[2] & 0xfffff) << 32) << 12); - printf("MSI-X/RspQ: %u\n", (data[2] >> 20) & 0x3f); - printf("intr enable: %u\n", (data[2] >> 26) & 1); - printf("intr armed: %u\n", (data[2] >> 27) & 1); - printf("generation: %u\n", (data[2] >> 28) & 1); - printf("CQ mode: %u\n", (data[2] >> 31) & 1); - printf("FL threshold: %u\n", data[3]); -} - -static void -show_cq_cntxt(uint32_t data[]) -{ - printf("index: %u\n", data[0] & 0xffff); - printf("size: %u\n", data[0] >> 16); - printf("base address: 0x%" PRIx64 "\n", - ((uint64_t)data[1] | ((uint64_t)data[2] & 0xfffff) << 32) << 12); - printf("rsp queue #: %u\n", (data[2] >> 20) & 0x3f); - printf("AN: %u\n", (data[2] >> 26) & 1); - printf("armed: %u\n", (data[2] >> 27) & 1); - printf("ANS: %u\n", (data[2] >> 28) & 1); - printf("generation: %u\n", (data[2] >> 29) & 1); - printf("overflow mode: %u\n", (data[2] >> 31) & 1); - printf("credits: %u\n", data[3] & 0xffff); - printf("credit threshold: %u\n", data[3] >> 16); -} - -static int -get_sge_context(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_cntxt ctx; - - if (argc != start_arg + 2) return -1; - - if (!strcmp(argv[start_arg], "egress")) - ctx.cntxt_type = CNTXT_TYPE_EGRESS; - else if (!strcmp(argv[start_arg], "fl")) - ctx.cntxt_type = CNTXT_TYPE_FL; - else if (!strcmp(argv[start_arg], "response")) - ctx.cntxt_type = CNTXT_TYPE_RSP; - else if (!strcmp(argv[start_arg], "cq")) - ctx.cntxt_type = CNTXT_TYPE_CQ; - else { - warnx("unknown context type \"%s\"; known types are egress, " - "fl, cq, and response", argv[start_arg]); - return -1; - } - - if (get_int_arg(argv[start_arg + 1], &ctx.cntxt_id)) - return -1; - - if (doit(iff_name, CHELSIO_GET_SGE_CONTEXT, &ctx) < 0) - err(1, "get SGE context"); - - if (!strcmp(argv[start_arg], "egress")) - show_egress_cntxt(ctx.data); - else if (!strcmp(argv[start_arg], "fl")) - show_fl_cntxt(ctx.data); - else if (!strcmp(argv[start_arg], "response")) - show_response_cntxt(ctx.data); - else if (!strcmp(argv[start_arg], "cq")) - show_cq_cntxt(ctx.data); - return 0; -} - -#define ntohll(x) be64toh((x)) - -static int -get_sge_desc(int argc, char *argv[], int start_arg, const char *iff_name) -{ - uint64_t *p, wr_hdr; - unsigned int n = 1, qset, qnum; - struct ch_desc desc; - - if (argc != start_arg + 3 && argc != start_arg + 4) - return -1; - - if (get_int_arg(argv[start_arg], &qset) || - get_int_arg(argv[start_arg + 1], &qnum) || - get_int_arg(argv[start_arg + 2], &desc.idx)) - return -1; - - if (argc == start_arg + 4 && get_int_arg(argv[start_arg + 3], &n)) - return -1; - - if (qnum > 5) - errx(1, "invalid queue number %d, range is 0..5", qnum); - - desc.queue_num = qset * 6 + qnum; - - for (; n--; desc.idx++) { - if (doit(iff_name, CHELSIO_GET_SGE_DESC, &desc) < 0) - err(1, "get SGE descriptor"); - - p = (uint64_t *)desc.data; - wr_hdr = ntohll(*p); - printf("Descriptor %u: cmd %u, TID %u, %s%s%s%s%u flits\n", - desc.idx, (unsigned int)(wr_hdr >> 56), - ((unsigned int)wr_hdr >> 8) & 0xfffff, - ((wr_hdr >> 55) & 1) ? "SOP, " : "", - ((wr_hdr >> 54) & 1) ? "EOP, " : "", - ((wr_hdr >> 53) & 1) ? "COMPL, " : "", - ((wr_hdr >> 52) & 1) ? "SGL, " : "", - (unsigned int)wr_hdr & 0xff); - - for (; desc.size; p++, desc.size -= sizeof(uint64_t)) - printf("%016" PRIx64 "%c", ntohll(*p), - desc.size % 32 == 8 ? '\n' : ' '); - } - return 0; -} -#endif - -static int -get_tcb2(int argc, char *argv[], int start_arg, const char *iff_name) -{ - uint64_t *d; - unsigned int i; - unsigned int tcb_idx; - struct ch_mem_range mr; - - if (argc != start_arg + 1) - return -1; - - if (get_int_arg(argv[start_arg], &tcb_idx)) - return -1; - - mr.buf = calloc(1, TCB_SIZE); - if (!mr.buf) - err(1, "get TCB"); - - mr.mem_id = MEM_CM; - mr.addr = tcb_idx * TCB_SIZE; - mr.len = TCB_SIZE; - - if (doit(iff_name, CHELSIO_GET_MEM, &mr) < 0) - err(1, "get TCB"); - - for (d = (uint64_t *)mr.buf, i = 0; i < TCB_SIZE / 32; i++) { - printf("%2u:", i); - printf(" %08x %08x %08x %08x", (uint32_t)d[1], - (uint32_t)(d[1] >> 32), (uint32_t)d[0], - (uint32_t)(d[0] >> 32)); - d += 2; - printf(" %08x %08x %08x %08x\n", (uint32_t)d[1], - (uint32_t)(d[1] >> 32), (uint32_t)d[0], - (uint32_t)(d[0] >> 32)); - d += 2; - } - free(mr.buf); - return 0; -} - -static int -get_pm_page_spec(const char *s, unsigned int *page_size, - unsigned int *num_pages) -{ - char *p; - unsigned long val; - - val = strtoul(s, &p, 0); - if (p == s) return -1; - if (*p == 'x' && p[1]) { - *num_pages = val; - *page_size = strtoul(p + 1, &p, 0); - } else { - *num_pages = -1; - *page_size = val; - } - *page_size <<= 10; // KB -> bytes - return *p; -} - -static int -conf_pm(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_pm pm; - - if (argc == start_arg) { - if (doit(iff_name, CHELSIO_GET_PM, &pm) < 0) - err(1, "read pm config"); - printf("%ux%uKB TX pages, %ux%uKB RX pages, %uKB total memory\n", - pm.tx_num_pg, pm.tx_pg_sz >> 10, pm.rx_num_pg, - pm.rx_pg_sz >> 10, pm.pm_total >> 10); - return 0; - } - - if (argc != start_arg + 2) return -1; - - if (get_pm_page_spec(argv[start_arg], &pm.tx_pg_sz, &pm.tx_num_pg)) { - warnx("bad parameter \"%s\"", argv[start_arg]); - return -1; - } - if (get_pm_page_spec(argv[start_arg + 1], &pm.rx_pg_sz, - &pm.rx_num_pg)) { - warnx("bad parameter \"%s\"", argv[start_arg + 1]); - return -1; - } - if (doit(iff_name, CHELSIO_SET_PM, &pm) < 0) - err(1, "pm config"); - return 0; -} - -#ifdef CHELSIO_INTERNAL -static int -dump_tcam(int argc, char *argv[], int start_arg, const char *iff_name) -{ - unsigned int nwords; - struct ch_tcam_word op; - - if (argc != start_arg + 2) return -1; - - if (get_int_arg(argv[start_arg], &op.addr) || - get_int_arg(argv[start_arg + 1], &nwords)) - return -1; - - while (nwords--) { - if (doit(iff_name, CHELSIO_READ_TCAM_WORD, &op) < 0) - err(1, "tcam dump"); - - printf("0x%08x: 0x%02x 0x%08x 0x%08x\n", op.addr, - op.buf[0] & 0xff, op.buf[1], op.buf[2]); - op.addr++; - } - return 0; -} - -static void -hexdump_8b(unsigned int start, uint64_t *data, unsigned int len) -{ - int i; - - while (len) { - printf("0x%08x:", start); - for (i = 0; i < 4 && len; ++i, --len) - printf(" %016llx", (unsigned long long)*data++); - printf("\n"); - start += 32; - } -} - -static int -dump_mc7(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_mem_range mem; - unsigned int mem_id, addr, len; - - if (argc != start_arg + 3) return -1; - - if (!strcmp(argv[start_arg], "cm")) - mem_id = MEM_CM; - else if (!strcmp(argv[start_arg], "rx")) - mem_id = MEM_PMRX; - else if (!strcmp(argv[start_arg], "tx")) - mem_id = MEM_PMTX; - else - errx(1, "unknown memory \"%s\"; must be one of \"cm\", \"tx\"," - " or \"rx\"", argv[start_arg]); - - if (get_int_arg(argv[start_arg + 1], &addr) || - get_int_arg(argv[start_arg + 2], &len)) - return -1; - - mem.buf = malloc(len); - if (!mem.buf) - err(1, "memory dump"); - - mem.mem_id = mem_id; - mem.addr = addr; - mem.len = len; - - if (doit(iff_name, CHELSIO_GET_MEM, &mem) < 0) - err(1, "memory dump"); - - hexdump_8b(mem.addr, (uint64_t *)mem.buf, mem.len >> 3); - free(mem.buf); - return 0; -} -#endif - -/* Max FW size is 64K including version, +4 bytes for the checksum. */ -#define MAX_FW_IMAGE_SIZE (64 * 1024) - -static int -load_fw(int argc, char *argv[], int start_arg, const char *iff_name) -{ - int fd, len; - struct ch_mem_range op; - const char *fname = argv[start_arg]; - - if (argc != start_arg + 1) return -1; - - fd = open(fname, O_RDONLY); - if (fd < 0) - err(1, "load firmware"); - - bzero(&op, sizeof(op)); - op.buf = malloc(MAX_FW_IMAGE_SIZE + 1); - if (!op.buf) - err(1, "load firmware"); - - len = read(fd, op.buf, MAX_FW_IMAGE_SIZE + 1); - if (len < 0) - err(1, "load firmware"); - if (len > MAX_FW_IMAGE_SIZE) - errx(1, "FW image too large"); - - op.len = len; - if (doit(iff_name, CHELSIO_LOAD_FW, &op) < 0) - err(1, "load firmware"); - return 0; -} - -/* Max BOOT size is 255*512 bytes including the BIOS boot ROM basic header */ -#define MAX_BOOT_IMAGE_SIZE (0xff * 512) - -static int -load_boot(int argc, char *argv[], int start_arg, const char *iff_name) -{ - int fd, len; - struct ch_mem_range op; - const char *fname = argv[start_arg]; - - if (argc != start_arg + 1) return -1; - - fd = open(fname, O_RDONLY); - if (fd < 0) - err(1, "load boot image"); - - op.buf = malloc(MAX_BOOT_IMAGE_SIZE + 1); - if (!op.buf) - err(1, "load boot image"); - - len = read(fd, op.buf, MAX_BOOT_IMAGE_SIZE + 1); - if (len < 0) - err(1, "load boot image"); - if (len > MAX_BOOT_IMAGE_SIZE) - errx(1, "boot image too large"); - - op.len = len; - - if (doit(iff_name, CHELSIO_LOAD_BOOT, &op) < 0) - err(1, "load boot image"); - - return 0; -} - -static int -dump_proto_sram(const char *iff_name) -{ - int i, j; - uint8_t buf[PROTO_SRAM_SIZE]; - struct ch_eeprom ee; - uint8_t *p = buf; - - bzero(buf, sizeof(buf)); - ee.offset = PROTO_SRAM_EEPROM_ADDR; - ee.data = p; - ee.len = sizeof(buf); - if (doit(iff_name, CHELSIO_GET_EEPROM, &ee)) - err(1, "show protocol sram"); - - for (i = 0; i < PROTO_SRAM_LINES; i++) { - for (j = PROTO_SRAM_LINE_NIBBLES - 1; j >= 0; j--) { - int nibble_idx = i * PROTO_SRAM_LINE_NIBBLES + j; - uint8_t nibble = p[nibble_idx / 2]; - - if (nibble_idx & 1) - nibble >>= 4; - else - nibble &= 0xf; - printf("%x", nibble); - } - putchar('\n'); - } - return 0; -} - -static int -proto_sram_op(int argc, char *argv[], int start_arg, - const char *iff_name) -{ - (void) argv; - (void) start_arg; - - if (argc == start_arg) - return dump_proto_sram(iff_name); - return -1; -} - -static int -dump_qset_params(const char *iff_name) -{ - struct ch_qset_params qp; - - qp.qset_idx = 0; - - while (doit(iff_name, CHELSIO_GET_QSET_PARAMS, &qp) == 0) { - if (!qp.qset_idx) - printf("Qset TxQ0 TxQ1 TxQ2 RspQ RxQ0 RxQ1" - " Cong Lat IRQ\n"); - printf("%4u %6u %6u %6u %6u %6u %6u %5u %4u %5d\n", - qp.qnum, - qp.txq_size[0], qp.txq_size[1], qp.txq_size[2], - qp.rspq_size, qp.fl_size[0], qp.fl_size[1], - qp.cong_thres, qp.intr_lat, qp.vector); - qp.qset_idx++; - } - if (!qp.qset_idx || (errno && errno != EINVAL)) - err(1, "get qset parameters"); - return 0; -} - -static int -qset_config(int argc, char *argv[], int start_arg, const char *iff_name) -{ - (void) argv; - - if (argc == start_arg) - return dump_qset_params(iff_name); - - return -1; -} - -static int -qset_num_config(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_reg reg; - - (void) argv; - - if (argc == start_arg) { - if (doit(iff_name, CHELSIO_GET_QSET_NUM, ®) < 0) - err(1, "get qsets"); - printf("%u\n", reg.val); - return 0; - } - - return -1; -} - -/* - * Parse a string containing an IP address with an optional network prefix. - */ -static int -parse_ipaddr(const char *s, uint32_t *addr, uint32_t *mask) -{ - char *p, *slash; - struct in_addr ia; - - *mask = 0xffffffffU; - slash = strchr(s, '/'); - if (slash) - *slash = 0; - if (!inet_aton(s, &ia)) { - if (slash) - *slash = '/'; - *addr = 0; - return -1; - } - *addr = ntohl(ia.s_addr); - if (slash) { - unsigned int prefix = strtoul(slash + 1, &p, 10); - - *slash = '/'; - if (p == slash + 1 || *p || prefix > 32) - return -1; - *mask <<= (32 - prefix); - } - return 0; -} - -/* - * Parse a string containing a value and an optional colon separated mask. - */ -static int -parse_val_mask_param(const char *s, uint32_t *val, uint32_t *mask, - uint32_t default_mask) -{ - char *p; - - *mask = default_mask; - *val = strtoul(s, &p, 0); - if (p == s || *val > default_mask) - return -1; - if (*p == ':' && p[1]) - *mask = strtoul(p + 1, &p, 0); - return *p || *mask > default_mask ? -1 : 0; -} - -static int -parse_trace_param(const char *s, uint32_t *val, uint32_t *mask) -{ - return strchr(s, '.') ? parse_ipaddr(s, val, mask) : - parse_val_mask_param(s, val, mask, 0xffffffffU); -} - -static int -trace_config(int argc, char *argv[], int start_arg, const char *iff_name) -{ - uint32_t val, mask; - struct ch_trace trace; - - if (argc == start_arg) - return -1; - - memset(&trace, 0, sizeof(trace)); - if (!strcmp(argv[start_arg], "tx")) - trace.config_tx = 1; - else if (!strcmp(argv[start_arg], "rx")) - trace.config_rx = 1; - else if (!strcmp(argv[start_arg], "all")) - trace.config_tx = trace.config_rx = 1; - else - errx(1, "bad trace filter \"%s\"; must be one of \"rx\", " - "\"tx\" or \"all\"", argv[start_arg]); - - if (argc == ++start_arg) - return -1; - if (!strcmp(argv[start_arg], "on")) { - trace.trace_tx = trace.config_tx; - trace.trace_rx = trace.config_rx; - } else if (strcmp(argv[start_arg], "off")) - errx(1, "bad argument \"%s\"; must be \"on\" or \"off\"", - argv[start_arg]); - - start_arg++; - if (start_arg < argc && !strcmp(argv[start_arg], "not")) { - trace.invert_match = 1; - start_arg++; - } - - while (start_arg + 2 <= argc) { - int ret = parse_trace_param(argv[start_arg + 1], &val, &mask); - - if (!strcmp(argv[start_arg], "interface")) { - trace.intf = val; - trace.intf_mask = mask; - } else if (!strcmp(argv[start_arg], "sip")) { - trace.sip = val; - trace.sip_mask = mask; - } else if (!strcmp(argv[start_arg], "dip")) { - trace.dip = val; - trace.dip_mask = mask; - } else if (!strcmp(argv[start_arg], "sport")) { - trace.sport = val; - trace.sport_mask = mask; - } else if (!strcmp(argv[start_arg], "dport")) { - trace.dport = val; - trace.dport_mask = mask; - } else if (!strcmp(argv[start_arg], "vlan")) { - trace.vlan = val; - trace.vlan_mask = mask; - } else if (!strcmp(argv[start_arg], "proto")) { - trace.proto = val; - trace.proto_mask = mask; - } else - errx(1, "unknown trace parameter \"%s\"\n" - "known parameters are \"interface\", \"sip\", " - "\"dip\", \"sport\", \"dport\", \"vlan\", " - "\"proto\"", argv[start_arg]); - if (ret < 0) - errx(1, "bad parameter \"%s\"", argv[start_arg + 1]); - start_arg += 2; - } - if (start_arg != argc) - errx(1, "unknown parameter \"%s\"", argv[start_arg]); - - if (doit(iff_name, CHELSIO_SET_TRACE_FILTER, &trace) < 0) - err(1, "trace"); - return 0; -} - -static void -show_filters(const char *iff_name) -{ - static const char *pkt_type[] = { "*", "tcp", "udp", "frag" }; - struct ch_filter op; - union { - uint32_t nip; - uint8_t octet[4]; - } nsip, ndip; - char sip[20], dip[20]; - int header = 0; - - bzero(&op, sizeof(op)); - op.filter_id = 0xffffffff; - - do { - if (doit(iff_name, CHELSIO_GET_FILTER, &op) < 0) - err(1, "list filters"); - - if (op.filter_id == 0xffffffff) - break; - - if (!header) { - printf("index SIP DIP sport " - "dport VLAN PRI P/MAC type Q\n"); - header = 1; - } - - nsip.nip = htonl(op.val.sip); - ndip.nip = htonl(op.val.dip); - - sprintf(sip, "%u.%u.%u.%u/%-2u", nsip.octet[0], nsip.octet[1], - nsip.octet[2], nsip.octet[3], - op.mask.sip ? 33 - ffs(op.mask.sip) : 0); - sprintf(dip, "%u.%u.%u.%u", ndip.octet[0], ndip.octet[1], - ndip.octet[2], ndip.octet[3]); - printf("%5zu %18s %15s ", (size_t)op.filter_id, sip, dip); - printf(op.val.sport ? "%5u " : " * ", op.val.sport); - printf(op.val.dport ? "%5u " : " * ", op.val.dport); - printf(op.val.vlan != 0xfff ? "%4u " : " * ", op.val.vlan); - printf(op.val.vlan_prio == 7 ? " * " : - "%1u/%1u ", op.val.vlan_prio, op.val.vlan_prio | 1); - if (op.mac_addr_idx == 0xffff) - printf("*/* "); - else if (op.mac_hit) - printf("%1u/%3u ", (op.mac_addr_idx >> 3) & 0x1, - (op.mac_addr_idx) & 0x7); - else - printf("%1u/ * ", (op.mac_addr_idx >> 3) & 0x1); - printf("%4s ", pkt_type[op.proto]); - if (!op.pass) - printf("-\n"); - else if (op.rss) - printf("*\n"); - else - printf("%1u\n", op.qset); - } while (1); -} - -static int -filter_config(int argc, char *argv[], int start_arg, const char *iff_name) -{ - int ret = 0; - uint32_t val, mask; - struct ch_filter op; - - if (argc < start_arg + 1) - return -1; - - memset(&op, 0, sizeof(op)); - op.mac_addr_idx = 0xffff; - op.rss = 1; - - if (argc == start_arg + 1 && !strcmp(argv[start_arg], "list")) { - show_filters(iff_name); - return 0; - } - - if (get_int_arg(argv[start_arg++], &op.filter_id)) - return -1; - if (argc == start_arg + 1 && (!strcmp(argv[start_arg], "delete") || - !strcmp(argv[start_arg], "clear"))) { - if (doit(iff_name, CHELSIO_DEL_FILTER, &op) < 0) { - if (errno == EBUSY) - err(1, "no filter support when offload in use"); - err(1, "delete filter"); - } - return 0; - } - - while (start_arg + 2 <= argc) { - if (!strcmp(argv[start_arg], "sip")) { - ret = parse_ipaddr(argv[start_arg + 1], &op.val.sip, - &op.mask.sip); - } else if (!strcmp(argv[start_arg], "dip")) { - ret = parse_ipaddr(argv[start_arg + 1], &op.val.dip, - &op.mask.dip); - } else if (!strcmp(argv[start_arg], "sport")) { - ret = parse_val_mask_param(argv[start_arg + 1], - &val, &mask, 0xffff); - op.val.sport = val; - op.mask.sport = mask; - } else if (!strcmp(argv[start_arg], "dport")) { - ret = parse_val_mask_param(argv[start_arg + 1], - &val, &mask, 0xffff); - op.val.dport = val; - op.mask.dport = mask; - } else if (!strcmp(argv[start_arg], "vlan")) { - ret = parse_val_mask_param(argv[start_arg + 1], - &val, &mask, 0xfff); - op.val.vlan = val; - op.mask.vlan = mask; - } else if (!strcmp(argv[start_arg], "prio")) { - ret = parse_val_mask_param(argv[start_arg + 1], - &val, &mask, 7); - op.val.vlan_prio = val; - op.mask.vlan_prio = mask; - } else if (!strcmp(argv[start_arg], "mac")) { - if (!strcmp(argv[start_arg + 1], "none")) - val = -1; - else - ret = get_int_arg(argv[start_arg + 1], &val); - op.mac_hit = val != (uint32_t)-1; - op.mac_addr_idx = op.mac_hit ? val : 0; - } else if (!strcmp(argv[start_arg], "type")) { - if (!strcmp(argv[start_arg + 1], "tcp")) - op.proto = 1; - else if (!strcmp(argv[start_arg + 1], "udp")) - op.proto = 2; - else if (!strcmp(argv[start_arg + 1], "frag")) - op.proto = 3; - else - errx(1, "unknown type \"%s\"; must be one of " - "\"tcp\", \"udp\", or \"frag\"", - argv[start_arg + 1]); - } else if (!strcmp(argv[start_arg], "queue")) { - ret = get_int_arg(argv[start_arg + 1], &val); - op.qset = val; - op.rss = 0; - } else if (!strcmp(argv[start_arg], "action")) { - if (!strcmp(argv[start_arg + 1], "pass")) - op.pass = 1; - else if (strcmp(argv[start_arg + 1], "drop")) - errx(1, "unknown action \"%s\"; must be one of " - "\"pass\" or \"drop\"", - argv[start_arg + 1]); - } else - errx(1, "unknown filter parameter \"%s\"\n" - "known parameters are \"mac\", \"sip\", " - "\"dip\", \"sport\", \"dport\", \"vlan\", " - "\"prio\", \"type\", \"queue\", and \"action\"", - argv[start_arg]); - if (ret < 0) - errx(1, "bad value \"%s\" for parameter \"%s\"", - argv[start_arg + 1], argv[start_arg]); - start_arg += 2; - } - if (start_arg != argc) - errx(1, "no value for \"%s\"", argv[start_arg]); - - if (doit(iff_name, CHELSIO_SET_FILTER, &op) < 0) { - if (errno == EBUSY) - err(1, "no filter support when offload in use"); - err(1, "set filter"); - } - - return 0; -} -static int -get_sched_param(int argc, char *argv[], int pos, unsigned int *valp) -{ - if (pos + 1 >= argc) - errx(1, "missing value for %s", argv[pos]); - if (get_int_arg(argv[pos + 1], valp)) - exit(1); - return 0; -} - -static int -tx_sched(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_hw_sched op; - unsigned int idx, val; - - if (argc < 5 || get_int_arg(argv[start_arg++], &idx)) - return -1; - - op.sched = idx; - op.mode = op.channel = -1; - op.kbps = op.class_ipg = op.flow_ipg = -1; - - while (argc > start_arg) { - if (!strcmp(argv[start_arg], "mode")) { - if (start_arg + 1 >= argc) - errx(1, "missing value for mode"); - if (!strcmp(argv[start_arg + 1], "class")) - op.mode = 0; - else if (!strcmp(argv[start_arg + 1], "flow")) - op.mode = 1; - else - errx(1, "bad mode \"%s\"", argv[start_arg + 1]); - } else if (!strcmp(argv[start_arg], "channel") && - !get_sched_param(argc, argv, start_arg, &val)) - op.channel = val; - else if (!strcmp(argv[start_arg], "rate") && - !get_sched_param(argc, argv, start_arg, &val)) - op.kbps = val; - else if (!strcmp(argv[start_arg], "ipg") && - !get_sched_param(argc, argv, start_arg, &val)) - op.class_ipg = val; - else if (!strcmp(argv[start_arg], "flowipg") && - !get_sched_param(argc, argv, start_arg, &val)) - op.flow_ipg = val; - else - errx(1, "unknown scheduler parameter \"%s\"", - argv[start_arg]); - start_arg += 2; - } - - if (doit(iff_name, CHELSIO_SET_HW_SCHED, &op) < 0) - err(1, "pktsched"); - - return 0; -} - -static int -pktsched(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_pktsched_params op; - unsigned int idx, min = -1, max, binding = -1; - - if (argc < 4) - errx(1, "no scheduler specified"); - - if (!strcmp(argv[start_arg], "port")) { - if (argc != start_arg + 4) - return -1; - if (get_int_arg(argv[start_arg + 1], &idx) || - get_int_arg(argv[start_arg + 2], &min) || - get_int_arg(argv[start_arg + 3], &max)) - return -1; - op.sched = 0; - } else if (!strcmp(argv[start_arg], "tunnelq")) { - if (argc != start_arg + 4) - return -1; - if (get_int_arg(argv[start_arg + 1], &idx) || - get_int_arg(argv[start_arg + 2], &max) || - get_int_arg(argv[start_arg + 3], &binding)) - return -1; - op.sched = 1; - } else if (!strcmp(argv[start_arg], "tx")) - return tx_sched(argc, argv, start_arg + 1, iff_name); - else - errx(1, "unknown scheduler \"%s\"; must be one of \"port\", " - "\"tunnelq\" or \"tx\"", argv[start_arg]); - - op.idx = idx; - op.min = min; - op.max = max; - op.binding = binding; - if (doit(iff_name, CHELSIO_SET_PKTSCHED, &op) < 0) - err(1, "pktsched"); - - return 0; -} - -static int -clear_stats(int argc, char *argv[], int start_arg, const char *iff_name) -{ - (void) argc; - (void) argv; - (void) start_arg; - - if (doit(iff_name, CHELSIO_CLEAR_STATS, NULL) < 0) - err(1, "clearstats"); - - return 0; -} - -static int -get_up_la(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_up_la la; - int i, idx, max_idx, entries; - - (void) argc; - (void) argv; - (void) start_arg; - - la.stopped = 0; - la.idx = -1; - la.bufsize = LA_BUFSIZE; - la.data = malloc(la.bufsize); - if (!la.data) - err(1, "uP_LA malloc"); - - if (doit(iff_name, CHELSIO_GET_UP_LA, &la) < 0) - err(1, "uP_LA"); - - if (la.stopped) - printf("LA is not running\n"); - - entries = la.bufsize / 4; - idx = (int)la.idx; - max_idx = (entries / 4) - 1; - for (i = 0; i < max_idx; i++) { - printf("%04x %08x %08x\n", - la.data[idx], la.data[idx+2], la.data[idx+1]); - idx = (idx + 4) & (entries - 1); - } - - return 0; -} - -static int -get_up_ioqs(int argc, char *argv[], int start_arg, const char *iff_name) -{ - struct ch_up_ioqs ioqs; - int i, entries; - - (void) argc; - (void) argv; - (void) start_arg; - - bzero(&ioqs, sizeof(ioqs)); - ioqs.bufsize = IOQS_BUFSIZE; - ioqs.data = malloc(IOQS_BUFSIZE); - if (!ioqs.data) - err(1, "uP_IOQs malloc"); - - if (doit(iff_name, CHELSIO_GET_UP_IOQS, &ioqs) < 0) - err(1, "uP_IOQs"); - - printf("ioq_rx_enable : 0x%08x\n", ioqs.ioq_rx_enable); - printf("ioq_tx_enable : 0x%08x\n", ioqs.ioq_tx_enable); - printf("ioq_rx_status : 0x%08x\n", ioqs.ioq_rx_status); - printf("ioq_tx_status : 0x%08x\n", ioqs.ioq_tx_status); - - entries = ioqs.bufsize / sizeof(struct t3_ioq_entry); - for (i = 0; i < entries; i++) { - printf("\nioq[%d].cp : 0x%08x\n", i, - ioqs.data[i].ioq_cp); - printf("ioq[%d].pp : 0x%08x\n", i, - ioqs.data[i].ioq_pp); - printf("ioq[%d].alen : 0x%08x\n", i, - ioqs.data[i].ioq_alen); - printf("ioq[%d].stats : 0x%08x\n", i, - ioqs.data[i].ioq_stats); - printf(" sop %u\n", ioqs.data[i].ioq_stats >> 16); - printf(" eop %u\n", ioqs.data[i].ioq_stats & 0xFFFF); - } - - return 0; -} - -static int -run_cmd(int argc, char *argv[], const char *iff_name) -{ - int r = -1; - - if (!strcmp(argv[2], "reg")) - r = register_io(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "mdio")) - r = mdio_io(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "mtus")) - r = mtu_tab_op(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "pm")) - r = conf_pm(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "regdump")) - r = dump_regs(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "tcamdump")) - r = dump_tcam(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "memdump")) - r = dump_mc7(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "meminfo")) - r = meminfo(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "context")) - r = get_sge_context(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "desc")) - r = get_sge_desc(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "loadfw")) - r = load_fw(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "loadboot")) - r = load_boot(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "proto")) - r = proto_sram_op(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "qset")) - r = qset_config(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "qsets")) - r = qset_num_config(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "trace")) - r = trace_config(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "pktsched")) - r = pktsched(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "tcb")) - r = get_tcb2(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "filter")) - r = filter_config(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "clearstats")) - r = clear_stats(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "la")) - r = get_up_la(argc, argv, 3, iff_name); - else if (!strcmp(argv[2], "ioqs")) - r = get_up_ioqs(argc, argv, 3, iff_name); - - if (r == -1) - usage(stderr); - - return (0); -} - -static int -run_cmd_loop(int argc, char *argv[], const char *iff_name) -{ - int n; - unsigned int i; - char buf[64]; - char *args[8], *s; - - (void) argc; - args[0] = argv[0]; - args[1] = argv[1]; - - /* - * Fairly simplistic loop. Displays a "> " prompt and processes any - * input as a cxgbtool command. You're supposed to enter only the part - * after "cxgbtool cxgbX". Use "quit" or "exit" to exit. Any error in - * the command will also terminate cxgbtool. - */ - for (;;) { - fprintf(stdout, "> "); - fflush(stdout); - n = read(STDIN_FILENO, buf, sizeof(buf) - 1); - if (n <= 0) - return (0); - - if (buf[--n] != '\n') - continue; - else - buf[n] = 0; - - s = &buf[0]; - for (i = 2; i < sizeof(args)/sizeof(args[0]) - 1; i++) { - while (s && (*s == ' ' || *s == '\t')) - s++; - if ((args[i] = strsep(&s, " \t")) == NULL) - break; - } - args[sizeof(args)/sizeof(args[0]) - 1] = 0; - - if (!strcmp(args[2], "quit") || !strcmp(args[2], "exit")) - return (0); - - (void) run_cmd(i, args, iff_name); - } - - /* Can't really get here */ - return (0); -} - -int -main(int argc, char *argv[]) -{ - int r = -1; - const char *iff_name; - - progname = argv[0]; - - if (argc == 2) { - if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) - usage(stdout); - if (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) { - printf("%s version %s\n", PROGNAME, VERSION); - printf("%s\n", COPYRIGHT); - exit(0); - } - } - - if (argc < 3) usage(stderr); - - iff_name = argv[1]; - - if (argc == 3 && !strcmp(argv[2], "stdio")) - r = run_cmd_loop(argc, argv, iff_name); - else - r = run_cmd(argc, argv, iff_name); - - return (r); -} diff --git a/usr.sbin/cxgbtool/reg_defs.c b/usr.sbin/cxgbtool/reg_defs.c deleted file mode 100644 index 687bb75..0000000 --- a/usr.sbin/cxgbtool/reg_defs.c +++ /dev/null @@ -1,837 +0,0 @@ -/* - * $FreeBSD$ - */ - -/* This file is automatically generated --- do not edit */ - -struct reg_info sge_regs[] = { - { "SG_CONTROL", 0x0, 0 }, - { "CmdQ0_Enable", 0, 1 }, - { "CmdQ1_Enable", 1, 1 }, - { "FL0_Enable", 2, 1 }, - { "FL1_Enable", 3, 1 }, - { "CPL_Enable", 4, 1 }, - { "Response_Queue_Enable", 5, 1 }, - { "CmdQ_Priority", 6, 2 }, - { "Disable_CmdQ0_GTS", 8, 1 }, - { "Disable_CmdQ1_GTS", 9, 1 }, - { "Disable_FL0_GTS", 10, 1 }, - { "Disable_FL1_GTS", 11, 1 }, - { "Enable_Big_Endian", 12, 1 }, - { "FL_Selection_Criteria", 13, 1 }, - { "iSCSI_Coalesce", 14, 1 }, - { "RX_Pkt_Offset", 15, 3 }, - { "VLAN_Xtract", 18, 1 }, - { "SG_DOORBELL", 0x4, 0 }, - { "CmdQ0_Enable", 0, 1 }, - { "CmdQ1_Enable", 1, 1 }, - { "FL0_Enable", 2, 1 }, - { "FL1_Enable", 3, 1 }, - { "SG_CMD0BASELWR", 0x8, 0 }, - { "SG_CMD0BASEUPR", 0xc, 0 }, - { "SG_CMD1BASELWR", 0x10, 0 }, - { "SG_CMD1BASEUPR", 0x14, 0 }, - { "SG_FL0BASELWR", 0x18, 0 }, - { "SG_FL0BASEUPR", 0x1c, 0 }, - { "SG_FL1BASELWR", 0x20, 0 }, - { "SG_FL1BASEUPR", 0x24, 0 }, - { "SG_CMD0SIZE", 0x28, 0 }, - { "CmdQ0_Size", 0, 17 }, - { "SG_FL0SIZE", 0x2c, 0 }, - { "FL0_Size", 0, 17 }, - { "SG_RSPSIZE", 0x30, 0 }, - { "RespQ_Size", 0, 17 }, - { "SG_RSPBASELWR", 0x34, 0 }, - { "SG_RSPBASEUPR", 0x38, 0 }, - { "SG_FLTHRESHOLD", 0x3c, 0 }, - { "FL_Threshold", 0, 16 }, - { "SG_RSPQUEUECREDIT", 0x40, 0 }, - { "RespQ_Credit", 0, 17 }, - { "SG_DEBUGTXDATAL", 0x44, 0 }, - { "SG_SLEEPING", 0x48, 0 }, - { "Sleeping", 0, 16 }, - { "SG_INTRTIMER", 0x4c, 0 }, - { "Interrupt_Timer_Count", 0, 24 }, - { "SG_CMD0PTR", 0x50, 0 }, - { "CmdQ0_Pointer", 0, 16 }, - { "Current_Generation_Bit", 16, 1 }, - { "SG_CMD1PTR", 0x54, 0 }, - { "CmdQ1_Pointer", 0, 16 }, - { "Current_Generation_Bit", 16, 1 }, - { "SG_FL0PTR", 0x58, 0 }, - { "FL0_Pointer", 0, 16 }, - { "Current_Generation_Bit", 16, 1 }, - { "SG_FL1PTR", 0x5c, 0 }, - { "FL1_Pointer", 0, 16 }, - { "Current_Generation_Bit", 16, 1 }, - { "SG_DEBUGTXDATAH", 0x60, 0 }, - { "SG_DEBUGRXDATAL", 0x64, 0 }, - { "SG_DEBUGRXDATAH", 0x68, 0 }, - { "SG_VERSION", 0x6c, 0 }, - { "Day", 0, 5 }, - { "Month", 5, 4 }, - { "SG_DEBUGRXSOP", 0x70, 0 }, - { "SG_DEBUGTXSOP", 0x74, 0 }, - { "SG_LA_RDPTR0", 0x78, 0 }, - { "Logic_Analyzer0_Read_Pointer", 0, 9 }, - { "SG_LA_RDDATA0", 0x7c, 0 }, - { "SG_LA_WRPTR0", 0x80, 0 }, - { "SG_DEBUGRXEOP", 0x84, 0 }, - { "SG_DEBUGTXEOP", 0x88, 0 }, - { "SG_DEBUGRXSIZE", 0x8c, 0 }, - { "SG_DEBUGTXSIZE", 0x90, 0 }, - { "SG_NUMBER_LA", 0x94, 0 }, - { "SG_LA_RDPTR1", 0x98, 0 }, - { "Logic_Analyzer1_Read_Pointer", 0, 9 }, - { "SG_LA_RDDATA1", 0x9c, 0 }, - { "SG_LA_WRPTR1", 0xa0, 0 }, - { "SG_LA_RDPTR2", 0xa4, 0 }, - { "Logic_Analyzer2_Read_Pointer", 0, 9 }, - { "SG_LA_RDDATA2", 0xa8, 0 }, - { "SG_LA_WRPTR2", 0xac, 0 }, - { "SG_CMD1SIZE", 0xb0, 0 }, - { "CmdQ1_Size", 0, 17 }, - { "SG_FL1SIZE", 0xb4, 0 }, - { "FL1_Size", 0, 17 }, - { "SG_INT_ENABLE", 0xb8, 0 }, - { "RespQ_Exhausted", 0, 1 }, - { "RespQ_Overflow", 1, 1 }, - { "FL_Exhausted", 2, 1 }, - { "Packet_Too_Big", 3, 1 }, - { "Packet_Mismatch", 4, 1 }, - { "SG_INT_CAUSE", 0xbc, 0 }, - { "RespQ_Exhausted", 0, 1 }, - { "RespQ_Overflow", 1, 1 }, - { "FL_Exhausted", 2, 1 }, - { "Packet_Too_Big", 3, 1 }, - { "Packet_Mismatch", 4, 1 }, - { "SG_RESPACCUTIMER", 0xc0, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info mc3_regs[] = { - { "MC3_CFG", 0x100, 0 }, - { "Clk_Enable", 0, 1 }, - { "Ready", 1, 1 }, - { "Read_to_Write_Delay", 2, 3 }, - { "Write_to_Read_Delay", 5, 3 }, - { "MC3_Bank_Cycle", 8, 4 }, - { "Refresh_Cycle", 12, 4 }, - { "Precharge_Cycle", 16, 2 }, - { "Active_to_Read_Write_Delay", 18, 1 }, - { "Active_to_Precharge_Delay", 19, 3 }, - { "Write_Recovery_Delay", 22, 2 }, - { "Density", 24, 2 }, - { "Organization", 26, 1 }, - { "Banks", 27, 1 }, - { "Unregistered", 28, 1 }, - { "MC3_Width", 29, 2 }, - { "MC3_Slow", 31, 1 }, - { "MC3_MODE", 0x104, 0 }, - { "MC3_Mode", 0, 14 }, - { "Busy", 31, 1 }, - { "MC3_EXT_MODE", 0x108, 0 }, - { "MC3_Extended_Mode", 0, 14 }, - { "Busy", 31, 1 }, - { "MC3_PRECHARG", 0x10c, 0 }, - { "Busy", 31, 1 }, - { "MC3_REFRESH", 0x110, 0 }, - { "Refresh_Enable", 0, 1 }, - { "Refresh_Divisor", 1, 14 }, - { "Busy", 31, 1 }, - { "MC3_STROBE", 0x114, 0 }, - { "Master_DLL_Reset", 0, 1 }, - { "Master_DLL_Tap_Count", 1, 8 }, - { "Master_DLL_Locked", 9, 1 }, - { "Master_DLL_Max_Tap_Count", 10, 1 }, - { "Master_DLL_Tap_Count_Offset", 11, 6 }, - { "Slave_DLL_Reset", 11, 1 }, - { "Slave_DLL_Delta", 12, 4 }, - { "Slave_Delay_Line_Manual_Tap_Count", 17, 6 }, - { "Slave_Delay_Line_Manual_Tap_Count_Enable", 23, 1 }, - { "Slave_Delay_Line_Tap_Count", 24, 6 }, - { "MC3_ECC_CNTL", 0x118, 0 }, - { "ECC_Generation_Enable", 0, 1 }, - { "ECC_Check_Enable", 1, 1 }, - { "Correctable_Error_Count", 2, 8 }, - { "Uncorrectable_Error_Count", 10, 8 }, - { "MC3_CE_ADDR", 0x11c, 0 }, - { "MC3_CE_Addr", 4, 28 }, - { "MC3_CE_DATA0", 0x120, 0 }, - { "MC3_CE_DATA1", 0x124, 0 }, - { "MC3_CE_DATA2", 0x128, 0 }, - { "MC3_CE_DATA3", 0x12c, 0 }, - { "MC3_CE_DATA4", 0x130, 0 }, - { "MC3_UE_ADDR", 0x134, 0 }, - { "MC3_UE_Addr", 4, 28 }, - { "MC3_UE_DATA0", 0x138, 0 }, - { "MC3_UE_DATA1", 0x13c, 0 }, - { "MC3_UE_DATA2", 0x140, 0 }, - { "MC3_UE_DATA3", 0x144, 0 }, - { "MC3_UE_DATA4", 0x148, 0 }, - { "MC3_BD_ADDR", 0x14c, 0 }, - { "MC3_BD_DATA0", 0x150, 0 }, - { "MC3_BD_DATA1", 0x154, 0 }, - { "MC3_BD_DATA2", 0x158, 0 }, - { "MC3_BD_DATA3", 0x15c, 0 }, - { "MC3_BD_DATA4", 0x160, 0 }, - { "MC3_BD_OP", 0x164, 0 }, - { "Back_Door_Operation", 0, 1 }, - { "Busy", 31, 1 }, - { "MC3_BIST_ADDR_BEG", 0x168, 0 }, - { "MC3_BIST_ADDR_END", 0x16c, 0 }, - { "MC3_BIST_DATA", 0x170, 0 }, - { "MC3_BIST_OP", 0x174, 0 }, - { "Op", 0, 1 }, - { "Data_Pattern", 1, 2 }, - { "Continuous", 3, 1 }, - { "Busy", 31, 1 }, - { "MC3_INT_ENABLE", 0x178, 0 }, - { "MC3_Corr_Err", 0, 1 }, - { "MC3_Uncorr_Err", 1, 1 }, - { "MC3_Parity_Err", 2, 8 }, - { "MC3_Addr_Err", 10, 1 }, - { "MC3_INT_CAUSE", 0x17c, 0 }, - { "MC3_Corr_Err", 0, 1 }, - { "MC3_Uncorr_Err", 1, 1 }, - { "MC3_Parity_Err", 2, 8 }, - { "MC3_Addr_Err", 10, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info mc4_regs[] = { - { "MC4_CFG", 0x180, 0 }, - { "Power_Up", 0, 1 }, - { "Ready", 1, 1 }, - { "Read_to_Write_Delay", 2, 3 }, - { "Write_to_Read_Delay", 5, 3 }, - { "MC4_Bank_Cycle", 8, 3 }, - { "MC4_Narrow", 24, 1 }, - { "MC4_Slow", 25, 1 }, - { "MC4A_Width", 24, 2 }, - { "MC4A_Slow", 26, 1 }, - { "MC4_MODE", 0x184, 0 }, - { "MC4_Mode", 0, 15 }, - { "Busy", 31, 1 }, - { "MC4_EXT_MODE", 0x188, 0 }, - { "MC4_Extended_Mode", 0, 15 }, - { "Busy", 31, 1 }, - { "MC4_REFRESH", 0x190, 0 }, - { "Refresh_Enable", 0, 1 }, - { "Refresh_Divisor", 1, 14 }, - { "Busy", 31, 1 }, - { "MC4_STROBE", 0x194, 0 }, - { "Master_DLL_Reset", 0, 1 }, - { "Master_DLL_Tap_Count", 1, 8 }, - { "Master_DLL_Locked", 9, 1 }, - { "Master_DLL_Max_Tap_Count", 10, 1 }, - { "Master_DLL_Tap_Count_Offset", 11, 6 }, - { "Slave_DLL_Reset", 11, 1 }, - { "Slave_DLL_Delta", 12, 4 }, - { "Slave_Delay_Line_Manual_Tap_Count", 17, 6 }, - { "Slave_Delay_Line_Manual_Tap_Count_Enable", 23, 1 }, - { "Slave_Delay_Line_Tap_Count", 24, 6 }, - { "MC4_ECC_CNTL", 0x198, 0 }, - { "ECC_Generation_Enable", 0, 1 }, - { "ECC_Check_Enable", 1, 1 }, - { "Correctable_Error_Count", 2, 8 }, - { "Uncorrectable_Error_Count", 10, 8 }, - { "MC4_CE_ADDR", 0x19c, 0 }, - { "MC4_CE_Addr", 4, 24 }, - { "MC4_CE_DATA0", 0x1a0, 0 }, - { "MC4_CE_DATA1", 0x1a4, 0 }, - { "MC4_CE_DATA2", 0x1a8, 0 }, - { "MC4_CE_DATA3", 0x1ac, 0 }, - { "MC4_CE_DATA4", 0x1b0, 0 }, - { "MC4_UE_ADDR", 0x1b4, 0 }, - { "MC4_UE_Addr", 4, 24 }, - { "MC4_UE_DATA0", 0x1b8, 0 }, - { "MC4_UE_DATA1", 0x1bc, 0 }, - { "MC4_UE_DATA2", 0x1c0, 0 }, - { "MC4_UE_DATA3", 0x1c4, 0 }, - { "MC4_UE_DATA4", 0x1c8, 0 }, - { "MC4_BD_ADDR", 0x1cc, 0 }, - { "MC4_Back_Door_Addr", 0, 28 }, - { "MC4_BD_DATA0", 0x1d0, 0 }, - { "MC4_BD_DATA1", 0x1d4, 0 }, - { "MC4_BD_DATA2", 0x1d8, 0 }, - { "MC4_BD_DATA3", 0x1dc, 0 }, - { "MC4_BD_DATA4", 0x1e0, 0 }, - { "MC4_BD_OP", 0x1e4, 0 }, - { "Operation", 0, 1 }, - { "Busy", 31, 1 }, - { "MC4_BIST_ADDR_BEG", 0x1e8, 0 }, - { "MC4_BIST_ADDR_END", 0x1ec, 0 }, - { "MC4_BIST_DATA", 0x1f0, 0 }, - { "MC4_BIST_OP", 0x1f4, 0 }, - { "Op", 0, 1 }, - { "Data_Pattern", 1, 2 }, - { "Continuous", 3, 1 }, - { "Busy", 31, 1 }, - { "MC4_INT_ENABLE", 0x1f8, 0 }, - { "MC4_Corr_Err", 0, 1 }, - { "MC4_Uncorr_Err", 1, 1 }, - { "MC4_Addr_Err", 2, 1 }, - { "MC4_INT_CAUSE", 0x1fc, 0 }, - { "MC4_Corr_Err", 0, 1 }, - { "MC4_Uncorr_Err", 1, 1 }, - { "MC4_Addr_Err", 2, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info tpi_regs[] = { - { "TPI_ADDR", 0x280, 0 }, - { "TPI_ADDRESS", 0, 24 }, - { "TPI_WR_DATA", 0x284, 0 }, - { "TPI_RD_DATA", 0x288, 0 }, - { "TPI_CSR", 0x28c, 0 }, - { "TPIWR", 0, 1 }, - { "TPIRDY", 1, 1 }, - { "INT_DIR", 31, 1 }, - { "TPI_PAR", 0x29c, 0 }, - { "TPIPAR", 0, 7 }, - { NULL, 0, 0 } -}; - -struct reg_info tp_regs[] = { - { "TP_IN_CONFIG", 0x300, 0 }, - { "TP_IN_CSPI_Tunnel", 0, 1 }, - { "TP_IN_CSPI_Ethernet", 1, 1 }, - { "TP_IN_CSPI_CPL", 3, 1 }, - { "TP_IN_CSPI_POS", 4, 1 }, - { "TP_IN_CSPI_Check_IP_Csum", 5, 1 }, - { "TP_IN_CSPI_Check_TCP_Csum", 6, 1 }, - { "TP_IN_ESPI_Tunnel", 7, 1 }, - { "TP_IN_ESPI_Ethernet", 8, 1 }, - { "TP_IN_ESPI_CPL", 10, 1 }, - { "TP_IN_ESPI_POS", 11, 1 }, - { "TP_IN_ESPI_Check_IP_Csum", 12, 1 }, - { "TP_IN_ESPI_Check_TCP_Csum", 13, 1 }, - { "Offload_Disable", 14, 1 }, - { "TP_OUT_CONFIG", 0x304, 0 }, - { "TP_OUT_C_ETH", 0, 1 }, - { "TP_OUT_CSPI_CPL", 2, 1 }, - { "TP_OUT_CSPI_POS", 3, 1 }, - { "TP_OUT_CSPI_Generate_IP_Csum", 4, 1 }, - { "TP_OUT_CSPI_Generate_TCP_Csum", 5, 1 }, - { "TP_OUT_ESPI_Ethernet", 6, 1 }, - { "TP_OUT_ESPI_TAG_Ethernet", 7, 1 }, - { "TP_OUT_ESPI_CPL", 8, 1 }, - { "TP_OUT_ESPI_POS", 9, 1 }, - { "TP_OUT_ESPI_Generate_IP_Csum", 10, 1 }, - { "TP_OUT_ESPI_Generate_TCP_Csum", 11, 1 }, - { "TP_GLOBAL_CONFIG", 0x308, 0 }, - { "IP_TTL", 0, 8 }, - { "TCAM_Server_Region_Usage", 8, 2 }, - { "QOS_Mapping", 10, 1 }, - { "TCP_Csum", 11, 1 }, - { "UDP_Csum", 12, 1 }, - { "IP_Csum", 13, 1 }, - { "IP_ID_Split", 14, 1 }, - { "Path_MTU", 15, 1 }, - { "5Tuple_Lookup", 17, 2 }, - { "IP_Fragment_Drop", 19, 1 }, - { "Ping_Drop", 20, 1 }, - { "Protect_Mode", 21, 1 }, - { "SYN_Cookie_Algorithm", 22, 1 }, - { "Attack_Filter", 23, 1 }, - { "Interface_Type", 24, 1 }, - { "Disable_RX_Flow_Control", 25, 1 }, - { "SYN_Cookie_Parameter", 26, 6 }, - { "TP_GLOBAL_RX_CREDITS", 0x30c, 0 }, - { "TP_CM_SIZE", 0x310, 0 }, - { "TP_CM_MM_BASE", 0x314, 0 }, - { "CM_MemMgr_Base", 0, 28 }, - { "TP_CM_TIMER_BASE", 0x318, 0 }, - { "CM_Timer_Base", 0, 28 }, - { "TP_PM_SIZE", 0x31c, 0 }, - { "TP_PM_TX_BASE", 0x320, 0 }, - { "TP_PM_DEFRAG_BASE", 0x324, 0 }, - { "TP_PM_RX_BASE", 0x328, 0 }, - { "TP_PM_RX_PG_SIZE", 0x32c, 0 }, - { "TP_PM_RX_MAX_PGS", 0x330, 0 }, - { "TP_PM_TX_PG_SIZE", 0x334, 0 }, - { "TP_PM_TX_MAX_PGS", 0x338, 0 }, - { "TP_TCP_OPTIONS", 0x340, 0 }, - { "Timestamp", 0, 2 }, - { "Window_Scale", 2, 2 }, - { "SACK", 4, 2 }, - { "ECN", 6, 2 }, - { "SACK_Algorithm", 8, 2 }, - { "MSS", 10, 1 }, - { "Default_Peer_MSS", 16, 16 }, - { "TP_DACK_CONFIG", 0x344, 0 }, - { "DACK_Mode", 0, 1 }, - { "DACK_Auto_Mgmt", 1, 1 }, - { "DACK_Auto_Careful", 2, 1 }, - { "DACK_MSS_Selector", 3, 2 }, - { "DACK_Byte_Threshold", 5, 20 }, - { "TP_PC_CONFIG", 0x348, 0 }, - { "TP_Access_Latency", 0, 4 }, - { "Held_FIN_Disable", 4, 1 }, - { "DDP_FC_Enable", 5, 1 }, - { "RDMA_Err_Enable", 6, 1 }, - { "Fast_PDU_Delivery", 7, 1 }, - { "Clear_FIN", 8, 1 }, - { "TP_PC_Rev", 30, 2 }, - { "TP_BACKOFF0", 0x350, 0 }, - { "Element0", 0, 8 }, - { "Element1", 8, 8 }, - { "Element2", 16, 8 }, - { "Element3", 24, 8 }, - { "TP_BACKOFF1", 0x354, 0 }, - { "Element0", 0, 8 }, - { "Element1", 8, 8 }, - { "Element2", 16, 8 }, - { "Element3", 24, 8 }, - { "TP_BACKOFF2", 0x358, 0 }, - { "Element0", 0, 8 }, - { "Element1", 8, 8 }, - { "Element2", 16, 8 }, - { "Element3", 24, 8 }, - { "TP_BACKOFF3", 0x35c, 0 }, - { "Element0", 0, 8 }, - { "Element1", 8, 8 }, - { "Element2", 16, 8 }, - { "Element3", 24, 8 }, - { "TP_PARA_REG0", 0x360, 0 }, - { "Var_Mult", 0, 4 }, - { "Var_Gain", 4, 4 }, - { "SRTT_Gain", 8, 4 }, - { "RTTVar_Init", 12, 4 }, - { "Dup_Thresh", 20, 4 }, - { "Init_Cong_Win", 24, 3 }, - { "TP_PARA_REG1", 0x364, 0 }, - { "Initial_Slow_Start_Threshold", 0, 16 }, - { "Receive_Buffer_Size", 16, 16 }, - { "TP_PARA_REG2", 0x368, 0 }, - { "RX_Coalesce_Size", 0, 16 }, - { "MAX_RX_Size", 16, 16 }, - { "TP_PARA_REG3", 0x36c, 0 }, - { "RX_Coalescing_PSH_Deliver", 0, 1 }, - { "RX_Coalescing_Enable", 1, 1 }, - { "Tahoe_Enable", 2, 1 }, - { "MAX_Reorder_Fragments", 12, 3 }, - { "TP_TIMER_RESOLUTION", 0x390, 0 }, - { "Delayed_ACK_Timer_Resolution", 0, 6 }, - { "Generic_Timer_Resolution", 16, 6 }, - { "TP_2MSL", 0x394, 0 }, - { "2MSL", 0, 30 }, - { "TP_RXT_MIN", 0x398, 0 }, - { "Retransmit_Timer_MIN", 0, 16 }, - { "TP_RXT_MAX", 0x39c, 0 }, - { "Retransmit_Timer_MAX", 0, 30 }, - { "TP_PERS_MIN", 0x3a0, 0 }, - { "Persist_Timer_MIN", 0, 16 }, - { "TP_PERS_MAX", 0x3a4, 0 }, - { "Persist_Timer_MAX", 0, 30 }, - { "TP_KEEP_IDLE", 0x3ac, 0 }, - { "Keep_Alive_Idle_Time", 0, 30 }, - { "TP_KEEP_INTVL", 0x3b0, 0 }, - { "Keep_Alive_Interval_Time", 0, 30 }, - { "TP_INIT_SRTT", 0x3b4, 0 }, - { "Initial_SRTT", 0, 16 }, - { "TP_DACK_TIME", 0x3b8, 0 }, - { "Delayed_ACK_Time", 0, 11 }, - { "TP_FINWAIT2_TIME", 0x3bc, 0 }, - { "FINWAIT2_TIME", 0, 30 }, - { "TP_FAST_FINWAIT2_TIME", 0x3c0, 0 }, - { "Fast_FINWAIT2_Time", 0, 30 }, - { "TP_SHIFT_CNT", 0x3c4, 0 }, - { "KeepAlive_MAX", 0, 8 }, - { "WindowProbe_MAX", 8, 8 }, - { "Retransmission_MAX", 16, 8 }, - { "SYN_MAX", 24, 8 }, - { "TP_QOS_REG0", 0x3e0, 0 }, - { "L3_Value", 0, 6 }, - { "TP_QOS_REG1", 0x3e4, 0 }, - { "L3_Value", 0, 6 }, - { "TP_QOS_REG2", 0x3e8, 0 }, - { "L3_Value", 0, 6 }, - { "TP_QOS_REG3", 0x3ec, 0 }, - { "L3_Value", 0, 6 }, - { "TP_QOS_REG4", 0x3f0, 0 }, - { "L3_Value", 0, 6 }, - { "TP_QOS_REG5", 0x3f4, 0 }, - { "L3_Value", 0, 6 }, - { "TP_QOS_REG6", 0x3f8, 0 }, - { "L3_Value", 0, 6 }, - { "TP_QOS_REG7", 0x3fc, 0 }, - { "L3_Value", 0, 6 }, - { "TP_MTU_REG0", 0x404, 0 }, - { "TP_MTU_REG1", 0x408, 0 }, - { "TP_MTU_REG2", 0x40c, 0 }, - { "TP_MTU_REG3", 0x410, 0 }, - { "TP_MTU_REG4", 0x414, 0 }, - { "TP_MTU_REG5", 0x418, 0 }, - { "TP_MTU_REG6", 0x41c, 0 }, - { "TP_MTU_REG7", 0x420, 0 }, - { "TP_RESET", 0x44c, 0 }, - { "TP_Reset", 0, 1 }, - { "CM_MemMgr_Init", 1, 1 }, - { "TP_MIB_INDEX", 0x450, 0 }, - { "TP_MIB_DATA", 0x454, 0 }, - { "TP_SYNC_TIME_HI", 0x458, 0 }, - { "TP_SYNC_TIME_LO", 0x45c, 0 }, - { "TP_CM_MM_RX_FLST_BASE", 0x460, 0 }, - { "CM_MemMgr_RX_Free_List_Base", 0, 28 }, - { "TP_CM_MM_TX_FLST_BASE", 0x464, 0 }, - { "CM_MemMgr_TX_Free_List_Base", 0, 28 }, - { "TP_CM_MM_P_FLST_BASE", 0x468, 0 }, - { "CM_MemMgr_PStruct_Free_List_Base", 0, 28 }, - { "TP_CM_MM_MAX_P", 0x46c, 0 }, - { "CM_MemMgr_MAX_PStruct", 0, 28 }, - { "TP_INT_ENABLE", 0x470, 0 }, - { "TX_Free_List_Empty", 0, 1 }, - { "RX_Free_List_Empty", 1, 1 }, - { "TP_INT_CAUSE", 0x474, 0 }, - { "TX_Free_List_Empty", 0, 1 }, - { "RX_Free_List_Empty", 1, 1 }, - { "TP_FLM_FREE_PSTRUCT_CNT", 0x480, 0 }, - { "TP_FLM_FREE_RX_PG_CNT", 0x484, 0 }, - { "TP_FLM_FREE_TX_PG_CNT", 0x488, 0 }, - { "TP_HEAP_PUSH_CNT", 0x48c, 0 }, - { "TP_HEAP_POP_CNT", 0x490, 0 }, - { "TP_DACK_PUSH_CNT", 0x494, 0 }, - { "TP_DACK_POP_CNT", 0x498, 0 }, - { "TP_MOD_PUSH_CNT", 0x49c, 0 }, - { "TP_MOD_POP_CNT", 0x4a0, 0 }, - { "TP_TIMER_SEPARATOR", 0x4a4, 0 }, - { "Disable_Past_Timer_Insertion", 0, 1 }, - { "Modulation_Timer_Separator", 1, 15 }, - { "Global_Timer_Separator", 16, 16 }, - { "TP_DEBUG_SEL", 0x4a8, 0 }, - { "TP_CM_FC_MODE", 0x4b0, 0 }, - { "TP_PC_CONGESTION_CNTL", 0x4b4, 0 }, - { "TP_TX_DROP_CONFIG", 0x4b8, 0 }, - { "ENABLE_TX_DROP", 31, 1 }, - { "ENABLE_TX_ERROR", 30, 1 }, - { "DROP_TICKS_CNT", 4, 26 }, - { "NUM_PKTS_DROPPED", 0, 4 }, - { "TP_TX_DROP_COUNT", 0x4bc, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info rat_regs[] = { - { "RAT_ROUTE_CONTROL", 0x580, 0 }, - { "Use_Route_Table", 0, 1 }, - { "Enable_CSPI", 1, 1 }, - { "Enable_PCIX", 2, 1 }, - { "RAT_ROUTE_TABLE_INDEX", 0x584, 0 }, - { "Route_Table_Index", 0, 4 }, - { "RAT_ROUTE_TABLE_DATA", 0x588, 0 }, - { "RAT_NO_ROUTE", 0x58c, 0 }, - { "CPL_Opcode", 0, 8 }, - { "RAT_INTR_ENABLE", 0x590, 0 }, - { "ZeroRouteError", 0, 1 }, - { "CspiFramingError", 1, 1 }, - { "SgeFramingError", 2, 1 }, - { "TpFramingError", 3, 1 }, - { "RAT_INTR_CAUSE", 0x594, 0 }, - { "ZeroRouteError", 0, 1 }, - { "CspiFramingError", 1, 1 }, - { "SgeFramingError", 2, 1 }, - { "TpFramingError", 3, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info cspi_regs[] = { - { "CSPI_RX_AE_WM", 0x810, 0 }, - { "CSPI_RX_AF_WM", 0x814, 0 }, - { "CSPI_CALENDAR_LEN", 0x818, 0 }, - { "CalendarLength", 0, 16 }, - { "CSPI_FIFO_STATUS_ENABLE", 0x820, 0 }, - { "FifoStatusEnable", 0, 1 }, - { "CSPI_MAXBURST1_MAXBURST2", 0x828, 0 }, - { "MaxBurst1", 0, 16 }, - { "MaxBurst2", 16, 16 }, - { "CSPI_TRAIN", 0x82c, 0 }, - { "CSPI_TRAIN_ALPHA", 0, 16 }, - { "CSPI_TRAIN_DATA_MAXT", 16, 16 }, - { "CSPI_INTR_STATUS", 0x848, 0 }, - { "DIP4Err", 0, 1 }, - { "RXDrop", 1, 1 }, - { "TXDrop", 2, 1 }, - { "RXOverflow", 3, 1 }, - { "RAMParityErr", 4, 1 }, - { "CSPI_INTR_ENABLE", 0x84c, 0 }, - { "DIP4Err", 0, 1 }, - { "RXDrop", 1, 1 }, - { "TXDrop", 2, 1 }, - { "RXOverflow", 3, 1 }, - { "RAMParityErr", 4, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info espi_regs[] = { - { "ESPI_SCH_TOKEN0", 0x880, 0 }, - { "SchToken0", 0, 16 }, - { "ESPI_SCH_TOKEN1", 0x884, 0 }, - { "SchToken1", 0, 16 }, - { "ESPI_SCH_TOKEN2", 0x888, 0 }, - { "SchToken2", 0, 16 }, - { "ESPI_SCH_TOKEN3", 0x88c, 0 }, - { "SchToken3", 0, 16 }, - { "ESPI_RX_FIFO_ALMOST_EMPTY_WATERMARK", 0x890, 0 }, - { "AlmostEmpty", 0, 16 }, - { "ESPI_RX_FIFO_ALMOST_FULL_WATERMARK", 0x894, 0 }, - { "AlmostFull", 0, 16 }, - { "ESPI_CALENDAR_LENGTH", 0x898, 0 }, - { "CalendarLength", 0, 16 }, - { "PORT_CONFIG", 0x89c, 0 }, - { "RX_NPorts", 0, 8 }, - { "TX_NPorts", 8, 8 }, - { "ESPI_FIFO_STATUS_ENABLE", 0x8a0, 0 }, - { "RXStatusEnable", 0, 1 }, - { "TXDropEnable", 1, 1 }, - { "RXEndianMode", 2, 1 }, - { "TXEndianMode", 3, 1 }, - { "Intel1010Mode", 4, 1 }, - { "ESPI_MAXBURST1_MAXBURST2", 0x8a8, 0 }, - { "MaxBurst1", 0, 16 }, - { "MaxBurst2", 16, 16 }, - { "ESPI_TRAIN", 0x8ac, 0 }, - { "MaxTrainAlpha", 0, 16 }, - { "MaxTrainData", 16, 16 }, - { "RAM_STATUS", 0x8b0, 0 }, - { "RXFIFOParityError", 0, 10 }, - { "TXFIFOParityError", 10, 10 }, - { "RXFIFOOverflow", 20, 10 }, - { "TX_DROP_COUNT0", 0x8b4, 0 }, - { "TXPort0DropCnt", 0, 16 }, - { "TxPort1DropCnt", 16, 16 }, - { "TX_DROP_COUNT1", 0x8b8, 0 }, - { "TXPort2DropCnt", 0, 16 }, - { "TxPort3DropCnt", 16, 16 }, - { "RX_DROP_COUNT0", 0x8bc, 0 }, - { "RXPort0DropCnt", 0, 16 }, - { "RxPort1DropCnt", 16, 16 }, - { "RX_DROP_COUNT1", 0x8c0, 0 }, - { "RXPort2DropCnt", 0, 16 }, - { "RxPort3DropCnt", 16, 16 }, - { "DIP4_ERROR_COUNT", 0x8c4, 0 }, - { "Dip4ErrorCnt", 0, 12 }, - { "Dip4ErrorCntShadow", 12, 12 }, - { "TriCN_RX_Train_Err", 24, 1 }, - { "TriCN_RX_Training", 25, 1 }, - { "TriCN_RX_Train_OK", 26, 1 }, - { "ESPI_INTR_STATUS", 0x8c8, 0 }, - { "DIP4Err", 0, 1 }, - { "RXDrop", 1, 1 }, - { "TXDrop", 2, 1 }, - { "RXOverflow", 3, 1 }, - { "RAMParityErr", 4, 1 }, - { "DIP2ParityErr", 5, 1 }, - { "ESPI_INTR_ENABLE", 0x8cc, 0 }, - { "DIP4Err", 0, 1 }, - { "RXDrop", 1, 1 }, - { "TXDrop", 2, 1 }, - { "RXOverflow", 3, 1 }, - { "RAMParityErr", 4, 1 }, - { "DIP2ParityErr", 5, 1 }, - { "RX_DROP_THRESHOLD", 0x8d0, 0 }, - { "ESPI_RX_RESET", 0x8ec, 0 }, - { "ESPI_RX_LNK_RST", 0, 1 }, - { "ESPI_RX_CORE_RST", 1, 1 }, - { "RX_CLK_STATUS", 2, 1 }, - { "ESPI_MISC_CONTROL", 0x8f0, 0 }, - { "Out_of_Sync_Count", 0, 4 }, - { "DIP2_Count_Mode_Enable", 4, 1 }, - { "DIP2_Parity_Err_Thres", 5, 4 }, - { "DIP4_Thres", 9, 12 }, - { "DIP4_Thres_Enable", 21, 1 }, - { "Force_Disable_Status", 22, 1 }, - { "Dynamic_Deskew", 23, 1 }, - { "Monitored_Port_Num", 25, 2 }, - { "Monitored_Direction", 27, 1 }, - { "Monitored_Interface", 28, 1 }, - { "ESPI_DIP2_ERR_COUNT", 0x8f4, 0 }, - { "DIP2_Err_Cnt", 0, 4 }, - { "ESPI_CMD_ADDR", 0x8f8, 0 }, - { "Write_Data", 0, 8 }, - { "Register_Offset", 8, 4 }, - { "Channel_Addr", 12, 4 }, - { "Module_Addr", 16, 2 }, - { "Bundle_Addr", 20, 2 }, - { "SPI4_Command", 24, 8 }, - { "ESPI_GOSTAT", 0x8fc, 0 }, - { "Read_Data", 0, 8 }, - { "ESPI_Cmd_Busy", 8, 1 }, - { "Error_Ack", 9, 1 }, - { "Unmapped_Err", 10, 1 }, - { "Transaction_Timer", 16, 8 }, - { NULL, 0, 0 } -}; - -struct reg_info ulp_regs[] = { - { "ULP_ULIMIT", 0x980, 0 }, - { "ULP_TAGMASK", 0x984, 0 }, - { "ULP_HREG_INDEX", 0x988, 0 }, - { "ULP_HREG_DATA", 0x98c, 0 }, - { "ULP_INT_ENABLE", 0x990, 0 }, - { "ULP_INT_CAUSE", 0x994, 0 }, - { "Hreg_Par_Err", 0, 1 }, - { "Egrs_Data_Par_Err", 1, 1 }, - { "Ingrs_Data_Par_Err", 2, 1 }, - { "Pm_Intr", 3, 1 }, - { "Pm_E2C_Sync_Err", 4, 1 }, - { "Pm_C2E_Sync_Err", 5, 1 }, - { "Pm_E2C_Empty_Err", 6, 1 }, - { "Pm_C2E_Empty_Err", 7, 1 }, - { "Pm_Par_Err", 8, 16 }, - { "Pm_E2C_Wrt_Full", 24, 1 }, - { "Pm_C2E_Wrt_Full", 25, 1 }, - { "ULP_PIO_CTRL", 0x998, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info pl_regs[] = { - { "PL_ENABLE", 0xa00, 0 }, - { "PL_Intr_SGE_Err", 0, 1 }, - { "PL_Intr_SGE_Data", 1, 1 }, - { "PL_Intr_MC3", 2, 1 }, - { "PL_Intr_MC4", 3, 1 }, - { "PL_Intr_MC5", 4, 1 }, - { "PL_Intr_RAT", 5, 1 }, - { "PL_Intr_TP", 6, 1 }, - { "PL_Intr_ULP", 7, 1 }, - { "PL_Intr_ESPI", 8, 1 }, - { "PL_Intr_CSPI", 9, 1 }, - { "PL_Intr_PCIX", 10, 1 }, - { "PL_Intr_EXT", 11, 1 }, - { "PL_CAUSE", 0xa04, 0 }, - { "PL_Intr_SGE_Err", 0, 1 }, - { "PL_Intr_SGE_Data", 1, 1 }, - { "PL_Intr_MC3", 2, 1 }, - { "PL_Intr_MC4", 3, 1 }, - { "PL_Intr_MC5", 4, 1 }, - { "PL_Intr_RAT", 5, 1 }, - { "PL_Intr_TP", 6, 1 }, - { "PL_Intr_ULP", 7, 1 }, - { "PL_Intr_ESPI", 8, 1 }, - { "PL_Intr_CSPI", 9, 1 }, - { "PL_Intr_PCIX", 10, 1 }, - { "PL_Intr_EXT", 11, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info mc5_regs[] = { - { "MC5_CONFIG", 0xc04, 0 }, - { "Mode", 0, 1 }, - { "TCAM_Reset", 1, 1 }, - { "TCAM_Ready", 2, 1 }, - { "DBGI_Enable", 4, 1 }, - { "M_Bus_Enable", 5, 1 }, - { "Parity_Enable", 6, 1 }, - { "SYN_Issue_Mode", 7, 2 }, - { "Build", 16, 1 }, - { "Compression_Enable", 17, 1 }, - { "Num_LIP", 18, 6 }, - { "TCAM_Part_Cnt", 24, 2 }, - { "TCAM_Part_Type", 26, 2 }, - { "TCAM_Part_Size", 28, 2 }, - { "TCAM_Part_Type_HI", 30, 1 }, - { "MC5_SIZE", 0xc08, 0 }, - { "Size", 0, 22 }, - { "MC5_ROUTING_TABLE_INDEX", 0xc0c, 0 }, - { "Start_of_Routing_Table", 0, 22 }, - { "MC5_SERVER_INDEX", 0xc14, 0 }, - { "Start_of_Server_Index", 0, 22 }, - { "MC5_LIP_RAM_ADDR", 0xc18, 0 }, - { "Local_IP_RAM_Addr", 0, 6 }, - { "RAM_Write_Enable", 8, 1 }, - { "MC5_LIP_RAM_DATA", 0xc1c, 0 }, - { "MC5_RSP_LATENCY", 0xc20, 0 }, - { "Search_Response_Latency", 0, 5 }, - { "Learn_Response_Latency", 8, 5 }, - { "MC5_PARITY_LATENCY", 0xc24, 0 }, - { "SRCHLAT", 0, 5 }, - { "PARLAT", 8, 5 }, - { "MC5_WR_LRN_VERIFY", 0xc28, 0 }, - { "POVEREN", 0, 1 }, - { "LRNVEREN", 1, 1 }, - { "VWVEREN", 2, 1 }, - { "MC5_PART_ID_INDEX", 0xc2c, 0 }, - { "IDINDEX", 0, 4 }, - { "MC5_RESET_MAX", 0xc30, 0 }, - { "RSTMAX", 0, 9 }, - { "MC5_INT_ENABLE", 0xc40, 0 }, - { "MC5_Int_Hit_Out_Active_Region_Err", 0, 1 }, - { "MC5_Int_Hit_In_Active_Region_Err", 1, 1 }, - { "MC5_Int_Hit_In_RT_Region_Err", 2, 1 }, - { "MC5_Int_Miss_Err", 3, 1 }, - { "MC5_Int_LIP0_Err", 4, 1 }, - { "MC5_Int_LIP_Miss_Err", 5, 1 }, - { "MC5_Int_Parity_Err", 6, 1 }, - { "MC5_Int_Active_Region_Full", 7, 1 }, - { "MC5_Int_NFA_Srch_Err", 8, 1 }, - { "MC5_Int_SYN_Cookie", 9, 1 }, - { "MC5_Int_SYN_Cookie_Bad", 10, 1 }, - { "MC5_Int_SYN_Cookie_Off", 11, 1 }, - { "MC5_Int_Unknown_Cmd", 15, 1 }, - { "MC5_Int_RequestQ_Parity_Err", 16, 1 }, - { "MC5_Int_DispatchQ_Parity_Err", 17, 1 }, - { "MC5_Int_Del_Act_Empty", 18, 1 }, - { "MC5_INT_CAUSE", 0xc44, 0 }, - { "MC5_Int_Hit_Out_Active_Region_Err", 0, 1 }, - { "MC5_Int_Hit_In_Active_Region_Err", 1, 1 }, - { "MC5_Int_Hit_In_RT_Region_Err", 2, 1 }, - { "MC5_Int_Miss_Err", 3, 1 }, - { "MC5_Int_LIP0_Err", 4, 1 }, - { "MC5_Int_LIP_Miss_Err", 5, 1 }, - { "MC5_Int_Parity_Err", 6, 1 }, - { "MC5_Int_Active_Region_Full", 7, 1 }, - { "MC5_Int_NFA_Srch_Err", 8, 1 }, - { "MC5_Int_SYN_Cookie", 9, 1 }, - { "MC5_Int_SYN_Cookie_Bad", 10, 1 }, - { "MC5_Int_SYN_Cookie_Off", 11, 1 }, - { "MC5_Int_Unknown_Cmd", 15, 1 }, - { "MC5_Int_RequestQ_Parity_Err", 16, 1 }, - { "MC5_Int_DispatchQ_Parity_Err", 17, 1 }, - { "MC5_Int_Del_Act_Empty", 18, 1 }, - { "MC5_INT_TID", 0xc48, 0 }, - { "MC5_INT_PTID", 0xc4c, 0 }, - { "MC5_DBGI_CONFIG", 0xc74, 0 }, - { "MC5_DBGI_REQ_CMD", 0xc78, 0 }, - { "CmdMode", 0, 3 }, - { "SADRSEL", 4, 1 }, - { "Write_Burst_Size", 22, 10 }, - { "MC5_DBGI_REQ_ADDR0", 0xc7c, 0 }, - { "MC5_DBGI_REQ_ADDR1", 0xc80, 0 }, - { "MC5_DBGI_REQ_ADDR2", 0xc84, 0 }, - { "MC5_DBGI_REQ_DATA0", 0xc88, 0 }, - { "MC5_DBGI_REQ_DATA1", 0xc8c, 0 }, - { "MC5_DBGI_REQ_DATA2", 0xc90, 0 }, - { "MC5_DBGI_REQ_DATA3", 0xc94, 0 }, - { "MC5_DBGI_REQ_DATA4", 0xc98, 0 }, - { "MC5_DBGI_REQ_MASK0", 0xc9c, 0 }, - { "MC5_DBGI_REQ_MASK1", 0xca0, 0 }, - { "MC5_DBGI_REQ_MASK2", 0xca4, 0 }, - { "MC5_DBGI_REQ_MASK3", 0xca8, 0 }, - { "MC5_DBGI_REQ_MASK4", 0xcac, 0 }, - { "MC5_DBGI_RSP_STATUS", 0xcb0, 0 }, - { "DBGI_Rsp_Valid", 0, 1 }, - { "DBGI_Rsp_Hit", 1, 1 }, - { "DBGI_Rsp_Err", 2, 1 }, - { "DBGI_Rsp_Err_Reason", 8, 3 }, - { "MC5_DBGI_RSP_DATA0", 0xcb4, 0 }, - { "MC5_DBGI_RSP_DATA1", 0xcb8, 0 }, - { "MC5_DBGI_RSP_DATA2", 0xcbc, 0 }, - { "MC5_DBGI_RSP_DATA3", 0xcc0, 0 }, - { "MC5_DBGI_RSP_DATA4", 0xcc4, 0 }, - { "MC5_DBGI_RSP_LAST_CMD", 0xcc8, 0 }, - { "MC5_POPEN_DATA_WR_CMD", 0xccc, 0 }, - { "MC5_POPEN_MASK_WR_CMD", 0xcd0, 0 }, - { "MC5_AOPEN_SRCH_CMD", 0xcd4, 0 }, - { "MC5_AOPEN_LRN_CMD", 0xcd8, 0 }, - { "MC5_SYN_SRCH_CMD", 0xcdc, 0 }, - { "MC5_SYN_LRN_CMD", 0xce0, 0 }, - { "MC5_ACK_SRCH_CMD", 0xce4, 0 }, - { "MC5_ACK_LRN_CMD", 0xce8, 0 }, - { "MC5_ILOOKUP_CMD", 0xcec, 0 }, - { "MC5_ELOOKUP_CMD", 0xcf0, 0 }, - { "MC5_DATA_WRITE_CMD", 0xcf4, 0 }, - { "MC5_DATA_READ_CMD", 0xcf8, 0 }, - { "MC5_MASK_WRITE_CMD", 0xcfc, 0 }, - { NULL, 0, 0 } -}; diff --git a/usr.sbin/cxgbtool/reg_defs_t3.c b/usr.sbin/cxgbtool/reg_defs_t3.c deleted file mode 100644 index 6e9b8b1..0000000 --- a/usr.sbin/cxgbtool/reg_defs_t3.c +++ /dev/null @@ -1,2676 +0,0 @@ -/* - * $FreeBSD$ - */ - - -/* This file is automatically generated --- do not edit */ - -struct reg_info sge3_regs[] = { - { "SG_CONTROL", 0x0, 0 }, - { "EgrEnUpBp", 21, 1 }, - { "DropPkt", 20, 1 }, - { "EgrGenCtrl", 19, 1 }, - { "UserSpaceSize", 14, 5 }, - { "HostPageSize", 11, 3 }, - { "PCIRelax", 10, 1 }, - { "FLMode", 9, 1 }, - { "PktShift", 6, 3 }, - { "OneIntMultQ", 5, 1 }, - { "FLPickAvail", 4, 1 }, - { "BigEndianEgress", 3, 1 }, - { "BigEndianIngress", 2, 1 }, - { "IscsiCoalescing", 1, 1 }, - { "GlobalEnable", 0, 1 }, - { "SG_KDOORBELL", 0x4, 0 }, - { "SelEgrCntx", 31, 1 }, - { "EgrCntx", 0, 16 }, - { "SG_GTS", 0x8, 0 }, - { "RspQ", 29, 3 }, - { "NewTimer", 16, 13 }, - { "NewIndex", 0, 16 }, - { "SG_CONTEXT_CMD", 0xc, 0 }, - { "Opcode", 28, 4 }, - { "Busy", 27, 1 }, - { "CQ_credit", 20, 7 }, - { "CQ", 19, 1 }, - { "RspQ", 18, 1 }, - { "Egress", 17, 1 }, - { "FreeList", 16, 1 }, - { "Context", 0, 16 }, - { "SG_CONTEXT_DATA0", 0x10, 0 }, - { "SG_CONTEXT_DATA1", 0x14, 0 }, - { "SG_CONTEXT_DATA2", 0x18, 0 }, - { "SG_CONTEXT_DATA3", 0x1c, 0 }, - { "SG_CONTEXT_MASK0", 0x20, 0 }, - { "SG_CONTEXT_MASK1", 0x24, 0 }, - { "SG_CONTEXT_MASK2", 0x28, 0 }, - { "SG_CONTEXT_MASK3", 0x2c, 0 }, - { "SG_RSPQ_CREDIT_RETURN", 0x30, 0 }, - { "RspQ", 29, 3 }, - { "Data", 0, 16 }, - { "SG_HI_DRB_HI_THRSH", 0x38, 0 }, - { "HiDrbHiThrsh", 0, 10 }, - { "SG_HI_DRB_LO_THRSH", 0x3c, 0 }, - { "HiDrbLoThrsh", 0, 10 }, - { "SG_LO_DRB_HI_THRSH", 0x40, 0 }, - { "LoDrbHiThrsh", 0, 10 }, - { "SG_LO_DRB_LO_THRSH", 0x44, 0 }, - { "LoDrbLoThrsh", 0, 10 }, - { "SG_ONE_INT_MULT_Q_COALESCING_TIMER", 0x48, 0 }, - { "SG_RSPQ_FL_STATUS", 0x4c, 0 }, - { "RspQ0Starved", 0, 1 }, - { "RspQ1Starved", 1, 1 }, - { "RspQ2Starved", 2, 1 }, - { "RspQ3Starved", 3, 1 }, - { "RspQ4Starved", 4, 1 }, - { "RspQ5Starved", 5, 1 }, - { "RspQ6Starved", 6, 1 }, - { "RspQ7Starved", 7, 1 }, - { "RspQ0Disabled", 8, 1 }, - { "RspQ1Disabled", 9, 1 }, - { "RspQ2Disabled", 10, 1 }, - { "RspQ3Disabled", 11, 1 }, - { "RspQ4Disabled", 12, 1 }, - { "RspQ5Disabled", 13, 1 }, - { "RspQ6Disabled", 14, 1 }, - { "RspQ7Disabled", 15, 1 }, - { "FL0Empty", 16, 1 }, - { "FL1Empty", 17, 1 }, - { "FL2Empty", 18, 1 }, - { "FL3Empty", 19, 1 }, - { "FL4Empty", 20, 1 }, - { "FL5Empty", 21, 1 }, - { "FL6Empty", 22, 1 }, - { "FL7Empty", 23, 1 }, - { "FL8Empty", 24, 1 }, - { "FL9Empty", 25, 1 }, - { "FL10Empty", 26, 1 }, - { "FL11Empty", 27, 1 }, - { "FL12Empty", 28, 1 }, - { "FL13Empty", 29, 1 }, - { "FL14Empty", 30, 1 }, - { "FL15Empty", 31, 1 }, - { "SG_EGR_PRI_CNT", 0x50, 0 }, - { "EgrPriCnt", 0, 5 }, - { "SG_EGR_RCQ_DRB_THRSH", 0x54, 0 }, - { "HiRcqDrbThrsh", 16, 11 }, - { "LoRcqDrbThrsh", 0, 11 }, - { "SG_EGR_CNTX_BADDR", 0x58, 0 }, - { "EgrCntxBAddr", 5, 27 }, - { "SG_INT_CAUSE", 0x5c, 0 }, - { "HiCtlDrbDropErr", 13, 1 }, - { "LoCtlDrbDropErr", 12, 1 }, - { "HiPioDrbDropErr", 11, 1 }, - { "LoPioDrbDropErr", 10, 1 }, - { "HiCrdtUndFlowErr", 9, 1 }, - { "LoCrdtUndFlowErr", 8, 1 }, - { "HiPriorityDBFull", 7, 1 }, - { "HiPriorityDBEmpty", 6, 1 }, - { "LoPriorityDBFull", 5, 1 }, - { "LoPriorityDBEmpty", 4, 1 }, - { "RspQDisabled", 3, 1 }, - { "RspQCreditOverfow", 2, 1 }, - { "FlEmpty", 1, 1 }, - { "RspQStarve", 0, 1 }, - { "SG_INT_ENABLE", 0x60, 0 }, - { "HiCtlDrbDropErr", 13, 1 }, - { "LoCtlDrbDropErr", 12, 1 }, - { "HiPioDrbDropErr", 11, 1 }, - { "LoPioDrbDropErr", 10, 1 }, - { "HiCrdtUndFlowErr", 9, 1 }, - { "LoCrdtUndFlowErr", 8, 1 }, - { "HiPriorityDBFull", 7, 1 }, - { "HiPriorityDBEmpty", 6, 1 }, - { "LoPriorityDBFull", 5, 1 }, - { "LoPriorityDBEmpty", 4, 1 }, - { "RspQDisabled", 3, 1 }, - { "RspQCreditOverfow", 2, 1 }, - { "FlEmpty", 1, 1 }, - { "RspQStarve", 0, 1 }, - { "SG_CMDQ_CREDIT_TH", 0x64, 0 }, - { "Timeout", 8, 24 }, - { "Threshold", 0, 8 }, - { "SG_TIMER_TICK", 0x68, 0 }, - { "SG_CQ_CONTEXT_BADDR", 0x6c, 0 }, - { "baseAddr", 5, 27 }, - { "SG_OCO_BASE", 0x70, 0 }, - { "Base1", 16, 16 }, - { "Base0", 0, 16 }, - { "SG_DRB_PRI_THRESH", 0x74, 0 }, - { "DrbPriThrsh", 0, 16 }, - { "SG_DEBUG_INDEX", 0x78, 0 }, - { "SG_DEBUG_DATA", 0x7c, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info pcix1_regs[] = { - { "PCIX_INT_ENABLE", 0x80, 0 }, - { "MSIXParErr", 22, 3 }, - { "CFParErr", 18, 4 }, - { "RFParErr", 14, 4 }, - { "WFParErr", 12, 2 }, - { "PIOParErr", 11, 1 }, - { "DetUncECCErr", 10, 1 }, - { "DetCorECCErr", 9, 1 }, - { "RcvSplCmpErr", 8, 1 }, - { "UnxSplCmp", 7, 1 }, - { "SplCmpDis", 6, 1 }, - { "DetParErr", 5, 1 }, - { "SigSysErr", 4, 1 }, - { "RcvMstAbt", 3, 1 }, - { "RcvTarAbt", 2, 1 }, - { "SigTarAbt", 1, 1 }, - { "MstDetParErr", 0, 1 }, - { "PCIX_INT_CAUSE", 0x84, 0 }, - { "MSIXParErr", 22, 3 }, - { "CFParErr", 18, 4 }, - { "RFParErr", 14, 4 }, - { "WFParErr", 12, 2 }, - { "PIOParErr", 11, 1 }, - { "DetUncECCErr", 10, 1 }, - { "DetCorECCErr", 9, 1 }, - { "RcvSplCmpErr", 8, 1 }, - { "UnxSplCmp", 7, 1 }, - { "SplCmpDis", 6, 1 }, - { "DetParErr", 5, 1 }, - { "SigSysErr", 4, 1 }, - { "RcvMstAbt", 3, 1 }, - { "RcvTarAbt", 2, 1 }, - { "SigTarAbt", 1, 1 }, - { "MstDetParErr", 0, 1 }, - { "PCIX_CFG", 0x88, 0 }, - { "CLIDecEn", 18, 1 }, - { "LatTmrDis", 17, 1 }, - { "LowPwrEn", 16, 1 }, - { "AsyncIntVec", 11, 5 }, - { "MaxSplTrnC", 8, 3 }, - { "MaxSplTrnR", 5, 3 }, - { "MaxWrByteCnt", 3, 2 }, - { "WrReqAtomicEn", 2, 1 }, - { "CRstWrmMode", 1, 1 }, - { "PIOAck64En", 0, 1 }, - { "PCIX_MODE", 0x8c, 0 }, - { "PClkRange", 6, 2 }, - { "PCIXInitPat", 2, 4 }, - { "66MHz", 1, 1 }, - { "64Bit", 0, 1 }, - { "PCIX_CAL", 0x90, 0 }, - { "Busy", 31, 1 }, - { "PerCalDiv", 22, 8 }, - { "PerCalEn", 21, 1 }, - { "SglCalEn", 20, 1 }, - { "ZInUpdMode", 19, 1 }, - { "ZInSel", 18, 1 }, - { "ZPDMan", 15, 3 }, - { "ZPUMan", 12, 3 }, - { "ZPDOut", 9, 3 }, - { "ZPUOut", 6, 3 }, - { "ZPDIn", 3, 3 }, - { "ZPUIn", 0, 3 }, - { "PCIX_WOL", 0x94, 0 }, - { "WakeUp1", 3, 1 }, - { "WakeUp0", 2, 1 }, - { "SleepMode1", 1, 1 }, - { "SleepMode0", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info pcie0_regs[] = { - { "PCIE_INT_ENABLE", 0x80, 0 }, - { "BISTErr", 15, 8 }, - { "MSIXParErr", 12, 3 }, - { "CFParErr", 11, 1 }, - { "RFParErr", 10, 1 }, - { "WFParErr", 9, 1 }, - { "PIOParErr", 8, 1 }, - { "UnxSplCplErrC", 7, 1 }, - { "UnxSplCplErrR", 6, 1 }, - { "VPDAddrChng", 5, 1 }, - { "BusMstrEn", 4, 1 }, - { "PMStChng", 3, 1 }, - { "PEXMsg", 2, 1 }, - { "ZeroLenRd", 1, 1 }, - { "PEXErr", 0, 1 }, - { "PCIE_INT_CAUSE", 0x84, 0 }, - { "BISTErr", 15, 8 }, - { "MSIXParErr", 12, 3 }, - { "CFParErr", 11, 1 }, - { "RFParErr", 10, 1 }, - { "WFParErr", 9, 1 }, - { "PIOParErr", 8, 1 }, - { "UnxSplCplErrC", 7, 1 }, - { "UnxSplCplErrR", 6, 1 }, - { "VPDAddrChng", 5, 1 }, - { "BusMstrEn", 4, 1 }, - { "PMStChng", 3, 1 }, - { "PEXMsg", 2, 1 }, - { "ZeroLenRd", 1, 1 }, - { "PEXErr", 0, 1 }, - { "PCIE_CFG", 0x88, 0 }, - { "EnableLinkDwnDRst", 21, 1 }, - { "EnableLinkDownRst", 20, 1 }, - { "EnableHotRst", 19, 1 }, - { "IniWaitForGnt", 18, 1 }, - { "IniBEDis", 17, 1 }, - { "CLIDecEn", 16, 1 }, - { "AsyncIntVec", 11, 5 }, - { "MaxSplTrnC", 7, 4 }, - { "MaxSplTrnR", 1, 6 }, - { "CRstWrmMode", 0, 1 }, - { "PCIE_MODE", 0x8c, 0 }, - { "LnkCntlState", 2, 8 }, - { "VC0Up", 1, 1 }, - { "LnkInitial", 0, 1 }, - { "PCIE_CAL", 0x90, 0 }, - { "CalBusy", 31, 1 }, - { "CalFault", 30, 1 }, - { "ZInSel", 11, 1 }, - { "ZMan", 8, 3 }, - { "ZOut", 3, 5 }, - { "ZIn", 0, 3 }, - { "PCIE_WOL", 0x94, 0 }, - { "WakeUp1", 3, 1 }, - { "WakeUp0", 2, 1 }, - { "SleepMode1", 1, 1 }, - { "SleepMode0", 0, 1 }, - { "PCIE_PEX_CTRL0", 0x98, 0 }, - { "NumFstTrnSeq", 22, 8 }, - { "ReplayLmt", 2, 20 }, - { "TxPndChkEn", 1, 1 }, - { "CplPndChkEn", 0, 1 }, - { "PCIE_PEX_CTRL1", 0x9c, 0 }, - { "DLLPTimeoutLmt", 11, 20 }, - { "AckLat", 0, 11 }, - { "PCIE_PEX_CTRL2", 0xa0, 0 }, - { "PMExitL1Req", 29, 1 }, - { "PMTxIdle", 28, 1 }, - { "PCIModeLoop", 27, 1 }, - { "L1ASPMTxRxL0sTime", 15, 12 }, - { "L0sIdleTime", 4, 11 }, - { "EnterL23", 3, 1 }, - { "EnterL1ASPMEn", 2, 1 }, - { "EnterL1En", 1, 1 }, - { "EnterL0sEn", 0, 1 }, - { "PCIE_PEX_ERR", 0xa4, 0 }, - { "FlowCtlOFlowErr", 17, 1 }, - { "ReplayTimeout", 16, 1 }, - { "ReplayRollover", 15, 1 }, - { "BadDLLP", 14, 1 }, - { "DLLPErr", 13, 1 }, - { "FlowCtlProtErr", 12, 1 }, - { "CplTimeout", 11, 1 }, - { "PHYRcvErr", 10, 1 }, - { "DisTLP", 9, 1 }, - { "BadECRC", 8, 1 }, - { "BadTLP", 7, 1 }, - { "MalTLP", 6, 1 }, - { "UnxCpl", 5, 1 }, - { "UnsReq", 4, 1 }, - { "PsnReq", 3, 1 }, - { "UnsCpl", 2, 1 }, - { "CplAbt", 1, 1 }, - { "PsnCpl", 0, 1 }, - { "PCIE_PIPE_CTRL", 0xa8, 0 }, - { "RecDetUsec", 19, 3 }, - { "PLLLckCyc", 6, 13 }, - { "ElecIdleDetCyc", 3, 3 }, - { "UseCDRLOS", 2, 1 }, - { "PClkReqInP1", 1, 1 }, - { "PClkOffInP1", 0, 1 }, - { "PCIE_SERDES_CTRL", 0xac, 0 }, - { "ManMode", 31, 1 }, - { "ManLpbkEn", 29, 2 }, - { "ManTxRecDetEn", 28, 1 }, - { "ManTxBeacon", 27, 1 }, - { "ManTxEI", 26, 1 }, - { "ManRxPolarity", 25, 1 }, - { "ManTxRst", 24, 1 }, - { "ManRxRst", 23, 1 }, - { "ManTxEn", 22, 1 }, - { "ManRxEn", 21, 1 }, - { "ManEn", 20, 1 }, - { "CMURange", 17, 3 }, - { "BGEnb", 16, 1 }, - { "EnSkpDrop", 15, 1 }, - { "EnComma", 14, 1 }, - { "En8B10B", 13, 1 }, - { "EnElBuf", 12, 1 }, - { "Gain", 7, 5 }, - { "BandGap", 3, 4 }, - { "RxComAdj", 2, 1 }, - { "PreEmph", 0, 2 }, - { "PCIE_SERDES_STATUS0", 0xb0, 0 }, - { "RxErrLane7", 21, 3 }, - { "RxErrLane6", 18, 3 }, - { "RxErrLane5", 15, 3 }, - { "RxErrLane4", 12, 3 }, - { "RxErrLane3", 9, 3 }, - { "RxErrLane2", 6, 3 }, - { "RxErrLane1", 3, 3 }, - { "RxErrLane0", 0, 3 }, - { "PCIE_SERDES_STATUS1", 0xb4, 0 }, - { "CMULock", 31, 1 }, - { "RxKLockLane7", 23, 1 }, - { "RxKLockLane6", 22, 1 }, - { "RxKLockLane5", 21, 1 }, - { "RxKLockLane4", 20, 1 }, - { "RxKLockLane3", 19, 1 }, - { "RxKLockLane2", 18, 1 }, - { "RxKLockLane1", 17, 1 }, - { "RxKLockLane0", 16, 1 }, - { "RxUFlowLane7", 15, 1 }, - { "RxUFlowLane6", 14, 1 }, - { "RxUFlowLane5", 13, 1 }, - { "RxUFlowLane4", 12, 1 }, - { "RxUFlowLane3", 11, 1 }, - { "RxUFlowLane2", 10, 1 }, - { "RxUFlowLane1", 9, 1 }, - { "RxUFlowLane0", 8, 1 }, - { "RxOFlowLane7", 7, 1 }, - { "RxOFlowLane6", 6, 1 }, - { "RxOFlowLane5", 5, 1 }, - { "RxOFlowLane4", 4, 1 }, - { "RxOFlowLane3", 3, 1 }, - { "RxOFlowLane2", 2, 1 }, - { "RxOFlowLane1", 1, 1 }, - { "RxOFlowLane0", 0, 1 }, - { "PCIE_SERDES_STATUS2", 0xb8, 0 }, - { "TxRecDetLane7", 31, 1 }, - { "TxRecDetLane6", 30, 1 }, - { "TxRecDetLane5", 29, 1 }, - { "TxRecDetLane4", 28, 1 }, - { "TxRecDetLane3", 27, 1 }, - { "TxRecDetLane2", 26, 1 }, - { "TxRecDetLane1", 25, 1 }, - { "TxRecDetLane0", 24, 1 }, - { "RxEIDLane7", 23, 1 }, - { "RxEIDLane6", 22, 1 }, - { "RxEIDLane5", 21, 1 }, - { "RxEIDLane4", 20, 1 }, - { "RxEIDLane3", 19, 1 }, - { "RxEIDLane2", 18, 1 }, - { "RxEIDLane1", 17, 1 }, - { "RxEIDLane0", 16, 1 }, - { "RxRemSkipLane7", 15, 1 }, - { "RxRemSkipLane6", 14, 1 }, - { "RxRemSkipLane5", 13, 1 }, - { "RxRemSkipLane4", 12, 1 }, - { "RxRemSkipLane3", 11, 1 }, - { "RxRemSkipLane2", 10, 1 }, - { "RxRemSkipLane1", 9, 1 }, - { "RxRemSkipLane0", 8, 1 }, - { "RxAddSkipLane7", 7, 1 }, - { "RxAddSkipLane6", 6, 1 }, - { "RxAddSkipLane5", 5, 1 }, - { "RxAddSkipLane4", 4, 1 }, - { "RxAddSkipLane3", 3, 1 }, - { "RxAddSkipLane2", 2, 1 }, - { "RxAddSkipLane1", 1, 1 }, - { "RxAddSkipLane0", 0, 1 }, - { "PCIE_SERDES_BIST", 0xbc, 0 }, - { "BISTDone", 24, 8 }, - { "BISTCycleThresh", 3, 16 }, - { "BISTMode", 0, 3 }, - { NULL, 0, 0 } -}; - -struct reg_info t3dbg_regs[] = { - { "T3DBG_DBG0_CFG", 0xc0, 0 }, - { "RegSelect", 9, 8 }, - { "ModuleSelect", 4, 5 }, - { "ClkSelect", 0, 4 }, - { "T3DBG_DBG0_EN", 0xc4, 0 }, - { "SDRByte0", 8, 1 }, - { "DDREn", 4, 1 }, - { "PortEn", 0, 1 }, - { "T3DBG_DBG1_CFG", 0xc8, 0 }, - { "RegSelect", 9, 8 }, - { "ModuleSelect", 4, 5 }, - { "ClkSelect", 0, 4 }, - { "T3DBG_DBG1_EN", 0xcc, 0 }, - { "SDRByte0", 8, 1 }, - { "DDREn", 4, 1 }, - { "PortEn", 0, 1 }, - { "T3DBG_GPIO_EN", 0xd0, 0 }, - { "GPIO11_OEn", 27, 1 }, - { "GPIO10_OEn", 26, 1 }, - { "GPIO9_OEn", 25, 1 }, - { "GPIO8_OEn", 24, 1 }, - { "GPIO7_OEn", 23, 1 }, - { "GPIO6_OEn", 22, 1 }, - { "GPIO5_OEn", 21, 1 }, - { "GPIO4_OEn", 20, 1 }, - { "GPIO3_OEn", 19, 1 }, - { "GPIO2_OEn", 18, 1 }, - { "GPIO1_OEn", 17, 1 }, - { "GPIO0_OEn", 16, 1 }, - { "GPIO11_Out_Val", 11, 1 }, - { "GPIO10_Out_Val", 10, 1 }, - { "GPIO9_Out_Val", 9, 1 }, - { "GPIO8_Out_Val", 8, 1 }, - { "GPIO7_Out_Val", 7, 1 }, - { "GPIO6_Out_Val", 6, 1 }, - { "GPIO5_Out_Val", 5, 1 }, - { "GPIO4_Out_Val", 4, 1 }, - { "GPIO3_Out_Val", 3, 1 }, - { "GPIO2_Out_Val", 2, 1 }, - { "GPIO1_Out_Val", 1, 1 }, - { "GPIO0_Out_Val", 0, 1 }, - { "T3DBG_GPIO_IN", 0xd4, 0 }, - { "GPIO11_IN", 11, 1 }, - { "GPIO10_IN", 10, 1 }, - { "GPIO9_IN", 9, 1 }, - { "GPIO8_IN", 8, 1 }, - { "GPIO7_IN", 7, 1 }, - { "GPIO6_IN", 6, 1 }, - { "GPIO5_IN", 5, 1 }, - { "GPIO4_IN", 4, 1 }, - { "GPIO3_IN", 3, 1 }, - { "GPIO2_IN", 2, 1 }, - { "GPIO1_IN", 1, 1 }, - { "GPIO0_IN", 0, 1 }, - { "T3DBG_INT_ENABLE", 0xd8, 0 }, - { "C_LOCK", 21, 1 }, - { "M_LOCK", 20, 1 }, - { "U_LOCK", 19, 1 }, - { "R_LOCK", 18, 1 }, - { "PX_LOCK", 17, 1 }, - { "PE_LOCK", 16, 1 }, - { "GPIO11", 11, 1 }, - { "GPIO10", 10, 1 }, - { "GPIO9", 9, 1 }, - { "GPIO8", 8, 1 }, - { "GPIO7", 7, 1 }, - { "GPIO6", 6, 1 }, - { "GPIO5", 5, 1 }, - { "GPIO4", 4, 1 }, - { "GPIO3", 3, 1 }, - { "GPIO2", 2, 1 }, - { "GPIO1", 1, 1 }, - { "GPIO0", 0, 1 }, - { "T3DBG_INT_CAUSE", 0xdc, 0 }, - { "C_LOCK", 21, 1 }, - { "M_LOCK", 20, 1 }, - { "U_LOCK", 19, 1 }, - { "R_LOCK", 18, 1 }, - { "PX_LOCK", 17, 1 }, - { "PE_LOCK", 16, 1 }, - { "GPIO11", 11, 1 }, - { "GPIO10", 10, 1 }, - { "GPIO9", 9, 1 }, - { "GPIO8", 8, 1 }, - { "GPIO7", 7, 1 }, - { "GPIO6", 6, 1 }, - { "GPIO5", 5, 1 }, - { "GPIO4", 4, 1 }, - { "GPIO3", 3, 1 }, - { "GPIO2", 2, 1 }, - { "GPIO1", 1, 1 }, - { "GPIO0", 0, 1 }, - { "T3DBG_DBG0_RST_VALUE", 0xe0, 0 }, - { "DebugData", 0, 1 }, - { "T3DBG_PLL_OCLK_PAD_EN", 0xe4, 0 }, - { "PCIE_OCLK_En", 20, 1 }, - { "PCIX_OCLK_En", 16, 1 }, - { "U_OCLK_En", 12, 1 }, - { "R_OCLK_En", 8, 1 }, - { "M_OCLK_En", 4, 1 }, - { "C_OCLK_En", 0, 1 }, - { "T3DBG_PLL_LOCK", 0xe8, 0 }, - { "PCIE_LOCK", 20, 1 }, - { "PCIX_LOCK", 16, 1 }, - { "U_LOCK", 12, 1 }, - { "R_LOCK", 8, 1 }, - { "M_LOCK", 4, 1 }, - { "C_LOCK", 0, 1 }, - { "T3DBG_SERDES_RBC_CFG", 0xec, 0 }, - { "X_RBC_Lane_Sel", 16, 1 }, - { "X_RBC_Dbg_En", 12, 1 }, - { "X_Serdes_Sel", 8, 1 }, - { "PE_RBC_Lane_Sel", 4, 1 }, - { "PE_RBC_Dbg_En", 0, 1 }, - { "T3DBG_GPIO_ACT_LOW", 0xf0, 0 }, - { "C_LOCK_ACT_LOW", 21, 1 }, - { "M_LOCK_ACT_LOW", 20, 1 }, - { "U_LOCK_ACT_LOW", 19, 1 }, - { "R_LOCK_ACT_LOW", 18, 1 }, - { "PX_LOCK_ACT_LOW", 17, 1 }, - { "PE_LOCK_ACT_LOW", 16, 1 }, - { "GPIO11_ACT_LOW", 11, 1 }, - { "GPIO10_ACT_LOW", 10, 1 }, - { "GPIO9_ACT_LOW", 9, 1 }, - { "GPIO8_ACT_LOW", 8, 1 }, - { "GPIO7_ACT_LOW", 7, 1 }, - { "GPIO6_ACT_LOW", 6, 1 }, - { "GPIO5_ACT_LOW", 5, 1 }, - { "GPIO4_ACT_LOW", 4, 1 }, - { "GPIO3_ACT_LOW", 3, 1 }, - { "GPIO2_ACT_LOW", 2, 1 }, - { "GPIO1_ACT_LOW", 1, 1 }, - { "GPIO0_ACT_LOW", 0, 1 }, - { "T3DBG_PMON_CFG", 0xf4, 0 }, - { "PMON_DONE", 29, 1 }, - { "PMON_FAIL", 28, 1 }, - { "PMON_FDEL_AUTO", 22, 1 }, - { "PMON_CDEL_AUTO", 16, 1 }, - { "PMON_FDEL_MANUAL", 10, 1 }, - { "PMON_CDEL_MANUAL", 4, 1 }, - { "PMON_MANUAL", 1, 1 }, - { "PMON_AUTO", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info mc7_pmrx_regs[] = { - { "MC7_CFG", 0x100, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x104, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x108, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x10c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x110, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x114, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x118, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x11c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x120, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x124, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x128, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ECC", 0x130, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x134, 0 }, - { "MC7_CE_DATA0", 0x138, 0 }, - { "MC7_CE_DATA1", 0x13c, 0 }, - { "MC7_CE_DATA2", 0x140, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x144, 0 }, - { "MC7_UE_DATA0", 0x148, 0 }, - { "MC7_UE_DATA1", 0x14c, 0 }, - { "MC7_UE_DATA2", 0x150, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x154, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x158, 0 }, - { "MC7_BD_DATA1", 0x15c, 0 }, - { "MC7_BD_DATA2", 0x160, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x164, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x168, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x16c, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x170, 0 }, - { "MC7_BIST_OP", 0x174, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x178, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x17c, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info mc7_pmtx_regs[] = { - { "MC7_CFG", 0x180, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x184, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x188, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x18c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x190, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x194, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x198, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x19c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x1a0, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x1a4, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x1a8, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ECC", 0x1b0, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x1b4, 0 }, - { "MC7_CE_DATA0", 0x1b8, 0 }, - { "MC7_CE_DATA1", 0x1bc, 0 }, - { "MC7_CE_DATA2", 0x1c0, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x1c4, 0 }, - { "MC7_UE_DATA0", 0x1c8, 0 }, - { "MC7_UE_DATA1", 0x1cc, 0 }, - { "MC7_UE_DATA2", 0x1d0, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x1d4, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x1d8, 0 }, - { "MC7_BD_DATA1", 0x1dc, 0 }, - { "MC7_BD_DATA2", 0x1e0, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x1e4, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x1e8, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x1ec, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x1f0, 0 }, - { "MC7_BIST_OP", 0x1f4, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x1f8, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x1fc, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info mc7_cm_regs[] = { - { "MC7_CFG", 0x200, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x204, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x208, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x20c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x210, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x214, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x218, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x21c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x220, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x224, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x228, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ECC", 0x230, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x234, 0 }, - { "MC7_CE_DATA0", 0x238, 0 }, - { "MC7_CE_DATA1", 0x23c, 0 }, - { "MC7_CE_DATA2", 0x240, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x244, 0 }, - { "MC7_UE_DATA0", 0x248, 0 }, - { "MC7_UE_DATA1", 0x24c, 0 }, - { "MC7_UE_DATA2", 0x250, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x254, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x258, 0 }, - { "MC7_BD_DATA1", 0x25c, 0 }, - { "MC7_BD_DATA2", 0x260, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x264, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x268, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x26c, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x270, 0 }, - { "MC7_BIST_OP", 0x274, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x278, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x27c, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info cim_regs[] = { - { "CIM_BOOT_CFG", 0x280, 0 }, - { "BootAddr", 2, 30 }, - { "BootSdram", 1, 1 }, - { "uPCRst", 0, 1 }, - { "CIM_FLASH_BASE_ADDR", 0x284, 0 }, - { "FlashBaseAddr", 2, 22 }, - { "CIM_FLASH_ADDR_SIZE", 0x288, 0 }, - { "FlashAddrSize", 2, 22 }, - { "CIM_SDRAM_BASE_ADDR", 0x28c, 0 }, - { "SdramBaseAddr", 2, 30 }, - { "CIM_SDRAM_ADDR_SIZE", 0x290, 0 }, - { "SdramAddrSize", 2, 30 }, - { "CIM_UP_SPARE_INT", 0x294, 0 }, - { "uPSpareInt", 0, 3 }, - { "CIM_HOST_INT_ENABLE", 0x298, 0 }, - { "Timer1IntEn", 15, 1 }, - { "Timer0IntEn", 14, 1 }, - { "PrefDropIntEn", 13, 1 }, - { "BlkWrPlIntEn", 12, 1 }, - { "BlkRdPlIntEn", 11, 1 }, - { "BlkWrCtlIntEn", 10, 1 }, - { "BlkRdCtlIntEn", 9, 1 }, - { "BlkWrFlashIntEn", 8, 1 }, - { "BlkRdFlashIntEn", 7, 1 }, - { "SglWrFlashIntEn", 6, 1 }, - { "WrBlkFlashIntEn", 5, 1 }, - { "BlkWrBootIntEn", 4, 1 }, - { "BlkRdBootIntEn", 3, 1 }, - { "FlashRangeIntEn", 2, 1 }, - { "SdramRangeIntEn", 1, 1 }, - { "RsvdSpaceIntEn", 0, 1 }, - { "CIM_HOST_INT_CAUSE", 0x29c, 0 }, - { "Timer1Int", 15, 1 }, - { "Timer0Int", 14, 1 }, - { "PrefDropInt", 13, 1 }, - { "BlkWrPlInt", 12, 1 }, - { "BlkRdPlInt", 11, 1 }, - { "BlkWrCtlInt", 10, 1 }, - { "BlkRdCtlInt", 9, 1 }, - { "BlkWrFlashInt", 8, 1 }, - { "BlkRdFlashInt", 7, 1 }, - { "SglWrFlashInt", 6, 1 }, - { "WrBlkFlashInt", 5, 1 }, - { "BlkWrBootInt", 4, 1 }, - { "BlkRdBootInt", 3, 1 }, - { "FlashRangeInt", 2, 1 }, - { "SdramRangeInt", 1, 1 }, - { "RsvdSpaceInt", 0, 1 }, - { "CIM_UP_INT_ENABLE", 0x2a0, 0 }, - { "MstPlIntEn", 16, 1 }, - { "Timer1IntEn", 15, 1 }, - { "Timer0IntEn", 14, 1 }, - { "PrefDropIntEn", 13, 1 }, - { "BlkWrPlIntEn", 12, 1 }, - { "BlkRdPlIntEn", 11, 1 }, - { "BlkWrCtlIntEn", 10, 1 }, - { "BlkRdCtlIntEn", 9, 1 }, - { "BlkWrFlashIntEn", 8, 1 }, - { "BlkRdFlashIntEn", 7, 1 }, - { "SglWrFlashIntEn", 6, 1 }, - { "WrBlkFlashIntEn", 5, 1 }, - { "BlkWrBootIntEn", 4, 1 }, - { "BlkRdBootIntEn", 3, 1 }, - { "FlashRangeIntEn", 2, 1 }, - { "SdramRangeIntEn", 1, 1 }, - { "RsvdSpaceIntEn", 0, 1 }, - { "CIM_UP_INT_CAUSE", 0x2a4, 0 }, - { "MstPlInt", 16, 1 }, - { "Timer1Int", 15, 1 }, - { "Timer0Int", 14, 1 }, - { "PrefDropInt", 13, 1 }, - { "BlkWrPlInt", 12, 1 }, - { "BlkRdPlInt", 11, 1 }, - { "BlkWrCtlInt", 10, 1 }, - { "BlkRdCtlInt", 9, 1 }, - { "BlkWrFlashInt", 8, 1 }, - { "BlkRdFlashInt", 7, 1 }, - { "SglWrFlashInt", 6, 1 }, - { "WrBlkFlashInt", 5, 1 }, - { "BlkWrBootInt", 4, 1 }, - { "BlkRdBootInt", 3, 1 }, - { "FlashRangeInt", 2, 1 }, - { "SdramRangeInt", 1, 1 }, - { "RsvdSpaceInt", 0, 1 }, - { "CIM_IBQ_FULLA_THRSH", 0x2a8, 0 }, - { "Ibq0FullThrsh", 0, 9 }, - { "Ibq1FullThrsh", 16, 9 }, - { "CIM_IBQ_FULLB_THRSH", 0x2ac, 0 }, - { "Ibq2FullThrsh", 0, 9 }, - { "Ibq3FullThrsh", 16, 9 }, - { "CIM_HOST_ACC_CTRL", 0x2b0, 0 }, - { "HostBusy", 17, 1 }, - { "HostWrite", 16, 1 }, - { "HostAddr", 0, 16 }, - { "CIM_HOST_ACC_DATA", 0x2b4, 0 }, - { "CIM_IBQ_DBG_CFG", 0x2c0, 0 }, - { "IbqDbgAddr", 16, 9 }, - { "IbqDbgQID", 3, 2 }, - { "IbqDbgWr", 2, 1 }, - { "IbqDbgBusy", 1, 1 }, - { "IbqDbgEn", 0, 1 }, - { "CIM_OBQ_DBG_CFG", 0x2c4, 0 }, - { "ObqDbgAddr", 16, 9 }, - { "ObqDbgQID", 3, 2 }, - { "ObqDbgWr", 2, 1 }, - { "ObqDbgBusy", 1, 1 }, - { "ObqDbgEn", 0, 1 }, - { "CIM_IBQ_DBG_DATA", 0x2c8, 0 }, - { "CIM_OBQ_DBG_DATA", 0x2cc, 0 }, - { "CIM_CDEBUGDATA", 0x2d0, 0 }, - { "CDebugDataH", 16, 16 }, - { "CDebugDataL", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info tp1_regs[] = { - { "TP_IN_CONFIG", 0x300, 0 }, - { "RXFbArbPrio", 25, 1 }, - { "TXFbArbPrio", 24, 1 }, - { "DBMaxOpCnt", 16, 8 }, - { "NICMode", 14, 1 }, - { "EChecksumCheckTCP", 13, 1 }, - { "EChecksumCheckIP", 12, 1 }, - { "ECPL", 10, 1 }, - { "EEthernet", 8, 1 }, - { "ETunnel", 7, 1 }, - { "CChecksumCheckTCP", 6, 1 }, - { "CChecksumCheckIP", 5, 1 }, - { "CCPL", 3, 1 }, - { "CEthernet", 1, 1 }, - { "CTunnel", 0, 1 }, - { "TP_OUT_CONFIG", 0x304, 0 }, - { "VLANExtractionEnable", 12, 1 }, - { "EChecksumGenerateTCP", 11, 1 }, - { "EChecksumGenerateIP", 10, 1 }, - { "ECPL", 8, 1 }, - { "EEthernet", 6, 1 }, - { "CChecksumGenerateTCP", 5, 1 }, - { "CChecksumGenerateIP", 4, 1 }, - { "CCPL", 2, 1 }, - { "CEthernet", 0, 1 }, - { "TP_GLOBAL_CONFIG", 0x308, 0 }, - { "RXFlowControlDisable", 25, 1 }, - { "TXPacingEnable", 24, 1 }, - { "AttackFilterEnable", 23, 1 }, - { "SYNCookieNoOptions", 22, 1 }, - { "ProtectedMode", 21, 1 }, - { "PingDrop", 20, 1 }, - { "FragmentDrop", 19, 1 }, - { "FiveTupleLookup", 17, 2 }, - { "PathMTU", 15, 1 }, - { "IPIdentSplit", 14, 1 }, - { "IPChecksumOffload", 13, 1 }, - { "UDPChecksumOffload", 12, 1 }, - { "TCPChecksumOffload", 11, 1 }, - { "QOSMapping", 10, 1 }, - { "TCAMServerUse", 8, 2 }, - { "IPTTL", 0, 8 }, - { "TP_GLOBAL_RX_CREDIT", 0x30c, 0 }, - { "TP_CMM_SIZE", 0x310, 0 }, - { "CMMemMgrSize", 0, 28 }, - { "TP_CMM_MM_BASE", 0x314, 0 }, - { "CMMemMgrBase", 0, 28 }, - { "TP_CMM_TIMER_BASE", 0x318, 0 }, - { "CMTimerBase", 0, 28 }, - { "TP_PMM_SIZE", 0x31c, 0 }, - { "PMSize", 0, 28 }, - { "TP_PMM_TX_BASE", 0x320, 0 }, - { "TP_PMM_DEFRAG_BASE", 0x324, 0 }, - { "TP_PMM_RX_BASE", 0x328, 0 }, - { "TP_PMM_RX_PAGE_SIZE", 0x32c, 0 }, - { "TP_PMM_RX_MAX_PAGE", 0x330, 0 }, - { "PMRxMaxPage", 0, 21 }, - { "TP_PMM_TX_PAGE_SIZE", 0x334, 0 }, - { "TP_PMM_TX_MAX_PAGE", 0x338, 0 }, - { "PMTxMaxPage", 0, 21 }, - { "TP_TCP_OPTIONS", 0x340, 0 }, - { "MTUDefault", 16, 16 }, - { "MTUEnable", 10, 1 }, - { "SACKTx", 9, 1 }, - { "SACKRx", 8, 1 }, - { "SACKMode", 4, 2 }, - { "WindowScaleMode", 2, 2 }, - { "TimestampsMode", 0, 2 }, - { "TP_DACK_CONFIG", 0x344, 0 }, - { "AutoState3", 30, 2 }, - { "AutoState2", 28, 2 }, - { "AutoState1", 26, 2 }, - { "ByteThreshold", 5, 20 }, - { "MSSThreshold", 3, 2 }, - { "AutoCareful", 2, 1 }, - { "AutoEnable", 1, 1 }, - { "Mode", 0, 1 }, - { "TP_PC_CONFIG", 0x348, 0 }, - { "TxTosQueueMapMode", 26, 1 }, - { "RddpCongEn", 25, 1 }, - { "EnableOnFlyPDU", 24, 1 }, - { "EnableEPCMDAFull", 23, 1 }, - { "ModulateUnionMode", 22, 1 }, - { "TxDataAckRateEnable", 21, 1 }, - { "TxDeferEnable", 20, 1 }, - { "RxCongestionMode", 19, 1 }, - { "HearbeatOnceDACK", 18, 1 }, - { "HearbeatOnceHeap", 17, 1 }, - { "HearbeatDACK", 16, 1 }, - { "TxCongestionMode", 15, 1 }, - { "AcceptLatestRcvAdv", 14, 1 }, - { "DisableSYNData", 13, 1 }, - { "DisableWindowPSH", 12, 1 }, - { "DisableFINOldData", 11, 1 }, - { "EnableFLMError", 10, 1 }, - { "DisableFINOldDataFix", 9, 1 }, - { "FilterPeerFIN", 8, 1 }, - { "EnableFeedbackSend", 7, 1 }, - { "EnableRDMAError", 6, 1 }, - { "EnableDDPFlowControl", 5, 1 }, - { "DisableHeldData", 4, 1 }, - { "TableLatencyDelta", 0, 4 }, - { "TP_TCP_BACKOFF_REG0", 0x350, 0 }, - { "TimerBackoffIndex3", 24, 8 }, - { "TimerBackoffIndex2", 16, 8 }, - { "TimerBackoffIndex1", 8, 8 }, - { "TimerBackoffIndex0", 0, 8 }, - { "TP_TCP_BACKOFF_REG1", 0x354, 0 }, - { "TimerBackoffIndex7", 24, 8 }, - { "TimerBackoffIndex6", 16, 8 }, - { "TimerBackoffIndex5", 8, 8 }, - { "TimerBackoffIndex4", 0, 8 }, - { "TP_TCP_BACKOFF_REG2", 0x358, 0 }, - { "TimerBackoffIndex11", 24, 8 }, - { "TimerBackoffIndex10", 16, 8 }, - { "TimerBackoffIndex9", 8, 8 }, - { "TimerBackoffIndex8", 0, 8 }, - { "TP_TCP_BACKOFF_REG3", 0x35c, 0 }, - { "TimerBackoffIndex15", 24, 8 }, - { "TimerBackoffIndex14", 16, 8 }, - { "TimerBackoffIndex13", 8, 8 }, - { "TimerBackoffIndex12", 0, 8 }, - { "TP_PARA_REG0", 0x360, 0 }, - { "InitCwnd", 24, 3 }, - { "DupAckThresh", 20, 4 }, - { "TP_PARA_REG1", 0x364, 0 }, - { "InitRwnd", 16, 16 }, - { "InitialSSThresh", 0, 16 }, - { "TP_PARA_REG2", 0x368, 0 }, - { "MaxRxData", 16, 16 }, - { "RxCoalesceSize", 0, 16 }, - { "TP_PARA_REG3", 0x36c, 0 }, - { "TunnelCngDrop1", 21, 1 }, - { "TunnelCngDrop0", 20, 1 }, - { "TxDataAckIdx", 16, 4 }, - { "RxFragEnable", 12, 3 }, - { "TxPaceFixedStrict", 11, 1 }, - { "TxPaceAutoStrict", 10, 1 }, - { "TxPaceFixed", 9, 1 }, - { "TxPaceAuto", 8, 1 }, - { "RxUrgMode", 5, 1 }, - { "TxUrgMode", 4, 1 }, - { "CngCtrlMode", 2, 2 }, - { "RxCoalesceEnable", 1, 1 }, - { "RxCoalescePshEn", 0, 1 }, - { "TP_PARA_REG4", 0x370, 0 }, - { "HighSpeedCfg", 24, 8 }, - { "NewRenoCfg", 16, 8 }, - { "TahoeCfg", 8, 8 }, - { "RenoCfg", 0, 8 }, - { "TP_PARA_REG5", 0x374, 0 }, - { "IndicateSize", 16, 16 }, - { "SchdEnable", 8, 1 }, - { "OnFlyDDPEnable", 2, 1 }, - { "DackTimerSpin", 1, 1 }, - { "PushTimerEnable", 0, 1 }, - { "TP_PARA_REG6", 0x378, 0 }, - { "TxPDUSizeAdj", 16, 8 }, - { "EnableEPDU", 14, 1 }, - { "EnableESnd", 13, 1 }, - { "EnableCSnd", 12, 1 }, - { "EnableDeferACK", 9, 1 }, - { "EnablePDUC", 8, 1 }, - { "EnablePDUI", 7, 1 }, - { "EnablePDUE", 6, 1 }, - { "EnableDefer", 5, 1 }, - { "EnableClearRxmtOos", 4, 1 }, - { "DisablePDUCng", 3, 1 }, - { "DisablePDUTimeout", 2, 1 }, - { "DisablePDURxmt", 1, 1 }, - { "DisablePDUxmt", 0, 1 }, - { "TP_PARA_REG7", 0x37c, 0 }, - { "PMMaxXferLen1", 16, 16 }, - { "PMMaxXferLen0", 0, 16 }, - { "TP_TIMER_RESOLUTION", 0x390, 0 }, - { "TimerResolution", 16, 8 }, - { "TimestampResolution", 8, 8 }, - { "DelayedACKResolution", 0, 8 }, - { "TP_MSL", 0x394, 0 }, - { "MSL", 0, 30 }, - { "TP_RXT_MIN", 0x398, 0 }, - { "RxtMin", 0, 30 }, - { "TP_RXT_MAX", 0x39c, 0 }, - { "RxtMax", 0, 30 }, - { "TP_PERS_MIN", 0x3a0, 0 }, - { "PersMin", 0, 30 }, - { "TP_PERS_MAX", 0x3a4, 0 }, - { "PersMax", 0, 30 }, - { "TP_KEEP_IDLE", 0x3a8, 0 }, - { "KeepaliveIdle", 0, 30 }, - { "TP_KEEP_INTVL", 0x3ac, 0 }, - { "KeepaliveIntvl", 0, 30 }, - { "TP_INIT_SRTT", 0x3b0, 0 }, - { "InitSrtt", 0, 16 }, - { "TP_DACK_TIMER", 0x3b4, 0 }, - { "DackTime", 0, 12 }, - { "TP_FINWAIT2_TIMER", 0x3b8, 0 }, - { "Finwait2Time", 0, 30 }, - { "TP_FAST_FINWAIT2_TIMER", 0x3bc, 0 }, - { "FastFinwait2Time", 0, 30 }, - { "TP_SHIFT_CNT", 0x3c0, 0 }, - { "SynShiftMax", 24, 8 }, - { "RxtShiftMaxR1", 20, 4 }, - { "RxtShiftMaxR2", 16, 4 }, - { "PerShiftBackoffMax", 12, 4 }, - { "PerShiftMax", 8, 4 }, - { "KeepaliveMax", 0, 8 }, - { "TP_TIME_HI", 0x3c8, 0 }, - { "TP_TIME_LO", 0x3cc, 0 }, - { "TP_ULP_TABLE", 0x3d4, 0 }, - { "ULPType7Field", 28, 4 }, - { "ULPType6Field", 24, 4 }, - { "ULPType5Field", 20, 4 }, - { "ULPType4Field", 16, 4 }, - { "ULPType3Field", 12, 4 }, - { "ULPType2Field", 8, 4 }, - { "ULPType1Field", 4, 4 }, - { "ULPType0Field", 0, 4 }, - { "TP_PACE_TABLE", 0x3d8, 0 }, - { "TP_CCTRL_TABLE", 0x3dc, 0 }, - { "TP_TOS_TABLE", 0x3e0, 0 }, - { "TP_MTU_TABLE", 0x3e4, 0 }, - { "TP_RSS_MAP_TABLE", 0x3e8, 0 }, - { "TP_RSS_LKP_TABLE", 0x3ec, 0 }, - { "TP_RSS_CONFIG", 0x3f0, 0 }, - { "TNL4tupEn", 29, 1 }, - { "TNL2tupEn", 28, 1 }, - { "TNLprtEn", 26, 1 }, - { "TNLMapEn", 25, 1 }, - { "TNLLkpEn", 24, 1 }, - { "OFD4tupEn", 21, 1 }, - { "OFD2tupEn", 20, 1 }, - { "OFDMapEn", 17, 1 }, - { "OFDLkpEn", 16, 1 }, - { "SYN4tupEn", 13, 1 }, - { "SYN2tupEn", 12, 1 }, - { "SYNMapEn", 9, 1 }, - { "SYNLkpEn", 8, 1 }, - { "RRCPLMapEn", 7, 1 }, - { "RRCPLCPUSIZE", 4, 3 }, - { "RQFeedbackEnable", 3, 1 }, - { "HashToeplitz", 2, 1 }, - { "HashSave", 1, 1 }, - { "Disable", 0, 1 }, - { "TP_RSS_CONFIG_TNL", 0x3f4, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_CONFIG_OFD", 0x3f8, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_CONFIG_SYN", 0x3fc, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_SECRET_KEY0", 0x400, 0 }, - { "TP_RSS_SECRET_KEY1", 0x404, 0 }, - { "TP_RSS_SECRET_KEY2", 0x408, 0 }, - { "TP_RSS_SECRET_KEY3", 0x40c, 0 }, - { "TP_TM_PIO_ADDR", 0x418, 0 }, - { "TP_TM_PIO_DATA", 0x41c, 0 }, - { "TP_TX_MOD_QUE_TABLE", 0x420, 0 }, - { "TP_TX_RESOURCE_LIMIT", 0x424, 0 }, - { "TX_RESOURCE_LIMIT_CH1_PC", 24, 8 }, - { "TX_RESOURCE_LIMIT_CH1_NON_PC", 16, 8 }, - { "TX_RESOURCE_LIMIT_CH0_PC", 8, 8 }, - { "TX_RESOURCE_LIMIT_CH0_NON_PC", 0, 8 }, - { "TP_TX_MOD_QUEUE_REQ_MAP", 0x428, 0 }, - { "RX_MOD_WEIGHT", 24, 8 }, - { "TX_MOD_WEIGHT", 16, 8 }, - { "TX_MOD_TIMER_MODE", 8, 8 }, - { "TX_MOD_QUEUE_REQ_MAP", 0, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT1", 0x42c, 0 }, - { "TP_TX_MOD_QUEUE_WEIGHT7", 24, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT6", 16, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT5", 8, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT4", 0, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT0", 0x430, 0 }, - { "TP_TX_MOD_QUEUE_WEIGHT3", 24, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT2", 16, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT1", 8, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT0", 0, 8 }, - { "TP_MOD_CHANNEL_WEIGHT", 0x434, 0 }, - { "RX_MOD_CHANNEL_WEIGHT1", 24, 8 }, - { "RX_MOD_CHANNEL_WEIGHT0", 16, 8 }, - { "TX_MOD_CHANNEL_WEIGHT1", 8, 8 }, - { "TX_MOD_CHANNEL_WEIGHT0", 0, 8 }, - { "TP_MOD_RATE_LIMIT", 0x438, 0 }, - { "RX_MOD_RATE_LIMIT_INC", 24, 8 }, - { "RX_MOD_RATE_LIMIT_TICK", 16, 8 }, - { "TX_MOD_RATE_LIMIT_INC", 8, 8 }, - { "TX_MOD_RATE_LIMIT_TICK", 0, 8 }, - { "TP_PIO_ADDR", 0x440, 0 }, - { "TP_PIO_DATA", 0x444, 0 }, - { "TP_RESET", 0x44c, 0 }, - { "FlstInitEnable", 1, 1 }, - { "TPReset", 0, 1 }, - { "TP_MIB_INDEX", 0x450, 0 }, - { "TP_MIB_RDATA", 0x454, 0 }, - { "TP_SYNC_TIME_HI", 0x458, 0 }, - { "TP_SYNC_TIME_LO", 0x45c, 0 }, - { "TP_CMM_MM_RX_FLST_BASE", 0x460, 0 }, - { "CMRxFlstBase", 0, 28 }, - { "TP_CMM_MM_TX_FLST_BASE", 0x464, 0 }, - { "CMTxFlstBase", 0, 28 }, - { "TP_CMM_MM_PS_FLST_BASE", 0x468, 0 }, - { "CMPsFlstBase", 0, 28 }, - { "TP_CMM_MM_MAX_PSTRUCT", 0x46c, 0 }, - { "CMMaxPstruct", 0, 21 }, - { "TP_INT_ENABLE", 0x470, 0 }, - { "TP_INT_CAUSE", 0x474, 0 }, - { "TP_FLM_FREE_PS_CNT", 0x480, 0 }, - { "FreePstructCount", 0, 21 }, - { "TP_FLM_FREE_RX_CNT", 0x484, 0 }, - { "FreeRxPageCount", 0, 21 }, - { "TP_FLM_FREE_TX_CNT", 0x488, 0 }, - { "FreeTxPageCount", 0, 21 }, - { "TP_TM_HEAP_PUSH_CNT", 0x48c, 0 }, - { "TP_TM_HEAP_POP_CNT", 0x490, 0 }, - { "TP_TM_DACK_PUSH_CNT", 0x494, 0 }, - { "TP_TM_DACK_POP_CNT", 0x498, 0 }, - { "TP_TM_MOD_PUSH_CNT", 0x49c, 0 }, - { "TP_MOD_POP_CNT", 0x4a0, 0 }, - { "TP_TIMER_SEPARATOR", 0x4a4, 0 }, - { "TP_DEBUG_SEL", 0x4a8, 0 }, - { "TP_DEBUG_FLAGS", 0x4ac, 0 }, - { "RXDebugFlags", 16, 16 }, - { "TXDebugFlags", 0, 16 }, - { "TP_CM_FLOW_CNTL_MODE", 0x4b0, 0 }, - { "CMFlowCacheDisable", 0, 1 }, - { "TP_PC_CONGESTION_CNTL", 0x4b4, 0 }, - { "EDropTunnel", 19, 1 }, - { "CDropTunnel", 18, 1 }, - { "EThreshold", 12, 6 }, - { "CThreshold", 6, 6 }, - { "TxThreshold", 0, 6 }, - { "TP_TX_DROP_COUNT", 0x4bc, 0 }, - { "TP_CLEAR_DEBUG", 0x4c0, 0 }, - { "ClrDebug", 0, 1 }, - { "TP_DEBUG_VEC", 0x4c4, 0 }, - { "TP_DEBUG_VEC2", 0x4c8, 0 }, - { "TP_DEBUG_REG_SEL", 0x4cc, 0 }, - { "TP_DEBUG", 0x4d0, 0 }, - { "TP_DBG_LA_CONFIG", 0x4d4, 0 }, - { "TP_DBG_LA_DATAH", 0x4d8, 0 }, - { "TP_DBG_LA_DATAL", 0x4dc, 0 }, - { "TP_EMBED_OP_FIELD0", 0x4e8, 0 }, - { "TP_EMBED_OP_FIELD1", 0x4ec, 0 }, - { "TP_EMBED_OP_FIELD2", 0x4f0, 0 }, - { "TP_EMBED_OP_FIELD3", 0x4f4, 0 }, - { "TP_EMBED_OP_FIELD4", 0x4f8, 0 }, - { "TP_EMBED_OP_FIELD5", 0x4fc, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info ulp2_rx_regs[] = { - { "ULPRX_CTL", 0x500, 0 }, - { "PCMD1Threshold", 24, 8 }, - { "PCMD0Threshold", 16, 8 }, - { "round_robin", 4, 1 }, - { "RDMA_permissive_mode", 3, 1 }, - { "PagePodME", 2, 1 }, - { "IscsiTagTcb", 1, 1 }, - { "TddpTagTcb", 0, 1 }, - { "ULPRX_INT_ENABLE", 0x504, 0 }, - { "ParErr", 0, 1 }, - { "ULPRX_INT_CAUSE", 0x508, 0 }, - { "ParErr", 0, 1 }, - { "ULPRX_ISCSI_LLIMIT", 0x50c, 0 }, - { "IscsiLlimit", 6, 26 }, - { "ULPRX_ISCSI_ULIMIT", 0x510, 0 }, - { "IscsiUlimit", 6, 26 }, - { "ULPRX_ISCSI_TAGMASK", 0x514, 0 }, - { "IscsiTagMask", 6, 26 }, - { "ULPRX_ISCSI_PSZ", 0x518, 0 }, - { "Hpz3", 24, 4 }, - { "Hpz2", 16, 4 }, - { "Hpz1", 8, 4 }, - { "Hpz0", 0, 4 }, - { "ULPRX_TDDP_LLIMIT", 0x51c, 0 }, - { "TddpLlimit", 6, 26 }, - { "ULPRX_TDDP_ULIMIT", 0x520, 0 }, - { "TddpUlimit", 6, 26 }, - { "ULPRX_TDDP_TAGMASK", 0x524, 0 }, - { "TddpTagMask", 6, 26 }, - { "ULPRX_TDDP_PSZ", 0x528, 0 }, - { "Hpz3", 24, 4 }, - { "Hpz2", 16, 4 }, - { "Hpz1", 8, 4 }, - { "Hpz0", 0, 4 }, - { "ULPRX_STAG_LLIMIT", 0x52c, 0 }, - { "ULPRX_STAG_ULIMIT", 0x530, 0 }, - { "ULPRX_RQ_LLIMIT", 0x534, 0 }, - { "ULPRX_RQ_ULIMIT", 0x538, 0 }, - { "ULPRX_PBL_LLIMIT", 0x53c, 0 }, - { "ULPRX_PBL_ULIMIT", 0x540, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info ulp2_tx_regs[] = { - { "ULPTX_CONFIG", 0x580, 0 }, - { "CFG_RR_ARB", 0, 1 }, - { "ULPTX_INT_ENABLE", 0x584, 0 }, - { "Pbl_bound_err_ch1", 1, 1 }, - { "Pbl_bound_err_ch0", 0, 1 }, - { "ULPTX_INT_CAUSE", 0x588, 0 }, - { "Pbl_bound_err_ch1", 1, 1 }, - { "Pbl_bound_err_ch0", 0, 1 }, - { "ULPTX_TPT_LLIMIT", 0x58c, 0 }, - { "ULPTX_TPT_ULIMIT", 0x590, 0 }, - { "ULPTX_PBL_LLIMIT", 0x594, 0 }, - { "ULPTX_PBL_ULIMIT", 0x598, 0 }, - { "ULPTX_CPL_ERR_OFFSET", 0x59c, 0 }, - { "ULPTX_CPL_ERR_MASK", 0x5a0, 0 }, - { "ULPTX_CPL_ERR_VALUE", 0x5a4, 0 }, - { "ULPTX_CPL_PACK_SIZE", 0x5a8, 0 }, - { "value", 24, 8 }, - { "Ch1Size2", 24, 8 }, - { "Ch1Size1", 16, 8 }, - { "Ch0Size2", 8, 8 }, - { "Ch0Size1", 0, 8 }, - { "ULPTX_DMA_WEIGHT", 0x5ac, 0 }, - { "D1_WEIGHT", 16, 16 }, - { "D0_WEIGHT", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info pm1_rx_regs[] = { - { "PM1_RX_CFG", 0x5c0, 0 }, - { "PM1_RX_MODE", 0x5c4, 0 }, - { "stat_channel", 1, 1 }, - { "priority_ch", 0, 1 }, - { "PM1_RX_STAT_CONFIG", 0x5c8, 0 }, - { "PM1_RX_STAT_COUNT", 0x5cc, 0 }, - { "PM1_RX_STAT_MSB", 0x5d0, 0 }, - { "PM1_RX_STAT_LSB", 0x5d4, 0 }, - { "PM1_RX_INT_ENABLE", 0x5d8, 0 }, - { "zero_e_cmd_error", 18, 1 }, - { "iespi0_fifo2x_Rx_framing_error", 17, 1 }, - { "iespi1_fifo2x_Rx_framing_error", 16, 1 }, - { "iespi0_Rx_framing_error", 15, 1 }, - { "iespi1_Rx_framing_error", 14, 1 }, - { "iespi0_Tx_framing_error", 13, 1 }, - { "iespi1_Tx_framing_error", 12, 1 }, - { "ocspi0_Rx_framing_error", 11, 1 }, - { "ocspi1_Rx_framing_error", 10, 1 }, - { "ocspi0_Tx_framing_error", 9, 1 }, - { "ocspi1_Tx_framing_error", 8, 1 }, - { "ocspi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "ocspi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "iespi_par_error", 3, 3 }, - { "ocspi_par_error", 0, 3 }, - { "PM1_RX_INT_CAUSE", 0x5dc, 0 }, - { "zero_e_cmd_error", 18, 1 }, - { "iespi0_fifo2x_Rx_framing_error", 17, 1 }, - { "iespi1_fifo2x_Rx_framing_error", 16, 1 }, - { "iespi0_Rx_framing_error", 15, 1 }, - { "iespi1_Rx_framing_error", 14, 1 }, - { "iespi0_Tx_framing_error", 13, 1 }, - { "iespi1_Tx_framing_error", 12, 1 }, - { "ocspi0_Rx_framing_error", 11, 1 }, - { "ocspi1_Rx_framing_error", 10, 1 }, - { "ocspi0_Tx_framing_error", 9, 1 }, - { "ocspi1_Tx_framing_error", 8, 1 }, - { "ocspi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "ocspi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "iespi_par_error", 3, 3 }, - { "ocspi_par_error", 0, 3 }, - { NULL, 0, 0 } -}; - -struct reg_info pm1_tx_regs[] = { - { "PM1_TX_CFG", 0x5e0, 0 }, - { "PM1_TX_MODE", 0x5e4, 0 }, - { "stat_channel", 1, 1 }, - { "priority_ch", 0, 1 }, - { "PM1_TX_STAT_CONFIG", 0x5e8, 0 }, - { "PM1_TX_STAT_COUNT", 0x5ec, 0 }, - { "PM1_TX_STAT_MSB", 0x5f0, 0 }, - { "PM1_TX_STAT_LSB", 0x5f4, 0 }, - { "PM1_TX_INT_ENABLE", 0x5f8, 0 }, - { "zero_c_cmd_error", 18, 1 }, - { "icspi0_fifo2x_Rx_framing_error", 17, 1 }, - { "icspi1_fifo2x_Rx_framing_error", 16, 1 }, - { "icspi0_Rx_framing_error", 15, 1 }, - { "icspi1_Rx_framing_error", 14, 1 }, - { "icspi0_Tx_framing_error", 13, 1 }, - { "icspi1_Tx_framing_error", 12, 1 }, - { "oespi0_Rx_framing_error", 11, 1 }, - { "oespi1_Rx_framing_error", 10, 1 }, - { "oespi0_Tx_framing_error", 9, 1 }, - { "oespi1_Tx_framing_error", 8, 1 }, - { "oespi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "oespi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "icspi_par_error", 3, 3 }, - { "oespi_par_error", 0, 3 }, - { "PM1_TX_INT_CAUSE", 0x5fc, 0 }, - { "zero_c_cmd_error", 18, 1 }, - { "icspi0_fifo2x_Rx_framing_error", 17, 1 }, - { "icspi1_fifo2x_Rx_framing_error", 16, 1 }, - { "icspi0_Rx_framing_error", 15, 1 }, - { "icspi1_Rx_framing_error", 14, 1 }, - { "icspi0_Tx_framing_error", 13, 1 }, - { "icspi1_Tx_framing_error", 12, 1 }, - { "oespi0_Rx_framing_error", 11, 1 }, - { "oespi1_Rx_framing_error", 10, 1 }, - { "oespi0_Tx_framing_error", 9, 1 }, - { "oespi1_Tx_framing_error", 8, 1 }, - { "oespi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "oespi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "icspi_par_error", 3, 3 }, - { "oespi_par_error", 0, 3 }, - { NULL, 0, 0 } -}; - -struct reg_info mps0_regs[] = { - { "MPS_CFG", 0x600, 0 }, - { "SGETPQid", 8, 3 }, - { "TPRxPortSize", 7, 1 }, - { "TPTxPort1Size", 6, 1 }, - { "TPTxPort0Size", 5, 1 }, - { "TPRxPortEn", 4, 1 }, - { "TPTxPort1En", 3, 1 }, - { "TPTxPort0En", 2, 1 }, - { "Port1Active", 1, 1 }, - { "Port0Active", 0, 1 }, - { "MPS_DRR_CFG1", 0x604, 0 }, - { "RldWtTPD1", 11, 11 }, - { "RldWtTPD0", 0, 11 }, - { "MPS_DRR_CFG2", 0x608, 0 }, - { "RldWtTotal", 0, 12 }, - { "MPS_MCA_STATUS", 0x60c, 0 }, - { "MCAPktCnt", 12, 20 }, - { "MCADepth", 0, 12 }, - { "MPS_TX0_TP_CNT", 0x610, 0 }, - { "TX0TPDisCnt", 24, 8 }, - { "TX0TPCnt", 0, 24 }, - { "MPS_TX1_TP_CNT", 0x614, 0 }, - { "TX1TPDisCnt", 24, 8 }, - { "TX1TPCnt", 0, 24 }, - { "MPS_RX_TP_CNT", 0x618, 0 }, - { "RXTPDisCnt", 24, 8 }, - { "RXTPCnt", 0, 24 }, - { "MPS_INT_ENABLE", 0x61c, 0 }, - { "MCAParErrEnb", 6, 3 }, - { "RXTpParErrEnb", 4, 2 }, - { "TX1TpParErrEnb", 2, 2 }, - { "TX0TpParErrEnb", 0, 2 }, - { "MPS_INT_CAUSE", 0x620, 0 }, - { "MCAParErr", 6, 3 }, - { "RXTpParErr", 4, 2 }, - { "TX1TpParErr", 2, 2 }, - { "TX0TpParErr", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info cpl_switch_regs[] = { - { "CPL_SWITCH_CNTRL", 0x640, 0 }, - { "cpl_pkt_tid", 8, 24 }, - { "cpu_no_3F_CIM_enable", 3, 1 }, - { "switch_table_enable", 2, 1 }, - { "sge_enable", 1, 1 }, - { "cim_enable", 0, 1 }, - { "CPL_SWITCH_TBL_IDX", 0x644, 0 }, - { "switch_tbl_idx", 0, 4 }, - { "CPL_SWITCH_TBL_DATA", 0x648, 0 }, - { "CPL_SWITCH_ZERO_ERROR", 0x64c, 0 }, - { "zero_cmd", 0, 8 }, - { "CPL_INTR_ENABLE", 0x650, 0 }, - { "cim_ovfl_error", 4, 1 }, - { "tp_framing_error", 3, 1 }, - { "sge_framing_error", 2, 1 }, - { "cim_framing_error", 1, 1 }, - { "zero_switch_error", 0, 1 }, - { "CPL_INTR_CAUSE", 0x654, 0 }, - { "cim_ovfl_error", 4, 1 }, - { "tp_framing_error", 3, 1 }, - { "sge_framing_error", 2, 1 }, - { "cim_framing_error", 1, 1 }, - { "zero_switch_error", 0, 1 }, - { "CPL_MAP_TBL_IDX", 0x658, 0 }, - { "cpl_map_tbl_idx", 0, 8 }, - { "CPL_MAP_TBL_DATA", 0x65c, 0 }, - { "cpl_map_tbl_data", 0, 8 }, - { NULL, 0, 0 } -}; - -struct reg_info smb0_regs[] = { - { "SMB_GLOBAL_TIME_CFG", 0x660, 0 }, - { "LADbgWrPtr", 24, 8 }, - { "LADbgRdPtr", 16, 8 }, - { "LADbgEn", 13, 1 }, - { "MacroCntCfg", 8, 5 }, - { "MicroCntCfg", 0, 8 }, - { "SMB_MST_TIMEOUT_CFG", 0x664, 0 }, - { "DebugSelH", 28, 4 }, - { "DebugSelL", 24, 4 }, - { "MstTimeOutCfg", 0, 24 }, - { "SMB_MST_CTL_CFG", 0x668, 0 }, - { "MstFifoDbg", 31, 1 }, - { "MstFifoDbgClr", 30, 1 }, - { "MstRxByteCfg", 12, 6 }, - { "MstTxByteCfg", 6, 6 }, - { "MstReset", 1, 1 }, - { "MstCtlEn", 0, 1 }, - { "SMB_MST_CTL_STS", 0x66c, 0 }, - { "MstRxByteCnt", 12, 6 }, - { "MstTxByteCnt", 6, 6 }, - { "MstBusySts", 0, 1 }, - { "SMB_MST_TX_FIFO_RDWR", 0x670, 0 }, - { "SMB_MST_RX_FIFO_RDWR", 0x674, 0 }, - { "SMB_SLV_TIMEOUT_CFG", 0x678, 0 }, - { "SlvTimeOutCfg", 0, 24 }, - { "SMB_SLV_CTL_CFG", 0x67c, 0 }, - { "SlvFifoDbg", 31, 1 }, - { "SlvFifoDbgClr", 30, 1 }, - { "SlvAddrCfg", 4, 7 }, - { "SlvAlrtSet", 2, 1 }, - { "SlvReset", 1, 1 }, - { "SlvCtlEn", 0, 1 }, - { "SMB_SLV_CTL_STS", 0x680, 0 }, - { "SlvFifoTxCnt", 12, 6 }, - { "SlvFifoCnt", 6, 6 }, - { "SlvAlrtSts", 2, 1 }, - { "SlvBusySts", 0, 1 }, - { "SMB_SLV_FIFO_RDWR", 0x684, 0 }, - { "SMB_SLV_CMD_FIFO_RDWR", 0x688, 0 }, - { "SMB_INT_ENABLE", 0x68c, 0 }, - { "SlvTimeOutIntEn", 7, 1 }, - { "SlvErrIntEn", 6, 1 }, - { "SlvDoneIntEn", 5, 1 }, - { "SlvRxRdyIntEn", 4, 1 }, - { "MstTimeOutIntEn", 3, 1 }, - { "MstNAckIntEn", 2, 1 }, - { "MstLostArbIntEn", 1, 1 }, - { "MstDoneIntEn", 0, 1 }, - { "SMB_INT_CAUSE", 0x690, 0 }, - { "SlvTimeOutInt", 7, 1 }, - { "SlvErrInt", 6, 1 }, - { "SlvDoneInt", 5, 1 }, - { "SlvRxRdyInt", 4, 1 }, - { "MstTimeOutInt", 3, 1 }, - { "MstNAckInt", 2, 1 }, - { "MstLostArbInt", 1, 1 }, - { "MstDoneInt", 0, 1 }, - { "SMB_DEBUG_DATA", 0x694, 0 }, - { "DebugDataH", 16, 16 }, - { "DebugDataL", 0, 16 }, - { "SMB_DEBUG_LA", 0x69c, 0 }, - { "DebugLAReqAddr", 0, 10 }, - { NULL, 0, 0 } -}; - -struct reg_info i2cm0_regs[] = { - { "I2C_CFG", 0x6a0, 0 }, - { "ClkDiv", 0, 12 }, - { "I2C_DATA", 0x6a4, 0 }, - { "Data", 0, 8 }, - { "I2C_OP", 0x6a8, 0 }, - { "Busy", 31, 1 }, - { "Ack", 30, 1 }, - { "Cont", 1, 1 }, - { "Op", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info mi1_regs[] = { - { "MI1_CFG", 0x6b0, 0 }, - { "ClkDiv", 5, 8 }, - { "St", 3, 2 }, - { "PreEn", 2, 1 }, - { "MDIInv", 1, 1 }, - { "MDIEn", 0, 1 }, - { "MI1_ADDR", 0x6b4, 0 }, - { "PhyAddr", 5, 5 }, - { "RegAddr", 0, 5 }, - { "MI1_DATA", 0x6b8, 0 }, - { "Data", 0, 16 }, - { "MI1_OP", 0x6bc, 0 }, - { "Busy", 31, 1 }, - { "Inc", 2, 1 }, - { "Op", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info jm1_regs[] = { - { "JM_CFG", 0x6c0, 0 }, - { "ClkDiv", 2, 8 }, - { "TRst", 1, 1 }, - { "En", 0, 1 }, - { "JM_MODE", 0x6c4, 0 }, - { "JM_DATA", 0x6c8, 0 }, - { "JM_OP", 0x6cc, 0 }, - { "Busy", 31, 1 }, - { "Cnt", 0, 5 }, - { NULL, 0, 0 } -}; - -struct reg_info sf1_regs[] = { - { "SF_DATA", 0x6d8, 0 }, - { "SF_OP", 0x6dc, 0 }, - { "Busy", 31, 1 }, - { "Cont", 3, 1 }, - { "ByteCnt", 1, 2 }, - { "Op", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info pl3_regs[] = { - { "PL_INT_ENABLE0", 0x6e0, 0 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_CAUSE0", 0x6e4, 0 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_ENABLE1", 0x6e8, 0 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_CAUSE1", 0x6ec, 0 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_RST", 0x6f0, 0 }, - { "CRstWrm", 1, 1 }, - { "CRstWrmMode", 0, 1 }, - { "PL_REV", 0x6f4, 0 }, - { "Rev", 0, 4 }, - { "PL_CLI", 0x6f8, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info mc5a_regs[] = { - { "MC5_BUF_CONFIG", 0x700, 0 }, - { "term300_240", 31, 1 }, - { "term150", 30, 1 }, - { "term60", 29, 1 }, - { "gddriii", 28, 1 }, - { "gddrii", 27, 1 }, - { "gddri", 26, 1 }, - { "read", 25, 1 }, - { "cal_imp_upd", 23, 1 }, - { "cal_busy", 22, 1 }, - { "cal_error", 21, 1 }, - { "sgl_cal_en", 20, 1 }, - { "imp_upd_mode", 19, 1 }, - { "imp_sel", 18, 1 }, - { "man_pu", 15, 3 }, - { "man_pd", 12, 3 }, - { "cal_pu", 9, 3 }, - { "cal_pd", 6, 3 }, - { "set_pu", 3, 3 }, - { "set_pd", 0, 3 }, - { "MC5_DB_CONFIG", 0x704, 0 }, - { "TMCfgWrLock", 31, 1 }, - { "TMTypeHi", 30, 1 }, - { "TMPartSize", 28, 2 }, - { "TMType", 26, 2 }, - { "TMPartCount", 24, 2 }, - { "nLIP", 18, 6 }, - { "COMPEN", 17, 1 }, - { "BUILD", 16, 1 }, - { "TM_IO_PDOWN", 9, 1 }, - { "SYNMode", 7, 2 }, - { "PRTYEN", 6, 1 }, - { "MBUSEN", 5, 1 }, - { "DBGIEN", 4, 1 }, - { "TMRDY", 2, 1 }, - { "TMRST", 1, 1 }, - { "TMMode", 0, 1 }, - { "MC5_DB_ROUTING_TABLE_INDEX", 0x70c, 0 }, - { "RTINDX", 0, 22 }, - { "MC5_DB_SERVER_INDEX", 0x714, 0 }, - { "SRINDX", 0, 22 }, - { "MC5_DB_LIP_RAM_ADDR", 0x718, 0 }, - { "RAMWR", 8, 1 }, - { "RAMADDR", 0, 6 }, - { "MC5_DB_LIP_RAM_DATA", 0x71c, 0 }, - { "MC5_DB_RSP_LATENCY", 0x720, 0 }, - { "RDLAT", 16, 5 }, - { "LRNLAT", 8, 5 }, - { "SRCHLAT", 0, 5 }, - { "MC5_DB_PARITY_LATENCY", 0x724, 0 }, - { "PARLAT", 0, 4 }, - { "MC5_DB_WR_LRN_VERIFY", 0x728, 0 }, - { "VWVEREN", 2, 1 }, - { "LRNVEREN", 1, 1 }, - { "POVEREN", 0, 1 }, - { "MC5_DB_PART_ID_INDEX", 0x72c, 0 }, - { "IDINDEX", 0, 4 }, - { "MC5_DB_RESET_MAX", 0x730, 0 }, - { "RSTMAX", 0, 4 }, - { "MC5_DB_ACT_CNT", 0x734, 0 }, - { "ACTCNT", 0, 20 }, - { "MC5_DB_INT_ENABLE", 0x740, 0 }, - { "MsgSel", 28, 4 }, - { "DelActEmpty", 18, 1 }, - { "DispQParErr", 17, 1 }, - { "ReqQParErr", 16, 1 }, - { "UnknownCmd", 15, 1 }, - { "SYNCookieOff", 11, 1 }, - { "SYNCookieBad", 10, 1 }, - { "SYNCookie", 9, 1 }, - { "NFASrchFail", 8, 1 }, - { "ActRgnFull", 7, 1 }, - { "ParityErr", 6, 1 }, - { "LIPMiss", 5, 1 }, - { "LIP0", 4, 1 }, - { "Miss", 3, 1 }, - { "RoutingHit", 2, 1 }, - { "ActiveHit", 1, 1 }, - { "ActiveOutHit", 0, 1 }, - { "MC5_DB_INT_CAUSE", 0x744, 0 }, - { "DelActEmpty", 18, 1 }, - { "DispQParErr", 17, 1 }, - { "ReqQParErr", 16, 1 }, - { "UnknownCmd", 15, 1 }, - { "SYNCookieOff", 11, 1 }, - { "SYNCookieBad", 10, 1 }, - { "SYNCookie", 9, 1 }, - { "NFASrchFail", 8, 1 }, - { "ActRgnFull", 7, 1 }, - { "ParityErr", 6, 1 }, - { "LIPMiss", 5, 1 }, - { "LIP0", 4, 1 }, - { "Miss", 3, 1 }, - { "RoutingHit", 2, 1 }, - { "ActiveHit", 1, 1 }, - { "ActiveOutHit", 0, 1 }, - { "MC5_DB_INT_TID", 0x748, 0 }, - { "INTTID", 0, 20 }, - { "MC5_DB_INT_PTID", 0x74c, 0 }, - { "INTPTID", 0, 20 }, - { "MC5_DB_DBGI_CONFIG", 0x774, 0 }, - { "WRReqSize", 22, 10 }, - { "SADRSel", 4, 1 }, - { "CMDMode", 0, 3 }, - { "MC5_DB_DBGI_REQ_CMD", 0x778, 0 }, - { "MBusCmd", 0, 4 }, - { "IDTCmdHi", 11, 3 }, - { "IDTCmdLo", 0, 4 }, - { "IDTCmd", 0, 20 }, - { "LCMDB", 16, 11 }, - { "LCMDA", 0, 11 }, - { "MC5_DB_DBGI_REQ_ADDR0", 0x77c, 0 }, - { "MC5_DB_DBGI_REQ_ADDR1", 0x780, 0 }, - { "MC5_DB_DBGI_REQ_ADDR2", 0x784, 0 }, - { "DBGIReqAdrHi", 0, 8 }, - { "MC5_DB_DBGI_REQ_DATA0", 0x788, 0 }, - { "MC5_DB_DBGI_REQ_DATA1", 0x78c, 0 }, - { "MC5_DB_DBGI_REQ_DATA2", 0x790, 0 }, - { "MC5_DB_DBGI_REQ_DATA3", 0x794, 0 }, - { "MC5_DB_DBGI_REQ_DATA4", 0x798, 0 }, - { "DBGIReqData4", 0, 16 }, - { "MC5_DB_DBGI_REQ_MASK0", 0x79c, 0 }, - { "MC5_DB_DBGI_REQ_MASK1", 0x7a0, 0 }, - { "MC5_DB_DBGI_REQ_MASK2", 0x7a4, 0 }, - { "MC5_DB_DBGI_REQ_MASK3", 0x7a8, 0 }, - { "MC5_DB_DBGI_REQ_MASK4", 0x7ac, 0 }, - { "DBGIReqMsk4", 0, 16 }, - { "MC5_DB_DBGI_RSP_STATUS", 0x7b0, 0 }, - { "DBGIRspMsg", 8, 4 }, - { "DBGIRspMsgVld", 2, 1 }, - { "DBGIRspHit", 1, 1 }, - { "DBGIRspValid", 0, 1 }, - { "MC5_DB_DBGI_RSP_DATA0", 0x7b4, 0 }, - { "MC5_DB_DBGI_RSP_DATA1", 0x7b8, 0 }, - { "MC5_DB_DBGI_RSP_DATA2", 0x7bc, 0 }, - { "MC5_DB_DBGI_RSP_DATA3", 0x7c0, 0 }, - { "MC5_DB_DBGI_RSP_DATA4", 0x7c4, 0 }, - { "DBGIRspData3", 0, 16 }, - { "MC5_DB_DBGI_RSP_LAST_CMD", 0x7c8, 0 }, - { "LastCmdB", 16, 11 }, - { "LastCmdA", 0, 11 }, - { "MC5_DB_POPEN_DATA_WR_CMD", 0x7cc, 0 }, - { "PO_DWR", 0, 20 }, - { "MC5_DB_POPEN_MASK_WR_CMD", 0x7d0, 0 }, - { "PO_MWR", 0, 20 }, - { "MC5_DB_AOPEN_SRCH_CMD", 0x7d4, 0 }, - { "AO_SRCH", 0, 20 }, - { "MC5_DB_AOPEN_LRN_CMD", 0x7d8, 0 }, - { "AO_LRN", 0, 20 }, - { "MC5_DB_SYN_SRCH_CMD", 0x7dc, 0 }, - { "SYN_SRCH", 0, 20 }, - { "MC5_DB_SYN_LRN_CMD", 0x7e0, 0 }, - { "SYN_LRN", 0, 20 }, - { "MC5_DB_ACK_SRCH_CMD", 0x7e4, 0 }, - { "ACK_SRCH", 0, 20 }, - { "MC5_DB_ACK_LRN_CMD", 0x7e8, 0 }, - { "ACK_LRN", 0, 20 }, - { "MC5_DB_ILOOKUP_CMD", 0x7ec, 0 }, - { "I_SRCH", 0, 20 }, - { "MC5_DB_ELOOKUP_CMD", 0x7f0, 0 }, - { "E_SRCH", 0, 20 }, - { "MC5_DB_DATA_WRITE_CMD", 0x7f4, 0 }, - { "Write", 0, 20 }, - { "MC5_DB_DATA_READ_CMD", 0x7f8, 0 }, - { "ReadCmd", 0, 20 }, - { "MC5_DB_MASK_WRITE_CMD", 0x7fc, 0 }, - { "MaskWr", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info xgmac0_0_regs[] = { - { "XGM_TX_CTRL", 0x800, 0 }, - { "SendPause", 2, 1 }, - { "SendZeroPause", 1, 1 }, - { "TxEn", 0, 1 }, - { "XGM_TX_CFG", 0x804, 0 }, - { "CfgClkSpeed", 2, 3 }, - { "StretchMode", 1, 1 }, - { "TxPauseEn", 0, 1 }, - { "XGM_TX_PAUSE_QUANTA", 0x808, 0 }, - { "TxPauseQuanta", 0, 16 }, - { "XGM_RX_CTRL", 0x80c, 0 }, - { "RxEn", 0, 1 }, - { "XGM_RX_CFG", 0x810, 0 }, - { "Con802_3Preamble", 12, 1 }, - { "EnNon802_3Preamble", 11, 1 }, - { "CopyPreamble", 10, 1 }, - { "DisPauseFrames", 9, 1 }, - { "En1536BFrames", 8, 1 }, - { "EnJumbo", 7, 1 }, - { "RmFCS", 6, 1 }, - { "DisNonVlan", 5, 1 }, - { "EnExtMatch", 4, 1 }, - { "EnHashUcast", 3, 1 }, - { "EnHashMcast", 2, 1 }, - { "DisBCast", 1, 1 }, - { "CopyAllFrames", 0, 1 }, - { "XGM_RX_HASH_LOW", 0x814, 0 }, - { "XGM_RX_HASH_HIGH", 0x818, 0 }, - { "XGM_RX_EXACT_MATCH_LOW_1", 0x81c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_1", 0x820, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_2", 0x824, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_2", 0x828, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_3", 0x82c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_3", 0x830, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_4", 0x834, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_4", 0x838, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_5", 0x83c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_5", 0x840, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_6", 0x844, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_6", 0x848, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_7", 0x84c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_7", 0x850, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_8", 0x854, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_8", 0x858, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_TYPE_MATCH_1", 0x85c, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_2", 0x860, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_3", 0x864, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_4", 0x868, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_INT_STATUS", 0x86c, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_MASK", 0x870, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_ENABLE", 0x874, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_DISABLE", 0x878, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_TX_PAUSE_TIMER", 0x87c, 0 }, - { "CurPauseTimer", 0, 16 }, - { "XGM_STAT_CTRL", 0x880, 0 }, - { "ReadSnpShot", 4, 1 }, - { "TakeSnpShot", 3, 1 }, - { "ClrStats", 2, 1 }, - { "IncrStats", 1, 1 }, - { "EnTestModeWr", 0, 1 }, - { "XGM_RXFIFO_CFG", 0x884, 0 }, - { "RxFIFOPauseHWM", 17, 12 }, - { "RxFIFOPauseLWM", 5, 12 }, - { "ForcedPause", 4, 1 }, - { "ExternLoopback", 3, 1 }, - { "RxByteSwap", 2, 1 }, - { "RxStrFrwrd", 1, 1 }, - { "DisErrFrames", 0, 1 }, - { "XGM_TXFIFO_CFG", 0x888, 0 }, - { "TxIPG", 13, 8 }, - { "TxFIFOThresh", 4, 9 }, - { "InternLoopback", 3, 1 }, - { "TxByteSwap", 2, 1 }, - { "DisCRC", 1, 1 }, - { "DisPreAmble", 0, 1 }, - { "XGM_SLOW_TIMER", 0x88c, 0 }, - { "PauseSlowTimerEn", 31, 1 }, - { "PauseSlowTimer", 0, 20 }, - { "XGM_SERDES_CTRL", 0x890, 0 }, - { "SERDESEn", 25, 1 }, - { "SERDESReset_", 24, 1 }, - { "CMURange", 21, 3 }, - { "BGEnb", 20, 1 }, - { "EnSkpDrop", 19, 1 }, - { "EnComma", 18, 1 }, - { "En8B10B", 17, 1 }, - { "EnElBuf", 16, 1 }, - { "Gain", 11, 5 }, - { "BandGap", 7, 4 }, - { "LpbkEn", 5, 2 }, - { "RxEn", 4, 1 }, - { "TxEn", 3, 1 }, - { "RxComAdj", 2, 1 }, - { "PreEmph", 0, 2 }, - { "XGM_XAUI_PCS_TEST", 0x894, 0 }, - { "TestPattern", 1, 2 }, - { "EnTest", 0, 1 }, - { "XGM_RGMII_CTRL", 0x898, 0 }, - { "PhAlignFIFOThresh", 1, 2 }, - { "TxClk90Shift", 0, 1 }, - { "XGM_RGMII_IMP", 0x89c, 0 }, - { "ImpSetUpdate", 6, 1 }, - { "RGMIIImpPD", 3, 3 }, - { "RGMIIImpPU", 0, 3 }, - { "XGM_XAUI_IMP", 0x8a0, 0 }, - { "CalBusy", 31, 1 }, - { "CalFault", 29, 1 }, - { "CalImp", 24, 5 }, - { "XAUIImp", 0, 3 }, - { "XGM_SERDES_BIST", 0x8a4, 0 }, - { "BISTDone", 28, 4 }, - { "BISTCycleThresh", 3, 17 }, - { "BISTMode", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE", 0x8a8, 0 }, - { "RxMaxPktSize", 0, 14 }, - { "XGM_RESET_CTRL", 0x8ac, 0 }, - { "XG2G_Reset_", 3, 1 }, - { "RGMII_Reset_", 2, 1 }, - { "PCS_Reset_", 1, 1 }, - { "MAC_Reset_", 0, 1 }, - { "XGM_XAUI1G_CTRL", 0x8b0, 0 }, - { "XAUI1GLinkId", 0, 2 }, - { "XGM_SERDES_LANE_CTRL", 0x8b4, 0 }, - { "LaneReversal", 8, 1 }, - { "TxPolarity", 4, 4 }, - { "RxPolarity", 0, 4 }, - { "XGM_PORT_CFG", 0x8b8, 0 }, - { "SafeSpeedChange", 4, 1 }, - { "ClkDivReset_", 3, 1 }, - { "PortSpeed", 1, 2 }, - { "EnRGMII", 0, 1 }, - { "XGM_EPIO_DATA0", 0x8c0, 0 }, - { "XGM_EPIO_DATA1", 0x8c4, 0 }, - { "XGM_EPIO_DATA2", 0x8c8, 0 }, - { "XGM_EPIO_DATA3", 0x8cc, 0 }, - { "XGM_EPIO_OP", 0x8d0, 0 }, - { "PIO_Ready", 31, 1 }, - { "PIO_WrRd", 24, 1 }, - { "PIO_Address", 0, 8 }, - { "XGM_INT_ENABLE", 0x8d4, 0 }, - { "SERDESCMULock_loss", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBIST_err", 8, 4 }, - { "SERDES_los", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_INT_CAUSE", 0x8d8, 0 }, - { "SERDESCMULock_loss", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBIST_err", 8, 4 }, - { "SERDES_los", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_STAT_TX_BYTE_LOW", 0x900, 0 }, - { "XGM_STAT_TX_BYTE_HIGH", 0x904, 0 }, - { "TxBytes_high", 0, 13 }, - { "XGM_STAT_TX_FRAME_LOW", 0x908, 0 }, - { "XGM_STAT_TX_FRAME_HIGH", 0x90c, 0 }, - { "TxFrames_high", 0, 4 }, - { "XGM_STAT_TX_BCAST", 0x910, 0 }, - { "XGM_STAT_TX_MCAST", 0x914, 0 }, - { "XGM_STAT_TX_PAUSE", 0x918, 0 }, - { "XGM_STAT_TX_64B_FRAMES", 0x91c, 0 }, - { "XGM_STAT_TX_65_127B_FRAMES", 0x920, 0 }, - { "XGM_STAT_TX_128_255B_FRAMES", 0x924, 0 }, - { "XGM_STAT_TX_256_511B_FRAMES", 0x928, 0 }, - { "XGM_STAT_TX_512_1023B_FRAMES", 0x92c, 0 }, - { "XGM_STAT_TX_1024_1518B_FRAMES", 0x930, 0 }, - { "XGM_STAT_TX_1519_MAXB_FRAMES", 0x934, 0 }, - { "XGM_STAT_TX_ERR_FRAMES", 0x938, 0 }, - { "XGM_STAT_RX_BYTES_LOW", 0x93c, 0 }, - { "XGM_STAT_RX_BYTES_HIGH", 0x940, 0 }, - { "RxBytes_high", 0, 13 }, - { "XGM_STAT_RX_FRAMES_LOW", 0x944, 0 }, - { "XGM_STAT_RX_FRAMES_HIGH", 0x948, 0 }, - { "RxFrames_high", 0, 4 }, - { "XGM_STAT_RX_BCAST_FRAMES", 0x94c, 0 }, - { "XGM_STAT_RX_MCAST_FRAMES", 0x950, 0 }, - { "XGM_STAT_RX_PAUSE_FRAMES", 0x954, 0 }, - { "RxPauseFrames", 0, 16 }, - { "XGM_STAT_RX_64B_FRAMES", 0x958, 0 }, - { "XGM_STAT_RX_65_127B_FRAMES", 0x95c, 0 }, - { "XGM_STAT_RX_128_255B_FRAMES", 0x960, 0 }, - { "XGM_STAT_RX_256_511B_FRAMES", 0x964, 0 }, - { "XGM_STAT_RX_512_1023B_FRAMES", 0x968, 0 }, - { "XGM_STAT_RX_1024_1518B_FRAMES", 0x96c, 0 }, - { "XGM_STAT_RX_1519_MAXB_FRAMES", 0x970, 0 }, - { "XGM_STAT_RX_SHORT_FRAMES", 0x974, 0 }, - { "RxShortFrames", 0, 16 }, - { "XGM_STAT_RX_OVERSIZE_FRAMES", 0x978, 0 }, - { "RxOversizeFrames", 0, 16 }, - { "XGM_STAT_RX_JABBER_FRAMES", 0x97c, 0 }, - { "RxJabberFrames", 0, 16 }, - { "XGM_STAT_RX_CRC_ERR_FRAMES", 0x980, 0 }, - { "RxCRCErrFrames", 0, 16 }, - { "XGM_STAT_RX_LENGTH_ERR_FRAMES", 0x984, 0 }, - { "RxLengthErrFrames", 0, 16 }, - { "XGM_STAT_RX_SYM_CODE_ERR_FRAMES", 0x988, 0 }, - { "RxSymCodeErrFrames", 0, 16 }, - { "XGM_SERDES_STATUS0", 0x98c, 0 }, - { "RxErrLane3", 9, 3 }, - { "RxErrLane2", 6, 3 }, - { "RxErrLane1", 3, 3 }, - { "RxErrLane0", 0, 3 }, - { "XGM_SERDES_STATUS1", 0x990, 0 }, - { "CMULock", 31, 1 }, - { "RxKLockLane3", 11, 1 }, - { "RxKLockLane2", 10, 1 }, - { "RxKLockLane1", 9, 1 }, - { "RxKLockLane0", 8, 1 }, - { "RxUFlowLane3", 7, 1 }, - { "RxUFlowLane2", 6, 1 }, - { "RxUFlowLane1", 5, 1 }, - { "RxUFlowLane0", 4, 1 }, - { "RxOFlowLane3", 3, 1 }, - { "RxOFlowLane2", 2, 1 }, - { "RxOFlowLane1", 1, 1 }, - { "RxOFlowLane0", 0, 1 }, - { "XGM_SERDES_STATUS2", 0x994, 0 }, - { "RxEIDLane3", 11, 1 }, - { "RxEIDLane2", 10, 1 }, - { "RxEIDLane1", 9, 1 }, - { "RxEIDLane0", 8, 1 }, - { "RxRemSkipLane3", 7, 1 }, - { "RxRemSkipLane2", 6, 1 }, - { "RxRemSkipLane1", 5, 1 }, - { "RxRemSkipLane0", 4, 1 }, - { "RxAddSkipLane3", 3, 1 }, - { "RxAddSkipLane2", 2, 1 }, - { "RxAddSkipLane1", 1, 1 }, - { "RxAddSkipLane0", 0, 1 }, - { "XGM_XAUI_PCS_ERR", 0x998, 0 }, - { "PCS_SyncStatus", 5, 4 }, - { "PCS_CTCFIFOErr", 1, 4 }, - { "PCS_NotAligned", 0, 1 }, - { "XGM_RGMII_STATUS", 0x99c, 0 }, - { "GMIIDuplex", 3, 1 }, - { "GMIISpeed", 1, 2 }, - { "GMIILinkStatus", 0, 1 }, - { "XGM_WOL_STATUS", 0x9a0, 0 }, - { "PatDetected", 31, 1 }, - { "MatchedFilter", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE_ERR_CNT", 0x9a4, 0 }, - { "XGM_TX_SPI4_SOP_EOP_CNT", 0x9a8, 0 }, - { "TxSPI4SopCnt", 16, 16 }, - { "TxSPI4EopCnt", 0, 16 }, - { "XGM_RX_SPI4_SOP_EOP_CNT", 0x9ac, 0 }, - { "RxSPI4SopCnt", 16, 16 }, - { "RxSPI4EopCnt", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info xgmac0_1_regs[] = { - { "XGM_TX_CTRL", 0xa00, 0 }, - { "SendPause", 2, 1 }, - { "SendZeroPause", 1, 1 }, - { "TxEn", 0, 1 }, - { "XGM_TX_CFG", 0xa04, 0 }, - { "CfgClkSpeed", 2, 3 }, - { "StretchMode", 1, 1 }, - { "TxPauseEn", 0, 1 }, - { "XGM_TX_PAUSE_QUANTA", 0xa08, 0 }, - { "TxPauseQuanta", 0, 16 }, - { "XGM_RX_CTRL", 0xa0c, 0 }, - { "RxEn", 0, 1 }, - { "XGM_RX_CFG", 0xa10, 0 }, - { "Con802_3Preamble", 12, 1 }, - { "EnNon802_3Preamble", 11, 1 }, - { "CopyPreamble", 10, 1 }, - { "DisPauseFrames", 9, 1 }, - { "En1536BFrames", 8, 1 }, - { "EnJumbo", 7, 1 }, - { "RmFCS", 6, 1 }, - { "DisNonVlan", 5, 1 }, - { "EnExtMatch", 4, 1 }, - { "EnHashUcast", 3, 1 }, - { "EnHashMcast", 2, 1 }, - { "DisBCast", 1, 1 }, - { "CopyAllFrames", 0, 1 }, - { "XGM_RX_HASH_LOW", 0xa14, 0 }, - { "XGM_RX_HASH_HIGH", 0xa18, 0 }, - { "XGM_RX_EXACT_MATCH_LOW_1", 0xa1c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_1", 0xa20, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_2", 0xa24, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_2", 0xa28, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_3", 0xa2c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_3", 0xa30, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_4", 0xa34, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_4", 0xa38, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_5", 0xa3c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_5", 0xa40, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_6", 0xa44, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_6", 0xa48, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_7", 0xa4c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_7", 0xa50, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_8", 0xa54, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_8", 0xa58, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_TYPE_MATCH_1", 0xa5c, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_2", 0xa60, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_3", 0xa64, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_4", 0xa68, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_INT_STATUS", 0xa6c, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_MASK", 0xa70, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_ENABLE", 0xa74, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_DISABLE", 0xa78, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_TX_PAUSE_TIMER", 0xa7c, 0 }, - { "CurPauseTimer", 0, 16 }, - { "XGM_STAT_CTRL", 0xa80, 0 }, - { "ReadSnpShot", 4, 1 }, - { "TakeSnpShot", 3, 1 }, - { "ClrStats", 2, 1 }, - { "IncrStats", 1, 1 }, - { "EnTestModeWr", 0, 1 }, - { "XGM_RXFIFO_CFG", 0xa84, 0 }, - { "RxFIFOPauseHWM", 17, 12 }, - { "RxFIFOPauseLWM", 5, 12 }, - { "ForcedPause", 4, 1 }, - { "ExternLoopback", 3, 1 }, - { "RxByteSwap", 2, 1 }, - { "RxStrFrwrd", 1, 1 }, - { "DisErrFrames", 0, 1 }, - { "XGM_TXFIFO_CFG", 0xa88, 0 }, - { "TxIPG", 13, 8 }, - { "TxFIFOThresh", 4, 9 }, - { "InternLoopback", 3, 1 }, - { "TxByteSwap", 2, 1 }, - { "DisCRC", 1, 1 }, - { "DisPreAmble", 0, 1 }, - { "XGM_SLOW_TIMER", 0xa8c, 0 }, - { "PauseSlowTimerEn", 31, 1 }, - { "PauseSlowTimer", 0, 20 }, - { "XGM_SERDES_CTRL", 0xa90, 0 }, - { "SERDESEn", 25, 1 }, - { "SERDESReset_", 24, 1 }, - { "CMURange", 21, 3 }, - { "BGEnb", 20, 1 }, - { "EnSkpDrop", 19, 1 }, - { "EnComma", 18, 1 }, - { "En8B10B", 17, 1 }, - { "EnElBuf", 16, 1 }, - { "Gain", 11, 5 }, - { "BandGap", 7, 4 }, - { "LpbkEn", 5, 2 }, - { "RxEn", 4, 1 }, - { "TxEn", 3, 1 }, - { "RxComAdj", 2, 1 }, - { "PreEmph", 0, 2 }, - { "XGM_XAUI_PCS_TEST", 0xa94, 0 }, - { "TestPattern", 1, 2 }, - { "EnTest", 0, 1 }, - { "XGM_RGMII_CTRL", 0xa98, 0 }, - { "PhAlignFIFOThresh", 1, 2 }, - { "TxClk90Shift", 0, 1 }, - { "XGM_RGMII_IMP", 0xa9c, 0 }, - { "ImpSetUpdate", 6, 1 }, - { "RGMIIImpPD", 3, 3 }, - { "RGMIIImpPU", 0, 3 }, - { "XGM_XAUI_IMP", 0xaa0, 0 }, - { "CalBusy", 31, 1 }, - { "CalFault", 29, 1 }, - { "CalImp", 24, 5 }, - { "XAUIImp", 0, 3 }, - { "XGM_SERDES_BIST", 0xaa4, 0 }, - { "BISTDone", 28, 4 }, - { "BISTCycleThresh", 3, 17 }, - { "BISTMode", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE", 0xaa8, 0 }, - { "RxMaxPktSize", 0, 14 }, - { "XGM_RESET_CTRL", 0xaac, 0 }, - { "XG2G_Reset_", 3, 1 }, - { "RGMII_Reset_", 2, 1 }, - { "PCS_Reset_", 1, 1 }, - { "MAC_Reset_", 0, 1 }, - { "XGM_XAUI1G_CTRL", 0xab0, 0 }, - { "XAUI1GLinkId", 0, 2 }, - { "XGM_SERDES_LANE_CTRL", 0xab4, 0 }, - { "LaneReversal", 8, 1 }, - { "TxPolarity", 4, 4 }, - { "RxPolarity", 0, 4 }, - { "XGM_PORT_CFG", 0xab8, 0 }, - { "SafeSpeedChange", 4, 1 }, - { "ClkDivReset_", 3, 1 }, - { "PortSpeed", 1, 2 }, - { "EnRGMII", 0, 1 }, - { "XGM_EPIO_DATA0", 0xac0, 0 }, - { "XGM_EPIO_DATA1", 0xac4, 0 }, - { "XGM_EPIO_DATA2", 0xac8, 0 }, - { "XGM_EPIO_DATA3", 0xacc, 0 }, - { "XGM_EPIO_OP", 0xad0, 0 }, - { "PIO_Ready", 31, 1 }, - { "PIO_WrRd", 24, 1 }, - { "PIO_Address", 0, 8 }, - { "XGM_INT_ENABLE", 0xad4, 0 }, - { "SERDESCMULock_loss", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBIST_err", 8, 4 }, - { "SERDES_los", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_INT_CAUSE", 0xad8, 0 }, - { "SERDESCMULock_loss", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBIST_err", 8, 4 }, - { "SERDES_los", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_STAT_TX_BYTE_LOW", 0xb00, 0 }, - { "XGM_STAT_TX_BYTE_HIGH", 0xb04, 0 }, - { "TxBytes_high", 0, 13 }, - { "XGM_STAT_TX_FRAME_LOW", 0xb08, 0 }, - { "XGM_STAT_TX_FRAME_HIGH", 0xb0c, 0 }, - { "TxFrames_high", 0, 4 }, - { "XGM_STAT_TX_BCAST", 0xb10, 0 }, - { "XGM_STAT_TX_MCAST", 0xb14, 0 }, - { "XGM_STAT_TX_PAUSE", 0xb18, 0 }, - { "XGM_STAT_TX_64B_FRAMES", 0xb1c, 0 }, - { "XGM_STAT_TX_65_127B_FRAMES", 0xb20, 0 }, - { "XGM_STAT_TX_128_255B_FRAMES", 0xb24, 0 }, - { "XGM_STAT_TX_256_511B_FRAMES", 0xb28, 0 }, - { "XGM_STAT_TX_512_1023B_FRAMES", 0xb2c, 0 }, - { "XGM_STAT_TX_1024_1518B_FRAMES", 0xb30, 0 }, - { "XGM_STAT_TX_1519_MAXB_FRAMES", 0xb34, 0 }, - { "XGM_STAT_TX_ERR_FRAMES", 0xb38, 0 }, - { "XGM_STAT_RX_BYTES_LOW", 0xb3c, 0 }, - { "XGM_STAT_RX_BYTES_HIGH", 0xb40, 0 }, - { "RxBytes_high", 0, 13 }, - { "XGM_STAT_RX_FRAMES_LOW", 0xb44, 0 }, - { "XGM_STAT_RX_FRAMES_HIGH", 0xb48, 0 }, - { "RxFrames_high", 0, 4 }, - { "XGM_STAT_RX_BCAST_FRAMES", 0xb4c, 0 }, - { "XGM_STAT_RX_MCAST_FRAMES", 0xb50, 0 }, - { "XGM_STAT_RX_PAUSE_FRAMES", 0xb54, 0 }, - { "RxPauseFrames", 0, 16 }, - { "XGM_STAT_RX_64B_FRAMES", 0xb58, 0 }, - { "XGM_STAT_RX_65_127B_FRAMES", 0xb5c, 0 }, - { "XGM_STAT_RX_128_255B_FRAMES", 0xb60, 0 }, - { "XGM_STAT_RX_256_511B_FRAMES", 0xb64, 0 }, - { "XGM_STAT_RX_512_1023B_FRAMES", 0xb68, 0 }, - { "XGM_STAT_RX_1024_1518B_FRAMES", 0xb6c, 0 }, - { "XGM_STAT_RX_1519_MAXB_FRAMES", 0xb70, 0 }, - { "XGM_STAT_RX_SHORT_FRAMES", 0xb74, 0 }, - { "RxShortFrames", 0, 16 }, - { "XGM_STAT_RX_OVERSIZE_FRAMES", 0xb78, 0 }, - { "RxOversizeFrames", 0, 16 }, - { "XGM_STAT_RX_JABBER_FRAMES", 0xb7c, 0 }, - { "RxJabberFrames", 0, 16 }, - { "XGM_STAT_RX_CRC_ERR_FRAMES", 0xb80, 0 }, - { "RxCRCErrFrames", 0, 16 }, - { "XGM_STAT_RX_LENGTH_ERR_FRAMES", 0xb84, 0 }, - { "RxLengthErrFrames", 0, 16 }, - { "XGM_STAT_RX_SYM_CODE_ERR_FRAMES", 0xb88, 0 }, - { "RxSymCodeErrFrames", 0, 16 }, - { "XGM_SERDES_STATUS0", 0xb8c, 0 }, - { "RxErrLane3", 9, 3 }, - { "RxErrLane2", 6, 3 }, - { "RxErrLane1", 3, 3 }, - { "RxErrLane0", 0, 3 }, - { "XGM_SERDES_STATUS1", 0xb90, 0 }, - { "CMULock", 31, 1 }, - { "RxKLockLane3", 11, 1 }, - { "RxKLockLane2", 10, 1 }, - { "RxKLockLane1", 9, 1 }, - { "RxKLockLane0", 8, 1 }, - { "RxUFlowLane3", 7, 1 }, - { "RxUFlowLane2", 6, 1 }, - { "RxUFlowLane1", 5, 1 }, - { "RxUFlowLane0", 4, 1 }, - { "RxOFlowLane3", 3, 1 }, - { "RxOFlowLane2", 2, 1 }, - { "RxOFlowLane1", 1, 1 }, - { "RxOFlowLane0", 0, 1 }, - { "XGM_SERDES_STATUS2", 0xb94, 0 }, - { "RxEIDLane3", 11, 1 }, - { "RxEIDLane2", 10, 1 }, - { "RxEIDLane1", 9, 1 }, - { "RxEIDLane0", 8, 1 }, - { "RxRemSkipLane3", 7, 1 }, - { "RxRemSkipLane2", 6, 1 }, - { "RxRemSkipLane1", 5, 1 }, - { "RxRemSkipLane0", 4, 1 }, - { "RxAddSkipLane3", 3, 1 }, - { "RxAddSkipLane2", 2, 1 }, - { "RxAddSkipLane1", 1, 1 }, - { "RxAddSkipLane0", 0, 1 }, - { "XGM_XAUI_PCS_ERR", 0xb98, 0 }, - { "PCS_SyncStatus", 5, 4 }, - { "PCS_CTCFIFOErr", 1, 4 }, - { "PCS_NotAligned", 0, 1 }, - { "XGM_RGMII_STATUS", 0xb9c, 0 }, - { "GMIIDuplex", 3, 1 }, - { "GMIISpeed", 1, 2 }, - { "GMIILinkStatus", 0, 1 }, - { "XGM_WOL_STATUS", 0xba0, 0 }, - { "PatDetected", 31, 1 }, - { "MatchedFilter", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE_ERR_CNT", 0xba4, 0 }, - { "XGM_TX_SPI4_SOP_EOP_CNT", 0xba8, 0 }, - { "TxSPI4SopCnt", 16, 16 }, - { "TxSPI4EopCnt", 0, 16 }, - { "XGM_RX_SPI4_SOP_EOP_CNT", 0xbac, 0 }, - { "RxSPI4SopCnt", 16, 16 }, - { "RxSPI4EopCnt", 0, 16 }, - { NULL, 0, 0 } -}; diff --git a/usr.sbin/cxgbtool/reg_defs_t3b.c b/usr.sbin/cxgbtool/reg_defs_t3b.c deleted file mode 100644 index cd85d84..0000000 --- a/usr.sbin/cxgbtool/reg_defs_t3b.c +++ /dev/null @@ -1,2832 +0,0 @@ -/* - * $FreeBSD$ - */ - -/* This file is automatically generated --- do not edit */ - -struct reg_info t3b_sge3_regs[] = { - { "SG_CONTROL", 0x0, 0 }, - { "UrgTnl", 26, 1 }, - { "NewNotify", 25, 1 }, - { "AvoidCqOvfl", 24, 1 }, - { "OptOneIntMultQ", 23, 1 }, - { "CQCrdtCtrl", 22, 1 }, - { "EgrEnUpBp", 21, 1 }, - { "DropPkt", 20, 1 }, - { "EgrGenCtrl", 19, 1 }, - { "UserSpaceSize", 14, 5 }, - { "HostPageSize", 11, 3 }, - { "PCIRelax", 10, 1 }, - { "FLMode", 9, 1 }, - { "PktShift", 6, 3 }, - { "OneIntMultQ", 5, 1 }, - { "FLPickAvail", 4, 1 }, - { "BigEndianEgress", 3, 1 }, - { "BigEndianIngress", 2, 1 }, - { "IscsiCoalescing", 1, 1 }, - { "GlobalEnable", 0, 1 }, - { "SG_KDOORBELL", 0x4, 0 }, - { "SelEgrCntx", 31, 1 }, - { "EgrCntx", 0, 16 }, - { "SG_GTS", 0x8, 0 }, - { "RspQ", 29, 3 }, - { "NewTimer", 16, 13 }, - { "NewIndex", 0, 16 }, - { "SG_CONTEXT_CMD", 0xc, 0 }, - { "Opcode", 28, 4 }, - { "Busy", 27, 1 }, - { "CQ_credit", 20, 7 }, - { "CQ", 19, 1 }, - { "RspQ", 18, 1 }, - { "Egress", 17, 1 }, - { "FreeList", 16, 1 }, - { "Context", 0, 16 }, - { "SG_CONTEXT_DATA0", 0x10, 0 }, - { "SG_CONTEXT_DATA1", 0x14, 0 }, - { "SG_CONTEXT_DATA2", 0x18, 0 }, - { "SG_CONTEXT_DATA3", 0x1c, 0 }, - { "SG_CONTEXT_MASK0", 0x20, 0 }, - { "SG_CONTEXT_MASK1", 0x24, 0 }, - { "SG_CONTEXT_MASK2", 0x28, 0 }, - { "SG_CONTEXT_MASK3", 0x2c, 0 }, - { "SG_RSPQ_CREDIT_RETURN", 0x30, 0 }, - { "RspQ", 29, 3 }, - { "Data", 0, 16 }, - { "SG_DATA_INTR", 0x34, 0 }, - { "ErrIntr", 31, 1 }, - { "DataIntr", 0, 8 }, - { "SG_HI_DRB_HI_THRSH", 0x38, 0 }, - { "HiDrbHiThrsh", 0, 10 }, - { "SG_HI_DRB_LO_THRSH", 0x3c, 0 }, - { "HiDrbLoThrsh", 0, 10 }, - { "SG_LO_DRB_HI_THRSH", 0x40, 0 }, - { "LoDrbHiThrsh", 0, 10 }, - { "SG_LO_DRB_LO_THRSH", 0x44, 0 }, - { "LoDrbLoThrsh", 0, 10 }, - { "SG_ONE_INT_MULT_Q_COALESCING_TIMER", 0x48, 0 }, - { "SG_RSPQ_FL_STATUS", 0x4c, 0 }, - { "RspQ0Starved", 0, 1 }, - { "RspQ1Starved", 1, 1 }, - { "RspQ2Starved", 2, 1 }, - { "RspQ3Starved", 3, 1 }, - { "RspQ4Starved", 4, 1 }, - { "RspQ5Starved", 5, 1 }, - { "RspQ6Starved", 6, 1 }, - { "RspQ7Starved", 7, 1 }, - { "RspQ0Disabled", 8, 1 }, - { "RspQ1Disabled", 9, 1 }, - { "RspQ2Disabled", 10, 1 }, - { "RspQ3Disabled", 11, 1 }, - { "RspQ4Disabled", 12, 1 }, - { "RspQ5Disabled", 13, 1 }, - { "RspQ6Disabled", 14, 1 }, - { "RspQ7Disabled", 15, 1 }, - { "FL0Empty", 16, 1 }, - { "FL1Empty", 17, 1 }, - { "FL2Empty", 18, 1 }, - { "FL3Empty", 19, 1 }, - { "FL4Empty", 20, 1 }, - { "FL5Empty", 21, 1 }, - { "FL6Empty", 22, 1 }, - { "FL7Empty", 23, 1 }, - { "FL8Empty", 24, 1 }, - { "FL9Empty", 25, 1 }, - { "FL10Empty", 26, 1 }, - { "FL11Empty", 27, 1 }, - { "FL12Empty", 28, 1 }, - { "FL13Empty", 29, 1 }, - { "FL14Empty", 30, 1 }, - { "FL15Empty", 31, 1 }, - { "SG_EGR_PRI_CNT", 0x50, 0 }, - { "EgrErrOpCode", 24, 8 }, - { "EgrHiOpCode", 16, 8 }, - { "EgrLoOpCode", 8, 8 }, - { "EgrPriCnt", 0, 5 }, - { "SG_EGR_RCQ_DRB_THRSH", 0x54, 0 }, - { "HiRcqDrbThrsh", 16, 11 }, - { "LoRcqDrbThrsh", 0, 11 }, - { "SG_EGR_CNTX_BADDR", 0x58, 0 }, - { "EgrCntxBAddr", 5, 27 }, - { "SG_INT_CAUSE", 0x5c, 0 }, - { "HiCtlDrbDropErr", 13, 1 }, - { "LoCtlDrbDropErr", 12, 1 }, - { "HiPioDrbDropErr", 11, 1 }, - { "LoPioDrbDropErr", 10, 1 }, - { "HiCrdtUndFlowErr", 9, 1 }, - { "LoCrdtUndFlowErr", 8, 1 }, - { "HiPriorityDBFull", 7, 1 }, - { "HiPriorityDBEmpty", 6, 1 }, - { "LoPriorityDBFull", 5, 1 }, - { "LoPriorityDBEmpty", 4, 1 }, - { "RspQDisabled", 3, 1 }, - { "RspQCreditOverfow", 2, 1 }, - { "FlEmpty", 1, 1 }, - { "RspQStarve", 0, 1 }, - { "SG_INT_ENABLE", 0x60, 0 }, - { "HiCtlDrbDropErr", 13, 1 }, - { "LoCtlDrbDropErr", 12, 1 }, - { "HiPioDrbDropErr", 11, 1 }, - { "LoPioDrbDropErr", 10, 1 }, - { "HiCrdtUndFlowErr", 9, 1 }, - { "LoCrdtUndFlowErr", 8, 1 }, - { "HiPriorityDBFull", 7, 1 }, - { "HiPriorityDBEmpty", 6, 1 }, - { "LoPriorityDBFull", 5, 1 }, - { "LoPriorityDBEmpty", 4, 1 }, - { "RspQDisabled", 3, 1 }, - { "RspQCreditOverfow", 2, 1 }, - { "FlEmpty", 1, 1 }, - { "RspQStarve", 0, 1 }, - { "SG_CMDQ_CREDIT_TH", 0x64, 0 }, - { "Timeout", 8, 24 }, - { "Threshold", 0, 8 }, - { "SG_TIMER_TICK", 0x68, 0 }, - { "SG_CQ_CONTEXT_BADDR", 0x6c, 0 }, - { "baseAddr", 5, 27 }, - { "SG_OCO_BASE", 0x70, 0 }, - { "Base1", 16, 16 }, - { "Base0", 0, 16 }, - { "SG_DRB_PRI_THRESH", 0x74, 0 }, - { "DrbPriThrsh", 0, 16 }, - { "SG_DEBUG_INDEX", 0x78, 0 }, - { "SG_DEBUG_DATA", 0x7c, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_pcix1_regs[] = { - { "PCIX_INT_ENABLE", 0x80, 0 }, - { "MSIXParErr", 22, 3 }, - { "CFParErr", 18, 4 }, - { "RFParErr", 14, 4 }, - { "WFParErr", 12, 2 }, - { "PIOParErr", 11, 1 }, - { "DetUncECCErr", 10, 1 }, - { "DetCorECCErr", 9, 1 }, - { "RcvSplCmpErr", 8, 1 }, - { "UnxSplCmp", 7, 1 }, - { "SplCmpDis", 6, 1 }, - { "DetParErr", 5, 1 }, - { "SigSysErr", 4, 1 }, - { "RcvMstAbt", 3, 1 }, - { "RcvTarAbt", 2, 1 }, - { "SigTarAbt", 1, 1 }, - { "MstDetParErr", 0, 1 }, - { "PCIX_INT_CAUSE", 0x84, 0 }, - { "MSIXParErr", 22, 3 }, - { "CFParErr", 18, 4 }, - { "RFParErr", 14, 4 }, - { "WFParErr", 12, 2 }, - { "PIOParErr", 11, 1 }, - { "DetUncECCErr", 10, 1 }, - { "DetCorECCErr", 9, 1 }, - { "RcvSplCmpErr", 8, 1 }, - { "UnxSplCmp", 7, 1 }, - { "SplCmpDis", 6, 1 }, - { "DetParErr", 5, 1 }, - { "SigSysErr", 4, 1 }, - { "RcvMstAbt", 3, 1 }, - { "RcvTarAbt", 2, 1 }, - { "SigTarAbt", 1, 1 }, - { "MstDetParErr", 0, 1 }, - { "PCIX_CFG", 0x88, 0 }, - { "CLIDecEn", 18, 1 }, - { "LatTmrDis", 17, 1 }, - { "LowPwrEn", 16, 1 }, - { "AsyncIntVec", 11, 5 }, - { "MaxSplTrnC", 8, 3 }, - { "MaxSplTrnR", 5, 3 }, - { "MaxWrByteCnt", 3, 2 }, - { "WrReqAtomicEn", 2, 1 }, - { "CRstWrmMode", 1, 1 }, - { "PIOAck64En", 0, 1 }, - { "PCIX_MODE", 0x8c, 0 }, - { "PClkRange", 6, 2 }, - { "PCIXInitPat", 2, 4 }, - { "66MHz", 1, 1 }, - { "64Bit", 0, 1 }, - { "PCIX_CAL", 0x90, 0 }, - { "Busy", 31, 1 }, - { "PerCalDiv", 22, 8 }, - { "PerCalEn", 21, 1 }, - { "SglCalEn", 20, 1 }, - { "ZInUpdMode", 19, 1 }, - { "ZInSel", 18, 1 }, - { "ZPDMan", 15, 3 }, - { "ZPUMan", 12, 3 }, - { "ZPDOut", 9, 3 }, - { "ZPUOut", 6, 3 }, - { "ZPDIn", 3, 3 }, - { "ZPUIn", 0, 3 }, - { "PCIX_WOL", 0x94, 0 }, - { "WakeUp1", 3, 1 }, - { "WakeUp0", 2, 1 }, - { "SleepMode1", 1, 1 }, - { "SleepMode0", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_pcie0_regs[] = { - { "PCIE_INT_ENABLE", 0x80, 0 }, - { "BISTErr", 15, 8 }, - { "MSIXParErr", 12, 3 }, - { "CFParErr", 11, 1 }, - { "RFParErr", 10, 1 }, - { "WFParErr", 9, 1 }, - { "PIOParErr", 8, 1 }, - { "UnxSplCplErrC", 7, 1 }, - { "UnxSplCplErrR", 6, 1 }, - { "VPDAddrChng", 5, 1 }, - { "BusMstrEn", 4, 1 }, - { "PMStChng", 3, 1 }, - { "PEXMsg", 2, 1 }, - { "ZeroLenRd", 1, 1 }, - { "PEXErr", 0, 1 }, - { "PCIE_INT_CAUSE", 0x84, 0 }, - { "BISTErr", 15, 8 }, - { "MSIXParErr", 12, 3 }, - { "CFParErr", 11, 1 }, - { "RFParErr", 10, 1 }, - { "WFParErr", 9, 1 }, - { "PIOParErr", 8, 1 }, - { "UnxSplCplErrC", 7, 1 }, - { "UnxSplCplErrR", 6, 1 }, - { "VPDAddrChng", 5, 1 }, - { "BusMstrEn", 4, 1 }, - { "PMStChng", 3, 1 }, - { "PEXMsg", 2, 1 }, - { "ZeroLenRd", 1, 1 }, - { "PEXErr", 0, 1 }, - { "PCIE_CFG", 0x88, 0 }, - { "PriorityINTA", 23, 1 }, - { "IniFullPkt", 22, 1 }, - { "EnableLinkDwnDRst", 21, 1 }, - { "EnableLinkDownRst", 20, 1 }, - { "EnableHotRst", 19, 1 }, - { "IniWaitForGnt", 18, 1 }, - { "IniBEDis", 17, 1 }, - { "CLIDecEn", 16, 1 }, - { "AsyncIntVec", 11, 5 }, - { "MaxSplTrnC", 7, 4 }, - { "MaxSplTrnR", 1, 6 }, - { "CRstWrmMode", 0, 1 }, - { "PCIE_MODE", 0x8c, 0 }, - { "NumFstTrnSeqRx", 10, 8 }, - { "LnkCntlState", 2, 8 }, - { "VC0Up", 1, 1 }, - { "LnkInitial", 0, 1 }, - { "PCIE_WOL", 0x94, 0 }, - { "WakeUp1", 3, 1 }, - { "WakeUp0", 2, 1 }, - { "SleepMode1", 1, 1 }, - { "SleepMode0", 0, 1 }, - { "PCIE_PEX_CTRL0", 0x98, 0 }, - { "CplTimeoutRetry", 31, 1 }, - { "StrictTSMN", 30, 1 }, - { "NumFstTrnSeq", 22, 8 }, - { "ReplayLmt", 2, 20 }, - { "TxPndChkEn", 1, 1 }, - { "CplPndChkEn", 0, 1 }, - { "PCIE_PEX_CTRL1", 0x9c, 0 }, - { "RxPhyErrEn", 31, 1 }, - { "DLLPTimeoutLmt", 13, 18 }, - { "AckLat", 0, 13 }, - { "PCIE_PEX_CTRL2", 0xa0, 0 }, - { "LnkCntlDetDir", 30, 1 }, - { "EnterL1rEn", 29, 1 }, - { "PMExitL1Req", 28, 1 }, - { "PMTxIdle", 27, 1 }, - { "PCIModeLoop", 26, 1 }, - { "L1ASPMTxRxL0sTime", 14, 12 }, - { "L0sIdleTime", 3, 11 }, - { "EnterL1ASPMEn", 2, 1 }, - { "EnterL1En", 1, 1 }, - { "EnterL0sEn", 0, 1 }, - { "PCIE_PEX_ERR", 0xa4, 0 }, - { "CplTimeoutID", 18, 7 }, - { "FlowCtlOFlowErr", 17, 1 }, - { "ReplayTimeout", 16, 1 }, - { "ReplayRollover", 15, 1 }, - { "BadDLLP", 14, 1 }, - { "DLLPErr", 13, 1 }, - { "FlowCtlProtErr", 12, 1 }, - { "CplTimeout", 11, 1 }, - { "PHYRcvErr", 10, 1 }, - { "DisTLP", 9, 1 }, - { "BadECRC", 8, 1 }, - { "BadTLP", 7, 1 }, - { "MalTLP", 6, 1 }, - { "UnxCpl", 5, 1 }, - { "UnsReq", 4, 1 }, - { "PsnReq", 3, 1 }, - { "UnsCpl", 2, 1 }, - { "CplAbt", 1, 1 }, - { "PsnCpl", 0, 1 }, - { "PCIE_SERDES_CTRL", 0xa8, 0 }, - { "PMASel", 3, 1 }, - { "Lane", 0, 3 }, - { "PCIE_SERDES_QUAD_CTRL0", 0xac, 0 }, - { "TestSig", 10, 19 }, - { "Offset", 2, 8 }, - { "OffsetEn", 1, 1 }, - { "IDDQb", 0, 1 }, - { "PCIE_SERDES_QUAD_CTRL1", 0xb0, 0 }, - { "FastInit", 28, 1 }, - { "CTCDisable", 27, 1 }, - { "ManResetPLL", 26, 1 }, - { "ManL2Pwrdn", 25, 1 }, - { "ManQuadEn", 24, 1 }, - { "RxEqCtl", 22, 2 }, - { "HiVMode", 21, 1 }, - { "RefSel", 19, 2 }, - { "RxTermAdj", 17, 2 }, - { "TxTermAdj", 15, 2 }, - { "Deq", 11, 4 }, - { "Dtx", 7, 4 }, - { "LoDrv", 6, 1 }, - { "HiDrv", 5, 1 }, - { "IntParReset", 4, 1 }, - { "IntParLPBK", 3, 1 }, - { "IntSerLPBKwDrv", 2, 1 }, - { "PW", 1, 1 }, - { "PClkDetect", 0, 1 }, - { "PCIE_SERDES_LANE_CTRL", 0xb4, 0 }, - { "ExtBISTChkErrClr", 22, 1 }, - { "ExtBISTChkEn", 21, 1 }, - { "ExtBISTGenEn", 20, 1 }, - { "ExtBISTPat", 17, 3 }, - { "ExtParReset", 16, 1 }, - { "ExtParLPBK", 15, 1 }, - { "ManRxTermEn", 14, 1 }, - { "ManBeaconTxEn", 13, 1 }, - { "ManRxDetectEn", 12, 1 }, - { "ManTxIdleEn", 11, 1 }, - { "ManRxIdleEn", 10, 1 }, - { "ManL1Pwrdn", 9, 1 }, - { "ManReset", 8, 1 }, - { "ManFmOffset", 3, 5 }, - { "ManFmOffsetEn", 2, 1 }, - { "ManLaneEn", 1, 1 }, - { "IntSerLPBK", 0, 1 }, - { "PCIE_SERDES_LANE_STAT", 0xb8, 0 }, - { "ExtBISTChkErrCnt", 8, 24 }, - { "ExtBISTChkFmd", 7, 1 }, - { "BeaconDetectChg", 6, 1 }, - { "RxDetectChg", 5, 1 }, - { "TxIdleDetectChg", 4, 1 }, - { "BeaconDetect", 2, 1 }, - { "RxDetect", 1, 1 }, - { "TxIdleDetect", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_t3dbg_regs[] = { - { "T3DBG_DBG0_CFG", 0xc0, 0 }, - { "RegSelect", 9, 8 }, - { "ModuleSelect", 4, 5 }, - { "ClkSelect", 0, 4 }, - { "T3DBG_DBG0_EN", 0xc4, 0 }, - { "SDRByte0", 8, 1 }, - { "DDREn", 4, 1 }, - { "PortEn", 0, 1 }, - { "T3DBG_DBG1_CFG", 0xc8, 0 }, - { "RegSelect", 9, 8 }, - { "ModuleSelect", 4, 5 }, - { "ClkSelect", 0, 4 }, - { "T3DBG_DBG1_EN", 0xcc, 0 }, - { "SDRByte0", 8, 1 }, - { "DDREn", 4, 1 }, - { "PortEn", 0, 1 }, - { "T3DBG_GPIO_EN", 0xd0, 0 }, - { "GPIO11_OEn", 27, 1 }, - { "GPIO10_OEn", 26, 1 }, - { "GPIO9_OEn", 25, 1 }, - { "GPIO8_OEn", 24, 1 }, - { "GPIO7_OEn", 23, 1 }, - { "GPIO6_OEn", 22, 1 }, - { "GPIO5_OEn", 21, 1 }, - { "GPIO4_OEn", 20, 1 }, - { "GPIO3_OEn", 19, 1 }, - { "GPIO2_OEn", 18, 1 }, - { "GPIO1_OEn", 17, 1 }, - { "GPIO0_OEn", 16, 1 }, - { "GPIO11_Out_Val", 11, 1 }, - { "GPIO10_Out_Val", 10, 1 }, - { "GPIO9_Out_Val", 9, 1 }, - { "GPIO8_Out_Val", 8, 1 }, - { "GPIO7_Out_Val", 7, 1 }, - { "GPIO6_Out_Val", 6, 1 }, - { "GPIO5_Out_Val", 5, 1 }, - { "GPIO4_Out_Val", 4, 1 }, - { "GPIO3_Out_Val", 3, 1 }, - { "GPIO2_Out_Val", 2, 1 }, - { "GPIO1_Out_Val", 1, 1 }, - { "GPIO0_Out_Val", 0, 1 }, - { "T3DBG_GPIO_IN", 0xd4, 0 }, - { "GPIO11_CHG_DET", 27, 1 }, - { "GPIO10_CHG_DET", 26, 1 }, - { "GPIO9_CHG_DET", 25, 1 }, - { "GPIO8_CHG_DET", 24, 1 }, - { "GPIO7_CHG_DET", 23, 1 }, - { "GPIO6_CHG_DET", 22, 1 }, - { "GPIO5_CHG_DET", 21, 1 }, - { "GPIO4_CHG_DET", 20, 1 }, - { "GPIO3_CHG_DET", 19, 1 }, - { "GPIO2_CHG_DET", 18, 1 }, - { "GPIO1_CHG_DET", 17, 1 }, - { "GPIO0_CHG_DET", 16, 1 }, - { "GPIO11_IN", 11, 1 }, - { "GPIO10_IN", 10, 1 }, - { "GPIO9_IN", 9, 1 }, - { "GPIO8_IN", 8, 1 }, - { "GPIO7_IN", 7, 1 }, - { "GPIO6_IN", 6, 1 }, - { "GPIO5_IN", 5, 1 }, - { "GPIO4_IN", 4, 1 }, - { "GPIO3_IN", 3, 1 }, - { "GPIO2_IN", 2, 1 }, - { "GPIO1_IN", 1, 1 }, - { "GPIO0_IN", 0, 1 }, - { "T3DBG_INT_ENABLE", 0xd8, 0 }, - { "C_LOCK", 21, 1 }, - { "M_LOCK", 20, 1 }, - { "U_LOCK", 19, 1 }, - { "R_LOCK", 18, 1 }, - { "PX_LOCK", 17, 1 }, - { "GPIO11", 11, 1 }, - { "GPIO10", 10, 1 }, - { "GPIO9", 9, 1 }, - { "GPIO8", 8, 1 }, - { "GPIO7", 7, 1 }, - { "GPIO6", 6, 1 }, - { "GPIO5", 5, 1 }, - { "GPIO4", 4, 1 }, - { "GPIO3", 3, 1 }, - { "GPIO2", 2, 1 }, - { "GPIO1", 1, 1 }, - { "GPIO0", 0, 1 }, - { "T3DBG_INT_CAUSE", 0xdc, 0 }, - { "C_LOCK", 21, 1 }, - { "M_LOCK", 20, 1 }, - { "U_LOCK", 19, 1 }, - { "R_LOCK", 18, 1 }, - { "PX_LOCK", 17, 1 }, - { "GPIO11", 11, 1 }, - { "GPIO10", 10, 1 }, - { "GPIO9", 9, 1 }, - { "GPIO8", 8, 1 }, - { "GPIO7", 7, 1 }, - { "GPIO6", 6, 1 }, - { "GPIO5", 5, 1 }, - { "GPIO4", 4, 1 }, - { "GPIO3", 3, 1 }, - { "GPIO2", 2, 1 }, - { "GPIO1", 1, 1 }, - { "GPIO0", 0, 1 }, - { "T3DBG_DBG0_RST_VALUE", 0xe0, 0 }, - { "DebugData", 0, 8 }, - { "T3DBG_PLL_OCLK_PAD_EN", 0xe4, 0 }, - { "PCIE_OCLK_En", 20, 1 }, - { "PClkTree_DBG_En", 17, 1 }, - { "PCIX_OCLK_En", 16, 1 }, - { "U_OCLK_En", 12, 1 }, - { "R_OCLK_En", 8, 1 }, - { "M_OCLK_En", 4, 1 }, - { "C_OCLK_En", 0, 1 }, - { "T3DBG_PLL_LOCK", 0xe8, 0 }, - { "PCIX_LOCK", 16, 1 }, - { "U_LOCK", 12, 1 }, - { "R_LOCK", 8, 1 }, - { "M_LOCK", 4, 1 }, - { "C_LOCK", 0, 1 }, - { "T3DBG_SERDES_RBC_CFG", 0xec, 0 }, - { "X_RBC_Lane_Sel", 16, 2 }, - { "X_RBC_Dbg_En", 12, 1 }, - { "X_Serdes_Sel", 8, 1 }, - { "PE_RBC_Lane_Sel", 4, 3 }, - { "PE_RBC_Dbg_En", 0, 1 }, - { "T3DBG_GPIO_ACT_LOW", 0xf0, 0 }, - { "C_LOCK_ACT_LOW", 21, 1 }, - { "M_LOCK_ACT_LOW", 20, 1 }, - { "U_LOCK_ACT_LOW", 19, 1 }, - { "R_LOCK_ACT_LOW", 18, 1 }, - { "PX_LOCK_ACT_LOW", 17, 1 }, - { "GPIO11_ACT_LOW", 11, 1 }, - { "GPIO10_ACT_LOW", 10, 1 }, - { "GPIO9_ACT_LOW", 9, 1 }, - { "GPIO8_ACT_LOW", 8, 1 }, - { "GPIO7_ACT_LOW", 7, 1 }, - { "GPIO6_ACT_LOW", 6, 1 }, - { "GPIO5_ACT_LOW", 5, 1 }, - { "GPIO4_ACT_LOW", 4, 1 }, - { "GPIO3_ACT_LOW", 3, 1 }, - { "GPIO2_ACT_LOW", 2, 1 }, - { "GPIO1_ACT_LOW", 1, 1 }, - { "GPIO0_ACT_LOW", 0, 1 }, - { "T3DBG_PMON_CFG", 0xf4, 0 }, - { "PMON_DONE", 29, 1 }, - { "PMON_FAIL", 28, 1 }, - { "PMON_FDEL_AUTO", 22, 6 }, - { "PMON_CDEL_AUTO", 16, 6 }, - { "PMON_FDEL_MANUAL", 10, 6 }, - { "PMON_CDEL_MANUAL", 4, 6 }, - { "PMON_MANUAL", 1, 1 }, - { "PMON_AUTO", 0, 1 }, - { "T3DBG_SERDES_REFCLK_CFG", 0xf8, 0 }, - { "PE_REFCLK_DBG_EN", 12, 1 }, - { "X_REFCLK_DBG_EN", 8, 1 }, - { "PE_REFCLK_TERMADJ", 5, 2 }, - { "PE_REFCLK_PD", 4, 1 }, - { "X_REFCLK_TERMADJ", 1, 2 }, - { "X_REFCLK_PD", 0, 1 }, - { "T3DBG_PCIE_PMA_BSPIN_CFG", 0xfc, 0 }, - { "BSModeQuad1", 31, 1 }, - { "BSInSelLane7", 29, 2 }, - { "BSEnLane7", 28, 1 }, - { "BSInSelLane6", 25, 2 }, - { "BSEnLane6", 24, 1 }, - { "BSInSelLane5", 21, 2 }, - { "BSEnLane5", 20, 1 }, - { "BSInSelLane4", 17, 2 }, - { "BSEnLane4", 16, 1 }, - { "BSModeQuad0", 15, 1 }, - { "BSInSelLane3", 13, 2 }, - { "BSEnLane3", 12, 1 }, - { "BSInSelLane2", 9, 2 }, - { "BSEnLane2", 8, 1 }, - { "BSInSelLane1", 5, 2 }, - { "BSEnLane1", 4, 1 }, - { "BSInSelLane0", 1, 2 }, - { "BSEnLane0", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_mc7_pmrx_regs[] = { - { "MC7_CFG", 0x100, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x104, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x108, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x10c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x110, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x114, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x118, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x11c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x120, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x124, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x128, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ERR_ADDR", 0x12c, 0 }, - { "ErrAddress", 3, 29 }, - { "ErrAgent", 1, 2 }, - { "ErrOp", 0, 1 }, - { "MC7_ECC", 0x130, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x134, 0 }, - { "MC7_CE_DATA0", 0x138, 0 }, - { "MC7_CE_DATA1", 0x13c, 0 }, - { "MC7_CE_DATA2", 0x140, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x144, 0 }, - { "MC7_UE_DATA0", 0x148, 0 }, - { "MC7_UE_DATA1", 0x14c, 0 }, - { "MC7_UE_DATA2", 0x150, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x154, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x158, 0 }, - { "MC7_BD_DATA1", 0x15c, 0 }, - { "MC7_BD_DATA2", 0x160, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x164, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x168, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x16c, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x170, 0 }, - { "MC7_BIST_OP", 0x174, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x178, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x17c, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_mc7_pmtx_regs[] = { - { "MC7_CFG", 0x180, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x184, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x188, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x18c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x190, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x194, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x198, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x19c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x1a0, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x1a4, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x1a8, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ERR_ADDR", 0x1ac, 0 }, - { "ErrAddress", 3, 29 }, - { "ErrAgent", 1, 2 }, - { "ErrOp", 0, 1 }, - { "MC7_ECC", 0x1b0, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x1b4, 0 }, - { "MC7_CE_DATA0", 0x1b8, 0 }, - { "MC7_CE_DATA1", 0x1bc, 0 }, - { "MC7_CE_DATA2", 0x1c0, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x1c4, 0 }, - { "MC7_UE_DATA0", 0x1c8, 0 }, - { "MC7_UE_DATA1", 0x1cc, 0 }, - { "MC7_UE_DATA2", 0x1d0, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x1d4, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x1d8, 0 }, - { "MC7_BD_DATA1", 0x1dc, 0 }, - { "MC7_BD_DATA2", 0x1e0, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x1e4, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x1e8, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x1ec, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x1f0, 0 }, - { "MC7_BIST_OP", 0x1f4, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x1f8, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x1fc, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_mc7_cm_regs[] = { - { "MC7_CFG", 0x200, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x204, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x208, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x20c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x210, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x214, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x218, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x21c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x220, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x224, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x228, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ERR_ADDR", 0x22c, 0 }, - { "ErrAddress", 3, 29 }, - { "ErrAgent", 1, 2 }, - { "ErrOp", 0, 1 }, - { "MC7_ECC", 0x230, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x234, 0 }, - { "MC7_CE_DATA0", 0x238, 0 }, - { "MC7_CE_DATA1", 0x23c, 0 }, - { "MC7_CE_DATA2", 0x240, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x244, 0 }, - { "MC7_UE_DATA0", 0x248, 0 }, - { "MC7_UE_DATA1", 0x24c, 0 }, - { "MC7_UE_DATA2", 0x250, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x254, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x258, 0 }, - { "MC7_BD_DATA1", 0x25c, 0 }, - { "MC7_BD_DATA2", 0x260, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x264, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x268, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x26c, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x270, 0 }, - { "MC7_BIST_OP", 0x274, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x278, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x27c, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_cim_regs[] = { - { "CIM_BOOT_CFG", 0x280, 0 }, - { "BootAddr", 2, 30 }, - { "BootSdram", 1, 1 }, - { "uPCRst", 0, 1 }, - { "CIM_FLASH_BASE_ADDR", 0x284, 0 }, - { "FlashBaseAddr", 2, 22 }, - { "CIM_FLASH_ADDR_SIZE", 0x288, 0 }, - { "FlashAddrSize", 2, 22 }, - { "CIM_SDRAM_BASE_ADDR", 0x28c, 0 }, - { "SdramBaseAddr", 2, 30 }, - { "CIM_SDRAM_ADDR_SIZE", 0x290, 0 }, - { "SdramAddrSize", 2, 30 }, - { "CIM_UP_SPARE_INT", 0x294, 0 }, - { "uPSpareInt", 0, 3 }, - { "CIM_HOST_INT_ENABLE", 0x298, 0 }, - { "Timer1IntEn", 15, 1 }, - { "Timer0IntEn", 14, 1 }, - { "PrefDropIntEn", 13, 1 }, - { "BlkWrPlIntEn", 12, 1 }, - { "BlkRdPlIntEn", 11, 1 }, - { "BlkWrCtlIntEn", 10, 1 }, - { "BlkRdCtlIntEn", 9, 1 }, - { "BlkWrFlashIntEn", 8, 1 }, - { "BlkRdFlashIntEn", 7, 1 }, - { "SglWrFlashIntEn", 6, 1 }, - { "WrBlkFlashIntEn", 5, 1 }, - { "BlkWrBootIntEn", 4, 1 }, - { "BlkRdBootIntEn", 3, 1 }, - { "FlashRangeIntEn", 2, 1 }, - { "SdramRangeIntEn", 1, 1 }, - { "RsvdSpaceIntEn", 0, 1 }, - { "CIM_HOST_INT_CAUSE", 0x29c, 0 }, - { "Timer1Int", 15, 1 }, - { "Timer0Int", 14, 1 }, - { "PrefDropInt", 13, 1 }, - { "BlkWrPlInt", 12, 1 }, - { "BlkRdPlInt", 11, 1 }, - { "BlkWrCtlInt", 10, 1 }, - { "BlkRdCtlInt", 9, 1 }, - { "BlkWrFlashInt", 8, 1 }, - { "BlkRdFlashInt", 7, 1 }, - { "SglWrFlashInt", 6, 1 }, - { "WrBlkFlashInt", 5, 1 }, - { "BlkWrBootInt", 4, 1 }, - { "BlkRdBootInt", 3, 1 }, - { "FlashRangeInt", 2, 1 }, - { "SdramRangeInt", 1, 1 }, - { "RsvdSpaceInt", 0, 1 }, - { "CIM_UP_INT_ENABLE", 0x2a0, 0 }, - { "MstPlIntEn", 16, 1 }, - { "Timer1IntEn", 15, 1 }, - { "Timer0IntEn", 14, 1 }, - { "PrefDropIntEn", 13, 1 }, - { "BlkWrPlIntEn", 12, 1 }, - { "BlkRdPlIntEn", 11, 1 }, - { "BlkWrCtlIntEn", 10, 1 }, - { "BlkRdCtlIntEn", 9, 1 }, - { "BlkWrFlashIntEn", 8, 1 }, - { "BlkRdFlashIntEn", 7, 1 }, - { "SglWrFlashIntEn", 6, 1 }, - { "WrBlkFlashIntEn", 5, 1 }, - { "BlkWrBootIntEn", 4, 1 }, - { "BlkRdBootIntEn", 3, 1 }, - { "FlashRangeIntEn", 2, 1 }, - { "SdramRangeIntEn", 1, 1 }, - { "RsvdSpaceIntEn", 0, 1 }, - { "CIM_UP_INT_CAUSE", 0x2a4, 0 }, - { "MstPlInt", 16, 1 }, - { "Timer1Int", 15, 1 }, - { "Timer0Int", 14, 1 }, - { "PrefDropInt", 13, 1 }, - { "BlkWrPlInt", 12, 1 }, - { "BlkRdPlInt", 11, 1 }, - { "BlkWrCtlInt", 10, 1 }, - { "BlkRdCtlInt", 9, 1 }, - { "BlkWrFlashInt", 8, 1 }, - { "BlkRdFlashInt", 7, 1 }, - { "SglWrFlashInt", 6, 1 }, - { "WrBlkFlashInt", 5, 1 }, - { "BlkWrBootInt", 4, 1 }, - { "BlkRdBootInt", 3, 1 }, - { "FlashRangeInt", 2, 1 }, - { "SdramRangeInt", 1, 1 }, - { "RsvdSpaceInt", 0, 1 }, - { "CIM_IBQ_FULLA_THRSH", 0x2a8, 0 }, - { "Ibq0FullThrsh", 0, 9 }, - { "Ibq1FullThrsh", 16, 9 }, - { "CIM_IBQ_FULLB_THRSH", 0x2ac, 0 }, - { "Ibq2FullThrsh", 0, 9 }, - { "Ibq3FullThrsh", 16, 9 }, - { "CIM_HOST_ACC_CTRL", 0x2b0, 0 }, - { "HostBusy", 17, 1 }, - { "HostWrite", 16, 1 }, - { "HostAddr", 0, 16 }, - { "CIM_HOST_ACC_DATA", 0x2b4, 0 }, - { "CIM_IBQ_DBG_CFG", 0x2c0, 0 }, - { "IbqDbgAddr", 16, 9 }, - { "IbqDbgQID", 3, 2 }, - { "IbqDbgWr", 2, 1 }, - { "IbqDbgBusy", 1, 1 }, - { "IbqDbgEn", 0, 1 }, - { "CIM_OBQ_DBG_CFG", 0x2c4, 0 }, - { "ObqDbgAddr", 16, 9 }, - { "ObqDbgQID", 3, 2 }, - { "ObqDbgWr", 2, 1 }, - { "ObqDbgBusy", 1, 1 }, - { "ObqDbgEn", 0, 1 }, - { "CIM_IBQ_DBG_DATA", 0x2c8, 0 }, - { "CIM_OBQ_DBG_DATA", 0x2cc, 0 }, - { "CIM_CDEBUGDATA", 0x2d0, 0 }, - { "CDebugDataH", 16, 16 }, - { "CDebugDataL", 0, 16 }, - { "CIM_DEBUGCFG", 0x2e0, 0 }, - { "POLADbgRdPtr", 23, 9 }, - { "PILADbgRdPtr", 14, 9 }, - { "LADbgEn", 12, 1 }, - { "DebugSelH", 5, 5 }, - { "DebugSelL", 0, 5 }, - { "CIM_DEBUGSTS", 0x2e4, 0 }, - { "POLADbgWrPtr", 16, 9 }, - { "PILADbgWrPtr", 0, 9 }, - { "CIM_PO_LA_DEBUGDATA", 0x2e8, 0 }, - { "CIM_PI_LA_DEBUGDATA", 0x2ec, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_tp1_regs[] = { - { "TP_IN_CONFIG", 0x300, 0 }, - { "RXFbArbPrio", 25, 1 }, - { "TXFbArbPrio", 24, 1 }, - { "DBMaxOpCnt", 16, 8 }, - { "IPv6Enable", 15, 1 }, - { "NICMode", 14, 1 }, - { "EChecksumCheckTCP", 13, 1 }, - { "EChecksumCheckIP", 12, 1 }, - { "ECPL", 10, 1 }, - { "EEthernet", 8, 1 }, - { "ETunnel", 7, 1 }, - { "CChecksumCheckTCP", 6, 1 }, - { "CChecksumCheckIP", 5, 1 }, - { "CCPL", 3, 1 }, - { "CEthernet", 1, 1 }, - { "CTunnel", 0, 1 }, - { "TP_OUT_CONFIG", 0x304, 0 }, - { "IPIDSplitMode", 16, 1 }, - { "VLANExtractionEnable2ndPort", 13, 1 }, - { "VLANExtractionEnable", 12, 1 }, - { "EChecksumGenerateTCP", 11, 1 }, - { "EChecksumGenerateIP", 10, 1 }, - { "ECPL", 8, 1 }, - { "EEthernet", 6, 1 }, - { "CChecksumGenerateTCP", 5, 1 }, - { "CChecksumGenerateIP", 4, 1 }, - { "CCPL", 2, 1 }, - { "CEthernet", 0, 1 }, - { "TP_GLOBAL_CONFIG", 0x308, 0 }, - { "SYNCookieParams", 26, 6 }, - { "RXFlowControlDisable", 25, 1 }, - { "TXPacingEnable", 24, 1 }, - { "AttackFilterEnable", 23, 1 }, - { "SYNCookieNoOptions", 22, 1 }, - { "ProtectedMode", 21, 1 }, - { "PingDrop", 20, 1 }, - { "FragmentDrop", 19, 1 }, - { "FiveTupleLookup", 17, 2 }, - { "PathMTU", 15, 1 }, - { "IPIdentSplit", 14, 1 }, - { "IPChecksumOffload", 13, 1 }, - { "UDPChecksumOffload", 12, 1 }, - { "TCPChecksumOffload", 11, 1 }, - { "QOSMapping", 10, 1 }, - { "TCAMServerUse", 8, 2 }, - { "IPTTL", 0, 8 }, - { "TP_GLOBAL_RX_CREDIT", 0x30c, 0 }, - { "TP_CMM_SIZE", 0x310, 0 }, - { "CMMemMgrSize", 0, 28 }, - { "TP_CMM_MM_BASE", 0x314, 0 }, - { "CMMemMgrBase", 0, 28 }, - { "TP_CMM_TIMER_BASE", 0x318, 0 }, - { "CMTimerMaxNum", 28, 2 }, - { "CMTimerBase", 0, 28 }, - { "TP_PMM_SIZE", 0x31c, 0 }, - { "PMSize", 0, 28 }, - { "TP_PMM_TX_BASE", 0x320, 0 }, - { "TP_PMM_DEFRAG_BASE", 0x324, 0 }, - { "TP_PMM_RX_BASE", 0x328, 0 }, - { "TP_PMM_RX_PAGE_SIZE", 0x32c, 0 }, - { "TP_PMM_RX_MAX_PAGE", 0x330, 0 }, - { "PMRxMaxPage", 0, 21 }, - { "TP_PMM_TX_PAGE_SIZE", 0x334, 0 }, - { "TP_PMM_TX_MAX_PAGE", 0x338, 0 }, - { "PMTxMaxPage", 0, 21 }, - { "TP_TCP_OPTIONS", 0x340, 0 }, - { "MTUDefault", 16, 16 }, - { "MTUEnable", 10, 1 }, - { "SACKTx", 9, 1 }, - { "SACKRx", 8, 1 }, - { "SACKMode", 4, 2 }, - { "WindowScaleMode", 2, 2 }, - { "TimestampsMode", 0, 2 }, - { "TP_DACK_CONFIG", 0x344, 0 }, - { "AutoState3", 30, 2 }, - { "AutoState2", 28, 2 }, - { "AutoState1", 26, 2 }, - { "ByteThreshold", 5, 20 }, - { "MSSThreshold", 3, 2 }, - { "AutoCareful", 2, 1 }, - { "AutoEnable", 1, 1 }, - { "Mode", 0, 1 }, - { "TP_PC_CONFIG", 0x348, 0 }, - { "CMCacheDisable", 31, 1 }, - { "EnableOcspiFull", 30, 1 }, - { "EnableFLMErrorDDP", 29, 1 }, - { "LockTid", 28, 1 }, - { "FixRcvWnd", 27, 1 }, - { "TxTosQueueMapMode", 26, 1 }, - { "RddpCongEn", 25, 1 }, - { "EnableOnFlyPDU", 24, 1 }, - { "EnableEPCMDAFull", 23, 1 }, - { "ModulateUnionMode", 22, 1 }, - { "TxDataAckRateEnable", 21, 1 }, - { "TxDeferEnable", 20, 1 }, - { "RxCongestionMode", 19, 1 }, - { "HearbeatOnceDACK", 18, 1 }, - { "HearbeatOnceHeap", 17, 1 }, - { "HearbeatDACK", 16, 1 }, - { "TxCongestionMode", 15, 1 }, - { "AcceptLatestRcvAdv", 14, 1 }, - { "DisableSYNData", 13, 1 }, - { "DisableWindowPSH", 12, 1 }, - { "DisableFINOldData", 11, 1 }, - { "EnableFLMError", 10, 1 }, - { "DisableNextMtu", 9, 1 }, - { "FilterPeerFIN", 8, 1 }, - { "EnableFeedbackSend", 7, 1 }, - { "EnableRDMAError", 6, 1 }, - { "EnableDDPFlowControl", 5, 1 }, - { "DisableHeldFIN", 4, 1 }, - { "TableLatencyDelta", 0, 4 }, - { "TP_PC_CONFIG2", 0x34c, 0 }, - { "EnableDropRQEmptyPkt", 10, 1 }, - { "EnableTxPortfromDA2", 9, 1 }, - { "EnableRxPktTmstpRss", 8, 1 }, - { "EnableSndUnaInRxData", 7, 1 }, - { "EnableRxPortFromAddr", 6, 1 }, - { "EnableTxPortfromDA", 5, 1 }, - { "CHdrAFull", 4, 1 }, - { "EnableNonOfdScbBit", 3, 1 }, - { "EnableNonOfdTidRss", 2, 1 }, - { "EnableNonOfdTcbRss", 1, 1 }, - { "EnableOldRxForward", 0, 1 }, - { "TP_TCP_BACKOFF_REG0", 0x350, 0 }, - { "TimerBackoffIndex3", 24, 8 }, - { "TimerBackoffIndex2", 16, 8 }, - { "TimerBackoffIndex1", 8, 8 }, - { "TimerBackoffIndex0", 0, 8 }, - { "TP_TCP_BACKOFF_REG1", 0x354, 0 }, - { "TimerBackoffIndex7", 24, 8 }, - { "TimerBackoffIndex6", 16, 8 }, - { "TimerBackoffIndex5", 8, 8 }, - { "TimerBackoffIndex4", 0, 8 }, - { "TP_TCP_BACKOFF_REG2", 0x358, 0 }, - { "TimerBackoffIndex11", 24, 8 }, - { "TimerBackoffIndex10", 16, 8 }, - { "TimerBackoffIndex9", 8, 8 }, - { "TimerBackoffIndex8", 0, 8 }, - { "TP_TCP_BACKOFF_REG3", 0x35c, 0 }, - { "TimerBackoffIndex15", 24, 8 }, - { "TimerBackoffIndex14", 16, 8 }, - { "TimerBackoffIndex13", 8, 8 }, - { "TimerBackoffIndex12", 0, 8 }, - { "TP_PARA_REG0", 0x360, 0 }, - { "InitCwnd", 24, 3 }, - { "DupAckThresh", 20, 4 }, - { "TP_PARA_REG1", 0x364, 0 }, - { "InitRwnd", 16, 16 }, - { "InitialSSThresh", 0, 16 }, - { "TP_PARA_REG2", 0x368, 0 }, - { "MaxRxData", 16, 16 }, - { "RxCoalesceSize", 0, 16 }, - { "TP_PARA_REG3", 0x36c, 0 }, - { "TunnelCngDrop1", 21, 1 }, - { "TunnelCngDrop0", 20, 1 }, - { "TxDataAckIdx", 16, 4 }, - { "RxFragEnable", 12, 3 }, - { "TxPaceFixedStrict", 11, 1 }, - { "TxPaceAutoStrict", 10, 1 }, - { "TxPaceFixed", 9, 1 }, - { "TxPaceAuto", 8, 1 }, - { "RxUrgTunnel", 6, 1 }, - { "RxUrgMode", 5, 1 }, - { "TxUrgMode", 4, 1 }, - { "CngCtrlMode", 2, 2 }, - { "RxCoalesceEnable", 1, 1 }, - { "RxCoalescePshEn", 0, 1 }, - { "TP_PARA_REG4", 0x370, 0 }, - { "HighSpeedCfg", 24, 8 }, - { "NewRenoCfg", 16, 8 }, - { "TahoeCfg", 8, 8 }, - { "RenoCfg", 0, 8 }, - { "TP_PARA_REG5", 0x374, 0 }, - { "IndicateSize", 16, 16 }, - { "SchdEnable", 8, 1 }, - { "OnFlyDDPEnable", 2, 1 }, - { "DackTimerSpin", 1, 1 }, - { "PushTimerEnable", 0, 1 }, - { "TP_PARA_REG6", 0x378, 0 }, - { "TxPDUSizeAdj", 16, 8 }, - { "EnableDeferACK", 12, 1 }, - { "EnableESnd", 11, 1 }, - { "EnableCSnd", 10, 1 }, - { "EnablePDUE", 9, 1 }, - { "EnablePDUC", 8, 1 }, - { "EnableBUFI", 7, 1 }, - { "EnableBUFE", 6, 1 }, - { "EnableDefer", 5, 1 }, - { "EnableClearRxmtOos", 4, 1 }, - { "DisablePDUCng", 3, 1 }, - { "DisablePDUTimeout", 2, 1 }, - { "DisablePDURxmt", 1, 1 }, - { "DisablePDUxmt", 0, 1 }, - { "TP_PARA_REG7", 0x37c, 0 }, - { "PMMaxXferLen1", 16, 16 }, - { "PMMaxXferLen0", 0, 16 }, - { "TP_TIMER_RESOLUTION", 0x390, 0 }, - { "TimerResolution", 16, 8 }, - { "TimestampResolution", 8, 8 }, - { "DelayedACKResolution", 0, 8 }, - { "TP_MSL", 0x394, 0 }, - { "MSL", 0, 30 }, - { "TP_RXT_MIN", 0x398, 0 }, - { "RxtMin", 0, 30 }, - { "TP_RXT_MAX", 0x39c, 0 }, - { "RxtMax", 0, 30 }, - { "TP_PERS_MIN", 0x3a0, 0 }, - { "PersMin", 0, 30 }, - { "TP_PERS_MAX", 0x3a4, 0 }, - { "PersMax", 0, 30 }, - { "TP_KEEP_IDLE", 0x3a8, 0 }, - { "KeepaliveIdle", 0, 30 }, - { "TP_KEEP_INTVL", 0x3ac, 0 }, - { "KeepaliveIntvl", 0, 30 }, - { "TP_INIT_SRTT", 0x3b0, 0 }, - { "InitSrtt", 0, 16 }, - { "TP_DACK_TIMER", 0x3b4, 0 }, - { "DackTime", 0, 12 }, - { "TP_FINWAIT2_TIMER", 0x3b8, 0 }, - { "Finwait2Time", 0, 30 }, - { "TP_FAST_FINWAIT2_TIMER", 0x3bc, 0 }, - { "FastFinwait2Time", 0, 30 }, - { "TP_SHIFT_CNT", 0x3c0, 0 }, - { "SynShiftMax", 24, 8 }, - { "RxtShiftMaxR1", 20, 4 }, - { "RxtShiftMaxR2", 16, 4 }, - { "PerShiftBackoffMax", 12, 4 }, - { "PerShiftMax", 8, 4 }, - { "KeepaliveMax", 0, 8 }, - { "TP_TIME_HI", 0x3c8, 0 }, - { "TP_TIME_LO", 0x3cc, 0 }, - { "TP_MTU_PORT_TABLE", 0x3d0, 0 }, - { "Port1MTUValue", 16, 16 }, - { "Port0MTUValue", 0, 16 }, - { "TP_ULP_TABLE", 0x3d4, 0 }, - { "ULPType7Field", 28, 4 }, - { "ULPType6Field", 24, 4 }, - { "ULPType5Field", 20, 4 }, - { "ULPType4Field", 16, 4 }, - { "ULPType3Field", 12, 4 }, - { "ULPType2Field", 8, 4 }, - { "ULPType1Field", 4, 4 }, - { "ULPType0Field", 0, 4 }, - { "TP_PACE_TABLE", 0x3d8, 0 }, - { "TP_CCTRL_TABLE", 0x3dc, 0 }, - { "TP_TOS_TABLE", 0x3e0, 0 }, - { "TP_MTU_TABLE", 0x3e4, 0 }, - { "TP_RSS_MAP_TABLE", 0x3e8, 0 }, - { "TP_RSS_LKP_TABLE", 0x3ec, 0 }, - { "TP_RSS_CONFIG", 0x3f0, 0 }, - { "TNL4tupEn", 29, 1 }, - { "TNL2tupEn", 28, 1 }, - { "TNLprtEn", 26, 1 }, - { "TNLMapEn", 25, 1 }, - { "TNLLkpEn", 24, 1 }, - { "OFD4tupEn", 21, 1 }, - { "OFD2tupEn", 20, 1 }, - { "OFDMapEn", 17, 1 }, - { "OFDLkpEn", 16, 1 }, - { "SYN4tupEn", 13, 1 }, - { "SYN2tupEn", 12, 1 }, - { "SYNMapEn", 9, 1 }, - { "SYNLkpEn", 8, 1 }, - { "RRCPLMapEn", 7, 1 }, - { "RRCPLCPUSIZE", 4, 3 }, - { "RQFeedbackEnable", 3, 1 }, - { "HashToeplitz", 2, 1 }, - { "HashSave", 1, 1 }, - { "Disable", 0, 1 }, - { "TP_RSS_CONFIG_TNL", 0x3f4, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_CONFIG_OFD", 0x3f8, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_CONFIG_SYN", 0x3fc, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_SECRET_KEY0", 0x400, 0 }, - { "TP_RSS_SECRET_KEY1", 0x404, 0 }, - { "TP_RSS_SECRET_KEY2", 0x408, 0 }, - { "TP_RSS_SECRET_KEY3", 0x40c, 0 }, - { "TP_TM_PIO_ADDR", 0x418, 0 }, - { "TP_TM_PIO_DATA", 0x41c, 0 }, - { "TP_TX_MOD_QUE_TABLE", 0x420, 0 }, - { "TP_TX_RESOURCE_LIMIT", 0x424, 0 }, - { "TX_RESOURCE_LIMIT_CH1_PC", 24, 8 }, - { "TX_RESOURCE_LIMIT_CH1_NON_PC", 16, 8 }, - { "TX_RESOURCE_LIMIT_CH0_PC", 8, 8 }, - { "TX_RESOURCE_LIMIT_CH0_NON_PC", 0, 8 }, - { "TP_TX_MOD_QUEUE_REQ_MAP", 0x428, 0 }, - { "RX_MOD_WEIGHT", 24, 8 }, - { "TX_MOD_WEIGHT", 16, 8 }, - { "TX_MOD_TIMER_MODE", 8, 8 }, - { "TX_MOD_QUEUE_REQ_MAP", 0, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT1", 0x42c, 0 }, - { "TP_TX_MOD_QUEUE_WEIGHT7", 24, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT6", 16, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT5", 8, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT4", 0, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT0", 0x430, 0 }, - { "TP_TX_MOD_QUEUE_WEIGHT3", 24, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT2", 16, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT1", 8, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT0", 0, 8 }, - { "TP_MOD_CHANNEL_WEIGHT", 0x434, 0 }, - { "RX_MOD_CHANNEL_WEIGHT1", 24, 8 }, - { "RX_MOD_CHANNEL_WEIGHT0", 16, 8 }, - { "TX_MOD_CHANNEL_WEIGHT1", 8, 8 }, - { "TX_MOD_CHANNEL_WEIGHT0", 0, 8 }, - { "TP_MOD_RATE_LIMIT", 0x438, 0 }, - { "RX_MOD_RATE_LIMIT_INC", 24, 8 }, - { "RX_MOD_RATE_LIMIT_TICK", 16, 8 }, - { "TX_MOD_RATE_LIMIT_INC", 8, 8 }, - { "TX_MOD_RATE_LIMIT_TICK", 0, 8 }, - { "TP_PIO_ADDR", 0x440, 0 }, - { "TP_PIO_DATA", 0x444, 0 }, - { "TP_RESET", 0x44c, 0 }, - { "FlstInitEnable", 1, 1 }, - { "TPReset", 0, 1 }, - { "TP_MIB_INDEX", 0x450, 0 }, - { "TP_MIB_RDATA", 0x454, 0 }, - { "TP_SYNC_TIME_HI", 0x458, 0 }, - { "TP_SYNC_TIME_LO", 0x45c, 0 }, - { "TP_CMM_MM_RX_FLST_BASE", 0x460, 0 }, - { "CMRxFlstBase", 0, 28 }, - { "TP_CMM_MM_TX_FLST_BASE", 0x464, 0 }, - { "CMTxFlstBase", 0, 28 }, - { "TP_CMM_MM_PS_FLST_BASE", 0x468, 0 }, - { "CMPsFlstBase", 0, 28 }, - { "TP_CMM_MM_MAX_PSTRUCT", 0x46c, 0 }, - { "CMMaxPstruct", 0, 21 }, - { "TP_INT_ENABLE", 0x470, 0 }, - { "TP_INT_CAUSE", 0x474, 0 }, - { "TP_FLM_FREE_PS_CNT", 0x480, 0 }, - { "FreePstructCount", 0, 21 }, - { "TP_FLM_FREE_RX_CNT", 0x484, 0 }, - { "FreeRxPageCount", 0, 21 }, - { "TP_FLM_FREE_TX_CNT", 0x488, 0 }, - { "FreeTxPageCount", 0, 21 }, - { "TP_TM_HEAP_PUSH_CNT", 0x48c, 0 }, - { "TP_TM_HEAP_POP_CNT", 0x490, 0 }, - { "TP_TM_DACK_PUSH_CNT", 0x494, 0 }, - { "TP_TM_DACK_POP_CNT", 0x498, 0 }, - { "TP_TM_MOD_PUSH_CNT", 0x49c, 0 }, - { "TP_MOD_POP_CNT", 0x4a0, 0 }, - { "TP_TIMER_SEPARATOR", 0x4a4, 0 }, - { "TP_DEBUG_SEL", 0x4a8, 0 }, - { "TP_DEBUG_FLAGS", 0x4ac, 0 }, - { "RxTimerDackFirst", 26, 1 }, - { "RxTimerDack", 25, 1 }, - { "RxTimerHeartbeat", 24, 1 }, - { "RxPawsDrop", 23, 1 }, - { "RxUrgDataDrop", 22, 1 }, - { "RxFutureData", 21, 1 }, - { "RxRcvRxmData", 20, 1 }, - { "RxRcvOooDataFin", 19, 1 }, - { "RxRcvOooData", 18, 1 }, - { "RxRcvWndZero", 17, 1 }, - { "RxRcvWndLtMss", 16, 1 }, - { "TxDupAckInc", 11, 1 }, - { "TxRxmUrg", 10, 1 }, - { "TxRxmFin", 9, 1 }, - { "TxRxmSyn", 8, 1 }, - { "TxRxmNewReno", 7, 1 }, - { "TxRxmFast", 6, 1 }, - { "TxRxmTimer", 5, 1 }, - { "TxRxmTimerKeepalive", 4, 1 }, - { "TxRxmTimerPersist", 3, 1 }, - { "TxRcvAdvShrunk", 2, 1 }, - { "TxRcvAdvZero", 1, 1 }, - { "TxRcvAdvLtMss", 0, 1 }, - { "TP_PROXY_FLOW_CNTL", 0x4b0, 0 }, - { "TP_PC_CONGESTION_CNTL", 0x4b4, 0 }, - { "EDropTunnel", 19, 1 }, - { "CDropTunnel", 18, 1 }, - { "EThreshold", 12, 6 }, - { "CThreshold", 6, 6 }, - { "TxThreshold", 0, 6 }, - { "TP_TX_DROP_COUNT", 0x4bc, 0 }, - { "TP_CLEAR_DEBUG", 0x4c0, 0 }, - { "ClrDebug", 0, 1 }, - { "TP_DEBUG_VEC", 0x4c4, 0 }, - { "TP_DEBUG_VEC2", 0x4c8, 0 }, - { "TP_DEBUG_REG_SEL", 0x4cc, 0 }, - { "TP_DEBUG", 0x4d0, 0 }, - { "TP_DBG_LA_CONFIG", 0x4d4, 0 }, - { "TP_DBG_LA_DATAH", 0x4d8, 0 }, - { "TP_DBG_LA_DATAL", 0x4dc, 0 }, - { "TP_EMBED_OP_FIELD0", 0x4e8, 0 }, - { "TP_EMBED_OP_FIELD1", 0x4ec, 0 }, - { "TP_EMBED_OP_FIELD2", 0x4f0, 0 }, - { "TP_EMBED_OP_FIELD3", 0x4f4, 0 }, - { "TP_EMBED_OP_FIELD4", 0x4f8, 0 }, - { "TP_EMBED_OP_FIELD5", 0x4fc, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_ulp2_rx_regs[] = { - { "ULPRX_CTL", 0x500, 0 }, - { "PCMD1Threshold", 24, 8 }, - { "PCMD0Threshold", 16, 8 }, - { "round_robin", 4, 1 }, - { "RDMA_permissive_mode", 3, 1 }, - { "PagePodME", 2, 1 }, - { "IscsiTagTcb", 1, 1 }, - { "TddpTagTcb", 0, 1 }, - { "ULPRX_INT_ENABLE", 0x504, 0 }, - { "ParErr", 0, 1 }, - { "ULPRX_INT_CAUSE", 0x508, 0 }, - { "ParErr", 0, 1 }, - { "ULPRX_ISCSI_LLIMIT", 0x50c, 0 }, - { "IscsiLlimit", 6, 26 }, - { "ULPRX_ISCSI_ULIMIT", 0x510, 0 }, - { "IscsiUlimit", 6, 26 }, - { "ULPRX_ISCSI_TAGMASK", 0x514, 0 }, - { "IscsiTagMask", 6, 26 }, - { "ULPRX_ISCSI_PSZ", 0x518, 0 }, - { "Hpz3", 24, 4 }, - { "Hpz2", 16, 4 }, - { "Hpz1", 8, 4 }, - { "Hpz0", 0, 4 }, - { "ULPRX_TDDP_LLIMIT", 0x51c, 0 }, - { "TddpLlimit", 6, 26 }, - { "ULPRX_TDDP_ULIMIT", 0x520, 0 }, - { "TddpUlimit", 6, 26 }, - { "ULPRX_TDDP_TAGMASK", 0x524, 0 }, - { "TddpTagMask", 6, 26 }, - { "ULPRX_TDDP_PSZ", 0x528, 0 }, - { "Hpz3", 24, 4 }, - { "Hpz2", 16, 4 }, - { "Hpz1", 8, 4 }, - { "Hpz0", 0, 4 }, - { "ULPRX_STAG_LLIMIT", 0x52c, 0 }, - { "ULPRX_STAG_ULIMIT", 0x530, 0 }, - { "ULPRX_RQ_LLIMIT", 0x534, 0 }, - { "ULPRX_RQ_ULIMIT", 0x538, 0 }, - { "ULPRX_PBL_LLIMIT", 0x53c, 0 }, - { "ULPRX_PBL_ULIMIT", 0x540, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_ulp2_tx_regs[] = { - { "ULPTX_CONFIG", 0x580, 0 }, - { "CFG_RR_ARB", 0, 1 }, - { "ULPTX_INT_ENABLE", 0x584, 0 }, - { "Pbl_bound_err_ch1", 1, 1 }, - { "Pbl_bound_err_ch0", 0, 1 }, - { "ULPTX_INT_CAUSE", 0x588, 0 }, - { "Pbl_bound_err_ch1", 1, 1 }, - { "Pbl_bound_err_ch0", 0, 1 }, - { "ULPTX_TPT_LLIMIT", 0x58c, 0 }, - { "ULPTX_TPT_ULIMIT", 0x590, 0 }, - { "ULPTX_PBL_LLIMIT", 0x594, 0 }, - { "ULPTX_PBL_ULIMIT", 0x598, 0 }, - { "ULPTX_CPL_ERR_OFFSET", 0x59c, 0 }, - { "ULPTX_CPL_ERR_MASK", 0x5a0, 0 }, - { "ULPTX_CPL_ERR_VALUE", 0x5a4, 0 }, - { "ULPTX_CPL_PACK_SIZE", 0x5a8, 0 }, - { "value", 24, 8 }, - { "Ch1Size2", 24, 8 }, - { "Ch1Size1", 16, 8 }, - { "Ch0Size2", 8, 8 }, - { "Ch0Size1", 0, 8 }, - { "ULPTX_DMA_WEIGHT", 0x5ac, 0 }, - { "D1_WEIGHT", 16, 16 }, - { "D0_WEIGHT", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_pm1_rx_regs[] = { - { "PM1_RX_CFG", 0x5c0, 0 }, - { "PM1_RX_MODE", 0x5c4, 0 }, - { "stat_channel", 1, 1 }, - { "priority_ch", 0, 1 }, - { "PM1_RX_STAT_CONFIG", 0x5c8, 0 }, - { "PM1_RX_STAT_COUNT", 0x5cc, 0 }, - { "PM1_RX_STAT_MSB", 0x5d0, 0 }, - { "PM1_RX_STAT_LSB", 0x5d4, 0 }, - { "PM1_RX_INT_ENABLE", 0x5d8, 0 }, - { "zero_e_cmd_error", 18, 1 }, - { "iespi0_fifo2x_Rx_framing_error", 17, 1 }, - { "iespi1_fifo2x_Rx_framing_error", 16, 1 }, - { "iespi0_Rx_framing_error", 15, 1 }, - { "iespi1_Rx_framing_error", 14, 1 }, - { "iespi0_Tx_framing_error", 13, 1 }, - { "iespi1_Tx_framing_error", 12, 1 }, - { "ocspi0_Rx_framing_error", 11, 1 }, - { "ocspi1_Rx_framing_error", 10, 1 }, - { "ocspi0_Tx_framing_error", 9, 1 }, - { "ocspi1_Tx_framing_error", 8, 1 }, - { "ocspi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "ocspi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "iespi_par_error", 3, 3 }, - { "ocspi_par_error", 0, 3 }, - { "PM1_RX_INT_CAUSE", 0x5dc, 0 }, - { "zero_e_cmd_error", 18, 1 }, - { "iespi0_fifo2x_Rx_framing_error", 17, 1 }, - { "iespi1_fifo2x_Rx_framing_error", 16, 1 }, - { "iespi0_Rx_framing_error", 15, 1 }, - { "iespi1_Rx_framing_error", 14, 1 }, - { "iespi0_Tx_framing_error", 13, 1 }, - { "iespi1_Tx_framing_error", 12, 1 }, - { "ocspi0_Rx_framing_error", 11, 1 }, - { "ocspi1_Rx_framing_error", 10, 1 }, - { "ocspi0_Tx_framing_error", 9, 1 }, - { "ocspi1_Tx_framing_error", 8, 1 }, - { "ocspi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "ocspi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "iespi_par_error", 3, 3 }, - { "ocspi_par_error", 0, 3 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_pm1_tx_regs[] = { - { "PM1_TX_CFG", 0x5e0, 0 }, - { "PM1_TX_MODE", 0x5e4, 0 }, - { "stat_channel", 1, 1 }, - { "priority_ch", 0, 1 }, - { "PM1_TX_STAT_CONFIG", 0x5e8, 0 }, - { "PM1_TX_STAT_COUNT", 0x5ec, 0 }, - { "PM1_TX_STAT_MSB", 0x5f0, 0 }, - { "PM1_TX_STAT_LSB", 0x5f4, 0 }, - { "PM1_TX_INT_ENABLE", 0x5f8, 0 }, - { "zero_c_cmd_error", 18, 1 }, - { "icspi0_fifo2x_Rx_framing_error", 17, 1 }, - { "icspi1_fifo2x_Rx_framing_error", 16, 1 }, - { "icspi0_Rx_framing_error", 15, 1 }, - { "icspi1_Rx_framing_error", 14, 1 }, - { "icspi0_Tx_framing_error", 13, 1 }, - { "icspi1_Tx_framing_error", 12, 1 }, - { "oespi0_Rx_framing_error", 11, 1 }, - { "oespi1_Rx_framing_error", 10, 1 }, - { "oespi0_Tx_framing_error", 9, 1 }, - { "oespi1_Tx_framing_error", 8, 1 }, - { "oespi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "oespi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "icspi_par_error", 3, 3 }, - { "oespi_par_error", 0, 3 }, - { "PM1_TX_INT_CAUSE", 0x5fc, 0 }, - { "zero_c_cmd_error", 18, 1 }, - { "icspi0_fifo2x_Rx_framing_error", 17, 1 }, - { "icspi1_fifo2x_Rx_framing_error", 16, 1 }, - { "icspi0_Rx_framing_error", 15, 1 }, - { "icspi1_Rx_framing_error", 14, 1 }, - { "icspi0_Tx_framing_error", 13, 1 }, - { "icspi1_Tx_framing_error", 12, 1 }, - { "oespi0_Rx_framing_error", 11, 1 }, - { "oespi1_Rx_framing_error", 10, 1 }, - { "oespi0_Tx_framing_error", 9, 1 }, - { "oespi1_Tx_framing_error", 8, 1 }, - { "oespi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "oespi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "icspi_par_error", 3, 3 }, - { "oespi_par_error", 0, 3 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_mps0_regs[] = { - { "MPS_CFG", 0x600, 0 }, - { "EnForcePkt", 11, 1 }, - { "SGETPQid", 8, 3 }, - { "TPRxPortSize", 7, 1 }, - { "TPTxPort1Size", 6, 1 }, - { "TPTxPort0Size", 5, 1 }, - { "TPRxPortEn", 4, 1 }, - { "TPTxPort1En", 3, 1 }, - { "TPTxPort0En", 2, 1 }, - { "Port1Active", 1, 1 }, - { "Port0Active", 0, 1 }, - { "MPS_DRR_CFG1", 0x604, 0 }, - { "RldWtTPD1", 11, 11 }, - { "RldWtTPD0", 0, 11 }, - { "MPS_DRR_CFG2", 0x608, 0 }, - { "RldWtTotal", 0, 12 }, - { "MPS_MCA_STATUS", 0x60c, 0 }, - { "MCAPktCnt", 12, 20 }, - { "MCADepth", 0, 12 }, - { "MPS_TX0_TP_CNT", 0x610, 0 }, - { "TX0TPDisCnt", 24, 8 }, - { "TX0TPCnt", 0, 24 }, - { "MPS_TX1_TP_CNT", 0x614, 0 }, - { "TX1TPDisCnt", 24, 8 }, - { "TX1TPCnt", 0, 24 }, - { "MPS_RX_TP_CNT", 0x618, 0 }, - { "RXTPDisCnt", 24, 8 }, - { "RXTPCnt", 0, 24 }, - { "MPS_INT_ENABLE", 0x61c, 0 }, - { "MCAParErrEnb", 6, 3 }, - { "RXTpParErrEnb", 4, 2 }, - { "TX1TpParErrEnb", 2, 2 }, - { "TX0TpParErrEnb", 0, 2 }, - { "MPS_INT_CAUSE", 0x620, 0 }, - { "MCAParErr", 6, 3 }, - { "RXTpParErr", 4, 2 }, - { "TX1TpParErr", 2, 2 }, - { "TX0TpParErr", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_cpl_switch_regs[] = { - { "CPL_SWITCH_CNTRL", 0x640, 0 }, - { "cpl_pkt_tid", 8, 24 }, - { "cpu_no_3F_CIM_enable", 3, 1 }, - { "switch_table_enable", 2, 1 }, - { "sge_enable", 1, 1 }, - { "cim_enable", 0, 1 }, - { "CPL_SWITCH_TBL_IDX", 0x644, 0 }, - { "switch_tbl_idx", 0, 4 }, - { "CPL_SWITCH_TBL_DATA", 0x648, 0 }, - { "CPL_SWITCH_ZERO_ERROR", 0x64c, 0 }, - { "zero_cmd", 0, 8 }, - { "CPL_INTR_ENABLE", 0x650, 0 }, - { "cim_ovfl_error", 4, 1 }, - { "tp_framing_error", 3, 1 }, - { "sge_framing_error", 2, 1 }, - { "cim_framing_error", 1, 1 }, - { "zero_switch_error", 0, 1 }, - { "CPL_INTR_CAUSE", 0x654, 0 }, - { "cim_ovfl_error", 4, 1 }, - { "tp_framing_error", 3, 1 }, - { "sge_framing_error", 2, 1 }, - { "cim_framing_error", 1, 1 }, - { "zero_switch_error", 0, 1 }, - { "CPL_MAP_TBL_IDX", 0x658, 0 }, - { "cpl_map_tbl_idx", 0, 8 }, - { "CPL_MAP_TBL_DATA", 0x65c, 0 }, - { "cpl_map_tbl_data", 0, 8 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_smb0_regs[] = { - { "SMB_GLOBAL_TIME_CFG", 0x660, 0 }, - { "LADbgWrPtr", 24, 8 }, - { "LADbgRdPtr", 16, 8 }, - { "LADbgEn", 13, 1 }, - { "MacroCntCfg", 8, 5 }, - { "MicroCntCfg", 0, 8 }, - { "SMB_MST_TIMEOUT_CFG", 0x664, 0 }, - { "DebugSelH", 28, 4 }, - { "DebugSelL", 24, 4 }, - { "MstTimeOutCfg", 0, 24 }, - { "SMB_MST_CTL_CFG", 0x668, 0 }, - { "MstFifoDbg", 31, 1 }, - { "MstFifoDbgClr", 30, 1 }, - { "MstRxByteCfg", 12, 6 }, - { "MstTxByteCfg", 6, 6 }, - { "MstReset", 1, 1 }, - { "MstCtlEn", 0, 1 }, - { "SMB_MST_CTL_STS", 0x66c, 0 }, - { "MstRxByteCnt", 12, 6 }, - { "MstTxByteCnt", 6, 6 }, - { "MstBusySts", 0, 1 }, - { "SMB_MST_TX_FIFO_RDWR", 0x670, 0 }, - { "SMB_MST_RX_FIFO_RDWR", 0x674, 0 }, - { "SMB_SLV_TIMEOUT_CFG", 0x678, 0 }, - { "SlvTimeOutCfg", 0, 24 }, - { "SMB_SLV_CTL_CFG", 0x67c, 0 }, - { "SlvFifoDbg", 31, 1 }, - { "SlvFifoDbgClr", 30, 1 }, - { "SlvAddrCfg", 4, 7 }, - { "SlvAlrtSet", 2, 1 }, - { "SlvReset", 1, 1 }, - { "SlvCtlEn", 0, 1 }, - { "SMB_SLV_CTL_STS", 0x680, 0 }, - { "SlvFifoTxCnt", 12, 6 }, - { "SlvFifoCnt", 6, 6 }, - { "SlvAlrtSts", 2, 1 }, - { "SlvBusySts", 0, 1 }, - { "SMB_SLV_FIFO_RDWR", 0x684, 0 }, - { "SMB_SLV_CMD_FIFO_RDWR", 0x688, 0 }, - { "SMB_INT_ENABLE", 0x68c, 0 }, - { "SlvTimeOutIntEn", 7, 1 }, - { "SlvErrIntEn", 6, 1 }, - { "SlvDoneIntEn", 5, 1 }, - { "SlvRxRdyIntEn", 4, 1 }, - { "MstTimeOutIntEn", 3, 1 }, - { "MstNAckIntEn", 2, 1 }, - { "MstLostArbIntEn", 1, 1 }, - { "MstDoneIntEn", 0, 1 }, - { "SMB_INT_CAUSE", 0x690, 0 }, - { "SlvTimeOutInt", 7, 1 }, - { "SlvErrInt", 6, 1 }, - { "SlvDoneInt", 5, 1 }, - { "SlvRxRdyInt", 4, 1 }, - { "MstTimeOutInt", 3, 1 }, - { "MstNAckInt", 2, 1 }, - { "MstLostArbInt", 1, 1 }, - { "MstDoneInt", 0, 1 }, - { "SMB_DEBUG_DATA", 0x694, 0 }, - { "DebugDataH", 16, 16 }, - { "DebugDataL", 0, 16 }, - { "SMB_DEBUG_LA", 0x69c, 0 }, - { "DebugLAReqAddr", 0, 10 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_i2cm0_regs[] = { - { "I2C_CFG", 0x6a0, 0 }, - { "ClkDiv", 0, 12 }, - { "I2C_DATA", 0x6a4, 0 }, - { "Data", 0, 8 }, - { "I2C_OP", 0x6a8, 0 }, - { "Busy", 31, 1 }, - { "Ack", 30, 1 }, - { "Cont", 1, 1 }, - { "Op", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_mi1_regs[] = { - { "MI1_CFG", 0x6b0, 0 }, - { "ClkDiv", 5, 8 }, - { "St", 3, 2 }, - { "PreEn", 2, 1 }, - { "MDIInv", 1, 1 }, - { "MDIEn", 0, 1 }, - { "MI1_ADDR", 0x6b4, 0 }, - { "PhyAddr", 5, 5 }, - { "RegAddr", 0, 5 }, - { "MI1_DATA", 0x6b8, 0 }, - { "Data", 0, 16 }, - { "MI1_OP", 0x6bc, 0 }, - { "Busy", 31, 1 }, - { "Inc", 2, 1 }, - { "Op", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_jm1_regs[] = { - { "JM_CFG", 0x6c0, 0 }, - { "ClkDiv", 2, 8 }, - { "TRst", 1, 1 }, - { "En", 0, 1 }, - { "JM_MODE", 0x6c4, 0 }, - { "JM_DATA", 0x6c8, 0 }, - { "JM_OP", 0x6cc, 0 }, - { "Busy", 31, 1 }, - { "Cnt", 0, 5 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_sf1_regs[] = { - { "SF_DATA", 0x6d8, 0 }, - { "SF_OP", 0x6dc, 0 }, - { "Busy", 31, 1 }, - { "Cont", 3, 1 }, - { "ByteCnt", 1, 2 }, - { "Op", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_pl3_regs[] = { - { "PL_INT_ENABLE0", 0x6e0, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_CAUSE0", 0x6e4, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_ENABLE1", 0x6e8, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_CAUSE1", 0x6ec, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_RST", 0x6f0, 0 }, - { "SWInt1", 3, 1 }, - { "SWInt0", 2, 1 }, - { "CRstWrm", 1, 1 }, - { "CRstWrmMode", 0, 1 }, - { "PL_REV", 0x6f4, 0 }, - { "Rev", 0, 4 }, - { "PL_CLI", 0x6f8, 0 }, - { "PL_LCK", 0x6fc, 0 }, - { "Lck", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_mc5a_regs[] = { - { "MC5_BUF_CONFIG", 0x700, 0 }, - { "term300_240", 31, 1 }, - { "term150", 30, 1 }, - { "term60", 29, 1 }, - { "gddriii", 28, 1 }, - { "gddrii", 27, 1 }, - { "gddri", 26, 1 }, - { "read", 25, 1 }, - { "imp_set_update", 24, 1 }, - { "cal_update", 23, 1 }, - { "cal_busy", 22, 1 }, - { "cal_error", 21, 1 }, - { "sgl_cal_en", 20, 1 }, - { "imp_upd_mode", 19, 1 }, - { "imp_sel", 18, 1 }, - { "man_pu", 15, 3 }, - { "man_pd", 12, 3 }, - { "cal_pu", 9, 3 }, - { "cal_pd", 6, 3 }, - { "set_pu", 3, 3 }, - { "set_pd", 0, 3 }, - { "MC5_DB_CONFIG", 0x704, 0 }, - { "TMCfgWrLock", 31, 1 }, - { "TMTypeHi", 30, 1 }, - { "TMPartSize", 28, 2 }, - { "TMType", 26, 2 }, - { "TMPartCount", 24, 2 }, - { "nLIP", 18, 6 }, - { "COMPEN", 17, 1 }, - { "BUILD", 16, 1 }, - { "FilterEn", 11, 1 }, - { "CLIPUpdate", 10, 1 }, - { "TM_IO_PDOWN", 9, 1 }, - { "SYNMode", 7, 2 }, - { "PRTYEN", 6, 1 }, - { "MBUSEN", 5, 1 }, - { "DBGIEN", 4, 1 }, - { "TcmCfgOvr", 3, 1 }, - { "TMRDY", 2, 1 }, - { "TMRST", 1, 1 }, - { "TMMode", 0, 1 }, - { "MC5_MISC", 0x708, 0 }, - { "LIP_Cmp_Unavailable", 0, 4 }, - { "MC5_DB_ROUTING_TABLE_INDEX", 0x70c, 0 }, - { "RTINDX", 0, 22 }, - { "MC5_DB_FILTER_TABLE", 0x710, 0 }, - { "SRINDX", 0, 22 }, - { "MC5_DB_SERVER_INDEX", 0x714, 0 }, - { "SRINDX", 0, 22 }, - { "MC5_DB_LIP_RAM_ADDR", 0x718, 0 }, - { "RAMWR", 8, 1 }, - { "RAMADDR", 0, 6 }, - { "MC5_DB_LIP_RAM_DATA", 0x71c, 0 }, - { "MC5_DB_RSP_LATENCY", 0x720, 0 }, - { "RDLAT", 16, 5 }, - { "LRNLAT", 8, 5 }, - { "SRCHLAT", 0, 5 }, - { "MC5_DB_PARITY_LATENCY", 0x724, 0 }, - { "PARLAT", 0, 4 }, - { "MC5_DB_WR_LRN_VERIFY", 0x728, 0 }, - { "VWVEREN", 2, 1 }, - { "LRNVEREN", 1, 1 }, - { "POVEREN", 0, 1 }, - { "MC5_DB_PART_ID_INDEX", 0x72c, 0 }, - { "IDINDEX", 0, 4 }, - { "MC5_DB_RESET_MAX", 0x730, 0 }, - { "RSTMAX", 0, 4 }, - { "MC5_DB_ACT_CNT", 0x734, 0 }, - { "ACTCNT", 0, 20 }, - { "MC5_DB_CLIP_MAP", 0x738, 0 }, - { "CLIPMapOp", 31, 1 }, - { "CLIPMapVal", 16, 6 }, - { "CLIPMapAddr", 0, 6 }, - { "MC5_DB_INT_ENABLE", 0x740, 0 }, - { "MsgSel", 28, 4 }, - { "DelActEmpty", 18, 1 }, - { "DispQParErr", 17, 1 }, - { "ReqQParErr", 16, 1 }, - { "UnknownCmd", 15, 1 }, - { "SYNCookieOff", 11, 1 }, - { "SYNCookieBad", 10, 1 }, - { "SYNCookie", 9, 1 }, - { "NFASrchFail", 8, 1 }, - { "ActRgnFull", 7, 1 }, - { "ParityErr", 6, 1 }, - { "LIPMiss", 5, 1 }, - { "LIP0", 4, 1 }, - { "Miss", 3, 1 }, - { "RoutingHit", 2, 1 }, - { "ActiveHit", 1, 1 }, - { "ActiveOutHit", 0, 1 }, - { "MC5_DB_INT_CAUSE", 0x744, 0 }, - { "DelActEmpty", 18, 1 }, - { "DispQParErr", 17, 1 }, - { "ReqQParErr", 16, 1 }, - { "UnknownCmd", 15, 1 }, - { "SYNCookieOff", 11, 1 }, - { "SYNCookieBad", 10, 1 }, - { "SYNCookie", 9, 1 }, - { "NFASrchFail", 8, 1 }, - { "ActRgnFull", 7, 1 }, - { "ParityErr", 6, 1 }, - { "LIPMiss", 5, 1 }, - { "LIP0", 4, 1 }, - { "Miss", 3, 1 }, - { "RoutingHit", 2, 1 }, - { "ActiveHit", 1, 1 }, - { "ActiveOutHit", 0, 1 }, - { "MC5_DB_INT_TID", 0x748, 0 }, - { "INTTID", 0, 20 }, - { "MC5_DB_INT_PTID", 0x74c, 0 }, - { "INTPTID", 0, 20 }, - { "MC5_DB_DBGI_CONFIG", 0x774, 0 }, - { "WRReqSize", 22, 10 }, - { "SADRSel", 4, 1 }, - { "CMDMode", 0, 3 }, - { "MC5_DB_DBGI_REQ_CMD", 0x778, 0 }, - { "MBusCmd", 0, 4 }, - { "IDTCmdHi", 11, 3 }, - { "IDTCmdLo", 0, 4 }, - { "IDTCmd", 0, 20 }, - { "LCMDB", 16, 11 }, - { "LCMDA", 0, 11 }, - { "MC5_DB_DBGI_REQ_ADDR0", 0x77c, 0 }, - { "MC5_DB_DBGI_REQ_ADDR1", 0x780, 0 }, - { "MC5_DB_DBGI_REQ_ADDR2", 0x784, 0 }, - { "DBGIReqAdrHi", 0, 8 }, - { "MC5_DB_DBGI_REQ_DATA0", 0x788, 0 }, - { "MC5_DB_DBGI_REQ_DATA1", 0x78c, 0 }, - { "MC5_DB_DBGI_REQ_DATA2", 0x790, 0 }, - { "MC5_DB_DBGI_REQ_DATA3", 0x794, 0 }, - { "MC5_DB_DBGI_REQ_DATA4", 0x798, 0 }, - { "DBGIReqData4", 0, 16 }, - { "MC5_DB_DBGI_REQ_MASK0", 0x79c, 0 }, - { "MC5_DB_DBGI_REQ_MASK1", 0x7a0, 0 }, - { "MC5_DB_DBGI_REQ_MASK2", 0x7a4, 0 }, - { "MC5_DB_DBGI_REQ_MASK3", 0x7a8, 0 }, - { "MC5_DB_DBGI_REQ_MASK4", 0x7ac, 0 }, - { "DBGIReqMsk4", 0, 16 }, - { "MC5_DB_DBGI_RSP_STATUS", 0x7b0, 0 }, - { "DBGIRspMsg", 8, 4 }, - { "DBGIRspMsgVld", 2, 1 }, - { "DBGIRspHit", 1, 1 }, - { "DBGIRspValid", 0, 1 }, - { "MC5_DB_DBGI_RSP_DATA0", 0x7b4, 0 }, - { "MC5_DB_DBGI_RSP_DATA1", 0x7b8, 0 }, - { "MC5_DB_DBGI_RSP_DATA2", 0x7bc, 0 }, - { "MC5_DB_DBGI_RSP_DATA3", 0x7c0, 0 }, - { "MC5_DB_DBGI_RSP_DATA4", 0x7c4, 0 }, - { "DBGIRspData3", 0, 16 }, - { "MC5_DB_DBGI_RSP_LAST_CMD", 0x7c8, 0 }, - { "LastCmdB", 16, 11 }, - { "LastCmdA", 0, 11 }, - { "MC5_DB_POPEN_DATA_WR_CMD", 0x7cc, 0 }, - { "PO_DWR", 0, 20 }, - { "MC5_DB_POPEN_MASK_WR_CMD", 0x7d0, 0 }, - { "PO_MWR", 0, 20 }, - { "MC5_DB_AOPEN_SRCH_CMD", 0x7d4, 0 }, - { "AO_SRCH", 0, 20 }, - { "MC5_DB_AOPEN_LRN_CMD", 0x7d8, 0 }, - { "AO_LRN", 0, 20 }, - { "MC5_DB_SYN_SRCH_CMD", 0x7dc, 0 }, - { "SYN_SRCH", 0, 20 }, - { "MC5_DB_SYN_LRN_CMD", 0x7e0, 0 }, - { "SYN_LRN", 0, 20 }, - { "MC5_DB_ACK_SRCH_CMD", 0x7e4, 0 }, - { "ACK_SRCH", 0, 20 }, - { "MC5_DB_ACK_LRN_CMD", 0x7e8, 0 }, - { "ACK_LRN", 0, 20 }, - { "MC5_DB_ILOOKUP_CMD", 0x7ec, 0 }, - { "I_SRCH", 0, 20 }, - { "MC5_DB_ELOOKUP_CMD", 0x7f0, 0 }, - { "E_SRCH", 0, 20 }, - { "MC5_DB_DATA_WRITE_CMD", 0x7f4, 0 }, - { "Write", 0, 20 }, - { "MC5_DB_DATA_READ_CMD", 0x7f8, 0 }, - { "ReadCmd", 0, 20 }, - { "MC5_DB_MASK_WRITE_CMD", 0x7fc, 0 }, - { "MaskWr", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_xgmac0_0_regs[] = { - { "XGM_TX_CTRL", 0x800, 0 }, - { "SendPause", 2, 1 }, - { "SendZeroPause", 1, 1 }, - { "TxEn", 0, 1 }, - { "XGM_TX_CFG", 0x804, 0 }, - { "CfgClkSpeed", 2, 3 }, - { "StretchMode", 1, 1 }, - { "TxPauseEn", 0, 1 }, - { "XGM_TX_PAUSE_QUANTA", 0x808, 0 }, - { "TxPauseQuanta", 0, 16 }, - { "XGM_RX_CTRL", 0x80c, 0 }, - { "RxEn", 0, 1 }, - { "XGM_RX_CFG", 0x810, 0 }, - { "Con802_3Preamble", 12, 1 }, - { "EnNon802_3Preamble", 11, 1 }, - { "CopyPreamble", 10, 1 }, - { "DisPauseFrames", 9, 1 }, - { "En1536BFrames", 8, 1 }, - { "EnJumbo", 7, 1 }, - { "RmFCS", 6, 1 }, - { "DisNonVlan", 5, 1 }, - { "EnExtMatch", 4, 1 }, - { "EnHashUcast", 3, 1 }, - { "EnHashMcast", 2, 1 }, - { "DisBCast", 1, 1 }, - { "CopyAllFrames", 0, 1 }, - { "XGM_RX_HASH_LOW", 0x814, 0 }, - { "XGM_RX_HASH_HIGH", 0x818, 0 }, - { "XGM_RX_EXACT_MATCH_LOW_1", 0x81c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_1", 0x820, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_2", 0x824, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_2", 0x828, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_3", 0x82c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_3", 0x830, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_4", 0x834, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_4", 0x838, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_5", 0x83c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_5", 0x840, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_6", 0x844, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_6", 0x848, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_7", 0x84c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_7", 0x850, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_8", 0x854, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_8", 0x858, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_TYPE_MATCH_1", 0x85c, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_2", 0x860, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_3", 0x864, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_4", 0x868, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_INT_STATUS", 0x86c, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_MASK", 0x870, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_ENABLE", 0x874, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_DISABLE", 0x878, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_TX_PAUSE_TIMER", 0x87c, 0 }, - { "CurPauseTimer", 0, 16 }, - { "XGM_STAT_CTRL", 0x880, 0 }, - { "ReadSnpShot", 4, 1 }, - { "TakeSnpShot", 3, 1 }, - { "ClrStats", 2, 1 }, - { "IncrStats", 1, 1 }, - { "EnTestModeWr", 0, 1 }, - { "XGM_RXFIFO_CFG", 0x884, 0 }, - { "RxFIFOPauseHWM", 17, 12 }, - { "RxFIFOPauseLWM", 5, 12 }, - { "ForcedPause", 4, 1 }, - { "ExternLoopback", 3, 1 }, - { "RxByteSwap", 2, 1 }, - { "RxStrFrwrd", 1, 1 }, - { "DisErrFrames", 0, 1 }, - { "XGM_TXFIFO_CFG", 0x888, 0 }, - { "EnDropPkt", 21, 1 }, - { "TxIPG", 13, 8 }, - { "TxFIFOThresh", 4, 9 }, - { "InternLoopback", 3, 1 }, - { "TxByteSwap", 2, 1 }, - { "DisCRC", 1, 1 }, - { "DisPreAmble", 0, 1 }, - { "XGM_SLOW_TIMER", 0x88c, 0 }, - { "PauseSlowTimerEn", 31, 1 }, - { "PauseSlowTimer", 0, 20 }, - { "XGM_PAUSE_TIMER", 0x890, 0 }, - { "PauseTimer", 0, 20 }, - { "XGM_XAUI_PCS_TEST", 0x894, 0 }, - { "TestPattern", 1, 2 }, - { "EnTest", 0, 1 }, - { "XGM_RGMII_CTRL", 0x898, 0 }, - { "PhAlignFIFOThresh", 1, 2 }, - { "TxClk90Shift", 0, 1 }, - { "XGM_RGMII_IMP", 0x89c, 0 }, - { "CalReset", 8, 1 }, - { "CalUpdate", 7, 1 }, - { "ImpSetUpdate", 6, 1 }, - { "RGMIIImpPD", 3, 3 }, - { "RGMIIImpPU", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE", 0x8a8, 0 }, - { "RxMaxPktSize", 0, 14 }, - { "XGM_RESET_CTRL", 0x8ac, 0 }, - { "XG2G_Reset_", 3, 1 }, - { "RGMII_Reset_", 2, 1 }, - { "PCS_Reset_", 1, 1 }, - { "MAC_Reset_", 0, 1 }, - { "XGM_XAUI1G_CTRL", 0x8b0, 0 }, - { "XAUI1GLinkId", 0, 2 }, - { "XGM_SERDES_LANE_CTRL", 0x8b4, 0 }, - { "LaneReversal", 8, 1 }, - { "TxPolarity", 4, 4 }, - { "RxPolarity", 0, 4 }, - { "XGM_PORT_CFG", 0x8b8, 0 }, - { "SafeSpeedChange", 4, 1 }, - { "ClkDivReset_", 3, 1 }, - { "PortSpeed", 1, 2 }, - { "EnRGMII", 0, 1 }, - { "XGM_EPIO_DATA0", 0x8c0, 0 }, - { "XGM_EPIO_DATA1", 0x8c4, 0 }, - { "XGM_EPIO_DATA2", 0x8c8, 0 }, - { "XGM_EPIO_DATA3", 0x8cc, 0 }, - { "XGM_EPIO_OP", 0x8d0, 0 }, - { "PIO_Ready", 31, 1 }, - { "PIO_WrRd", 24, 1 }, - { "PIO_Address", 0, 8 }, - { "XGM_INT_ENABLE", 0x8d4, 0 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_INT_CAUSE", 0x8d8, 0 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_XAUI_ACT_CTRL", 0x8dc, 0 }, - { "TxEn", 1, 1 }, - { "RxEn", 0, 1 }, - { "XGM_SERDES_CTRL0", 0x8e0, 0 }, - { "IntSerLPBK3", 27, 1 }, - { "IntSerLPBK2", 26, 1 }, - { "IntSerLPBK1", 25, 1 }, - { "IntSerLPBK0", 24, 1 }, - { "Reset3", 23, 1 }, - { "Reset2", 22, 1 }, - { "Reset1", 21, 1 }, - { "Reset0", 20, 1 }, - { "Pwrdn3", 19, 1 }, - { "Pwrdn2", 18, 1 }, - { "Pwrdn1", 17, 1 }, - { "Pwrdn0", 16, 1 }, - { "ResetPLL23", 15, 1 }, - { "ResetPLL01", 14, 1 }, - { "PW23", 12, 2 }, - { "PW01", 10, 2 }, - { "Deq", 6, 4 }, - { "Dtx", 2, 4 }, - { "LoDrv", 1, 1 }, - { "HiDrv", 0, 1 }, - { "XGM_SERDES_CTRL1", 0x8e4, 0 }, - { "FmOffset3", 19, 5 }, - { "FmOffsetEn3", 18, 1 }, - { "FmOffset2", 13, 5 }, - { "FmOffsetEn2", 12, 1 }, - { "FmOffset1", 7, 5 }, - { "FmOffsetEn1", 6, 1 }, - { "FmOffset0", 1, 5 }, - { "FmOffsetEn0", 0, 1 }, - { "XGM_SERDES_CTRL2", 0x8e8, 0 }, - { "DnIn3", 11, 1 }, - { "UpIn3", 10, 1 }, - { "RxSlave3", 9, 1 }, - { "DnIn2", 8, 1 }, - { "UpIn2", 7, 1 }, - { "RxSlave2", 6, 1 }, - { "DnIn1", 5, 1 }, - { "UpIn1", 4, 1 }, - { "RxSlave1", 3, 1 }, - { "DnIn0", 2, 1 }, - { "UpIn0", 1, 1 }, - { "RxSlave0", 0, 1 }, - { "XGM_SERDES_CTRL3", 0x8ec, 0 }, - { "ExtBISTChkErrClr3", 31, 1 }, - { "ExtBISTChkEn3", 30, 1 }, - { "ExtBISTGenEn3", 29, 1 }, - { "ExtBISTPat3", 26, 3 }, - { "ExtParReset3", 25, 1 }, - { "ExtParLPBK3", 24, 1 }, - { "ExtBISTChkErrClr2", 23, 1 }, - { "ExtBISTChkEn2", 22, 1 }, - { "ExtBISTGenEn2", 21, 1 }, - { "ExtBISTPat2", 18, 3 }, - { "ExtParReset2", 17, 1 }, - { "ExtParLPBK2", 16, 1 }, - { "ExtBISTChkErrClr1", 15, 1 }, - { "ExtBISTChkEn1", 14, 1 }, - { "ExtBISTGenEn1", 13, 1 }, - { "ExtBISTPat1", 10, 3 }, - { "ExtParReset1", 9, 1 }, - { "ExtParLPBK1", 8, 1 }, - { "ExtBISTChkErrClr0", 7, 1 }, - { "ExtBISTChkEn0", 6, 1 }, - { "ExtBISTGenEn0", 5, 1 }, - { "ExtBISTPat0", 2, 3 }, - { "ExtParReset0", 1, 1 }, - { "ExtParLPBK0", 0, 1 }, - { "XGM_SERDES_STAT0", 0x8f0, 0 }, - { "ExtBISTChkErrCnt0", 4, 24 }, - { "ExtBISTChkFmd0", 3, 1 }, - { "LowSig0", 0, 1 }, - { "XGM_SERDES_STAT1", 0x8f4, 0 }, - { "ExtBISTChkErrCnt1", 4, 24 }, - { "ExtBISTChkFmd1", 3, 1 }, - { "LowSig1", 0, 1 }, - { "XGM_SERDES_STAT2", 0x8f8, 0 }, - { "ExtBISTChkErrCnt2", 4, 24 }, - { "ExtBISTChkFmd2", 3, 1 }, - { "LowSig2", 0, 1 }, - { "XGM_SERDES_STAT3", 0x8fc, 0 }, - { "ExtBISTChkErrCnt3", 4, 24 }, - { "ExtBISTChkFmd3", 3, 1 }, - { "LowSig3", 0, 1 }, - { "XGM_STAT_TX_BYTE_LOW", 0x900, 0 }, - { "XGM_STAT_TX_BYTE_HIGH", 0x904, 0 }, - { "TxBytes_high", 0, 13 }, - { "XGM_STAT_TX_FRAME_LOW", 0x908, 0 }, - { "XGM_STAT_TX_FRAME_HIGH", 0x90c, 0 }, - { "TxFrames_high", 0, 4 }, - { "XGM_STAT_TX_BCAST", 0x910, 0 }, - { "XGM_STAT_TX_MCAST", 0x914, 0 }, - { "XGM_STAT_TX_PAUSE", 0x918, 0 }, - { "XGM_STAT_TX_64B_FRAMES", 0x91c, 0 }, - { "XGM_STAT_TX_65_127B_FRAMES", 0x920, 0 }, - { "XGM_STAT_TX_128_255B_FRAMES", 0x924, 0 }, - { "XGM_STAT_TX_256_511B_FRAMES", 0x928, 0 }, - { "XGM_STAT_TX_512_1023B_FRAMES", 0x92c, 0 }, - { "XGM_STAT_TX_1024_1518B_FRAMES", 0x930, 0 }, - { "XGM_STAT_TX_1519_MAXB_FRAMES", 0x934, 0 }, - { "XGM_STAT_TX_ERR_FRAMES", 0x938, 0 }, - { "XGM_STAT_RX_BYTES_LOW", 0x93c, 0 }, - { "XGM_STAT_RX_BYTES_HIGH", 0x940, 0 }, - { "RxBytes_high", 0, 13 }, - { "XGM_STAT_RX_FRAMES_LOW", 0x944, 0 }, - { "XGM_STAT_RX_FRAMES_HIGH", 0x948, 0 }, - { "RxFrames_high", 0, 4 }, - { "XGM_STAT_RX_BCAST_FRAMES", 0x94c, 0 }, - { "XGM_STAT_RX_MCAST_FRAMES", 0x950, 0 }, - { "XGM_STAT_RX_PAUSE_FRAMES", 0x954, 0 }, - { "RxPauseFrames", 0, 16 }, - { "XGM_STAT_RX_64B_FRAMES", 0x958, 0 }, - { "XGM_STAT_RX_65_127B_FRAMES", 0x95c, 0 }, - { "XGM_STAT_RX_128_255B_FRAMES", 0x960, 0 }, - { "XGM_STAT_RX_256_511B_FRAMES", 0x964, 0 }, - { "XGM_STAT_RX_512_1023B_FRAMES", 0x968, 0 }, - { "XGM_STAT_RX_1024_1518B_FRAMES", 0x96c, 0 }, - { "XGM_STAT_RX_1519_MAXB_FRAMES", 0x970, 0 }, - { "XGM_STAT_RX_SHORT_FRAMES", 0x974, 0 }, - { "RxShortFrames", 0, 16 }, - { "XGM_STAT_RX_OVERSIZE_FRAMES", 0x978, 0 }, - { "RxOversizeFrames", 0, 16 }, - { "XGM_STAT_RX_JABBER_FRAMES", 0x97c, 0 }, - { "RxJabberFrames", 0, 16 }, - { "XGM_STAT_RX_CRC_ERR_FRAMES", 0x980, 0 }, - { "RxCRCErrFrames", 0, 16 }, - { "XGM_STAT_RX_LENGTH_ERR_FRAMES", 0x984, 0 }, - { "RxLengthErrFrames", 0, 16 }, - { "XGM_STAT_RX_SYM_CODE_ERR_FRAMES", 0x988, 0 }, - { "RxSymCodeErrFrames", 0, 16 }, - { "XGM_XAUI_PCS_ERR", 0x998, 0 }, - { "PCS_SyncStatus", 5, 4 }, - { "PCS_CTCFIFOErr", 1, 4 }, - { "PCS_NotAligned", 0, 1 }, - { "XGM_RGMII_STATUS", 0x99c, 0 }, - { "GMIIDuplex", 3, 1 }, - { "GMIISpeed", 1, 2 }, - { "GMIILinkStatus", 0, 1 }, - { "XGM_WOL_STATUS", 0x9a0, 0 }, - { "PatDetected", 31, 1 }, - { "MatchedFilter", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE_ERR_CNT", 0x9a4, 0 }, - { "XGM_TX_SPI4_SOP_EOP_CNT", 0x9a8, 0 }, - { "TxSPI4SopCnt", 16, 16 }, - { "TxSPI4EopCnt", 0, 16 }, - { "XGM_RX_SPI4_SOP_EOP_CNT", 0x9ac, 0 }, - { "RxSPI4SopCnt", 16, 16 }, - { "RxSPI4EopCnt", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info t3b_xgmac0_1_regs[] = { - { "XGM_TX_CTRL", 0xa00, 0 }, - { "SendPause", 2, 1 }, - { "SendZeroPause", 1, 1 }, - { "TxEn", 0, 1 }, - { "XGM_TX_CFG", 0xa04, 0 }, - { "CfgClkSpeed", 2, 3 }, - { "StretchMode", 1, 1 }, - { "TxPauseEn", 0, 1 }, - { "XGM_TX_PAUSE_QUANTA", 0xa08, 0 }, - { "TxPauseQuanta", 0, 16 }, - { "XGM_RX_CTRL", 0xa0c, 0 }, - { "RxEn", 0, 1 }, - { "XGM_RX_CFG", 0xa10, 0 }, - { "Con802_3Preamble", 12, 1 }, - { "EnNon802_3Preamble", 11, 1 }, - { "CopyPreamble", 10, 1 }, - { "DisPauseFrames", 9, 1 }, - { "En1536BFrames", 8, 1 }, - { "EnJumbo", 7, 1 }, - { "RmFCS", 6, 1 }, - { "DisNonVlan", 5, 1 }, - { "EnExtMatch", 4, 1 }, - { "EnHashUcast", 3, 1 }, - { "EnHashMcast", 2, 1 }, - { "DisBCast", 1, 1 }, - { "CopyAllFrames", 0, 1 }, - { "XGM_RX_HASH_LOW", 0xa14, 0 }, - { "XGM_RX_HASH_HIGH", 0xa18, 0 }, - { "XGM_RX_EXACT_MATCH_LOW_1", 0xa1c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_1", 0xa20, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_2", 0xa24, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_2", 0xa28, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_3", 0xa2c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_3", 0xa30, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_4", 0xa34, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_4", 0xa38, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_5", 0xa3c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_5", 0xa40, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_6", 0xa44, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_6", 0xa48, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_7", 0xa4c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_7", 0xa50, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_8", 0xa54, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_8", 0xa58, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_TYPE_MATCH_1", 0xa5c, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_2", 0xa60, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_3", 0xa64, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_4", 0xa68, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_INT_STATUS", 0xa6c, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_MASK", 0xa70, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_ENABLE", 0xa74, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_DISABLE", 0xa78, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_TX_PAUSE_TIMER", 0xa7c, 0 }, - { "CurPauseTimer", 0, 16 }, - { "XGM_STAT_CTRL", 0xa80, 0 }, - { "ReadSnpShot", 4, 1 }, - { "TakeSnpShot", 3, 1 }, - { "ClrStats", 2, 1 }, - { "IncrStats", 1, 1 }, - { "EnTestModeWr", 0, 1 }, - { "XGM_RXFIFO_CFG", 0xa84, 0 }, - { "RxFIFOPauseHWM", 17, 12 }, - { "RxFIFOPauseLWM", 5, 12 }, - { "ForcedPause", 4, 1 }, - { "ExternLoopback", 3, 1 }, - { "RxByteSwap", 2, 1 }, - { "RxStrFrwrd", 1, 1 }, - { "DisErrFrames", 0, 1 }, - { "XGM_TXFIFO_CFG", 0xa88, 0 }, - { "EnDropPkt", 21, 1 }, - { "TxIPG", 13, 8 }, - { "TxFIFOThresh", 4, 9 }, - { "InternLoopback", 3, 1 }, - { "TxByteSwap", 2, 1 }, - { "DisCRC", 1, 1 }, - { "DisPreAmble", 0, 1 }, - { "XGM_SLOW_TIMER", 0xa8c, 0 }, - { "PauseSlowTimerEn", 31, 1 }, - { "PauseSlowTimer", 0, 20 }, - { "XGM_PAUSE_TIMER", 0xa90, 0 }, - { "PauseTimer", 0, 20 }, - { "XGM_XAUI_PCS_TEST", 0xa94, 0 }, - { "TestPattern", 1, 2 }, - { "EnTest", 0, 1 }, - { "XGM_RGMII_CTRL", 0xa98, 0 }, - { "PhAlignFIFOThresh", 1, 2 }, - { "TxClk90Shift", 0, 1 }, - { "XGM_RGMII_IMP", 0xa9c, 0 }, - { "CalReset", 8, 1 }, - { "CalUpdate", 7, 1 }, - { "ImpSetUpdate", 6, 1 }, - { "RGMIIImpPD", 3, 3 }, - { "RGMIIImpPU", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE", 0xaa8, 0 }, - { "RxMaxPktSize", 0, 14 }, - { "XGM_RESET_CTRL", 0xaac, 0 }, - { "XG2G_Reset_", 3, 1 }, - { "RGMII_Reset_", 2, 1 }, - { "PCS_Reset_", 1, 1 }, - { "MAC_Reset_", 0, 1 }, - { "XGM_XAUI1G_CTRL", 0xab0, 0 }, - { "XAUI1GLinkId", 0, 2 }, - { "XGM_SERDES_LANE_CTRL", 0xab4, 0 }, - { "LaneReversal", 8, 1 }, - { "TxPolarity", 4, 4 }, - { "RxPolarity", 0, 4 }, - { "XGM_PORT_CFG", 0xab8, 0 }, - { "SafeSpeedChange", 4, 1 }, - { "ClkDivReset_", 3, 1 }, - { "PortSpeed", 1, 2 }, - { "EnRGMII", 0, 1 }, - { "XGM_EPIO_DATA0", 0xac0, 0 }, - { "XGM_EPIO_DATA1", 0xac4, 0 }, - { "XGM_EPIO_DATA2", 0xac8, 0 }, - { "XGM_EPIO_DATA3", 0xacc, 0 }, - { "XGM_EPIO_OP", 0xad0, 0 }, - { "PIO_Ready", 31, 1 }, - { "PIO_WrRd", 24, 1 }, - { "PIO_Address", 0, 8 }, - { "XGM_INT_ENABLE", 0xad4, 0 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_INT_CAUSE", 0xad8, 0 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_XAUI_ACT_CTRL", 0xadc, 0 }, - { "TxEn", 1, 1 }, - { "RxEn", 0, 1 }, - { "XGM_SERDES_CTRL0", 0xae0, 0 }, - { "IntSerLPBK3", 27, 1 }, - { "IntSerLPBK2", 26, 1 }, - { "IntSerLPBK1", 25, 1 }, - { "IntSerLPBK0", 24, 1 }, - { "Reset3", 23, 1 }, - { "Reset2", 22, 1 }, - { "Reset1", 21, 1 }, - { "Reset0", 20, 1 }, - { "Pwrdn3", 19, 1 }, - { "Pwrdn2", 18, 1 }, - { "Pwrdn1", 17, 1 }, - { "Pwrdn0", 16, 1 }, - { "ResetPLL23", 15, 1 }, - { "ResetPLL01", 14, 1 }, - { "PW23", 12, 2 }, - { "PW01", 10, 2 }, - { "Deq", 6, 4 }, - { "Dtx", 2, 4 }, - { "LoDrv", 1, 1 }, - { "HiDrv", 0, 1 }, - { "XGM_SERDES_CTRL1", 0xae4, 0 }, - { "FmOffset3", 19, 5 }, - { "FmOffsetEn3", 18, 1 }, - { "FmOffset2", 13, 5 }, - { "FmOffsetEn2", 12, 1 }, - { "FmOffset1", 7, 5 }, - { "FmOffsetEn1", 6, 1 }, - { "FmOffset0", 1, 5 }, - { "FmOffsetEn0", 0, 1 }, - { "XGM_SERDES_CTRL2", 0xae8, 0 }, - { "DnIn3", 11, 1 }, - { "UpIn3", 10, 1 }, - { "RxSlave3", 9, 1 }, - { "DnIn2", 8, 1 }, - { "UpIn2", 7, 1 }, - { "RxSlave2", 6, 1 }, - { "DnIn1", 5, 1 }, - { "UpIn1", 4, 1 }, - { "RxSlave1", 3, 1 }, - { "DnIn0", 2, 1 }, - { "UpIn0", 1, 1 }, - { "RxSlave0", 0, 1 }, - { "XGM_SERDES_CTRL3", 0xaec, 0 }, - { "ExtBISTChkErrClr3", 31, 1 }, - { "ExtBISTChkEn3", 30, 1 }, - { "ExtBISTGenEn3", 29, 1 }, - { "ExtBISTPat3", 26, 3 }, - { "ExtParReset3", 25, 1 }, - { "ExtParLPBK3", 24, 1 }, - { "ExtBISTChkErrClr2", 23, 1 }, - { "ExtBISTChkEn2", 22, 1 }, - { "ExtBISTGenEn2", 21, 1 }, - { "ExtBISTPat2", 18, 3 }, - { "ExtParReset2", 17, 1 }, - { "ExtParLPBK2", 16, 1 }, - { "ExtBISTChkErrClr1", 15, 1 }, - { "ExtBISTChkEn1", 14, 1 }, - { "ExtBISTGenEn1", 13, 1 }, - { "ExtBISTPat1", 10, 3 }, - { "ExtParReset1", 9, 1 }, - { "ExtParLPBK1", 8, 1 }, - { "ExtBISTChkErrClr0", 7, 1 }, - { "ExtBISTChkEn0", 6, 1 }, - { "ExtBISTGenEn0", 5, 1 }, - { "ExtBISTPat0", 2, 3 }, - { "ExtParReset0", 1, 1 }, - { "ExtParLPBK0", 0, 1 }, - { "XGM_SERDES_STAT0", 0xaf0, 0 }, - { "ExtBISTChkErrCnt0", 4, 24 }, - { "ExtBISTChkFmd0", 3, 1 }, - { "LowSig0", 0, 1 }, - { "XGM_SERDES_STAT1", 0xaf4, 0 }, - { "ExtBISTChkErrCnt1", 4, 24 }, - { "ExtBISTChkFmd1", 3, 1 }, - { "LowSig1", 0, 1 }, - { "XGM_SERDES_STAT2", 0xaf8, 0 }, - { "ExtBISTChkErrCnt2", 4, 24 }, - { "ExtBISTChkFmd2", 3, 1 }, - { "LowSig2", 0, 1 }, - { "XGM_SERDES_STAT3", 0xafc, 0 }, - { "ExtBISTChkErrCnt3", 4, 24 }, - { "ExtBISTChkFmd3", 3, 1 }, - { "LowSig3", 0, 1 }, - { "XGM_STAT_TX_BYTE_LOW", 0xb00, 0 }, - { "XGM_STAT_TX_BYTE_HIGH", 0xb04, 0 }, - { "TxBytes_high", 0, 13 }, - { "XGM_STAT_TX_FRAME_LOW", 0xb08, 0 }, - { "XGM_STAT_TX_FRAME_HIGH", 0xb0c, 0 }, - { "TxFrames_high", 0, 4 }, - { "XGM_STAT_TX_BCAST", 0xb10, 0 }, - { "XGM_STAT_TX_MCAST", 0xb14, 0 }, - { "XGM_STAT_TX_PAUSE", 0xb18, 0 }, - { "XGM_STAT_TX_64B_FRAMES", 0xb1c, 0 }, - { "XGM_STAT_TX_65_127B_FRAMES", 0xb20, 0 }, - { "XGM_STAT_TX_128_255B_FRAMES", 0xb24, 0 }, - { "XGM_STAT_TX_256_511B_FRAMES", 0xb28, 0 }, - { "XGM_STAT_TX_512_1023B_FRAMES", 0xb2c, 0 }, - { "XGM_STAT_TX_1024_1518B_FRAMES", 0xb30, 0 }, - { "XGM_STAT_TX_1519_MAXB_FRAMES", 0xb34, 0 }, - { "XGM_STAT_TX_ERR_FRAMES", 0xb38, 0 }, - { "XGM_STAT_RX_BYTES_LOW", 0xb3c, 0 }, - { "XGM_STAT_RX_BYTES_HIGH", 0xb40, 0 }, - { "RxBytes_high", 0, 13 }, - { "XGM_STAT_RX_FRAMES_LOW", 0xb44, 0 }, - { "XGM_STAT_RX_FRAMES_HIGH", 0xb48, 0 }, - { "RxFrames_high", 0, 4 }, - { "XGM_STAT_RX_BCAST_FRAMES", 0xb4c, 0 }, - { "XGM_STAT_RX_MCAST_FRAMES", 0xb50, 0 }, - { "XGM_STAT_RX_PAUSE_FRAMES", 0xb54, 0 }, - { "RxPauseFrames", 0, 16 }, - { "XGM_STAT_RX_64B_FRAMES", 0xb58, 0 }, - { "XGM_STAT_RX_65_127B_FRAMES", 0xb5c, 0 }, - { "XGM_STAT_RX_128_255B_FRAMES", 0xb60, 0 }, - { "XGM_STAT_RX_256_511B_FRAMES", 0xb64, 0 }, - { "XGM_STAT_RX_512_1023B_FRAMES", 0xb68, 0 }, - { "XGM_STAT_RX_1024_1518B_FRAMES", 0xb6c, 0 }, - { "XGM_STAT_RX_1519_MAXB_FRAMES", 0xb70, 0 }, - { "XGM_STAT_RX_SHORT_FRAMES", 0xb74, 0 }, - { "RxShortFrames", 0, 16 }, - { "XGM_STAT_RX_OVERSIZE_FRAMES", 0xb78, 0 }, - { "RxOversizeFrames", 0, 16 }, - { "XGM_STAT_RX_JABBER_FRAMES", 0xb7c, 0 }, - { "RxJabberFrames", 0, 16 }, - { "XGM_STAT_RX_CRC_ERR_FRAMES", 0xb80, 0 }, - { "RxCRCErrFrames", 0, 16 }, - { "XGM_STAT_RX_LENGTH_ERR_FRAMES", 0xb84, 0 }, - { "RxLengthErrFrames", 0, 16 }, - { "XGM_STAT_RX_SYM_CODE_ERR_FRAMES", 0xb88, 0 }, - { "RxSymCodeErrFrames", 0, 16 }, - { "XGM_XAUI_PCS_ERR", 0xb98, 0 }, - { "PCS_SyncStatus", 5, 4 }, - { "PCS_CTCFIFOErr", 1, 4 }, - { "PCS_NotAligned", 0, 1 }, - { "XGM_RGMII_STATUS", 0xb9c, 0 }, - { "GMIIDuplex", 3, 1 }, - { "GMIISpeed", 1, 2 }, - { "GMIILinkStatus", 0, 1 }, - { "XGM_WOL_STATUS", 0xba0, 0 }, - { "PatDetected", 31, 1 }, - { "MatchedFilter", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE_ERR_CNT", 0xba4, 0 }, - { "XGM_TX_SPI4_SOP_EOP_CNT", 0xba8, 0 }, - { "TxSPI4SopCnt", 16, 16 }, - { "TxSPI4EopCnt", 0, 16 }, - { "XGM_RX_SPI4_SOP_EOP_CNT", 0xbac, 0 }, - { "RxSPI4SopCnt", 16, 16 }, - { "RxSPI4EopCnt", 0, 16 }, - { NULL, 0, 0 } -}; diff --git a/usr.sbin/cxgbtool/reg_defs_t3c.c b/usr.sbin/cxgbtool/reg_defs_t3c.c deleted file mode 100644 index b9181b6..0000000 --- a/usr.sbin/cxgbtool/reg_defs_t3c.c +++ /dev/null @@ -1,3119 +0,0 @@ -/* - * $FreeBSD$ - */ - -/* This file is automatically generated --- do not edit */ - -struct reg_info t3c_sge3_regs[] = { - { "SG_CONTROL", 0x0, 0 }, - { "CongMode", 29, 1 }, - { "TnlFLMode", 28, 1 }, - { "FatlPerrEn", 27, 1 }, - { "UrgTnl", 26, 1 }, - { "NewNotify", 25, 1 }, - { "AvoidCqOvfl", 24, 1 }, - { "OptOneIntMultQ", 23, 1 }, - { "CQCrdtCtrl", 22, 1 }, - { "EgrEnUpBp", 21, 1 }, - { "DropPkt", 20, 1 }, - { "EgrGenCtrl", 19, 1 }, - { "UserSpaceSize", 14, 5 }, - { "HostPageSize", 11, 3 }, - { "PCIRelax", 10, 1 }, - { "FLMode", 9, 1 }, - { "PktShift", 6, 3 }, - { "OneIntMultQ", 5, 1 }, - { "FLPickAvail", 4, 1 }, - { "BigEndianEgress", 3, 1 }, - { "BigEndianIngress", 2, 1 }, - { "IscsiCoalescing", 1, 1 }, - { "GlobalEnable", 0, 1 }, - { "SG_KDOORBELL", 0x4, 0 }, - { "SelEgrCntx", 31, 1 }, - { "EgrCntx", 0, 16 }, - { "SG_GTS", 0x8, 0 }, - { "RspQ", 29, 3 }, - { "NewTimer", 16, 13 }, - { "NewIndex", 0, 16 }, - { "SG_CONTEXT_CMD", 0xc, 0 }, - { "Opcode", 28, 4 }, - { "Busy", 27, 1 }, - { "CQ_credit", 20, 7 }, - { "CQ", 19, 1 }, - { "RspQ", 18, 1 }, - { "Egress", 17, 1 }, - { "FreeList", 16, 1 }, - { "Context", 0, 16 }, - { "SG_CONTEXT_DATA0", 0x10, 0 }, - { "SG_CONTEXT_DATA1", 0x14, 0 }, - { "SG_CONTEXT_DATA2", 0x18, 0 }, - { "SG_CONTEXT_DATA3", 0x1c, 0 }, - { "SG_CONTEXT_MASK0", 0x20, 0 }, - { "SG_CONTEXT_MASK1", 0x24, 0 }, - { "SG_CONTEXT_MASK2", 0x28, 0 }, - { "SG_CONTEXT_MASK3", 0x2c, 0 }, - { "SG_RSPQ_CREDIT_RETURN", 0x30, 0 }, - { "RspQ", 29, 3 }, - { "Data", 0, 16 }, - { "SG_DATA_INTR", 0x34, 0 }, - { "ErrIntr", 31, 1 }, - { "DataIntr", 0, 8 }, - { "SG_HI_DRB_HI_THRSH", 0x38, 0 }, - { "HiDrbHiThrsh", 0, 10 }, - { "SG_HI_DRB_LO_THRSH", 0x3c, 0 }, - { "HiDrbLoThrsh", 0, 10 }, - { "SG_LO_DRB_HI_THRSH", 0x40, 0 }, - { "LoDrbHiThrsh", 0, 10 }, - { "SG_LO_DRB_LO_THRSH", 0x44, 0 }, - { "LoDrbLoThrsh", 0, 10 }, - { "SG_ONE_INT_MULT_Q_COALESCING_TIMER", 0x48, 0 }, - { "SG_RSPQ_FL_STATUS", 0x4c, 0 }, - { "RspQ0Starved", 0, 1 }, - { "RspQ1Starved", 1, 1 }, - { "RspQ2Starved", 2, 1 }, - { "RspQ3Starved", 3, 1 }, - { "RspQ4Starved", 4, 1 }, - { "RspQ5Starved", 5, 1 }, - { "RspQ6Starved", 6, 1 }, - { "RspQ7Starved", 7, 1 }, - { "RspQ0Disabled", 8, 1 }, - { "RspQ1Disabled", 9, 1 }, - { "RspQ2Disabled", 10, 1 }, - { "RspQ3Disabled", 11, 1 }, - { "RspQ4Disabled", 12, 1 }, - { "RspQ5Disabled", 13, 1 }, - { "RspQ6Disabled", 14, 1 }, - { "RspQ7Disabled", 15, 1 }, - { "FL0Empty", 16, 1 }, - { "FL1Empty", 17, 1 }, - { "FL2Empty", 18, 1 }, - { "FL3Empty", 19, 1 }, - { "FL4Empty", 20, 1 }, - { "FL5Empty", 21, 1 }, - { "FL6Empty", 22, 1 }, - { "FL7Empty", 23, 1 }, - { "FL8Empty", 24, 1 }, - { "FL9Empty", 25, 1 }, - { "FL10Empty", 26, 1 }, - { "FL11Empty", 27, 1 }, - { "FL12Empty", 28, 1 }, - { "FL13Empty", 29, 1 }, - { "FL14Empty", 30, 1 }, - { "FL15Empty", 31, 1 }, - { "SG_EGR_PRI_CNT", 0x50, 0 }, - { "EgrErrOpCode", 24, 8 }, - { "EgrHiOpCode", 16, 8 }, - { "EgrLoOpCode", 8, 8 }, - { "EgrPriCnt", 0, 5 }, - { "SG_EGR_RCQ_DRB_THRSH", 0x54, 0 }, - { "HiRcqDrbThrsh", 16, 11 }, - { "LoRcqDrbThrsh", 0, 11 }, - { "SG_EGR_CNTX_BADDR", 0x58, 0 }, - { "EgrCntxBAddr", 5, 27 }, - { "SG_INT_CAUSE", 0x5c, 0 }, - { "HiRcqParityError", 31, 1 }, - { "LoRcqParityError", 30, 1 }, - { "HiDrbParityError", 29, 1 }, - { "LoDrbParityError", 28, 1 }, - { "FlParityError", 22, 6 }, - { "ItParityError", 20, 2 }, - { "IrParityError", 19, 1 }, - { "RcParityError", 18, 1 }, - { "OcParityError", 17, 1 }, - { "CpParityError", 16, 1 }, - { "R_Req_FramingError", 15, 1 }, - { "UC_Req_FramingError", 14, 1 }, - { "HiCtlDrbDropErr", 13, 1 }, - { "LoCtlDrbDropErr", 12, 1 }, - { "HiPioDrbDropErr", 11, 1 }, - { "LoPioDrbDropErr", 10, 1 }, - { "HiCrdtUndFlowErr", 9, 1 }, - { "LoCrdtUndFlowErr", 8, 1 }, - { "HiPriorityDBFull", 7, 1 }, - { "HiPriorityDBEmpty", 6, 1 }, - { "LoPriorityDBFull", 5, 1 }, - { "LoPriorityDBEmpty", 4, 1 }, - { "RspQDisabled", 3, 1 }, - { "RspQCreditOverfow", 2, 1 }, - { "FlEmpty", 1, 1 }, - { "RspQStarve", 0, 1 }, - { "SG_INT_ENABLE", 0x60, 0 }, - { "HiRcqParityError", 31, 1 }, - { "LoRcqParityError", 30, 1 }, - { "HiDrbParityError", 29, 1 }, - { "LoDrbParityError", 28, 1 }, - { "FlParityError", 22, 6 }, - { "ItParityError", 20, 2 }, - { "IrParityError", 19, 1 }, - { "RcParityError", 18, 1 }, - { "OcParityError", 17, 1 }, - { "CpParityError", 16, 1 }, - { "R_Req_FramingError", 15, 1 }, - { "UC_Req_FramingError", 14, 1 }, - { "HiCtlDrbDropErr", 13, 1 }, - { "LoCtlDrbDropErr", 12, 1 }, - { "HiPioDrbDropErr", 11, 1 }, - { "LoPioDrbDropErr", 10, 1 }, - { "HiCrdtUndFlowErr", 9, 1 }, - { "LoCrdtUndFlowErr", 8, 1 }, - { "HiPriorityDBFull", 7, 1 }, - { "HiPriorityDBEmpty", 6, 1 }, - { "LoPriorityDBFull", 5, 1 }, - { "LoPriorityDBEmpty", 4, 1 }, - { "RspQDisabled", 3, 1 }, - { "RspQCreditOverfow", 2, 1 }, - { "FlEmpty", 1, 1 }, - { "RspQStarve", 0, 1 }, - { "SG_CMDQ_CREDIT_TH", 0x64, 0 }, - { "Timeout", 8, 24 }, - { "Threshold", 0, 8 }, - { "SG_TIMER_TICK", 0x68, 0 }, - { "SG_CQ_CONTEXT_BADDR", 0x6c, 0 }, - { "baseAddr", 5, 27 }, - { "SG_OCO_BASE", 0x70, 0 }, - { "Base1", 16, 16 }, - { "Base0", 0, 16 }, - { "SG_DRB_PRI_THRESH", 0x74, 0 }, - { "DrbPriThrsh", 0, 16 }, - { "SG_DEBUG_INDEX", 0x78, 0 }, - { "SG_DEBUG_DATA", 0x7c, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_pcix1_regs[] = { - { "PCIX_INT_ENABLE", 0x80, 0 }, - { "MSIXParErr", 22, 3 }, - { "CFParErr", 18, 4 }, - { "RFParErr", 14, 4 }, - { "WFParErr", 12, 2 }, - { "PIOParErr", 11, 1 }, - { "DetUncECCErr", 10, 1 }, - { "DetCorECCErr", 9, 1 }, - { "RcvSplCmpErr", 8, 1 }, - { "UnxSplCmp", 7, 1 }, - { "SplCmpDis", 6, 1 }, - { "DetParErr", 5, 1 }, - { "SigSysErr", 4, 1 }, - { "RcvMstAbt", 3, 1 }, - { "RcvTarAbt", 2, 1 }, - { "SigTarAbt", 1, 1 }, - { "MstDetParErr", 0, 1 }, - { "PCIX_INT_CAUSE", 0x84, 0 }, - { "MSIXParErr", 22, 3 }, - { "CFParErr", 18, 4 }, - { "RFParErr", 14, 4 }, - { "WFParErr", 12, 2 }, - { "PIOParErr", 11, 1 }, - { "DetUncECCErr", 10, 1 }, - { "DetCorECCErr", 9, 1 }, - { "RcvSplCmpErr", 8, 1 }, - { "UnxSplCmp", 7, 1 }, - { "SplCmpDis", 6, 1 }, - { "DetParErr", 5, 1 }, - { "SigSysErr", 4, 1 }, - { "RcvMstAbt", 3, 1 }, - { "RcvTarAbt", 2, 1 }, - { "SigTarAbt", 1, 1 }, - { "MstDetParErr", 0, 1 }, - { "PCIX_CFG", 0x88, 0 }, - { "DMAStopEn", 19, 1 }, - { "CLIDecEn", 18, 1 }, - { "LatTmrDis", 17, 1 }, - { "LowPwrEn", 16, 1 }, - { "AsyncIntVec", 11, 5 }, - { "MaxSplTrnC", 8, 3 }, - { "MaxSplTrnR", 5, 3 }, - { "MaxWrByteCnt", 3, 2 }, - { "WrReqAtomicEn", 2, 1 }, - { "CRstWrmMode", 1, 1 }, - { "PIOAck64En", 0, 1 }, - { "PCIX_MODE", 0x8c, 0 }, - { "PClkRange", 6, 2 }, - { "PCIXInitPat", 2, 4 }, - { "66MHz", 1, 1 }, - { "64Bit", 0, 1 }, - { "PCIX_CAL", 0x90, 0 }, - { "Busy", 31, 1 }, - { "PerCalDiv", 22, 8 }, - { "PerCalEn", 21, 1 }, - { "SglCalEn", 20, 1 }, - { "ZInUpdMode", 19, 1 }, - { "ZInSel", 18, 1 }, - { "ZPDMan", 15, 3 }, - { "ZPUMan", 12, 3 }, - { "ZPDOut", 9, 3 }, - { "ZPUOut", 6, 3 }, - { "ZPDIn", 3, 3 }, - { "ZPUIn", 0, 3 }, - { "PCIX_WOL", 0x94, 0 }, - { "WakeUp1", 3, 1 }, - { "WakeUp0", 2, 1 }, - { "SleepMode1", 1, 1 }, - { "SleepMode0", 0, 1 }, - { "PCIX_STAT0", 0x98, 0 }, - { "PIOReqFifoLevel", 26, 6 }, - { "RFIniSt", 24, 2 }, - { "RFRespRdSt", 22, 2 }, - { "TarCSt", 19, 3 }, - { "TarXSt", 16, 3 }, - { "WFReqWrSt", 13, 3 }, - { "WFRespFifoEmpty", 12, 1 }, - { "WFReqFifoEmpty", 11, 1 }, - { "RFRespFifoEmpty", 10, 1 }, - { "RFReqFifoEmpty", 9, 1 }, - { "PIORespFifoLevel", 7, 2 }, - { "CFRespFifoEmpty", 6, 1 }, - { "CFReqFifoEmpty", 5, 1 }, - { "VPDRespFifoEmpty", 4, 1 }, - { "VPDReqFifoEmpty", 3, 1 }, - { "PIO_RspPnd", 2, 1 }, - { "DlyTrnPnd", 1, 1 }, - { "SplTrnPnd", 0, 1 }, - { "PCIX_STAT1", 0x9c, 0 }, - { "WFIniSt", 26, 4 }, - { "ArbSt", 23, 3 }, - { "PMISt", 21, 2 }, - { "CalSt", 19, 2 }, - { "CFReqRdSt", 17, 2 }, - { "CFIniSt", 15, 2 }, - { "CFRespRdSt", 13, 2 }, - { "IniCSt", 10, 3 }, - { "IniXSt", 7, 3 }, - { "IntSt", 4, 3 }, - { "PIOSt", 2, 2 }, - { "RFReqRdSt", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_pcie0_regs[] = { - { "PCIE_INT_ENABLE", 0x80, 0 }, - { "BISTErr", 19, 8 }, - { "TxParErr", 18, 1 }, - { "RxParErr", 17, 1 }, - { "RetryLUTParErr", 16, 1 }, - { "RetryBUFParErr", 15, 1 }, - { "MSIXParErr", 12, 3 }, - { "CFParErr", 11, 1 }, - { "RFParErr", 10, 1 }, - { "WFParErr", 9, 1 }, - { "PIOParErr", 8, 1 }, - { "UnxSplCplErrC", 7, 1 }, - { "UnxSplCplErrR", 6, 1 }, - { "VPDAddrChng", 5, 1 }, - { "BusMstrEn", 4, 1 }, - { "PMStChng", 3, 1 }, - { "PEXMsg", 2, 1 }, - { "ZeroLenRd", 1, 1 }, - { "PEXErr", 0, 1 }, - { "PCIE_INT_CAUSE", 0x84, 0 }, - { "BISTErr", 19, 8 }, - { "TxParErr", 18, 1 }, - { "RxParErr", 17, 1 }, - { "RetryLUTParErr", 16, 1 }, - { "RetryBUFParErr", 15, 1 }, - { "MSIXParErr", 12, 3 }, - { "CFParErr", 11, 1 }, - { "RFParErr", 10, 1 }, - { "WFParErr", 9, 1 }, - { "PIOParErr", 8, 1 }, - { "UnxSplCplErrC", 7, 1 }, - { "UnxSplCplErrR", 6, 1 }, - { "VPDAddrChng", 5, 1 }, - { "BusMstrEn", 4, 1 }, - { "PMStChng", 3, 1 }, - { "PEXMsg", 2, 1 }, - { "ZeroLenRd", 1, 1 }, - { "PEXErr", 0, 1 }, - { "PCIE_CFG", 0x88, 0 }, - { "DMAStopEn", 24, 1 }, - { "PriorityINTA", 23, 1 }, - { "IniFullPkt", 22, 1 }, - { "EnableLinkDwnDRst", 21, 1 }, - { "EnableLinkDownRst", 20, 1 }, - { "EnableHotRst", 19, 1 }, - { "IniWaitForGnt", 18, 1 }, - { "IniBEDis", 17, 1 }, - { "CLIDecEn", 16, 1 }, - { "AsyncIntVec", 11, 5 }, - { "MaxSplTrnC", 7, 4 }, - { "MaxSplTrnR", 1, 6 }, - { "CRstWrmMode", 0, 1 }, - { "PCIE_MODE", 0x8c, 0 }, - { "TAR_State", 29, 3 }, - { "RF_StateIni", 26, 3 }, - { "CF_StateIni", 23, 3 }, - { "PIO_StatePL", 20, 3 }, - { "PIO_StateISC", 18, 2 }, - { "NumFstTrnSeqRx", 10, 8 }, - { "LnkCntlState", 2, 8 }, - { "VC0Up", 1, 1 }, - { "LnkInitial", 0, 1 }, - { "PCIE_STAT", 0x90, 0 }, - { "INI_State", 28, 4 }, - { "WF_StateIni", 24, 4 }, - { "PLM_ReqFIFOCnt", 22, 2 }, - { "ER_ReqFIFOEmpty", 21, 1 }, - { "WF_RspFIFOEmpty", 20, 1 }, - { "WF_ReqFIFOEmpty", 19, 1 }, - { "RF_RspFIFOEmpty", 18, 1 }, - { "RF_ReqFIFOEmpty", 17, 1 }, - { "RF_ActEmpty", 16, 1 }, - { "PIO_RspFIFOCnt", 11, 5 }, - { "PIO_ReqFIFOCnt", 5, 6 }, - { "CF_RspFIFOEmpty", 4, 1 }, - { "CF_ReqFIFOEmpty", 3, 1 }, - { "CF_ActEmpty", 2, 1 }, - { "VPD_RspFIFOEmpty", 1, 1 }, - { "VPD_ReqFIFOEmpty", 0, 1 }, - { "PCIE_WOL", 0x94, 0 }, - { "CF_RspState", 12, 2 }, - { "RF_RspState", 10, 2 }, - { "PME_State", 7, 3 }, - { "INT_State", 4, 3 }, - { "WakeUp1", 3, 1 }, - { "WakeUp0", 2, 1 }, - { "SleepMode1", 1, 1 }, - { "SleepMode0", 0, 1 }, - { "PCIE_PEX_CTRL0", 0x98, 0 }, - { "CplTimeoutRetry", 31, 1 }, - { "StrictTSMN", 30, 1 }, - { "NumFstTrnSeq", 22, 8 }, - { "ReplayLmt", 2, 20 }, - { "TxPndChkEn", 1, 1 }, - { "CplPndChkEn", 0, 1 }, - { "PCIE_PEX_CTRL1", 0x9c, 0 }, - { "RxPhyErrEn", 31, 1 }, - { "DLLPTimeoutLmt", 13, 18 }, - { "AckLat", 0, 13 }, - { "PCIE_PEX_CTRL2", 0xa0, 0 }, - { "LnkCntlDetDir", 30, 1 }, - { "EnterL1rEn", 29, 1 }, - { "PMExitL1Req", 28, 1 }, - { "PMTxIdle", 27, 1 }, - { "PCIModeLoop", 26, 1 }, - { "L1ASPMTxRxL0sTime", 14, 12 }, - { "L0sIdleTime", 3, 11 }, - { "EnterL1ASPMEn", 2, 1 }, - { "EnterL1En", 1, 1 }, - { "EnterL0sEn", 0, 1 }, - { "PCIE_PEX_ERR", 0xa4, 0 }, - { "CplTimeoutID", 18, 7 }, - { "FlowCtlOFlowErr", 17, 1 }, - { "ReplayTimeout", 16, 1 }, - { "ReplayRollover", 15, 1 }, - { "BadDLLP", 14, 1 }, - { "DLLPErr", 13, 1 }, - { "FlowCtlProtErr", 12, 1 }, - { "CplTimeout", 11, 1 }, - { "PHYRcvErr", 10, 1 }, - { "DisTLP", 9, 1 }, - { "BadECRC", 8, 1 }, - { "BadTLP", 7, 1 }, - { "MalTLP", 6, 1 }, - { "UnxCpl", 5, 1 }, - { "UnsReq", 4, 1 }, - { "PsnReq", 3, 1 }, - { "UnsCpl", 2, 1 }, - { "CplAbt", 1, 1 }, - { "PsnCpl", 0, 1 }, - { "PCIE_SERDES_CTRL", 0xa8, 0 }, - { "PMASel", 3, 1 }, - { "Lane", 0, 3 }, - { "PCIE_SERDES_QUAD_CTRL0", 0xac, 0 }, - { "TestSig", 10, 19 }, - { "Offset", 2, 8 }, - { "OffsetEn", 1, 1 }, - { "IDDQb", 0, 1 }, - { "PCIE_SERDES_QUAD_CTRL1", 0xb0, 0 }, - { "FastInit", 28, 1 }, - { "CTCDisable", 27, 1 }, - { "ManResetPLL", 26, 1 }, - { "ManL2Pwrdn", 25, 1 }, - { "ManQuadEn", 24, 1 }, - { "RxEqCtl", 22, 2 }, - { "HiVMode", 21, 1 }, - { "RefSel", 19, 2 }, - { "RxTermAdj", 17, 2 }, - { "TxTermAdj", 15, 2 }, - { "Deq", 11, 4 }, - { "Dtx", 7, 4 }, - { "LoDrv", 6, 1 }, - { "HiDrv", 5, 1 }, - { "IntParReset", 4, 1 }, - { "IntParLPBK", 3, 1 }, - { "IntSerLPBKwDrv", 2, 1 }, - { "PW", 1, 1 }, - { "PClkDetect", 0, 1 }, - { "PCIE_SERDES_LANE_CTRL", 0xb4, 0 }, - { "ExtBISTChkErrClr", 22, 1 }, - { "ExtBISTChkEn", 21, 1 }, - { "ExtBISTGenEn", 20, 1 }, - { "ExtBISTPat", 17, 3 }, - { "ExtParReset", 16, 1 }, - { "ExtParLPBK", 15, 1 }, - { "ManRxTermEn", 14, 1 }, - { "ManBeaconTxEn", 13, 1 }, - { "ManRxDetectEn", 12, 1 }, - { "ManTxIdleEn", 11, 1 }, - { "ManRxIdleEn", 10, 1 }, - { "ManL1Pwrdn", 9, 1 }, - { "ManReset", 8, 1 }, - { "ManFmOffset", 3, 5 }, - { "ManFmOffsetEn", 2, 1 }, - { "ManLaneEn", 1, 1 }, - { "IntSerLPBK", 0, 1 }, - { "PCIE_SERDES_LANE_STAT", 0xb8, 0 }, - { "ExtBISTChkErrCnt", 8, 24 }, - { "ExtBISTChkFmd", 7, 1 }, - { "BeaconDetectChg", 6, 1 }, - { "RxDetectChg", 5, 1 }, - { "TxIdleDetectChg", 4, 1 }, - { "BeaconDetect", 2, 1 }, - { "RxDetect", 1, 1 }, - { "TxIdleDetect", 0, 1 }, - { "PCIE_PEX_WMARK", 0xbc, 0 }, - { "P_WMark", 18, 11 }, - { "NP_WMark", 11, 7 }, - { "CPL_WMark", 0, 11 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_t3dbg_regs[] = { - { "T3DBG_DBG0_CFG", 0xc0, 0 }, - { "RegSelect", 9, 8 }, - { "ModuleSelect", 4, 5 }, - { "ClkSelect", 0, 4 }, - { "T3DBG_DBG0_EN", 0xc4, 0 }, - { "SDRByte0", 8, 1 }, - { "DDREn", 4, 1 }, - { "PortEn", 0, 1 }, - { "T3DBG_DBG1_CFG", 0xc8, 0 }, - { "RegSelect", 9, 8 }, - { "ModuleSelect", 4, 5 }, - { "ClkSelect", 0, 4 }, - { "T3DBG_DBG1_EN", 0xcc, 0 }, - { "SDRByte0", 8, 1 }, - { "DDREn", 4, 1 }, - { "PortEn", 0, 1 }, - { "T3DBG_GPIO_EN", 0xd0, 0 }, - { "GPIO11_OEn", 27, 1 }, - { "GPIO10_OEn", 26, 1 }, - { "GPIO9_OEn", 25, 1 }, - { "GPIO8_OEn", 24, 1 }, - { "GPIO7_OEn", 23, 1 }, - { "GPIO6_OEn", 22, 1 }, - { "GPIO5_OEn", 21, 1 }, - { "GPIO4_OEn", 20, 1 }, - { "GPIO3_OEn", 19, 1 }, - { "GPIO2_OEn", 18, 1 }, - { "GPIO1_OEn", 17, 1 }, - { "GPIO0_OEn", 16, 1 }, - { "GPIO11_Out_Val", 11, 1 }, - { "GPIO10_Out_Val", 10, 1 }, - { "GPIO9_Out_Val", 9, 1 }, - { "GPIO8_Out_Val", 8, 1 }, - { "GPIO7_Out_Val", 7, 1 }, - { "GPIO6_Out_Val", 6, 1 }, - { "GPIO5_Out_Val", 5, 1 }, - { "GPIO4_Out_Val", 4, 1 }, - { "GPIO3_Out_Val", 3, 1 }, - { "GPIO2_Out_Val", 2, 1 }, - { "GPIO1_Out_Val", 1, 1 }, - { "GPIO0_Out_Val", 0, 1 }, - { "T3DBG_GPIO_IN", 0xd4, 0 }, - { "GPIO11_CHG_DET", 27, 1 }, - { "GPIO10_CHG_DET", 26, 1 }, - { "GPIO9_CHG_DET", 25, 1 }, - { "GPIO8_CHG_DET", 24, 1 }, - { "GPIO7_CHG_DET", 23, 1 }, - { "GPIO6_CHG_DET", 22, 1 }, - { "GPIO5_CHG_DET", 21, 1 }, - { "GPIO4_CHG_DET", 20, 1 }, - { "GPIO3_CHG_DET", 19, 1 }, - { "GPIO2_CHG_DET", 18, 1 }, - { "GPIO1_CHG_DET", 17, 1 }, - { "GPIO0_CHG_DET", 16, 1 }, - { "GPIO11_IN", 11, 1 }, - { "GPIO10_IN", 10, 1 }, - { "GPIO9_IN", 9, 1 }, - { "GPIO8_IN", 8, 1 }, - { "GPIO7_IN", 7, 1 }, - { "GPIO6_IN", 6, 1 }, - { "GPIO5_IN", 5, 1 }, - { "GPIO4_IN", 4, 1 }, - { "GPIO3_IN", 3, 1 }, - { "GPIO2_IN", 2, 1 }, - { "GPIO1_IN", 1, 1 }, - { "GPIO0_IN", 0, 1 }, - { "T3DBG_INT_ENABLE", 0xd8, 0 }, - { "C_LOCK", 21, 1 }, - { "M_LOCK", 20, 1 }, - { "U_LOCK", 19, 1 }, - { "R_LOCK", 18, 1 }, - { "PX_LOCK", 17, 1 }, - { "GPIO11", 11, 1 }, - { "GPIO10", 10, 1 }, - { "GPIO9", 9, 1 }, - { "GPIO8", 8, 1 }, - { "GPIO7", 7, 1 }, - { "GPIO6", 6, 1 }, - { "GPIO5", 5, 1 }, - { "GPIO4", 4, 1 }, - { "GPIO3", 3, 1 }, - { "GPIO2", 2, 1 }, - { "GPIO1", 1, 1 }, - { "GPIO0", 0, 1 }, - { "T3DBG_INT_CAUSE", 0xdc, 0 }, - { "C_LOCK", 21, 1 }, - { "M_LOCK", 20, 1 }, - { "U_LOCK", 19, 1 }, - { "R_LOCK", 18, 1 }, - { "PX_LOCK", 17, 1 }, - { "GPIO11", 11, 1 }, - { "GPIO10", 10, 1 }, - { "GPIO9", 9, 1 }, - { "GPIO8", 8, 1 }, - { "GPIO7", 7, 1 }, - { "GPIO6", 6, 1 }, - { "GPIO5", 5, 1 }, - { "GPIO4", 4, 1 }, - { "GPIO3", 3, 1 }, - { "GPIO2", 2, 1 }, - { "GPIO1", 1, 1 }, - { "GPIO0", 0, 1 }, - { "T3DBG_DBG0_RST_VALUE", 0xe0, 0 }, - { "DebugData", 0, 8 }, - { "T3DBG_PLL_OCLK_PAD_EN", 0xe4, 0 }, - { "PCIE_OCLK_En", 20, 1 }, - { "PClkTree_DBG_En", 17, 1 }, - { "PCIX_OCLK_En", 16, 1 }, - { "U_OCLK_En", 12, 1 }, - { "R_OCLK_En", 8, 1 }, - { "M_OCLK_En", 4, 1 }, - { "C_OCLK_En", 0, 1 }, - { "T3DBG_PLL_LOCK", 0xe8, 0 }, - { "PCIX_LOCK", 16, 1 }, - { "U_LOCK", 12, 1 }, - { "R_LOCK", 8, 1 }, - { "M_LOCK", 4, 1 }, - { "C_LOCK", 0, 1 }, - { "T3DBG_SERDES_RBC_CFG", 0xec, 0 }, - { "X_RBC_Lane_Sel", 16, 2 }, - { "X_RBC_Dbg_En", 12, 1 }, - { "X_Serdes_Sel", 8, 1 }, - { "PE_RBC_Lane_Sel", 4, 3 }, - { "PE_RBC_Dbg_En", 0, 1 }, - { "T3DBG_GPIO_ACT_LOW", 0xf0, 0 }, - { "C_LOCK_ACT_LOW", 21, 1 }, - { "M_LOCK_ACT_LOW", 20, 1 }, - { "U_LOCK_ACT_LOW", 19, 1 }, - { "R_LOCK_ACT_LOW", 18, 1 }, - { "PX_LOCK_ACT_LOW", 17, 1 }, - { "GPIO11_ACT_LOW", 11, 1 }, - { "GPIO10_ACT_LOW", 10, 1 }, - { "GPIO9_ACT_LOW", 9, 1 }, - { "GPIO8_ACT_LOW", 8, 1 }, - { "GPIO7_ACT_LOW", 7, 1 }, - { "GPIO6_ACT_LOW", 6, 1 }, - { "GPIO5_ACT_LOW", 5, 1 }, - { "GPIO4_ACT_LOW", 4, 1 }, - { "GPIO3_ACT_LOW", 3, 1 }, - { "GPIO2_ACT_LOW", 2, 1 }, - { "GPIO1_ACT_LOW", 1, 1 }, - { "GPIO0_ACT_LOW", 0, 1 }, - { "T3DBG_PMON_CFG", 0xf4, 0 }, - { "PMON_DONE", 29, 1 }, - { "PMON_FAIL", 28, 1 }, - { "PMON_FDEL_AUTO", 22, 6 }, - { "PMON_CDEL_AUTO", 16, 6 }, - { "PMON_FDEL_MANUAL", 10, 6 }, - { "PMON_CDEL_MANUAL", 4, 6 }, - { "PMON_MANUAL", 1, 1 }, - { "PMON_AUTO", 0, 1 }, - { "T3DBG_SERDES_REFCLK_CFG", 0xf8, 0 }, - { "PE_REFCLK_DBG_EN", 12, 1 }, - { "X_REFCLK_DBG_EN", 8, 1 }, - { "PE_REFCLK_TERMADJ", 5, 2 }, - { "PE_REFCLK_PD", 4, 1 }, - { "X_REFCLK_TERMADJ", 1, 2 }, - { "X_REFCLK_PD", 0, 1 }, - { "T3DBG_PCIE_PMA_BSPIN_CFG", 0xfc, 0 }, - { "BSModeQuad1", 31, 1 }, - { "BSInSelLane7", 29, 2 }, - { "BSEnLane7", 28, 1 }, - { "BSInSelLane6", 25, 2 }, - { "BSEnLane6", 24, 1 }, - { "BSInSelLane5", 21, 2 }, - { "BSEnLane5", 20, 1 }, - { "BSInSelLane4", 17, 2 }, - { "BSEnLane4", 16, 1 }, - { "BSModeQuad0", 15, 1 }, - { "BSInSelLane3", 13, 2 }, - { "BSEnLane3", 12, 1 }, - { "BSInSelLane2", 9, 2 }, - { "BSEnLane2", 8, 1 }, - { "BSInSelLane1", 5, 2 }, - { "BSEnLane1", 4, 1 }, - { "BSInSelLane0", 1, 2 }, - { "BSEnLane0", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_mc7_pmrx_regs[] = { - { "MC7_CFG", 0x100, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x104, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x108, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x10c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x110, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x114, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x118, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x11c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x120, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x124, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x128, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ERR_ADDR", 0x12c, 0 }, - { "ErrAddress", 3, 29 }, - { "ErrAgent", 1, 2 }, - { "ErrOp", 0, 1 }, - { "MC7_ECC", 0x130, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x134, 0 }, - { "MC7_CE_DATA0", 0x138, 0 }, - { "MC7_CE_DATA1", 0x13c, 0 }, - { "MC7_CE_DATA2", 0x140, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x144, 0 }, - { "MC7_UE_DATA0", 0x148, 0 }, - { "MC7_UE_DATA1", 0x14c, 0 }, - { "MC7_UE_DATA2", 0x150, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x154, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x158, 0 }, - { "MC7_BD_DATA1", 0x15c, 0 }, - { "MC7_BD_DATA2", 0x160, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x164, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x168, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x16c, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x170, 0 }, - { "MC7_BIST_OP", 0x174, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x178, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x17c, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_mc7_pmtx_regs[] = { - { "MC7_CFG", 0x180, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x184, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x188, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x18c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x190, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x194, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x198, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x19c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x1a0, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x1a4, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x1a8, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ERR_ADDR", 0x1ac, 0 }, - { "ErrAddress", 3, 29 }, - { "ErrAgent", 1, 2 }, - { "ErrOp", 0, 1 }, - { "MC7_ECC", 0x1b0, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x1b4, 0 }, - { "MC7_CE_DATA0", 0x1b8, 0 }, - { "MC7_CE_DATA1", 0x1bc, 0 }, - { "MC7_CE_DATA2", 0x1c0, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x1c4, 0 }, - { "MC7_UE_DATA0", 0x1c8, 0 }, - { "MC7_UE_DATA1", 0x1cc, 0 }, - { "MC7_UE_DATA2", 0x1d0, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x1d4, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x1d8, 0 }, - { "MC7_BD_DATA1", 0x1dc, 0 }, - { "MC7_BD_DATA2", 0x1e0, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x1e4, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x1e8, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x1ec, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x1f0, 0 }, - { "MC7_BIST_OP", 0x1f4, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x1f8, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x1fc, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_mc7_cm_regs[] = { - { "MC7_CFG", 0x200, 0 }, - { "ImpSetUpdate", 14, 1 }, - { "IFEn", 13, 1 }, - { "TERM300", 12, 1 }, - { "TERM150", 11, 1 }, - { "Slow", 10, 1 }, - { "Width", 8, 2 }, - { "ODTEn", 7, 1 }, - { "Bks", 6, 1 }, - { "Org", 5, 1 }, - { "Den", 2, 3 }, - { "Rdy", 1, 1 }, - { "ClkEn", 0, 1 }, - { "MC7_MODE", 0x204, 0 }, - { "Busy", 31, 1 }, - { "Mode", 0, 16 }, - { "MC7_EXT_MODE1", 0x208, 0 }, - { "Busy", 31, 1 }, - { "OCDAdjustMode", 20, 1 }, - { "OCDCode", 16, 4 }, - { "ExtMode1", 0, 16 }, - { "MC7_EXT_MODE2", 0x20c, 0 }, - { "Busy", 31, 1 }, - { "ExtMode2", 0, 16 }, - { "MC7_EXT_MODE3", 0x210, 0 }, - { "Busy", 31, 1 }, - { "ExtMode3", 0, 16 }, - { "MC7_PRE", 0x214, 0 }, - { "Busy", 31, 1 }, - { "MC7_REF", 0x218, 0 }, - { "Busy", 31, 1 }, - { "PreRefDiv", 1, 14 }, - { "PerRefEn", 0, 1 }, - { "MC7_DLL", 0x21c, 0 }, - { "DLLLock", 31, 1 }, - { "DLLDelta", 24, 7 }, - { "ManDelta", 3, 7 }, - { "DLLDeltaSel", 2, 1 }, - { "DLLEnb", 1, 1 }, - { "DLLRst", 0, 1 }, - { "MC7_PARM", 0x220, 0 }, - { "ActToPreDly", 26, 4 }, - { "ActToRdWrDly", 23, 3 }, - { "PreCyc", 20, 3 }, - { "RefCyc", 13, 7 }, - { "BkCyc", 8, 5 }, - { "WrToRdDly", 4, 4 }, - { "RdToWrDly", 0, 4 }, - { "MC7_HWM_WRR", 0x224, 0 }, - { "MEM_HWM", 26, 6 }, - { "ULP_HWM", 22, 4 }, - { "TOT_RLD_WT", 14, 8 }, - { "MEM_RLD_WT", 7, 7 }, - { "ULP_RLD_WT", 0, 7 }, - { "MC7_CAL", 0x228, 0 }, - { "BUSY", 31, 1 }, - { "CAL_FAULT", 30, 1 }, - { "PER_CAL_DIV", 22, 8 }, - { "PER_CAL_EN", 21, 1 }, - { "SGL_CAL_EN", 20, 1 }, - { "IMP_UPD_MODE", 19, 1 }, - { "IMP_SEL", 18, 1 }, - { "IMP_MAN_PD", 15, 3 }, - { "IMP_MAN_PU", 12, 3 }, - { "IMP_CAL_PD", 9, 3 }, - { "IMP_CAL_PU", 6, 3 }, - { "IMP_SET_PD", 3, 3 }, - { "IMP_SET_PU", 0, 3 }, - { "MC7_ERR_ADDR", 0x22c, 0 }, - { "ErrAddress", 3, 29 }, - { "ErrAgent", 1, 2 }, - { "ErrOp", 0, 1 }, - { "MC7_ECC", 0x230, 0 }, - { "UECnt", 10, 8 }, - { "CECnt", 2, 8 }, - { "ECCChkEn", 1, 1 }, - { "ECCGenEn", 0, 1 }, - { "MC7_CE_ADDR", 0x234, 0 }, - { "MC7_CE_DATA0", 0x238, 0 }, - { "MC7_CE_DATA1", 0x23c, 0 }, - { "MC7_CE_DATA2", 0x240, 0 }, - { "Data", 0, 8 }, - { "MC7_UE_ADDR", 0x244, 0 }, - { "MC7_UE_DATA0", 0x248, 0 }, - { "MC7_UE_DATA1", 0x24c, 0 }, - { "MC7_UE_DATA2", 0x250, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_ADDR", 0x254, 0 }, - { "Addr", 3, 29 }, - { "MC7_BD_DATA0", 0x258, 0 }, - { "MC7_BD_DATA1", 0x25c, 0 }, - { "MC7_BD_DATA2", 0x260, 0 }, - { "Data", 0, 8 }, - { "MC7_BD_OP", 0x264, 0 }, - { "Busy", 31, 1 }, - { "Op", 0, 1 }, - { "MC7_BIST_ADDR_BEG", 0x268, 0 }, - { "AddrBeg", 5, 27 }, - { "MC7_BIST_ADDR_END", 0x26c, 0 }, - { "AddrEnd", 5, 27 }, - { "MC7_BIST_DATA", 0x270, 0 }, - { "MC7_BIST_OP", 0x274, 0 }, - { "Busy", 31, 1 }, - { "Gap", 4, 5 }, - { "Cont", 3, 1 }, - { "DataPat", 1, 2 }, - { "Op", 0, 1 }, - { "MC7_INT_ENABLE", 0x278, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { "MC7_INT_CAUSE", 0x27c, 0 }, - { "AE", 17, 1 }, - { "PE", 2, 15 }, - { "UE", 1, 1 }, - { "CE", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_cim_regs[] = { - { "CIM_BOOT_CFG", 0x280, 0 }, - { "BootAddr", 2, 30 }, - { "BootSdram", 1, 1 }, - { "uPCRst", 0, 1 }, - { "CIM_FLASH_BASE_ADDR", 0x284, 0 }, - { "FlashBaseAddr", 2, 22 }, - { "CIM_FLASH_ADDR_SIZE", 0x288, 0 }, - { "FlashAddrSize", 2, 22 }, - { "CIM_SDRAM_BASE_ADDR", 0x28c, 0 }, - { "SdramBaseAddr", 2, 30 }, - { "CIM_SDRAM_ADDR_SIZE", 0x290, 0 }, - { "SdramAddrSize", 2, 30 }, - { "CIM_UP_SPARE_INT", 0x294, 0 }, - { "uPSpareInt", 0, 3 }, - { "CIM_HOST_INT_ENABLE", 0x298, 0 }, - { "DTagParErr", 28, 1 }, - { "ITagParErr", 27, 1 }, - { "IBQTPParErr", 26, 1 }, - { "IBQULPParErr", 25, 1 }, - { "IBQSGEHIParErr", 24, 1 }, - { "IBQSGELOParErr", 23, 1 }, - { "OBQULPLOParErr", 22, 1 }, - { "OBQULPHIParErr", 21, 1 }, - { "OBQSGEParErr", 20, 1 }, - { "DCacheParErr", 19, 1 }, - { "ICacheParErr", 18, 1 }, - { "DRamParErr", 17, 1 }, - { "Timer1IntEn", 15, 1 }, - { "Timer0IntEn", 14, 1 }, - { "PrefDropIntEn", 13, 1 }, - { "BlkWrPlIntEn", 12, 1 }, - { "BlkRdPlIntEn", 11, 1 }, - { "BlkWrCtlIntEn", 10, 1 }, - { "BlkRdCtlIntEn", 9, 1 }, - { "BlkWrFlashIntEn", 8, 1 }, - { "BlkRdFlashIntEn", 7, 1 }, - { "SglWrFlashIntEn", 6, 1 }, - { "WrBlkFlashIntEn", 5, 1 }, - { "BlkWrBootIntEn", 4, 1 }, - { "BlkRdBootIntEn", 3, 1 }, - { "FlashRangeIntEn", 2, 1 }, - { "SdramRangeIntEn", 1, 1 }, - { "RsvdSpaceIntEn", 0, 1 }, - { "CIM_HOST_INT_CAUSE", 0x29c, 0 }, - { "DTagParErr", 28, 1 }, - { "ITagParErr", 27, 1 }, - { "IBQTPParErr", 26, 1 }, - { "IBQULPParErr", 25, 1 }, - { "IBQSGEHIParErr", 24, 1 }, - { "IBQSGELOParErr", 23, 1 }, - { "OBQULPLOParErr", 22, 1 }, - { "OBQULPHIParErr", 21, 1 }, - { "OBQSGEParErr", 20, 1 }, - { "DCacheParErr", 19, 1 }, - { "ICacheParErr", 18, 1 }, - { "DRamParErr", 17, 1 }, - { "Timer1Int", 15, 1 }, - { "Timer0Int", 14, 1 }, - { "PrefDropInt", 13, 1 }, - { "BlkWrPlInt", 12, 1 }, - { "BlkRdPlInt", 11, 1 }, - { "BlkWrCtlInt", 10, 1 }, - { "BlkRdCtlInt", 9, 1 }, - { "BlkWrFlashInt", 8, 1 }, - { "BlkRdFlashInt", 7, 1 }, - { "SglWrFlashInt", 6, 1 }, - { "WrBlkFlashInt", 5, 1 }, - { "BlkWrBootInt", 4, 1 }, - { "BlkRdBootInt", 3, 1 }, - { "FlashRangeInt", 2, 1 }, - { "SdramRangeInt", 1, 1 }, - { "RsvdSpaceInt", 0, 1 }, - { "CIM_UP_INT_ENABLE", 0x2a0, 0 }, - { "DTagParErr", 28, 1 }, - { "ITagParErr", 27, 1 }, - { "IBQTPParErr", 26, 1 }, - { "IBQULPParErr", 25, 1 }, - { "IBQSGEHIParErr", 24, 1 }, - { "IBQSGELOParErr", 23, 1 }, - { "OBQULPLOParErr", 22, 1 }, - { "OBQULPHIParErr", 21, 1 }, - { "OBQSGEParErr", 20, 1 }, - { "DCacheParErr", 19, 1 }, - { "ICacheParErr", 18, 1 }, - { "DRamParErr", 17, 1 }, - { "MstPlIntEn", 16, 1 }, - { "Timer1IntEn", 15, 1 }, - { "Timer0IntEn", 14, 1 }, - { "PrefDropIntEn", 13, 1 }, - { "BlkWrPlIntEn", 12, 1 }, - { "BlkRdPlIntEn", 11, 1 }, - { "BlkWrCtlIntEn", 10, 1 }, - { "BlkRdCtlIntEn", 9, 1 }, - { "BlkWrFlashIntEn", 8, 1 }, - { "BlkRdFlashIntEn", 7, 1 }, - { "SglWrFlashIntEn", 6, 1 }, - { "WrBlkFlashIntEn", 5, 1 }, - { "BlkWrBootIntEn", 4, 1 }, - { "BlkRdBootIntEn", 3, 1 }, - { "FlashRangeIntEn", 2, 1 }, - { "SdramRangeIntEn", 1, 1 }, - { "RsvdSpaceIntEn", 0, 1 }, - { "CIM_UP_INT_CAUSE", 0x2a4, 0 }, - { "DTagParErr", 28, 1 }, - { "ITagParErr", 27, 1 }, - { "IBQTPParErr", 26, 1 }, - { "IBQULPParErr", 25, 1 }, - { "IBQSGEHIParErr", 24, 1 }, - { "IBQSGELOParErr", 23, 1 }, - { "OBQULPLOParErr", 22, 1 }, - { "OBQULPHIParErr", 21, 1 }, - { "OBQSGEParErr", 20, 1 }, - { "DCacheParErr", 19, 1 }, - { "ICacheParErr", 18, 1 }, - { "DRamParErr", 17, 1 }, - { "MstPlInt", 16, 1 }, - { "Timer1Int", 15, 1 }, - { "Timer0Int", 14, 1 }, - { "PrefDropInt", 13, 1 }, - { "BlkWrPlInt", 12, 1 }, - { "BlkRdPlInt", 11, 1 }, - { "BlkWrCtlInt", 10, 1 }, - { "BlkRdCtlInt", 9, 1 }, - { "BlkWrFlashInt", 8, 1 }, - { "BlkRdFlashInt", 7, 1 }, - { "SglWrFlashInt", 6, 1 }, - { "WrBlkFlashInt", 5, 1 }, - { "BlkWrBootInt", 4, 1 }, - { "BlkRdBootInt", 3, 1 }, - { "FlashRangeInt", 2, 1 }, - { "SdramRangeInt", 1, 1 }, - { "RsvdSpaceInt", 0, 1 }, - { "CIM_IBQ_FULLA_THRSH", 0x2a8, 0 }, - { "Ibq0FullThrsh", 0, 9 }, - { "Ibq1FullThrsh", 16, 9 }, - { "CIM_IBQ_FULLB_THRSH", 0x2ac, 0 }, - { "Ibq2FullThrsh", 0, 9 }, - { "Ibq3FullThrsh", 16, 9 }, - { "CIM_HOST_ACC_CTRL", 0x2b0, 0 }, - { "HostBusy", 17, 1 }, - { "HostWrite", 16, 1 }, - { "HostAddr", 0, 16 }, - { "CIM_HOST_ACC_DATA", 0x2b4, 0 }, - { "CIM_IBQ_DBG_CFG", 0x2c0, 0 }, - { "IbqDbgAddr", 16, 9 }, - { "IbqDbgQID", 3, 2 }, - { "IbqDbgWr", 2, 1 }, - { "IbqDbgBusy", 1, 1 }, - { "IbqDbgEn", 0, 1 }, - { "CIM_OBQ_DBG_CFG", 0x2c4, 0 }, - { "ObqDbgAddr", 16, 9 }, - { "ObqDbgQID", 3, 2 }, - { "ObqDbgWr", 2, 1 }, - { "ObqDbgBusy", 1, 1 }, - { "ObqDbgEn", 0, 1 }, - { "CIM_IBQ_DBG_DATA", 0x2c8, 0 }, - { "CIM_OBQ_DBG_DATA", 0x2cc, 0 }, - { "CIM_CDEBUGDATA", 0x2d0, 0 }, - { "CDebugDataH", 16, 16 }, - { "CDebugDataL", 0, 16 }, - { "CIM_DEBUGCFG", 0x2e0, 0 }, - { "POLADbgRdPtr", 23, 9 }, - { "PILADbgRdPtr", 14, 9 }, - { "LADbgEn", 12, 1 }, - { "DebugSelH", 5, 5 }, - { "DebugSelL", 0, 5 }, - { "CIM_DEBUGSTS", 0x2e4, 0 }, - { "POLADbgWrPtr", 16, 9 }, - { "PILADbgWrPtr", 0, 9 }, - { "CIM_PO_LA_DEBUGDATA", 0x2e8, 0 }, - { "CIM_PI_LA_DEBUGDATA", 0x2ec, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_tp1_regs[] = { - { "TP_IN_CONFIG", 0x300, 0 }, - { "RXFbArbPrio", 25, 1 }, - { "TXFbArbPrio", 24, 1 }, - { "DBMaxOpCnt", 16, 8 }, - { "IPv6Enable", 15, 1 }, - { "NICMode", 14, 1 }, - { "EChecksumCheckTCP", 13, 1 }, - { "EChecksumCheckIP", 12, 1 }, - { "ECPL", 10, 1 }, - { "EEthernet", 8, 1 }, - { "ETunnel", 7, 1 }, - { "CChecksumCheckTCP", 6, 1 }, - { "CChecksumCheckIP", 5, 1 }, - { "CCPL", 3, 1 }, - { "CEthernet", 1, 1 }, - { "CTunnel", 0, 1 }, - { "TP_OUT_CONFIG", 0x304, 0 }, - { "IPIDSplitMode", 16, 1 }, - { "VLANExtractionEnable2ndPort", 13, 1 }, - { "VLANExtractionEnable", 12, 1 }, - { "EChecksumGenerateTCP", 11, 1 }, - { "EChecksumGenerateIP", 10, 1 }, - { "ECPL", 8, 1 }, - { "EEthernet", 6, 1 }, - { "CChecksumGenerateTCP", 5, 1 }, - { "CChecksumGenerateIP", 4, 1 }, - { "CCPL", 2, 1 }, - { "CEthernet", 0, 1 }, - { "TP_GLOBAL_CONFIG", 0x308, 0 }, - { "SYNCookieParams", 26, 6 }, - { "RXFlowControlDisable", 25, 1 }, - { "TXPacingEnable", 24, 1 }, - { "AttackFilterEnable", 23, 1 }, - { "SYNCookieNoOptions", 22, 1 }, - { "ProtectedMode", 21, 1 }, - { "PingDrop", 20, 1 }, - { "FragmentDrop", 19, 1 }, - { "FiveTupleLookup", 17, 2 }, - { "PathMTU", 15, 1 }, - { "IPIdentSplit", 14, 1 }, - { "IPChecksumOffload", 13, 1 }, - { "UDPChecksumOffload", 12, 1 }, - { "TCPChecksumOffload", 11, 1 }, - { "QOSMapping", 10, 1 }, - { "TCAMServerUse", 8, 2 }, - { "IPTTL", 0, 8 }, - { "TP_GLOBAL_RX_CREDIT", 0x30c, 0 }, - { "TP_CMM_SIZE", 0x310, 0 }, - { "CMMemMgrSize", 0, 28 }, - { "TP_CMM_MM_BASE", 0x314, 0 }, - { "CMMemMgrBase", 0, 28 }, - { "TP_CMM_TIMER_BASE", 0x318, 0 }, - { "CMTimerMaxNum", 28, 2 }, - { "CMTimerBase", 0, 28 }, - { "TP_PMM_SIZE", 0x31c, 0 }, - { "PMSize", 0, 28 }, - { "TP_PMM_TX_BASE", 0x320, 0 }, - { "TP_PMM_DEFRAG_BASE", 0x324, 0 }, - { "TP_PMM_RX_BASE", 0x328, 0 }, - { "TP_PMM_RX_PAGE_SIZE", 0x32c, 0 }, - { "TP_PMM_RX_MAX_PAGE", 0x330, 0 }, - { "PMRxMaxPage", 0, 21 }, - { "TP_PMM_TX_PAGE_SIZE", 0x334, 0 }, - { "TP_PMM_TX_MAX_PAGE", 0x338, 0 }, - { "PMTxMaxPage", 0, 21 }, - { "TP_TCP_OPTIONS", 0x340, 0 }, - { "MTUDefault", 16, 16 }, - { "MTUEnable", 10, 1 }, - { "SACKTx", 9, 1 }, - { "SACKRx", 8, 1 }, - { "SACKMode", 4, 2 }, - { "WindowScaleMode", 2, 2 }, - { "TimestampsMode", 0, 2 }, - { "TP_DACK_CONFIG", 0x344, 0 }, - { "AutoState3", 30, 2 }, - { "AutoState2", 28, 2 }, - { "AutoState1", 26, 2 }, - { "ByteThreshold", 5, 20 }, - { "MSSThreshold", 3, 2 }, - { "AutoCareful", 2, 1 }, - { "AutoEnable", 1, 1 }, - { "Mode", 0, 1 }, - { "TP_PC_CONFIG", 0x348, 0 }, - { "CMCacheDisable", 31, 1 }, - { "EnableOcspiFull", 30, 1 }, - { "EnableFLMErrorDDP", 29, 1 }, - { "LockTid", 28, 1 }, - { "FixRcvWnd", 27, 1 }, - { "TxTosQueueMapMode", 26, 1 }, - { "RddpCongEn", 25, 1 }, - { "EnableOnFlyPDU", 24, 1 }, - { "EnableEPCMDAFull", 23, 1 }, - { "ModulateUnionMode", 22, 1 }, - { "TxDataAckRateEnable", 21, 1 }, - { "TxDeferEnable", 20, 1 }, - { "RxCongestionMode", 19, 1 }, - { "HearbeatOnceDACK", 18, 1 }, - { "HearbeatOnceHeap", 17, 1 }, - { "HearbeatDACK", 16, 1 }, - { "TxCongestionMode", 15, 1 }, - { "AcceptLatestRcvAdv", 14, 1 }, - { "DisableSYNData", 13, 1 }, - { "DisableWindowPSH", 12, 1 }, - { "DisableFINOldData", 11, 1 }, - { "EnableFLMError", 10, 1 }, - { "DisableNextMtu", 9, 1 }, - { "FilterPeerFIN", 8, 1 }, - { "EnableFeedbackSend", 7, 1 }, - { "EnableRDMAError", 6, 1 }, - { "EnableDDPFlowControl", 5, 1 }, - { "DisableHeldFIN", 4, 1 }, - { "TableLatencyDelta", 0, 4 }, - { "TP_PC_CONFIG2", 0x34c, 0 }, - { "DisbleDaParbit0", 15, 1 }, - { "EnableArpMiss", 13, 1 }, - { "EnableNonOfdTnlSyn", 12, 1 }, - { "EnableIPv6RSS", 11, 1 }, - { "EnableDropRQEmptyPkt", 10, 1 }, - { "EnableTxPortfromDA2", 9, 1 }, - { "EnableRxPktTmstpRss", 8, 1 }, - { "EnableSndUnaInRxData", 7, 1 }, - { "EnableRxPortFromAddr", 6, 1 }, - { "EnableTxPortfromDA", 5, 1 }, - { "EnableCHdrAFull", 4, 1 }, - { "EnableNonOfdScbBit", 3, 1 }, - { "EnableNonOfdTidRss", 2, 1 }, - { "EnableNonOfdTcbRss", 1, 1 }, - { "EnableOldRxForward", 0, 1 }, - { "TP_TCP_BACKOFF_REG0", 0x350, 0 }, - { "TimerBackoffIndex3", 24, 8 }, - { "TimerBackoffIndex2", 16, 8 }, - { "TimerBackoffIndex1", 8, 8 }, - { "TimerBackoffIndex0", 0, 8 }, - { "TP_TCP_BACKOFF_REG1", 0x354, 0 }, - { "TimerBackoffIndex7", 24, 8 }, - { "TimerBackoffIndex6", 16, 8 }, - { "TimerBackoffIndex5", 8, 8 }, - { "TimerBackoffIndex4", 0, 8 }, - { "TP_TCP_BACKOFF_REG2", 0x358, 0 }, - { "TimerBackoffIndex11", 24, 8 }, - { "TimerBackoffIndex10", 16, 8 }, - { "TimerBackoffIndex9", 8, 8 }, - { "TimerBackoffIndex8", 0, 8 }, - { "TP_TCP_BACKOFF_REG3", 0x35c, 0 }, - { "TimerBackoffIndex15", 24, 8 }, - { "TimerBackoffIndex14", 16, 8 }, - { "TimerBackoffIndex13", 8, 8 }, - { "TimerBackoffIndex12", 0, 8 }, - { "TP_PARA_REG0", 0x360, 0 }, - { "InitCwnd", 24, 3 }, - { "DupAckThresh", 20, 4 }, - { "TP_PARA_REG1", 0x364, 0 }, - { "InitRwnd", 16, 16 }, - { "InitialSSThresh", 0, 16 }, - { "TP_PARA_REG2", 0x368, 0 }, - { "MaxRxData", 16, 16 }, - { "RxCoalesceSize", 0, 16 }, - { "TP_PARA_REG3", 0x36c, 0 }, - { "TunnelCngDrop1", 21, 1 }, - { "TunnelCngDrop0", 20, 1 }, - { "TxDataAckIdx", 16, 4 }, - { "RxFragEnable", 12, 3 }, - { "TxPaceFixedStrict", 11, 1 }, - { "TxPaceAutoStrict", 10, 1 }, - { "TxPaceFixed", 9, 1 }, - { "TxPaceAuto", 8, 1 }, - { "RxUrgTunnel", 6, 1 }, - { "RxUrgMode", 5, 1 }, - { "TxUrgMode", 4, 1 }, - { "CngCtrlMode", 2, 2 }, - { "RxCoalesceEnable", 1, 1 }, - { "RxCoalescePshEn", 0, 1 }, - { "TP_PARA_REG4", 0x370, 0 }, - { "HighSpeedCfg", 24, 8 }, - { "NewRenoCfg", 16, 8 }, - { "TahoeCfg", 8, 8 }, - { "RenoCfg", 0, 8 }, - { "TP_PARA_REG5", 0x374, 0 }, - { "IndicateSize", 16, 16 }, - { "SchdEnable", 8, 1 }, - { "RxDdpOffInit", 3, 1 }, - { "OnFlyDDPEnable", 2, 1 }, - { "DackTimerSpin", 1, 1 }, - { "PushTimerEnable", 0, 1 }, - { "TP_PARA_REG6", 0x378, 0 }, - { "TxPDUSizeAdj", 16, 8 }, - { "EnableDeferACK", 12, 1 }, - { "EnableESnd", 11, 1 }, - { "EnableCSnd", 10, 1 }, - { "EnablePDUE", 9, 1 }, - { "EnablePDUC", 8, 1 }, - { "EnableBUFI", 7, 1 }, - { "EnableBUFE", 6, 1 }, - { "EnableDefer", 5, 1 }, - { "EnableClearRxmtOos", 4, 1 }, - { "DisablePDUCng", 3, 1 }, - { "DisablePDUTimeout", 2, 1 }, - { "DisablePDURxmt", 1, 1 }, - { "DisablePDUxmt", 0, 1 }, - { "TP_PARA_REG7", 0x37c, 0 }, - { "PMMaxXferLen1", 16, 16 }, - { "PMMaxXferLen0", 0, 16 }, - { "TP_TIMER_RESOLUTION", 0x390, 0 }, - { "TimerResolution", 16, 8 }, - { "TimestampResolution", 8, 8 }, - { "DelayedACKResolution", 0, 8 }, - { "TP_MSL", 0x394, 0 }, - { "MSL", 0, 30 }, - { "TP_RXT_MIN", 0x398, 0 }, - { "RxtMin", 0, 30 }, - { "TP_RXT_MAX", 0x39c, 0 }, - { "RxtMax", 0, 30 }, - { "TP_PERS_MIN", 0x3a0, 0 }, - { "PersMin", 0, 30 }, - { "TP_PERS_MAX", 0x3a4, 0 }, - { "PersMax", 0, 30 }, - { "TP_KEEP_IDLE", 0x3a8, 0 }, - { "KeepaliveIdle", 0, 30 }, - { "TP_KEEP_INTVL", 0x3ac, 0 }, - { "KeepaliveIntvl", 0, 30 }, - { "TP_INIT_SRTT", 0x3b0, 0 }, - { "InitSrtt", 0, 16 }, - { "TP_DACK_TIMER", 0x3b4, 0 }, - { "DackTime", 0, 12 }, - { "TP_FINWAIT2_TIMER", 0x3b8, 0 }, - { "Finwait2Time", 0, 30 }, - { "TP_FAST_FINWAIT2_TIMER", 0x3bc, 0 }, - { "FastFinwait2Time", 0, 30 }, - { "TP_SHIFT_CNT", 0x3c0, 0 }, - { "SynShiftMax", 24, 8 }, - { "RxtShiftMaxR1", 20, 4 }, - { "RxtShiftMaxR2", 16, 4 }, - { "PerShiftBackoffMax", 12, 4 }, - { "PerShiftMax", 8, 4 }, - { "KeepaliveMax", 0, 8 }, - { "TP_TIME_HI", 0x3c8, 0 }, - { "TP_TIME_LO", 0x3cc, 0 }, - { "TP_MTU_PORT_TABLE", 0x3d0, 0 }, - { "Port1MTUValue", 16, 16 }, - { "Port0MTUValue", 0, 16 }, - { "TP_ULP_TABLE", 0x3d4, 0 }, - { "ULPType7Field", 28, 4 }, - { "ULPType6Field", 24, 4 }, - { "ULPType5Field", 20, 4 }, - { "ULPType4Field", 16, 4 }, - { "ULPType3Field", 12, 4 }, - { "ULPType2Field", 8, 4 }, - { "ULPType1Field", 4, 4 }, - { "ULPType0Field", 0, 4 }, - { "TP_PACE_TABLE", 0x3d8, 0 }, - { "TP_CCTRL_TABLE", 0x3dc, 0 }, - { "TP_TOS_TABLE", 0x3e0, 0 }, - { "TP_MTU_TABLE", 0x3e4, 0 }, - { "TP_RSS_MAP_TABLE", 0x3e8, 0 }, - { "TP_RSS_LKP_TABLE", 0x3ec, 0 }, - { "TP_RSS_CONFIG", 0x3f0, 0 }, - { "TNL4tupEn", 29, 1 }, - { "TNL2tupEn", 28, 1 }, - { "TNLprtEn", 26, 1 }, - { "TNLMapEn", 25, 1 }, - { "TNLLkpEn", 24, 1 }, - { "OFD4tupEn", 21, 1 }, - { "OFD2tupEn", 20, 1 }, - { "OFDMapEn", 17, 1 }, - { "OFDLkpEn", 16, 1 }, - { "SYN4tupEn", 13, 1 }, - { "SYN2tupEn", 12, 1 }, - { "SYNMapEn", 9, 1 }, - { "SYNLkpEn", 8, 1 }, - { "RRCPLMapEn", 7, 1 }, - { "RRCPLCPUSIZE", 4, 3 }, - { "RQFeedbackEnable", 3, 1 }, - { "HashToeplitz", 2, 1 }, - { "HashSave", 1, 1 }, - { "Disable", 0, 1 }, - { "TP_RSS_CONFIG_TNL", 0x3f4, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_CONFIG_OFD", 0x3f8, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_CONFIG_SYN", 0x3fc, 0 }, - { "MaskSize", 28, 3 }, - { "DefaultCPUBase", 22, 6 }, - { "DefaultCPU", 16, 6 }, - { "DefaultQueue", 0, 16 }, - { "TP_RSS_SECRET_KEY0", 0x400, 0 }, - { "TP_RSS_SECRET_KEY1", 0x404, 0 }, - { "TP_RSS_SECRET_KEY2", 0x408, 0 }, - { "TP_RSS_SECRET_KEY3", 0x40c, 0 }, - { "TP_TM_PIO_ADDR", 0x418, 0 }, - { "TP_TM_PIO_DATA", 0x41c, 0 }, - { "TP_TX_MOD_QUE_TABLE", 0x420, 0 }, - { "TP_TX_RESOURCE_LIMIT", 0x424, 0 }, - { "TX_RESOURCE_LIMIT_CH1_PC", 24, 8 }, - { "TX_RESOURCE_LIMIT_CH1_NON_PC", 16, 8 }, - { "TX_RESOURCE_LIMIT_CH0_PC", 8, 8 }, - { "TX_RESOURCE_LIMIT_CH0_NON_PC", 0, 8 }, - { "TP_TX_MOD_QUEUE_REQ_MAP", 0x428, 0 }, - { "RX_MOD_WEIGHT", 24, 8 }, - { "TX_MOD_WEIGHT", 16, 8 }, - { "TX_MOD_TIMER_MODE", 8, 8 }, - { "TX_MOD_QUEUE_REQ_MAP", 0, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT1", 0x42c, 0 }, - { "TP_TX_MOD_QUEUE_WEIGHT7", 24, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT6", 16, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT5", 8, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT4", 0, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT0", 0x430, 0 }, - { "TP_TX_MOD_QUEUE_WEIGHT3", 24, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT2", 16, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT1", 8, 8 }, - { "TP_TX_MOD_QUEUE_WEIGHT0", 0, 8 }, - { "TP_MOD_CHANNEL_WEIGHT", 0x434, 0 }, - { "RX_MOD_CHANNEL_WEIGHT1", 24, 8 }, - { "RX_MOD_CHANNEL_WEIGHT0", 16, 8 }, - { "TX_MOD_CHANNEL_WEIGHT1", 8, 8 }, - { "TX_MOD_CHANNEL_WEIGHT0", 0, 8 }, - { "TP_MOD_RATE_LIMIT", 0x438, 0 }, - { "RX_MOD_RATE_LIMIT_INC", 24, 8 }, - { "RX_MOD_RATE_LIMIT_TICK", 16, 8 }, - { "TX_MOD_RATE_LIMIT_INC", 8, 8 }, - { "TX_MOD_RATE_LIMIT_TICK", 0, 8 }, - { "TP_PIO_ADDR", 0x440, 0 }, - { "TP_PIO_DATA", 0x444, 0 }, - { "TP_RESET", 0x44c, 0 }, - { "FlstInitEnable", 1, 1 }, - { "TPReset", 0, 1 }, - { "TP_MIB_INDEX", 0x450, 0 }, - { "TP_MIB_RDATA", 0x454, 0 }, - { "TP_SYNC_TIME_HI", 0x458, 0 }, - { "TP_SYNC_TIME_LO", 0x45c, 0 }, - { "TP_CMM_MM_RX_FLST_BASE", 0x460, 0 }, - { "CMRxFlstBase", 0, 28 }, - { "TP_CMM_MM_TX_FLST_BASE", 0x464, 0 }, - { "CMTxFlstBase", 0, 28 }, - { "TP_CMM_MM_PS_FLST_BASE", 0x468, 0 }, - { "CMPsFlstBase", 0, 28 }, - { "TP_CMM_MM_MAX_PSTRUCT", 0x46c, 0 }, - { "CMMaxPstruct", 0, 21 }, - { "TP_INT_ENABLE", 0x470, 0 }, - { "FlmTxFlstEmpty", 30, 1 }, - { "FlmRxFlstEmpty", 29, 1 }, - { "FlmPerrSet", 28, 1 }, - { "ProtocolSramPerr", 27, 1 }, - { "ArpLutPerr", 26, 1 }, - { "CmRcfOpPerr", 25, 1 }, - { "CmCachePerr", 24, 1 }, - { "CmRcfDataPerr", 23, 1 }, - { "DbL2tLutPerr", 22, 1 }, - { "DbTxTidPerr", 21, 1 }, - { "DbExtPerr", 20, 1 }, - { "DbOpPerr", 19, 1 }, - { "TmCachePerr", 18, 1 }, - { "ETpOutCplFifoPerr", 17, 1 }, - { "ETpOutTcpFifoPerr", 16, 1 }, - { "ETpOutIpFifoPerr", 15, 1 }, - { "ETpOutEthFifoPerr", 14, 1 }, - { "ETpInCplFifoPerr", 13, 1 }, - { "ETpInTcpOptFifoPerr", 12, 1 }, - { "ETpInTcpFifoPerr", 11, 1 }, - { "ETpInIpFifoPerr", 10, 1 }, - { "ETpInEthFifoPerr", 9, 1 }, - { "CTpOutCplFifoPerr", 8, 1 }, - { "CTpOutTcpFifoPerr", 7, 1 }, - { "CTpOutIpFifoPerr", 6, 1 }, - { "CTpOutEthFifoPerr", 5, 1 }, - { "CTpInCplFifoPerr", 4, 1 }, - { "CTpInTcpOpFifoPerr", 3, 1 }, - { "CTpInTcpFifoPerr", 2, 1 }, - { "CTpInIpFifoPerr", 1, 1 }, - { "CTpInEthFifoPerr", 0, 1 }, - { "TP_INT_CAUSE", 0x474, 0 }, - { "FlmTxFlstEmpty", 30, 1 }, - { "FlmRxFlstEmpty", 29, 1 }, - { "FlmPerrSet", 28, 1 }, - { "ProtocolSramPerr", 27, 1 }, - { "ArpLutPerr", 26, 1 }, - { "CmRcfOpPerr", 25, 1 }, - { "CmCachePerr", 24, 1 }, - { "CmRcfDataPerr", 23, 1 }, - { "DbL2tLutPerr", 22, 1 }, - { "DbTxTidPerr", 21, 1 }, - { "DbExtPerr", 20, 1 }, - { "DbOpPerr", 19, 1 }, - { "TmCachePerr", 18, 1 }, - { "ETpOutCplFifoPerr", 17, 1 }, - { "ETpOutTcpFifoPerr", 16, 1 }, - { "ETpOutIpFifoPerr", 15, 1 }, - { "ETpOutEthFifoPerr", 14, 1 }, - { "ETpInCplFifoPerr", 13, 1 }, - { "ETpInTcpOptFifoPerr", 12, 1 }, - { "ETpInTcpFifoPerr", 11, 1 }, - { "ETpInIpFifoPerr", 10, 1 }, - { "ETpInEthFifoPerr", 9, 1 }, - { "CTpOutCplFifoPerr", 8, 1 }, - { "CTpOutTcpFifoPerr", 7, 1 }, - { "CTpOutIpFifoPerr", 6, 1 }, - { "CTpOutEthFifoPerr", 5, 1 }, - { "CTpInCplFifoPerr", 4, 1 }, - { "CTpInTcpOpFifoPerr", 3, 1 }, - { "CTpInTcpFifoPerr", 2, 1 }, - { "CTpInIpFifoPerr", 1, 1 }, - { "CTpInEthFifoPerr", 0, 1 }, - { "TP_FLM_FREE_PS_CNT", 0x480, 0 }, - { "FreePstructCount", 0, 21 }, - { "TP_FLM_FREE_RX_CNT", 0x484, 0 }, - { "FreeRxPageCount", 0, 21 }, - { "TP_FLM_FREE_TX_CNT", 0x488, 0 }, - { "FreeTxPageCount", 0, 21 }, - { "TP_TM_HEAP_PUSH_CNT", 0x48c, 0 }, - { "TP_TM_HEAP_POP_CNT", 0x490, 0 }, - { "TP_TM_DACK_PUSH_CNT", 0x494, 0 }, - { "TP_TM_DACK_POP_CNT", 0x498, 0 }, - { "TP_TM_MOD_PUSH_CNT", 0x49c, 0 }, - { "TP_MOD_POP_CNT", 0x4a0, 0 }, - { "TP_TIMER_SEPARATOR", 0x4a4, 0 }, - { "TP_DEBUG_SEL", 0x4a8, 0 }, - { "TP_DEBUG_FLAGS", 0x4ac, 0 }, - { "RxTimerDackFirst", 26, 1 }, - { "RxTimerDack", 25, 1 }, - { "RxTimerHeartbeat", 24, 1 }, - { "RxPawsDrop", 23, 1 }, - { "RxUrgDataDrop", 22, 1 }, - { "RxFutureData", 21, 1 }, - { "RxRcvRxmData", 20, 1 }, - { "RxRcvOooDataFin", 19, 1 }, - { "RxRcvOooData", 18, 1 }, - { "RxRcvWndZero", 17, 1 }, - { "RxRcvWndLtMss", 16, 1 }, - { "TxDupAckInc", 11, 1 }, - { "TxRxmUrg", 10, 1 }, - { "TxRxmFin", 9, 1 }, - { "TxRxmSyn", 8, 1 }, - { "TxRxmNewReno", 7, 1 }, - { "TxRxmFast", 6, 1 }, - { "TxRxmTimer", 5, 1 }, - { "TxRxmTimerKeepalive", 4, 1 }, - { "TxRxmTimerPersist", 3, 1 }, - { "TxRcvAdvShrunk", 2, 1 }, - { "TxRcvAdvZero", 1, 1 }, - { "TxRcvAdvLtMss", 0, 1 }, - { "TP_PROXY_FLOW_CNTL", 0x4b0, 0 }, - { "TP_PC_CONGESTION_CNTL", 0x4b4, 0 }, - { "EDropTunnel", 19, 1 }, - { "CDropTunnel", 18, 1 }, - { "EThreshold", 12, 6 }, - { "CThreshold", 6, 6 }, - { "TxThreshold", 0, 6 }, - { "TP_TX_DROP_COUNT", 0x4bc, 0 }, - { "TP_CLEAR_DEBUG", 0x4c0, 0 }, - { "ClrDebug", 0, 1 }, - { "TP_DEBUG_VEC", 0x4c4, 0 }, - { "TP_DEBUG_VEC2", 0x4c8, 0 }, - { "TP_DEBUG_REG_SEL", 0x4cc, 0 }, - { "TP_DEBUG", 0x4d0, 0 }, - { "TP_DBG_LA_CONFIG", 0x4d4, 0 }, - { "TP_DBG_LA_DATAH", 0x4d8, 0 }, - { "TP_DBG_LA_DATAL", 0x4dc, 0 }, - { "TP_EMBED_OP_FIELD0", 0x4e8, 0 }, - { "TP_EMBED_OP_FIELD1", 0x4ec, 0 }, - { "TP_EMBED_OP_FIELD2", 0x4f0, 0 }, - { "TP_EMBED_OP_FIELD3", 0x4f4, 0 }, - { "TP_EMBED_OP_FIELD4", 0x4f8, 0 }, - { "TP_EMBED_OP_FIELD5", 0x4fc, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_ulp2_rx_regs[] = { - { "ULPRX_CTL", 0x500, 0 }, - { "PCMD1Threshold", 24, 8 }, - { "PCMD0Threshold", 16, 8 }, - { "round_robin", 4, 1 }, - { "RDMA_permissive_mode", 3, 1 }, - { "PagePodME", 2, 1 }, - { "IscsiTagTcb", 1, 1 }, - { "TddpTagTcb", 0, 1 }, - { "ULPRX_INT_ENABLE", 0x504, 0 }, - { "DataSelFrameErr0", 7, 1 }, - { "DataSelFrameErr1", 6, 1 }, - { "PcmdMuxPerr", 5, 1 }, - { "ArbFPerr", 4, 1 }, - { "ArbPF0Perr", 3, 1 }, - { "ArbPF1Perr", 2, 1 }, - { "ParErrPcmd", 1, 1 }, - { "ParErrData", 0, 1 }, - { "ULPRX_INT_CAUSE", 0x508, 0 }, - { "DataSelFrameErr0", 7, 1 }, - { "DataSelFrameErr1", 6, 1 }, - { "PcmdMuxPerr", 5, 1 }, - { "ArbFPerr", 4, 1 }, - { "ArbPF0Perr", 3, 1 }, - { "ArbPF1Perr", 2, 1 }, - { "ParErrPcmd", 1, 1 }, - { "ParErrData", 0, 1 }, - { "ULPRX_ISCSI_LLIMIT", 0x50c, 0 }, - { "IscsiLlimit", 6, 26 }, - { "ULPRX_ISCSI_ULIMIT", 0x510, 0 }, - { "IscsiUlimit", 6, 26 }, - { "ULPRX_ISCSI_TAGMASK", 0x514, 0 }, - { "IscsiTagMask", 6, 26 }, - { "ULPRX_ISCSI_PSZ", 0x518, 0 }, - { "Hpz3", 24, 4 }, - { "Hpz2", 16, 4 }, - { "Hpz1", 8, 4 }, - { "Hpz0", 0, 4 }, - { "ULPRX_TDDP_LLIMIT", 0x51c, 0 }, - { "TddpLlimit", 6, 26 }, - { "ULPRX_TDDP_ULIMIT", 0x520, 0 }, - { "TddpUlimit", 6, 26 }, - { "ULPRX_TDDP_TAGMASK", 0x524, 0 }, - { "TddpTagMask", 6, 26 }, - { "ULPRX_TDDP_PSZ", 0x528, 0 }, - { "Hpz3", 24, 4 }, - { "Hpz2", 16, 4 }, - { "Hpz1", 8, 4 }, - { "Hpz0", 0, 4 }, - { "ULPRX_STAG_LLIMIT", 0x52c, 0 }, - { "ULPRX_STAG_ULIMIT", 0x530, 0 }, - { "ULPRX_RQ_LLIMIT", 0x534, 0 }, - { "ULPRX_RQ_ULIMIT", 0x538, 0 }, - { "ULPRX_PBL_LLIMIT", 0x53c, 0 }, - { "ULPRX_PBL_ULIMIT", 0x540, 0 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_ulp2_tx_regs[] = { - { "ULPTX_CONFIG", 0x580, 0 }, - { "CFG_CQE_SOP_MASK", 1, 1 }, - { "CFG_RR_ARB", 0, 1 }, - { "ULPTX_INT_ENABLE", 0x584, 0 }, - { "cmd_fifo_perr_set1", 7, 1 }, - { "cmd_fifo_perr_set0", 6, 1 }, - { "lso_hdr_sram_perr_set1", 5, 1 }, - { "lso_hdr_sram_perr_set0", 4, 1 }, - { "imm_data_perr_set_ch1", 3, 1 }, - { "imm_data_perr_set_ch0", 2, 1 }, - { "Pbl_bound_err_ch1", 1, 1 }, - { "Pbl_bound_err_ch0", 0, 1 }, - { "ULPTX_INT_CAUSE", 0x588, 0 }, - { "cmd_fifo_perr_set1", 7, 1 }, - { "cmd_fifo_perr_set0", 6, 1 }, - { "lso_hdr_sram_perr_set1", 5, 1 }, - { "lso_hdr_sram_perr_set0", 4, 1 }, - { "imm_data_perr_set_ch1", 3, 1 }, - { "imm_data_perr_set_ch0", 2, 1 }, - { "Pbl_bound_err_ch1", 1, 1 }, - { "Pbl_bound_err_ch0", 0, 1 }, - { "ULPTX_TPT_LLIMIT", 0x58c, 0 }, - { "ULPTX_TPT_ULIMIT", 0x590, 0 }, - { "ULPTX_PBL_LLIMIT", 0x594, 0 }, - { "ULPTX_PBL_ULIMIT", 0x598, 0 }, - { "ULPTX_CPL_ERR_OFFSET", 0x59c, 0 }, - { "ULPTX_CPL_ERR_MASK", 0x5a0, 0 }, - { "ULPTX_CPL_ERR_VALUE", 0x5a4, 0 }, - { "ULPTX_CPL_PACK_SIZE", 0x5a8, 0 }, - { "value", 24, 8 }, - { "Ch1Size2", 24, 8 }, - { "Ch1Size1", 16, 8 }, - { "Ch0Size2", 8, 8 }, - { "Ch0Size1", 0, 8 }, - { "ULPTX_DMA_WEIGHT", 0x5ac, 0 }, - { "D1_WEIGHT", 16, 16 }, - { "D0_WEIGHT", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_pm1_rx_regs[] = { - { "PM1_RX_CFG", 0x5c0, 0 }, - { "PM1_RX_MODE", 0x5c4, 0 }, - { "stat_channel", 1, 1 }, - { "priority_ch", 0, 1 }, - { "PM1_RX_STAT_CONFIG", 0x5c8, 0 }, - { "PM1_RX_STAT_COUNT", 0x5cc, 0 }, - { "PM1_RX_STAT_MSB", 0x5d0, 0 }, - { "PM1_RX_STAT_LSB", 0x5d4, 0 }, - { "PM1_RX_INT_ENABLE", 0x5d8, 0 }, - { "zero_e_cmd_error", 18, 1 }, - { "iespi0_fifo2x_Rx_framing_error", 17, 1 }, - { "iespi1_fifo2x_Rx_framing_error", 16, 1 }, - { "iespi0_Rx_framing_error", 15, 1 }, - { "iespi1_Rx_framing_error", 14, 1 }, - { "iespi0_Tx_framing_error", 13, 1 }, - { "iespi1_Tx_framing_error", 12, 1 }, - { "ocspi0_Rx_framing_error", 11, 1 }, - { "ocspi1_Rx_framing_error", 10, 1 }, - { "ocspi0_Tx_framing_error", 9, 1 }, - { "ocspi1_Tx_framing_error", 8, 1 }, - { "ocspi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "ocspi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "iespi_par_error", 3, 3 }, - { "ocspi_par_error", 0, 3 }, - { "PM1_RX_INT_CAUSE", 0x5dc, 0 }, - { "zero_e_cmd_error", 18, 1 }, - { "iespi0_fifo2x_Rx_framing_error", 17, 1 }, - { "iespi1_fifo2x_Rx_framing_error", 16, 1 }, - { "iespi0_Rx_framing_error", 15, 1 }, - { "iespi1_Rx_framing_error", 14, 1 }, - { "iespi0_Tx_framing_error", 13, 1 }, - { "iespi1_Tx_framing_error", 12, 1 }, - { "ocspi0_Rx_framing_error", 11, 1 }, - { "ocspi1_Rx_framing_error", 10, 1 }, - { "ocspi0_Tx_framing_error", 9, 1 }, - { "ocspi1_Tx_framing_error", 8, 1 }, - { "ocspi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "ocspi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "iespi_par_error", 3, 3 }, - { "ocspi_par_error", 0, 3 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_pm1_tx_regs[] = { - { "PM1_TX_CFG", 0x5e0, 0 }, - { "PM1_TX_MODE", 0x5e4, 0 }, - { "stat_channel", 1, 1 }, - { "priority_ch", 0, 1 }, - { "PM1_TX_STAT_CONFIG", 0x5e8, 0 }, - { "PM1_TX_STAT_COUNT", 0x5ec, 0 }, - { "PM1_TX_STAT_MSB", 0x5f0, 0 }, - { "PM1_TX_STAT_LSB", 0x5f4, 0 }, - { "PM1_TX_INT_ENABLE", 0x5f8, 0 }, - { "zero_c_cmd_error", 18, 1 }, - { "icspi0_fifo2x_Rx_framing_error", 17, 1 }, - { "icspi1_fifo2x_Rx_framing_error", 16, 1 }, - { "icspi0_Rx_framing_error", 15, 1 }, - { "icspi1_Rx_framing_error", 14, 1 }, - { "icspi0_Tx_framing_error", 13, 1 }, - { "icspi1_Tx_framing_error", 12, 1 }, - { "oespi0_Rx_framing_error", 11, 1 }, - { "oespi1_Rx_framing_error", 10, 1 }, - { "oespi0_Tx_framing_error", 9, 1 }, - { "oespi1_Tx_framing_error", 8, 1 }, - { "oespi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "oespi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "icspi_par_error", 3, 3 }, - { "oespi_par_error", 0, 3 }, - { "PM1_TX_INT_CAUSE", 0x5fc, 0 }, - { "zero_c_cmd_error", 18, 1 }, - { "icspi0_fifo2x_Rx_framing_error", 17, 1 }, - { "icspi1_fifo2x_Rx_framing_error", 16, 1 }, - { "icspi0_Rx_framing_error", 15, 1 }, - { "icspi1_Rx_framing_error", 14, 1 }, - { "icspi0_Tx_framing_error", 13, 1 }, - { "icspi1_Tx_framing_error", 12, 1 }, - { "oespi0_Rx_framing_error", 11, 1 }, - { "oespi1_Rx_framing_error", 10, 1 }, - { "oespi0_Tx_framing_error", 9, 1 }, - { "oespi1_Tx_framing_error", 8, 1 }, - { "oespi0_ofifo2x_Tx_framing_error", 7, 1 }, - { "oespi1_ofifo2x_Tx_framing_error", 6, 1 }, - { "icspi_par_error", 3, 3 }, - { "oespi_par_error", 0, 3 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_mps0_regs[] = { - { "MPS_CFG", 0x600, 0 }, - { "EnForcePkt", 11, 1 }, - { "SGETPQid", 8, 3 }, - { "TPRxPortSize", 7, 1 }, - { "TPTxPort1Size", 6, 1 }, - { "TPTxPort0Size", 5, 1 }, - { "TPRxPortEn", 4, 1 }, - { "TPTxPort1En", 3, 1 }, - { "TPTxPort0En", 2, 1 }, - { "Port1Active", 1, 1 }, - { "Port0Active", 0, 1 }, - { "MPS_DRR_CFG1", 0x604, 0 }, - { "RldWtTPD1", 11, 11 }, - { "RldWtTPD0", 0, 11 }, - { "MPS_DRR_CFG2", 0x608, 0 }, - { "RldWtTotal", 0, 12 }, - { "MPS_MCA_STATUS", 0x60c, 0 }, - { "MCAPktCnt", 12, 20 }, - { "MCADepth", 0, 12 }, - { "MPS_TX0_TP_CNT", 0x610, 0 }, - { "TX0TPDisCnt", 24, 8 }, - { "TX0TPCnt", 0, 24 }, - { "MPS_TX1_TP_CNT", 0x614, 0 }, - { "TX1TPDisCnt", 24, 8 }, - { "TX1TPCnt", 0, 24 }, - { "MPS_RX_TP_CNT", 0x618, 0 }, - { "RXTPDisCnt", 24, 8 }, - { "RXTPCnt", 0, 24 }, - { "MPS_INT_ENABLE", 0x61c, 0 }, - { "MCAParErrEnb", 6, 3 }, - { "RXTpParErrEnb", 4, 2 }, - { "TX1TpParErrEnb", 2, 2 }, - { "TX0TpParErrEnb", 0, 2 }, - { "MPS_INT_CAUSE", 0x620, 0 }, - { "MCAParErr", 6, 3 }, - { "RXTpParErr", 4, 2 }, - { "TX1TpParErr", 2, 2 }, - { "TX0TpParErr", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_cpl_switch_regs[] = { - { "CPL_SWITCH_CNTRL", 0x640, 0 }, - { "cpl_pkt_tid", 8, 24 }, - { "cim_to_up_full_size", 4, 1 }, - { "cpu_no_3F_CIM_enable", 3, 1 }, - { "switch_table_enable", 2, 1 }, - { "sge_enable", 1, 1 }, - { "cim_enable", 0, 1 }, - { "CPL_SWITCH_TBL_IDX", 0x644, 0 }, - { "switch_tbl_idx", 0, 4 }, - { "CPL_SWITCH_TBL_DATA", 0x648, 0 }, - { "CPL_SWITCH_ZERO_ERROR", 0x64c, 0 }, - { "zero_cmd", 0, 8 }, - { "CPL_INTR_ENABLE", 0x650, 0 }, - { "cim_op_map_perr", 5, 1 }, - { "cim_ovfl_error", 4, 1 }, - { "tp_framing_error", 3, 1 }, - { "sge_framing_error", 2, 1 }, - { "cim_framing_error", 1, 1 }, - { "zero_switch_error", 0, 1 }, - { "CPL_INTR_CAUSE", 0x654, 0 }, - { "cim_op_map_perr", 5, 1 }, - { "cim_ovfl_error", 4, 1 }, - { "tp_framing_error", 3, 1 }, - { "sge_framing_error", 2, 1 }, - { "cim_framing_error", 1, 1 }, - { "zero_switch_error", 0, 1 }, - { "CPL_MAP_TBL_IDX", 0x658, 0 }, - { "cpl_map_tbl_idx", 0, 8 }, - { "CPL_MAP_TBL_DATA", 0x65c, 0 }, - { "cpl_map_tbl_data", 0, 8 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_smb0_regs[] = { - { "SMB_GLOBAL_TIME_CFG", 0x660, 0 }, - { "LADbgWrPtr", 24, 8 }, - { "LADbgRdPtr", 16, 8 }, - { "LADbgEn", 13, 1 }, - { "MacroCntCfg", 8, 5 }, - { "MicroCntCfg", 0, 8 }, - { "SMB_MST_TIMEOUT_CFG", 0x664, 0 }, - { "DebugSelH", 28, 4 }, - { "DebugSelL", 24, 4 }, - { "MstTimeOutCfg", 0, 24 }, - { "SMB_MST_CTL_CFG", 0x668, 0 }, - { "MstFifoDbg", 31, 1 }, - { "MstFifoDbgClr", 30, 1 }, - { "MstRxByteCfg", 12, 6 }, - { "MstTxByteCfg", 6, 6 }, - { "MstReset", 1, 1 }, - { "MstCtlEn", 0, 1 }, - { "SMB_MST_CTL_STS", 0x66c, 0 }, - { "MstRxByteCnt", 12, 6 }, - { "MstTxByteCnt", 6, 6 }, - { "MstBusySts", 0, 1 }, - { "SMB_MST_TX_FIFO_RDWR", 0x670, 0 }, - { "SMB_MST_RX_FIFO_RDWR", 0x674, 0 }, - { "SMB_SLV_TIMEOUT_CFG", 0x678, 0 }, - { "SlvTimeOutCfg", 0, 24 }, - { "SMB_SLV_CTL_CFG", 0x67c, 0 }, - { "SlvFifoDbg", 31, 1 }, - { "SlvFifoDbgClr", 30, 1 }, - { "SlvAddrCfg", 4, 7 }, - { "SlvAlrtSet", 2, 1 }, - { "SlvReset", 1, 1 }, - { "SlvCtlEn", 0, 1 }, - { "SMB_SLV_CTL_STS", 0x680, 0 }, - { "SlvFifoTxCnt", 12, 6 }, - { "SlvFifoCnt", 6, 6 }, - { "SlvAlrtSts", 2, 1 }, - { "SlvBusySts", 0, 1 }, - { "SMB_SLV_FIFO_RDWR", 0x684, 0 }, - { "SMB_SLV_CMD_FIFO_RDWR", 0x688, 0 }, - { "SMB_INT_ENABLE", 0x68c, 0 }, - { "SlvTimeOutIntEn", 7, 1 }, - { "SlvErrIntEn", 6, 1 }, - { "SlvDoneIntEn", 5, 1 }, - { "SlvRxRdyIntEn", 4, 1 }, - { "MstTimeOutIntEn", 3, 1 }, - { "MstNAckIntEn", 2, 1 }, - { "MstLostArbIntEn", 1, 1 }, - { "MstDoneIntEn", 0, 1 }, - { "SMB_INT_CAUSE", 0x690, 0 }, - { "SlvTimeOutInt", 7, 1 }, - { "SlvErrInt", 6, 1 }, - { "SlvDoneInt", 5, 1 }, - { "SlvRxRdyInt", 4, 1 }, - { "MstTimeOutInt", 3, 1 }, - { "MstNAckInt", 2, 1 }, - { "MstLostArbInt", 1, 1 }, - { "MstDoneInt", 0, 1 }, - { "SMB_DEBUG_DATA", 0x694, 0 }, - { "DebugDataH", 16, 16 }, - { "DebugDataL", 0, 16 }, - { "SMB_DEBUG_LA", 0x69c, 0 }, - { "DebugLAReqAddr", 0, 10 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_i2cm0_regs[] = { - { "I2C_CFG", 0x6a0, 0 }, - { "ClkDiv", 0, 12 }, - { "I2C_DATA", 0x6a4, 0 }, - { "Data", 0, 8 }, - { "I2C_OP", 0x6a8, 0 }, - { "Busy", 31, 1 }, - { "Ack", 30, 1 }, - { "Cont", 1, 1 }, - { "Op", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_mi1_regs[] = { - { "MI1_CFG", 0x6b0, 0 }, - { "ClkDiv", 5, 8 }, - { "St", 3, 2 }, - { "PreEn", 2, 1 }, - { "MDIInv", 1, 1 }, - { "MDIEn", 0, 1 }, - { "MI1_ADDR", 0x6b4, 0 }, - { "PhyAddr", 5, 5 }, - { "RegAddr", 0, 5 }, - { "MI1_DATA", 0x6b8, 0 }, - { "Data", 0, 16 }, - { "MI1_OP", 0x6bc, 0 }, - { "Busy", 31, 1 }, - { "Inc", 2, 1 }, - { "Op", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_jm1_regs[] = { - { "JM_CFG", 0x6c0, 0 }, - { "ClkDiv", 2, 8 }, - { "TRst", 1, 1 }, - { "En", 0, 1 }, - { "JM_MODE", 0x6c4, 0 }, - { "JM_DATA", 0x6c8, 0 }, - { "JM_OP", 0x6cc, 0 }, - { "Busy", 31, 1 }, - { "Cnt", 0, 5 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_sf1_regs[] = { - { "SF_DATA", 0x6d8, 0 }, - { "SF_OP", 0x6dc, 0 }, - { "Busy", 31, 1 }, - { "Cont", 3, 1 }, - { "ByteCnt", 1, 2 }, - { "Op", 0, 1 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_pl3_regs[] = { - { "PL_INT_ENABLE0", 0x6e0, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_CAUSE0", 0x6e4, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_ENABLE1", 0x6e8, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_INT_CAUSE1", 0x6ec, 0 }, - { "SW", 25, 1 }, - { "EXT", 24, 1 }, - { "T3DBG", 23, 1 }, - { "XGMAC0_1", 20, 1 }, - { "XGMAC0_0", 19, 1 }, - { "MC5A", 18, 1 }, - { "SF1", 17, 1 }, - { "SMB0", 15, 1 }, - { "I2CM0", 14, 1 }, - { "MI1", 13, 1 }, - { "CPL_SWITCH", 12, 1 }, - { "MPS0", 11, 1 }, - { "PM1_TX", 10, 1 }, - { "PM1_RX", 9, 1 }, - { "ULP2_TX", 8, 1 }, - { "ULP2_RX", 7, 1 }, - { "TP1", 6, 1 }, - { "CIM", 5, 1 }, - { "MC7_CM", 4, 1 }, - { "MC7_PMTX", 3, 1 }, - { "MC7_PMRX", 2, 1 }, - { "PCIM0", 1, 1 }, - { "SGE3", 0, 1 }, - { "PL_RST", 0x6f0, 0 }, - { "FatalPerrEn", 4, 1 }, - { "SWInt1", 3, 1 }, - { "SWInt0", 2, 1 }, - { "CRstWrm", 1, 1 }, - { "CRstWrmMode", 0, 1 }, - { "PL_REV", 0x6f4, 0 }, - { "Rev", 0, 4 }, - { "PL_CLI", 0x6f8, 0 }, - { "PL_LCK", 0x6fc, 0 }, - { "Lck", 0, 2 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_mc5a_regs[] = { - { "MC5_BUF_CONFIG", 0x700, 0 }, - { "term300_240", 31, 1 }, - { "term150", 30, 1 }, - { "term60", 29, 1 }, - { "gddriii", 28, 1 }, - { "gddrii", 27, 1 }, - { "gddri", 26, 1 }, - { "read", 25, 1 }, - { "imp_set_update", 24, 1 }, - { "cal_update", 23, 1 }, - { "cal_busy", 22, 1 }, - { "cal_error", 21, 1 }, - { "sgl_cal_en", 20, 1 }, - { "imp_upd_mode", 19, 1 }, - { "imp_sel", 18, 1 }, - { "man_pu", 15, 3 }, - { "man_pd", 12, 3 }, - { "cal_pu", 9, 3 }, - { "cal_pd", 6, 3 }, - { "set_pu", 3, 3 }, - { "set_pd", 0, 3 }, - { "MC5_DB_CONFIG", 0x704, 0 }, - { "TMCfgWrLock", 31, 1 }, - { "TMTypeHi", 30, 1 }, - { "TMPartSize", 28, 2 }, - { "TMType", 26, 2 }, - { "TMPartCount", 24, 2 }, - { "nLIP", 18, 6 }, - { "COMPEN", 17, 1 }, - { "BUILD", 16, 1 }, - { "FilterEn", 11, 1 }, - { "CLIPUpdate", 10, 1 }, - { "TM_IO_PDOWN", 9, 1 }, - { "SYNMode", 7, 2 }, - { "PRTYEN", 6, 1 }, - { "MBUSEN", 5, 1 }, - { "DBGIEN", 4, 1 }, - { "TcmCfgOvr", 3, 1 }, - { "TMRDY", 2, 1 }, - { "TMRST", 1, 1 }, - { "TMMode", 0, 1 }, - { "MC5_MISC", 0x708, 0 }, - { "LIP_Cmp_Unavailable", 0, 4 }, - { "MC5_DB_ROUTING_TABLE_INDEX", 0x70c, 0 }, - { "RTINDX", 0, 22 }, - { "MC5_DB_FILTER_TABLE", 0x710, 0 }, - { "SRINDX", 0, 22 }, - { "MC5_DB_SERVER_INDEX", 0x714, 0 }, - { "SRINDX", 0, 22 }, - { "MC5_DB_LIP_RAM_ADDR", 0x718, 0 }, - { "RAMWR", 8, 1 }, - { "RAMADDR", 0, 6 }, - { "MC5_DB_LIP_RAM_DATA", 0x71c, 0 }, - { "MC5_DB_RSP_LATENCY", 0x720, 0 }, - { "RDLAT", 16, 5 }, - { "LRNLAT", 8, 5 }, - { "SRCHLAT", 0, 5 }, - { "MC5_DB_PARITY_LATENCY", 0x724, 0 }, - { "PARLAT", 0, 4 }, - { "MC5_DB_WR_LRN_VERIFY", 0x728, 0 }, - { "VWVEREN", 2, 1 }, - { "LRNVEREN", 1, 1 }, - { "POVEREN", 0, 1 }, - { "MC5_DB_PART_ID_INDEX", 0x72c, 0 }, - { "IDINDEX", 0, 4 }, - { "MC5_DB_RESET_MAX", 0x730, 0 }, - { "RSTMAX", 0, 4 }, - { "MC5_DB_ACT_CNT", 0x734, 0 }, - { "ACTCNT", 0, 20 }, - { "MC5_DB_CLIP_MAP", 0x738, 0 }, - { "CLIPMapOp", 31, 1 }, - { "CLIPMapVal", 16, 6 }, - { "CLIPMapAddr", 0, 6 }, - { "MC5_DB_SIZE", 0x73c, 0 }, - { "MC5_DB_INT_ENABLE", 0x740, 0 }, - { "MsgSel", 28, 4 }, - { "DelActEmpty", 18, 1 }, - { "DispQParErr", 17, 1 }, - { "ReqQParErr", 16, 1 }, - { "UnknownCmd", 15, 1 }, - { "SYNCookieOff", 11, 1 }, - { "SYNCookieBad", 10, 1 }, - { "SYNCookie", 9, 1 }, - { "NFASrchFail", 8, 1 }, - { "ActRgnFull", 7, 1 }, - { "ParityErr", 6, 1 }, - { "LIPMiss", 5, 1 }, - { "LIP0", 4, 1 }, - { "Miss", 3, 1 }, - { "RoutingHit", 2, 1 }, - { "ActiveHit", 1, 1 }, - { "ActiveOutHit", 0, 1 }, - { "MC5_DB_INT_CAUSE", 0x744, 0 }, - { "DelActEmpty", 18, 1 }, - { "DispQParErr", 17, 1 }, - { "ReqQParErr", 16, 1 }, - { "UnknownCmd", 15, 1 }, - { "SYNCookieOff", 11, 1 }, - { "SYNCookieBad", 10, 1 }, - { "SYNCookie", 9, 1 }, - { "NFASrchFail", 8, 1 }, - { "ActRgnFull", 7, 1 }, - { "ParityErr", 6, 1 }, - { "LIPMiss", 5, 1 }, - { "LIP0", 4, 1 }, - { "Miss", 3, 1 }, - { "RoutingHit", 2, 1 }, - { "ActiveHit", 1, 1 }, - { "ActiveOutHit", 0, 1 }, - { "MC5_DB_INT_TID", 0x748, 0 }, - { "INTTID", 0, 20 }, - { "MC5_DB_INT_PTID", 0x74c, 0 }, - { "INTPTID", 0, 20 }, - { "MC5_DB_DBGI_CONFIG", 0x774, 0 }, - { "WRReqSize", 22, 10 }, - { "SADRSel", 4, 1 }, - { "CMDMode", 0, 3 }, - { "MC5_DB_DBGI_REQ_CMD", 0x778, 0 }, - { "MBusCmd", 0, 4 }, - { "IDTCmdHi", 11, 3 }, - { "IDTCmdLo", 0, 4 }, - { "IDTCmd", 0, 20 }, - { "LCMDB", 16, 11 }, - { "LCMDA", 0, 11 }, - { "MC5_DB_DBGI_REQ_ADDR0", 0x77c, 0 }, - { "MC5_DB_DBGI_REQ_ADDR1", 0x780, 0 }, - { "MC5_DB_DBGI_REQ_ADDR2", 0x784, 0 }, - { "DBGIReqAdrHi", 0, 8 }, - { "MC5_DB_DBGI_REQ_DATA0", 0x788, 0 }, - { "MC5_DB_DBGI_REQ_DATA1", 0x78c, 0 }, - { "MC5_DB_DBGI_REQ_DATA2", 0x790, 0 }, - { "MC5_DB_DBGI_REQ_DATA3", 0x794, 0 }, - { "MC5_DB_DBGI_REQ_DATA4", 0x798, 0 }, - { "DBGIReqData4", 0, 16 }, - { "MC5_DB_DBGI_REQ_MASK0", 0x79c, 0 }, - { "MC5_DB_DBGI_REQ_MASK1", 0x7a0, 0 }, - { "MC5_DB_DBGI_REQ_MASK2", 0x7a4, 0 }, - { "MC5_DB_DBGI_REQ_MASK3", 0x7a8, 0 }, - { "MC5_DB_DBGI_REQ_MASK4", 0x7ac, 0 }, - { "DBGIReqMsk4", 0, 16 }, - { "MC5_DB_DBGI_RSP_STATUS", 0x7b0, 0 }, - { "DBGIRspMsg", 8, 4 }, - { "DBGIRspMsgVld", 2, 1 }, - { "DBGIRspHit", 1, 1 }, - { "DBGIRspValid", 0, 1 }, - { "MC5_DB_DBGI_RSP_DATA0", 0x7b4, 0 }, - { "MC5_DB_DBGI_RSP_DATA1", 0x7b8, 0 }, - { "MC5_DB_DBGI_RSP_DATA2", 0x7bc, 0 }, - { "MC5_DB_DBGI_RSP_DATA3", 0x7c0, 0 }, - { "MC5_DB_DBGI_RSP_DATA4", 0x7c4, 0 }, - { "DBGIRspData3", 0, 16 }, - { "MC5_DB_DBGI_RSP_LAST_CMD", 0x7c8, 0 }, - { "LastCmdB", 16, 11 }, - { "LastCmdA", 0, 11 }, - { "MC5_DB_POPEN_DATA_WR_CMD", 0x7cc, 0 }, - { "PO_DWR", 0, 20 }, - { "MC5_DB_POPEN_MASK_WR_CMD", 0x7d0, 0 }, - { "PO_MWR", 0, 20 }, - { "MC5_DB_AOPEN_SRCH_CMD", 0x7d4, 0 }, - { "AO_SRCH", 0, 20 }, - { "MC5_DB_AOPEN_LRN_CMD", 0x7d8, 0 }, - { "AO_LRN", 0, 20 }, - { "MC5_DB_SYN_SRCH_CMD", 0x7dc, 0 }, - { "SYN_SRCH", 0, 20 }, - { "MC5_DB_SYN_LRN_CMD", 0x7e0, 0 }, - { "SYN_LRN", 0, 20 }, - { "MC5_DB_ACK_SRCH_CMD", 0x7e4, 0 }, - { "ACK_SRCH", 0, 20 }, - { "MC5_DB_ACK_LRN_CMD", 0x7e8, 0 }, - { "ACK_LRN", 0, 20 }, - { "MC5_DB_ILOOKUP_CMD", 0x7ec, 0 }, - { "I_SRCH", 0, 20 }, - { "MC5_DB_ELOOKUP_CMD", 0x7f0, 0 }, - { "E_SRCH", 0, 20 }, - { "MC5_DB_DATA_WRITE_CMD", 0x7f4, 0 }, - { "Write", 0, 20 }, - { "MC5_DB_DATA_READ_CMD", 0x7f8, 0 }, - { "ReadCmd", 0, 20 }, - { "MC5_DB_MASK_WRITE_CMD", 0x7fc, 0 }, - { "MaskWr", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_xgmac0_0_regs[] = { - { "XGM_TX_CTRL", 0x800, 0 }, - { "SendPause", 2, 1 }, - { "SendZeroPause", 1, 1 }, - { "TxEn", 0, 1 }, - { "XGM_TX_CFG", 0x804, 0 }, - { "CfgClkSpeed", 2, 3 }, - { "StretchMode", 1, 1 }, - { "TxPauseEn", 0, 1 }, - { "XGM_TX_PAUSE_QUANTA", 0x808, 0 }, - { "TxPauseQuanta", 0, 16 }, - { "XGM_RX_CTRL", 0x80c, 0 }, - { "RxEn", 0, 1 }, - { "XGM_RX_CFG", 0x810, 0 }, - { "Con802_3Preamble", 12, 1 }, - { "EnNon802_3Preamble", 11, 1 }, - { "CopyPreamble", 10, 1 }, - { "DisPauseFrames", 9, 1 }, - { "En1536BFrames", 8, 1 }, - { "EnJumbo", 7, 1 }, - { "RmFCS", 6, 1 }, - { "DisNonVlan", 5, 1 }, - { "EnExtMatch", 4, 1 }, - { "EnHashUcast", 3, 1 }, - { "EnHashMcast", 2, 1 }, - { "DisBCast", 1, 1 }, - { "CopyAllFrames", 0, 1 }, - { "XGM_RX_HASH_LOW", 0x814, 0 }, - { "XGM_RX_HASH_HIGH", 0x818, 0 }, - { "XGM_RX_EXACT_MATCH_LOW_1", 0x81c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_1", 0x820, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_2", 0x824, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_2", 0x828, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_3", 0x82c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_3", 0x830, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_4", 0x834, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_4", 0x838, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_5", 0x83c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_5", 0x840, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_6", 0x844, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_6", 0x848, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_7", 0x84c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_7", 0x850, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_8", 0x854, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_8", 0x858, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_TYPE_MATCH_1", 0x85c, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_2", 0x860, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_3", 0x864, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_4", 0x868, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_INT_STATUS", 0x86c, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_MASK", 0x870, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_ENABLE", 0x874, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_DISABLE", 0x878, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_TX_PAUSE_TIMER", 0x87c, 0 }, - { "CurPauseTimer", 0, 16 }, - { "XGM_STAT_CTRL", 0x880, 0 }, - { "ReadSnpShot", 4, 1 }, - { "TakeSnpShot", 3, 1 }, - { "ClrStats", 2, 1 }, - { "IncrStats", 1, 1 }, - { "EnTestModeWr", 0, 1 }, - { "XGM_RXFIFO_CFG", 0x884, 0 }, - { "RxFIFO_empty", 31, 1 }, - { "RxFIFO_full", 30, 1 }, - { "RxFIFOPauseHWM", 17, 12 }, - { "RxFIFOPauseLWM", 5, 12 }, - { "ForcedPause", 4, 1 }, - { "ExternLoopback", 3, 1 }, - { "RxByteSwap", 2, 1 }, - { "RxStrFrwrd", 1, 1 }, - { "DisErrFrames", 0, 1 }, - { "XGM_TXFIFO_CFG", 0x888, 0 }, - { "TxFIFO_empty", 31, 1 }, - { "TxFIFO_full", 30, 1 }, - { "UnderunFix", 22, 1 }, - { "EnDropPkt", 21, 1 }, - { "TxIPG", 13, 8 }, - { "TxFIFOThresh", 4, 9 }, - { "InternLoopback", 3, 1 }, - { "TxByteSwap", 2, 1 }, - { "DisCRC", 1, 1 }, - { "DisPreAmble", 0, 1 }, - { "XGM_SLOW_TIMER", 0x88c, 0 }, - { "PauseSlowTimerEn", 31, 1 }, - { "PauseSlowTimer", 0, 20 }, - { "XGM_PAUSE_TIMER", 0x890, 0 }, - { "PauseTimer", 0, 20 }, - { "XGM_XAUI_PCS_TEST", 0x894, 0 }, - { "TestPattern", 1, 2 }, - { "EnTest", 0, 1 }, - { "XGM_RGMII_CTRL", 0x898, 0 }, - { "PhAlignFIFOThresh", 1, 2 }, - { "TxClk90Shift", 0, 1 }, - { "XGM_RGMII_IMP", 0x89c, 0 }, - { "CalReset", 8, 1 }, - { "CalUpdate", 7, 1 }, - { "ImpSetUpdate", 6, 1 }, - { "RGMIIImpPD", 3, 3 }, - { "RGMIIImpPU", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE", 0x8a8, 0 }, - { "RxMaxFramerSize", 17, 14 }, - { "RxEnErrorGather", 16, 1 }, - { "RxEnSingleFlit", 15, 1 }, - { "RxEnFramer", 14, 1 }, - { "RxMaxPktSize", 0, 14 }, - { "XGM_RESET_CTRL", 0x8ac, 0 }, - { "XGMAC_STOP_EN", 4, 1 }, - { "XG2G_Reset_", 3, 1 }, - { "RGMII_Reset_", 2, 1 }, - { "PCS_Reset_", 1, 1 }, - { "MAC_Reset_", 0, 1 }, - { "XGM_XAUI1G_CTRL", 0x8b0, 0 }, - { "XAUI1GLinkId", 0, 2 }, - { "XGM_SERDES_LANE_CTRL", 0x8b4, 0 }, - { "LaneReversal", 8, 1 }, - { "TxPolarity", 4, 4 }, - { "RxPolarity", 0, 4 }, - { "XGM_PORT_CFG", 0x8b8, 0 }, - { "SafeSpeedChange", 4, 1 }, - { "ClkDivReset_", 3, 1 }, - { "PortSpeed", 1, 2 }, - { "EnRGMII", 0, 1 }, - { "XGM_EPIO_DATA0", 0x8c0, 0 }, - { "XGM_EPIO_DATA1", 0x8c4, 0 }, - { "XGM_EPIO_DATA2", 0x8c8, 0 }, - { "XGM_EPIO_DATA3", 0x8cc, 0 }, - { "XGM_EPIO_OP", 0x8d0, 0 }, - { "PIO_Ready", 31, 1 }, - { "PIO_WrRd", 24, 1 }, - { "PIO_Address", 0, 8 }, - { "XGM_INT_ENABLE", 0x8d4, 0 }, - { "XAUIPCSDECErr", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_INT_CAUSE", 0x8d8, 0 }, - { "XAUIPCSDECErr", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_XAUI_ACT_CTRL", 0x8dc, 0 }, - { "TxEn", 1, 1 }, - { "RxEn", 0, 1 }, - { "XGM_SERDES_CTRL0", 0x8e0, 0 }, - { "IntSerLPBK3", 27, 1 }, - { "IntSerLPBK2", 26, 1 }, - { "IntSerLPBK1", 25, 1 }, - { "IntSerLPBK0", 24, 1 }, - { "Reset3", 23, 1 }, - { "Reset2", 22, 1 }, - { "Reset1", 21, 1 }, - { "Reset0", 20, 1 }, - { "Pwrdn3", 19, 1 }, - { "Pwrdn2", 18, 1 }, - { "Pwrdn1", 17, 1 }, - { "Pwrdn0", 16, 1 }, - { "ResetPLL23", 15, 1 }, - { "ResetPLL01", 14, 1 }, - { "PW23", 12, 2 }, - { "PW01", 10, 2 }, - { "Deq", 6, 4 }, - { "Dtx", 2, 4 }, - { "LoDrv", 1, 1 }, - { "HiDrv", 0, 1 }, - { "XGM_SERDES_CTRL1", 0x8e4, 0 }, - { "FmOffset3", 19, 5 }, - { "FmOffsetEn3", 18, 1 }, - { "FmOffset2", 13, 5 }, - { "FmOffsetEn2", 12, 1 }, - { "FmOffset1", 7, 5 }, - { "FmOffsetEn1", 6, 1 }, - { "FmOffset0", 1, 5 }, - { "FmOffsetEn0", 0, 1 }, - { "XGM_SERDES_CTRL2", 0x8e8, 0 }, - { "DnIn3", 11, 1 }, - { "UpIn3", 10, 1 }, - { "RxSlave3", 9, 1 }, - { "DnIn2", 8, 1 }, - { "UpIn2", 7, 1 }, - { "RxSlave2", 6, 1 }, - { "DnIn1", 5, 1 }, - { "UpIn1", 4, 1 }, - { "RxSlave1", 3, 1 }, - { "DnIn0", 2, 1 }, - { "UpIn0", 1, 1 }, - { "RxSlave0", 0, 1 }, - { "XGM_SERDES_CTRL3", 0x8ec, 0 }, - { "ExtBISTChkErrClr3", 31, 1 }, - { "ExtBISTChkEn3", 30, 1 }, - { "ExtBISTGenEn3", 29, 1 }, - { "ExtBISTPat3", 26, 3 }, - { "ExtParReset3", 25, 1 }, - { "ExtParLPBK3", 24, 1 }, - { "ExtBISTChkErrClr2", 23, 1 }, - { "ExtBISTChkEn2", 22, 1 }, - { "ExtBISTGenEn2", 21, 1 }, - { "ExtBISTPat2", 18, 3 }, - { "ExtParReset2", 17, 1 }, - { "ExtParLPBK2", 16, 1 }, - { "ExtBISTChkErrClr1", 15, 1 }, - { "ExtBISTChkEn1", 14, 1 }, - { "ExtBISTGenEn1", 13, 1 }, - { "ExtBISTPat1", 10, 3 }, - { "ExtParReset1", 9, 1 }, - { "ExtParLPBK1", 8, 1 }, - { "ExtBISTChkErrClr0", 7, 1 }, - { "ExtBISTChkEn0", 6, 1 }, - { "ExtBISTGenEn0", 5, 1 }, - { "ExtBISTPat0", 2, 3 }, - { "ExtParReset0", 1, 1 }, - { "ExtParLPBK0", 0, 1 }, - { "XGM_SERDES_STAT0", 0x8f0, 0 }, - { "ExtBISTChkErrCnt0", 4, 24 }, - { "ExtBISTChkFmd0", 3, 1 }, - { "LowSigForceEn0", 2, 1 }, - { "LowSigForceValue0", 1, 1 }, - { "LowSig0", 0, 1 }, - { "XGM_SERDES_STAT1", 0x8f4, 0 }, - { "ExtBISTChkErrCnt1", 4, 24 }, - { "ExtBISTChkFmd1", 3, 1 }, - { "LowSigForceEn1", 2, 1 }, - { "LowSigForceValue1", 1, 1 }, - { "LowSig1", 0, 1 }, - { "XGM_SERDES_STAT2", 0x8f8, 0 }, - { "ExtBISTChkErrCnt2", 4, 24 }, - { "ExtBISTChkFmd2", 3, 1 }, - { "LowSigForceEn2", 2, 1 }, - { "LowSigForceValue2", 1, 1 }, - { "LowSig2", 0, 1 }, - { "XGM_SERDES_STAT3", 0x8fc, 0 }, - { "ExtBISTChkErrCnt3", 4, 24 }, - { "ExtBISTChkFmd3", 3, 1 }, - { "LowSigForceEn3", 2, 1 }, - { "LowSigForceValue3", 1, 1 }, - { "LowSig3", 0, 1 }, - { "XGM_STAT_TX_BYTE_LOW", 0x900, 0 }, - { "XGM_STAT_TX_BYTE_HIGH", 0x904, 0 }, - { "TxBytes_high", 0, 13 }, - { "XGM_STAT_TX_FRAME_LOW", 0x908, 0 }, - { "XGM_STAT_TX_FRAME_HIGH", 0x90c, 0 }, - { "TxFrames_high", 0, 4 }, - { "XGM_STAT_TX_BCAST", 0x910, 0 }, - { "XGM_STAT_TX_MCAST", 0x914, 0 }, - { "XGM_STAT_TX_PAUSE", 0x918, 0 }, - { "XGM_STAT_TX_64B_FRAMES", 0x91c, 0 }, - { "XGM_STAT_TX_65_127B_FRAMES", 0x920, 0 }, - { "XGM_STAT_TX_128_255B_FRAMES", 0x924, 0 }, - { "XGM_STAT_TX_256_511B_FRAMES", 0x928, 0 }, - { "XGM_STAT_TX_512_1023B_FRAMES", 0x92c, 0 }, - { "XGM_STAT_TX_1024_1518B_FRAMES", 0x930, 0 }, - { "XGM_STAT_TX_1519_MAXB_FRAMES", 0x934, 0 }, - { "XGM_STAT_TX_ERR_FRAMES", 0x938, 0 }, - { "XGM_STAT_RX_BYTES_LOW", 0x93c, 0 }, - { "XGM_STAT_RX_BYTES_HIGH", 0x940, 0 }, - { "RxBytes_high", 0, 13 }, - { "XGM_STAT_RX_FRAMES_LOW", 0x944, 0 }, - { "XGM_STAT_RX_FRAMES_HIGH", 0x948, 0 }, - { "RxFrames_high", 0, 4 }, - { "XGM_STAT_RX_BCAST_FRAMES", 0x94c, 0 }, - { "XGM_STAT_RX_MCAST_FRAMES", 0x950, 0 }, - { "XGM_STAT_RX_PAUSE_FRAMES", 0x954, 0 }, - { "RxPauseFrames", 0, 16 }, - { "XGM_STAT_RX_64B_FRAMES", 0x958, 0 }, - { "XGM_STAT_RX_65_127B_FRAMES", 0x95c, 0 }, - { "XGM_STAT_RX_128_255B_FRAMES", 0x960, 0 }, - { "XGM_STAT_RX_256_511B_FRAMES", 0x964, 0 }, - { "XGM_STAT_RX_512_1023B_FRAMES", 0x968, 0 }, - { "XGM_STAT_RX_1024_1518B_FRAMES", 0x96c, 0 }, - { "XGM_STAT_RX_1519_MAXB_FRAMES", 0x970, 0 }, - { "XGM_STAT_RX_SHORT_FRAMES", 0x974, 0 }, - { "RxShortFrames", 0, 16 }, - { "XGM_STAT_RX_OVERSIZE_FRAMES", 0x978, 0 }, - { "RxOversizeFrames", 0, 16 }, - { "XGM_STAT_RX_JABBER_FRAMES", 0x97c, 0 }, - { "RxJabberFrames", 0, 16 }, - { "XGM_STAT_RX_CRC_ERR_FRAMES", 0x980, 0 }, - { "RxCRCErrFrames", 0, 16 }, - { "XGM_STAT_RX_LENGTH_ERR_FRAMES", 0x984, 0 }, - { "RxLengthErrFrames", 0, 16 }, - { "XGM_STAT_RX_SYM_CODE_ERR_FRAMES", 0x988, 0 }, - { "RxSymCodeErrFrames", 0, 16 }, - { "XGM_XAUI_PCS_ERR", 0x998, 0 }, - { "PCS_SyncStatus", 5, 4 }, - { "PCS_CTCFIFOErr", 1, 4 }, - { "PCS_NotAligned", 0, 1 }, - { "XGM_RGMII_STATUS", 0x99c, 0 }, - { "GMIIDuplex", 3, 1 }, - { "GMIISpeed", 1, 2 }, - { "GMIILinkStatus", 0, 1 }, - { "XGM_WOL_STATUS", 0x9a0, 0 }, - { "PatDetected", 31, 1 }, - { "MatchedFilter", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE_ERR_CNT", 0x9a4, 0 }, - { "XGM_TX_SPI4_SOP_EOP_CNT", 0x9a8, 0 }, - { "TxSPI4SopCnt", 16, 16 }, - { "TxSPI4EopCnt", 0, 16 }, - { "XGM_RX_SPI4_SOP_EOP_CNT", 0x9ac, 0 }, - { "RxSPI4SopCnt", 16, 16 }, - { "RxSPI4EopCnt", 0, 16 }, - { NULL, 0, 0 } -}; - -struct reg_info t3c_xgmac0_1_regs[] = { - { "XGM_TX_CTRL", 0xa00, 0 }, - { "SendPause", 2, 1 }, - { "SendZeroPause", 1, 1 }, - { "TxEn", 0, 1 }, - { "XGM_TX_CFG", 0xa04, 0 }, - { "CfgClkSpeed", 2, 3 }, - { "StretchMode", 1, 1 }, - { "TxPauseEn", 0, 1 }, - { "XGM_TX_PAUSE_QUANTA", 0xa08, 0 }, - { "TxPauseQuanta", 0, 16 }, - { "XGM_RX_CTRL", 0xa0c, 0 }, - { "RxEn", 0, 1 }, - { "XGM_RX_CFG", 0xa10, 0 }, - { "Con802_3Preamble", 12, 1 }, - { "EnNon802_3Preamble", 11, 1 }, - { "CopyPreamble", 10, 1 }, - { "DisPauseFrames", 9, 1 }, - { "En1536BFrames", 8, 1 }, - { "EnJumbo", 7, 1 }, - { "RmFCS", 6, 1 }, - { "DisNonVlan", 5, 1 }, - { "EnExtMatch", 4, 1 }, - { "EnHashUcast", 3, 1 }, - { "EnHashMcast", 2, 1 }, - { "DisBCast", 1, 1 }, - { "CopyAllFrames", 0, 1 }, - { "XGM_RX_HASH_LOW", 0xa14, 0 }, - { "XGM_RX_HASH_HIGH", 0xa18, 0 }, - { "XGM_RX_EXACT_MATCH_LOW_1", 0xa1c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_1", 0xa20, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_2", 0xa24, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_2", 0xa28, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_3", 0xa2c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_3", 0xa30, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_4", 0xa34, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_4", 0xa38, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_5", 0xa3c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_5", 0xa40, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_6", 0xa44, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_6", 0xa48, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_7", 0xa4c, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_7", 0xa50, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_EXACT_MATCH_LOW_8", 0xa54, 0 }, - { "XGM_RX_EXACT_MATCH_HIGH_8", 0xa58, 0 }, - { "address_high", 0, 16 }, - { "XGM_RX_TYPE_MATCH_1", 0xa5c, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_2", 0xa60, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_3", 0xa64, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_RX_TYPE_MATCH_4", 0xa68, 0 }, - { "EnTypeMatch", 31, 1 }, - { "type", 0, 16 }, - { "XGM_INT_STATUS", 0xa6c, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_MASK", 0xa70, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_ENABLE", 0xa74, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_XGM_INT_DISABLE", 0xa78, 0 }, - { "XGMIIExtInt", 10, 1 }, - { "LinkFaultChange", 9, 1 }, - { "PhyFrameComplete", 8, 1 }, - { "PauseFrameTxmt", 7, 1 }, - { "PauseCntrTimeOut", 6, 1 }, - { "Non0PauseRcvd", 5, 1 }, - { "StatOFlow", 4, 1 }, - { "TxErrFIFO", 3, 1 }, - { "TxUFlow", 2, 1 }, - { "FrameTxmt", 1, 1 }, - { "FrameRcvd", 0, 1 }, - { "XGM_TX_PAUSE_TIMER", 0xa7c, 0 }, - { "CurPauseTimer", 0, 16 }, - { "XGM_STAT_CTRL", 0xa80, 0 }, - { "ReadSnpShot", 4, 1 }, - { "TakeSnpShot", 3, 1 }, - { "ClrStats", 2, 1 }, - { "IncrStats", 1, 1 }, - { "EnTestModeWr", 0, 1 }, - { "XGM_RXFIFO_CFG", 0xa84, 0 }, - { "RxFIFO_empty", 31, 1 }, - { "RxFIFO_full", 30, 1 }, - { "RxFIFOPauseHWM", 17, 12 }, - { "RxFIFOPauseLWM", 5, 12 }, - { "ForcedPause", 4, 1 }, - { "ExternLoopback", 3, 1 }, - { "RxByteSwap", 2, 1 }, - { "RxStrFrwrd", 1, 1 }, - { "DisErrFrames", 0, 1 }, - { "XGM_TXFIFO_CFG", 0xa88, 0 }, - { "TxFIFO_empty", 31, 1 }, - { "TxFIFO_full", 30, 1 }, - { "UnderunFix", 22, 1 }, - { "EnDropPkt", 21, 1 }, - { "TxIPG", 13, 8 }, - { "TxFIFOThresh", 4, 9 }, - { "InternLoopback", 3, 1 }, - { "TxByteSwap", 2, 1 }, - { "DisCRC", 1, 1 }, - { "DisPreAmble", 0, 1 }, - { "XGM_SLOW_TIMER", 0xa8c, 0 }, - { "PauseSlowTimerEn", 31, 1 }, - { "PauseSlowTimer", 0, 20 }, - { "XGM_PAUSE_TIMER", 0xa90, 0 }, - { "PauseTimer", 0, 20 }, - { "XGM_XAUI_PCS_TEST", 0xa94, 0 }, - { "TestPattern", 1, 2 }, - { "EnTest", 0, 1 }, - { "XGM_RGMII_CTRL", 0xa98, 0 }, - { "PhAlignFIFOThresh", 1, 2 }, - { "TxClk90Shift", 0, 1 }, - { "XGM_RGMII_IMP", 0xa9c, 0 }, - { "CalReset", 8, 1 }, - { "CalUpdate", 7, 1 }, - { "ImpSetUpdate", 6, 1 }, - { "RGMIIImpPD", 3, 3 }, - { "RGMIIImpPU", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE", 0xaa8, 0 }, - { "RxMaxFramerSize", 17, 14 }, - { "RxEnErrorGather", 16, 1 }, - { "RxEnSingleFlit", 15, 1 }, - { "RxEnFramer", 14, 1 }, - { "RxMaxPktSize", 0, 14 }, - { "XGM_RESET_CTRL", 0xaac, 0 }, - { "XGMAC_STOP_EN", 4, 1 }, - { "XG2G_Reset_", 3, 1 }, - { "RGMII_Reset_", 2, 1 }, - { "PCS_Reset_", 1, 1 }, - { "MAC_Reset_", 0, 1 }, - { "XGM_XAUI1G_CTRL", 0xab0, 0 }, - { "XAUI1GLinkId", 0, 2 }, - { "XGM_SERDES_LANE_CTRL", 0xab4, 0 }, - { "LaneReversal", 8, 1 }, - { "TxPolarity", 4, 4 }, - { "RxPolarity", 0, 4 }, - { "XGM_PORT_CFG", 0xab8, 0 }, - { "SafeSpeedChange", 4, 1 }, - { "ClkDivReset_", 3, 1 }, - { "PortSpeed", 1, 2 }, - { "EnRGMII", 0, 1 }, - { "XGM_EPIO_DATA0", 0xac0, 0 }, - { "XGM_EPIO_DATA1", 0xac4, 0 }, - { "XGM_EPIO_DATA2", 0xac8, 0 }, - { "XGM_EPIO_DATA3", 0xacc, 0 }, - { "XGM_EPIO_OP", 0xad0, 0 }, - { "PIO_Ready", 31, 1 }, - { "PIO_WrRd", 24, 1 }, - { "PIO_Address", 0, 8 }, - { "XGM_INT_ENABLE", 0xad4, 0 }, - { "XAUIPCSDECErr", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_INT_CAUSE", 0xad8, 0 }, - { "XAUIPCSDECErr", 24, 1 }, - { "RGMIIRxFIFOOverflow", 23, 1 }, - { "RGMIIRxFIFOUnderflow", 22, 1 }, - { "RxPktSizeError", 21, 1 }, - { "WOLPatDetected", 20, 1 }, - { "TXFIFO_prty_err", 17, 3 }, - { "RXFIFO_prty_err", 14, 3 }, - { "TXFIFO_underrun", 13, 1 }, - { "RXFIFO_overflow", 12, 1 }, - { "SERDESBISTErr", 8, 4 }, - { "SERDESLowSigChange", 4, 4 }, - { "XAUIPCSCTCErr", 3, 1 }, - { "XAUIPCSAlignChange", 2, 1 }, - { "RGMIILinkStsChange", 1, 1 }, - { "xgm_int", 0, 1 }, - { "XGM_XAUI_ACT_CTRL", 0xadc, 0 }, - { "TxEn", 1, 1 }, - { "RxEn", 0, 1 }, - { "XGM_SERDES_CTRL0", 0xae0, 0 }, - { "IntSerLPBK3", 27, 1 }, - { "IntSerLPBK2", 26, 1 }, - { "IntSerLPBK1", 25, 1 }, - { "IntSerLPBK0", 24, 1 }, - { "Reset3", 23, 1 }, - { "Reset2", 22, 1 }, - { "Reset1", 21, 1 }, - { "Reset0", 20, 1 }, - { "Pwrdn3", 19, 1 }, - { "Pwrdn2", 18, 1 }, - { "Pwrdn1", 17, 1 }, - { "Pwrdn0", 16, 1 }, - { "ResetPLL23", 15, 1 }, - { "ResetPLL01", 14, 1 }, - { "PW23", 12, 2 }, - { "PW01", 10, 2 }, - { "Deq", 6, 4 }, - { "Dtx", 2, 4 }, - { "LoDrv", 1, 1 }, - { "HiDrv", 0, 1 }, - { "XGM_SERDES_CTRL1", 0xae4, 0 }, - { "FmOffset3", 19, 5 }, - { "FmOffsetEn3", 18, 1 }, - { "FmOffset2", 13, 5 }, - { "FmOffsetEn2", 12, 1 }, - { "FmOffset1", 7, 5 }, - { "FmOffsetEn1", 6, 1 }, - { "FmOffset0", 1, 5 }, - { "FmOffsetEn0", 0, 1 }, - { "XGM_SERDES_CTRL2", 0xae8, 0 }, - { "DnIn3", 11, 1 }, - { "UpIn3", 10, 1 }, - { "RxSlave3", 9, 1 }, - { "DnIn2", 8, 1 }, - { "UpIn2", 7, 1 }, - { "RxSlave2", 6, 1 }, - { "DnIn1", 5, 1 }, - { "UpIn1", 4, 1 }, - { "RxSlave1", 3, 1 }, - { "DnIn0", 2, 1 }, - { "UpIn0", 1, 1 }, - { "RxSlave0", 0, 1 }, - { "XGM_SERDES_CTRL3", 0xaec, 0 }, - { "ExtBISTChkErrClr3", 31, 1 }, - { "ExtBISTChkEn3", 30, 1 }, - { "ExtBISTGenEn3", 29, 1 }, - { "ExtBISTPat3", 26, 3 }, - { "ExtParReset3", 25, 1 }, - { "ExtParLPBK3", 24, 1 }, - { "ExtBISTChkErrClr2", 23, 1 }, - { "ExtBISTChkEn2", 22, 1 }, - { "ExtBISTGenEn2", 21, 1 }, - { "ExtBISTPat2", 18, 3 }, - { "ExtParReset2", 17, 1 }, - { "ExtParLPBK2", 16, 1 }, - { "ExtBISTChkErrClr1", 15, 1 }, - { "ExtBISTChkEn1", 14, 1 }, - { "ExtBISTGenEn1", 13, 1 }, - { "ExtBISTPat1", 10, 3 }, - { "ExtParReset1", 9, 1 }, - { "ExtParLPBK1", 8, 1 }, - { "ExtBISTChkErrClr0", 7, 1 }, - { "ExtBISTChkEn0", 6, 1 }, - { "ExtBISTGenEn0", 5, 1 }, - { "ExtBISTPat0", 2, 3 }, - { "ExtParReset0", 1, 1 }, - { "ExtParLPBK0", 0, 1 }, - { "XGM_SERDES_STAT0", 0xaf0, 0 }, - { "ExtBISTChkErrCnt0", 4, 24 }, - { "ExtBISTChkFmd0", 3, 1 }, - { "LowSigForceEn0", 2, 1 }, - { "LowSigForceValue0", 1, 1 }, - { "LowSig0", 0, 1 }, - { "XGM_SERDES_STAT1", 0xaf4, 0 }, - { "ExtBISTChkErrCnt1", 4, 24 }, - { "ExtBISTChkFmd1", 3, 1 }, - { "LowSigForceEn1", 2, 1 }, - { "LowSigForceValue1", 1, 1 }, - { "LowSig1", 0, 1 }, - { "XGM_SERDES_STAT2", 0xaf8, 0 }, - { "ExtBISTChkErrCnt2", 4, 24 }, - { "ExtBISTChkFmd2", 3, 1 }, - { "LowSigForceEn2", 2, 1 }, - { "LowSigForceValue2", 1, 1 }, - { "LowSig2", 0, 1 }, - { "XGM_SERDES_STAT3", 0xafc, 0 }, - { "ExtBISTChkErrCnt3", 4, 24 }, - { "ExtBISTChkFmd3", 3, 1 }, - { "LowSigForceEn3", 2, 1 }, - { "LowSigForceValue3", 1, 1 }, - { "LowSig3", 0, 1 }, - { "XGM_STAT_TX_BYTE_LOW", 0xb00, 0 }, - { "XGM_STAT_TX_BYTE_HIGH", 0xb04, 0 }, - { "TxBytes_high", 0, 13 }, - { "XGM_STAT_TX_FRAME_LOW", 0xb08, 0 }, - { "XGM_STAT_TX_FRAME_HIGH", 0xb0c, 0 }, - { "TxFrames_high", 0, 4 }, - { "XGM_STAT_TX_BCAST", 0xb10, 0 }, - { "XGM_STAT_TX_MCAST", 0xb14, 0 }, - { "XGM_STAT_TX_PAUSE", 0xb18, 0 }, - { "XGM_STAT_TX_64B_FRAMES", 0xb1c, 0 }, - { "XGM_STAT_TX_65_127B_FRAMES", 0xb20, 0 }, - { "XGM_STAT_TX_128_255B_FRAMES", 0xb24, 0 }, - { "XGM_STAT_TX_256_511B_FRAMES", 0xb28, 0 }, - { "XGM_STAT_TX_512_1023B_FRAMES", 0xb2c, 0 }, - { "XGM_STAT_TX_1024_1518B_FRAMES", 0xb30, 0 }, - { "XGM_STAT_TX_1519_MAXB_FRAMES", 0xb34, 0 }, - { "XGM_STAT_TX_ERR_FRAMES", 0xb38, 0 }, - { "XGM_STAT_RX_BYTES_LOW", 0xb3c, 0 }, - { "XGM_STAT_RX_BYTES_HIGH", 0xb40, 0 }, - { "RxBytes_high", 0, 13 }, - { "XGM_STAT_RX_FRAMES_LOW", 0xb44, 0 }, - { "XGM_STAT_RX_FRAMES_HIGH", 0xb48, 0 }, - { "RxFrames_high", 0, 4 }, - { "XGM_STAT_RX_BCAST_FRAMES", 0xb4c, 0 }, - { "XGM_STAT_RX_MCAST_FRAMES", 0xb50, 0 }, - { "XGM_STAT_RX_PAUSE_FRAMES", 0xb54, 0 }, - { "RxPauseFrames", 0, 16 }, - { "XGM_STAT_RX_64B_FRAMES", 0xb58, 0 }, - { "XGM_STAT_RX_65_127B_FRAMES", 0xb5c, 0 }, - { "XGM_STAT_RX_128_255B_FRAMES", 0xb60, 0 }, - { "XGM_STAT_RX_256_511B_FRAMES", 0xb64, 0 }, - { "XGM_STAT_RX_512_1023B_FRAMES", 0xb68, 0 }, - { "XGM_STAT_RX_1024_1518B_FRAMES", 0xb6c, 0 }, - { "XGM_STAT_RX_1519_MAXB_FRAMES", 0xb70, 0 }, - { "XGM_STAT_RX_SHORT_FRAMES", 0xb74, 0 }, - { "RxShortFrames", 0, 16 }, - { "XGM_STAT_RX_OVERSIZE_FRAMES", 0xb78, 0 }, - { "RxOversizeFrames", 0, 16 }, - { "XGM_STAT_RX_JABBER_FRAMES", 0xb7c, 0 }, - { "RxJabberFrames", 0, 16 }, - { "XGM_STAT_RX_CRC_ERR_FRAMES", 0xb80, 0 }, - { "RxCRCErrFrames", 0, 16 }, - { "XGM_STAT_RX_LENGTH_ERR_FRAMES", 0xb84, 0 }, - { "RxLengthErrFrames", 0, 16 }, - { "XGM_STAT_RX_SYM_CODE_ERR_FRAMES", 0xb88, 0 }, - { "RxSymCodeErrFrames", 0, 16 }, - { "XGM_XAUI_PCS_ERR", 0xb98, 0 }, - { "PCS_SyncStatus", 5, 4 }, - { "PCS_CTCFIFOErr", 1, 4 }, - { "PCS_NotAligned", 0, 1 }, - { "XGM_RGMII_STATUS", 0xb9c, 0 }, - { "GMIIDuplex", 3, 1 }, - { "GMIISpeed", 1, 2 }, - { "GMIILinkStatus", 0, 1 }, - { "XGM_WOL_STATUS", 0xba0, 0 }, - { "PatDetected", 31, 1 }, - { "MatchedFilter", 0, 3 }, - { "XGM_RX_MAX_PKT_SIZE_ERR_CNT", 0xba4, 0 }, - { "XGM_TX_SPI4_SOP_EOP_CNT", 0xba8, 0 }, - { "TxSPI4SopCnt", 16, 16 }, - { "TxSPI4EopCnt", 0, 16 }, - { "XGM_RX_SPI4_SOP_EOP_CNT", 0xbac, 0 }, - { "RxSPI4SopCnt", 16, 16 }, - { "RxSPI4EopCnt", 0, 16 }, - { NULL, 0, 0 } -}; - diff --git a/usr.sbin/cxgbtool/version.h b/usr.sbin/cxgbtool/version.h deleted file mode 100644 index 403a8be..0000000 --- a/usr.sbin/cxgbtool/version.h +++ /dev/null @@ -1,32 +0,0 @@ -/***************************************************************************** - * * - * File: * - * version.h * - * * - * Description: * - * cxgbtool userspace utility version defines. * - * * - * http://www.chelsio.com * - * * - * Copyright (c) 2003 - 2008 Chelsio Communications, Inc. * - * All rights reserved. * - * * - * Maintainers: maintainers@chelsio.com * - * * - * History: * - * * - ****************************************************************************/ -/* $Date: 2007/02/05 18:46:24 $ $RCSfile: version.h,v $ $Revision: 1.9 $ */ - -/* - * $FreeBSD$ - */ - -#ifndef __CXGBTOOL_VERSION_H -#define __CXGBTOOL_VERSION_H - -#define PROGNAME "cxgbtool" -#define VERSION "1.16f" -#define COPYRIGHT "Copyright (c) 2004-2009 Chelsio Communications" - -#endif //__CXGBTOOL_VERSION_H diff --git a/usr.sbin/daemon/Makefile b/usr.sbin/daemon/Makefile deleted file mode 100644 index 2def803..0000000 --- a/usr.sbin/daemon/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD$ - -PROG= daemon -MAN= daemon.8 - -DPADD= ${LIBUTIL} -LDADD= -lutil - -.include diff --git a/usr.sbin/daemon/daemon.8 b/usr.sbin/daemon/daemon.8 deleted file mode 100644 index bdebd83..0000000 --- a/usr.sbin/daemon/daemon.8 +++ /dev/null @@ -1,96 +0,0 @@ -.\" Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Berkeley Software Design Inc's name may not be used to endorse or -.\" promote products derived from this software without specific prior -.\" written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd March 19, 2007 -.Dt DAEMON 8 -.Os -.Sh NAME -.Nm daemon -.Nd run detached from the controlling terminal -.Sh SYNOPSIS -.Nm -.Op Fl cf -.Op Fl p Ar pidfile -.Op Fl u Ar user -.Ar command arguments ... -.Sh DESCRIPTION -The -.Nm -utility detaches itself from the controlling terminal and -executes the program specified by its arguments. -Privileges may be lowered to the specified user. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl c -Change the current working directory to the root -.Pq Dq Pa / . -.It Fl f -Redirect standard input, standard output and standard error to -.Pa /dev/null . -.It Fl p Ar file -Write the ID of the created process into the -.Ar file -using the -.Xr pidfile 3 -functionality. -Note, that the file will be created shortly before the process is -actually executed, and will remain after the process exits (although -it will be removed if the execution fails). -.It Fl u Ar user -Login name of the user to execute the program under. -Requires adequate superuser privileges. -.El -.Sh EXIT STATUS -The -.Nm -utility exits 1 if an error is returned by the -.Xr daemon 3 -library routine, 2 if the -.Ar pidfile -is requested, but cannot be opened, 3 if process is already running (pidfile -exists and is locked), -otherwise 0. -.Sh DIAGNOSTICS -If the command cannot be executed, an error message is displayed on -standard error unless the -.Fl f -flag is specified. -.Sh SEE ALSO -.Xr setregid 2 , -.Xr setreuid 2 , -.Xr daemon 3 , -.Xr exec 3 , -.Xr pidfile 3 , -.Xr termios 4 , -.Xr tty 4 -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 4.7 . diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c deleted file mode 100644 index 540ebf3..0000000 --- a/usr.sbin/daemon/daemon.c +++ /dev/null @@ -1,141 +0,0 @@ -/*- - * Copyright (c) 1999 Berkeley Software Design, Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Berkeley Software Design Inc's name may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * From BSDI: daemon.c,v 1.2 1996/08/15 01:11:09 jch Exp - */ - -#include -__FBSDID("$FreeBSD$"); - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -static void restrict_process(const char *); -static void usage(void); - -int -main(int argc, char *argv[]) -{ - struct pidfh *pfh = NULL; - int ch, nochdir, noclose, errcode; - const char *pidfile, *user; - pid_t otherpid; - - nochdir = noclose = 1; - pidfile = user = NULL; - while ((ch = getopt(argc, argv, "-cfp:u:")) != -1) { - switch (ch) { - case 'c': - nochdir = 0; - break; - case 'f': - noclose = 0; - break; - case 'p': - pidfile = optarg; - break; - case 'u': - user = optarg; - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc == 0) - usage(); - - if (user != NULL) - restrict_process(user); - - /* - * Try to open the pidfile before calling daemon(3), - * to be able to report the error intelligently - */ - if (pidfile) { - pfh = pidfile_open(pidfile, 0600, &otherpid); - if (pfh == NULL) { - if (errno == EEXIST) { - errx(3, "process already running, pid: %d", - otherpid); - } - err(2, "pidfile ``%s''", pidfile); - } - } - - if (daemon(nochdir, noclose) == -1) - err(1, NULL); - - /* Now that we are the child, write out the pid */ - if (pidfile) - pidfile_write(pfh); - - execvp(argv[0], argv); - - /* - * execvp() failed -- unlink pidfile if any, and - * report the error - */ - errcode = errno; /* Preserve errcode -- unlink may reset it */ - if (pidfile) - pidfile_remove(pfh); - - /* The child is now running, so the exit status doesn't matter. */ - errc(1, errcode, "%s", argv[0]); -} - -static void -restrict_process(const char *user) -{ - struct passwd *pw = NULL; - - pw = getpwnam(user); - if (pw == NULL) - errx(1, "unknown user: %s", user); - - if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL) != 0) - errx(1, "failed to set user environment"); -} - -static void -usage(void) -{ - (void)fprintf(stderr, - "usage: daemon [-cf] [-p pidfile] [-u user] command " - "arguments ...\n"); - exit(1); -} diff --git a/usr.sbin/dconschat/Makefile b/usr.sbin/dconschat/Makefile deleted file mode 100644 index 2836a66..0000000 --- a/usr.sbin/dconschat/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $FreeBSD$ - -PROG= dconschat -MAN= dconschat.8 - -CFLAGS+= -I${.CURDIR}/../../sys - -DPADD= ${LIBKVM} -LDADD= -lkvm - -WARNS?= 1 - -.include diff --git a/usr.sbin/dconschat/dconschat.8 b/usr.sbin/dconschat/dconschat.8 deleted file mode 100644 index 4f8dcd4..0000000 --- a/usr.sbin/dconschat/dconschat.8 +++ /dev/null @@ -1,329 +0,0 @@ -.\" Copyright (c) 2003 Hidetoshi Shimokawa -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.\" -.Dd February 11, 2003 -.Dt DCONSCHAT 8 -.Os -.Sh NAME -.Nm dconschat -.Nd user interface to -.Xr dcons 4 -.Sh SYNOPSIS -.Nm -.Op Fl brvwRT1 -.Op Fl e Ar escape-char -.Op Fl h Ar hz -.Op Fl C Ar console_port -.Op Fl G Ar gdb_port -.Op Fl M Ar core -.Op Fl N Ar system -.Nm -.Op Fl brvwR1 -.Op Fl h Ar hz -.Op Fl C Ar console_port -.Op Fl G Ar gdb_port -.Op Fl a Ar address -.Op Fl u Ar bus_num -.Fl t Ar target_eui64 -.Sh DESCRIPTION -The -.Nm -utility is designed to provide a way for users to access -.Xr dcons 4 -(dumb console device) on a local or remote system. -The -.Nm -utility interacts with -.Xr dcons 4 -using -.Xr kvm 3 -or -.Xr firewire 4 , -and interacts with the user over TTY or TCP/IP. -To access remote -.Xr dcons 4 -using -.Xr firewire 4 , -you have to specify target EUI64 address using the -.Fl t -option. Physical DMA should be enabled on the target machine for access -via FireWire. -.Pp -The -.Nm -utility and the -.Xr dcons 4 -driver communicate using 2 ports, one for the console port and another -for remote -.Xr gdb 1 -port. -Users are supposed to access -.Nm -using TTY, -.Xr telnet 1 -and -.Xr gdb 1 . -You can specify listen ports for console and -.Xr gdb 1 -port using the -.Fl C -and -.Fl G -options respectively. -The port number 0 has special meaning that -current TTY (stdin/stdout) is used instead of TCP/IP. -A negative port number will disable the port. -By analogy with -.Xr pty 4 -device, the -.Xr dcons 4 -acts as a slave device and -.Nm -acts as a master device with -.Xr telnetd 8 . -.Pp -Typed characters are normally transmitted directly to -.Xr dcons 4 . -A escape character (the default is -.Ql ~ -) appearing as the first character of a line is an escape signal; the -following are recognized: -.Bl -tag -width ident -.It Ic ~. -Drop the connection and exit. -.It Ic ~^G -Invoke kgdb on the terminal on which dconschat is running. -.It Ic ~^R -Reset the target over FireWire if a reset address is registered in Configuration ROM. -.It Ic ~^Z -Suspend the dconschat process. -.El -.Pp -The following options are supported. -.Bl -tag -width indent -.It Fl b -Translate Ctrl-C to ALT_BREAK (CR + -.Ql ~ -+ Ctrl-B) on -.Xr gdb 1 -port. -.It Fl r -Replay old buffer on connection. -.It Fl v -Verbose debug output. -Multiple -.Fl v -options increase verbosity. -.It Fl w -Listen on a wildcard address rather than localhost. -.It Fl R -Read-only. -Do not write anything to the -.Xr dcons 4 -buffer. -.It Fl T -Enable ad-hoc workaround for the TELNET protocol to -remove unnecessary byte sequences. -It should be set when you access -.Nm -using -.Xr telnet 1 . -.It Fl 1 -One-shot. -Read available buffer, then exit. -This implies the -.Fl r -option. -.It Fl e Ar escape-char -Specify escape character. -The default is '~'. -.It Fl h Ar hz -Specify polling rate. -The default value is 100. -.It Fl C Ar console_port -Specify the console port. -The default value is 0 (stdin/stdout). -.It Fl G Ar gdb_port -Specify -.Xr gdb 1 -port. -The default value is \-1 (disabled). -.It Fl M Ar core -Specify core file. -.It Fl N Ar system -Specify system file such as -.Pa /boot/kernel/kernel . -.It Fl t Ar target_eui64 -Specify the 64-bit extended unique identifier of the target, -and use FireWire to access remote -.Xr dcons 4 . -.It Fl a Ar address -Specify the physical I/O address of the -.Xr dcons 4 -buffer. -See -.Xr dcons 4 -for details. -If this option is not specified, -.Nm -tries to get the address from the Configuration ROM on the target. -You are supposed to enable -.Xr dcons_crom 4 -on the target to omit this option. -.It Fl u Ar bus_num -Specify FireWire bus number. -The default is 0. -.El -.Sh FILES -.Bl -tag -width indent -compact -.It Pa /dev/fwmem0.0 -.It Pa /dev/mem -.It Pa /dev/kmem -.El -.Sh EXAMPLES -To use -.Nm -with FireWire for remote -.Xr dcons 4 , -you have to specify the EUI64 of the target. -You can obtain EUI64 by running -.Xr fwcontrol 8 -without options. -The first EUI64 is of the host running -.Xr fwcontrol 8 -and others on the bus follow. -.Bd -literal -offset indent -# fwcontrol -2 devices (info_len=2) -node EUI64 status - 1 77-66-55-44-33-22-11-00 0 - 0 00-11-22-33-44-55-66-77 1 -.Ed -.Pp -The EUI64 does not change unless you change the hardware -as the ethernet address. -.Pp -Now we can run -.Nm . -.Bd -literal -offset indent -# dconschat -br -G 12345 -t 00-11-22-33-44-55-66-77 -.Ed -.Pp -You will get console output of the target and login prompt if a -.Xr getty 8 -is running on -.Xr dcons 4 . -You can break to DDB with ALT_BREAK (CR + -.Ql ~ -+ Ctrl-B) -if -.Dv DDB -and -.Dv ALT_BREAK_TO_DEBUGGER -are enabled in the target kernel. -To quit the session, type CR + -.Ql ~ -+ -.Ql \&. -in the console port. -.Pp -Using -.Xr gdb 1 -port is almost the same as remote -.Xr gdb 1 -over serial line except -using TCP/IP instead of -.Pa /dev/cu* . -See -.Sx "On-line Kernel Debugging Using Remote GDB" -section of -.%T "The FreeBSD Developers Handbook" -and -.Xr gdb 4 -for details. -.Bd -literal -offset indent -% gdb -k kernel.debug -(kgdb) target remote :12345 -.Ed -.Pp -Once -.Xr gdb 1 -is attached and you specified the -.Fl b -option to -.Nm , -typing Ctrl-C in -.Xr gdb 1 -causes a break to debugger. -.Pp -The following command gets the console log from the crash dump: -.Bd -literal -offset indent -# dconschat -1 -M vmcore.0 -N kernel.0 -.Ed -.Pp -If you want access to the console using -.Xr telnet 1 , -try the following: -.Bd -literal -offset indent -# dconschat -rTC 5555 & -# telnet localhost 5555 -.Ed -.Pp -You may want to keep logging console output of several machines. -.Nm conserver-com -in the Ports collection may help you. -Insert the following lines in -.Pa conserver.cf : -.Bd -literal -offset indent -console local { - master localhost; - type exec; - exec /usr/sbin/dconschat -rh 25; -} -console remote { - master localhost; - type exec; - exec /usr/sbin/dconschat -rh 25 -t 00-11-22-33-44-55-66-77; -} -.Ed -.Sh SEE ALSO -.Xr gdb 1 , -.Xr telnet 1 , -.Xr kvm 3 , -.Xr dcons 4 , -.Xr dcons_crom 4 , -.Xr ddb 4 , -.Xr firewire 4 , -.Xr fwohci 4 , -.Xr gdb 4 , -.Xr eui64 5 , -.Xr fwcontrol 8 -.Sh AUTHORS -.An Hidetoshi Shimokawa Aq simokawa@FreeBSD.org -.Sh BUGS -This utility is -.Ud diff --git a/usr.sbin/dconschat/dconschat.c b/usr.sbin/dconschat/dconschat.c deleted file mode 100644 index 9246181..0000000 --- a/usr.sbin/dconschat/dconschat.c +++ /dev/null @@ -1,1154 +0,0 @@ -/* - * Copyright (C) 2003 - * Hidetoshi Shimokawa. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by Hidetoshi Shimokawa. - * - * 4. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id: dconschat.c,v 1.76 2003/10/23 06:21:13 simokawa Exp $ - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#define DCONS_POLL_HZ 100 -#define DCONS_POLL_OFFLINE 2 /* sec */ - -#define RETRY 3 - -#ifdef CSRVAL_VENDOR_PRIVATE -#define USE_CROM 1 -#else -#define USE_CROM 0 -#endif - -int verbose = 0; -int tc_set = 0; -int poll_hz = DCONS_POLL_HZ; -static u_char abreak[3] = {13 /* CR */, 126 /* ~ */, 2 /* ^B */}; - -#define IS_CONSOLE(p) ((p)->port == DCONS_CON) -#define IS_GDB(p) ((p)->port == DCONS_GDB) - -static struct dcons_state { - int fd; - kvm_t *kd; - int kq; - off_t paddr; - off_t reset; -#define F_READY (1 << 1) -#define F_RD_ONLY (1 << 2) -#define F_ALT_BREAK (1 << 3) -#define F_TELNET (1 << 4) -#define F_USE_CROM (1 << 5) -#define F_ONE_SHOT (1 << 6) -#define F_REPLAY (1 << 7) - int flags; - enum { - TYPE_KVM, - TYPE_FW - } type; - int escape_state; - struct dcons_port { - int port; - int sport; - struct dcons_ch o; - struct dcons_ch i; - u_int32_t optr; - u_int32_t iptr; - int s; - int infd; - int outfd; - struct addrinfo *res; - int skip_read; - } port[DCONS_NPORT]; - struct timespec to; - struct timespec zero; - struct termios tsave; - struct termios traw; - char escape; -} sc; - -static int dconschat_write_dcons(struct dcons_state *, int, char *, int); - -static int -dread(struct dcons_state *dc, void *buf, size_t n, off_t offset) -{ - switch (dc->type) { - case TYPE_FW: - return (pread(dc->fd, buf, n, offset)); - case TYPE_KVM: - return (kvm_read(dc->kd, offset, buf, n)); - } - return (-1); -} - -static int -dwrite(struct dcons_state *dc, void *buf, size_t n, off_t offset) -{ - if ((dc->flags & F_RD_ONLY) != 0) - return (n); - - switch (dc->type) { - case TYPE_FW: - return (pwrite(dc->fd, buf, n, offset)); - case TYPE_KVM: - return (kvm_write(dc->kd, offset, buf, n)); - } - return (-1); -} - -static void -dconschat_reset_target(struct dcons_state *dc, struct dcons_port *p) -{ - char buf[PAGE_SIZE]; - if (dc->reset == 0) - return; - - snprintf(buf, PAGE_SIZE, "\r\n[dconschat reset target(addr=0x%zx)...]\r\n", dc->reset); - write(p->outfd, buf, strlen(buf)); - bzero(&buf[0], PAGE_SIZE); - dwrite(dc, (void *)buf, PAGE_SIZE, dc->reset); -} - - -static void -dconschat_suspend(struct dcons_state *dc, struct dcons_port *p) -{ - if (p->sport != 0) - return; - - if (tc_set) - tcsetattr(STDIN_FILENO, TCSADRAIN, &dc->tsave); - - printf("\n[dconschat suspend]\n"); - kill(getpid(), SIGTSTP); - - if (tc_set) - tcsetattr(STDIN_FILENO, TCSADRAIN, &dc->traw); -} - -static void -dconschat_sigchld(int s) -{ - struct kevent kev; - struct dcons_port *p; - char buf[256]; - - p = &sc.port[DCONS_CON]; - - snprintf(buf, 256, "\r\n[child exit]\r\n"); - write(p->outfd, buf, strlen(buf)); - - if (tc_set) - tcsetattr(STDIN_FILENO, TCSADRAIN, &sc.traw); - - EV_SET(&kev, p->infd, EVFILT_READ, EV_ADD, NOTE_LOWAT, 1, (void *)p); - kevent(sc.kq, &kev, 1, NULL, 0, &sc.zero); -} - -static void -dconschat_fork_gdb(struct dcons_state *dc, struct dcons_port *p) -{ - pid_t pid; - char buf[256], com[256]; - struct kevent kev; - - pid = fork(); - if (pid < 0) { - snprintf(buf, 256, "\r\n[%s: fork failed]\r\n", __FUNCTION__); - write(p->outfd, buf, strlen(buf)); - } - - - if (pid == 0) { - /* child */ - if (tc_set) - tcsetattr(STDIN_FILENO, TCSADRAIN, &dc->tsave); - - snprintf(com, sizeof(buf), "kgdb -r :%d kernel", - dc->port[DCONS_GDB].sport); - snprintf(buf, 256, "\n[fork %s]\n", com); - write(p->outfd, buf, strlen(buf)); - - execl("/bin/sh", "/bin/sh", "-c", com, 0); - - snprintf(buf, 256, "\n[fork failed]\n"); - write(p->outfd, buf, strlen(buf)); - - if (tc_set) - tcsetattr(STDIN_FILENO, TCSADRAIN, &dc->traw); - - exit(0); - } else { - signal(SIGCHLD, dconschat_sigchld); - EV_SET(&kev, p->infd, EVFILT_READ, EV_DELETE, 0, 0, NULL); - kevent(sc.kq, &kev, 1, NULL, 0, &sc.zero); - } -} - - -static void -dconschat_cleanup(int sig) -{ - struct dcons_state *dc; - int status; - - dc = ≻ - if (tc_set != 0) - tcsetattr(STDIN_FILENO, TCSADRAIN, &dc->tsave); - - if (sig > 0) - printf("\n[dconschat exiting with signal %d ...]\n", sig); - else - printf("\n[dconschat exiting...]\n"); - wait(&status); - exit(0); -} - -#if USE_CROM -static int -dconschat_get_crom(struct dcons_state *dc) -{ - off_t addr; - int i, state = 0; - u_int32_t buf, hi = 0, lo = 0, reset_hi = 0, reset_lo = 0; - struct csrreg *reg; - - reg = (struct csrreg *)&buf; - addr = 0xffff; - addr = (addr << 32) | 0xf0000400; - for (i = 20; i < 0x400; i += 4) { - if (dread(dc, &buf, 4, addr + i) < 0) { - if (verbose) - warn("crom read faild"); - goto out; - } - buf = ntohl(buf); - if (verbose) - printf("%d %02x %06x\n", state, reg->key, reg->val); - switch (state) { - case 0: - if (reg->key == CSRKEY_SPEC && - reg->val == CSRVAL_VENDOR_PRIVATE) - state = 1; - break; - case 1: - if (reg->key == CSRKEY_VER && - reg->val == DCONS_CSR_VAL_VER) - state = 2; - break; - case 2: - switch (reg->key) { - case DCONS_CSR_KEY_HI: - hi = reg->val; - break; - case DCONS_CSR_KEY_LO: - lo = reg->val; - break; - case DCONS_CSR_KEY_RESET_HI: - reset_hi = reg->val; - break; - case DCONS_CSR_KEY_RESET_LO: - reset_lo = reg->val; - goto out; - break; - case 0x81: - break; - default: - state = 0; - } - break; - } - } -out: - if (verbose) - printf("addr: %06x %06x\n", hi, lo); - dc->paddr = ((off_t)hi << 24) | lo; - dc->reset = ((off_t)reset_hi << 24) | reset_lo; - if (dc->paddr == 0) - return (-1); - return (0); -} -#endif - -static void -dconschat_ready(struct dcons_state *dc, int ready, char *reason) -{ - static char oldreason[64] = ""; - int old; - - old = (dc->flags & F_READY) ? 1 : 0; - - if (ready) { - dc->flags |= F_READY; - if (ready != old) - printf("[dcons connected]\r\n"); - oldreason[0] = 0; - } else { - dc->flags &= ~F_READY; - if (strncmp(oldreason, reason, sizeof(oldreason)) != 0) { - printf("[dcons disconnected (%s)]\r\n", reason); - strlcpy(oldreason, reason, sizeof(oldreason)); - } - } -} - -static int -dconschat_fetch_header(struct dcons_state *dc) -{ - char ebuf[64]; - struct dcons_buf dbuf; - int j; - -#if USE_CROM - if (dc->paddr == 0 && (dc->flags & F_USE_CROM) != 0) { - if (dconschat_get_crom(dc)) { - dconschat_ready(dc, 0, "get crom failed"); - return (-1); - } - } -#endif - - if (dread(dc, &dbuf, DCONS_HEADER_SIZE, dc->paddr) < 0) { - dconschat_ready(dc, 0, "read header failed"); - return (-1); - } - if (dbuf.magic != htonl(DCONS_MAGIC)) { - if ((dc->flags & F_USE_CROM) !=0) - dc->paddr = 0; - snprintf(ebuf, sizeof(ebuf), "wrong magic 0x%08x", dbuf.magic); - dconschat_ready(dc, 0, ebuf); - return (-1); - } - if (ntohl(dbuf.version) != DCONS_VERSION) { - snprintf(ebuf, sizeof(ebuf), -#if __FreeBSD_version < 500000 - "wrong version %ld,%d", -#else - "wrong version %d,%d", -#endif - ntohl(dbuf.version), DCONS_VERSION); - /* XXX exit? */ - dconschat_ready(dc, 0, ebuf); - return (-1); - } - - for (j = 0; j < DCONS_NPORT; j++) { - struct dcons_ch *o, *i; - off_t newbuf; - int new = 0; - - o = &dc->port[j].o; - newbuf = dc->paddr + ntohl(dbuf.ooffset[j]); - o->size = ntohl(dbuf.osize[j]); - - if (newbuf != o->buf) { - /* buffer address has changes */ - new = 1; - o->gen = ntohl(dbuf.optr[j]) >> DCONS_GEN_SHIFT; - o->pos = ntohl(dbuf.optr[j]) & DCONS_POS_MASK; - o->buf = newbuf; - } - - i = &dc->port[j].i; - i->size = ntohl(dbuf.isize[j]); - i->gen = ntohl(dbuf.iptr[j]) >> DCONS_GEN_SHIFT; - i->pos = ntohl(dbuf.iptr[j]) & DCONS_POS_MASK; - i->buf = dc->paddr + ntohl(dbuf.ioffset[j]); - - if (verbose) { - printf("port %d size offset gen pos\n", j); -#if __FreeBSD_version < 500000 - printf("output: %5d %6ld %5d %5d\n" - "input : %5d %6ld %5d %5d\n", -#else - printf("output: %5d %6d %5d %5d\n" - "input : %5d %6d %5d %5d\n", -#endif - o->size, ntohl(dbuf.ooffset[j]), o->gen, o->pos, - i->size, ntohl(dbuf.ioffset[j]), i->gen, i->pos); - } - - if (IS_CONSOLE(&dc->port[j]) && new && - (dc->flags & F_REPLAY) !=0) { - if (o->gen > 0) - o->gen --; - else - o->pos = 0; - } - } - dconschat_ready(dc, 1, NULL); - return(0); -} - -static int -dconschat_get_ptr (struct dcons_state *dc) { - int dlen, i; - u_int32_t ptr[DCONS_NPORT*2+1]; - static int retry = RETRY; - char ebuf[64]; - -again: - dlen = dread(dc, &ptr, sizeof(ptr), - dc->paddr + __offsetof(struct dcons_buf, magic)); - - if (dlen < 0) { - if (errno == ETIMEDOUT) - if (retry -- > 0) - goto again; - dconschat_ready(dc, 0, "get ptr failed"); - return(-1); - } - if (ptr[0] != htonl(DCONS_MAGIC)) { - if ((dc->flags & F_USE_CROM) !=0) - dc->paddr = 0; - snprintf(ebuf, sizeof(ebuf), "wrong magic 0x%08x", ptr[0]); - dconschat_ready(dc, 0, ebuf); - return(-1); - } - retry = RETRY; - for (i = 0; i < DCONS_NPORT; i ++) { - dc->port[i].optr = ntohl(ptr[i + 1]); - dc->port[i].iptr = ntohl(ptr[DCONS_NPORT + i + 1]); - } - return(0); -} - -#define MAX_XFER 2048 -static int -dconschat_read_dcons(struct dcons_state *dc, int port, char *buf, int len) -{ - struct dcons_ch *ch; - u_int32_t ptr, pos, gen, next_gen; - int rlen, dlen, lost; - int retry = RETRY; - - ch = &dc->port[port].o; - ptr = dc->port[port].optr; - gen = ptr >> DCONS_GEN_SHIFT; - pos = ptr & DCONS_POS_MASK; - if (gen == ch->gen && pos == ch->pos) - return (-1); - - next_gen = DCONS_NEXT_GEN(ch->gen); - /* XXX sanity check */ - if (gen == ch->gen) { - if (pos > ch->pos) - goto ok; - lost = ch->size * DCONS_GEN_MASK - ch->pos; - ch->pos = 0; - } else if (gen == next_gen) { - if (pos <= ch->pos) - goto ok; - lost = pos - ch->pos; - ch->pos = pos; - } else { - lost = gen - ch->gen; - if (lost < 0) - lost += DCONS_GEN_MASK; - if (verbose) - printf("[genskip %d]", lost); - lost = lost * ch->size - ch->pos; - ch->pos = 0; - ch->gen = gen; - } - /* generation skipped !! */ - /* XXX discard */ - if (verbose) - printf("[lost %d]", lost); -ok: - if (gen == ch->gen) - rlen = pos - ch->pos; - else - rlen = ch->size - ch->pos; - - if (rlen > MAX_XFER) - rlen = MAX_XFER; - if (rlen > len) - rlen = len; - -#if 1 - if (verbose == 1) - printf("[%d]", rlen); fflush(stdout); -#endif - -again: - dlen = dread(dc, buf, rlen, ch->buf + ch->pos); - if (dlen < 0) { - if (errno == ETIMEDOUT) - if (retry -- > 0) - goto again; - dconschat_ready(dc, 0, "read buffer failed"); - return(-1); - } - if (dlen != rlen) - warnx("dlen(%d) != rlen(%d)\n", dlen, rlen); - ch->pos += dlen; - if (ch->pos >= ch->size) { - ch->gen = next_gen; - ch->pos = 0; - if (verbose) - printf("read_dcons: gen=%d", ch->gen); - } - return (dlen); -} - -static int -dconschat_write_dcons(struct dcons_state *dc, int port, char *buf, int blen) -{ - struct dcons_ch *ch; - u_int32_t ptr; - int len, wlen; - int retry = RETRY; - - ch = &dc->port[port].i; - ptr = dc->port[port].iptr; - - /* the others may advance the pointer sync with it */ - ch->gen = ptr >> DCONS_GEN_SHIFT; - ch->pos = ptr & DCONS_POS_MASK; - - while(blen > 0) { - wlen = MIN(blen, ch->size - ch->pos); - wlen = MIN(wlen, MAX_XFER); - len = dwrite(dc, buf, wlen, ch->buf + ch->pos); - if (len < 0) { - if (errno == ETIMEDOUT) - if (retry -- > 0) - continue; /* try again */ - dconschat_ready(dc, 0, "write buffer failed"); - return(-1); - } - ch->pos += len; - buf += len; - blen -= len; - if (ch->pos >= ch->size) { - ch->gen = DCONS_NEXT_GEN(ch->gen); - ch->pos = 0; - if (verbose) - printf("write_dcons: gen=%d", ch->gen); - - } - } - - ptr = DCONS_MAKE_PTR(ch); - dc->port[port].iptr = ptr; - - if (verbose > 2) - printf("(iptr: 0x%x)", ptr); -again: - len = dwrite(dc, &ptr, sizeof(u_int32_t), - dc->paddr + __offsetof(struct dcons_buf, iptr[port])); - if (len < 0) { - if (errno == ETIMEDOUT) - if (retry -- > 0) - goto again; - dconschat_ready(dc, 0, "write ptr failed"); - return(-1); - } - return(0); -} - - -static int -dconschat_write_socket(int fd, char *buf, int len) -{ - write(fd, buf, len); - if (verbose > 1) { - buf[len] = 0; - printf("<- %s\n", buf); - } - return (0); -} - -static void -dconschat_init_socket(struct dcons_state *dc, int port, char *host, int sport) -{ - struct addrinfo hints, *res; - int on = 1, error; - char service[10]; - struct kevent kev; - struct dcons_port *p; - - p = &dc->port[port]; - p->port = port; - p->sport = sport; - p->infd = p->outfd = -1; - - if (sport < 0) - return; - - if (sport == 0) { - - /* Use stdin and stdout */ - p->infd = STDIN_FILENO; - p->outfd = STDOUT_FILENO; - p->s = -1; - if (tc_set == 0 && - tcgetattr(STDIN_FILENO, &dc->tsave) == 0) { - dc->traw = dc->tsave; - cfmakeraw(&dc->traw); - tcsetattr(STDIN_FILENO, TCSADRAIN, &dc->traw); - tc_set = 1; - } - EV_SET(&kev, p->infd, EVFILT_READ, EV_ADD, NOTE_LOWAT, 1, - (void *)p); - kevent(dc->kq, &kev, 1, NULL, 0, &dc->zero); - return; - } - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_PASSIVE; -#if 1 /* gdb can talk v4 only */ - hints.ai_family = PF_INET; -#else - hints.ai_family = PF_UNSPEC; -#endif - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = 0; - - if (verbose) - printf("%s:%d for port %d\n", - host == NULL ? "*" : host, sport, port); - snprintf(service, sizeof(service), "%d", sport); - error = getaddrinfo(host, service, &hints, &res); - if (error) - errx(1, "tcp/%s: %s\n", service, gai_strerror(error)); - p->res = res; - p->s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (p->s < 0) - err(1, "socket"); - setsockopt(p->s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - - if (bind(p->s, p->res->ai_addr, p->res->ai_addrlen) < 0) { - err(1, "bind"); - } - if (listen(p->s, 1) < 0) - err(1, "listen"); - EV_SET(&kev, p->s, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, (void *)p); - error = kevent(dc->kq, &kev, 1, NULL, 0, &dc->to); - if (error < 0) - err(1, "kevent"); - return; -} - -static int -dconschat_accept_socket(struct dcons_state *dc, struct dcons_port *p) -{ - socklen_t addrlen; - int ns, flags; - struct kevent kev; - - /* accept connection */ - addrlen = p->res->ai_addrlen; - ns = accept(p->s, p->res->ai_addr, &addrlen); - if (ns < 0) - err(1, "accept"); - if (verbose) - printf("port%d accepted\n", p->port); - - flags = fcntl(ns, F_GETFL, 0); - flags |= O_NDELAY; - fcntl(ns, F_SETFL, flags); -#if 1 - if (IS_CONSOLE(p) && (dc->flags & F_TELNET) != 0) { - char sga[] = {IAC, WILL, TELOPT_SGA}; - char linemode[] = {IAC, DONT, TELOPT_LINEMODE}; - char echo[] = {IAC, WILL, TELOPT_ECHO}; - char bin[] = {IAC, DO, TELOPT_BINARY}; - - write(ns, sga, sizeof(sga)); - write(ns, linemode, sizeof(linemode)); - write(ns, echo, sizeof(echo)); - write(ns, bin, sizeof(bin)); - p->skip_read = 0; - } -#endif - /* discard backlog on GDB port */ - if (IS_GDB(p)) { - char buf[2048]; - int len; - - while ((len = dconschat_read_dcons(dc, DCONS_GDB, &buf[0], - 2048)) > 0) - if (verbose) - printf("discard %d chars on GDB port\n", len); - } - - p->infd = p->outfd = ns; - EV_SET(&kev, ns, EVFILT_READ, EV_ADD, NOTE_LOWAT, 1, (void *)p); - kevent(dc->kq, &kev, 1, NULL, 0, &dc->zero); - return(0); -} - -static int -dconschat_read_filter(struct dcons_state *dc, struct dcons_port *p, - u_char *sp, int slen, u_char *dp, int *dlen) -{ - int skip; - char *buf; - - while (slen > 0) { - skip = 0; - if (IS_CONSOLE(p)) { - if ((dc->flags & F_TELNET) != 0) { - /* XXX Telnet workarounds */ - if (p->skip_read -- > 0) { - sp ++; - slen --; - continue; - } - if (*sp == IAC) { - if (verbose) - printf("(IAC)"); - p->skip_read = 2; - sp ++; - slen --; - continue; - } - if (*sp == 0) { - if (verbose) - printf("(0 stripped)"); - sp ++; - slen --; - continue; - } - } - switch (dc->escape_state) { - case STATE1: - if (*sp == dc->escape) { - skip = 1; - dc->escape_state = STATE2; - } else - dc->escape_state = STATE0; - break; - case STATE2: - dc->escape_state = STATE0; - skip = 1; - if (*sp == '.') - dconschat_cleanup(0); - else if (*sp == CTRL('B')) { - bcopy(abreak, dp, 3); - dp += 3; - *dlen += 3; - } - else if (*sp == CTRL('G')) - dconschat_fork_gdb(dc, p); - else if ((*sp == CTRL('R')) - && (dc->reset != 0)) { - dc->escape_state = STATE3; - buf = "\r\n[Are you sure to reset target? (y/N)]"; - write(p->outfd, buf, strlen(buf)); - } else if (*sp == CTRL('Z')) - dconschat_suspend(dc, p); - else { - skip = 0; - *dp++ = dc->escape; - (*dlen) ++; - } - break; - case STATE3: - dc->escape_state = STATE0; - skip = 1; - if (*sp == 'y') - dconschat_reset_target(dc, p); - else { - write(p->outfd, sp, 1); - write(p->outfd, "\r\n", 2); - } - break; - } - if (*sp == KEY_CR) - dc->escape_state = STATE1; - } else if (IS_GDB(p)) { - /* GDB: ^C -> CR+~+^B */ - if (*sp == CTRL('C') && (dc->flags & F_ALT_BREAK) != 0) { - bcopy(abreak, dp, 3); - dp += 3; - sp ++; - *dlen += 3; - /* discard rest of the packet */ - slen = 0; - break; - } - } - if (!skip) { - *dp++ = *sp; - (*dlen) ++; - } - sp ++; - slen --; - } - return (*dlen); - -} - -static int -dconschat_read_socket(struct dcons_state *dc, struct dcons_port *p) -{ - struct kevent kev; - int len, wlen; - char rbuf[MAX_XFER], wbuf[MAX_XFER+2]; - - if ((len = read(p->infd, rbuf, sizeof(rbuf))) > 0) { - wlen = 0; - dconschat_read_filter(dc, p, rbuf, len, wbuf, &wlen); - /* XXX discard if not ready*/ - if (wlen > 0 && (dc->flags & F_READY) != 0) { - dconschat_write_dcons(dc, p->port, wbuf, wlen); - if (verbose > 1) { - wbuf[wlen] = 0; - printf("-> %s\n", wbuf); - } else if (verbose == 1) { - printf("(%d)", wlen); - fflush(stdout); - } - } - } else { - if (verbose) { - if (len == 0) - warnx("port%d: closed", p->port); - else - warn("port%d: read", p->port); - } - EV_SET(&kev, p->infd, EVFILT_READ, - EV_DELETE, 0, 0, NULL); - kevent(dc->kq, &kev, 1, NULL, 0, &dc->zero); - close(p->infd); - close(p->outfd); - /* XXX exit for pipe case XXX */ - EV_SET(&kev, p->s, EVFILT_READ, - EV_ADD | EV_ONESHOT, 0, 0, (void *) p); - kevent(dc->kq, &kev, 1, NULL, 0, &dc->zero); - p->infd = p->outfd = -1; - } - return(0); -} -#define NEVENT 5 -static int -dconschat_proc_socket(struct dcons_state *dc) -{ - struct kevent elist[NEVENT], *e; - int i, n; - struct dcons_port *p; - - n = kevent(dc->kq, NULL, 0, elist, NEVENT, &dc->to); - for (i = 0; i < n; i ++) { - e = &elist[i]; - p = (struct dcons_port *)e->udata; - if (e->ident == p->s) { - dconschat_accept_socket(dc, p); - } else { - dconschat_read_socket(dc, p); - } - } - return(0); -} - -static int -dconschat_proc_dcons(struct dcons_state *dc) -{ - int port, len, err; - char buf[MAX_XFER]; - struct dcons_port *p; - - err = dconschat_get_ptr(dc); - if (err) { - /* XXX we should stop write operation too. */ - return err; - } - for (port = 0; port < DCONS_NPORT; port ++) { - p = &dc->port[port]; - if (p->infd < 0) - continue; - while ((len = dconschat_read_dcons(dc, port, buf, - sizeof(buf))) > 0) { - dconschat_write_socket(p->outfd, buf, len); - if ((err = dconschat_get_ptr(dc))) - return (err); - } - if ((dc->flags & F_ONE_SHOT) != 0 && len <= 0) - dconschat_cleanup(0); - } - return 0; -} - -static int -dconschat_start_session(struct dcons_state *dc) -{ - int counter = 0; - int retry = 0; - int retry_unit_init = MAX(1, poll_hz / 10); - int retry_unit_offline = poll_hz * DCONS_POLL_OFFLINE; - int retry_unit = retry_unit_init; - int retry_max = retry_unit_offline / retry_unit; - - while (1) { - if (((dc->flags & F_READY) == 0) && ++counter > retry_unit) { - counter = 0; - retry ++; - if (retry > retry_max) - retry_unit = retry_unit_offline; - if (verbose) { - printf("%d/%d ", retry, retry_max); - fflush(stdout); - } - dconschat_fetch_header(dc); - } - if ((dc->flags & F_READY) != 0) { - counter = 0; - retry = 0; - retry_unit = retry_unit_init; - dconschat_proc_dcons(dc); - } - dconschat_proc_socket(dc); - } - return (0); -} - -static void -usage(void) -{ - fprintf(stderr, - "usage: dconschat [-brvwRT1] [-h hz] [-C port] [-G port]\n" - "\t\t\t[-M core] [-N system]\n" - "\t\t\t[-u unit] [-a address] [-t target_eui64]\n" - "\t-b translate ctrl-C to CR+~+ctrl-B on gdb port\n" - "\t-v verbose\n" - "\t-w listen on wildcard address rather than localhost\n" - "\t-r replay old buffer on connection\n" - "\t-R read-only\n" - "\t-T enable Telnet protocol workaround on console port\n" - "\t-1 one shot: read buffer and exit\n" - "\t-h polling rate\n" - "\t-C port number for console port\n" - "\t-G port number for gdb port\n" - "\t(for KVM)\n" - "\t-M core file\n" - "\t-N system file\n" - "\t(for FireWire)\n" - "\t-u specify unit number of the bus\n" - "\t-t EUI64 of target host (must be specified)\n" - "\t-a physical address of dcons buffer on target host\n" - ); - exit(0); -} -int -main(int argc, char **argv) -{ - struct dcons_state *dc; - struct fw_eui64 eui; - struct eui64 target; - char devname[256], *core = NULL, *system = NULL; - int i, ch, error; - int unit=0, wildcard=0; - int port[DCONS_NPORT]; - - bzero(&sc, sizeof(sc)); - dc = ≻ - dc->flags |= USE_CROM ? F_USE_CROM : 0; - - /* default ports */ - port[0] = 0; /* stdin/out for console */ - port[1] = -1; /* disable gdb port */ - - /* default escape char */ - dc->escape = KEY_TILDE; - - while ((ch = getopt(argc, argv, "a:be:h:rt:u:vwC:G:M:N:RT1")) != -1) { - switch(ch) { - case 'a': - dc->paddr = strtoull(optarg, NULL, 0); - dc->flags &= ~F_USE_CROM; - break; - case 'b': - dc->flags |= F_ALT_BREAK; - break; - case 'e': - dc->escape = optarg[0]; - break; - case 'h': - poll_hz = strtoul(optarg, NULL, 0); - if (poll_hz == 0) - poll_hz = DCONS_POLL_HZ; - break; - case 'r': - dc->flags |= F_REPLAY; - break; - case 't': - if (eui64_hostton(optarg, &target) != 0 && - eui64_aton(optarg, &target) != 0) - errx(1, "invalid target: %s", optarg); - eui.hi = ntohl(*(u_int32_t*)&(target.octet[0])); - eui.lo = ntohl(*(u_int32_t*)&(target.octet[4])); - dc->type = TYPE_FW; - break; - case 'u': - unit = strtol(optarg, NULL, 0); - break; - case 'v': - verbose ++; - break; - case 'w': - wildcard = 1; - break; - case 'C': - port[0] = strtol(optarg, NULL, 0); - break; - case 'G': - port[1] = strtol(optarg, NULL, 0); - break; - case 'M': - core = optarg; - break; - case 'N': - system = optarg; - break; - case 'R': - dc->flags |= F_RD_ONLY; - break; - case 'T': - dc->flags |= F_TELNET; - break; - case '1': - dc->flags |= F_ONE_SHOT | F_REPLAY; - break; - default: - usage(); - } - } - if (dc->paddr == 0 && (dc->flags & F_USE_CROM) == 0) { - warnx("no address specified"); - usage(); - } - - if (port[0] < 0 && port[1] < 0) { - warnx("no port specified"); - usage(); - } - - /* set signal handler */ - signal(SIGHUP, dconschat_cleanup); - signal(SIGINT, dconschat_cleanup); - signal(SIGPIPE, dconschat_cleanup); - signal(SIGTERM, dconschat_cleanup); - - /* init firewire */ - switch (dc->type) { - case TYPE_FW: -#define MAXDEV 10 - for (i = 0; i < MAXDEV; i ++) { - snprintf(devname, sizeof(devname), - "/dev/fwmem%d.%d", unit, i); - dc->fd = open(devname, O_RDWR); - if (dc->fd >= 0) - goto found; - } - err(1, "open"); -found: - error = ioctl(dc->fd, FW_SDEUI64, &eui); - if (error) - err(1, "ioctl"); - break; - case TYPE_KVM: - { - struct nlist nl[] = {{"dcons_buf"}, {""}}; - void *dcons_buf; - - dc->kd = kvm_open(system, core, NULL, - (dc->flags & F_RD_ONLY) ? O_RDONLY : O_RDWR, "dconschat"); - if (dc->kd == NULL) - errx(1, "kvm_open"); - - if (kvm_nlist(dc->kd, nl) < 0) - errx(1, "kvm_nlist: %s", kvm_geterr(dc->kd)); - - if (kvm_read(dc->kd, nl[0].n_value, &dcons_buf, - sizeof(void *)) < 0) - errx(1, "kvm_read: %s", kvm_geterr(dc->kd)); - dc->paddr = (uintptr_t)dcons_buf; - if (verbose) - printf("dcons_buf: 0x%x\n", (uint)dc->paddr); - break; - } - } - dconschat_fetch_header(dc); - - /* init sockets */ - dc->kq = kqueue(); - if (poll_hz == 1) { - dc->to.tv_sec = 1; - dc->to.tv_nsec = 0; - } else { - dc->to.tv_sec = 0; - dc->to.tv_nsec = 1000 * 1000 * 1000 / poll_hz; - } - dc->zero.tv_sec = 0; - dc->zero.tv_nsec = 0; - for (i = 0; i < DCONS_NPORT; i++) - dconschat_init_socket(dc, i, - wildcard ? NULL : "localhost", port[i]); - - dconschat_start_session(dc); - - for (i = 0; i < DCONS_NPORT; i++) { - freeaddrinfo(dc->port[i].res); - } - return (0); -} diff --git a/usr.sbin/devinfo/Makefile b/usr.sbin/devinfo/Makefile deleted file mode 100644 index 2a2301b..0000000 --- a/usr.sbin/devinfo/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $FreeBSD$ - -PROG= devinfo -MAN= devinfo.8 - -DPADD= ${LIBDEVINFO} -LDADD= -ldevinfo - -.include diff --git a/usr.sbin/devinfo/devinfo.8 b/usr.sbin/devinfo/devinfo.8 deleted file mode 100644 index ecb3b01..0000000 --- a/usr.sbin/devinfo/devinfo.8 +++ /dev/null @@ -1,76 +0,0 @@ -.\" -*- nroff -*- -.\" -.\" Copyright (c) 2002 Hiten Pandya -.\" Copyright (c) 2002 Robert N. M. Watson -.\" -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd November 28, 2005 -.Dt DEVINFO 8 -.Os -.Sh NAME -.Nm devinfo -.Nd print information about system device configuration -.Sh SYNOPSIS -.Nm -.Op Fl rv -.Nm -.Fl u -.Sh DESCRIPTION -The -.Nm -utility, without any arguments, shows the hierarchy of devices available -in the system, starting from the -.Dq nexus -device. -.Pp -The following options are accepted. -.Bl -tag -width indent -.It Fl r -Causes hardware resource information (such as IRQ, I/O ports, I/O memory -addresses) to be also listed, under each device that has reserved those resources. -.It Fl u -Displays the same information as with -.Fl r -but sorts by resource type rather than by device, allowing to review the -set of system resources by usage and available resources. -I.e., it lists all -the IRQ consumers together. -.It Fl v -Display all devices in the driver tree, not just those that are attached or -busy. -Without this flag, only those devices that have attached are reported. -.El -.Sh SEE ALSO -.Xr systat 1 , -.Xr devinfo 3 , -.Xr iostat 8 , -.Xr pciconf 8 , -.Xr pnpinfo 8 , -.Xr vmstat 8 , -.Xr devclass 9 , -.Xr device 9 -.Sh AUTHORS -.An Mike Smith Aq msmith@FreeBSD.org diff --git a/usr.sbin/devinfo/devinfo.c b/usr.sbin/devinfo/devinfo.c deleted file mode 100644 index 73dcfd5..0000000 --- a/usr.sbin/devinfo/devinfo.c +++ /dev/null @@ -1,233 +0,0 @@ -/*- - * Copyright (c) 2000, 2001 Michael Smith - * Copyright (c) 2000 BSDi - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Print information about system device configuration. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include "devinfo.h" - -int rflag; -int vflag; - -static void print_resource(struct devinfo_res *); -static int print_device_matching_resource(struct devinfo_res *, void *); -static int print_device_rman_resources(struct devinfo_rman *, void *); -static int print_device(struct devinfo_dev *, void *); -static int print_rman_resource(struct devinfo_res *, void *); -static int print_rman(struct devinfo_rman *, void *); - -struct indent_arg -{ - int indent; - void *arg; -}; - -/* - * Print a resource. - */ -void -print_resource(struct devinfo_res *res) -{ - struct devinfo_rman *rman; - int hexmode; - - rman = devinfo_handle_to_rman(res->dr_rman); - hexmode = (rman->dm_size > 1000) || (rman->dm_size == 0); - printf(hexmode ? "0x%lx" : "%lu", res->dr_start); - if (res->dr_size > 1) - printf(hexmode ? "-0x%lx" : "-%lu", - res->dr_start + res->dr_size - 1); -} - -/* - * Print resource information if this resource matches the - * given device. - * - * If the given indent is 0, return an indicator that a matching - * resource exists. - */ -int -print_device_matching_resource(struct devinfo_res *res, void *arg) -{ - struct indent_arg *ia = (struct indent_arg *)arg; - struct devinfo_dev *dev = (struct devinfo_dev *)ia->arg; - int i; - - if (devinfo_handle_to_device(res->dr_device) == dev) { - /* in 'detect' mode, found a match */ - if (ia->indent == 0) - return(1); - for (i = 0; i < ia->indent; i++) - printf(" "); - print_resource(res); - printf("\n"); - } - return(0); -} - -/* - * Print resource information for this device and resource manager. - */ -int -print_device_rman_resources(struct devinfo_rman *rman, void *arg) -{ - struct indent_arg *ia = (struct indent_arg *)arg; - int indent, i; - - indent = ia->indent; - - /* check whether there are any resources matching this device */ - ia->indent = 0; - if (devinfo_foreach_rman_resource(rman, - print_device_matching_resource, ia) != 0) { - - /* there are, print header */ - for (i = 0; i < indent; i++) - printf(" "); - printf("%s:\n", rman->dm_desc); - - /* print resources */ - ia->indent = indent + 4; - devinfo_foreach_rman_resource(rman, - print_device_matching_resource, ia); - } - ia->indent = indent; - return(0); -} - -/* - * Print information about a device. - */ -int -print_device(struct devinfo_dev *dev, void *arg) -{ - struct indent_arg ia; - int i, indent; - - if (vflag || (dev->dd_name[0] != 0 && dev->dd_state >= DS_ATTACHED)) { - indent = (int)(intptr_t)arg; - for (i = 0; i < indent; i++) - printf(" "); - printf("%s", dev->dd_name[0] ? dev->dd_name : "unknown"); - if (vflag && *dev->dd_pnpinfo) - printf(" pnpinfo %s", dev->dd_pnpinfo); - if (vflag && *dev->dd_location) - printf(" at %s", dev->dd_location); - printf("\n"); - if (rflag) { - ia.indent = indent + 4; - ia.arg = dev; - devinfo_foreach_rman(print_device_rman_resources, - (void *)&ia); - } - } - - return(devinfo_foreach_device_child(dev, print_device, - (void *)((char *)arg + 2))); -} - -/* - * Print information about a resource under a resource manager. - */ -int -print_rman_resource(struct devinfo_res *res, void *arg __unused) -{ - struct devinfo_dev *dev; - - printf(" "); - print_resource(res); - dev = devinfo_handle_to_device(res->dr_device); - if ((dev != NULL) && (dev->dd_name[0] != 0)) { - printf(" (%s)", dev->dd_name); - } else { - printf(" ----"); - } - printf("\n"); - return(0); -} - -/* - * Print information about a resource manager. - */ -int -print_rman(struct devinfo_rman *rman, void *arg __unused) -{ - printf("%s:\n", rman->dm_desc); - devinfo_foreach_rman_resource(rman, print_rman_resource, 0); - return(0); -} - -int -main(int argc, char *argv[]) -{ - struct devinfo_dev *root; - int c, uflag; - - uflag = 0; - while ((c = getopt(argc, argv, "ruv")) != -1) { - switch(c) { - case 'r': - rflag++; - break; - case 'u': - uflag++; - break; - case 'v': - vflag++; - break; - default: - fprintf(stderr, "%s\n%s\n", - "usage: devinfo [-rv]", - " devinfo -u"); - exit(1); - } - } - - if (devinfo_init()) - err(1, "devinfo_init"); - - if ((root = devinfo_handle_to_device(DEVINFO_ROOT_DEVICE)) == NULL) - errx(1, "can't find root device"); - - /* print resource usage? */ - if (uflag) { - devinfo_foreach_rman(print_rman, NULL); - } else { - /* print device hierarchy */ - devinfo_foreach_device_child(root, print_device, (void *)0); - } - return(0); -} diff --git a/usr.sbin/digictl/Makefile b/usr.sbin/digictl/Makefile deleted file mode 100644 index cb3745b..0000000 --- a/usr.sbin/digictl/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= digictl -MAN= digictl.8 - -.include diff --git a/usr.sbin/digictl/digictl.8 b/usr.sbin/digictl/digictl.8 deleted file mode 100644 index 2ac98ea..0000000 --- a/usr.sbin/digictl/digictl.8 +++ /dev/null @@ -1,118 +0,0 @@ -.\" $FreeBSD$ -.Dd June 20, 2001 -.Dt DIGICTL 8 -.Os -.Sh NAME -.Nm digictl -.Nd control -.Tn Digiboard -devices -.Sh SYNOPSIS -.Nm -.Fl a -.Cm disable | enable | query -.Ar device ... -.Nm -.Op Fl d Ar debug -.Op Fl ir -.Ar ctrl-device ... -.Sh DESCRIPTION -The -.Nm -utility provides control of the -.Tn Digiboard -installed with the given -.Ar ctrl-device -name and provides control of individual digiboard -.Ar devices . -A digiboard -.Ar ctrl-device -is usually of the form -.Sm off -.Pa /dev/digi Ar N Pa .ctl -.Sm on -where -.Ar N -is the card number and starts at -.Dq 0 -for the first attached card. -A digiboard -.Ar device -is usually of the form -.Sm off -.Pa /dev/cua Oo Pa il Oc Pa D Ar N Pa \&. Ar P -.Sm on -or -.Sm off -.Pa /dev/tty Oo Pa il Oc Pa D Ar N Pa \&. Ar P -.Sm on -where -.Ar N -is the card number and -.Ar P -is the port number. -.Pp -The following flags are recognized: -.Bl -tag -.It Fl a Cm disable | enable | query -Disable, enable or query the -.Em ALTPIN -settings for the given port(s). -.Pp -When ALTPIN is enabled, the CD and DSR lines are logically reversed. -This is useful when wiring serial ports to an 8 way RJ45 cable (full -10 way RJ45 cables are quite rare). -.Pp -A single ALTPIN setting applies to both of the callout and callin devices. -.It Fl d Ar debug -If the driver has been compiled with -.Dv DEBUG -defined, the following bits from the -.Ar debug -variable are used to enable diagnostics in the digiboard driver: -.Bl -tag -width ".No 1024 ( Em MODEM )" -.It 1 ( Em INIT ) -Diagnostics during card attach, detach and initialization. -.It 2 ( Em OPEN ) -Diagnostics when opening a port. -.It 4 ( Em CLOSE ) -Diagnostics when closing a port. -.It 8 ( Em SET ) -Diagnostics when setting tty device flags. -.It 16 ( Em INT ) -Diagnostics when processing card events. -.It 32 ( Em READ ) -Reports return values from port reads. -.It 64 ( Em WRITE ) -Reports return values from port writes. -.It 128 ( Em RX ) -Reports receive queue flow control. -.It 256 ( Em TX ) -Reports transmit queue flow control. -.It 512 ( Em IRQ ) -Diagnostics during interrupts (enable these with care). -.It 1024 ( Em MODEM ) -Diagnostics when setting modem status flags. -.It 2048 ( Em RI ) -Reports when a RING is received. -.El -.It Fl i -Display the card identification string and type ID. -.It Fl r -Reinitialize the card. -For boards with external port modules, it is possible to add or remove -modules and dynamically reprobe the number of ports using this switch. -All ports on the card must be closed in order to reinitialize the card. -.Pp -It is preferable to reinitialize the card rather than reload the entire -digi module as reinitialization only affects the specified board rather -than affecting all attached boards. -.El -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 5.0 . -.Sh BUGS -It should be possible to reinitialize a board without closing all of the -existing ports. diff --git a/usr.sbin/digictl/digictl.c b/usr.sbin/digictl/digictl.c deleted file mode 100644 index 0aa5f68..0000000 --- a/usr.sbin/digictl/digictl.c +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * Copyright (c) 2001 Brian Somers - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum aflag { NO_AFLAG, ALTPIN_DISABLE, ALTPIN_ENABLE, ALTPIN_QUERY }; - -static int -usage(const char *prog) -{ - fprintf(stderr, "usage: %s -a disable|enable|query device\n", prog); - fprintf(stderr, " %s [-d debug] [-ir] ctrl-device...\n", prog); - return (EX_USAGE); -} - -int -main(int argc, char **argv) -{ - char namedata[256], *name = namedata; - const char *prog; - enum digi_model model; - int altpin, ch, debug, fd, i, res; - int dflag, iflag, rflag; - enum aflag aflag; - - if ((prog = strrchr(argv[0], '/')) == NULL) - prog = argv[0]; - else - prog++; - - aflag = NO_AFLAG; - dflag = iflag = rflag = 0; - while ((ch = getopt(argc, argv, "a:d:ir")) != -1) - switch (ch) { - case 'a': - if (strcasecmp(optarg, "disable") == 0) - aflag = ALTPIN_DISABLE; - else if (strcasecmp(optarg, "enable") == 0) - aflag = ALTPIN_ENABLE; - else if (strcasecmp(optarg, "query") == 0) - aflag = ALTPIN_QUERY; - else - return (usage(prog)); - break; - - case 'd': - dflag = 1; - debug = atoi(optarg); - break; - - case 'i': - iflag = 1; - break; - - case 'r': - rflag = 1; - break; - - default: - return (usage(prog)); - } - - if ((dflag || iflag || rflag) && aflag != NO_AFLAG) - return (usage(prog)); - - if (argc <= optind) - return (usage(prog)); - - altpin = (aflag == ALTPIN_ENABLE); - res = 0; - - for (i = optind; i < argc; i++) { - if ((fd = open(argv[i], O_RDONLY)) == -1) { - fprintf(stderr, "%s: %s: open: %s\n", prog, argv[i], - strerror(errno)); - res++; - continue; - } - - switch (aflag) { - case NO_AFLAG: - break; - - case ALTPIN_ENABLE: - case ALTPIN_DISABLE: - if (ioctl(fd, DIGIIO_SETALTPIN, &altpin) != 0) { - fprintf(stderr, "%s: %s: set altpin: %s\n", - prog, argv[i], strerror(errno)); - res++; - } - break; - - case ALTPIN_QUERY: - if (ioctl(fd, DIGIIO_GETALTPIN, &altpin) != 0) { - fprintf(stderr, "%s: %s: get altpin: %s\n", - prog, argv[i], strerror(errno)); - res++; - } else { - if (argc > optind + 1) - printf("%s: ", argv[i]); - puts(altpin ? "enabled" : "disabled"); - } - break; - } - - if (dflag && ioctl(fd, DIGIIO_DEBUG, &debug) != 0) { - fprintf(stderr, "%s: %s: debug: %s\n", - prog, argv[i], strerror(errno)); - res++; - } - - if (iflag) { - if (ioctl(fd, DIGIIO_MODEL, &model) != 0) { - fprintf(stderr, "%s: %s: model: %s\n", - prog, argv[i], strerror(errno)); - res++; - } else if (ioctl(fd, DIGIIO_IDENT, &name) != 0) { - fprintf(stderr, "%s: %s: ident: %s\n", - prog, argv[i], strerror(errno)); - res++; - } else { - if (argc > optind + 1) - printf("%s: ", argv[i]); - printf("%s (type %d)\n", name, (int)model); - } - } - - if (rflag && ioctl(fd, DIGIIO_REINIT) != 0) { - fprintf(stderr, "%s: %s: reinit: %s\n", - prog, argv[i], strerror(errno)); - res++; - } - - close(fd); - } - - return (res); -} diff --git a/usr.sbin/diskinfo/Makefile b/usr.sbin/diskinfo/Makefile deleted file mode 100644 index b16b933..0000000 --- a/usr.sbin/diskinfo/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $FreeBSD$ - -PROG= diskinfo -MAN= diskinfo.8 - -DPADD= ${LIBUTIL} -LDADD= -lutil - -.include - -test: ${PROG} - ./${PROG} /dev/ad4 md50 - ./${PROG} -v /dev/ad4 md50 - ./${PROG} -t /dev/ad4 diff --git a/usr.sbin/diskinfo/diskinfo.8 b/usr.sbin/diskinfo/diskinfo.8 deleted file mode 100644 index f68d426..0000000 --- a/usr.sbin/diskinfo/diskinfo.8 +++ /dev/null @@ -1,74 +0,0 @@ -.\" -.\" Copyright (c) 2003 Poul-Henning Kamp -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The names of the authors may not be used to endorse or promote -.\" products derived from this software without specific prior written -.\" permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd November 9, 2004 -.Dt DISKINFO 8 -.Os -.Sh NAME -.Nm diskinfo -.Nd get information about disk device -.Sh SYNOPSIS -.Nm -.Op Fl ctv -.Ar disk ... -.Sh DESCRIPTION -The -.Nm -utility prints out information about a disk device, -and optionally runs a naive performance test on the device. -.Pp -If given no arguments, the output will be a single line per specified device -with the following fields: device name, sectorsize, media size in bytes, -media size in sectors, stripe size, stripe offset, firmware cylinders, -firmware heads, and firmware sectors. -The last three fields are only present if the information is available. -.Pp -If given the -.Fl v -option, the fields will be printed one per line with a descriptive comment. -.Pp -The -.Fl c -option triggers a simple measurement of the I/O read command overhead. -.Pp -The -.Fl t -option triggers a simple and rather naive benchmark of the disks seek -and transfer performance. -.Sh HISTORY -The -.Nm -command appeared in -.Fx 5.1 . -.Sh AUTHORS -.An Poul-Henning Kamp -.Sh BUGS -There are in order of increasing severity: lies, -damn lies, statistics, and computer benchmarks. diff --git a/usr.sbin/diskinfo/diskinfo.c b/usr.sbin/diskinfo/diskinfo.c deleted file mode 100644 index 1f967b7..0000000 --- a/usr.sbin/diskinfo/diskinfo.c +++ /dev/null @@ -1,364 +0,0 @@ -/*- - * Copyright (c) 2003 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The names of the authors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static void -usage(void) -{ - fprintf(stderr, "usage: diskinfo [-ctv] disk ...\n"); - exit (1); -} - -static int opt_c, opt_t, opt_v; - -static void speeddisk(int fd, off_t mediasize, u_int sectorsize); -static void commandtime(int fd, off_t mediasize, u_int sectorsize); - -int -main(int argc, char **argv) -{ - int i, ch, fd, error; - char buf[BUFSIZ], ident[DISK_IDENT_SIZE]; - off_t mediasize, stripesize, stripeoffset; - u_int sectorsize, fwsectors, fwheads; - - while ((ch = getopt(argc, argv, "ctv")) != -1) { - switch (ch) { - case 'c': - opt_c = 1; - opt_v = 1; - break; - case 't': - opt_t = 1; - opt_v = 1; - break; - case 'v': - opt_v = 1; - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc < 1) - usage(); - - for (i = 0; i < argc; i++) { - fd = open(argv[i], O_RDONLY); - if (fd < 0 && errno == ENOENT && *argv[i] != '/') { - sprintf(buf, "%s%s", _PATH_DEV, argv[i]); - fd = open(buf, O_RDONLY); - } - if (fd < 0) - err(1, argv[i]); - error = ioctl(fd, DIOCGMEDIASIZE, &mediasize); - if (error) - err(1, "%s: ioctl(DIOCGMEDIASIZE) failed, probably not a disk.", argv[i]); - error = ioctl(fd, DIOCGSECTORSIZE, §orsize); - if (error) - err(1, "%s: DIOCGSECTORSIZE failed, probably not a disk.", argv[i]); - error = ioctl(fd, DIOCGFWSECTORS, &fwsectors); - if (error) - fwsectors = 0; - error = ioctl(fd, DIOCGFWHEADS, &fwheads); - if (error) - fwheads = 0; - error = ioctl(fd, DIOCGSTRIPESIZE, &stripesize); - if (error) - stripesize = 0; - error = ioctl(fd, DIOCGSTRIPEOFFSET, &stripeoffset); - if (error) - stripeoffset = 0; - if (!opt_v) { - printf("%s", argv[i]); - printf("\t%u", sectorsize); - printf("\t%jd", (intmax_t)mediasize); - printf("\t%jd", (intmax_t)mediasize/sectorsize); - printf("\t%jd", (intmax_t)stripesize); - printf("\t%jd", (intmax_t)stripeoffset); - if (fwsectors != 0 && fwheads != 0) { - printf("\t%jd", (intmax_t)mediasize / - (fwsectors * fwheads * sectorsize)); - printf("\t%u", fwheads); - printf("\t%u", fwsectors); - } - } else { - humanize_number(buf, 5, (int64_t)mediasize, "", - HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL); - printf("%s\n", argv[i]); - printf("\t%-12u\t# sectorsize\n", sectorsize); - printf("\t%-12jd\t# mediasize in bytes (%s)\n", - (intmax_t)mediasize, buf); - printf("\t%-12jd\t# mediasize in sectors\n", - (intmax_t)mediasize/sectorsize); - printf("\t%-12jd\t# stripesize\n", stripesize); - printf("\t%-12jd\t# stripeoffset\n", stripeoffset); - if (fwsectors != 0 && fwheads != 0) { - printf("\t%-12jd\t# Cylinders according to firmware.\n", (intmax_t)mediasize / - (fwsectors * fwheads * sectorsize)); - printf("\t%-12u\t# Heads according to firmware.\n", fwheads); - printf("\t%-12u\t# Sectors according to firmware.\n", fwsectors); - } - if (ioctl(fd, DIOCGIDENT, ident) == 0) - printf("\t%-12s\t# Disk ident.\n", ident); - } - printf("\n"); - if (opt_c) - commandtime(fd, mediasize, sectorsize); - if (opt_t) - speeddisk(fd, mediasize, sectorsize); - close(fd); - } - exit (0); -} - - -static char sector[65536]; -static char mega[1024 * 1024]; - -static void -rdsect(int fd, u_int blockno, u_int sectorsize) -{ - int error; - - lseek(fd, (off_t)blockno * sectorsize, SEEK_SET); - error = read(fd, sector, sectorsize); - if (error != (int)sectorsize) - err(1, "read error or disk too small for test."); -} - -static void -rdmega(int fd) -{ - int error; - - error = read(fd, mega, sizeof(mega)); - if (error != sizeof(mega)) - err(1, "read error or disk too small for test."); -} - -static struct timeval tv1, tv2; - -static void -T0(void) -{ - - fflush(stdout); - sync(); - sleep(1); - sync(); - sync(); - gettimeofday(&tv1, NULL); -} - -static void -TN(int count) -{ - double dt; - - gettimeofday(&tv2, NULL); - dt = (tv2.tv_usec - tv1.tv_usec) / 1e6; - dt += (tv2.tv_sec - tv1.tv_sec); - printf("%5d iter in %10.6f sec = %8.3f msec\n", - count, dt, dt * 1000.0 / count); -} - -static void -TR(double count) -{ - double dt; - - gettimeofday(&tv2, NULL); - dt = (tv2.tv_usec - tv1.tv_usec) / 1e6; - dt += (tv2.tv_sec - tv1.tv_sec); - printf("%8.0f kbytes in %10.6f sec = %8.0f kbytes/sec\n", - count, dt, count / dt); -} - -static void -speeddisk(int fd, off_t mediasize, u_int sectorsize) -{ - int i; - uint b0, b1, sectorcount; - - sectorcount = mediasize / sectorsize; - - printf("Seek times:\n"); - printf("\tFull stroke:\t"); - b0 = 0; - b1 = sectorcount - 1 - 16384; - T0(); - for (i = 0; i < 125; i++) { - rdsect(fd, b0, sectorsize); - b0 += 16384; - rdsect(fd, b1, sectorsize); - b1 -= 16384; - } - TN(250); - - printf("\tHalf stroke:\t"); - b0 = sectorcount / 4; - b1 = b0 + sectorcount / 2; - T0(); - for (i = 0; i < 125; i++) { - rdsect(fd, b0, sectorsize); - b0 += 16384; - rdsect(fd, b1, sectorsize); - b1 += 16384; - } - TN(250); - printf("\tQuarter stroke:\t"); - b0 = sectorcount / 4; - b1 = b0 + sectorcount / 4; - T0(); - for (i = 0; i < 250; i++) { - rdsect(fd, b0, sectorsize); - b0 += 16384; - rdsect(fd, b1, sectorsize); - b1 += 16384; - } - TN(500); - - printf("\tShort forward:\t"); - b0 = sectorcount / 2; - T0(); - for (i = 0; i < 400; i++) { - rdsect(fd, b0, sectorsize); - b0 += 16384; - } - TN(400); - - printf("\tShort backward:\t"); - b0 = sectorcount / 2; - T0(); - for (i = 0; i < 400; i++) { - rdsect(fd, b0, sectorsize); - b0 -= 16384; - } - TN(400); - - printf("\tSeq outer:\t"); - b0 = 0; - T0(); - for (i = 0; i < 2048; i++) { - rdsect(fd, b0, sectorsize); - b0++; - } - TN(2048); - - printf("\tSeq inner:\t"); - b0 = sectorcount - 2048 - 1; - T0(); - for (i = 0; i < 2048; i++) { - rdsect(fd, b0, sectorsize); - b0++; - } - TN(2048); - - printf("Transfer rates:\n"); - printf("\toutside: "); - rdsect(fd, 0, sectorsize); - T0(); - for (i = 0; i < 100; i++) { - rdmega(fd); - } - TR(100 * 1024); - - printf("\tmiddle: "); - b0 = sectorcount / 2; - rdsect(fd, b0, sectorsize); - T0(); - for (i = 0; i < 100; i++) { - rdmega(fd); - } - TR(100 * 1024); - - printf("\tinside: "); - b0 = sectorcount - 100 * (1024*1024 / sectorsize) - 1;; - rdsect(fd, b0, sectorsize); - T0(); - for (i = 0; i < 100; i++) { - rdmega(fd); - } - TR(100 * 1024); - - printf("\n"); - return; -} - -static void -commandtime(int fd, off_t mediasize, u_int sectorsize) -{ - double dtmega, dtsector; - int i; - - printf("I/O command overhead:\n"); - i = mediasize; - rdsect(fd, 0, sectorsize); - T0(); - for (i = 0; i < 10; i++) - rdmega(fd); - gettimeofday(&tv2, NULL); - dtmega = (tv2.tv_usec - tv1.tv_usec) / 1e6; - dtmega += (tv2.tv_sec - tv1.tv_sec); - - printf("\ttime to read 10MB block %10.6f sec\t= %8.3f msec/sector\n", - dtmega, dtmega*100/2048); - - rdsect(fd, 0, sectorsize); - T0(); - for (i = 0; i < 20480; i++) - rdsect(fd, 0, sectorsize); - gettimeofday(&tv2, NULL); - dtsector = (tv2.tv_usec - tv1.tv_usec) / 1e6; - dtsector += (tv2.tv_sec - tv1.tv_sec); - - printf("\ttime to read 20480 sectors %10.6f sec\t= %8.3f msec/sector\n", - dtsector, dtsector*100/2048); - printf("\tcalculated command overhead\t\t\t= %8.3f msec/sector\n", - (dtsector - dtmega)*100/2048); - - printf("\n"); - return; -} diff --git a/usr.sbin/dnssec-dsfromkey/Makefile b/usr.sbin/dnssec-dsfromkey/Makefile deleted file mode 100644 index 0b57eb5..0000000 --- a/usr.sbin/dnssec-dsfromkey/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# $FreeBSD$ - -BIND_DIR= ${.CURDIR}/../../contrib/bind9 -LIB_BIND_REL= ../../lib/bind -LIB_BIND_DIR= ${.CURDIR}/${LIB_BIND_REL} -SRCDIR= ${BIND_DIR}/bin/dnssec - -.include "${LIB_BIND_DIR}/config.mk" - -PROG= dnssec-dsfromkey - -.PATH: ${SRCDIR} -SRCS+= dnssec-dsfromkey.c dnssectool.c - -CFLAGS+= -I${SRCDIR}/unix/include -I${SRCDIR}/include - -DPADD+= ${BIND_DPADD} ${CRYPTO_DPADD} ${PTHREAD_DPADD} -LDADD+= ${BIND_LDADD} ${CRYPTO_LDADD} ${PTHREAD_LDADD} - -WARNS?= 3 - -MAN= dnssec-dsfromkey.8 - -.include diff --git a/usr.sbin/dnssec-keyfromlabel/Makefile b/usr.sbin/dnssec-keyfromlabel/Makefile deleted file mode 100644 index fd6a341..0000000 --- a/usr.sbin/dnssec-keyfromlabel/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# $FreeBSD$ - -BIND_DIR= ${.CURDIR}/../../contrib/bind9 -LIB_BIND_REL= ../../lib/bind -LIB_BIND_DIR= ${.CURDIR}/${LIB_BIND_REL} -SRCDIR= ${BIND_DIR}/bin/dnssec - -.include "${LIB_BIND_DIR}/config.mk" - -PROG= dnssec-keyfromlabel - -.PATH: ${SRCDIR} -SRCS+= dnssec-keyfromlabel.c dnssectool.c - -CFLAGS+= -I${SRCDIR}/unix/include -I${SRCDIR}/include - -DPADD+= ${BIND_DPADD} ${CRYPTO_DPADD} ${PTHREAD_DPADD} -LDADD+= ${BIND_LDADD} ${CRYPTO_LDADD} ${PTHREAD_LDADD} - -WARNS?= 3 - -MAN= dnssec-keyfromlabel.8 - -.include diff --git a/usr.sbin/dnssec-keygen/Makefile b/usr.sbin/dnssec-keygen/Makefile deleted file mode 100644 index 1bdf0c0..0000000 --- a/usr.sbin/dnssec-keygen/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# $FreeBSD$ - -BIND_DIR= ${.CURDIR}/../../contrib/bind9 -LIB_BIND_REL= ../../lib/bind -LIB_BIND_DIR= ${.CURDIR}/${LIB_BIND_REL} -SRCDIR= ${BIND_DIR}/bin/dnssec - -.include "${LIB_BIND_DIR}/config.mk" - -PROG= dnssec-keygen - -.PATH: ${SRCDIR} -SRCS+= dnssec-keygen.c dnssectool.c - -CFLAGS+= -I${SRCDIR}/unix/include -I${SRCDIR}/include - -DPADD+= ${BIND_DPADD} ${CRYPTO_DPADD} ${PTHREAD_DPADD} -LDADD+= ${BIND_LDADD} ${CRYPTO_LDADD} ${PTHREAD_LDADD} - -WARNS?= 3 - -MAN= dnssec-keygen.8 - -.include diff --git a/usr.sbin/dnssec-signzone/Makefile b/usr.sbin/dnssec-signzone/Makefile deleted file mode 100644 index 70ddc3e..0000000 --- a/usr.sbin/dnssec-signzone/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# $FreeBSD$ - -BIND_DIR= ${.CURDIR}/../../contrib/bind9 -LIB_BIND_REL= ../../lib/bind -LIB_BIND_DIR= ${.CURDIR}/${LIB_BIND_REL} -SRCDIR= ${BIND_DIR}/bin/dnssec - -.include "${LIB_BIND_DIR}/config.mk" - -PROG= dnssec-signzone - -.PATH: ${SRCDIR} -SRCS+= dnssec-signzone.c dnssectool.c - -CFLAGS+= -I${SRCDIR}/unix/include -I${SRCDIR}/include - -DPADD+= ${BIND_DPADD} ${CRYPTO_DPADD} ${PTHREAD_DPADD} -LDADD+= ${BIND_LDADD} ${CRYPTO_LDADD} ${PTHREAD_LDADD} - -WARNS?= 3 - -MAN= dnssec-signzone.8 - -.include diff --git a/usr.sbin/dumpcis/Makefile b/usr.sbin/dumpcis/Makefile deleted file mode 100644 index 7a5a590..0000000 --- a/usr.sbin/dumpcis/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# pccardc Makefile -# -# $FreeBSD$ - -PROG= dumpcis -MAN= dumpcis.8 -SRCS= main.c readcis.c printcis.c - -.include diff --git a/usr.sbin/dumpcis/cardinfo.h b/usr.sbin/dumpcis/cardinfo.h deleted file mode 100644 index 9489067..0000000 --- a/usr.sbin/dumpcis/cardinfo.h +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Include file for PCMCIA user process interface - * - *------------------------------------------------------------------------- - */ -/*- - * Copyright (c) 1995 Andrew McRae. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/* $FreeBSD$ */ - -#ifndef _PCCARD_CARDINFO_H_ -#define _PCCARD_CARDINFO_H_ - -#ifndef _KERNEL -#include -#endif -#include - -#define PIOCGSTATE _IOR('P', 1, struct slotstate) /* Get slot state */ -#define PIOCGMEM _IOWR('P', 2, struct mem_desc) /* Get memory map */ -#define PIOCSMEM _IOW('P', 3, struct mem_desc) /* Set memory map */ -#define PIOCGIO _IOWR('P', 4, struct io_desc) /* Get I/O map */ -#define PIOCSIO _IOW('P', 5, struct io_desc) /* Set I/O map */ -#define PIOCSDRV _IOWR('P', 6, struct dev_desc) /* Set driver */ -#define PIOCRWFLAG _IOW('P', 7, int) /* Set flags for drv use */ -#define PIOCRWMEM _IOWR('P', 8, unsigned long) /* Set mem for drv use */ -#define PIOCSPOW _IOW('P', 9, struct power) /* Set power structure */ -#define PIOCSVIR _IOW('P', 10, int) /* Virtual insert/remove */ -#define PIOCSBEEP _IOW('P', 11, int) /* Select Beep */ -#define PIOCSRESOURCE _IOWR('P', 12, struct pccard_resource) /* get resource info */ -/* - * Debug codes. - */ -#define PIOCGREG _IOWR('P',100, struct pcic_reg) /* get reg */ -#define PIOCSREG _IOW('P', 101, struct pcic_reg) /* Set reg */ - -/* - * Slot states for PIOCGSTATE - * - * Here's a state diagram of all the possible states: - * - * power x 1 - * ------------------- - * / \ - * / v - * resume +----------+ power x 0 +----------+ - * ------->| inactive |<--------------| filled | - * / +----------+ +----------+ - * / / \ ^ | - * nil <--------- \ insert or | | suspend or - * suspend \ power x 1 | | eject - * \ | v - * \ +----------+ - * ----------->| empty | - * eject +----------+ - * - * Note, the above diagram is for the state. On suspend, the laststate - * gets set to suspend to tell pccardd what happened. Also the nil state - * means that when the no state change has happened. Note: if you eject - * while suspended in the inactive state, you will return to the - * empty state if you do not insert a new card and to the inactive state - * if you do insert a new card. - * - * Some might argue that inactive should be sticky forever and - * eject/insert shouldn't take it out of that state. They might be - * right. On the other hand, some would argue that eject resets all - * state. They might be right. They both can't be right. The above - * represents a reasonable compromise between the two. - * - * Some bridges allow one to query to see if the card was changed while - * we were suspended. Others do not. We make no use of this functionality - * at this time. - */ -enum cardstate { noslot, empty, suspend, filled, inactive }; - -/* - * Descriptor structure for memory map. - */ -struct mem_desc { - int window; /* Memory map window number (0-4) */ - int flags; /* Flags - see below */ - caddr_t start; /* System memory start */ - int size; /* Size of memory area */ - unsigned long card; /* Card memory address */ -}; - -#define MDF_16BITS 0x01 /* Memory is 16 bits wide */ -#define MDF_ZEROWS 0x02 /* Set no wait states for memory */ -#define MDF_WS0 0x04 /* Wait state flags */ -#define MDF_WS1 0x08 -#define MDF_ATTR 0x10 /* Memory is attribute memory */ -#define MDF_WP 0x20 /* Write protect memory */ -#define MDF_ACTIVE 0x40 /* Context active (read-only) */ - -/* - * Descriptor structure for I/O map - */ -struct io_desc { - int window; /* I/O map number (0-1) */ - int flags; /* Flags - see below */ - int start; /* I/O port start */ - int size; /* Number of port addresses */ -}; - -#define IODF_WS 0x01 /* Set wait states for 16 bit I/O access */ -#define IODF_16BIT 0x02 /* I/O access are 16 bit */ -#define IODF_CS16 0x04 /* Allow card selection of 16 bit access */ -#define IODF_ZEROWS 0x08 /* No wait states for 8 bit I/O */ -#define IODF_ACTIVE 0x10 /* Context active (read-only) */ - -/* - * Device descriptor for allocation of driver. - */ -#define DEV_MISC_LEN 36 -#define DEV_MAX_CIS_LEN 40 -struct dev_desc { - char name[16]; /* Driver name */ - int unit; /* Driver unit number */ - unsigned long mem; /* Memory address of driver */ - int memsize; /* Memory size (if used) */ - int iobase; /* base of I/O ports */ - int iosize; /* Length of I/O ports */ - int irqmask; /* Interrupt number(s) to allocate */ - int flags; /* Device flags */ - uint8_t misc[DEV_MISC_LEN]; /* For any random info */ - uint8_t manufstr[DEV_MAX_CIS_LEN]; - uint8_t versstr[DEV_MAX_CIS_LEN]; - uint8_t cis3str[DEV_MAX_CIS_LEN]; - uint8_t cis4str[DEV_MAX_CIS_LEN]; - uint32_t manufacturer; /* Manufacturer ID */ - uint32_t product; /* Product ID */ - uint32_t prodext; /* Product ID (extended) */ -}; -#define DEV_DESC_HAS_SIZE 1 - -struct pcic_reg { - unsigned char reg; - unsigned char value; -}; - -/* - * Slot information. Used to read current status of slot. - */ -struct slotstate { - enum cardstate state; /* Current state of slot */ - enum cardstate laststate; /* Previous state of slot */ - int maxmem; /* Max allowed memory windows */ - int maxio; /* Max allowed I/O windows */ - int irqs; /* Bitmap of IRQs allowed */ - int flags; /* Capability flags */ -}; - -/* - * The power values are in volts * 10, e.g. 5V is 50, 3.3V is 33. - */ -struct power { - int vcc; - int vpp; -}; - -/* - * The PC-Card resource IOC_GET_RESOURCE_RANGE - */ -struct pccard_resource { - int type; - u_long size; - u_long min; - u_long max; - u_long resource_addr; -}; - - -/* - * Other system limits - */ -#define MAXSLOT 16 -#define NUM_MEM_WINDOWS 10 -#define NUM_IO_WINDOWS 6 -#define CARD_DEVICE "/dev/card%d" /* String for snprintf */ -#define PCCARD_MEMSIZE (4*1024) - -#endif /* !_PCCARD_CARDINFO_H_ */ diff --git a/usr.sbin/dumpcis/cis.h b/usr.sbin/dumpcis/cis.h deleted file mode 100644 index 6cc935b..0000000 --- a/usr.sbin/dumpcis/cis.h +++ /dev/null @@ -1,279 +0,0 @@ -/* - * PCMCIA card structures and defines. - * These defines relate to the user level - * structures and card information, not - * driver/process communication. - *------------------------------------------------------------------------- - */ -/*- - * Copyright (c) 1995 Andrew McRae. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - * - */ - -/* - * Card Information Structure tuples definitions - * The structure of a tuple is basically: - * - * Tuple_code - * Tuple_data_length - * Tuple_data ... - * - * Tuples are contiguous in attribute memory, and - * are terminated with a 0xFF for the tuple code or - * the tuple length. - */ -#ifndef _PCCARD_CIS_H -#define _PCCARD_CIS_H - -#define CIS_NULL 0 /* Empty tuple */ -#define CIS_MEM_COMMON 0x01 /* Device descriptor, common memory */ -#define CIS_LONGLINK_CB 0x02 /* Long link to next chain for CardBus */ -#define CIS_INDIRECT 0x03 /* Indirect access */ -#define CIS_CONF_MAP_CB 0x04 /* Card Configuration map for CardBus */ -#define CIS_CONFIG_CB 0x05 /* Card Configuration entry for CardBus */ -#define CIS_LONGLINK_MFC 0x06 /* Long link to next chain for Multi function card */ -#define CIS_BAR 0x07 /* Base address register for CardBus */ -#define CIS_CHECKSUM 0x10 /* Checksum */ -#define CIS_LONGLINK_A 0x11 /* Link to Attribute memory */ -#define CIS_LONGLINK_C 0x12 /* Link to Common memory */ -#define CIS_LINKTARGET 0x13 /* Linked tuple must start with this. */ -#define CIS_NOLINK 0x14 /* Assume no common memory link tuple. */ -#define CIS_INFO_V1 0x15 /* Card info data, version 1 */ -#define CIS_ALTSTR 0x16 /* Alternate language string tuple. */ -#define CIS_MEM_ATTR 0x17 /* Device descriptor, Attribute memory */ -#define CIS_JEDEC_C 0x18 /* JEDEC descr for common memory */ -#define CIS_JEDEC_A 0x19 /* JEDEC descr for Attribute memory */ -#define CIS_CONF_MAP 0x1A /* Card Configuration map */ -#define CIS_CONFIG 0x1B /* Card Configuration entry */ -#define CIS_DEVICE_OC 0x1C /* Other conditions info - common memory */ -#define CIS_DEVICE_OA 0x1D /* Other conditions info - attribute memory */ -#define CIS_DEVICEGEO 0x1E /* Geometry info for common memory */ -#define CIS_DEVICEGEO_A 0x1F /* Geometry info for attribute memory */ -#define CIS_MANUF_ID 0x20 /* Card manufacturer's ID */ -#define CIS_FUNC_ID 0x21 /* Function of card */ -#define CIS_FUNC_EXT 0x22 /* Functional extension */ -/* - * Data recording format tuples. - */ -#define CIS_SW_INTERLV 0x23 /* Software interleave */ -#define CIS_VERS_2 0x40 /* Card info data, version 2 */ -#define CIS_FORMAT 0x41 /* Memory card format */ -#define CIS_GEOMETRY 0x42 /* Disk sector layout */ -#define CIS_BYTEORDER 0x43 /* Byte order of memory data */ -#define CIS_DATE 0x44 /* Format data/time */ -#define CIS_BATTERY 0x45 /* Battery replacement date */ -#define CIS_ORG 0x46 /* Organization of data on card */ -#define CIS_END 0xFF /* Termination code */ - -/* - * Internal tuple definitions. - * - * Device descriptor for memory (CIS_MEM_ATTR, CIS_MEM_COMMON) - * - * Byte 1: - * 0xF0 - Device type - * 0x08 - Write protect switch - * 0x07 - Speed index (7 = extended speed) - * Byte 2: Extended speed (bit 7 = another follows) - * Byte 3: (ignored if 0xFF) - * 0xF8 - Addressable units (0's numbered) - * 0x07 - Unit size - * The three byte sequence is repeated until byte 1 == 0xFF - */ - -/* - * CIS_INFO_V1 - Version one card information. - * - * Byte 1: Major version number (should be 4) - * Byte 2: Minor version number (should be 1) - * Byte 3-x: Null terminated Manufacturer name - * Byte x-x: Null terminated product name - * Byte x-x: Null terminated additional info 1 - * Byte x-x: Null terminated additional info 2 - * Byte x: final byte must be 0xFF - */ -#define CIS_MAJOR_VERSION 4 -#define CIS_MINOR_VERSION 1 - -/* - * CIS_CONF_MAP - Provides an address map for the card - * configuration register(s), and a max value - * identifying the last configuration tuple. - * - * Byte 1: - * 0x3C - Register mask size (0's numbered) - * 0x03 - Register address size (0's numbered) - * Byte 2: - * 0x3F - ID of last configuration. - * Byte 3-n: Card register address (size is determined by - * the value in byte 1). - * Byte x-x: Card register masks (size determined by the - * value in byte 1) - */ - -/* - * CIS_CONFIG - Card configuration entry. Multiple tuples may - * exist of this type, each one describing a different - * memory/I-O map that can be used to address this card. - * The first one usually has extra config data about the - * card features. The final configuration tuple number - * is stored in the CIS_CONF_MAP tuple so that the complete - * list can be scanned. - * - * Byte 1: - * 0x3F - Configuration ID number. - * 0x40 - Indicates this is the default configuration - * 0x80 - Interface byte exists - * Byte 2: (exists only if bit 0x80 set in byte 1) - * 0x0F - Interface type value - * 0x10 - Battery voltage detect - * 0x20 - Write protect active - * 0x40 - RdyBsy active bit - * 0x80 - Wait signal required - * Byte 3: (features byte) - * 0x03 - Power sub-tuple(s) exists - * 0x04 - Timing sub-tuple exists - * 0x08 - I/O space sub-tuple exists - * 0x10 - IRQ sub-tuple exists - * 0x60 - Memory space sub-tuple(s) exists - * 0x80 - Miscellaneous sub-tuple exists - */ -#define CIS_FEAT_POWER(x) ((x) & 0x3) -#define CIS_FEAT_TIMING 0x4 -#define CIS_FEAT_I_O 0x8 -#define CIS_FEAT_IRQ 0x10 -#define CIS_FEAT_MEMORY(x) (((x) >> 5) & 0x3) -#define CIS_FEAT_MISC 0x80 -/* - * Depending on whether the "features" byte has the corresponding - * bit set, a number of sub-tuples follow. Some features have - * more than one sub-tuple, depending on the count within the - * features byte (e.g power feature bits allows up to 3 sub-tuples). - * - * Power structure sub-tuple: - * Byte 1: parameter exists - Each bit (starting from 0x01) indicates - * that a parameter block exists - up to 8 parameter blocks - * are therefore allowed). - * Byte 2: - * 0x7F - Parameter data - * 0x80 - More bytes follow (0 = last byte) - * - * Timing sub-tuple - * Byte 1: - * 0x03 - Wait scale - * 0x1C - Ready scale - * 0xE0 - Reserved scale - * Byte 2: extended wait scale if wait scale != 3 - * Byte 3: extended ready scale if ready scale != 7 - * Byte 4: extended reserved scale if reserved scale != 7 - */ -#define CIS_WAIT_SCALE(x) ((x) & 0x3) -#define CIS_READY_SCALE(x) (((x)>>2) & 0x7) -#define CIS_RESERVED_SCALE(x) (((x)>>5) & 0x7) -/* - * I/O mapping sub-tuple: - * Byte 1: - * 0x1F - I/O address lines - * 0x20 - 8 bit I/O - * 0x40 - 16 bit I/O - * 0x80 - I/O range?? - * Byte 2: - * 0x0F - 0's numbered count of I/O block subtuples following. - * 0x30 - Size of I/O address value within subtuple. Values - * can be 1 (8 bits), 2 (16 bits) or 3 (32 bits). - * 0xC0 - Size of I/O port block size value within subtuple. - * I/O block sub-tuples, count from previous block: - * Byte 1-n: I/O start address - * Byte x-x: Size of I/O port block. - */ -#define CIS_IO_ADDR(x) ((x) & 0x1F) -#define CIS_IO_8BIT 0x20 -#define CIS_IO_16BIT 0x40 -#define CIS_IO_RANGE 0x80 -#define CIS_IO_BLKS(x) ((x) & 0xF) -#define CIS_IO_ADSZ(x) (((x)>>4) & 3) -#define CIS_IO_BLKSZ(x) (((x)>>6) & 3) -/* - * IRQ sub-tuple. - * Byte 1: - * 0x0F - Irq number or mask bits - * 0x10 - IRQ mask values exist - * 0x20 - Level triggered interrupts - * 0x40 - Pulse triggered requests - * 0x80 - Interrupt sharing. - * Byte 2-3: Interrupt req mask (if 0x10 of byte 1 set). - */ -#define CIS_IRQ_IRQN(x) ((x) & 0xF) -#define CIS_IRQ_MASK 0x10 -#define CIS_IRQ_LEVEL 0x20 -#define CIS_IRQ_PULSE 0x40 -#define CIS_IRQ_SHARING 0x80 -/* - * Memory block subtuple. Depending on the features bits, the - * following subtuples are used: - * mem features == 1 - * Byte 1-2: upper 16 bits of 24 bit memory length. - * mem features == 2 - * Byte 1-2: upper 16 bits of 24 bit memory length. - * Byte 3-4: upper 16 bits of 24 bit memory address. - * mem_features == 3 - * Byte 1: - * 0x07 - 0's numbered count of memory sub-tuples - * 0x18 - Memory length size (1's numbered) - * 0x60 - Memory address size (1's numbered) - * 0x80 - Host address value exists - * Memory sub-tuples follow: - * Byte 1-n: Memory length value (<< 8) - * Byte n-n: Memory card address value (<< 8) - * Byte n-n: Memory host address value (<< 8) - */ -#define CIS_FEAT_MEM_NONE 0 /* No memory config */ -#define CIS_FEAT_MEM_LEN 1 /* Just length */ -#define CIS_FEAT_MEM_ADDR 2 /* Card address & length */ -#define CIS_FEAT_MEM_WIN 3 /* Multiple windows */ - -#define CIS_MEM_WINS(x) (((x) & 0x7)+1) -#define CIS_MEM_LENSZ(x) (((x) >> 3) & 0x3) -#define CIS_MEM_ADDRSZ(x) (((x) >> 5) & 0x3) -#define CIS_MEM_HOST 0x80 -/* - * Misc sub-tuple. - * Byte 1: - * Byte 2: - * 0x0c - DMA Request Signal - * 00 - not support DMA - * 01 - use SPKR# line - * 10 - use IOIS16# line - * 11 - use INPACK# line - * 0x10 - DMA Width - * 0 - 8 bit DMA - * 1 - 16 bit DMA - */ -#define CIS_MISC_DMA_WIDTH(x) (((x) & 0x10) >> 4) -#define CIS_MISC_DMA_REQ(x) (((x) >> 2) & 0x3) - -#endif /* _PCCARD_CIS_H */ diff --git a/usr.sbin/dumpcis/dumpcis.8 b/usr.sbin/dumpcis/dumpcis.8 deleted file mode 100644 index 518eadd..0000000 --- a/usr.sbin/dumpcis/dumpcis.8 +++ /dev/null @@ -1,49 +0,0 @@ -.\" -.\" Copyright (c) 2006 M. Warner Losh -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd October 18, 2006 -.Dt DUMPCIS 8 -.Os -.Sh NAME -.Nm dumpcis -.Nd PC Card and Cardbus (PCMCIA) CIS display tool -.Sh SYNOPSIS -.Nm -.Ar -.Sh DESCRIPTION -The -.Nm -utility translates a raw CIS stream into human readable form. -.Sh SEE ALSO -.Xr cardbus 4 , -.Xr cbb 4 , -.Xr pccard 4 -.Sh AUTHORS -.An -nosplit -The original version was written by -.An Warner Losh Aq imp@FreeBSD.org . diff --git a/usr.sbin/dumpcis/main.c b/usr.sbin/dumpcis/main.c deleted file mode 100644 index 2e66506..0000000 --- a/usr.sbin/dumpcis/main.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2006 M. Warner Losh. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include "readcis.h" - -static void -scanfile(char *name) -{ - int fd; - struct tuple_list *tl; - - fd = open(name, O_RDONLY); - if (fd < 0) - return; - tl = readcis(fd); - if (tl) { - printf("Configuration data for file %s\n", - name); - dumpcis(tl); - freecis(tl); - } - close(fd); -} - -int -main(int argc, char **argv) -{ - for (argc--, argv++; argc; argc--, argv++) - scanfile(*argv); - return 0; -} diff --git a/usr.sbin/dumpcis/printcis.c b/usr.sbin/dumpcis/printcis.c deleted file mode 100644 index 74221e8..0000000 --- a/usr.sbin/dumpcis/printcis.c +++ /dev/null @@ -1,1105 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Code cleanup, bug-fix and extension - * by Tatsumi Hosokawa - */ - -#include -#include -#include -#include -#include -#include - -#include "cis.h" -#include "readcis.h" - -static void dump_config_map(struct tuple *tp); -static void dump_cis_config(struct tuple *tp); -static void dump_other_cond(u_char *p, int len); -static void dump_device_desc(u_char *p, int len, const char *type); -static void dump_info_v1(u_char *p, int len); -static void dump_longlink_mfc(u_char *p, int len); -static void dump_bar(u_char *p, int len); -static void dump_device_geo(u_char *p, int len); -static void dump_func_id(u_char *p); -static void dump_serial_ext(u_char *p, int len); -static void dump_disk_ext(u_char *p, int len); -static void dump_network_ext(u_char *p, int len); -static void dump_info_v2(u_char *p, int len); -static void dump_org(u_char *p, int len); - -void -dumpcis(struct tuple_list *tlist) -{ - struct tuple *tp; - struct tuple_list *tl; - int count = 0, sz, ad, i; - u_char *p; - int func = 0; - - for (tl = tlist; tl; tl = tl->next) - for (tp = tl->tuples; tp; tp = tp->next) { - printf("Tuple #%d, code = 0x%x (%s), length = %d\n", - ++count, tp->code, tuple_name(tp->code), tp->length); - p = tp->data; - sz = tp->length; - ad = 0; - while (sz > 0) { - printf(" %03x: ", ad); - for (i = 0; i < ((sz < 16) ? sz : 16); i++) - printf(" %02x", p[i]); - printf("\n"); - sz -= 16; - p += 16; - ad += 16; - } - switch (tp->code) { - default: - break; - case CIS_MEM_COMMON: /* 0x01 */ - dump_device_desc(tp->data, tp->length, "Common"); - break; - case CIS_CONF_MAP_CB: /* 0x04 */ - dump_config_map(tp); - break; - case CIS_CONFIG_CB: /* 0x05 */ - dump_cis_config(tp); - break; - case CIS_LONGLINK_MFC: /* 0x06 */ - dump_longlink_mfc(tp->data, tp->length); - break; - case CIS_BAR: /* 0x07 */ - dump_bar(tp->data, tp->length); - break; - case CIS_CHECKSUM: /* 0x10 */ - printf("\tChecksum from offset %d, length %d, value is 0x%x\n", - tpl16(tp->data), - tpl16(tp->data + 2), - tp->data[4]); - break; - case CIS_LONGLINK_A: /* 0x11 */ - printf("\tLong link to attribute memory, address 0x%x\n", - tpl32(tp->data)); - break; - case CIS_LONGLINK_C: /* 0x12 */ - printf("\tLong link to common memory, address 0x%x\n", - tpl32(tp->data)); - break; - case CIS_INFO_V1: /* 0x15 */ - dump_info_v1(tp->data, tp->length); - break; - case CIS_ALTSTR: /* 0x16 */ - break; - case CIS_MEM_ATTR: /* 0x17 */ - dump_device_desc(tp->data, tp->length, "Attribute"); - break; - case CIS_JEDEC_C: /* 0x18 */ - case CIS_JEDEC_A: /* 0x19 */ - break; - case CIS_CONF_MAP: /* 0x1A */ - dump_config_map(tp); - break; - case CIS_CONFIG: /* 0x1B */ - dump_cis_config(tp); - break; - case CIS_DEVICE_OC: /* 0x1C */ - case CIS_DEVICE_OA: /* 0x1D */ - dump_other_cond(tp->data, tp->length); - break; - case CIS_DEVICEGEO: /* 0x1E */ - case CIS_DEVICEGEO_A: /* 0x1F */ - dump_device_geo(tp->data, tp->length); - break; - case CIS_MANUF_ID: /* 0x20 */ - printf("\tPCMCIA ID = 0x%x, OEM ID = 0x%x\n", - tpl16(tp->data), - tpl16(tp->data + 2)); - break; - case CIS_FUNC_ID: /* 0x21 */ - func = tp->data[0]; - dump_func_id(tp->data); - break; - case CIS_FUNC_EXT: /* 0x22 */ - switch (func) { - case 2: - dump_serial_ext(tp->data, tp->length); - break; - case 4: - dump_disk_ext(tp->data, tp->length); - break; - case 6: - dump_network_ext(tp->data, tp->length); - break; - } - break; - case CIS_VERS_2: /* 0x40 */ - dump_info_v2(tp->data, tp->length); - break; - case CIS_ORG: /* 0x46 */ - dump_org(tp->data, tp->length); - break; - } - } -} - -/* - * CIS_CONF_MAP : Dump configuration map tuple. - * CIS_CONF_MAP_CB: Dump configuration map for CardBus - */ -static void -dump_config_map(struct tuple *tp) -{ - u_char *p = tp->data, x; - int rlen, mlen = 0; - int i; - - rlen = (p[0] & 3) + 1; - if (tp->code == CIS_CONF_MAP) - mlen = ((p[0] >> 2) & 3) + 1; - if (tp->length < rlen + mlen + 2) { - printf("\tWrong length for configuration map tuple\n"); - return; - } - printf("\tReg len = %d, config register addr = 0x%x, last config = 0x%x\n", - rlen, parse_num(rlen | 0x10, p + 2, &p, 0), p[1]); - if (mlen) { - printf("\tRegisters: "); - for (i = 0; i < mlen; i++, p++) { - for (x = 0x1; x; x <<= 1) - printf("%c", x & *p ? 'X' : '-'); - putchar(' '); - } - } - i = tp->length - (rlen + mlen + 2); - if (i) { - if (!mlen) - putchar('\t'); - printf("%d bytes in subtuples", i); - } - if (mlen || i) - putchar('\n'); -} - -/* - * Dump power descriptor. - * call from dump_cis_config() - */ -static int -print_pwr_desc(u_char *p) -{ - int len = 1, i; - u_char mask; - const char **expp; - static const char *pname[] = - {"Nominal operating supply voltage", - "Minimum operating supply voltage", - "Maximum operating supply voltage", - "Continuous supply current", - "Max current average over 1 second", - "Max current average over 10 ms", - "Power down supply current", - "Reserved" - }; - static const char *vexp[] = - {"10uV", "100uV", "1mV", "10mV", "100mV", "1V", "10V", "100V"}; - static const char *cexp[] = - {"10nA", "1uA", "10uA", "100uA", "1mA", "10mA", "100mA", "1A"}; - static const char *mant[] = - {"1", "1.2", "1.3", "1.5", "2", "2.5", "3", "3.5", "4", "4.5", - "5", "5.5", "6", "7", "8", "9"}; - - mask = *p++; - expp = vexp; - for (i = 0; i < 8; i++) - if (mask & (1 << i)) { - len++; - if (i >= 3) - expp = cexp; - printf("\t\t%s: ", pname[i]); - printf("%s x %s", - mant[(*p >> 3) & 0xF], - expp[*p & 7]); - while (*p & 0x80) { - len++; - p++; - printf(", ext = 0x%x", *p); - } - printf("\n"); - p++; - } - return (len); -} - -/* - * print_ext_speed - Print extended speed. - * call from dump_cis_config(), dump_device_desc() - */ -static void -print_ext_speed(u_char x, int scale) -{ - static const char *mant[] = - {"Reserved", "1.0", "1.2", "1.3", "1.5", "2.0", "2.5", "3.0", - "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", "7.0", "8.0"}; - static const char *exp[] = - {"1 ns", "10 ns", "100 ns", "1 us", "10 us", "100 us", - "1 ms", "10 ms"}; - static const char *scale_name[] = - {"None", "10", "100", "1,000", "10,000", "100,000", - "1,000,000", "10,000,000"}; - - printf("Speed = %s x %s", mant[(x >> 3) & 0xF], exp[x & 7]); - if (scale) - printf(", scaled by %s", scale_name[scale & 7]); -} - -/* - * Print variable length value. - * call from print_io_map(), print_mem_map() - */ -static int -print_num(int sz, const char *fmt, u_char *p, int ofs) -{ - switch (sz) { - case 0: - case 0x10: - return 0; - case 1: - case 0x11: - printf(fmt, *p + ofs); - return 1; - case 2: - case 0x12: - printf(fmt, tpl16(p) + ofs); - return 2; - case 0x13: - printf(fmt, tpl24(p) + ofs); - return 3; - case 3: - case 0x14: - printf(fmt, tpl32(p) + ofs); - return 4; - } - errx(1, "print_num(0x%x): Illegal arguments", sz); -/*NOTREACHED*/ -} - -/* - * Print I/O mapping sub-tuple. - * call from dump_cis_config() - */ -static u_char * -print_io_map(u_char *p, u_char *q) -{ - int i, j; - u_char c; - - if (q <= p) - goto err; - if (CIS_IO_ADDR(*p)) /* I/O address line */ - printf("\tCard decodes %d address lines", - CIS_IO_ADDR(*p)); - else - printf("\tCard provides address decode"); - - /* 8/16 bit I/O */ - switch (*p & (CIS_IO_8BIT | CIS_IO_16BIT)) { - case CIS_IO_8BIT: - printf(", 8 Bit I/O only"); - break; - case CIS_IO_16BIT: - printf(", limited 8/16 Bit I/O"); - break; - case (CIS_IO_8BIT | CIS_IO_16BIT): - printf(", full 8/16 Bit I/O"); - break; - } - putchar('\n'); - - /* I/O block sub-tuple exist */ - if (*p++ & CIS_IO_RANGE) { - if (q <= p) - goto err; - c = *p++; - /* calculate byte length */ - j = CIS_IO_ADSZ(c) + CIS_IO_BLKSZ(c); - if (CIS_IO_ADSZ(c) == 3) - j++; - if (CIS_IO_BLKSZ(c) == 3) - j++; - /* number of I/O block sub-tuples */ - for (i = 0; i <= CIS_IO_BLKS(c); i++) { - if (q - p < j) - goto err; - printf("\t\tI/O address # %d: ", i + 1); - /* start block address */ - p += print_num(CIS_IO_ADSZ(c), - "block start = 0x%x", p, 0); - /* block size */ - p += print_num(CIS_IO_BLKSZ(c), - " block length = 0x%x", p, 1); - putchar('\n'); - } - } - return p; - - err: /* warning */ - printf("\tWrong length for I/O mapping sub-tuple\n"); - return p; -} - -/* - * Print IRQ sub-tuple. - * call from dump_cis_config() - */ -static u_char * -print_irq_map(u_char *p, u_char *q) -{ - int i, j; - u_char c; - - if (q <= p) - goto err; - printf("\t\tIRQ modes:"); - c = ' '; - if (*p & CIS_IRQ_LEVEL) { /* Level triggered interrupts */ - printf(" Level"); - c = ','; - } - if (*p & CIS_IRQ_PULSE) { /* Pulse triggered requests */ - printf("%c Pulse", c); - c = ','; - } - if (*p & CIS_IRQ_SHARING) /* Interrupt sharing */ - printf("%c Shared", c); - putchar('\n'); - - /* IRQ mask values exist */ - if (*p & CIS_IRQ_MASK) { - if (q - p < 3) - goto err; - i = tpl16(p + 1); /* IRQ mask */ - printf("\t\tIRQs: "); - if (*p & 1) - printf(" NMI"); - if (*p & 0x2) - printf(" IOCK"); - if (*p & 0x4) - printf(" BERR"); - if (*p & 0x8) - printf(" VEND"); - for (j = 0; j < 16; j++) - if (i & (1 << j)) - printf(" %d", j); - putchar('\n'); - p += 3; - } else { - printf("\t\tIRQ level = %d\n", CIS_IRQ_IRQN(*p)); - p++; - } - return p; - - err: /* warning */ - printf("\tWrong length for IRQ sub-tuple\n"); - return p; -} - -/* - * Print memory map sub-tuple. - * call from dump_cis_config() - */ -static u_char * -print_mem_map(u_char feat, u_char *p, u_char *q) -{ - int i, j; - u_char c; - - switch (CIS_FEAT_MEMORY(feat)) { - - case CIS_FEAT_MEM_NONE: /* No memory block */ - break; - case CIS_FEAT_MEM_LEN: /* Specify memory length */ - if (q - p < 2) - goto err; - printf("\tMemory space length = 0x%x\n", tpl16(p)); - p += 2; - break; - case CIS_FEAT_MEM_ADDR: /* Memory address and length */ - if (q - p < 4) - goto err; - printf("\tMemory space address = 0x%x, length = 0x%x\n", - tpl16(p + 2), tpl16(p)); - p += 4; - break; - case CIS_FEAT_MEM_WIN: /* Memory descriptors. */ - if (q <= p) - goto err; - c = *p++; - /* calculate byte length */ - j = CIS_MEM_LENSZ(c) + CIS_MEM_ADDRSZ(c); - if (c & CIS_MEM_HOST) - j += CIS_MEM_ADDRSZ(c); - /* number of memory block */ - for (i = 0; i < CIS_MEM_WINS(c); i++) { - if (q - p < j) - goto err; - printf("\tMemory descriptor %d\n\t\t", i + 1); - /* memory length */ - p += print_num(CIS_MEM_LENSZ(c) | 0x10, - " blk length = 0x%x00", p, 0); - /* card address */ - p += print_num(CIS_MEM_ADDRSZ(c) | 0x10, - " card addr = 0x%x00", p, 0); - if (c & CIS_MEM_HOST) /* Host address value exist */ - p += print_num(CIS_MEM_ADDRSZ(c) | 0x10, - " host addr = 0x%x00", p, 0); - putchar('\n'); - } - break; - } - return p; - - err: /* warning */ - printf("\tWrong length for memory mapping sub-tuple\n"); - return p; -} - -/* - * CIS_CONFIG : Dump a config entry. - * CIS_CONFIG_CB: Dump a configuration entry for CardBus - */ -static void -dump_cis_config(struct tuple *tp) -{ - u_char *p, *q, feat; - int i, j; - char c; - - p = tp->data; - q = p + tp->length; - printf("\tConfig index = 0x%x%s\n", *p & 0x3F, - *p & 0x40 ? "(default)" : ""); - - /* Interface byte exists */ - if (tp->code == CIS_CONFIG && (*p & 0x80)) { - p++; - printf("\tInterface byte = 0x%x ", *p); - switch (*p & 0xF) { /* Interface type */ - default: - printf("(reserved)"); - break; - case 0: - printf("(memory)"); - break; - case 1: - printf("(I/O)"); - break; - case 4: - case 5: - case 6: - case 7: - case 8: - printf("(custom)"); - break; - } - c = ' '; - if (*p & 0x10) { /* Battery voltage detect */ - printf(" BVD1/2 active"); - c = ','; - } - if (*p & 0x20) { /* Write protect active */ - printf("%c card WP active", c); /* Write protect */ - c = ','; - } - if (*p & 0x40) { /* RdyBsy active bit */ - printf("%c +RDY/-BSY active", c); - c = ','; - } - if (*p & 0x80) /* Wait signal required */ - printf("%c wait signal supported", c); - printf("\n"); - } - - /* features byte */ - p++; - feat = *p++; - - /* Power structure sub-tuple */ - switch (CIS_FEAT_POWER(feat)) { /* Power sub-tuple(s) exists */ - case 0: - break; - case 1: - printf("\tVcc pwr:\n"); - p += print_pwr_desc(p); - break; - case 2: - printf("\tVcc pwr:\n"); - p += print_pwr_desc(p); - printf("\tVpp pwr:\n"); - p += print_pwr_desc(p); - break; - case 3: - printf("\tVcc pwr:\n"); - p += print_pwr_desc(p); - printf("\tVpp1 pwr:\n"); - p += print_pwr_desc(p); - printf("\tVpp2 pwr:\n"); - p += print_pwr_desc(p); - break; - } - - /* Timing sub-tuple */ - if (tp->code == CIS_CONFIG && - (feat & CIS_FEAT_TIMING)) { /* Timing sub-tuple exists */ - i = *p++; - j = CIS_WAIT_SCALE(i); - if (j != 3) { - printf("\tWait scale "); - print_ext_speed(*p++, j); - printf("\n"); - } - j = CIS_READY_SCALE(i); - if (j != 7) { - printf("\tRDY/BSY scale "); - print_ext_speed(*p++, j); - printf("\n"); - } - j = CIS_RESERVED_SCALE(i); - if (j != 7) { - printf("\tExternal scale "); - print_ext_speed(*p++, j); - printf("\n"); - } - } - - /* I/O mapping sub-tuple */ - if (feat & CIS_FEAT_I_O) { /* I/O space sub-tuple exists */ - if (tp->code == CIS_CONFIG) - p = print_io_map(p, q); - else { /* CIS_CONFIG_CB */ - printf("\tI/O base:"); - for (i = 0; i < 8; i++) - if (*p & (1 << i)) - printf(" %d", i); - putchar('\n'); - p++; - } - } - - /* IRQ descriptor sub-tuple */ - if (feat & CIS_FEAT_IRQ) /* IRQ sub-tuple exists */ - p = print_irq_map(p, q); - - /* Memory map sub-tuple */ - if (CIS_FEAT_MEMORY(feat)) { /* Memory space sub-tuple(s) exists */ - if (tp->code == CIS_CONFIG) - p = print_mem_map(feat, p, q); - else { /* CIS_CONFIG_CB */ - printf("\tMemory base:"); - for (i = 0; i < 8; i++) - if (*p & (1 << i)) - printf(" %d", i); - putchar('\n'); - p++; - } - } - - /* Misc sub-tuple */ - if (feat & CIS_FEAT_MISC) { /* Miscellaneous sub-tuple exists */ - if (tp->code == CIS_CONFIG) { - printf("\tMax twin cards = %d\n", *p & 7); - printf("\tMisc attr:%s%s%s", - (*p & 8) ? " (Audio-BVD2)" : "", - (*p & 0x10) ? " (Read-only)" : "", - (*p & 0x20) ? " (Power down supported)" : ""); - if (*p++ & 0x80) { - printf(" (Ext byte = 0x%x)", *p); - p++; - } - putchar('\n'); - } - else { /* CIS_CONFIG_CB */ - printf("\tMisc attr:"); - printf("%s%s%s%s%s%s%s", - (*p & 1) ? " (Master)" : "", - (*p & 2) ? " (Invalidate)" : "", - (*p & 4) ? " (VGA palette)" : "", - (*p & 8) ? " (Parity)" : "", - (*p & 0x10) ? " (Wait)" : "", - (*p & 0x20) ? " (Serr)" : "", - (*p & 0x40) ? " (Fast back)" : ""); - if (*p++ & 0x80) { - printf("%s%s", - (*p & 1) ? " (Binary audio)" : "", - (*p & 2) ? " (pwm audio)" : ""); - p++; - } - putchar('\n'); - } - } -} - -/* - * CIS_DEVICE_OC, CIS_DEVICE_OA: - * Dump other conditions for common/attribute memory - */ -static void -dump_other_cond(u_char *p, int len) -{ - if (p[0] && len > 0) { - printf("\t"); - if (p[0] & 1) - printf("(MWAIT)"); - if (p[0] & 2) - printf(" (3V card)"); - if (p[0] & 0x80) - printf(" (Extension bytes follow)"); - printf("\n"); - } -} - -/* - * CIS_MEM_COMMON, CIS_MEM_ATTR: - * Common / Attribute memory descripter - */ -static void -dump_device_desc(u_char *p, int len, const char *type) -{ - static const char *un_name[] = - {"512b", "2Kb", "8Kb", "32Kb", "128Kb", "512Kb", "2Mb", "reserved"}; - static const char *speed[] = - {"No speed", "250nS", "200nS", "150nS", - "100nS", "Reserved", "Reserved"}; - static const char *dev[] = - {"No device", "Mask ROM", "OTPROM", "UV EPROM", - "EEPROM", "FLASH EEPROM", "SRAM", "DRAM", - "Reserved", "Reserved", "Reserved", "Reserved", - "Reserved", "Function specific", "Extended", - "Reserved"}; - int count = 0; - - while (*p != 0xFF && len > 0) { - u_char x; - - x = *p++; - len -= 2; - if (count++ == 0) - printf("\t%s memory device information:\n", type); - printf("\t\tDevice number %d, type %s, WPS = %s\n", - count, dev[x >> 4], (x & 0x8) ? "ON" : "OFF"); - if ((x & 7) == 7) { - len--; - if (*p) { - printf("\t\t"); - print_ext_speed(*p, 0); - while (*p & 0x80) { - p++; - len--; - } - } - p++; - } else - printf("\t\tSpeed = %s", speed[x & 7]); - printf(", Memory block size = %s, %d units\n", - un_name[*p & 7], (*p >> 3) + 1); - p++; - } -} - -/* - * CIS_INFO_V1: Print version-1 info - */ -static void -dump_info_v1(u_char *p, int len) -{ - if (len < 2) { - printf("\tWrong length for version-1 info tuple\n"); - return; - } - printf("\tVersion = %d.%d", p[0], p[1]); - p += 2; - len -= 2; - if (len > 1 && *p != 0xff) { - printf(", Manuf = [%s]", p); - while (*p++ && --len > 0); - } - if (len > 1 && *p != 0xff) { - printf(", card vers = [%s]", p); - while (*p++ && --len > 0); - } else { - printf("\n\tWrong length for version-1 info tuple\n"); - return; - } - putchar('\n'); - if (len > 1 && *p != 0xff) { - printf("\tAddit. info = [%.*s]", len, p); - while (*p++ && --len > 0); - if (len > 1 && *p != 0xff) - printf(",[%.*s]", len, p); - putchar('\n'); - } -} - -/* - * CIS_FUNC_ID: Functional ID - */ -static void -dump_func_id(u_char *p) -{ - static const char *id[] = { - "Multifunction card", - "Memory card", - "Serial port/modem", - "Parallel port", - "Fixed disk card", - "Video adapter", - "Network/LAN adapter", - "AIMS", - "SCSI card", - "Security" - }; - - printf("\t%s%s%s\n", - (*p <= 9) ? id[*p] : "Unknown function", - (p[1] & 1) ? " - POST initialize" : "", - (p[1] & 2) ? " - Card has ROM" : ""); -} - -/* - * CIS_FUNC_EXT: Dump functional extension tuple. - * (Serial port/modem) - */ -static void -dump_serial_ext(u_char *p, int len) -{ - static const char *type[] = { - "", "Modem", "Data", "Fax", "Voice", "Data modem", - "Fax/modem", "Voice", " (Data)", " (Fax)", " (Voice)" - }; - - if (len < 1) - return; - switch (p[0]) { - case 0: /* Serial */ - case 8: /* Data */ - case 9: /* Fax */ - case 10: /* Voice */ - printf("\tSerial interface extension:%s\n", type[*p]); - if (len < 4) - goto err; - switch (p[1] & 0x1F) { - default: - printf("\t\tUnknown device"); - break; - case 0: - printf("\t\t8250 UART"); - break; - case 1: - printf("\t\t16450 UART"); - break; - case 2: - printf("\t\t16550 UART"); - break; - } - printf(", Parity - %s%s%s%s\n", - (p[2] & 1) ? "Space," : "", - (p[2] & 2) ? "Mark," : "", - (p[2] & 4) ? "Odd," : "", - (p[2] & 8) ? "Even" : ""); - printf("\t\tData bit - %s%s%s%s Stop bit - %s%s%s\n", - (p[3] & 1) ? "5bit," : "", - (p[3] & 2) ? "6bit," : "", - (p[3] & 4) ? "7bit," : "", - (p[3] & 8) ? "8bit," : "", - (p[3] & 0x10) ? "1bit," : "", - (p[3] & 0x20) ? "1.5bit," : "", - (p[3] & 0x40) ? "2bit" : ""); - break; - case 1: /* Serial */ - case 5: /* Data */ - case 6: /* Fax */ - case 7: /* Voice */ - printf("\t%s interface capabilities:\n", type[*p]); - if (len < 9) - goto err; - break; - case 2: /* Data */ - printf("\tData modem services available:\n"); - break; - case 0x13: /* Fax1 */ - case 0x23: /* Fax2 */ - case 0x33: /* Fax3 */ - printf("\tFax%d/modem services available:\n", *p >> 4); - break; - case 0x84: /* Voice */ - printf("\tVoice services available:\n"); - break; - err: /* warning */ - printf("\tWrong length for serial extension tuple\n"); - return; - } -} - -/* - * CIS_FUNC_EXT: Dump functional extension tuple. - * (Fixed disk card) - */ -static void -dump_disk_ext(u_char *p, int len) -{ - if (len < 1) - return; - switch (p[0]) { - case 1: /* IDE interface */ - if (len < 2) - goto err; - printf("\tDisk interface: %s\n", - (p[1] & 1) ? "IDE" : "Undefined"); - break; - case 2: /* Master */ - case 3: /* Slave */ - if (len < 3) - goto err; - printf("\tDisk features: %s, %s%s\n", - (p[1] & 0x04) ? "Silicon" : "Rotating", - (p[1] & 0x08) ? "Unique, " : "", - (p[1] & 0x10) ? "Dual" : "Single"); - if (p[2] & 0x7f) - printf("\t\t%s%s%s%s%s%s%s\n", - (p[2] & 0x01) ? "Sleep, " : "", - (p[2] & 0x02) ? "Standby, " : "", - (p[2] & 0x04) ? "Idle, " : "", - (p[2] & 0x08) ? "Low power, " : "", - (p[2] & 0x10) ? "Reg inhibit, " : "", - (p[2] & 0x20) ? "Index, " : "", - (p[2] & 0x40) ? "Iois16" : ""); - break; - err: /* warning */ - printf("\tWrong length for fixed disk extension tuple\n"); - return; - } -} - -static void -print_speed(u_int i) -{ - if (i < 1000) - printf("%u bits/sec", i); - else if (i < 1000000) - printf("%u kb/sec", i / 1000); - else - printf("%u Mb/sec", i / 1000000); -} - -/* - * CIS_FUNC_EXT: Dump functional extension tuple. - * (Network/LAN adapter) - */ -static void -dump_network_ext(u_char *p, int len) -{ - static const char *tech[] = { - "Undefined", "ARCnet", "Ethernet", "Token ring", - "Localtalk", "FDDI/CDDI", "ATM", "Wireless" - }; - static const char *media[] = { - "Undefined", "UTP", "STP", "Thin coax", - "THICK coax", "Fiber", "900 MHz", "2.4 GHz", - "5.4 GHz", "Diffuse Infrared", "Point to point Infrared" - }; - u_int i = 0; - - if (len < 1) - return; - switch (p[0]) { - case 1: /* Network technology */ - if (len < 2) - goto err; - printf("\tNetwork technology: %s\n", tech[p[1] & 7]); - break; - case 2: /* Network speed */ - if (len < 5) - goto err; - printf("\tNetwork speed: "); - print_speed(tpl32(p + 1)); - putchar('\n'); - break; - case 3: /* Network media */ - if (len < 2) - goto err; - if (p[1] <= 10) - i = p[1]; - printf("\tNetwork media: %s\n", media[i]); - break; - case 4: /* Node ID */ - if (len <= 2 || len < p[1] + 2) - goto err; - printf("\tNetwork node ID:"); - for (i = 0; i < p[1]; i++) - printf(" %02x", p[i + 2]); - putchar('\n'); - break; - case 5: /* Connecter type */ - if (len < 2) - goto err; - printf("\tNetwork connector: %s connector standard\n", - (p[1] == 0) ? "open" : "closed"); - break; - err: /* warning */ - printf("\tWrong length for network extension tuple\n"); - return; - } -} - -/* - * CIS_LONGLINK_MFC: Long link to next chain for Multi function card - */ -static void -dump_longlink_mfc(u_char *p, int len) -{ - u_int i, n = *p++; - - --len; - for (i = 0; i < n; i++) { - if (len < 5) { - printf("\tWrong length for long link MFC tuple\n"); - return; - } - printf("\tFunction %d: %s memory, address 0x%x\n", - i, (*p ? "common" : "attribute"), tpl32(p + 1)); - p += 5; - len -= 5; - } -} - -/* - * CIS_DEVICEGEO, CIS_DEVICEGEO_A: - * Geometry info for common/attribute memory - */ -static void -dump_device_geo(u_char *p, int len) -{ - while (len >= 6) { - printf("\twidth = %d, erase = 0x%x, read = 0x%x, write = 0x%x\n" - "\t\tpartition = 0x%x, interleave = 0x%x\n", - p[0], 1 << (p[1] - 1), - 1 << (p[2] - 1), 1 << (p[3] - 1), - 1 << (p[4] - 1), 1 << (p[5] - 1)); - len -= 6; - } -} - -/* - * CIS_INFO_V2: Print version-2 info - */ -static void -dump_info_v2(u_char *p, int len) -{ - if (len < 9) { - printf("\tWrong length for version-2 info tuple\n"); - return; - } - printf("\tVersion = 0x%x, compliance = 0x%x, dindex = 0x%x\n", - p[0], p[1], tpl16(p + 2)); - printf("\tVspec8 = 0x%x, vspec9 = 0x%x, nhdr = %d\n", - p[6], p[7], p[8]); - p += 9; - len -= 9; - if (len <= 1 || *p == 0xff) - return; - printf("\tVendor = [%.*s]", len, p); - while (*p++ && --len > 0); - if (len > 1 && *p != 0xff) - printf(", info = [%.*s]", len, p); - putchar('\n'); -} - -/* - * CIS_ORG: Organization - */ -static void -dump_org(u_char *p, int len) -{ - if (len < 1) { - printf("\tWrong length for organization tuple\n"); - return; - } - switch (*p) { - case 0: - printf("\tFilesystem"); - break; - case 1: - printf("\tApp specific"); - break; - case 2: - printf("\tCode"); - break; - default: - if (*p < 0x80) - printf("\tReserved"); - else - printf("\tVendor specific"); - break; - } - printf(" [%.*s]\n", len - 1, p + 1); -} - -static void -print_size(u_int i) -{ - if (i < 1024) - printf("%ubits", i); - else if (i < 1024*1024) - printf("%ukb", i / 1024); - else - printf("%uMb", i / (1024*1024)); -} - -/* - * CIS_BAR: Base address register for CardBus - */ -static void -dump_bar(u_char *p, int len) -{ - if (len < 6) { - printf("\tWrong length for BAR tuple\n"); - return; - } - printf("\tBAR %d: size = ", *p & 7); - print_size(tpl32(p + 2)); - printf(", %s%s%s%s\n", - (*p & 0x10) ? "I/O" : "Memory", - (*p & 0x20) ? ", Prefetch" : "", - (*p & 0x40) ? ", Cacheable" : "", - (*p & 0x80) ? ", <1Mb" : ""); -} diff --git a/usr.sbin/dumpcis/readcis.c b/usr.sbin/dumpcis/readcis.c deleted file mode 100644 index 25bd396..0000000 --- a/usr.sbin/dumpcis/readcis.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; -#endif /* not lint */ - -/* - * Code cleanup, bug-fix and extension - * by Tatsumi Hosokawa - */ - -#include -#include -#include -#include -#include - -#include "cardinfo.h" -#include "cis.h" -#include "readcis.h" - -static int ck_linktarget(int, off_t, int); -static struct tuple_list *read_one_tuplelist(int, int, off_t); -static struct tuple_list *read_tuples(int); -static struct tuple *find_tuple_in_list(struct tuple_list *, unsigned char); -static struct tuple_info *get_tuple_info(unsigned char); - -static struct tuple_info tuple_info[] = { - {"Null tuple", CIS_NULL, 0}, - {"Common memory descriptor", CIS_MEM_COMMON, 255}, - {"Long link to next chain for CardBus", CIS_LONGLINK_CB, 255}, - {"Indirect access", CIS_INDIRECT, 255}, - {"Configuration map for CardBus", CIS_CONF_MAP_CB, 255}, - {"Configuration entry for CardBus", CIS_CONFIG_CB, 255}, - {"Long link to next chain for MFC", CIS_LONGLINK_MFC, 255}, - {"Base address register for CardBus", CIS_BAR, 6}, - {"Checksum", CIS_CHECKSUM, 5}, - {"Long link to attribute memory", CIS_LONGLINK_A, 4}, - {"Long link to common memory", CIS_LONGLINK_C, 4}, - {"Link target", CIS_LINKTARGET, 3}, - {"No link", CIS_NOLINK, 0}, - {"Version 1 info", CIS_INFO_V1, 255}, - {"Alternate language string", CIS_ALTSTR, 255}, - {"Attribute memory descriptor", CIS_MEM_ATTR, 255}, - {"JEDEC descr for common memory", CIS_JEDEC_C, 255}, - {"JEDEC descr for attribute memory", CIS_JEDEC_A, 255}, - {"Configuration map", CIS_CONF_MAP, 255}, - {"Configuration entry", CIS_CONFIG, 255}, - {"Other conditions for common memory", CIS_DEVICE_OC, 255}, - {"Other conditions for attribute memory", CIS_DEVICE_OA, 255}, - {"Geometry info for common memory", CIS_DEVICEGEO, 255}, - {"Geometry info for attribute memory", CIS_DEVICEGEO_A, 255}, - {"Manufacturer ID", CIS_MANUF_ID, 4}, - {"Functional ID", CIS_FUNC_ID, 2}, - {"Functional EXT", CIS_FUNC_EXT, 255}, - {"Software interleave", CIS_SW_INTERLV, 2}, - {"Version 2 Info", CIS_VERS_2, 255}, - {"Data format", CIS_FORMAT, 255}, - {"Geometry", CIS_GEOMETRY, 4}, - {"Byte order", CIS_BYTEORDER, 2}, - {"Card init date", CIS_DATE, 4}, - {"Battery replacement", CIS_BATTERY, 4}, - {"Organization", CIS_ORG, 255}, - {"Terminator", CIS_END, 0}, - {0, 0, 0} -}; - -static void * -xmalloc(int sz) -{ - void *p; - - sz = (sz + 7) & ~7; - p = malloc(sz); - if (p) - bzero(p, sz); - else - errx(1, "malloc"); - return (p); -} - -/* - * After reading the tuples, decode the relevant ones. - */ -struct tuple_list * -readcis(int fd) -{ - - return (read_tuples(fd)); -} - -/* - * free_cis - delete cis entry. - */ -void -freecis(struct tuple_list *tlist) -{ - struct tuple_list *tl; - struct tuple *tp; - - while ((tl = tlist) != 0) { - tlist = tl->next; - while ((tp = tl->tuples) != 0) { - tl->tuples = tp->next; - free(tp->data); - free(tp); - } - free(tl); - } -} - -/* - * Parse variable length value. - */ -u_int -parse_num(int sz, u_char *p, u_char **q, int ofs) -{ - u_int num = 0; - - switch (sz) { - case 0: - case 0x10: - break; - case 1: - case 0x11: - num = (*p++) + ofs; - break; - case 2: - case 0x12: - num = tpl16(p) + ofs; - p += 2; - break; - case 0x13: - num = tpl24(p) + ofs; - p += 3; - break; - case 3: - case 0x14: - num = tpl32(p) + ofs; - p += 4; - break; - } - if (q) - *q = p; - return num; -} - -/* - * Read the tuples from the card. - * The processing of tuples is as follows: - * - Read tuples at attribute memory, offset 0. - * - If a CIS_END is the first tuple, look for - * a tuple list at common memory offset 0; this list - * must start with a LINKTARGET. - * - If a long link tuple was encountered, execute the long - * link. - * - If a no-link tuple was seen, terminate processing. - * - If no no-link tuple exists, and no long link tuple - * exists while processing the primary tuple list, - * then look for a LINKTARGET tuple in common memory. - * - If a long link tuple is found in any list, then process - * it. Only one link is allowed per list. - */ -static struct tuple_list *tlist; - -static struct tuple_list * -read_tuples(int fd) -{ - struct tuple_list *tl = 0, *last_tl; - struct tuple *tp; - int flag; - off_t offs; - - tlist = 0; - last_tl = tlist = read_one_tuplelist(fd, MDF_ATTR, (off_t) 0); - - /* Now start processing the links (if any). */ - do { - flag = MDF_ATTR; - tp = find_tuple_in_list(last_tl, CIS_LONGLINK_A); - if (tp == 0) { - flag = 0; - tp = find_tuple_in_list(last_tl, CIS_LONGLINK_C); - } - if (tp && tp->length == 4) { - offs = tpl32(tp->data); -#ifdef DEBUG - printf("Checking long link at %zd (%s memory)\n", - offs, flag ? "Attribute" : "Common"); -#endif - /* If a link was found, read the tuple list from it. */ - if (ck_linktarget(fd, offs, flag)) { - tl = read_one_tuplelist(fd, flag, offs); - last_tl->next = tl; - last_tl = tl; - } - } else - tl = 0; - } while (tl); - - /* - * If the primary list had no NOLINK tuple, and no LINKTARGET, - * then try to read a tuple list at common memory (offset 0). - */ - if (find_tuple_in_list(tlist, CIS_NOLINK) == 0 && - find_tuple_in_list(tlist, CIS_LINKTARGET) == 0 && - ck_linktarget(fd, (off_t) 0, 0)) { - offs = 0; -#ifdef DEBUG - printf("Reading long link at %zd (%s memory)\n", - offs, flag ? "Attribute" : "Common"); -#endif - tlist->next = read_one_tuplelist(fd, 0, offs); - } - return (tlist); -} - -/* - * Read one tuple list from the card. - */ -static struct tuple_list * -read_one_tuplelist(int fd, int flags, off_t offs) -{ - struct tuple *tp, *last_tp = 0; - struct tuple_list *tl; - struct tuple_info *tinfo; - int total = 0; - unsigned char code, length; - - /* Check to see if this memory has already been scanned. */ - for (tl = tlist; tl; tl = tl->next) - if (tl->offs == offs && tl->flags == (flags & MDF_ATTR)) - return (0); - tl = xmalloc(sizeof(*tl)); - tl->offs = offs; - tl->flags = flags & MDF_ATTR; - ioctl(fd, PIOCRWFLAG, &flags); - lseek(fd, offs, SEEK_SET); - do { - if (read(fd, &code, 1) != 1) { - warn("CIS code read"); - break; - } - total++; - if (code == CIS_NULL) - continue; - tp = xmalloc(sizeof(*tp)); - tp->code = code; - if (code == CIS_END) - length = 0; - else { - if (read(fd, &length, 1) != 1) { - warn("CIS len read"); - break; - } - total++; - } - tp->length = length; -#ifdef DEBUG - printf("Tuple code = 0x%x, len = %d\n", code, length); -#endif - if (length == 0xFF) { - length = tp->length = 0; - code = CIS_END; - } - if (length != 0) { - total += length; - tp->data = xmalloc(length); - if (read(fd, tp->data, length) != length) { - warn("CIS read"); - break; - } - } - - /* - * Check the tuple, and ignore it if it isn't in the table - * or the length is illegal. - */ - tinfo = get_tuple_info(code); - if (tinfo != NULL && (tinfo->length != 255 && tinfo->length > length)) { - printf("code %s (%d) ignored\n", tuple_name(code), code); - tp->code = CIS_NULL; - } - if (tl->tuples == NULL) - tl->tuples = tp; - else - last_tp->next = tp; - last_tp = tp; - } while (code != CIS_END && total < 1024); - return (tl); -} - -/* - * return true if the offset points to a LINKTARGET tuple. - */ -static int -ck_linktarget(int fd, off_t offs, int flag) -{ - char blk[5]; - - ioctl(fd, PIOCRWFLAG, &flag); - lseek(fd, offs, SEEK_SET); - if (read(fd, blk, 5) != 5) - return (0); - if (blk[0] == CIS_LINKTARGET && - blk[1] == 0x3 && - blk[2] == 'C' && - blk[3] == 'I' && - blk[4] == 'S') - return (1); - return (0); -} - -/* - * find_tuple_in_list - find a tuple within a - * single tuple list. - */ -static struct tuple * -find_tuple_in_list(struct tuple_list *tl, unsigned char code) -{ - struct tuple *tp; - - for (tp = tl->tuples; tp; tp = tp->next) - if (tp->code == code) - break; - return (tp); -} - -/* - * return table entry for code. - */ -static struct tuple_info * -get_tuple_info(unsigned char code) -{ - struct tuple_info *tp; - - for (tp = tuple_info; tp->name; tp++) - if (tp->code == code) - return (tp); - return (0); -} - -const char * -tuple_name(unsigned char code) -{ - struct tuple_info *tp; - - tp = get_tuple_info(code); - if (tp) - return (tp->name); - return ("Unknown"); -} diff --git a/usr.sbin/dumpcis/readcis.h b/usr.sbin/dumpcis/readcis.h deleted file mode 100644 index 8fc2e2d..0000000 --- a/usr.sbin/dumpcis/readcis.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 1995 Andrew McRae. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -struct tuple { - struct tuple *next; - unsigned char code; - int length; - unsigned char *data; -}; - -struct tuple_list { - struct tuple_list *next; - struct tuple *tuples; - off_t offs; - int flags; -}; - -struct tuple_info { - const char *name; - unsigned char code; - unsigned char length; /* 255 means variable length */ -}; - -#define tpl32(tp) ((*((tp) + 3) << 24) | \ - (*((tp) + 2) << 16) | \ - (*((tp) + 1) << 8) | *(tp)) -#define tpl24(tp) ((*((tp) + 2) << 16) | \ - (*((tp) + 1) << 8) | *(tp)) -#define tpl16(tp) ((*((tp) + 1) << 8) | *(tp)) - -void dumpcis(struct tuple_list *); -void freecis(struct tuple_list *); -struct tuple_list *readcis(int); - -const char *tuple_name(unsigned char); -u_int parse_num(int, u_char *, u_char **, int); diff --git a/usr.sbin/editmap/Makefile b/usr.sbin/editmap/Makefile deleted file mode 100644 index 92d8392..0000000 --- a/usr.sbin/editmap/Makefile +++ /dev/null @@ -1,39 +0,0 @@ -# $FreeBSD$ - -SENDMAIL_DIR=${.CURDIR}/../../contrib/sendmail -.PATH: ${SENDMAIL_DIR}/editmap - -PROG= editmap -SRCS= editmap.c -MAN= editmap.8 - -CFLAGS+= -I${SENDMAIL_DIR}/src -I${SENDMAIL_DIR}/include -I. -CFLAGS+= -DNEWDB -DNOT_SENDMAIL - -WARNS?= 2 - -LIBSMDIR= ${.OBJDIR}/../../lib/libsm -LIBSM= ${LIBSMDIR}/libsm.a - -LIBSMDBDIR= ${.OBJDIR}/../../lib/libsmdb -LIBSMDB= ${LIBSMDBDIR}/libsmdb.a - -LIBSMUTILDIR= ${.OBJDIR}/../../lib/libsmutil -LIBSMUTIL= ${LIBSMUTILDIR}/libsmutil.a - -DPADD= ${LIBSMDB} ${LIBSMUTIL} ${LIBSM} -LDADD= ${LIBSMDB} ${LIBSMUTIL} ${LIBSM} - -SRCS+= sm_os.h -CLEANFILES+=sm_os.h - -# User customizations to the sendmail build environment -CFLAGS+=${SENDMAIL_CFLAGS} -DPADD+=${SENDMAIL_DPADD} -LDADD+=${SENDMAIL_LDADD} -LDFLAGS+=${SENDMAIL_LDFLAGS} - -sm_os.h: - ln -sf ${SENDMAIL_DIR}/include/sm/os/sm_os_freebsd.h sm_os.h - -.include diff --git a/usr.sbin/edquota/Makefile b/usr.sbin/edquota/Makefile deleted file mode 100644 index 1196e47..0000000 --- a/usr.sbin/edquota/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -PROG= edquota -MAN= edquota.8 - -CSTD= gnu99 -WARNS?= 4 - -DPADD= ${LIBUTIL} -LDADD= -lutil - -.include diff --git a/usr.sbin/edquota/edquota.8 b/usr.sbin/edquota/edquota.8 deleted file mode 100644 index 326c837..0000000 --- a/usr.sbin/edquota/edquota.8 +++ /dev/null @@ -1,264 +0,0 @@ -.\" Copyright (c) 1983, 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" This code is derived from software contributed to Berkeley by -.\" Robert Elz at The University of Melbourne. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)edquota.8 8.1 (Berkeley) 6/6/93 -.\" $FreeBSD$ -.\" -.Dd June 6, 1993 -.Dt EDQUOTA 8 -.Os -.Sh NAME -.Nm edquota -.Nd edit user quotas -.Sh SYNOPSIS -.Nm -.Op Fl uh -.Op Fl f Ar fspath -.Op Fl p Ar proto-username -.Ar username ... -.Nm -.Op Fl u -.Fl e -.Sm off -.Ar fspath Op : Ar bslim Op : Ar bhlim Op : Ar islim Op : Ar ihlim -.Sm on -.Op Fl e Ar ... -.Ar username ... -.Nm -.Fl g -.Op Fl h -.Op Fl f Ar fspath -.Op Fl p Ar proto-groupname -.Ar groupname ... -.Nm -.Fl g -.Fl e -.Sm off -.Ar fspath Op : Ar bslim Op : Ar bhlim Op : Ar islim Op : Ar ihlim -.Sm on -.Op Fl e Ar ... -.Ar groupname ... -.Nm -.Fl t -.Op Fl u -.Op Fl f Ar fspath -.Nm -.Fl t -.Fl g -.Op Fl f Ar fspath -.Sh DESCRIPTION -The -.Nm -utility is a quota editor. -By default, or if the -.Fl u -flag is specified, -one or more users may be specified on the command line. -For each user a temporary file is created -with an -.Tn ASCII -representation of the current -disk quotas for that user. -The list of file systems with user quotas is determined from -.Pa /etc/fstab . -An editor is invoked on the -.Tn ASCII -file. -The editor invoked is -.Xr vi 1 -unless the environment variable -.Ev EDITOR -specifies otherwise. -.Pp -The quotas may then be modified, new quotas added, etc. -Block quotas can be specified in bytes (B), kilobytes (K), -megabytes (M), terabytes (T), petabytes (P), or exabytes (E). -If no units are specified, kilobytes are assumed. -Inode quotas can be specified in kiloinodes (K), -megainodes (M), terainodes (T), petainodes (P), or exainodes (E). -If no units are specified, the number of inodes specified are used. -If the -.Fl h -flag is specified, the editor will always display the -block usage and limits in a more human readable format -rather than displaying them in the historic kilobyte format. -Setting a quota to zero indicates that no quota should be imposed. -Setting a hard limit to one indicates that no allocations should -be permitted. -Setting a soft limit to one with a hard limit of zero -indicates that allocations should be permitted only on -a temporary basis (see -.Fl t -below). -The current usage information in the file is for informational purposes; -only the hard and soft limits can be changed. -.Pp -On leaving the editor, -.Nm -reads the temporary file and modifies the binary -quota files to reflect the changes made. -.Pp -If the -.Fl p -option is specified, -.Nm -will duplicate the quotas of the prototypical user -specified for each user specified. -This is the normal mechanism used to -initialize quotas for groups of users. -If the user given to assign quotas to is a numerical uid -range (e.g.\& 1000-2000), then -.Nm -will duplicate the quotas of the prototypical user -for each uid in the range specified. -This allows -for easy setup of default quotas for a group of users. -The uids in question do not have to be currently assigned in -.Pa /etc/passwd . -.Pp -If one or more -.Fl e -.Sm off -.Ar fspath Op : Ar bslim Op : Ar bhlim Op : Ar islim Op : Ar ihlim -.Sm on -options are specified, -.Nm -will non-interactively set quotas defined by -.Ar bslim , bhlim , islim , -and -.Ar ihlim -on each particular file system referenced by -.Ar fspath . -Here -.Ar bslim -is the soft limit on the number of blocks, -.Ar bhlim -is the hard limit on the number of blocks, -.Ar islim -is the soft limit on the number of files, and -.Ar ihlim -is the hard limit on the number of files. -If any of the -.Ar bslim , bhlim , islim , -and -.Ar ihlim -values is omitted, it is assumed to be zero, therefore -indicating that no particular quota should be imposed. -Block quotas can be specified in bytes (B), kilobytes (K), -megabytes (M), terabytes (T), petabytes (P), or exabytes (E). -If no units are specified, kilobytes are assumed. -Inode quotas can be specified in kiloinodes (K), -megainodes (M), terainodes (T), petainodes (P), or exainodes (E). -If no units are specified, the number of inodes specified are used. -.Pp -If invoked with the -.Fl f -option, -.Nm -will read and modify quotas on the file system specified by -.Ar fspath -only. -The -.Ar fspath -argument may be either a special device -or a file system mount point. -The primary purpose of this option is to set the scope for the -.Fl p -option, which would overwrite quota records on every -file system with quotas otherwise. -.Pp -If the -.Fl g -flag is specified, -.Nm -is invoked to edit the quotas of -one or more groups specified on the command line. -The -.Fl p -flag can be specified in conjunction with -the -.Fl g -flag to specify a prototypical group -to be duplicated among the listed set of groups. -Similarly, -.Fl e -flag can be specified in conjunction with -the -.Fl g -flag to non-interactively set-up quotas on the listed set -of groups. -.Pp -Users are permitted to exceed their soft limits -for a grace period that may be specified per file system. -Once the grace period has expired, -the soft limit is enforced as a hard limit. -The default grace period for a file system is specified in -.In ufs/ufs/quota.h . -The -.Fl t -flag can be used to change the grace period. -By default, or when invoked with the -.Fl u -flag, -the grace period is set for all the file systems with user -quotas specified in -.Pa /etc/fstab . -When invoked with the -.Fl g -flag the grace period is -set for all the file systems with group quotas specified in -.Pa /etc/fstab . -The grace period may be specified in days, hours, minutes, or seconds. -Setting a grace period to zero indicates that the default -grace period should be imposed. -Setting a grace period to one second indicates that no -grace period should be granted. -Quotas must be turned off for the file system and -then turned back on for the new grace period to take effect. -.Pp -Only the super-user may edit quotas. -.Sh FILES -.Bl -tag -width quota.group -compact -.It Pa quota.user -at the file system root with user quotas -.It Pa quota.group -at the file system root with group quotas -.It Pa /etc/fstab -to find file system names and locations -.El -.Sh DIAGNOSTICS -Various messages about inaccessible files; self-explanatory. -.Sh SEE ALSO -.Xr quota 1 , -.Xr quotactl 2 , -.Xr fstab 5 , -.Xr quotacheck 8 , -.Xr quotaon 8 , -.Xr repquota 8 diff --git a/usr.sbin/edquota/edquota.c b/usr.sbin/edquota/edquota.c deleted file mode 100644 index 69ea497..0000000 --- a/usr.sbin/edquota/edquota.c +++ /dev/null @@ -1,959 +0,0 @@ -/* - * Copyright (c) 1980, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Robert Elz at The University of Melbourne. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1980, 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)edquota.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ -#endif - -#include -__FBSDID("$FreeBSD$"); - -/* - * Disk quota editor. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "pathnames.h" - -/* Let's be paranoid about block size */ -#if 10 > DEV_BSHIFT -#define dbtokb(db) \ - ((off_t)(db) >> (10-DEV_BSHIFT)) -#elif 10 < DEV_BSHIFT -#define dbtokb(db) \ - ((off_t)(db) << (DEV_BSHIFT-10)) -#else -#define dbtokb(db) (db) -#endif - -const char *qfextension[] = INITQFNAMES; -char tmpfil[] = _PATH_TMP; -int hflag; - -struct quotause { - struct quotause *next; - struct quotafile *qf; - struct dqblk dqblk; - int flags; - char fsname[MAXPATHLEN + 1]; -}; -#define FOUND 0x01 - -int alldigits(const char *s); -int cvtatos(uint64_t, char *, uint64_t *); -char *cvtstoa(uint64_t); -uint64_t cvtblkval(uint64_t, char, const char *); -uint64_t cvtinoval(uint64_t, char, const char *); -int editit(char *); -char *fmthumanvalblks(int64_t); -char *fmthumanvalinos(int64_t); -void freeprivs(struct quotause *); -int getentry(const char *, int); -struct quotause *getprivs(long, int, char *); -void putprivs(long, struct quotause *); -int readprivs(struct quotause *, char *); -int readtimes(struct quotause *, char *); -static void usage(void); -int writetimes(struct quotause *, int, int); -int writeprivs(struct quotause *, int, char *, int); - -int -main(int argc, char *argv[]) -{ - struct quotause *qup, *protoprivs, *curprivs; - long id, protoid; - int i, quotatype, range, tmpfd; - uid_t startuid, enduid; - uint64_t lim; - char *protoname, *cp, *endpt, *oldoptarg; - int eflag = 0, tflag = 0, pflag = 0, ch; - char *fspath = NULL; - char buf[MAXLOGNAME]; - - if (argc < 2) - usage(); - if (getuid()) - errx(1, "permission denied"); - quotatype = USRQUOTA; - protoprivs = NULL; - curprivs = NULL; - protoname = NULL; - while ((ch = getopt(argc, argv, "ughtf:p:e:")) != -1) { - switch(ch) { - case 'f': - fspath = optarg; - break; - case 'p': - if (eflag) { - warnx("cannot specify both -e and -p"); - usage(); - /* not reached */ - } - protoname = optarg; - pflag++; - break; - case 'g': - quotatype = GRPQUOTA; - break; - case 'h': - hflag++; - break; - case 'u': - quotatype = USRQUOTA; - break; - case 't': - tflag++; - break; - case 'e': - if (pflag) { - warnx("cannot specify both -e and -p"); - usage(); - /* not reached */ - } - if ((qup = calloc(1, sizeof(*qup))) == NULL) - errx(2, "out of memory"); - oldoptarg = optarg; - for (i = 0, cp = optarg; - (cp = strsep(&optarg, ":")) != NULL; i++) { - if (cp != oldoptarg) - *(cp - 1) = ':'; - if (i > 0 && !isdigit(*cp)) { - warnx("incorrect quota specification: " - "%s", oldoptarg); - usage(); - /* Not Reached */ - } - switch (i) { - case 0: - strlcpy(qup->fsname, cp, - sizeof(qup->fsname)); - break; - case 1: - lim = strtoll(cp, &endpt, 10); - qup->dqblk.dqb_bsoftlimit = - cvtblkval(lim, *endpt, - "block soft limit"); - continue; - case 2: - lim = strtoll(cp, &endpt, 10); - qup->dqblk.dqb_bhardlimit = - cvtblkval(lim, *endpt, - "block hard limit"); - continue; - case 3: - lim = strtoll(cp, &endpt, 10); - qup->dqblk.dqb_isoftlimit = - cvtinoval(lim, *endpt, - "inode soft limit"); - continue; - case 4: - lim = strtoll(cp, &endpt, 10); - qup->dqblk.dqb_ihardlimit = - cvtinoval(lim, *endpt, - "inode hard limit"); - continue; - default: - warnx("incorrect quota specification: " - "%s", oldoptarg); - usage(); - /* Not Reached */ - } - } - if (protoprivs == NULL) { - protoprivs = curprivs = qup; - } else { - curprivs->next = qup; - curprivs = qup; - } - eflag++; - break; - default: - usage(); - /* Not Reached */ - } - } - argc -= optind; - argv += optind; - if (pflag || eflag) { - if (pflag) { - if ((protoid = getentry(protoname, quotatype)) == -1) - exit(1); - protoprivs = getprivs(protoid, quotatype, fspath); - if (protoprivs == NULL) - exit(0); - for (qup = protoprivs; qup; qup = qup->next) { - qup->dqblk.dqb_btime = 0; - qup->dqblk.dqb_itime = 0; - } - } - for (; argc-- > 0; argv++) { - if (strspn(*argv, "0123456789-") == strlen(*argv) && - (cp = strchr(*argv, '-')) != NULL) { - *cp++ = '\0'; - startuid = atoi(*argv); - enduid = atoi(cp); - if (enduid < startuid) - errx(1, - "ending uid (%d) must be >= starting uid (%d) when using uid ranges", - enduid, startuid); - range = 1; - } else { - startuid = enduid = 0; - range = 0; - } - for ( ; startuid <= enduid; startuid++) { - if (range) - snprintf(buf, sizeof(buf), "%d", - startuid); - else - snprintf(buf, sizeof(buf), "%s", - *argv); - if ((id = getentry(buf, quotatype)) < 0) - continue; - if (pflag) { - putprivs(id, protoprivs); - continue; - } - for (qup = protoprivs; qup; qup = qup->next) { - curprivs = getprivs(id, quotatype, - qup->fsname); - if (curprivs == NULL) - continue; - curprivs->dqblk = qup->dqblk; - putprivs(id, curprivs); - freeprivs(curprivs); - } - } - } - if (pflag) - freeprivs(protoprivs); - exit(0); - } - tmpfd = mkstemp(tmpfil); - fchown(tmpfd, getuid(), getgid()); - if (tflag) { - if ((protoprivs = getprivs(0, quotatype, fspath)) != NULL) { - if (writetimes(protoprivs, tmpfd, quotatype) != 0 && - editit(tmpfil) && readtimes(protoprivs, tmpfil)) - putprivs(0L, protoprivs); - freeprivs(protoprivs); - } - close(tmpfd); - unlink(tmpfil); - exit(0); - } - for ( ; argc > 0; argc--, argv++) { - if ((id = getentry(*argv, quotatype)) == -1) - continue; - if ((curprivs = getprivs(id, quotatype, fspath)) == NULL) - exit(1); - if (writeprivs(curprivs, tmpfd, *argv, quotatype) == 0) - continue; - if (editit(tmpfil) && readprivs(curprivs, tmpfil)) - putprivs(id, curprivs); - freeprivs(curprivs); - } - close(tmpfd); - unlink(tmpfil); - exit(0); -} - -static void -usage(void) -{ - fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: edquota [-uh] [-f fspath] [-p username] username ...", - " edquota [-u] -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]", - " username ...", - " edquota -g [-h] [-f fspath] [-p groupname] groupname ...", - " edquota -g -e fspath[:bslim[:bhlim[:islim[:ihlim]]]] [-e ...]", - " groupname ...", - " edquota [-u] -t [-f fspath]", - " edquota -g -t [-f fspath]"); - exit(1); -} - -/* - * This routine converts a name for a particular quota type to - * an identifier. This routine must agree with the kernel routine - * getinoquota as to the interpretation of quota types. - */ -int -getentry(const char *name, int quotatype) -{ - struct passwd *pw; - struct group *gr; - - if (alldigits(name)) - return (atoi(name)); - switch(quotatype) { - case USRQUOTA: - if ((pw = getpwnam(name))) - return (pw->pw_uid); - warnx("%s: no such user", name); - sleep(3); - break; - case GRPQUOTA: - if ((gr = getgrnam(name))) - return (gr->gr_gid); - warnx("%s: no such group", name); - sleep(3); - break; - default: - warnx("%d: unknown quota type", quotatype); - sleep(3); - break; - } - sleep(1); - return (-1); -} - -/* - * Collect the requested quota information. - */ -struct quotause * -getprivs(long id, int quotatype, char *fspath) -{ - struct quotafile *qf; - struct fstab *fs; - struct quotause *qup, *quptail; - struct quotause *quphead; - - setfsent(); - quphead = quptail = NULL; - while ((fs = getfsent())) { - if (fspath && *fspath && strcmp(fspath, fs->fs_spec) && - strcmp(fspath, fs->fs_file)) - continue; - if (strcmp(fs->fs_vfstype, "ufs")) - continue; - if ((qf = quota_open(fs, quotatype, O_CREAT|O_RDWR)) == NULL) { - if (errno != EOPNOTSUPP) - warn("cannot open quotas on %s", fs->fs_file); - continue; - } - if ((qup = (struct quotause *)calloc(1, sizeof(*qup))) == NULL) - errx(2, "out of memory"); - qup->qf = qf; - strncpy(qup->fsname, fs->fs_file, sizeof(qup->fsname)); - if (quota_read(qf, &qup->dqblk, id) == -1) { - warn("cannot read quotas on %s", fs->fs_file); - freeprivs(qup); - continue; - } - if (quphead == NULL) - quphead = qup; - else - quptail->next = qup; - quptail = qup; - qup->next = 0; - } - if (quphead == NULL) { - warnx("No quotas on %s", fspath ? fspath : "any filesystems"); - } - endfsent(); - return (quphead); -} - -/* - * Store the requested quota information. - */ -void -putprivs(long id, struct quotause *quplist) -{ - struct quotause *qup; - - for (qup = quplist; qup; qup = qup->next) - if (quota_write_limits(qup->qf, &qup->dqblk, id) == -1) - warn("%s", qup->fsname); -} - -/* - * Take a list of priviledges and get it edited. - */ -int -editit(char *tmpf) -{ - long omask; - int pid, status; - - omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); - top: - if ((pid = fork()) < 0) { - - if (errno == EPROCLIM) { - warnx("you have too many processes"); - return(0); - } - if (errno == EAGAIN) { - sleep(1); - goto top; - } - warn("fork"); - return (0); - } - if (pid == 0) { - const char *ed; - - sigsetmask(omask); - setgid(getgid()); - setuid(getuid()); - if ((ed = getenv("EDITOR")) == (char *)0) - ed = _PATH_VI; - execlp(ed, ed, tmpf, (char *)0); - err(1, "%s", ed); - } - waitpid(pid, &status, 0); - sigsetmask(omask); - if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) - return (0); - return (1); -} - -/* - * Convert a quotause list to an ASCII file. - */ -int -writeprivs(struct quotause *quplist, int outfd, char *name, int quotatype) -{ - struct quotause *qup; - FILE *fd; - - ftruncate(outfd, 0); - lseek(outfd, 0, L_SET); - if ((fd = fdopen(dup(outfd), "w")) == NULL) - err(1, "%s", tmpfil); - fprintf(fd, "Quotas for %s %s:\n", qfextension[quotatype], name); - for (qup = quplist; qup; qup = qup->next) { - fprintf(fd, "%s: in use: %s, ", qup->fsname, - fmthumanvalblks(qup->dqblk.dqb_curblocks)); - fprintf(fd, "limits (soft = %s, ", - fmthumanvalblks(qup->dqblk.dqb_bsoftlimit)); - fprintf(fd, "hard = %s)\n", - fmthumanvalblks(qup->dqblk.dqb_bhardlimit)); - fprintf(fd, "\tinodes in use: %s, ", - fmthumanvalinos(qup->dqblk.dqb_curinodes)); - fprintf(fd, "limits (soft = %s, ", - fmthumanvalinos(qup->dqblk.dqb_isoftlimit)); - fprintf(fd, "hard = %s)\n", - fmthumanvalinos(qup->dqblk.dqb_ihardlimit)); - } - fclose(fd); - return (1); -} - -char * -fmthumanvalblks(int64_t blocks) -{ - static char numbuf[20]; - - if (hflag) { - humanize_number(numbuf, blocks < 0 ? 7 : 6, - dbtob(blocks), "", HN_AUTOSCALE, HN_NOSPACE); - return (numbuf); - } - snprintf(numbuf, sizeof(numbuf), "%juk", (uintmax_t)dbtokb(blocks)); - return(numbuf); -} - -char * -fmthumanvalinos(int64_t inos) -{ - static char numbuf[20]; - - if (hflag) { - humanize_number(numbuf, inos < 0 ? 7 : 6, - inos, "", HN_AUTOSCALE, HN_NOSPACE | HN_DIVISOR_1000); - return (numbuf); - } - snprintf(numbuf, sizeof(numbuf), "%ju", (uintmax_t)inos); - return(numbuf); -} - -/* - * Merge changes to an ASCII file into a quotause list. - */ -int -readprivs(struct quotause *quplist, char *inname) -{ - struct quotause *qup; - FILE *fd; - uintmax_t hardlimit, softlimit, curitems; - char hardunits, softunits, curitemunits; - int cnt; - char *cp; - struct dqblk dqblk; - char *fsp, line1[BUFSIZ], line2[BUFSIZ]; - - fd = fopen(inname, "r"); - if (fd == NULL) { - warnx("can't re-read temp file!!"); - return (0); - } - /* - * Discard title line, then read pairs of lines to process. - */ - (void) fgets(line1, sizeof (line1), fd); - while (fgets(line1, sizeof (line1), fd) != NULL && - fgets(line2, sizeof (line2), fd) != NULL) { - if ((fsp = strtok(line1, " \t:")) == NULL) { - warnx("%s: bad format", line1); - return (0); - } - if ((cp = strtok((char *)0, "\n")) == NULL) { - warnx("%s: %s: bad format", fsp, &fsp[strlen(fsp) + 1]); - return (0); - } - cnt = sscanf(cp, - " in use: %ju%c, limits (soft = %ju%c, hard = %ju%c)", - &curitems, &curitemunits, &softlimit, &softunits, - &hardlimit, &hardunits); - /* - * The next three check for old-style input formats. - */ - if (cnt != 6) - cnt = sscanf(cp, - " in use: %ju%c, limits (soft = %ju%c hard = %ju%c", - &curitems, &curitemunits, &softlimit, - &softunits, &hardlimit, &hardunits); - if (cnt != 6) - cnt = sscanf(cp, - " in use: %ju%c, limits (soft = %ju%c hard = %ju%c)", - &curitems, &curitemunits, &softlimit, - &softunits, &hardlimit, &hardunits); - if (cnt != 6) - cnt = sscanf(cp, - " in use: %ju%c, limits (soft = %ju%c, hard = %ju%c", - &curitems, &curitemunits, &softlimit, - &softunits, &hardlimit, &hardunits); - if (cnt != 6) { - warnx("%s:%s: bad format", fsp, cp); - return (0); - } - dqblk.dqb_curblocks = cvtblkval(curitems, curitemunits, - "current block count"); - dqblk.dqb_bsoftlimit = cvtblkval(softlimit, softunits, - "block soft limit"); - dqblk.dqb_bhardlimit = cvtblkval(hardlimit, hardunits, - "block hard limit"); - if ((cp = strtok(line2, "\n")) == NULL) { - warnx("%s: %s: bad format", fsp, line2); - return (0); - } - cnt = sscanf(&cp[7], - " in use: %ju%c limits (soft = %ju%c, hard = %ju%c)", - &curitems, &curitemunits, &softlimit, - &softunits, &hardlimit, &hardunits); - /* - * The next three check for old-style input formats. - */ - if (cnt != 6) - cnt = sscanf(&cp[7], - " in use: %ju%c limits (soft = %ju%c hard = %ju%c", - &curitems, &curitemunits, &softlimit, - &softunits, &hardlimit, &hardunits); - if (cnt != 6) - cnt = sscanf(&cp[7], - " in use: %ju%c limits (soft = %ju%c hard = %ju%c)", - &curitems, &curitemunits, &softlimit, - &softunits, &hardlimit, &hardunits); - if (cnt != 6) - cnt = sscanf(&cp[7], - " in use: %ju%c limits (soft = %ju%c, hard = %ju%c", - &curitems, &curitemunits, &softlimit, - &softunits, &hardlimit, &hardunits); - if (cnt != 6) { - warnx("%s: %s: bad format cnt %d", fsp, &cp[7], cnt); - return (0); - } - dqblk.dqb_curinodes = cvtinoval(curitems, curitemunits, - "current inode count"); - dqblk.dqb_isoftlimit = cvtinoval(softlimit, softunits, - "inode soft limit"); - dqblk.dqb_ihardlimit = cvtinoval(hardlimit, hardunits, - "inode hard limit"); - for (qup = quplist; qup; qup = qup->next) { - if (strcmp(fsp, qup->fsname)) - continue; - /* - * Cause time limit to be reset when the quota - * is next used if previously had no soft limit - * or were under it, but now have a soft limit - * and are over it. - */ - if (dqblk.dqb_bsoftlimit && - qup->dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit && - (qup->dqblk.dqb_bsoftlimit == 0 || - qup->dqblk.dqb_curblocks < - qup->dqblk.dqb_bsoftlimit)) - qup->dqblk.dqb_btime = 0; - if (dqblk.dqb_isoftlimit && - qup->dqblk.dqb_curinodes >= dqblk.dqb_isoftlimit && - (qup->dqblk.dqb_isoftlimit == 0 || - qup->dqblk.dqb_curinodes < - qup->dqblk.dqb_isoftlimit)) - qup->dqblk.dqb_itime = 0; - qup->dqblk.dqb_bsoftlimit = dqblk.dqb_bsoftlimit; - qup->dqblk.dqb_bhardlimit = dqblk.dqb_bhardlimit; - qup->dqblk.dqb_isoftlimit = dqblk.dqb_isoftlimit; - qup->dqblk.dqb_ihardlimit = dqblk.dqb_ihardlimit; - qup->flags |= FOUND; - /* Humanized input returns only approximate counts */ - if (hflag || - (dqblk.dqb_curblocks == qup->dqblk.dqb_curblocks && - dqblk.dqb_curinodes == qup->dqblk.dqb_curinodes)) - break; - warnx("%s: cannot change current allocation", fsp); - break; - } - } - fclose(fd); - /* - * Disable quotas for any filesystems that have not been found. - */ - for (qup = quplist; qup; qup = qup->next) { - if (qup->flags & FOUND) { - qup->flags &= ~FOUND; - continue; - } - qup->dqblk.dqb_bsoftlimit = 0; - qup->dqblk.dqb_bhardlimit = 0; - qup->dqblk.dqb_isoftlimit = 0; - qup->dqblk.dqb_ihardlimit = 0; - } - return (1); -} - -/* - * Convert a quotause list to an ASCII file of grace times. - */ -int -writetimes(struct quotause *quplist, int outfd, int quotatype) -{ - struct quotause *qup; - FILE *fd; - - ftruncate(outfd, 0); - lseek(outfd, 0, L_SET); - if ((fd = fdopen(dup(outfd), "w")) == NULL) - err(1, "%s", tmpfil); - fprintf(fd, "Time units may be: days, hours, minutes, or seconds\n"); - fprintf(fd, "Grace period before enforcing soft limits for %ss:\n", - qfextension[quotatype]); - for (qup = quplist; qup; qup = qup->next) { - fprintf(fd, "%s: block grace period: %s, ", - qup->fsname, cvtstoa(qup->dqblk.dqb_btime)); - fprintf(fd, "file grace period: %s\n", - cvtstoa(qup->dqblk.dqb_itime)); - } - fclose(fd); - return (1); -} - -/* - * Merge changes of grace times in an ASCII file into a quotause list. - */ -int -readtimes(struct quotause *quplist, char *inname) -{ - struct quotause *qup; - FILE *fd; - int cnt; - char *cp; - uintmax_t itime, btime, iseconds, bseconds; - char *fsp, bunits[10], iunits[10], line1[BUFSIZ]; - - fd = fopen(inname, "r"); - if (fd == NULL) { - warnx("can't re-read temp file!!"); - return (0); - } - /* - * Discard two title lines, then read lines to process. - */ - (void) fgets(line1, sizeof (line1), fd); - (void) fgets(line1, sizeof (line1), fd); - while (fgets(line1, sizeof (line1), fd) != NULL) { - if ((fsp = strtok(line1, " \t:")) == NULL) { - warnx("%s: bad format", line1); - return (0); - } - if ((cp = strtok((char *)0, "\n")) == NULL) { - warnx("%s: %s: bad format", fsp, &fsp[strlen(fsp) + 1]); - return (0); - } - cnt = sscanf(cp, - " block grace period: %ju %s file grace period: %ju %s", - &btime, bunits, &itime, iunits); - if (cnt != 4) { - warnx("%s:%s: bad format", fsp, cp); - return (0); - } - if (cvtatos(btime, bunits, &bseconds) == 0) - return (0); - if (cvtatos(itime, iunits, &iseconds) == 0) - return (0); - for (qup = quplist; qup; qup = qup->next) { - if (strcmp(fsp, qup->fsname)) - continue; - qup->dqblk.dqb_btime = bseconds; - qup->dqblk.dqb_itime = iseconds; - qup->flags |= FOUND; - break; - } - } - fclose(fd); - /* - * reset default grace periods for any filesystems - * that have not been found. - */ - for (qup = quplist; qup; qup = qup->next) { - if (qup->flags & FOUND) { - qup->flags &= ~FOUND; - continue; - } - qup->dqblk.dqb_btime = 0; - qup->dqblk.dqb_itime = 0; - } - return (1); -} - -/* - * Convert seconds to ASCII times. - */ -char * -cvtstoa(uint64_t secs) -{ - static char buf[20]; - - if (secs % (24 * 60 * 60) == 0) { - secs /= 24 * 60 * 60; - sprintf(buf, "%ju day%s", (uintmax_t)secs, - secs == 1 ? "" : "s"); - } else if (secs % (60 * 60) == 0) { - secs /= 60 * 60; - sprintf(buf, "%ju hour%s", (uintmax_t)secs, - secs == 1 ? "" : "s"); - } else if (secs % 60 == 0) { - secs /= 60; - sprintf(buf, "%ju minute%s", (uintmax_t)secs, - secs == 1 ? "" : "s"); - } else - sprintf(buf, "%ju second%s", (uintmax_t)secs, - secs == 1 ? "" : "s"); - return (buf); -} - -/* - * Convert ASCII input times to seconds. - */ -int -cvtatos(uint64_t period, char *units, uint64_t *seconds) -{ - - if (bcmp(units, "second", 6) == 0) - *seconds = period; - else if (bcmp(units, "minute", 6) == 0) - *seconds = period * 60; - else if (bcmp(units, "hour", 4) == 0) - *seconds = period * 60 * 60; - else if (bcmp(units, "day", 3) == 0) - *seconds = period * 24 * 60 * 60; - else { - warnx("%s: bad units, specify %s\n", units, - "days, hours, minutes, or seconds"); - return (0); - } - return (1); -} - -/* - * Convert a limit to number of disk blocks. - */ -uint64_t -cvtblkval(uint64_t limit, char units, const char *itemname) -{ - - switch(units) { - case 'B': - case 'b': - limit = btodb(limit); - break; - case '\0': /* historic behavior */ - case ',': /* historic behavior */ - case ')': /* historic behavior */ - case 'K': - case 'k': - limit *= btodb(1024); - break; - case 'M': - case 'm': - limit *= btodb(1048576); - break; - case 'G': - case 'g': - limit *= btodb(1073741824); - break; - case 'T': - case 't': - limit *= btodb(1099511627776); - break; - case 'P': - case 'p': - limit *= btodb(1125899906842624); - break; - case 'E': - case 'e': - limit *= btodb(1152921504606846976); - break; - case ' ': - errx(2, "No space permitted between value and units for %s\n", - itemname); - break; - default: - errx(2, "%ju%c: unknown units for %s, specify " - "none, K, M, G, T, P, or E\n", - (uintmax_t)limit, units, itemname); - break; - } - return (limit); -} - -/* - * Convert a limit to number of inodes. - */ -uint64_t -cvtinoval(uint64_t limit, char units, const char *itemname) -{ - - switch(units) { - case 'B': - case 'b': - case '\0': /* historic behavior */ - case ',': /* historic behavior */ - case ')': /* historic behavior */ - break; - case 'K': - case 'k': - limit *= 1000; - break; - case 'M': - case 'm': - limit *= 1000000; - break; - case 'G': - case 'g': - limit *= 1000000000; - break; - case 'T': - case 't': - limit *= 1000000000000; - break; - case 'P': - case 'p': - limit *= 1000000000000000; - break; - case 'E': - case 'e': - limit *= 1000000000000000000; - break; - case ' ': - errx(2, "No space permitted between value and units for %s\n", - itemname); - break; - default: - errx(2, "%ju%c: unknown units for %s, specify " - "none, K, M, G, T, P, or E\n", - (uintmax_t)limit, units, itemname); - break; - } - return (limit); -} - -/* - * Free a list of quotause structures. - */ -void -freeprivs(struct quotause *quplist) -{ - struct quotause *qup, *nextqup; - - for (qup = quplist; qup; qup = nextqup) { - quota_close(qup->qf); - nextqup = qup->next; - free(qup); - } -} - -/* - * Check whether a string is completely composed of digits. - */ -int -alldigits(const char *s) -{ - int c; - - c = *s++; - do { - if (!isdigit(c)) - return (0); - } while ((c = *s++)); - return (1); -} diff --git a/usr.sbin/edquota/pathnames.h b/usr.sbin/edquota/pathnames.h deleted file mode 100644 index 53bfbfe..0000000 --- a/usr.sbin/edquota/pathnames.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD$ - */ - -#include - -#undef _PATH_TMP -#define _PATH_TMP "/tmp/EdP.aXXXXX" diff --git a/usr.sbin/eeprom/Makefile b/usr.sbin/eeprom/Makefile deleted file mode 100644 index 61b48a2..0000000 --- a/usr.sbin/eeprom/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../ofwdump - -PROG= eeprom -MAN= eeprom.8 -MANSUBDIR= /sparc64 -SRCS= eeprom.c ofw_options.c ofw_util.c -CFLAGS+= -I${.CURDIR}/../ofwdump - -.include diff --git a/usr.sbin/eeprom/eeprom.8 b/usr.sbin/eeprom/eeprom.8 deleted file mode 100644 index e132da9..0000000 --- a/usr.sbin/eeprom/eeprom.8 +++ /dev/null @@ -1,700 +0,0 @@ -.\" Copyright (c) 1996 The NetBSD Foundation, Inc. -.\" Copyright (c) 2004 Marius Strobl -.\" All rights reserved. -.\" -.\" This code is derived from software contributed to The NetBSD Foundation -.\" by Jason R. Thorpe. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS -.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS -.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" from: NetBSD: eeprom.8,v 1.11 2003/03/31 01:31:39 perry Exp -.\" $FreeBSD$ -.\" -.Dd September 1, 2006 -.Dt EEPROM 8 sparc64 -.Os -.Sh NAME -.Nm eeprom -.Nd "display or modify contents of the EEPROM or NVRAM" -.Sh SYNOPSIS -.Nm -.Fl a -.Nm -.Op Fl -.Ar name Ns Op = Ns Ar value -.Ar ... -.Sh DESCRIPTION -The -.Nm -utility provides an interface for displaying and changing the system's -configuration variables contained in EEPROM or NVRAM. -In the first synopsis form, all available configuration variables and their -current values are printed. -In the second form, only the variable selected by -.Ar name -and its value is printed or changed if -.Ar name -is followed by -.Ql = -and a -.Ar value . -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl -Commands for displaying or changing variables are taken from stdin, allowing -one -.Ar name -or one -.Ar name -and -.Ar value -pair per line. -The output is printed on stdout. -.It Fl a -Print all available configuration variables and their current values. -.El -.Sh VARIABLES AND VALUES -Below are variables and values that one is likely to find on a system equipped -with OpenBoot 3.x and Open Firmware respectively. -.Pp -Note: the attempt to set a variable to an illegal value results in the -Open Firmware setting it to some legal value instead. -The -.Nm -utility will detect this, try to recover the previous value of the variable -and issue a warning telling that the requested value could not be set. -.Bl -tag -width ".Va last-hardware-update" -.It Va auto-boot? -If -.Dq Li true , -the system will try to boot automatically from the devices listed in -.Va boot-device -and -.Va diag-device -respectively, using the command specified in -.Va boot-command -at power-up. -Default: -.Dq Li true . -.It Va auto-boot-retry? -If set to -.Dq Li true -and -.Va auto-boot? -is also set to -.Dq Li true , -the system will try to boot from the specified boot devices forever. -Default: -.Dq Li false . -.It Va ansi-terminal? -If -.Dq Li false , -.Tn ANSI -escape sequences are not interpreted by the terminal emulator. -Default: -.Dq Li true . -.It Va boot-command -Command executed when -.Va auto-boot? -is set to -.Dq Li true . -Default: -.Dq Li boot . -.It Va boot-device -Default device to boot from if -.Va diag-switch? -is set to -.Dq Li false . -Takes one or more device aliases or device paths. -The boot devices are sequentially tried to boot from, beginning with the first -one specified. -Default: -.Dq Li "net disk" . -.It Va cpci-probe-list -Digits in the format -.Dq Li 0,1,2 -specifying in which order to probe the devices on the CompactPCI bus at -power-up. -Default: system-dependent. -.It Va boot-file -Default arguments for boot when -.Va diag-switch? -is set to -.Dq Li false . -When empty, the secondary boot loader will choose the file to boot. -Default: empty string. -.It Va diag-device -Like -.Va boot-device . -Used when -.Va diag-switch? -is set to -.Dq Li true . -Default: -.Dq Li net . -.It Va diag-file -Like -.Va boot-file . -Used when -.Va diag-switch? -is set to -.Dq Li true . -Default: empty string. -.It Va diag-level -Level of diagnostics to run when -.Va diag-switch? -is set to -.Dq Li true . -Possible values are -.Dq Li max , -.Dq Li menus , -.Dq Li min -and -.Dq Li off -(depending on the system model). -When set to -.Dq Li off , -the Power-On Self Test (POST) is not run. -The other values are interpreted by the POST. -Default: -.Dq Li min -or -.Dq Li max -(system-dependent). -.It Va diag-switch? -If -.Dq Li true , -the system will boot and run in diagnostic mode. -Default: -.Dq Li false -or -.Dq Li true -(system-dependent). -.It Va env-monitor -Enables or disables the Advanced System Monitoring (ASM). -Possible values are -.Dq Li enabled -and -.Dq Li disabled . -Default: -.Dq Li enabled . -.It Va fcode-debug? -Used for debugging FCode programs. -If set to -.Dq Li true , -names of additional FCodes are registered in the Forth dictionary. -Default: -.Dq Li false . -.It Va hardware-revision -A string describing the system hardware version. -Default: system-dependent. -.It Va input-device -One of the strings -.Dq Li keyboard , -.Dq Li ttya , -or -.Dq Li ttyb , -specifying the default console input device. -Default: -.Dq Li keyboard -or -.Dq Li ttya -(system-dependent). -.It Va keyboard-click? -If set to -.Dq Li true , -the keys click annoyingly. -Default: -.Dq Li false . -.It Va keymap -Keymap for a custom keyboard. -Default: empty string. -.It Va last-hardware-update -Similar to -.Va hardware-revision , -describing when the hardware was last updated. -Default: system-dependent. -.It Va last-poweroff-cause -Cause of the last power-off. -Used internally by the OpenBoot PROM. -Default: -.Dq Li 0 . -.It Va load-base -Default address where client programs are loaded to. -It is unlikely that this value should ever be changed. -Default: -.Dq Li 16384 . -.It Va local-mac-address? -If set to -.Dq Li false , -all Ethernet devices with FCode will use the system default MAC address. -If set to -.Dq Li true , -Ethernet devices with FCode that contains a unique MAC address will use it -rather than the system's default MAC address. -Default: -.Dq Li false . -.Pp -Ethernet devices with FCode include those supported by -.Xr dc 4 , -.Xr gem 4 -and -.Xr hme 4 . -Please see the respective manual page for further information. -.It Va mfg-mode -Manufacture test mode interpreted by the POST. -Possible values are -.Dq Li chamber -and -.Dq Li off . -Default: -.Dq Li off . -.It Va mfg-switch? -If set to -.Dq Li true , -manufacturing tests are repeated until stopped by pressing STOP-A. -Default: -.Dq Li off . -.It Va net-timeout -If set to -.Dq Li 0 , -the system will try to boot forever when the boot device used is a network -device. -Any non-zero value is interpreted as minutes to try a network boot. -Default: -.Dq Li 0 . -.It Va nvramrc -Contents of the NVRAMRC. -Default: empty string. -.Pp -While -.Va nvramrc -can be set using -.Nm , -it is preferred to use -.Ic nvedit -in the boot monitor instead. -.It Va oem-banner -A string displayed at power-up, rather than the default banner. -Used when -.Va oem-banner? -is set to -.Dq Li true . -Default: system-dependent. -.It Va oem-banner? -If set to -.Dq Li true , -the string stored in -.Va oem-banner -is displayed at power-up rather than the default banner. -Default: system-dependent. -.It Va oem-logo -A logo displayed at power-up when -.Va oem-logo? -is set to -.Dq Li true , -rather than the default logo. -The logo has to be 512 bytes in size, containing a 64x64-bit monochrome image -in Sun Raster format without the leading 32-byte header. -Default: system-dependent. -.Pp -To set the logo with -.Nm , -give the pathname of the file containing the image as the -.Ar value . -Using an empty -.Ar value -will remove the image. -.It Va oem-logo? -If set to -.Dq Li true , -the logo stored in -.Va oem-logo -is displayed at power-up rather than the default logo. -.It Va output-device -One of the strings -.Dq Li screen , -.Dq Li ttya , -or -.Dq Li ttyb , -specifying the default console output device. -Default: -.Dq Li screen -or -.Dq Li ttya -(system-dependent). -.It Va pcia-probe-list -Digits in the format -.Dq Li 1,2,3 -specifying in which order to probe the devices on the PCI bus A. -Default: system-dependent. -.It Va pcib-probe-list -Like -.Va pcia-probe-list , -but for PCI bus B. -Default: system-dependent. -.It Va #power-cycles -Number of power-cycles. -Automatically incremented on each power-cycle. -Default: system-dependent. -.It Va sbus-probe-list -Digits in the format -.Dq Li 0123 -specifying in which order to probe the SBus slots at power-up. -Default: system-dependent. -.It Va screen-#columns -An integer specifying the screen width in characters per line. -Default: -.Dq Li 80 . -.It Va screen-#rows -An integer specifying the screen height in lines. -Default: -.Dq Li 34 . -.It Va scsi-initiator-id -The SCSI ID of SCSI controllers in the range of [0-7] or [0-f] (depending -on the controller). -A SCSI controller may or may not adhere to this setting, depending on its -FCode and device driver. -Default: -.Dq Li 7 . -.It Va security-#badlogins -Number of incorrect password attempts when -.Va security-mode -is set to -.Dq Li command -or -.Dq Li full . -Default: -.Dq Li 0 . -.It Va security-mode -Boot monitor security level. -One of the three possible values -.Dq Li full , -.Dq Li command , -or -.Dq Li none . -When set to -.Dq Li full , -all boot monitor commands except for -.Ic go -require the password. -When set to -.Dq Li command , -all boot monitor commands except for -.Ic boot -and -.Ic go -require the password. -When set to -.Dq Li none , -no password is required. -Default: -.Dq Li none . -.Pp -When -.Nm -is used to set -.Va security-mode -to -.Dq Li full -or -.Dq Li command , -you will be prompted for the password. -When -.Va security-mode -is set to -.Dq Li none , -.Nm -will clear the password. -.It Va security-password -The password used when -.Va security-mode -is set to -.Dq Li full -or -.Dq Li command . -The maximum length for this password is 8 characters. -All characters exceeding this length will be ignored. -The value displayed for -.Va security-password -is always an empty string, even when a password is set. -Default: empty string. -.Pp -When -.Va security-mode -is set to -.Dq Li full -or -.Dq Li command , -.Nm -can be used to enter a new password using any -.Ar value -for -.Va security-password -on the command line. -You will be prompted by -.Nm -to type in the new password in this case. -Trying to set -.Va security-password -when -.Va security-mode -is set to -.Dq Li none -using -.Nm -has no effect. -.It Va selftest-#megs -An integer specifying the number of megabytes of memory to test upon -power-up when -.Va diag-switch? -is set to -.Dq Li false . -Default: -.Dq Li 1 . -.It Va shutdown-temperature -Temperature at which the ASM issues an over-temperature shutdown. -Default: system-dependent. -.It Va silent-mode -If set to -.Dq Li true , -memory test messages will not be displayed at power-up. -Default: -.Dq Li false . -.It Va sunmon-compat? -If set to -.Dq Li true , -the old bootROM interface will be used while in the boot monitor, -rather than the OpenBoot PROM interface. -Default: -.Dq Li false . -.It Va system-board-date -Manufacturing date of the system board. -Default: system-dependent. -.It Va system-board-serial# -Serial number of the system board. -Default: system-dependent. -.It Va tpe-link-test? -Enable link test on 10baseT and 100baseTX Ethernet devices. -Default: -.Dq Li true . -.It Va ttya-mode -A string of five comma separated fields in the format -.Dq Li 9600,8,n,1,- . -The first field is the baud rate. -The second field is the number of data bits. -The third field is the parity; acceptable values for parity are -.Ql n -(none), -.Ql e -(even), -.Ql o -(odd), -.Ql m -(mark), and -.Ql s -(space). -The fourth field is the number of stop bits. -The fifth field is the -.Dq handshake -field; acceptable values are -.Ql - -(none), -.Ql h -(RTS/CTS), and -.Ql s -(Xon/Xoff). -Default: -.Dq Li 9600,8,n,1,- . -.It Va ttya-ignore-cd -If set to -.Dq Li true , -the system will ignore carrier detect. -Default: -.Dq Li true . -.It Va ttya-rts-dtr-off -If set to -.Dq Li true , -the system will ignore RTS/DTR. -Default: -.Dq Li false . -.It Va ttyb-mode -Like -.Va ttya-mode , -but for ttyb. -Default: -.Dq Li 9600,8,n,1,- . -.It Va ttyb-ignore-cd -Like -.Va ttya-ignore-cd , -but for ttyb. -Default: -.Dq Li true . -.It Va ttyb-rts-dtr-off -Like -.Va ttya-rts-dtr-off , -but for ttyb. -Default: -.Dq Li false . -.It Va use-boot-table? -Use boot table defined by the OEM. -Default: system-dependent. -.It Va use-nvramrc? -If set to -.Dq Li true , -the script stored in -.Va nvramrc -will be executed during start-up. -Default: -.Dq Li false . -.It Va warning-temperature -Temperature at which the ASM issues an over-temperature warning. -Default: system-dependent. -.It Va watchdog-enable? -Enables or disables the system watchdog timer. -Default: -.Dq Li false . -.It Va watchdog-reboot? -If set to -.Dq Li true , -the system will reboot upon terminal count of the system watchdog timer. -If set to -.Dq Li false , -the system will fall into the boot monitor. -Default: -.Dq Li false . -.It Va watchdog-timeout -Expiry limit for the system watchdog timer. -Range and unit depend on the system model. -Default: system-dependent. -.El -.Sh EXAMPLES -Print all available configuration variables and their current values: -.Pp -.Dl "eeprom -a" -.Pp -Print the current value of the -.Va local-mac-address? -variable: -.Pp -.Dl "eeprom local-mac-address\e?" -.Pp -Set the value of the -.Va local-mac-address? -variable to -.Dq Li true : -.Pp -.Dl "eeprom local-mac-address\e?=true" -.Pp -Note that the -.Ql \e -in the above examples is used to keep the shell from interpreting the -.Ql \&? . -.Pp -Write an image to the -.Va oem-logo -variable: -.Pp -.Dl "eeprom oem-logo=/path/to/image.raw" -.Pp -Remove the image from the -.Va oem-logo -variable again: -.Pp -.Dl "eeprom oem-logo=" -.Pp -Set the value of the -.Va security-mode -variable to -.Dq Li full , -and set the password: -.Bd -literal -offset indent -eeprom security-mode=full -New password: -Retype new password: -.Ed -.Pp -Remember that the maximum length for the password is 8 characters. -All characters exceeding this length will be ignored. -.Pp -Set a new password when the -.Va security-mode -variable is set to -.Dq Li command -or -.Dq Li full : -.Bd -literal -offset indent -eeprom security-password= -New password: -Retype new password: -.Ed -.Sh SEE ALSO -.Xr dc 4 , -.Xr gem 4 , -.Xr hme 4 , -.Xr ofwdump 8 -.Sh HISTORY -The -.Nm -utility first appeared in -.Bx 4.4 . -It was adopted from there by -.Fx 2.0 . -The -.Nm -utility was removed from -.Fx -again after -.Fx 2.1.7 -because the utility was unused at that time. -The present implementation of the -.Nm -utility first appeared in -.Fx 5.3 . -It is inspired by the -.Nx -.Xr eeprom 8 -and SunOS/Solaris -.Xr eeprom 1M -utilities. -.Sh AUTHORS -.An -nosplit -The -.Nm -utility uses base code from the -.Nx -version written by -.An "Jason R. Thorpe" . -The handlers for the Open Firmware -.Pa /options -node were written by -.An "Marius Strobl" Aq marius@FreeBSD.org . -The code for accessing the Open Firmware device tree is shared with the -.Xr ofwdump 8 -utility written by -.An "Thomas Moestl" Aq tmm@FreeBSD.org . -.Sh BUGS -Currently, -.Nm -only supports systems equipped with Open Firmware and is only tested on Sun -Microsystems sun4u machines. diff --git a/usr.sbin/eeprom/eeprom.c b/usr.sbin/eeprom/eeprom.c deleted file mode 100644 index 30c1a93..0000000 --- a/usr.sbin/eeprom/eeprom.c +++ /dev/null @@ -1,146 +0,0 @@ -/*- - * Copyright (c) 1996 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Jason R. Thorpe. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * from: NetBSD: main.c,v 1.15 2001/02/19 23:22:42 cgd Exp - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -#include "ofw_options.h" - -static int action(char *); -static void dump_config(void); -static void usage(void); - -static void -usage(void) -{ - - fprintf(stderr, - "usage: eeprom -a\n" - " eeprom [-] name[=value] ...\n"); - exit(EX_USAGE); -} - -int -main(int argc, char *argv[]) -{ - int do_stdin, opt; - int aflag, rv; - char *cp; - char line[BUFSIZ]; - - aflag = do_stdin = 0; - rv = EX_OK; - while ((opt = getopt(argc, argv, "-a")) != -1) { - switch (opt) { - case '-': - if (aflag) - usage(); - do_stdin = 1; - break; - case 'a': - if (do_stdin) - usage(); - aflag = 1; - break; - case '?': - default: - usage(); - /* NOTREACHED */ - } - } - argc -= optind; - argv += optind; - - if (aflag) { - if (argc != 0) - usage(); - dump_config(); - } else { - if (do_stdin) { - while (fgets(line, BUFSIZ, stdin) != NULL && - rv == EX_OK) { - if (line[0] == '\n') - continue; - if ((cp = strrchr(line, '\n')) != NULL) - *cp = '\0'; - rv = action(line); - } - if (ferror(stdin)) - err(EX_NOINPUT, "stdin"); - } else { - if (argc == 0) - usage(); - while (argc && rv == EX_OK) { - rv = action(*argv); - ++argv; - --argc; - } - } - } - return (rv); -} - -static int -action(char *line) -{ - int rv; - char *keyword, *arg; - - keyword = strdup(line); - if (keyword == NULL) - err(EX_OSERR, "malloc() failed"); - if ((arg = strrchr(keyword, '=')) != NULL) - *arg++ = '\0'; - switch (rv = ofwo_action(keyword, arg)) { - case EX_UNAVAILABLE: - warnx("nothing available for '%s'.", keyword); - break; - case EX_DATAERR: - warnx("invalid value '%s' for '%s'.", arg, keyword); - break; - } - free(keyword); - return(rv); -} - -static void -dump_config(void) -{ - - ofwo_dump(); -} diff --git a/usr.sbin/eeprom/ofw_options.c b/usr.sbin/eeprom/ofw_options.c deleted file mode 100644 index eb7437f..0000000 --- a/usr.sbin/eeprom/ofw_options.c +++ /dev/null @@ -1,310 +0,0 @@ -/*- - * Copyright (c) 2004 Marius Strobl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -/* - * Handlers for Open Firmware /options node. - */ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "ofw_options.h" -#include "ofw_util.h" - -#define OFWO_LOGO 512 -#define OFWO_MAXPROP 31 -#define OFWO_MAXPWD 8 - -struct ofwo_extabent { - const char *ex_prop; - int (*ex_handler)(const struct ofwo_extabent *, int, - const void *, int, const char *); -}; - -static int ofwo_oemlogo(const struct ofwo_extabent *, int, const void *, - int, const char *); -static int ofwo_secmode(const struct ofwo_extabent *, int, const void *, - int, const char *); -static int ofwo_secpwd(const struct ofwo_extabent *, int, const void *, - int, const char *); - -static const struct ofwo_extabent const ofwo_extab[] = { - { "oem-logo", ofwo_oemlogo }, - { "security-mode", ofwo_secmode }, - { "security-password", ofwo_secpwd }, - { NULL, NULL } -}; - -static int ofwo_setpass(int); -static int ofwo_setstr(int, const void *, int, const char *, const char *); - -static __inline void -ofwo_printprop(const char *prop, const char* buf, int buflen) -{ - - printf("%s: %.*s\n", prop, buflen, buf); -} - -static int -ofwo_oemlogo(const struct ofwo_extabent *exent, int fd, const void *buf, - int buflen, const char *val) -{ - int lfd; - char logo[OFWO_LOGO + 1]; - - if (val) { - if (val[0] == '\0') - ofw_setprop(fd, ofw_optnode(fd), exent->ex_prop, "", 1); - else { - if ((lfd = open(val, O_RDONLY)) == -1) { - warn("could not open '%s'", val); - return (EX_USAGE); - } - if (read(lfd, logo, OFWO_LOGO) != OFWO_LOGO || - lseek(lfd, 0, SEEK_END) != OFWO_LOGO) { - close(lfd); - warnx("logo '%s' has wrong size.", val); - return (EX_USAGE); - } - close(lfd); - logo[OFWO_LOGO] = '\0'; - if (ofw_setprop(fd, ofw_optnode(fd), exent->ex_prop, - logo, OFWO_LOGO + 1) != OFWO_LOGO) - errx(EX_IOERR, "writing logo failed."); - } - } else - if (buflen != 0) - printf("%s: \n", exent->ex_prop); - else - ofwo_printprop(exent->ex_prop, (const char *)buf, - buflen); - return (EX_OK); -} - -static int -ofwo_secmode(const struct ofwo_extabent *exent, int fd, const void *buf, - int buflen, const char *val) -{ - int res; - - if (val) { - if (strcmp(val, "full") == 0 || strcmp(val, "command") == 0) { - if ((res = ofwo_setpass(fd)) != EX_OK) - return (res); - if ((res = ofwo_setstr(fd, buf, buflen, exent->ex_prop, - val)) != EX_OK) - ofw_setprop(fd, ofw_optnode(fd), - "security-password", "", 1); - return (res); - } - if (strcmp(val, "none") == 0) { - ofw_setprop(fd, ofw_optnode(fd), "security-password", - "", 1); - return (ofwo_setstr(fd, buf, buflen, exent->ex_prop, - val)); - } - return (EX_DATAERR); - } else - ofwo_printprop(exent->ex_prop, (const char *)buf, buflen); - return (EX_OK); -} - -static int -ofwo_secpwd(const struct ofwo_extabent *exent, int fd, const void *buf, - int buflen, const char *val) -{ - void *pbuf; - int len, pblen, rv; - - pblen = 0; - rv = EX_OK; - pbuf = NULL; - if (val) { - len = ofw_getprop_alloc(fd, ofw_optnode(fd), "security-mode", - &pbuf, &pblen, 1); - if (len <= 0 || strncmp("none", (char *)pbuf, len) == 0) { - rv = EX_CONFIG; - warnx("no security mode set."); - } else if (strncmp("command", (char *)pbuf, len) == 0 || - strncmp("full", (char *)pbuf, len) == 0) { - rv = ofwo_setpass(fd); - } else { - rv = EX_CONFIG; - warnx("invalid security mode."); - } - } else - ofwo_printprop(exent->ex_prop, (const char *)buf, buflen); - if (pbuf != NULL) - free(pbuf); - return (rv); -} - -static int -ofwo_setpass(int fd) -{ - char pwd1[OFWO_MAXPWD + 1], pwd2[OFWO_MAXPWD + 1]; - - if (readpassphrase("New password:", pwd1, sizeof(pwd1), - RPP_ECHO_OFF | RPP_REQUIRE_TTY) == NULL || - readpassphrase("Retype new password:", pwd2, sizeof(pwd2), - RPP_ECHO_OFF | RPP_REQUIRE_TTY) == NULL) - errx(EX_USAGE, "failed to get password."); - if (strlen(pwd1) == 0) { - printf("Password unchanged.\n"); - return (EX_OK); - } - if (strcmp(pwd1, pwd2) != 0) { - printf("Mismatch - password unchanged.\n"); - return (EX_USAGE); - } - ofw_setprop(fd, ofw_optnode(fd), "security-password", pwd1, - strlen(pwd1) + 1); - return (EX_OK); -} - -static int -ofwo_setstr(int fd, const void *buf, int buflen, const char *prop, - const char *val) -{ - void *pbuf; - int len, pblen, rv; - phandle_t optnode; - char *oval; - - pblen = 0; - rv = EX_OK; - pbuf = NULL; - optnode = ofw_optnode(fd); - ofw_setprop(fd, optnode, prop, val, strlen(val) + 1); - len = ofw_getprop_alloc(fd, optnode, prop, &pbuf, &pblen, 1); - if (len < 0 || strncmp(val, (char *)pbuf, len) != 0) { - /* - * The value is too long for this property and the OFW has - * truncated it to fit or the value is illegal and a legal - * one has been written instead (e.g. attempted to write - * "foobar" to a "true"/"false"-property) - try to recover - * the old value. - */ - rv = EX_DATAERR; - if ((oval = malloc(buflen + 1)) == NULL) - err(EX_OSERR, "malloc() failed."); - strncpy(oval, buf, buflen); - oval[buflen] = '\0'; - len = ofw_setprop(fd, optnode, prop, oval, buflen + 1); - if (len != buflen) - errx(EX_IOERR, "recovery of old value failed."); - free(oval); - goto out; - } - printf("%s: %.*s%s->%s%.*s\n", prop, buflen, (const char *)buf, - buflen > 0 ? " " : "", len > 0 ? " " : "", len, (char *)pbuf); -out: - if (pbuf != NULL) - free(pbuf); - return (rv); -} - -void -ofwo_dump(void) -{ - void *pbuf; - int fd, len, nlen, pblen; - phandle_t optnode; - char prop[OFWO_MAXPROP + 1]; - const struct ofwo_extabent *ex; - - pblen = 0; - pbuf = NULL; - fd = ofw_open(O_RDONLY); - optnode = ofw_optnode(fd); - for (nlen = ofw_firstprop(fd, optnode, prop, sizeof(prop)); nlen != 0; - nlen = ofw_nextprop(fd, optnode, prop, prop, sizeof(prop))) { - len = ofw_getprop_alloc(fd, optnode, prop, &pbuf, &pblen, 1); - if (len < 0) - continue; - if (strcmp(prop, "name") == 0) - continue; - for (ex = ofwo_extab; ex->ex_prop != NULL; ++ex) - if (strcmp(ex->ex_prop, prop) == 0) - break; - if (ex->ex_prop != NULL) - (*ex->ex_handler)(ex, fd, pbuf, len, NULL); - else - ofwo_printprop(prop, (char *)pbuf, len); - } - if (pbuf != NULL) - free(pbuf); - ofw_close(fd); -} - -int -ofwo_action(const char *prop, const char *val) -{ - void *pbuf; - int fd, len, pblen, rv; - const struct ofwo_extabent *ex; - - pblen = 0; - rv = EX_OK; - pbuf = NULL; - if (strcmp(prop, "name") == 0) - return (EX_UNAVAILABLE); - if (val) - fd = ofw_open(O_RDWR); - else - fd = ofw_open(O_RDONLY); - len = ofw_getprop_alloc(fd, ofw_optnode(fd), prop, &pbuf, &pblen, 1); - if (len < 0) { - rv = EX_UNAVAILABLE; - goto out; - } - for (ex = ofwo_extab; ex->ex_prop != NULL; ++ex) - if (strcmp(ex->ex_prop, prop) == 0) - break; - if (ex->ex_prop != NULL) - rv = (*ex->ex_handler)(ex, fd, pbuf, len, val); - else if (val) - rv = ofwo_setstr(fd, pbuf, len, prop, val); - else - ofwo_printprop(prop, (char *)pbuf, len); -out: - if (pbuf != NULL) - free(pbuf); - ofw_close(fd); - return (rv); -} diff --git a/usr.sbin/eeprom/ofw_options.h b/usr.sbin/eeprom/ofw_options.h deleted file mode 100644 index 5bc6656..0000000 --- a/usr.sbin/eeprom/ofw_options.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2004 Marius Strobl - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef OFW_OPTIONS_H -#define OFW_OPTIONS_H - -void ofwo_dump(void); -int ofwo_action(const char *prop, const char *val); - -#endif /* OFW_OPTIONS_H */ diff --git a/usr.sbin/extattr/Makefile b/usr.sbin/extattr/Makefile deleted file mode 100644 index 8e2b5f7..0000000 --- a/usr.sbin/extattr/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $FreeBSD$ - -PROG= rmextattr -MAN= rmextattr.8 - -LINKS+= ${BINDIR}/rmextattr ${BINDIR}/getextattr -LINKS+= ${BINDIR}/rmextattr ${BINDIR}/setextattr -LINKS+= ${BINDIR}/rmextattr ${BINDIR}/lsextattr - -MLINKS+= rmextattr.8 setextattr.8 -MLINKS+= rmextattr.8 getextattr.8 -MLINKS+= rmextattr.8 lsextattr.8 - -.include diff --git a/usr.sbin/extattr/rmextattr.8 b/usr.sbin/extattr/rmextattr.8 deleted file mode 100644 index c51fa6d..0000000 --- a/usr.sbin/extattr/rmextattr.8 +++ /dev/null @@ -1,135 +0,0 @@ -.\"- -.\" Copyright (c) 2000, 2001 Robert N. M. Watson -.\" Copyright (c) 2002 Networks Associates Technology, Inc. -.\" All rights reserved. -.\" -.\" This software was developed for the FreeBSD Project by Poul-Henning -.\" Kamp and Network Associates Laboratories, the Security Research Division -.\" of Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 -.\" ("CBOSS"), as part of the DARPA CHATS research program -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd August 30, 2000 -.Dt RMEXTATTR 8 -.Os -.Sh NAME -.Nm getextattr , -.Nm lsextattr , -.Nm rmextattr , -.Nm setextattr -.Nd manipulate extended attributes -.Sh SYNOPSIS -.Nm getextattr -.Op Fl fhqsx -.Ar attrnamespace -.Ar attrname -.Ar filename ... -.Nm lsextattr -.Op Fl fhq -.Ar attrnamespace -.Ar filename ... -.Nm rmextattr -.Op Fl fhq -.Ar attrnamespace -.Ar attrname -.Ar filename ... -.Nm setextattr -.Op Fl fhnq -.Ar attrnamespace -.Ar attrname -.Ar attrvalue -.Ar filename ... -.Sh DESCRIPTION -These -utilities -are user tools to manipulate the named extended attributes on files and -directories. -The -.Ar attrnamespace -argument should be the namespace of the attribute to retrieve: legal -values are -.Cm user -and -.Cm system . -The -.Ar attrname -argument should be the name of the attribute, -.Ar filename -the name of the target file or directory, -.Ar attrvalue -a string to store in the attribute. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl f -(Force.) -Ignore errors on individual filenames and continue with -the remaining arguments. -.It Fl h -(No follow.) -If the file is a symbolic link, perform the operation on the -link itself rather than the file that the link points to. -.It Fl n -.Dv ( NUL Ns --terminate.) -.Dv NUL Ns --terminate the extent content written out. -.It Fl q -(Quiet.) -Do not print out the pathname and suppress error messages. -.It Fl s -(Stringify.) -Escape nonprinting characters and put quotes around the output. -.It Fl x -(Hex.) -Print the output in hexadecimal. -.El -.Sh EXAMPLES -.Bd -literal -setextattr system md5 `md5 -q /boot/kernel/kernel` /boot/kernel/kernel -getextattr system md5 /boot/kernel/kernel -lsextattr system /boot/kernel/kernel -rmextattr system md5 /boot/kernel/kernel -.Ed -.Sh SEE ALSO -.Xr extattr 2 , -.Xr extattr 3 , -.Xr extattrctl 8 , -.Xr extattr 9 -.Sh HISTORY -Extended attribute support was developed as part of the -.Tn TrustedBSD -Project, -and introduced in -.Fx 5.0 . -It was developed to support security extensions requiring additional labels -to be associated with each file or directory. -.Sh AUTHORS -.An Robert N M Watson -.An Poul-Henning Kamp -.Sh BUGS -The -.Nm setextattr -utility can only be used to set attributes to strings. diff --git a/usr.sbin/extattr/rmextattr.c b/usr.sbin/extattr/rmextattr.c deleted file mode 100644 index db7df1a..0000000 --- a/usr.sbin/extattr/rmextattr.c +++ /dev/null @@ -1,289 +0,0 @@ -/*- - * Copyright (c) 2002, 2003 Networks Associates Technology, Inc. - * Copyright (c) 2002 Poul-Henning Kamp. - * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson - * All rights reserved. - * - * This software was developed for the FreeBSD Project by Poul-Henning - * Kamp and Network Associates Laboratories, the Security Research Division - * of Network Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 - * ("CBOSS"), as part of the DARPA CHATS research program - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The names of the authors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static enum { EADUNNO, EAGET, EASET, EARM, EALS } what = EADUNNO; - -static void __dead2 -usage(void) -{ - - switch (what) { - case EAGET: - fprintf(stderr, "usage: getextattr [-fhqsx] attrnamespace"); - fprintf(stderr, " attrname filename ...\n"); - exit(-1); - case EASET: - fprintf(stderr, "usage: setextattr [-fhnq] attrnamespace"); - fprintf(stderr, " attrname attrvalue filename ...\n"); - exit(-1); - case EARM: - fprintf(stderr, "usage: rmextattr [-fhq] attrnamespace"); - fprintf(stderr, " attrname filename ...\n"); - exit(-1); - case EALS: - fprintf(stderr, "usage: lsextattr [-fhq] attrnamespace"); - fprintf(stderr, " filename ...\n"); - exit(-1); - case EADUNNO: - default: - fprintf(stderr, "usage: (getextattr|lsextattr|rmextattr"); - fprintf(stderr, "|setextattr)\n"); - exit (-1); - } -} - -static void -mkbuf(char **buf, int *oldlen, int newlen) -{ - - if (*oldlen >= newlen) - return; - if (*buf != NULL) - free(*buf); - *buf = malloc(newlen); - if (*buf == NULL) - err(1, "malloc"); - *oldlen = newlen; - return; -} - -int -main(int argc, char *argv[]) -{ - char *buf, *visbuf, *p; - - const char *options, *attrname; - int buflen, visbuflen, ch, error, i, arg_counter, attrnamespace, - minargc; - - int flag_force = 0; - int flag_nofollow = 0; - int flag_null = 0; - int flag_quiet = 0; - int flag_string = 0; - int flag_hex = 0; - - visbuflen = buflen = 0; - visbuf = buf = NULL; - - p = basename(argv[0]); - if (p == NULL) - p = argv[0]; - if (!strcmp(p, "getextattr")) { - what = EAGET; - options = "fhqsx"; - minargc = 3; - } else if (!strcmp(p, "setextattr")) { - what = EASET; - options = "fhnq"; - minargc = 4; - } else if (!strcmp(p, "rmextattr")) { - what = EARM; - options = "fhq"; - minargc = 3; - } else if (!strcmp(p, "lsextattr")) { - what = EALS; - options = "fhq"; - minargc = 2; - } else { - usage(); - } - - while ((ch = getopt(argc, argv, options)) != -1) { - switch (ch) { - case 'f': - flag_force = 1; - break; - case 'h': - flag_nofollow = 1; - break; - case 'n': - flag_null = 1; - break; - case 'q': - flag_quiet = 1; - break; - case 's': - flag_string = 1; - break; - case 'x': - flag_hex = 1; - break; - case '?': - default: - usage(); - } - } - - argc -= optind; - argv += optind; - - if (argc < minargc) - usage(); - - error = extattr_string_to_namespace(argv[0], &attrnamespace); - if (error) - err(-1, "%s", argv[0]); - argc--; argv++; - - if (what != EALS) { - attrname = argv[0]; - argc--; argv++; - } else - attrname = NULL; - - if (what == EASET) { - mkbuf(&buf, &buflen, strlen(argv[0]) + 1); - strcpy(buf, argv[0]); - argc--; argv++; - } - - for (arg_counter = 0; arg_counter < argc; arg_counter++) { - switch (what) { - case EARM: - if (flag_nofollow) - error = extattr_delete_link(argv[arg_counter], - attrnamespace, attrname); - else - error = extattr_delete_file(argv[arg_counter], - attrnamespace, attrname); - if (error >= 0) - continue; - break; - case EASET: - if (flag_nofollow) - error = extattr_set_link(argv[arg_counter], - attrnamespace, attrname, buf, - strlen(buf) + flag_null); - else - error = extattr_set_file(argv[arg_counter], - attrnamespace, attrname, buf, - strlen(buf) + flag_null); - if (error >= 0) - continue; - break; - case EALS: - if (flag_nofollow) - error = extattr_list_link(argv[arg_counter], - attrnamespace, NULL, 0); - else - error = extattr_list_file(argv[arg_counter], - attrnamespace, NULL, 0); - if (error < 0) - break; - mkbuf(&buf, &buflen, error); - if (flag_nofollow) - error = extattr_list_link(argv[arg_counter], - attrnamespace, buf, buflen); - else - error = extattr_list_file(argv[arg_counter], - attrnamespace, buf, buflen); - if (error < 0) - break; - if (!flag_quiet) - printf("%s\t", argv[arg_counter]); - for (i = 0; i < error; i += ch + 1) { - /* The attribute name length is unsigned. */ - ch = (unsigned char)buf[i]; - printf("%s%*.*s", i ? "\t" : "", - ch, ch, buf + i + 1); - } - printf("\n"); - continue; - case EAGET: - if (flag_nofollow) - error = extattr_get_link(argv[arg_counter], - attrnamespace, attrname, NULL, 0); - else - error = extattr_get_file(argv[arg_counter], - attrnamespace, attrname, NULL, 0); - if (error < 0) - break; - mkbuf(&buf, &buflen, error); - if (flag_nofollow) - error = extattr_get_link(argv[arg_counter], - attrnamespace, attrname, buf, buflen); - else - error = extattr_get_file(argv[arg_counter], - attrnamespace, attrname, buf, buflen); - if (error < 0) - break; - if (!flag_quiet) - printf("%s\t", argv[arg_counter]); - if (flag_string) { - mkbuf(&visbuf, &visbuflen, error * 4 + 1); - strvisx(visbuf, buf, error, - VIS_SAFE | VIS_WHITE); - printf("\"%s\"\n", visbuf); - continue; - } else if (flag_hex) { - for (i = 0; i < error; i++) - printf("%s%02x", i ? " " : "", - buf[i]); - printf("\n"); - continue; - } else { - fwrite(buf, error, 1, stdout); - printf("\n"); - continue; - } - default: - break; - } - if (!flag_quiet) - warn("%s: failed", argv[arg_counter]); - if (flag_force) - continue; - return(1); - } - return (0); -} diff --git a/usr.sbin/extattrctl/Makefile b/usr.sbin/extattrctl/Makefile deleted file mode 100644 index 496a8aa..0000000 --- a/usr.sbin/extattrctl/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= extattrctl -MAN= extattrctl.8 - -.include diff --git a/usr.sbin/extattrctl/extattrctl.8 b/usr.sbin/extattrctl/extattrctl.8 deleted file mode 100644 index c5850ab4..0000000 --- a/usr.sbin/extattrctl/extattrctl.8 +++ /dev/null @@ -1,181 +0,0 @@ -.\"- -.\" Copyright (c) 2000-2001 Robert N. M. Watson -.\" All rights reserved. -.\" -.\" This software was developed by Robert Watson for the TrustedBSD Project. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.\" Developed by the TrustedBSD Project. -.\" Support for file system extended attribute. -.\" -.Dd March 30, 2000 -.Dt EXTATTRCTL 8 -.Os -.Sh NAME -.Nm extattrctl -.Nd manage UFS1 extended attributes -.Sh SYNOPSIS -.Nm -.Cm start -.Ar path -.Nm -.Cm stop -.Ar path -.Nm -.Cm initattr -.Op Fl f -.Op Fl p Ar path -.Ar attrsize -.Ar attrfile -.Nm -.Cm showattr -.Ar attrfile -.Nm -.Cm enable -.Ar path -.Ar attrnamespace -.Ar attrname -.Ar attrfile -.Nm -.Cm disable -.Ar path -.Ar attrnamespace -.Ar attrname -.Sh DESCRIPTION -The -.Nm -utility -is the management utility for extended attributes over the UFS1 file system. -It allows the starting and stopping of extended attributes on a file system, -as well as initialization of attribute backing files, and enabling and -disabling of specific extended attributes on a file system. -.Pp -The first argument on the command line indicates the operation to be -performed. -Operation must be one of the following: -.Bl -tag -width indent -.It Cm start Ar path -Start extended attribute support on the file system named using -.Ar path . -The file system must be an UFS1 file system, and the UFS_EXTATTR kernel -option must have been enabled. -.It Cm stop Ar path -Stop extended attribute support on the file system named using -.Ar path . -Extended attribute support must previously have been started. -.It Xo -.Cm initattr -.Op Fl f -.Op Fl p Ar path -.Ar attrsize attrfile -.Xc -Create and initialize a file to use as an attribute backing file. -You must specify a maximum per-inode size for the attribute in bytes in -.Ar attrsize , -as well as the file where the attribute will be stored, using -.Ar attrfile . -.Pp -The -.Fl f -argument may be used to indicate that it is alright to overwrite an -existing attribute backing file; otherwise, if the target file exists, -an error will be returned. -.Pp -The -.Fl p Ar path -argument may be used to preallocate space for all attributes rather than -relying on sparse files to conserve space. -This has the advantage of guaranteeing that space will be available -for attributes when they are written, preventing low disk space conditions -from denying attribute service. -.Pp -This file should not exist before running -.Cm initattr . -.It Cm showattr Ar attrfile -Show the attribute header values in the attribute file named by -.Ar attrfile . -.It Cm enable Ar path attrnamespace attrname attrfile -Enable an attribute named -.Ar attrname -in the namespace -.Ar attrnamespace -on the file system identified using -.Ar path , -and backed by initialized attribute file -.Ar attrfile . -Available namespaces are "user" and "system". -The backing file must have been initialized using -.Cm initattr -before its first use. -Attributes must have been started on the file system prior to the -enabling of any attributes. -.It Cm disable Ar path attrnamespace attrname -Disable the attributed named -.Ar attrname -in namespace -.Ar attrnamespace -on the file system identified by -.Ar path . -Available namespaces are "user" and "system". -The file system must have attributes started on it, and the attribute -most have been enabled using -.Cm enable . -.El -.Sh EXAMPLES -.Dl extattrctl start / -.Pp -Start extended attributes on the root file system. -.Pp -.Dl extattrctl initattr 17 /.attribute/system/md5 -.Pp -Create an attribute backing file in /.attribute/system/md5, and set the maximum -size of each attribute to 17 bytes, with a sparse file used for storing -the attributes. -.Pp -.Dl extattrctl enable / system md5 /.attribute/system/md5 -.Pp -Enable an attribute named md5 on the root file system, backed from the file -/.attribute/system/md5. -.Pp -.Dl extattrctl disable / md5 -.Pp -Disable the attribute named md5 on the root file system. -.Pp -.Dl extattrctl stop / -.Pp -Stop extended attributes on the root file system. -.Sh SEE ALSO -.Xr ffs 7 , -.Xr getextattr 8 , -.Xr setextattr 8 , -.Xr extattr 9 -.Sh HISTORY -Extended attribute support was developed as part of the TrustedBSD Project, -and introduced in -.Fx 5.0 . -It was developed to support security extensions requiring additional labels -to be associated with each file or directory. -.Sh AUTHORS -Robert N M Watson diff --git a/usr.sbin/extattrctl/extattrctl.c b/usr.sbin/extattrctl/extattrctl.c deleted file mode 100644 index 1929f79..0000000 --- a/usr.sbin/extattrctl/extattrctl.c +++ /dev/null @@ -1,259 +0,0 @@ -/*- - * Copyright (c) 1999-2002 Robert N. M. Watson - * All rights reserved. - * - * This software was developed by Robert Watson for the TrustedBSD Project. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -/* - * Developed by the TrustedBSD Project. - * Support for file system extended attribute. - */ - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -int initattr(int argc, char *argv[]); -int showattr(int argc, char *argv[]); -long num_inodes_by_path(char *path); -void usage(void); - -void -usage(void) -{ - - fprintf(stderr, - "usage:\n" - " extattrctl start path\n" - " extattrctl stop path\n" - " extattrctl initattr [-f] [-p path] attrsize attrfile\n" - " extattrctl showattr attrfile\n" - " extattrctl enable path attrnamespace attrname attrfile\n" - " extattrctl disable path attrnamespace attrname\n"); - exit(-1); -} - -long -num_inodes_by_path(char *path) -{ - struct statfs buf; - int error; - - error = statfs(path, &buf); - if (error) { - perror("statfs"); - return (-1); - } - - return (buf.f_files); -} - -static const char zero_buf[8192]; - -int -initattr(int argc, char *argv[]) -{ - struct ufs_extattr_fileheader uef; - char *fs_path = NULL; - int ch, i, error, flags; - ssize_t wlen; - size_t easize; - - flags = O_CREAT | O_WRONLY | O_TRUNC | O_EXCL; - optind = 0; - while ((ch = getopt(argc, argv, "fp:r:w:")) != -1) - switch (ch) { - case 'f': - flags &= ~O_EXCL; - break; - case 'p': - fs_path = optarg; - break; - case '?': - default: - usage(); - } - - argc -= optind; - argv += optind; - - if (argc != 2) - usage(); - - error = 0; - if ((i = open(argv[1], flags, 0600)) == -1) { - /* unable to open file */ - perror(argv[1]); - return (-1); - } - uef.uef_magic = UFS_EXTATTR_MAGIC; - uef.uef_version = UFS_EXTATTR_VERSION; - uef.uef_size = atoi(argv[0]); - if (write(i, &uef, sizeof(uef)) == -1) - error = -1; - else if (fs_path != NULL) { - easize = (sizeof uef + uef.uef_size) * - num_inodes_by_path(fs_path); - while (easize > 0) { - if (easize > sizeof zero_buf) - wlen = write(i, zero_buf, sizeof zero_buf); - else - wlen = write(i, zero_buf, easize); - if (wlen == -1) { - error = -1; - break; - } - easize -= wlen; - } - } - if (error == -1) { - perror(argv[1]); - unlink(argv[1]); - return (-1); - } - - return (0); -} - -int -showattr(int argc, char *argv[]) -{ - struct ufs_extattr_fileheader uef; - int i, fd; - - if (argc != 1) - usage(); - - fd = open(argv[0], O_RDONLY); - if (fd == -1) { - perror(argv[0]); - return (-1); - } - - i = read(fd, &uef, sizeof(uef)); - if (i == -1) { - perror(argv[0]); - return (-1); - } - if (i != sizeof(uef)) { - fprintf(stderr, "%s: invalid file header\n", argv[0]); - return (-1); - } - - if (uef.uef_magic != UFS_EXTATTR_MAGIC) { - fprintf(stderr, "%s: bad magic\n", argv[0]); - return (-1); - } - - printf("%s: version %d, size %d\n", argv[0], uef.uef_version, - uef.uef_size); - - return (0); -} - -int -main(int argc, char *argv[]) -{ - int error = 0, attrnamespace; - - if (argc < 2) - usage(); - - if (!strcmp(argv[1], "start")) { - if (argc != 3) - usage(); - error = extattrctl(argv[2], UFS_EXTATTR_CMD_START, NULL, 0, - NULL); - if (error) { - perror("extattrctl start"); - return (-1); - } - } else if (!strcmp(argv[1], "stop")) { - if (argc != 3) - usage(); - error = extattrctl(argv[2], UFS_EXTATTR_CMD_STOP, NULL, 0, - NULL); - if (error) { - perror("extattrctl stop"); - return (-1); - } - } else if (!strcmp(argv[1], "enable")) { - if (argc != 6) - usage(); - error = extattr_string_to_namespace(argv[3], &attrnamespace); - if (error) { - perror("extattrctl enable"); - return (-1); - } - error = extattrctl(argv[2], UFS_EXTATTR_CMD_ENABLE, argv[5], - attrnamespace, argv[4]); - if (error) { - perror("extattrctl enable"); - return (-1); - } - } else if (!strcmp(argv[1], "disable")) { - if (argc != 5) - usage(); - error = extattr_string_to_namespace(argv[3], &attrnamespace); - if (error) { - perror("extattrctl disable"); - return (-1); - } - error = extattrctl(argv[2], UFS_EXTATTR_CMD_DISABLE, NULL, - attrnamespace, argv[4]); - if (error) { - perror("extattrctl disable"); - return (-1); - } - } else if (!strcmp(argv[1], "initattr")) { - argc -= 2; - argv += 2; - error = initattr(argc, argv); - if (error) - return (-1); - } else if (!strcmp(argv[1], "showattr")) { - argc -= 2; - argv += 2; - error = showattr(argc, argv); - if (error) - return (-1); - } else - usage(); - - return (0); -} diff --git a/usr.sbin/faithd/Makefile b/usr.sbin/faithd/Makefile deleted file mode 100644 index dec45b9..0000000 --- a/usr.sbin/faithd/Makefile +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright (c) 1996 WIDE Project. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modifications, are permitted provided that the above copyright notice -# and this paragraph are duplicated in all such forms and that any -# documentation, advertising materials, and other materials related to -# such distribution and use acknowledge that the software was developed -# by the WIDE Project, Japan. The name of the Project may not be used to -# endorse or promote products derived from this software without -# specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' -# AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT -# LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE. -# -# $FreeBSD$ - -PROG= faithd -MAN= faithd.8 -SRCS= faithd.c tcp.c ftp.c prefix.c - -CFLAGS+= -DHAVE_POLL_H - -WARNS?= 2 - -.include diff --git a/usr.sbin/faithd/README b/usr.sbin/faithd/README deleted file mode 100644 index 6628bf6..0000000 --- a/usr.sbin/faithd/README +++ /dev/null @@ -1,148 +0,0 @@ -Configuring FAITH IPv6-to-IPv4 TCP relay - -Kazu Yamamoto and Jun-ichiro itojun Hagino -$KAME: README,v 1.10 2003/01/06 21:40:33 sumikawa Exp $ -$FreeBSD$ - - -Introduction -============ - -FAITH is an IPv6-to-IPv4 TCP relay. It performs tcp relay just as some of -firewall-oriented gateway does, but between IPv6 and IPv4 with address -translation. -TCP connections has to be made from IPv6 node to IPv4 node. FAITH will -not relay connections for the opposite direction. -To perform relays, FAITH daemon needs to be executed on a router between -your local IPv6 site and outside IPv4 network. The daemon needs to be -invoked per each TCP services (TCP port number). - - IPv4 node "dest" = 123.4.5.6 - | - [[[[ outside IPv4 ocean ]]]] - | - node that runs FAITH-daemon (usually a router) - | - ==+=====+===+==== IPv6, or IPv4/v6 network in your site ^ - | | | connection - clients IPv6 node "src" | - -You will have to allocate an IPv6 address prefix to map IPv4 addresses into. -The following description uses 3ffe:0501:ffff:0000:: as example. -Please use a prefix which belongs to your site. -FAITH will make it possible to make an IPv6 TCP connection From IPv6 node -"src", toward IPv4 node "dest", by specifying FAITH-mapped address -3ffe:0501:ffff:0000::123.4.5.6 -(which is, 3ffe:0501:ffff:0000:0000:0000:7b04:0506). -The address mapping can be performed by hand:-), by special nameserver on -the network, or by special resolver on the source node. - - -Setup -===== - -The following example assumes: -- You have assigned 3ffe:0501:ffff:0000:: as FAITH adderss prefix. -- You are willing to provide IPv6-to IPv4 TCP relay for telnet. - -<> - -(1) If you have IPv6 TCP server for the "telnet" service, i.e. telnetd via - inet6d, disable that daemon. Comment out the line from "inet6d.conf" - and send the HUP signal to "inet6d". - -(2) Execute sysctl as root to enable FAITH support in the kernel. - - # sysctl net.inet6.ip6.keepfaith=1 - -(3) Route packets toward FAITH prefix into "faith0" interface. - - # ifconfig faith0 up - # route add -inet6 3ffe:0501:ffff:0000:: -prefixlen 64 ::1 - # route change -inet6 3ffe:0501:ffff:0000:: -prefixlen 64 -ifp faith0 - -(4) Execute "faithd" by root as follows: - - # faithd telnet /usr/libexec/telnetd telnetd - - 1st argument is a service name you are willing to provide TCP relay. - (it can be specified either by number "23" or by string "telnet") - 2nd argument is a path name for local IPv6 TCP server. If there is a - connection toward the router itself, this program will be invoked. - 3rd and the following arguments are arguments for the local IPv6 TCP - server. (3rd argument is typically the program name without its path.) - - More examples: - - # faithd ftpd /usr/libexec/ftpd ftpd -l - # faithd sshd - -If inetd(8) on your platform have special support for faithd, it is possible -to setup faithd services via inetd(8). Consult manpage for details. - - -<> - -(4) Make sure that packets whose destinations match the prefix can -reach from the IPv6 host to the translating router. - -<> - -There are two ways to translate IPv4 address to IPv6 address: - (a) Faked by DNS - (b) Faked by /etc/hosts. - -(5.a) Install "newbie" and set up FAITH mode. See kit/ports/newbie. - -(5.b) Add an entry into /etc/hosts so that you can resolve hostname into -faked IPv6 addrss. For example, add the following line for www.netbsd.org: - - 3ffe:0501:ffff:0000::140.160.140.252 www.netbsd.org - -<> - -(6) To see if "faithd" works, watch "/var/log/daemon". Note: please -setup "/etc/syslog.conf" so that LOG_DAEMON messages are to be stored -in "/var/log/daemon". - - - daemon.* /var/log/daemon - - -Access control -============== - -Since faithd implements TCP relaying service, it is critical to implement -proper access control to cope with malicious use. Bad guy may try to -use your relay router to circumvent access controls, or may try to -abuse your network (like sending SPAMs from IPv4 address that belong to you). -Install IPv6 packet filter directives that would reject traffic from -unwanted source. If you are using inetd-based setup, you may be able to -use access control mechanisms in inetd. - - -Advanced configuration -====================== - -If you would like to restrict IPv4 destination for translation, you may -want to do the following: - - # route add -inet6 3ffe:0501:ffff:0000::123.0.0.0 -prefixlen 104 ::1 - # route change -inet6 3ffe:0501:ffff:0000::123.0.0.0 -prefixlen 104 \ - -ifp faith0 - -By this way, you can restrict IPv4 destination to 123.0.0.0/8. -You may also want to reject packets toward 3ffe:0501:ffff:0000::/64 which -is not in 3ffe:0501:ffff:0000::123.0.0.0/104. This will be left as excerside -for the reader. - -By doing this, you will be able to provide your IPv4 web server to outside -IPv6 customers, without risks of unwanted open relays. - - [[[[ IPv6 network outside ]]]] | - | | connection - node that runs FAITH-daemon (usually a router) v - | - ========+======== IPv4/v6 network in your site - | (123.0.0.0/8) - IPv4 web server diff --git a/usr.sbin/faithd/faithd.8 b/usr.sbin/faithd/faithd.8 deleted file mode 100644 index 25c118d..0000000 --- a/usr.sbin/faithd/faithd.8 +++ /dev/null @@ -1,404 +0,0 @@ -.\" $KAME: faithd.8,v 1.37 2002/05/09 14:21:23 itojun Exp $ -.\" -.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd January 9, 2010 -.Dt FAITHD 8 -.Os -.Sh NAME -.Nm faithd -.Nd FAITH IPv6/v4 translator daemon -.Sh SYNOPSIS -.Nm -.Op Fl dp -.Op Fl f Ar configfile -.Ar service -.Op Ar serverpath Op Ar serverargs -.Sh DESCRIPTION -The -.Nm -utility provides IPv6-to-IPv4 TCP relaying. -It can only be used on an IPv4/v6 dual stack router. -.Pp -When -.Nm -receives -.Tn TCPv6 -traffic, it will relay the -.Tn TCPv6 -traffic to -.Tn TCPv4 . -The destination for the relayed -.Tn TCPv4 -connection will be determined by the last 4 octets of the original -.Tn IPv6 -destination. -For example, if -.Li 3ffe:0501:4819:ffff:: -is reserved for -.Nm , -and the -.Tn TCPv6 -destination address is -.Li 3ffe:0501:4819:ffff::0a01:0101 , -the traffic will be relayed to IPv4 destination -.Li 10.1.1.1 . -.Pp -To use the -.Nm -translation service, -an IPv6 address prefix must be reserved for mapping IPv4 addresses into. -The kernel must be properly configured to route all the TCP connections -toward the reserved IPv6 address prefix into the -.Xr faith 4 -pseudo interface, using the -.Xr route 8 -command. -Also, -.Xr sysctl 8 -should be used to configure -.Dv net.inet6.ip6.keepfaith -to -.Dv 1 . -.Pp -The router must be configured to capture all the TCP traffic -for the reserved -.Tn IPv6 -address prefix, by using -.Xr route 8 -and -.Xr sysctl 8 -commands. -.Pp -The -.Nm -utility needs special name-to-address translation logic, so that -hostnames get resolved into the special -.Tn IPv6 -address prefix. -For small-scale installations, use -.Xr hosts 5 ; -For large-scale installations, it is useful to have -a DNS server with special address translation support. -An implementation called -.Nm totd -is available at -.Pa http://www.vermicelli.pasta.cs.uit.no/software/totd.html . -Make sure you do not propagate translated DNS records over to normal -DNS, as it can cause severe problems. -.Ss Daemon mode -When -.Nm -is invoked as a standalone program, -.Nm -will daemonize itself. -The -.Nm -utility will listen to -.Tn TCPv6 -port -.Ar service . -If -.Tn TCPv6 -traffic to port -.Ar service -is found, it relays the connection. -.Pp -Since -.Nm -listens to TCP port -.Ar service , -it is not possible to run local TCP daemons for port -.Ar service -on the router, using -.Xr inetd 8 -or other standard mechanisms. -By specifying -.Ar serverpath -to -.Nm , -you can run local daemons on the router. -The -.Nm -utility will invoke a local daemon at -.Ar serverpath -if the destination address is a local interface address, -and will perform translation to IPv4 TCP in other cases. -You can also specify -.Ar serverargs -for the arguments for the local daemon. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl d -Debugging information will be generated using -.Xr syslog 3 . -.It Fl f Ar configfile -Specify a configuration file for access control. -See below. -.It Fl p -Use privileged TCP port number as source port, -for IPv4 TCP connection toward final destination. -For relaying -.Xr ftp 1 , -this flag is not necessary as special program code is supplied. -.El -.Pp -The -.Nm -utility will relay both normal and out-of-band TCP data. -It is capable of emulating TCP half close as well. -The -.Nm -utility includes special support for protocols used by -.Xr ftp 1 . -When translating the FTP protocol, -.Nm -translates network level addresses in -.Li PORT/LPRT/EPRT -and -.Li PASV/LPSV/EPSV -commands. -.Pp -Inactive sessions will be disconnected in 30 minutes, -to prevent stale sessions from chewing up resources. -This may be inappropriate for some services -(should this be configurable?). -.Ss inetd mode -When -.Nm -is invoked via -.Xr inetd 8 , -.Nm -will handle connections passed from standard input. -If the connection endpoint is in the reserved IPv6 address prefix, -.Nm -will relay the connection. -Otherwise, -.Nm -will invoke a service-specific daemon like -.Xr telnetd 8 , -by using the command argument passed from -.Xr inetd 8 . -.Pp -The -.Nm -utility determines operation mode by the local TCP port number, -and enables special protocol handling whenever necessary/possible. -For example, if -.Nm -is invoked via -.Xr inetd 8 -on the FTP port, it will operate as an FTP relay. -.Pp -The operation mode requires special support for -.Nm -in -.Xr inetd 8 . -.Ss Access control -To prevent malicious access, -.Nm -implements simple address-based access control. -With -.Pa /etc/faithd.conf -(or -.Ar configfile -specified by -.Fl f ) , -.Nm -will avoid relaying unwanted traffic. -The -.Pa faithd.conf -configuration file contains directives of the following format: -.Bl -bullet -.It -.Ar src Ns / Ns Ar slen Cm deny Ar dst Ns / Ns Ar dlen -.Pp -If the source address of a query matches -.Ar src Ns / Ns Ar slen , -and the translated destination address matches -.Ar dst Ns / Ns Ar dlen , -deny the connection. -.It -.Ar src Ns / Ns Ar slen Cm permit Ar dst Ns / Ns Ar dlen -.Pp -If the source address of a query matches -.Ar src Ns / Ns Ar slen , -and the translated destination address matches -.Ar dst Ns / Ns Ar dlen , -permit the connection. -.El -.Pp -The directives are evaluated in sequence, -and the first matching entry will be effective. -If there is no match -(if we reach the end of the ruleset) -the traffic will be denied. -.Pp -With inetd mode, -traffic may be filtered by using access control functionality in -.Xr inetd 8 . -.Sh EXIT STATUS -The -.Nm -utility exits with -.Dv EXIT_SUCCESS -.Pq 0 -on success, and -.Dv EXIT_FAILURE -.Pq 1 -on error. -.Sh EXAMPLES -Before invoking -.Nm , -the -.Xr faith 4 -interface has to be configured properly. -.Bd -literal -offset -# sysctl net.inet6.ip6.accept_rtadv=0 -# sysctl net.inet6.ip6.forwarding=1 -# sysctl net.inet6.ip6.keepfaith=1 -# ifconfig faith0 up -# route add -inet6 3ffe:501:4819:ffff:: -prefixlen 96 ::1 -# route change -inet6 3ffe:501:4819:ffff:: -prefixlen 96 -ifp faith0 -.Ed -.Ss Daemon mode samples -To translate -.Li telnet -service, and provide no local telnet service, invoke -.Nm -as follows: -.Bd -literal -offset -# faithd telnet -.Ed -.Pp -If you would like to provide local telnet service via -.Xr telnetd 8 -on -.Pa /usr/libexec/telnetd , -use the following command line: -.Bd -literal -offset -# faithd telnet /usr/libexec/telnetd telnetd -.Ed -.Pp -If you would like to pass extra arguments to the local daemon: -.Bd -literal -offset -# faithd ftp /usr/libexec/ftpd ftpd -l -.Ed -.Pp -Here are some other examples. -You may need -.Fl p -if the service checks the source port range. -.Bd -literal -offset -# faithd ssh -# faithd telnet /usr/libexec/telnetd telnetd -.Ed -.Ss inetd mode samples -Add the following lines into -.Xr inetd.conf 5 . -Syntax may vary depending upon your operating system. -.Bd -literal -offset -telnet stream tcp6/faith nowait root faithd telnetd -ftp stream tcp6/faith nowait root faithd ftpd -l -ssh stream tcp6/faith nowait root faithd /usr/sbin/sshd -i -.Ed -.Pp -.Xr inetd 8 -will open listening sockets with kernel TCP relay support enabled. -Whenever a connection comes in, -.Nm -will be invoked by -.Xr inetd 8 . -If the connection endpoint is in the reserved IPv6 address prefix. -The -.Nm -utility will relay the connection. -Otherwise, -.Nm -will invoke service-specific daemon like -.Xr telnetd 8 . -.Ss Access control samples -The following illustrates a simple -.Pa faithd.conf -setting. -.Bd -literal -offset -# permit anyone from 3ffe:501:ffff::/48 to use the translator, -# to connect to the following IPv4 destinations: -# - any location except 10.0.0.0/8 and 127.0.0.0/8. -# Permit no other connections. -# -3ffe:501:ffff::/48 deny 10.0.0.0/8 -3ffe:501:ffff::/48 deny 127.0.0.0/8 -3ffe:501:ffff::/48 permit 0.0.0.0/0 -.Ed -.Sh SEE ALSO -.Xr faith 4 , -.Xr route 8 , -.Xr sysctl 8 -.Rs -.%A Jun-ichiro itojun Hagino -.%A Kazu Yamamoto -.%T "An IPv6-to-IPv4 transport relay translator" -.%B RFC3142 -.%U ftp://ftp.isi.edu/in-notes/rfc3142.txt -.%D June 2001 -.Re -.\" -.Sh HISTORY -The -.Nm -utility first appeared in the WIDE Hydrangea IPv6 protocol stack kit. -.\" -.Pp -IPv6 and IPsec support based on the KAME Project (http://www.kame.net/) stack -was initially integrated into -.Fx 4.0 . -.Sh SECURITY CONSIDERATIONS -It is very insecure to use IP-address based authentication, for connections relayed by -.Nm , -and any other TCP relaying services. -.Pp -Administrators are advised to limit accesses to -.Nm -using -.Pa faithd.conf , -or by using IPv6 packet filters, to protect the -.Nm -service from malicious parties, and to avoid theft of service/bandwidth. -IPv6 destination addresses can be limited by -carefully configuring routing entries that point to -.Xr faith 4 , -using -.Xr route 8 . -The IPv6 source address needs to be filtered using packet filters. -The documents listed in -.Sx SEE ALSO -have more information on this topic. diff --git a/usr.sbin/faithd/faithd.c b/usr.sbin/faithd/faithd.c deleted file mode 100644 index 9caf0e9..0000000 --- a/usr.sbin/faithd/faithd.c +++ /dev/null @@ -1,908 +0,0 @@ -/* $KAME: faithd.c,v 1.67 2003/10/16 05:26:21 itojun Exp $ */ - -/* - * Copyright (C) 1997 and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * User level translator from IPv6 to IPv4. - * - * Usage: faithd [ ...] - * e.g. faithd telnet /usr/libexec/telnetd telnetd - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_POLL_H -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#ifdef IFT_FAITH -# define USE_ROUTE -# include -# include -# include -#endif - -#include -#include -#include -#include - -#include "faithd.h" -#include "prefix.h" - -char *serverpath = NULL; -char *serverarg[MAXARGV + 1]; -static char *faithdname = NULL; -char logname[BUFSIZ]; -char procname[BUFSIZ]; - -struct myaddrs { - struct myaddrs *next; - struct sockaddr *addr; -}; -struct myaddrs *myaddrs = NULL; - -static const char *service; -#ifdef USE_ROUTE -static int sockfd = 0; -#endif -int dflag = 0; -static int pflag = 0; -static int inetd = 0; -static char *configfile = NULL; - -int main(int, char **); -static int inetd_main(int, char **); -static int daemon_main(int, char **); -static void play_service(int); -static void play_child(int, struct sockaddr *); -static int faith_prefix(struct sockaddr *); -static int map6to4(struct sockaddr_in6 *, struct sockaddr_in *); -static void sig_child(int); -static void sig_terminate(int); -static void start_daemon(void); -static void exit_stderr(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); -static void grab_myaddrs(void); -static void free_myaddrs(void); -static void update_myaddrs(void); -static void usage(void); - -int -main(int argc, char **argv) -{ - - /* - * Initializing stuff - */ - - faithdname = strrchr(argv[0], '/'); - if (faithdname) - faithdname++; - else - faithdname = argv[0]; - - if (strcmp(faithdname, "faithd") != 0) { - inetd = 1; - return inetd_main(argc, argv); - } else - return daemon_main(argc, argv); -} - -static int -inetd_main(int argc, char **argv) -{ - char path[MAXPATHLEN]; - struct sockaddr_storage me; - struct sockaddr_storage from; - socklen_t melen, fromlen; - int i; - int error; - const int on = 1; - char sbuf[NI_MAXSERV], snum[NI_MAXSERV]; - - if (config_load(configfile) < 0 && configfile) { - exit_failure("could not load config file"); - /*NOTREACHED*/ - } - - if (strrchr(argv[0], '/') == NULL) - snprintf(path, sizeof(path), "%s/%s", DEFAULT_DIR, argv[0]); - else - snprintf(path, sizeof(path), "%s", argv[0]); - -#ifdef USE_ROUTE - grab_myaddrs(); - - sockfd = socket(PF_ROUTE, SOCK_RAW, PF_UNSPEC); - if (sockfd < 0) { - exit_failure("socket(PF_ROUTE): %s", strerror(errno)); - /*NOTREACHED*/ - } -#endif - - melen = sizeof(me); - if (getsockname(STDIN_FILENO, (struct sockaddr *)&me, &melen) < 0) { - exit_failure("getsockname: %s", strerror(errno)); - /*NOTREACHED*/ - } - fromlen = sizeof(from); - if (getpeername(STDIN_FILENO, (struct sockaddr *)&from, &fromlen) < 0) { - exit_failure("getpeername: %s", strerror(errno)); - /*NOTREACHED*/ - } - if (getnameinfo((struct sockaddr *)&me, melen, NULL, 0, - sbuf, sizeof(sbuf), NI_NUMERICHOST) == 0) - service = sbuf; - else - service = DEFAULT_PORT_NAME; - if (getnameinfo((struct sockaddr *)&me, melen, NULL, 0, - snum, sizeof(snum), NI_NUMERICHOST) != 0) - snprintf(snum, sizeof(snum), "?"); - - snprintf(logname, sizeof(logname), "faithd %s", snum); - snprintf(procname, sizeof(procname), "accepting port %s", snum); - openlog(logname, LOG_PID | LOG_NOWAIT, LOG_DAEMON); - - if (argc >= MAXARGV) { - exit_failure("too many arguments"); - /*NOTREACHED*/ - } - serverarg[0] = serverpath = path; - for (i = 1; i < argc; i++) - serverarg[i] = argv[i]; - serverarg[i] = NULL; - - error = setsockopt(STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE, &on, - sizeof(on)); - if (error < 0) { - exit_failure("setsockopt(SO_OOBINLINE): %s", strerror(errno)); - /*NOTREACHED*/ - } - - play_child(STDIN_FILENO, (struct sockaddr *)&from); - exit_failure("should not reach here"); - return 0; /*dummy!*/ -} - -static int -daemon_main(int argc, char **argv) -{ - struct addrinfo hints, *res; - int s_wld, error, i, serverargc, on = 1; - int family = AF_INET6; - int c; - - while ((c = getopt(argc, argv, "df:p")) != -1) { - switch (c) { - case 'd': - dflag++; - break; - case 'f': - configfile = optarg; - break; - case 'p': - pflag++; - break; - default: - usage(); - /*NOTREACHED*/ - } - } - argc -= optind; - argv += optind; - - if (config_load(configfile) < 0 && configfile) { - exit_failure("could not load config file"); - /*NOTREACHED*/ - } - - -#ifdef USE_ROUTE - grab_myaddrs(); -#endif - - switch (argc) { - case 0: - usage(); - /*NOTREACHED*/ - default: - serverargc = argc - NUMARG; - if (serverargc >= MAXARGV) - exit_stderr("too many arguments"); - - serverpath = strdup(argv[NUMPRG]); - if (!serverpath) - exit_stderr("not enough core"); - for (i = 0; i < serverargc; i++) { - serverarg[i] = strdup(argv[i + NUMARG]); - if (!serverarg[i]) - exit_stderr("not enough core"); - } - serverarg[i] = NULL; - /* fall throuth */ - case 1: /* no local service */ - service = argv[NUMPRT]; - break; - } - - start_daemon(); - - /* - * Opening wild card socket for this service. - */ - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_PASSIVE; - hints.ai_family = family; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; /* SCTP? */ - error = getaddrinfo(NULL, service, &hints, &res); - if (error) - exit_failure("getaddrinfo: %s", gai_strerror(error)); - - s_wld = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (s_wld == -1) - exit_failure("socket: %s", strerror(errno)); - -#ifdef IPV6_FAITH - if (res->ai_family == AF_INET6) { - error = setsockopt(s_wld, IPPROTO_IPV6, IPV6_FAITH, &on, sizeof(on)); - if (error == -1) - exit_failure("setsockopt(IPV6_FAITH): %s", - strerror(errno)); - } -#endif - - error = setsockopt(s_wld, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); - if (error == -1) - exit_failure("setsockopt(SO_REUSEADDR): %s", strerror(errno)); - - error = setsockopt(s_wld, SOL_SOCKET, SO_OOBINLINE, &on, sizeof(on)); - if (error == -1) - exit_failure("setsockopt(SO_OOBINLINE): %s", strerror(errno)); - -#ifdef IPV6_V6ONLY - error = setsockopt(s_wld, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)); - if (error == -1) - exit_failure("setsockopt(IPV6_V6ONLY): %s", strerror(errno)); -#endif - - error = bind(s_wld, (struct sockaddr *)res->ai_addr, res->ai_addrlen); - if (error == -1) - exit_failure("bind: %s", strerror(errno)); - - error = listen(s_wld, 5); - if (error == -1) - exit_failure("listen: %s", strerror(errno)); - -#ifdef USE_ROUTE - sockfd = socket(PF_ROUTE, SOCK_RAW, PF_UNSPEC); - if (sockfd < 0) { - exit_failure("socket(PF_ROUTE): %s", strerror(errno)); - /*NOTREACHED*/ - } -#endif - - /* - * Everything is OK. - */ - - snprintf(logname, sizeof(logname), "faithd %s", service); - snprintf(procname, sizeof(procname), "accepting port %s", service); - openlog(logname, LOG_PID | LOG_NOWAIT, LOG_DAEMON); - syslog(LOG_INFO, "Staring faith daemon for %s port", service); - - play_service(s_wld); - /* NOTREACHED */ - exit(1); /*pacify gcc*/ -} - -static void -play_service(int s_wld) -{ - struct sockaddr_storage srcaddr; - socklen_t len; - int s_src; - pid_t child_pid; -#ifdef HAVE_POLL_H - struct pollfd pfd[2]; -#else - fd_set rfds; - int maxfd; -#endif - int error; - - /* - * Wait, accept, fork, faith.... - */ -again: - setproctitle("%s", procname); - -#ifdef HAVE_POLL_H - pfd[0].fd = s_wld; - pfd[0].events = POLLIN; - pfd[1].fd = -1; - pfd[1].revents = 0; -#else - FD_ZERO(&rfds); - if (s_wld >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(s_wld, &rfds); - maxfd = s_wld; -#endif -#ifdef USE_ROUTE - if (sockfd) { -#ifdef HAVE_POLL_H - pfd[1].fd = sockfd; - pfd[1].events = POLLIN; -#else - if (sockfd >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(sockfd, &rfds); - maxfd = (maxfd < sockfd) ? sockfd : maxfd; -#endif - } -#endif - -#ifdef HAVE_POLL_H - error = poll(pfd, sizeof(pfd)/sizeof(pfd[0]), INFTIM); -#else - error = select(maxfd + 1, &rfds, NULL, NULL, NULL); -#endif - if (error < 0) { - if (errno == EINTR) - goto again; - exit_failure("select: %s", strerror(errno)); - /*NOTREACHED*/ - } - -#ifdef USE_ROUTE -#ifdef HAVE_POLL_H - if (pfd[1].revents & POLLIN) -#else - if (FD_ISSET(sockfd, &rfds)) -#endif - { - update_myaddrs(); - } -#endif -#ifdef HAVE_POLL_H - if (pfd[0].revents & POLLIN) -#else - if (FD_ISSET(s_wld, &rfds)) -#endif - { - len = sizeof(srcaddr); - s_src = accept(s_wld, (struct sockaddr *)&srcaddr, &len); - if (s_src < 0) { - if (errno == ECONNABORTED) - goto again; - exit_failure("socket: %s", strerror(errno)); - /*NOTREACHED*/ - } - if (srcaddr.ss_family == AF_INET6 && - IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)&srcaddr)->sin6_addr)) { - close(s_src); - syslog(LOG_ERR, "connection from IPv4 mapped address?"); - goto again; - } - - child_pid = fork(); - - if (child_pid == 0) { - /* child process */ - close(s_wld); - closelog(); - openlog(logname, LOG_PID | LOG_NOWAIT, LOG_DAEMON); - play_child(s_src, (struct sockaddr *)&srcaddr); - exit_failure("should never reach here"); - /*NOTREACHED*/ - } else { - /* parent process */ - close(s_src); - if (child_pid == -1) - syslog(LOG_ERR, "can't fork"); - } - } - goto again; -} - -static void -play_child(int s_src, struct sockaddr *srcaddr) -{ - struct sockaddr_storage dstaddr6; - struct sockaddr_storage dstaddr4; - char src[NI_MAXHOST]; - char dst6[NI_MAXHOST]; - char dst4[NI_MAXHOST]; - socklen_t len = sizeof(dstaddr6); - int s_dst, error, hport, nresvport, on = 1; - struct timeval tv; - struct sockaddr *sa4; - const struct config *conf; - - tv.tv_sec = 1; - tv.tv_usec = 0; - - getnameinfo(srcaddr, srcaddr->sa_len, - src, sizeof(src), NULL, 0, NI_NUMERICHOST); - syslog(LOG_INFO, "accepted a client from %s", src); - - error = getsockname(s_src, (struct sockaddr *)&dstaddr6, &len); - if (error == -1) { - exit_failure("getsockname: %s", strerror(errno)); - /*NOTREACHED*/ - } - - getnameinfo((struct sockaddr *)&dstaddr6, len, - dst6, sizeof(dst6), NULL, 0, NI_NUMERICHOST); - syslog(LOG_INFO, "the client is connecting to %s", dst6); - - if (!faith_prefix((struct sockaddr *)&dstaddr6)) { - if (serverpath) { - /* - * Local service - */ - syslog(LOG_INFO, "executing local %s", serverpath); - if (!inetd) { - dup2(s_src, 0); - close(s_src); - dup2(0, 1); - dup2(0, 2); - } - execv(serverpath, serverarg); - syslog(LOG_ERR, "execv %s: %s", serverpath, - strerror(errno)); - _exit(EXIT_FAILURE); - } else { - close(s_src); - exit_success("no local service for %s", service); - } - } - - /* - * Act as a translator - */ - - switch (((struct sockaddr *)&dstaddr6)->sa_family) { - case AF_INET6: - if (!map6to4((struct sockaddr_in6 *)&dstaddr6, - (struct sockaddr_in *)&dstaddr4)) { - close(s_src); - exit_failure("map6to4 failed"); - /*NOTREACHED*/ - } - syslog(LOG_INFO, "translating from v6 to v4"); - break; - default: - close(s_src); - exit_failure("family not supported"); - /*NOTREACHED*/ - } - - sa4 = (struct sockaddr *)&dstaddr4; - getnameinfo(sa4, sa4->sa_len, - dst4, sizeof(dst4), NULL, 0, NI_NUMERICHOST); - - conf = config_match(srcaddr, sa4); - if (!conf || !conf->permit) { - close(s_src); - if (conf) { - exit_failure("translation to %s not permitted for %s", - dst4, prefix_string(&conf->match)); - /*NOTREACHED*/ - } else { - exit_failure("translation to %s not permitted", dst4); - /*NOTREACHED*/ - } - } - - syslog(LOG_INFO, "the translator is connecting to %s", dst4); - - setproctitle("port %s, %s -> %s", service, src, dst4); - - if (sa4->sa_family == AF_INET6) - hport = ntohs(((struct sockaddr_in6 *)&dstaddr4)->sin6_port); - else /* AF_INET */ - hport = ntohs(((struct sockaddr_in *)&dstaddr4)->sin_port); - - if (pflag) - s_dst = rresvport_af(&nresvport, sa4->sa_family); - else - s_dst = socket(sa4->sa_family, SOCK_STREAM, 0); - if (s_dst < 0) { - exit_failure("socket: %s", strerror(errno)); - /*NOTREACHED*/ - } - - if (conf->src.a.ss_family) { - if (bind(s_dst, (const struct sockaddr *)&conf->src.a, - conf->src.a.ss_len) < 0) { - exit_failure("bind: %s", strerror(errno)); - /*NOTREACHED*/ - } - } - - error = setsockopt(s_dst, SOL_SOCKET, SO_OOBINLINE, &on, sizeof(on)); - if (error < 0) { - exit_failure("setsockopt(SO_OOBINLINE): %s", strerror(errno)); - /*NOTREACHED*/ - } - - error = setsockopt(s_src, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); - if (error < 0) { - exit_failure("setsockopt(SO_SNDTIMEO): %s", strerror(errno)); - /*NOTREACHED*/ - } - error = setsockopt(s_dst, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); - if (error < 0) { - exit_failure("setsockopt(SO_SNDTIMEO): %s", strerror(errno)); - /*NOTREACHED*/ - } - - error = connect(s_dst, sa4, sa4->sa_len); - if (error < 0) { - exit_failure("connect: %s", strerror(errno)); - /*NOTREACHED*/ - } - - switch (hport) { - case FTP_PORT: - ftp_relay(s_src, s_dst); - break; - default: - tcp_relay(s_src, s_dst, service); - break; - } - - /* NOTREACHED */ -} - -/* 0: non faith, 1: faith */ -static int -faith_prefix(struct sockaddr *dst) -{ -#ifndef USE_ROUTE - int mib[4], size; - struct in6_addr faith_prefix; - struct sockaddr_in6 *dst6 = (struct sockaddr_in *)dst; - - if (dst->sa_family != AF_INET6) - return 0; - - mib[0] = CTL_NET; - mib[1] = PF_INET6; - mib[2] = IPPROTO_IPV6; - mib[3] = IPV6CTL_FAITH_PREFIX; - size = sizeof(struct in6_addr); - if (sysctl(mib, 4, &faith_prefix, &size, NULL, 0) < 0) { - exit_failure("sysctl: %s", strerror(errno)); - /*NOTREACHED*/ - } - - if (memcmp(dst, &faith_prefix, - sizeof(struct in6_addr) - sizeof(struct in_addr) == 0) { - return 1; - } - return 0; -#else - struct myaddrs *p; - struct sockaddr_in6 *sin6; - struct sockaddr_in *sin4; - struct sockaddr_in6 *dst6; - struct sockaddr_in *dst4; - struct sockaddr_in dstmap; - - dst6 = (struct sockaddr_in6 *)dst; - if (dst->sa_family == AF_INET6 - && IN6_IS_ADDR_V4MAPPED(&dst6->sin6_addr)) { - /* ugly... */ - memset(&dstmap, 0, sizeof(dstmap)); - dstmap.sin_family = AF_INET; - dstmap.sin_len = sizeof(dstmap); - memcpy(&dstmap.sin_addr, &dst6->sin6_addr.s6_addr[12], - sizeof(dstmap.sin_addr)); - dst = (struct sockaddr *)&dstmap; - } - - dst6 = (struct sockaddr_in6 *)dst; - dst4 = (struct sockaddr_in *)dst; - - for (p = myaddrs; p; p = p->next) { - sin6 = (struct sockaddr_in6 *)p->addr; - sin4 = (struct sockaddr_in *)p->addr; - - if (p->addr->sa_len != dst->sa_len - || p->addr->sa_family != dst->sa_family) - continue; - - switch (dst->sa_family) { - case AF_INET6: - if (sin6->sin6_scope_id == dst6->sin6_scope_id - && IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &dst6->sin6_addr)) - return 0; - break; - case AF_INET: - if (sin4->sin_addr.s_addr == dst4->sin_addr.s_addr) - return 0; - break; - } - } - return 1; -#endif -} - -/* 0: non faith, 1: faith */ -static int -map6to4(struct sockaddr_in6 *dst6, struct sockaddr_in *dst4) -{ - memset(dst4, 0, sizeof(*dst4)); - dst4->sin_len = sizeof(*dst4); - dst4->sin_family = AF_INET; - dst4->sin_port = dst6->sin6_port; - memcpy(&dst4->sin_addr, &dst6->sin6_addr.s6_addr[12], - sizeof(dst4->sin_addr)); - - if (dst4->sin_addr.s_addr == INADDR_ANY - || dst4->sin_addr.s_addr == INADDR_BROADCAST - || IN_MULTICAST(ntohl(dst4->sin_addr.s_addr))) - return 0; - - return 1; -} - - -static void -sig_child(int sig __unused) -{ - int status; - pid_t pid; - - while ((pid = wait3(&status, WNOHANG, (struct rusage *)0)) > 0) - if (WEXITSTATUS(status)) - syslog(LOG_WARNING, "child %ld exit status 0x%x", - (long)pid, status); -} - -void -sig_terminate(int sig __unused) -{ - syslog(LOG_INFO, "Terminating faith daemon"); - exit(EXIT_SUCCESS); -} - -static void -start_daemon(void) -{ -#ifdef SA_NOCLDWAIT - struct sigaction sa; -#endif - - if (daemon(0, 0) == -1) - exit_stderr("daemon: %s", strerror(errno)); - -#ifdef SA_NOCLDWAIT - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = sig_child; - sa.sa_flags = SA_NOCLDWAIT; - sigemptyset(&sa.sa_mask); - sigaction(SIGCHLD, &sa, (struct sigaction *)0); -#else - if (signal(SIGCHLD, sig_child) == SIG_ERR) { - exit_failure("signal CHLD: %s", strerror(errno)); - /*NOTREACHED*/ - } -#endif - - if (signal(SIGTERM, sig_terminate) == SIG_ERR) { - exit_failure("signal TERM: %s", strerror(errno)); - /*NOTREACHED*/ - } -} - -static void -exit_stderr(const char *fmt, ...) -{ - va_list ap; - char buf[BUFSIZ]; - - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - fprintf(stderr, "%s\n", buf); - exit(EXIT_FAILURE); -} - -void -exit_failure(const char *fmt, ...) -{ - va_list ap; - char buf[BUFSIZ]; - - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - syslog(LOG_ERR, "%s", buf); - exit(EXIT_FAILURE); -} - -void -exit_success(const char *fmt, ...) -{ - va_list ap; - char buf[BUFSIZ]; - - va_start(ap, fmt); - vsnprintf(buf, sizeof(buf), fmt, ap); - va_end(ap); - syslog(LOG_INFO, "%s", buf); - exit(EXIT_SUCCESS); -} - -#ifdef USE_ROUTE -static void -grab_myaddrs(void) -{ - struct ifaddrs *ifap, *ifa; - struct myaddrs *p; - struct sockaddr_in6 *sin6; - - if (getifaddrs(&ifap) != 0) { - exit_failure("getifaddrs"); - /*NOTREACHED*/ - } - - for (ifa = ifap; ifa; ifa = ifa->ifa_next) { - switch (ifa->ifa_addr->sa_family) { - case AF_INET: - case AF_INET6: - break; - default: - continue; - } - - p = (struct myaddrs *)malloc(sizeof(struct myaddrs) + - ifa->ifa_addr->sa_len); - if (!p) { - exit_failure("not enough core"); - /*NOTREACHED*/ - } - memcpy(p + 1, ifa->ifa_addr, ifa->ifa_addr->sa_len); - p->next = myaddrs; - p->addr = (struct sockaddr *)(p + 1); -#ifdef __KAME__ - if (ifa->ifa_addr->sa_family == AF_INET6) { - sin6 = (struct sockaddr_in6 *)p->addr; - if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) - || IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) { - sin6->sin6_scope_id = - ntohs(*(u_int16_t *)&sin6->sin6_addr.s6_addr[2]); - sin6->sin6_addr.s6_addr[2] = 0; - sin6->sin6_addr.s6_addr[3] = 0; - } - } -#endif - myaddrs = p; - if (dflag) { - char hbuf[NI_MAXHOST]; - getnameinfo(p->addr, p->addr->sa_len, - hbuf, sizeof(hbuf), NULL, 0, - NI_NUMERICHOST); - syslog(LOG_INFO, "my interface: %s %s", hbuf, - ifa->ifa_name); - } - } - - freeifaddrs(ifap); -} - -static void -free_myaddrs(void) -{ - struct myaddrs *p, *q; - - p = myaddrs; - while (p) { - q = p->next; - free(p); - p = q; - } - myaddrs = NULL; -} - -static void -update_myaddrs(void) -{ - char msg[BUFSIZ]; - int len; - struct rt_msghdr *rtm; - - len = read(sockfd, msg, sizeof(msg)); - if (len < 0) { - syslog(LOG_ERR, "read(PF_ROUTE) failed"); - return; - } - rtm = (struct rt_msghdr *)msg; - if (len < 4 || len < rtm->rtm_msglen) { - syslog(LOG_ERR, "read(PF_ROUTE) short read"); - return; - } - if (rtm->rtm_version != RTM_VERSION) { - syslog(LOG_ERR, "routing socket version mismatch"); - close(sockfd); - sockfd = 0; - return; - } - switch (rtm->rtm_type) { - case RTM_NEWADDR: - case RTM_DELADDR: - case RTM_IFINFO: - break; - default: - return; - } - /* XXX more filters here? */ - - syslog(LOG_INFO, "update interface address list"); - free_myaddrs(); - grab_myaddrs(); -} -#endif /*USE_ROUTE*/ - -static void -usage(void) -{ - fprintf(stderr, "usage: %s [-dp] [-f conf] service [serverpath [serverargs]]\n", - faithdname); - exit(0); -} diff --git a/usr.sbin/faithd/faithd.h b/usr.sbin/faithd/faithd.h deleted file mode 100644 index c578d46..0000000 --- a/usr.sbin/faithd/faithd.h +++ /dev/null @@ -1,70 +0,0 @@ -/* $KAME: faithd.h,v 1.9 2002/05/09 09:41:24 itojun Exp $ */ - -/* - * Copyright (C) 1997 and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -extern char logname[]; -extern int dflag; - -extern void tcp_relay(int, int, const char *); -extern void ftp_relay(int, int); -extern int ftp_active(int, int, int *, int *); -extern int ftp_passive(int, int, int *, int *); -extern void exit_success(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); -extern void exit_failure(const char *, ...) - __attribute__((__format__(__printf__, 1, 2))); - -#define DEFAULT_PORT_NAME "telnet" -#define DEFAULT_DIR "/usr/libexec" -#define DEFAULT_NAME "telnetd" -#define DEFAULT_PATH (DEFAULT_DIR "/" DEFAULT_NAME) - -#define FTP_PORT 21 -#define RLOGIN_PORT 513 -#define RSH_PORT 514 - -#define RETURN_SUCCESS 0 -#define RETURN_FAILURE 1 - -#define YES 1 -#define NO 0 - -#define MSS 2048 -#define MAXARGV 20 - -#define NUMPRT 0 -#define NUMPRG 1 -#define NUMARG 2 - -#define UC(b) (((int)b)&0xff) - -#define FAITH_TIMEOUT (30 * 60) /*second*/ diff --git a/usr.sbin/faithd/ftp.c b/usr.sbin/faithd/ftp.c deleted file mode 100644 index c54371a..0000000 --- a/usr.sbin/faithd/ftp.c +++ /dev/null @@ -1,1085 +0,0 @@ -/* $KAME: ftp.c,v 1.24 2005/03/16 05:05:48 itojun Exp $ */ - -/* - * Copyright (C) 1997 and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#ifdef HAVE_POLL_H -#include -#endif -#include -#include - -#include -#include -#include - -#include "faithd.h" - -static char rbuf[MSS]; -static char sbuf[MSS]; -static int passivemode = 0; -static int wport4 = -1; /* listen() to active */ -static int wport6 = -1; /* listen() to passive */ -static int port4 = -1; /* active: inbound passive: outbound */ -static int port6 = -1; /* active: outbound passive: inbound */ -static struct sockaddr_storage data4; /* server data address */ -static struct sockaddr_storage data6; /* client data address */ -static int epsvall = 0; - -enum state { NONE, LPRT, EPRT, LPSV, EPSV }; - -static int ftp_activeconn(void); -static int ftp_passiveconn(void); -static int ftp_copy(int, int); -static int ftp_copyresult(int, int, enum state); -static int ftp_copycommand(int, int, enum state *); - -void -ftp_relay(int ctl6, int ctl4) -{ -#ifdef HAVE_POLL_H - struct pollfd pfd[6]; -#else - fd_set readfds; -#endif - int error; - enum state state = NONE; - struct timeval tv; - - syslog(LOG_INFO, "starting ftp control connection"); - - for (;;) { -#ifdef HAVE_POLL_H - pfd[0].fd = ctl4; - pfd[0].events = POLLIN; - pfd[1].fd = ctl6; - pfd[1].events = POLLIN; - if (0 <= port4) { - pfd[2].fd = port4; - pfd[2].events = POLLIN; - } else - pfd[2].fd = -1; - if (0 <= port6) { - pfd[3].fd = port6; - pfd[3].events = POLLIN; - } else - pfd[3].fd = -1; -#if 0 - if (0 <= wport4) { - pfd[4].fd = wport4; - pfd[4].events = POLLIN; - } else - pfd[4].fd = -1; - if (0 <= wport6) { - pfd[5].fd = wport4; - pfd[5].events = POLLIN; - } else - pfd[5].fd = -1; -#else - pfd[4].fd = pfd[5].fd = -1; - pfd[4].events = pfd[5].events = 0; -#endif -#else - int maxfd = 0; - - FD_ZERO(&readfds); - if (ctl4 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(ctl4, &readfds); - maxfd = ctl4; - if (ctl6 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(ctl6, &readfds); - maxfd = (ctl6 > maxfd) ? ctl6 : maxfd; - if (0 <= port4) { - if (port4 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(port4, &readfds); - maxfd = (port4 > maxfd) ? port4 : maxfd; - } - if (0 <= port6) { - if (port6 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(port6, &readfds); - maxfd = (port6 > maxfd) ? port6 : maxfd; - } -#if 0 - if (0 <= wport4) { - if (wport4 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(wport4, &readfds); - maxfd = (wport4 > maxfd) ? wport4 : maxfd; - } - if (0 <= wport6) { - if (wport6 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(wport6, &readfds); - maxfd = (wport6 > maxfd) ? wport6 : maxfd; - } -#endif -#endif - tv.tv_sec = FAITH_TIMEOUT; - tv.tv_usec = 0; - -#ifdef HAVE_POLL_H - error = poll(pfd, sizeof(pfd)/sizeof(pfd[0]), tv.tv_sec * 1000); -#else - error = select(maxfd + 1, &readfds, NULL, NULL, &tv); -#endif - if (error == -1) { -#ifdef HAVE_POLL_H - exit_failure("poll: %s", strerror(errno)); -#else - exit_failure("select: %s", strerror(errno)); -#endif - } - else if (error == 0) - exit_failure("connection timeout"); - - /* - * The order of the following checks does (slightly) matter. - * It is important to visit all checks (do not use "continue"), - * otherwise some of the pipe may become full and we cannot - * relay correctly. - */ -#ifdef HAVE_POLL_H - if (pfd[1].revents & POLLIN) -#else - if (FD_ISSET(ctl6, &readfds)) -#endif - { - /* - * copy control connection from the client. - * command translation is necessary. - */ - error = ftp_copycommand(ctl6, ctl4, &state); - - if (error < 0) - goto bad; - else if (error == 0) { - close(ctl4); - close(ctl6); - exit_success("terminating ftp control connection"); - /*NOTREACHED*/ - } - } -#ifdef HAVE_POLL_H - if (pfd[0].revents & POLLIN) -#else - if (FD_ISSET(ctl4, &readfds)) -#endif - { - /* - * copy control connection from the server - * translation of result code is necessary. - */ - error = ftp_copyresult(ctl4, ctl6, state); - - if (error < 0) - goto bad; - else if (error == 0) { - close(ctl4); - close(ctl6); - exit_success("terminating ftp control connection"); - /*NOTREACHED*/ - } - } -#ifdef HAVE_POLL_H - if (0 <= port4 && 0 <= port6 && (pfd[2].revents & POLLIN)) -#else - if (0 <= port4 && 0 <= port6 && FD_ISSET(port4, &readfds)) -#endif - { - /* - * copy data connection. - * no special treatment necessary. - */ -#ifdef HAVE_POLL_H - if (pfd[2].revents & POLLIN) -#else - if (FD_ISSET(port4, &readfds)) -#endif - error = ftp_copy(port4, port6); - switch (error) { - case -1: - goto bad; - case 0: - close(port4); - close(port6); - port4 = port6 = -1; - syslog(LOG_INFO, "terminating data connection"); - break; - default: - break; - } - } -#ifdef HAVE_POLL_H - if (0 <= port4 && 0 <= port6 && (pfd[3].revents & POLLIN)) -#else - if (0 <= port4 && 0 <= port6 && FD_ISSET(port6, &readfds)) -#endif - { - /* - * copy data connection. - * no special treatment necessary. - */ -#ifdef HAVE_POLL_H - if (pfd[3].revents & POLLIN) -#else - if (FD_ISSET(port6, &readfds)) -#endif - error = ftp_copy(port6, port4); - switch (error) { - case -1: - goto bad; - case 0: - close(port4); - close(port6); - port4 = port6 = -1; - syslog(LOG_INFO, "terminating data connection"); - break; - default: - break; - } - } -#if 0 -#ifdef HAVE_POLL_H - if (wport4 && (pfd[4].revents & POLLIN)) -#else - if (wport4 && FD_ISSET(wport4, &readfds)) -#endif - { - /* - * establish active data connection from the server. - */ - ftp_activeconn(); - } -#ifdef HAVE_POLL_H - if (wport4 && (pfd[5].revents & POLLIN)) -#else - if (wport6 && FD_ISSET(wport6, &readfds)) -#endif - { - /* - * establish passive data connection from the client. - */ - ftp_passiveconn(); - } -#endif - } - - bad: - exit_failure("%s", strerror(errno)); -} - -static int -ftp_activeconn() -{ - socklen_t n; - int error; -#ifdef HAVE_POLL_H - struct pollfd pfd[1]; -#else - fd_set set; -#endif - struct timeval timeout; - struct sockaddr *sa; - - /* get active connection from server */ -#ifdef HAVE_POLL_H - pfd[0].fd = wport4; - pfd[0].events = POLLIN; -#else - FD_ZERO(&set); - if (wport4 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(wport4, &set); -#endif - timeout.tv_sec = 120; - timeout.tv_usec = 0; - n = sizeof(data4); -#ifdef HAVE_POLL_H - if (poll(pfd, sizeof(pfd)/sizeof(pfd[0]), timeout.tv_sec * 1000) == 0 || - (port4 = accept(wport4, (struct sockaddr *)&data4, &n)) < 0) -#else - if (select(wport4 + 1, &set, NULL, NULL, &timeout) == 0 || - (port4 = accept(wport4, (struct sockaddr *)&data4, &n)) < 0) -#endif - { - close(wport4); - wport4 = -1; - syslog(LOG_INFO, "active mode data connection failed"); - return -1; - } - - /* ask active connection to client */ - sa = (struct sockaddr *)&data6; - port6 = socket(sa->sa_family, SOCK_STREAM, 0); - if (port6 == -1) { - close(port4); - close(wport4); - port4 = wport4 = -1; - syslog(LOG_INFO, "active mode data connection failed"); - return -1; - } - error = connect(port6, sa, sa->sa_len); - if (error < 0) { - close(port6); - close(port4); - close(wport4); - port6 = port4 = wport4 = -1; - syslog(LOG_INFO, "active mode data connection failed"); - return -1; - } - - syslog(LOG_INFO, "active mode data connection established"); - return 0; -} - -static int -ftp_passiveconn() -{ - socklen_t len; - int error; -#ifdef HAVE_POLL_H - struct pollfd pfd[1]; -#else - fd_set set; -#endif - struct timeval timeout; - struct sockaddr *sa; - - /* get passive connection from client */ -#ifdef HAVE_POLL_H - pfd[0].fd = wport6; - pfd[0].events = POLLIN; -#else - FD_ZERO(&set); - if (wport6 >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(wport6, &set); -#endif - timeout.tv_sec = 120; - timeout.tv_usec = 0; - len = sizeof(data6); -#ifdef HAVE_POLL_H - if (poll(pfd, sizeof(pfd)/sizeof(pfd[0]), timeout.tv_sec * 1000) == 0 || - (port6 = accept(wport6, (struct sockaddr *)&data6, &len)) < 0) -#else - if (select(wport6 + 1, &set, NULL, NULL, &timeout) == 0 || - (port6 = accept(wport6, (struct sockaddr *)&data6, &len)) < 0) -#endif - { - close(wport6); - wport6 = -1; - syslog(LOG_INFO, "passive mode data connection failed"); - return -1; - } - - /* ask passive connection to server */ - sa = (struct sockaddr *)&data4; - port4 = socket(sa->sa_family, SOCK_STREAM, 0); - if (port4 == -1) { - close(wport6); - close(port6); - wport6 = port6 = -1; - syslog(LOG_INFO, "passive mode data connection failed"); - return -1; - } - error = connect(port4, sa, sa->sa_len); - if (error < 0) { - close(wport6); - close(port4); - close(port6); - wport6 = port4 = port6 = -1; - syslog(LOG_INFO, "passive mode data connection failed"); - return -1; - } - - syslog(LOG_INFO, "passive mode data connection established"); - return 0; -} - -static int -ftp_copy(int src, int dst) -{ - int error, atmark, n; - - /* OOB data handling */ - error = ioctl(src, SIOCATMARK, &atmark); - if (error != -1 && atmark == 1) { - n = read(src, rbuf, 1); - if (n == -1) - goto bad; - send(dst, rbuf, n, MSG_OOB); -#if 0 - n = read(src, rbuf, sizeof(rbuf)); - if (n == -1) - goto bad; - write(dst, rbuf, n); - return n; -#endif - } - - n = read(src, rbuf, sizeof(rbuf)); - switch (n) { - case -1: - case 0: - return n; - default: - write(dst, rbuf, n); - return n; - } - - bad: - exit_failure("%s", strerror(errno)); - /*NOTREACHED*/ - return 0; /* to make gcc happy */ -} - -static int -ftp_copyresult(int src, int dst, enum state state) -{ - int error, atmark, n; - socklen_t len; - char *param; - int code; - char *a, *p; - int i; - - /* OOB data handling */ - error = ioctl(src, SIOCATMARK, &atmark); - if (error != -1 && atmark == 1) { - n = read(src, rbuf, 1); - if (n == -1) - goto bad; - send(dst, rbuf, n, MSG_OOB); -#if 0 - n = read(src, rbuf, sizeof(rbuf)); - if (n == -1) - goto bad; - write(dst, rbuf, n); - return n; -#endif - } - - n = read(src, rbuf, sizeof(rbuf)); - if (n <= 0) - return n; - rbuf[n] = '\0'; - - /* - * parse argument - */ - p = rbuf; - for (i = 0; i < 3; i++) { - if (!isdigit(*p)) { - /* invalid reply */ - write(dst, rbuf, n); - return n; - } - p++; - } - if (!isspace(*p)) { - /* invalid reply */ - write(dst, rbuf, n); - return n; - } - code = atoi(rbuf); - param = p; - /* param points to first non-command token, if any */ - while (*param && isspace(*param)) - param++; - if (!*param) - param = NULL; - - switch (state) { - case NONE: - if (!passivemode && rbuf[0] == '1') { - if (ftp_activeconn() < 0) { - n = snprintf(rbuf, sizeof(rbuf), - "425 Cannot open data connetion\r\n"); - if (n < 0 || n >= sizeof(rbuf)) - n = 0; - } - } - if (n) - write(dst, rbuf, n); - return n; - case LPRT: - case EPRT: - /* expecting "200 PORT command successful." */ - if (code == 200) { - p = strstr(rbuf, "PORT"); - if (p) { - p[0] = (state == LPRT) ? 'L' : 'E'; - p[1] = 'P'; - } - } else { - close(wport4); - wport4 = -1; - } - write(dst, rbuf, n); - return n; - case LPSV: - case EPSV: - /* - * expecting "227 Entering Passive Mode (x,x,x,x,x,x,x)" - * (in some cases result comes without paren) - */ - if (code != 227) { -passivefail0: - close(wport6); - wport6 = -1; - write(dst, rbuf, n); - return n; - } - - { - unsigned int ho[4], po[2]; - struct sockaddr_in *sin; - struct sockaddr_in6 *sin6; - u_short port; - - /* - * PASV result -> LPSV/EPSV result - */ - p = param; - while (*p && *p != '(' && !isdigit(*p)) /*)*/ - p++; - if (!*p) - goto passivefail0; /*XXX*/ - if (*p == '(') /*)*/ - p++; - n = sscanf(p, "%u,%u,%u,%u,%u,%u", - &ho[0], &ho[1], &ho[2], &ho[3], &po[0], &po[1]); - if (n != 6) - goto passivefail0; /*XXX*/ - - /* keep PORT parameter */ - memset(&data4, 0, sizeof(data4)); - sin = (struct sockaddr_in *)&data4; - sin->sin_len = sizeof(*sin); - sin->sin_family = AF_INET; - sin->sin_addr.s_addr = 0; - for (n = 0; n < 4; n++) { - sin->sin_addr.s_addr |= - htonl((ho[n] & 0xff) << ((3 - n) * 8)); - } - sin->sin_port = htons(((po[0] & 0xff) << 8) | (po[1] & 0xff)); - - /* get ready for passive data connection */ - memset(&data6, 0, sizeof(data6)); - sin6 = (struct sockaddr_in6 *)&data6; - sin6->sin6_len = sizeof(*sin6); - sin6->sin6_family = AF_INET6; - wport6 = socket(sin6->sin6_family, SOCK_STREAM, 0); - if (wport6 == -1) { -passivefail: - n = snprintf(sbuf, sizeof(sbuf), - "500 could not translate from PASV\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } -#ifdef IPV6_FAITH - { - int on = 1; - error = setsockopt(wport6, IPPROTO_IPV6, IPV6_FAITH, - &on, sizeof(on)); - if (error == -1) - exit_failure("setsockopt(IPV6_FAITH): %s", strerror(errno)); - } -#endif - error = bind(wport6, (struct sockaddr *)sin6, sin6->sin6_len); - if (error == -1) { - close(wport6); - wport6 = -1; - goto passivefail; - } - error = listen(wport6, 1); - if (error == -1) { - close(wport6); - wport6 = -1; - goto passivefail; - } - - /* transmit LPSV or EPSV */ - /* - * addr from dst, port from wport6 - */ - len = sizeof(data6); - error = getsockname(wport6, (struct sockaddr *)&data6, &len); - if (error == -1) { - close(wport6); - wport6 = -1; - goto passivefail; - } - sin6 = (struct sockaddr_in6 *)&data6; - port = sin6->sin6_port; - - len = sizeof(data6); - error = getsockname(dst, (struct sockaddr *)&data6, &len); - if (error == -1) { - close(wport6); - wport6 = -1; - goto passivefail; - } - sin6 = (struct sockaddr_in6 *)&data6; - sin6->sin6_port = port; - - if (state == LPSV) { - a = (char *)&sin6->sin6_addr; - p = (char *)&sin6->sin6_port; - n = snprintf(sbuf, sizeof(sbuf), -"228 Entering Long Passive Mode (%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)\r\n", - 6, 16, UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), - UC(a[4]), UC(a[5]), UC(a[6]), UC(a[7]), - UC(a[8]), UC(a[9]), UC(a[10]), UC(a[11]), - UC(a[12]), UC(a[13]), UC(a[14]), UC(a[15]), - 2, UC(p[0]), UC(p[1])); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(dst, sbuf, n); - passivemode = 1; - return n; - } else { - n = snprintf(sbuf, sizeof(sbuf), -"229 Entering Extended Passive Mode (|||%d|)\r\n", - ntohs(sin6->sin6_port)); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(dst, sbuf, n); - passivemode = 1; - return n; - } - } - } - - bad: - exit_failure("%s", strerror(errno)); - /*NOTREACHED*/ - return 0; /* to make gcc happy */ -} - -static int -ftp_copycommand(int src, int dst, enum state *state) -{ - int error, atmark, n; - socklen_t len; - unsigned int af, hal, ho[16], pal, po[2]; - char *a, *p, *q; - char cmd[5], *param; - struct sockaddr_in *sin; - struct sockaddr_in6 *sin6; - enum state nstate; - char ch; - int i; - - /* OOB data handling */ - error = ioctl(src, SIOCATMARK, &atmark); - if (error != -1 && atmark == 1) { - n = read(src, rbuf, 1); - if (n == -1) - goto bad; - send(dst, rbuf, n, MSG_OOB); -#if 0 - n = read(src, rbuf, sizeof(rbuf)); - if (n == -1) - goto bad; - write(dst, rbuf, n); - return n; -#endif - } - - n = read(src, rbuf, sizeof(rbuf)); - if (n <= 0) - return n; - rbuf[n] = '\0'; - - if (n < 4) { - write(dst, rbuf, n); - return n; - } - - /* - * parse argument - */ - p = rbuf; - q = cmd; - for (i = 0; i < 4; i++) { - if (!isalpha(*p)) { - /* invalid command */ - write(dst, rbuf, n); - return n; - } - *q++ = islower(*p) ? toupper(*p) : *p; - p++; - } - if (!isspace(*p)) { - /* invalid command */ - write(dst, rbuf, n); - return n; - } - *q = '\0'; - param = p; - /* param points to first non-command token, if any */ - while (*param && isspace(*param)) - param++; - if (!*param) - param = NULL; - - *state = NONE; - - if (strcmp(cmd, "LPRT") == 0 && param) { - /* - * LPRT -> PORT - */ - nstate = LPRT; - - close(wport4); - close(wport6); - close(port4); - close(port6); - wport4 = wport6 = port4 = port6 = -1; - - if (epsvall) { - n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n", - cmd); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - - n = sscanf(param, -"%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u", - &af, &hal, &ho[0], &ho[1], &ho[2], &ho[3], - &ho[4], &ho[5], &ho[6], &ho[7], - &ho[8], &ho[9], &ho[10], &ho[11], - &ho[12], &ho[13], &ho[14], &ho[15], - &pal, &po[0], &po[1]); - if (n != 21 || af != 6 || hal != 16|| pal != 2) { - n = snprintf(sbuf, sizeof(sbuf), - "501 illegal parameter to LPRT\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - - /* keep LPRT parameter */ - memset(&data6, 0, sizeof(data6)); - sin6 = (struct sockaddr_in6 *)&data6; - sin6->sin6_len = sizeof(*sin6); - sin6->sin6_family = AF_INET6; - for (n = 0; n < 16; n++) - sin6->sin6_addr.s6_addr[n] = ho[n]; - sin6->sin6_port = htons(((po[0] & 0xff) << 8) | (po[1] & 0xff)); - -sendport: - /* get ready for active data connection */ - len = sizeof(data4); - error = getsockname(dst, (struct sockaddr *)&data4, &len); - if (error == -1) { -lprtfail: - n = snprintf(sbuf, sizeof(sbuf), - "500 could not translate to PORT\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - if (((struct sockaddr *)&data4)->sa_family != AF_INET) - goto lprtfail; - sin = (struct sockaddr_in *)&data4; - sin->sin_port = 0; - wport4 = socket(sin->sin_family, SOCK_STREAM, 0); - if (wport4 == -1) - goto lprtfail; - error = bind(wport4, (struct sockaddr *)sin, sin->sin_len); - if (error == -1) { - close(wport4); - wport4 = -1; - goto lprtfail; - } - error = listen(wport4, 1); - if (error == -1) { - close(wport4); - wport4 = -1; - goto lprtfail; - } - - /* transmit PORT */ - len = sizeof(data4); - error = getsockname(wport4, (struct sockaddr *)&data4, &len); - if (error == -1) { - close(wport4); - wport4 = -1; - goto lprtfail; - } - if (((struct sockaddr *)&data4)->sa_family != AF_INET) { - close(wport4); - wport4 = -1; - goto lprtfail; - } - sin = (struct sockaddr_in *)&data4; - a = (char *)&sin->sin_addr; - p = (char *)&sin->sin_port; - n = snprintf(sbuf, sizeof(sbuf), "PORT %d,%d,%d,%d,%d,%d\r\n", - UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), - UC(p[0]), UC(p[1])); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(dst, sbuf, n); - *state = nstate; - passivemode = 0; - return n; - } else if (strcmp(cmd, "EPRT") == 0 && param) { - /* - * EPRT -> PORT - */ - char *afp, *hostp, *portp; - struct addrinfo hints, *res; - - nstate = EPRT; - - close(wport4); - close(wport6); - close(port4); - close(port6); - wport4 = wport6 = port4 = port6 = -1; - - if (epsvall) { - n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n", - cmd); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - - p = param; - ch = *p++; /* boundary character */ - afp = p; - while (*p && *p != ch) - p++; - if (!*p) { -eprtparamfail: - n = snprintf(sbuf, sizeof(sbuf), - "501 illegal parameter to EPRT\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - *p++ = '\0'; - hostp = p; - while (*p && *p != ch) - p++; - if (!*p) - goto eprtparamfail; - *p++ = '\0'; - portp = p; - while (*p && *p != ch) - p++; - if (!*p) - goto eprtparamfail; - *p++ = '\0'; - - n = sscanf(afp, "%d", &af); - if (n != 1 || af != 2) { - n = snprintf(sbuf, sizeof(sbuf), - "501 unsupported address family to EPRT\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - error = getaddrinfo(hostp, portp, &hints, &res); - if (error) { - n = snprintf(sbuf, sizeof(sbuf), - "501 EPRT: %s\r\n", gai_strerror(error)); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - if (res->ai_next) { - n = snprintf(sbuf, sizeof(sbuf), - "501 EPRT: %s resolved to multiple addresses\r\n", hostp); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - freeaddrinfo(res); - return n; - } - - memcpy(&data6, res->ai_addr, res->ai_addrlen); - - freeaddrinfo(res); - goto sendport; - } else if (strcmp(cmd, "LPSV") == 0 && !param) { - /* - * LPSV -> PASV - */ - nstate = LPSV; - - close(wport4); - close(wport6); - close(port4); - close(port6); - wport4 = wport6 = port4 = port6 = -1; - - if (epsvall) { - n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n", - cmd); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } - - /* transmit PASV */ - n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(dst, sbuf, n); - *state = LPSV; - passivemode = 0; /* to be set to 1 later */ - return n; - } else if (strcmp(cmd, "EPSV") == 0 && !param) { - /* - * EPSV -> PASV - */ - close(wport4); - close(wport6); - close(port4); - close(port6); - wport4 = wport6 = port4 = port6 = -1; - - n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(dst, sbuf, n); - *state = EPSV; - passivemode = 0; /* to be set to 1 later */ - return n; - } else if (strcmp(cmd, "EPSV") == 0 && param - && strncasecmp(param, "ALL", 3) == 0 && isspace(param[3])) { - /* - * EPSV ALL - */ - epsvall = 1; - n = snprintf(sbuf, sizeof(sbuf), "200 EPSV ALL command successful.\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } else if (strcmp(cmd, "PORT") == 0 || strcmp(cmd, "PASV") == 0) { - /* - * reject PORT/PASV - */ - n = snprintf(sbuf, sizeof(sbuf), "502 %s not implemented.\r\n", cmd); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - return n; - } else if (passivemode - && (strcmp(cmd, "STOR") == 0 - || strcmp(cmd, "STOU") == 0 - || strcmp(cmd, "RETR") == 0 - || strcmp(cmd, "LIST") == 0 - || strcmp(cmd, "NLST") == 0 - || strcmp(cmd, "APPE") == 0)) { - /* - * commands with data transfer. need to care about passive - * mode data connection. - */ - - if (ftp_passiveconn() < 0) { - n = snprintf(sbuf, sizeof(sbuf), "425 Cannot open data connetion\r\n"); - if (n < 0 || n >= sizeof(sbuf)) - n = 0; - if (n) - write(src, sbuf, n); - } else { - /* simply relay the command */ - write(dst, rbuf, n); - } - - *state = NONE; - return n; - } else { - /* simply relay it */ - *state = NONE; - write(dst, rbuf, n); - return n; - } - - bad: - exit_failure("%s", strerror(errno)); - /*NOTREACHED*/ - return 0; /* to make gcc happy */ -} diff --git a/usr.sbin/faithd/prefix.c b/usr.sbin/faithd/prefix.c deleted file mode 100644 index 6a3f66b..0000000 --- a/usr.sbin/faithd/prefix.c +++ /dev/null @@ -1,349 +0,0 @@ -/* $KAME: prefix.c,v 1.13 2003/09/02 22:50:17 itojun Exp $ */ -/* $FreeBSD$ */ - -/* - * Copyright (C) 2000 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef offsetof -#define offsetof(type, member) ((size_t)(u_long)(&((type *)0)->member)) -#endif - -#include "faithd.h" -#include "prefix.h" - -static int prefix_set(const char *, struct prefix *, int); -static struct config *config_load1(const char *); -#if 0 -static void config_show1(const struct config *); -static void config_show(void); -#endif - -struct config *config_list = NULL; -const int niflags = NI_NUMERICHOST; - -static int -prefix_set(const char *s, struct prefix *prefix, int slash) -{ - char *p = NULL, *q, *r; - struct addrinfo hints, *res = NULL; - int max; - char *a; - - p = strdup(s); - if (!p) - goto fail; - q = strchr(p, '/'); - if (q) { - if (!slash) - goto fail; - *q++ = '\0'; - } - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; - hints.ai_socktype = SOCK_DGRAM; /*dummy*/ - hints.ai_flags = AI_NUMERICHOST; - if (getaddrinfo(p, "0", &hints, &res)) - goto fail; - if (res->ai_next || res->ai_addrlen > sizeof(prefix->a)) - goto fail; - memcpy(&prefix->a, res->ai_addr, res->ai_addrlen); - - switch (prefix->a.ss_family) { - case AF_INET: - max = 32; - a = (char *)&((struct sockaddr_in *)&prefix->a)->sin_addr; - break; - case AF_INET6: - max = 128; - a = (char *)&((struct sockaddr_in6 *)&prefix->a)->sin6_addr; - break; - default: - a = NULL; - max = -1; - break; - } - - if (q) { - r = NULL; - prefix->l = (int)strtoul(q, &r, 10); - if (!*q || *r) - goto fail; - if (prefix->l < 0 || prefix->l > max) - goto fail; - } else - prefix->l = max; - - if (p) - free(p); - if (res) - freeaddrinfo(res); - return 0; - -fail: - if (p) - free(p); - if (res) - freeaddrinfo(res); - return -1; -} - -const char * -prefix_string(const struct prefix *prefix) -{ - static char buf[NI_MAXHOST + 20]; - char hbuf[NI_MAXHOST]; - - if (getnameinfo((const struct sockaddr *)&prefix->a, prefix->a.ss_len, - hbuf, sizeof(hbuf), NULL, 0, niflags)) - return NULL; - snprintf(buf, sizeof(buf), "%s/%d", hbuf, prefix->l); - return buf; -} - -int -prefix_match(const struct prefix *prefix, const struct sockaddr *sa) -{ - struct sockaddr_storage a, b; - char *pa, *pb; - int off, l; - - if (prefix->a.ss_family != sa->sa_family || - prefix->a.ss_len != sa->sa_len) - return 0; - - if (prefix->a.ss_len > sizeof(a) || sa->sa_len > sizeof(b)) - return 0; - - switch (prefix->a.ss_family) { - case AF_INET: - off = offsetof(struct sockaddr_in, sin_addr); - break; - case AF_INET6: - off = offsetof(struct sockaddr_in6, sin6_addr); - break; - default: - if (memcmp(&prefix->a, sa, prefix->a.ss_len) != 0) - return 0; - else - return 1; - } - - memcpy(&a, &prefix->a, prefix->a.ss_len); - memcpy(&b, sa, sa->sa_len); - l = prefix->l / 8 + (prefix->l % 8 ? 1 : 0); - - /* overrun check */ - if (off + l > a.ss_len) - return 0; - - pa = ((char *)&a) + off; - pb = ((char *)&b) + off; - if (prefix->l % 8) { - pa[prefix->l / 8] &= 0xff00 >> (prefix->l % 8); - pb[prefix->l / 8] &= 0xff00 >> (prefix->l % 8); - } - if (memcmp(pa, pb, l) != 0) - return 0; - else - return 1; -} - -/* - * prefix/prefixlen permit/deny prefix/prefixlen [srcaddr] - * 3ffe::/16 permit 10.0.0.0/8 10.1.1.1 - */ -static struct config * -config_load1(const char *line) -{ - struct config *conf; - char buf[BUFSIZ]; - char *p; - char *token[4]; - int i; - - if (strlen(line) + 1 > sizeof(buf)) - return NULL; - strlcpy(buf, line, sizeof(buf)); - - p = strchr(buf, '\n'); - if (!p) - return NULL; - *p = '\0'; - p = strchr(buf, '#'); - if (p) - *p = '\0'; - if (strlen(buf) == 0) - return NULL; - - p = buf; - memset(token, 0, sizeof(token)); - for (i = 0; i < sizeof(token) / sizeof(token[0]); i++) { - token[i] = strtok(p, "\t "); - p = NULL; - if (token[i] == NULL) - break; - } - /* extra tokens? */ - if (strtok(p, "\t ") != NULL) - return NULL; - /* insufficient tokens */ - switch (i) { - case 3: - case 4: - break; - default: - return NULL; - } - - conf = (struct config *)malloc(sizeof(*conf)); - if (conf == NULL) - return NULL; - memset(conf, 0, sizeof(*conf)); - - if (strcasecmp(token[1], "permit") == 0) - conf->permit = 1; - else if (strcasecmp(token[1], "deny") == 0) - conf->permit = 0; - else { - /* invalid keyword is considered as "deny" */ - conf->permit = 0; - } - - if (prefix_set(token[0], &conf->match, 1) < 0) - goto fail; - if (prefix_set(token[2], &conf->dest, 1) < 0) - goto fail; - if (token[3]) { - if (prefix_set(token[3], &conf->src, 0) < 0) - goto fail; - } - - return conf; - -fail: - free(conf); - return NULL; -} - -int -config_load(const char *configfile) -{ - FILE *fp; - char buf[BUFSIZ]; - struct config *conf, *p; - struct config sentinel; - - config_list = NULL; - - if (!configfile) - configfile = _PATH_PREFIX_CONF; - fp = fopen(configfile, "r"); - if (fp == NULL) - return -1; - - p = &sentinel; - sentinel.next = NULL; - while (fgets(buf, sizeof(buf), fp) != NULL) { - conf = config_load1(buf); - if (conf) { - p->next = conf; - p = p->next; - } - } - config_list = sentinel.next; - - fclose(fp); - return 0; -} - -#if 0 -static void -config_show1(const struct config *conf) -{ - const char *p; - - p = prefix_string(&conf->match); - printf("%s", p ? p : "?"); - - if (conf->permit) - printf(" permit"); - else - printf(" deny"); - - p = prefix_string(&conf->dest); - printf(" %s", p ? p : "?"); - - printf("\n"); -} - -static void -config_show() -{ - struct config *conf; - - for (conf = config_list; conf; conf = conf->next) - config_show1(conf); -} -#endif - -const struct config * -config_match(struct sockaddr *sa1, struct sockaddr *sa2) -{ - static struct config conf; - const struct config *p; - - if (sa1->sa_len > sizeof(conf.match.a) || - sa2->sa_len > sizeof(conf.dest.a)) - return NULL; - - memset(&conf, 0, sizeof(conf)); - if (!config_list) { - conf.permit = 1; - memcpy(&conf.match.a, sa1, sa1->sa_len); - memcpy(&conf.dest.a, sa2, sa2->sa_len); - return &conf; - } - - for (p = config_list; p; p = p->next) - if (prefix_match(&p->match, sa1) && prefix_match(&p->dest, sa2)) - return p; - - return NULL; -} diff --git a/usr.sbin/faithd/prefix.h b/usr.sbin/faithd/prefix.h deleted file mode 100644 index 4d6b3d5..0000000 --- a/usr.sbin/faithd/prefix.h +++ /dev/null @@ -1,52 +0,0 @@ -/* $KAME: prefix.h,v 1.4 2001/09/05 03:04:21 itojun Exp $ */ -/* $FreeBSD$ */ - -/* - * Copyright (C) 2000 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -struct prefix { - struct sockaddr_storage a; - int l; -}; - -struct config { - struct config *next; - - int permit; - struct prefix match; - struct prefix dest; - struct prefix src; /* src to use for outgoing connection */ -}; - -#define _PATH_PREFIX_CONF "/etc/faithd.conf" - -extern const char *prefix_string(const struct prefix *); -extern int prefix_match(const struct prefix *, const struct sockaddr *); -extern int config_load(const char *); -extern const struct config *config_match(struct sockaddr *, struct sockaddr *); diff --git a/usr.sbin/faithd/tcp.c b/usr.sbin/faithd/tcp.c deleted file mode 100644 index 2197694..0000000 --- a/usr.sbin/faithd/tcp.c +++ /dev/null @@ -1,324 +0,0 @@ -/* $KAME: tcp.c,v 1.13 2003/09/02 22:49:21 itojun Exp $ */ - -/* - * Copyright (C) 1997 and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "faithd.h" - -static char tcpbuf[16*1024]; - /* bigger than MSS and may be lesser than window size */ -static int tblen, tboff, oob_exists; -static fd_set readfds, writefds, exceptfds; -static char atmark_buf[2]; -static pid_t cpid = (pid_t)0; -static pid_t ppid = (pid_t)0; -volatile time_t child_lastactive = (time_t)0; -static time_t parent_lastactive = (time_t)0; - -static void sig_ctimeout(int); -static void sig_child(int); -static void notify_inactive(void); -static void notify_active(void); -static void send_data(int, int, const char *, int); -static void relay(int, int, const char *, int); - -/* - * Inactivity timer: - * - child side (ppid != 0) will send SIGUSR1 to parent every (FAITH_TIMEOUT/4) - * second if traffic is active. if traffic is inactive, don't send SIGUSR1. - * - parent side (ppid == 0) will check the last SIGUSR1 it have seen. - */ -static void -sig_ctimeout(int sig __unused) -{ - /* parent side: record notification from the child */ - if (dflag) - syslog(LOG_DEBUG, "activity timer from child"); - child_lastactive = time(NULL); -} - -/* parent will terminate if child dies. */ -static void -sig_child(int sig __unused) -{ - int status; - pid_t pid; - - pid = wait3(&status, WNOHANG, (struct rusage *)0); - if (pid > 0 && WEXITSTATUS(status)) - syslog(LOG_WARNING, "child %ld exit status 0x%x", - (long)pid, status); - exit_success("terminate connection due to child termination"); -} - -static void -notify_inactive() -{ - time_t t; - - /* only on parent side... */ - if (ppid) - return; - - /* parent side should check for timeout. */ - t = time(NULL); - if (dflag) { - syslog(LOG_DEBUG, "parent side %sactive, child side %sactive", - (FAITH_TIMEOUT < t - parent_lastactive) ? "in" : "", - (FAITH_TIMEOUT < t - child_lastactive) ? "in" : ""); - } - - if (FAITH_TIMEOUT < t - child_lastactive - && FAITH_TIMEOUT < t - parent_lastactive) { - /* both side timeouted */ - signal(SIGCHLD, SIG_DFL); - kill(cpid, SIGTERM); - wait(NULL); - exit_failure("connection timeout"); - /* NOTREACHED */ - } -} - -static void -notify_active() -{ - if (ppid) { - /* child side: notify parent of active traffic */ - time_t t; - t = time(NULL); - if (FAITH_TIMEOUT / 4 < t - child_lastactive) { - if (kill(ppid, SIGUSR1) < 0) { - exit_failure("terminate connection due to parent termination"); - /* NOTREACHED */ - } - child_lastactive = t; - } - } else { - /* parent side */ - parent_lastactive = time(NULL); - } -} - -static void -send_data(int s_rcv, int s_snd, const char *service __unused, int direction) -{ - int cc; - - if (oob_exists) { - cc = send(s_snd, atmark_buf, 1, MSG_OOB); - if (cc == -1) - goto retry_or_err; - oob_exists = 0; - if (s_rcv >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(s_rcv, &exceptfds); - } - - for (; tboff < tblen; tboff += cc) { - cc = write(s_snd, tcpbuf + tboff, tblen - tboff); - if (cc < 0) - goto retry_or_err; - } -#ifdef DEBUG - if (tblen) { - if (tblen >= sizeof(tcpbuf)) - tblen = sizeof(tcpbuf) - 1; - tcpbuf[tblen] = '\0'; - syslog(LOG_DEBUG, "from %s (%dbytes): %s", - direction == 1 ? "client" : "server", tblen, tcpbuf); - } -#endif /* DEBUG */ - tblen = 0; tboff = 0; - if (s_snd >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_CLR(s_snd, &writefds); - if (s_rcv >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(s_rcv, &readfds); - return; - retry_or_err: - if (errno != EAGAIN) - exit_failure("writing relay data failed: %s", strerror(errno)); - if (s_snd >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(s_snd, &writefds); -} - -static void -relay(int s_rcv, int s_snd, const char *service, int direction) -{ - int atmark, error, maxfd; - struct timeval tv; - fd_set oreadfds, owritefds, oexceptfds; - - FD_ZERO(&readfds); - FD_ZERO(&writefds); - FD_ZERO(&exceptfds); - fcntl(s_snd, F_SETFD, O_NONBLOCK); - oreadfds = readfds; owritefds = writefds; oexceptfds = exceptfds; - if (s_rcv >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(s_rcv, &readfds); - FD_SET(s_rcv, &exceptfds); - oob_exists = 0; - maxfd = (s_rcv > s_snd) ? s_rcv : s_snd; - - for (;;) { - tv.tv_sec = FAITH_TIMEOUT / 4; - tv.tv_usec = 0; - oreadfds = readfds; - owritefds = writefds; - oexceptfds = exceptfds; - error = select(maxfd + 1, &readfds, &writefds, &exceptfds, &tv); - if (error == -1) { - if (errno == EINTR) - continue; - exit_failure("select: %s", strerror(errno)); - } else if (error == 0) { - readfds = oreadfds; - writefds = owritefds; - exceptfds = oexceptfds; - notify_inactive(); - continue; - } - - /* activity notification */ - notify_active(); - - if (FD_ISSET(s_rcv, &exceptfds)) { - error = ioctl(s_rcv, SIOCATMARK, &atmark); - if (error != -1 && atmark == 1) { - int cc; - oob_read_retry: - cc = read(s_rcv, atmark_buf, 1); - if (cc == 1) { - if (s_rcv >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_CLR(s_rcv, &exceptfds); - if (s_snd >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(s_snd, &writefds); - oob_exists = 1; - } else if (cc == -1) { - if (errno == EINTR) - goto oob_read_retry; - exit_failure("reading oob data failed" - ": %s", - strerror(errno)); - } - } - } - if (FD_ISSET(s_rcv, &readfds)) { - relaydata_read_retry: - tblen = read(s_rcv, tcpbuf, sizeof(tcpbuf)); - tboff = 0; - - switch (tblen) { - case -1: - if (errno == EINTR) - goto relaydata_read_retry; - exit_failure("reading relay data failed: %s", - strerror(errno)); - /* NOTREACHED */ - case 0: - /* to close opposite-direction relay process */ - shutdown(s_snd, 0); - - close(s_rcv); - close(s_snd); - exit_success("terminating %s relay", service); - /* NOTREACHED */ - default: - if (s_rcv >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_CLR(s_rcv, &readfds); - if (s_snd >= FD_SETSIZE) - exit_failure("descriptor too big"); - FD_SET(s_snd, &writefds); - break; - } - } - if (FD_ISSET(s_snd, &writefds)) - send_data(s_rcv, s_snd, service, direction); - } -} - -void -tcp_relay(int s_src, int s_dst, const char *service) -{ - syslog(LOG_INFO, "starting %s relay", service); - - child_lastactive = parent_lastactive = time(NULL); - - cpid = fork(); - switch (cpid) { - case -1: - exit_failure("tcp_relay: can't fork grand child: %s", - strerror(errno)); - /* NOTREACHED */ - case 0: - /* child process: relay going traffic */ - ppid = getppid(); - /* this is child so reopen log */ - closelog(); - openlog(logname, LOG_PID | LOG_NOWAIT, LOG_DAEMON); - relay(s_src, s_dst, service, 1); - /* NOTREACHED */ - default: - /* parent process: relay coming traffic */ - ppid = (pid_t)0; - signal(SIGUSR1, sig_ctimeout); - signal(SIGCHLD, sig_child); - relay(s_dst, s_src, service, 0); - /* NOTREACHED */ - } -} diff --git a/usr.sbin/faithd/test/faithd.rb b/usr.sbin/faithd/test/faithd.rb deleted file mode 100644 index 682f540..0000000 --- a/usr.sbin/faithd/test/faithd.rb +++ /dev/null @@ -1,312 +0,0 @@ -# faithd, ruby version. requires v6-enabled ruby. -# -# highly experimental (not working right at all) and very limited -# functionality. -# -# $Id: faithd.rb,v 1.1.2.4 1999/05/10 17:06:30 itojun Exp $ -# $FreeBSD$ - -require "socket" -require "thread" - -# XXX should be derived from system headers -IPPROTO_IPV6 = 41 -IPV6_FAITH = 29 -DEBUG = true -DEBUG_LOOPBACK = true - -# TODO: OOB data handling -def tcpcopy(s1, s2, m) - STDERR.print "tcpcopy #{s1} #{s2}\n" if DEBUG - buf = "" - while TRUE - begin - buf = s1.sysread(100) - s2.syswrite(buf) - rescue EOFError - break - rescue IOError - break - end - end - STDERR.print "tcpcopy #{s1} #{s2} finished\n" if DEBUG - s1.shutdown(0) - s2.shutdown(1) -end - -def relay_ftp_passiveconn(s6, s4, dport6, dport4) - Thread.start do - d6 = TCPserver.open("::", dport6).accept - d4 = TCPsocket.open(s4.getpeer[3], dport4) - t = [] - t[0] = Thread.start do - tcpcopy(d6, d4) - end - t[1] = Thread.start do - tcpcopy(d4, d6) - end - for i in t - i.join - end - d4.close - d6.close - end -end - -def ftp_parse_2428(line) - if (line[0] != line[line.length - 1]) - return nil - end - t = line.split(line[0 .. 0]) # as string - if (t.size != 4 || t[1] !~ /^[12]$/ || t[3] !~ /^\d+$/) - return nil - end - return t[1 .. 3] -end - -def relay_ftp_command(s6, s4, state) - STDERR.print "relay_ftp_command start\n" if DEBUG - while TRUE - begin - STDERR.print "s6.gets\n" if DEBUG - line = s6.gets - STDERR.print "line is #{line}\n" if DEBUG - if line == nil - return nil - end - - # translate then copy - STDERR.print "line is #{line}\n" if DEBUG - if (line =~ /^EPSV\r\n/i) - STDERR.print "EPSV -> PASV\n" if DEBUG - line = "PASV\n" - state = "EPSV" - elsif (line =~ /^EPRT\s+(.+)\r\n/i) - t = ftp_parse_2428($1) - if t == nil - s6.puts "501 illegal parameter to EPRT\r\n" - next - end - - # some tricks should be here - s6.puts "501 illegal parameter to EPRT\r\n" - next - end - STDERR.print "fail: send #{line} as is\n" if DEBUG - s4.puts(line) - break - rescue EOFError - return nil - rescue IOError - return nil - end - end - STDERR.print "relay_ftp_command finish\n" if DEBUG - return state -end - -def relay_ftp_status(s4, s6, state) - STDERR.print "relay_ftp_status start\n" if DEBUG - while TRUE - begin - line = s4.gets - if line == nil - return nil - end - - # translate then copy - s6.puts(line) - - next if line =~ /^\d\d\d-/ - next if line !~ /^\d/ - - # special post-processing - case line - when /^221 / # result to QUIT - s4.shutdown(0) - s6.shutdown(1) - end - - break if (line =~ /^\d\d\d /) - rescue EOFError - return nil - rescue IOError - return nil - end - end - STDERR.print "relay_ftp_status finish\n" if DEBUG - return state -end - -def relay_ftp(sock, name) - STDERR.print "relay_ftp(#{sock}, #{name})\n" if DEBUG - while TRUE - STDERR.print "relay_ftp(#{sock}, #{name}) accepting\n" if DEBUG - s = sock.accept - STDERR.print "relay_ftp(#{sock}, #{name}) accepted #{s}\n" if DEBUG - Thread.start do - threads = [] - STDERR.print "accepted #{s} -> #{Thread.current}\n" if DEBUG - s6 = s - dest6 = s.addr[3] - if !DEBUG_LOOPBACK - t = s.getsockname.unpack("x8 x12 C4") - dest4 = "#{t[0]}.#{t[1]}.#{t[2]}.#{t[3]}" - port4 = s.addr[1] - else - dest4 = "127.0.0.1" - port4 = "ftp" - end - if DEBUG - STDERR.print "IPv6 dest: #{dest6} IPv4 dest: #{dest4}\n" if DEBUG - end - STDERR.print "connect to #{dest4} #{port4}\n" if DEBUG - s4 = TCPsocket.open(dest4, port4) - STDERR.print "connected to #{dest4} #{port4}, #{s4.addr[1]}\n" if DEBUG - state = 0 - while TRUE - # translate status line - state = relay_ftp_status(s4, s6, state) - break if state == nil - # translate command line - state = relay_ftp_command(s6, s4, state) - break if state == nil - end - STDERR.print "relay_ftp(#{sock}, #{name}) closing s4\n" if DEBUG - s4.close - STDERR.print "relay_ftp(#{sock}, #{name}) closing s6\n" if DEBUG - s6.close - STDERR.print "relay_ftp(#{sock}, #{name}) done\n" if DEBUG - end - end - STDERR.print "relay_ftp(#{sock}, #{name}) finished\n" if DEBUG -end - -def relay_tcp(sock, name) - STDERR.print "relay_tcp(#{sock}, #{name})\n" if DEBUG - while TRUE - STDERR.print "relay_tcp(#{sock}, #{name}) accepting\n" if DEBUG - s = sock.accept - STDERR.print "relay_tcp(#{sock}, #{name}) accepted #{s}\n" if DEBUG - Thread.start do - threads = [] - STDERR.print "accepted #{s} -> #{Thread.current}\n" if DEBUG - s6 = s - dest6 = s.addr[3] - if !DEBUG_LOOPBACK - t = s.getsockname.unpack("x8 x12 C4") - dest4 = "#{t[0]}.#{t[1]}.#{t[2]}.#{t[3]}" - port4 = s.addr[1] - else - dest4 = "127.0.0.1" - port4 = "telnet" - end - if DEBUG - STDERR.print "IPv6 dest: #{dest6} IPv4 dest: #{dest4}\n" if DEBUG - end - STDERR.print "connect to #{dest4} #{port4}\n" if DEBUG - s4 = TCPsocket.open(dest4, port4) - STDERR.print "connected to #{dest4} #{port4}, #{s4.addr[1]}\n" if DEBUG - [0, 1].each do |i| - threads[i] = Thread.start do - if (i == 0) - tcpcopy(s6, s4) - else - tcpcopy(s4, s6) - end - end - end - STDERR.print "relay_tcp(#{sock}, #{name}) wait\n" if DEBUG - for i in threads - STDERR.print "relay_tcp(#{sock}, #{name}) wait #{i}\n" if DEBUG - i.join - STDERR.print "relay_tcp(#{sock}, #{name}) wait #{i} done\n" if DEBUG - end - STDERR.print "relay_tcp(#{sock}, #{name}) closing s4\n" if DEBUG - s4.close - STDERR.print "relay_tcp(#{sock}, #{name}) closing s6\n" if DEBUG - s6.close - STDERR.print "relay_tcp(#{sock}, #{name}) done\n" if DEBUG - end - end - STDERR.print "relay_tcp(#{sock}, #{name}) finished\n" if DEBUG -end - -def usage() - STDERR.print "usage: #{$0} [-f] port...\n" -end - -#------------------------------------------------------------ - -$mode = "tcp" - -while ARGV[0] =~ /^-/ do - case ARGV[0] - when /^-f/ - $mode = "ftp" - else - usage() - exit 0 - end - ARGV.shift -end - -if ARGV.length == 0 - usage() - exit 1 -end - -ftpport = Socket.getservbyname("ftp") - -res = [] -for port in ARGV - t = Socket.getaddrinfo(nil, port, Socket::PF_INET6, Socket::SOCK_STREAM, - nil, Socket::AI_PASSIVE) - if (t.size <= 0) - STDERR.print "FATAL: getaddrinfo failed (port=#{port})\n" - exit 1 - end - res += t -end - -sockpool = [] -names = [] -listenthreads = [] - -res.each do |i| - s = TCPserver.new(i[3], i[1]) - n = Socket.getnameinfo(s.getsockname, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV).join(" port ") - if i[6] == IPPROTO_IPV6 - s.setsockopt(i[6], IPV6_FAITH, 1) - end - s.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, 1) - sockpool.push s - names.push n -end - -if DEBUG - (0 .. sockpool.size - 1).each do |i| - STDERR.print "listen[#{i}]: #{sockpool[i]} #{names[i]}\n" if DEBUG - end -end - -(0 .. sockpool.size - 1).each do |i| - listenthreads[i] = Thread.start do - if DEBUG - STDERR.print "listen[#{i}]: thread #{Thread.current}\n" if DEBUG - end - STDERR.print "listen[#{i}]: thread #{Thread.current}\n" if DEBUG - case $mode - when "tcp" - relay_tcp(sockpool[i], names[i]) - when "ftp" - relay_ftp(sockpool[i], names[i]) - end - end -end - -for i in listenthreads - i.join -end - -exit 0 diff --git a/usr.sbin/fdcontrol/Makefile b/usr.sbin/fdcontrol/Makefile deleted file mode 100644 index 5f1426b..0000000 --- a/usr.sbin/fdcontrol/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../fdread - -PROG= fdcontrol -SRCS= fdcontrol.c fdutil.c -CFLAGS+= -I${.CURDIR}/../fdread -MAN= fdcontrol.8 - -.if ${MACHINE} == "pc98" -CFLAGS+= -DPC98 -.endif - -.include diff --git a/usr.sbin/fdcontrol/fdcontrol.8 b/usr.sbin/fdcontrol/fdcontrol.8 deleted file mode 100644 index 8e2ab12..0000000 --- a/usr.sbin/fdcontrol/fdcontrol.8 +++ /dev/null @@ -1,334 +0,0 @@ -.\" Copyright (C) 1994, 2001 by Joerg Wunsch, Dresden -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY -.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT -.\" OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -.\" USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -.\" DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd December 25, 2001 -.Dt FDCONTROL 8 -.Os -.Sh NAME -.Nm fdcontrol -.Nd display and modify floppy disk parameters -.Sh SYNOPSIS -.Nm -.Op Fl F -.Op Fl d Ar dbg -.Op Fl f Ar fmt -.Op Fl s Ar fmtstr -.Op Fl v -.Ar device -.Sh DESCRIPTION -The -.Nm -utility allows the modification of the run-time behavior of the -.Xr fdc 4 -driver for the device specified by -.Ar device . -.Pp -Commands are implemented to query the current device density settings -as well as the underlying device hardware as registered with the -driver, to manipulate debugging levels, and to adjust the device -density settings. -All the operations that manipulate the kernel -settings are restricted to the superuser (by the device driver), while -all inquiry requests only require read access to -.Ar device . -.Pp -The -.Ar device -argument should always be given as a full path name, e.g.\& -.Pa /dev/fd0 . -.Ss Inquiry Commands -Running the -.Nm -utility without any of the optional flags will report the drive type -that is registered with the device driver. -In the shortest form, a single string describing the drive type will -be returned. -Possible values are: -.Dq Li 360K , -.Dq Li 1.2M , -.Dq Li 720K , -.Dq Li 1.44M , -.Dq Li 2.88M , -or -.Dq Li unknown . -This information is primarily intended to be easily parsable by -scripts. -.Pp -In order to add some descriptive text that makes the output better -human readable, the flag -.Fl v -can be added. -.Pp -Specifying flag -.Fl F -will report the device's density settings in a form that is suitable -as input to the -.Fl s Ar fmtstr -option (see below). -Again, together with -.Fl v , -some more text will be returned, including the total capacity of the -density settings in kilobytes. -.Ss Debug Control -If the -.Xr fdc 4 -driver was configured with the -.Dv FDC_DEBUG -option, by default, device debugging information is still disabled -since it could produce huge amounts of kernel messages. -It needs to -be turned on using -.Nm -together with -.Dq Fl d Li 1 , -usually immediately before starting an operation on the respective -device the debug information is wanted for, and later turned off again -using -.Dq Fl d Li 0 . -Note that debugging levels are a driver's global option that will -affect any drives and controllers using the -.Xr fdc 4 -driver, regardless which -.Ar device -was specified on the -.Nm -command line. -.Ss Density Control -The -.Xr fdc 4 -control utilities support two different options how to specify device -density settings. -The first form uses -.Fl f Ar fmt -to specify the format of the medium in kilobytes. -Depending on the -underlying drive type, the value is compared against a table of known -commonly used device density settings for that drive, and if a match -is found, those settings will be used. -Currently, the following -values for the respective drive types are acceptable: -.Bl -item -.It -2.88M and 1.44M drives: -.Bd -ragged -offset indent -compact -.TS -lB lB lB lB lB lB lB -r l l l l l l. -KB sectrac secsize ncyls speed heads flags -1721 21 2 (512) 82 500 2 MFM -1476 18 2 (512) 82 500 2 MFM -1440 18 2 (512) 80 500 2 MFM -1200 15 2 (512) 80 500 2 MFM -820 10 2 (512) 82 250 2 MFM -800 10 2 (512) 80 250 2 MFM -720 9 2 (512) 80 250 2 MFM -.TE -.Ed -.It -1.2M drives: -.Bd -ragged -offset indent -compact -.TS -lB lB lB lB lB lB lB -r l l l l l l. -KB sectrac secsize ncyls speed heads flags -1200 15 2 (512) 80 500 2 MFM -1232 8 3 (1024) 77 500 2 MFM -1476 18 2 (512) 82 500 2 MFM -1440 18 2 (512) 80 500 2 MFM -1200 15 2 (512) 80 500 2 MFM -820 10 2 (512) 82 300 2 MFM -800 10 2 (512) 80 300 2 MFM -720 9 2 (512) 80 300 2 MFM -360 9 2 (512) 40 300 2 MFM,2STEP -640 8 2 (512) 80 300 2 MFM -.TE -.Ed -.It -720K drives: -.Bd -ragged -offset indent -compact -.TS -lB lB lB lB lB lB lB -r l l l l l l. -KB sectrac secsize ncyls speed heads flags -720 9 2 (512) 80 250 2 MFM -.TE -.Ed -.It -360K drives: -.Bd -ragged -offset indent -compact -.TS -lB lB lB lB lB lB lB -r l l l l l l. -KB sectrac secsize ncyls speed heads flags -360 9 2 (512) 40 250 2 MFM -.TE -.Ed -.El -.Pp -The second form to specify a device density uses -.Fl s Ar fmtstr -to explicitly specify each parameter in detail. -The argument -.Ar fmtstr -is a comma-separated list of values of the form: -.Pp -.Sm off -.Ar sectrac , secsize , datalen , gap , ncyls , speed , -.Ar heads , f_gap , f_inter , offs2 , flags -.Sm on -.Pp -The meaning of the parameters is: -.Bl -tag -width ".Ar secsize" -.It Ar sectrac -The number of sectors per track. -.It Ar secsize -The sector size code, 0 = 128 bytes (or less), 1 = 256 bytes, 2 = 512 -bytes, 3 = 1024 bytes. -.It Ar datalen -The actual sector size if the size code is 0, or the (ignored) value -0xFF for larger size codes. -.It Ar gap -The length of the gap 3 parameter for read/write operations. -.It Ar ncyls -The number of cylinders. -.It Ar speed -The transfer speed in kilobytes per second. -Can be 250, 300, 500, or -1000, but each drive type only supports a subset of these values. -.It Ar heads -The number of heads. -.It Ar f_gap -The length of the gap 3 when formatting media. -.It Ar f_inter -The sector interleave to be applied when formatting. -0 means no -interleave, 1 means 1:1 etc. -.It Ar offs2 -The offset of the sector numbers on side 2 (i.e., head number 1). -Normally, sector numbering on both sides starts with 1. -.It Ar flags -A list from one of the following flag values: -.Pp -.Bl -tag -width ".Cm +perpend" -compact -.It Cm +mfm -Use MFM encoding. -.It Cm -mfm -Use FM (single-density) encoding. -.It Cm +2step -Use 2 steps per each cylinder (for accessing 40-cylinder media in -80-cylinder drives). -.It Cm -2step -Do not use 2 steps per cylinder, i.e., access each physical cylinder -of the drive. -.It Cm +perpend -Use perpendicular recording (for 2.88 MB media, currently not -supported). -.It Cm -perpend -Use longitudinal recording. -.El -.El -.Pp -For any missing parameter, the current value will be used, so only -actual changes need to be specified. -Thus to turn off a flag bit -(like -.Cm +mfm -which is the default for all drive types), the form with a leading -minus sign must explicitly be used. -.Sh EXAMPLES -A simple inquiry about the drive type: -.Bd -literal -offset indent -$ fdcontrol /dev/fd0 -1.44M -.Ed -.Pp -Same as above, but with verbose output. -Note that the result is about -the -.Em "drive type" , -as opposed to a -.Em "device density" , -so it is independent from the actual subdevice being used for -.Ar device . -.Bd -literal -offset indent -$ fdcontrol -v /dev/fd0 -/dev/fd0: 1.44M drive (3.5" high-density) -.Ed -.Pp -Inquiry about the density settings: -.Bd -literal -offset indent -$ fdcontrol -F /dev/fd0 -18,512,0xff,0x1b,80,500,2,0x6c,1,0,+mfm -.Ed -.Pp -The verbose flag makes this human readable: -.Bd -literal -offset indent -/dev/fd0: 1440 KB media type - Format: 18,512,0xff,0x1b,80,500,2,0x6c,1,0,+mfm - Sector size: 512 - Sectors/track: 18 - Heads/cylinder: 2 - Cylinders/disk: 80 - Transfer rate: 500 kbps - Sector gap: 27 - Format gap: 108 - Interleave: 1 - Side offset: 0 - Flags -.Ed -.Pp -As indicated, trailing commas in the parameter list may be omitted. -.Pp -In order to access archaic 160 KB single-density (FM encoded) 5.25 -media in a modern 1.2M drive, something like the following definition -would be needed. -(Note that not all controller hardware is actually -capable of handling FM encoding at all.) -.Bd -literal -# fdcontrol -s 16,128,0x80,0x2,40,300,,0x10,,,-mfm,+2step /dev/fd1.1 -.Ed -.Pp -It is still possible to hook up 8" drives to most modern floppy -controllers, given the right cable magic. -(On PC hardware, tell the BIOS that it is a 5.25" drive.) -The classical 128/26/2/77 format can be read with this entry -.Bd -literal -offset indent -fdcontrol -s 26,128,0x80,0x2,77,500,2,0x10,,,-mfm /dev/fd0 -.Ed -.Sh SEE ALSO -.Xr fdc 4 -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 2.0 , -and was vastly overhauled in -.Fx 5.0 . -.Sh AUTHORS -The program and this man page was contributed by -.An J\(:org Wunsch , -Dresden. diff --git a/usr.sbin/fdcontrol/fdcontrol.c b/usr.sbin/fdcontrol/fdcontrol.c deleted file mode 100644 index 91877e6..0000000 --- a/usr.sbin/fdcontrol/fdcontrol.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Copyright (C) 1994, 2001 by Joerg Wunsch, Dresden - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE - * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "fdutil.h" - - -static int format, verbose, show = 1, showfmt; -static char *fmtstring; - -static void showdev(enum fd_drivetype, const char *); -static void usage(void); - -static void -usage(void) -{ - errx(EX_USAGE, - "usage: fdcontrol [-F] [-d dbg] [-f fmt] [-s fmtstr] [-v] device"); -} - -void -showdev(enum fd_drivetype type, const char *fname) -{ - const char *name, *descr; - - getname(type, &name, &descr); - if (verbose) - printf("%s: %s drive (%s)\n", fname, name, descr); - else - printf("%s\n", name); -} - -int -main(int argc, char **argv) -{ - enum fd_drivetype type; - struct fd_type ft, newft, *fdtp; - const char *name, *descr; - int fd, i, autofmt; - - autofmt = 0; - while((i = getopt(argc, argv, "aFf:s:v")) != -1) - switch(i) { - - case 'a': - autofmt = 1; - case 'F': - showfmt = 1; - show = 0; - break; - - case 'f': - if (!strcmp(optarg, "auto")) { - format = -1; - } else if (getnum(optarg, &format)) { - fprintf(stderr, - "Bad argument %s to -f option; must be numeric\n", - optarg); - usage(); - } - show = 0; - break; - - case 's': - fmtstring = optarg; - show = 0; - break; - - case 'v': - verbose++; - break; - - default: - usage(); - } - - argc -= optind; - argv += optind; - - if(argc != 1) - usage(); - - if((fd = open(argv[0], O_RDONLY | O_NONBLOCK)) < 0) - err(EX_UNAVAILABLE, "open(%s)", argv[0]); - - if (ioctl(fd, FD_GDTYPE, &type) == -1) - err(EX_OSERR, "ioctl(FD_GDTYPE)"); - if (ioctl(fd, FD_GTYPE, &ft) == -1) - err(EX_OSERR, "ioctl(FD_GTYPE)"); - - if (show) { - showdev(type, argv[0]); - return (0); - } - - if (autofmt) { - memset(&newft, 0, sizeof newft); - ft = newft; - } - - if (format) { - getname(type, &name, &descr); - fdtp = get_fmt(format, type); - if (fdtp == 0) - errx(EX_USAGE, - "unknown format %d KB for drive type %s", - format, name); - ft = *fdtp; - } - - if (fmtstring) { - parse_fmt(fmtstring, type, ft, &newft); - ft = newft; - } - - if (showfmt) { - if (verbose) { - const char *s; - - printf("%s: %d KB media type\n", argv[0], - (128 << ft.secsize) * ft.size / 1024); - printf("\tFormat:\t\t"); - print_fmt(ft); - if (ft.datalen != 0xff && - ft.datalen != (128 << ft.secsize)) - printf("\tData length:\t%d\n", ft.datalen); - printf("\tSector size:\t%d\n", 128 << ft.secsize); - printf("\tSectors/track:\t%d\n", ft.sectrac); - printf("\tHeads/cylinder:\t%d\n", ft.heads); - printf("\tCylinders/disk:\t%d\n", ft.tracks); - switch (ft.trans) { - case 0: printf("\tTransfer rate:\t500 kbps\n"); break; - case 1: printf("\tTransfer rate:\t300 kbps\n"); break; - case 2: printf("\tTransfer rate:\t250 kbps\n"); break; - case 3: printf("\tTransfer rate:\t1 Mbps\n"); break; - } - printf("\tSector gap:\t%d\n", ft.gap); - printf("\tFormat gap:\t%d\n", ft.f_gap); - printf("\tInterleave:\t%d\n", ft.f_inter); - printf("\tSide offset:\t%d\n", ft.offset_side2); - printf("\tFlags\t\t<"); - s = ""; - if (ft.flags & FL_MFM) { - printf("%sMFM", s); - s = ","; - } - if (ft.flags & FL_2STEP) { - printf("%s2STEP", s); - s = ","; - } - if (ft.flags & FL_PERPND) { - printf("%sPERPENDICULAR", s); - s = ","; - } - if (ft.flags & FL_AUTO) { - printf("%sAUTO", s); - s = ","; - } - printf(">\n"); - } else { - print_fmt(ft); - } - return (0); - } - - if (format || fmtstring) { - if (ioctl(fd, FD_STYPE, &ft) == -1) - err(EX_OSERR, "ioctl(FD_STYPE)"); - return (0); - } - - return 0; -} diff --git a/usr.sbin/fdformat/Makefile b/usr.sbin/fdformat/Makefile deleted file mode 100644 index 59cd124..0000000 --- a/usr.sbin/fdformat/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../fdread - -PROG= fdformat -SRCS= fdformat.c fdutil.c - -CFLAGS+= -I${.CURDIR}/../fdread - -.if ${MACHINE} == "pc98" -CFLAGS+= -DPC98 -.endif - -.include diff --git a/usr.sbin/fdformat/fdformat.1 b/usr.sbin/fdformat/fdformat.1 deleted file mode 100644 index 596b09b..0000000 --- a/usr.sbin/fdformat/fdformat.1 +++ /dev/null @@ -1,180 +0,0 @@ -.\" Copyright (C) 1993, 1994, 1995, 2001 by Joerg Wunsch, Dresden -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS -.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, -.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd December 25, 2001 -.Dt FDFORMAT 1 -.Os -.Sh NAME -.Nm fdformat -.Nd format floppy disks -.Sh SYNOPSIS -.Nm -.Op Fl F Ar fill -.Op Fl f Ar fmt -.Op Fl s Ar fmtstr -.Op Fl nqvy -.Ar device -.Sh DESCRIPTION -The -.Nm -utility formats a floppy disk at -.Ar device , -where -.Ar device -may either be given as a full path -name of a device node for a floppy disk drive -(e.g.\& -.Pa /dev/fd0 ) , -or using an abbreviated name that will be looked up -under -.Pa /dev -(e.g.\& -.Dq Li fd0 ) . -.Pp -The options are as follows: -.Bl -tag -width ".Fl s Ar fmtstr" -.It Fl F Ar fill -Use -.Ar fill -as the fill byte for newly formatted sectors. -The -.Ar fill -argument -must be a number in the range 0 through 255 using common C -language notation. -The default value is -.Dq Li 0xf6 . -.It Fl f Ar fmt -Specify the density settings for a -.Ar fmt -kilobyte format, as described in -.Xr fdcontrol 8 . -.It Fl s Ar fmtstr -Specify the density settings using explicit parameters, as -described in -.Xr fdcontrol 8 . -.It Fl n -Do not verify floppy after formatting. -.It Fl q -Suppress any normal output from the command, and do not ask the -user for a confirmation whether to format the floppy disk at -.Ar device . -.It Fl v -Do not format, verify only. -.It Fl y -Do not ask for confirmation whether to format the floppy disk but -still report formatting status. -.El -.Pp -For non-autoselecting subdevices, neither -.Fl f Ar fmt -nor -.Fl s Ar fmtstr -may be specified, since the preconfigured media density settings -from the kernel driver will always be used. -However, if -.Ar device -is a device with automatic media density selection (see -.Xr fdc 4 ) , -both methods can be used to override the density settings for the -newly formatted medium (without permanently changing the density -settings of -.Ar device ) . -.Pp -If the -.Fl q -flag has not been specified, the user is asked for a confirmation -of the intended formatting process. -In order to continue, an answer -of -.Ql y -must be given. -.Pp -Note that -.Nm -does only perform low-level formatting. -In order to create -a file system on the medium, see the commands -.Xr newfs 8 -for a -.Tn UFS -file system, or -.Xr newfs_msdos 8 -for an -.Tn MS-DOS -(FAT) -file system. -.Sh EXIT STATUS -An exit status of 0 is returned upon successful operation. -Exit status -1 is returned on any errors during floppy formatting, and an exit status -of 2 reflects invalid arguments given to the program (along with an -appropriate information written to diagnostic output). -.Sh DIAGNOSTICS -Unless -.Fl q -has been specified, a single letter is printed to standard output -to inform the user about the progress of work. -First, an -.Ql F -is printed when the track is being formatted, then a -.Ql V -while it is being verified, and if an error has been detected, it -will finally change to -.Ql E . -Detailed status information (cylinder, head and sector number, and the -exact cause of the error) will be printed for up to 10 errors after the -entire formatting process has completed. -.Sh SEE ALSO -.Xr fdc 4 , -.Xr fdcontrol 8 , -.Xr newfs 8 , -.Xr newfs_msdos 8 -.Sh HISTORY -The -.Nm -utility -has been developed for -.Bx 386 0.1 -and upgraded to the new -.Xr fdc 4 -floppy disk driver. -It later became part of the -.Fx 1.1 -system. -Starting with -.Fx 5.0 , -it uses the unified density specifications as described in -.Xr fdcontrol 8 . -.Sh AUTHORS -.An -nosplit -The program has been contributed by -.An J\(:org Wunsch , -Dresden, with changes by -.An Serge Vakulenko -and -.An Andrey A. Chernov , -Moscow. diff --git a/usr.sbin/fdformat/fdformat.c b/usr.sbin/fdformat/fdformat.c deleted file mode 100644 index 807ad8d..0000000 --- a/usr.sbin/fdformat/fdformat.c +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Copyright (C) 1992-1994,2001 by Joerg Wunsch, Dresden - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fdutil.h" - -static void -format_track(int fd, int cyl, int secs, int head, int rate, - int gaplen, int secsize, int fill, int interleave, - int offset) -{ - struct fd_formb f; - int i, j, il[FD_MAX_NSEC + 1]; - - memset(il, 0, sizeof il); - for(j = 0, i = 1 + offset; i <= secs + offset; i++) { - while(il[(j % secs) + 1]) - j++; - il[(j % secs) + 1] = i; - j += interleave; - } - - f.format_version = FD_FORMAT_VERSION; - f.head = head; - f.cyl = cyl; - f.transfer_rate = rate; - - f.fd_formb_secshift = secsize; - f.fd_formb_nsecs = secs; - f.fd_formb_gaplen = gaplen; - f.fd_formb_fillbyte = fill; - for(i = 0; i < secs; i++) { - f.fd_formb_cylno(i) = cyl; - f.fd_formb_headno(i) = head; - f.fd_formb_secno(i) = il[i+1]; - f.fd_formb_secsize(i) = secsize; - } - if(ioctl(fd, FD_FORM, (caddr_t)&f) < 0) - err(EX_OSERR, "ioctl(FD_FORM)"); -} - -static int -verify_track(int fd, int track, int tracksize) -{ - static char *buf; - static int bufsz; - int fdopts = -1, ofdopts, rv = 0; - - if (ioctl(fd, FD_GOPTS, &fdopts) < 0) - warn("warning: ioctl(FD_GOPTS)"); - else { - ofdopts = fdopts; - fdopts |= FDOPT_NORETRY; - (void)ioctl(fd, FD_SOPTS, &fdopts); - } - - if (bufsz < tracksize) - buf = realloc(buf, bufsz = tracksize); - if (buf == 0) - errx(EX_UNAVAILABLE, "out of memory"); - if (lseek (fd, (long) track * tracksize, 0) < 0) - rv = -1; - /* try twice reading it, without using the normal retrier */ - else if (read (fd, buf, tracksize) != tracksize - && read (fd, buf, tracksize) != tracksize) - rv = -1; - if (fdopts != -1) - (void)ioctl(fd, FD_SOPTS, &ofdopts); - return (rv); -} - -static void -usage (void) -{ - errx(EX_USAGE, - "usage: fdformat [-F fill] [-f fmt] [-s fmtstr] [-nqvy] device"); -} - -static int -yes (void) -{ - char reply[256], *p; - - reply[sizeof(reply) - 1] = 0; - for (;;) { - fflush(stdout); - if (!fgets (reply, sizeof(reply) - 1, stdin)) - return (0); - for (p=reply; *p==' ' || *p=='\t'; ++p) - continue; - if (*p=='y' || *p=='Y') - return (1); - if (*p=='n' || *p=='N' || *p=='\n' || *p=='\r') - return (0); - printf("Answer `yes' or `no': "); - } -} - -int -main(int argc, char **argv) -{ - enum fd_drivetype type; - struct fd_type fdt, newft, *fdtp; - struct stat sb; -#define MAXPRINTERRS 10 - struct fdc_status fdcs[MAXPRINTERRS]; - int format, fill, quiet, verify, verify_only, confirm; - int fd, c, i, track, error, tracks_per_dot, bytes_per_track, errs; - int flags; - char *fmtstring, *device; - const char *name, *descr; - - format = quiet = verify_only = confirm = 0; - verify = 1; - fill = 0xf6; - fmtstring = 0; - - while((c = getopt(argc, argv, "F:f:nqs:vy")) != -1) - switch(c) { - case 'F': /* fill byte */ - if (getnum(optarg, &fill)) { - fprintf(stderr, - "Bad argument %s to -F option; must be numeric\n", - optarg); - usage(); - } - break; - - case 'f': /* format in kilobytes */ - if (getnum(optarg, &format)) { - fprintf(stderr, - "Bad argument %s to -f option; must be numeric\n", - optarg); - usage(); - } - break; - - case 'n': /* don't verify */ - verify = 0; - break; - - case 'q': /* quiet */ - quiet = 1; - break; - - case 's': /* format string with detailed options */ - fmtstring = optarg; - break; - - case 'v': /* verify only */ - verify = 1; - verify_only = 1; - break; - - case 'y': /* confirm */ - confirm = 1; - break; - - default: - usage(); - } - - if(optind != argc - 1) - usage(); - - if (stat(argv[optind], &sb) == -1 && errno == ENOENT) { - /* try prepending _PATH_DEV */ - device = malloc(strlen(argv[optind]) + sizeof(_PATH_DEV) + 1); - if (device == 0) - errx(EX_UNAVAILABLE, "out of memory"); - strcpy(device, _PATH_DEV); - strcat(device, argv[optind]); - if (stat(device, &sb) == -1) { - free(device); - device = argv[optind]; /* let it fail below */ - } - } else { - device = argv[optind]; - } - - if ((fd = open(device, O_RDWR | O_NONBLOCK)) < 0) - err(EX_OSERR, "open(%s)", device); - - /* - * Device initialization. - * - * First, get the device type descriptor. This tells us about - * the media geometry data we need to format a medium. It also - * lets us know quickly whether the device name actually points - * to a floppy disk drive. - * - * Then, obtain any drive options. We're mainly interested to - * see whether we're currently working on a device with media - * density autoselection (FDOPT_AUTOSEL). Then, we add the - * device option to tell the kernel not to log media errors, - * since we can handle them ourselves. If the device does - * media density autoselection, we then need to set the device - * type appropriately, since by opening with O_NONBLOCK we - * told the driver to bypass media autoselection (otherwise we - * wouldn't stand a chance to format an unformatted or damaged - * medium). We do not attempt to set the media type on any - * other devices since this is a privileged operation. For the - * same reason, specifying -f and -s options is only possible - * for autoselecting devices. - * - * Finally, we are ready to turn off O_NONBLOCK, and start to - * actually format something. - */ - if(ioctl(fd, FD_GTYPE, &fdt) < 0) - errx(EX_OSERR, "not a floppy disk: %s", device); - if (ioctl(fd, FD_GDTYPE, &type) == -1) - err(EX_OSERR, "ioctl(FD_GDTYPE)"); - if (format) { - getname(type, &name, &descr); - fdtp = get_fmt(format, type); - if (fdtp == 0) - errx(EX_USAGE, - "unknown format %d KB for drive type %s", - format, name); - fdt = *fdtp; - } - if (fmtstring) { - parse_fmt(fmtstring, type, fdt, &newft); - fdt = newft; - } - if (ioctl(fd, FD_STYPE, &fdt) < 0) - err(EX_OSERR, "ioctl(FD_STYPE)"); - if ((flags = fcntl(fd, F_GETFL, 0)) == -1) - err(EX_OSERR, "fcntl(F_GETFL)"); - flags &= ~O_NONBLOCK; - if (fcntl(fd, F_SETFL, flags) == -1) - err(EX_OSERR, "fcntl(F_SETFL)"); - - bytes_per_track = fdt.sectrac * (128 << fdt.secsize); - - /* XXX 20/40 = 0.5 */ - tracks_per_dot = (fdt.tracks * fdt.heads + 20) / 40; - - if (verify_only) { - if(!quiet) - printf("Verify %dK floppy `%s'.\n", - fdt.tracks * fdt.heads * bytes_per_track / 1024, - device); - } - else if(!quiet && !confirm) { - printf("Format %dK floppy `%s'? (y/n): ", - fdt.tracks * fdt.heads * bytes_per_track / 1024, - device); - if(!yes()) { - printf("Not confirmed.\n"); - return (EX_UNAVAILABLE); - } - } - - /* - * Formatting. - */ - if(!quiet) { - printf("Processing "); - for (i = 0; i < (fdt.tracks * fdt.heads) / tracks_per_dot; i++) - putchar('-'); - printf("\rProcessing "); - fflush(stdout); - } - - error = errs = 0; - - for (track = 0; track < fdt.tracks * fdt.heads; track++) { - if (!verify_only) { - format_track(fd, track / fdt.heads, fdt.sectrac, - track % fdt.heads, fdt.trans, fdt.f_gap, - fdt.secsize, fill, fdt.f_inter, - track % fdt.heads? fdt.offset_side2: 0); - if(!quiet && !((track + 1) % tracks_per_dot)) { - putchar('F'); - fflush(stdout); - } - } - if (verify) { - if (verify_track(fd, track, bytes_per_track) < 0) { - error = 1; - if (errs < MAXPRINTERRS && errno == EIO) { - if (ioctl(fd, FD_GSTAT, fdcs + errs) == - -1) - errx(EX_IOERR, - "floppy IO error, but no FDC status"); - errs++; - } - } - if(!quiet && !((track + 1) % tracks_per_dot)) { - if (!verify_only) - putchar('\b'); - if (error) { - putchar('E'); - error = 0; - } - else - putchar('V'); - fflush(stdout); - } - } - } - if(!quiet) - printf(" done.\n"); - - if (!quiet && errs) { - fflush(stdout); - fprintf(stderr, "Errors encountered:\nCyl Head Sect Error\n"); - for (i = 0; i < errs && i < MAXPRINTERRS; i++) { - fprintf(stderr, " %2d %2d %2d ", - fdcs[i].status[3], fdcs[i].status[4], - fdcs[i].status[5]); - printstatus(fdcs + i, 1); - putc('\n', stderr); - } - if (errs >= MAXPRINTERRS) - fprintf(stderr, "(Further errors not printed.)\n"); - } - - return errs != 0; -} diff --git a/usr.sbin/fdread/Makefile b/usr.sbin/fdread/Makefile deleted file mode 100644 index e99c620..0000000 --- a/usr.sbin/fdread/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -# $FreeBSD$ - -PROG= fdread -SRCS= fdread.c fdutil.c - -.if ${MACHINE} == "pc98" -CFLAGS+= -DPC98 -.endif - -.include diff --git a/usr.sbin/fdread/fdread.1 b/usr.sbin/fdread/fdread.1 deleted file mode 100644 index d29a4a4..0000000 --- a/usr.sbin/fdread/fdread.1 +++ /dev/null @@ -1,233 +0,0 @@ -.\" -.\" Copyright (c) 2001 Joerg Wunsch -.\" -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.\" -.Dd May 14, 2001 -.Dt FDREAD 1 -.Os -.Sh NAME -.Nm fdread -.Nd read floppy disks -.Sh SYNOPSIS -.Nm -.Op Fl qr -.Op Fl d Ar device -.Op Fl f Ar fillbyte -.Op Fl o Ar file -.Nm -.Op Fl d Ar device -.Fl I Ar numsects -.Op Fl t Ar trackno -.Sh DESCRIPTION -The -.Nm -utility reads floppy disks. -Effective read blocking based on the track -size is performed, and floppy-specific error recovery of otherwise -bad blocks can be enabled. -.Pp -The -.Nm -utility -will always read an entire floppy medium, and write its contents to -the respective output file. -Unlike other tools like -.Xr dd 1 , -.Nm -automatically uses a read block size that is more efficient than -reading single blocks (usually one track of data at a time), but -falls back to reading single floppy sectors in case of an input/output -error occurred, in order to obtain as much valid data as possible. -While -.Nm -is working, kernel error reporting for floppy errors is turned off, so -the console and/or syslog are not flooded with kernel error messages. -.Pp -The -.Nm -utility accepts the following options: -.Bl -tag -width indent -.It Fl q -Turn on quiet mode. -By default, the medium parameters of the device -are being written to standard error output, progress will be indicated -by the approximate number of kilobytes read so far, and errors will be -printed out in detail, including the information about the location of -recovered data in the output. -In quiet mode, none of these messages -will be generated. -.It Fl r -Enable error recovery. -By default, -.Nm -stops after the first unrecovered read error, much like -.Xr dd 1 -does. -In recovery mode, however, one of two recovery actions will be -taken: -.Bl -bullet -.It -If the error was a CRC error in the data field, the -kernel is told to ignore the error, and data are transferred to the -output file anyway. -.Bf -emphasis -Note that this will cause the erroneous data -to be included in the output file! -.Ef -Still, this is the best recovery action that can be taken at all. -.It -All other errors are really fatal (usually, the FDC did not find the -sector ID fields), thus a dummy block with fill -bytes will be included in the output file. -.El -.Pp -Unless operating in quiet mode, the action taken and the location of -the error in the output file will be displayed. -.It Fl d Ar device -Specify the input floppy device, defaulting to -.Pa /dev/fd0 . -The parameter -.Ar device -must be a valid floppy disk device. -.It Fl f Ar fillbyte -Value of the fill byte used for dummy blocks in the output file in -recovery mode. -Defaults to -.Ql 0xf0 . -(Mnemonic: -.Dq foo . ) -The value can be specified using the usual C language notation of -the number base. -.It Fl o Ar file -Specify the output file to be -.Ar file . -By default, the data will be written to standard output. -.It Fl I Ar numsects -Read -.Ar numsects -sector ID fields, and write out their contents to standard output. -Each sector ID field contains recorded values for the cylinder number -.Pq Ql C , -the head number -.Pq Ql H , -the record number (sector number starting with 1) -.Pq Ql R , -and the -.Em sector shift value -(0 = 128 bytes, 1 = 256 bytes, 2 = 512 bytes, 3 = 1024 bytes) -.Pq Ql N . -The -.Fl I -option is mutually exclusive with all other options except -.Fl d Ar device -and -.Fl t Ar trackno . -.It Fl t Ar trackno -Specify the track number (cylinder number * number of heads + head -number) to read the sector ID fields from; only allowed together with -the -.Fl I Ar numsects -option. -.El -.Sh FILES -.Bl -tag -width /dev/fd0 -.It Pa /dev/fd0 -Default device to read from. -.El -.Sh EXIT STATUS -The -.Nm -utility sets the exit value according to -.Xr sysexits 3 . -In recovery mode, the exit value will be set to -.Dv EX_IOERR -if any error occurred during processing (even in quiet mode). -.Sh DIAGNOSTICS -Unless running in quiet mode, upon encountering an error, the status -of the floppy disc controller (FDC) will be printed out, both in -hexadecimal form, followed by a textual description that translates -those values into a human-readable form for the most common error -cases that can happen in a PC environment. -.Pp -The FDC error status includes the three FDC status registers -.Ql ST0 , -.Ql ST1 , -and -.Ql ST2 , -as well as the location of the error (physical cylinder, head, and sector -number, plus the -.Dq sector shift value , -respectively). -See the manual for the NE765 or compatible for details -about the status register contents. -.Pp -The FDC's status is then examined to determine whether the error is -deemed to be recoverable. -If error recovery was requested, the -location of the bad block in the output file is indicated by its -(hexadecimal) bounds. -Also, a summary line indicating the total number -of transfer errors will be printed before exiting. -.Sh SEE ALSO -.Xr dd 1 , -.Xr fdwrite 1 , -.Xr sysexits 3 , -.Xr fdc 4 , -.Xr fdcontrol 8 -.Sh HISTORY -The -.Nm -utility was written mainly to provide a means of recovering at least some of -the data on bad media, and to obviate the need to invoke -.Xr dd 1 -with too many hard to memorize options that might be useful to handle -a floppy. -.Pp -The command appeared in -.Fx 5.0 . -.Sh AUTHORS -Program and man page by -.An J\(:org Wunsch . -.Sh BUGS -Concurrent traffic on the second floppy drive located at the same FDC -will make error recovery attempts pointless, since the FDC status -obtained after a read error occurred cannot be guaranteed to actually -belong to the erroneous transfer. -Thus using option -.Fl r -is only reliable if -.Ar device -is the only active drive on that controller. -.Pp -No attempt beyond the floppy error retry mechanism of -.Xr fdc 4 -is made in order to see whether bad sectors could still be read -without errors by trying multiple times. -.Pp -Bits that are (no longer) available on the floppy medium cannot be -guessed by -.Nm . diff --git a/usr.sbin/fdread/fdread.c b/usr.sbin/fdread/fdread.c deleted file mode 100644 index 1aae665..0000000 --- a/usr.sbin/fdread/fdread.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * Copyright (c) 2001 Joerg Wunsch - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fdutil.h" - -int quiet, recover; -unsigned char fillbyte = 0xf0; /* "foo" */ - -int doread(int fd, FILE *of, const char *_devname); -int doreadid(int fd, unsigned int numids, unsigned int trackno); -void usage(void); - -void -usage(void) -{ - - errx(EX_USAGE, - "usage: fdread [-qr] [-d device] [-f fillbyte]\n" - " fdread [-d device] -I numids [-t trackno]"); -} - - -int -main(int argc, char **argv) -{ - int c, errs = 0; - unsigned int numids = 0, trackno = 0; - const char *fname = 0, *_devname = "/dev/fd0"; - char *cp; - FILE *of = stdout; - int fd; - unsigned long ul; - - while ((c = getopt(argc, argv, "d:f:I:o:qrt:")) != -1) - switch (c) { - case 'd': - _devname = optarg; - break; - - case 'f': - ul = strtoul(optarg, &cp, 0); - if (*cp != '\0') { - fprintf(stderr, - "Bad argument %s to -f option; must be numeric\n", - optarg); - usage(); - } - if (ul > 0xff) - warnx( - "Warning: fillbyte %#lx too large, truncating\n", - ul); - fillbyte = ul & 0xff; - break; - - case 'I': - ul = strtoul(optarg, &cp, 0); - if (*cp != '\0') { - fprintf(stderr, - "Bad argument %s to -I option; must be numeric\n", - optarg); - usage(); - } - numids = ul; - break; - - case 'o': - fname = optarg; - break; - - case 'q': - quiet++; - break; - - case 'r': - recover++; - break; - - case 't': - ul = strtoul(optarg, &cp, 0); - if (*cp != '\0') { - fprintf(stderr, - "Bad argument %s to -t option; must be numeric\n", - optarg); - usage(); - } - trackno = ul; - break; - - default: - errs++; - } - argc -= optind; - argv += optind; - - if (argc != 0 || errs) - usage(); - /* check for mutually exclusive options */ - if (numids) { - if (fname || quiet || recover) - usage(); - } else { - if (trackno) - usage(); - } - - if (fname) { - if ((of = fopen(fname, "w")) == NULL) - err(EX_OSERR, "cannot create output file %s", fname); - } - - if ((fd = open(_devname, O_RDWR)) == -1) - err(EX_OSERR, "cannot open device %s", _devname); - - return (numids? doreadid(fd, numids, trackno): doread(fd, of, _devname)); -} - -int -doread(int fd, FILE *of, const char *_devname) -{ - char *trackbuf; - int rv, fdopts, recoverable, nerrs = 0; - unsigned int nbytes, tracksize, mediasize, secsize, n; - struct fdc_status fdcs; - struct fd_type fdt; - - if (ioctl(fd, FD_GTYPE, &fdt) == -1) - err(EX_OSERR, "ioctl(FD_GTYPE) failed -- not a floppy?"); - - secsize = 128 << fdt.secsize; - tracksize = fdt.sectrac * secsize; - mediasize = tracksize * fdt.tracks * fdt.heads; - if ((trackbuf = malloc(tracksize)) == 0) - errx(EX_TEMPFAIL, "out of memory"); - - if (!quiet) - fprintf(stderr, "Reading %d * %d * %d * %d medium at %s\n", - fdt.tracks, fdt.heads, fdt.sectrac, secsize, _devname); - - for (nbytes = 0; nbytes < mediasize;) { - if (lseek(fd, nbytes, SEEK_SET) != nbytes) - err(EX_OSERR, "cannot lseek()"); - rv = read(fd, trackbuf, tracksize); - if (rv == 0) { - /* EOF? */ - warnx("premature EOF after %u bytes", nbytes); - return (EX_OK); - } - if ((unsigned)rv == tracksize) { - nbytes += rv; - if (!quiet) - fprintf(stderr, "%5d KB\r", nbytes / 1024); - fwrite(trackbuf, sizeof(unsigned char), rv, of); - fflush(of); - continue; - } - if (rv == -1) { - /* fall back reading one sector at a time */ - for (n = 0; n < tracksize; n += secsize) { - if (lseek(fd, nbytes, SEEK_SET) != nbytes) - err(EX_OSERR, "cannot lseek()"); - rv = read(fd, trackbuf, secsize); - if ((unsigned) rv == secsize) { - nbytes += rv; - if (!quiet) - fprintf(stderr, "%5d KB\r", - nbytes / 1024); - fwrite(trackbuf, sizeof(unsigned char), - rv, of); - fflush(of); - continue; - } - if (rv == -1) { - if (errno != EIO) { - if (!quiet) - putc('\n', stderr); - perror("non-IO error"); - return (EX_OSERR); - } - if (ioctl(fd, FD_GSTAT, &fdcs) == -1) - errx(EX_IOERR, - "floppy IO error, but no FDC status"); - nerrs++; - recoverable = fdcs.status[2] & - NE7_ST2_DD; - if (!quiet) { - printstatus(&fdcs, 0); - fputs(" (", stderr); - if (!recoverable) - fputs("not ", stderr); - fputs("recoverable)", stderr); - } - if (!recover) { - if (!quiet) - putc('\n', stderr); - return (EX_IOERR); - } - memset(trackbuf, fillbyte, secsize); - if (recoverable) { - fdopts |= FDOPT_NOERROR; - if (ioctl(fd, FD_SOPTS, - &fdopts) == -1) - err(EX_OSERR, - "ioctl(fd, FD_SOPTS, FDOPT_NOERROR)"); - rv = read(fd, trackbuf, - secsize); - if ((unsigned)rv != secsize) - err(EX_IOERR, - "read() with FDOPT_NOERROR still fails"); - fdopts &= ~FDOPT_NOERROR; - (void)ioctl(fd, FD_SOPTS, - &fdopts); - } - if (!quiet) { - if (recoverable) - fprintf(stderr, - ": recovered"); - else - fprintf(stderr, - ": dummy"); - fprintf(stderr, - " data @ %#x ... %#x\n", - nbytes, - nbytes + secsize - 1); - } - nbytes += secsize; - fwrite(trackbuf, sizeof(unsigned char), - secsize, of); - fflush(of); - continue; - } - errx(EX_OSERR, "unexpected read() result: %d", - rv); - } - } - if ((unsigned)rv < tracksize) { - /* should not happen */ - nbytes += rv; - if (!quiet) - fprintf(stderr, "\nshort after %5d KB\r", - nbytes / 1024); - fwrite(trackbuf, sizeof(unsigned char), rv, of); - fflush(of); - continue; - } - } - if (!quiet) { - putc('\n', stderr); - if (nerrs) - fprintf(stderr, "%d error%s\n", - nerrs, nerrs > 1? "s": ""); - } - - return (nerrs? EX_IOERR: EX_OK); -} - -int -doreadid(int fd, unsigned int numids, unsigned int trackno) -{ - int rv = 0; - unsigned int i; - struct fdc_readid info; - struct fdc_status fdcs; - struct fd_type fdt; - - if (ioctl(fd, FD_GTYPE, &fdt) == -1) - err(EX_OSERR, "ioctl(FD_GTYPE) failed -- not a floppy?"); - - for (i = 0; i < numids; i++) { - info.cyl = trackno / fdt.heads; - info.head = fdt.heads > 1? trackno % fdt.heads: 0; - if (ioctl(fd, FD_READID, &info) == 0) { - printf("C = %d, H = %d, R = %d, N = %d\n", - info.cyl, info.head, info.sec, info.secshift); - } else { - if (errno != EIO) { - perror("non-IO error"); - return (EX_OSERR); - } - if (ioctl(fd, FD_GSTAT, &fdcs) == -1) - errx(EX_IOERR, - "floppy IO error, but no FDC status"); - printstatus(&fdcs, 0); - putc('\n', stderr); - rv = EX_IOERR; - } - } - - return (rv); -} diff --git a/usr.sbin/fdread/fdutil.c b/usr.sbin/fdread/fdutil.c deleted file mode 100644 index c1f4d8f..0000000 --- a/usr.sbin/fdread/fdutil.c +++ /dev/null @@ -1,523 +0,0 @@ -/* - * Copyright (c) 2001 Joerg Wunsch - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include - -#include - -#include -#include -#include -#include -#include - -#include "fdutil.h" - -/* - * Decode the FDC status pointed to by `fdcsp', and print a textual - * translation to stderr. If `terse' is false, the numerical FDC - * register status is printed, too. - */ -void -printstatus(struct fdc_status *fdcsp, int terse) -{ - char msgbuf[100]; - - if (!terse) - fprintf(stderr, - "\nFDC status ST0=%#x ST1=%#x ST2=%#x C=%u H=%u R=%u N=%u:\n", - fdcsp->status[0] & 0xff, - fdcsp->status[1] & 0xff, - fdcsp->status[2] & 0xff, - fdcsp->status[3] & 0xff, - fdcsp->status[4] & 0xff, - fdcsp->status[5] & 0xff, - fdcsp->status[6] & 0xff); - - if ((fdcsp->status[0] & NE7_ST0_IC_RC) == 0) { - sprintf(msgbuf, "timeout"); - } else if ((fdcsp->status[0] & NE7_ST0_IC_RC) != NE7_ST0_IC_AT) { - sprintf(msgbuf, "unexcpted interrupt code %#x", - fdcsp->status[0] & NE7_ST0_IC_RC); - } else { - strcpy(msgbuf, "unexpected error code in ST1/ST2"); - - if (fdcsp->status[1] & NE7_ST1_EN) - strcpy(msgbuf, "end of cylinder (wrong format)"); - else if (fdcsp->status[1] & NE7_ST1_DE) { - if (fdcsp->status[2] & NE7_ST2_DD) - strcpy(msgbuf, "CRC error in data field"); - else - strcpy(msgbuf, "CRC error in ID field"); - } else if (fdcsp->status[1] & NE7_ST1_MA) { - if (fdcsp->status[2] & NE7_ST2_MD) - strcpy(msgbuf, "no address mark in data field"); - else - strcpy(msgbuf, "no address mark in ID field"); - } else if (fdcsp->status[2] & NE7_ST2_WC) - strcpy(msgbuf, "wrong cylinder (format mismatch)"); - else if (fdcsp->status[1] & NE7_ST1_ND) - strcpy(msgbuf, "no data (sector not found)"); - } - fputs(msgbuf, stderr); -} - -static struct fd_type fd_types_auto[1] = - { { 0,0,0,0,0,0,0,0,0,0,0,FL_AUTO } }; - - -static struct fd_type fd_types_288m[] = { -#if 0 - { FDF_3_2880 }, -#endif - { FDF_3_1722 }, - { FDF_3_1476 }, - { FDF_3_1440 }, - { FDF_3_1200 }, - { FDF_3_820 }, - { FDF_3_800 }, - { FDF_3_720 }, - { 0,0,0,0,0,0,0,0,0,0,0,0 } -}; - -static struct fd_type fd_types_144m[] = { -#ifdef PC98 -#if 0 - { FDF_3_1722 }, - { FDF_3_1476 }, -#endif - { FDF_3_1440 }, - { FDF_3_1200 }, -#if 0 - { FDF_3_820 }, - { FDF_3_800 }, -#endif - { FDF_3_720 }, - { FDF_3_360 }, - { FDF_3_640 }, - { FDF_3_1230 }, -#if 0 - { FDF_3_1280 }, - { FDF_3_1480 }, - { FDF_3_1640 }, -#endif - { 0,0,0,0,0,0,0,0,0,0,0,0 } -#else - { FDF_3_1722 }, - { FDF_3_1476 }, - { FDF_3_1440 }, - { FDF_3_1200 }, - { FDF_3_820 }, - { FDF_3_800 }, - { FDF_3_720 }, - { 0,0,0,0,0,0,0,0,0,0,0,0 } -#endif -}; - -static struct fd_type fd_types_12m[] = { -#ifdef PC98 - { FDF_5_1200 }, -#if 0 - { FDF_5_820 }, - { FDF_5_800 }, -#endif - { FDF_5_720 }, - { FDF_5_360 }, - { FDF_5_640 }, - { FDF_5_1230 }, -#if 0 - { FDF_5_1280 }, -#endif - { 0,0,0,0,0,0,0,0,0,0,0,0 } -#else - { FDF_5_1200 }, - { FDF_5_1230 }, - { FDF_5_1480 }, - { FDF_5_1440 }, - { FDF_5_820 }, - { FDF_5_800 }, - { FDF_5_720 }, - { FDF_5_360 | FL_2STEP }, - { FDF_5_640 }, - { 0,0,0,0,0,0,0,0,0,0,0,0 } -#endif -}; - -static struct fd_type fd_types_720k[] = -{ - { FDF_3_720 }, - { 0,0,0,0,0,0,0,0,0,0,0,0 } -}; - -static struct fd_type fd_types_360k[] = -{ - { FDF_5_360 }, - { 0,0,0,0,0,0,0,0,0,0,0,0 } -}; - - -/* - * Parse a format string, and fill in the parameter pointed to by `out'. - * - * sectrac,secsize,datalen,gap,ncyls,speed,heads,f_gap,f_inter,offs2,flags[...] - * - * sectrac = sectors per track - * secsize = sector size in bytes - * datalen = length of sector if secsize == 128 - * gap = gap length when reading - * ncyls = number of cylinders - * speed = transfer speed 250/300/500/1000 KB/s - * heads = number of heads - * f_gap = gap length when formatting - * f_inter = sector interleave when formatting - * offs2 = offset of sectors on side 2 - * flags = +/-mfm | +/-2step | +/-perpend - * mfm - use MFM recording - * 2step - use 2 steps between cylinders - * perpend - user perpendicular (vertical) recording - * - * Any omitted value will be passed on from parameter `in'. - */ -void -parse_fmt(const char *s, enum fd_drivetype type, - struct fd_type in, struct fd_type *out) -{ - int i, j; - const char *cp; - char *s1; - - *out = in; - - for (i = 0;; i++) { - if (s == 0) - break; - - if ((cp = strchr(s, ',')) == 0) { - s1 = strdup(s); - if (s1 == NULL) - abort(); - s = 0; - } else { - s1 = malloc(cp - s + 1); - if (s1 == NULL) - abort(); - memcpy(s1, s, cp - s); - s1[cp - s] = 0; - - s = cp + 1; - } - if (strlen(s1) == 0) { - free(s1); - continue; - } - - switch (i) { - case 0: /* sectrac */ - if (getnum(s1, &out->sectrac)) - errx(EX_USAGE, - "bad numeric value for sectrac: %s", s1); - break; - - case 1: /* secsize */ - if (getnum(s1, &j)) - errx(EX_USAGE, - "bad numeric value for secsize: %s", s1); - if (j == 128) out->secsize = 0; - else if (j == 256) out->secsize = 1; - else if (j == 512) out->secsize = 2; - else if (j == 1024) out->secsize = 3; - else - errx(EX_USAGE, "bad sector size %d", j); - break; - - case 2: /* datalen */ - if (getnum(s1, &j)) - errx(EX_USAGE, - "bad numeric value for datalen: %s", s1); - if (j >= 256) - errx(EX_USAGE, "bad datalen %d", j); - out->datalen = j; - break; - - case 3: /* gap */ - if (getnum(s1, &out->gap)) - errx(EX_USAGE, - "bad numeric value for gap: %s", s1); - break; - - case 4: /* ncyls */ - if (getnum(s1, &j)) - errx(EX_USAGE, - "bad numeric value for ncyls: %s", s1); - if (j > 85) - errx(EX_USAGE, "bad # of cylinders %d", j); - out->tracks = j; - break; - - case 5: /* speed */ - if (getnum(s1, &j)) - errx(EX_USAGE, - "bad numeric value for speed: %s", s1); - switch (type) { - default: - abort(); /* paranoia */ - - case FDT_360K: - case FDT_720K: - if (j == 250) - out->trans = FDC_250KBPS; - else - errx(EX_USAGE, "bad speed %d", j); - break; - - case FDT_12M: - if (j == 300) - out->trans = FDC_300KBPS; - else if (j == 250) - out->trans = FDC_250KBPS; - else if (j == 500) - out->trans = FDC_500KBPS; - else - errx(EX_USAGE, "bad speed %d", j); - break; - - case FDT_288M: - if (j == 1000) - out->trans = FDC_1MBPS; - /* FALLTHROUGH */ - case FDT_144M: - if (j == 250) - out->trans = FDC_250KBPS; - else if (j == 500) - out->trans = FDC_500KBPS; - else - errx(EX_USAGE, "bad speed %d", j); - break; - } - break; - - case 6: /* heads */ - if (getnum(s1, &j)) - errx(EX_USAGE, - "bad numeric value for heads: %s", s1); - if (j == 1 || j == 2) - out->heads = j; - else - errx(EX_USAGE, "bad # of heads %d", j); - break; - - case 7: /* f_gap */ - if (getnum(s1, &out->f_gap)) - errx(EX_USAGE, - "bad numeric value for f_gap: %s", s1); - break; - - case 8: /* f_inter */ - if (getnum(s1, &out->f_inter)) - errx(EX_USAGE, - "bad numeric value for f_inter: %s", s1); - break; - - case 9: /* offs2 */ - if (getnum(s1, &out->offset_side2)) - errx(EX_USAGE, - "bad numeric value for offs2: %s", s1); - break; - - default: - if (strcmp(s1, "+mfm") == 0) - out->flags |= FL_MFM; - else if (strcmp(s1, "-mfm") == 0) - out->flags &= ~FL_MFM; - else if (strcmp(s1, "+auto") == 0) - out->flags |= FL_AUTO; - else if (strcmp(s1, "-auto") == 0) - out->flags &= ~FL_AUTO; - else if (strcmp(s1, "+2step") == 0) - out->flags |= FL_2STEP; - else if (strcmp(s1, "-2step") == 0) - out->flags &= ~FL_2STEP; - else if (strcmp(s1, "+perpnd") == 0) - out->flags |= FL_PERPND; - else if (strcmp(s1, "-perpnd") == 0) - out->flags &= ~FL_PERPND; - else - errx(EX_USAGE, "bad flag: %s", s1); - break; - } - free(s1); - } - - out->size = out->tracks * out->heads * out->sectrac; -} - -/* - * Print a textual translation of the drive (density) type described - * by `in' to stdout. The string uses the same form that is parseable - * by parse_fmt(). - */ -void -print_fmt(struct fd_type in) -{ - int secsize, speed; - - secsize = 128 << in.secsize; - switch (in.trans) { - case FDC_250KBPS: speed = 250; break; - case FDC_300KBPS: speed = 300; break; - case FDC_500KBPS: speed = 500; break; - case FDC_1MBPS: speed = 1000; break; - default: speed = 1; break; - } - - printf("%d,%d,%#x,%#x,%d,%d,%d,%#x,%d,%d", - in.sectrac, secsize, in.datalen, in.gap, in.tracks, - speed, in.heads, in.f_gap, in.f_inter, in.offset_side2); - if (in.flags & FL_MFM) - printf(",+mfm"); - if (in.flags & FL_2STEP) - printf(",+2step"); - if (in.flags & FL_PERPND) - printf(",+perpnd"); - if (in.flags & FL_AUTO) - printf(",+auto"); - putc('\n', stdout); -} - -/* - * Based on `size' (in kilobytes), walk through the table of known - * densities for drive type `type' and see if we can find one. If - * found, return it (as a pointer to static storage), otherwise return - * NULL. - */ -struct fd_type * -get_fmt(int size, enum fd_drivetype type) -{ - int i, n; - struct fd_type *fdtp; - - switch (type) { - default: - return (0); - - case FDT_360K: - fdtp = fd_types_360k; - n = sizeof fd_types_360k / sizeof(struct fd_type); - break; - - case FDT_720K: - fdtp = fd_types_720k; - n = sizeof fd_types_720k / sizeof(struct fd_type); - break; - - case FDT_12M: - fdtp = fd_types_12m; - n = sizeof fd_types_12m / sizeof(struct fd_type); - break; - - case FDT_144M: - fdtp = fd_types_144m; - n = sizeof fd_types_144m / sizeof(struct fd_type); - break; - - case FDT_288M: - fdtp = fd_types_288m; - n = sizeof fd_types_288m / sizeof(struct fd_type); - break; - } - - if (size == -1) - return fd_types_auto; - - for (i = 0; i < n; i++, fdtp++) { - fdtp->size = fdtp->sectrac * fdtp->heads * fdtp->tracks; - if (((128 << fdtp->secsize) * fdtp->size / 1024) == size) - return (fdtp); - } - return (0); -} - -/* - * Parse a number from `s'. If the string cannot be converted into a - * number completely, return -1, otherwise 0. The result is returned - * in `*res'. - */ -int -getnum(const char *s, int *res) -{ - unsigned long ul; - char *cp; - - ul = strtoul(s, &cp, 0); - if (*cp != '\0') - return (-1); - - *res = (int)ul; - return (0); -} - -/* - * Return a short name and a verbose description for the drive - * described by `t'. - */ -void -getname(enum fd_drivetype t, const char **name, const char **descr) -{ - - switch (t) { - default: - *name = "unknown"; - *descr = "unknown drive type"; - break; - - case FDT_360K: - *name = "360K"; - *descr = "5.25\" double-density"; - break; - - case FDT_12M: - *name = "1.2M"; - *descr = "5.25\" high-density"; - break; - - case FDT_720K: - *name = "720K"; - *descr = "3.5\" double-density"; - break; - - case FDT_144M: - *name = "1.44M"; - *descr = "3.5\" high-density"; - break; - - case FDT_288M: - *name = "2.88M"; - *descr = "3.5\" extra-density"; - break; - } -} diff --git a/usr.sbin/fdread/fdutil.h b/usr.sbin/fdread/fdutil.h deleted file mode 100644 index a093228..0000000 --- a/usr.sbin/fdread/fdutil.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2001 Joerg Wunsch - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $FreeBSD$ - */ - - -void printstatus(struct fdc_status *fdcsp, int terse); -void parse_fmt(const char *, enum fd_drivetype, - struct fd_type, struct fd_type *); -struct fd_type *get_fmt(int, enum fd_drivetype); -void print_fmt(struct fd_type); -int getnum(const char *, int *); -void getname(enum fd_drivetype, const char **, const char **); - diff --git a/usr.sbin/fdwrite/Makefile b/usr.sbin/fdwrite/Makefile deleted file mode 100644 index b97bdd4..0000000 --- a/usr.sbin/fdwrite/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# ---------------------------------------------------------------------------- -# "THE BEER-WARE LICENSE" (Revision 42): -# wrote this file. As long as you retain this notice you -# can do whatever you want with this stuff. If we meet some day, and you think -# this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp -# ---------------------------------------------------------------------------- -# -# $FreeBSD$ - -PROG= fdwrite - -.include diff --git a/usr.sbin/fdwrite/fdwrite.1 b/usr.sbin/fdwrite/fdwrite.1 deleted file mode 100644 index e847398..0000000 --- a/usr.sbin/fdwrite/fdwrite.1 +++ /dev/null @@ -1,129 +0,0 @@ -.\" -.\" ---------------------------------------------------------------------------- -.\" "THE BEER-WARE LICENSE" (Revision 42): -.\" wrote this file. As long as you retain this notice you -.\" can do whatever you want with this stuff. If we meet some day, and you think -.\" this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp -.\" ---------------------------------------------------------------------------- -.\" -.\" $FreeBSD$ -.\" -.\" -.Dd September 16, 1993 -.Dt FDWRITE 1 -.Os -.Sh NAME -.Nm fdwrite -.Nd format and write floppy disks -.Sh SYNOPSIS -.Nm -.Op Fl v -.Op Fl y -.Op Fl f Ar inputfile -.Op Fl d Ar device -.Sh DESCRIPTION -The -.Nm -utility formats and writes one and more floppy disks. -Any floppy disk device capable of formatting can be used. -.Pp -The -.Nm -utility will ask the user -(on -.Pa /dev/tty ) -to insert a new floppy and press return. -The device will then be opened, and queried for its parameters, -then each track will be formatted, written with data from the -.Ar inputfile , -read back and compared. -When the floppy disk is filled, the process is repeated, with the next disk. -This continues until the program is interrupted or EOF is encountered on the -.Ar inputfile . -.Pp -The options are as follows: -.Bl -tag -width 10n -offset indent -.It Fl v -Toggle verbosity on stdout. -Default is ``on''. -After -.Ar device -is opened first time the format will be printed. -During operation progress will be reported with the number of tracks -remaining on the current floppy disk, and the letters I, Z, F, W, -R and C, which indicates completion of Input, Zero-fill, Format -Write, Read and Compare of current track respectively. -.It Fl y -Do not ask for presence of a floppy disk in the drive. -This non-interactive flag -is useful for shell scripts. -.It Fl f Ar inputfile -Input file to read. -If none is given, stdin is assumed. -.It Fl d Ar device -The name of the floppy device to write to. -Default is -.Pa /dev/fd0 . -.El -.Pp -The -.Nm -utility actually closes the -.Ar device -while it waits for the user to press return, -it is thus quite possible to use the drive for other purposes at this -time and later resume writing with the next floppy. -.Pp -The parameters returned from -.Ar device -are used for formatting. -If custom formatting is needed, please use -.Xr fdformat 1 -instead. -.Sh EXAMPLES -The -.Nm -utility -was planned as a tool to make life easier when writing a set of floppies, -one such use could be to write a tar-archive: -.Pp -.Dl "tar cf - . | gzip -9 | fdwrite -d /dev/fd0.1720 -v -.Pp -The main difference from using -.Xr tar 1 Ns 's -multivolume facility is of course the formatting of the floppies, which -here is done on the fly, -thus reducing the amount of work for the floppy-jockey. -.Sh SEE ALSO -.Xr fdformat 1 -.Sh HISTORY -The -.Nm -utility was written while waiting for ``make world'' to complete. -Some of the code was taken from -.Xr fdformat 1 . -.Sh AUTHORS -The program has been contributed by -.An Poul-Henning Kamp Aq phk@FreeBSD.org . -.Sh BUGS -Diagnostics are less than complete at present. -.Pp -If a floppy is sick, and the -.Ar inputfile -is seekable, it should ask the user to frisbee the disk, insert -another, and rewind to the right spot and continue. -.Pp -This concept could be extended to cover non-seekable input also -by employing a temporary file. -.Pp -An option (defaulting to zero) should allow the user to ask for -retries in case of failure. -.Pp -At present a suitable tool for reading back a multivolume set -of floppies is missing. -Programs like -.Xr tar 1 -for instance, will do the job, if the data has not been compressed. -One can always trust -.Xr dd 1 -to help out in this situation of course. diff --git a/usr.sbin/fdwrite/fdwrite.c b/usr.sbin/fdwrite/fdwrite.c deleted file mode 100644 index 8c953a6..0000000 --- a/usr.sbin/fdwrite/fdwrite.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * ---------------------------------------------------------------------------- - * "THE BEER-WARE LICENSE" (Revision 42): - * wrote this file. As long as you retain this notice you - * can do whatever you want with this stuff. If we meet some day, and you think - * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp - * ---------------------------------------------------------------------------- - * - * $FreeBSD$ - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -static int -format_track(int fd, int cyl, int secs, int head, int rate, - int gaplen, int secsize, int fill, int interleave) -{ - struct fd_formb f; - register int i,j; - int il[100]; - - memset(il,0,sizeof il); - for(j = 0, i = 1; i <= secs; i++) { - while(il[(j%secs)+1]) j++; - il[(j%secs)+1] = i; - j += interleave; - } - - f.format_version = FD_FORMAT_VERSION; - f.head = head; - f.cyl = cyl; - f.transfer_rate = rate; - - f.fd_formb_secshift = secsize; - f.fd_formb_nsecs = secs; - f.fd_formb_gaplen = gaplen; - f.fd_formb_fillbyte = fill; - for(i = 0; i < secs; i++) { - f.fd_formb_cylno(i) = cyl; - f.fd_formb_headno(i) = head; - f.fd_formb_secno(i) = il[i+1]; - f.fd_formb_secsize(i) = secsize; - } - return ioctl(fd, FD_FORM, (caddr_t)&f); -} - -static void -usage(void) -{ - fprintf(stderr, "usage: fdwrite [-v] [-y] [-f inputfile] [-d device]\n"); - exit(2); -} - -int -main(int argc, char **argv) -{ - int inputfd = -1, c, fdn = 0, i,j,fd; - int bpt, verbose=1, nbytes=0, track; - int interactive = 1; - const char *device= "/dev/fd0"; - char *trackbuf = 0,*vrfybuf = 0; - struct fd_type fdt; - FILE *tty; - - setbuf(stdout,0); - while((c = getopt(argc, argv, "d:f:vy")) != -1) - switch(c) { - case 'd': /* Which drive */ - device = optarg; - break; - - case 'f': /* input file */ - if (inputfd >= 0) - close(inputfd); - inputfd = open(optarg,O_RDONLY); - if (inputfd < 0) - err(1, "%s", optarg); - break; - - case 'v': /* Toggle verbosity */ - verbose = !verbose; - break; - - case 'y': /* Don't confirm? */ - interactive = 0; - break; - - case '?': default: - usage(); - } - - if (inputfd < 0) - inputfd = 0; - - if (!isatty(1)) - interactive = 0; - - if(optind < argc) - usage(); - - tty = fopen(_PATH_TTY,"r+"); - if(!tty) - err(1, _PATH_TTY); - setbuf(tty,0); - - for(j=1;j > 0;) { - fdn++; - if (interactive) { - fprintf(tty, - "Please insert floppy #%d in drive %s and press return >", - fdn,device); - while(1) { - i = getc(tty); - if(i == '\n') break; - } - } - - if((fd = open(device, O_RDWR)) < 0) - err(1, "%s", device); - - if(ioctl(fd, FD_GTYPE, &fdt) < 0) - errx(1, "not a floppy disk: %s", device); - - bpt = fdt.sectrac * (1<= 0 && j= 0 && j diff --git a/usr.sbin/fifolog/Makefile.inc b/usr.sbin/fifolog/Makefile.inc deleted file mode 100644 index 5ec27dd..0000000 --- a/usr.sbin/fifolog/Makefile.inc +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -LIBFIFOLOG= ${.OBJDIR}/../lib/libfifolog.a - -#LINT= flint -#LINTFLAGS= ${.CURDIR}/../flint.lnt -I/usr/include - -.include "../Makefile.inc" diff --git a/usr.sbin/fifolog/fifolog_create/Makefile b/usr.sbin/fifolog/fifolog_create/Makefile deleted file mode 100644 index 8b59b25..0000000 --- a/usr.sbin/fifolog/fifolog_create/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -# $FreeBSD$ - -PROG= fifolog_create - -CFLAGS+= -I${.CURDIR}/../lib - -DPADD= ${LIBFIFOLOG} ${LIBUTIL} -LDADD= ${LIBFIFOLOG} -lutil - -MAN= fifolog.1 -MLINKS= fifolog.1 fifolog_create.1 \ - fifolog.1 fifolog_reader.1 \ - fifolog.1 fifolog_writer.1 - -regress: - rm -f /tmp/fifolog.? - ./${PROG} /tmp/fifolog.0 - ./${PROG} -s 10m /tmp/fifolog.1 - ./${PROG} -l 1k /tmp/fifolog.2 - ./${PROG} -r 1k /tmp/fifolog.3 - -.include diff --git a/usr.sbin/fifolog/fifolog_create/fifolog.1 b/usr.sbin/fifolog/fifolog_create/fifolog.1 deleted file mode 100644 index d0be0ce..0000000 --- a/usr.sbin/fifolog/fifolog_create/fifolog.1 +++ /dev/null @@ -1,218 +0,0 @@ -.\" Copyright (c) 2008 Poul-Henning Kamp -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd February 9, 2008 -.Dt FIFOLOG 1 -.Os -.Sh NAME -.Nm fifolog_create , fifolog_writer , fifolog_reader -.Nd "initialize, write, seek and extract data from a fifolog" -.Sh SYNOPSIS -.Nm fifolog_create -.Op Fl l Ar record-size -.Op Fl r Ar record-count -.Op Fl s Ar size -.Ar file -.Nm fifolog_reader -.Op Fl t -.Op Fl b Ar tstart -.Op Fl B Ar Tstart -.Op Fl e Ar tend -.Op Fl E Ar Tend -.Op Fl o Ar ofile -.Op Fl R Ar regexp -.Op Fl T Ar timefmt -.Ar file -.Nm fifolog_writer -.Op Fl w Ar write-rate -.Op Fl s Ar sync-rate -.Op Fl z Ar compression -.Ar file -.Sh DESCRIPTION -Fifologs provide a compact round-robin circular storage for -recording text and binary information to permanent storage in a bounded -and predictable fashion, time and space wise. -.Pp -A fifolog can be stored either directly on a disk partition or in a -regular file. -.Pp -The input data stream is encoded, compressed and marked up with -timestamps before it is written to storage, such that it is possible -to seek out a particular time interval in the stored data, without -having to decompress the entire logfile. -.Pp -The -.Nm fifolog_create -utility -is used to initialize the first sector of a disk device -or file system file to make it a fifolog and should be called only -once. -.Pp -Running -.Nm fifolog_create -on an existing fifolog will reset it so that -.Nm fifolog_reader -and -.Nm fifolog_writer -will not see the previous contents. -(The previous contents are not physically erased, and with a bit -of hand-work all but the first record can be easily recovered.) -.Pp -If the -.Ar file -does not already exist, -.Nm fifolog_create -will attempt to create and -.Xr ftruncate 2 -it to the specified size, defaulting to 86400 records of 512 bytes -if the -.Fl r , l -or -.Fl s -options do not specify otherwise. -.Pp -The -.Nm fifolog_writer -utility -will read standard input and write it to the end of the fifolog -according to the parameters given. -.Pp -Writes happen whenever the output buffer is filled with compressed -data or when either of two timers expire, forcing a partially filled -buffer to be written. -.Pp -The first and faster timer, -.Fl w Ar write-rate , -forces available data to be written -but does not flush and reset the compression dictionary. -This timer is intended to minimize the amount of logdata lost in RAM -in case of a crash and by default it fires 10 seconds after -the previous write. -.Pp -The second and slower timer, -.Fl s Ar sync-rate , -forces a full flush and reset of the compression -engine and causes the next record written to be a synchronization -point with an uncompressed timestamp, making it possible to start -reading the logfile from that record. -By default this timer fires a minute after the previous sync. -.Pp -The -.Fl z Ar compression -option controls the -.Xr zlib 3 -compression level; legal values are zero to nine which is the default. -.Pp -The -.Nm fifolog_reader -utility -will retrieve records from the fifolog according to the specified -parameters and write them either to standard output or the file specified -with -.Fl o . -.Pp -It is possible to specify a start and end time to limit the amount -of data -.Nm fifolog_reader -will report. -The lower-case variants -.Fl b -and -.Fl e -take a -.Vt time_t -value, whereas the upper-case variants -.Fl B -and -.Fl E -take human-readable specifications such as -.Dq Li "1 hour ago" . -.Pp -The -.Fl t -option forces timestamps to be formatted as -.Dq Li "YYYYMMDDhhmmss" -instead of as -.Vt time_t , -and -.Fl T -allows the specification of an -.Xr strftime 3 -formatting string. -.Pp -Finally, records can be filtered such that only records matching the -.Pq Dv REG_BASIC -regular expression specified with -.Fl R -are output. -.Sh IMPLEMENTATION NOTES -The data stored in the fifolog consists of three layers, an outer -layer that allows searches to synchronization points based on timestamps -without having to decompress and decode the actual contents, a -compression layer implemented with -.Xr zlib 3 , -and an inner serialization and timestamping layer. -.Pp -The exact encoding is described in the -.Pa fifolog.h -file. -.Pp -Fifolog is particularly well suited for use on Flash based media, where -it results in much lower write-wear, than a file system with regular -log files rotated with -.Xr newsyslog 8 -etc. -.Sh EXAMPLES -Create a fifolog with 1024*1024 records of 512 bytes: -.Pp -.Dl "fifolog_create -r 10m /tmp/fifolog" -.Pp -Write a single record to this file: -.Pp -.Dl "date | fifolog_writer /tmp/fifolog" -.Pp -Read it back with human readable timestamps: -.Pp -.Dl "fifolog_reader -t /tmp/fifolog" -.Pp -One particular useful use of -.Nm fifolog_writer -is with -.Xr syslogd 8 -using a line such as this in -.Xr /etc/syslog.conf 5 : -.Pp -.Dl "*.* |fifolog_writer /var/log/syslog_fifolog" -.Sh HISTORY -The fifolog tools have been liberated from an open source -.Tn SCADA -applications called -.Dq measured , -which monitors and controls remote radio navigation -transmitters for the Danish Air Traffic Control system. -.Sh AUTHORS -The fifolog tools were written by -.An Poul-Henning Kamp . diff --git a/usr.sbin/fifolog/fifolog_create/fifolog_create.c b/usr.sbin/fifolog/fifolog_create/fifolog_create.c deleted file mode 100644 index 5e91db1..0000000 --- a/usr.sbin/fifolog/fifolog_create/fifolog_create.c +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include - -#include "libfifolog.h" - -#define DEF_RECSIZE 512 -#define DEF_RECCNT (24 * 60 * 60) - -static void -usage(void) -{ - fprintf(stderr, "Usage: fifolog_create [-l record-size] " - "[-r record-count] [-s size] file\n"); - exit(EX_USAGE); -} - -int -main(int argc, char * const *argv) -{ - int ch; - int64_t size; - int64_t recsize; - int64_t reccnt; - const char *s; - - recsize = 0; - size = 0; - reccnt = 0; - while((ch = getopt(argc, argv, "l:r:s:")) != -1) { - switch (ch) { - case 'l': - if (expand_number(optarg, &recsize)) - err(1, "Couldn't parse -l argument"); - break; - case 'r': - if (expand_number(optarg, &reccnt)) - err(1, "Couldn't parse -r argument"); - break; - case 's': - if (expand_number(optarg, &size)) - err(1, "Couldn't parse -s argument"); - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - if (argc != 1) - usage(); - - if (size != 0 && reccnt != 0 && recsize != 0) { /* N N N */ - if (size != reccnt * recsize) - errx(1, "Inconsistent -l, -r and -s values"); - } else if (size != 0 && reccnt != 0 && recsize == 0) { /* N N Z */ - if (size % reccnt) - errx(1, - "Inconsistent -r and -s values (gives remainder)"); - recsize = size / reccnt; - } else if (size != 0 && reccnt == 0 && recsize != 0) { /* N Z N */ - if (size % recsize) - errx(1, "-s arg not divisible by -l arg"); - } else if (size != 0 && reccnt == 0 && recsize == 0) { /* N Z Z */ - recsize = DEF_RECSIZE; - if (size % recsize) - errx(1, "-s arg not divisible by %jd", recsize); - } else if (size == 0 && reccnt != 0 && recsize != 0) { /* Z N N */ - size = reccnt * recsize; - } else if (size == 0 && reccnt != 0 && recsize == 0) { /* Z N Z */ - recsize = DEF_RECSIZE; - size = reccnt * recsize; - } else if (size == 0 && reccnt == 0 && recsize != 0) { /* Z Z N */ - size = DEF_RECCNT * recsize; - } else if (size == 0 && reccnt == 0 && recsize == 0) { /* Z Z Z */ - recsize = DEF_RECSIZE; - size = DEF_RECCNT * recsize; - } - - s = fifolog_create(argv[0], size, recsize); - if (s == NULL) - return (0); - err(1, "%s", s); -} diff --git a/usr.sbin/fifolog/fifolog_reader/Makefile b/usr.sbin/fifolog/fifolog_reader/Makefile deleted file mode 100644 index 7dcc8c2..0000000 --- a/usr.sbin/fifolog/fifolog_reader/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# $FreeBSD$ - -PROG= fifolog_reader - -CFLAGS+= -I${.CURDIR}/../lib - -NO_MAN= # see ../fifolog_create/fifolog.1 - -DPADD= ${LIBFIFOLOG} ${LIBUTIL} ${LIBZ} -LDADD= ${LIBFIFOLOG} -lutil -lz - -regress: - ./${PROG} /tmp/fifolog.0 - ./${PROG} -t /tmp/fifolog.0 - ./${PROG} /tmp/fifolog.1 - ./${PROG} -B "00:00" /tmp/fifolog.1 - ./${PROG} -T "%y%m%d-%H%M%S" /tmp/fifolog.1 - ./${PROG} -T "" /tmp/fifolog.1 - -.include diff --git a/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c b/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c deleted file mode 100644 index 7178082..0000000 --- a/usr.sbin/fifolog/fifolog_reader/fifolog_reader.c +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libfifolog.h" - -static time_t opt_B; -static time_t opt_E; -static const char *opt_T; -static const char *opt_o; -static const char *opt_R; -static regex_t R; - -static FILE *fo; - -static void -Render(void *priv __unused, time_t now, unsigned flag __unused, const unsigned char *p, unsigned l __unused) -{ - static struct tm utc; - char buf[128]; - int i; - - if (now < opt_B || now > opt_E) - return; - - if (opt_R != NULL && regexec(&R, (const char *)p, 0, NULL, 0)) - return; - - if (opt_T != NULL && *opt_T == '\0') { - fprintf(fo, "%s\n", p); - } else if (opt_T != NULL) { - (void)gmtime_r(&now, &utc); - i = strftime(buf, sizeof buf, opt_T, &utc); - assert(i > 0); - fprintf(fo, "%s %s\n", buf, p); - } else { - fprintf(fo, "%12ld %s\n", (long)now, p); - } -} - -/*--------------------------------------------------------------------*/ - -static void -Usage(void) -{ - fprintf(stderr, - "Usage: fiforead [options] fifofile\n" - "\t-b \n" - "\t-B \n" - "\t-e \n" - "\t-E \n" - "\t-o \n" - "\t-R # match regexp\n" - "\t-t # format timestamps as %%Y%%m%%d%%H%%M%%S\n" - "\t-T \n" - ); - exit (EX_USAGE); -} - -int -main(int argc, char * const *argv) -{ - int ch, i; - off_t o; - struct fifolog_reader *fl; - - time(&opt_E); - opt_o = "-"; - while ((ch = getopt(argc, argv, "b:B:e:E:o:R:tT:")) != -1) { - switch (ch) { - case 'b': - opt_B = strtoul(optarg, NULL, 0); - break; - case 'B': - opt_B = get_date(optarg); - if (opt_B == -1) - errx(1, "Didn't understand \"%s\"", optarg); - break; - case 'e': - opt_E = strtoul(optarg, NULL, 0); - break; - case 'E': - opt_E = get_date(optarg); - if (opt_E == -1) - errx(1, "Didn't understand \"%s\"", optarg); - break; - case 'o': - opt_o = optarg; - break; - case 'R': - opt_R = optarg; - break; - case 't': - opt_T = "%Y%m%d%H%M%S"; - break; - case 'T': - opt_T = optarg; - break; - default: - Usage(); - } - } - argc -= optind; - argv += optind; - - if (opt_R != NULL) { - i = regcomp(&R, opt_R, REG_NOSUB); - if (i != 0) { - char buf[BUFSIZ]; - (void)regerror(i, &R, buf, sizeof buf); - fprintf(stderr, "-R argument: %s\n", buf); - exit (1); - } - } - - if (argv[0] == NULL) - Usage(); - - fprintf(stderr, "From\t%jd %s", (intmax_t)opt_B, ctime(&opt_B)); - fprintf(stderr, "To\t%jd %s", (intmax_t)opt_E, ctime(&opt_E)); - if (opt_B >= opt_E) - errx(1, "Begin time not before End time"); - - fl = fifolog_reader_open(argv[0]); - - if (!strcmp(opt_o, "-")) - fo = stdout; - else { - fo = fopen(opt_o, "w"); - if (fo == NULL) - err(1, "Cannot open: %s", argv[1]); - } - - o = fifolog_reader_seek(fl, opt_B); - fifolog_reader_process(fl, o, Render, NULL, opt_E); - return (0); -} diff --git a/usr.sbin/fifolog/fifolog_writer/Makefile b/usr.sbin/fifolog/fifolog_writer/Makefile deleted file mode 100644 index b6ceb63..0000000 --- a/usr.sbin/fifolog/fifolog_writer/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# $FreeBSD$ - -PROG= fifolog_writer - -CFLAGS+= -I${.CURDIR}/../lib - -NO_MAN= # see ../fifolog_create/fifolog.1 - -DPADD= ${LIBFIFOLOG} ${LIBUTIL} ${LIBZ} -LDADD= ${LIBFIFOLOG} -lutil -lz - -regress: - date | ./${PROG} -z 0 /tmp/fifolog.0 - lptest 65 | ./${PROG} -z 9 /tmp/fifolog.1 - -.include diff --git a/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c b/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c deleted file mode 100644 index 346297f..0000000 --- a/usr.sbin/fifolog/fifolog_writer/fifolog_writer.c +++ /dev/null @@ -1,114 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "libfifolog.h" - -static void -usage(void) -{ - fprintf(stderr, "Usage: fifolog_writer [-w write-rate] [-s sync-rate] " - "[-z compression] file\n"); - exit(EX_USAGE); -} - -int -main(int argc, char * const *argv) -{ - struct fifolog_writer *f; - const char *es; - struct pollfd pfd[1]; - char buf[BUFSIZ], *p; - int i, c; - unsigned w_opt = 10; - unsigned s_opt = 60; - unsigned z_opt = Z_BEST_COMPRESSION; - - while ((c = getopt(argc, argv, "w:s:z:")) != -1) { - switch(c) { - case 'w': - w_opt = strtoul(optarg, NULL, 0); - break; - case 's': - s_opt = strtoul(optarg, NULL, 0); - break; - case 'z': - z_opt = strtoul(optarg, NULL, 0); - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - if (argc != 1) - usage(); - - if (z_opt > 9) - usage(); - - if (w_opt > s_opt) - usage(); - - f = fifolog_write_new(); - assert(f != NULL); - - es = fifolog_write_open(f, argv[0], w_opt, s_opt, z_opt); - if (es) - err(1, "Error: %s", es); - - while (1) { - pfd[0].fd = 0; - pfd[0].events = POLLIN; - i = poll(pfd, 1, 1000); - if (i == 1) { - if (fgets(buf, sizeof buf, stdin) == NULL) - break; - p = strchr(buf, '\0'); - assert(p != NULL); - while (p > buf && isspace(p[-1])) - p--; - *p = '\0'; - if (*buf != '\0') - fifolog_write_bytes_poll(f, 0, 0, buf, 0); - } else if (i == 0) - (void)fifolog_write_poll(f, 0); - } - (void)fifolog_write_flush(f); - return (0); -} diff --git a/usr.sbin/fifolog/flint.lnt b/usr.sbin/fifolog/flint.lnt deleted file mode 100644 index 16ee7ad..0000000 --- a/usr.sbin/fifolog/flint.lnt +++ /dev/null @@ -1,49 +0,0 @@ -// $FreeBSD$ -// FlexeLint file for fifolog tools -// - --passes=3 --ffc - -// GCC --cgnu -+d__FreeBSD__=7 -+d__GNUC__=4 -+d__GNUC_MINOR__=2 -+d__FreeBSD_cc_version=700003 -+d__attribute__()= --d__builtin_va_list=void* // used by stdarg.h -// -d__builtin_stdarg_start()=_to_semi // ditto -// -d__builtin_va_start(a,b)=((void)(b),(a)=0) // ditto -// -d__builtin_va_end()=_to_semi // ditto -+rw(__inline) // enable the (non-standard) __inline keyword -+rw(__inline__) // enable the (non-standard) __inline__ keyword - -+d"__unused=/*lint -e{715} -e{818} */" - --e537 // Repeated include file --elib(652) // #define of symbol '...' declared previously --function(exit,__assert) --function(exit,err) --function(exit,errx) --e716 // while(1) ... --e717 // do ... while(0) - -// Ignore return values --esym(534, memset) --esym(534, memcpy) --esym(534, strcpy) --esym(534, printf) --esym(534, time) --esym(534, fprintf) --esym(534, vfprintf) - -+libh(fifolog.h) -+libh(miniobj.h) -+libh(libfifolog.h) - --e713 // loss of precision sign/unsigned --e732 // loss of sign --e734 // loss of precision assignment --e737 // loss of sign in promotion int->unsigned --e573 // sign/unsign mix in divide diff --git a/usr.sbin/fifolog/lib/Makefile b/usr.sbin/fifolog/lib/Makefile deleted file mode 100644 index c10126f..0000000 --- a/usr.sbin/fifolog/lib/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# $FreeBSD$ - -LIB= fifolog -INTERNALLIB= # API not published or supported. - -SRCS= fifolog_int.c fifolog_create.c fifolog_write_poll.c fifolog_reader.c -SRCS+= getdate.y - -CFLAGS+= -I${.CURDIR} - -.include diff --git a/usr.sbin/fifolog/lib/fifolog.h b/usr.sbin/fifolog/lib/fifolog.h deleted file mode 100644 index 14374ac..0000000 --- a/usr.sbin/fifolog/lib/fifolog.h +++ /dev/null @@ -1,138 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef __LOCAL_FIFOLOG_H_ -#define __LOCAL_FIFOLOG_H_ - -/* - * Definitions for fifolog "protocol": the on-media layout. - * - * The fifolog on-media record has three layers: - * The outer timestamping and synchronization layer. - * The zlib implemented data compression. - * The inner sequencing and identification layer. - * - * All three layers are synchronized at a subset of the outer layer - * record boundaries, from where reading can be initiated. - * - * - * The outer layer: - * ----------------- - * The first record in a fifolog contains a magic string and version - * information along with a 32be encoded recordsize for all records - * in the fifolog, including the first. - * The recordsize is explicit to avoid ambiguities when a media is - * moved from one machine to another. - * - * Each record in the fifolog has the following contents: - * offset type contents - * -------------------------------------------------------------- - * 0 32be sequence_number - * The sequence number is randomly chosen for the - * fifolog and increments once for each record written. - * It's presence allow quick identification of the next - * record to be written using a binary search for the - * first place where a discontinuity in the sequence - * numbers occur. - * 4 8 flags (FIFOLOG_FLG_*) - * - * If (flags & (FIFOLOG_FLG_SYNC)) the record is a synchronization point - * at which the inner layers are aligned so that reading can be started - * at this point. - * To enable seeks into the file based on timestamps, a third field is - * present in these records as well: - * 5 32be time_t containing POSIX's understanding of UTC. - * - * These fields are immediately followed by the inner layer payload as - * described below, which has variable length. - * - * If the inner layer payload is shorter than the available space in - * the record, it is padded with zero bytes, and the number of unused - * bytes, including the encoded length thereof is recorded at the end - * of the record as follows: - * - * If (flags & FIFOLOG_FLG_1BYTE) - * n-1 8 number of unused bytes - * else if (flags & FIFOLOG_FLG_4BYTE) - * n-4 32be number of unused bytes - * - * - * The gzip layer - * -------------- - * Is just output from zlib, nothing special here. FIFOLOG_FLG_SYNC - * corresponds to Z_FINISH flags to zlib. - * In most cases, the timer will expire before zlib has filled an entire - * record in which case Z_SYNC_FLUSH will be used to force as much as - * possible into the buffer before it is written. This is not marked - * in outer layer (apart from a natural correlation with padding) since - * zlibs data stream handles this without help. - * - * - * The inner layer: - * ---------------- - * The inner layer contains data identification and to the second - * timestamping (the timestamp in the outer layer only marks the - * first possible timestamp for content in the SYNC record). - * - * offset type contents - * -------------------------------------------------------------- - * 0 32be ident - * - * The bottom 30 bits of the identification word are application defined, - * presently unused in the stand-alone fifolog tools, but used in the - * original "measured" application that originated the fifolog format. - * Should for instance syslogd(8) grow native support for fifolog format, - * it could store the message priority here. - * - * If (ident & FIFOLOG_TIMESTAMP) the record is prefixed by: - * 4 32be time_t containing POSIX's understanding of UTC. - * - * Then follows the content, either as a NUL terminated string or as - * a length encoded binary sequence: - * - * If (ident & FIFOLOG_LENGTH) the record is prefixed by: - * {0|4} 8 length of binary data - * - */ - -/* Magic identification string */ -#define FIFOLOG_FMT_MAGIC "Measured FIFOLOG Ver 1.01\n" - -/* Offset of the 32be encoded recordsize in the first sector */ -#define FIFOLOG_OFF_BS 0x20 - -#define FIFOLOG_FLG_1BYTE 0x01 -#define FIFOLOG_FLG_4BYTE 0x02 -#define FIFOLOG_FLG_RESTART 0x40 -#define FIFOLOG_FLG_SYNC 0x80 - -#define FIFOLOG_TIMESTAMP 0x80000000 -#define FIFOLOG_LENGTH 0x40000000 -#define FIFOLOG_IDENT 0x3fffffff - -#endif /* __LOCAL_FIFOLOG_H_ */ diff --git a/usr.sbin/fifolog/lib/fifolog_create.c b/usr.sbin/fifolog/lib/fifolog_create.c deleted file mode 100644 index 68f8cef..0000000 --- a/usr.sbin/fifolog/lib/fifolog_create.c +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fifolog.h" -#include "libfifolog.h" - -const char * -fifolog_create(const char *fn, off_t size, unsigned recsize) -{ - int i, fd; - unsigned u; - off_t ms; - struct stat st; - char *buf; - int created; - - fd = open(fn, O_WRONLY | O_TRUNC | O_EXCL | O_CREAT, 0644); - if (fd < 0) { - created = 0; - fd = open(fn, O_WRONLY); - if (fd < 0) - return ("Could not open"); - } else - created = 1; - - /* Default sectorsize is 512 */ - if (recsize == 0) - recsize = 512; - - /* See what we got... */ - i = fstat(fd, &st); - assert(i == 0); - if (!S_ISBLK(st.st_mode) && - !S_ISCHR(st.st_mode) && - !S_ISREG(st.st_mode)) { - assert(!close (fd)); - return ("Wrong file type"); - } - - if(!created && S_ISREG(st.st_mode)) { - assert(!close (fd)); - return ("Wrong file type"); - } - - /* For raw disk with larger sectors: use 1 sector */ - i = ioctl(fd, DIOCGSECTORSIZE, &u); - if (i == 0 && (u > recsize || (recsize % u) != 0)) - recsize = u; - - /* If no configured size, or too large for disk, use device size */ - i = ioctl(fd, DIOCGMEDIASIZE, &ms); - if (i == 0 && (size == 0 || size > ms)) - size = ms; - - if (size == 0 && S_ISREG(st.st_mode)) - size = st.st_size; - - if (size == 0) - size = recsize * (off_t)(24*60*60); - - if (S_ISREG(st.st_mode) && ftruncate(fd, size) < 0) - return ("Could not ftrunc"); - - buf = calloc(recsize, 1); - if (buf == NULL) - return ("Could not malloc"); - - strcpy(buf, FIFOLOG_FMT_MAGIC); /*lint !e64 */ - be32enc(buf + FIFOLOG_OFF_BS, recsize); - if ((int)recsize != pwrite(fd, buf, recsize, 0)) { - i = errno; - free(buf); - errno = i; - return ("Could not write first sector"); - } - memset(buf, 0, recsize); - if ((int)recsize != pwrite(fd, buf, recsize, recsize)) { - i = errno; - free(buf); - errno = i; - return ("Could not write second sector"); - } - free(buf); - assert(0 == close(fd)); - return (NULL); -} diff --git a/usr.sbin/fifolog/lib/fifolog_int.c b/usr.sbin/fifolog/lib/fifolog_int.c deleted file mode 100644 index f87fd82..0000000 --- a/usr.sbin/fifolog/lib/fifolog_int.c +++ /dev/null @@ -1,275 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "miniobj.h" -#include "fifolog.h" -#include "libfifolog_int.h" - -/* - * Memory handling for zlib - */ - -static voidpf -fifo_zalloc(voidpf opaque __unused, uInt items, uInt size) -{ - - return calloc(items,size); -} - -static void -fifo_zfree(voidpf opaque __unused, voidpf address) -{ - - free(address); -} - -/* - * Open a fifolog file or partition for reading or writing. - * - * Return value is NULL for success or a error description string to - * be augmented by errno if non-zero. - * - * The second function is just an error-handling wrapper around the - * first which, does the actual work. - */ - -static const char * -fifolog_int_open_i(struct fifolog_file *f, const char *fname, int mode) -{ - struct stat st; - unsigned u; - int i; - - f->fd = open(fname, mode ? O_RDWR : O_RDONLY); - if (f->fd < 0) - return ("Cannot open"); - - /* Determine initial record size guesstimate */ - i = ioctl(f->fd, DIOCGSECTORSIZE, &f->recsize); - if (i != 0 && errno != ENOTTY) - return ("ioctl(DIOCGSECTORSIZE) failed"); - - if (i != 0) { - i = fstat(f->fd, &st); - if (!S_ISREG(st.st_mode)) - return ("Neither disk nor regular file"); - f->recsize = 512; - f->logsize = st.st_size; - } else if (f->recsize < 64) { - return ("Disk device sectorsize smaller than 64"); - } else { - i = ioctl(f->fd, DIOCGMEDIASIZE, &f->logsize); - if (i < 0 && errno != ENOTTY) - return ("ioctl(DIOCGMEDIASIZE) failed"); - } - - /* Allocate a record buffer */ - f->recbuf = malloc(f->recsize); - if (f->recbuf == NULL) - return ("Cannot malloc"); - - /* Read and validate the label sector */ - i = pread(f->fd, f->recbuf, f->recsize, 0); - if (i < 0 || i < (int)f->recsize) - return ("Read error, first sector"); - - errno = 0; - if (memcmp(f->recbuf, FIFOLOG_FMT_MAGIC, strlen(FIFOLOG_FMT_MAGIC) + 1)) - return ("Wrong or missing magic string"); - - u = be32dec(f->recbuf + FIFOLOG_OFF_BS); - if (u < 64) - return ("Wrong record size in header (<64)"); - - if ((off_t)u >= f->logsize) - return ("Record size in header bigger than fifolog"); - - f->recsize = u; - - /* Reallocate the buffer to correct size if necessary */ - if (u != f->recsize) { - free(f->recbuf); - f->recbuf = NULL; - f->recsize = u; - f->recbuf = malloc(f->recsize); - if (f->recbuf == NULL) - return ("Cannot malloc"); - } - - /* Calculate number of records in fifolog */ - f->logsize /= u; - if (f->logsize < 10) - return ("less than 10 records in fifolog"); - - f->logsize--; /* the label record */ - - /* Initialize zlib handling */ - - f->zs = calloc(sizeof *f->zs, 1); - if (f->zs == NULL) - return ("cannot malloc"); - f->zs->zalloc = fifo_zalloc; - f->zs->zfree = fifo_zfree; - - return (NULL); -} - -const char * -fifolog_int_open(struct fifolog_file **ff, const char *fname, int mode) -{ - struct fifolog_file fs, *f; - const char *retval; - int e; - - f = &fs; - memset(f, 0, sizeof *f); - f->fd = -1; - retval = fifolog_int_open_i(f, fname, mode); - e = errno; - if (retval == NULL) { - *ff = malloc(sizeof *f); - if (*ff != NULL) { - memcpy(*ff, f, sizeof *f); - (*ff)->magic = FIFOLOG_FILE_MAGIC; - return (retval); - } - } - fifolog_int_close(&f); - errno = e; - return (retval); -} - -void -fifolog_int_close(struct fifolog_file **ff) -{ - struct fifolog_file *f; - - f = *ff; - *ff = NULL; - if (f == NULL) - return; - - if (f->fd >= 0) - (void)close(f->fd); - if (f->zs != NULL) - free(f->zs); - if (f->recbuf != NULL) - free(f->recbuf); -} - -static void -fifolog_int_file_assert(const struct fifolog_file *ff) -{ - - CHECK_OBJ_NOTNULL(ff, FIFOLOG_FILE_MAGIC); - assert(ff->fd >= 0); - assert(ff->recbuf != NULL); -} - - -/* - * Read a record. - * - * Return zero on success - */ - -int -fifolog_int_read(const struct fifolog_file *ff, off_t recno) -{ - int i; - - fifolog_int_file_assert(ff); - if (recno >= ff->logsize) - return (-1); - recno++; /* label sector */ - i = pread(ff->fd, ff->recbuf, ff->recsize, recno * ff->recsize); - if (i < 0) - return (-2); - if (i != (int)ff->recsize) - return (-3); - return (0); -} - -/* - * Find the last written record in the fifolog. - * - * Return is error string or NULL on success - */ - -const char * -fifolog_int_findend(const struct fifolog_file *ff, off_t *last) -{ - off_t o, s; - int e; - unsigned seq0, seq; - - fifolog_int_file_assert(ff); - - o = 0; - e = fifolog_int_read(ff, o); - if (e) - return("Read error, first record"); - - seq0 = be32dec(ff->recbuf); - - /* If the first records sequence is zero, the fifolog is empty */ - if (seq0 == 0) { - *last = o; - return (NULL); - } - - /* Do a binary search for a discontinuity in the sequence numbers */ - s = ff->logsize / 2; - do { - e = fifolog_int_read(ff, o + s); - if (e) - return ("Read error while searching"); - seq = be32dec(ff->recbuf); - if (seq == seq0 + s) { - o += s; - seq0 = seq; - } - s /= 2; - assert(o < ff->logsize); - } while (s > 0); - - *last = o; - return (NULL); -} diff --git a/usr.sbin/fifolog/lib/fifolog_reader.c b/usr.sbin/fifolog/lib/fifolog_reader.c deleted file mode 100644 index d7475ed..0000000 --- a/usr.sbin/fifolog/lib/fifolog_reader.c +++ /dev/null @@ -1,322 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fifolog.h" -#include "libfifolog.h" -#include "libfifolog_int.h" -#include "miniobj.h" - -/*--------------------------------------------------------------------*/ - -struct fifolog_reader { - unsigned magic; -#define FIFOLOG_READER_MAGIC 0x1036d139 - struct fifolog_file *ff; - unsigned olen; - unsigned char *obuf; - time_t now; -}; - -struct fifolog_reader * -fifolog_reader_open(const char *fname) -{ - const char *retval; - struct fifolog_reader *fr; - int i; - - fr = calloc(sizeof *fr, 1); - if (fr == NULL) - err(1, "Cannot malloc"); - - retval = fifolog_int_open(&fr->ff, fname, 0); - if (retval != NULL) - err(1, "%s", retval); - - fr->olen = fr->ff->recsize * 16; - fr->obuf = calloc(fr->olen, 1); - if (fr->obuf == NULL) - err(1, "Cannot malloc"); - - i = inflateInit(fr->ff->zs); - assert(i == Z_OK); - - fr->magic = FIFOLOG_READER_MAGIC; - return (fr); -} - -/* - * Find the next SYNC block - * - * Return: - * 0 - empty fifolog - * 1 - found sync block - * 2 - would have wrapped around - * 3 - End of written log. - */ - -static int -fifolog_reader_findsync(const struct fifolog_file *ff, off_t *o) -{ - int e; - unsigned seq, seqs; - - assert(*o < ff->logsize); - e = fifolog_int_read(ff, *o); - if (e) - err(1, "Read error (%d) while looking for SYNC", e); - seq = be32dec(ff->recbuf); - if (*o == 0 && seq == 0) - return (0); - - if (ff->recbuf[4] & FIFOLOG_FLG_SYNC) - return (1); /* That was easy... */ - while(1) { - assert(*o < ff->logsize); - (*o)++; - seq++; - if (*o == ff->logsize) - return (2); /* wraparound */ - e = fifolog_int_read(ff, *o); - if (e) - err(1, "Read error (%d) while looking for SYNC", e); - seqs = be32dec(ff->recbuf); - if (seqs != seq) - return (3); /* End of log */ - if (ff->recbuf[4] & FIFOLOG_FLG_SYNC) - return (1); /* Bingo! */ - } -} - -/* - * Seek out a given timestamp - */ - -off_t -fifolog_reader_seek(const struct fifolog_reader *fr, time_t t0) -{ - off_t o, s, st; - time_t t, tt; - unsigned seq, seqs; - const char *retval; - int e; - - CHECK_OBJ_NOTNULL(fr, FIFOLOG_READER_MAGIC); - - /* - * First, find the first SYNC block - */ - o = 0; - e = fifolog_reader_findsync(fr->ff, &o); - if (e == 0) - return (0); /* empty fifolog */ - assert(e == 1); - - assert(fr->ff->recbuf[4] & FIFOLOG_FLG_SYNC); - seq = be32dec(fr->ff->recbuf); - t = be32dec(fr->ff->recbuf + 5); - - if (t > t0) { - /* Check if there is a second older part we can use */ - retval = fifolog_int_findend(fr->ff, &s); - if (retval != NULL) - err(1, "%s", retval); - s++; - e = fifolog_reader_findsync(fr->ff, &s); - if (e == 0) - return (0); /* empty fifolog */ - if (e == 1) { - o = s; - seq = be32dec(fr->ff->recbuf); - t = be32dec(fr->ff->recbuf + 5); - } - } - - /* Now do a binary search to find the sync block right before t0 */ - s = st = (fr->ff->logsize - o) / 2; - while (s > 1) { - /* We know we shouldn't wrap */ - if (o + st > fr->ff->logsize + 1) { - s = st = s / 2; - continue; - } - e = fifolog_int_read(fr->ff, o + st); - if (e) { - s = st = s / 2; - continue; - } - /* If not in same part, sequence won't match */ - seqs = be32dec(fr->ff->recbuf); - if (seqs != seq + st) { - s = st = s / 2; - continue; - } - /* If not sync block, try next */ - if (!(fr->ff->recbuf[4] & FIFOLOG_FLG_SYNC)) { - st++; - continue; - } - /* Check timestamp */ - tt = be32dec(fr->ff->recbuf + 5); - if (tt >= t0) { - s = st = s / 2; - continue; - } - o += st; - seq = seqs; - } - fprintf(stderr, "Read from %jx\n", o * fr->ff->recsize); - return (o); -} - -static unsigned char * -fifolog_reader_chop(struct fifolog_reader *fr, fifolog_reader_render_t *func, void *priv) -{ - u_char *p, *q; - uint32_t v, w, u; - - p = fr->obuf; - q = fr->obuf + (fr->olen - fr->ff->zs->avail_out); - - while (1) { - /* Make sure we have a complete header */ - if (p + 5 >= q) - return (p); - w = 4; - u = be32dec(p); - if (u & FIFOLOG_TIMESTAMP) { - fr->now = be32dec(p + 4); - w += 4; - } - if (u & FIFOLOG_LENGTH) { - v = p[w]; - w++; - if (p + w + v >= q) - return (p); - } else { - for (v = 0; p + v + w < q && p[v + w] != '\0'; v++) - continue; - if (p + v + w >= q) - return (p); - v++; - } - func(priv, fr->now, u, p + w, v); - p += w + v; - } -} - -/* - * Process fifolog until end of written log or provided timestamp - */ - -void -fifolog_reader_process(struct fifolog_reader *fr, off_t from, fifolog_reader_render_t *func, void *priv, time_t end) -{ - uint32_t seq, lseq; - off_t o = from; - int i, e; - time_t t; - u_char *p, *q; - z_stream *zs; - - CHECK_OBJ_NOTNULL(fr, FIFOLOG_READER_MAGIC); - zs = fr->ff->zs; - lseq = 0; - while (1) { - e = fifolog_int_read(fr->ff, o); - if (e) - err(1, "Read error (%d)", e); - if (++o >= fr->ff->logsize) - o = 0; - seq = be32dec(fr->ff->recbuf); - if (lseq != 0 && seq != lseq + 1) - break; - lseq = seq; - zs->avail_in = fr->ff->recsize - 5; - zs->next_in = fr->ff->recbuf + 5; - if (fr->ff->recbuf[4] & FIFOLOG_FLG_1BYTE) - zs->avail_in -= fr->ff->recbuf[fr->ff->recsize - 1]; - if (fr->ff->recbuf[4] & FIFOLOG_FLG_4BYTE) - zs->avail_in -= - be32dec(fr->ff->recbuf + fr->ff->recsize - 4); - if (fr->ff->recbuf[4] & FIFOLOG_FLG_SYNC) { - i = inflateReset(zs); - assert(i == Z_OK); - zs->next_out = fr->obuf; - zs->avail_out = fr->olen; - t = be32dec(fr->ff->recbuf + 5); - if (t > end) - break; - zs->next_in += 4; - zs->avail_in -= 4; - } - - while(zs->avail_in > 0) { - i = inflate(zs, 0); - if (i == Z_BUF_ERROR) { -#if 1 - fprintf(stderr, - "Z_BUF_ERROR [%d,%d] [%d,%d,%d]\n", - (int)(zs->next_in - fr->ff->recbuf), - zs->avail_in, - (int)(zs->next_out - fr->obuf), - zs->avail_out, fr->olen); - exit (250); -#else - - i = Z_OK; -#endif - } - if (i == Z_STREAM_END) { - i = inflateReset(zs); - } - if (i != Z_OK) { - fprintf(stderr, "inflate = %d\n", i); - exit (250); - } - assert(i == Z_OK); - if (zs->avail_out != fr->olen) { - q = fr->obuf + (fr->olen - zs->avail_out); - p = fifolog_reader_chop(fr, func, priv); - if (p < q) - (void)memmove(fr->obuf, p, q - p); - zs->avail_out = fr->olen - (q - p); - zs->next_out = fr->obuf + (q - p); - } - } - } -} diff --git a/usr.sbin/fifolog/lib/fifolog_write.h b/usr.sbin/fifolog/lib/fifolog_write.h deleted file mode 100644 index 06b3233..0000000 --- a/usr.sbin/fifolog/lib/fifolog_write.h +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#define FIFOLOG_PT_BYTES_PRE 0 -#define FIFOLOG_PT_BYTES_POST 1 -#define FIFOLOG_PT_WRITES 2 -#define FIFOLOG_PT_FLUSH 3 -#define FIFOLOG_PT_SYNC 4 -#define FIFOLOG_PT_RUNTIME 5 -#define FIFOLOG_NPOINT 6 - -struct fifolog_writer { - unsigned magic; -#define FIFOLOG_WRITER_MAGIC 0xf1f0706 - - struct fifolog_file *ff; - - unsigned writerate; - unsigned syncrate; - unsigned compression; - - unsigned writes_since_sync; - - int cleanup; - - intmax_t cnt[FIFOLOG_NPOINT]; - - uint32_t seq; - off_t recno; - int flag; - time_t last; - - u_int ibufsize; - u_char *ibuf; - u_char *iptr; - - time_t starttime; - time_t lastwrite; - time_t lastsync; -}; diff --git a/usr.sbin/fifolog/lib/fifolog_write_poll.c b/usr.sbin/fifolog/lib/fifolog_write_poll.c deleted file mode 100644 index 4fc5204..0000000 --- a/usr.sbin/fifolog/lib/fifolog_write_poll.c +++ /dev/null @@ -1,417 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fifolog.h" -#include "libfifolog.h" -#include "libfifolog_int.h" -#include "fifolog_write.h" -#include "miniobj.h" - -#define ALLOC(ptr, size) do { \ - (*(ptr)) = calloc(size, 1); \ - assert(*(ptr) != NULL); \ -} while (0) - - -const char *fifolog_write_statnames[] = { -[FIFOLOG_PT_BYTES_PRE] = "Bytes before compression", -[FIFOLOG_PT_BYTES_POST] = "Bytes after compression", -[FIFOLOG_PT_WRITES] = "Writes", -[FIFOLOG_PT_FLUSH] = "Flushes", -[FIFOLOG_PT_SYNC] = "Syncs", -[FIFOLOG_PT_RUNTIME] = "Runtime" -}; - -/* - * Check that everything is all right - */ -static void -fifolog_write_assert(const struct fifolog_writer *f) -{ - - CHECK_OBJ_NOTNULL(f, FIFOLOG_WRITER_MAGIC); - assert(f->iptr == f->ff->zs->next_in + f->ff->zs->avail_in); - assert(f->ff->zs->next_out + f->ff->zs->avail_out == \ - f->ff->recbuf + f->ff->recsize); -} - -struct fifolog_writer * -fifolog_write_new(void) -{ - struct fifolog_writer *f; - - ALLOC(&f, sizeof *f); - f->magic = FIFOLOG_WRITER_MAGIC; - return (f); -} - -void -fifolog_write_destroy(struct fifolog_writer *f) -{ - CHECK_OBJ_NOTNULL(f, FIFOLOG_WRITER_MAGIC); - free(f); -} - -void -fifolog_write_close(struct fifolog_writer *f) -{ - - CHECK_OBJ_NOTNULL(f, FIFOLOG_WRITER_MAGIC); - fifolog_int_close(&f->ff); - free(f->ff); - if (f->ibuf != NULL) - free(f->ibuf); - free(f); -} - -static void -fifo_prepobuf(struct fifolog_writer *f, time_t now, int flag) -{ - - memset(f->ff->recbuf, 0, f->ff->recsize); - f->ff->zs->next_out = f->ff->recbuf + 5; - f->ff->zs->avail_out = f->ff->recsize - 5; - if (f->recno == 0 && f->seq == 0) { - srandomdev(); - do { - f->seq = random(); - } while (f->seq == 0); - } - be32enc(f->ff->recbuf, f->seq++); - f->ff->recbuf[4] = f->flag; - f->flag = 0; - if (flag) { - f->ff->recbuf[4] |= FIFOLOG_FLG_SYNC; - be32enc(f->ff->recbuf + 5, (u_int)now); - f->ff->zs->next_out += 4; - f->ff->zs->avail_out -= 4; - } - fifolog_write_assert(f); -} - -const char * -fifolog_write_open(struct fifolog_writer *f, const char *fn, unsigned writerate, unsigned syncrate, int compression) -{ - const char *es; - int i; - time_t now; - off_t o; - - CHECK_OBJ_NOTNULL(f, FIFOLOG_WRITER_MAGIC); - - /* Check for legal compression value */ - if (compression < Z_DEFAULT_COMPRESSION || - compression > Z_BEST_COMPRESSION) - return ("Illegal compression value"); - - f->writerate = writerate; - f->syncrate = syncrate; - f->compression = compression; - - /* Reset statistics */ - memset(f->cnt, 0, sizeof f->cnt); - - es = fifolog_int_open(&f->ff, fn, 1); - if (es != NULL) - return (es); - es = fifolog_int_findend(f->ff, &o); - if (es != NULL) - return (es); - i = fifolog_int_read(f->ff, o); - if (i) - return ("Read error, looking for seq"); - f->seq = be32dec(f->ff->recbuf); - if (f->seq == 0) { - /* Empty fifolog */ - f->seq = random(); - } else { - f->recno = o + 1; - f->seq++; - } - - f->ibufsize = 32768; - ALLOC(&f->ibuf, f->ibufsize); - f->iptr = f->ibuf; - f->ff->zs->next_in = f->iptr; - i = deflateInit(f->ff->zs, (int)f->compression); - assert(i == Z_OK); - - f->flag |= FIFOLOG_FLG_RESTART; - - time(&now); - fifo_prepobuf(f, now, 1); - f->starttime = now; - - fifolog_write_assert(f); - return (NULL); -} - -static void -fifo_writerec(struct fifolog_writer *f) -{ - int i; - time_t t; - - fifolog_write_assert(f); - f->writes_since_sync++; - - assert(f->recno < f->ff->logsize); - f->cnt[FIFOLOG_PT_BYTES_POST] += f->ff->recsize - f->ff->zs->avail_out; - if (f->ff->zs->avail_out == 0) { - /* nothing */ - } else if (f->ff->zs->avail_out <= 255) { - f->ff->recbuf[f->ff->recsize - 1] = - (u_char)f->ff->zs->avail_out; - f->ff->recbuf[4] |= FIFOLOG_FLG_1BYTE; - } else { - be32enc(f->ff->recbuf + f->ff->recsize - 4, - f->ff->zs->avail_out); - f->ff->recbuf[4] |= FIFOLOG_FLG_4BYTE; - } - i = pwrite(f->ff->fd, f->ff->recbuf, f->ff->recsize, - (f->recno + 1) * f->ff->recsize); - assert (i == (int)f->ff->recsize); - if (++f->recno == f->ff->logsize) - f->recno = 0; - f->cnt[FIFOLOG_PT_WRITES]++; - time(&t); - f->cnt[FIFOLOG_PT_RUNTIME] = t - f->starttime; /*lint !e776 */ - fifolog_write_assert(f); -} - -int -fifolog_write_poll(struct fifolog_writer *f, time_t now) -{ - int i, fl, bo, bf; - - if (now == 0) - time(&now); - - fifolog_write_assert(f); - if (f->cleanup || now >= (int)(f->lastsync + f->syncrate)) { - /* - * We always check the sync timer, otherwise a flood of data - * would not get any sync records at all - */ - f->cleanup = 0; - fl = Z_FINISH; - f->lastsync = now; - f->lastwrite = now; - f->cnt[FIFOLOG_PT_SYNC]++; - } else if (f->ff->zs->avail_in == 0 && - now >= (int)(f->lastwrite + f->writerate)) { - /* - * We only check for writerate timeouts when the input - * buffer is empty. It would be silly to force a write if - * pending input could cause it to happen on its own. - */ - fl = Z_SYNC_FLUSH; - f->lastwrite = now; - f->cnt[FIFOLOG_PT_FLUSH]++; - } else if (f->ff->zs->avail_in == 0) - return (0); /* nothing to do */ - else - fl = Z_NO_FLUSH; - - for (;;) { - assert(f->ff->zs->avail_out > 0); - - bf = f->ff->zs->avail_out; - - i = deflate(f->ff->zs, fl); - assert (i == Z_OK || i == Z_BUF_ERROR || i == Z_STREAM_END); - - bo = f->ff->zs->avail_out; - - /* If we have output space and not in a hurry.. */ - if (bo > 0 && fl == Z_NO_FLUSH) - break; - - /* Write output buffer, if anything in it */ - if (bo != bf) - fifo_writerec(f); - - /* If the buffer were full, we need to check again */ - if (bo == 0) { - fifo_prepobuf(f, now, 0); - continue; - } - - if (fl == Z_FINISH) { - /* Make next record a SYNC record */ - fifo_prepobuf(f, now, 1); - /* And reset the zlib engine */ - i = deflateReset(f->ff->zs); - assert(i == Z_OK); - f->writes_since_sync = 0; - } else { - fifo_prepobuf(f, now, 0); - } - break; - } - - if (f->ff->zs->avail_in == 0) { - /* Reset input buffer when empty */ - f->iptr = f->ibuf; - f->ff->zs->next_in = f->iptr; - } - - fifolog_write_assert(f); - return (1); -} - -static void -fifolog_acct(struct fifolog_writer *f, unsigned bytes) -{ - - f->ff->zs->avail_in += bytes; - f->iptr += bytes; - f->cnt[FIFOLOG_PT_BYTES_PRE] += bytes; -} - -/* - * Attempt to write an entry. - * Return zero if there is no space, one otherwise - */ - -int -fifolog_write_bytes(struct fifolog_writer *f, uint32_t id, time_t now, const void *ptr, unsigned len) -{ - u_int l; - const unsigned char *p; - - fifolog_write_assert(f); - assert(!(id & (FIFOLOG_TIMESTAMP|FIFOLOG_LENGTH))); - assert(ptr != NULL); - - p = ptr; - if (len == 0) { - len = strlen(ptr) + 1; - l = 4 + len; /* id */ - } else { - assert(len <= 255); - id |= FIFOLOG_LENGTH; - l = 5 + len; /* id + len */ - } - - l += 4; /* A timestamp may be necessary */ - - /* Now do timestamp, if needed */ - if (now == 0) - time(&now); - - assert(l < f->ibufsize); - - /* Return if there is not enough space */ - if (f->iptr + l > f->ibuf + f->ibufsize) - return (0); - - if (now != f->last) { - id |= FIFOLOG_TIMESTAMP; - f->last = now; - } - - /* Emit instance+flag and length */ - be32enc(f->iptr, id); - fifolog_acct(f, 4); - - if (id & FIFOLOG_TIMESTAMP) { - be32enc(f->iptr, (uint32_t)f->last); - fifolog_acct(f, 4); - } - if (id & FIFOLOG_LENGTH) { - f->iptr[0] = (u_char)len; - fifolog_acct(f, 1); - } - - assert (len > 0); - memcpy(f->iptr, p, len); - fifolog_acct(f, len); - fifolog_write_assert(f); - return (1); -} - -/* - * Write an entry, polling until success. - * Long binary entries are broken into 255 byte chunks. - */ - -void -fifolog_write_bytes_poll(struct fifolog_writer *f, uint32_t id, time_t now, const void *ptr, unsigned len) -{ - u_int l; - const unsigned char *p; - - fifolog_write_assert(f); - - assert(!(id & (FIFOLOG_TIMESTAMP|FIFOLOG_LENGTH))); - assert(ptr != NULL); - - if (len == 0) { - while (!fifolog_write_bytes(f, id, now, ptr, len)) { - (void)fifolog_write_poll(f, now); - (void)usleep(10000); - } - } else { - p = ptr; - for (p = ptr; len > 0; len -= l, p += l) { - l = len; - if (l > 255) - l = 255; - while (!fifolog_write_bytes(f, id, now, p, l)) { - (void)fifolog_write_poll(f, now); - (void)usleep(10000); - } - } - } - fifolog_write_assert(f); -} - -int -fifolog_write_flush(struct fifolog_writer *f) -{ - int i; - - fifolog_write_assert(f); - - f->cleanup = 1; - for (i = 0; fifolog_write_poll(f, 0); i = 1) - continue; - fifolog_write_assert(f); - return (i); -} diff --git a/usr.sbin/fifolog/lib/getdate.y b/usr.sbin/fifolog/lib/getdate.y deleted file mode 100644 index 8e63e81..0000000 --- a/usr.sbin/fifolog/lib/getdate.y +++ /dev/null @@ -1,889 +0,0 @@ -%{ -/* -** Originally written by Steven M. Bellovin while -** at the University of North Carolina at Chapel Hill. Later tweaked by -** a couple of people on Usenet. Completely overhauled by Rich $alz -** and Jim Berets in August, 1990; -** -** This grammar has 10 shift/reduce conflicts. -** -** This code is in the public domain and has no copyright. -** -** Picked up from CVS and slightly cleaned up by to WARNS=5 level by -** Poul-Henning Kamp -** -** $FreeBSD$ -*/ - -#include -#include -#include -#include -#include -#include - -#include "libfifolog.h" - -#define yyparse getdate_yyparse -#define yylex getdate_yylex -#define yyerror getdate_yyerror - -static int yyparse(void); -static int yylex(void); -static int yyerror(const char *); - -#define EPOCH 1970 -#define HOUR(x) ((time_t)(x) * 60) -#define SECSPERDAY (24L * 60L * 60L) - - -/* -** An entry in the lexical lookup table. -*/ -typedef struct _TABLE { - const char *name; - int type; - time_t value; -} TABLE; - - -/* -** Daylight-savings mode: on, off, or not yet known. -*/ -typedef enum _DSTMODE { - DSToff, DSTon, DSTmaybe -} DSTMODE; - -/* -** Meridian: am, pm, or 24-hour style. -*/ -typedef enum _MERIDIAN { - MERam, MERpm, MER24 -} MERIDIAN; - - -/* -** Global variables. We could get rid of most of these by using a good -** union as the yacc stack. (This routine was originally written before -** yacc had the %union construct.) Maybe someday; right now we only use -** the %union very rarely. -*/ -static char *yyInput; -static DSTMODE yyDSTmode; -static time_t yyDayOrdinal; -static time_t yyDayNumber; -static int yyHaveDate; -static int yyHaveDay; -static int yyHaveRel; -static int yyHaveTime; -static int yyHaveZone; -static time_t yyTimezone; -static time_t yyDay; -static time_t yyHour; -static time_t yyMinutes; -static time_t yyMonth; -static time_t yySeconds; -static time_t yyYear; -static MERIDIAN yyMeridian; -static time_t yyRelMonth; -static time_t yyRelSeconds; - -%} - -%union { - time_t Number; - enum _MERIDIAN Meridian; -} - -%token tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT -%token tSEC_UNIT tSNUMBER tUNUMBER tZONE tDST - -%type tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT -%type tSEC_UNIT tSNUMBER tUNUMBER tZONE -%type tMERIDIAN o_merid - -%% - -spec : /* NULL */ - | spec item - ; - -item : time { - yyHaveTime++; - } - | zone { - yyHaveZone++; - } - | date { - yyHaveDate++; - } - | day { - yyHaveDay++; - } - | rel { - yyHaveRel++; - } - | cvsstamp { - yyHaveTime++; - yyHaveDate++; - yyHaveZone++; - } - | number - ; - -cvsstamp: tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER '.' tUNUMBER { - yyYear = $1; - if (yyYear < 100) yyYear += 1900; - yyMonth = $3; - yyDay = $5; - yyHour = $7; - yyMinutes = $9; - yySeconds = $11; - yyDSTmode = DSToff; - yyTimezone = 0; - } - ; - -time : tUNUMBER tMERIDIAN { - yyHour = $1; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = $2; - } - | tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = 0; - yyMeridian = $4; - } - | tUNUMBER ':' tUNUMBER tSNUMBER { - yyHour = $1; - yyMinutes = $3; - yyMeridian = MER24; - yyDSTmode = DSToff; - yyTimezone = - ($4 % 100 + ($4 / 100) * 60); - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = $6; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = MER24; - yyDSTmode = DSToff; - yyTimezone = - ($6 % 100 + ($6 / 100) * 60); - } - ; - -zone : tZONE { - yyTimezone = $1; - yyDSTmode = DSToff; - } - | tDAYZONE { - yyTimezone = $1; - yyDSTmode = DSTon; - } - | - tZONE tDST { - yyTimezone = $1; - yyDSTmode = DSTon; - } - ; - -day : tDAY { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tDAY ',' { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tUNUMBER tDAY { - yyDayOrdinal = $1; - yyDayNumber = $2; - } - ; - -date : tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - } - | tUNUMBER '/' tUNUMBER '/' tUNUMBER { - if ($1 >= 100) { - yyYear = $1; - yyMonth = $3; - yyDay = $5; - } else { - yyMonth = $1; - yyDay = $3; - yyYear = $5; - } - } - | tUNUMBER tSNUMBER tSNUMBER { - /* ISO 8601 format. yyyy-mm-dd. */ - yyYear = $1; - yyMonth = -$2; - yyDay = -$3; - } - | tUNUMBER tMONTH tSNUMBER { - /* e.g. 17-JUN-1992. */ - yyDay = $1; - yyMonth = $2; - yyYear = -$3; - } - | tMONTH tUNUMBER { - yyMonth = $1; - yyDay = $2; - } - | tMONTH tUNUMBER ',' tUNUMBER { - yyMonth = $1; - yyDay = $2; - yyYear = $4; - } - | tUNUMBER tMONTH { - yyMonth = $2; - yyDay = $1; - } - | tUNUMBER tMONTH tUNUMBER { - yyMonth = $2; - yyDay = $1; - yyYear = $3; - } - ; - -rel : relunit tAGO { - yyRelSeconds = -yyRelSeconds; - yyRelMonth = -yyRelMonth; - } - | relunit - ; - -relunit : tUNUMBER tMINUTE_UNIT { - yyRelSeconds += $1 * $2 * 60L; - } - | tSNUMBER tMINUTE_UNIT { - yyRelSeconds += $1 * $2 * 60L; - } - | tMINUTE_UNIT { - yyRelSeconds += $1 * 60L; - } - | tSNUMBER tSEC_UNIT { - yyRelSeconds += $1; - } - | tUNUMBER tSEC_UNIT { - yyRelSeconds += $1; - } - | tSEC_UNIT { - yyRelSeconds++; - } - | tSNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tMONTH_UNIT { - yyRelMonth += $1; - } - ; - -number : tUNUMBER { - if (yyHaveTime && yyHaveDate && !yyHaveRel) - yyYear = $1; - else { - if($1>10000) { - yyHaveDate++; - yyDay= ($1)%100; - yyMonth= ($1/100)%100; - yyYear = $1/10000; - } - else { - yyHaveTime++; - if ($1 < 100) { - yyHour = $1; - yyMinutes = 0; - } - else { - yyHour = $1 / 100; - yyMinutes = $1 % 100; - } - yySeconds = 0; - yyMeridian = MER24; - } - } - } - ; - -o_merid : /* NULL */ { - $$ = MER24; - } - | tMERIDIAN { - $$ = $1; - } - ; - -%% - -/* Month and day table. */ -static TABLE const MonthDayTable[] = { - { "january", tMONTH, 1 }, - { "february", tMONTH, 2 }, - { "march", tMONTH, 3 }, - { "april", tMONTH, 4 }, - { "may", tMONTH, 5 }, - { "june", tMONTH, 6 }, - { "july", tMONTH, 7 }, - { "august", tMONTH, 8 }, - { "september", tMONTH, 9 }, - { "sept", tMONTH, 9 }, - { "october", tMONTH, 10 }, - { "november", tMONTH, 11 }, - { "december", tMONTH, 12 }, - { "sunday", tDAY, 0 }, - { "monday", tDAY, 1 }, - { "tuesday", tDAY, 2 }, - { "tues", tDAY, 2 }, - { "wednesday", tDAY, 3 }, - { "wednes", tDAY, 3 }, - { "thursday", tDAY, 4 }, - { "thur", tDAY, 4 }, - { "thurs", tDAY, 4 }, - { "friday", tDAY, 5 }, - { "saturday", tDAY, 6 }, - { NULL, 0, 0 } -}; - -/* Time units table. */ -static TABLE const UnitsTable[] = { - { "year", tMONTH_UNIT, 12 }, - { "month", tMONTH_UNIT, 1 }, - { "fortnight", tMINUTE_UNIT, 14 * 24 * 60 }, - { "week", tMINUTE_UNIT, 7 * 24 * 60 }, - { "day", tMINUTE_UNIT, 1 * 24 * 60 }, - { "hour", tMINUTE_UNIT, 60 }, - { "minute", tMINUTE_UNIT, 1 }, - { "min", tMINUTE_UNIT, 1 }, - { "second", tSEC_UNIT, 1 }, - { "sec", tSEC_UNIT, 1 }, - { NULL, 0, 0 } -}; - -/* Assorted relative-time words. */ -static TABLE const OtherTable[] = { - { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 }, - { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 }, - { "today", tMINUTE_UNIT, 0 }, - { "now", tMINUTE_UNIT, 0 }, - { "last", tUNUMBER, -1 }, - { "this", tMINUTE_UNIT, 0 }, - { "next", tUNUMBER, 2 }, - { "first", tUNUMBER, 1 }, -/* { "second", tUNUMBER, 2 }, */ - { "third", tUNUMBER, 3 }, - { "fourth", tUNUMBER, 4 }, - { "fifth", tUNUMBER, 5 }, - { "sixth", tUNUMBER, 6 }, - { "seventh", tUNUMBER, 7 }, - { "eighth", tUNUMBER, 8 }, - { "ninth", tUNUMBER, 9 }, - { "tenth", tUNUMBER, 10 }, - { "eleventh", tUNUMBER, 11 }, - { "twelfth", tUNUMBER, 12 }, - { "ago", tAGO, 1 }, - { NULL, 0, 0 } -}; - -/* The timezone table. */ -/* Some of these are commented out because a time_t can't store a float. */ -static TABLE const TimezoneTable[] = { - { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */ - { "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */ - { "utc", tZONE, HOUR( 0) }, - { "wet", tZONE, HOUR( 0) }, /* Western European */ - { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */ - { "wat", tZONE, HOUR( 1) }, /* West Africa */ - { "at", tZONE, HOUR( 2) }, /* Azores */ -#if 0 - /* For completeness. BST is also British Summer, and GST is - * also Guam Standard. */ - { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */ - { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */ -#endif -#if 0 - { "nft", tZONE, HOUR(3.5) }, /* Newfoundland */ - { "nst", tZONE, HOUR(3.5) }, /* Newfoundland Standard */ - { "ndt", tDAYZONE, HOUR(3.5) }, /* Newfoundland Daylight */ -#endif - { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */ - { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */ - { "est", tZONE, HOUR( 5) }, /* Eastern Standard */ - { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */ - { "cst", tZONE, HOUR( 6) }, /* Central Standard */ - { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */ - { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */ - { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */ - { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */ - { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */ - { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */ - { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */ - { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */ - { "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */ - { "cat", tZONE, HOUR(10) }, /* Central Alaska */ - { "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */ - { "nt", tZONE, HOUR(11) }, /* Nome */ - { "idlw", tZONE, HOUR(12) }, /* International Date Line West */ - { "cet", tZONE, -HOUR(1) }, /* Central European */ - { "met", tZONE, -HOUR(1) }, /* Middle European */ - { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */ - { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */ - { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */ - { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */ - { "fwt", tZONE, -HOUR(1) }, /* French Winter */ - { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */ - { "eet", tZONE, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */ - { "bt", tZONE, -HOUR(3) }, /* Baghdad, USSR Zone 2 */ -#if 0 - { "it", tZONE, -HOUR(3.5) },/* Iran */ -#endif - { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */ - { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */ -#if 0 - { "ist", tZONE, -HOUR(5.5) },/* Indian Standard */ -#endif - { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */ -#if 0 - /* For completeness. NST is also Newfoundland Stanard, and SST is - * also Swedish Summer. */ - { "nst", tZONE, -HOUR(6.5) },/* North Sumatra */ - { "sst", tZONE, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */ -#endif /* 0 */ - { "wast", tZONE, -HOUR(7) }, /* West Australian Standard */ - { "wadt", tDAYZONE, -HOUR(7) }, /* West Australian Daylight */ -#if 0 - { "jt", tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */ -#endif - { "cct", tZONE, -HOUR(8) }, /* China Coast, USSR Zone 7 */ - { "jst", tZONE, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */ -#if 0 - { "cast", tZONE, -HOUR(9.5) },/* Central Australian Standard */ - { "cadt", tDAYZONE, -HOUR(9.5) },/* Central Australian Daylight */ -#endif - { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */ - { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */ - { "gst", tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */ - { "nzt", tZONE, -HOUR(12) }, /* New Zealand */ - { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */ - { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */ - { "idle", tZONE, -HOUR(12) }, /* International Date Line East */ - { NULL, 0, 0 } -}; - -/* Military timezone table. */ -static TABLE const MilitaryTable[] = { - { "a", tZONE, HOUR( 1) }, - { "b", tZONE, HOUR( 2) }, - { "c", tZONE, HOUR( 3) }, - { "d", tZONE, HOUR( 4) }, - { "e", tZONE, HOUR( 5) }, - { "f", tZONE, HOUR( 6) }, - { "g", tZONE, HOUR( 7) }, - { "h", tZONE, HOUR( 8) }, - { "i", tZONE, HOUR( 9) }, - { "k", tZONE, HOUR( 10) }, - { "l", tZONE, HOUR( 11) }, - { "m", tZONE, HOUR( 12) }, - { "n", tZONE, HOUR(- 1) }, - { "o", tZONE, HOUR(- 2) }, - { "p", tZONE, HOUR(- 3) }, - { "q", tZONE, HOUR(- 4) }, - { "r", tZONE, HOUR(- 5) }, - { "s", tZONE, HOUR(- 6) }, - { "t", tZONE, HOUR(- 7) }, - { "u", tZONE, HOUR(- 8) }, - { "v", tZONE, HOUR(- 9) }, - { "w", tZONE, HOUR(-10) }, - { "x", tZONE, HOUR(-11) }, - { "y", tZONE, HOUR(-12) }, - { "z", tZONE, HOUR( 0) }, - { NULL, 0, 0 } -}; - - - - -/* ARGSUSED */ -static int -yyerror(const char *s __unused) -{ - return 0; -} - - -static time_t -ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian) -{ - if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) - return -1; - switch (Meridian) { - case MER24: - if (Hours < 0 || Hours > 23) - return -1; - return (Hours * 60L + Minutes) * 60L + Seconds; - case MERam: - if (Hours < 1 || Hours > 12) - return -1; - if (Hours == 12) - Hours = 0; - return (Hours * 60L + Minutes) * 60L + Seconds; - case MERpm: - if (Hours < 1 || Hours > 12) - return -1; - if (Hours == 12) - Hours = 0; - return ((Hours + 12) * 60L + Minutes) * 60L + Seconds; - default: - abort (); - } - /* NOTREACHED */ -} - - -/* Year is either - * A negative number, which means to use its absolute value (why?) - * A number from 0 to 99, which means a year from 1900 to 1999, or - * The actual year (>=100). */ -static time_t -Convert(time_t Month, time_t Day, time_t Year, - time_t Hours, time_t Minutes, time_t Seconds, - MERIDIAN Meridian, DSTMODE DSTmode) -{ - static int DaysInMonth[12] = { - 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - time_t tod; - time_t Julian; - int i; - struct tm *ltm; - - if (Year < 0) - Year = -Year; - if (Year < 69) - Year += 2000; - else if (Year < 100) - Year += 1900; - DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) - ? 29 : 28; - /* Checking for 2038 bogusly assumes that time_t is 32 bits. But - I'm too lazy to try to check for time_t overflow in another way. */ - if (Year < EPOCH || Year > 2038 - || Month < 1 || Month > 12 - /* Lint fluff: "conversion from long may lose accuracy" */ - || Day < 1 || Day > DaysInMonth[(int)--Month]) - /* FIXME: - * It would be nice to set a global error string here. - * "February 30 is not a valid date" is much more informative than - * "Can't parse date/time: 100 months" when the user input was - * "100 months" and addition resolved that to February 30, for - * example. See rcs2-7 in src/sanity.sh for more. */ - return -1; - - for (Julian = Day - 1, i = 0; i < Month; i++) - Julian += DaysInMonth[i]; - for (i = EPOCH; i < Year; i++) - Julian += 365 + (i % 4 == 0); - Julian *= SECSPERDAY; - Julian += yyTimezone * 60L; - if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0) - return -1; - Julian += tod; - ltm = localtime(&Julian); -fprintf(stderr, "DST %d TZ %s %d\n", DSTmode, ltm->tm_zone, ltm->tm_isdst); - if (DSTmode == DSTon - || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) - Julian -= 60 * 60; - return Julian; -} - - -static time_t -DSTcorrect(time_t Start, time_t Future) -{ - time_t StartDay; - time_t FutureDay; - - StartDay = (localtime(&Start)->tm_hour + 1) % 24; - FutureDay = (localtime(&Future)->tm_hour + 1) % 24; - return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; -} - - -static time_t -RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber) -{ - struct tm *tm; - time_t now; - - now = Start; - tm = localtime(&now); - now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); - now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); - return DSTcorrect(Start, now); -} - - -static time_t -RelativeMonth(time_t Start, time_t RelMonth) -{ - struct tm *tm; - time_t Month; - time_t Year; - - if (RelMonth == 0) - return 0; - tm = localtime(&Start); - Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth; - Year = Month / 12; - Month = Month % 12 + 1; - return DSTcorrect(Start, - Convert(Month, (time_t)tm->tm_mday, Year, - (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, - MER24, DSTmaybe)); -} - - -static int -LookupWord(char *buff) -{ - char *p; - char *q; - const TABLE *tp; - int i; - int abbrev; - - /* Make it lowercase. */ - for (p = buff; *p; p++) - if (isupper(*p)) - *p = tolower(*p); - - if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) { - yylval.Meridian = MERam; - return tMERIDIAN; - } - if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) { - yylval.Meridian = MERpm; - return tMERIDIAN; - } - - /* See if we have an abbreviation for a month. */ - if (strlen(buff) == 3) - abbrev = 1; - else if (strlen(buff) == 4 && buff[3] == '.') { - abbrev = 1; - buff[3] = '\0'; - } - else - abbrev = 0; - - for (tp = MonthDayTable; tp->name; tp++) { - if (abbrev) { - if (strncmp(buff, tp->name, 3) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - else if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - if (strcmp(buff, "dst") == 0) - return tDST; - - for (tp = UnitsTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Strip off any plural and try the units table again. */ - i = strlen(buff) - 1; - if (buff[i] == 's') { - buff[i] = '\0'; - for (tp = UnitsTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - buff[i] = 's'; /* Put back for "this" in OtherTable. */ - } - - for (tp = OtherTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Military timezones. */ - if (buff[1] == '\0' && isalpha(*buff)) { - for (tp = MilitaryTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - - /* Drop out any periods and try the timezone table again. */ - for (i = 0, p = q = buff; *q; q++) - if (*q != '.') - *p++ = *q; - else - i++; - *p = '\0'; - if (i) - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - return tID; -} - - -static int -yylex(void) -{ - char c; - char *p; - char buff[20]; - int Count; - int sign; - - for ( ; ; ) { - while (isspace(*yyInput)) - yyInput++; - - if (isdigit(c = *yyInput) || c == '-' || c == '+') { - if (c == '-' || c == '+') { - sign = c == '-' ? -1 : 1; - if (!isdigit(*++yyInput)) - /* skip the '-' sign */ - continue; - } - else - sign = 0; - for (yylval.Number = 0; isdigit(c = *yyInput++); ) - yylval.Number = 10 * yylval.Number + c - '0'; - yyInput--; - if (sign < 0) - yylval.Number = -yylval.Number; - return sign ? tSNUMBER : tUNUMBER; - } - if (isalpha(c)) { - for (p = buff; isalpha(c = *yyInput++) || c == '.'; ) - if (p < &buff[sizeof buff - 1]) - *p++ = c; - *p = '\0'; - yyInput--; - return LookupWord(buff); - } - if (c != '(') - return *yyInput++; - Count = 0; - do { - c = *yyInput++; - if (c == '\0') - return c; - if (c == '(') - Count++; - else if (c == ')') - Count--; - } while (Count > 0); - } -} - -#define TM_YEAR_ORIGIN 1900 - -time_t -get_date(char *p) -{ - struct tm *tm, gmt; - time_t Start; - time_t tod; - time_t nowtime; - struct tm *gmt_ptr; - - yyInput = p; - - (void)time (&nowtime); - - gmt_ptr = gmtime (&nowtime); - if (gmt_ptr != NULL) - { - /* Make a copy, in case localtime modifies *tm (I think - that comment now applies to *gmt_ptr, but I am too - lazy to dig into how gmtime and locatime allocate the - structures they return pointers to). */ - gmt = *gmt_ptr; - } - - if (! (tm = localtime (&nowtime))) - return -1; - - tm = localtime(&nowtime); - yyYear = tm->tm_year + 1900; - yyMonth = tm->tm_mon + 1; - yyDay = tm->tm_mday; - yyTimezone = tm->tm_gmtoff; - yyDSTmode = DSTmaybe; - yyHour = 0; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = MER24; - yyRelSeconds = 0; - yyRelMonth = 0; - yyHaveDate = 0; - yyHaveDay = 0; - yyHaveRel = 0; - yyHaveTime = 0; - yyHaveZone = 0; - - if (yyparse() - || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1) - return -1; - - if (yyHaveDate || yyHaveTime || yyHaveDay) { - Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, - yyMeridian, yyDSTmode); - if (Start < 0) - return -1; - } - else { - Start = nowtime; - if (!yyHaveRel) - Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec; - } - - Start += yyRelSeconds; - Start += RelativeMonth(Start, yyRelMonth); - - if (yyHaveDay && !yyHaveDate) { - tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber); - Start += tod; - } - - /* Have to do *something* with a legitimate -1 so it's distinguishable - * from the error return value. (Alternately could set errno on error.) */ - return Start == -1 ? 0 : Start; -} diff --git a/usr.sbin/fifolog/lib/libfifolog.h b/usr.sbin/fifolog/lib/libfifolog.h deleted file mode 100644 index 430e72b..0000000 --- a/usr.sbin/fifolog/lib/libfifolog.h +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include - -/* CREATORS */ -const char *fifolog_create(const char *fn, off_t size, unsigned recsize); - - -/* WRITERS */ - -struct fifolog_writer; -struct fifolog_writer *fifolog_write_new(void); -const char *fifolog_write_open(struct fifolog_writer *f, const char *fn, unsigned writerate, unsigned syncrate, int compression); -int fifolog_write_bytes(struct fifolog_writer *f, uint32_t id, time_t now, const void *ptr, unsigned len); -void fifolog_write_bytes_poll(struct fifolog_writer *f, uint32_t id, time_t now, const void *ptr, unsigned len); -int fifolog_write_poll(struct fifolog_writer *f, time_t now); -void fifolog_write_close(struct fifolog_writer *f); -void fifolog_write_destroy(struct fifolog_writer *f); -int fifolog_write_flush(struct fifolog_writer *f); -extern const char *fifolog_write_statnames[]; - -/* READERS */ - -typedef void fifolog_reader_render_t(void *priv, time_t when, unsigned flag, const unsigned char *p, unsigned l); -struct fifolog_reader; -struct fifolog_reader *fifolog_reader_open(const char *fname); -off_t fifolog_reader_seek(const struct fifolog_reader *fl, time_t t0); -void fifolog_reader_process(struct fifolog_reader *fl, off_t from, fifolog_reader_render_t *func, void *priv, time_t end); - -/* UTILS */ -time_t get_date(char *p); - -#if (__FreeBSD__ < 7) -int expand_number(char *_buf, int64_t *_num); -#endif - diff --git a/usr.sbin/fifolog/lib/libfifolog_int.h b/usr.sbin/fifolog/lib/libfifolog_int.h deleted file mode 100644 index 54ab897..0000000 --- a/usr.sbin/fifolog/lib/libfifolog_int.h +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * Copyright (c) 2005-2008 - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -struct fifolog_file { - unsigned magic; -#define FIFOLOG_FILE_MAGIC 0x307ea50d - - unsigned recsize; - off_t logsize; - int fd; - - z_stream *zs; - - unsigned char *recbuf; -}; - -const char *fifolog_int_open(struct fifolog_file **ff, const char *fname, int mode); -void fifolog_int_close(struct fifolog_file **ff); -int fifolog_int_read(const struct fifolog_file *ff, off_t recno); -const char *fifolog_int_findend(const struct fifolog_file *ff, off_t *last); diff --git a/usr.sbin/fifolog/lib/miniobj.h b/usr.sbin/fifolog/lib/miniobj.h deleted file mode 100644 index a805316..0000000 --- a/usr.sbin/fifolog/lib/miniobj.h +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * Copyright (c) 2005-2008 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#define ALLOC_OBJ(to, type_magic) \ - do { \ - (to) = calloc(sizeof *(to), 1); \ - assert((to) != NULL); \ - (to)->magic = (type_magic); \ - } while (0) - -#define FREE_OBJ(to) \ - do { \ - (to)->magic = (0); \ - free(to); \ - } while (0) - -#define CHECK_OBJ(ptr, type_magic) \ - do { \ - assert((ptr)->magic == type_magic); \ - } while (0) - -#define CHECK_OBJ_NOTNULL(ptr, type_magic) \ - do { \ - assert((ptr) != NULL); \ - assert((ptr)->magic == type_magic); \ - } while (0) - -#define CAST_OBJ(to, from, type_magic) \ - do { \ - (to) = (from); \ - if ((to) != NULL) \ - CHECK_OBJ((to), (type_magic)); \ - } while (0) - -#define CAST_OBJ_NOTNULL(to, from, type_magic) \ - do { \ - (to) = (from); \ - assert((to) != NULL); \ - CHECK_OBJ((to), (type_magic)); \ - } while (0) - diff --git a/usr.sbin/flowctl/Makefile b/usr.sbin/flowctl/Makefile deleted file mode 100644 index d47993b..0000000 --- a/usr.sbin/flowctl/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# -# $FreeBSD$ -# - -PROG= flowctl -MAN= flowctl.8 - -WARNS?= 2 -DPADD= ${LIBNETGRAPH} -LDADD= -lnetgraph - -.include diff --git a/usr.sbin/flowctl/flowctl.8 b/usr.sbin/flowctl/flowctl.8 deleted file mode 100644 index cf1396b..0000000 --- a/usr.sbin/flowctl/flowctl.8 +++ /dev/null @@ -1,83 +0,0 @@ -.\" Copyright (c) 2004-2005 Gleb Smirnoff -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd March 23, 2005 -.Dt FLOWCTL 8 -.Os -.Sh NAME -.Nm flowctl -.Nd -.Xr ng_netflow 4 -control utility -.Sh SYNOPSIS -.Nm -.Op Fl d Ar level -.Ar node command -.Sh DESCRIPTION -The -.Nm -utility is intended to control the -.Xr ng_netflow 4 -nodes. -It has a single option: -.Bl -tag -width ".Fl d Ar level" -.It Fl d Ar level -Set the -.Xr netgraph 3 -debugging level to -.Ar level . -.El -.Sh COMMANDS -Currently, -.Nm -supports only one command. -.Bl -tag -width ".Cm show" -.It Cm show -This command is the analog of the -.Dq "show ip cache flow" -command of a Cisco router. -It dumps the contents of the flow cache in Cisco-like format. -It has optional parameter -.Cm verbose , -which is analog of the -.Dq "show ip cache verbose flow" -command. -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr netgraph 3 , -.Xr ng_netflow 4 -.Sh AUTHORS -.An -nosplit -The -.Nm -utility was written by -.An Gleb Smirnoff Aq glebius@FreeBSD.org , -based on -.Nm ipacctctl -written by -.An Roman V. Palagin Aq romanp@unshadow.net . diff --git a/usr.sbin/flowctl/flowctl.c b/usr.sbin/flowctl/flowctl.c deleted file mode 100644 index 16f960a..0000000 --- a/usr.sbin/flowctl/flowctl.c +++ /dev/null @@ -1,281 +0,0 @@ -/*- - * Copyright (c) 2004-2005 Gleb Smirnoff - * Copyright (c) 2001-2003 Roman V. Palagin - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $SourceForge: flowctl.c,v 1.15 2004/08/31 20:24:58 glebius Exp $ - */ - -#ifndef lint -static const char rcs_id[] = - "@(#) $FreeBSD$"; -#endif - -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#define CISCO_SH_FLOW_HEADER "SrcIf SrcIPaddress DstIf DstIPaddress Pr SrcP DstP Pkts\n" -#define CISCO_SH_FLOW "%-13s %-15s %-13s %-15s %2u %4.4x %4.4x %6lu\n" - -#define CISCO_SH_VERB_FLOW_HEADER "SrcIf SrcIPaddress DstIf DstIPaddress Pr TOS Flgs Pkts\n" \ -"Port Msk AS Port Msk AS NextHop B/Pk Active\n" - -#define CISCO_SH_VERB_FLOW "%-14s %-15s %-14s %-15s %2u %3x %4x %6lu\n" \ - "%4.4x /%-2u %-5u %4.4x /%-2u %-5u %-15s %9u %8u\n\n" - -static int flow_cache_print(struct ngnf_flows *recs); -static int flow_cache_print_verbose(struct ngnf_flows *recs); -static int ctl_show(int, char **); -static void help(void); -static void execute_command(int, char **); - -struct ip_ctl_cmd { - char *cmd_name; - int (*cmd_func)(int argc, char **argv); -}; - -struct ip_ctl_cmd cmds[] = { - {"show", ctl_show}, - {NULL, NULL}, -}; - -int cs; -char ng_nodename[NG_PATHSIZ]; - -int -main(int argc, char **argv) -{ - int c; - char sname[NG_NODESIZ]; - int rcvbuf = SORCVBUF_SIZE; - char *ng_name; - - /* parse options */ - while ((c = getopt(argc, argv, "d:")) != -1) { - switch (c) { - case 'd': /* set libnetgraph debug level. */ - NgSetDebug(atoi(optarg)); - break; - } - } - - argc -= optind; - argv += optind; - ng_name = argv[0]; - if (ng_name == NULL) - help(); - argc--; - argv++; - - snprintf(ng_nodename, sizeof(ng_nodename), "%s:", ng_name); - - /* create control socket. */ - snprintf(sname, sizeof(sname), "flowctl%i", getpid()); - - if (NgMkSockNode(sname, &cs, NULL) == -1) - err(1, "NgMkSockNode"); - - /* set receive buffer size */ - if (setsockopt(cs, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(int)) == -1) - err(1, "setsockopt(SOL_SOCKET, SO_RCVBUF)"); - - /* parse and execute command */ - execute_command(argc, argv); - - close(cs); - - exit(0); -} - -static void -execute_command(int argc, char **argv) -{ - int cindex = -1; - int i; - - if (!argc) - help(); - for (i = 0; cmds[i].cmd_name != NULL; i++) - if (!strncmp(argv[0], cmds[i].cmd_name, strlen(argv[0]))) { - if (cindex != -1) - errx(1, "ambiguous command: %s", argv[0]); - cindex = i; - } - if (cindex == -1) - errx(1, "bad command: %s", argv[0]); - argc--; - argv++; - (*cmds[cindex].cmd_func)(argc, argv); -} - -static int -ctl_show(int argc, char **argv) -{ - struct ng_mesg *ng_mesg; - struct ngnf_flows *data; - char path[NG_PATHSIZ]; - int token, nread, last = 0; - int verbose = 0; - - if (argc > 0 && !strncmp(argv[0], "verbose", strlen(argv[0]))) - verbose = 1; - - ng_mesg = alloca(SORCVBUF_SIZE); - - if (verbose) - printf(CISCO_SH_VERB_FLOW_HEADER); - else - printf(CISCO_SH_FLOW_HEADER); - - for (;;) { - /* request set of accounting records */ - token = NgSendMsg(cs, ng_nodename, NGM_NETFLOW_COOKIE, - NGM_NETFLOW_SHOW, (void *)&last, sizeof(last)); - if (token == -1) - err(1, "NgSendMsg(NGM_NETFLOW_SHOW)"); - - /* read reply */ - nread = NgRecvMsg(cs, ng_mesg, SORCVBUF_SIZE, path); - if (nread == -1) - err(1, "NgRecvMsg() failed"); - - if (ng_mesg->header.token != token) - err(1, "NgRecvMsg(NGM_NETFLOW_SHOW): token mismatch"); - - data = (struct ngnf_flows*)ng_mesg->data; - if ((ng_mesg->header.arglen < (sizeof(*data))) || - (ng_mesg->header.arglen < (sizeof(*data) + - (data->nentries * sizeof(struct flow_entry_data))))) - err(1, "NgRecvMsg(NGM_NETFLOW_SHOW): arglen too small"); - - if (verbose) - (void )flow_cache_print_verbose(data); - else - (void )flow_cache_print(data); - - if (data->last != 0) - last = data->last; - else - break; - } - - return (0); -} - -static int -flow_cache_print(struct ngnf_flows *recs) -{ - struct flow_entry_data *fle; - char src[INET_ADDRSTRLEN], dst[INET_ADDRSTRLEN]; - char src_if[IFNAMSIZ], dst_if[IFNAMSIZ]; - int i; - - /* quick check */ - if (recs->nentries == 0) - return (0); - - fle = recs->entries; - for (i = 0; i < recs->nentries; i++, fle++) { - inet_ntop(AF_INET, &fle->r.r_src, src, sizeof(src)); - inet_ntop(AF_INET, &fle->r.r_dst, dst, sizeof(dst)); - printf(CISCO_SH_FLOW, - if_indextoname(fle->fle_i_ifx, src_if), - src, - if_indextoname(fle->fle_o_ifx, dst_if), - dst, - fle->r.r_ip_p, - ntohs(fle->r.r_sport), - ntohs(fle->r.r_dport), - fle->packets); - - } - - return (i); -} - -static int -flow_cache_print_verbose(struct ngnf_flows *recs) -{ - struct flow_entry_data *fle; - char src[INET_ADDRSTRLEN], dst[INET_ADDRSTRLEN], next[INET_ADDRSTRLEN]; - char src_if[IFNAMSIZ], dst_if[IFNAMSIZ]; - int i; - - /* quick check */ - if (recs->nentries == 0) - return (0); - - fle = recs->entries; - for (i = 0; i < recs->nentries; i++, fle++) { - inet_ntop(AF_INET, &fle->r.r_src, src, sizeof(src)); - inet_ntop(AF_INET, &fle->r.r_dst, dst, sizeof(dst)); - inet_ntop(AF_INET, &fle->next_hop, next, sizeof(next)); - printf(CISCO_SH_VERB_FLOW, - if_indextoname(fle->fle_i_ifx, src_if), - src, - if_indextoname(fle->fle_o_ifx, dst_if), - dst, - fle->r.r_ip_p, - fle->r.r_tos, - fle->tcp_flags, - fle->packets, - ntohs(fle->r.r_sport), - fle->src_mask, - 0, - ntohs(fle->r.r_dport), - fle->dst_mask, - 0, - next, - (u_int)(fle->bytes / fle->packets), - 0); - - } - - return (i); -} - -static void -help(void) -{ - extern char *__progname; - - fprintf(stderr, "usage: %s [-d level] nodename command\n", __progname); - exit (0); -} diff --git a/usr.sbin/freebsd-update/Makefile b/usr.sbin/freebsd-update/Makefile deleted file mode 100644 index c5d4b00..0000000 --- a/usr.sbin/freebsd-update/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -SCRIPTS=freebsd-update.sh -MAN= freebsd-update.8 - -.include diff --git a/usr.sbin/freebsd-update/freebsd-update.8 b/usr.sbin/freebsd-update/freebsd-update.8 deleted file mode 100644 index 1943a53..0000000 --- a/usr.sbin/freebsd-update/freebsd-update.8 +++ /dev/null @@ -1,177 +0,0 @@ -.\"- -.\" Copyright 2006, 2007 Colin Percival -.\" All rights reserved -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted providing that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd July 14, 2010 -.Dt FREEBSD-UPDATE 8 -.Os FreeBSD -.Sh NAME -.Nm freebsd-update -.Nd fetch and install binary updates to FreeBSD -.Sh SYNOPSIS -.Nm -.Op Fl b Ar basedir -.Op Fl d Ar workdir -.Op Fl f Ar conffile -.Op Fl k Ar KEY -.Op Fl r Ar newrelease -.Op Fl s Ar server -.Op Fl t Ar address -.Cm command ... -.Sh DESCRIPTION -The -.Nm -tool is used to fetch, install, and rollback binary -updates to the FreeBSD base system. -Note that updates are only available if they are being built for the -FreeBSD release and architecture being used; in particular, the -.Fx -Security Team only builds updates for releases shipped in binary form -by the -.Fx -Release Engineering Team, e.g., -.Fx -7.3-RELEASE and -.Fx -8.0-RELEASE, but not -.Fx -6.3-STABLE or -.Fx -9.0-CURRENT. -.Sh OPTIONS -The following options are supported -.Bl -tag -width "-f conffile" -.It Fl b Ar basedir -Operate on a system mounted at -.Ar basedir . -(default: -.Pa / , -or as given in the configuration file.) -.It Fl d Ar workdir -Store working files in -.Ar workdir . -(default: -.Pa /var/db/freebsd-update/ , -or as given in the configuration file.) -.It Fl f Ar conffile -Read configuration options from -.Ar conffile . -(default: -.Pa /etc/freebsd-update.conf ) -.It Fl k Ar KEY -Trust an RSA key with SHA256 of -.Ar KEY . -(default: read value from configuration file.) -.It Fl r Ar newrelease -Specify the new release to which -.Nm -should upgrade (upgrade command only). -.It Fl s Ar server -Fetch files from the specified server or server pool. -(default: read value from configuration file.) -.It Fl t Ar address -Mail output of -.Cm cron -command, if any, to -.Ar address . -(default: root, or as given in the configuration file.) -.El -.Sh COMMANDS -The -.Cm command -can be any one of the following: -.Bl -tag -width "-f conffile" -.It Cm fetch -Based on the currently installed world and the configuration -options set, fetch all available binary updates. -.It Cm cron -Sleep a random amount of time between 1 and 3600 seconds, -then download updates as if the -.Cm fetch -command was used. -If updates are downloaded, an email will be sent -(to root or a different address if specified via the -.Fl t -option or in the configuration file). -As the name suggests, this command is designed for running -from -.Xr cron 8 ; -the random delay serves to minimize the probability that -a large number of machines will simultaneously attempt to -fetch updates. -.It Cm upgrade -Fetch files necessary for upgrading to a new release. -Before using this command, make sure that you read the -announcement and release notes for the new release in -case there are any special steps needed for upgrading. -Note that this command may require up to 500 MB of space in -.Ar workdir -depending on which components of the -.Fx -base system are installed. -.It Cm install -Install the most recently fetched updates or upgrade. -.It Cm rollback -Uninstall the most recently installed updates. -.It Cm IDS -Compare the system against a "known good" index of the -installed release. -.El -.Sh TIPS -.Bl -bullet -.It -If your clock is set to local time, adding the line -.Pp -.Dl 0 3 * * * root /usr/sbin/freebsd-update cron -.Pp -to /etc/crontab will check for updates every night. -If your clock is set to UTC, please pick a random time -other than 3AM, to avoid overly imposing an uneven load -on the server(s) hosting the updates. -.It -In spite of its name, -.Nm -IDS should not be relied upon as an "Intrusion Detection -System", since if the system has been tampered with -it cannot be trusted to operate correctly. -If you intend to use this command for intrusion-detection -purposes, make sure you boot from a secure disk (e.g., a CD). -.El -.Sh FILES -.Bl -tag -width "/etc/freebsd-update.conf" -.It /etc/freebsd-update.conf -Default location of the -.Nm -configuration file. -.It /var/db/freebsd-update/ -Default location where -.Nm -stores temporary files and downloaded updates. -.El -.Sh SEE ALSO -.Xr freebsd-update.conf 5 -.Sh AUTHORS -.An Colin Percival Aq cperciva@FreeBSD.org diff --git a/usr.sbin/freebsd-update/freebsd-update.sh b/usr.sbin/freebsd-update/freebsd-update.sh deleted file mode 100644 index 441d257..0000000 --- a/usr.sbin/freebsd-update/freebsd-update.sh +++ /dev/null @@ -1,3211 +0,0 @@ -#!/bin/sh - -#- -# Copyright 2004-2007 Colin Percival -# All rights reserved -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted providing that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY -# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -# $FreeBSD$ - -#### Usage function -- called from command-line handling code. - -# Usage instructions. Options not listed: -# --debug -- don't filter output from utilities -# --no-stats -- don't show progress statistics while fetching files -usage () { - cat < ${LINE}" - exit 1 - fi - done < ${CONFFILE} - - # Merge the settings read from the configuration file with those - # provided at the command line. - mergeconfig -} - -# Provide some default parameters -default_params () { - # Save any parameters already configured, and clear the slate - saveconfig - nullconfig - - # Default configurations - config_WorkDir /var/db/freebsd-update - config_MailTo root - config_AllowAdd yes - config_AllowDelete yes - config_KeepModifiedMetadata yes - config_BaseDir / - config_VerboseLevel stats - config_StrictComponents no - config_BackupKernel yes - config_BackupKernelDir /boot/kernel.old - config_BackupKernelSymbolFiles no - - # Merge these defaults into the earlier-configured settings - mergeconfig -} - -# Set utility output filtering options, based on ${VERBOSELEVEL} -fetch_setup_verboselevel () { - case ${VERBOSELEVEL} in - debug) - QUIETREDIR="/dev/stderr" - QUIETFLAG=" " - STATSREDIR="/dev/stderr" - DDSTATS=".." - XARGST="-t" - NDEBUG=" " - ;; - nostats) - QUIETREDIR="" - QUIETFLAG="" - STATSREDIR="/dev/null" - DDSTATS=".." - XARGST="" - NDEBUG="" - ;; - stats) - QUIETREDIR="/dev/null" - QUIETFLAG="-q" - STATSREDIR="/dev/stdout" - DDSTATS="" - XARGST="" - NDEBUG="-n" - ;; - esac -} - -# Perform sanity checks and set some final parameters -# in preparation for fetching files. Figure out which -# set of updates should be downloaded: If the user is -# running *-p[0-9]+, strip off the last part; if the -# user is running -SECURITY, call it -RELEASE. Chdir -# into the working directory. -fetchupgrade_check_params () { - export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)" - - _SERVERNAME_z=\ -"SERVERNAME must be given via command line or configuration file." - _KEYPRINT_z="Key must be given via -k option or configuration file." - _KEYPRINT_bad="Invalid key fingerprint: " - _WORKDIR_bad="Directory does not exist or is not writable: " - - if [ -z "${SERVERNAME}" ]; then - echo -n "`basename $0`: " - echo "${_SERVERNAME_z}" - exit 1 - fi - if [ -z "${KEYPRINT}" ]; then - echo -n "`basename $0`: " - echo "${_KEYPRINT_z}" - exit 1 - fi - if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then - echo -n "`basename $0`: " - echo -n "${_KEYPRINT_bad}" - echo ${KEYPRINT} - exit 1 - fi - if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then - echo -n "`basename $0`: " - echo -n "${_WORKDIR_bad}" - echo ${WORKDIR} - exit 1 - fi - chmod 700 ${WORKDIR} - cd ${WORKDIR} || exit 1 - - # Generate release number. The s/SECURITY/RELEASE/ bit exists - # to provide an upgrade path for FreeBSD Update 1.x users, since - # the kernels provided by FreeBSD Update 1.x are always labelled - # as X.Y-SECURITY. - RELNUM=`uname -r | - sed -E 's,-p[0-9]+,,' | - sed -E 's,-SECURITY,-RELEASE,'` - ARCH=`uname -m` - FETCHDIR=${RELNUM}/${ARCH} - PATCHDIR=${RELNUM}/${ARCH}/bp - - # Figure out what directory contains the running kernel - BOOTFILE=`sysctl -n kern.bootfile` - KERNELDIR=${BOOTFILE%/kernel} - if ! [ -d ${KERNELDIR} ]; then - echo "Cannot identify running kernel" - exit 1 - fi - - # Figure out what kernel configuration is running. We start with - # the output of `uname -i`, and then make the following adjustments: - # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config - # file says "ident SMP-GENERIC", I don't know... - # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64" - # _and_ `sysctl kern.version` contains a line which ends "/SMP", then - # we're running an SMP kernel. This mis-identification is a bug - # which was fixed in 6.2-STABLE. - KERNCONF=`uname -i` - if [ ${KERNCONF} = "SMP-GENERIC" ]; then - KERNCONF=SMP - fi - if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then - if sysctl kern.version | grep -qE '/SMP$'; then - KERNCONF=SMP - fi - fi - - # Define some paths - BSPATCH=/usr/bin/bspatch - SHA256=/sbin/sha256 - PHTTPGET=/usr/libexec/phttpget - - # Set up variables relating to VERBOSELEVEL - fetch_setup_verboselevel - - # Construct a unique name from ${BASEDIR} - BDHASH=`echo ${BASEDIR} | sha256 -q` -} - -# Perform sanity checks etc. before fetching updates. -fetch_check_params () { - fetchupgrade_check_params - - if ! [ -z "${TARGETRELEASE}" ]; then - echo -n "`basename $0`: " - echo -n "-r option is meaningless with 'fetch' command. " - echo "(Did you mean 'upgrade' instead?)" - exit 1 - fi -} - -# Perform sanity checks etc. before fetching upgrades. -upgrade_check_params () { - fetchupgrade_check_params - - # Unless set otherwise, we're upgrading to the same kernel config. - NKERNCONF=${KERNCONF} - - # We need TARGETRELEASE set - _TARGETRELEASE_z="Release target must be specified via -r option." - if [ -z "${TARGETRELEASE}" ]; then - echo -n "`basename $0`: " - echo "${_TARGETRELEASE_z}" - exit 1 - fi - - # The target release should be != the current release. - if [ "${TARGETRELEASE}" = "${RELNUM}" ]; then - echo -n "`basename $0`: " - echo "Cannot upgrade from ${RELNUM} to itself" - exit 1 - fi - - # Turning off AllowAdd or AllowDelete is a bad idea for upgrades. - if [ "${ALLOWADD}" = "no" ]; then - echo -n "`basename $0`: " - echo -n "WARNING: \"AllowAdd no\" is a bad idea " - echo "when upgrading between releases." - echo - fi - if [ "${ALLOWDELETE}" = "no" ]; then - echo -n "`basename $0`: " - echo -n "WARNING: \"AllowDelete no\" is a bad idea " - echo "when upgrading between releases." - echo - fi - - # Set EDITOR to /usr/bin/vi if it isn't already set - : ${EDITOR:='/usr/bin/vi'} -} - -# Perform sanity checks and set some final parameters in -# preparation for installing updates. -install_check_params () { - # Check that we are root. All sorts of things won't work otherwise. - if [ `id -u` != 0 ]; then - echo "You must be root to run this." - exit 1 - fi - - # Check that securelevel <= 0. Otherwise we can't update schg files. - if [ `sysctl -n kern.securelevel` -gt 0 ]; then - echo "Updates cannot be installed when the system securelevel" - echo "is greater than zero." - exit 1 - fi - - # Check that we have a working directory - _WORKDIR_bad="Directory does not exist or is not writable: " - if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then - echo -n "`basename $0`: " - echo -n "${_WORKDIR_bad}" - echo ${WORKDIR} - exit 1 - fi - cd ${WORKDIR} || exit 1 - - # Construct a unique name from ${BASEDIR} - BDHASH=`echo ${BASEDIR} | sha256 -q` - - # Check that we have updates ready to install - if ! [ -L ${BDHASH}-install ]; then - echo "No updates are available to install." - echo "Run '$0 fetch' first." - exit 1 - fi - if ! [ -f ${BDHASH}-install/INDEX-OLD ] || - ! [ -f ${BDHASH}-install/INDEX-NEW ]; then - echo "Update manifest is corrupt -- this should never happen." - echo "Re-run '$0 fetch'." - exit 1 - fi - - # Figure out what directory contains the running kernel - BOOTFILE=`sysctl -n kern.bootfile` - KERNELDIR=${BOOTFILE%/kernel} - if ! [ -d ${KERNELDIR} ]; then - echo "Cannot identify running kernel" - exit 1 - fi -} - -# Perform sanity checks and set some final parameters in -# preparation for UNinstalling updates. -rollback_check_params () { - # Check that we are root. All sorts of things won't work otherwise. - if [ `id -u` != 0 ]; then - echo "You must be root to run this." - exit 1 - fi - - # Check that we have a working directory - _WORKDIR_bad="Directory does not exist or is not writable: " - if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then - echo -n "`basename $0`: " - echo -n "${_WORKDIR_bad}" - echo ${WORKDIR} - exit 1 - fi - cd ${WORKDIR} || exit 1 - - # Construct a unique name from ${BASEDIR} - BDHASH=`echo ${BASEDIR} | sha256 -q` - - # Check that we have updates ready to rollback - if ! [ -L ${BDHASH}-rollback ]; then - echo "No rollback directory found." - exit 1 - fi - if ! [ -f ${BDHASH}-rollback/INDEX-OLD ] || - ! [ -f ${BDHASH}-rollback/INDEX-NEW ]; then - echo "Update manifest is corrupt -- this should never happen." - exit 1 - fi -} - -# Perform sanity checks and set some final parameters -# in preparation for comparing the system against the -# published index. Figure out which index we should -# compare against: If the user is running *-p[0-9]+, -# strip off the last part; if the user is running -# -SECURITY, call it -RELEASE. Chdir into the working -# directory. -IDS_check_params () { - export HTTP_USER_AGENT="freebsd-update (${COMMAND}, `uname -r`)" - - _SERVERNAME_z=\ -"SERVERNAME must be given via command line or configuration file." - _KEYPRINT_z="Key must be given via -k option or configuration file." - _KEYPRINT_bad="Invalid key fingerprint: " - _WORKDIR_bad="Directory does not exist or is not writable: " - - if [ -z "${SERVERNAME}" ]; then - echo -n "`basename $0`: " - echo "${_SERVERNAME_z}" - exit 1 - fi - if [ -z "${KEYPRINT}" ]; then - echo -n "`basename $0`: " - echo "${_KEYPRINT_z}" - exit 1 - fi - if ! echo "${KEYPRINT}" | grep -qE "^[0-9a-f]{64}$"; then - echo -n "`basename $0`: " - echo -n "${_KEYPRINT_bad}" - echo ${KEYPRINT} - exit 1 - fi - if ! [ -d "${WORKDIR}" -a -w "${WORKDIR}" ]; then - echo -n "`basename $0`: " - echo -n "${_WORKDIR_bad}" - echo ${WORKDIR} - exit 1 - fi - cd ${WORKDIR} || exit 1 - - # Generate release number. The s/SECURITY/RELEASE/ bit exists - # to provide an upgrade path for FreeBSD Update 1.x users, since - # the kernels provided by FreeBSD Update 1.x are always labelled - # as X.Y-SECURITY. - RELNUM=`uname -r | - sed -E 's,-p[0-9]+,,' | - sed -E 's,-SECURITY,-RELEASE,'` - ARCH=`uname -m` - FETCHDIR=${RELNUM}/${ARCH} - PATCHDIR=${RELNUM}/${ARCH}/bp - - # Figure out what directory contains the running kernel - BOOTFILE=`sysctl -n kern.bootfile` - KERNELDIR=${BOOTFILE%/kernel} - if ! [ -d ${KERNELDIR} ]; then - echo "Cannot identify running kernel" - exit 1 - fi - - # Figure out what kernel configuration is running. We start with - # the output of `uname -i`, and then make the following adjustments: - # 1. Replace "SMP-GENERIC" with "SMP". Why the SMP kernel config - # file says "ident SMP-GENERIC", I don't know... - # 2. If the kernel claims to be GENERIC _and_ ${ARCH} is "amd64" - # _and_ `sysctl kern.version` contains a line which ends "/SMP", then - # we're running an SMP kernel. This mis-identification is a bug - # which was fixed in 6.2-STABLE. - KERNCONF=`uname -i` - if [ ${KERNCONF} = "SMP-GENERIC" ]; then - KERNCONF=SMP - fi - if [ ${KERNCONF} = "GENERIC" ] && [ ${ARCH} = "amd64" ]; then - if sysctl kern.version | grep -qE '/SMP$'; then - KERNCONF=SMP - fi - fi - - # Define some paths - SHA256=/sbin/sha256 - PHTTPGET=/usr/libexec/phttpget - - # Set up variables relating to VERBOSELEVEL - fetch_setup_verboselevel -} - -#### Core functionality -- the actual work gets done here - -# Use an SRV query to pick a server. If the SRV query doesn't provide -# a useful answer, use the server name specified by the user. -# Put another way... look up _http._tcp.${SERVERNAME} and pick a server -# from that; or if no servers are returned, use ${SERVERNAME}. -# This allows a user to specify "portsnap.freebsd.org" (in which case -# portsnap will select one of the mirrors) or "portsnap5.tld.freebsd.org" -# (in which case portsnap will use that particular server, since there -# won't be an SRV entry for that name). -# -# We ignore the Port field, since we are always going to use port 80. - -# Fetch the mirror list, but do not pick a mirror yet. Returns 1 if -# no mirrors are available for any reason. -fetch_pick_server_init () { - : > serverlist_tried - -# Check that host(1) exists (i.e., that the system wasn't built with the -# WITHOUT_BIND set) and don't try to find a mirror if it doesn't exist. - if ! which -s host; then - : > serverlist_full - return 1 - fi - - echo -n "Looking up ${SERVERNAME} mirrors... " - -# Issue the SRV query and pull out the Priority, Weight, and Target fields. -# BIND 9 prints "$name has SRV record ..." while BIND 8 prints -# "$name server selection ..."; we allow either format. - MLIST="_http._tcp.${SERVERNAME}" - host -t srv "${MLIST}" | - sed -nE "s/${MLIST} (has SRV record|server selection) //p" | - cut -f 1,2,4 -d ' ' | - sed -e 's/\.$//' | - sort > serverlist_full - -# If no records, give up -- we'll just use the server name we were given. - if [ `wc -l < serverlist_full` -eq 0 ]; then - echo "none found." - return 1 - fi - -# Report how many mirrors we found. - echo `wc -l < serverlist_full` "mirrors found." - -# Generate a random seed for use in picking mirrors. If HTTP_PROXY -# is set, this will be used to generate the seed; otherwise, the seed -# will be random. - if [ -n "${HTTP_PROXY}${http_proxy}" ]; then - RANDVALUE=`sha256 -qs "${HTTP_PROXY}${http_proxy}" | - tr -d 'a-f' | - cut -c 1-9` - else - RANDVALUE=`jot -r 1 0 999999999` - fi -} - -# Pick a mirror. Returns 1 if we have run out of mirrors to try. -fetch_pick_server () { -# Generate a list of not-yet-tried mirrors - sort serverlist_tried | - comm -23 serverlist_full - > serverlist - -# Have we run out of mirrors? - if [ `wc -l < serverlist` -eq 0 ]; then - echo "No mirrors remaining, giving up." - return 1 - fi - -# Find the highest priority level (lowest numeric value). - SRV_PRIORITY=`cut -f 1 -d ' ' serverlist | sort -n | head -1` - -# Add up the weights of the response lines at that priority level. - SRV_WSUM=0; - while read X; do - case "$X" in - ${SRV_PRIORITY}\ *) - SRV_W=`echo $X | cut -f 2 -d ' '` - SRV_WSUM=$(($SRV_WSUM + $SRV_W)) - ;; - esac - done < serverlist - -# If all the weights are 0, pretend that they are all 1 instead. - if [ ${SRV_WSUM} -eq 0 ]; then - SRV_WSUM=`grep -E "^${SRV_PRIORITY} " serverlist | wc -l` - SRV_W_ADD=1 - else - SRV_W_ADD=0 - fi - -# Pick a value between 0 and the sum of the weights - 1 - SRV_RND=`expr ${RANDVALUE} % ${SRV_WSUM}` - -# Read through the list of mirrors and set SERVERNAME. Write the line -# corresponding to the mirror we selected into serverlist_tried so that -# we won't try it again. - while read X; do - case "$X" in - ${SRV_PRIORITY}\ *) - SRV_W=`echo $X | cut -f 2 -d ' '` - SRV_W=$(($SRV_W + $SRV_W_ADD)) - if [ $SRV_RND -lt $SRV_W ]; then - SERVERNAME=`echo $X | cut -f 3 -d ' '` - echo "$X" >> serverlist_tried - break - else - SRV_RND=$(($SRV_RND - $SRV_W)) - fi - ;; - esac - done < serverlist -} - -# Take a list of ${oldhash}|${newhash} and output a list of needed patches, -# i.e., those for which we have ${oldhash} and don't have ${newhash}. -fetch_make_patchlist () { - grep -vE "^([0-9a-f]{64})\|\1$" | - tr '|' ' ' | - while read X Y; do - if [ -f "files/${Y}.gz" ] || - [ ! -f "files/${X}.gz" ]; then - continue - fi - echo "${X}|${Y}" - done | uniq -} - -# Print user-friendly progress statistics -fetch_progress () { - LNC=0 - while read x; do - LNC=$(($LNC + 1)) - if [ $(($LNC % 10)) = 0 ]; then - echo -n $LNC - elif [ $(($LNC % 2)) = 0 ]; then - echo -n . - fi - done - echo -n " " -} - -# Function for asking the user if everything is ok -continuep () { - while read -p "Does this look reasonable (y/n)? " CONTINUE; do - case "${CONTINUE}" in - y*) - return 0 - ;; - n*) - return 1 - ;; - esac - done -} - -# Initialize the working directory -workdir_init () { - mkdir -p files - touch tINDEX.present -} - -# Check that we have a public key with an appropriate hash, or -# fetch the key if it doesn't exist. Returns 1 if the key has -# not yet been fetched. -fetch_key () { - if [ -r pub.ssl ] && [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then - return 0 - fi - - echo -n "Fetching public key from ${SERVERNAME}... " - rm -f pub.ssl - fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/pub.ssl \ - 2>${QUIETREDIR} || true - if ! [ -r pub.ssl ]; then - echo "failed." - return 1 - fi - if ! [ `${SHA256} -q pub.ssl` = ${KEYPRINT} ]; then - echo "key has incorrect hash." - rm -f pub.ssl - return 1 - fi - echo "done." -} - -# Fetch metadata signature, aka "tag". -fetch_tag () { - echo -n "Fetching metadata signature " - echo ${NDEBUG} "for ${RELNUM} from ${SERVERNAME}... " - rm -f latest.ssl - fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/latest.ssl \ - 2>${QUIETREDIR} || true - if ! [ -r latest.ssl ]; then - echo "failed." - return 1 - fi - - openssl rsautl -pubin -inkey pub.ssl -verify \ - < latest.ssl > tag.new 2>${QUIETREDIR} || true - rm latest.ssl - - if ! [ `wc -l < tag.new` = 1 ] || - ! grep -qE \ - "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \ - tag.new; then - echo "invalid signature." - return 1 - fi - - echo "done." - - RELPATCHNUM=`cut -f 4 -d '|' < tag.new` - TINDEXHASH=`cut -f 5 -d '|' < tag.new` - EOLTIME=`cut -f 6 -d '|' < tag.new` -} - -# Sanity-check the patch number in a tag, to make sure that we're not -# going to "update" backwards and to prevent replay attacks. -fetch_tagsanity () { - # Check that we're not going to move from -pX to -pY with Y < X. - RELPX=`uname -r | sed -E 's,.*-,,'` - if echo ${RELPX} | grep -qE '^p[0-9]+$'; then - RELPX=`echo ${RELPX} | cut -c 2-` - else - RELPX=0 - fi - if [ "${RELPATCHNUM}" -lt "${RELPX}" ]; then - echo - echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})" - echo " appear older than what" - echo "we are currently running (`uname -r`)!" - echo "Cowardly refusing to proceed any further." - return 1 - fi - - # If "tag" exists and corresponds to ${RELNUM}, make sure that - # it contains a patch number <= RELPATCHNUM, in order to protect - # against rollback (replay) attacks. - if [ -f tag ] && - grep -qE \ - "^freebsd-update\|${ARCH}\|${RELNUM}\|[0-9]+\|[0-9a-f]{64}\|[0-9]{10}" \ - tag; then - LASTRELPATCHNUM=`cut -f 4 -d '|' < tag` - - if [ "${RELPATCHNUM}" -lt "${LASTRELPATCHNUM}" ]; then - echo - echo -n "Files on mirror (${RELNUM}-p${RELPATCHNUM})" - echo " are older than the" - echo -n "most recently seen updates" - echo " (${RELNUM}-p${LASTRELPATCHNUM})." - echo "Cowardly refusing to proceed any further." - return 1 - fi - fi -} - -# Fetch metadata index file -fetch_metadata_index () { - echo ${NDEBUG} "Fetching metadata index... " - rm -f ${TINDEXHASH} - fetch ${QUIETFLAG} http://${SERVERNAME}/${FETCHDIR}/t/${TINDEXHASH} - 2>${QUIETREDIR} - if ! [ -f ${TINDEXHASH} ]; then - echo "failed." - return 1 - fi - if [ `${SHA256} -q ${TINDEXHASH}` != ${TINDEXHASH} ]; then - echo "update metadata index corrupt." - return 1 - fi - echo "done." -} - -# Print an error message about signed metadata being bogus. -fetch_metadata_bogus () { - echo - echo "The update metadata$1 is correctly signed, but" - echo "failed an integrity check." - echo "Cowardly refusing to proceed any further." - return 1 -} - -# Construct tINDEX.new by merging the lines named in $1 from ${TINDEXHASH} -# with the lines not named in $@ from tINDEX.present (if that file exists). -fetch_metadata_index_merge () { - for METAFILE in $@; do - if [ `grep -E "^${METAFILE}\|" ${TINDEXHASH} | wc -l` \ - -ne 1 ]; then - fetch_metadata_bogus " index" - return 1 - fi - - grep -E "${METAFILE}\|" ${TINDEXHASH} - done | - sort > tINDEX.wanted - - if [ -f tINDEX.present ]; then - join -t '|' -v 2 tINDEX.wanted tINDEX.present | - sort -m - tINDEX.wanted > tINDEX.new - rm tINDEX.wanted - else - mv tINDEX.wanted tINDEX.new - fi -} - -# Sanity check all the lines of tINDEX.new. Even if more metadata lines -# are added by future versions of the server, this won't cause problems, -# since the only lines which appear in tINDEX.new are the ones which we -# specifically grepped out of ${TINDEXHASH}. -fetch_metadata_index_sanity () { - if grep -qvE '^[0-9A-Z.-]+\|[0-9a-f]{64}$' tINDEX.new; then - fetch_metadata_bogus " index" - return 1 - fi -} - -# Sanity check the metadata file $1. -fetch_metadata_sanity () { - # Some aliases to save space later: ${P} is a character which can - # appear in a path; ${M} is the four numeric metadata fields; and - # ${H} is a sha256 hash. - P="[-+./:=_[[:alnum:]]" - M="[0-9]+\|[0-9]+\|[0-9]+\|[0-9]+" - H="[0-9a-f]{64}" - - # Check that the first four fields make sense. - if gunzip -c < files/$1.gz | - grep -qvE "^[a-z]+\|[0-9a-z]+\|${P}+\|[fdL-]\|"; then - fetch_metadata_bogus "" - return 1 - fi - - # Remove the first three fields. - gunzip -c < files/$1.gz | - cut -f 4- -d '|' > sanitycheck.tmp - - # Sanity check entries with type 'f' - if grep -E '^f' sanitycheck.tmp | - grep -qvE "^f\|${M}\|${H}\|${P}*\$"; then - fetch_metadata_bogus "" - return 1 - fi - - # Sanity check entries with type 'd' - if grep -E '^d' sanitycheck.tmp | - grep -qvE "^d\|${M}\|\|\$"; then - fetch_metadata_bogus "" - return 1 - fi - - # Sanity check entries with type 'L' - if grep -E '^L' sanitycheck.tmp | - grep -qvE "^L\|${M}\|${P}*\|\$"; then - fetch_metadata_bogus "" - return 1 - fi - - # Sanity check entries with type '-' - if grep -E '^-' sanitycheck.tmp | - grep -qvE "^-\|\|\|\|\|\|"; then - fetch_metadata_bogus "" - return 1 - fi - - # Clean up - rm sanitycheck.tmp -} - -# Fetch the metadata index and metadata files listed in $@, -# taking advantage of metadata patches where possible. -fetch_metadata () { - fetch_metadata_index || return 1 - fetch_metadata_index_merge $@ || return 1 - fetch_metadata_index_sanity || return 1 - - # Generate a list of wanted metadata patches - join -t '|' -o 1.2,2.2 tINDEX.present tINDEX.new | - fetch_make_patchlist > patchlist - - if [ -s patchlist ]; then - # Attempt to fetch metadata patches - echo -n "Fetching `wc -l < patchlist | tr -d ' '` " - echo ${NDEBUG} "metadata patches.${DDSTATS}" - tr '|' '-' < patchlist | - lam -s "${FETCHDIR}/tp/" - -s ".gz" | - xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ - 2>${STATSREDIR} | fetch_progress - echo "done." - - # Attempt to apply metadata patches - echo -n "Applying metadata patches... " - tr '|' ' ' < patchlist | - while read X Y; do - if [ ! -f "${X}-${Y}.gz" ]; then continue; fi - gunzip -c < ${X}-${Y}.gz > diff - gunzip -c < files/${X}.gz > diff-OLD - - # Figure out which lines are being added and removed - grep -E '^-' diff | - cut -c 2- | - while read PREFIX; do - look "${PREFIX}" diff-OLD - done | - sort > diff-rm - grep -E '^\+' diff | - cut -c 2- > diff-add - - # Generate the new file - comm -23 diff-OLD diff-rm | - sort - diff-add > diff-NEW - - if [ `${SHA256} -q diff-NEW` = ${Y} ]; then - mv diff-NEW files/${Y} - gzip -n files/${Y} - else - mv diff-NEW ${Y}.bad - fi - rm -f ${X}-${Y}.gz diff - rm -f diff-OLD diff-NEW diff-add diff-rm - done 2>${QUIETREDIR} - echo "done." - fi - - # Update metadata without patches - cut -f 2 -d '|' < tINDEX.new | - while read Y; do - if [ ! -f "files/${Y}.gz" ]; then - echo ${Y}; - fi - done | - sort -u > filelist - - if [ -s filelist ]; then - echo -n "Fetching `wc -l < filelist | tr -d ' '` " - echo ${NDEBUG} "metadata files... " - lam -s "${FETCHDIR}/m/" - -s ".gz" < filelist | - xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ - 2>${QUIETREDIR} - - while read Y; do - if ! [ -f ${Y}.gz ]; then - echo "failed." - return 1 - fi - if [ `gunzip -c < ${Y}.gz | - ${SHA256} -q` = ${Y} ]; then - mv ${Y}.gz files/${Y}.gz - else - echo "metadata is corrupt." - return 1 - fi - done < filelist - echo "done." - fi - -# Sanity-check the metadata files. - cut -f 2 -d '|' tINDEX.new > filelist - while read X; do - fetch_metadata_sanity ${X} || return 1 - done < filelist - -# Remove files which are no longer needed - cut -f 2 -d '|' tINDEX.present | - sort > oldfiles - cut -f 2 -d '|' tINDEX.new | - sort | - comm -13 - oldfiles | - lam -s "files/" - -s ".gz" | - xargs rm -f - rm patchlist filelist oldfiles - rm ${TINDEXHASH} - -# We're done! - mv tINDEX.new tINDEX.present - mv tag.new tag - - return 0 -} - -# Extract a subset of a downloaded metadata file containing only the parts -# which are listed in COMPONENTS. -fetch_filter_metadata_components () { - METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'` - gunzip -c < files/${METAHASH}.gz > $1.all - - # Fish out the lines belonging to components we care about. - for C in ${COMPONENTS}; do - look "`echo ${C} | tr '/' '|'`|" $1.all - done > $1 - - # Remove temporary file. - rm $1.all -} - -# Generate a filtered version of the metadata file $1 from the downloaded -# file, by fishing out the lines corresponding to components we're trying -# to keep updated, and then removing lines corresponding to paths we want -# to ignore. -fetch_filter_metadata () { - # Fish out the lines belonging to components we care about. - fetch_filter_metadata_components $1 - - # Canonicalize directory names by removing any trailing / in - # order to avoid listing directories multiple times if they - # belong to multiple components. Turning "/" into "" doesn't - # matter, since we add a leading "/" when we use paths later. - cut -f 3- -d '|' $1 | - sed -e 's,/|d|,|d|,' | - sort -u > $1.tmp - - # Figure out which lines to ignore and remove them. - for X in ${IGNOREPATHS}; do - grep -E "^${X}" $1.tmp - done | - sort -u | - comm -13 - $1.tmp > $1 - - # Remove temporary files. - rm $1.tmp -} - -# Filter the metadata file $1 by adding lines with "/boot/$2" -# replaced by ${KERNELDIR} (which is `sysctl -n kern.bootfile` minus the -# trailing "/kernel"); and if "/boot/$2" does not exist, remove -# the original lines which start with that. -# Put another way: Deal with the fact that the FOO kernel is sometimes -# installed in /boot/FOO/ and is sometimes installed elsewhere. -fetch_filter_kernel_names () { - grep ^/boot/$2 $1 | - sed -e "s,/boot/$2,${KERNELDIR},g" | - sort - $1 > $1.tmp - mv $1.tmp $1 - - if ! [ -d /boot/$2 ]; then - grep -v ^/boot/$2 $1 > $1.tmp - mv $1.tmp $1 - fi -} - -# For all paths appearing in $1 or $3, inspect the system -# and generate $2 describing what is currently installed. -fetch_inspect_system () { - # No errors yet... - rm -f .err - - # Tell the user why his disk is suddenly making lots of noise - echo -n "Inspecting system... " - - # Generate list of files to inspect - cat $1 $3 | - cut -f 1 -d '|' | - sort -u > filelist - - # Examine each file and output lines of the form - # /path/to/file|type|device-inum|user|group|perm|flags|value - # sorted by device and inode number. - while read F; do - # If the symlink/file/directory does not exist, record this. - if ! [ -e ${BASEDIR}/${F} ]; then - echo "${F}|-||||||" - continue - fi - if ! [ -r ${BASEDIR}/${F} ]; then - echo "Cannot read file: ${BASEDIR}/${F}" \ - >/dev/stderr - touch .err - return 1 - fi - - # Otherwise, output an index line. - if [ -L ${BASEDIR}/${F} ]; then - echo -n "${F}|L|" - stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; - readlink ${BASEDIR}/${F}; - elif [ -f ${BASEDIR}/${F} ]; then - echo -n "${F}|f|" - stat -n -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; - sha256 -q ${BASEDIR}/${F}; - elif [ -d ${BASEDIR}/${F} ]; then - echo -n "${F}|d|" - stat -f '%d-%i|%u|%g|%Mp%Lp|%Of|' ${BASEDIR}/${F}; - else - echo "Unknown file type: ${BASEDIR}/${F}" \ - >/dev/stderr - touch .err - return 1 - fi - done < filelist | - sort -k 3,3 -t '|' > $2.tmp - rm filelist - - # Check if an error occured during system inspection - if [ -f .err ]; then - return 1 - fi - - # Convert to the form - # /path/to/file|type|user|group|perm|flags|value|hlink - # by resolving identical device and inode numbers into hard links. - cut -f 1,3 -d '|' $2.tmp | - sort -k 1,1 -t '|' | - sort -s -u -k 2,2 -t '|' | - join -1 2 -2 3 -t '|' - $2.tmp | - awk -F \| -v OFS=\| \ - '{ - if (($2 == $3) || ($4 == "-")) - print $3,$4,$5,$6,$7,$8,$9,"" - else - print $3,$4,$5,$6,$7,$8,$9,$2 - }' | - sort > $2 - rm $2.tmp - - # We're finished looking around - echo "done." -} - -# For any paths matching ${MERGECHANGES}, compare $1 and $2 and find any -# files which differ; generate $3 containing these paths and the old hashes. -fetch_filter_mergechanges () { - # Pull out the paths and hashes of the files matching ${MERGECHANGES}. - for F in $1 $2; do - for X in ${MERGECHANGES}; do - grep -E "^${X}" ${F} - done | - cut -f 1,2,7 -d '|' | - sort > ${F}-values - done - - # Any line in $2-values which doesn't appear in $1-values and is a - # file means that we should list the path in $3. - comm -13 $1-values $2-values | - fgrep '|f|' | - cut -f 1 -d '|' > $2-paths - - # For each path, pull out one (and only one!) entry from $1-values. - # Note that we cannot distinguish which "old" version the user made - # changes to; but hopefully any changes which occur due to security - # updates will exist in both the "new" version and the version which - # the user has installed, so the merging will still work. - while read X; do - look "${X}|" $1-values | - head -1 - done < $2-paths > $3 - - # Clean up - rm $1-values $2-values $2-paths -} - -# For any paths matching ${UPDATEIFUNMODIFIED}, remove lines from $[123] -# which correspond to lines in $2 with hashes not matching $1 or $3, unless -# the paths are listed in $4. For entries in $2 marked "not present" -# (aka. type -), remove lines from $[123] unless there is a corresponding -# entry in $1. -fetch_filter_unmodified_notpresent () { - # Figure out which lines of $1 and $3 correspond to bits which - # should only be updated if they haven't changed, and fish out - # the (path, type, value) tuples. - # NOTE: We don't consider a file to be "modified" if it matches - # the hash from $3. - for X in ${UPDATEIFUNMODIFIED}; do - grep -E "^${X}" $1 - grep -E "^${X}" $3 - done | - cut -f 1,2,7 -d '|' | - sort > $1-values - - # Do the same for $2. - for X in ${UPDATEIFUNMODIFIED}; do - grep -E "^${X}" $2 - done | - cut -f 1,2,7 -d '|' | - sort > $2-values - - # Any entry in $2-values which is not in $1-values corresponds to - # a path which we need to remove from $1, $2, and $3, unless it - # that path appears in $4. - comm -13 $1-values $2-values | - sort -t '|' -k 1,1 > mlines.tmp - cut -f 1 -d '|' $4 | - sort | - join -v 2 -t '|' - mlines.tmp | - sort > mlines - rm $1-values $2-values mlines.tmp - - # Any lines in $2 which are not in $1 AND are "not present" lines - # also belong in mlines. - comm -13 $1 $2 | - cut -f 1,2,7 -d '|' | - fgrep '|-|' >> mlines - - # Remove lines from $1, $2, and $3 - for X in $1 $2 $3; do - sort -t '|' -k 1,1 ${X} > ${X}.tmp - cut -f 1 -d '|' < mlines | - sort | - join -v 2 -t '|' - ${X}.tmp | - sort > ${X} - rm ${X}.tmp - done - - # Store a list of the modified files, for future reference - fgrep -v '|-|' mlines | - cut -f 1 -d '|' > modifiedfiles - rm mlines -} - -# For each entry in $1 of type -, remove any corresponding -# entry from $2 if ${ALLOWADD} != "yes". Remove all entries -# of type - from $1. -fetch_filter_allowadd () { - cut -f 1,2 -d '|' < $1 | - fgrep '|-' | - cut -f 1 -d '|' > filesnotpresent - - if [ ${ALLOWADD} != "yes" ]; then - sort < $2 | - join -v 1 -t '|' - filesnotpresent | - sort > $2.tmp - mv $2.tmp $2 - fi - - sort < $1 | - join -v 1 -t '|' - filesnotpresent | - sort > $1.tmp - mv $1.tmp $1 - rm filesnotpresent -} - -# If ${ALLOWDELETE} != "yes", then remove any entries from $1 -# which don't correspond to entries in $2. -fetch_filter_allowdelete () { - # Produce a lists ${PATH}|${TYPE} - for X in $1 $2; do - cut -f 1-2 -d '|' < ${X} | - sort -u > ${X}.nodes - done - - # Figure out which lines need to be removed from $1. - if [ ${ALLOWDELETE} != "yes" ]; then - comm -23 $1.nodes $2.nodes > $1.badnodes - else - : > $1.badnodes - fi - - # Remove the relevant lines from $1 - while read X; do - look "${X}|" $1 - done < $1.badnodes | - comm -13 - $1 > $1.tmp - mv $1.tmp $1 - - rm $1.badnodes $1.nodes $2.nodes -} - -# If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in $2 -# with metadata not matching any entry in $1, replace the corresponding -# line of $3 with one having the same metadata as the entry in $2. -fetch_filter_modified_metadata () { - # Fish out the metadata from $1 and $2 - for X in $1 $2; do - cut -f 1-6 -d '|' < ${X} > ${X}.metadata - done - - # Find the metadata we need to keep - if [ ${KEEPMODIFIEDMETADATA} = "yes" ]; then - comm -13 $1.metadata $2.metadata > keepmeta - else - : > keepmeta - fi - - # Extract the lines which we need to remove from $3, and - # construct the lines which we need to add to $3. - : > $3.remove - : > $3.add - while read LINE; do - NODE=`echo "${LINE}" | cut -f 1-2 -d '|'` - look "${NODE}|" $3 >> $3.remove - look "${NODE}|" $3 | - cut -f 7- -d '|' | - lam -s "${LINE}|" - >> $3.add - done < keepmeta - - # Remove the specified lines and add the new lines. - sort $3.remove | - comm -13 - $3 | - sort -u - $3.add > $3.tmp - mv $3.tmp $3 - - rm keepmeta $1.metadata $2.metadata $3.add $3.remove -} - -# Remove lines from $1 and $2 which are identical; -# no need to update a file if it isn't changing. -fetch_filter_uptodate () { - comm -23 $1 $2 > $1.tmp - comm -13 $1 $2 > $2.tmp - - mv $1.tmp $1 - mv $2.tmp $2 -} - -# Fetch any "clean" old versions of files we need for merging changes. -fetch_files_premerge () { - # We only need to do anything if $1 is non-empty. - if [ -s $1 ]; then - # Tell the user what we're doing - echo -n "Fetching files from ${OLDRELNUM} for merging... " - - # List of files wanted - fgrep '|f|' < $1 | - cut -f 3 -d '|' | - sort -u > files.wanted - - # Only fetch the files we don't already have - while read Y; do - if [ ! -f "files/${Y}.gz" ]; then - echo ${Y}; - fi - done < files.wanted > filelist - - # Actually fetch them - lam -s "${OLDFETCHDIR}/f/" - -s ".gz" < filelist | - xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ - 2>${QUIETREDIR} - - # Make sure we got them all, and move them into /files/ - while read Y; do - if ! [ -f ${Y}.gz ]; then - echo "failed." - return 1 - fi - if [ `gunzip -c < ${Y}.gz | - ${SHA256} -q` = ${Y} ]; then - mv ${Y}.gz files/${Y}.gz - else - echo "${Y} has incorrect hash." - return 1 - fi - done < filelist - echo "done." - - # Clean up - rm filelist files.wanted - fi -} - -# Prepare to fetch files: Generate a list of the files we need, -# copy the unmodified files we have into /files/, and generate -# a list of patches to download. -fetch_files_prepare () { - # Tell the user why his disk is suddenly making lots of noise - echo -n "Preparing to download files... " - - # Reduce indices to ${PATH}|${HASH} pairs - for X in $1 $2 $3; do - cut -f 1,2,7 -d '|' < ${X} | - fgrep '|f|' | - cut -f 1,3 -d '|' | - sort > ${X}.hashes - done - - # List of files wanted - cut -f 2 -d '|' < $3.hashes | - sort -u | - while read HASH; do - if ! [ -f files/${HASH}.gz ]; then - echo ${HASH} - fi - done > files.wanted - - # Generate a list of unmodified files - comm -12 $1.hashes $2.hashes | - sort -k 1,1 -t '|' > unmodified.files - - # Copy all files into /files/. We only need the unmodified files - # for use in patching; but we'll want all of them if the user asks - # to rollback the updates later. - while read LINE; do - F=`echo "${LINE}" | cut -f 1 -d '|'` - HASH=`echo "${LINE}" | cut -f 2 -d '|'` - - # Skip files we already have. - if [ -f files/${HASH}.gz ]; then - continue - fi - - # Make sure the file hasn't changed. - cp "${BASEDIR}/${F}" tmpfile - if [ `sha256 -q tmpfile` != ${HASH} ]; then - echo - echo "File changed while FreeBSD Update running: ${F}" - return 1 - fi - - # Place the file into storage. - gzip -c < tmpfile > files/${HASH}.gz - rm tmpfile - done < $2.hashes - - # Produce a list of patches to download - sort -k 1,1 -t '|' $3.hashes | - join -t '|' -o 2.2,1.2 - unmodified.files | - fetch_make_patchlist > patchlist - - # Garbage collect - rm unmodified.files $1.hashes $2.hashes $3.hashes - - # We don't need the list of possible old files any more. - rm $1 - - # We're finished making noise - echo "done." -} - -# Fetch files. -fetch_files () { - # Attempt to fetch patches - if [ -s patchlist ]; then - echo -n "Fetching `wc -l < patchlist | tr -d ' '` " - echo ${NDEBUG} "patches.${DDSTATS}" - tr '|' '-' < patchlist | - lam -s "${PATCHDIR}/" - | - xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ - 2>${STATSREDIR} | fetch_progress - echo "done." - - # Attempt to apply patches - echo -n "Applying patches... " - tr '|' ' ' < patchlist | - while read X Y; do - if [ ! -f "${X}-${Y}" ]; then continue; fi - gunzip -c < files/${X}.gz > OLD - - bspatch OLD NEW ${X}-${Y} - - if [ `${SHA256} -q NEW` = ${Y} ]; then - mv NEW files/${Y} - gzip -n files/${Y} - fi - rm -f diff OLD NEW ${X}-${Y} - done 2>${QUIETREDIR} - echo "done." - fi - - # Download files which couldn't be generate via patching - while read Y; do - if [ ! -f "files/${Y}.gz" ]; then - echo ${Y}; - fi - done < files.wanted > filelist - - if [ -s filelist ]; then - echo -n "Fetching `wc -l < filelist | tr -d ' '` " - echo ${NDEBUG} "files... " - lam -s "${FETCHDIR}/f/" - -s ".gz" < filelist | - xargs ${XARGST} ${PHTTPGET} ${SERVERNAME} \ - 2>${QUIETREDIR} - - while read Y; do - if ! [ -f ${Y}.gz ]; then - echo "failed." - return 1 - fi - if [ `gunzip -c < ${Y}.gz | - ${SHA256} -q` = ${Y} ]; then - mv ${Y}.gz files/${Y}.gz - else - echo "${Y} has incorrect hash." - return 1 - fi - done < filelist - echo "done." - fi - - # Clean up - rm files.wanted filelist patchlist -} - -# Create and populate install manifest directory; and report what updates -# are available. -fetch_create_manifest () { - # If we have an existing install manifest, nuke it. - if [ -L "${BDHASH}-install" ]; then - rm -r ${BDHASH}-install/ - rm ${BDHASH}-install - fi - - # Report to the user if any updates were avoided due to local changes - if [ -s modifiedfiles ]; then - echo - echo -n "The following files are affected by updates, " - echo "but no changes have" - echo -n "been downloaded because the files have been " - echo "modified locally:" - cat modifiedfiles - fi | more - rm modifiedfiles - - # If no files will be updated, tell the user and exit - if ! [ -s INDEX-PRESENT ] && - ! [ -s INDEX-NEW ]; then - rm INDEX-PRESENT INDEX-NEW - echo - echo -n "No updates needed to update system to " - echo "${RELNUM}-p${RELPATCHNUM}." - return - fi - - # Divide files into (a) removed files, (b) added files, and - # (c) updated files. - cut -f 1 -d '|' < INDEX-PRESENT | - sort > INDEX-PRESENT.flist - cut -f 1 -d '|' < INDEX-NEW | - sort > INDEX-NEW.flist - comm -23 INDEX-PRESENT.flist INDEX-NEW.flist > files.removed - comm -13 INDEX-PRESENT.flist INDEX-NEW.flist > files.added - comm -12 INDEX-PRESENT.flist INDEX-NEW.flist > files.updated - rm INDEX-PRESENT.flist INDEX-NEW.flist - - # Report removed files, if any - if [ -s files.removed ]; then - echo - echo -n "The following files will be removed " - echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:" - cat files.removed - fi | more - rm files.removed - - # Report added files, if any - if [ -s files.added ]; then - echo - echo -n "The following files will be added " - echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:" - cat files.added - fi | more - rm files.added - - # Report updated files, if any - if [ -s files.updated ]; then - echo - echo -n "The following files will be updated " - echo "as part of updating to ${RELNUM}-p${RELPATCHNUM}:" - - cat files.updated - fi | more - rm files.updated - - # Create a directory for the install manifest. - MDIR=`mktemp -d install.XXXXXX` || return 1 - - # Populate it - mv INDEX-PRESENT ${MDIR}/INDEX-OLD - mv INDEX-NEW ${MDIR}/INDEX-NEW - - # Link it into place - ln -s ${MDIR} ${BDHASH}-install -} - -# Warn about any upcoming EoL -fetch_warn_eol () { - # What's the current time? - NOWTIME=`date "+%s"` - - # When did we last warn about the EoL date? - if [ -f lasteolwarn ]; then - LASTWARN=`cat lasteolwarn` - else - LASTWARN=`expr ${NOWTIME} - 63072000` - fi - - # If the EoL time is past, warn. - if [ ${EOLTIME} -lt ${NOWTIME} ]; then - echo - cat <<-EOF - WARNING: `uname -sr` HAS PASSED ITS END-OF-LIFE DATE. - Any security issues discovered after `date -r ${EOLTIME}` - will not have been corrected. - EOF - return 1 - fi - - # Figure out how long it has been since we last warned about the - # upcoming EoL, and how much longer we have left. - SINCEWARN=`expr ${NOWTIME} - ${LASTWARN}` - TIMELEFT=`expr ${EOLTIME} - ${NOWTIME}` - - # Don't warn if the EoL is more than 3 months away - if [ ${TIMELEFT} -gt 7884000 ]; then - return 0 - fi - - # Don't warn if the time remaining is more than 3 times the time - # since the last warning. - if [ ${TIMELEFT} -gt `expr ${SINCEWARN} \* 3` ]; then - return 0 - fi - - # Figure out what time units to use. - if [ ${TIMELEFT} -lt 604800 ]; then - UNIT="day" - SIZE=86400 - elif [ ${TIMELEFT} -lt 2678400 ]; then - UNIT="week" - SIZE=604800 - else - UNIT="month" - SIZE=2678400 - fi - - # Compute the right number of units - NUM=`expr ${TIMELEFT} / ${SIZE}` - if [ ${NUM} != 1 ]; then - UNIT="${UNIT}s" - fi - - # Print the warning - echo - cat <<-EOF - WARNING: `uname -sr` is approaching its End-of-Life date. - It is strongly recommended that you upgrade to a newer - release within the next ${NUM} ${UNIT}. - EOF - - # Update the stored time of last warning - echo ${NOWTIME} > lasteolwarn -} - -# Do the actual work involved in "fetch" / "cron". -fetch_run () { - workdir_init || return 1 - - # Prepare the mirror list. - fetch_pick_server_init && fetch_pick_server - - # Try to fetch the public key until we run out of servers. - while ! fetch_key; do - fetch_pick_server || return 1 - done - - # Try to fetch the metadata index signature ("tag") until we run - # out of available servers; and sanity check the downloaded tag. - while ! fetch_tag; do - fetch_pick_server || return 1 - done - fetch_tagsanity || return 1 - - # Fetch the latest INDEX-NEW and INDEX-OLD files. - fetch_metadata INDEX-NEW INDEX-OLD || return 1 - - # Generate filtered INDEX-NEW and INDEX-OLD files containing only - # the lines which (a) belong to components we care about, and (b) - # don't correspond to paths we're explicitly ignoring. - fetch_filter_metadata INDEX-NEW || return 1 - fetch_filter_metadata INDEX-OLD || return 1 - - # Translate /boot/${KERNCONF} into ${KERNELDIR} - fetch_filter_kernel_names INDEX-NEW ${KERNCONF} - fetch_filter_kernel_names INDEX-OLD ${KERNCONF} - - # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the - # system and generate an INDEX-PRESENT file. - fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 - - # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which - # correspond to lines in INDEX-PRESENT with hashes not appearing - # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in - # INDEX-PRESENT has type - and there isn't a corresponding entry in - # INDEX-OLD with type -. - fetch_filter_unmodified_notpresent \ - INDEX-OLD INDEX-PRESENT INDEX-NEW /dev/null - - # For each entry in INDEX-PRESENT of type -, remove any corresponding - # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries - # of type - from INDEX-PRESENT. - fetch_filter_allowadd INDEX-PRESENT INDEX-NEW - - # If ${ALLOWDELETE} != "yes", then remove any entries from - # INDEX-PRESENT which don't correspond to entries in INDEX-NEW. - fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW - - # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in - # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD, - # replace the corresponding line of INDEX-NEW with one having the - # same metadata as the entry in INDEX-PRESENT. - fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW - - # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical; - # no need to update a file if it isn't changing. - fetch_filter_uptodate INDEX-PRESENT INDEX-NEW - - # Prepare to fetch files: Generate a list of the files we need, - # copy the unmodified files we have into /files/, and generate - # a list of patches to download. - fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 - - # Fetch files. - fetch_files || return 1 - - # Create and populate install manifest directory; and report what - # updates are available. - fetch_create_manifest || return 1 - - # Warn about any upcoming EoL - fetch_warn_eol || return 1 -} - -# If StrictComponents is not "yes", generate a new components list -# with only the components which appear to be installed. -upgrade_guess_components () { - if [ "${STRICTCOMPONENTS}" = "no" ]; then - # Generate filtered INDEX-ALL with only the components listed - # in COMPONENTS. - fetch_filter_metadata_components $1 || return 1 - - # Tell the user why his disk is suddenly making lots of noise - echo -n "Inspecting system... " - - # Look at the files on disk, and assume that a component is - # supposed to be present if it is more than half-present. - cut -f 1-3 -d '|' < INDEX-ALL | - tr '|' ' ' | - while read C S F; do - if [ -e ${BASEDIR}/${F} ]; then - echo "+ ${C}|${S}" - fi - echo "= ${C}|${S}" - done | - sort | - uniq -c | - sed -E 's,^ +,,' > compfreq - grep ' = ' compfreq | - cut -f 1,3 -d ' ' | - sort -k 2,2 -t ' ' > compfreq.total - grep ' + ' compfreq | - cut -f 1,3 -d ' ' | - sort -k 2,2 -t ' ' > compfreq.present - join -t ' ' -1 2 -2 2 compfreq.present compfreq.total | - while read S P T; do - if [ ${P} -gt `expr ${T} / 2` ]; then - echo ${S} - fi - done > comp.present - cut -f 2 -d ' ' < compfreq.total > comp.total - rm INDEX-ALL compfreq compfreq.total compfreq.present - - # We're done making noise. - echo "done." - - # Sometimes the kernel isn't installed where INDEX-ALL - # thinks that it should be: In particular, it is often in - # /boot/kernel instead of /boot/GENERIC or /boot/SMP. To - # deal with this, if "kernel|X" is listed in comp.total - # (i.e., is a component which would be upgraded if it is - # found to be present) we will add it to comp.present. - # If "kernel|" is in comp.total but "kernel|X" is - # not, we print a warning -- the user is running a kernel - # which isn't part of the release. - KCOMP=`echo ${KERNCONF} | tr 'A-Z' 'a-z'` - grep -E "^kernel\|${KCOMP}\$" comp.total >> comp.present - - if grep -qE "^kernel\|" comp.total && - ! grep -qE "^kernel\|${KCOMP}\$" comp.total; then - cat <<-EOF - -WARNING: This system is running a "${KCOMP}" kernel, which is not a -kernel configuration distributed as part of FreeBSD ${RELNUM}. -This kernel will not be updated: you MUST update the kernel manually -before running "$0 install". - EOF - fi - - # Re-sort the list of installed components and generate - # the list of non-installed components. - sort -u < comp.present > comp.present.tmp - mv comp.present.tmp comp.present - comm -13 comp.present comp.total > comp.absent - - # Ask the user to confirm that what we have is correct. To - # reduce user confusion, translate "X|Y" back to "X/Y" (as - # subcomponents must be listed in the configuration file). - echo - echo -n "The following components of FreeBSD " - echo "seem to be installed:" - tr '|' '/' < comp.present | - fmt -72 - echo - echo -n "The following components of FreeBSD " - echo "do not seem to be installed:" - tr '|' '/' < comp.absent | - fmt -72 - echo - continuep || return 1 - echo - - # Suck the generated list of components into ${COMPONENTS}. - # Note that comp.present.tmp is used due to issues with - # pipelines and setting variables. - COMPONENTS="" - tr '|' '/' < comp.present > comp.present.tmp - while read C; do - COMPONENTS="${COMPONENTS} ${C}" - done < comp.present.tmp - - # Delete temporary files - rm comp.present comp.present.tmp comp.absent comp.total - fi -} - -# If StrictComponents is not "yes", COMPONENTS contains an entry -# corresponding to the currently running kernel, and said kernel -# does not exist in the new release, add "kernel/generic" to the -# list of components. -upgrade_guess_new_kernel () { - if [ "${STRICTCOMPONENTS}" = "no" ]; then - # Grab the unfiltered metadata file. - METAHASH=`look "$1|" tINDEX.present | cut -f 2 -d '|'` - gunzip -c < files/${METAHASH}.gz > $1.all - - # If "kernel/${KCOMP}" is in ${COMPONENTS} and that component - # isn't in $1.all, we need to add kernel/generic. - for C in ${COMPONENTS}; do - if [ ${C} = "kernel/${KCOMP}" ] && - ! grep -qE "^kernel\|${KCOMP}\|" $1.all; then - COMPONENTS="${COMPONENTS} kernel/generic" - NKERNCONF="GENERIC" - cat <<-EOF - -WARNING: This system is running a "${KCOMP}" kernel, which is not a -kernel configuration distributed as part of FreeBSD ${RELNUM}. -As part of upgrading to FreeBSD ${RELNUM}, this kernel will be -replaced with a "generic" kernel. - EOF - continuep || return 1 - fi - done - - # Don't need this any more... - rm $1.all - fi -} - -# Convert INDEX-OLD (last release) and INDEX-ALL (new release) into -# INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades). -upgrade_oldall_to_oldnew () { - # For each ${F}|... which appears in INDEX-ALL but does not appear - # in INDEX-OLD, add ${F}|-|||||| to INDEX-OLD. - cut -f 1 -d '|' < $1 | - sort -u > $1.paths - cut -f 1 -d '|' < $2 | - sort -u | - comm -13 $1.paths - | - lam - -s "|-||||||" | - sort - $1 > $1.tmp - mv $1.tmp $1 - - # Remove lines from INDEX-OLD which also appear in INDEX-ALL - comm -23 $1 $2 > $1.tmp - mv $1.tmp $1 - - # Remove lines from INDEX-ALL which have a file name not appearing - # anywhere in INDEX-OLD (since these must be files which haven't - # changed -- if they were new, there would be an entry of type "-"). - cut -f 1 -d '|' < $1 | - sort -u > $1.paths - sort -k 1,1 -t '|' < $2 | - join -t '|' - $1.paths | - sort > $2.tmp - rm $1.paths - mv $2.tmp $2 - - # Rename INDEX-ALL to INDEX-NEW. - mv $2 $3 -} - -# From the list of "old" files in $1, merge changes in $2 with those in $3, -# and update $3 to reflect the hashes of merged files. -upgrade_merge () { - # We only need to do anything if $1 is non-empty. - if [ -s $1 ]; then - cut -f 1 -d '|' $1 | - sort > $1-paths - - # Create staging area for merging files - rm -rf merge/ - while read F; do - D=`dirname ${F}` - mkdir -p merge/old/${D} - mkdir -p merge/${OLDRELNUM}/${D} - mkdir -p merge/${RELNUM}/${D} - mkdir -p merge/new/${D} - done < $1-paths - - # Copy in files - while read F; do - # Currently installed file - V=`look "${F}|" $2 | cut -f 7 -d '|'` - gunzip < files/${V}.gz > merge/old/${F} - - # Old release - if look "${F}|" $1 | fgrep -q "|f|"; then - V=`look "${F}|" $1 | cut -f 3 -d '|'` - gunzip < files/${V}.gz \ - > merge/${OLDRELNUM}/${F} - fi - - # New release - if look "${F}|" $3 | cut -f 1,2,7 -d '|' | - fgrep -q "|f|"; then - V=`look "${F}|" $3 | cut -f 7 -d '|'` - gunzip < files/${V}.gz \ - > merge/${RELNUM}/${F} - fi - done < $1-paths - - # Attempt to automatically merge changes - echo -n "Attempting to automatically merge " - echo -n "changes in files..." - : > failed.merges - while read F; do - # If the file doesn't exist in the new release, - # the result of "merging changes" is having the file - # not exist. - if ! [ -f merge/${RELNUM}/${F} ]; then - continue - fi - - # If the file didn't exist in the old release, we're - # going to throw away the existing file and hope that - # the version from the new release is what we want. - if ! [ -f merge/${OLDRELNUM}/${F} ]; then - cp merge/${RELNUM}/${F} merge/new/${F} - continue - fi - - # Some files need special treatment. - case ${F} in - /etc/spwd.db | /etc/pwd.db | /etc/login.conf.db) - # Don't merge these -- we're rebuild them - # after updates are installed. - cp merge/old/${F} merge/new/${F} - ;; - *) - if ! merge -p -L "current version" \ - -L "${OLDRELNUM}" -L "${RELNUM}" \ - merge/old/${F} \ - merge/${OLDRELNUM}/${F} \ - merge/${RELNUM}/${F} \ - > merge/new/${F} 2>/dev/null; then - echo ${F} >> failed.merges - fi - ;; - esac - done < $1-paths - echo " done." - - # Ask the user to handle any files which didn't merge. - while read F; do - cat <<-EOF - -The following file could not be merged automatically: ${F} -Press Enter to edit this file in ${EDITOR} and resolve the conflicts -manually... - EOF - read dummy files/${V}.gz - echo "${F}|${V}" - fi - done < $1-paths > newhashes - - # Pull lines out from $3 which need to be updated to - # reflect merged files. - while read F; do - look "${F}|" $3 - done < $1-paths > $3-oldlines - - # Update lines to reflect merged files - join -t '|' -o 1.1,1.2,1.3,1.4,1.5,1.6,2.2,1.8 \ - $3-oldlines newhashes > $3-newlines - - # Remove old lines from $3 and add new lines. - sort $3-oldlines | - comm -13 - $3 | - sort - $3-newlines > $3.tmp - mv $3.tmp $3 - - # Clean up - rm $1-paths newhashes $3-oldlines $3-newlines - rm -rf merge/ - fi - - # We're done with merging files. - rm $1 -} - -# Do the work involved in fetching upgrades to a new release -upgrade_run () { - workdir_init || return 1 - - # Prepare the mirror list. - fetch_pick_server_init && fetch_pick_server - - # Try to fetch the public key until we run out of servers. - while ! fetch_key; do - fetch_pick_server || return 1 - done - - # Try to fetch the metadata index signature ("tag") until we run - # out of available servers; and sanity check the downloaded tag. - while ! fetch_tag; do - fetch_pick_server || return 1 - done - fetch_tagsanity || return 1 - - # Fetch the INDEX-OLD and INDEX-ALL. - fetch_metadata INDEX-OLD INDEX-ALL || return 1 - - # If StrictComponents is not "yes", generate a new components list - # with only the components which appear to be installed. - upgrade_guess_components INDEX-ALL || return 1 - - # Generate filtered INDEX-OLD and INDEX-ALL files containing only - # the components we want and without anything marked as "Ignore". - fetch_filter_metadata INDEX-OLD || return 1 - fetch_filter_metadata INDEX-ALL || return 1 - - # Merge the INDEX-OLD and INDEX-ALL files into INDEX-OLD. - sort INDEX-OLD INDEX-ALL > INDEX-OLD.tmp - mv INDEX-OLD.tmp INDEX-OLD - rm INDEX-ALL - - # Adjust variables for fetching files from the new release. - OLDRELNUM=${RELNUM} - RELNUM=${TARGETRELEASE} - OLDFETCHDIR=${FETCHDIR} - FETCHDIR=${RELNUM}/${ARCH} - - # Try to fetch the NEW metadata index signature ("tag") until we run - # out of available servers; and sanity check the downloaded tag. - while ! fetch_tag; do - fetch_pick_server || return 1 - done - - # Fetch the new INDEX-ALL. - fetch_metadata INDEX-ALL || return 1 - - # If StrictComponents is not "yes", COMPONENTS contains an entry - # corresponding to the currently running kernel, and said kernel - # does not exist in the new release, add "kernel/generic" to the - # list of components. - upgrade_guess_new_kernel INDEX-ALL || return 1 - - # Filter INDEX-ALL to contain only the components we want and without - # anything marked as "Ignore". - fetch_filter_metadata INDEX-ALL || return 1 - - # Convert INDEX-OLD (last release) and INDEX-ALL (new release) into - # INDEX-OLD and INDEX-NEW files (in the sense of normal upgrades). - upgrade_oldall_to_oldnew INDEX-OLD INDEX-ALL INDEX-NEW - - # Translate /boot/${KERNCONF} or /boot/${NKERNCONF} into ${KERNELDIR} - fetch_filter_kernel_names INDEX-NEW ${NKERNCONF} - fetch_filter_kernel_names INDEX-OLD ${KERNCONF} - - # For all paths appearing in INDEX-OLD or INDEX-NEW, inspect the - # system and generate an INDEX-PRESENT file. - fetch_inspect_system INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 - - # Based on ${MERGECHANGES}, generate a file tomerge-old with the - # paths and hashes of old versions of files to merge. - fetch_filter_mergechanges INDEX-OLD INDEX-PRESENT tomerge-old - - # Based on ${UPDATEIFUNMODIFIED}, remove lines from INDEX-* which - # correspond to lines in INDEX-PRESENT with hashes not appearing - # in INDEX-OLD or INDEX-NEW. Also remove lines where the entry in - # INDEX-PRESENT has type - and there isn't a corresponding entry in - # INDEX-OLD with type -. - fetch_filter_unmodified_notpresent \ - INDEX-OLD INDEX-PRESENT INDEX-NEW tomerge-old - - # For each entry in INDEX-PRESENT of type -, remove any corresponding - # entry from INDEX-NEW if ${ALLOWADD} != "yes". Remove all entries - # of type - from INDEX-PRESENT. - fetch_filter_allowadd INDEX-PRESENT INDEX-NEW - - # If ${ALLOWDELETE} != "yes", then remove any entries from - # INDEX-PRESENT which don't correspond to entries in INDEX-NEW. - fetch_filter_allowdelete INDEX-PRESENT INDEX-NEW - - # If ${KEEPMODIFIEDMETADATA} == "yes", then for each entry in - # INDEX-PRESENT with metadata not matching any entry in INDEX-OLD, - # replace the corresponding line of INDEX-NEW with one having the - # same metadata as the entry in INDEX-PRESENT. - fetch_filter_modified_metadata INDEX-OLD INDEX-PRESENT INDEX-NEW - - # Remove lines from INDEX-PRESENT and INDEX-NEW which are identical; - # no need to update a file if it isn't changing. - fetch_filter_uptodate INDEX-PRESENT INDEX-NEW - - # Fetch "clean" files from the old release for merging changes. - fetch_files_premerge tomerge-old - - # Prepare to fetch files: Generate a list of the files we need, - # copy the unmodified files we have into /files/, and generate - # a list of patches to download. - fetch_files_prepare INDEX-OLD INDEX-PRESENT INDEX-NEW || return 1 - - # Fetch patches from to-${RELNUM}/${ARCH}/bp/ - PATCHDIR=to-${RELNUM}/${ARCH}/bp - fetch_files || return 1 - - # Merge configuration file changes. - upgrade_merge tomerge-old INDEX-PRESENT INDEX-NEW || return 1 - - # Create and populate install manifest directory; and report what - # updates are available. - fetch_create_manifest || return 1 - - # Leave a note behind to tell the "install" command that the kernel - # needs to be installed before the world. - touch ${BDHASH}-install/kernelfirst - - # Remind the user that they need to run "freebsd-update install" - # to install the downloaded bits, in case they didn't RTFM. - echo "To install the downloaded upgrades, run \"$0 install\"." -} - -# Make sure that all the file hashes mentioned in $@ have corresponding -# gzipped files stored in /files/. -install_verify () { - # Generate a list of hashes - cat $@ | - cut -f 2,7 -d '|' | - grep -E '^f' | - cut -f 2 -d '|' | - sort -u > filelist - - # Make sure all the hashes exist - while read HASH; do - if ! [ -f files/${HASH}.gz ]; then - echo -n "Update files missing -- " - echo "this should never happen." - echo "Re-run '$0 fetch'." - return 1 - fi - done < filelist - - # Clean up - rm filelist -} - -# Remove the system immutable flag from files -install_unschg () { - # Generate file list - cat $@ | - cut -f 1 -d '|' > filelist - - # Remove flags - while read F; do - if ! [ -e ${BASEDIR}/${F} ]; then - continue - fi - - chflags noschg ${BASEDIR}/${F} || return 1 - done < filelist - - # Clean up - rm filelist -} - -# Decide which directory name to use for kernel backups. -backup_kernel_finddir () { - CNT=0 - while true ; do - # Pathname does not exist, so it is OK use that name - # for backup directory. - if [ ! -e $BACKUPKERNELDIR ]; then - return 0 - fi - - # If directory do exist, we only use if it has our - # marker file. - if [ -d $BACKUPKERNELDIR -a \ - -e $BACKUPKERNELDIR/.freebsd-update ]; then - return 0 - fi - - # We could not use current directory name, so add counter to - # the end and try again. - CNT=$((CNT + 1)) - if [ $CNT -gt 9 ]; then - echo "Could not find valid backup dir ($BACKUPKERNELDIR)" - exit 1 - fi - BACKUPKERNELDIR="`echo $BACKUPKERNELDIR | sed -Ee 's/[0-9]\$//'`" - BACKUPKERNELDIR="${BACKUPKERNELDIR}${CNT}" - done -} - -# Backup the current kernel using hardlinks, if not disabled by user. -# Since we delete all files in the directory used for previous backups -# we create a marker file called ".freebsd-update" in the directory so -# we can determine on the next run that the directory was created by -# freebsd-update and we then do not accidentally remove user files in -# the unlikely case that the user has created a directory with a -# conflicting name. -backup_kernel () { - # Only make kernel backup is so configured. - if [ $BACKUPKERNEL != yes ]; then - return 0 - fi - - # Decide which directory name to use for kernel backups. - backup_kernel_finddir - - # Remove old kernel backup files. If $BACKUPKERNELDIR was - # "not ours", backup_kernel_finddir would have exited, so - # deleting the directory content is as safe as we can make it. - if [ -d $BACKUPKERNELDIR ]; then - rm -fr $BACKUPKERNELDIR - fi - - # Create directories for backup. - mkdir -p $BACKUPKERNELDIR - mtree -cdn -p "${KERNELDIR}" | \ - mtree -Ue -p "${BACKUPKERNELDIR}" > /dev/null - - # Mark the directory as having been created by freebsd-update. - touch $BACKUPKERNELDIR/.freebsd-update - if [ $? -ne 0 ]; then - echo "Could not create kernel backup directory" - exit 1 - fi - - # Disable pathname expansion to be sure *.symbols is not - # expanded. - set -f - - # Use find to ignore symbol files, unless disabled by user. - if [ $BACKUPKERNELSYMBOLFILES = yes ]; then - FINDFILTER="" - else - FINDFILTER=-"a ! -name *.symbols" - fi - - # Backup all the kernel files using hardlinks. - (cd $KERNELDIR && find . -type f $FINDFILTER -exec \ - cp -pl '{}' ${BACKUPKERNELDIR}/'{}' \;) - - # Re-enable patchname expansion. - set +f -} - -# Install new files -install_from_index () { - # First pass: Do everything apart from setting file flags. We - # can't set flags yet, because schg inhibits hard linking. - sort -k 1,1 -t '|' $1 | - tr '|' ' ' | - while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do - case ${TYPE} in - d) - # Create a directory - install -d -o ${OWNER} -g ${GROUP} \ - -m ${PERM} ${BASEDIR}/${FPATH} - ;; - f) - if [ -z "${LINK}" ]; then - # Create a file, without setting flags. - gunzip < files/${HASH}.gz > ${HASH} - install -S -o ${OWNER} -g ${GROUP} \ - -m ${PERM} ${HASH} ${BASEDIR}/${FPATH} - rm ${HASH} - else - # Create a hard link. - ln -f ${BASEDIR}/${LINK} ${BASEDIR}/${FPATH} - fi - ;; - L) - # Create a symlink - ln -sfh ${HASH} ${BASEDIR}/${FPATH} - ;; - esac - done - - # Perform a second pass, adding file flags. - tr '|' ' ' < $1 | - while read FPATH TYPE OWNER GROUP PERM FLAGS HASH LINK; do - if [ ${TYPE} = "f" ] && - ! [ ${FLAGS} = "0" ]; then - chflags ${FLAGS} ${BASEDIR}/${FPATH} - fi - done -} - -# Remove files which we want to delete -install_delete () { - # Generate list of new files - cut -f 1 -d '|' < $2 | - sort > newfiles - - # Generate subindex of old files we want to nuke - sort -k 1,1 -t '|' $1 | - join -t '|' -v 1 - newfiles | - sort -r -k 1,1 -t '|' | - cut -f 1,2 -d '|' | - tr '|' ' ' > killfiles - - # Remove the offending bits - while read FPATH TYPE; do - case ${TYPE} in - d) - rmdir ${BASEDIR}/${FPATH} - ;; - f) - rm ${BASEDIR}/${FPATH} - ;; - L) - rm ${BASEDIR}/${FPATH} - ;; - esac - done < killfiles - - # Clean up - rm newfiles killfiles -} - -# Install new files, delete old files, and update linker.hints -install_files () { - # If we haven't already dealt with the kernel, deal with it. - if ! [ -f $1/kerneldone ]; then - grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD - grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW - - # Backup current kernel before installing a new one - backup_kernel || return 1 - - # Install new files - install_from_index INDEX-NEW || return 1 - - # Remove files which need to be deleted - install_delete INDEX-OLD INDEX-NEW || return 1 - - # Update linker.hints if necessary - if [ -s INDEX-OLD -o -s INDEX-NEW ]; then - kldxref -R /boot/ 2>/dev/null - fi - - # We've finished updating the kernel. - touch $1/kerneldone - - # Do we need to ask for a reboot now? - if [ -f $1/kernelfirst ] && - [ -s INDEX-OLD -o -s INDEX-NEW ]; then - cat <<-EOF - -Kernel updates have been installed. Please reboot and run -"$0 install" again to finish installing updates. - EOF - exit 0 - fi - fi - - # If we haven't already dealt with the world, deal with it. - if ! [ -f $1/worlddone ]; then - # Install new shared libraries next - grep -vE '^/boot/' $1/INDEX-NEW | - grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW - install_from_index INDEX-NEW || return 1 - - # Deal with everything else - grep -vE '^/boot/' $1/INDEX-OLD | - grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD - grep -vE '^/boot/' $1/INDEX-NEW | - grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW - install_from_index INDEX-NEW || return 1 - install_delete INDEX-OLD INDEX-NEW || return 1 - - # Rebuild /etc/spwd.db and /etc/pwd.db if necessary. - if [ /etc/master.passwd -nt /etc/spwd.db ] || - [ /etc/master.passwd -nt /etc/pwd.db ]; then - pwd_mkdb /etc/master.passwd - fi - - # Rebuild /etc/login.conf.db if necessary. - if [ /etc/login.conf -nt /etc/login.conf.db ]; then - cap_mkdb /etc/login.conf - fi - - # We've finished installing the world and deleting old files - # which are not shared libraries. - touch $1/worlddone - - # Do we need to ask the user to portupgrade now? - grep -vE '^/boot/' $1/INDEX-NEW | - grep -E '/lib/.*\.so\.[0-9]+\|' | - cut -f 1 -d '|' | - sort > newfiles - if grep -vE '^/boot/' $1/INDEX-OLD | - grep -E '/lib/.*\.so\.[0-9]+\|' | - cut -f 1 -d '|' | - sort | - join -v 1 - newfiles | - grep -q .; then - cat <<-EOF - -Completing this upgrade requires removing old shared object files. -Please rebuild all installed 3rd party software (e.g., programs -installed from the ports tree) and then run "$0 install" -again to finish installing updates. - EOF - rm newfiles - exit 0 - fi - rm newfiles - fi - - # Remove old shared libraries - grep -vE '^/boot/' $1/INDEX-NEW | - grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW - grep -vE '^/boot/' $1/INDEX-OLD | - grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD - install_delete INDEX-OLD INDEX-NEW || return 1 - - # Remove temporary files - rm INDEX-OLD INDEX-NEW -} - -# Rearrange bits to allow the installed updates to be rolled back -install_setup_rollback () { - # Remove the "reboot after installing kernel", "kernel updated", and - # "finished installing the world" flags if present -- they are - # irrelevant when rolling back updates. - if [ -f ${BDHASH}-install/kernelfirst ]; then - rm ${BDHASH}-install/kernelfirst - rm ${BDHASH}-install/kerneldone - fi - if [ -f ${BDHASH}-install/worlddone ]; then - rm ${BDHASH}-install/worlddone - fi - - if [ -L ${BDHASH}-rollback ]; then - mv ${BDHASH}-rollback ${BDHASH}-install/rollback - fi - - mv ${BDHASH}-install ${BDHASH}-rollback -} - -# Actually install updates -install_run () { - echo -n "Installing updates..." - - # Make sure we have all the files we should have - install_verify ${BDHASH}-install/INDEX-OLD \ - ${BDHASH}-install/INDEX-NEW || return 1 - - # Remove system immutable flag from files - install_unschg ${BDHASH}-install/INDEX-OLD \ - ${BDHASH}-install/INDEX-NEW || return 1 - - # Install new files, delete old files, and update linker.hints - install_files ${BDHASH}-install || return 1 - - # Rearrange bits to allow the installed updates to be rolled back - install_setup_rollback - - echo " done." -} - -# Rearrange bits to allow the previous set of updates to be rolled back next. -rollback_setup_rollback () { - if [ -L ${BDHASH}-rollback/rollback ]; then - mv ${BDHASH}-rollback/rollback rollback-tmp - rm -r ${BDHASH}-rollback/ - rm ${BDHASH}-rollback - mv rollback-tmp ${BDHASH}-rollback - else - rm -r ${BDHASH}-rollback/ - rm ${BDHASH}-rollback - fi -} - -# Install old files, delete new files, and update linker.hints -rollback_files () { - # Install old shared library files which don't have the same path as - # a new shared library file. - grep -vE '^/boot/' $1/INDEX-NEW | - grep -E '/lib/.*\.so\.[0-9]+\|' | - cut -f 1 -d '|' | - sort > INDEX-NEW.libs.flist - grep -vE '^/boot/' $1/INDEX-OLD | - grep -E '/lib/.*\.so\.[0-9]+\|' | - sort -k 1,1 -t '|' - | - join -t '|' -v 1 - INDEX-NEW.libs.flist > INDEX-OLD - install_from_index INDEX-OLD || return 1 - - # Deal with files which are neither kernel nor shared library - grep -vE '^/boot/' $1/INDEX-OLD | - grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD - grep -vE '^/boot/' $1/INDEX-NEW | - grep -vE '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW - install_from_index INDEX-OLD || return 1 - install_delete INDEX-NEW INDEX-OLD || return 1 - - # Install any old shared library files which we didn't install above. - grep -vE '^/boot/' $1/INDEX-OLD | - grep -E '/lib/.*\.so\.[0-9]+\|' | - sort -k 1,1 -t '|' - | - join -t '|' - INDEX-NEW.libs.flist > INDEX-OLD - install_from_index INDEX-OLD || return 1 - - # Delete unneeded shared library files - grep -vE '^/boot/' $1/INDEX-OLD | - grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-OLD - grep -vE '^/boot/' $1/INDEX-NEW | - grep -E '/lib/.*\.so\.[0-9]+\|' > INDEX-NEW - install_delete INDEX-NEW INDEX-OLD || return 1 - - # Deal with kernel files - grep -E '^/boot/' $1/INDEX-OLD > INDEX-OLD - grep -E '^/boot/' $1/INDEX-NEW > INDEX-NEW - install_from_index INDEX-OLD || return 1 - install_delete INDEX-NEW INDEX-OLD || return 1 - if [ -s INDEX-OLD -o -s INDEX-NEW ]; then - kldxref -R /boot/ 2>/dev/null - fi - - # Remove temporary files - rm INDEX-OLD INDEX-NEW INDEX-NEW.libs.flist -} - -# Actually rollback updates -rollback_run () { - echo -n "Uninstalling updates..." - - # If there are updates waiting to be installed, remove them; we - # want the user to re-run 'fetch' after rolling back updates. - if [ -L ${BDHASH}-install ]; then - rm -r ${BDHASH}-install/ - rm ${BDHASH}-install - fi - - # Make sure we have all the files we should have - install_verify ${BDHASH}-rollback/INDEX-NEW \ - ${BDHASH}-rollback/INDEX-OLD || return 1 - - # Remove system immutable flag from files - install_unschg ${BDHASH}-rollback/INDEX-NEW \ - ${BDHASH}-rollback/INDEX-OLD || return 1 - - # Install old files, delete new files, and update linker.hints - rollback_files ${BDHASH}-rollback || return 1 - - # Remove the rollback directory and the symlink pointing to it; and - # rearrange bits to allow the previous set of updates to be rolled - # back next. - rollback_setup_rollback - - echo " done." -} - -# Compare INDEX-ALL and INDEX-PRESENT and print warnings about differences. -IDS_compare () { - # Get all the lines which mismatch in something other than file - # flags. We ignore file flags because sysinstall doesn't seem to - # set them when it installs FreeBSD; warning about these adds a - # very large amount of noise. - cut -f 1-5,7-8 -d '|' $1 > $1.noflags - sort -k 1,1 -t '|' $1.noflags > $1.sorted - cut -f 1-5,7-8 -d '|' $2 | - comm -13 $1.noflags - | - fgrep -v '|-|||||' | - sort -k 1,1 -t '|' | - join -t '|' $1.sorted - > INDEX-NOTMATCHING - - # Ignore files which match IDSIGNOREPATHS. - for X in ${IDSIGNOREPATHS}; do - grep -E "^${X}" INDEX-NOTMATCHING - done | - sort -u | - comm -13 - INDEX-NOTMATCHING > INDEX-NOTMATCHING.tmp - mv INDEX-NOTMATCHING.tmp INDEX-NOTMATCHING - - # Go through the lines and print warnings. - while read LINE; do - FPATH=`echo "${LINE}" | cut -f 1 -d '|'` - TYPE=`echo "${LINE}" | cut -f 2 -d '|'` - OWNER=`echo "${LINE}" | cut -f 3 -d '|'` - GROUP=`echo "${LINE}" | cut -f 4 -d '|'` - PERM=`echo "${LINE}" | cut -f 5 -d '|'` - HASH=`echo "${LINE}" | cut -f 6 -d '|'` - LINK=`echo "${LINE}" | cut -f 7 -d '|'` - P_TYPE=`echo "${LINE}" | cut -f 8 -d '|'` - P_OWNER=`echo "${LINE}" | cut -f 9 -d '|'` - P_GROUP=`echo "${LINE}" | cut -f 10 -d '|'` - P_PERM=`echo "${LINE}" | cut -f 11 -d '|'` - P_HASH=`echo "${LINE}" | cut -f 12 -d '|'` - P_LINK=`echo "${LINE}" | cut -f 13 -d '|'` - - # Warn about different object types. - if ! [ "${TYPE}" = "${P_TYPE}" ]; then - echo -n "${FPATH} is a " - case "${P_TYPE}" in - f) echo -n "regular file, " - ;; - d) echo -n "directory, " - ;; - L) echo -n "symlink, " - ;; - esac - echo -n "but should be a " - case "${TYPE}" in - f) echo -n "regular file." - ;; - d) echo -n "directory." - ;; - L) echo -n "symlink." - ;; - esac - echo - - # Skip other tests, since they don't make sense if - # we're comparing different object types. - continue - fi - - # Warn about different owners. - if ! [ "${OWNER}" = "${P_OWNER}" ]; then - echo -n "${FPATH} is owned by user id ${P_OWNER}, " - echo "but should be owned by user id ${OWNER}." - fi - - # Warn about different groups. - if ! [ "${GROUP}" = "${P_GROUP}" ]; then - echo -n "${FPATH} is owned by group id ${P_GROUP}, " - echo "but should be owned by group id ${GROUP}." - fi - - # Warn about different permissions. We do not warn about - # different permissions on symlinks, since some archivers - # don't extract symlink permissions correctly and they are - # ignored anyway. - if ! [ "${PERM}" = "${P_PERM}" ] && - ! [ "${TYPE}" = "L" ]; then - echo -n "${FPATH} has ${P_PERM} permissions, " - echo "but should have ${PERM} permissions." - fi - - # Warn about different file hashes / symlink destinations. - if ! [ "${HASH}" = "${P_HASH}" ]; then - if [ "${TYPE}" = "L" ]; then - echo -n "${FPATH} is a symlink to ${P_HASH}, " - echo "but should be a symlink to ${HASH}." - fi - if [ "${TYPE}" = "f" ]; then - echo -n "${FPATH} has SHA256 hash ${P_HASH}, " - echo "but should have SHA256 hash ${HASH}." - fi - fi - - # We don't warn about different hard links, since some - # some archivers break hard links, and as long as the - # underlying data is correct they really don't matter. - done < INDEX-NOTMATCHING - - # Clean up - rm $1 $1.noflags $1.sorted $2 INDEX-NOTMATCHING -} - -# Do the work involved in comparing the system to a "known good" index -IDS_run () { - workdir_init || return 1 - - # Prepare the mirror list. - fetch_pick_server_init && fetch_pick_server - - # Try to fetch the public key until we run out of servers. - while ! fetch_key; do - fetch_pick_server || return 1 - done - - # Try to fetch the metadata index signature ("tag") until we run - # out of available servers; and sanity check the downloaded tag. - while ! fetch_tag; do - fetch_pick_server || return 1 - done - fetch_tagsanity || return 1 - - # Fetch INDEX-OLD and INDEX-ALL. - fetch_metadata INDEX-OLD INDEX-ALL || return 1 - - # Generate filtered INDEX-OLD and INDEX-ALL files containing only - # the components we want and without anything marked as "Ignore". - fetch_filter_metadata INDEX-OLD || return 1 - fetch_filter_metadata INDEX-ALL || return 1 - - # Merge the INDEX-OLD and INDEX-ALL files into INDEX-ALL. - sort INDEX-OLD INDEX-ALL > INDEX-ALL.tmp - mv INDEX-ALL.tmp INDEX-ALL - rm INDEX-OLD - - # Translate /boot/${KERNCONF} to ${KERNELDIR} - fetch_filter_kernel_names INDEX-ALL ${KERNCONF} - - # Inspect the system and generate an INDEX-PRESENT file. - fetch_inspect_system INDEX-ALL INDEX-PRESENT /dev/null || return 1 - - # Compare INDEX-ALL and INDEX-PRESENT and print warnings about any - # differences. - IDS_compare INDEX-ALL INDEX-PRESENT -} - -#### Main functions -- call parameter-handling and core functions - -# Using the command line, configuration file, and defaults, -# set all the parameters which are needed later. -get_params () { - init_params - parse_cmdline $@ - parse_conffile - default_params -} - -# Fetch command. Make sure that we're being called -# interactively, then run fetch_check_params and fetch_run -cmd_fetch () { - if [ ! -t 0 ]; then - echo -n "`basename $0` fetch should not " - echo "be run non-interactively." - echo "Run `basename $0` cron instead." - exit 1 - fi - fetch_check_params - fetch_run || exit 1 -} - -# Cron command. Make sure the parameters are sensible; wait -# rand(3600) seconds; then fetch updates. While fetching updates, -# send output to a temporary file; only print that file if the -# fetching failed. -cmd_cron () { - fetch_check_params - sleep `jot -r 1 0 3600` - - TMPFILE=`mktemp /tmp/freebsd-update.XXXXXX` || exit 1 - if ! fetch_run >> ${TMPFILE} || - ! grep -q "No updates needed" ${TMPFILE} || - [ ${VERBOSELEVEL} = "debug" ]; then - mail -s "`hostname` security updates" ${MAILTO} < ${TMPFILE} - fi - - rm ${TMPFILE} -} - -# Fetch files for upgrading to a new release. -cmd_upgrade () { - upgrade_check_params - upgrade_run || exit 1 -} - -# Install downloaded updates. -cmd_install () { - install_check_params - install_run || exit 1 -} - -# Rollback most recently installed updates. -cmd_rollback () { - rollback_check_params - rollback_run || exit 1 -} - -# Compare system against a "known good" index. -cmd_IDS () { - IDS_check_params - IDS_run || exit 1 -} - -#### Entry point - -# Make sure we find utilities from the base system -export PATH=/sbin:/bin:/usr/sbin:/usr/bin:${PATH} - -# Set LC_ALL in order to avoid problems with character ranges like [A-Z]. -export LC_ALL=C - -get_params $@ -for COMMAND in ${COMMANDS}; do - cmd_${COMMAND} -done diff --git a/usr.sbin/ftp-proxy/Makefile b/usr.sbin/ftp-proxy/Makefile deleted file mode 100644 index 67660c8..0000000 --- a/usr.sbin/ftp-proxy/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -SUBDIR= libevent ftp-proxy - -.include diff --git a/usr.sbin/ftp-proxy/Makefile.inc b/usr.sbin/ftp-proxy/Makefile.inc deleted file mode 100644 index 9043d09..0000000 --- a/usr.sbin/ftp-proxy/Makefile.inc +++ /dev/null @@ -1,5 +0,0 @@ -# $FreeBSD$ - -LIBEVENT= ${.OBJDIR}/../libevent/libevent.a - -.include "../Makefile.inc" diff --git a/usr.sbin/ftp-proxy/ftp-proxy/Makefile b/usr.sbin/ftp-proxy/ftp-proxy/Makefile deleted file mode 100644 index 773c25d..0000000 --- a/usr.sbin/ftp-proxy/ftp-proxy/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/pf/ftp-proxy - -PROG= ftp-proxy -MAN= ftp-proxy.8 - -SRCS= ftp-proxy.c filter.c - -CFLAGS+= -I${.CURDIR}/../../../contrib/pf/libevent -CFLAGS+= -I${.CURDIR}/../../../sys/contrib/pf - -DPADD= ${LIBEVENT} -LDADD= ${LIBEVENT} - -WARNS?= 2 - -.include diff --git a/usr.sbin/ftp-proxy/libevent/Makefile b/usr.sbin/ftp-proxy/libevent/Makefile deleted file mode 100644 index a8ff09b..0000000 --- a/usr.sbin/ftp-proxy/libevent/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -# $FreeBSD$ - -.PATH: ${.CURDIR}/../../../contrib/pf/libevent - - -LIB= event -INTERNALLIB=yes -SRCS= buffer.c evbuffer.c event.c kqueue.c log.c poll.c select.c signal.c -HDRS= event.h - -CFLAGS+= -I${.CURDIR} \ - -DHAVE_CLOCK_GETTIME \ - -DHAVE_FCNTL_H \ - -DHAVE_POLL \ - -DHAVE_SELECT \ - -DHAVE_SETFD \ - -DHAVE_STDARG_H \ - -DHAVE_SYS_IOCTL_H \ - -DHAVE_SYS_TIME_H \ - -DHAVE_UNISTD_H \ - -DHAVE_VASPRINTF \ - -DHAVE_WORKING_KQUEUE \ - -DVERSION='"1.3b"' - -WARNS?= 2 - -.include diff --git a/usr.sbin/fwcontrol/Makefile b/usr.sbin/fwcontrol/Makefile deleted file mode 100644 index 10320d2..0000000 --- a/usr.sbin/fwcontrol/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $FreeBSD$ - -PROG= fwcontrol -SRCS= fwcontrol.c fwcrom.c fwdv.c fwmpegts.c -MAN= fwcontrol.8 -WARNS?= 3 - -.PATH: ${.CURDIR}/../../sys/dev/firewire - -SDIR= ${.CURDIR}/../../sys -CFLAGS+=-I${.CURDIR} -I${SDIR} - -.include diff --git a/usr.sbin/fwcontrol/fwcontrol.8 b/usr.sbin/fwcontrol/fwcontrol.8 deleted file mode 100644 index f3a83b7..0000000 --- a/usr.sbin/fwcontrol/fwcontrol.8 +++ /dev/null @@ -1,220 +0,0 @@ -.\" Copyright (c) 2002 Hidetoshi Shimokawa -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, -.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -.\" POSSIBILITY OF SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd September 12, 2008 -.Dt FWCONTROL 8 -.Os -.Sh NAME -.Nm fwcontrol -.Nd FireWire control utility -.Sh SYNOPSIS -.Nm -.Op Fl u Ar bus_num -.Op Fl prt -.Op Fl c Ar node -.Op Fl d Ar node -.Op Fl o Ar node -.Op Fl s Ar node -.Op Fl l Ar file -.Op Fl f Ar node -.Op Fl g Ar gap_count -.Op Fl b Ar pri_req -.Op Fl M Ar mode -.Op Fl R Ar filename -.Op Fl S Ar filename -.Op Fl m Ar EUI64 | hostname -.Sh DESCRIPTION -The -.Nm -utility is designed to provide a way for users to access and control the -.Fx -FireWire subsystem. -Without options, -.Nm -will output a list of devices that are/were connected to the bus. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl u Ar bus_num -Specify the FireWire bus number to be operated on. -The default is bus 0. -.It Fl r -Initiate bus reset. -.It Fl t -Show the topology map. -.It Fl p -Dump PHY registers. -.It Fl c Ar node -Show the configuration ROM on the node. -.It Fl d Ar node -Hex dump of the configuration ROM. -.It Fl o Ar node -Send a link-on PHY packet to the node. -.It Fl s Ar node -Write to the -.Dv RESET_START -register on the node. -.It Fl l Ar file -Load hex dump file of the configuration ROM and parse it. -.It Fl f Ar node -Force specified -.Ar node -to be the root node on the next bus reset by sending a PHY config packet. -Valid values are 0 - 63. -.It Fl g Ar gap_count -Broadcast new -.Ar gap_count -by sending a PHY_config packet. -By default this value is 63 on all nodes. -Valid values are 0 - 63. -.It Fl i Ar pri_req -Set the -.Dv PRIORITY_BUDGET -register on all supported nodes. -.It Fl M Ar mode -Explicitly specify either -.Ar dv -or -.Ar mpeg -mode for the incoming stream. -Only meaningful in case of and must precede the -.Fl R -option. -If not specified, the program will try to guess. -In case of -.Dq format 0x20 -error, try to force the -.Dq mpeg -mode. -.It Fl R Ar filename -Receive DV or MPEG TS stream and dump it to a file. -Use ^C to stop the receiving. -Some DV cameras seem not to send the stream if a bus manager exists. -If it is impossible to get the stream, try the following commands: -.Bd -literal -offset indent -sysctl hw.firewire.try_bmr=0 -fwcontrol -r -.Ed -.Pp -The resulting file contains raw DV data excluding isochronous header -and CIP header. -It can be handled by -.Nm libdv -in the -.Fx -Ports Collection. -Resulting MPEG TS stream can be played and sent over a -network using the VideoLAN -.Nm vlc -tool in the -.Fx -Ports Collection. -The stream can be piped directly to -.Nm vlc, -see -.Sx EXAMPLES . -.It Fl S Ar filename -Send a DV file as isochronous stream. -.It Fl m Ar EUI64 | hostname -Set default fwmem target. -Hostname will be converted to EUI64 using -.Xr eui64 5 . -.El -.Sh FILES -.Bl -tag -.It Pa /dev/fw0.0 -.El -.Sh EXAMPLES -Each DV frame has a fixed size and it is easy to edit the frame order. -.Pp -.Dl "fwcontrol -R original.dv" -.Pp -Receive a DV stream with DV camera attached. -.Pp -.Dl "dd if=original.dv of=first.dv bs=120000 count=30" -.Pp -Get first 30 frames(NTSC). -.Pp -.Dl "dd if=original.dv of=second.dv bs=120000 skip=30 count=30" -.Pp -Get second 30 frames(NTSC). -.Pp -.Dl "cat second.dv first.dv | fwcontrol -S /dev/stdin" -.Pp -Swap first and second 30 frames and send them to DV recorder. -.Pp -For PAL, replace -.Dq Li bs=120000 -with -.Dq Li bs=144000 . -.Pp -.Dl "fwcontrol -R file.m2t -.Pp -Receive an MPEG TS stream from a camera producing MPEG transport stream. -This has been tested with SONY HDR-FX1E camera that produces HD MPEG-2 -stream at 25 Mbps bandwidth. -.Pp -To send the stream from the camera over the network using TCP (which -surprisingly works better with vlc), you can use -.Dl "fwcontrol -R - | nc 192.168.10.11 9000 -with -.Nm netcat -from ports and to receive the stream, use -.Dl nc -l -p 9000 | vlc - -.Pp -To netcast via UDP, you need to use -.Nm buffer -program from ports, since vlc is not fast enough to read UDP packets from -buffers and thus it experiences dropouts when run directly. -The sending side can use -.Dl "fwcontrol -R - | nc 192.168.10.11 9000 -and to receive the stream, use -.Dl nc -l -u -p 9000 | buffer -s 10k -b 1000 -m 20m -p 5 | vlc - -.Pp -For more information on how to work with -.Nm vlc -see its docs. -.Sh SEE ALSO -.Xr mplayer 1 , -.Xr vlc 1 , -.Xr firewire 4 , -.Xr fwe 4 , -.Xr fwip 4 , -.Xr fwohci 4 , -.Xr sbp 4 -.Sh HISTORY -The -.Nm -utility first appeared in -.Fx 5.0 . -.Sh AUTHORS -.An Hidetoshi Shimokawa Aq simokawa@FreeBSD.org -.An Petr Holub Aq hopet@ics.muni.cz -- MPEG TS mode. -.Sh BUGS -This utility is still under development and provided for debugging purposes. -Especially MPEG TS reception support is very rudimental and supports only -high-bandwidth MPEG-2 streams (fn field in CIP header equals 3). diff --git a/usr.sbin/fwcontrol/fwcontrol.c b/usr.sbin/fwcontrol/fwcontrol.c deleted file mode 100644 index 509d25d..0000000 --- a/usr.sbin/fwcontrol/fwcontrol.c +++ /dev/null @@ -1,1089 +0,0 @@ -/* - * Copyright (C) 2002 - * Hidetoshi Shimokawa. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by Hidetoshi Shimokawa. - * - * 4. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(__FreeBSD__) -#include -__FBSDID("$FreeBSD$"); -#endif - -#include -#include -#include -#include -#include -#include -#include -#if defined(__FreeBSD__) -#include -#include -#include -#include -#include -#elif defined(__NetBSD__) -#include "eui64.h" -#include -#include -#include -#include -#else -#warning "You need to add support for your OS" -#endif - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "fwmethods.h" - -static void sysctl_set_int(const char *, int); - -static void -usage(void) -{ - fprintf(stderr, - "%s [-u bus_num] [-prt] [-c node] [-d node] [-o node] [-s node]\n" - "\t [-l file] [-g gap_count] [-f force_root ] [-b pri_req]\n" - "\t [-M mode] [-R filename] [-S filename] [-m EUI64 | hostname]\n" - "\t-u: specify bus number\n" - "\t-p: Display current PHY register settings\n" - "\t-r: bus reset\n" - "\t-t: read topology map\n" - "\t-c: read configuration ROM\n" - "\t-d: hex dump of configuration ROM\n" - "\t-o: send link-on packet to the node\n" - "\t-s: write RESET_START register on the node\n" - "\t-l: load and parse hex dump file of configuration ROM\n" - "\t-g: set gap count\n" - "\t-f: force root node\n" - "\t-b: set PRIORITY_BUDGET register on all supported nodes\n" - "\t-M: specify dv or mpeg\n" - "\t-R: Receive DV or MPEG TS stream\n" - "\t-S: Send DV stream\n" - "\t-m: set fwmem target\n" - , getprogname() ); - fprintf(stderr, "\n"); -} - -static void -fweui2eui64(const struct fw_eui64 *fweui, struct eui64 *eui) -{ - *(u_int32_t*)&(eui->octet[0]) = htonl(fweui->hi); - *(u_int32_t*)&(eui->octet[4]) = htonl(fweui->lo); -} - -static void -get_dev(int fd, struct fw_devlstreq *data) -{ - if (data == NULL) - err(EX_SOFTWARE, "%s: data malloc", __func__); - if( ioctl(fd, FW_GDEVLST, data) < 0) { - err(EX_IOERR, "%s: ioctl", __func__); - } -} - -static int -str2node(int fd, const char *nodestr) -{ - struct eui64 eui, tmpeui; - struct fw_devlstreq *data; - char *endptr; - int i, node; - - if (nodestr == '\0') - return (-1); - - /* - * Deal with classic node specifications. - */ - node = strtol(nodestr, &endptr, 0); - if (*endptr == '\0') - goto gotnode; - - /* - * Try to get an eui and match it against available nodes. - */ - if (eui64_hostton(nodestr, &eui) != 0 && eui64_aton(nodestr, &eui) != 0) - return (-1); - - data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); - if (data == NULL) - err(EX_SOFTWARE, "%s: data malloc", __func__); - get_dev(fd,data); - - for (i = 0; i < data->info_len; i++) { - fweui2eui64(&data->dev[i].eui, &tmpeui); - if (memcmp(&eui, &tmpeui, sizeof(struct eui64)) == 0) { - node = data->dev[i].dst; - if (data != NULL) - free(data); - goto gotnode; - } - } - if (i >= data->info_len) { - if (data != NULL) - free(data); - return (-1); - } - -gotnode: - if (node < 0 || node > 63) - return (-1); - else - return (node); -} - -static void -list_dev(int fd) -{ - struct fw_devlstreq *data; - struct fw_devinfo *devinfo; - struct eui64 eui; - char addr[EUI64_SIZ], hostname[40]; - int i; - - data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); - if (data == NULL) - err(EX_SOFTWARE, "%s:data malloc", __func__); - get_dev(fd, data); - printf("%d devices (info_len=%d)\n", data->n, data->info_len); - printf("node EUI64 status hostname\n"); - for (i = 0; i < data->info_len; i++) { - devinfo = &data->dev[i]; - fweui2eui64(&devinfo->eui, &eui); - eui64_ntoa(&eui, addr, sizeof(addr)); - if (eui64_ntohost(hostname, sizeof(hostname), &eui)) - hostname[0] = 0; - printf("%4d %s %6d %s\n", - (devinfo->status || i == 0) ? devinfo->dst : -1, - addr, - devinfo->status, - hostname - ); - } - free((void *)data); -} - -static u_int32_t -read_write_quad(int fd, struct fw_eui64 eui, u_int32_t addr_lo, int readmode, u_int32_t data) -{ - struct fw_asyreq *asyreq; - u_int32_t *qld, res; - - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16); - if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); - asyreq->req.len = 16; -#if 0 - asyreq->req.type = FWASREQNODE; - asyreq->pkt.mode.rreqq.dst = FWLOCALBUS | node; -#else - asyreq->req.type = FWASREQEUI; - asyreq->req.dst.eui = eui; -#endif - asyreq->pkt.mode.rreqq.tlrt = 0; - if (readmode) - asyreq->pkt.mode.rreqq.tcode = FWTCODE_RREQQ; - else - asyreq->pkt.mode.rreqq.tcode = FWTCODE_WREQQ; - - asyreq->pkt.mode.rreqq.dest_hi = 0xffff; - asyreq->pkt.mode.rreqq.dest_lo = addr_lo; - - qld = (u_int32_t *)&asyreq->pkt; - if (!readmode) - asyreq->pkt.mode.wreqq.data = htonl(data); - - if (ioctl(fd, FW_ASYREQ, asyreq) < 0) { - err(EX_IOERR, "%s: ioctl", __func__); - } - res = qld[3]; - free(asyreq); - if (readmode) - return ntohl(res); - else - return 0; -} - -/* - * Send a PHY Config Packet - * ieee 1394a-2005 4.3.4.3 - * - * Message ID Root ID R T Gap Count - * 00(2 bits) (6 bits) 1 1 (6 bits) - * - * if "R" is set, then Root ID will be the next - * root node upon the next bus reset. - * if "T" is set, then Gap Count will be the - * value that all nodes use for their Gap Count - * if "R" and "T" are not set, then this message - * is either ignored or interpreted as an extended - * PHY config Packet as per 1394a-2005 4.3.4.4 - */ -static void -send_phy_config(int fd, int root_node, int gap_count) -{ - struct fw_asyreq *asyreq; - - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12); - if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); - asyreq->req.len = 12; - asyreq->req.type = FWASREQNODE; - asyreq->pkt.mode.ld[0] = 0; - asyreq->pkt.mode.ld[1] = 0; - asyreq->pkt.mode.common.tcode = FWTCODE_PHY; - if (root_node >= 0) - asyreq->pkt.mode.ld[1] |= ((root_node << 24) | (1 << 23)); - if (gap_count >= 0) - asyreq->pkt.mode.ld[1] |= ((1 << 22) | (gap_count << 16)); - asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1]; - - printf("send phy_config root_node=%d gap_count=%d\n", - root_node, gap_count); - - if (ioctl(fd, FW_ASYREQ, asyreq) < 0) - err(EX_IOERR, "%s: ioctl", __func__); - free(asyreq); -} - -static void -link_on(int fd, int node) -{ - struct fw_asyreq *asyreq; - - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 12); - if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); - asyreq->req.len = 12; - asyreq->req.type = FWASREQNODE; - asyreq->pkt.mode.common.tcode = FWTCODE_PHY; - asyreq->pkt.mode.ld[1] |= (1 << 30) | ((node & 0x3f) << 24); - asyreq->pkt.mode.ld[2] = ~asyreq->pkt.mode.ld[1]; - - if (ioctl(fd, FW_ASYREQ, asyreq) < 0) - err(EX_IOERR, "%s: ioctl", __func__); - free(asyreq); -} - -static void -reset_start(int fd, int node) -{ - struct fw_asyreq *asyreq; - - asyreq = (struct fw_asyreq *)malloc(sizeof(struct fw_asyreq_t) + 16); - if (asyreq == NULL) - err(EX_SOFTWARE, "%s:asyreq malloc", __func__); - asyreq->req.len = 16; - asyreq->req.type = FWASREQNODE; - asyreq->pkt.mode.wreqq.dst = FWLOCALBUS | (node & 0x3f); - asyreq->pkt.mode.wreqq.tlrt = 0; - asyreq->pkt.mode.wreqq.tcode = FWTCODE_WREQQ; - - asyreq->pkt.mode.wreqq.dest_hi = 0xffff; - asyreq->pkt.mode.wreqq.dest_lo = 0xf0000000 | RESET_START; - - asyreq->pkt.mode.wreqq.data = htonl(0x1); - - if (ioctl(fd, FW_ASYREQ, asyreq) < 0) - err(EX_IOERR, "%s: ioctl", __func__); - free(asyreq); -} - -static void -set_pri_req(int fd, u_int32_t pri_req) -{ - struct fw_devlstreq *data; - struct fw_devinfo *devinfo; - struct eui64 eui; - char addr[EUI64_SIZ]; - u_int32_t max, reg, old; - int i; - - data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); - if (data == NULL) - err(EX_SOFTWARE, "%s:data malloc", __func__); - get_dev(fd, data); -#define BUGET_REG 0xf0000218 - for (i = 0; i < data->info_len; i++) { - devinfo = &data->dev[i]; - if (!devinfo->status) - continue; - reg = read_write_quad(fd, devinfo->eui, BUGET_REG, 1, 0); - fweui2eui64(&devinfo->eui, &eui); - eui64_ntoa(&eui, addr, sizeof(addr)); - printf("%d %s, %08x", - devinfo->dst, addr, reg); - if (reg > 0) { - old = (reg & 0x3f); - max = (reg & 0x3f00) >> 8; - if (pri_req > max) - pri_req = max; - printf(" 0x%x -> 0x%x\n", old, pri_req); - read_write_quad(fd, devinfo->eui, BUGET_REG, 0, pri_req); - } else { - printf("\n"); - } - } - free((void *)data); -} - -static void -parse_bus_info_block(u_int32_t *p) -{ - char addr[EUI64_SIZ]; - struct bus_info *bi; - struct eui64 eui; - - bi = (struct bus_info *)p; - fweui2eui64(&bi->eui64, &eui); - eui64_ntoa(&eui, addr, sizeof(addr)); - printf("bus_name: 0x%04x\n" - "irmc:%d cmc:%d isc:%d bmc:%d pmc:%d\n" - "cyc_clk_acc:%d max_rec:%d max_rom:%d\n" - "generation:%d link_spd:%d\n" - "EUI64: %s\n", - bi->bus_name, - bi->irmc, bi->cmc, bi->isc, bi->bmc, bi->pmc, - bi->cyc_clk_acc, bi->max_rec, bi->max_rom, - bi->generation, bi->link_spd, - addr); -} - -static int -get_crom(int fd, int node, void *crom_buf, int len) -{ - struct fw_crom_buf buf; - int i, error; - struct fw_devlstreq *data; - - data = (struct fw_devlstreq *)malloc(sizeof(struct fw_devlstreq)); - if (data == NULL) - err(EX_SOFTWARE, "%s:data malloc", __func__); - get_dev(fd, data); - - for (i = 0; i < data->info_len; i++) { - if (data->dev[i].dst == node && data->dev[i].eui.lo != 0) - break; - } - if (i == data->info_len) - errx(1, "no such node %d.", node); - else - buf.eui = data->dev[i].eui; - free((void *)data); - - buf.len = len; - buf.ptr = crom_buf; - bzero(crom_buf, len); - if ((error = ioctl(fd, FW_GCROM, &buf)) < 0) { - err(EX_IOERR, "%s: ioctl", __func__); - } - - return error; -} - -static void -show_crom(u_int32_t *crom_buf) -{ - int i; - struct crom_context cc; - char *desc, info[256]; - static const char *key_types = "ICLD"; - struct csrreg *reg; - struct csrdirectory *dir; - struct csrhdr *hdr; - u_int16_t crc; - - printf("first quad: 0x%08x ", *crom_buf); - if (crom_buf[0] == 0) { - printf("(Invalid Configuration ROM)\n"); - return; - } - hdr = (struct csrhdr *)crom_buf; - if (hdr->info_len == 1) { - /* minimum ROM */ - reg = (struct csrreg *)hdr; - printf("verndor ID: 0x%06x\n", reg->val); - return; - } - printf("info_len=%d crc_len=%d crc=0x%04x", - hdr->info_len, hdr->crc_len, hdr->crc); - crc = crom_crc(crom_buf+1, hdr->crc_len); - if (crc == hdr->crc) - printf("(OK)\n"); - else - printf("(NG)\n"); - parse_bus_info_block(crom_buf+1); - - crom_init_context(&cc, crom_buf); - dir = cc.stack[0].dir; - if (!dir) { - printf("no root directory - giving up\n"); - return; - } - printf("root_directory: len=0x%04x(%d) crc=0x%04x", - dir->crc_len, dir->crc_len, dir->crc); - crc = crom_crc((u_int32_t *)&dir->entry[0], dir->crc_len); - if (crc == dir->crc) - printf("(OK)\n"); - else - printf("(NG)\n"); - if (dir->crc_len < 1) - return; - while (cc.depth >= 0) { - desc = crom_desc(&cc, info, sizeof(info)); - reg = crom_get(&cc); - for (i = 0; i < cc.depth; i++) - printf("\t"); - printf("%02x(%c:%02x) %06x %s: %s\n", - reg->key, - key_types[(reg->key & CSRTYPE_MASK)>>6], - reg->key & CSRKEY_MASK, reg->val, - desc, info); - crom_next(&cc); - } -} - -#define DUMP_FORMAT "%08x %08x %08x %08x %08x %08x %08x %08x\n" - -static void -dump_crom(u_int32_t *p) -{ - int len=1024, i; - - for (i = 0; i < len/(4*8); i ++) { - printf(DUMP_FORMAT, - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - p += 8; - } -} - -static void -load_crom(char *filename, u_int32_t *p) -{ - FILE *file; - int len=1024, i; - - if ((file = fopen(filename, "r")) == NULL) - err(1, "load_crom %s", filename); - for (i = 0; i < len/(4*8); i ++) { - fscanf(file, DUMP_FORMAT, - p, p+1, p+2, p+3, p+4, p+5, p+6, p+7); - p += 8; - } -} - -static void -show_topology_map(int fd) -{ - struct fw_topology_map *tmap; - union fw_self_id sid; - int i; - static const char *port_status[] = {" ", "-", "P", "C"}; - static const char *pwr_class[] = {" 0W", "15W", "30W", "45W", - "-1W", "-2W", "-5W", "-9W"}; - static const char *speed[] = {"S100", "S200", "S400", "S800"}; - tmap = malloc(sizeof(struct fw_topology_map)); - if (tmap == NULL) - err(EX_SOFTWARE, "%s:tmap malloc", __func__); - if (ioctl(fd, FW_GTPMAP, tmap) < 0) { - err(EX_IOERR, "%s: ioctl", __func__); - } - printf("crc_len: %d generation:%d node_count:%d sid_count:%d\n", - tmap->crc_len, tmap->generation, - tmap->node_count, tmap->self_id_count); - printf("id link gap_cnt speed delay cIRM power port0 port1 port2" - " ini more\n"); - for (i = 0; i < tmap->crc_len - 2; i++) { - sid = tmap->self_id[i]; - if (sid.p0.sequel) { - printf("%02d sequel packet\n", sid.p0.phy_id); - continue; - } - printf("%02d %2d %2d %4s %d %3s" - " %s %s %s %d %d\n", - sid.p0.phy_id, - sid.p0.link_active, - sid.p0.gap_count, - speed[sid.p0.phy_speed], - sid.p0.contender, - pwr_class[sid.p0.power_class], - port_status[sid.p0.port0], - port_status[sid.p0.port1], - port_status[sid.p0.port2], - sid.p0.initiated_reset, - sid.p0.more_packets - ); - } - free(tmap); -} - -static void -read_phy_registers(int fd, u_int8_t *buf, int offset, int len) -{ - struct fw_reg_req_t reg; - int i; - - for (i = 0; i < len; i++) { - reg.addr = offset + i; - if (ioctl(fd, FWOHCI_RDPHYREG, ®) < 0) - err(EX_IOERR, "%s: ioctl", __func__); - buf[i] = (u_int8_t) reg.data; - printf("0x%02x ", reg.data); - } - printf("\n"); -} - -static void -read_phy_page(int fd, u_int8_t *buf, int page, int port) -{ - struct fw_reg_req_t reg; - - reg.addr = 0x7; - reg.data = ((page & 7) << 5) | (port & 0xf); - if (ioctl(fd, FWOHCI_WRPHYREG, ®) < 0) - err(EX_IOERR, "%s: ioctl", __func__); - read_phy_registers(fd, buf, 8, 8); -} - -static void -dump_phy_registers(int fd) -{ - struct phyreg_base b; - struct phyreg_page0 p; - struct phyreg_page1 v; - int i; - - printf("=== base register ===\n"); - read_phy_registers(fd, (u_int8_t *)&b, 0, 8); - printf( - "Physical_ID:%d R:%d CPS:%d\n" - "RHB:%d IBR:%d Gap_Count:%d\n" - "Extended:%d Num_Ports:%d\n" - "PHY_Speed:%d Delay:%d\n" - "LCtrl:%d C:%d Jitter:%d Pwr_Class:%d\n" - "WDIE:%d ISBR:%d CTOI:%d CPSI:%d STOI:%d PEI:%d EAA:%d EMC:%d\n" - "Max_Legacy_SPD:%d BLINK:%d Bridge:%d\n" - "Page_Select:%d Port_Select%d\n", - b.phy_id, b.r, b.cps, - b.rhb, b.ibr, b.gap_count, - b.extended, b.num_ports, - b.phy_speed, b.delay, - b.lctrl, b.c, b.jitter, b.pwr_class, - b.wdie, b.isbr, b.ctoi, b.cpsi, b.stoi, b.pei, b.eaa, b.emc, - b.legacy_spd, b.blink, b.bridge, - b.page_select, b.port_select - ); - - for (i = 0; i < b.num_ports; i ++) { - printf("\n=== page 0 port %d ===\n", i); - read_phy_page(fd, (u_int8_t *)&p, 0, i); - printf( - "Astat:%d BStat:%d Ch:%d Con:%d RXOK:%d Dis:%d\n" - "Negotiated_speed:%d PIE:%d Fault:%d Stanby_fault:%d Disscrm:%d B_Only:%d\n" - "DC_connected:%d Max_port_speed:%d LPP:%d Cable_speed:%d\n" - "Connection_unreliable:%d Beta_mode:%d\n" - "Port_error:0x%x\n" - "Loop_disable:%d In_standby:%d Hard_disable:%d\n", - p.astat, p.bstat, p.ch, p.con, p.rxok, p.dis, - p.negotiated_speed, p.pie, p.fault, p.stanby_fault, p.disscrm, p.b_only, - p.dc_connected, p.max_port_speed, p.lpp, p.cable_speed, - p.connection_unreliable, p.beta_mode, - p.port_error, - p.loop_disable, p.in_standby, p.hard_disable - ); - } - printf("\n=== page 1 ===\n"); - read_phy_page(fd, (u_int8_t *)&v, 1, 0); - printf( - "Compliance:%d\n" - "Vendor_ID:0x%06x\n" - "Product_ID:0x%06x\n", - v.compliance, - (v.vendor_id[0] << 16) | (v.vendor_id[1] << 8) | v.vendor_id[2], - (v.product_id[0] << 16) | (v.product_id[1] << 8) | v.product_id[2] - ); -} - -static int -open_dev(int *fd, char *devname) -{ - if (*fd < 0) { - *fd = open(devname, O_RDWR); - if (*fd < 0) - return(-1); - - } - return(0); -} - -static void -sysctl_set_int(const char *name, int val) -{ - if (sysctlbyname(name, NULL, NULL, &val, sizeof(int)) < 0) - err(1, "sysctl %s failed.", name); -} - -static fwmethod * -detect_recv_fn(int fd, char ich) -{ - char *buf; - struct fw_isochreq isoreq; - struct fw_isobufreq bufreq; - int len; - u_int32_t *ptr; - struct ciphdr *ciph; - fwmethod *retfn; -#define RECV_NUM_PACKET 16 -#define RECV_PACKET_SZ 1024 - - bufreq.rx.nchunk = 8; - bufreq.rx.npacket = RECV_NUM_PACKET; - bufreq.rx.psize = RECV_PACKET_SZ; - bufreq.tx.nchunk = 0; - bufreq.tx.npacket = 0; - bufreq.tx.psize = 0; - - if (ioctl(fd, FW_SSTBUF, &bufreq) < 0) - err(EX_IOERR, "%s: ioctl FW_SSTBUF", __func__); - - isoreq.ch = ich & 0x3f; - isoreq.tag = (ich >> 6) & 3; - - if (ioctl(fd, FW_SRSTREAM, &isoreq) < 0) - err(EX_IOERR, "%s: ioctl FW_SRSTREAM", __func__); - - buf = (char *)malloc(RECV_NUM_PACKET * RECV_PACKET_SZ); - if (buf == NULL) - err(EX_SOFTWARE, "%s:buf malloc", __func__); - /* - * fwdev.c seems to return EIO on error and - * the return value of the last uiomove - * on success. For now, checking that the - * return is not less than zero should be - * sufficient. fwdev.c::fw_read() should - * return the total length read, not the value - * of the last uiomove(). - */ - len = read(fd, buf, RECV_NUM_PACKET * RECV_PACKET_SZ); - if (len < 0) - err(EX_IOERR, "%s: error reading from device", __func__); - ptr = (u_int32_t *) buf; - ciph = (struct ciphdr *)(ptr + 1); - - switch(ciph->fmt) { - case CIP_FMT_DVCR: - fprintf(stderr, "Detected DV format on input.\n"); - retfn = dvrecv; - break; - case CIP_FMT_MPEG: - fprintf(stderr, "Detected MPEG TS format on input.\n"); - retfn = mpegtsrecv; - break; - default: - errx(1, "Unsupported format for receiving: fmt=0x%x", ciph->fmt); - } - free(buf); - return retfn; -} - -int -main(int argc, char **argv) -{ -#define MAX_BOARDS 10 - u_int32_t crom_buf[1024/4]; - u_int32_t crom_buf_hex[1024/4]; - char devbase[64]; - const char *device_string = "/dev/fw"; - int fd = -1, ch, len=1024; - int32_t current_board = 0; - /* - * If !command_set, then -u will display the nodes for the board. - * This emulates the previous behavior when -u is passed by itself - */ - bool command_set = false; - bool open_needed = false; - long tmp; - struct fw_eui64 eui; - struct eui64 target; - fwmethod *recvfn = NULL; -/* - * Holders for which functions - * to iterate through - */ - bool display_board_only = false; - bool display_crom = false; - bool send_bus_reset = false; - bool display_crom_hex = false; - bool load_crom_from_file = false; - bool set_fwmem_target = false; - bool dump_topology = false; - bool dump_phy_reg = false; - - int32_t priority_budget = -1; - int32_t set_root_node = -1; - int32_t set_gap_count = -1; - int32_t send_link_on = -1; - int32_t send_reset_start = -1; - - char *crom_string = NULL; - char *crom_string_hex = NULL; - char *recv_data = NULL; - char *send_data = NULL; - - if (argc < 2) { - for (current_board = 0; current_board < MAX_BOARDS; current_board++) { - snprintf(devbase, sizeof(devbase), "%s%d.0", device_string, current_board); - if (open_dev(&fd, devbase) < 0) { - if (current_board == 0) { - usage(); - err(EX_IOERR, "%s: Error opening firewire controller #%d %s", - __func__, current_board, devbase); - } - return(EIO); - } - list_dev(fd); - close(fd); - fd = -1; - } - } - /* - * Parse all command line options, then execute requested operations. - */ - while ((ch = getopt(argc, argv, "M:f:g:m:o:s:b:prtc:d:l:u:R:S:")) != -1) { - switch(ch) { - case 'b': - priority_budget = strtol(optarg, NULL, 0); - if (priority_budget < 0 || priority_budget > INT32_MAX) - errx(EX_USAGE, "%s: priority_budget out of range: %s", __func__, optarg); - command_set = true; - open_needed = true; - display_board_only = false; - break; - case 'c': - crom_string = malloc(strlen(optarg)+1); - if (crom_string == NULL) - err(EX_SOFTWARE, "%s:crom_string malloc", __func__); - if ( (strtol(crom_string, NULL, 0) < 0) || strtol(crom_string, NULL, 0) > MAX_BOARDS) - errx(EX_USAGE, "%s:Invalid value for node", __func__); - strcpy(crom_string, optarg); - display_crom = 1; - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 'd': - crom_string_hex = malloc(strlen(optarg)+1); - if (crom_string_hex == NULL) - err(EX_SOFTWARE, "%s:crom_string_hex malloc", __func__); - strcpy(crom_string_hex, optarg); - display_crom_hex = 1; - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 'f': -#define MAX_PHY_CONFIG 0x3f - set_root_node = strtol(optarg, NULL, 0); - if ( (set_root_node < 0) || (set_root_node > MAX_PHY_CONFIG) ) - errx(EX_USAGE, "%s:set_root_node out of range", __func__); - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 'g': - set_gap_count = strtol(optarg, NULL, 0); - if ( (set_gap_count < 0) || (set_gap_count > MAX_PHY_CONFIG) ) - errx(EX_USAGE, "%s:set_gap_count out of range", __func__); - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 'l': - load_crom_from_file = 1; - load_crom(optarg, crom_buf); - command_set = true; - display_board_only = false; - break; - case 'm': - set_fwmem_target = 1; - open_needed = 0; - command_set = true; - display_board_only = false; - if (eui64_hostton(optarg, &target) != 0 && - eui64_aton(optarg, &target) != 0) - errx(EX_USAGE, "%s: invalid target: %s", __func__, optarg); - break; - case 'o': - send_link_on = str2node(fd, optarg); - if ( (send_link_on < 0) || (send_link_on > MAX_PHY_CONFIG) ) - errx(EX_USAGE, "%s: node out of range: %s\n",__func__, optarg); - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 'p': - dump_phy_reg = 1; - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 'r': - send_bus_reset = 1; - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 's': - send_reset_start = str2node(fd, optarg); - if ( (send_reset_start < 0) || (send_reset_start > MAX_PHY_CONFIG) ) - errx(EX_USAGE, "%s: node out of range: %s\n", __func__, optarg); - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 't': - dump_topology = 1; - open_needed = true; - command_set = true; - display_board_only = false; - break; - case 'u': - if(!command_set) - display_board_only = true; - current_board = strtol(optarg, NULL, 0); - open_needed = true; - break; - case 'M': - switch (optarg[0]) { - case 'm': - recvfn = mpegtsrecv; - break; - case 'd': - recvfn = dvrecv; - break; - default: - errx(EX_USAGE, "unrecognized method: %s", - optarg); - } - command_set = true; - display_board_only = false; - break; - case 'R': - recv_data = malloc(strlen(optarg)+1); - if (recv_data == NULL) - err(EX_SOFTWARE, "%s:recv_data malloc", __func__); - strcpy(recv_data, optarg); - open_needed = false; - command_set = true; - display_board_only = false; - break; - case 'S': - send_data = malloc(strlen(optarg)+1); - if (send_data == NULL) - err(EX_SOFTWARE, "%s:send_data malloc", __func__); - strcpy(send_data, optarg); - open_needed = true; - command_set = true; - display_board_only = false; - break; - case '?': - default: - usage(); - warnc(EINVAL, "%s: Unknown command line arguments", __func__); - return 0; - } - } /* end while */ - - /* - * Catch the error case when the user - * executes the command with non ''-'' - * delimited arguments. - * Generate the usage() display and exit. - */ - if (!command_set && !display_board_only) { - usage(); - warnc(EINVAL, "%s: Unknown command line arguments", __func__); - return 0; - } - - /* - * If -u is passed, execute - * command for that card only. - * - * If -u is not passed, execute - * command for card 0 only. - * - */ - if(open_needed){ - snprintf(devbase, sizeof(devbase), "%s%d.0", device_string, current_board); - if (open_dev(&fd, devbase) < 0) { - err(EX_IOERR, "%s: Error opening firewire controller #%d %s", __func__, current_board, devbase); - } - } - /* - * display the nodes on this board "-u" - * only - */ - if (display_board_only) - list_dev(fd); - - /* - * dump_phy_reg "-p" - */ - if (dump_phy_reg) - dump_phy_registers(fd); - - /* - * send a BUS_RESET Event "-r" - */ - if (send_bus_reset) { - if(ioctl(fd, FW_IBUSRST, &tmp) < 0) - err(EX_IOERR, "%s: Ioctl of bus reset failed for %s", __func__, devbase); - } - /* - * Print out the CROM for this node "-c" - */ - if (display_crom) { - tmp = str2node(fd, crom_string); - get_crom(fd, tmp, crom_buf, len); - show_crom(crom_buf); - free(crom_string); - } - /* - * Hex Dump the CROM for this node "-d" - */ - if (display_crom_hex) { - tmp = str2node(fd, crom_string_hex); - get_crom(fd, tmp, crom_buf_hex, len); - dump_crom(crom_buf_hex); - free(crom_string_hex); - } - /* - * Set Priority Budget to value for this node "-b" - */ - if (priority_budget >= 0) - set_pri_req(fd, priority_budget); - - /* - * Explicitly set the root node of this bus to value "-f" - */ - if (set_root_node >= 0) - send_phy_config(fd, set_root_node, -1); - - /* - * Set the gap count for this card/bus "-g" - */ - if (set_gap_count >= 0) - send_phy_config(fd, -1, set_gap_count); - - /* - * Load a CROM from a file "-l" - */ - if (load_crom_from_file) - show_crom(crom_buf); - /* - * Set the fwmem target for a node to argument "-m" - */ - if (set_fwmem_target) { - eui.hi = ntohl(*(u_int32_t*)&(target.octet[0])); - eui.lo = ntohl(*(u_int32_t*)&(target.octet[4])); -#if defined(__FreeBSD__) - sysctl_set_int("hw.firewire.fwmem.eui64_hi", eui.hi); - sysctl_set_int("hw.firewire.fwmem.eui64_lo", eui.lo); -#elif defined(__NetBSD__) - sysctl_set_int("hw.fwmem.eui64_hi", eui.hi); - sysctl_set_int("hw.fwmem.eui64_lo", eui.lo); -#else -#warning "You need to add support for your OS" -#endif - - } - - /* - * Send a link on to this board/bus "-o" - */ - if (send_link_on >= 0) - link_on(fd, send_link_on); - - /* - * Send a reset start to this board/bus "-s" - */ - if (send_reset_start >= 0) - reset_start(fd, send_reset_start); - - /* - * Dump the node topology for this board/bus "-t" - */ - if (dump_topology) - show_topology_map(fd); - - /* - * Recieve data file from node "-R" - */ -#define TAG (1<<6) -#define CHANNEL 63 - if (recv_data != NULL){ - if (recvfn == NULL) { /* guess... */ - recvfn = detect_recv_fn(fd, TAG | CHANNEL); - close(fd); - fd = -1; - } - snprintf(devbase, sizeof(devbase), "%s%d.0", device_string, current_board); - if (open_dev(&fd, devbase) < 0) - err(EX_IOERR, "%s: Error opening firewire controller #%d %s in recv_data\n", __func__, current_board, devbase); - (*recvfn)(fd, recv_data, TAG | CHANNEL, -1); - free(recv_data); - } - - /* - * Send data file to node "-S" - */ - if (send_data != NULL){ - dvsend(fd, send_data, TAG | CHANNEL, -1); - free(send_data); - } - - if (fd > 0) { - close(fd); - fd = -1; - } - return 0; -} diff --git a/usr.sbin/fwcontrol/fwdv.c b/usr.sbin/fwcontrol/fwdv.c deleted file mode 100644 index 23237e5..0000000 --- a/usr.sbin/fwcontrol/fwdv.c +++ /dev/null @@ -1,418 +0,0 @@ -/* - * Copyright (C) 2003 - * Hidetoshi Shimokawa. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by Hidetoshi Shimokawa. - * - * 4. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include -#include -#include -#include -#include - -#if __FreeBSD_version >= 500000 -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "fwmethods.h" - -#define DEBUG 0 -#define FIX_FRAME 1 - -struct frac { - int n,d; -}; - -struct frac frame_cycle[2] = { - {8000*100, 2997}, /* NTSC 8000 cycle / 29.97 Hz */ - {320, 1}, /* PAL 8000 cycle / 25 Hz */ -}; -int npackets[] = { - 250 /* NTSC */, - 300 /* PAL */ -}; -struct frac pad_rate[2] = { - {203, 2997}, /* = (8000 - 29.97 * 250)/(29.97 * 250) */ - {1, 15}, /* = (8000 - 25 * 300)/(25 * 300) */ -}; -char *system_name[] = {"NTSC", "PAL"}; -int frame_rate[] = {30, 25}; - -#define PSIZE 512 -#define DSIZE 480 -#define NCHUNK 64 - -#define NPACKET_R 256 -#define NPACKET_T 255 -#define TNBUF 100 /* XXX too large value causes block noise */ -#define NEMPTY 10 /* depends on TNBUF */ -#define RBUFSIZE (PSIZE * NPACKET_R) -#define MAXBLOCKS (300) -#define CYCLE_FRAC 0xc00 - -void -dvrecv(int d, const char *filename, char ich, int count) -{ - struct fw_isochreq isoreq; - struct fw_isobufreq bufreq; - struct dvdbc *dv; - struct ciphdr *ciph; - struct fw_pkt *pkt; - char *pad, *buf; - u_int32_t *ptr; - int len, tlen, npad, fd, k, m, vec, system = -1, nb; - int nblocks[] = {250 /* NTSC */, 300 /* PAL */}; - struct iovec wbuf[NPACKET_R]; - - if(strcmp(filename, "-") == 0) { - fd = STDOUT_FILENO; - } else { - fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660); - if (fd == -1) - err(EX_NOINPUT, filename); - } - buf = malloc(RBUFSIZE); - pad = malloc(DSIZE*MAXBLOCKS); - memset(pad, 0xff, DSIZE*MAXBLOCKS); - bzero(wbuf, sizeof(wbuf)); - - bufreq.rx.nchunk = NCHUNK; - bufreq.rx.npacket = NPACKET_R; - bufreq.rx.psize = PSIZE; - bufreq.tx.nchunk = 0; - bufreq.tx.npacket = 0; - bufreq.tx.psize = 0; - if (ioctl(d, FW_SSTBUF, &bufreq) < 0) - err(1, "ioctl FW_SSTBUF"); - - isoreq.ch = ich & 0x3f; - isoreq.tag = (ich >> 6) & 3; - - if (ioctl(d, FW_SRSTREAM, &isoreq) < 0) - err(1, "ioctl"); - - k = m = 0; - while (count <= 0 || k <= count) { -#if 0 - tlen = 0; - while ((len = read(d, buf + tlen, PSIZE - /* RBUFSIZE - tlen */)) > 0) { - if (len < 0) { - if (errno == EAGAIN) { - fprintf(stderr, "(EAGAIN)\n"); - fflush(stderr); - if (len <= 0) - continue; - } else - err(1, "read failed"); - } - tlen += len; - if ((RBUFSIZE - tlen) < PSIZE) - break; - }; -#else - tlen = len = read(d, buf, RBUFSIZE); - if (len < 0) { - if (errno == EAGAIN) { - fprintf(stderr, "(EAGAIN) - push 'Play'?\n"); - fflush(stderr); - if (len <= 0) - continue; - } else - err(1, "read failed"); - } -#endif - vec = 0; - ptr = (u_int32_t *) buf; -again: - pkt = (struct fw_pkt *) ptr; -#if DEBUG - fprintf(stderr, "%08x %08x %08x %08x\n", - htonl(ptr[0]), htonl(ptr[1]), - htonl(ptr[2]), htonl(ptr[3])); -#endif - ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */ - if (ciph->fmt != CIP_FMT_DVCR) - errx(1, "unknown format 0x%x", ciph->fmt); - ptr = (u_int32_t *) (ciph + 1); /* skip cip header */ -#if DEBUG - if (ciph->fdf.dv.cyc != 0xffff && k == 0) { - fprintf(stderr, "0x%04x\n", ntohs(ciph->fdf.dv.cyc)); - } -#endif - if (pkt->mode.stream.len <= sizeof(struct ciphdr)) - /* no payload */ - goto next; - for (dv = (struct dvdbc *)ptr; - (char *)dv < (char *)(ptr + ciph->len); - dv+=6) { - -#if DEBUG - fprintf(stderr, "(%d,%d) ", dv->sct, dv->dseq); -#endif - if (dv->sct == DV_SCT_HEADER && dv->dseq == 0) { - if (system < 0) { - system = ciph->fdf.dv.fs; - fprintf(stderr, "%s\n", system_name[system]); - } - - /* Fix DSF bit */ - if (system == 1 && - (dv->payload[0] & DV_DSF_12) == 0) - dv->payload[0] |= DV_DSF_12; - nb = nblocks[system]; - fprintf(stderr, "%d:%02d:%02d %d\r", - k / (3600 * frame_rate[system]), - (k / (60 * frame_rate[system])) % 60, - (k / frame_rate[system]) % 60, - k % frame_rate[system]); - -#if FIX_FRAME - if (m > 0 && m != nb) { - /* padding bad frame */ - npad = ((nb - m) % nb); - if (npad < 0) - npad += nb; - fprintf(stderr, "\n%d blocks padded\n", - npad); - npad *= DSIZE; - wbuf[vec].iov_base = pad; - wbuf[vec++].iov_len = npad; - if (vec >= NPACKET_R) { - writev(fd, wbuf, vec); - vec = 0; - } - } -#endif - k++; - fflush(stderr); - m = 0; - } - if (k == 0 || (count > 0 && k > count)) - continue; - m++; - wbuf[vec].iov_base = (char *) dv; - wbuf[vec++].iov_len = DSIZE; - if (vec >= NPACKET_R) { - writev(fd, wbuf, vec); - vec = 0; - } - } - ptr = (u_int32_t *)dv; -next: - if ((char *)ptr < buf + tlen) - goto again; - if (vec > 0) - writev(fd, wbuf, vec); - } - if (fd != STDOUT_FILENO) - close(fd); - fprintf(stderr, "\n"); -} - - -void -dvsend(int d, const char *filename, char ich, int count) -{ - struct fw_isochreq isoreq; - struct fw_isobufreq bufreq; - struct dvdbc *dv; - struct fw_pkt *pkt; - int len, tlen, header, fd, frames, packets, vec, offset, nhdr, i; - int system=-1, pad_acc, cycle_acc, cycle, f_cycle, f_frac; - struct iovec wbuf[TNBUF*2 + NEMPTY]; - char *pbuf; - u_int32_t iso_data, iso_empty, hdr[TNBUF + NEMPTY][3]; - struct ciphdr *ciph; - struct timeval start, end; - double rtime; - - fd = open(filename, O_RDONLY); - if (fd == -1) - err(EX_NOINPUT, filename); - - pbuf = malloc(DSIZE * TNBUF); - bzero(wbuf, sizeof(wbuf)); - - bufreq.rx.nchunk = 0; - bufreq.rx.npacket = 0; - bufreq.rx.psize = 0; - bufreq.tx.nchunk = NCHUNK; - bufreq.tx.npacket = NPACKET_T; - bufreq.tx.psize = PSIZE; - if (ioctl(d, FW_SSTBUF, &bufreq) < 0) - err(1, "ioctl FW_SSTBUF"); - - isoreq.ch = ich & 0x3f; - isoreq.tag = (ich >> 6) & 3; - - if (ioctl(d, FW_STSTREAM, &isoreq) < 0) - err(1, "ioctl FW_STSTREAM"); - - iso_data = 0; - pkt = (struct fw_pkt *) &iso_data; - pkt->mode.stream.len = DSIZE + sizeof(struct ciphdr); - pkt->mode.stream.sy = 0; - pkt->mode.stream.tcode = FWTCODE_STREAM; - pkt->mode.stream.chtag = ich; - iso_empty = iso_data; - pkt = (struct fw_pkt *) &iso_empty; - pkt->mode.stream.len = sizeof(struct ciphdr); - - bzero(hdr[0], sizeof(hdr[0])); - hdr[0][0] = iso_data; - ciph = (struct ciphdr *)&hdr[0][1]; - ciph->src = 0; /* XXX */ - ciph->len = 120; - ciph->dbc = 0; - ciph->eoh1 = 1; - ciph->fdf.dv.cyc = 0xffff; - - for (i = 1; i < TNBUF; i++) - bcopy(hdr[0], hdr[i], sizeof(hdr[0])); - - gettimeofday(&start, NULL); -#if DEBUG - fprintf(stderr, "%08x %08x %08x\n", - htonl(hdr[0]), htonl(hdr[1]), htonl(hdr[2])); -#endif - frames = 0; - packets = 0; - pad_acc = 0; - while (1) { - tlen = 0; - while (tlen < DSIZE * TNBUF) { - len = read(fd, pbuf + tlen, DSIZE * TNBUF - tlen); - if (len <= 0) { - if (tlen > 0) - break; - if (len < 0) - warn("read"); - else - fprintf(stderr, "\nend of file\n"); - goto send_end; - } - tlen += len; - } - vec = 0; - offset = 0; - nhdr = 0; -next: - dv = (struct dvdbc *)(pbuf + offset * DSIZE); -#if 0 - header = (dv->sct == 0 && dv->dseq == 0); -#else - header = (packets == 0 || packets % npackets[system] == 0); -#endif - - ciph = (struct ciphdr *)&hdr[nhdr][1]; - if (header) { - if (system < 0) { - system = ((dv->payload[0] & DV_DSF_12) != 0); - printf("%s\n", system_name[system]); - cycle = 1; - cycle_acc = frame_cycle[system].d * cycle; - } - fprintf(stderr, "%d", frames % 10); - frames ++; - if (count > 0 && frames > count) - break; - if (frames % frame_rate[system] == 0) - fprintf(stderr, "\n"); - fflush(stderr); - f_cycle = (cycle_acc / frame_cycle[system].d) & 0xf; - f_frac = (cycle_acc % frame_cycle[system].d - * CYCLE_FRAC) / frame_cycle[system].d; -#if 0 - ciph->fdf.dv.cyc = htons(f_cycle << 12 | f_frac); -#else - ciph->fdf.dv.cyc = htons(cycle << 12 | f_frac); -#endif - cycle_acc += frame_cycle[system].n; - cycle_acc %= frame_cycle[system].d * 0x10; - - } else { - ciph->fdf.dv.cyc = 0xffff; - } - ciph->dbc = packets++ % 256; - pad_acc += pad_rate[system].n; - if (pad_acc >= pad_rate[system].d) { - pad_acc -= pad_rate[system].d; - bcopy(hdr[nhdr], hdr[nhdr+1], sizeof(hdr[0])); - hdr[nhdr][0] = iso_empty; - wbuf[vec].iov_base = (char *)hdr[nhdr]; - wbuf[vec++].iov_len = sizeof(hdr[0]); - nhdr ++; - cycle ++; - } - hdr[nhdr][0] = iso_data; - wbuf[vec].iov_base = (char *)hdr[nhdr]; - wbuf[vec++].iov_len = sizeof(hdr[0]); - wbuf[vec].iov_base = (char *)dv; - wbuf[vec++].iov_len = DSIZE; - nhdr ++; - cycle ++; - offset ++; - if (offset * DSIZE < tlen) - goto next; - -again: - len = writev(d, wbuf, vec); - if (len < 0) { - if (errno == EAGAIN) { - fprintf(stderr, "(EAGAIN) - push 'Play'?\n"); - goto again; - } - err(1, "write failed"); - } - } - close(fd); - fprintf(stderr, "\n"); -send_end: - gettimeofday(&end, NULL); - rtime = end.tv_sec - start.tv_sec - + (end.tv_usec - start.tv_usec) * 1e-6; - fprintf(stderr, "%d frames, %.2f secs, %.2f frames/sec\n", - frames, rtime, frames/rtime); -} diff --git a/usr.sbin/fwcontrol/fwmethods.h b/usr.sbin/fwcontrol/fwmethods.h deleted file mode 100644 index 9ac82e6..0000000 --- a/usr.sbin/fwcontrol/fwmethods.h +++ /dev/null @@ -1,10 +0,0 @@ -/*- - * This file is in the public domain. - * - * $FreeBSD$ - */ - -typedef void (fwmethod)(int dev_fd, const char *filename, char ich, int count); -extern fwmethod dvrecv; -extern fwmethod dvsend; -extern fwmethod mpegtsrecv; diff --git a/usr.sbin/fwcontrol/fwmpegts.c b/usr.sbin/fwcontrol/fwmpegts.c deleted file mode 100644 index e92b799..0000000 --- a/usr.sbin/fwcontrol/fwmpegts.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (C) 2005 - * Petr Holub, Hidetoshi Shimokawa. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by Hidetoshi Shimokawa. - * - * 4. Neither the name of the author nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include -#include -#include -#include -#include - -#if __FreeBSD_version >= 500000 -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(__FreeBSD__) -#include -#include -#elif defined(__NetBSD__) -#include -#include -#else -#warning "You need to add support for your OS" -#endif - - -#include "fwmethods.h" - -#define DEBUG 0 - -/***************************************************************************** - -MPEG-2 Transport Stream (MPEG TS) packet format according to IEC 61883: - -31 15 0 -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- -| len |tag| channel | tcode | sy | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 1394 -| header_CRC | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- -|0|0| sid | dbs |fn | qpc |S|RSV| dbc | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ CIP -|1|0| fmt | fdf | fdf/syt | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- -| reserved | cycle_count | cycle_offset | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -| | N x -. . MPEG -. MPEG TS payload 188 bytes . -. . -| | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -------- -| data_CRC | -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - -N.b. that CRCs are removed by firewire layer! - -The following fiels are fixed for IEEE-1394: -tag = 01b -tcode = 1010b -The length is payload length, i.e. includes CIP header and data size. - -The following fields are constant for MPEG TS: -sph = 1 (denoted as S in CIP header above) -dbs = 6 -fmt = (1<<5) -fdf = reserved -In the supported streams we also require -qpc = 0 -fn = 3 -and thus the payload is divided in 8 blocks as follows: - - +-----+-----+-----+-----+-----+-----+-----+-----+ - | db0 | db1 | db2 | db3 | db4 | db5 | db6 | db7 | - +-----+-----+-----+-----+-----+-----+-----+-----+ - -We have several cases of payload distribution based on stream -bandwidth (R): -1) R < 1.5 Mbps: any of db0..db7 may be payload, -2) 1.5 < R < 3 Mbps: db0/db1 or db2/db3 or db4/db5 or db6/db7 is payload, -3) 3 < R < 6 Mbps: db0/db1/db2/db3 or db4/db5/db6/db7 is payload, -4) R > 6 Mbps: all db0..db7 contain the payload. -Curently, only case (4) is supported in fwmpegts.c - -Each packet may contain N MPEG TS data blocks with timestamp header, -which are (4+188)B long. Experimentally, the N ranges from 0 through 3. - -*****************************************************************************/ - - -typedef uint8_t mpeg_ts_pld[188]; - -struct mpeg_pldt { -#if BYTE_ORDER == BIG_ENDIAN - uint32_t :7, - c_count:13, - c_offset:12; -#else /* BYTE_ORDER != BIG_ENDIAN */ - uint32_t c_offset:12, - c_count:13, - :7; -#endif /* BYTE_ORDER == BIG_ENDIAN */ - mpeg_ts_pld payload; -}; - - -#define NCHUNK 8 -#define PSIZE 596 -#define NPACKET_R 4096 -#define RBUFSIZE (PSIZE * NPACKET_R) - -void -mpegtsrecv(int d, const char *filename, char ich, int count) -{ - struct ciphdr *ciph; - struct fw_isochreq isoreq; - struct fw_isobufreq bufreq; - struct fw_pkt *pkt; - struct mpeg_pldt *pld; - uint32_t *ptr; - int fd, k, len, m, pkt_size, startwr, tlen; - char *buf; - - startwr = 0; - - if (strcmp(filename, "-") == 0) - fd = STDOUT_FILENO; - else { - fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0660); - if (fd == -1) - err(EX_NOINPUT, filename); - } - buf = malloc(RBUFSIZE); - - bufreq.rx.nchunk = NCHUNK; - bufreq.rx.npacket = NPACKET_R; - bufreq.rx.psize = PSIZE; - bufreq.tx.nchunk = 0; - bufreq.tx.npacket = 0; - bufreq.tx.psize = 0; - if (ioctl(d, FW_SSTBUF, &bufreq) < 0) - err(1, "ioctl"); - - isoreq.ch = ich & 0x3f; - isoreq.tag = (ich >> 6) & 3; - - if (ioctl(d, FW_SRSTREAM, &isoreq) < 0) - err(1, "ioctl"); - - k = m = 0; - while (count <= 0 || k <= count) { - len = tlen = read(d, buf, RBUFSIZE); -#if DEBUG - fprintf(stderr, "Read %d bytes.\n", len); -#endif /* DEBUG */ - if (len < 0) { - if (errno == EAGAIN) { - fprintf(stderr, "(EAGAIN) - push 'Play'?\n"); - continue; - } - err(1, "read failed"); - } - ptr = (uint32_t *) buf; - - do { - pkt = (struct fw_pkt *) ptr; -#if DEBUG - fprintf(stderr, "\nReading new packet.\n"); - fprintf(stderr, "%08x %08x %08x %08x\n", - htonl(ptr[0]), htonl(ptr[1]), - htonl(ptr[2]), htonl(ptr[3])); -#endif /* DEBUG */ - /* there is no CRC in the 1394 header */ - ciph = (struct ciphdr *)(ptr + 1); /* skip iso header */ - if (ciph->fmt != CIP_FMT_MPEG) - errx(1, "unknown format 0x%x", ciph->fmt); - if (ciph->fn != 3) { - errx(1, - "unsupported MPEG TS stream, fn=%d (only fn=3 is supported)", - ciph->fn); - } - ptr = (uint32_t *) (ciph + 1); /* skip cip header */ - - if (pkt->mode.stream.len <= sizeof(struct ciphdr)) { - /* no payload */ - /* tlen needs to be decremented before end of the loop */ - goto next; - } -#if DEBUG - else { - fprintf(stderr, - "Packet net payload length (IEEE1394 header): %d\n", - pkt->mode.stream.len - sizeof(struct ciphdr)); - fprintf(stderr, "Data block size (CIP header): %d [q], %d [B]\n", - ciph->len, ciph->len * 4); - fprintf(stderr, - "Data fraction number (CIP header): %d => DBC increments with %d\n", - ciph->fn, (1<fn) ); - fprintf(stderr, "QCP (CIP header): %d\n", ciph->qpc ); - fprintf(stderr, "DBC counter (CIP header): %d\n", ciph->dbc ); - fprintf(stderr, "MPEG payload type size: %d\n", - sizeof(struct mpeg_pldt)); - } -#endif /* DEBUG */ - - /* This is a condition that needs to be satisfied to start - writing the data */ - if (ciph->dbc % (1<fn) == 0) - startwr = 1; - /* Read out all the MPEG TS data blocks from current packet */ - for (pld = (struct mpeg_pldt *)ptr; - (intptr_t)pld < (intptr_t)((char *)ptr + - pkt->mode.stream.len - sizeof(struct ciphdr)); - pld++) { - if (startwr == 1) - write(fd, pld->payload, - sizeof(pld->payload)); - } - -next: - /* CRCs are removed from both header and trailer - so that only 4 bytes of 1394 header remains */ - pkt_size = pkt->mode.stream.len + 4; - ptr = (uint32_t *)((intptr_t)pkt + pkt_size); - tlen -= pkt_size; - } while (tlen > 0); -#if DEBUG - fprintf(stderr, "\nReading a data from firewire.\n"); -#endif /* DEBUG */ - - } - if (fd != STDOUT_FILENO) - close(fd); - fprintf(stderr, "\n"); -} diff --git a/usr.sbin/getfmac/Makefile b/usr.sbin/getfmac/Makefile deleted file mode 100644 index f9fa1b2..0000000 --- a/usr.sbin/getfmac/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= getfmac -MAN= getfmac.8 - -.include diff --git a/usr.sbin/getfmac/getfmac.8 b/usr.sbin/getfmac/getfmac.8 deleted file mode 100644 index f8ebb31..0000000 --- a/usr.sbin/getfmac/getfmac.8 +++ /dev/null @@ -1,57 +0,0 @@ -.\" Copyright (c) 2002 Networks Associates Technology, Inc. -.\" All rights reserved. -.\" -.\" This software was developed for the FreeBSD Project by Chris -.\" Costello at Safeport Network Services and NAI Labs, the Security -.\" Research Division of Network Associates, Inc. under DARPA/SPAWAR -.\" contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS -.\" research program. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The names of the authors may not be used to endorse or promote -.\" products derived from this software without specific prior written -.\" permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd June 27, 2002 -.Dt GETFMAC 8 -.Os -.Sh NAME -.Nm getfmac -.Nd print MAC label for a file system object -.Sh SYNOPSIS -.Nm -.Op Fl h -.Op Fl l Ar list,of,labels -.Op Ar -.Sh DESCRIPTION -The -.Nm -utility prints the text representation of the MAC label associated with the -specified files. -.Sh SEE ALSO -.Xr mac 3 , -.Xr mac_get_file 3 , -.Xr mac 4 , -.Xr setfmac 8 , -.Xr mac 9 diff --git a/usr.sbin/getfmac/getfmac.c b/usr.sbin/getfmac/getfmac.c deleted file mode 100644 index 7c03d59..0000000 --- a/usr.sbin/getfmac/getfmac.c +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * Copyright (c) 2002 Networks Associates Technology, Inc. - * All rights reserved. - * - * This software was developed for the FreeBSD Project by NAI Labs, the - * Security Research Division of Network Associates, Inc. under - * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA - * CHATS research program. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The names of the authors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define MAXELEMENTS 32 - -static void -usage(void) -{ - - fprintf(stderr, - "getfmac [-h] [-l list,of,labels] [file1] [file2 ...]\n"); - exit (EX_USAGE); -} - -int -main(int argc, char *argv[]) -{ - char *labellist, *string; - mac_t label; - int ch, hflag; - int error, i; - - labellist = NULL; - hflag = 0; - while ((ch = getopt(argc, argv, "hl:")) != -1) { - switch (ch) { - case 'h': - hflag = 1; - break; - case 'l': - if (labellist != NULL) - usage(); - labellist = argv[optind - 1]; - break; - default: - usage(); - } - - } - - for (i = optind; i < argc; i++) { - if (labellist != NULL) - error = mac_prepare(&label, labellist); - else - error = mac_prepare_file_label(&label); - - if (error != 0) { - perror("mac_prepare"); - return (-1); - } - - if (hflag) - error = mac_get_link(argv[i], label); - else - error = mac_get_file(argv[i], label); - if (error) { - perror(argv[i]); - mac_free(label); - continue; - } - - error = mac_to_text(label, &string); - if (error != 0) - perror("mac_to_text"); - else { - printf("%s: %s\n", argv[i], string); - free(string); - } - mac_free(label); - } - - exit(EX_OK); -} diff --git a/usr.sbin/getpmac/Makefile b/usr.sbin/getpmac/Makefile deleted file mode 100644 index 5974728..0000000 --- a/usr.sbin/getpmac/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= getpmac -MAN= getpmac.8 - -.include diff --git a/usr.sbin/getpmac/getpmac.8 b/usr.sbin/getpmac/getpmac.8 deleted file mode 100644 index 307c962..0000000 --- a/usr.sbin/getpmac/getpmac.8 +++ /dev/null @@ -1,59 +0,0 @@ -.\" Copyright (c) 2003 Networks Associates Technology, Inc. -.\" All rights reserved. -.\" -.\" This software was developed for the FreeBSD Project by Chris Costello -.\" at Safeport Network Services and Network Associates Labs, the -.\" Security Research Division of Network Associates, Inc. under -.\" DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the -.\" DARPA CHATS research program. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd January 14, 2003 -.Dt GETPMAC 8 -.Os -.Sh NAME -.Nm getpmac -.Nd print process-related MAC labels -.Sh SYNOPSIS -.Nm -.Op Fl l Ar list,of,labels -.Op Fl p Ar pid -.Sh DESCRIPTION -The -.Nm -utility prints the text representation of the MAC label associated with the -specified process. -If no process is specified, it prints the label associated with its own -process. -.Sh SEE ALSO -.Xr mac 3 , -.Xr mac_get_pid 3 , -.Xr mac_get_proc 3 , -.Xr mac 4 , -.Xr maclabel 7 , -.Xr getfmac 8 , -.Xr setfmac 8 , -.Xr setpmac 8 , -.Xr mac 9 diff --git a/usr.sbin/getpmac/getpmac.c b/usr.sbin/getpmac/getpmac.c deleted file mode 100644 index 2abe87f..0000000 --- a/usr.sbin/getpmac/getpmac.c +++ /dev/null @@ -1,127 +0,0 @@ -/*- - * Copyright (c) 2002 Networks Associates Technology, Inc. - * All rights reserved. - * - * This software was developed for the FreeBSD Project by Network - * Associates Laboratories, the Security Research Division of Network - * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 - * ("CBOSS"), as part of the DARPA CHATS research program. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The names of the authors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#define MAXELEMENTS 32 - -static void -usage(void) -{ - - fprintf(stderr, "getpmac [-l list,of,labels] [-p pid]\n"); - exit (EX_USAGE); -} - -int -main(int argc, char *argv[]) -{ - char *labellist, *string; - mac_t label; - pid_t pid; - int ch, error, pid_set; - - pid_set = 0; - pid = 0; - labellist = NULL; - while ((ch = getopt(argc, argv, "l:p:")) != -1) { - switch (ch) { - case 'l': - if (labellist != NULL) - usage(); - labellist = argv[optind - 1]; - break; - case 'p': - if (pid_set) - usage(); - pid = atoi(argv[optind - 1]); - pid_set = 1; - break; - default: - usage(); - } - - } - - argc -= optind; - argv += optind; - - if (argc != 0) - usage(); - - if (labellist != NULL) - error = mac_prepare(&label, labellist); - else - error = mac_prepare_process_label(&label); - if (error != 0) { - perror("mac_prepare"); - return (-1); - } - - if (pid_set) { - error = mac_get_pid(pid, label); - if (error) - perror("mac_get_pid"); - } else { - error = mac_get_proc(label); - if (error) - perror("mac_get_proc"); - } - if (error) { - mac_free(label); - exit (-1); - } - error = mac_to_text(label, &string); - if (error != 0) { - perror("mac_to_text"); - exit(EX_DATAERR); - } - - if (strlen(string) > 0) - printf("%s\n", string); - - mac_free(label); - free(string); - exit(EX_OK); -} diff --git a/usr.sbin/gpioctl/Makefile b/usr.sbin/gpioctl/Makefile deleted file mode 100644 index 997f0c7..0000000 --- a/usr.sbin/gpioctl/Makefile +++ /dev/null @@ -1,6 +0,0 @@ -# $FreeBSD$ - -PROG= gpioctl -MAN= gpioctl.8 - -.include diff --git a/usr.sbin/gpioctl/gpioctl.8 b/usr.sbin/gpioctl/gpioctl.8 deleted file mode 100644 index 12bae3a..0000000 --- a/usr.sbin/gpioctl/gpioctl.8 +++ /dev/null @@ -1,123 +0,0 @@ -.\" Copyright (c) 1980, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd September 27, 2010 -.Dt GPIOCTL 1 -.Os -.Sh NAME -.Nm gpioctl -.Nd GPIO control utility -.Sh SYNOPSIS -.Nm -.Cm -l -.Fl f Ar ctldev -.Op Fl v -.Nm -.Cm -t -.Fl f Ar ctldev -.Ar pin -.Nm -.Cm -c -.Fl f Ar ctldev -.Ar pin -.Ar flag -.Op flag ... -.Nm -.Cm -f Ar ctldev -.Ar pin -.Ar [0|1] -.Sh DESCRIPTION -The -.Nm -utility could be used to manage GPIO pins from userland and list available pins. -.Pp -The options are as follows: -.Bl -tag -width ".Fl f Ar ctldev" -.It Fl c Ar pin Ar flag Op flag ... -Configure pin by setting provided flags. The following flags are currently defined: -.Bl -tag -offset indent -width ".Cm PULSE" -.It Cm IN -Input pin -.It Cm OUT -Output pin -.It Cm OD -Open drain pin -.It Cm PP -Push pull pin -.It Cm TS -Tristate pin -.It Cm PU -Pull-up pin -.It Cm PD -Pull-down pin -.It Cm II -Inverted input pin -.It Cm IO -Inverted output pin -.El -.It Fl f Ar ctldev -GPIO controller device to use -.It Fl l -list available pins -.It Fl t Ar pin -toggle value of provided pin number -.It Fl v -be verbose: for each listed pin print current configuration -.El -.Sh EXAMPLES -.Bl -bullet -.It -List pins available on GPIO controller defined by device /dev/gpioctl0 -.Pp -gpioctl -f /dev/gpioctl0 -l -.It -Set the value of pin 12 to 1 -.Pp -gpioctl -f /dev/gpioctl0 12 1 -.It -Configure pin 12 to be input pin -.Pp -gpioctl -f /dev/gpioctl0 -c 12 IN -.El -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 9.0 . -.Sh AUTHORS -.An -nosplit -The -.Nm -utility and this manual page were written by -.An Oleksandr Tymoshenko -.Aq gonzo@freebsd.org diff --git a/usr.sbin/gpioctl/gpioctl.c b/usr.sbin/gpioctl/gpioctl.c deleted file mode 100644 index 8956ef4..0000000 --- a/usr.sbin/gpioctl/gpioctl.c +++ /dev/null @@ -1,323 +0,0 @@ -/*- - * Copyright (c) 2009, Oleksandr Tymoshenko - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice unmodified, this list of conditions, and the following - * disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include - -#include - -struct flag_desc { - const char *name; - uint32_t flag; -}; - -struct flag_desc gpio_flags[] = { - { "IN", GPIO_PIN_INPUT }, - { "OUT", GPIO_PIN_OUTPUT }, - { "OD", GPIO_PIN_OPENDRAIN }, - { "PP", GPIO_PIN_PUSHPULL }, - { "TS", GPIO_PIN_TRISTATE }, - { "PU", GPIO_PIN_PULLUP }, - { "PD", GPIO_PIN_PULLDOWN }, - { "II", GPIO_PIN_INVIN }, - { "IO", GPIO_PIN_INVOUT }, - { "PULSE", GPIO_PIN_PULSATE }, - { NULL, 0 }, -}; - -int str2cap(const char *str); - -static void -usage(void) -{ - fprintf(stderr, "Usage:\n"); - fprintf(stderr, "\tgpioctl -f ctldev -l [-v]\n"); - fprintf(stderr, "\tgpioctl -f ctldev -t pin\n"); - fprintf(stderr, "\tgpioctl -f ctldev -c pin flag ...\n"); - fprintf(stderr, "\tgpioctl -f ctldev pin [0|1]\n"); - exit(1); -} - -static const char * -cap2str(uint32_t cap) -{ - struct flag_desc * pdesc = gpio_flags; - while (pdesc->name) { - if (pdesc->flag == cap) - return pdesc->name; - pdesc++; - } - - return "UNKNOWN"; -} - -int -str2cap(const char *str) -{ - struct flag_desc * pdesc = gpio_flags; - while (pdesc->name) { - if (strcasecmp(str, pdesc->name) == 0) - return pdesc->flag; - pdesc++; - } - - return (-1); -} - -/* - * Our handmade function for converting string to number - */ -static int -str2int(const char *s, int *ok) -{ - char *endptr; - int res = strtod(s, &endptr); - if (endptr != s + strlen(s) ) - *ok = 0; - else - *ok = 1; - - return res; -} - -static void -print_caps(int caps) -{ - int i, need_coma; - - need_coma = 0; - printf("<"); - for (i = 0; i < 32; i++) { - if (caps & (1 << i)) { - if (need_coma) - printf(","); - printf("%s", cap2str(1 << i)); - need_coma = 1; - } - } - printf(">"); -} - -static void -dump_pins(int fd, int verbose) -{ - int i, maxpin; - struct gpio_pin pin; - struct gpio_req req; - - if (ioctl(fd, GPIOMAXPIN, &maxpin) < 0) { - perror("ioctl(GPIOMAXPIN)"); - exit(1); - } - - for (i = 0; i <= maxpin; i++) { - pin.gp_pin = i; - if (ioctl(fd, GPIOGETCONFIG, &pin) < 0) - /* For some reason this pin is inaccessible */ - continue; - - req.gp_pin = i; - if (ioctl(fd, GPIOGET, &req) < 0) { - /* Now, that's wrong */ - perror("ioctl(GPIOGET)"); - exit(1); - } - - printf("pin %02d:\t%d\t%s", pin.gp_pin, req.gp_value, - pin.gp_name); - - print_caps(pin.gp_flags); - - if (verbose) { - printf(", caps:"); - print_caps(pin.gp_caps); - } - printf("\n"); - } -} - -static void -fail(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - exit(1); -} - -int -main(int argc, char **argv) -{ - int i; - struct gpio_pin pin; - struct gpio_req req; - char *ctlfile = NULL; - int pinn, pinv, fd, ch; - int flags, flag, ok; - int config, toggle, verbose, list; - - config = toggle = verbose = list = pinn = 0; - - while ((ch = getopt(argc, argv, "c:f:lt:v")) != -1) { - switch (ch) { - case 'c': - config = 1; - pinn = str2int(optarg, &ok); - if (!ok) - fail("Invalid pin number: %s\n", optarg); - break; - case 'f': - ctlfile = optarg; - break; - case 'l': - list = 1; - break; - case 't': - toggle = 1; - pinn = str2int(optarg, &ok); - if (!ok) - fail("Invalid pin number: %s\n", optarg); - break; - case 'v': - verbose = 1; - break; - default: - usage(); - break; - } - } - argv += optind; - argc -= optind; - for (i = 0; i < argc; i++) - printf("%d/%s\n", i, argv[i]); - - if (ctlfile == NULL) - fail("No gpioctl device provided\n"); - - fd = open(ctlfile, O_RDONLY); - if (fd < 0) { - perror("open"); - exit(1); - } - - if (list) { - dump_pins(fd, verbose); - close(fd); - exit(0); - } - - if (toggle) { - /* - * -t pin assumes no additional arguments - */ - if(argc > 0) { - usage(); - exit(1); - } - - req.gp_pin = pinn; - if (ioctl(fd, GPIOTOGGLE, &req) < 0) { - perror("ioctl(GPIOTOGGLE)"); - exit(1); - } - - close(fd); - exit (0); - } - - if (config) { - flags = 0; - for (i = 0; i < argc; i++) { - flag = str2cap(argv[i]); - if (flag < 0) - fail("Invalid flag: %s\n", argv[i]); - flags |= flag; - } - - pin.gp_pin = pinn; - pin.gp_flags = flags; - if (ioctl(fd, GPIOSETCONFIG, &pin) < 0) { - perror("ioctl(GPIOSETCONFIG)"); - exit(1); - } - - exit(0); - } - - /* - * Last two cases - set value or print value - */ - if ((argc == 0) || (argc > 2)) { - usage(); - exit(1); - } - - pinn = str2int(argv[0], &ok); - if (!ok) - fail("Invalid pin number: %s\n", argv[0]); - - /* - * Read pin value - */ - if (argc == 1) { - req.gp_pin = pinn; - if (ioctl(fd, GPIOGET, &req) < 0) { - perror("ioctl(GPIOGET)"); - exit(1); - } - printf("%d\n", req.gp_value); - exit (0); - } - - /* Is it valid number (0 or 1) ? */ - pinv = str2int(argv[1], &ok); - if (!ok || ((pinv != 0) && (pinv != 1))) - fail("Invalid pin value: %s\n", argv[1]); - - /* - * Set pin value - */ - req.gp_pin = pinn; - req.gp_value = pinv; - if (ioctl(fd, GPIOSET, &req) < 0) { - perror("ioctl(GPIOSET)"); - exit(1); - } - - close(fd); - exit(0); -} diff --git a/usr.sbin/gssd/Makefile b/usr.sbin/gssd/Makefile deleted file mode 100644 index 45d8de4..0000000 --- a/usr.sbin/gssd/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# $FreeBSD$ - -PROG= gssd -MAN= gssd.8 -SRCS= gssd.c gssd.h gssd_svc.c gssd_xdr.c gssd_prot.c - -CFLAGS+= -I. -WARNS?= 1 - -DPADD= ${LIBGSSAPI} -LDADD= -lgssapi - -CLEANFILES= gssd_svc.c gssd.h - -RPCSRC= ${.CURDIR}/../../sys/kgssapi/gssd.x -RPCGEN= rpcgen -L -C -M - -gssd_svc.c: ${RPCSRC} gssd.h - ${RPCGEN} -m -o ${.TARGET} ${RPCSRC} - -gssd_xdr.c: ${RPCSRC} gssd.h - ${RPCGEN} -c -o ${.TARGET} ${RPCSRC} - -gssd.h: ${RPCSRC} - ${RPCGEN} -h -o ${.TARGET} ${RPCSRC} - -.PATH: ${.CURDIR}/../../sys/kgssapi - -.include diff --git a/usr.sbin/gssd/gssd.8 b/usr.sbin/gssd/gssd.8 deleted file mode 100644 index 02116e5..0000000 --- a/usr.sbin/gssd/gssd.8 +++ /dev/null @@ -1,68 +0,0 @@ -.\" Copyright (c) 2008 Isilon Inc http://www.isilon.com/ -.\" Authors: Doug Rabson -.\" Developed with Red Inc: Alfred Perlstein -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd November 5, 2008 -.Dt GSSD 8 -.Os -.Sh NAME -.Nm gssd -.Nd "Generic Security Services Daemon" -.Sh SYNOPSIS -.Nm -.Op Fl d -.Sh DESCRIPTION -The -.Nm -program provides support for the kernel GSS-API implementation. -.Pp -The options are as follows: -.Bl -tag -.It Fl d -Run in debug mode. -In this mode, -.Nm -will not fork when it starts. -.El -.Sh FILES -.Bl -tag -width ".Pa /etc/krb5.keytab" -compact -.It Pa /etc/krb5.keytab -Contains Kerberos service principals which may be used as credentials -by kernel GSS-API services. -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr gssapi 3 -.Sh HISTORY -The -.Nm -manual page first appeared in -.Fx 8.0 . -.Sh AUTHORS -This -manual page was written by -.An Doug Rabson Aq dfr@FreeBSD.org . diff --git a/usr.sbin/gssd/gssd.c b/usr.sbin/gssd/gssd.c deleted file mode 100644 index ba2805b..0000000 --- a/usr.sbin/gssd/gssd.c +++ /dev/null @@ -1,610 +0,0 @@ -/*- - * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ - * Authors: Doug Rabson - * Developed with Red Inc: Alfred Perlstein - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gssd.h" - -#ifndef _PATH_GSS_MECH -#define _PATH_GSS_MECH "/etc/gss/mech" -#endif -#ifndef _PATH_GSSDSOCK -#define _PATH_GSSDSOCK "/var/run/gssd.sock" -#endif - -struct gss_resource { - LIST_ENTRY(gss_resource) gr_link; - uint64_t gr_id; /* indentifier exported to kernel */ - void* gr_res; /* GSS-API resource pointer */ -}; -LIST_HEAD(gss_resource_list, gss_resource) gss_resources; -int gss_resource_count; -uint32_t gss_next_id; -uint32_t gss_start_time; -int debug_level; - -static void gssd_load_mech(void); - -extern void gssd_1(struct svc_req *rqstp, SVCXPRT *transp); -extern int gssd_syscall(char *path); - -int -main(int argc, char **argv) -{ - /* - * We provide an RPC service on a local-domain socket. The - * kernel's GSS-API code will pass what it can't handle - * directly to us. - */ - struct sockaddr_un sun; - int fd, oldmask, ch, debug; - SVCXPRT *xprt; - - debug = 0; - while ((ch = getopt(argc, argv, "d")) != -1) { - switch (ch) { - case 'd': - debug_level++; - break; - default: - fprintf(stderr, "usage: %s [-d]\n", argv[0]); - exit(1); - break; - } - } - - gssd_load_mech(); - - if (!debug_level) - daemon(0, 0); - - memset(&sun, 0, sizeof sun); - sun.sun_family = AF_LOCAL; - unlink(_PATH_GSSDSOCK); - strcpy(sun.sun_path, _PATH_GSSDSOCK); - sun.sun_len = SUN_LEN(&sun); - fd = socket(AF_LOCAL, SOCK_STREAM, 0); - if (!fd) { - err(1, "Can't create local gssd socket"); - } - oldmask = umask(S_IXUSR|S_IRWXG|S_IRWXO); - if (bind(fd, (struct sockaddr *) &sun, sun.sun_len) < 0) { - err(1, "Can't bind local gssd socket"); - } - umask(oldmask); - if (listen(fd, SOMAXCONN) < 0) { - err(1, "Can't listen on local gssd socket"); - } - xprt = svc_vc_create(fd, RPC_MAXDATASIZE, RPC_MAXDATASIZE); - if (!xprt) { - err(1, "Can't create transport for local gssd socket"); - } - if (!svc_reg(xprt, GSSD, GSSDVERS, gssd_1, NULL)) { - err(1, "Can't register service for local gssd socket"); - } - - LIST_INIT(&gss_resources); - gss_next_id = 1; - gss_start_time = time(0); - - gssd_syscall(_PATH_GSSDSOCK); - svc_run(); - - return (0); -} - -static void -gssd_load_mech(void) -{ - FILE *fp; - char buf[256]; - char *p; - char *name, *oid, *lib, *kobj; - - fp = fopen(_PATH_GSS_MECH, "r"); - if (!fp) - return; - - while (fgets(buf, sizeof(buf), fp)) { - if (*buf == '#') - continue; - p = buf; - name = strsep(&p, "\t\n "); - if (p) while (isspace(*p)) p++; - oid = strsep(&p, "\t\n "); - if (p) while (isspace(*p)) p++; - lib = strsep(&p, "\t\n "); - if (p) while (isspace(*p)) p++; - kobj = strsep(&p, "\t\n "); - if (!name || !oid || !lib || !kobj) - continue; - - if (strcmp(kobj, "-")) { - /* - * Attempt to load the kernel module if its - * not already present. - */ - if (modfind(kobj) < 0) { - if (kldload(kobj) < 0) { - fprintf(stderr, - "%s: can't find or load kernel module %s for %s\n", - getprogname(), kobj, name); - } - } - } - } - fclose(fp); -} - -static void * -gssd_find_resource(uint64_t id) -{ - struct gss_resource *gr; - - if (!id) - return (NULL); - - LIST_FOREACH(gr, &gss_resources, gr_link) - if (gr->gr_id == id) - return (gr->gr_res); - - return (NULL); -} - -static uint64_t -gssd_make_resource(void *res) -{ - struct gss_resource *gr; - - if (!res) - return (0); - - gr = malloc(sizeof(struct gss_resource)); - if (!gr) - return (0); - gr->gr_id = (gss_next_id++) + ((uint64_t) gss_start_time << 32); - gr->gr_res = res; - LIST_INSERT_HEAD(&gss_resources, gr, gr_link); - gss_resource_count++; - if (debug_level > 1) - printf("%d resources allocated\n", gss_resource_count); - - return (gr->gr_id); -} - -static void -gssd_delete_resource(uint64_t id) -{ - struct gss_resource *gr; - - LIST_FOREACH(gr, &gss_resources, gr_link) { - if (gr->gr_id == id) { - LIST_REMOVE(gr, gr_link); - free(gr); - gss_resource_count--; - if (debug_level > 1) - printf("%d resources allocated\n", - gss_resource_count); - return; - } - } -} - -bool_t -gssd_null_1_svc(void *argp, void *result, struct svc_req *rqstp) -{ - - return (TRUE); -} - -bool_t -gssd_init_sec_context_1_svc(init_sec_context_args *argp, init_sec_context_res *result, struct svc_req *rqstp) -{ - gss_cred_id_t cred = GSS_C_NO_CREDENTIAL; - gss_ctx_id_t ctx = GSS_C_NO_CONTEXT; - gss_name_t name = GSS_C_NO_NAME; - char ccname[strlen("FILE:/tmp/krb5cc_") + 6 + 1]; - - snprintf(ccname, sizeof(ccname), "FILE:/tmp/krb5cc_%d", - (int) argp->uid); - setenv("KRB5CCNAME", ccname, TRUE); - - memset(result, 0, sizeof(*result)); - if (argp->cred) { - cred = gssd_find_resource(argp->cred); - if (!cred) { - result->major_status = GSS_S_CREDENTIALS_EXPIRED; - return (TRUE); - } - } - if (argp->ctx) { - ctx = gssd_find_resource(argp->ctx); - if (!ctx) { - result->major_status = GSS_S_CONTEXT_EXPIRED; - return (TRUE); - } - } - if (argp->name) { - name = gssd_find_resource(argp->name); - if (!name) { - result->major_status = GSS_S_BAD_NAME; - return (TRUE); - } - } - - memset(result, 0, sizeof(*result)); - result->major_status = gss_init_sec_context(&result->minor_status, - cred, &ctx, name, argp->mech_type, - argp->req_flags, argp->time_req, argp->input_chan_bindings, - &argp->input_token, &result->actual_mech_type, - &result->output_token, &result->ret_flags, &result->time_rec); - - if (result->major_status == GSS_S_COMPLETE - || result->major_status == GSS_S_CONTINUE_NEEDED) { - if (argp->ctx) - result->ctx = argp->ctx; - else - result->ctx = gssd_make_resource(ctx); - } - - return (TRUE); -} - -bool_t -gssd_accept_sec_context_1_svc(accept_sec_context_args *argp, accept_sec_context_res *result, struct svc_req *rqstp) -{ - gss_ctx_id_t ctx = GSS_C_NO_CONTEXT; - gss_cred_id_t cred = GSS_C_NO_CREDENTIAL; - gss_name_t src_name; - gss_cred_id_t delegated_cred_handle; - - memset(result, 0, sizeof(*result)); - if (argp->ctx) { - ctx = gssd_find_resource(argp->ctx); - if (!ctx) { - result->major_status = GSS_S_CONTEXT_EXPIRED; - return (TRUE); - } - } - if (argp->cred) { - cred = gssd_find_resource(argp->cred); - if (!cred) { - result->major_status = GSS_S_CREDENTIALS_EXPIRED; - return (TRUE); - } - } - - memset(result, 0, sizeof(*result)); - result->major_status = gss_accept_sec_context(&result->minor_status, - &ctx, cred, &argp->input_token, argp->input_chan_bindings, - &src_name, &result->mech_type, &result->output_token, - &result->ret_flags, &result->time_rec, - &delegated_cred_handle); - - if (result->major_status == GSS_S_COMPLETE - || result->major_status == GSS_S_CONTINUE_NEEDED) { - if (argp->ctx) - result->ctx = argp->ctx; - else - result->ctx = gssd_make_resource(ctx); - result->src_name = gssd_make_resource(src_name); - result->delegated_cred_handle = - gssd_make_resource(delegated_cred_handle); - } - - return (TRUE); -} - -bool_t -gssd_delete_sec_context_1_svc(delete_sec_context_args *argp, delete_sec_context_res *result, struct svc_req *rqstp) -{ - gss_ctx_id_t ctx = gssd_find_resource(argp->ctx); - - if (ctx) { - result->major_status = gss_delete_sec_context( - &result->minor_status, &ctx, &result->output_token); - gssd_delete_resource(argp->ctx); - } else { - result->major_status = GSS_S_COMPLETE; - result->minor_status = 0; - } - - return (TRUE); -} - -bool_t -gssd_export_sec_context_1_svc(export_sec_context_args *argp, export_sec_context_res *result, struct svc_req *rqstp) -{ - gss_ctx_id_t ctx = gssd_find_resource(argp->ctx); - - if (ctx) { - result->major_status = gss_export_sec_context( - &result->minor_status, &ctx, - &result->interprocess_token); - result->format = KGSS_HEIMDAL_1_1; - gssd_delete_resource(argp->ctx); - } else { - result->major_status = GSS_S_FAILURE; - result->minor_status = 0; - result->interprocess_token.length = 0; - result->interprocess_token.value = NULL; - } - - return (TRUE); -} - -bool_t -gssd_import_name_1_svc(import_name_args *argp, import_name_res *result, struct svc_req *rqstp) -{ - gss_name_t name; - - result->major_status = gss_import_name(&result->minor_status, - &argp->input_name_buffer, argp->input_name_type, &name); - - if (result->major_status == GSS_S_COMPLETE) - result->output_name = gssd_make_resource(name); - else - result->output_name = 0; - - return (TRUE); -} - -bool_t -gssd_canonicalize_name_1_svc(canonicalize_name_args *argp, canonicalize_name_res *result, struct svc_req *rqstp) -{ - gss_name_t name = gssd_find_resource(argp->input_name); - gss_name_t output_name; - - memset(result, 0, sizeof(*result)); - if (!name) { - result->major_status = GSS_S_BAD_NAME; - return (TRUE); - } - - result->major_status = gss_canonicalize_name(&result->minor_status, - name, argp->mech_type, &output_name); - - if (result->major_status == GSS_S_COMPLETE) - result->output_name = gssd_make_resource(output_name); - else - result->output_name = 0; - - return (TRUE); -} - -bool_t -gssd_export_name_1_svc(export_name_args *argp, export_name_res *result, struct svc_req *rqstp) -{ - gss_name_t name = gssd_find_resource(argp->input_name); - - memset(result, 0, sizeof(*result)); - if (!name) { - result->major_status = GSS_S_BAD_NAME; - return (TRUE); - } - - result->major_status = gss_export_name(&result->minor_status, - name, &result->exported_name); - - return (TRUE); -} - -bool_t -gssd_release_name_1_svc(release_name_args *argp, release_name_res *result, struct svc_req *rqstp) -{ - gss_name_t name = gssd_find_resource(argp->input_name); - - if (name) { - result->major_status = gss_release_name(&result->minor_status, - &name); - gssd_delete_resource(argp->input_name); - } else { - result->major_status = GSS_S_COMPLETE; - result->minor_status = 0; - } - - return (TRUE); -} - -bool_t -gssd_pname_to_uid_1_svc(pname_to_uid_args *argp, pname_to_uid_res *result, struct svc_req *rqstp) -{ - gss_name_t name = gssd_find_resource(argp->pname); - uid_t uid; - char buf[128]; - struct passwd pwd, *pw; - - memset(result, 0, sizeof(*result)); - if (name) { - result->major_status = - gss_pname_to_uid(&result->minor_status, - name, argp->mech, &uid); - if (result->major_status == GSS_S_COMPLETE) { - result->uid = uid; - getpwuid_r(uid, &pwd, buf, sizeof(buf), &pw); - if (pw) { - int len = NGRPS; - int groups[NGRPS]; - result->gid = pw->pw_gid; - getgrouplist(pw->pw_name, pw->pw_gid, - groups, &len); - result->gidlist.gidlist_len = len; - result->gidlist.gidlist_val = - mem_alloc(len * sizeof(int)); - memcpy(result->gidlist.gidlist_val, groups, - len * sizeof(int)); - } else { - result->gid = 65534; - result->gidlist.gidlist_len = 0; - result->gidlist.gidlist_val = NULL; - } - } - } else { - result->major_status = GSS_S_BAD_NAME; - result->minor_status = 0; - } - - return (TRUE); -} - -bool_t -gssd_acquire_cred_1_svc(acquire_cred_args *argp, acquire_cred_res *result, struct svc_req *rqstp) -{ - gss_name_t desired_name = GSS_C_NO_NAME; - gss_cred_id_t cred; - char ccname[strlen("FILE:/tmp/krb5cc_") + 6 + 1]; - - snprintf(ccname, sizeof(ccname), "FILE:/tmp/krb5cc_%d", - (int) argp->uid); - setenv("KRB5CCNAME", ccname, TRUE); - - memset(result, 0, sizeof(*result)); - if (argp->desired_name) { - desired_name = gssd_find_resource(argp->desired_name); - if (!desired_name) { - result->major_status = GSS_S_BAD_NAME; - return (TRUE); - } - } - - result->major_status = gss_acquire_cred(&result->minor_status, - desired_name, argp->time_req, argp->desired_mechs, - argp->cred_usage, &cred, &result->actual_mechs, &result->time_rec); - - if (result->major_status == GSS_S_COMPLETE) - result->output_cred = gssd_make_resource(cred); - else - result->output_cred = 0; - - return (TRUE); -} - -bool_t -gssd_set_cred_option_1_svc(set_cred_option_args *argp, set_cred_option_res *result, struct svc_req *rqstp) -{ - gss_cred_id_t cred = gssd_find_resource(argp->cred); - - memset(result, 0, sizeof(*result)); - if (!cred) { - result->major_status = GSS_S_CREDENTIALS_EXPIRED; - return (TRUE); - } - - result->major_status = gss_set_cred_option(&result->minor_status, - &cred, argp->option_name, &argp->option_value); - - return (TRUE); -} - -bool_t -gssd_release_cred_1_svc(release_cred_args *argp, release_cred_res *result, struct svc_req *rqstp) -{ - gss_cred_id_t cred = gssd_find_resource(argp->cred); - - if (cred) { - result->major_status = gss_release_cred(&result->minor_status, - &cred); - gssd_delete_resource(argp->cred); - } else { - result->major_status = GSS_S_COMPLETE; - result->minor_status = 0; - } - - return (TRUE); -} - -bool_t -gssd_display_status_1_svc(display_status_args *argp, display_status_res *result, struct svc_req *rqstp) -{ - - result->message_context = argp->message_context; - result->major_status = gss_display_status(&result->minor_status, - argp->status_value, argp->status_type, argp->mech_type, - &result->message_context, &result->status_string); - - return (TRUE); -} - -int -gssd_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) -{ - /* - * We don't use XDR to free the results - anything which was - * allocated came from GSS-API. We use xdr_result to figure - * out what to do. - */ - OM_uint32 junk; - - if (xdr_result == (xdrproc_t) xdr_init_sec_context_res) { - init_sec_context_res *p = (init_sec_context_res *) result; - gss_release_buffer(&junk, &p->output_token); - } else if (xdr_result == (xdrproc_t) xdr_accept_sec_context_res) { - accept_sec_context_res *p = (accept_sec_context_res *) result; - gss_release_buffer(&junk, &p->output_token); - } else if (xdr_result == (xdrproc_t) xdr_delete_sec_context_res) { - delete_sec_context_res *p = (delete_sec_context_res *) result; - gss_release_buffer(&junk, &p->output_token); - } else if (xdr_result == (xdrproc_t) xdr_export_sec_context_res) { - export_sec_context_res *p = (export_sec_context_res *) result; - if (p->interprocess_token.length) - memset(p->interprocess_token.value, 0, - p->interprocess_token.length); - gss_release_buffer(&junk, &p->interprocess_token); - } else if (xdr_result == (xdrproc_t) xdr_export_name_res) { - export_name_res *p = (export_name_res *) result; - gss_release_buffer(&junk, &p->exported_name); - } else if (xdr_result == (xdrproc_t) xdr_acquire_cred_res) { - acquire_cred_res *p = (acquire_cred_res *) result; - gss_release_oid_set(&junk, &p->actual_mechs); - } else if (xdr_result == (xdrproc_t) xdr_pname_to_uid_res) { - pname_to_uid_res *p = (pname_to_uid_res *) result; - if (p->gidlist.gidlist_val) - free(p->gidlist.gidlist_val); - } else if (xdr_result == (xdrproc_t) xdr_display_status_res) { - display_status_res *p = (display_status_res *) result; - gss_release_buffer(&junk, &p->status_string); - } - - return (TRUE); -} diff --git a/usr.sbin/gstat/Makefile b/usr.sbin/gstat/Makefile deleted file mode 100644 index 2a6da40..0000000 --- a/usr.sbin/gstat/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= gstat -MAN= gstat.8 -DPADD= ${LIBDEVSTAT} ${LIBKVM} ${LIBGEOM} ${LIBBSDXML} ${LIBSBUF} ${LIBEDIT} ${LIBCURSES} -LDADD= -ldevstat -lkvm -lgeom -lbsdxml -lsbuf -ledit -lcurses - -.include diff --git a/usr.sbin/gstat/gstat.8 b/usr.sbin/gstat/gstat.8 deleted file mode 100644 index 9ac6789..0000000 --- a/usr.sbin/gstat/gstat.8 +++ /dev/null @@ -1,96 +0,0 @@ -.\" Copyright (c) 2003 Giorgos Keramidas -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd March 12, 2009 -.Dt GSTAT 8 -.Os -.Sh NAME -.Nm gstat -.Nd print statistics about GEOM disks -.Sh SYNOPSIS -.Nm -.Op Fl abcd -.Op Fl f Ar filter -.Op Fl I Ar interval -.Sh DESCRIPTION -The -.Nm -utility can be used to monitor I/O transactions of -.Xr geom 4 -devices. -.Pp -The options are as follows: -.Bl -tag -width indent -.It Fl a -Only display providers that are at least 0.1% busy. -.It Fl b -Batch mode. -Collect numbers, print and exit. -Default if stdout is not a tty. -.It Fl c -Enable display of -.Xr geom 4 -consumers too. -The default is to show statistics only for -.Xr geom 4 -producers. -.It Fl d -Enable display of statistics for delete -.Pq Dv BIO_DELETE -operations. -.It Fl f Ar filter -A regular expression that can be used to only show statistics for some -devices. -Only devices with the names matching -.Ar filter -will be displayed. -The format of the regular expression is described in -.Xr re_format 7 . -.It Fl I Ar interval -Refresh the -.Nm -display every -.Ar interval -microseconds. -Adding a suffix of -.Cm s , ms , -or -.Cm us -(the default) indicates that the update interval is specified in -seconds, milliseconds, or microseconds, respectively. -.El -.Sh EXIT STATUS -.Ex -std -.Sh SEE ALSO -.Xr systat 1 , -.Xr geom 4 , -.Xr iostat 8 , -.Xr vmstat 8 -.Sh HISTORY -A -.Nm -utility appeared in -.Fx 5.0 . diff --git a/usr.sbin/gstat/gstat.c b/usr.sbin/gstat/gstat.c deleted file mode 100644 index 39054eb..0000000 --- a/usr.sbin/gstat/gstat.c +++ /dev/null @@ -1,431 +0,0 @@ -/*- - * Copyright (c) 2003 Poul-Henning Kamp - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The names of the authors may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int flag_a, flag_b, flag_c, flag_d; -static int flag_I = 1000000; - -#define PRINTMSG(...) do { \ - if (flag_b && !loop) \ - printf(__VA_ARGS__); \ - else if (!flag_b) \ - printw(__VA_ARGS__); \ - } while(0) - -static void usage(void); - -static const char* -el_prompt(void) -{ - - return ("Filter: "); -} - -int -main(int argc, char **argv) -{ - int error, i, quit; - int curx, cury, maxx, maxy, line_len, loop, max_flen; - struct devstat *gsp, *gsq; - void *sp, *sq; - double dt; - struct timespec tp, tq; - struct gmesh gmp; - struct gprovider *pp; - struct gconsumer *cp; - struct gident *gid; - regex_t f_re, tmp_f_re; - short cf, cb; - char *p; - char f_s[100], pf_s[100], tmp_f_s[100]; - const char *line; - long double ld[11]; - uint64_t u64; - EditLine *el; - History *hist; - HistEvent hist_ev; - - hist = NULL; - el = NULL; - maxx = -1; - curx = -1; - loop = 1; - /* Turn on batch mode if output is not tty. */ - if (!isatty(fileno(stdout))) - flag_b = 1; - - f_s[0] = '\0'; - while ((i = getopt(argc, argv, "adcf:I:b")) != -1) { - switch (i) { - case 'a': - flag_a = 1; - break; - case 'b': - flag_b = 1; - break; - case 'c': - flag_c = 1; - break; - case 'd': - flag_d = 1; - break; - case 'f': - if (strlen(optarg) > sizeof(f_s) - 1) - errx(EX_USAGE, "Filter string too long"); - if (regcomp(&f_re, optarg, REG_EXTENDED) != 0) - errx(EX_USAGE, - "Invalid filter - see re_format(7)"); - strncpy(f_s, optarg, sizeof(f_s)); - break; - case 'I': - p = NULL; - i = strtoul(optarg, &p, 0); - if (p == optarg || errno == EINVAL || - errno == ERANGE) { - errx(1, "Invalid argument to -I"); - } else if (!strcmp(p, "s")) - i *= 1000000; - else if (!strcmp(p, "ms")) - i *= 1000; - else if (!strcmp(p, "us")) - i *= 1; - flag_I = i; - break; - case '?': - default: - usage(); - } - } - argc -= optind; - argv += optind; - if (argc != 0) - usage(); - - i = geom_gettree(&gmp); - if (i != 0) - err(1, "geom_gettree = %d", i); - error = geom_stats_open(); - if (error) - err(1, "geom_stats_open()"); - sq = NULL; - sq = geom_stats_snapshot_get(); - if (sq == NULL) - err(1, "geom_stats_snapshot()"); - if (!flag_b) { - /* Setup curses */ - initscr(); - start_color(); - use_default_colors(); - pair_content(0, &cf, &cb); - init_pair(1, COLOR_GREEN, cb); - init_pair(2, COLOR_MAGENTA, cb); - init_pair(3, COLOR_RED, cb); - cbreak(); - noecho(); - nonl(); - nodelay(stdscr, 1); - intrflush(stdscr, FALSE); - keypad(stdscr, TRUE); - /* Setup libedit */ - hist = history_init(); - if (hist == NULL) - err(EX_SOFTWARE, "history_init()"); - history(hist, &hist_ev, H_SETSIZE, 100); - el = el_init("gstat", stdin, stdout, stderr); - if (el == NULL) - err(EX_SOFTWARE, "el_init"); - el_set(el, EL_EDITOR, "emacs"); - el_set(el, EL_SIGNAL, 1); - el_set(el, EL_HIST, history, hist); - el_set(el, EL_PROMPT, el_prompt); - if (f_s[0] != '\0') - history(hist, &hist_ev, H_ENTER, f_s); - } - geom_stats_snapshot_timestamp(sq, &tq); - for (quit = 0; !quit;) { - sp = geom_stats_snapshot_get(); - if (sp == NULL) - err(1, "geom_stats_snapshot()"); - geom_stats_snapshot_timestamp(sp, &tp); - dt = tp.tv_sec - tq.tv_sec; - dt += (tp.tv_nsec - tq.tv_nsec) * 1e-9; - tq = tp; - - geom_stats_snapshot_reset(sp); - geom_stats_snapshot_reset(sq); - move(0,0); - PRINTMSG("dT: %5.3fs w: %.3fs", dt, (float)flag_I / 1000000); - if (f_s[0] != '\0') { - PRINTMSG(" filter: "); - if (!flag_b) { - getyx(stdscr, cury, curx); - getmaxyx(stdscr, maxy, maxx); - } - strncpy(pf_s, f_s, sizeof(pf_s)); - max_flen = maxx - curx - 1; - if ((int)strlen(f_s) > max_flen && max_flen >= 0) { - if (max_flen > 3) - pf_s[max_flen - 3] = '.'; - if (max_flen > 2) - pf_s[max_flen - 2] = '.'; - if (max_flen > 1) - pf_s[max_flen - 1] = '.'; - pf_s[max_flen] = '\0'; - } - PRINTMSG("%s", pf_s); - } - PRINTMSG("\n"); - PRINTMSG(" L(q) ops/s "); - PRINTMSG(" r/s kBps ms/r "); - PRINTMSG(" w/s kBps ms/w "); - if (flag_d) - PRINTMSG(" d/s kBps ms/d "); - PRINTMSG("%%busy Name\n"); - for (;;) { - gsp = geom_stats_snapshot_next(sp); - gsq = geom_stats_snapshot_next(sq); - if (gsp == NULL || gsq == NULL) - break; - if (gsp->id == NULL) - continue; - gid = geom_lookupid(&gmp, gsp->id); - if (gid == NULL) { - geom_deletetree(&gmp); - i = geom_gettree(&gmp); - if (i != 0) - err(1, "geom_gettree = %d", i); - gid = geom_lookupid(&gmp, gsp->id); - } - if (gid == NULL) - continue; - if (gid->lg_what == ISCONSUMER && !flag_c) - continue; - /* Do not print past end of window */ - if (!flag_b) { - getyx(stdscr, cury, curx); - if (curx > 0) - continue; - } - if ((gid->lg_what == ISPROVIDER - || gid->lg_what == ISCONSUMER) && f_s[0] != '\0') { - pp = gid->lg_ptr; - if ((regexec(&f_re, pp->lg_name, 0, NULL, 0) - != 0)) - continue; - } - if (gsp->sequence0 != gsp->sequence1) { - PRINTMSG("*\n"); - continue; - } - devstat_compute_statistics(gsp, gsq, dt, - DSM_QUEUE_LENGTH, &u64, - DSM_TRANSFERS_PER_SECOND, &ld[0], - - DSM_TRANSFERS_PER_SECOND_READ, &ld[1], - DSM_MB_PER_SECOND_READ, &ld[2], - DSM_MS_PER_TRANSACTION_READ, &ld[3], - - DSM_TRANSFERS_PER_SECOND_WRITE, &ld[4], - DSM_MB_PER_SECOND_WRITE, &ld[5], - DSM_MS_PER_TRANSACTION_WRITE, &ld[6], - - DSM_BUSY_PCT, &ld[7], - DSM_TRANSFERS_PER_SECOND_FREE, &ld[8], - DSM_MB_PER_SECOND_FREE, &ld[9], - DSM_MS_PER_TRANSACTION_FREE, &ld[10], - DSM_NONE); - - if (flag_a && ld[7] < 0.1) { - *gsq = *gsp; - continue; - } - - PRINTMSG(" %4ju", (uintmax_t)u64); - PRINTMSG(" %6.0f", (double)ld[0]); - PRINTMSG(" %6.0f", (double)ld[1]); - PRINTMSG(" %6.0f", (double)ld[2] * 1024); - if (ld[3] > 1e3) - PRINTMSG(" %6.0f", (double)ld[3]); - else - PRINTMSG(" %6.1f", (double)ld[3]); - PRINTMSG(" %6.0f", (double)ld[4]); - PRINTMSG(" %6.0f", (double)ld[5] * 1024); - if (ld[6] > 1e3) - PRINTMSG(" %6.0f", (double)ld[6]); - else - PRINTMSG(" %6.1f", (double)ld[6]); - - if (flag_d) { - PRINTMSG(" %6.0f", (double)ld[8]); - PRINTMSG(" %6.0f", (double)ld[9] * 1024); - if (ld[10] > 1e3) - PRINTMSG(" %6.0f", (double)ld[10]); - else - PRINTMSG(" %6.1f", (double)ld[10]); - } - - if (ld[7] > 80) - i = 3; - else if (ld[7] > 50) - i = 2; - else - i = 1; - if (!flag_b) - attron(COLOR_PAIR(i)); - PRINTMSG(" %6.1lf", (double)ld[7]); - if (!flag_b) { - attroff(COLOR_PAIR(i)); - PRINTMSG("|"); - } else - PRINTMSG(" "); - if (gid == NULL) { - PRINTMSG(" ??"); - } else if (gid->lg_what == ISPROVIDER) { - pp = gid->lg_ptr; - PRINTMSG(" %s", pp->lg_name); - } else if (gid->lg_what == ISCONSUMER) { - cp = gid->lg_ptr; - PRINTMSG(" %s/%s/%s", - cp->lg_geom->lg_class->lg_name, - cp->lg_geom->lg_name, - cp->lg_provider->lg_name); - } - if (!flag_b) - clrtoeol(); - PRINTMSG("\n"); - *gsq = *gsp; - } - geom_stats_snapshot_free(sp); - if (flag_b) { - /* We loop extra to make sure we get the information. */ - if (!loop) - break; - loop = 0; - usleep(flag_I); - continue; - } - getyx(stdscr, cury, curx); - getmaxyx(stdscr, maxy, maxx); - clrtobot(); - if (maxy - 1 <= cury) - move(maxy - 1, 0); - refresh(); - usleep(flag_I); - while((i = getch()) != ERR) { - switch (i) { - case '>': - flag_I *= 2; - break; - case '<': - flag_I /= 2; - if (flag_I < 1000) - flag_I = 1000; - break; - case 'c': - flag_c = !flag_c; - break; - case 'f': - move(0,0); - clrtoeol(); - refresh(); - line = el_gets(el, &line_len); - if (line == NULL) - err(1, "el_gets"); - if (line_len > 1) - history(hist, &hist_ev, H_ENTER, line); - strncpy(tmp_f_s, line, sizeof(f_s)); - if ((p = strchr(tmp_f_s, '\n')) != NULL) - *p = '\0'; - /* - * We have to clear since we messed up - * curses idea of the screen by using - * libedit. - */ - clear(); - refresh(); - if (regcomp(&tmp_f_re, tmp_f_s, REG_EXTENDED) - != 0) { - move(0, 0); - printw("Invalid filter"); - refresh(); - sleep(1); - } else { - strncpy(f_s, tmp_f_s, sizeof(f_s)); - f_re = tmp_f_re; - } - break; - case 'F': - f_s[0] = '\0'; - break; - case 'q': - quit = 1; - break; - default: - break; - } - } - } - - if (!flag_b) { - endwin(); - el_end(el); - } - exit(EX_OK); -} - -static void -usage(void) -{ - fprintf(stderr, "usage: gstat [-abcd] [-f filter] [-I interval]\n"); - exit(EX_USAGE); - /* NOTREACHED */ -} diff --git a/usr.sbin/i2c/Makefile b/usr.sbin/i2c/Makefile deleted file mode 100644 index 9f377e6..0000000 --- a/usr.sbin/i2c/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= i2c -MAN= i2c.8 - -WARNS?= 2 - -.include diff --git a/usr.sbin/i2c/i2c.8 b/usr.sbin/i2c/i2c.8 deleted file mode 100644 index dab26ea..0000000 --- a/usr.sbin/i2c/i2c.8 +++ /dev/null @@ -1,166 +0,0 @@ -.\" -.\" Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd January 23, 2009 -.Dt I2C 8 -.Os -.Sh NAME -.Nm i2c -.Nd test I2C bus and slave devices -.Sh SYNOPSIS -.Nm -.Cm -a Ar address -.Op Fl f Ar device -.Op Fl d Ar r|w -.Op Fl w Ar 0|8|16 -.Op Fl o Ar offset -.Op Fl c Ar count -.Op Fl m Ar ss|rs|no -.Op Fl b -.Op Fl v -.Nm -.Cm -s -.Op Fl f Ar device -.Op Fl n Ar skip_addr -.Op Fl v -.Nm -.Cm -r -.Op Fl f Ar device -.Op Fl v -.Sh DESCRIPTION -The -.Nm -utility can be used to perform raw data transfers (read or write) with devices -on the I2C bus. It can also scan the bus for available devices and reset the -I2C controller. -.Pp -The options are as follows: -.Bl -tag -width ".Fl d Ar direction" -.It Fl a Ar address -7-bit address on the I2C device to operate on (hex). -.It Fl b -binary mode - when performing a read operation, the data read from the device -is output in binary format on stdout; when doing a write, the binary data to -be written to the device is read from stdin. -.It Fl c Ar count -number of bytes to transfer (dec). -.It Fl d Ar r|w -transfer direction: r - read, w - write. -.It Fl f Ar device -I2C bus to use (default is /dev/iic0). -.It Fl m Ar ss|rs|no -addressing mode, i.e., I2C bus operations performed after the offset for the -transfer has been written to the device and before the actual read/write -operation. rs - repeated start; ss - stop start; no - none. -.It Fl n Ar skip_addr -skip address - address(es) to be skipped during bus scan. -There are two ways to specify addresses to ignore: by range 'a..b' or -using selected addresses 'a:b:c'. This option is available only when "-s" is -used. -.It Fl o Ar offset -offset within the device for data transfer (hex). -.It Fl r -reset the controller. -.It Fl s -scan the bus for devices. -.It Fl v -be verbose -.It Fl w Ar 0|8|16 -device addressing width (in bits). -.El -.Sh WARNINGS -Great care must be taken when manipulating slave I2C devices with the -.Nm -utility. Often times important configuration data for the system is kept in -non-volatile but write enabled memories located on the I2C bus, for example -Ethernet hardware addresses, RAM module parameters (SPD), processor reset -configuration word etc. -.Pp -It is very easy to render the whole system unusable when such configuration -data is deleted or altered, so use the -.Dq -d w -(write) command only if you know exactly what you are doing. -.Pp -Also avoid ungraceful interrupting of an ongoing transaction on the I2C bus, -as it can lead to potentially dangerous effects. Consider the following -scenario: when the host CPU is reset (for whatever reason) in the middle of a -started I2C transaction, the I2C slave device could be left in write mode -waiting for data or offset to arrive. When the CPU reinitializes itself and -talks to this I2C slave device again, the commands and other control info it -sends are treated by the slave device as data or offset it was waiting for, -and there's great potential for corruption if such a write is performed. -.Sh EXAMPLES -.Bl -bullet -.It -Scan the default bus (/dev/iic0) for devices: -.Pp -i2c -s -.It -Scan the default bus (/dev/iic0) for devices and skip addresses 0x56 and -0x45. -.Pp -i2c -s -n 0x56:0x45 -.It -Scan the default bus (/dev/iic0) for devices and skip address range -0x34 to 0x56. -.Pp -i2c -s -n 0x34..0x56 -.It -Read 8 bytes of data from device at address 0x56 (e.g., an EEPROM): -.Pp -i2c -a 0x56 -d r -c 8 -.It -Write 16 bytes of data from file data.bin to device 0x56 at offset 0x10: -.Pp -i2c -a 0x56 -d w -c 16 -o 0x10 -b < data.bin -.It -Copy 4 bytes between two EEPROMs (0x56 on /dev/iic1 to 0x57 on /dev/iic0): -.Pp -i2c -a 0x56 -f /dev/iic1 -d r -c 0x4 -b | i2c -a 0x57 -f /dev/iic0 -d w -c 4 -b -.It -Reset the controller: -.Pp -i2c -f /dev/iic1 -r -.El -.Sh SEE ALSO -.Xr iic 4 , -.Xr iicbus 4 -.Sh HISTORY -The -.Nm -utility appeared in -.Fx 8.0 . -.Sh AUTHORS -.An -nosplit -The -.Nm -utility and this manual page were written by -.An Bartlomiej Sieka -.Aq tur@semihalf.com -and -.An Michal Hajduk -.Aq mih@semihalf.com . diff --git a/usr.sbin/i2c/i2c.c b/usr.sbin/i2c/i2c.c deleted file mode 100644 index c0b3663..0000000 --- a/usr.sbin/i2c/i2c.c +++ /dev/null @@ -1,633 +0,0 @@ -/*- - * Copyright (C) 2008-2009 Semihalf, Michal Hajduk and Bartlomiej Sieka - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define I2C_DEV "/dev/iic0" -#define I2C_MODE_NOTSET 0 -#define I2C_MODE_NONE 1 -#define I2C_MODE_STOP_START 2 -#define I2C_MODE_REPEATED_START 3 - -struct options { - int width; - int count; - int verbose; - int addr_set; - int binary; - int scan; - int skip; - int reset; - int mode; - char dir; - uint32_t addr; - uint32_t off; -}; - -struct skip_range { - int start; - int end; -}; - -__dead2 static void -usage(void) -{ - - fprintf(stderr, "usage: %s -a addr [-f device] [-d [r|w]] [-o offset] " - "[-w [0|8|16]] [-c count] [-m [ss|rs|no]] [-b] [-v]\n", - getprogname()); - fprintf(stderr, " %s -s [-f device] [-n skip_addr] -v\n", - getprogname()); - fprintf(stderr, " %s -r [-f device] -v\n", getprogname()); - exit(EX_USAGE); -} - -static struct skip_range -skip_get_range(char *skip_addr) -{ - struct skip_range addr_range; - char *token; - - addr_range.start = 0; - addr_range.end = 0; - - token = strsep(&skip_addr, ".."); - if (token) { - addr_range.start = strtoul(token, 0, 16); - token = strsep(&skip_addr, ".."); - if ((token != NULL) && !atoi(token)) { - token = strsep(&skip_addr, ".."); - if (token) - addr_range.end = strtoul(token, 0, 16); - } - } - - return (addr_range); -} - -/* Parse the string to get hex 7 bits addresses */ -static int -skip_get_tokens(char *skip_addr, int *sk_addr, int max_index) -{ - char *token; - int i; - - for (i = 0; i < max_index; i++) { - token = strsep(&skip_addr, ":"); - if (token == NULL) - break; - sk_addr[i] = strtoul(token, 0, 16); - } - return (i); -} - -static int -scan_bus(struct iiccmd cmd, char *dev, int skip, char *skip_addr) -{ - struct skip_range addr_range = { 0, 0 }; - int *tokens, fd, error, i, index, j; - int len = 0, do_skip = 0, no_range = 1; - - fd = open(dev, O_RDWR); - if (fd == -1) { - fprintf(stderr, "Error opening I2C controller (%s) for " - "scanning: %s\n", dev, strerror(errno)); - return (EX_NOINPUT); - } - - if (skip) { - len = strlen(skip_addr); - if (strstr(skip_addr, "..") != NULL) { - addr_range = skip_get_range(skip_addr); - no_range = 0; - } else { - tokens = (int *)malloc((len / 2 + 1) * sizeof(int)); - if (tokens == NULL) { - fprintf(stderr, "Error allocating tokens " - "buffer\n"); - goto out; - } - index = skip_get_tokens(skip_addr, tokens, - len / 2 + 1); - } - - if (!no_range && (addr_range.start > addr_range.end)) { - fprintf(stderr, "Skip address out of range\n"); - goto out; - } - } - - printf("Scanning I2C devices on %s: ", dev); - for (i = 1; i < 127; i++) { - - if (skip && ( addr_range.start < addr_range.end)) { - if (i >= addr_range.start && i <= addr_range.end) - continue; - - } else if (skip && no_range) - for (j = 0; j < index; j++) { - if (tokens[j] == i) { - do_skip = 1; - break; - } - } - - if (do_skip) { - do_skip = 0; - continue; - } - - cmd.slave = i << 1; - cmd.last = 1; - cmd.count = 0; - error = ioctl(fd, I2CRSTCARD, &cmd); - if (error) - goto out; - - cmd.slave = i << 1; - cmd.last = 1; - error = ioctl(fd, I2CSTART, &cmd); - if (!error) - printf("%x ", i); - cmd.slave = i << 1; - cmd.last = 1; - error = ioctl(fd, I2CSTOP, &cmd); - } - printf("\n"); - - error = ioctl(fd, I2CRSTCARD, &cmd); -out: - close(fd); - if (skip && no_range) - free(tokens); - - if (error) { - fprintf(stderr, "Error scanning I2C controller (%s): %s\n", - dev, strerror(errno)); - return (EX_NOINPUT); - } else - return (EX_OK); -} - -static int -reset_bus(struct iiccmd cmd, char *dev) -{ - int fd, error; - - fd = open(dev, O_RDWR); - if (fd == -1) { - fprintf(stderr, "Error opening I2C controller (%s) for " - "resetting: %s\n", dev, strerror(errno)); - return (EX_NOINPUT); - } - - printf("Resetting I2C controller on %s: ", dev); - error = ioctl(fd, I2CRSTCARD, &cmd); - close (fd); - - if (error) { - printf("error: %s\n", strerror(errno)); - return (EX_IOERR); - } else { - printf("OK\n"); - return (EX_OK); - } -} - -static char * -prepare_buf(int size, uint32_t off) -{ - char *buf; - - buf = malloc(size); - if (buf == NULL) - return (buf); - - if (size == 1) - buf[0] = off & 0xff; - else if (size == 2) { - buf[0] = (off >> 8) & 0xff; - buf[1] = off & 0xff; - } - - return (buf); -} - -static int -i2c_write(char *dev, struct options i2c_opt, char *i2c_buf) -{ - struct iiccmd cmd; - int ch, i, error, fd, bufsize; - char *err_msg, *buf; - - /* - * Read data to be written to the chip from stdin - */ - if (i2c_opt.verbose && !i2c_opt.binary) - fprintf(stderr, "Enter %u bytes of data: ", i2c_opt.count); - - for (i = 0; i < i2c_opt.count; i++) { - ch = getchar(); - if (ch == EOF) { - free(i2c_buf); - err(1, "not enough data, exiting\n"); - } - i2c_buf[i] = ch; - } - - fd = open(dev, O_RDWR); - if (fd == -1) { - free(i2c_buf); - err(1, "open failed"); - } - - /* - * Write offset where the data will go - */ - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CSTART, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending start condition"; - goto err1; - } - - if (i2c_opt.width) { - bufsize = i2c_opt.width / 8; - buf = prepare_buf(bufsize, i2c_opt.off); - if (buf == NULL) { - err_msg = "error: offset malloc"; - goto err1; - } - - cmd.count = bufsize; - cmd.buf = buf; - error = ioctl(fd, I2CWRITE, &cmd); - free(buf); - if (error == -1) { - err_msg = "ioctl: error when write offset"; - goto err1; - } - } - - /* Mode - stop start */ - if (i2c_opt.mode == I2C_MODE_STOP_START) { - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CSTOP, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending stop condition"; - goto err2; - } - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CSTART, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending start condition"; - goto err1; - } - } - /* Mode - repeated start */ - if (i2c_opt.mode == I2C_MODE_REPEATED_START) { - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CRPTSTART, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending repeated start " - "condition"; - goto err1; - } - } - - /* - * Write the data - */ - cmd.count = i2c_opt.count; - cmd.buf = i2c_buf; - cmd.last = 0; - error = ioctl(fd, I2CWRITE, &cmd); - if (error == -1) { - err_msg = "ioctl: error when write"; - goto err1; - } - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CSTOP, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending stop condition"; - goto err2; - } - - close(fd); - return (0); - -err1: - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CSTOP, &cmd); - if (error == -1) - fprintf(stderr, "error sending stop condtion\n"); -err2: - if (err_msg) - fprintf(stderr, err_msg); - - close(fd); - return (1); -} - -static int -i2c_read(char *dev, struct options i2c_opt, char *i2c_buf) -{ - struct iiccmd cmd; - int i, fd, error, bufsize; - char *err_msg, data = 0, *buf; - - fd = open(dev, O_RDWR); - if (fd == -1) - err(1, "open failed"); - - bzero(&cmd, sizeof(cmd)); - - if (i2c_opt.width) { - cmd.slave = i2c_opt.addr; - cmd.count = 1; - cmd.last = 0; - cmd.buf = &data; - error = ioctl(fd, I2CSTART, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending start condition"; - goto err1; - } - bufsize = i2c_opt.width / 8; - buf = prepare_buf(bufsize, i2c_opt.off); - if (buf == NULL) { - err_msg = "error: offset malloc"; - goto err1; - } - - cmd.count = bufsize; - cmd.buf = buf; - cmd.last = 0; - error = ioctl(fd, I2CWRITE, &cmd); - free(buf); - if (error == -1) { - err_msg = "ioctl: error when write offset"; - goto err1; - } - - if (i2c_opt.mode == I2C_MODE_STOP_START) { - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CSTOP, &cmd); - if (error == -1) - goto err2; - } - } - cmd.slave = i2c_opt.addr; - cmd.count = 1; - cmd.last = 0; - cmd.buf = &data; - if (i2c_opt.mode == I2C_MODE_STOP_START) { - error = ioctl(fd, I2CSTART, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending start condition"; - goto err1; - } - } else if (i2c_opt.mode == I2C_MODE_REPEATED_START) { - error = ioctl(fd, I2CRPTSTART, &cmd); - if (error == -1) { - err_msg = "ioctl: error sending repeated start " - "condition"; - goto err1; - } - } - error = ioctl(fd, I2CSTOP, &cmd); - if (error == -1) - goto err2; - - for (i = 0; i < i2c_opt.count; i++) { - error = read(fd, &i2c_buf[i], 1); - if (error == -1) { - err_msg = "ioctl: error while reading"; - goto err1; - } - } - - close(fd); - return (0); - -err1: - cmd.slave = i2c_opt.addr; - error = ioctl(fd, I2CSTOP, &cmd); - if (error == -1) - fprintf(stderr, "error sending stop condtion\n"); -err2: - if (err_msg) - fprintf(stderr, err_msg); - - close(fd); - return (1); -} - -int -main(int argc, char** argv) -{ - struct iiccmd cmd; - struct options i2c_opt; - char *dev, *skip_addr, *err_msg, *i2c_buf; - int error, chunk_size, i, j, ch; - - errno = 0; - error = 0; - - /* Line-break the output every chunk_size bytes */ - chunk_size = 16; - - dev = I2C_DEV; - err_msg = NULL; - - /* Default values */ - i2c_opt.addr_set = 0; - i2c_opt.off = 0; - i2c_opt.verbose = 0; - i2c_opt.dir = 'r'; /* direction = read */ - i2c_opt.width = 8; - i2c_opt.count = 1; - i2c_opt.binary = 0; /* ASCII text output */ - i2c_opt.scan = 0; /* no bus scan */ - i2c_opt.skip = 0; /* scan all addresses */ - i2c_opt.reset = 0; /* no bus reset */ - i2c_opt.mode = I2C_MODE_NOTSET; - - while ((ch = getopt(argc, argv, "a:f:d:o:w:c:m:n:sbvrh")) != -1) { - switch(ch) { - case 'a': - i2c_opt.addr = (strtoul(optarg, 0, 16) << 1); - if (i2c_opt.addr == 0 && errno == EINVAL) - i2c_opt.addr_set = 0; - else - i2c_opt.addr_set = 1; - break; - case 'f': - dev = optarg; - break; - case 'd': - i2c_opt.dir = optarg[0]; - break; - case 'o': - i2c_opt.off = strtoul(optarg, 0, 16); - if (i2c_opt.off == 0 && errno == EINVAL) - error = 1; - break; - case 'w': - i2c_opt.width = atoi(optarg); - break; - case 'c': - i2c_opt.count = atoi(optarg); - break; - case 'm': - if (!strcmp(optarg, "no")) - i2c_opt.mode = I2C_MODE_NONE; - else if (!strcmp(optarg, "ss")) - i2c_opt.mode = I2C_MODE_STOP_START; - else if (!strcmp(optarg, "rs")) - i2c_opt.mode = I2C_MODE_REPEATED_START; - else - usage(); - break; - case 'n': - i2c_opt.skip = 1; - skip_addr = optarg; - break; - case 's': - i2c_opt.scan = 1; - break; - case 'b': - i2c_opt.binary = 1; - break; - case 'v': - i2c_opt.verbose = 1; - break; - case 'r': - i2c_opt.reset = 1; - break; - case 'h': - default: - usage(); - } - } - argc -= optind; - argv += optind; - - /* Set default mode if option -m is not specified */ - if (i2c_opt.mode == I2C_MODE_NOTSET) { - if (i2c_opt.dir == 'r') - i2c_opt.mode = I2C_MODE_STOP_START; - else if (i2c_opt.dir == 'w') - i2c_opt.mode = I2C_MODE_NONE; - } - - /* Basic sanity check of command line arguments */ - if (i2c_opt.scan) { - if (i2c_opt.addr_set) - usage(); - } else if (i2c_opt.reset) { - if (i2c_opt.addr_set) - usage(); - } else if (error) { - usage(); - } else if ((i2c_opt.dir == 'r' || i2c_opt.dir == 'w')) { - if ((i2c_opt.addr_set == 0) || - !(i2c_opt.width == 0 || i2c_opt.width == 8 || - i2c_opt.width == 16)) - usage(); - } - - if (i2c_opt.verbose) - fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, " - "offset: 0x%02x, width: %u, count: %u\n", dev, - i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off, - i2c_opt.width, i2c_opt.count); - - if (i2c_opt.scan) - exit(scan_bus(cmd, dev, i2c_opt.skip, skip_addr)); - - if (i2c_opt.reset) - exit(reset_bus(cmd, dev)); - - i2c_buf = malloc(i2c_opt.count); - if (i2c_buf == NULL) - err(1, "data malloc"); - - if (i2c_opt.dir == 'w') { - error = i2c_write(dev, i2c_opt, i2c_buf); - if (error) { - free(i2c_buf); - return (1); - } - } - if (i2c_opt.dir == 'r') { - error = i2c_read(dev, i2c_opt, i2c_buf); - if (error) { - free(i2c_buf); - return (1); - } - } - - if (i2c_opt.verbose) - fprintf(stderr, "\nData %s (hex):\n", i2c_opt.dir == 'r' ? - "read" : "written"); - - i = 0; - j = 0; - while (i < i2c_opt.count) { - if (i2c_opt.verbose || (i2c_opt.dir == 'r' && - !i2c_opt.binary)) - fprintf (stderr, "%02hhx ", i2c_buf[i++]); - - if (i2c_opt.dir == 'r' && i2c_opt.binary) { - fprintf(stdout, "%c", i2c_buf[j++]); - if(!i2c_opt.verbose) - i++; - } - if (!i2c_opt.verbose && (i2c_opt.dir == 'w')) - break; - if ((i % chunk_size) == 0) - fprintf(stderr, "\n"); - } - if ((i % chunk_size) != 0) - fprintf(stderr, "\n"); - - free(i2c_buf); - return (0); -} diff --git a/usr.sbin/ifmcstat/Makefile b/usr.sbin/ifmcstat/Makefile deleted file mode 100644 index fab7ea6..0000000 --- a/usr.sbin/ifmcstat/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/5/93 -# $FreeBSD$ - -.include - -PROG= ifmcstat -SRCS= ifmcstat.c printb.c - -MAN= ifmcstat.8 -BINMODE= 555 - -WARNS?= 2 - -.if ${MK_INET6_SUPPORT} != "no" -CFLAGS+=-DINET6 -.endif - -.if ${MK_KVM_SUPPORT} != "no" -CFLAGS+=-DWITH_KVM -DPADD= ${LIBKVM} -LDADD= -lkvm -.endif - -.include diff --git a/usr.sbin/ifmcstat/ifmcstat.8 b/usr.sbin/ifmcstat/ifmcstat.8 deleted file mode 100644 index 5a6956d..0000000 --- a/usr.sbin/ifmcstat/ifmcstat.8 +++ /dev/null @@ -1,131 +0,0 @@ -.\" $KAME: ifmcstat.8,v 1.6 2002/10/31 04:23:43 suz Exp $ -.\" -.\" Copyright (c) 2007-2009 Bruce Simpson. -.\" Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd May 27, 2009 -.Dt IFMCSTAT 8 -.Os -.Sh NAME -.Nm ifmcstat -.Nd dump multicast group management statistics per interface -.Sh SYNOPSIS -.Nm -.Op Fl i Ar interface -.Op Fl f Ar address-family -.Op Fl v -.Op Fl K -.Op Fl M Ar core -.Op Fl N Ar system -.\" -.Sh DESCRIPTION -The -.Nm -command dumps multicast group information from the kernel. -.Pp -The following options are supported: -.Bl -tag -width Fl -.It Fl i Ar interface -specifies the interface to be displayed. -.Pp -.It Fl f Ar address-family -specifies the address family to be displayed; -.Ar inet , -.Ar inet6 -and -.Ar link -are supported. -.It Fl v -specifies that link-layer memberships should be printed; -they are suppressed by default. -It may not be specified for -.Fl f Ar link . -Source lists for each group will also be printed. -.Pp -If specified twice, and -.Xr kvm 3 -is in use, the control plane timers for each interface -and the source list counters for each group -will also be printed. -.El -.Pp -The following options are only available if -.Nm -has been built with support for -.Xr kvm 3 : -.Bl -tag -width Fl -.It Fl K -attempts to use -.Xr kvm 3 -to retrieve the multicast group information. -.It Fl M Ar core -extracts values associated with the name list from the specified core, -instead of the default -.Pa /dev/kmem . -.It Fl N Ar system -extracts the name list from the specified kernel instead of the -default, which is the kernel image the system has booted from. -.El -.Sh IMPLEMENTATION NOTES -.Nm -will always print the embedded scope IDs of IPv6 multicast group -memberships. -This is because memberships are always scoped to an interface. -.Pp -When run with the -.Fl v -option, -.Nm -may print multicast MAC addresses twice if they are -referenced by a layer 3 protocol. -.Pp -When run with -.Xr kvm 3 -support, -the names of all interfaces configured in the system will be -printed in the first column of output, even if no multicast -group memberships are present on those interfaces. -The output may also be slightly different, as the kernel -data structures are being traversed with minimal post-processing -of the output. -.Pp -When built without -.Xr kvm 3 -support, the information displayed by -.Nm -is more limited. -This support is recommended for debugging purposes. -It requires super-user privilege if used to inspect a running kernel. -.Pp -.Sh SEE ALSO -.Xr getifaddrs 3 , -.Xr getifmaddrs 3 , -.Xr kvm 3 , -.Xr netstat 8 diff --git a/usr.sbin/ifmcstat/ifmcstat.c b/usr.sbin/ifmcstat/ifmcstat.c deleted file mode 100644 index e45e36d..0000000 --- a/usr.sbin/ifmcstat/ifmcstat.c +++ /dev/null @@ -1,1241 +0,0 @@ -/* $KAME: ifmcstat.c,v 1.48 2006/11/15 05:13:59 itojun Exp $ */ - -/* - * Copyright (c) 2007-2009 Bruce Simpson. - * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#define KERNEL -# include -#undef KERNEL -#define _KERNEL -#define SYSCTL_DECL(x) -# include -#undef SYSCTL_DECL -#undef _KERNEL - -#ifdef INET6 -#include -#define _KERNEL -# include -#undef _KERNEL -#endif /* INET6 */ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* XXX: This file currently assumes INET and KVM support in the base system. */ -#ifndef INET -#define INET -#endif - -extern void printb(const char *, unsigned int, const char *); - -union sockunion { - struct sockaddr_storage ss; - struct sockaddr sa; - struct sockaddr_dl sdl; -#ifdef INET - struct sockaddr_in sin; -#endif -#ifdef INET6 - struct sockaddr_in6 sin6; -#endif -}; -typedef union sockunion sockunion_t; - -uint32_t ifindex = 0; -int af = AF_UNSPEC; -#ifdef WITH_KVM -int Kflag = 0; -#endif -int vflag = 0; - -#define sa_equal(a1, a2) \ - (bcmp((a1), (a2), ((a1))->sa_len) == 0) - -#define sa_dl_equal(a1, a2) \ - ((((struct sockaddr_dl *)(a1))->sdl_len == \ - ((struct sockaddr_dl *)(a2))->sdl_len) && \ - (bcmp(LLADDR((struct sockaddr_dl *)(a1)), \ - LLADDR((struct sockaddr_dl *)(a2)), \ - ((struct sockaddr_dl *)(a1))->sdl_alen) == 0)) - -/* - * Most of the code in this utility is to support the use of KVM for - * post-mortem debugging of the multicast code. - */ -#ifdef WITH_KVM - -#ifdef INET -static void if_addrlist(struct ifaddr *); -static struct in_multi * - in_multientry(struct in_multi *); -#endif /* INET */ - -#ifdef INET6 -static void if6_addrlist(struct ifaddr *); -static struct in6_multi * - in6_multientry(struct in6_multi *); -#endif /* INET6 */ - -static void kread(u_long, void *, int); -static void ll_addrlist(struct ifaddr *); - -static int ifmcstat_kvm(const char *kernel, const char *core); - -#define KREAD(addr, buf, type) \ - kread((u_long)addr, (void *)buf, sizeof(type)) - -kvm_t *kvmd; -struct nlist nl[] = { - { "_ifnet", 0, 0, 0, 0, }, - { "", 0, 0, 0, 0, }, -}; -#define N_IFNET 0 - -#endif /* WITH_KVM */ - -static int ifmcstat_getifmaddrs(void); -#ifdef INET -static void in_ifinfo(struct igmp_ifinfo *); -static const char * inm_mode(u_int mode); -#endif -#ifdef INET6 -static void in6_ifinfo(struct mld_ifinfo *); -static const char * inet6_n2a(struct in6_addr *); -#endif -int main(int, char **); - -static void -usage() -{ - - fprintf(stderr, - "usage: ifmcstat [-i interface] [-f address family]" - " [-v]" -#ifdef WITH_KVM - " [-K] [-M core] [-N system]" -#endif - "\n"); - exit(EX_USAGE); -} - -static const char *options = "i:f:vM:N:" -#ifdef WITH_KVM - "K" -#endif - ; - -int -main(int argc, char **argv) -{ - int c, error; -#ifdef WITH_KVM - const char *kernel = NULL; - const char *core = NULL; -#endif - - while ((c = getopt(argc, argv, options)) != -1) { - switch (c) { - case 'i': - if ((ifindex = if_nametoindex(optarg)) == 0) { - fprintf(stderr, "%s: unknown interface\n", - optarg); - exit(EX_NOHOST); - } - break; - - case 'f': -#ifdef INET - if (strcmp(optarg, "inet") == 0) { - af = AF_INET; - break; - } -#endif -#ifdef INET6 - if (strcmp(optarg, "inet6") == 0) { - af = AF_INET6; - break; - } -#endif - if (strcmp(optarg, "link") == 0) { - af = AF_LINK; - break; - } - fprintf(stderr, "%s: unknown address family\n", optarg); - exit(EX_USAGE); - /*NOTREACHED*/ - break; - -#ifdef WITH_KVM - case 'K': - ++Kflag; - break; -#endif - - case 'v': - ++vflag; - break; - -#ifdef WITH_KVM - case 'M': - core = strdup(optarg); - break; - - case 'N': - kernel = strdup(optarg); - break; -#endif - - default: - usage(); - break; - /*NOTREACHED*/ - } - } - - if (af == AF_LINK && vflag) - usage(); - -#ifdef WITH_KVM - if (Kflag) - error = ifmcstat_kvm(kernel, core); - /* - * If KVM failed, and user did not explicitly specify a core file, - * or force KVM backend to be disabled, try the sysctl backend. - */ - if (!Kflag || (error != 0 && (core == NULL && kernel == NULL))) -#endif - error = ifmcstat_getifmaddrs(); - if (error != 0) - exit(EX_OSERR); - - exit(EX_OK); - /*NOTREACHED*/ -} - -#ifdef INET - -static void -in_ifinfo(struct igmp_ifinfo *igi) -{ - - printf("\t"); - switch (igi->igi_version) { - case IGMP_VERSION_1: - case IGMP_VERSION_2: - case IGMP_VERSION_3: - printf("igmpv%d", igi->igi_version); - break; - default: - printf("igmpv?(%d)", igi->igi_version); - break; - } - printb(" flags", igi->igi_flags, "\020\1SILENT\2LOOPBACK"); - if (igi->igi_version == IGMP_VERSION_3) { - printf(" rv %u qi %u qri %u uri %u", - igi->igi_rv, igi->igi_qi, igi->igi_qri, igi->igi_uri); - } - if (vflag >= 2) { - printf(" v1timer %u v2timer %u v3timer %u", - igi->igi_v1_timer, igi->igi_v2_timer, igi->igi_v3_timer); - } - printf("\n"); -} - -static const char *inm_modes[] = { - "undefined", - "include", - "exclude", -}; - -static const char * -inm_mode(u_int mode) -{ - - if (mode >= MCAST_UNDEFINED && mode <= MCAST_EXCLUDE) - return (inm_modes[mode]); - return (NULL); -} - -#endif /* INET */ - -#ifdef WITH_KVM - -static int -ifmcstat_kvm(const char *kernel, const char *core) -{ - char buf[_POSIX2_LINE_MAX], ifname[IFNAMSIZ]; - struct ifnet *ifp, *nifp, ifnet; - - if ((kvmd = kvm_openfiles(kernel, core, NULL, O_RDONLY, buf)) == - NULL) { - perror("kvm_openfiles"); - return (-1); - } - if (kvm_nlist(kvmd, nl) < 0) { - perror("kvm_nlist"); - return (-1); - } - if (nl[N_IFNET].n_value == 0) { - printf("symbol %s not found\n", nl[N_IFNET].n_name); - return (-1); - } - KREAD(nl[N_IFNET].n_value, &ifp, struct ifnet *); - while (ifp) { - KREAD(ifp, &ifnet, struct ifnet); - nifp = ifnet.if_link.tqe_next; - if (ifindex && ifindex != ifnet.if_index) - goto next; - - printf("%s:\n", if_indextoname(ifnet.if_index, ifname)); -#ifdef INET - if_addrlist(TAILQ_FIRST(&ifnet.if_addrhead)); -#endif -#ifdef INET6 - if6_addrlist(TAILQ_FIRST(&ifnet.if_addrhead)); -#endif - if (vflag) - ll_addrlist(TAILQ_FIRST(&ifnet.if_addrhead)); - next: - ifp = nifp; - } - - return (0); -} - -static void -kread(u_long addr, void *buf, int len) -{ - - if (kvm_read(kvmd, addr, buf, len) != len) { - perror("kvm_read"); - exit(EX_OSERR); - } -} - -static void -ll_addrlist(struct ifaddr *ifap) -{ - char addrbuf[NI_MAXHOST]; - struct ifaddr ifa; - struct sockaddr sa; - struct sockaddr_dl sdl; - struct ifaddr *ifap0; - int error; - - if (af && af != AF_LINK) - return; - - ifap0 = ifap; - while (ifap) { - KREAD(ifap, &ifa, struct ifaddr); - if (ifa.ifa_addr == NULL) - goto nextifap; - KREAD(ifa.ifa_addr, &sa, struct sockaddr); - if (sa.sa_family != PF_LINK) - goto nextifap; - KREAD(ifa.ifa_addr, &sdl, struct sockaddr_dl); - if (sdl.sdl_alen == 0) - goto nextifap; - addrbuf[0] = '\0'; - error = getnameinfo((struct sockaddr *)&sdl, sdl.sdl_len, - addrbuf, sizeof(addrbuf), NULL, 0, NI_NUMERICHOST); - printf("\tlink %s\n", addrbuf); - nextifap: - ifap = ifa.ifa_link.tqe_next; - } - if (ifap0) { - struct ifnet ifnet; - struct ifmultiaddr ifm, *ifmp = 0; - - KREAD(ifap0, &ifa, struct ifaddr); - KREAD(ifa.ifa_ifp, &ifnet, struct ifnet); - if (TAILQ_FIRST(&ifnet.if_multiaddrs)) - ifmp = TAILQ_FIRST(&ifnet.if_multiaddrs); - while (ifmp) { - KREAD(ifmp, &ifm, struct ifmultiaddr); - if (ifm.ifma_addr == NULL) - goto nextmulti; - KREAD(ifm.ifma_addr, &sa, struct sockaddr); - if (sa.sa_family != AF_LINK) - goto nextmulti; - KREAD(ifm.ifma_addr, &sdl, struct sockaddr_dl); - addrbuf[0] = '\0'; - error = getnameinfo((struct sockaddr *)&sdl, - sdl.sdl_len, addrbuf, sizeof(addrbuf), - NULL, 0, NI_NUMERICHOST); - printf("\t\tgroup %s refcnt %d\n", - addrbuf, ifm.ifma_refcount); - nextmulti: - ifmp = TAILQ_NEXT(&ifm, ifma_link); - } - } -} - -#ifdef INET6 - -static void -in6_ifinfo(struct mld_ifinfo *mli) -{ - - printf("\t"); - switch (mli->mli_version) { - case MLD_VERSION_1: - case MLD_VERSION_2: - printf("mldv%d", mli->mli_version); - break; - default: - printf("mldv?(%d)", mli->mli_version); - break; - } - printb(" flags", mli->mli_flags, "\020\1SILENT"); - if (mli->mli_version == MLD_VERSION_2) { - printf(" rv %u qi %u qri %u uri %u", - mli->mli_rv, mli->mli_qi, mli->mli_qri, mli->mli_uri); - } - if (vflag >= 2) { - printf(" v1timer %u v2timer %u", mli->mli_v1_timer, - mli->mli_v2_timer); - } - printf("\n"); -} - -static void -if6_addrlist(struct ifaddr *ifap) -{ - struct ifnet ifnet; - struct ifaddr ifa; - struct sockaddr sa; - struct in6_ifaddr if6a; - struct ifaddr *ifap0; - - if (af && af != AF_INET6) - return; - ifap0 = ifap; - while (ifap) { - KREAD(ifap, &ifa, struct ifaddr); - if (ifa.ifa_addr == NULL) - goto nextifap; - KREAD(ifa.ifa_addr, &sa, struct sockaddr); - if (sa.sa_family != PF_INET6) - goto nextifap; - KREAD(ifap, &if6a, struct in6_ifaddr); - printf("\tinet6 %s\n", inet6_n2a(&if6a.ia_addr.sin6_addr)); - /* - * Print per-link MLD information, if available. - */ - if (ifa.ifa_ifp != NULL) { - struct in6_ifextra ie; - struct mld_ifinfo mli; - - KREAD(ifa.ifa_ifp, &ifnet, struct ifnet); - KREAD(ifnet.if_afdata[AF_INET6], &ie, - struct in6_ifextra); - if (ie.mld_ifinfo != NULL) { - KREAD(ie.mld_ifinfo, &mli, struct mld_ifinfo); - in6_ifinfo(&mli); - } - } - nextifap: - ifap = ifa.ifa_link.tqe_next; - } - if (ifap0) { - struct ifnet ifnet; - struct ifmultiaddr ifm, *ifmp = 0; - struct sockaddr_dl sdl; - - KREAD(ifap0, &ifa, struct ifaddr); - KREAD(ifa.ifa_ifp, &ifnet, struct ifnet); - if (TAILQ_FIRST(&ifnet.if_multiaddrs)) - ifmp = TAILQ_FIRST(&ifnet.if_multiaddrs); - while (ifmp) { - KREAD(ifmp, &ifm, struct ifmultiaddr); - if (ifm.ifma_addr == NULL) - goto nextmulti; - KREAD(ifm.ifma_addr, &sa, struct sockaddr); - if (sa.sa_family != AF_INET6) - goto nextmulti; - (void)in6_multientry((struct in6_multi *) - ifm.ifma_protospec); - if (ifm.ifma_lladdr == 0) - goto nextmulti; - KREAD(ifm.ifma_lladdr, &sdl, struct sockaddr_dl); - printf("\t\t\tmcast-macaddr %s refcnt %d\n", - ether_ntoa((struct ether_addr *)LLADDR(&sdl)), - ifm.ifma_refcount); - nextmulti: - ifmp = TAILQ_NEXT(&ifm, ifma_link); - } - } -} - -static struct in6_multi * -in6_multientry(struct in6_multi *mc) -{ - struct in6_multi multi; - - KREAD(mc, &multi, struct in6_multi); - printf("\t\tgroup %s", inet6_n2a(&multi.in6m_addr)); - printf(" refcnt %u\n", multi.in6m_refcount); - - return (multi.in6m_entry.le_next); -} - -#endif /* INET6 */ - -#ifdef INET - -static void -if_addrlist(struct ifaddr *ifap) -{ - struct ifaddr ifa; - struct ifnet ifnet; - struct sockaddr sa; - struct in_ifaddr ia; - struct ifaddr *ifap0; - - if (af && af != AF_INET) - return; - ifap0 = ifap; - while (ifap) { - KREAD(ifap, &ifa, struct ifaddr); - if (ifa.ifa_addr == NULL) - goto nextifap; - KREAD(ifa.ifa_addr, &sa, struct sockaddr); - if (sa.sa_family != PF_INET) - goto nextifap; - KREAD(ifap, &ia, struct in_ifaddr); - printf("\tinet %s\n", inet_ntoa(ia.ia_addr.sin_addr)); - /* - * Print per-link IGMP information, if available. - */ - if (ifa.ifa_ifp != NULL) { - struct in_ifinfo ii; - struct igmp_ifinfo igi; - - KREAD(ifa.ifa_ifp, &ifnet, struct ifnet); - KREAD(ifnet.if_afdata[AF_INET], &ii, struct in_ifinfo); - if (ii.ii_igmp != NULL) { - KREAD(ii.ii_igmp, &igi, struct igmp_ifinfo); - in_ifinfo(&igi); - } - } - nextifap: - ifap = ifa.ifa_link.tqe_next; - } - if (ifap0) { - struct ifmultiaddr ifm, *ifmp = 0; - struct sockaddr_dl sdl; - - KREAD(ifap0, &ifa, struct ifaddr); - KREAD(ifa.ifa_ifp, &ifnet, struct ifnet); - if (TAILQ_FIRST(&ifnet.if_multiaddrs)) - ifmp = TAILQ_FIRST(&ifnet.if_multiaddrs); - while (ifmp) { - KREAD(ifmp, &ifm, struct ifmultiaddr); - if (ifm.ifma_addr == NULL) - goto nextmulti; - KREAD(ifm.ifma_addr, &sa, struct sockaddr); - if (sa.sa_family != AF_INET) - goto nextmulti; - (void)in_multientry((struct in_multi *) - ifm.ifma_protospec); - if (ifm.ifma_lladdr == 0) - goto nextmulti; - KREAD(ifm.ifma_lladdr, &sdl, struct sockaddr_dl); - printf("\t\t\tmcast-macaddr %s refcnt %d\n", - ether_ntoa((struct ether_addr *)LLADDR(&sdl)), - ifm.ifma_refcount); - nextmulti: - ifmp = TAILQ_NEXT(&ifm, ifma_link); - } - } -} - -static const char *inm_states[] = { - "not-member", - "silent", - "idle", - "lazy", - "sleeping", - "awakening", - "query-pending", - "sg-query-pending", - "leaving" -}; - -static const char * -inm_state(u_int state) -{ - - if (state >= IGMP_NOT_MEMBER && state <= IGMP_LEAVING_MEMBER) - return (inm_states[state]); - return (NULL); -} - -#if 0 -static struct ip_msource * -ims_min_kvm(struct in_multi *pinm) -{ - struct ip_msource ims0; - struct ip_msource *tmp, *parent; - - parent = NULL; - tmp = RB_ROOT(&pinm->inm_srcs); - while (tmp) { - parent = tmp; - KREAD(tmp, &ims0, struct ip_msource); - tmp = RB_LEFT(&ims0, ims_link); - } - return (parent); /* kva */ -} - -/* XXX This routine is buggy. See RB_NEXT in sys/tree.h. */ -static struct ip_msource * -ims_next_kvm(struct ip_msource *ims) -{ - struct ip_msource ims0, ims1; - struct ip_msource *tmp; - - KREAD(ims, &ims0, struct ip_msource); - if (RB_RIGHT(&ims0, ims_link)) { - ims = RB_RIGHT(&ims0, ims_link); - KREAD(ims, &ims1, struct ip_msource); - while ((tmp = RB_LEFT(&ims1, ims_link))) { - KREAD(tmp, &ims0, struct ip_msource); - ims = RB_LEFT(&ims0, ims_link); - } - } else { - tmp = RB_PARENT(&ims0, ims_link); - if (tmp) { - KREAD(tmp, &ims1, struct ip_msource); - if (ims == RB_LEFT(&ims1, ims_link)) - ims = tmp; - } else { - while ((tmp = RB_PARENT(&ims0, ims_link))) { - KREAD(tmp, &ims1, struct ip_msource); - if (ims == RB_RIGHT(&ims1, ims_link)) { - ims = tmp; - KREAD(ims, &ims0, struct ip_msource); - } else - break; - } - ims = RB_PARENT(&ims0, ims_link); - } - } - return (ims); /* kva */ -} - -static void -inm_print_sources_kvm(struct in_multi *pinm) -{ - struct ip_msource ims0; - struct ip_msource *ims; - struct in_addr src; - int cnt; - uint8_t fmode; - - cnt = 0; - fmode = pinm->inm_st[1].iss_fmode; - if (fmode == MCAST_UNDEFINED) - return; - for (ims = ims_min_kvm(pinm); ims != NULL; ims = ims_next_kvm(ims)) { - if (cnt == 0) - printf(" srcs "); - KREAD(ims, &ims0, struct ip_msource); - /* Only print sources in-mode at t1. */ - if (fmode != ims_get_mode(pinm, ims, 1)) - continue; - src.s_addr = htonl(ims0.ims_haddr); - printf("%s%s", (cnt++ == 0 ? "" : ","), inet_ntoa(src)); - } -} -#endif - -static struct in_multi * -in_multientry(struct in_multi *pinm) -{ - struct in_multi inm; - const char *state, *mode; - - KREAD(pinm, &inm, struct in_multi); - printf("\t\tgroup %s", inet_ntoa(inm.inm_addr)); - printf(" refcnt %u", inm.inm_refcount); - - state = inm_state(inm.inm_state); - if (state) - printf(" state %s", state); - else - printf(" state (%d)", inm.inm_state); - - mode = inm_mode(inm.inm_st[1].iss_fmode); - if (mode) - printf(" mode %s", mode); - else - printf(" mode (%d)", inm.inm_st[1].iss_fmode); - - if (vflag >= 2) { - printf(" asm %u ex %u in %u rec %u", - (u_int)inm.inm_st[1].iss_asm, - (u_int)inm.inm_st[1].iss_ex, - (u_int)inm.inm_st[1].iss_in, - (u_int)inm.inm_st[1].iss_rec); - } - -#if 0 - /* Buggy. */ - if (vflag) - inm_print_sources_kvm(&inm); -#endif - - printf("\n"); - return (NULL); -} - -#endif /* INET */ - -#endif /* WITH_KVM */ - -#ifdef INET6 -static const char * -inet6_n2a(struct in6_addr *p) -{ - static char buf[NI_MAXHOST]; - struct sockaddr_in6 sin6; - u_int32_t scopeid; - const int niflags = NI_NUMERICHOST; - - memset(&sin6, 0, sizeof(sin6)); - sin6.sin6_family = AF_INET6; - sin6.sin6_len = sizeof(struct sockaddr_in6); - sin6.sin6_addr = *p; - if (IN6_IS_ADDR_LINKLOCAL(p) || IN6_IS_ADDR_MC_LINKLOCAL(p) || - IN6_IS_ADDR_MC_NODELOCAL(p)) { - scopeid = ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]); - if (scopeid) { - sin6.sin6_scope_id = scopeid; - sin6.sin6_addr.s6_addr[2] = 0; - sin6.sin6_addr.s6_addr[3] = 0; - } - } - if (getnameinfo((struct sockaddr *)&sin6, sin6.sin6_len, - buf, sizeof(buf), NULL, 0, niflags) == 0) { - return (buf); - } else { - return ("(invalid)"); - } -} -#endif /* INET6 */ - -#ifdef INET -/* - * Retrieve per-group source filter mode and lists via sysctl. - */ -static void -inm_print_sources_sysctl(uint32_t ifindex, struct in_addr gina) -{ -#define MAX_SYSCTL_TRY 5 - int mib[7]; - int ntry = 0; - size_t mibsize; - size_t len; - size_t needed; - size_t cnt; - int i; - char *buf; - struct in_addr *pina; - uint32_t *p; - uint32_t fmode; - const char *modestr; - - mibsize = sizeof(mib) / sizeof(mib[0]); - if (sysctlnametomib("net.inet.ip.mcast.filters", mib, &mibsize) == -1) { - perror("sysctlnametomib"); - return; - } - - needed = 0; - mib[5] = ifindex; - mib[6] = gina.s_addr; /* 32 bits wide */ - mibsize = sizeof(mib) / sizeof(mib[0]); - do { - if (sysctl(mib, mibsize, NULL, &needed, NULL, 0) == -1) { - perror("sysctl net.inet.ip.mcast.filters"); - return; - } - if ((buf = malloc(needed)) == NULL) { - perror("malloc"); - return; - } - if (sysctl(mib, mibsize, buf, &needed, NULL, 0) == -1) { - if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) { - perror("sysctl"); - goto out_free; - } - free(buf); - buf = NULL; - } - } while (buf == NULL); - - len = needed; - if (len < sizeof(uint32_t)) { - perror("sysctl"); - goto out_free; - } - - p = (uint32_t *)buf; - fmode = *p++; - len -= sizeof(uint32_t); - - modestr = inm_mode(fmode); - if (modestr) - printf(" mode %s", modestr); - else - printf(" mode (%u)", fmode); - - if (vflag == 0) - goto out_free; - - cnt = len / sizeof(struct in_addr); - pina = (struct in_addr *)p; - - for (i = 0; i < cnt; i++) { - if (i == 0) - printf(" srcs "); - fprintf(stdout, "%s%s", (i == 0 ? "" : ","), - inet_ntoa(*pina++)); - len -= sizeof(struct in_addr); - } - if (len > 0) { - fprintf(stderr, "warning: %u trailing bytes from %s\n", - (unsigned int)len, "net.inet.ip.mcast.filters"); - } - -out_free: - free(buf); -#undef MAX_SYSCTL_TRY -} - -#endif /* INET */ - -#ifdef INET6 -/* - * Retrieve MLD per-group source filter mode and lists via sysctl. - * - * Note: The 128-bit IPv6 group addres needs to be segmented into - * 32-bit pieces for marshaling to sysctl. So the MIB name ends - * up looking like this: - * a.b.c.d.e.ifindex.g[0].g[1].g[2].g[3] - * Assumes that pgroup originated from the kernel, so its components - * are already in network-byte order. - */ -static void -in6m_print_sources_sysctl(uint32_t ifindex, struct in6_addr *pgroup) -{ -#define MAX_SYSCTL_TRY 5 - char addrbuf[INET6_ADDRSTRLEN]; - int mib[10]; - int ntry = 0; - int *pi; - size_t mibsize; - size_t len; - size_t needed; - size_t cnt; - int i; - char *buf; - struct in6_addr *pina; - uint32_t *p; - uint32_t fmode; - const char *modestr; - - mibsize = sizeof(mib) / sizeof(mib[0]); - if (sysctlnametomib("net.inet6.ip6.mcast.filters", mib, - &mibsize) == -1) { - perror("sysctlnametomib"); - return; - } - - needed = 0; - mib[5] = ifindex; - pi = (int *)pgroup; - for (i = 0; i < 4; i++) - mib[6 + i] = *pi++; - - mibsize = sizeof(mib) / sizeof(mib[0]); - do { - if (sysctl(mib, mibsize, NULL, &needed, NULL, 0) == -1) { - perror("sysctl net.inet6.ip6.mcast.filters"); - return; - } - if ((buf = malloc(needed)) == NULL) { - perror("malloc"); - return; - } - if (sysctl(mib, mibsize, buf, &needed, NULL, 0) == -1) { - if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) { - perror("sysctl"); - goto out_free; - } - free(buf); - buf = NULL; - } - } while (buf == NULL); - - len = needed; - if (len < sizeof(uint32_t)) { - perror("sysctl"); - goto out_free; - } - - p = (uint32_t *)buf; - fmode = *p++; - len -= sizeof(uint32_t); - - modestr = inm_mode(fmode); - if (modestr) - printf(" mode %s", modestr); - else - printf(" mode (%u)", fmode); - - if (vflag == 0) - goto out_free; - - cnt = len / sizeof(struct in6_addr); - pina = (struct in6_addr *)p; - - for (i = 0; i < cnt; i++) { - if (i == 0) - printf(" srcs "); - inet_ntop(AF_INET6, (const char *)pina++, addrbuf, - INET6_ADDRSTRLEN); - fprintf(stdout, "%s%s", (i == 0 ? "" : ","), addrbuf); - len -= sizeof(struct in6_addr); - } - if (len > 0) { - fprintf(stderr, "warning: %u trailing bytes from %s\n", - (unsigned int)len, "net.inet6.ip6.mcast.filters"); - } - -out_free: - free(buf); -#undef MAX_SYSCTL_TRY -} -#endif /* INET6 */ - -static int -ifmcstat_getifmaddrs(void) -{ - char thisifname[IFNAMSIZ]; - char addrbuf[NI_MAXHOST]; - struct ifaddrs *ifap, *ifa; - struct ifmaddrs *ifmap, *ifma; - sockunion_t lastifasa; - sockunion_t *psa, *pgsa, *pllsa, *pifasa; - char *pcolon; - char *pafname; - uint32_t lastifindex, thisifindex; - int error; - - error = 0; - ifap = NULL; - ifmap = NULL; - lastifindex = 0; - thisifindex = 0; - lastifasa.ss.ss_family = AF_UNSPEC; - - if (getifaddrs(&ifap) != 0) { - warn("getifmaddrs"); - return (-1); - } - - if (getifmaddrs(&ifmap) != 0) { - warn("getifmaddrs"); - error = -1; - goto out; - } - - for (ifma = ifmap; ifma; ifma = ifma->ifma_next) { - error = 0; - if (ifma->ifma_name == NULL || ifma->ifma_addr == NULL) - continue; - - psa = (sockunion_t *)ifma->ifma_name; - if (psa->sa.sa_family != AF_LINK) { - fprintf(stderr, - "WARNING: Kernel returned invalid data.\n"); - error = -1; - break; - } - - /* Filter on interface name. */ - thisifindex = psa->sdl.sdl_index; - if (ifindex != 0 && thisifindex != ifindex) - continue; - - /* Filter on address family. */ - pgsa = (sockunion_t *)ifma->ifma_addr; - if (af != 0 && pgsa->sa.sa_family != af) - continue; - - strlcpy(thisifname, link_ntoa(&psa->sdl), IFNAMSIZ); - pcolon = strchr(thisifname, ':'); - if (pcolon) - *pcolon = '\0'; - - /* Only print the banner for the first ifmaddrs entry. */ - if (lastifindex == 0 || lastifindex != thisifindex) { - lastifindex = thisifindex; - fprintf(stdout, "%s:\n", thisifname); - } - - /* - * Currently, multicast joins only take place on the - * primary IPv4 address, and only on the link-local IPv6 - * address, as per IGMPv2/3 and MLDv1/2 semantics. - * Therefore, we only look up the primary address on - * the first pass. - */ - pifasa = NULL; - for (ifa = ifap; ifa; ifa = ifa->ifa_next) { - if ((strcmp(ifa->ifa_name, thisifname) != 0) || - (ifa->ifa_addr == NULL) || - (ifa->ifa_addr->sa_family != pgsa->sa.sa_family)) - continue; - /* - * For AF_INET6 only the link-local address should - * be returned. If built without IPv6 support, - * skip this address entirely. - */ - pifasa = (sockunion_t *)ifa->ifa_addr; - if (pifasa->sa.sa_family == AF_INET6 -#ifdef INET6 - && !IN6_IS_ADDR_LINKLOCAL(&pifasa->sin6.sin6_addr) -#endif - ) { - pifasa = NULL; - continue; - } - break; - } - if (pifasa == NULL) - continue; /* primary address not found */ - - if (!vflag && pifasa->sa.sa_family == AF_LINK) - continue; - - /* Parse and print primary address, if not already printed. */ - if (lastifasa.ss.ss_family == AF_UNSPEC || - ((lastifasa.ss.ss_family == AF_LINK && - !sa_dl_equal(&lastifasa.sa, &pifasa->sa)) || - !sa_equal(&lastifasa.sa, &pifasa->sa))) { - - switch (pifasa->sa.sa_family) { - case AF_INET: - pafname = "inet"; - break; - case AF_INET6: - pafname = "inet6"; - break; - case AF_LINK: - pafname = "link"; - break; - default: - pafname = "unknown"; - break; - } - - switch (pifasa->sa.sa_family) { - case AF_INET6: -#ifdef INET6 - { - const char *p = - inet6_n2a(&pifasa->sin6.sin6_addr); - strlcpy(addrbuf, p, sizeof(addrbuf)); - break; - } -#else - /* FALLTHROUGH */ -#endif - case AF_INET: - case AF_LINK: - error = getnameinfo(&pifasa->sa, - pifasa->sa.sa_len, - addrbuf, sizeof(addrbuf), NULL, 0, - NI_NUMERICHOST); - if (error) - perror("getnameinfo"); - break; - default: - addrbuf[0] = '\0'; - break; - } - - fprintf(stdout, "\t%s %s\n", pafname, addrbuf); -#ifdef INET - /* - * Print per-link IGMP information, if available. - */ - if (pifasa->sa.sa_family == AF_INET) { - struct igmp_ifinfo igi; - size_t mibsize, len; - int mib[5]; - - mibsize = sizeof(mib) / sizeof(mib[0]); - if (sysctlnametomib("net.inet.igmp.ifinfo", - mib, &mibsize) == -1) { - perror("sysctlnametomib"); - goto next_ifnet; - } - mib[mibsize] = thisifindex; - len = sizeof(struct igmp_ifinfo); - if (sysctl(mib, mibsize + 1, &igi, &len, NULL, - 0) == -1) { - perror("sysctl net.inet.igmp.ifinfo"); - goto next_ifnet; - } - in_ifinfo(&igi); - } -#endif /* INET */ -#ifdef INET6 - /* - * Print per-link MLD information, if available. - */ - if (pifasa->sa.sa_family == AF_INET6) { - struct mld_ifinfo mli; - size_t mibsize, len; - int mib[5]; - - mibsize = sizeof(mib) / sizeof(mib[0]); - if (sysctlnametomib("net.inet6.mld.ifinfo", - mib, &mibsize) == -1) { - perror("sysctlnametomib"); - goto next_ifnet; - } - mib[mibsize] = thisifindex; - len = sizeof(struct mld_ifinfo); - if (sysctl(mib, mibsize + 1, &mli, &len, NULL, - 0) == -1) { - perror("sysctl net.inet6.mld.ifinfo"); - goto next_ifnet; - } - in6_ifinfo(&mli); - } -#endif /* INET6 */ -#if defined(INET) || defined(INET6) -next_ifnet: -#endif - lastifasa = *pifasa; - } - - /* Print this group address. */ -#ifdef INET6 - if (pgsa->sa.sa_family == AF_INET6) { - const char *p = inet6_n2a(&pgsa->sin6.sin6_addr); - strlcpy(addrbuf, p, sizeof(addrbuf)); - } else -#endif - { - error = getnameinfo(&pgsa->sa, pgsa->sa.sa_len, - addrbuf, sizeof(addrbuf), NULL, 0, NI_NUMERICHOST); - if (error) - perror("getnameinfo"); - } - - fprintf(stdout, "\t\tgroup %s", addrbuf); -#ifdef INET - if (pgsa->sa.sa_family == AF_INET) { - inm_print_sources_sysctl(thisifindex, - pgsa->sin.sin_addr); - } -#endif -#ifdef INET6 - if (pgsa->sa.sa_family == AF_INET6) { - in6m_print_sources_sysctl(thisifindex, - &pgsa->sin6.sin6_addr); - } -#endif - fprintf(stdout, "\n"); - - /* Link-layer mapping, if present. */ - pllsa = (sockunion_t *)ifma->ifma_lladdr; - if (pllsa != NULL) { - error = getnameinfo(&pllsa->sa, pllsa->sa.sa_len, - addrbuf, sizeof(addrbuf), NULL, 0, NI_NUMERICHOST); - fprintf(stdout, "\t\t\tmcast-macaddr %s\n", addrbuf); - } - } -out: - if (ifmap != NULL) - freeifmaddrs(ifmap); - if (ifap != NULL) - freeifaddrs(ifap); - - return (error); -} diff --git a/usr.sbin/ifmcstat/printb.c b/usr.sbin/ifmcstat/printb.c deleted file mode 100644 index a60d4f0..0000000 --- a/usr.sbin/ifmcstat/printb.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 1983, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include - -/* - * Print a value a la the %b format of the kernel's printf - */ -void -printb(const char *s, unsigned int v, const char *bits) -{ - int i, any = 0; - char c; - - if (bits && *bits == 8) - printf("%s=%o", s, v); - else - printf("%s=%x", s, v); - bits++; - if (bits) { - putchar('<'); - while ((i = *bits++) != '\0') { - if (v & (1 << (i-1))) { - if (any) - putchar(','); - any = 1; - for (; (c = *bits) > 32; bits++) - putchar(c); - } else - for (; *bits > 32; bits++) - ; - } - putchar('>'); - } -} diff --git a/usr.sbin/inetd/Makefile b/usr.sbin/inetd/Makefile deleted file mode 100644 index 29aacd1..0000000 --- a/usr.sbin/inetd/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -.include - -PROG= inetd -MAN= inetd.8 -MLINKS= inetd.8 inetd.conf.5 -SRCS= inetd.c builtins.c - -WARNS?= 3 -CFLAGS+= -DLOGIN_CAP -#CFLAGS+= -DSANITY_CHECK - -.if ${MK_INET6_SUPPORT} != "no" -CFLAGS+= -DINET6 -.endif - -DPADD= ${LIBUTIL} ${LIBWRAP} -LDADD= -lutil -lwrap - -# XXX for src/release/picobsd -.if !defined(RELEASE_CRUNCH) -CFLAGS+= -DIPSEC -DPADD+= ${LIBIPSEC} -LDADD+= -lipsec -.endif - -.include diff --git a/usr.sbin/inetd/builtins.c b/usr.sbin/inetd/builtins.c deleted file mode 100644 index ad7a82e..0000000 --- a/usr.sbin/inetd/builtins.c +++ /dev/null @@ -1,820 +0,0 @@ -/*- - * Copyright (c) 1983, 1991, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "inetd.h" - -void chargen_dg(int, struct servtab *); -void chargen_stream(int, struct servtab *); -void daytime_dg(int, struct servtab *); -void daytime_stream(int, struct servtab *); -void discard_dg(int, struct servtab *); -void discard_stream(int, struct servtab *); -void echo_dg(int, struct servtab *); -void echo_stream(int, struct servtab *); -static int getline(int, char *, int); -void iderror(int, int, int, const char *); -void ident_stream(int, struct servtab *); -void initring(void); -uint32_t machtime(void); -void machtime_dg(int, struct servtab *); -void machtime_stream(int, struct servtab *); - -char ring[128]; -char *endring; - - -struct biltin biltins[] = { - /* Echo received data */ - { "echo", SOCK_STREAM, 1, -1, echo_stream }, - { "echo", SOCK_DGRAM, 0, 1, echo_dg }, - - /* Internet /dev/null */ - { "discard", SOCK_STREAM, 1, -1, discard_stream }, - { "discard", SOCK_DGRAM, 0, 1, discard_dg }, - - /* Return 32 bit time since 1900 */ - { "time", SOCK_STREAM, 0, -1, machtime_stream }, - { "time", SOCK_DGRAM, 0, 1, machtime_dg }, - - /* Return human-readable time */ - { "daytime", SOCK_STREAM, 0, -1, daytime_stream }, - { "daytime", SOCK_DGRAM, 0, 1, daytime_dg }, - - /* Familiar character generator */ - { "chargen", SOCK_STREAM, 1, -1, chargen_stream }, - { "chargen", SOCK_DGRAM, 0, 1, chargen_dg }, - - { "tcpmux", SOCK_STREAM, 1, -1, (bi_fn_t *)tcpmux }, - - { "auth", SOCK_STREAM, 1, -1, ident_stream }, - - { NULL, 0, 0, 0, NULL } -}; - -/* - * RFC864 Character Generator Protocol. Generates character data without - * any regard for input. - */ - -void -initring(void) -{ - int i; - - endring = ring; - - for (i = 0; i <= 128; ++i) - if (isprint(i)) - *endring++ = i; -} - -/* Character generator - * The RFC says that we should send back a random number of - * characters chosen from the range 0 to 512. We send LINESIZ+2. - */ -/* ARGSUSED */ -void -chargen_dg(int s, struct servtab *sep) -{ - struct sockaddr_storage ss; - static char *rs; - int len; - socklen_t size; - char text[LINESIZ+2]; - - if (endring == 0) { - initring(); - rs = ring; - } - - size = sizeof(ss); - if (recvfrom(s, text, sizeof(text), 0, - (struct sockaddr *)&ss, &size) < 0) - return; - - if (check_loop((struct sockaddr *)&ss, sep)) - return; - - if ((len = endring - rs) >= LINESIZ) - memmove(text, rs, LINESIZ); - else { - memmove(text, rs, len); - memmove(text + len, ring, LINESIZ - len); - } - if (++rs == endring) - rs = ring; - text[LINESIZ] = '\r'; - text[LINESIZ + 1] = '\n'; - (void) sendto(s, text, sizeof(text), 0, (struct sockaddr *)&ss, size); -} - -/* Character generator */ -/* ARGSUSED */ -void -chargen_stream(int s, struct servtab *sep) -{ - int len; - char *rs, text[LINESIZ+2]; - - inetd_setproctitle(sep->se_service, s); - - if (!endring) { - initring(); - rs = ring; - } - - text[LINESIZ] = '\r'; - text[LINESIZ + 1] = '\n'; - for (rs = ring;;) { - if ((len = endring - rs) >= LINESIZ) - memmove(text, rs, LINESIZ); - else { - memmove(text, rs, len); - memmove(text + len, ring, LINESIZ - len); - } - if (++rs == endring) - rs = ring; - if (write(s, text, sizeof(text)) != sizeof(text)) - break; - } - exit(0); -} - -/* - * RFC867 Daytime Protocol. Sends the current date and time as an ascii - * character string without any regard for input. - */ - -/* Return human-readable time of day */ -/* ARGSUSED */ -void -daytime_dg(int s, struct servtab *sep) -{ - char buffer[256]; - time_t now; - struct sockaddr_storage ss; - socklen_t size; - - now = time((time_t *) 0); - - size = sizeof(ss); - if (recvfrom(s, buffer, sizeof(buffer), 0, - (struct sockaddr *)&ss, &size) < 0) - return; - - if (check_loop((struct sockaddr *)&ss, sep)) - return; - - (void) sprintf(buffer, "%.24s\r\n", ctime(&now)); - (void) sendto(s, buffer, strlen(buffer), 0, - (struct sockaddr *)&ss, size); -} - -/* Return human-readable time of day */ -/* ARGSUSED */ -void -daytime_stream(int s, struct servtab *sep __unused) -{ - char buffer[256]; - time_t now; - - now = time((time_t *) 0); - - (void) sprintf(buffer, "%.24s\r\n", ctime(&now)); - (void) send(s, buffer, strlen(buffer), MSG_EOF); -} - -/* - * RFC863 Discard Protocol. Any data received is thrown away and no response - * is sent. - */ - -/* Discard service -- ignore data */ -/* ARGSUSED */ -void -discard_dg(int s, struct servtab *sep __unused) -{ - char buffer[BUFSIZE]; - - (void) read(s, buffer, sizeof(buffer)); -} - -/* Discard service -- ignore data */ -/* ARGSUSED */ -void -discard_stream(int s, struct servtab *sep) -{ - int ret; - char buffer[BUFSIZE]; - - inetd_setproctitle(sep->se_service, s); - while (1) { - while ((ret = read(s, buffer, sizeof(buffer))) > 0) - ; - if (ret == 0 || errno != EINTR) - break; - } - exit(0); -} - -/* - * RFC862 Echo Protocol. Any data received is sent back to the sender as - * received. - */ - -/* Echo service -- echo data back */ -/* ARGSUSED */ -void -echo_dg(int s, struct servtab *sep) -{ - char buffer[65536]; /* Should be sizeof(max datagram). */ - int i; - socklen_t size; - struct sockaddr_storage ss; - - size = sizeof(ss); - if ((i = recvfrom(s, buffer, sizeof(buffer), 0, - (struct sockaddr *)&ss, &size)) < 0) - return; - - if (check_loop((struct sockaddr *)&ss, sep)) - return; - - (void) sendto(s, buffer, i, 0, (struct sockaddr *)&ss, size); -} - -/* Echo service -- echo data back */ -/* ARGSUSED */ -void -echo_stream(int s, struct servtab *sep) -{ - char buffer[BUFSIZE]; - int i; - - inetd_setproctitle(sep->se_service, s); - while ((i = read(s, buffer, sizeof(buffer))) > 0 && - write(s, buffer, i) > 0) - ; - exit(0); -} - -/* - * RFC1413 Identification Protocol. Given a TCP port number pair, return a - * character string which identifies the owner of that connection on the - * server's system. Extended to allow for ~/.fakeid support and ~/.noident - * support. - */ - -/* RFC 1413 says the following are the only errors you can return. */ -#define ID_INVALID "INVALID-PORT" /* Port number improperly specified. */ -#define ID_NOUSER "NO-USER" /* Port not in use/not identifable. */ -#define ID_HIDDEN "HIDDEN-USER" /* Hiden at user's request. */ -#define ID_UNKNOWN "UNKNOWN-ERROR" /* Everything else. */ - -/* Generic ident_stream error-sending func */ -/* ARGSUSED */ -void -iderror(int lport, int fport, int s, const char *er) -{ - char *p; - - asprintf(&p, "%d , %d : ERROR : %s\r\n", lport, fport, er); - if (p == NULL) { - syslog(LOG_ERR, "asprintf: %m"); - exit(EX_OSERR); - } - send(s, p, strlen(p), MSG_EOF); - free(p); - - exit(0); -} - -/* Ident service (AKA "auth") */ -/* ARGSUSED */ -void -ident_stream(int s, struct servtab *sep) -{ - struct utsname un; - struct stat sb; - struct sockaddr_in sin4[2]; -#ifdef INET6 - struct sockaddr_in6 sin6[2]; -#endif - struct sockaddr_storage ss[2]; - struct xucred uc; - struct timeval tv = { - 10, - 0 - }, to; - struct passwd *pw = NULL; - fd_set fdset; - char buf[BUFSIZE], *p, **av, *osname = NULL, e; - char idbuf[MAXLOGNAME] = ""; /* Big enough to hold uid in decimal. */ - socklen_t socklen; - ssize_t ssize; - size_t size, bufsiz; - int c, fflag = 0, nflag = 0, rflag = 0, argc = 0; - int gflag = 0, iflag = 0, Fflag = 0, getcredfail = 0, onreadlen; - u_short lport, fport; - - inetd_setproctitle(sep->se_service, s); - /* - * Reset getopt() since we are a fork() but not an exec() from - * a parent which used getopt() already. - */ - optind = 1; - optreset = 1; - /* - * Take the internal argument vector and count it out to make an - * argument count for getopt. This can be used for any internal - * service to read arguments and use getopt() easily. - */ - for (av = sep->se_argv; *av; av++) - argc++; - if (argc) { - int sec, usec; - size_t i; - u_int32_t rnd32; - - while ((c = getopt(argc, sep->se_argv, "d:fFgino:rt:")) != -1) - switch (c) { - case 'd': - if (!gflag) - strlcpy(idbuf, optarg, sizeof(idbuf)); - break; - case 'f': - fflag = 1; - break; - case 'F': - fflag = 1; - Fflag=1; - break; - case 'g': - gflag = 1; - rnd32 = 0; /* Shush, compiler. */ - /* - * The number of bits in "rnd32" divided - * by the number of bits needed per iteration - * gives a more optimal way to reload the - * random number only when necessary. - * - * 32 bits from arc4random corresponds to - * about 6 base-36 digits, so we reseed evey 6. - */ - for (i = 0; i < sizeof(idbuf) - 1; i++) { - static const char *const base36 = - "0123456789" - "abcdefghijklmnopqrstuvwxyz"; - if (i % 6 == 0) - rnd32 = arc4random(); - idbuf[i] = base36[rnd32 % 36]; - rnd32 /= 36; - } - idbuf[i] = '\0'; - break; - case 'i': - iflag = 1; - break; - case 'n': - nflag = 1; - break; - case 'o': - osname = optarg; - break; - case 'r': - rflag = 1; - break; - case 't': - switch (sscanf(optarg, "%d.%d", &sec, &usec)) { - case 2: - tv.tv_usec = usec; - /* FALLTHROUGH */ - case 1: - tv.tv_sec = sec; - break; - default: - if (debug) - warnx("bad -t argument"); - break; - } - break; - default: - break; - } - } - if (osname == NULL) { - if (uname(&un) == -1) - iderror(0, 0, s, ID_UNKNOWN); - osname = un.sysname; - } - - /* - * We're going to prepare for and execute reception of a - * packet of data from the user. The data is in the format - * "local_port , foreign_port\r\n" (with local being the - * server's port and foreign being the client's.) - */ - gettimeofday(&to, NULL); - to.tv_sec += tv.tv_sec; - to.tv_usec += tv.tv_usec; - if (to.tv_usec >= 1000000) { - to.tv_usec -= 1000000; - to.tv_sec++; - } - - size = 0; - bufsiz = sizeof(buf) - 1; - FD_ZERO(&fdset); - while (bufsiz > 0) { - gettimeofday(&tv, NULL); - tv.tv_sec = to.tv_sec - tv.tv_sec; - tv.tv_usec = to.tv_usec - tv.tv_usec; - if (tv.tv_usec < 0) { - tv.tv_usec += 1000000; - tv.tv_sec--; - } - if (tv.tv_sec < 0) - break; - FD_SET(s, &fdset); - if (select(s + 1, &fdset, NULL, NULL, &tv) == -1) - iderror(0, 0, s, ID_UNKNOWN); - if (ioctl(s, FIONREAD, &onreadlen) == -1) - iderror(0, 0, s, ID_UNKNOWN); - if ((size_t)onreadlen > bufsiz) - onreadlen = bufsiz; - ssize = read(s, &buf[size], (size_t)onreadlen); - if (ssize == -1) - iderror(0, 0, s, ID_UNKNOWN); - else if (ssize == 0) - break; - bufsiz -= ssize; - size += ssize; - if (memchr(&buf[size - ssize], '\n', ssize) != NULL) - break; - } - buf[size] = '\0'; - /* Read two characters, and check for a delimiting character */ - if (sscanf(buf, "%hu , %hu%c", &lport, &fport, &e) != 3 || isdigit(e)) - iderror(0, 0, s, ID_INVALID); - - /* Send garbage? */ - if (gflag) - goto printit; - - /* - * If not "real" (-r), send a HIDDEN-USER error for everything. - * If -d is used to set a fallback username, this is used to - * override it, and the fallback is returned instead. - */ - if (!rflag) { - if (*idbuf == '\0') - iderror(lport, fport, s, ID_HIDDEN); - goto printit; - } - - /* - * We take the input and construct an array of two sockaddr_ins - * which contain the local address information and foreign - * address information, respectively, used to look up the - * credentials for the socket (which are returned by the - * sysctl "net.inet.tcp.getcred" when we call it.) - */ - socklen = sizeof(ss[0]); - if (getsockname(s, (struct sockaddr *)&ss[0], &socklen) == -1) - iderror(lport, fport, s, ID_UNKNOWN); - socklen = sizeof(ss[1]); - if (getpeername(s, (struct sockaddr *)&ss[1], &socklen) == -1) - iderror(lport, fport, s, ID_UNKNOWN); - if (ss[0].ss_family != ss[1].ss_family) - iderror(lport, fport, s, ID_UNKNOWN); - size = sizeof(uc); - switch (ss[0].ss_family) { - case AF_INET: - sin4[0] = *(struct sockaddr_in *)&ss[0]; - sin4[0].sin_port = htons(lport); - sin4[1] = *(struct sockaddr_in *)&ss[1]; - sin4[1].sin_port = htons(fport); - if (sysctlbyname("net.inet.tcp.getcred", &uc, &size, sin4, - sizeof(sin4)) == -1) - getcredfail = errno; - break; -#ifdef INET6 - case AF_INET6: - sin6[0] = *(struct sockaddr_in6 *)&ss[0]; - sin6[0].sin6_port = htons(lport); - sin6[1] = *(struct sockaddr_in6 *)&ss[1]; - sin6[1].sin6_port = htons(fport); - if (sysctlbyname("net.inet6.tcp6.getcred", &uc, &size, sin6, - sizeof(sin6)) == -1) - getcredfail = errno; - break; -#endif - default: /* should not reach here */ - getcredfail = EAFNOSUPPORT; - break; - } - if (getcredfail != 0 || uc.cr_version != XUCRED_VERSION) { - if (*idbuf == '\0') - iderror(lport, fport, s, - getcredfail == ENOENT ? ID_NOUSER : ID_UNKNOWN); - goto printit; - } - - /* Look up the pw to get the username and home directory*/ - errno = 0; - pw = getpwuid(uc.cr_uid); - if (pw == NULL) - iderror(lport, fport, s, errno == 0 ? ID_NOUSER : ID_UNKNOWN); - - if (iflag) - snprintf(idbuf, sizeof(idbuf), "%u", (unsigned)pw->pw_uid); - else - strlcpy(idbuf, pw->pw_name, sizeof(idbuf)); - - /* - * If enabled, we check for a file named ".noident" in the user's - * home directory. If found, we return HIDDEN-USER. - */ - if (nflag) { - if (asprintf(&p, "%s/.noident", pw->pw_dir) == -1) - iderror(lport, fport, s, ID_UNKNOWN); - if (lstat(p, &sb) == 0) { - free(p); - iderror(lport, fport, s, ID_HIDDEN); - } - free(p); - } - - /* - * Here, if enabled, we read a user's ".fakeid" file in their - * home directory. It consists of a line containing the name - * they want. - */ - if (fflag) { - int fakeid_fd; - - /* - * Here we set ourself to effectively be the user, so we don't - * open any files we have no permission to open, especially - * symbolic links to sensitive root-owned files or devices. - */ - if (initgroups(pw->pw_name, pw->pw_gid) == -1) - iderror(lport, fport, s, ID_UNKNOWN); - if (seteuid(pw->pw_uid) == -1) - iderror(lport, fport, s, ID_UNKNOWN); - /* - * We can't stat() here since that would be a race - * condition. - * Therefore, we open the file we have permissions to open - * and if it's not a regular file, we close it and end up - * returning the user's real username. - */ - if (asprintf(&p, "%s/.fakeid", pw->pw_dir) == -1) - iderror(lport, fport, s, ID_UNKNOWN); - fakeid_fd = open(p, O_RDONLY | O_NONBLOCK); - free(p); - if (fakeid_fd == -1 || fstat(fakeid_fd, &sb) == -1 || - !S_ISREG(sb.st_mode)) - goto fakeid_fail; - - if ((ssize = read(fakeid_fd, buf, sizeof(buf) - 1)) < 0) - goto fakeid_fail; - buf[ssize] = '\0'; - - /* - * Usually, the file will have the desired identity - * in the form "identity\n". Allow for leading white - * space and trailing white space/end of line. - */ - p = buf; - p += strspn(p, " \t"); - p[strcspn(p, " \t\r\n")] = '\0'; - if (strlen(p) > MAXLOGNAME - 1) /* Too long (including nul)? */ - p[MAXLOGNAME - 1] = '\0'; - - /* - * If the name is a zero-length string or matches it - * the id or name of another user (unless permitted by -F) - * then it is invalid. - */ - if (*p == '\0') - goto fakeid_fail; - if (!Fflag) { - if (iflag) { - if (p[strspn(p, "0123456789")] == '\0' && - getpwuid(atoi(p)) != NULL) - goto fakeid_fail; - } else { - if (getpwnam(p) != NULL) - goto fakeid_fail; - } - } - - strlcpy(idbuf, p, sizeof(idbuf)); - -fakeid_fail: - if (fakeid_fd != -1) - close(fakeid_fd); - } - -printit: - /* Finally, we make and send the reply. */ - if (asprintf(&p, "%d , %d : USERID : %s : %s\r\n", lport, fport, osname, - idbuf) == -1) { - syslog(LOG_ERR, "asprintf: %m"); - exit(EX_OSERR); - } - send(s, p, strlen(p), MSG_EOF); - free(p); - - exit(0); -} - -/* - * RFC738/868 Time Server. - * Return a machine readable date and time, in the form of the - * number of seconds since midnight, Jan 1, 1900. Since gettimeofday - * returns the number of seconds since midnight, Jan 1, 1970, - * we must add 2208988800 seconds to this figure to make up for - * some seventy years Bell Labs was asleep. - */ - -uint32_t -machtime(void) -{ - struct timeval tv; - - if (gettimeofday(&tv, (struct timezone *)NULL) < 0) { - if (debug) - warnx("unable to get time of day"); - return (0L); - } -#define OFFSET ((uint32_t)25567 * 24*60*60) - return (htonl((uint32_t)(tv.tv_sec + OFFSET))); -#undef OFFSET -} - -/* ARGSUSED */ -void -machtime_dg(int s, struct servtab *sep) -{ - uint32_t result; - struct sockaddr_storage ss; - socklen_t size; - - size = sizeof(ss); - if (recvfrom(s, (char *)&result, sizeof(result), 0, - (struct sockaddr *)&ss, &size) < 0) - return; - - if (check_loop((struct sockaddr *)&ss, sep)) - return; - - result = machtime(); - (void) sendto(s, (char *) &result, sizeof(result), 0, - (struct sockaddr *)&ss, size); -} - -/* ARGSUSED */ -void -machtime_stream(int s, struct servtab *sep __unused) -{ - uint32_t result; - - result = machtime(); - (void) send(s, (char *) &result, sizeof(result), MSG_EOF); -} - -/* - * RFC1078 TCP Port Service Multiplexer (TCPMUX). Service connections to - * services based on the service name sent. - * - * Based on TCPMUX.C by Mark K. Lottor November 1988 - * sri-nic::ps:tcpmux.c - */ - -#define MAX_SERV_LEN (256+2) /* 2 bytes for \r\n */ -#define strwrite(fd, buf) (void) write(fd, buf, sizeof(buf)-1) - -static int /* # of characters upto \r,\n or \0 */ -getline(int fd, char *buf, int len) -{ - int count = 0, n; - struct sigaction sa; - - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sa.sa_handler = SIG_DFL; - sigaction(SIGALRM, &sa, (struct sigaction *)0); - do { - alarm(10); - n = read(fd, buf, len-count); - alarm(0); - if (n == 0) - return (count); - if (n < 0) - return (-1); - while (--n >= 0) { - if (*buf == '\r' || *buf == '\n' || *buf == '\0') - return (count); - count++; - buf++; - } - } while (count < len); - return (count); -} - -struct servtab * -tcpmux(int s) -{ - struct servtab *sep; - char service[MAX_SERV_LEN+1]; - int len; - - /* Get requested service name */ - if ((len = getline(s, service, MAX_SERV_LEN)) < 0) { - strwrite(s, "-Error reading service name\r\n"); - return (NULL); - } - service[len] = '\0'; - - if (debug) - warnx("tcpmux: someone wants %s", service); - - /* - * Help is a required command, and lists available services, - * one per line. - */ - if (!strcasecmp(service, "help")) { - for (sep = servtab; sep; sep = sep->se_next) { - if (!ISMUX(sep)) - continue; - (void)write(s,sep->se_service,strlen(sep->se_service)); - strwrite(s, "\r\n"); - } - return (NULL); - } - - /* Try matching a service in inetd.conf with the request */ - for (sep = servtab; sep; sep = sep->se_next) { - if (!ISMUX(sep)) - continue; - if (!strcasecmp(service, sep->se_service)) { - if (ISMUXPLUS(sep)) { - strwrite(s, "+Go\r\n"); - } - return (sep); - } - } - strwrite(s, "-Service not available\r\n"); - return (NULL); -} diff --git a/usr.sbin/inetd/inetd.8 b/usr.sbin/inetd/inetd.8 deleted file mode 100644 index 80cfbd2..0000000 --- a/usr.sbin/inetd/inetd.8 +++ /dev/null @@ -1,955 +0,0 @@ -.\" Copyright (c) 1985, 1991, 1993, 1994 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)inetd.8 8.3 (Berkeley) 4/13/94 -.\" $FreeBSD$ -.\" -.Dd January 12, 2008 -.Dt INETD 8 -.Os -.Sh NAME -.Nm inetd -.Nd internet -.Dq super-server -.Sh SYNOPSIS -.Nm -.Op Fl d -.Op Fl l -.Op Fl w -.Op Fl W -.Op Fl c Ar maximum -.Op Fl C Ar rate -.Op Fl a Ar address | hostname -.Op Fl p Ar filename -.Op Fl R Ar rate -.Op Fl s Ar maximum -.Op Ar configuration file -.Sh DESCRIPTION -The -.Nm -utility should be run at boot time by -.Pa /etc/rc -(see -.Xr rc 8 ) . -It then listens for connections on certain -internet sockets. -When a connection is found on one -of its sockets, it decides what service the socket -corresponds to, and invokes a program to service the request. -The server program is invoked with the service socket -as its standard input, output and error descriptors. -After the program is -finished, -.Nm -continues to listen on the socket (except in some cases which -will be described below). -Essentially, -.Nm -allows running one daemon to invoke several others, -reducing load on the system. -.Pp -The following options are available: -.Bl -tag -width indent -.It Fl d -Turn on debugging. -.It Fl l -Turn on logging of successful connections. -.It Fl w -Turn on TCP Wrapping for external services. -See the -.Sx "IMPLEMENTATION NOTES" -section for more information on TCP Wrappers support. -.It Fl W -Turn on TCP Wrapping for internal services which are built in to -.Nm . -.It Fl c Ar maximum -Specify the default maximum number of -simultaneous invocations of each service; -the default is unlimited. -May be overridden on a per-service basis with the "max-child" -parameter. -.It Fl C Ar rate -Specify the default maximum number of times a service can be invoked -from a single IP address in one minute; the default is unlimited. -May be overridden on a per-service basis with the -"max-connections-per-ip-per-minute" parameter. -.It Fl R Ar rate -Specify the maximum number of times a service can be invoked -in one minute; the default is 256. -A rate of 0 allows an unlimited number of invocations. -.It Fl s Ar maximum -Specify the default maximum number of -simultaneous invocations of each service from a single IP address; -the default is unlimited. -May be overridden on a per-service basis with the "max-child-per-ip" -parameter. -.It Fl a -Specify one specific IP address to bind to. -Alternatively, a hostname can be specified, -in which case the IPv4 or IPv6 address -which corresponds to that hostname is used. -Usually a hostname is specified when -.Nm -is run inside a -.Xr jail 8 , -in which case the hostname corresponds to that of the -.Xr jail 8 -environment. -.Pp -When the hostname specification is used -and both IPv4 and IPv6 bindings are desired, -one entry with the appropriate -.Em protocol -type for each binding -is required for each service in -.Pa /etc/inetd.conf . -For example, -a TCP-based service would need two entries, -one using -.Dq tcp4 -for the -.Em protocol -and the other using -.Dq tcp6 . -See the explanation of the -.Pa /etc/inetd.conf -.Em protocol -field below. -.It Fl p -Specify an alternate file in which to store the process ID. -.El -.Pp -Upon execution, -.Nm -reads its configuration information from a configuration -file which, by default, is -.Pa /etc/inetd.conf . -There must be an entry for each field of the configuration -file, with entries for each field separated by a tab or -a space. -Comments are denoted by a -.Dq # -at the beginning -of a line. -There must be an entry for each field. -The -fields of the configuration file are as follows: -.Pp -.Bd -unfilled -offset indent -compact -service-name -socket-type -protocol -{wait|nowait}[/max-child[/max-connections-per-ip-per-minute[/max-child-per-ip]]] -user[:group][/login-class] -server-program -server-program-arguments -.Ed -.Pp -To specify an -.Tn "ONC RPC" Ns -based -service, the entry would contain these fields: -.Pp -.Bd -unfilled -offset indent -compact -service-name/version -socket-type -rpc/protocol -{wait|nowait}[/max-child[/max-connections-per-ip-per-minute[/max-child-per-ip]]] -user[:group][/login-class] -server-program -server-program-arguments -.Ed -.Pp -There are two types of services that -.Nm -can start: standard and TCPMUX. -A standard service has a well-known port assigned to it; -it may be a service that implements an official Internet standard or is a -.Bx Ns -specific -service. -As described in -.Tn RFC 1078 , -TCPMUX services are nonstandard services that do not have a -well-known port assigned to them. -They are invoked from -.Nm -when a program connects to the -.Dq tcpmux -well-known port and specifies -the service name. -This feature is useful for adding locally-developed servers. -TCPMUX requests are only accepted when the multiplexor service itself -is enabled, above and beyond and specific TCPMUX-based servers; see the -discussion of internal services below. -.Pp -The -.Em service-name -entry is the name of a valid service in -the file -.Pa /etc/services , -or the specification of a -.Ux -domain socket (see below). -For -.Dq internal -services (discussed below), the service -name -should -be the official name of the service (that is, the first entry in -.Pa /etc/services ) . -When used to specify an -.Tn "ONC RPC" Ns -based -service, this field is a valid RPC service name listed in -the file -.Pa /etc/rpc . -The part on the right of the -.Dq / -is the RPC version number. -This -can simply be a single numeric argument or a range of versions. -A range is bounded by the low version to the high version - -.Dq rusers/1-3 . -For TCPMUX services, the value of the -.Em service-name -field consists of the string -.Dq tcpmux -followed by a slash and the -locally-chosen service name. -The service names listed in -.Pa /etc/services -and the name -.Dq help -are reserved. -Try to choose unique names for your TCPMUX services by prefixing them with -your organization's name and suffixing them with a version number. -.Pp -The -.Em socket-type -should be one of -.Dq stream , -.Dq dgram , -.Dq raw , -.Dq rdm , -or -.Dq seqpacket , -depending on whether the socket is a stream, datagram, raw, -reliably delivered message, or sequenced packet socket. -TCPMUX services must use -.Dq stream . -.Pp -The -.Em protocol -must be a valid protocol or -.Dq unix . -Examples are -.Dq tcp -or -.Dq udp , -both of which imply IPv4 for backward compatibility. -The names -.Dq tcp4 -and -.Dq udp4 -specify IPv4 only. -The names -.Dq tcp6 -and -.Dq udp6 -specify IPv6 only. -The names -.Dq tcp46 -and -.Dq udp46 -specify that the entry accepts both IPv4 and IPv6 connections -via a wildcard -.Dv AF_INET6 -socket. -Rpc based services -are specified with the -.Dq rpc/tcp -or -.Dq rpc/udp -service type. -One can use specify IPv4 and/or IPv6 with the 4, 6 or 46 suffix, for example -.Dq rpc/tcp6 -or -.Dq rpc/udp46 . -TCPMUX services must use -.Dq tcp , -.Dq tcp4 , -.Dq tcp6 -or -.Dq tcp46 . -.Pp -The -.Em wait/nowait -entry specifies whether the server that is invoked by -.Nm -will take over -the socket associated with the service access point, and thus whether -.Nm -should wait for the server to exit before listening for new service -requests. -Datagram servers must use -.Dq wait , -as they are always invoked with the original datagram socket bound -to the specified service address. -These servers must read at least one datagram from the socket -before exiting. -If a datagram server connects -to its peer, freeing the socket so -.Nm -can receive further messages on the socket, it is said to be -a -.Dq multi-threaded -server; -it should read one datagram from the socket and create a new socket -connected to the peer. -It should fork, and the parent should then exit -to allow -.Nm -to check for new service requests to spawn new servers. -Datagram servers which process all incoming datagrams -on a socket and eventually time out are said to be -.Dq single-threaded . -The -.Xr comsat 8 -and -.Xr talkd 8 -utilities are examples of the latter type of -datagram server. -The -.Xr tftpd 8 -utility is an example of a multi-threaded datagram server. -.Pp -Servers using stream sockets generally are multi-threaded and -use the -.Dq nowait -entry. -Connection requests for these services are accepted by -.Nm , -and the server is given only the newly-accepted socket connected -to a client of the service. -Most stream-based services operate in this manner. -Stream-based servers that use -.Dq wait -are started with the listening service socket, and must accept -at least one connection request before exiting. -Such a server would normally accept and process incoming connection -requests until a timeout. -TCPMUX services must use -.Dq nowait . -.Pp -The maximum number of outstanding child processes (or -.Dq threads ) -for a -.Dq nowait -service may be explicitly specified by appending a -.Dq / -followed by the number to the -.Dq nowait -keyword. -Normally -(or if a value of zero is specified) there is no maximum. -Otherwise, -once the maximum is reached, further connection attempts will be -queued up until an existing child process exits. -This also works -in the case of -.Dq wait -mode, although a value other than one (the -default) might not make sense in some cases. -You can also specify the maximum number of connections per minute -for a given IP address by appending -a -.Dq / -followed by the number to the maximum number of -outstanding child processes. -Once the maximum is reached, further -connections from this IP address will be dropped until the end of the -minute. -In addition, you can specify the maximum number of simultaneous -invocations of each service from a single IP address by appending a -.Dq / -followed by the number to the maximum number of outstanding child -processes. -Once the maximum is reached, further connections from this -IP address will be dropped. -.Pp -The -.Em user -entry should contain the user name of the user as whom the server -should run. -This allows for servers to be given less permission -than root. -The optional -.Em group -part separated by -.Dq \&: -allows a group name other -than the default group for this user to be specified. -The optional -.Em login-class -part separated by -.Dq / -allows specification of a login class other -than the default -.Dq daemon -login class. -.Pp -The -.Em server-program -entry should contain the pathname of the program which is to be -executed by -.Nm -when a request is found on its socket. -If -.Nm -provides this service internally, this entry should -be -.Dq internal . -.Pp -The -.Em server-program-arguments -entry lists the arguments to be passed to the -.Em server-program , -starting with argv[0], which usually is the name of -the program. -If the service is provided internally, the -.Em service-name -of the service (and any arguments to it) or the word -.Dq internal -should take the place of this entry. -.Pp -Currently, the only internal service to take arguments is -.Dq auth . -Without options, the service will always return -.Dq ERROR\ : HIDDEN-USER . -The available arguments to this service that alter its behavior are: -.Bl -tag -width indent -.It Fl d Ar fallback -Provide a -.Ar fallback -username. -If the real -.Dq auth -service is enabled -(with the -.Fl r -option discussed below), -return this username instead of an error -when lookups fail -for either socket credentials or the username. -If the real -.Dq auth -service is disabled, -return this username for every request. -This is primarily useful when running this service on a NAT machine. -.It Fl g -Instead of returning -the user's name to the ident requester, -report a -username made up of random alphanumeric characters, -e.g.\& -.Dq c0c993 . -The -.Fl g -flag overrides not only the user names, -but also any fallback name, -.Pa .fakeid -or -.Pa .noident -files. -.It Fl t Xo -.Ar sec Ns Op . Ns Ar usec -.Xc -Specify a timeout for the service. -The default timeout is 10.0 seconds. -.It Fl r -Offer a real -.Dq auth -service, as per RFC 1413. -All the remaining flags apply only in this case. -.It Fl i -Return numeric user IDs instead of usernames. -.It Fl f -If the file -.Pa .fakeid -exists in the home directory of the identified user, report the username -found in that file instead of the real username. -If the username found in -.Pa .fakeid -is that of an existing user, -then the real username is reported. -If the -.Fl i -flag is also given then the username in -.Pa .fakeid -is checked against existing user IDs instead. -.It Fl F -same as -.Fl f -but without the restriction that the username in -.Pa .fakeid -must not match an existing user. -.It Fl n -If the file -.Pa .noident -exists in the home directory of the identified user, return -.Dq ERROR\ : HIDDEN-USER . -This overrides any -.Pa fakeid -file which might exist. -.It Fl o Ar osname -Use -.Ar osname -instead of the name of the system as reported by -.Xr uname 3 . -.El -.Pp -The -.Nm -utility also provides several other -.Dq trivial -services internally by use of -routines within itself. -These services are -.Dq echo , -.Dq discard , -.Dq chargen -(character generator), -.Dq daytime -(human readable time), and -.Dq time -(machine readable time, in the form of the number of seconds since -midnight, January 1, 1900). -All of these services are available in -both TCP and UDP versions; the UDP versions will refuse service if the -request specifies a reply port corresponding to any internal service. -(This is done as a defense against looping attacks; the remote IP address -is logged.) -For details of these services, consult the -appropriate -.Tn RFC -document. -.Pp -The TCPMUX-demultiplexing service is also implemented as an internal service. -For any TCPMUX-based service to function, the following line must be included -in -.Pa inetd.conf : -.Bd -literal -offset indent -tcpmux stream tcp nowait root internal -.Ed -.Pp -When given the -.Fl l -option -.Nm -will log an entry to syslog each time a connection is accepted, noting the -service selected and the IP-number of the remote requester if available. -Unless otherwise specified in the configuration file, -and in the absence of the -.Fl W -and -.Fl w -options, -.Nm -will log to the -.Dq daemon -facility. -.Pp -The -.Nm -utility rereads its configuration file when it receives a hangup signal, -.Dv SIGHUP . -Services may be added, deleted or modified when the configuration file -is reread. -Except when started in debugging mode, -or configured otherwise with the -.Fl p -option, -.Nm -records its process ID in the file -.Pa /var/run/inetd.pid -to assist in reconfiguration. -.Sh IMPLEMENTATION NOTES -.Ss TCP Wrappers -When given the -.Fl w -option, -.Nm -will wrap all services specified as -.Dq stream nowait -or -.Dq dgram -except for -.Dq internal -services. -If the -.Fl W -option is given, such -.Dq internal -services will be wrapped. -If both options are given, wrapping for both -internal and external services will be enabled. -Either wrapping option -will cause failed connections to be logged to the -.Dq auth -syslog facility. -Adding the -.Fl l -flag to the wrapping options will include successful connections in the -logging to the -.Dq auth -facility. -.Pp -Note that -.Nm -only wraps requests for a -.Dq wait -service while no servers are available to service requests. -Once a -connection to such a service has been allowed, -.Nm -has no control -over subsequent connections to the service until no more servers -are left listening for connection requests. -.Pp -When wrapping is enabled, the -.Pa tcpd -daemon is not required, as that functionality is builtin. -For more information on TCP Wrappers, see the relevant documentation -.Pq Xr hosts_access 5 . -When reading that document, keep in mind that -.Dq internal -services have no associated daemon name. -Therefore, the service name -as specified in -.Pa inetd.conf -should be used as the daemon name for -.Dq internal -services. -.Ss TCPMUX -.Tn RFC 1078 -describes the TCPMUX protocol: -``A TCP client connects to a foreign host on TCP port 1. -It sends the -service name followed by a carriage-return line-feed . -The -service name is never case sensitive. -The server replies with a -single character indicating positive (+) or negative (\-) -acknowledgment, immediately followed by an optional message of -explanation, terminated with a . -If the reply was positive, -the selected protocol begins; otherwise the connection is closed.'' -The program is passed the TCP connection as file descriptors 0 and 1. -.Pp -If the TCPMUX service name begins with a -.Dq + , -.Nm -returns the positive reply for the program. -This allows you to invoke programs that use stdin/stdout -without putting any special server code in them. -.Pp -The special service name -.Dq help -causes -.Nm -to list the TCPMUX services which are enabled in -.Pa inetd.conf . -.Ss IPsec -The implementation includes a tiny hack -to support IPsec policy settings for each socket. -A special form of comment line, starting with -.Dq Li #@ , -is interpreted as a policy specifier. -Everything after the -.Dq Li #@ -will be used as an IPsec policy string, -as described in -.Xr ipsec_set_policy 3 . -Each -policy specifier is applied to all the following lines in -.Pa inetd.conf -until the next policy specifier. -An empty policy specifier resets the IPsec policy. -.Pp -If an invalid IPsec policy specifier appears in -.Pa inetd.conf , -.Nm -will provide an error message via the -.Xr syslog 3 -interface and abort execution. -.Ss Ux Domain Sockets -In addition to running services on IP sockets, -.Nm -can also manage -.Ux -domain sockets. -To do this you specify a -.Em protocol -of -.Dq unix -and specify the -.Ux -domain socket as the -.Em service-name . -The -.Em service-type -may be -.Dq stream -or -.Dq dgram . -The specification of the socket must be -an absolute path name, -optionally prefixed by an owner and mode -of the form -.Em :user:group:mode: . -The specification: -.Pp -.Dl ":news:daemon:220:/var/run/sock" -.Pp -creates a socket owned -by user -.Dq news -in group -.Dq daemon -with permissions allowing only that user and group to connect. -The default owner is the user that -.Nm -is running as. -The default mode only allows the socket's owner to connect. -.Pp -.Sy WARNING : -while creating a -.Ux -domain socket, -.Nm -must change the ownership and permissions on the socket. -This can only be done securely if -the directory in which the socket is created -is writable only by root. -Do -.Em NOT -use -.Nm -to create sockets in world writable directories -such as -.Pa /tmp ; -use -.Pa /var/run -or a similar directory instead. -.Pp -Internal services may be run on -.Ux -domain sockets, in the usual way. -In this case -the name of the internal service -is determined using -the last component of the socket's pathname. -For example, specifying a socket named -.Pa /var/run/chargen -would invoke the -.Dq chargen -service when a connection is received on that socket. -.Sh "FILES" -.Bl -tag -width /var/run/inetd.pid -compact -.It Pa /etc/inetd.conf -configuration file -.It Pa /etc/netconfig -network configuration data base -.It Pa /etc/rpc -translation of service names to RPC program numbers -.It Pa /etc/services -translation of service names to port numbers -.It Pa /var/run/inetd.pid -the pid of the currently running -.Nm -.El -.Sh "EXAMPLES" -Here are several example service entries for the various types of services: -.Bd -literal -ftp stream tcp nowait root /usr/libexec/ftpd ftpd -l -ntalk dgram udp wait root /usr/libexec/ntalkd ntalkd -telnet stream tcp6 nowait root /usr/libexec/telnetd telnetd -shell stream tcp46 nowait root /usr/libexec/rshd rshd -tcpmux/+date stream tcp nowait guest /bin/date date -tcpmux/phonebook stream tcp nowait guest /usr/local/bin/phonebook phonebook -rstatd/1-3 dgram rpc/udp wait root /usr/libexec/rpc.rstatd rpc.rstatd -/var/run/echo stream unix nowait root internal -#@ ipsec ah/require -chargen stream tcp nowait root internal -#@ -.Ed -.Sh "ERROR MESSAGES" -The -.Nm -server -logs error messages using -.Xr syslog 3 . -Important error messages and their explanations are: -.Pp -.Bl -ohang -compact -.It Xo -.Ar service Ns / Ns Ar protocol -.No "server failing (looping), service terminated." -.Xc -The number of requests for the specified service in the past minute -exceeded the limit. -The limit exists to prevent a broken program -or a malicious user from swamping the system. -This message may occur for several reasons: -.Bl -enum -offset indent -.It -There are many hosts requesting the service within a short time period. -.It -A broken client program is requesting the service too frequently. -.It -A malicious user is running a program to invoke the service in -a denial-of-service attack. -.It -The invoked service program has an error that causes clients -to retry quickly. -.El -.Pp -Use the -.Fl R Ar rate -option, -as described above, to change the rate limit. -Once the limit is reached, the service will be -reenabled automatically in 10 minutes. -.Pp -.It Xo -.Ar service Ns / Ns Ar protocol : -.No \&No such user -.Ar user , -.No service ignored -.Xc -.It Xo -.Ar service Ns / Ns Ar protocol : -.No getpwnam : -.Ar user : -.No \&No such user -.Xc -No entry for -.Ar user -exists in the -.Xr passwd 5 -database. -The first message -occurs when -.Nm -(re)reads the configuration file. -The second message occurs when the -service is invoked. -.Pp -.It Xo -.Ar service : -.No can't set uid -.Ar uid -.Xc -.It Xo -.Ar service : -.No can't set gid -.Ar gid -.Xc -The user or group ID for the entry's -.Ar user -field is invalid. -.Pp -.It "setsockopt(SO_PRIVSTATE): Operation not supported" -The -.Nm -utility attempted to renounce the privileged state associated with a -socket but was unable to. -.Pp -.It Xo unknown -.Ar rpc/udp -or -.Ar rpc/tcp -.Xc -No entry was found for either -.Ar udp -or -.Ar tcp -in the -.Xr netconfig 5 -database. -.Pp -.It Xo unknown -.Ar rpc/udp6 -or -.Ar rpc/tcp6 -.Xc -No entry was found for either -.Ar udp6 -or -.Ar tcp6 -in the -.Xr netconfig 5 -database. -.El -.Sh SEE ALSO -.Xr ipsec_set_policy 3 , -.Xr hosts_access 5 , -.Xr hosts_options 5 , -.Xr login.conf 5 , -.Xr netconfig 5 , -.Xr passwd 5 , -.Xr rpc 5 , -.Xr services 5 , -.Xr comsat 8 , -.Xr fingerd 8 , -.Xr ftpd 8 , -.Xr rlogind 8 , -.Xr rpcbind 8 , -.Xr rshd 8 , -.Xr talkd 8 , -.Xr telnetd 8 , -.Xr tftpd 8 -.Rs -.%A Michael C. St. Johns -.%T Identification Protocol -.%O RFC1413 -.Re -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 4.3 . -TCPMUX is based on code and documentation by Mark Lottor. -Support for -.Tn "ONC RPC" -based services is modeled after that -provided by -.Tn SunOS -4.1. -The IPsec hack was contributed by the KAME project in 1999. -The -.Fx -TCP Wrappers support first appeared in -.Fx 3.2 . diff --git a/usr.sbin/inetd/inetd.c b/usr.sbin/inetd/inetd.c deleted file mode 100644 index 0a39fdf..0000000 --- a/usr.sbin/inetd/inetd.c +++ /dev/null @@ -1,2584 +0,0 @@ -/* - * Copyright (c) 1983, 1991, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1983, 1991, 1993, 1994\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)from: inetd.c 8.4 (Berkeley) 4/13/94"; -#endif -#endif /* not lint */ - -#include -__FBSDID("$FreeBSD$"); - -/* - * Inetd - Internet super-server - * - * This program invokes all internet services as needed. Connection-oriented - * services are invoked each time a connection is made, by creating a process. - * This process is passed the connection as file descriptor 0 and is expected - * to do a getpeername to find out the source host and port. - * - * Datagram oriented services are invoked when a datagram - * arrives; a process is created and passed a pending message - * on file descriptor 0. Datagram servers may either connect - * to their peer, freeing up the original socket for inetd - * to receive further messages on, or ``take over the socket'', - * processing all arriving datagrams and, eventually, timing - * out. The first type of server is said to be ``multi-threaded''; - * the second type of server ``single-threaded''. - * - * Inetd uses a configuration file which is read at startup - * and, possibly, at some later time in response to a hangup signal. - * The configuration file is ``free format'' with fields given in the - * order shown below. Continuation lines for an entry must begin with - * a space or tab. All fields must be present in each entry. - * - * service name must be in /etc/services - * or name a tcpmux service - * or specify a unix domain socket - * socket type stream/dgram/raw/rdm/seqpacket - * protocol tcp[4][6][/faith], udp[4][6], unix - * wait/nowait single-threaded/multi-threaded - * user[:group][/login-class] user/group/login-class to run daemon as - * server program full path name - * server program arguments maximum of MAXARGS (20) - * - * TCP services without official port numbers are handled with the - * RFC1078-based tcpmux internal service. Tcpmux listens on port 1 for - * requests. When a connection is made from a foreign host, the service - * requested is passed to tcpmux, which looks it up in the servtab list - * and returns the proper entry for the service. Tcpmux returns a - * negative reply if the service doesn't exist, otherwise the invoked - * server is expected to return the positive reply if the service type in - * inetd.conf file has the prefix "tcpmux/". If the service type has the - * prefix "tcpmux/+", tcpmux will return the positive reply for the - * process; this is for compatibility with older server code, and also - * allows you to invoke programs that use stdin/stdout without putting any - * special server code in them. Services that use tcpmux are "nowait" - * because they do not have a well-known port and hence cannot listen - * for new requests. - * - * For RPC services - * service name/version must be in /etc/rpc - * socket type stream/dgram/raw/rdm/seqpacket - * protocol rpc/tcp[4][6], rpc/udp[4][6] - * wait/nowait single-threaded/multi-threaded - * user[:group][/login-class] user/group/login-class to run daemon as - * server program full path name - * server program arguments maximum of MAXARGS - * - * Comment lines are indicated by a `#' in column 1. - * - * #ifdef IPSEC - * Comment lines that start with "#@" denote IPsec policy string, as described - * in ipsec_set_policy(3). This will affect all the following items in - * inetd.conf(8). To reset the policy, just use "#@" line. By default, - * there's no IPsec policy. - * #endif - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "inetd.h" -#include "pathnames.h" - -#ifdef IPSEC -#include -#ifndef IPSEC_POLICY_IPSEC /* no ipsec support on old ipsec */ -#undef IPSEC -#endif -#endif - -#ifndef LIBWRAP_ALLOW_FACILITY -# define LIBWRAP_ALLOW_FACILITY LOG_AUTH -#endif -#ifndef LIBWRAP_ALLOW_SEVERITY -# define LIBWRAP_ALLOW_SEVERITY LOG_INFO -#endif -#ifndef LIBWRAP_DENY_FACILITY -# define LIBWRAP_DENY_FACILITY LOG_AUTH -#endif -#ifndef LIBWRAP_DENY_SEVERITY -# define LIBWRAP_DENY_SEVERITY LOG_WARNING -#endif - -#define ISWRAP(sep) \ - ( ((wrap_ex && !(sep)->se_bi) || (wrap_bi && (sep)->se_bi)) \ - && (sep->se_family == AF_INET || sep->se_family == AF_INET6) \ - && ( ((sep)->se_accept && (sep)->se_socktype == SOCK_STREAM) \ - || (sep)->se_socktype == SOCK_DGRAM)) - -#ifdef LOGIN_CAP -#include - -/* see init.c */ -#define RESOURCE_RC "daemon" - -#endif - -#ifndef MAXCHILD -#define MAXCHILD -1 /* maximum number of this service - < 0 = no limit */ -#endif - -#ifndef MAXCPM -#define MAXCPM -1 /* rate limit invocations from a - single remote address, - < 0 = no limit */ -#endif - -#ifndef MAXPERIP -#define MAXPERIP -1 /* maximum number of this service - from a single remote address, - < 0 = no limit */ -#endif - -#ifndef TOOMANY -#define TOOMANY 256 /* don't start more than TOOMANY */ -#endif -#define CNT_INTVL 60 /* servers in CNT_INTVL sec. */ -#define RETRYTIME (60*10) /* retry after bind or server fail */ -#define MAX_MAXCHLD 32767 /* max allowable max children */ - -#define SIGBLOCK (sigmask(SIGCHLD)|sigmask(SIGHUP)|sigmask(SIGALRM)) - -void close_sep(struct servtab *); -void flag_signal(int); -void flag_config(int); -void config(void); -int cpmip(const struct servtab *, int); -void endconfig(void); -struct servtab *enter(struct servtab *); -void freeconfig(struct servtab *); -struct servtab *getconfigent(void); -int matchservent(const char *, const char *, const char *); -char *nextline(FILE *); -void addchild(struct servtab *, int); -void flag_reapchild(int); -void reapchild(void); -void enable(struct servtab *); -void disable(struct servtab *); -void flag_retry(int); -void retry(void); -int setconfig(void); -void setup(struct servtab *); -#ifdef IPSEC -void ipsecsetup(struct servtab *); -#endif -void unregisterrpc(register struct servtab *sep); -static struct conninfo *search_conn(struct servtab *sep, int ctrl); -static int room_conn(struct servtab *sep, struct conninfo *conn); -static void addchild_conn(struct conninfo *conn, pid_t pid); -static void reapchild_conn(pid_t pid); -static void free_conn(struct conninfo *conn); -static void resize_conn(struct servtab *sep, int maxperip); -static void free_connlist(struct servtab *sep); -static void free_proc(struct procinfo *); -static struct procinfo *search_proc(pid_t pid, int add); -static int hashval(char *p, int len); - -int allow_severity; -int deny_severity; -int wrap_ex = 0; -int wrap_bi = 0; -int debug = 0; -int dolog = 0; -int maxsock; /* highest-numbered descriptor */ -fd_set allsock; -int options; -int timingout; -int toomany = TOOMANY; -int maxchild = MAXCHILD; -int maxcpm = MAXCPM; -int maxperip = MAXPERIP; -struct servent *sp; -struct rpcent *rpc; -char *hostname = NULL; -struct sockaddr_in *bind_sa4; -int v4bind_ok = 0; -#ifdef INET6 -struct sockaddr_in6 *bind_sa6; -int v6bind_ok = 0; -#endif -int signalpipe[2]; -#ifdef SANITY_CHECK -int nsock; -#endif -uid_t euid; -gid_t egid; -mode_t mask; - -struct servtab *servtab; - -extern struct biltin biltins[]; - -const char *CONFIG = _PATH_INETDCONF; -const char *pid_file = _PATH_INETDPID; -struct pidfh *pfh = NULL; - -struct netconfig *udpconf, *tcpconf, *udp6conf, *tcp6conf; - -static LIST_HEAD(, procinfo) proctable[PERIPSIZE]; - -int -getvalue(const char *arg, int *value, const char *whine) -{ - int tmp; - char *p; - - tmp = strtol(arg, &p, 0); - if (tmp < 0 || *p) { - syslog(LOG_ERR, whine, arg); - return 1; /* failure */ - } - *value = tmp; - return 0; /* success */ -} - -static sa_family_t -whichaf(struct request_info *req) -{ - struct sockaddr *sa; - - sa = (struct sockaddr *)req->client->sin; - if (sa == NULL) - return AF_UNSPEC; - if (sa->sa_family == AF_INET6 && - IN6_IS_ADDR_V4MAPPED(&((struct sockaddr_in6 *)sa)->sin6_addr)) - return AF_INET; - return sa->sa_family; -} - -int -main(int argc, char **argv) -{ - struct servtab *sep; - struct passwd *pwd; - struct group *grp; - struct sigaction sa, saalrm, sachld, sahup, sapipe; - int ch, dofork; - pid_t pid; - char buf[50]; -#ifdef LOGIN_CAP - login_cap_t *lc = NULL; -#endif - struct request_info req; - int denied; - char *service = NULL; - union { - struct sockaddr peer_un; - struct sockaddr_in peer_un4; - struct sockaddr_in6 peer_un6; - struct sockaddr_storage peer_max; - } p_un; -#define peer p_un.peer_un -#define peer4 p_un.peer_un4 -#define peer6 p_un.peer_un6 -#define peermax p_un.peer_max - int i; - struct addrinfo hints, *res; - const char *servname; - int error; - struct conninfo *conn; - - openlog("inetd", LOG_PID | LOG_NOWAIT | LOG_PERROR, LOG_DAEMON); - - while ((ch = getopt(argc, argv, "dlwWR:a:c:C:p:s:")) != -1) - switch(ch) { - case 'd': - debug = 1; - options |= SO_DEBUG; - break; - case 'l': - dolog = 1; - break; - case 'R': - getvalue(optarg, &toomany, - "-R %s: bad value for service invocation rate"); - break; - case 'c': - getvalue(optarg, &maxchild, - "-c %s: bad value for maximum children"); - break; - case 'C': - getvalue(optarg, &maxcpm, - "-C %s: bad value for maximum children/minute"); - break; - case 'a': - hostname = optarg; - break; - case 'p': - pid_file = optarg; - break; - case 's': - getvalue(optarg, &maxperip, - "-s %s: bad value for maximum children per source address"); - break; - case 'w': - wrap_ex++; - break; - case 'W': - wrap_bi++; - break; - case '?': - default: - syslog(LOG_ERR, - "usage: inetd [-dlwW] [-a address] [-R rate]" - " [-c maximum] [-C rate]" - " [-p pidfile] [conf-file]"); - exit(EX_USAGE); - } - /* - * Initialize Bind Addrs. - * When hostname is NULL, wild card bind addrs are obtained from - * getaddrinfo(). But getaddrinfo() requires at least one of - * hostname or servname is non NULL. - * So when hostname is NULL, set dummy value to servname. - * Since getaddrinfo() doesn't accept numeric servname, and - * we doesn't use ai_socktype of struct addrinfo returned - * from getaddrinfo(), we set dummy value to ai_socktype. - */ - servname = (hostname == NULL) ? "0" /* dummy */ : NULL; - - bzero(&hints, sizeof(struct addrinfo)); - hints.ai_flags = AI_PASSIVE; - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; /* dummy */ - error = getaddrinfo(hostname, servname, &hints, &res); - if (error != 0) { - syslog(LOG_ERR, "-a %s: %s", hostname, gai_strerror(error)); - if (error == EAI_SYSTEM) - syslog(LOG_ERR, "%s", strerror(errno)); - exit(EX_USAGE); - } - do { - if (res->ai_addr == NULL) { - syslog(LOG_ERR, "-a %s: getaddrinfo failed", hostname); - exit(EX_USAGE); - } - switch (res->ai_addr->sa_family) { - case AF_INET: - if (v4bind_ok) - continue; - bind_sa4 = (struct sockaddr_in *)res->ai_addr; - /* init port num in case servname is dummy */ - bind_sa4->sin_port = 0; - v4bind_ok = 1; - continue; -#ifdef INET6 - case AF_INET6: - if (v6bind_ok) - continue; - bind_sa6 = (struct sockaddr_in6 *)res->ai_addr; - /* init port num in case servname is dummy */ - bind_sa6->sin6_port = 0; - v6bind_ok = 1; - continue; -#endif - } - if (v4bind_ok -#ifdef INET6 - && v6bind_ok -#endif - ) - break; - } while ((res = res->ai_next) != NULL); - if (!v4bind_ok -#ifdef INET6 - && !v6bind_ok -#endif - ) { - syslog(LOG_ERR, "-a %s: unknown address family", hostname); - exit(EX_USAGE); - } - - euid = geteuid(); - egid = getegid(); - umask(mask = umask(0777)); - - argc -= optind; - argv += optind; - - if (argc > 0) - CONFIG = argv[0]; - if (access(CONFIG, R_OK) < 0) - syslog(LOG_ERR, "Accessing %s: %m, continuing anyway.", CONFIG); - if (debug == 0) { - pid_t otherpid; - - pfh = pidfile_open(pid_file, 0600, &otherpid); - if (pfh == NULL) { - if (errno == EEXIST) { - syslog(LOG_ERR, "%s already running, pid: %d", - getprogname(), otherpid); - exit(EX_OSERR); - } - syslog(LOG_WARNING, "pidfile_open() failed: %m"); - } - - if (daemon(0, 0) < 0) { - syslog(LOG_WARNING, "daemon(0,0) failed: %m"); - } - /* From now on we don't want syslog messages going to stderr. */ - closelog(); - openlog("inetd", LOG_PID | LOG_NOWAIT, LOG_DAEMON); - /* - * In case somebody has started inetd manually, we need to - * clear the logname, so that old servers run as root do not - * get the user's logname.. - */ - if (setlogin("") < 0) { - syslog(LOG_WARNING, "cannot clear logname: %m"); - /* no big deal if it fails.. */ - } - if (pfh != NULL && pidfile_write(pfh) == -1) { - syslog(LOG_WARNING, "pidfile_write(): %m"); - } - } - - if (madvise(NULL, 0, MADV_PROTECT) != 0) - syslog(LOG_WARNING, "madvise() failed: %s", strerror(errno)); - - for (i = 0; i < PERIPSIZE; ++i) - LIST_INIT(&proctable[i]); - - if (v4bind_ok) { - udpconf = getnetconfigent("udp"); - tcpconf = getnetconfigent("tcp"); - if (udpconf == NULL || tcpconf == NULL) { - syslog(LOG_ERR, "unknown rpc/udp or rpc/tcp"); - exit(EX_USAGE); - } - } -#ifdef INET6 - if (v6bind_ok) { - udp6conf = getnetconfigent("udp6"); - tcp6conf = getnetconfigent("tcp6"); - if (udp6conf == NULL || tcp6conf == NULL) { - syslog(LOG_ERR, "unknown rpc/udp6 or rpc/tcp6"); - exit(EX_USAGE); - } - } -#endif - - sa.sa_flags = 0; - sigemptyset(&sa.sa_mask); - sigaddset(&sa.sa_mask, SIGALRM); - sigaddset(&sa.sa_mask, SIGCHLD); - sigaddset(&sa.sa_mask, SIGHUP); - sa.sa_handler = flag_retry; - sigaction(SIGALRM, &sa, &saalrm); - config(); - sa.sa_handler = flag_config; - sigaction(SIGHUP, &sa, &sahup); - sa.sa_handler = flag_reapchild; - sigaction(SIGCHLD, &sa, &sachld); - sa.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &sa, &sapipe); - - { - /* space for daemons to overwrite environment for ps */ -#define DUMMYSIZE 100 - char dummy[DUMMYSIZE]; - - (void)memset(dummy, 'x', DUMMYSIZE - 1); - dummy[DUMMYSIZE - 1] = '\0'; - (void)setenv("inetd_dummy", dummy, 1); - } - - if (pipe(signalpipe) != 0) { - syslog(LOG_ERR, "pipe: %m"); - exit(EX_OSERR); - } - if (fcntl(signalpipe[0], F_SETFD, FD_CLOEXEC) < 0 || - fcntl(signalpipe[1], F_SETFD, FD_CLOEXEC) < 0) { - syslog(LOG_ERR, "signalpipe: fcntl (F_SETFD, FD_CLOEXEC): %m"); - exit(EX_OSERR); - } - FD_SET(signalpipe[0], &allsock); -#ifdef SANITY_CHECK - nsock++; -#endif - if (signalpipe[0] > maxsock) - maxsock = signalpipe[0]; - if (signalpipe[1] > maxsock) - maxsock = signalpipe[1]; - - for (;;) { - int n, ctrl; - fd_set readable; - -#ifdef SANITY_CHECK - if (nsock == 0) { - syslog(LOG_ERR, "%s: nsock=0", __func__); - exit(EX_SOFTWARE); - } -#endif - readable = allsock; - if ((n = select(maxsock + 1, &readable, (fd_set *)0, - (fd_set *)0, (struct timeval *)0)) <= 0) { - if (n < 0 && errno != EINTR) { - syslog(LOG_WARNING, "select: %m"); - sleep(1); - } - continue; - } - /* handle any queued signal flags */ - if (FD_ISSET(signalpipe[0], &readable)) { - int nsig; - if (ioctl(signalpipe[0], FIONREAD, &nsig) != 0) { - syslog(LOG_ERR, "ioctl: %m"); - exit(EX_OSERR); - } - while (--nsig >= 0) { - char c; - if (read(signalpipe[0], &c, 1) != 1) { - syslog(LOG_ERR, "read: %m"); - exit(EX_OSERR); - } - if (debug) - warnx("handling signal flag %c", c); - switch(c) { - case 'A': /* sigalrm */ - retry(); - break; - case 'C': /* sigchld */ - reapchild(); - break; - case 'H': /* sighup */ - config(); - break; - } - } - } - for (sep = servtab; n && sep; sep = sep->se_next) - if (sep->se_fd != -1 && FD_ISSET(sep->se_fd, &readable)) { - n--; - if (debug) - warnx("someone wants %s", sep->se_service); - dofork = !sep->se_bi || sep->se_bi->bi_fork || ISWRAP(sep); - conn = NULL; - if (sep->se_accept && sep->se_socktype == SOCK_STREAM) { - i = 1; - if (ioctl(sep->se_fd, FIONBIO, &i) < 0) - syslog(LOG_ERR, "ioctl (FIONBIO, 1): %m"); - ctrl = accept(sep->se_fd, (struct sockaddr *)0, - (socklen_t *)0); - if (debug) - warnx("accept, ctrl %d", ctrl); - if (ctrl < 0) { - if (errno != EINTR) - syslog(LOG_WARNING, - "accept (for %s): %m", - sep->se_service); - if (sep->se_accept && - sep->se_socktype == SOCK_STREAM) - close(ctrl); - continue; - } - i = 0; - if (ioctl(sep->se_fd, FIONBIO, &i) < 0) - syslog(LOG_ERR, "ioctl1(FIONBIO, 0): %m"); - if (ioctl(ctrl, FIONBIO, &i) < 0) - syslog(LOG_ERR, "ioctl2(FIONBIO, 0): %m"); - if (cpmip(sep, ctrl) < 0) { - close(ctrl); - continue; - } - if (dofork && - (conn = search_conn(sep, ctrl)) != NULL && - !room_conn(sep, conn)) { - close(ctrl); - continue; - } - } else - ctrl = sep->se_fd; - if (dolog && !ISWRAP(sep)) { - char pname[INET6_ADDRSTRLEN] = "unknown"; - socklen_t sl; - sl = sizeof peermax; - if (getpeername(ctrl, (struct sockaddr *) - &peermax, &sl)) { - sl = sizeof peermax; - if (recvfrom(ctrl, buf, sizeof(buf), - MSG_PEEK, - (struct sockaddr *)&peermax, - &sl) >= 0) { - getnameinfo((struct sockaddr *)&peermax, - peer.sa_len, - pname, sizeof(pname), - NULL, 0, NI_NUMERICHOST); - } - } else { - getnameinfo((struct sockaddr *)&peermax, - peer.sa_len, - pname, sizeof(pname), - NULL, 0, NI_NUMERICHOST); - } - syslog(LOG_INFO,"%s from %s", sep->se_service, pname); - } - (void) sigblock(SIGBLOCK); - pid = 0; - /* - * Fork for all external services, builtins which need to - * fork and anything we're wrapping (as wrapping might - * block or use hosts_options(5) twist). - */ - if (dofork) { - if (sep->se_count++ == 0) - (void)gettimeofday(&sep->se_time, (struct timezone *)NULL); - else if (toomany > 0 && sep->se_count >= toomany) { - struct timeval now; - - (void)gettimeofday(&now, (struct timezone *)NULL); - if (now.tv_sec - sep->se_time.tv_sec > - CNT_INTVL) { - sep->se_time = now; - sep->se_count = 1; - } else { - syslog(LOG_ERR, - "%s/%s server failing (looping), service terminated", - sep->se_service, sep->se_proto); - if (sep->se_accept && - sep->se_socktype == SOCK_STREAM) - close(ctrl); - close_sep(sep); - free_conn(conn); - sigsetmask(0L); - if (!timingout) { - timingout = 1; - alarm(RETRYTIME); - } - continue; - } - } - pid = fork(); - } - if (pid < 0) { - syslog(LOG_ERR, "fork: %m"); - if (sep->se_accept && - sep->se_socktype == SOCK_STREAM) - close(ctrl); - free_conn(conn); - sigsetmask(0L); - sleep(1); - continue; - } - if (pid) { - addchild_conn(conn, pid); - addchild(sep, pid); - } - sigsetmask(0L); - if (pid == 0) { - pidfile_close(pfh); - if (dofork) { - sigaction(SIGALRM, &saalrm, (struct sigaction *)0); - sigaction(SIGCHLD, &sachld, (struct sigaction *)0); - sigaction(SIGHUP, &sahup, (struct sigaction *)0); - /* SIGPIPE reset before exec */ - } - /* - * Call tcpmux to find the real service to exec. - */ - if (sep->se_bi && - sep->se_bi->bi_fn == (bi_fn_t *) tcpmux) { - sep = tcpmux(ctrl); - if (sep == NULL) { - close(ctrl); - _exit(0); - } - } - if (ISWRAP(sep)) { - inetd_setproctitle("wrapping", ctrl); - service = sep->se_server_name ? - sep->se_server_name : sep->se_service; - request_init(&req, RQ_DAEMON, service, RQ_FILE, ctrl, 0); - fromhost(&req); - deny_severity = LIBWRAP_DENY_FACILITY|LIBWRAP_DENY_SEVERITY; - allow_severity = LIBWRAP_ALLOW_FACILITY|LIBWRAP_ALLOW_SEVERITY; - denied = !hosts_access(&req); - if (denied) { - syslog(deny_severity, - "refused connection from %.500s, service %s (%s%s)", - eval_client(&req), service, sep->se_proto, - (whichaf(&req) == AF_INET6) ? "6" : ""); - if (sep->se_socktype != SOCK_STREAM) - recv(ctrl, buf, sizeof (buf), 0); - if (dofork) { - sleep(1); - _exit(0); - } - } - if (dolog) { - syslog(allow_severity, - "connection from %.500s, service %s (%s%s)", - eval_client(&req), service, sep->se_proto, - (whichaf(&req) == AF_INET6) ? "6" : ""); - } - } - if (sep->se_bi) { - (*sep->se_bi->bi_fn)(ctrl, sep); - } else { - if (debug) - warnx("%d execl %s", - getpid(), sep->se_server); - /* Clear close-on-exec. */ - if (fcntl(ctrl, F_SETFD, 0) < 0) { - syslog(LOG_ERR, - "%s/%s: fcntl (F_SETFD, 0): %m", - sep->se_service, sep->se_proto); - _exit(EX_OSERR); - } - if (ctrl != 0) { - dup2(ctrl, 0); - close(ctrl); - } - dup2(0, 1); - dup2(0, 2); - if ((pwd = getpwnam(sep->se_user)) == NULL) { - syslog(LOG_ERR, - "%s/%s: %s: no such user", - sep->se_service, sep->se_proto, - sep->se_user); - if (sep->se_socktype != SOCK_STREAM) - recv(0, buf, sizeof (buf), 0); - _exit(EX_NOUSER); - } - grp = NULL; - if ( sep->se_group != NULL - && (grp = getgrnam(sep->se_group)) == NULL - ) { - syslog(LOG_ERR, - "%s/%s: %s: no such group", - sep->se_service, sep->se_proto, - sep->se_group); - if (sep->se_socktype != SOCK_STREAM) - recv(0, buf, sizeof (buf), 0); - _exit(EX_NOUSER); - } - if (grp != NULL) - pwd->pw_gid = grp->gr_gid; -#ifdef LOGIN_CAP - if ((lc = login_getclass(sep->se_class)) == NULL) { - /* error syslogged by getclass */ - syslog(LOG_ERR, - "%s/%s: %s: login class error", - sep->se_service, sep->se_proto, - sep->se_class); - if (sep->se_socktype != SOCK_STREAM) - recv(0, buf, sizeof (buf), 0); - _exit(EX_NOUSER); - } -#endif - if (setsid() < 0) { - syslog(LOG_ERR, - "%s: can't setsid(): %m", - sep->se_service); - /* _exit(EX_OSERR); not fatal yet */ - } -#ifdef LOGIN_CAP - if (setusercontext(lc, pwd, pwd->pw_uid, - LOGIN_SETALL & ~LOGIN_SETMAC) - != 0) { - syslog(LOG_ERR, - "%s: can't setusercontext(..%s..): %m", - sep->se_service, sep->se_user); - _exit(EX_OSERR); - } - login_close(lc); -#else - if (pwd->pw_uid) { - if (setlogin(sep->se_user) < 0) { - syslog(LOG_ERR, - "%s: can't setlogin(%s): %m", - sep->se_service, sep->se_user); - /* _exit(EX_OSERR); not yet */ - } - if (setgid(pwd->pw_gid) < 0) { - syslog(LOG_ERR, - "%s: can't set gid %d: %m", - sep->se_service, pwd->pw_gid); - _exit(EX_OSERR); - } - (void) initgroups(pwd->pw_name, - pwd->pw_gid); - if (setuid(pwd->pw_uid) < 0) { - syslog(LOG_ERR, - "%s: can't set uid %d: %m", - sep->se_service, pwd->pw_uid); - _exit(EX_OSERR); - } - } -#endif - sigaction(SIGPIPE, &sapipe, - (struct sigaction *)0); - execv(sep->se_server, sep->se_argv); - syslog(LOG_ERR, - "cannot execute %s: %m", sep->se_server); - if (sep->se_socktype != SOCK_STREAM) - recv(0, buf, sizeof (buf), 0); - } - if (dofork) - _exit(0); - } - if (sep->se_accept && sep->se_socktype == SOCK_STREAM) - close(ctrl); - } - } -} - -/* - * Add a signal flag to the signal flag queue for later handling - */ - -void -flag_signal(int c) -{ - char ch = c; - - if (write(signalpipe[1], &ch, 1) != 1) { - syslog(LOG_ERR, "write: %m"); - _exit(EX_OSERR); - } -} - -/* - * Record a new child pid for this service. If we've reached the - * limit on children, then stop accepting incoming requests. - */ - -void -addchild(struct servtab *sep, pid_t pid) -{ - if (sep->se_maxchild <= 0) - return; -#ifdef SANITY_CHECK - if (sep->se_numchild >= sep->se_maxchild) { - syslog(LOG_ERR, "%s: %d >= %d", - __func__, sep->se_numchild, sep->se_maxchild); - exit(EX_SOFTWARE); - } -#endif - sep->se_pids[sep->se_numchild++] = pid; - if (sep->se_numchild == sep->se_maxchild) - disable(sep); -} - -/* - * Some child process has exited. See if it's on somebody's list. - */ - -void -flag_reapchild(int signo __unused) -{ - flag_signal('C'); -} - -void -reapchild(void) -{ - int k, status; - pid_t pid; - struct servtab *sep; - - for (;;) { - pid = wait3(&status, WNOHANG, (struct rusage *)0); - if (pid <= 0) - break; - if (debug) - warnx("%d reaped, %s %u", pid, - WIFEXITED(status) ? "status" : "signal", - WIFEXITED(status) ? WEXITSTATUS(status) - : WTERMSIG(status)); - for (sep = servtab; sep; sep = sep->se_next) { - for (k = 0; k < sep->se_numchild; k++) - if (sep->se_pids[k] == pid) - break; - if (k == sep->se_numchild) - continue; - if (sep->se_numchild == sep->se_maxchild) - enable(sep); - sep->se_pids[k] = sep->se_pids[--sep->se_numchild]; - if (WIFSIGNALED(status) || WEXITSTATUS(status)) - syslog(LOG_WARNING, - "%s[%d]: exited, %s %u", - sep->se_server, pid, - WIFEXITED(status) ? "status" : "signal", - WIFEXITED(status) ? WEXITSTATUS(status) - : WTERMSIG(status)); - break; - } - reapchild_conn(pid); - } -} - -void -flag_config(int signo __unused) -{ - flag_signal('H'); -} - -void -config(void) -{ - struct servtab *sep, *new, **sepp; - long omask; - int new_nomapped; -#ifdef LOGIN_CAP - login_cap_t *lc = NULL; -#endif - - if (!setconfig()) { - syslog(LOG_ERR, "%s: %m", CONFIG); - return; - } - for (sep = servtab; sep; sep = sep->se_next) - sep->se_checked = 0; - while ((new = getconfigent())) { - if (getpwnam(new->se_user) == NULL) { - syslog(LOG_ERR, - "%s/%s: no such user '%s', service ignored", - new->se_service, new->se_proto, new->se_user); - continue; - } - if (new->se_group && getgrnam(new->se_group) == NULL) { - syslog(LOG_ERR, - "%s/%s: no such group '%s', service ignored", - new->se_service, new->se_proto, new->se_group); - continue; - } -#ifdef LOGIN_CAP - if ((lc = login_getclass(new->se_class)) == NULL) { - /* error syslogged by getclass */ - syslog(LOG_ERR, - "%s/%s: %s: login class error, service ignored", - new->se_service, new->se_proto, new->se_class); - continue; - } - login_close(lc); -#endif - new_nomapped = new->se_nomapped; - for (sep = servtab; sep; sep = sep->se_next) - if (strcmp(sep->se_service, new->se_service) == 0 && - strcmp(sep->se_proto, new->se_proto) == 0 && - sep->se_rpc == new->se_rpc && - sep->se_socktype == new->se_socktype && - sep->se_family == new->se_family) - break; - if (sep != 0) { - int i; - -#define SWAP(t,a, b) { t c = a; a = b; b = c; } - omask = sigblock(SIGBLOCK); - if (sep->se_nomapped != new->se_nomapped) { - /* for rpc keep old nommaped till unregister */ - if (!sep->se_rpc) - sep->se_nomapped = new->se_nomapped; - sep->se_reset = 1; - } - /* copy over outstanding child pids */ - if (sep->se_maxchild > 0 && new->se_maxchild > 0) { - new->se_numchild = sep->se_numchild; - if (new->se_numchild > new->se_maxchild) - new->se_numchild = new->se_maxchild; - memcpy(new->se_pids, sep->se_pids, - new->se_numchild * sizeof(*new->se_pids)); - } - SWAP(pid_t *, sep->se_pids, new->se_pids); - sep->se_maxchild = new->se_maxchild; - sep->se_numchild = new->se_numchild; - sep->se_maxcpm = new->se_maxcpm; - resize_conn(sep, new->se_maxperip); - sep->se_maxperip = new->se_maxperip; - sep->se_bi = new->se_bi; - /* might need to turn on or off service now */ - if (sep->se_fd >= 0) { - if (sep->se_maxchild > 0 - && sep->se_numchild == sep->se_maxchild) { - if (FD_ISSET(sep->se_fd, &allsock)) - disable(sep); - } else { - if (!FD_ISSET(sep->se_fd, &allsock)) - enable(sep); - } - } - sep->se_accept = new->se_accept; - SWAP(char *, sep->se_user, new->se_user); - SWAP(char *, sep->se_group, new->se_group); -#ifdef LOGIN_CAP - SWAP(char *, sep->se_class, new->se_class); -#endif - SWAP(char *, sep->se_server, new->se_server); - SWAP(char *, sep->se_server_name, new->se_server_name); - for (i = 0; i < MAXARGV; i++) - SWAP(char *, sep->se_argv[i], new->se_argv[i]); -#ifdef IPSEC - SWAP(char *, sep->se_policy, new->se_policy); - ipsecsetup(sep); -#endif - sigsetmask(omask); - freeconfig(new); - if (debug) - print_service("REDO", sep); - } else { - sep = enter(new); - if (debug) - print_service("ADD ", sep); - } - sep->se_checked = 1; - if (ISMUX(sep)) { - sep->se_fd = -1; - continue; - } - switch (sep->se_family) { - case AF_INET: - if (!v4bind_ok) { - sep->se_fd = -1; - continue; - } - break; -#ifdef INET6 - case AF_INET6: - if (!v6bind_ok) { - sep->se_fd = -1; - continue; - } - break; -#endif - } - if (!sep->se_rpc) { - if (sep->se_family != AF_UNIX) { - sp = getservbyname(sep->se_service, sep->se_proto); - if (sp == 0) { - syslog(LOG_ERR, "%s/%s: unknown service", - sep->se_service, sep->se_proto); - sep->se_checked = 0; - continue; - } - } - switch (sep->se_family) { - case AF_INET: - if (sp->s_port != sep->se_ctrladdr4.sin_port) { - sep->se_ctrladdr4.sin_port = - sp->s_port; - sep->se_reset = 1; - } - break; -#ifdef INET6 - case AF_INET6: - if (sp->s_port != - sep->se_ctrladdr6.sin6_port) { - sep->se_ctrladdr6.sin6_port = - sp->s_port; - sep->se_reset = 1; - } - break; -#endif - } - if (sep->se_reset != 0 && sep->se_fd >= 0) - close_sep(sep); - } else { - rpc = getrpcbyname(sep->se_service); - if (rpc == 0) { - syslog(LOG_ERR, "%s/%s unknown RPC service", - sep->se_service, sep->se_proto); - if (sep->se_fd != -1) - (void) close(sep->se_fd); - sep->se_fd = -1; - continue; - } - if (sep->se_reset != 0 || - rpc->r_number != sep->se_rpc_prog) { - if (sep->se_rpc_prog) - unregisterrpc(sep); - sep->se_rpc_prog = rpc->r_number; - if (sep->se_fd != -1) - (void) close(sep->se_fd); - sep->se_fd = -1; - } - sep->se_nomapped = new_nomapped; - } - sep->se_reset = 0; - if (sep->se_fd == -1) - setup(sep); - } - endconfig(); - /* - * Purge anything not looked at above. - */ - omask = sigblock(SIGBLOCK); - sepp = &servtab; - while ((sep = *sepp)) { - if (sep->se_checked) { - sepp = &sep->se_next; - continue; - } - *sepp = sep->se_next; - if (sep->se_fd >= 0) - close_sep(sep); - if (debug) - print_service("FREE", sep); - if (sep->se_rpc && sep->se_rpc_prog > 0) - unregisterrpc(sep); - freeconfig(sep); - free(sep); - } - (void) sigsetmask(omask); -} - -void -unregisterrpc(struct servtab *sep) -{ - u_int i; - struct servtab *sepp; - long omask; - struct netconfig *netid4, *netid6; - - omask = sigblock(SIGBLOCK); - netid4 = sep->se_socktype == SOCK_DGRAM ? udpconf : tcpconf; - netid6 = sep->se_socktype == SOCK_DGRAM ? udp6conf : tcp6conf; - if (sep->se_family == AF_INET) - netid6 = NULL; - else if (sep->se_nomapped) - netid4 = NULL; - /* - * Conflict if same prog and protocol - In that case one should look - * to versions, but it is not interesting: having separate servers for - * different versions does not work well. - * Therefore one do not unregister if there is a conflict. - * There is also transport conflict if destroying INET when INET46 - * exists, or destroying INET46 when INET exists - */ - for (sepp = servtab; sepp; sepp = sepp->se_next) { - if (sepp == sep) - continue; - if (sepp->se_checked == 0 || - !sepp->se_rpc || - strcmp(sep->se_proto, sepp->se_proto) != 0 || - sep->se_rpc_prog != sepp->se_rpc_prog) - continue; - if (sepp->se_family == AF_INET) - netid4 = NULL; - if (sepp->se_family == AF_INET6) { - netid6 = NULL; - if (!sep->se_nomapped) - netid4 = NULL; - } - if (netid4 == NULL && netid6 == NULL) - return; - } - if (debug) - print_service("UNREG", sep); - for (i = sep->se_rpc_lowvers; i <= sep->se_rpc_highvers; i++) { - if (netid4) - rpcb_unset(sep->se_rpc_prog, i, netid4); - if (netid6) - rpcb_unset(sep->se_rpc_prog, i, netid6); - } - if (sep->se_fd != -1) - (void) close(sep->se_fd); - sep->se_fd = -1; - (void) sigsetmask(omask); -} - -void -flag_retry(int signo __unused) -{ - flag_signal('A'); -} - -void -retry(void) -{ - struct servtab *sep; - - timingout = 0; - for (sep = servtab; sep; sep = sep->se_next) - if (sep->se_fd == -1 && !ISMUX(sep)) - setup(sep); -} - -void -setup(struct servtab *sep) -{ - int on = 1; - - if ((sep->se_fd = socket(sep->se_family, sep->se_socktype, 0)) < 0) { - if (debug) - warn("socket failed on %s/%s", - sep->se_service, sep->se_proto); - syslog(LOG_ERR, "%s/%s: socket: %m", - sep->se_service, sep->se_proto); - return; - } - /* Set all listening sockets to close-on-exec. */ - if (fcntl(sep->se_fd, F_SETFD, FD_CLOEXEC) < 0) { - syslog(LOG_ERR, "%s/%s: fcntl (F_SETFD, FD_CLOEXEC): %m", - sep->se_service, sep->se_proto); - close(sep->se_fd); - return; - } -#define turnon(fd, opt) \ -setsockopt(fd, SOL_SOCKET, opt, (char *)&on, sizeof (on)) - if (strcmp(sep->se_proto, "tcp") == 0 && (options & SO_DEBUG) && - turnon(sep->se_fd, SO_DEBUG) < 0) - syslog(LOG_ERR, "setsockopt (SO_DEBUG): %m"); - if (turnon(sep->se_fd, SO_REUSEADDR) < 0) - syslog(LOG_ERR, "setsockopt (SO_REUSEADDR): %m"); -#ifdef SO_PRIVSTATE - if (turnon(sep->se_fd, SO_PRIVSTATE) < 0) - syslog(LOG_ERR, "setsockopt (SO_PRIVSTATE): %m"); -#endif - /* tftpd opens a new connection then needs more infos */ - if ((sep->se_family == AF_INET6) && - (strcmp(sep->se_proto, "udp") == 0) && - (sep->se_accept == 0) && - (setsockopt(sep->se_fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, - (char *)&on, sizeof (on)) < 0)) - syslog(LOG_ERR, "setsockopt (IPV6_RECVPKTINFO): %m"); - if (sep->se_family == AF_INET6) { - int flag = sep->se_nomapped ? 1 : 0; - if (setsockopt(sep->se_fd, IPPROTO_IPV6, IPV6_V6ONLY, - (char *)&flag, sizeof (flag)) < 0) - syslog(LOG_ERR, "setsockopt (IPV6_V6ONLY): %m"); - } -#undef turnon -#ifdef IPV6_FAITH - if (sep->se_type == FAITH_TYPE) { - if (setsockopt(sep->se_fd, IPPROTO_IPV6, IPV6_FAITH, &on, - sizeof(on)) < 0) { - syslog(LOG_ERR, "setsockopt (IPV6_FAITH): %m"); - } - } -#endif -#ifdef IPSEC - ipsecsetup(sep); -#endif - if (sep->se_family == AF_UNIX) { - (void) unlink(sep->se_ctrladdr_un.sun_path); - umask(0777); /* Make socket with conservative permissions */ - } - if (bind(sep->se_fd, (struct sockaddr *)&sep->se_ctrladdr, - sep->se_ctrladdr_size) < 0) { - if (debug) - warn("bind failed on %s/%s", - sep->se_service, sep->se_proto); - syslog(LOG_ERR, "%s/%s: bind: %m", - sep->se_service, sep->se_proto); - (void) close(sep->se_fd); - sep->se_fd = -1; - if (!timingout) { - timingout = 1; - alarm(RETRYTIME); - } - if (sep->se_family == AF_UNIX) - umask(mask); - return; - } - if (sep->se_family == AF_UNIX) { - /* Ick - fch{own,mod} don't work on Unix domain sockets */ - if (chown(sep->se_service, sep->se_sockuid, sep->se_sockgid) < 0) - syslog(LOG_ERR, "chown socket: %m"); - if (chmod(sep->se_service, sep->se_sockmode) < 0) - syslog(LOG_ERR, "chmod socket: %m"); - umask(mask); - } - if (sep->se_rpc) { - u_int i; - socklen_t len = sep->se_ctrladdr_size; - struct netconfig *netid, *netid2 = NULL; - struct sockaddr_in sock; - struct netbuf nbuf, nbuf2; - - if (getsockname(sep->se_fd, - (struct sockaddr*)&sep->se_ctrladdr, &len) < 0){ - syslog(LOG_ERR, "%s/%s: getsockname: %m", - sep->se_service, sep->se_proto); - (void) close(sep->se_fd); - sep->se_fd = -1; - return; - } - nbuf.buf = &sep->se_ctrladdr; - nbuf.len = sep->se_ctrladdr.sa_len; - if (sep->se_family == AF_INET) - netid = sep->se_socktype==SOCK_DGRAM? udpconf:tcpconf; - else { - netid = sep->se_socktype==SOCK_DGRAM? udp6conf:tcp6conf; - if (!sep->se_nomapped) { /* INET and INET6 */ - netid2 = netid==udp6conf? udpconf:tcpconf; - memset(&sock, 0, sizeof sock); /* ADDR_ANY */ - nbuf2.buf = &sock; - nbuf2.len = sock.sin_len = sizeof sock; - sock.sin_family = AF_INET; - sock.sin_port = sep->se_ctrladdr6.sin6_port; - } - } - if (debug) - print_service("REG ", sep); - for (i = sep->se_rpc_lowvers; i <= sep->se_rpc_highvers; i++) { - rpcb_unset(sep->se_rpc_prog, i, netid); - rpcb_set(sep->se_rpc_prog, i, netid, &nbuf); - if (netid2) { - rpcb_unset(sep->se_rpc_prog, i, netid2); - rpcb_set(sep->se_rpc_prog, i, netid2, &nbuf2); - } - } - } - if (sep->se_socktype == SOCK_STREAM) - listen(sep->se_fd, 64); - enable(sep); - if (debug) { - warnx("registered %s on %d", - sep->se_server, sep->se_fd); - } -} - -#ifdef IPSEC -void -ipsecsetup(struct servtab *sep) -{ - char *buf; - char *policy_in = NULL; - char *policy_out = NULL; - int level; - int opt; - - switch (sep->se_family) { - case AF_INET: - level = IPPROTO_IP; - opt = IP_IPSEC_POLICY; - break; -#ifdef INET6 - case AF_INET6: - level = IPPROTO_IPV6; - opt = IPV6_IPSEC_POLICY; - break; -#endif - default: - return; - } - - if (!sep->se_policy || sep->se_policy[0] == '\0') { - static char def_in[] = "in entrust", def_out[] = "out entrust"; - policy_in = def_in; - policy_out = def_out; - } else { - if (!strncmp("in", sep->se_policy, 2)) - policy_in = sep->se_policy; - else if (!strncmp("out", sep->se_policy, 3)) - policy_out = sep->se_policy; - else { - syslog(LOG_ERR, "invalid security policy \"%s\"", - sep->se_policy); - return; - } - } - - if (policy_in != NULL) { - buf = ipsec_set_policy(policy_in, strlen(policy_in)); - if (buf != NULL) { - if (setsockopt(sep->se_fd, level, opt, - buf, ipsec_get_policylen(buf)) < 0 && - debug != 0) - warnx("%s/%s: ipsec initialization failed; %s", - sep->se_service, sep->se_proto, - policy_in); - free(buf); - } else - syslog(LOG_ERR, "invalid security policy \"%s\"", - policy_in); - } - if (policy_out != NULL) { - buf = ipsec_set_policy(policy_out, strlen(policy_out)); - if (buf != NULL) { - if (setsockopt(sep->se_fd, level, opt, - buf, ipsec_get_policylen(buf)) < 0 && - debug != 0) - warnx("%s/%s: ipsec initialization failed; %s", - sep->se_service, sep->se_proto, - policy_out); - free(buf); - } else - syslog(LOG_ERR, "invalid security policy \"%s\"", - policy_out); - } -} -#endif - -/* - * Finish with a service and its socket. - */ -void -close_sep(struct servtab *sep) -{ - if (sep->se_fd >= 0) { - if (FD_ISSET(sep->se_fd, &allsock)) - disable(sep); - (void) close(sep->se_fd); - sep->se_fd = -1; - } - sep->se_count = 0; - sep->se_numchild = 0; /* forget about any existing children */ -} - -int -matchservent(const char *name1, const char *name2, const char *proto) -{ - char **alias, *p; - struct servent *se; - - if (strcmp(proto, "unix") == 0) { - if ((p = strrchr(name1, '/')) != NULL) - name1 = p + 1; - if ((p = strrchr(name2, '/')) != NULL) - name2 = p + 1; - } - if (strcmp(name1, name2) == 0) - return(1); - if ((se = getservbyname(name1, proto)) != NULL) { - if (strcmp(name2, se->s_name) == 0) - return(1); - for (alias = se->s_aliases; *alias; alias++) - if (strcmp(name2, *alias) == 0) - return(1); - } - return(0); -} - -struct servtab * -enter(struct servtab *cp) -{ - struct servtab *sep; - long omask; - - sep = (struct servtab *)malloc(sizeof (*sep)); - if (sep == (struct servtab *)0) { - syslog(LOG_ERR, "malloc: %m"); - exit(EX_OSERR); - } - *sep = *cp; - sep->se_fd = -1; - omask = sigblock(SIGBLOCK); - sep->se_next = servtab; - servtab = sep; - sigsetmask(omask); - return (sep); -} - -void -enable(struct servtab *sep) -{ - if (debug) - warnx( - "enabling %s, fd %d", sep->se_service, sep->se_fd); -#ifdef SANITY_CHECK - if (sep->se_fd < 0) { - syslog(LOG_ERR, - "%s: %s: bad fd", __func__, sep->se_service); - exit(EX_SOFTWARE); - } - if (ISMUX(sep)) { - syslog(LOG_ERR, - "%s: %s: is mux", __func__, sep->se_service); - exit(EX_SOFTWARE); - } - if (FD_ISSET(sep->se_fd, &allsock)) { - syslog(LOG_ERR, - "%s: %s: not off", __func__, sep->se_service); - exit(EX_SOFTWARE); - } - nsock++; -#endif - FD_SET(sep->se_fd, &allsock); - if (sep->se_fd > maxsock) - maxsock = sep->se_fd; -} - -void -disable(struct servtab *sep) -{ - if (debug) - warnx( - "disabling %s, fd %d", sep->se_service, sep->se_fd); -#ifdef SANITY_CHECK - if (sep->se_fd < 0) { - syslog(LOG_ERR, - "%s: %s: bad fd", __func__, sep->se_service); - exit(EX_SOFTWARE); - } - if (ISMUX(sep)) { - syslog(LOG_ERR, - "%s: %s: is mux", __func__, sep->se_service); - exit(EX_SOFTWARE); - } - if (!FD_ISSET(sep->se_fd, &allsock)) { - syslog(LOG_ERR, - "%s: %s: not on", __func__, sep->se_service); - exit(EX_SOFTWARE); - } - if (nsock == 0) { - syslog(LOG_ERR, "%s: nsock=0", __func__); - exit(EX_SOFTWARE); - } - nsock--; -#endif - FD_CLR(sep->se_fd, &allsock); - if (sep->se_fd == maxsock) - maxsock--; -} - -FILE *fconfig = NULL; -struct servtab serv; -char line[LINE_MAX]; - -int -setconfig(void) -{ - - if (fconfig != NULL) { - fseek(fconfig, 0L, SEEK_SET); - return (1); - } - fconfig = fopen(CONFIG, "r"); - return (fconfig != NULL); -} - -void -endconfig(void) -{ - if (fconfig) { - (void) fclose(fconfig); - fconfig = NULL; - } -} - -struct servtab * -getconfigent(void) -{ - struct servtab *sep = &serv; - int argc; - char *cp, *arg, *s; - char *versp; - static char TCPMUX_TOKEN[] = "tcpmux/"; -#define MUX_LEN (sizeof(TCPMUX_TOKEN)-1) -#ifdef IPSEC - char *policy; -#endif - int v4bind; -#ifdef INET6 - int v6bind; -#endif - int i; - -#ifdef IPSEC - policy = NULL; -#endif -more: - v4bind = 0; -#ifdef INET6 - v6bind = 0; -#endif - while ((cp = nextline(fconfig)) != NULL) { -#ifdef IPSEC - /* lines starting with #@ is not a comment, but the policy */ - if (cp[0] == '#' && cp[1] == '@') { - char *p; - for (p = cp + 2; p && *p && isspace(*p); p++) - ; - if (*p == '\0') { - if (policy) - free(policy); - policy = NULL; - } else if (ipsec_get_policylen(p) >= 0) { - if (policy) - free(policy); - policy = newstr(p); - } else { - syslog(LOG_ERR, - "%s: invalid ipsec policy \"%s\"", - CONFIG, p); - exit(EX_CONFIG); - } - } -#endif - if (*cp == '#' || *cp == '\0') - continue; - break; - } - if (cp == NULL) - return ((struct servtab *)0); - /* - * clear the static buffer, since some fields (se_ctrladdr, - * for example) don't get initialized here. - */ - memset(sep, 0, sizeof *sep); - arg = skip(&cp); - if (cp == NULL) { - /* got an empty line containing just blanks/tabs. */ - goto more; - } - if (arg[0] == ':') { /* :user:group:perm: */ - char *user, *group, *perm; - struct passwd *pw; - struct group *gr; - user = arg+1; - if ((group = strchr(user, ':')) == NULL) { - syslog(LOG_ERR, "no group after user '%s'", user); - goto more; - } - *group++ = '\0'; - if ((perm = strchr(group, ':')) == NULL) { - syslog(LOG_ERR, "no mode after group '%s'", group); - goto more; - } - *perm++ = '\0'; - if ((pw = getpwnam(user)) == NULL) { - syslog(LOG_ERR, "no such user '%s'", user); - goto more; - } - sep->se_sockuid = pw->pw_uid; - if ((gr = getgrnam(group)) == NULL) { - syslog(LOG_ERR, "no such user '%s'", group); - goto more; - } - sep->se_sockgid = gr->gr_gid; - sep->se_sockmode = strtol(perm, &arg, 8); - if (*arg != ':') { - syslog(LOG_ERR, "bad mode '%s'", perm); - goto more; - } - *arg++ = '\0'; - } else { - sep->se_sockuid = euid; - sep->se_sockgid = egid; - sep->se_sockmode = 0200; - } - if (strncmp(arg, TCPMUX_TOKEN, MUX_LEN) == 0) { - char *c = arg + MUX_LEN; - if (*c == '+') { - sep->se_type = MUXPLUS_TYPE; - c++; - } else - sep->se_type = MUX_TYPE; - sep->se_service = newstr(c); - } else { - sep->se_service = newstr(arg); - sep->se_type = NORM_TYPE; - } - arg = sskip(&cp); - if (strcmp(arg, "stream") == 0) - sep->se_socktype = SOCK_STREAM; - else if (strcmp(arg, "dgram") == 0) - sep->se_socktype = SOCK_DGRAM; - else if (strcmp(arg, "rdm") == 0) - sep->se_socktype = SOCK_RDM; - else if (strcmp(arg, "seqpacket") == 0) - sep->se_socktype = SOCK_SEQPACKET; - else if (strcmp(arg, "raw") == 0) - sep->se_socktype = SOCK_RAW; - else - sep->se_socktype = -1; - - arg = sskip(&cp); - if (strncmp(arg, "tcp", 3) == 0) { - sep->se_proto = newstr(strsep(&arg, "/")); - if (arg != NULL) { - if (strcmp(arg, "faith") == 0) - sep->se_type = FAITH_TYPE; - } - } else { - if (sep->se_type == NORM_TYPE && - strncmp(arg, "faith/", 6) == 0) { - arg += 6; - sep->se_type = FAITH_TYPE; - } - sep->se_proto = newstr(arg); - } - if (strncmp(sep->se_proto, "rpc/", 4) == 0) { - memmove(sep->se_proto, sep->se_proto + 4, - strlen(sep->se_proto) + 1 - 4); - sep->se_rpc = 1; - sep->se_rpc_prog = sep->se_rpc_lowvers = - sep->se_rpc_lowvers = 0; - memcpy(&sep->se_ctrladdr4, bind_sa4, - sizeof(sep->se_ctrladdr4)); - if ((versp = rindex(sep->se_service, '/'))) { - *versp++ = '\0'; - switch (sscanf(versp, "%u-%u", - &sep->se_rpc_lowvers, - &sep->se_rpc_highvers)) { - case 2: - break; - case 1: - sep->se_rpc_highvers = - sep->se_rpc_lowvers; - break; - default: - syslog(LOG_ERR, - "bad RPC version specifier; %s", - sep->se_service); - freeconfig(sep); - goto more; - } - } - else { - sep->se_rpc_lowvers = - sep->se_rpc_highvers = 1; - } - } - sep->se_nomapped = 0; - if (strcmp(sep->se_proto, "unix") == 0) { - sep->se_family = AF_UNIX; - } else { - while (isdigit(sep->se_proto[strlen(sep->se_proto) - 1])) { -#ifdef INET6 - if (sep->se_proto[strlen(sep->se_proto) - 1] == '6') { - sep->se_proto[strlen(sep->se_proto) - 1] = '\0'; - v6bind = 1; - continue; - } -#endif - if (sep->se_proto[strlen(sep->se_proto) - 1] == '4') { - sep->se_proto[strlen(sep->se_proto) - 1] = '\0'; - v4bind = 1; - continue; - } - /* illegal version num */ - syslog(LOG_ERR, "bad IP version for %s", sep->se_proto); - freeconfig(sep); - goto more; - } -#ifdef INET6 - if (v6bind && !v6bind_ok) { - syslog(LOG_INFO, "IPv6 bind is ignored for %s", - sep->se_service); - if (v4bind && v4bind_ok) - v6bind = 0; - else { - freeconfig(sep); - goto more; - } - } - if (v6bind) { - sep->se_family = AF_INET6; - if (!v4bind || !v4bind_ok) - sep->se_nomapped = 1; - } else -#endif - { /* default to v4 bind if not v6 bind */ - if (!v4bind_ok) { - syslog(LOG_NOTICE, "IPv4 bind is ignored for %s", - sep->se_service); - freeconfig(sep); - goto more; - } - sep->se_family = AF_INET; - } - } - /* init ctladdr */ - switch(sep->se_family) { - case AF_INET: - memcpy(&sep->se_ctrladdr4, bind_sa4, - sizeof(sep->se_ctrladdr4)); - sep->se_ctrladdr_size = sizeof(sep->se_ctrladdr4); - break; -#ifdef INET6 - case AF_INET6: - memcpy(&sep->se_ctrladdr6, bind_sa6, - sizeof(sep->se_ctrladdr6)); - sep->se_ctrladdr_size = sizeof(sep->se_ctrladdr6); - break; -#endif - case AF_UNIX: - if (strlen(sep->se_service) >= sizeof(sep->se_ctrladdr_un.sun_path)) { - syslog(LOG_ERR, - "domain socket pathname too long for service %s", - sep->se_service); - goto more; - } - memset(&sep->se_ctrladdr, 0, sizeof(sep->se_ctrladdr)); - sep->se_ctrladdr_un.sun_family = sep->se_family; - sep->se_ctrladdr_un.sun_len = strlen(sep->se_service); - strcpy(sep->se_ctrladdr_un.sun_path, sep->se_service); - sep->se_ctrladdr_size = SUN_LEN(&sep->se_ctrladdr_un); - } - arg = sskip(&cp); - if (!strncmp(arg, "wait", 4)) - sep->se_accept = 0; - else if (!strncmp(arg, "nowait", 6)) - sep->se_accept = 1; - else { - syslog(LOG_ERR, - "%s: bad wait/nowait for service %s", - CONFIG, sep->se_service); - goto more; - } - sep->se_maxchild = -1; - sep->se_maxcpm = -1; - sep->se_maxperip = -1; - if ((s = strchr(arg, '/')) != NULL) { - char *eptr; - u_long val; - - val = strtoul(s + 1, &eptr, 10); - if (eptr == s + 1 || val > MAX_MAXCHLD) { - syslog(LOG_ERR, - "%s: bad max-child for service %s", - CONFIG, sep->se_service); - goto more; - } - if (debug) - if (!sep->se_accept && val != 1) - warnx("maxchild=%lu for wait service %s" - " not recommended", val, sep->se_service); - sep->se_maxchild = val; - if (*eptr == '/') - sep->se_maxcpm = strtol(eptr + 1, &eptr, 10); - if (*eptr == '/') - sep->se_maxperip = strtol(eptr + 1, &eptr, 10); - /* - * explicitly do not check for \0 for future expansion / - * backwards compatibility - */ - } - if (ISMUX(sep)) { - /* - * Silently enforce "nowait" mode for TCPMUX services - * since they don't have an assigned port to listen on. - */ - sep->se_accept = 1; - if (strcmp(sep->se_proto, "tcp")) { - syslog(LOG_ERR, - "%s: bad protocol for tcpmux service %s", - CONFIG, sep->se_service); - goto more; - } - if (sep->se_socktype != SOCK_STREAM) { - syslog(LOG_ERR, - "%s: bad socket type for tcpmux service %s", - CONFIG, sep->se_service); - goto more; - } - } - sep->se_user = newstr(sskip(&cp)); -#ifdef LOGIN_CAP - if ((s = strrchr(sep->se_user, '/')) != NULL) { - *s = '\0'; - sep->se_class = newstr(s + 1); - } else - sep->se_class = newstr(RESOURCE_RC); -#endif - if ((s = strrchr(sep->se_user, ':')) != NULL) { - *s = '\0'; - sep->se_group = newstr(s + 1); - } else - sep->se_group = NULL; - sep->se_server = newstr(sskip(&cp)); - if ((sep->se_server_name = rindex(sep->se_server, '/'))) - sep->se_server_name++; - if (strcmp(sep->se_server, "internal") == 0) { - struct biltin *bi; - - for (bi = biltins; bi->bi_service; bi++) - if (bi->bi_socktype == sep->se_socktype && - matchservent(bi->bi_service, sep->se_service, - sep->se_proto)) - break; - if (bi->bi_service == 0) { - syslog(LOG_ERR, "internal service %s unknown", - sep->se_service); - goto more; - } - sep->se_accept = 1; /* force accept mode for built-ins */ - sep->se_bi = bi; - } else - sep->se_bi = NULL; - if (sep->se_maxperip < 0) - sep->se_maxperip = maxperip; - if (sep->se_maxcpm < 0) - sep->se_maxcpm = maxcpm; - if (sep->se_maxchild < 0) { /* apply default max-children */ - if (sep->se_bi && sep->se_bi->bi_maxchild >= 0) - sep->se_maxchild = sep->se_bi->bi_maxchild; - else if (sep->se_accept) - sep->se_maxchild = maxchild > 0 ? maxchild : 0; - else - sep->se_maxchild = 1; - } - if (sep->se_maxchild > 0) { - sep->se_pids = malloc(sep->se_maxchild * sizeof(*sep->se_pids)); - if (sep->se_pids == NULL) { - syslog(LOG_ERR, "malloc: %m"); - exit(EX_OSERR); - } - } - argc = 0; - for (arg = skip(&cp); cp; arg = skip(&cp)) - if (argc < MAXARGV) { - sep->se_argv[argc++] = newstr(arg); - } else { - syslog(LOG_ERR, - "%s: too many arguments for service %s", - CONFIG, sep->se_service); - goto more; - } - while (argc <= MAXARGV) - sep->se_argv[argc++] = NULL; - for (i = 0; i < PERIPSIZE; ++i) - LIST_INIT(&sep->se_conn[i]); -#ifdef IPSEC - sep->se_policy = policy ? newstr(policy) : NULL; -#endif - return (sep); -} - -void -freeconfig(struct servtab *cp) -{ - int i; - - if (cp->se_service) - free(cp->se_service); - if (cp->se_proto) - free(cp->se_proto); - if (cp->se_user) - free(cp->se_user); - if (cp->se_group) - free(cp->se_group); -#ifdef LOGIN_CAP - if (cp->se_class) - free(cp->se_class); -#endif - if (cp->se_server) - free(cp->se_server); - if (cp->se_pids) - free(cp->se_pids); - for (i = 0; i < MAXARGV; i++) - if (cp->se_argv[i]) - free(cp->se_argv[i]); - free_connlist(cp); -#ifdef IPSEC - if (cp->se_policy) - free(cp->se_policy); -#endif -} - - -/* - * Safe skip - if skip returns null, log a syntax error in the - * configuration file and exit. - */ -char * -sskip(char **cpp) -{ - char *cp; - - cp = skip(cpp); - if (cp == NULL) { - syslog(LOG_ERR, "%s: syntax error", CONFIG); - exit(EX_DATAERR); - } - return (cp); -} - -char * -skip(char **cpp) -{ - char *cp = *cpp; - char *start; - char quote = '\0'; - -again: - while (*cp == ' ' || *cp == '\t') - cp++; - if (*cp == '\0') { - int c; - - c = getc(fconfig); - (void) ungetc(c, fconfig); - if (c == ' ' || c == '\t') - if ((cp = nextline(fconfig))) - goto again; - *cpp = (char *)0; - return ((char *)0); - } - if (*cp == '"' || *cp == '\'') - quote = *cp++; - start = cp; - if (quote) - while (*cp && *cp != quote) - cp++; - else - while (*cp && *cp != ' ' && *cp != '\t') - cp++; - if (*cp != '\0') - *cp++ = '\0'; - *cpp = cp; - return (start); -} - -char * -nextline(FILE *fd) -{ - char *cp; - - if (fgets(line, sizeof (line), fd) == NULL) - return ((char *)0); - cp = strchr(line, '\n'); - if (cp) - *cp = '\0'; - return (line); -} - -char * -newstr(const char *cp) -{ - char *cr; - - if ((cr = strdup(cp != NULL ? cp : ""))) - return (cr); - syslog(LOG_ERR, "strdup: %m"); - exit(EX_OSERR); -} - -void -inetd_setproctitle(const char *a, int s) -{ - socklen_t size; - struct sockaddr_storage ss; - char buf[80], pbuf[INET6_ADDRSTRLEN]; - - size = sizeof(ss); - if (getpeername(s, (struct sockaddr *)&ss, &size) == 0) { - getnameinfo((struct sockaddr *)&ss, size, pbuf, sizeof(pbuf), - NULL, 0, NI_NUMERICHOST); - (void) sprintf(buf, "%s [%s]", a, pbuf); - } else - (void) sprintf(buf, "%s", a); - setproctitle("%s", buf); -} - -int -check_loop(const struct sockaddr *sa, const struct servtab *sep) -{ - struct servtab *se2; - char pname[INET6_ADDRSTRLEN]; - - for (se2 = servtab; se2; se2 = se2->se_next) { - if (!se2->se_bi || se2->se_socktype != SOCK_DGRAM) - continue; - - switch (se2->se_family) { - case AF_INET: - if (((const struct sockaddr_in *)sa)->sin_port == - se2->se_ctrladdr4.sin_port) - goto isloop; - continue; -#ifdef INET6 - case AF_INET6: - if (((const struct sockaddr_in *)sa)->sin_port == - se2->se_ctrladdr4.sin_port) - goto isloop; - continue; -#endif - default: - continue; - } - isloop: - getnameinfo(sa, sa->sa_len, pname, sizeof(pname), NULL, 0, - NI_NUMERICHOST); - syslog(LOG_WARNING, "%s/%s:%s/%s loop request REFUSED from %s", - sep->se_service, sep->se_proto, - se2->se_service, se2->se_proto, - pname); - return 1; - } - return 0; -} - -/* - * print_service: - * Dump relevant information to stderr - */ -void -print_service(const char *action, const struct servtab *sep) -{ - fprintf(stderr, - "%s: %s proto=%s accept=%d max=%d user=%s group=%s" -#ifdef LOGIN_CAP - "class=%s" -#endif - " builtin=%p server=%s" -#ifdef IPSEC - " policy=\"%s\"" -#endif - "\n", - action, sep->se_service, sep->se_proto, - sep->se_accept, sep->se_maxchild, sep->se_user, sep->se_group, -#ifdef LOGIN_CAP - sep->se_class, -#endif - (void *) sep->se_bi, sep->se_server -#ifdef IPSEC - , (sep->se_policy ? sep->se_policy : "") -#endif - ); -} - -#define CPMHSIZE 256 -#define CPMHMASK (CPMHSIZE-1) -#define CHTGRAN 10 -#define CHTSIZE 6 - -typedef struct CTime { - unsigned long ct_Ticks; - int ct_Count; -} CTime; - -typedef struct CHash { - union { - struct in_addr c4_Addr; - struct in6_addr c6_Addr; - } cu_Addr; -#define ch_Addr4 cu_Addr.c4_Addr -#define ch_Addr6 cu_Addr.c6_Addr - int ch_Family; - time_t ch_LTime; - char *ch_Service; - CTime ch_Times[CHTSIZE]; -} CHash; - -CHash CHashAry[CPMHSIZE]; - -int -cpmip(const struct servtab *sep, int ctrl) -{ - struct sockaddr_storage rss; - socklen_t rssLen = sizeof(rss); - int r = 0; - - /* - * If getpeername() fails, just let it through (if logging is - * enabled the condition is caught elsewhere) - */ - - if (sep->se_maxcpm > 0 && - (sep->se_family == AF_INET || sep->se_family == AF_INET6) && - getpeername(ctrl, (struct sockaddr *)&rss, &rssLen) == 0 ) { - time_t t = time(NULL); - int hv = 0xABC3D20F; - int i; - int cnt = 0; - CHash *chBest = NULL; - unsigned int ticks = t / CHTGRAN; - struct sockaddr_in *sin4; -#ifdef INET6 - struct sockaddr_in6 *sin6; -#endif - - sin4 = (struct sockaddr_in *)&rss; -#ifdef INET6 - sin6 = (struct sockaddr_in6 *)&rss; -#endif - { - char *p; - int addrlen; - - switch (rss.ss_family) { - case AF_INET: - p = (char *)&sin4->sin_addr; - addrlen = sizeof(struct in_addr); - break; -#ifdef INET6 - case AF_INET6: - p = (char *)&sin6->sin6_addr; - addrlen = sizeof(struct in6_addr); - break; -#endif - default: - /* should not happen */ - return -1; - } - - for (i = 0; i < addrlen; ++i, ++p) { - hv = (hv << 5) ^ (hv >> 23) ^ *p; - } - hv = (hv ^ (hv >> 16)); - } - for (i = 0; i < 5; ++i) { - CHash *ch = &CHashAry[(hv + i) & CPMHMASK]; - - if (rss.ss_family == AF_INET && - ch->ch_Family == AF_INET && - sin4->sin_addr.s_addr == ch->ch_Addr4.s_addr && - ch->ch_Service && strcmp(sep->se_service, - ch->ch_Service) == 0) { - chBest = ch; - break; - } -#ifdef INET6 - if (rss.ss_family == AF_INET6 && - ch->ch_Family == AF_INET6 && - IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, - &ch->ch_Addr6) != 0 && - ch->ch_Service && strcmp(sep->se_service, - ch->ch_Service) == 0) { - chBest = ch; - break; - } -#endif - if (chBest == NULL || ch->ch_LTime == 0 || - ch->ch_LTime < chBest->ch_LTime) { - chBest = ch; - } - } - if ((rss.ss_family == AF_INET && - (chBest->ch_Family != AF_INET || - sin4->sin_addr.s_addr != chBest->ch_Addr4.s_addr)) || - chBest->ch_Service == NULL || - strcmp(sep->se_service, chBest->ch_Service) != 0) { - chBest->ch_Family = sin4->sin_family; - chBest->ch_Addr4 = sin4->sin_addr; - if (chBest->ch_Service) - free(chBest->ch_Service); - chBest->ch_Service = strdup(sep->se_service); - bzero(chBest->ch_Times, sizeof(chBest->ch_Times)); - } -#ifdef INET6 - if ((rss.ss_family == AF_INET6 && - (chBest->ch_Family != AF_INET6 || - IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, - &chBest->ch_Addr6) == 0)) || - chBest->ch_Service == NULL || - strcmp(sep->se_service, chBest->ch_Service) != 0) { - chBest->ch_Family = sin6->sin6_family; - chBest->ch_Addr6 = sin6->sin6_addr; - if (chBest->ch_Service) - free(chBest->ch_Service); - chBest->ch_Service = strdup(sep->se_service); - bzero(chBest->ch_Times, sizeof(chBest->ch_Times)); - } -#endif - chBest->ch_LTime = t; - { - CTime *ct = &chBest->ch_Times[ticks % CHTSIZE]; - if (ct->ct_Ticks != ticks) { - ct->ct_Ticks = ticks; - ct->ct_Count = 0; - } - ++ct->ct_Count; - } - for (i = 0; i < CHTSIZE; ++i) { - CTime *ct = &chBest->ch_Times[i]; - if (ct->ct_Ticks <= ticks && - ct->ct_Ticks >= ticks - CHTSIZE) { - cnt += ct->ct_Count; - } - } - if ((cnt * 60) / (CHTSIZE * CHTGRAN) > sep->se_maxcpm) { - char pname[INET6_ADDRSTRLEN]; - - getnameinfo((struct sockaddr *)&rss, - ((struct sockaddr *)&rss)->sa_len, - pname, sizeof(pname), NULL, 0, - NI_NUMERICHOST); - r = -1; - syslog(LOG_ERR, - "%s from %s exceeded counts/min (limit %d/min)", - sep->se_service, pname, - sep->se_maxcpm); - } - } - return(r); -} - -static struct conninfo * -search_conn(struct servtab *sep, int ctrl) -{ - struct sockaddr_storage ss; - socklen_t sslen = sizeof(ss); - struct conninfo *conn; - int hv; - char pname[NI_MAXHOST], pname2[NI_MAXHOST]; - - if (sep->se_maxperip <= 0) - return NULL; - - /* - * If getpeername() fails, just let it through (if logging is - * enabled the condition is caught elsewhere) - */ - if (getpeername(ctrl, (struct sockaddr *)&ss, &sslen) != 0) - return NULL; - - switch (ss.ss_family) { - case AF_INET: - hv = hashval((char *)&((struct sockaddr_in *)&ss)->sin_addr, - sizeof(struct in_addr)); - break; -#ifdef INET6 - case AF_INET6: - hv = hashval((char *)&((struct sockaddr_in6 *)&ss)->sin6_addr, - sizeof(struct in6_addr)); - break; -#endif - default: - /* - * Since we only support AF_INET and AF_INET6, just - * let other than AF_INET and AF_INET6 through. - */ - return NULL; - } - - if (getnameinfo((struct sockaddr *)&ss, sslen, pname, sizeof(pname), - NULL, 0, NI_NUMERICHOST) != 0) - return NULL; - - LIST_FOREACH(conn, &sep->se_conn[hv], co_link) { - if (getnameinfo((struct sockaddr *)&conn->co_addr, - conn->co_addr.ss_len, pname2, sizeof(pname2), NULL, 0, - NI_NUMERICHOST) == 0 && - strcmp(pname, pname2) == 0) - break; - } - - if (conn == NULL) { - if ((conn = malloc(sizeof(struct conninfo))) == NULL) { - syslog(LOG_ERR, "malloc: %m"); - exit(EX_OSERR); - } - conn->co_proc = malloc(sep->se_maxperip * sizeof(*conn->co_proc)); - if (conn->co_proc == NULL) { - syslog(LOG_ERR, "malloc: %m"); - exit(EX_OSERR); - } - memcpy(&conn->co_addr, (struct sockaddr *)&ss, sslen); - conn->co_numchild = 0; - LIST_INSERT_HEAD(&sep->se_conn[hv], conn, co_link); - } - - /* - * Since a child process is not invoked yet, we cannot - * determine a pid of a child. So, co_proc and co_numchild - * should be filled leter. - */ - - return conn; -} - -static int -room_conn(struct servtab *sep, struct conninfo *conn) -{ - char pname[NI_MAXHOST]; - - if (conn->co_numchild >= sep->se_maxperip) { - getnameinfo((struct sockaddr *)&conn->co_addr, - conn->co_addr.ss_len, pname, sizeof(pname), NULL, 0, - NI_NUMERICHOST); - syslog(LOG_ERR, "%s from %s exceeded counts (limit %d)", - sep->se_service, pname, sep->se_maxperip); - return 0; - } - return 1; -} - -static void -addchild_conn(struct conninfo *conn, pid_t pid) -{ - struct procinfo *proc; - - if (conn == NULL) - return; - - if ((proc = search_proc(pid, 1)) != NULL) { - if (proc->pr_conn != NULL) { - syslog(LOG_ERR, - "addchild_conn: child already on process list"); - exit(EX_OSERR); - } - proc->pr_conn = conn; - } - - conn->co_proc[conn->co_numchild++] = proc; -} - -static void -reapchild_conn(pid_t pid) -{ - struct procinfo *proc; - struct conninfo *conn; - int i; - - if ((proc = search_proc(pid, 0)) == NULL) - return; - if ((conn = proc->pr_conn) == NULL) - return; - for (i = 0; i < conn->co_numchild; ++i) - if (conn->co_proc[i] == proc) { - conn->co_proc[i] = conn->co_proc[--conn->co_numchild]; - break; - } - free_proc(proc); - free_conn(conn); -} - -static void -resize_conn(struct servtab *sep, int maxpip) -{ - struct conninfo *conn; - int i, j; - - if (sep->se_maxperip <= 0) - return; - if (maxpip <= 0) { - free_connlist(sep); - return; - } - for (i = 0; i < PERIPSIZE; ++i) { - LIST_FOREACH(conn, &sep->se_conn[i], co_link) { - for (j = maxpip; j < conn->co_numchild; ++j) - free_proc(conn->co_proc[j]); - conn->co_proc = realloc(conn->co_proc, - maxpip * sizeof(*conn->co_proc)); - if (conn->co_proc == NULL) { - syslog(LOG_ERR, "realloc: %m"); - exit(EX_OSERR); - } - if (conn->co_numchild > maxpip) - conn->co_numchild = maxpip; - } - } -} - -static void -free_connlist(struct servtab *sep) -{ - struct conninfo *conn; - int i, j; - - for (i = 0; i < PERIPSIZE; ++i) { - while ((conn = LIST_FIRST(&sep->se_conn[i])) != NULL) { - for (j = 0; j < conn->co_numchild; ++j) - free_proc(conn->co_proc[j]); - conn->co_numchild = 0; - free_conn(conn); - } - } -} - -static void -free_conn(struct conninfo *conn) -{ - if (conn == NULL) - return; - if (conn->co_numchild <= 0) { - LIST_REMOVE(conn, co_link); - free(conn->co_proc); - free(conn); - } -} - -static struct procinfo * -search_proc(pid_t pid, int add) -{ - struct procinfo *proc; - int hv; - - hv = hashval((char *)&pid, sizeof(pid)); - LIST_FOREACH(proc, &proctable[hv], pr_link) { - if (proc->pr_pid == pid) - break; - } - if (proc == NULL && add) { - if ((proc = malloc(sizeof(struct procinfo))) == NULL) { - syslog(LOG_ERR, "malloc: %m"); - exit(EX_OSERR); - } - proc->pr_pid = pid; - proc->pr_conn = NULL; - LIST_INSERT_HEAD(&proctable[hv], proc, pr_link); - } - return proc; -} - -static void -free_proc(struct procinfo *proc) -{ - if (proc == NULL) - return; - LIST_REMOVE(proc, pr_link); - free(proc); -} - -static int -hashval(char *p, int len) -{ - int i, hv = 0xABC3D20F; - - for (i = 0; i < len; ++i, ++p) - hv = (hv << 5) ^ (hv >> 23) ^ *p; - hv = (hv ^ (hv >> 16)) & (PERIPSIZE - 1); - return hv; -} diff --git a/usr.sbin/inetd/inetd.h b/usr.sbin/inetd/inetd.h deleted file mode 100644 index e0a83bd..0000000 --- a/usr.sbin/inetd/inetd.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 1983, 1991, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include - -#include - -#include - -#define BUFSIZE 8192 -#define LINESIZ 72 - -#define NORM_TYPE 0 -#define MUX_TYPE 1 -#define MUXPLUS_TYPE 2 -#define FAITH_TYPE 4 -#define ISMUX(sep) (((sep)->se_type == MUX_TYPE) || \ - ((sep)->se_type == MUXPLUS_TYPE)) -#define ISMUXPLUS(sep) ((sep)->se_type == MUXPLUS_TYPE) - -struct procinfo { - LIST_ENTRY(procinfo) pr_link; - pid_t pr_pid; /* child pid */ - struct conninfo *pr_conn; -}; - -struct conninfo { - LIST_ENTRY(conninfo) co_link; - struct sockaddr_storage co_addr; /* source address */ - int co_numchild; /* current number of children */ - struct procinfo **co_proc; /* array of child proc entry */ -}; - -#define PERIPSIZE 256 - -struct servtab { - char *se_service; /* name of service */ - int se_socktype; /* type of socket to use */ - int se_family; /* address family */ - char *se_proto; /* protocol used */ - int se_maxchild; /* max number of children */ - int se_maxcpm; /* max connects per IP per minute */ - int se_numchild; /* current number of children */ - pid_t *se_pids; /* array of child pids */ - char *se_user; /* user name to run as */ - char *se_group; /* group name to run as */ -#ifdef LOGIN_CAP - char *se_class; /* login class name to run with */ -#endif - struct biltin *se_bi; /* if built-in, description */ - char *se_server; /* server program */ - char *se_server_name; /* server program without path */ -#define MAXARGV 20 - char *se_argv[MAXARGV+1]; /* program arguments */ -#ifdef IPSEC - char *se_policy; /* IPsec policy string */ -#endif - int se_fd; /* open descriptor */ - union { /* bound address */ - struct sockaddr se_un_ctrladdr; - struct sockaddr_in se_un_ctrladdr4; - struct sockaddr_in6 se_un_ctrladdr6; - struct sockaddr_un se_un_ctrladdr_un; - } se_un; -#define se_ctrladdr se_un.se_un_ctrladdr -#define se_ctrladdr4 se_un.se_un_ctrladdr4 -#define se_ctrladdr6 se_un.se_un_ctrladdr6 -#define se_ctrladdr_un se_un.se_un_ctrladdr_un - socklen_t se_ctrladdr_size; - uid_t se_sockuid; /* Owner for unix domain socket */ - gid_t se_sockgid; /* Group for unix domain socket */ - mode_t se_sockmode; /* Mode for unix domain socket */ - u_char se_type; /* type: normal, mux, or mux+ */ - u_char se_checked; /* looked at during merge */ - u_char se_accept; /* i.e., wait/nowait mode */ - u_char se_rpc; /* ==1 if RPC service */ - int se_rpc_prog; /* RPC program number */ - u_int se_rpc_lowvers; /* RPC low version */ - u_int se_rpc_highvers; /* RPC high version */ - int se_count; /* number started since se_time */ - struct timeval se_time; /* start of se_count */ - struct servtab *se_next; - struct se_flags { - u_int se_nomapped : 1; - u_int se_reset : 1; - } se_flags; - int se_maxperip; /* max number of children per src */ - LIST_HEAD(, conninfo) se_conn[PERIPSIZE]; -}; - -#define se_nomapped se_flags.se_nomapped -#define se_reset se_flags.se_reset - -int check_loop(const struct sockaddr *, const struct servtab *sep); -int getvalue(const char *, int *, const char *); -char *newstr(const char *); -void inetd_setproctitle(const char *, int); -void print_service(const char *, const struct servtab *); -char *sskip(char **); -char *skip(char **); -struct servtab *tcpmux(int); - -extern int debug; -extern struct servtab *servtab; - -typedef void (bi_fn_t)(int, struct servtab *); - -struct biltin { - const char *bi_service; /* internally provided service name */ - int bi_socktype; /* type of socket supported */ - short bi_fork; /* 1 if should fork before call */ - int bi_maxchild; /* max number of children, -1=default */ - bi_fn_t *bi_fn; /* function which performs it */ -}; diff --git a/usr.sbin/inetd/pathnames.h b/usr.sbin/inetd/pathnames.h deleted file mode 100644 index d4fd81d..0000000 --- a/usr.sbin/inetd/pathnames.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 - * $FreeBSD$ - */ - -#include - -#define _PATH_INETDCONF "/etc/inetd.conf" -#define _PATH_INETDPID _PATH_VARRUN "inetd.pid" diff --git a/usr.sbin/iostat/Makefile b/usr.sbin/iostat/Makefile deleted file mode 100644 index 9fd4809..0000000 --- a/usr.sbin/iostat/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -PROG= iostat -MAN= iostat.8 - -DPADD= ${LIBDEVSTAT} ${LIBKVM} ${LIBM} -LDADD= -ldevstat -lkvm -lm - -WARNS?= 1 - -.include diff --git a/usr.sbin/iostat/iostat.8 b/usr.sbin/iostat/iostat.8 deleted file mode 100644 index 6a9ef02..0000000 --- a/usr.sbin/iostat/iostat.8 +++ /dev/null @@ -1,479 +0,0 @@ -.\" -.\" Copyright (c) 1997 Kenneth D. Merry. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.\" Copyright (c) 1985, 1991, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)iostat.8 8.1 (Berkeley) 6/6/93 -.\" -.Dd April 17, 2006 -.Dt IOSTAT 8 -.Os -.Sh NAME -.Nm iostat -.Nd report -.Tn I/O -statistics -.Sh SYNOPSIS -.Nm -.Op Fl CdhIKoTxz?\& -.Op Fl c Ar count -.Op Fl M Ar core -.Op Fl n Ar devs -.Op Fl N Ar system -.Oo -.Fl t -.Sm off -.Ar type , if , pass -.Sm on -.Oc -.Op Fl w Ar wait -.Op Ar drives -.Sh DESCRIPTION -The -.Nm -utility displays kernel -.Tn I/O -statistics on terminal, device and cpu operations. -The first statistics that are printed are averaged over the system uptime. -To get information about the current activity, a suitable wait time should -be specified, so that the subsequent sets of printed statistics will be -averaged over that time. -.Pp -The options are as follows: -.Bl -tag -width flag -.It Fl c -Repeat the display -.Ar count -times. -If no repeat -.Ar count -is specified, the default is infinity. -.It Fl C -Display CPU statistics. -This is on by default, unless -.Fl d -is specified. -.It Fl d -Display only device statistics. -If this flag is turned on, only device statistics will be displayed, unless -.Fl C -or -.Fl T -is also specified to enable the display of CPU or TTY statistics. -.It Fl h -Put -.Nm -in -.Sq top -mode. -In this mode, -.Nm -will show devices in order from highest to lowest bytes -per measurement cycle. -.It Fl I -Display total statistics for a given time period, rather than average -statistics for each second during that time period. -.It Fl K -In the blocks transferred display (-o), display block count in kilobytes rather -then the device native block size. -.It Fl M -Extract values associated with the name list from the specified core -instead of the default -.Dq Pa /dev/kmem . -.It Fl n -Display up to -.Ar devs -number of devices. -The -.Nm -utility will display fewer devices if there are not -.Ar devs -devices present. -.It Fl N -Extract the name list from the specified system instead of the default -.Dq Pa /boot/kernel/kernel . -.It Fl o -Display old-style -.Nm -device statistics. -Sectors per second, transfers per second, and milliseconds per seek are -displayed. -If -.Fl I -is specified, total blocks/sectors, total transfers, and -milliseconds per seek are displayed. -.It Fl t -Specify which types of devices to display. -There are three different categories of devices: -.Pp -.Bl -tag -width indent -compact -.It device type: -.Bl -tag -width 9n -compact -.It da -Direct Access devices -.It sa -Sequential Access devices -.It printer -Printers -.It proc -Processor devices -.It worm -Write Once Read Multiple devices -.It cd -CD devices -.It scanner -Scanner devices -.It optical -Optical Memory devices -.It changer -Medium Changer devices -.It comm -Communication devices -.It array -Storage Array devices -.It enclosure -Enclosure Services devices -.It floppy -Floppy devices -.El -.Pp -.It interface: -.Bl -tag -width 9n -compact -.It IDE -Integrated Drive Electronics devices -.It SCSI -Small Computer System Interface devices -.It other -Any other device interface -.El -.Pp -.It passthrough: -.Bl -tag -width 9n -compact -.It pass -Passthrough devices -.El -.El -.Pp -The user must specify at least one device type, and may specify at most -one device type from each category. -Multiple device types in a single device type statement must be separated by -commas. -.Pp -Any number of -.Fl t -arguments may be specified on the command line. -All -.Fl t -arguments are ORed together to form a matching expression against which -all devices in the system are compared. -Any device that fully matches any -.Fl t -argument will be included in the -.Nm -output, up to the number of devices that can be displayed in -80 columns, or the maximum number of devices specified by the user. -.It Fl T -Display TTY statistics. -This is on by default, unless -.Fl d -is specified. -.It Fl w -Pause -.Ar wait -seconds between each display. -If no -.Ar wait -interval is specified, the default is 1 second. -.Pp -The -.Nm -command will accept and honor a non-integer number of seconds. -Note that the interval only has millisecond granularity. -Finer values will be truncated. -E.g., -.Dq Li -w1.0001 -is the same as -.Dq Li -w1.000 . -The interval will also suffer from modifications to -.Va kern.hz -so your mileage may vary. -.It Fl x -Show extended disk statistics. -Each disk is displayed on a line of its own with all available statistics. -.It Fl z -If -.Fl x -is specified, omit lines for devices with no activity. -.It Fl ?\& -Display a usage statement and exit. -.El -.Pp -The -.Nm -utility displays its information in the following format: -.Bl -tag -width flag -.It tty -.Bl -tag -width indent -compact -.It tin -characters read from terminals -.It tout -characters written to terminals -.El -.It devices -Device operations. -The header of the field is the device name and unit number. -The -.Nm -utility -will display as many devices as will fit in a standard 80 column screen, or -the maximum number of devices in the system, whichever is smaller. -If -.Fl n -is specified on the command line, -.Nm -will display the smaller of the -requested number of devices, and the maximum number of devices in the system. -To force -.Nm -to display specific drives, their names may be supplied on the command -line. -The -.Nm -utility -will not display more devices than will fit in an 80 column screen, unless -the -.Fl n -argument is given on the command line to specify a maximum number of -devices to display. -If fewer devices are specified on the command line than will fit in an 80 -column screen, -.Nm -will show only the specified devices. -.Pp -The standard -.Nm -device display shows the following statistics: -.Pp -.Bl -tag -width indent -compact -.It KB/t -kilobytes per transfer -.It tps -transfers per second -.It MB/s -megabytes per second -.El -.Pp -The standard -.Nm -device display, with the -.Fl I -flag specified, shows the following statistics: -.Pp -.Bl -tag -width indent -compact -.It KB/t -kilobytes per transfer -.It xfrs -total number of transfers -.It MB -total number of megabytes transferred -.El -.Pp -The extended -.Nm -device display, with the -.Fl x -flag specified, shows the following statistics: -.Pp -.Bl -tag -width indent -compact -.It r/s -read operations per second -.It w/s -write operations per second -.It kr/s -kilobytes read per second -.It kw/s -kilobytes write per second -.It wait -transactions queue length -.It svc_t -average duration of transactions, in milliseconds -.It %b -% of time the device had one or more outstanding transactions -.El -.Pp -The old-style -.Nm -display (using -.Fl o ) -shows the following statistics: -.Pp -.Bl -tag -width indent -compact -.It sps -sectors transferred per second -.It tps -transfers per second -.It msps -average milliseconds per transaction -.El -.Pp -The old-style -.Nm -display, with the -.Fl I -flag specified, shows the following statistics: -.Pp -.Bl -tag -width indent -compact -.It blk -total blocks/sectors transferred -.It xfr -total transfers -.It msps -average milliseconds per transaction -.El -.It cpu -.Bl -tag -width indent -compact -.It \&us -% of cpu time in user mode -.It \&ni -% of cpu time in user mode running niced processes -.It \&sy -% of cpu time in system mode -.It \&in -% of cpu time in interrupt mode -.It \&id -% of cpu time in idle mode -.El -.El -.Sh FILES -.Bl -tag -width /boot/kernel/kernel -compact -.It Pa /boot/kernel/kernel -Default kernel namelist. -.It Pa /dev/kmem -Default memory file. -.El -.Sh EXAMPLES -.Dl iostat -w 1 da0 da1 cd0 -.Pp -Display statistics for the first two Direct Access devices and the first -CDROM device every second ad infinitum. -.Pp -.Dl iostat -c 2 -.Pp -Display the statistics for the first four devices in the system twice, with -a one second display interval. -.Pp -.Dl iostat -t da -t cd -w 1 -.Pp -Display statistics for all CDROM and Direct Access devices every second -ad infinitum. -.Pp -.Dl iostat -t da,scsi,pass -t cd,scsi,pass -.Pp -Display statistics once for all SCSI passthrough devices that provide access -to either Direct Access or CDROM devices. -.Pp -.Dl iostat -h -n 8 -w 1 -.Pp -Display up to 8 devices with the most I/O every second ad infinitum. -.Pp -.Dl iostat -dh -t da -w 1 -.Pp -Omit the TTY and CPU displays, show devices in order of performance and -show only Direct Access devices every second ad infinitum. -.Pp -.Dl iostat -Iw 3 -.Pp -Display total statistics every three seconds ad infinitum. -.Pp -.Dl iostat -odICTw 2 -c 9 -.Pp -Display total statistics using the old-style output format 9 times, with -a two second interval between each measurement/display. -The -.Fl d -flag generally disables the TTY and CPU displays, but since the -.Fl T -and -.Fl C -flags are given, the TTY and CPU displays will be displayed. -.Sh SEE ALSO -.Xr fstat 1 , -.Xr netstat 1 , -.Xr nfsstat 1 , -.Xr ps 1 , -.Xr systat 1 , -.Xr devstat 3 , -.Xr gstat 8 , -.Xr pstat 8 , -.Xr vmstat 8 -.Pp -The sections starting with ``Interpreting system activity'' in -.%T "Installing and Operating 4.3BSD" . -.Sh HISTORY -This version of -.Nm -first appeared in -.Fx 3.0 . -.Sh AUTHORS -.An Kenneth Merry Aq ken@FreeBSD.org -.Sh BUGS -The use of -.Nm -as a debugging tool for crash dumps is probably limited because there is -currently no way to get statistics that only cover the time immediately before -the crash. diff --git a/usr.sbin/iostat/iostat.c b/usr.sbin/iostat/iostat.c deleted file mode 100644 index dfa5ebc..0000000 --- a/usr.sbin/iostat/iostat.c +++ /dev/null @@ -1,956 +0,0 @@ -/* - * Copyright (c) 1997, 1998, 2000, 2001 Kenneth D. Merry - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -/* - * Parts of this program are derived from the original FreeBSD iostat - * program: - */ -/*- - * Copyright (c) 1986, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -/* - * Ideas for the new iostat statistics output modes taken from the NetBSD - * version of iostat: - */ -/* - * Copyright (c) 1996 John M. Vinopal - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed for the NetBSD Project - * by John M. Vinopal. - * 4. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct nlist namelist[] = { -#define X_TK_NIN 0 - { "_tk_nin" }, -#define X_TK_NOUT 1 - { "_tk_nout" }, -#define X_BOOTTIME 2 - { "_boottime" }, -#define X_END 2 - { NULL }, -}; - -#define IOSTAT_DEFAULT_ROWS 20 /* Traditional default `wrows' */ - -struct statinfo cur, last; -int num_devices; -struct device_selection *dev_select; -int maxshowdevs; -volatile sig_atomic_t headercount; -volatile sig_atomic_t wresized; /* Tty resized, when non-zero. */ -unsigned short wrows; /* Current number of tty rows. */ -int dflag = 0, Iflag = 0, Cflag = 0, Tflag = 0, oflag = 0, Kflag = 0; -int xflag = 0, zflag = 0; - -/* local function declarations */ -static void usage(void); -static void needhdr(int signo); -static void needresize(int signo); -static void doresize(void); -static void phdr(void); -static void devstats(int perf_select, long double etime, int havelast); -static void cpustats(void); -static int readvar(kvm_t *kd, const char *name, int nlid, void *ptr, - size_t len); - -static void -usage(void) -{ - /* - * We also support the following 'traditional' syntax: - * iostat [drives] [wait [count]] - * This isn't mentioned in the man page, or the usage statement, - * but it is supported. - */ - fprintf(stderr, "usage: iostat [-CdhIKoTxz?] [-c count] [-M core]" - " [-n devs] [-N system]\n" - "\t [-t type,if,pass] [-w wait] [drives]\n"); -} - -int -main(int argc, char **argv) -{ - int c, i; - int tflag = 0, hflag = 0, cflag = 0, wflag = 0, nflag = 0; - int count = 0, waittime = 0; - char *memf = NULL, *nlistf = NULL; - struct devstat_match *matches; - int num_matches = 0; - char errbuf[_POSIX2_LINE_MAX]; - kvm_t *kd = NULL; - long generation; - int num_devices_specified; - int num_selected, num_selections; - long select_generation; - char **specified_devices; - devstat_select_mode select_mode; - float f; - int havelast = 0; - - matches = NULL; - maxshowdevs = 3; - - while ((c = getopt(argc, argv, "c:CdhIKM:n:N:ot:Tw:xz?")) != -1) { - switch(c) { - case 'c': - cflag++; - count = atoi(optarg); - if (count < 1) - errx(1, "count %d is < 1", count); - break; - case 'C': - Cflag++; - break; - case 'd': - dflag++; - break; - case 'h': - hflag++; - break; - case 'I': - Iflag++; - break; - case 'K': - Kflag++; - break; - case 'M': - memf = optarg; - break; - case 'n': - nflag++; - maxshowdevs = atoi(optarg); - if (maxshowdevs < 0) - errx(1, "number of devices %d is < 0", - maxshowdevs); - break; - case 'N': - nlistf = optarg; - break; - case 'o': - oflag++; - break; - case 't': - tflag++; - if (devstat_buildmatch(optarg, &matches, - &num_matches) != 0) - errx(1, "%s", devstat_errbuf); - break; - case 'T': - Tflag++; - break; - case 'w': - wflag++; - f = atof(optarg); - waittime = f * 1000; - if (waittime < 1) - errx(1, "wait time is < 1ms"); - break; - case 'x': - xflag++; - break; - case 'z': - zflag++; - break; - default: - usage(); - exit(1); - break; - } - } - - argc -= optind; - argv += optind; - - if (nlistf != NULL || memf != NULL) { - kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf); - - if (kd == NULL) - errx(1, "kvm_openfiles: %s", errbuf); - - if (kvm_nlist(kd, namelist) == -1) - errx(1, "kvm_nlist: %s", kvm_geterr(kd)); - } - - /* - * Make sure that the userland devstat version matches the kernel - * devstat version. If not, exit and print a message informing - * the user of his mistake. - */ - if (devstat_checkversion(kd) < 0) - errx(1, "%s", devstat_errbuf); - - /* - * Make sure Tflag and/or Cflag are set if dflag == 0. If dflag is - * greater than 0, they may be 0 or non-zero. - */ - if (dflag == 0 && xflag == 0) { - Cflag = 1; - Tflag = 1; - } - - /* find out how many devices we have */ - if ((num_devices = devstat_getnumdevs(kd)) < 0) - err(1, "can't get number of devices"); - - /* - * Figure out how many devices we should display. - */ - if (nflag == 0) { - if (xflag > 0) - maxshowdevs = num_devices; - else if (oflag > 0) { - if ((dflag > 0) && (Cflag == 0) && (Tflag == 0)) - maxshowdevs = 5; - else if ((dflag > 0) && (Tflag > 0) && (Cflag == 0)) - maxshowdevs = 5; - else - maxshowdevs = 4; - } else { - if ((dflag > 0) && (Cflag == 0)) - maxshowdevs = 4; - else - maxshowdevs = 3; - } - } - - cur.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)); - if (cur.dinfo == NULL) - err(1, "calloc failed"); - - last.dinfo = (struct devinfo *)calloc(1, sizeof(struct devinfo)); - if (last.dinfo == NULL) - err(1, "calloc failed"); - - /* - * Grab all the devices. We don't look to see if the list has - * changed here, since it almost certainly has. We only look for - * errors. - */ - if (devstat_getdevs(kd, &cur) == -1) - errx(1, "%s", devstat_errbuf); - - num_devices = cur.dinfo->numdevs; - generation = cur.dinfo->generation; - - /* - * If the user specified any devices on the command line, see if - * they are in the list of devices we have now. - */ - specified_devices = (char **)malloc(sizeof(char *)); - if (specified_devices == NULL) - err(1, "malloc failed"); - - for (num_devices_specified = 0; *argv; ++argv) { - if (isdigit(**argv)) - break; - num_devices_specified++; - specified_devices = (char **)realloc(specified_devices, - sizeof(char *) * - num_devices_specified); - if (specified_devices == NULL) - err(1, "realloc failed"); - - specified_devices[num_devices_specified - 1] = *argv; - - } - if (nflag == 0 && maxshowdevs < num_devices_specified) - maxshowdevs = num_devices_specified; - - dev_select = NULL; - - if ((num_devices_specified == 0) && (num_matches == 0)) - select_mode = DS_SELECT_ADD; - else - select_mode = DS_SELECT_ONLY; - - /* - * At this point, selectdevs will almost surely indicate that the - * device list has changed, so we don't look for return values of 0 - * or 1. If we get back -1, though, there is an error. - */ - if (devstat_selectdevs(&dev_select, &num_selected, - &num_selections, &select_generation, generation, - cur.dinfo->devices, num_devices, matches, - num_matches, specified_devices, - num_devices_specified, select_mode, maxshowdevs, - hflag) == -1) - errx(1, "%s", devstat_errbuf); - - /* - * Look for the traditional wait time and count arguments. - */ - if (*argv) { - f = atof(*argv); - waittime = f * 1000; - - /* Let the user know he goofed, but keep going anyway */ - if (wflag != 0) - warnx("discarding previous wait interval, using" - " %g instead", waittime / 1000.0); - wflag++; - - if (*++argv) { - count = atoi(*argv); - if (cflag != 0) - warnx("discarding previous count, using %d" - " instead", count); - cflag++; - } else - count = -1; - } - - /* - * If the user specified a count, but not an interval, we default - * to an interval of 1 second. - */ - if ((wflag == 0) && (cflag > 0)) - waittime = 1 * 1000; - - /* - * If the user specified a wait time, but not a count, we want to - * go on ad infinitum. This can be redundant if the user uses the - * traditional method of specifying the wait, since in that case we - * already set count = -1 above. Oh well. - */ - if ((wflag > 0) && (cflag == 0)) - count = -1; - - bzero(cur.cp_time, sizeof(cur.cp_time)); - cur.tk_nout = 0; - cur.tk_nin = 0; - - /* - * Set the snap time to the system boot time (ie: zero), so the - * stats are calculated since system boot. - */ - cur.snap_time = 0; - - /* - * If the user stops the program (control-Z) and then resumes it, - * print out the header again. - */ - (void)signal(SIGCONT, needhdr); - - /* - * If our standard output is a tty, then install a SIGWINCH handler - * and set wresized so that our first iteration through the main - * iostat loop will peek at the terminal's current rows to find out - * how many lines can fit in a screenful of output. - */ - if (isatty(fileno(stdout)) != 0) { - wresized = 1; - (void)signal(SIGWINCH, needresize); - } else { - wresized = 0; - wrows = IOSTAT_DEFAULT_ROWS; - } - - for (headercount = 1;;) { - struct devinfo *tmp_dinfo; - long tmp; - long double etime; - - if (Tflag > 0) { - if ((readvar(kd, "kern.tty_nin", X_TK_NIN, &cur.tk_nin, - sizeof(cur.tk_nin)) != 0) - || (readvar(kd, "kern.tty_nout", X_TK_NOUT, - &cur.tk_nout, sizeof(cur.tk_nout))!= 0)) { - Tflag = 0; - warnx("disabling TTY statistics"); - } - } - - if (Cflag > 0) { - if (kd == NULL) { - if (readvar(kd, "kern.cp_time", 0, - &cur.cp_time, sizeof(cur.cp_time)) != 0) - Cflag = 0; - } else { - if (kvm_getcptime(kd, cur.cp_time) < 0) { - warnx("kvm_getcptime: %s", - kvm_geterr(kd)); - Cflag = 0; - } - } - if (Cflag == 0) - warnx("disabling CPU time statistics"); - } - - if (!--headercount) { - phdr(); - if (wresized != 0) - doresize(); - headercount = wrows; - } - - tmp_dinfo = last.dinfo; - last.dinfo = cur.dinfo; - cur.dinfo = tmp_dinfo; - - last.snap_time = cur.snap_time; - - /* - * Here what we want to do is refresh our device stats. - * devstat_getdevs() returns 1 when the device list has changed. - * If the device list has changed, we want to go through - * the selection process again, in case a device that we - * were previously displaying has gone away. - */ - switch (devstat_getdevs(kd, &cur)) { - case -1: - errx(1, "%s", devstat_errbuf); - break; - case 1: { - int retval; - - num_devices = cur.dinfo->numdevs; - generation = cur.dinfo->generation; - retval = devstat_selectdevs(&dev_select, &num_selected, - &num_selections, - &select_generation, - generation, - cur.dinfo->devices, - num_devices, matches, - num_matches, - specified_devices, - num_devices_specified, - select_mode, maxshowdevs, - hflag); - switch(retval) { - case -1: - errx(1, "%s", devstat_errbuf); - break; - case 1: - phdr(); - if (wresized != 0) - doresize(); - headercount = wrows; - break; - default: - break; - } - break; - } - default: - break; - } - - /* - * We only want to re-select devices if we're in 'top' - * mode. This is the only mode where the devices selected - * could actually change. - */ - if (hflag > 0) { - int retval; - retval = devstat_selectdevs(&dev_select, &num_selected, - &num_selections, - &select_generation, - generation, - cur.dinfo->devices, - num_devices, matches, - num_matches, - specified_devices, - num_devices_specified, - select_mode, maxshowdevs, - hflag); - switch(retval) { - case -1: - errx(1,"%s", devstat_errbuf); - break; - case 1: - phdr(); - if (wresized != 0) - doresize(); - headercount = wrows; - break; - default: - break; - } - } - - if (Tflag > 0) { - tmp = cur.tk_nin; - cur.tk_nin -= last.tk_nin; - last.tk_nin = tmp; - tmp = cur.tk_nout; - cur.tk_nout -= last.tk_nout; - last.tk_nout = tmp; - } - - etime = cur.snap_time - last.snap_time; - - if (etime == 0.0) - etime = 1.0; - - for (i = 0; i < CPUSTATES; i++) { - tmp = cur.cp_time[i]; - cur.cp_time[i] -= last.cp_time[i]; - last.cp_time[i] = tmp; - } - - if (xflag == 0 && Tflag > 0) - printf("%4.0Lf %5.0Lf", cur.tk_nin / etime, - cur.tk_nout / etime); - - devstats(hflag, etime, havelast); - - if (xflag == 0) { - if (Cflag > 0) - cpustats(); - - printf("\n"); - } - fflush(stdout); - - if (count >= 0 && --count <= 0) - break; - - usleep(waittime * 1000); - havelast = 1; - } - - exit(0); -} - -/* - * Force a header to be prepended to the next output. - */ -void -needhdr(int signo) -{ - - headercount = 1; -} - -/* - * When the terminal is resized, force an update of the maximum number of rows - * printed between each header repetition. Then force a new header to be - * prepended to the next output. - */ -void -needresize(int signo) -{ - - wresized = 1; - headercount = 1; -} - -/* - * Update the global `wrows' count of terminal rows. - */ -void -doresize(void) -{ - int status; - struct winsize w; - - for (;;) { - status = ioctl(fileno(stdout), TIOCGWINSZ, &w); - if (status == -1 && errno == EINTR) - continue; - else if (status == -1) - err(1, "ioctl"); - if (w.ws_row > 3) - wrows = w.ws_row - 3; - else - wrows = IOSTAT_DEFAULT_ROWS; - break; - } - - /* - * Inhibit doresize() calls until we are rescheduled by SIGWINCH. - */ - wresized = 0; -} - -static void -phdr(void) -{ - int i, printed; - char devbuf[256]; - - /* - * If xflag is set, we need a per-loop header, not a page header, so - * just return. We'll print the header in devstats(). - */ - if (xflag > 0) - return; - - if (Tflag > 0) - (void)printf(" tty"); - for (i = 0, printed=0;(i < num_devices) && (printed < maxshowdevs);i++){ - int di; - if ((dev_select[i].selected != 0) - && (dev_select[i].selected <= maxshowdevs)) { - di = dev_select[i].position; - snprintf(devbuf, sizeof(devbuf), "%s%d", - cur.dinfo->devices[di].device_name, - cur.dinfo->devices[di].unit_number); - if (oflag > 0) - (void)printf("%13.6s ", devbuf); - else - printf("%16.6s ", devbuf); - printed++; - } - } - if (Cflag > 0) - (void)printf(" cpu\n"); - else - (void)printf("\n"); - - if (Tflag > 0) - (void)printf(" tin tout"); - - for (i=0, printed = 0;(i < num_devices) && (printed < maxshowdevs);i++){ - if ((dev_select[i].selected != 0) - && (dev_select[i].selected <= maxshowdevs)) { - if (oflag > 0) { - if (Iflag == 0) - (void)printf(" sps tps msps "); - else - (void)printf(" blk xfr msps "); - } else { - if (Iflag == 0) - printf(" KB/t tps MB/s "); - else - printf(" KB/t xfrs MB "); - } - printed++; - } - } - if (Cflag > 0) - (void)printf(" us ni sy in id\n"); - else - printf("\n"); - -} - -static void -devstats(int perf_select, long double etime, int havelast) -{ - int dn; - long double transfers_per_second, transfers_per_second_read, transfers_per_second_write; - long double kb_per_transfer, mb_per_second, mb_per_second_read, mb_per_second_write; - u_int64_t total_bytes, total_transfers, total_blocks; - u_int64_t total_bytes_read, total_transfers_read; - u_int64_t total_bytes_write, total_transfers_write; - long double busy_pct; - u_int64_t queue_len; - long double total_mb; - long double blocks_per_second, ms_per_transaction; - int firstline = 1; - char *devname; - - if (xflag > 0) { - printf(" extended device statistics "); - if (Tflag > 0) - printf(" tty "); - if (Cflag > 0) - printf(" cpu "); - printf("\n"); - if (Iflag == 0) - printf( - "device r/s w/s kr/s kw/s wait svc_t %%b " - ); - else - printf( - "device r/i w/i kr/i kw/i wait svc_t %%b " - ); - if (Tflag > 0) - printf("tin tout "); - if (Cflag > 0) - printf("us ni sy in id "); - printf("\n"); - } - - for (dn = 0; dn < num_devices; dn++) { - int di; - - if (((perf_select == 0) && (dev_select[dn].selected == 0)) - || (dev_select[dn].selected > maxshowdevs)) - continue; - - di = dev_select[dn].position; - - if (devstat_compute_statistics(&cur.dinfo->devices[di], - havelast ? &last.dinfo->devices[di] : NULL, etime, - DSM_TOTAL_BYTES, &total_bytes, - DSM_TOTAL_BYTES_READ, &total_bytes_read, - DSM_TOTAL_BYTES_WRITE, &total_bytes_write, - DSM_TOTAL_TRANSFERS, &total_transfers, - DSM_TOTAL_TRANSFERS_READ, &total_transfers_read, - DSM_TOTAL_TRANSFERS_WRITE, &total_transfers_write, - DSM_TOTAL_BLOCKS, &total_blocks, - DSM_KB_PER_TRANSFER, &kb_per_transfer, - DSM_TRANSFERS_PER_SECOND, &transfers_per_second, - DSM_TRANSFERS_PER_SECOND_READ, &transfers_per_second_read, - DSM_TRANSFERS_PER_SECOND_WRITE, &transfers_per_second_write, - DSM_MB_PER_SECOND, &mb_per_second, - DSM_MB_PER_SECOND_READ, &mb_per_second_read, - DSM_MB_PER_SECOND_WRITE, &mb_per_second_write, - DSM_BLOCKS_PER_SECOND, &blocks_per_second, - DSM_MS_PER_TRANSACTION, &ms_per_transaction, - DSM_BUSY_PCT, &busy_pct, - DSM_QUEUE_LENGTH, &queue_len, - DSM_NONE) != 0) - errx(1, "%s", devstat_errbuf); - - if (perf_select != 0) { - dev_select[dn].bytes = total_bytes; - if ((dev_select[dn].selected == 0) - || (dev_select[dn].selected > maxshowdevs)) - continue; - } - - if (Kflag > 0 || xflag > 0) { - int block_size = cur.dinfo->devices[di].block_size; - total_blocks = total_blocks * (block_size ? - block_size : 512) / 1024; - } - - if (xflag > 0) { - if (asprintf(&devname, "%s%d", - cur.dinfo->devices[di].device_name, - cur.dinfo->devices[di].unit_number) == -1) - err(1, "asprintf"); - /* - * If zflag is set, skip any devices with zero I/O. - */ - if (zflag == 0 || transfers_per_second_read > 0.05 || - transfers_per_second_write > 0.05 || - mb_per_second_read > ((long double).0005)/1024 || - mb_per_second_write > ((long double).0005)/1024 || - busy_pct > 0.5) { - if (Iflag == 0) - printf("%-8.8s %5.1Lf %5.1Lf %7.1Lf %7.1Lf %4qu %5.1Lf %3.0Lf ", - devname, transfers_per_second_read, - transfers_per_second_write, - mb_per_second_read * 1024, - mb_per_second_write * 1024, - queue_len, - ms_per_transaction, busy_pct); - else - printf("%-8.8s %5.1Lf %5.1Lf %7.1Lf %7.1Lf %4qu %5.1Lf %3.0Lf ", - devname, - (long double)total_transfers_read, - (long double)total_transfers_write, - (long double) - total_bytes_read / 1024, - (long double) - total_bytes_write / 1024, - queue_len, - ms_per_transaction, busy_pct); - if (firstline) { - /* - * If this is the first device - * we're printing, also print - * CPU or TTY stats if requested. - */ - firstline = 0; - if (Tflag > 0) - printf("%4.0Lf%5.0Lf", - cur.tk_nin / etime, - cur.tk_nout / etime); - if (Cflag > 0) - cpustats(); - } - printf("\n"); - } - free(devname); - } else if (oflag > 0) { - int msdig = (ms_per_transaction < 100.0) ? 1 : 0; - - if (Iflag == 0) - printf("%4.0Lf%4.0Lf%5.*Lf ", - blocks_per_second, - transfers_per_second, - msdig, - ms_per_transaction); - else - printf("%4.1qu%4.1qu%5.*Lf ", - total_blocks, - total_transfers, - msdig, - ms_per_transaction); - } else { - if (Iflag == 0) - printf(" %5.2Lf %3.0Lf %5.2Lf ", - kb_per_transfer, - transfers_per_second, - mb_per_second); - else { - total_mb = total_bytes; - total_mb /= 1024 * 1024; - - printf(" %5.2Lf %3.1qu %5.2Lf ", - kb_per_transfer, - total_transfers, - total_mb); - } - } - } - if (xflag > 0 && zflag > 0 && firstline == 1 && - (Tflag > 0 || Cflag > 0)) { - /* - * If zflag is set and we did not print any device - * lines I/O because they were all zero, - * print TTY/CPU stats. - */ - printf("%52s",""); - if (Tflag > 0) - printf("%4.0Lf %5.0Lf", cur.tk_nin / etime, - cur.tk_nout / etime); - if (Cflag > 0) - cpustats(); - printf("\n"); - } -} - -static void -cpustats(void) -{ - int state; - double time; - - time = 0.0; - - for (state = 0; state < CPUSTATES; ++state) - time += cur.cp_time[state]; - for (state = 0; state < CPUSTATES; ++state) - printf(" %2.0f", - rint(100. * cur.cp_time[state] / (time ? time : 1))); -} - -static int -readvar(kvm_t *kd, const char *name, int nlid, void *ptr, size_t len) -{ - if (kd != NULL) { - ssize_t nbytes; - - nbytes = kvm_read(kd, namelist[nlid].n_value, ptr, len); - - if (nbytes < 0) { - warnx("kvm_read(%s): %s", namelist[nlid].n_name, - kvm_geterr(kd)); - return (1); - } - if (nbytes != len) { - warnx("kvm_read(%s): expected %zu bytes, got %zd bytes", - namelist[nlid].n_name, len, nbytes); - return (1); - } - } else { - size_t nlen = len; - - if (sysctlbyname(name, ptr, &nlen, NULL, 0) == -1) { - warn("sysctl(%s...) failed", name); - return (1); - } - if (nlen != len) { - warnx("sysctl(%s...): expected %lu, got %lu", name, - (unsigned long)len, (unsigned long)nlen); - return (1); - } - } - return (0); -} diff --git a/usr.sbin/ip6addrctl/Makefile b/usr.sbin/ip6addrctl/Makefile deleted file mode 100644 index 93a2990..0000000 --- a/usr.sbin/ip6addrctl/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# $FreeBSD$ - -PROG= ip6addrctl -MAN= ip6addrctl.8 - -WARNS?= 2 - -.include diff --git a/usr.sbin/ip6addrctl/ip6addrctl.8 b/usr.sbin/ip6addrctl/ip6addrctl.8 deleted file mode 100644 index 59154d4..0000000 --- a/usr.sbin/ip6addrctl/ip6addrctl.8 +++ /dev/null @@ -1,126 +0,0 @@ -.\" $KAME: ip6addrctl.8,v 1.3 2003/03/22 05:56:41 jinmei Exp $ -.\" -.\" Copyright (C) 2001 WIDE Project. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the project nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $FreeBSD$ -.\" -.Dd September 25, 2001 -.Dt IP6ADDRCTL 8 -.Os -.\" -.Sh NAME -.Nm ip6addrctl -.Nd configure address selection policy for IPv6 and IPv4 -.\" -.Sh SYNOPSIS -.Nm -.Op Cm show -.Nm -.Cm add -.Ar prefix precedence label -.Nm -.Cm delete -.Ar prefix -.Nm -.Cm flush -.Nm -.Cm install -.Ar configfile -.\" -.Sh DESCRIPTION -The -.Nm -utility manages the policy table of source and destination address -selection for outgoing IPv4 and IPv6 packets. -When -.Nm -is invoked without an argument or with a single argument -.Cm show , -it prints the content of the policy table currently installed in the -kernel. -.Pp -To modify the table, the following operations are available: -.Bl -tag -width indent -.It Cm add Ar prefix precedence label -Add a policy entry. -The -.Ar prefix -argument -is an IPv6 prefix, which is a key for the entry. -An IPv4 prefix should be specified with an IPv6 prefix using an -IPv4-mapped IPv6 address. -The -.Ar precedence -and -.Ar label -arguments -are decimal numbers, which specify the precedence and label values -for the entry, respectively. -This operation should be performed without an existing entry for the -prefix. -.It Cm delete Ar prefix -Delete a policy entry specified by -.Ar prefix , -which should be an IPv6 prefix. -A corresponding entry for the prefix should have already been -installed. -.It Cm flush -Delete all existing policy entries in the kernel. -.It Cm install Ar configfile -Install policy entries from a configuration file named -.Ar configfile . -The configuration file should contain a set of policy entries. -Each entry is specified in a single line which contains an IPv6 prefix, -a decimal precedence value, and a decimal label value, separated with -white space or tab characters. -In the configuration file, lines beginning with the pound-sign -.Pq Ql # -are -comments and are ignored. -.El -.\" -.Sh EXIT STATUS -.Ex -std -.\" -.Sh SEE ALSO -.Rs -.%A "Richard Draves" -.%T "Default Address Selection for IPv6" -.%N RFC 3484 -.Re -.\" -.Sh HISTORY -The -.Nm -utility first appeared in the KAME IPv6 protocol stack kit. -The original command name was -.Nm addrselect , -but it was then renamed to the current one so that the name would -describe its function well. -.\" .Sh BUGS -.\" (to be written) diff --git a/usr.sbin/ip6addrctl/ip6addrctl.c b/usr.sbin/ip6addrctl/ip6addrctl.c deleted file mode 100644 index 532a096..0000000 --- a/usr.sbin/ip6addrctl/ip6addrctl.c +++ /dev/null @@ -1,467 +0,0 @@ -/* $KAME: ip6addrctl.c,v 1.3 2003/12/16 08:14:28 suz Exp $ */ - -/* - * Copyright (C) 2001 WIDE Project. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the project nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static char *configfile; - -struct policyqueue { - TAILQ_ENTRY(policyqueue) pc_entry; - struct in6_addrpolicy pc_policy; -}; -TAILQ_HEAD(policyhead, policyqueue); -struct policyhead policyhead; - -static void usage(void); -static void get_policy(void); -static void dump_policy(void); -static int mask2plen(struct sockaddr_in6 *); -static int parse_prefix(const char *, struct in6_addrpolicy *); -static void make_policy_fromfile(char *); -static void plen2mask(struct sockaddr_in6 *, int); -static void set_policy(void); -static void add_policy(char *, char *, char *); -static void delete_policy(char *); -static void flush_policy(); - -int -main(argc, argv) - int argc; - char *argv[]; -{ - TAILQ_INIT(&policyhead); - - if (argc == 1 || strcasecmp(argv[1], "show") == 0) { - get_policy(); - dump_policy(); - } else if (strcasecmp(argv[1], "add") == 0) { - if (argc < 5) - usage(); - add_policy(argv[2], argv[3], argv[4]); - } else if (strcasecmp(argv[1], "delete") == 0) { - if (argc < 3) - usage(); - delete_policy(argv[2]); - } else if (strcasecmp(argv[1], "flush") == 0) { - get_policy(); - flush_policy(); - } else if (strcasecmp(argv[1], "install") == 0) { - if (argc < 3) - usage(); - configfile = argv[2]; - make_policy_fromfile(configfile); - set_policy(); - } else - usage(); - - exit(0); -} - -static void -get_policy() -{ - int mib[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, IPV6CTL_ADDRCTLPOLICY }; - size_t l; - char *buf; - struct in6_addrpolicy *pol, *ep; - - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &l, NULL, 0) < 0) { - err(1, "sysctl(IPV6CTL_ADDRCTLPOLICY)"); - /* NOTREACHED */ - } - if (l == 0) { - printf("no source-address-selection policy is installed\n"); - return; - } - if ((buf = malloc(l)) == NULL) { - errx(1, "malloc failed"); - /* NOTREACHED */ - } - if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &l, NULL, 0) < 0) { - err(1, "sysctl(IPV6CTL_ADDRCTLPOLICY)"); - /* NOTREACHED */ - } - - ep = (struct in6_addrpolicy *)(buf + l); - for (pol = (struct in6_addrpolicy *)buf; pol + 1 <= ep; pol++) { - struct policyqueue *new; - - if ((new = malloc(sizeof(*new))) == NULL) - errx(1, "malloc failed\n"); - new->pc_policy = *pol; - TAILQ_INSERT_TAIL(&policyhead, new, pc_entry); - } - - free(buf); -} - -static void -dump_policy() -{ - size_t addrlen; - char addrbuf[NI_MAXHOST]; - struct in6_addrpolicy *pol; - struct policyqueue *ent; - int plen, first = 1; - - for (ent = TAILQ_FIRST(&policyhead); ent; - ent = TAILQ_NEXT(ent, pc_entry)) { - pol = &ent->pc_policy; - if (first) { - printf("%-30s %5s %5s %8s\n", - "Prefix", "Prec", "Label", "Use"); - first = 0; - } - - if ((getnameinfo((struct sockaddr *)&pol->addr, - sizeof(pol->addr), addrbuf, sizeof(addrbuf), - NULL, 0, NI_NUMERICHOST))) { - warnx("getnameinfo for prefix address failed"); - continue; - } - if ((plen = mask2plen(&pol->addrmask)) < 0) { - warnx("invalid address mask"); - continue; - } - addrlen = strlen(addrbuf); - if (addrlen + sizeof("/128") < sizeof(addrbuf)) { - snprintf(&addrbuf[addrlen], - sizeof(addrbuf) - addrlen - 1, - "/%d", plen); - printf("%-30s", addrbuf); - } else /* XXX */ - printf("%s/%d", addrbuf, plen); - printf(" %5d %5d %8llu\n", pol->preced, pol->label, - (unsigned long long)pol->use); - } -} - -#define SKIP_WHITE(p, emptyok) \ - do { \ - while((*(p) == ' ' || *(p) == '\t')) \ - (p)++; \ - if ((*(p) == '\0' || (*(p) == '\n')) && !(emptyok)) \ - goto bad; \ - } while (0); -#define SKIP_WORD(p) \ - do { \ - while(*(p) != ' ' && *(p) != '\t') \ - (p)++; \ - if (*(p) == '\0' || *(p) == '\n') \ - goto bad; \ - } while (0); - -static void -make_policy_fromfile(conf) - char *conf; -{ - char line[_POSIX2_LINE_MAX], *cp; - char *addrstr; - FILE *fp; - int count = 0; - struct in6_addrpolicy pol0; - struct policyqueue *new; - - if ((fp = fopen(conf, "r")) == NULL) - err(1, "fopen: %s", conf); - - while(fgets(line, sizeof(line), fp)) { - count++; - cp = line; - - memset(&pol0, 0, sizeof(pol0)); - - /* get prefix */ - SKIP_WHITE(cp, 1); - if (*cp == '\n') /* empty line */ - continue; - if (*cp == '#') - continue; - addrstr = cp; - if (parse_prefix((const char *)addrstr, &pol0)) - goto bad; - - /* get precedence value */ - SKIP_WORD(cp); - SKIP_WHITE(cp, 0); - pol0.preced = atoi(cp); - - /* get label */ - SKIP_WORD(cp); - SKIP_WHITE(cp, 0); - pol0.label = atoi(cp); - - /* parse succeeded. make a control buffer entry. */ - if ((new = malloc(sizeof(*new))) == NULL) - errx(1, "malloc failed\n"); - memset(new, 0, sizeof(*new)); - new->pc_policy = pol0; - TAILQ_INSERT_TAIL(&policyhead, new, pc_entry); - } - - fclose(fp); - return; - - bad: - errx(1, "parse failed at line %d", count); - /* NOTREACHED */ -} - -static int -parse_prefix(prefix0, pol) - const char *prefix0; - struct in6_addrpolicy *pol; -{ - int e = 0, plen; - char *prefix, *plenstr; - struct addrinfo hints, *res; - - if ((prefix = strdup(prefix0)) == NULL) - errx(1, "strdup failed"); - - if ((plenstr = strchr(prefix, '/')) == NULL) { - e = -1; - goto end; - } - *plenstr = '\0'; - - memset(&hints, 0, sizeof(hints)); - hints.ai_flags = AI_NUMERICHOST; - hints.ai_family = AF_INET6; - - if ((e = getaddrinfo(prefix, NULL, &hints, &res)) != 0) { - warnx("getaddrinfo failed for %s: %s", prefix, - gai_strerror(e)); - goto end; - } - memcpy(&pol->addr, res->ai_addr, res->ai_addrlen); - freeaddrinfo(res); - plen = atoi(plenstr + 1); - if (plen < 0 || plen > 128) { - warnx("invalid prefix length: %d", plen); - e = -1; - goto end; - } - plen2mask(&pol->addrmask, plen); - - end: - free(prefix); - return(e); -} - -static void -plen2mask(mask, plen) - struct sockaddr_in6 *mask; - int plen; -{ - u_char *cp = (char *)&mask->sin6_addr; - - memset(mask, 0, sizeof(*mask)); - mask->sin6_family = AF_INET6; /* just in case */ - mask->sin6_len = sizeof(*mask); - - for(; plen >= 8; plen -= 8) - *cp++ = 0xff; - if (plen > 0) - *cp = (0xff << (8 - plen)); -} - -static void -set_policy() -{ - struct policyqueue *ent; - int s; - - if ((s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0) - err(1, "socket(UDP)"); - - for (ent = TAILQ_FIRST(&policyhead); ent; - ent = TAILQ_NEXT(ent, pc_entry)) { - if (ioctl(s, SIOCAADDRCTL_POLICY, &ent->pc_policy)) - warn("ioctl(SIOCAADDRCTL_POLICY)"); - } - - close(s); -} - -static int -mask2plen(mask) - struct sockaddr_in6 *mask; -{ - int masklen, final = 0; - u_char *p, *lim; - - masklen = 0; - lim = (u_char *)(mask + 1); - for (p = (u_char *)(&mask->sin6_addr); p < lim; p++) { - if (final && *p) { - goto bad; - } - - switch (*p & 0xff) { - case 0xff: - masklen += 8; - break; - case 0xfe: - masklen += 7; - final++; - break; - case 0xfc: - masklen += 6; - final++; - break; - case 0xf8: - masklen += 5; - final++; - break; - case 0xf0: - masklen += 4; - final++; - break; - case 0xe0: - masklen += 3; - final++; - break; - case 0xc0: - masklen += 2; - final++; - break; - case 0x80: - masklen += 1; - final++; - break; - case 0x00: - final++; - break; - default: - goto bad; - break; - } - } - return(masklen); - - bad: - return(-1); -} - -static void -add_policy(prefix, prec, label) - char *prefix, *prec, *label; -{ - struct in6_addrpolicy p; - int s; - - memset(&p, 0, sizeof(p)); - - if (parse_prefix((const char *)prefix, &p)) - errx(1, "bad prefix: %s", prefix); - p.preced = atoi(prec); - p.label = atoi(label); - - if ((s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0) - err(1, "socket(UDP)"); - if (ioctl(s, SIOCAADDRCTL_POLICY, &p)) - err(1, "ioctl(SIOCAADDRCTL_POLICY)"); - - close(s); -} - -static void -delete_policy(prefix) - char *prefix; -{ - struct in6_addrpolicy p; - int s; - - memset(&p, 0, sizeof(p)); - - if (parse_prefix((const char *)prefix, &p)) - errx(1, "bad prefix: %s", prefix); - - if ((s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0) - err(1, "socket(UDP)"); - if (ioctl(s, SIOCDADDRCTL_POLICY, &p)) - err(1, "ioctl(SIOCDADDRCTL_POLICY)"); - - close(s); -} - -static void -flush_policy() -{ - struct policyqueue *ent; - int s; - - if ((s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) < 0) - err(1, "socket(UDP)"); - - for (ent = TAILQ_FIRST(&policyhead); ent; - ent = TAILQ_NEXT(ent, pc_entry)) { - if (ioctl(s, SIOCDADDRCTL_POLICY, &ent->pc_policy)) - warn("ioctl(SIOCDADDRCTL_POLICY)"); - } - - close(s); -} - -static void -usage() -{ - fprintf(stderr, "usage: ip6addrctl [show]\n"); - fprintf(stderr, " ip6addrctl add " - "